| @@ -12,8 +12,9 @@ | ||
| 12 | 12 | public $is_rest = false; |
| 13 | 13 | public $is_cli = false; |
| 14 | 14 | public $site_url = null; |
| 15 | 15 | public $mwcode = null; |
| 16 | + public $licenser = null; | |
| 16 | 17 | |
| 17 | 18 | private $option_name = 'mwcode_options'; |
| 18 | 19 | |
| 19 | 20 | public function __construct() { |
| @@ -19,9 +20,9 @@ | ||
| 19 | 20 | public function __construct() { |
| 20 | 21 | global $mwcode; |
| 21 | 22 | |
| 22 | 23 | $this->site_url = get_site_url(); |
| 23 | - $this->is_rest = MeowCommon_Helpers::is_rest(); | |
| 24 | + $this->is_rest = MeowKit_MWCODE_Helpers::is_rest(); | |
| 24 | 25 | $this->is_cli = defined( 'WP_CLI' ) && WP_CLI; |
| 25 | 26 | |
| 26 | 27 | // Snippets |
| 27 | 28 | $snippet = new Meow_MWCODE_Modules_Snippet( $this ); |
| @@ -37,8 +38,13 @@ | ||
| 37 | 38 | add_action( 'plugins_loaded', array( $this, 'init' ) ); |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | 41 | function init() { |
| 42 | + // Initialize the licenser for Pro 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 | + } | |
| 46 | + | |
| 41 | 47 | // Part of the core, settings and stuff |
| 42 | 48 | $this->admin = new Meow_MWCODE_Admin( $this ); |
| 43 | 49 | |
| 44 | 50 | // Only for REST |
| @@ -104,8 +110,11 @@ | ||
| 104 | 110 | "api_token" => md5( time() . rand() ), |
| 105 | 111 | |
| 106 | 112 | //MCP |
| 107 | 113 | "mcp_support" => false, |
| 114 | + | |
| 115 | + //MAINTENANCE | |
| 116 | + "clean_uninstall" => false, | |
| 108 | 117 | ]; |
| 109 | 118 | } |
| 110 | 119 | |
| 111 | 120 | function get_all_options( ) { |
| @@ -119,19 +128,15 @@ | ||
| 119 | 128 | return $options; |
| 120 | 129 | } |
| 121 | 130 | |
| 122 | 131 | function update_options( $options ) { |
| 123 | - $current_options = get_option($this->option_name); | |
| 124 | 132 | |
| 125 | - if ($current_options === $options) { | |
| 126 | - // $this->log('💾 The options are already the expected value.'); | |
| 127 | - } else { | |
| 128 | - if ( !update_option( $this->option_name, $options, false ) ) { | |
| 129 | - $this->log( '💾 There was an issue updating the options.' ); | |
| 130 | - } | |
| 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.' ); | |
| 131 | 137 | } |
| 132 | - | |
| 133 | - $options = $this->sanitize_options( $options ); | |
| 138 | + | |
| 134 | 139 | return $options; |
| 135 | 140 | } |
| 136 | 141 | |
| 137 | 142 | function update_option( $option, $value ) { |
| @@ -174,12 +179,8 @@ | ||
| 174 | 179 | // Note: We don't disable MCP support here anymore |
| 175 | 180 | // It will be checked at runtime in the MCP class |
| 176 | 181 | } |
| 177 | 182 | |
| 178 | - if ( $options_modified ) { | |
| 179 | - update_option( $this->option_name, $options, false ); | |
| 180 | - } | |
| 181 | - | |
| 182 | 183 | return $options; |
| 183 | 184 | } |
| 184 | 185 | |
| 185 | 186 | private function updateAIEngineStatus( &$options ) { |
| @@ -279,10 +280,10 @@ | ||
| 279 | 280 | $value = array_map( 'trim', $value ); |
| 280 | 281 | } |
| 281 | 282 | |
| 282 | 283 | if ( $type === 'array' ) { |
| 283 | - $value = json_encode( $value ); | |
| 284 | - $value = str_replace( '\\', '', $value ); | |
| 284 | + // Convert to PHP array format instead of JSON | |
| 285 | + $value = var_export( $value, true ); | |
| 285 | 286 | } |
| 286 | 287 | |
| 287 | 288 | return [ $name, $value ]; |
| 288 | 289 | } |
| @@ -295,9 +296,9 @@ | ||
| 295 | 296 | $snippet = $this->get_snippet( $id ); |
| 296 | 297 | } |
| 297 | 298 | |
| 298 | 299 | // Remove any PHP opening tag. |
| 299 | - $snippet['code'] = preg_replace( '/<\?php/', '', $snippet['code'], 1 ); | |
| 300 | + $snippet['code'] = $this->snippet->sanitize_code( $snippet['code'] ); | |
| 300 | 301 | |
| 301 | 302 | if ( $test ) { |
| 302 | 303 | $snippet['code'] = preg_replace( '/echo\s+(.+?);/s', 'echo $1 . "\n";', $snippet['code'] ); |
| 303 | 304 | } |
| @@ -435,13 +436,14 @@ | ||
| 435 | 436 | if ( $index < count( $params['args'] ) - 1 ) { |
| 436 | 437 | $params['code'] .= ', '; |
| 437 | 438 | } |
| 438 | 439 | } |
| 440 | + | |
| 439 | 441 | $params['code'] .= ");\necho print_r(\$mwcode_result, true);"; |
| 440 | 442 | |
| 441 | 443 | $error = null; |
| 442 | 444 | $output = null; |
| 443 | - | |
| 445 | + | |
| 444 | 446 | try { |
| 445 | 447 | ob_start(); |
| 446 | 448 | eval( $params['code'] ); |
| 447 | 449 | $output = ob_get_clean(); |
| @@ -591,9 +593,9 @@ | ||
| 591 | 593 | $blocked = false; |
| 592 | 594 | //$blocked = true; |
| 593 | 595 | } |
| 594 | 596 | // Block REST requests that aren't whitelisted |
| 595 | - elseif ( MeowCommon_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) { | |
| 597 | + elseif ( MeowKit_MWCODE_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) { | |
| 596 | 598 | $blocked = true; |
| 597 | 599 | } |
| 598 | 600 | |
| 599 | 601 | if ( empty( $this->snippet ) ) { |
| @@ -624,9 +626,9 @@ | ||
| 624 | 626 | return; |
| 625 | 627 | } |
| 626 | 628 | |
| 627 | 629 | $snippets = array_map( function ( $snippet ) use ( $blocked ) { |
| 628 | - $snippet['code'] = preg_replace( '/<\?php/', '', $snippet['code'], 1 ); | |
| 630 | + $snippet['code'] = $this->snippet->sanitize_code( $snippet['code'] ); | |
| 629 | 631 | $snippet['blocked'] = $blocked; |
| 630 | 632 | |
| 631 | 633 | // If the snippet must be executed only in the frontend, we bypass the block |
| 632 | 634 | if ( !is_admin() && $snippet['scope'] === 'frontend' ) { |