| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | public function __construct() { |
| 21 | 21 | global $mwcode; |
| 22 | 22 | |
| 23 | 23 | $this->site_url = get_site_url(); |
| 24 | - $this->is_rest = MeowCommon_Helpers::is_rest(); | |
| 24 | + $this->is_rest = MeowKit_MWCODE_Helpers::is_rest(); | |
| 25 | 25 | $this->is_cli = defined( 'WP_CLI' ) && WP_CLI; |
| 26 | 26 | |
| 27 | 27 | // Snippets |
| 28 | 28 | $snippet = new Meow_MWCODE_Modules_Snippet( $this ); |
| @@ -39,10 +39,10 @@ | ||
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function init() { |
| 42 | 42 | // Initialize the licenser for Pro version |
| 43 | - if ( class_exists( 'MeowCommonPro_Licenser' ) ) { | |
| 44 | - $this->licenser = new MeowCommonPro_Licenser( MWCODE_PREFIX, MWCODE_ENTRY, MWCODE_DOMAIN, MWCODE_ITEM_ID, MWCODE_VERSION ); | |
| 43 | + if ( class_exists( 'MeowKitPro_MWCODE_Licenser' ) ) { | |
| 44 | + $this->licenser = new MeowKitPro_MWCODE_Licenser( MWCODE_PREFIX, MWCODE_ENTRY, MWCODE_DOMAIN, MWCODE_ITEM_ID, MWCODE_VERSION ); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Part of the core, settings and stuff |
| 48 | 48 | $this->admin = new Meow_MWCODE_Admin( $this ); |
| @@ -110,8 +110,11 @@ | ||
| 110 | 110 | "api_token" => md5( time() . rand() ), |
| 111 | 111 | |
| 112 | 112 | //MCP |
| 113 | 113 | "mcp_support" => false, |
| 114 | + | |
| 115 | + //MAINTENANCE | |
| 116 | + "clean_uninstall" => false, | |
| 114 | 117 | ]; |
| 115 | 118 | } |
| 116 | 119 | |
| 117 | 120 | function get_all_options( ) { |
| @@ -125,19 +128,15 @@ | ||
| 125 | 128 | return $options; |
| 126 | 129 | } |
| 127 | 130 | |
| 128 | 131 | function update_options( $options ) { |
| 129 | - $current_options = get_option($this->option_name); | |
| 130 | 132 | |
| 131 | - if ($current_options === $options) { | |
| 132 | - // $this->log('💾 The options are already the expected value.'); | |
| 133 | - } else { | |
| 134 | - if ( !update_option( $this->option_name, $options, false ) ) { | |
| 135 | - $this->log( '💾 There was an issue updating the options.' ); | |
| 136 | - } | |
| 133 | + $options = $this->sanitize_options( $options ); | |
| 134 | + | |
| 135 | + if ( !update_option( $this->option_name, $options, false ) ) { | |
| 136 | + $this->log( '💾 There was an issue updating the options.' ); | |
| 137 | 137 | } |
| 138 | - | |
| 139 | - $options = $this->sanitize_options( $options ); | |
| 138 | + | |
| 140 | 139 | return $options; |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | 142 | function update_option( $option, $value ) { |
| @@ -180,12 +179,8 @@ | ||
| 180 | 179 | // Note: We don't disable MCP support here anymore |
| 181 | 180 | // It will be checked at runtime in the MCP class |
| 182 | 181 | } |
| 183 | 182 | |
| 184 | - if ( $options_modified ) { | |
| 185 | - update_option( $this->option_name, $options, false ); | |
| 186 | - } | |
| 187 | - | |
| 188 | 183 | return $options; |
| 189 | 184 | } |
| 190 | 185 | |
| 191 | 186 | private function updateAIEngineStatus( &$options ) { |
| @@ -292,9 +287,9 @@ | ||
| 292 | 287 | |
| 293 | 288 | return [ $name, $value ]; |
| 294 | 289 | } |
| 295 | 290 | |
| 296 | - function run_non_fn_snippet( $id, $code = null, $test = false ) { | |
| 291 | + function run_non_fn_snippet( $id, $code = null, $test = false, $prefix = '' ) { | |
| 297 | 292 | // Retrieve the snippet code from the provided code or via the snippet ID. |
| 298 | 293 | if ( $code ) { |
| 299 | 294 | $snippet = [ 'code' => $code ]; |
| 300 | 295 | } else { |
| @@ -301,13 +296,17 @@ | ||
| 301 | 296 | $snippet = $this->get_snippet( $id ); |
| 302 | 297 | } |
| 303 | 298 | |
| 304 | 299 | // Remove any PHP opening tag. |
| 305 | - $snippet['code'] = preg_replace( '/<\?php/', '', $snippet['code'], 1 ); | |
| 300 | + $snippet['code'] = $this->snippet->sanitize_code( $snippet['code'] ); | |
| 306 | 301 | |
| 307 | 302 | if ( $test ) { |
| 308 | 303 | $snippet['code'] = preg_replace( '/echo\s+(.+?);/s', 'echo $1 . "\n";', $snippet['code'] ); |
| 309 | 304 | } |
| 305 | + | |
| 306 | + if( $prefix ) { | |
| 307 | + $snippet['code'] = $prefix . "\n" . $snippet['code']; | |
| 308 | + } | |
| 310 | 309 | |
| 311 | 310 | $error = null; |
| 312 | 311 | $output = null; |
| 313 | 312 | |
| @@ -598,9 +597,9 @@ | ||
| 598 | 597 | $blocked = false; |
| 599 | 598 | //$blocked = true; |
| 600 | 599 | } |
| 601 | 600 | // Block REST requests that aren't whitelisted |
| 602 | - elseif ( MeowCommon_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) { | |
| 601 | + elseif ( MeowKit_MWCODE_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) { | |
| 603 | 602 | $blocked = true; |
| 604 | 603 | } |
| 605 | 604 | |
| 606 | 605 | if ( empty( $this->snippet ) ) { |
| @@ -631,9 +630,9 @@ | ||
| 631 | 630 | return; |
| 632 | 631 | } |
| 633 | 632 | |
| 634 | 633 | $snippets = array_map( function ( $snippet ) use ( $blocked ) { |
| 635 | - $snippet['code'] = preg_replace( '/<\?php/', '', $snippet['code'], 1 ); | |
| 634 | + $snippet['code'] = $this->snippet->sanitize_code( $snippet['code'] ); | |
| 636 | 635 | $snippet['blocked'] = $blocked; |
| 637 | 636 | |
| 638 | 637 | // If the snippet must be executed only in the frontend, we bypass the block |
| 639 | 638 | if ( !is_admin() && $snippet['scope'] === 'frontend' ) { |
| @@ -649,16 +648,26 @@ | ||
| 649 | 648 | |
| 650 | 649 | #endregion |
| 651 | 650 | |
| 652 | 651 | #region Shortcodes |
| 652 | + function separate_mwcode_atts( $atts ) { | |
| 653 | 653 | |
| 654 | + if( array_key_exists( 'id', $atts ) ) unset( $atts['id'] ); | |
| 655 | + if( array_key_exists( 'target', $atts ) ) unset( $atts['target'] ); | |
| 656 | + if( array_key_exists( 'code', $atts ) ) unset( $atts['code'] ); | |
| 657 | + | |
| 658 | + return $atts; | |
| 659 | + } | |
| 660 | + | |
| 654 | 661 | function content_shortcode( $atts ) { |
| 655 | 662 | |
| 663 | + $user_atts = $this->separate_mwcode_atts( $atts ); | |
| 664 | + | |
| 656 | 665 | $atts = shortcode_atts( array( |
| 657 | - 'id' => null, | |
| 658 | - 'target' => null, | |
| 659 | - 'code' => null, | |
| 660 | - ), $atts ); | |
| 666 | + 'id' => null, | |
| 667 | + 'target' => null, // js or php | |
| 668 | + 'code' => null, // For Guttenberg block usage | |
| 669 | + ), $atts, 'code-engine' ); | |
| 661 | 670 | |
| 662 | 671 | $id = $atts['id']; |
| 663 | 672 | $target = $atts['target']; |
| 664 | 673 | $code = $atts['code']; |
| @@ -741,9 +750,10 @@ | ||
| 741 | 750 | $output = '<script>' . $snippet['code'] . '</script>'; |
| 742 | 751 | } |
| 743 | 752 | |
| 744 | 753 | if ( $is_content_php ) { |
| 745 | - $output = $this->run_non_fn_snippet( $id ); | |
| 754 | + $prefix = "\$mwcode_atts = unserialize( '" . serialize( $user_atts ) . "' );"; | |
| 755 | + $output = $this->run_non_fn_snippet( $id, null, false, $prefix ); | |
| 746 | 756 | } |
| 747 | 757 | |
| 748 | 758 | return $output; |
| 749 | 759 | } |