| @@ -142,15 +142,15 @@ | ||
| 142 | 142 | foreach ( $functions_snippet as $function_snippet ) { |
| 143 | 143 | if ( $function_snippet['snippetId'] == $snippetId ) { |
| 144 | 144 | |
| 145 | 145 | $snippet['functionName'] = $function_snippet['name']; |
| 146 | - if ( !isset( $function_snippet['behavior'] ) || empty( $function_snippet['behavior'] ) ) { | |
| 146 | + if ( !isset( $snippet['functionBehavior'] ) || empty( $snippet['functionBehavior'] ) ) { | |
| 147 | 147 | $snippet['functionBehavior'] = 'dynamic'; |
| 148 | 148 | } |
| 149 | 149 | else { |
| 150 | 150 | $snippet['functionBehavior'] = $function_snippet['behavior']; |
| 151 | 151 | } |
| 152 | - if ( !isset( $function_snippet['target'] ) || empty( $function_snippet['target'] ) ) { | |
| 152 | + if ( !isset( $snippet['functionTarget'] ) || empty( $snippet['functionTarget'] ) ) { | |
| 153 | 153 | $snippet['functionTarget'] = 'PHP'; |
| 154 | 154 | } |
| 155 | 155 | else { |
| 156 | 156 | $snippet['functionTarget'] = $function_snippet['target']; |
| @@ -223,9 +223,9 @@ | ||
| 223 | 223 | if ( !empty( $argName ) ) { |
| 224 | 224 | $argData = $params['functionArgsDict'][$argName]; |
| 225 | 225 | $snippet['args'][] = [ |
| 226 | 226 | 'name' => $argName, |
| 227 | - 'desc' => $argData['description'] ?? $argData['desc'] ?? '', // Support both 'description' and 'desc' | |
| 227 | + 'desc' => $argData['desc'], | |
| 228 | 228 | 'default' => $argData['default'], |
| 229 | 229 | 'required' => empty( $argData['default'] ), |
| 230 | 230 | 'type' => $argData['type'], |
| 231 | 231 | ]; |
| @@ -390,9 +390,8 @@ | ||
| 390 | 390 | $scopes = [ |
| 391 | 391 | "global" => "persistent", |
| 392 | 392 | "front-end" => "frontend", |
| 393 | 393 | "admin" => "backend", |
| 394 | - "content" => "content_php", | |
| 395 | 394 | ]; |
| 396 | 395 | |
| 397 | 396 | if ( array_key_exists( $params['scope'], $scopes ) ) { |
| 398 | 397 | $params['scope'] = $scopes[$params['scope']]; |
| @@ -537,9 +536,9 @@ | ||
| 537 | 536 | return $tag !== ''; |
| 538 | 537 | } ); |
| 539 | 538 | } |
| 540 | 539 | $params['tags'] = $tags ? implode( ',', $tags ) : ''; |
| 541 | - //$params['code'] = $this->sanitize_code( $params['code'] ); | |
| 540 | + $params['code'] = $this->sanitize_code( $params['code'] ); | |
| 542 | 541 | return $params; |
| 543 | 542 | } |
| 544 | 543 | |
| 545 | 544 | /** |
| @@ -550,9 +549,9 @@ | ||
| 550 | 549 | */ |
| 551 | 550 | private function formatParamsForFront( $params ) |
| 552 | 551 | { |
| 553 | 552 | // Separate the scope tags from the tags |
| 554 | - $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled', 'content_php', 'content_js']; | |
| 553 | + $scopes = ['backend', 'frontend', 'function', 'persistent', 'scheduled']; | |
| 555 | 554 | |
| 556 | 555 | if ( isset( $params['tags'] ) && !empty( $params['tags'] ) ) { |
| 557 | 556 | |
| 558 | 557 | $tags = array_map( function ( $tag ) use ( $scopes ) { |
| @@ -586,12 +585,9 @@ | ||
| 586 | 585 | $stats[$scope] = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT COUNT( * ) FROM $this->table_name WHERE scope = %s", $scope ) ); |
| 587 | 586 | } |
| 588 | 587 | $stats['all'] += $stats[$scope]; |
| 589 | 588 | } |
| 590 | - | |
| 591 | - // Combined count for the "Content" filter (PHP + JS). Not added to 'all', already counted above. | |
| 592 | - $stats['content'] = (int) $stats['content_php'] + (int) $stats['content_js']; | |
| 593 | - | |
| 589 | + | |
| 594 | 590 | return $stats; |
| 595 | 591 | } |
| 596 | 592 | |
| 597 | 593 | public function import( ) |
| @@ -614,34 +610,15 @@ | ||
| 614 | 610 | |
| 615 | 611 | return count( $snippets ); |
| 616 | 612 | } |
| 617 | 613 | |
| 618 | - public function sanitize_code( $code ) | |
| 614 | + private function sanitize_code( $code ) | |
| 619 | 615 | { |
| 616 | + $code = preg_replace( '/<\?php/', '', $code, 1 ); | |
| 620 | 617 | $code = ltrim( $code ); |
| 621 | - | |
| 622 | - $first_chats = substr( $code, 0, 5 ); | |
| 623 | - if( $first_chats === '<?php' ) { | |
| 624 | - $code = substr( $code, 5 ); | |
| 625 | - $code = ltrim( $code ); | |
| 626 | - } | |
| 627 | - | |
| 628 | 618 | return $code; |
| 629 | 619 | } |
| 630 | 620 | |
| 631 | - public function delete_duplicates() { | |
| 632 | - // Delete snippets that have the same code and scope, keeping only the most recent one ( based on the updated column ) | |
| 633 | - $query = "DELETE t1 FROM $this->table_name t1 | |
| 634 | - INNER JOIN $this->table_name t2 | |
| 635 | - WHERE t1.id < t2.id | |
| 636 | - AND t1.code = t2.code | |
| 637 | - AND t1.scope = t2.scope"; | |
| 638 | - | |
| 639 | - $this->wpdb->query( $query ); | |
| 640 | - | |
| 641 | - return $this->wpdb->rows_affected; | |
| 642 | - } | |
| 643 | - | |
| 644 | 621 | #endregion |
| 645 | 622 | |
| 646 | 623 | #region Snippet CRUD |
| 647 | 624 | |
| @@ -672,11 +649,8 @@ | ||
| 672 | 649 | } |
| 673 | 650 | else if ( $filter['accessor'] === 'scope' && $filter['value'] === 'global' ) { |
| 674 | 651 | $freshFilters[] = [ 'accessor' => 'scope', 'value' => ['backend', 'frontend', 'persistent'] ]; |
| 675 | 652 | } |
| 676 | - else if ( $filter['accessor'] === 'scope' && $filter['value'] === 'content' ) { | |
| 677 | - $freshFilters[] = [ 'accessor' => 'scope', 'value' => ['content_php', 'content_js'] ]; | |
| 678 | - } | |
| 679 | 653 | else { |
| 680 | 654 | $freshFilters[] = $filter; |
| 681 | 655 | } |
| 682 | 656 | } |
| @@ -713,9 +687,9 @@ | ||
| 713 | 687 | $scopes = array_map( function( $scope ) { |
| 714 | 688 | return esc_sql( $scope ); |
| 715 | 689 | }, $filter['value'] ); |
| 716 | 690 | $where[] = "scope IN ('" . implode( "', '", $scopes ) . "')"; |
| 717 | - } else if ( !empty( $filter['value'] ) ) { | |
| 691 | + } else { | |
| 718 | 692 | $value = esc_sql( $filter['value'] ); |
| 719 | 693 | $where[] = $this->wpdb->prepare( "scope = %s", $value ); |
| 720 | 694 | } |
| 721 | 695 | } |
| @@ -900,12 +874,8 @@ | ||
| 900 | 874 | } |
| 901 | 875 | |
| 902 | 876 | function check_db( ) |
| 903 | 877 | { |
| 904 | - if ( $this->db_check ) { | |
| 905 | - return true; | |
| 906 | - } | |
| 907 | - | |
| 908 | 878 | if ( $this->does_table_exist( $this->table_name ) ) { |
| 909 | 879 | $this->check_columns( ); |
| 910 | 880 | $this->db_check = true; |
| 911 | 881 | } else { |