', $__desc , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; $desc = implode("\n", array_filter($__desc)); //var_dump('
', $desc , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; if ( 'both' == $retWhat ) { return array( 'short' => $excerpt, 'desc' => $desc, ); } if ( 'desc' == $retWhat ) { return $desc; } return $excerpt; } public function product_clean_desc( $post_content ) { $__post_content = $post_content; $__post_content = preg_replace('/\[gallery\]/imu', '', $__post_content); // [amz_corss_sell asin="B01G7TG6SW"] $__post_content = preg_replace('/\[amz_corss_sell asin\=".*"\]/imu', '', $__post_content); $__post_content = trim( $__post_content ); return $__post_content; } // Determine if SSL is used. public function is_ssl() { if ( isset($_SERVER['HTTPS']) ) { if ( 'on' == strtolower($_SERVER['HTTPS']) ) return true; if ( '1' == $_SERVER['HTTPS'] ) return true; } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { return true; } // HTTP_X_FORWARDED_PROTO: a de facto standard for identifying the originating protocol of an HTTP request, since a reverse proxy (load balancer) may communicate with a web server using HTTP even if the request to the reverse proxy is HTTPS if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) { if ( 'https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) ) return true; } if ( isset($_SERVER['HTTP_X_FORWARDED_SSL']) ) { if ( 'on' == strtolower($_SERVER['HTTP_X_FORWARDED_SSL']) ) return true; if ( '1' == $_SERVER['HTTP_X_FORWARDED_SSL'] ) return true; } return false; } /** * 2016-september - for amzstore plugin */ // in wp_options we have options like 'amzStore' but in version >= 9.0 I've changed plugin alias, so we have options like 'AmzStore" public function fix_dbalias_issue() { $ret = array('status' => 'invalid', 'msg' => 'unknown msg.', 'count' => array()); if ( 'AmzStore' != $this->alias ) return $ret; $found = get_option('AmzStore_fixed_dbalias', false); // already fixed if ( $found ) return $ret; global $wpdb; $db = $wpdb; $table = $db->prefix . 'options'; // old version settings // MySQL queries are not case-sensitive by default. // If you need to make a case-sensitive query, it is very easy to do using the BINARY operator, which forces a byte by byte comparison $sql = "select option_id, option_name, option_value from $table where 1=1 and option_name regexp binary '^amzStore_' order by option_name asc;"; //var_dump('
',$sql,''); $res = $db->get_results( $sql, OBJECT ); if ( empty($res) ) { update_option('AmzStore_fixed_dbalias', true); return array_merge($ret, array('status' => 'valid', 'msg' => 'error or none found: trying to retrieve old version settings.')); } // new version 9.0 settings $sql90 = "select option_name, option_value from $table where 1=1 and option_name regexp binary '^AmzStore_' order by option_name asc;"; $res90 = $db->get_results( $sql90, OBJECT_K ); if ( empty($res90) ) { //return array_merge($ret, array('status' => 'valid', 'msg' => 'error or none found: trying to retrieve new version 9.0 settings.')); } foreach ($res90 as $key => $val) { $res90["$key"] = $val->option_value; } $ccupd = 0; $ccdel = 0; $ccupd_old = 0; foreach ($res as $val) { $option_id = $val->option_id; $option_name = $val->option_name; $option_value = $val->option_value; // amzStore_ option names become __amzStore_ if ( 1 ) { $sqlupd_old = "update $table set option_name = concat('__', option_name) where 1=1 and option_name = binary %s;"; $sqlupd_old = $db->prepare( $sqlupd_old, $option_name ); $resupd_old = $db->query( $sqlupd_old ); if ( $resupd_old ) ++$ccupd_old; } $option_name_new = str_replace('amzStore', 'AmzStore', $option_name); $option_value = maybe_unserialize( $option_value ); $option_value = maybe_unserialize( $option_value ); // old version prior to 9.0 had a bug of double serialize for some options $option_value = maybe_serialize( $option_value ); // add new option based on old setting value if ( isset($res90["$option_name_new"]) ) { // already exists $sqlupd = "update $table set option_value = %s where 1=1 and option_name = binary %s;"; $sqlupd = $db->prepare( $sqlupd, $option_value, $option_name_new ); $resupd = $db->query( $sqlupd ); if ( $resupd ) ++$ccupd; } else { $sqlupd = "insert into $table (option_name, option_value) values (%s, %s);"; $sqlupd = $db->prepare( $sqlupd, $option_name_new, $option_value ); $resupd = $db->query( $sqlupd ); if ( $resupd ) ++$ccupd; } } // end foreach update_option('AmzStore_fixed_dbalias', true); return array_merge($ret, array('status' => 'valid', 'msg' => 'successfull: old version settings fixed.', 'count' => array( 'ccupd' => $ccupd, 'ccdel' => $ccdel, 'ccupd_old' => $ccupd_old, ))); //return $ret; } /** * 2016-october - for product country check */ // from ADF public function discount_convert_country2country() { $countries = array( 'com' => array('us', 'com', 'united-states', 'United States'), 'uk' => array('gb', 'co.uk', 'united-kingdom', 'United Kingdom'), 'de' => array('de', 'de', 'germany', 'Germany'), 'fr' => array('fr', 'fr', 'france', 'France'), 'jp' => array('jp', 'co.jp', 'japan', 'Japan'), 'ca' => array('ca', 'ca', 'canada', 'Canada'), 'cn' => array('cn', 'cn', 'china', 'China'), 'in' => array('in', 'in', 'india', 'India'), 'it' => array('it', 'it', 'italy', 'Italy'), 'es' => array('es', 'es', 'spain', 'Spain'), 'mx' => array('mx', 'com.mx', 'mexico', 'Mexico'), 'br' => array('br', 'com.br', 'brazil', 'Brazil'), 'au' => array('au', 'com.au', 'australia', 'Australia'), 'ae' => array('ae', 'ae', 'ae', 'UAE'), 'nl' => array('nl', 'nl', 'nl', 'Netherlands'), 'sg' => array('sg', 'sg', 'sg', 'Singapore'), 'sa' => array('sa', 'sa', 'sa', 'Saudi Arabia'), 'tr' => array('tr', 'com.tr', 'turkey', 'Turkey'), 'se' => array('se', 'se', 'se', 'Sweden'), 'pl' => array('pl', 'pl', 'pl', 'Poland'), 'eg' => array('eg', 'eg', 'egypt', 'Egypt'), ); $ret = array( 'fromip' => array(), 'amzwebsite' => array(), 'tovalues' => array(), 'totitles' => array() ); foreach ($countries as $k => $v) { $ret['fromip']["$k"] = $v[0]; $ret['amzwebsite']["$k"] = $v[1]; $ret['tovalues']["$k"] = $v[2]; $ret['totitles']["$k"] = $v[3]; } return $ret; } // build a return array of type amzForUser from a domain key public function domain2amzForUser( $domain ) { $convertCountry = $this->discount_convert_country2country(); $country_key = 'com'; if ( in_array($domain, $convertCountry['amzwebsite']) ) { $country_key = array_search($domain, $convertCountry['amzwebsite']); } $ipcountry = isset($convertCountry['fromip']["$country_key"]) ? $convertCountry['fromip']["$country_key"] : 'us'; $ipcountry = strtoupper($ipcountry); $country = $this->amzForUser( $ipcountry ); $country_name = isset($convertCountry['totitles']["$country_key"]) ? $convertCountry['totitles']["$country_key"] : 'United States'; $country = array_merge($country, array( 'name' => $country_name, )); return $country; } public function get_aff_ids() { $main_aff_id = $this->main_aff_id(); $config = $this->amz_settings; $aff_ids = array(); if ( isset($config['AffiliateID']) && !empty($config['AffiliateID']) && is_array($config['AffiliateID']) ) { foreach ( $config['AffiliateID'] as $key => $val ) { if ( !empty($val) ) { $_key = $this->get_amazon_country_site( $key ); $aff_ids[] = array( 'country' => $_key, 'aff_id' => $val, ); } } } return array( 'main_aff_id' => $main_aff_id, 'aff_ids' => $aff_ids, ); } public function get_country_from_url( $url, $provider='amazon' ) { $country = ''; if ( empty($url) ) return $country; if ( 'amazon' == $provider ) { $regex = "/https?:\/\/(?:.+\.)amazon\.([^\/]*)/imu"; } else if ( 'ebay' == $provider ) { //http://www.ebay.com/itm/Vintage-Stained-Rustic-Wood-Crates-/322042522061 $regex = "/https?:\/\/(?:www\.|)([^\/]*)/imu"; } $found = preg_match($regex, $url, $m); if ( false !== $found ) { $country = $m[1]; } return $country; } public function delete_post_attachments( $post_id ) { global $wpdb, $post_type; //check if is product $_post_type = get_post_type($post_id); //$post_type if ( ! in_array($_post_type, array('product', 'product_variation')) ) return; if ( ! is_int( $post_id ) || $post_id <= 0 ) return; //$ids = get_children(array( // 'post_parent' => $post_id, // 'post_type' => 'attachment' //)); //$ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_parent = $post_id AND post_type = 'attachment'"); //if (empty($ids)) return; //foreach ( $ids as $id ) { // wp_delete_attachment( $id, true ); //} if (1) { $args = array( 'post_type' => 'attachment', 'post_parent' => $post_id, 'post_status' => 'any', 'nopaging' => true, // Optimize query for performance. 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); wp_delete_attachment( $query->post->ID, true ); } } wp_reset_postdata(); } } /** * Plugin Version */ // latest code version public function version() { if ( defined('WOOZONE_VERSION') ) { $this->version = (string) WOOZONE_VERSION; return $this->version; } $path = $this->cfg['paths']['plugin_dir_path'] . 'plugin.php'; if ( function_exists('get_plugin_data') ) { $plugin_data = get_plugin_data( $path ); } else { $plugin_data = WooZone_get_plugin_data(); } $latest_version = '1.0'; if( isset($plugin_data) && is_array($plugin_data) && !empty($plugin_data) ){ if ( isset($plugin_data['Version']) ) { $latest_version = (string)$plugin_data['Version']; } else if ( isset($plugin_data['version']) ) { $latest_version = (string)$plugin_data['version']; } } $this->version = $latest_version; return $this->version; } private function check_if_table_exists( $force=false ) { $need_check_tables = $this->plugin_integrity_need_verification('check_tables'); if ( ! $need_check_tables['status'] && ! $force ) { return true; // don't need verification yet! } // default sql - tables & tables data! require_once( $this->cfg['paths']['plugin_dir_path'] . 'modules/setup_backup/default-sql.php' ); // retrieve all database tables & clean prefix $dbTables = $this->db->get_results( "show tables;", OBJECT_K ); $dbTables = array_keys( $dbTables ); if ( empty($dbTables) || ! is_array($dbTables) ) { $this->plugin_integrity_update_time('check_tables', array( 'status' => 'invalid', 'html' => __('Check plugin tables: error requesting tables list.', 'woozone'), )); return false; //something was wrong! } $dbTables_ = array(); foreach ((array) $dbTables as $table) { $table_noprefix = str_replace($this->db->prefix, '', $table); $dbTables_[] = $table_noprefix; } // our plugin tables $dbTables_own = $this->plugin_tables; // did we find all our plugin tables? $dbTables_found = (array) array_intersect($dbTables_, $dbTables_own); $dbTables_missing = array_diff($dbTables_own, $dbTables_found); //var_dump('
', $dbTables_own, ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; if ( ! $dbTables_missing ) { $this->plugin_integrity_update_time('check_tables', array( 'timeout' => time(), 'status' => 'valid', 'html' => __('Check plugin tables: all installed ( ' . implode(', ', $dbTables_found) . ' ).', 'woozone'), )); return true; // all is fine! } $this->plugin_integrity_update_time('check_tables', array( 'status' => 'invalid', 'html' => __('Check plugin tables: missing ( ' . implode(', ', $dbTables_missing) . ' ).', 'woozone'), )); return false; //something was wrong! } private function update_db_version( $version=null ) { delete_option( 'WooZone_db_version' ); $version = empty($version) ? $this->version() : $version; add_option( 'WooZone_db_version', $version ); } public function update_db( $force=false ) { $curForceTableExists = $force; $curForceOthers = $force; // current installed db version //$current_db_version = get_option( 'WooZone_db_version' ); //$current_db_version = !empty($current_db_version) ? (string)$current_db_version : '1.0'; // added new amazon location 'australia' $amazon_location_check = get_option('WooZone_amazon_location_check', array()); $amazon_location_check = ! is_array($amazon_location_check) ? array() : $amazon_location_check; if ( ! in_array('com.au', $amazon_location_check) || ! in_array('sa', $amazon_location_check) || ! in_array('com.tr', $amazon_location_check) || ! in_array('se', $amazon_location_check) || ! in_array('pl', $amazon_location_check) ) { $curForceTableExists = true; $amazon_location_check[] = 'com.au'; $amazon_location_check[] = 'sa'; $amazon_location_check[] = 'com.tr'; $amazon_location_check[] = 'se'; $amazon_location_check[] = 'pl'; $amazon_location_check = array_unique( array_filter($amazon_location_check) ); update_option('WooZone_amazon_location_check', $amazon_location_check); } // default db structure - integrity verification is done in function $this->check_if_table_exists( $curForceTableExists ); $this->check_table_generic( 'amz_locale_reference', $curForceOthers, array() ); // update 2018-feb $this->check_table_generic( 'amz_amzkeys', $curForceOthers, array() ); // update 2018-feb $this->check_table_generic( 'amz_amazon_cache', $curForceOthers, array( 'must_have_rows' => false ) ); // update 2018-apr $this->check_table_generic( 'amz_import_stats', $curForceOthers, array( 'must_have_rows' => false ) ); // update 2019-jan-17 $this->check_table_generic( 'amz_sync_widget', $curForceOthers, array( 'must_have_rows' => false ) ); // update 2019-apr-24 $this->check_table_generic( 'amz_sync_widget_asins', $curForceOthers, array( 'must_have_rows' => false ) ); // update 2019-apr-24 //$this->check_amazon_newlocations(); // added 2020-03-26 $need_check_cronjobs_prefix = $this->plugin_integrity_need_verification('check_cronjobs_prefix'); $need_check_alter_tables = $this->plugin_integrity_need_verification('check_alter_tables'); $need_check_alter_table_amz_queue = $this->plugin_integrity_need_verification('check_alter_table_amz_queue'); // added 2018-04-11 $need_check_alter_table_amz_oct18 = $this->plugin_integrity_need_verification('check_alter_table_amz_oct18'); // added 2018-10-12 //:: need_check_alter_tables //if ( version_compare( $current_db_version, '9.0', '<' ) ) { if ( $need_check_alter_tables['status'] || $curForceOthers ) { // installed version less than 9.0 / ex. 8.4.1.3 $table_name = $this->db->prefix . "amz_assets"; if ( $this->db->get_var("show tables like '$table_name'") == $table_name ) { $this->_update_db_tables(array( 'opt_name' => 'check_alter_tables', 'operation' => $table_name, 'table' => $table_name, 'queries' => array( 'image_sizes' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `image_sizes` TEXT NULL;", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'image_sizes';", 'field_name' => 'image_sizes', 'field_type' => 'text', ), 'download_status' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `download_status` VARCHAR(20) NULL DEFAULT 'new' COMMENT 'new, success, inprogress, error, remote';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'download_status';", 'field_name' => 'download_status', 'field_type' => 'varchar(20)', ), ), )); } // installed version less than 9.0.3.3 $table_name = $this->db->prefix . "amz_cross_sell"; if ( $this->db->get_var("show tables like '$table_name'") == $table_name ) { $this->_update_db_tables(array( 'opt_name' => 'check_alter_tables', 'operation' => $table_name, 'table' => $table_name, 'queries' => array( 'is_variable' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `is_variable` CHAR(1) NULL DEFAULT 'N';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'is_variable';", 'field_name' => 'is_variable', 'field_type' => 'char(1)', ), 'nb_tries' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `nb_tries` TINYINT(1) UNSIGNED NULL DEFAULT '0';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'nb_tries';", 'field_name' => 'nb_tries', 'field_type' => 'tinyint(1)', ), ), )); } // occures with some clients servers $table_name = $this->db->prefix . "amz_queue"; if ( $this->db->get_var("show tables like '$table_name'") == $table_name ) { $this->_update_db_tables(array( 'opt_name' => 'check_alter_tables', 'operation' => $table_name, 'table' => $table_name, 'queries' => array( 'nb_tries' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `nb_tries` SMALLINT(1) UNSIGNED NOT NULL;", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'nb_tries';", 'field_name' => 'nb_tries', 'field_type' => 'smallint(1)', ), 'nb_tries_prev' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `nb_tries_prev` SMALLINT(1) UNSIGNED NOT NULL;", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'nb_tries_prev';", 'field_name' => 'nb_tries_prev', 'field_type' => 'smallint(1)', ), 'from_op' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `from_op` VARCHAR(30) NOT NULL;", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'from_op';", 'field_name' => 'from_op', 'field_type' => 'varchar(30)', ), ), )); } } //:: added on 2018-04-11 // if check_alter_table_amz_queue if ( $need_check_alter_table_amz_queue['status'] || $curForceOthers ) { $table_name = $this->db->prefix . "amz_queue"; if ( $this->db->get_var("show tables like '$table_name'") == $table_name ) { $this->_update_db_tables(array( 'opt_name' => 'check_alter_table_amz_queue', 'operation' => $table_name, 'table' => $table_name, 'queries' => array( // columns 'product_title' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `product_title` TEXT NULL;", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'product_title';", 'field_name' => 'product_title', 'field_type' => 'text', ), 'country' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `country` VARCHAR(10) NOT NULL DEFAULT '';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'country';", 'field_name' => 'country', 'field_type' => 'varchar(10)', ), ), // !!!must be after queries to be sure that all columns exists! // index_name, index_type, index_cols: all are mandatory 'indexes' => array( 'country' => array( 'main' => "ALTER TABLE " . $table_name . " %s (`country`);", 'verify' => "SHOW INDEX FROM " . $table_name . " WHERE 1=1 and Key_name LIKE 'country';", 'index_name' => 'country', 'index_type' => 'key', 'index_cols' => array('country'), ), ), )); } } //:: added on 2018-10-12 // if check_alter_table_amz_oct18 if ( $need_check_alter_table_amz_oct18['status'] || $curForceOthers ) { // installed version less than 10.2 $table_name = $this->db->prefix . "amz_queue"; if ( $this->db->get_var("show tables like '$table_name'") == $table_name ) { $this->_update_db_tables(array( 'opt_name' => 'check_alter_table_amz_oct18', 'operation' => $table_name, 'table' => $table_name, 'queries' => array( 'country' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `country` VARCHAR(30) NOT NULL DEFAULT '';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'country';", 'field_name' => 'country', 'field_type' => 'varchar(30)', ), 'provider' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `provider` VARCHAR(20) NOT NULL DEFAULT 'amazon';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'provider';", 'field_name' => 'provider', 'field_type' => 'varchar(20)', ), ), // !!!must be after queries to be sure that all columns exists! // index_name, index_type, index_cols: all are mandatory 'indexes' => array( 'provider' => array( 'main' => "ALTER TABLE " . $table_name . " %s (`provider`);", 'verify' => "SHOW INDEX FROM " . $table_name . " WHERE 1=1 and Key_name LIKE 'provider';", 'index_name' => 'provider', 'index_type' => 'key', 'index_cols' => array('provider'), ), ), )); } // installed version less than 10.2 $table_name = $this->db->prefix . "amz_search"; if ( $this->db->get_var("show tables like '$table_name'") == $table_name ) { $this->_update_db_tables(array( 'opt_name' => 'check_alter_table_amz_oct18', 'operation' => $table_name, 'table' => $table_name, 'queries' => array( 'country' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `country` VARCHAR(30) NOT NULL DEFAULT '';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'country';", 'field_name' => 'country', 'field_type' => 'varchar(30)', ), ), )); } // installed version less than 10.2 $table_name = $this->db->prefix . "amz_amazon_cache"; if ( $this->db->get_var("show tables like '$table_name'") == $table_name ) { $this->_update_db_tables(array( 'opt_name' => 'check_alter_table_amz_oct18', 'operation' => $table_name, 'table' => $table_name, 'queries' => array( 'country' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `country` VARCHAR(30) NOT NULL DEFAULT '';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'country';", 'field_name' => 'country', 'field_type' => 'varchar(30)', ), 'provider' => array( 'main' => "ALTER TABLE " . $table_name . " %s COLUMN `provider` VARCHAR(20) NOT NULL DEFAULT 'amazon';", 'verify' => "SHOW COLUMNS FROM " . $table_name . " LIKE 'provider';", 'field_name' => 'provider', 'field_type' => 'varchar(20)', ), ), // !!!must be after queries to be sure that all columns exists! // index_name, index_type, index_cols: all are mandatory 'indexes' => array( 'provider' => array( 'main' => "ALTER TABLE " . $table_name . " %s (`provider`);", 'verify' => "SHOW INDEX FROM " . $table_name . " WHERE 1=1 and Key_name LIKE 'provider';", 'index_name' => 'provider', 'index_type' => 'key', 'index_cols' => array('provider'), ), ), )); } } //:: installed version less than 9.0 / ex. 8.4.1.3 // update cronjobs prefix in wp_options / option name like 'cron' if ( $need_check_cronjobs_prefix['status'] || $curForceOthers ) { $this->update_cronjobs(); $this->plugin_integrity_update_time('check_cronjobs_prefix', array( 'timeout' => time(), 'status' => 'valid', 'html' => __('Check cronjobs prefix: OK.', 'woozone'), )); } // installed version less than 9.0 / ex. 8.4.1.3 $this->update_db_version('9.0'); // update installed version to latest $this->update_db_version(); return true; } public function _update_db_tables( $pms=array() ) { //require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); //$status = dbDelta($sql); extract( $pms ); global $wpdb; // queries columns foreach ( (array) $queries as $skey => $sql ) { if ( ! isset($sql['main']) ) continue 1; $do_main = 'add'; if ( isset($sql['verify']) ) { $status = $wpdb->get_row( $sql['verify'], ARRAY_A ); if ( ! empty($status) && isset($status['Field'], $status['Type']) ) { //'image_sizes' == strtolower($status['Field']) if ( isset($sql['field_type']) ) { if ( strtolower($sql['field_type']) == strtolower( $status['Type'] ) ) $do_main = false; else $do_main = 'modify'; } } } // end if verify if ( !empty($do_main) ) { $sql['main'] = sprintf( $sql['main'], strtoupper( $do_main ) ); $status = $wpdb->query( $sql['main'] ); //var_dump('
', $sql, $status, ''); } } // end foreach // queries indexes //ADD KEY newkeyname | DROP KEY oldkeyname, ADD KEY newkeyname if ( isset($indexes) ) { foreach ( (array) $indexes as $skey => $sql ) { if ( ! isset($sql['main']) ) continue 1; $index_name = isset($sql['index_name']) ? $sql['index_name'] : $skey; $index_type = isset($sql['index_type']) ? $sql['index_type'] : 'key'; $index_cols = isset($sql['index_cols']) ? $sql['index_cols'] : array(); $do_main = 'add'; if ( isset($sql['verify']) ) { $status = $wpdb->get_results( $sql['verify'], ARRAY_A ); $cols = array(); if ( ! empty($status) ) { foreach ($status as $idxKey => $idxVal) { $cols[] = $idxVal['Column_name']; } $cols = array_unique( array_filter( $cols) ); $diff = array_diff($index_cols, $cols); if ( ! empty($diff) ) $do_main = 'modify'; else $do_main = false; } } // end if verify if ( !empty($do_main) ) { $do_main2 = array(); if ( 'modify' == $do_main ) { $do_main2[] = 'DROP ' . strtoupper($index_type) . ' ' . $index_name; } $do_main2[] = 'ADD ' . strtoupper($index_type) . ' ' . $index_name; $do_main = implode(', ', $do_main2); $sql['main'] = sprintf( $sql['main'], $do_main ); $status = $wpdb->query( $sql['main'] ); //var_dump('
', $sql, $status, ''); } } } // end foreach & if //if ( $this->db->prefix . "psp_link_redirect" == $operation ) { // echo __FILE__ . ":" . __LINE__;die . PHP_EOL; //} $this->plugin_integrity_update_time($opt_name, array( 'timeout' => time(), 'status' => 'valid', 'html' => sprintf( __('Check plugin tables (alter): %s OK.', 'woozone'), $opt_name ), )); } public function update_options_prefix( $what='use_old' ) { $ret = array('status' => 'invalid', 'msg' => 'unknown msg.'); $db = $this->db; $table = $db->prefix . 'options'; if ( 'use_new' == $what ) { return array_merge($ret, array('status' => 'valid', 'msg' => 'successfull: you choose to use the new version settings, disregarding the old version settings.')); } else if ( 'use_old' == $what ) { // old version settings $sql = "select option_id, option_name, option_value from $table where 1=1 and option_name regexp '^wwcAmzAff' order by option_name asc;"; $res = $db->get_results( $sql, OBJECT ); if ( empty($res) ) { return array_merge($ret, array('status' => 'valid', 'msg' => 'error or none found: trying to retrieve old version settings.')); } // new version 9.0 settings $sql90 = "select option_name, option_value from $table where 1=1 and option_name regexp '^WooZone' order by option_name asc;"; $res90 = $db->get_results( $sql90, OBJECT_K ); if ( empty($res90) ) { return array_merge($ret, array('status' => 'valid', 'msg' => 'error or none found: trying to retrieve new version 9.0 settings.')); } foreach ($res90 as $key => $val) { $res90["$key"] = $val->option_value; } $ccupd = 0; $ccdel = 0; foreach ($res as $val) { $option_id = $val->option_id; $option_name = $val->option_name; $option_value = $val->option_value; $option_name_new = str_replace('wwcAmzAff', $this->alias, $option_name); // delete current new version setting if exist //$sqldel = "delete from $table where 1=1 and option_name = %s;"; //$sqldel = $db->prepare( $sqldel, $option_name_new ); //$resdel = $db->query( $sqldel ); //if ( $resdel ) ++$ccdel; $option_value = maybe_unserialize( $option_value ); $option_value = maybe_unserialize( $option_value ); // old version prior to 9.0 had a bug of double serialize for some options $option_value = maybe_serialize( $option_value ); // add new option based on old setting value if ( isset($res90["$option_name_new"]) ) { // already exists $sqlupd = "update $table set option_value = %s where 1=1 and option_name = %s;"; $sqlupd = $db->prepare( $sqlupd, $option_value, $option_name_new ); $resupd = $db->query( $sqlupd ); if ( $resupd ) ++$ccupd; } else { $sqlupd = "insert into $table (option_name, option_value) values (%s, %s);"; $sqlupd = $db->prepare( $sqlupd, $option_name_new, $option_value ); $resupd = $db->query( $sqlupd ); if ( $resupd ) ++$ccupd; } // replace new version setting with old version setting // !!! THIS WOULD REPLACE OLD VERSION SETTINGS - MAYBE WE SHOULD KEEP OLD VERSION SETTINGS FOR NOW //$sqlupd = "update $table set option_name = %s where 1=1 and option_id = %s;"; //$sqlupd = $db->prepare( $sqlupd, $option_name_new, $option_id ); //$resupd = $db->query( $sqlupd ); //if ( $resupd ) ++$ccupd; } return array_merge($ret, array('status' => 'valid', 'msg' => 'successfull: you choose to use the old version settings, the new version settings were replaced.')); } return $ret; } public function update_cronjobs() { $ret = array('status' => 'invalid', 'msg' => 'unknown msg.'); $db = $this->db; $table = $db->prefix . 'options'; $sql = "SELECT option_id, option_name, option_value FROM $table WHERE 1=1 and option_name = 'cron';"; $res = $db->get_results( $sql, OBJECT ); if ( empty($res) ) { return array_merge($ret, array('status' => 'valid', 'msg' => 'not found')); } foreach ($res as $val) { $option_id = $val->option_id; $option_name = $val->option_name; $option_value = $val->option_value; $option_value = maybe_unserialize( $option_value ); if ( empty($option_value) || !is_array($option_value) ) continue 1; foreach ($option_value as $kk => $vv) { if ( !is_array($vv) ) continue 1; foreach ($vv as $kk2 => $vv2) { if ( preg_match('/^wwcAmzAff/iu', $kk2) ) { // wwcAmzAff | WooZone unset($option_value["$kk"]["$kk2"]); } } } foreach ($option_value as $kk => $vv) { if ( empty($vv) ) { unset($option_value["$kk"]); } } $option_value = serialize( $option_value ); $sqlupd = "update $table set option_value = %s where 1=1 and option_id = %s;"; $sqlupd = $db->prepare( $sqlupd, $option_value, $option_id ); $resupd = $db->query( $sqlupd ); } //$sql = "SELECT option_id, option_name, option_value FROM $table WHERE 1=1 and option_name = 'cron';"; //$res = $db->get_results( $sql, OBJECT ); //var_dump('
', $res, ''); die('debug...'); return array_merge($ret, array('status' => 'valid', 'msg' => 'ok')); } /** * Plugin is ACTIVE */ // verify plugin is ACTIVE (the right way) public function is_plugin_active( $plugin_name, $pms=array() ) { $pms = array_replace_recursive(array( 'verify_active_for_network_only' => false, 'verify_network_only_plugin' => false, 'plugin_file' => array(), // verification is made by OR between items 'plugin_class' => array(), // verification is made by OR between items ), $pms); extract( $pms ); switch ( strtolower($plugin_name) ) { case 'woocommerce': $plugin_file = array( 'woocommerce/woocommerce.php', 'envato-wordpress-toolkit/woocommerce.php' ); $plugin_class = array( 'WooCommerce' ); break; case 'woozone': $plugin_file = array( 'woozone/plugin.php' ); $plugin_class = array( 'WooZone' ); break; case 'psp': $plugin_file = array( 'premium-seo-pack/plugin.php' ); $plugin_class = array( 'psp' ); break; case 'w3totalcache': $plugin_file = array( 'w3-total-cache/w3-total-cache.php' ); break; // Additional Variation Images Plugin for WooCommerce case 'avi': $plugin_file = array( 'additional-variation-images/plugin.php' ); $plugin_class = array( 'AVI' ); break; // CompareAzon case 'compareazon': $plugin_file = array( 'compareazon/plugin.php' ); $plugin_class = array( 'CT' ); break; // WooZone Provider Ebay case 'aawzone-ebay': $plugin_file = array( 'aawzone-ebay/plugin.php' ); $plugin_class = array( 'WooZoneProviderEbay' ); break; default: break; } $is_active = array(); // verify plugin is active base on plugin main file if ( ! empty($plugin_file) ) { if ( ! is_array($plugin_file) ) $plugin_file = array( $plugin_file ); include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $cc = false; foreach ($plugin_file as $_plugin_file) { // check if a plugin is site wide or network active only if ( $verify_active_for_network_only ) { if ( is_plugin_active_for_network( $_plugin_file ) ) $cc = true; } // check if a plugin is a Network-Only-Plugin else if ( $verify_network_only_plugin ) { if ( is_network_only_plugin( $_plugin_file ) ) $cc = true; } // check if a plugin is active (the right way) else { if ( is_plugin_active( $_plugin_file ) ) $cc = true; } } $is_active[] = $cc; } // verify plugin class exists! if ( ! empty($plugin_class) ) { if ( ! is_array($plugin_class) ) $plugin_class = array( $plugin_class ); $cc = false; foreach ($plugin_class as $_plugin_class) { if ( class_exists( $_plugin_class ) ) $cc = true; } $is_active[] = $cc; } // final verification if ( empty($is_active) ) return false; foreach ($is_active as $_is_active) { if ( ! $_is_active ) return false; } return true; } public function is_plugin_active_for_network_only( $plugin_name, $pms=array() ) { $pms = array_replace_recursive(array( 'verify_active_for_network_only' => true, ), $pms); return $this->is_plugin_active( $plugin_name, $pms ); } public function is_plugin_network_only_plugin( $plugin_name, $pms=array() ) { $pms = array_replace_recursive(array( 'verify_network_only_plugin' => true, ), $pms); return $this->is_plugin_active( $plugin_name, $pms ); } public function is_woocommerce_installed() { $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); if ( in_array( 'envato-wordpress-toolkit/woocommerce.php', $active_plugins ) || in_array( 'woocommerce/woocommerce.php', $active_plugins ) || is_multisite() ) { return true; } else { if ( !empty($active_plugins) && is_array($active_plugins) ) { foreach ( $active_plugins as $key => $val ) { if ( ($status = preg_match('/^woocommerce[^\/]*\/woocommerce\.php$/imu', $val))!==false && $status > 0 ) { return true; } } } return false; } } public function is_plugin_avi_active() { return $this->is_plugin_active( 'AVI' ); } public function is_plugin_CT_active() { return $this->is_plugin_active( 'CT' ); } public function is_plugin_aawzoneebay_active() { return $this->is_plugin_active( 'aawzone-ebay' ); } /** * check plugin integrity: 2017-feb-28 */ // what: check_database public function plugin_integrity_check( $what='all', $force=false ) { $what = ! is_array($what) ? array('check_database') : $what; if ( in_array('check_database', $what) ) { $this->update_db( $force ); } } public function plugin_integrity_get_last_status( $what ) { $ret = array( 'status' => true, 'html' => '', ); // verify plugin integrity $plugin_integrity = get_option( 'WooZone_integrity_check', array() ); $plugin_integrity = is_array($plugin_integrity) ? $plugin_integrity : array(); $_status = true; $_html = array(); if ( isset($plugin_integrity[ "$what" ]) && ! empty($plugin_integrity[ "$what" ]) ) { $__ = $plugin_integrity[ "$what" ]; $_status = isset($__['status']) && 'valid' == $__['status'] ? true : false; $_html[] = $__['html']; } else { if ( 'check_database' == $what ) { foreach ($plugin_integrity as $key => $val) { if ( ! in_array($key, array( 'check_tables', 'check_alter_tables', 'check_cronjobs_prefix', 'check_table_amz_locale_reference', 'check_table_amz_amzkeys', 'check_table_amz_amazon_cache', 'check_table_amz_import_stats', 'check_table_amz_sync_widget', 'check_table_amz_sync_widget_asins', 'check_alter_table_amz_queue', 'check_alter_table_amz_oct18', )) ) { continue 1; } $_status = $_status && ( isset($val['status']) && 'valid' == $val['status'] ? true : false ); if ( ! empty($val['html']) ) { $_html[] = $val['html']; } } } } //$html = '
', $what, $plugin_integrity[ "$what" ] ,''); if ( ( $plugin_integrity[ "$what" ]['timeout'] + $this->ss['check_integrity'][ "$what" ] ) > time() ) { $ret = array_merge( $ret, array('status' => false) ); // don't need verification yet! //var_dump('
',$ret,''); return $ret; } } $ret = array_merge( $ret, array('status' => true) ); return $ret; } public function plugin_integrity_update_time( $what, $data=array() ) { $plugin_integrity = get_option( 'WooZone_integrity_check', array() ); $plugin_integrity = is_array($plugin_integrity) ? $plugin_integrity : array(); $data = ! is_array($data) ? array() : $data; if ( ! isset($plugin_integrity[ "$what" ]) ) { $plugin_integrity[ "$what" ] = array( 'timeout' => time(), 'status' => 'invalid', 'html' => '', ); } $plugin_integrity[ "$what" ] = array_replace_recursive($plugin_integrity[ "$what" ], $data); update_option( 'WooZone_integrity_check', $plugin_integrity ); } public function is_debug_mode_allowed() { $ip = Utils::getInstance()->get_client_ip(); $debug_ip = isset($this->amz_settings['debug_ip']) && ! empty($this->amz_settings['debug_ip']) ? trim($this->amz_settings['debug_ip']) : ''; if ( ! empty($debug_ip) ) { $debug_ip = explode(',', $debug_ip); $debug_ip = array_map("trim", $debug_ip); if ( in_array($ip, $debug_ip) ) { return true; } } return false; } public function translatable_strings() { if( isset($this->amz_settings) && count($this->amz_settings) > 0 ){ if( isset($this->amz_settings['string_trans']) && count($this->amz_settings['string_trans']) > 0 ){ $cc = 0; foreach ($this->expressions as $key => $value) { if( isset($this->amz_settings['string_trans'][$cc]) ){ $this->expressions[$key] = $this->amz_settings['string_trans'][$cc]; } $cc++; } } } } public function _translate_string( $string='' ) { if( count($this->expressions) > 0 ){ if( in_array( $string, array_keys($this->expressions)) ){ return $this->expressions[$string]; } } return $string; } // update 2017-nov public function get_all_country2mainaffid( $pms=array() ) { $pms = array_replace_recursive(array( 'country2mainaffid' => true, // true = country to mainaffid OR false = mainaffid to country 'com2us' => true, 'toupper' => true, 'uk2gb' => false, ), $pms); extract( $pms ); $arr = $country2mainaffid ? $this->country2mainaffid : array_flip( $this->country2mainaffid ); foreach ($arr as $key => $ret) { if ( $com2us && ('com' == $ret) ) { $ret = 'us'; } if ( $uk2gb && ( ('co.uk' == $ret) || ('uk' == $ret) ) ) { $ret = 'gb'; } if ( $toupper ) { $ret = strtoupper( $ret ); } $arr["$key"] = $ret; } return $arr; } public function get_country2mainaffid( $country, $pms=array() ) { $pms = array_replace_recursive(array( 'country2mainaffid' => true, // true = country to mainaffid OR false = mainaffid to country 'com2us' => true, 'toupper' => true, 'uk2gb' => false, ), $pms); extract( $pms ); $ret = ''; if ( ! isset($country) || empty($country) ) { return $ret; } $arr = $country2mainaffid ? $this->country2mainaffid : array_flip( $this->country2mainaffid ); if ( isset($arr["$country"]) ) { $ret = $arr["$country"]; } if ( $com2us && ('com' == $ret) ) { $ret = 'us'; } if ( $uk2gb && ( ('co.uk' == $ret) || ('uk' == $ret) ) ) { $ret = 'gb'; } if ( $toupper ) { $ret = strtoupper( $ret ); } return $ret; } // update 2017-nov public function get_mainaffid2country( $mainaffid, $pms=array() ) { $pms = array_replace_recursive(array( 'country2mainaffid' => false, // true = country to mainaffid OR false = mainaffid to country 'com2us' => false, 'toupper' => false, 'withPrefixPoint' => false, ), $pms); extract( $pms ); $ret = $this->get_country2mainaffid( $mainaffid, $pms ); if ( $withPrefixPoint && ! empty($ret) ) { $ret = '.' . $ret; } return $ret; } public function init_plugin_attributes() { // disable amazon checkout? $this->amzapi = isset($this->amz_settings['amzapi']) && in_array($this->amz_settings['amzapi'], array('oldapi', 'newapi')) ? (string) $this->amz_settings['amzapi'] : 'newapi'; // disable amazon checkout? $this->disable_amazon_checkout = isset($this->amz_settings['disable_amazon_checkout']) && 'yes' == $this->amz_settings['disable_amazon_checkout'] ? true : false; // product type $this->p_type = isset($this->amz_settings['onsite_cart']) && $this->amz_settings['onsite_cart'] == "no" ? 'external' : 'simple'; // make products without an offerlistingid as external $this->product_offerlistingid_missing_external = isset($this->amz_settings['product_offerlistingid_missing_external']) && ( $this->amz_settings['product_offerlistingid_missing_external'] == 'yes' ) ? true : false; // ( delete | put in trash ) products (or variations childs) when syncing them $this->product_offerlistingid_missing_delete = isset($this->amz_settings['product_offerlistingid_missing_delete']) && ( $this->amz_settings['product_offerlistingid_missing_delete'] == 'yes' ) ? true : false; // import amazon product missing offerlistingid $this->import_product_offerlistingid_missing = ! isset($this->amz_settings["import_product_offerlistingid_missing"]) || ( $this->amz_settings["import_product_offerlistingid_missing"] == 'yes' ) ? true : false; // import amazon product variation childs missing offerlistingid $this->import_product_variation_offerlistingid_missing = ! isset($this->amz_settings["import_product_variation_offerlistingid_missing"]) || ( $this->amz_settings["import_product_variation_offerlistingid_missing"] == 'yes' ) ? true : false; // product buy url is the original amazon url! $this->product_buy_is_amazon_url = !isset($this->amz_settings['product_buy_is_amazon_url']) || ( isset($this->amz_settings['product_buy_is_amazon_url']) && $this->amz_settings['product_buy_is_amazon_url'] == 'yes' ) ? true : false; // get & show product short url (from bitly api) $this->product_url_short = isset($this->amz_settings['product_url_short']) && $this->amz_settings['product_url_short'] == 'yes' ? true : false; if ( ! in_array( 'product_url_short', $this->frontend_show_what() ) ) { $this->product_url_short = false; } // remote amazon images $is_ari = !isset($this->amz_settings['remote_amazon_images']) || 'yes' == $this->amz_settings['remote_amazon_images'] ? true : false; //$is_ari = $is_ari && 'gimi' == $this->dev ? $is_ari : false; //IN DEVELOPMENT! //$is_ari = false; //DE-ACTIVATE! $this->is_remote_images = $is_ari; // product: delete | move to trash - ( when syncing or | delete zero priced bug fix) $this->products_force_delete = isset($this->amz_settings['products_force_delete']) && $this->amz_settings['products_force_delete'] == 'yes' ? true : false; // activate debugbar $this->debug_bar_activate = isset($this->amz_settings['debug_bar_activate']) && $this->amz_settings['debug_bar_activate'] == 'no' ? false : true; // gdpr - 25 may 2018 $this->gdpr_rules_is_activated = isset($this->amz_settings['gdpr_rules_is_activated']) ? (string) $this->amz_settings['gdpr_rules_is_activated'] : 'no'; $this->frontend_hide_onsale_default_badge = isset($this->amz_settings['frontend_hide_onsale_default_badge']) ? (string) $this->amz_settings['frontend_hide_onsale_default_badge'] : 'no'; $this->frontend_show_free_shipping = isset($this->amz_settings['frontend_show_free_shipping']) ? (string) $this->amz_settings['frontend_show_free_shipping'] : 'yes'; $this->frontend_show_coupon_text = isset($this->amz_settings['frontend_show_coupon_text']) ? (string) $this->amz_settings['frontend_show_coupon_text'] : 'yes'; $this->show_availability_icon = isset($this->amz_settings['show_availability_icon']) ? (string) $this->amz_settings['show_availability_icon'] : 'yes'; $opt_badges_activated = array( 'new' => 'New', 'onsale' => 'On Sale', 'freeshipping' => 'Free Shipping', 'amazonprime' => 'Amazon Prime', ); $this->badges_activated = isset($this->amz_settings['badges_activated']) ? (array) $this->amz_settings['badges_activated'] : array_keys( $opt_badges_activated ); $this->badges_activated = $this->clean_multiselect( $this->badges_activated ); $opt_badges_where = array( 'product_page' => 'product page', 'sidebar' => 'sidebar', 'minicart' => 'minicart', 'box_related_products' => 'box related products', 'box_cross_sell' => 'box cross sell', ); $this->badges_where = isset($this->amz_settings['badges_where']) ? (array) $this->amz_settings['badges_where'] : array_keys( $opt_badges_where ); $this->badges_where = $this->clean_multiselect( $this->badges_where ); $this->dropshiptax = array( 'activate' => isset($this->amz_settings['dropshiptax_activate']) ? $this->amz_settings['dropshiptax_activate'] : 'no', 'type' => isset($this->amz_settings['dropshiptax_type']) ? $this->amz_settings['dropshiptax_type'] : 'proc', 'value' => isset($this->amz_settings['dropshiptax_value']) ? (float) $this->amz_settings['dropshiptax_value'] : 0, ); $this->roundedprices = array( 'activate' => isset($this->amz_settings['roundedprices_activate']) ? $this->amz_settings['roundedprices_activate'] : 'no', 'direction' => isset($this->amz_settings['roundedprices_direction']) ? $this->amz_settings['roundedprices_direction'] : 'always_up', 'decimals' => isset($this->amz_settings['roundedprices_decimals']) ? (int) $this->amz_settings['roundedprices_decimals'] : 0, 'marketing' => isset($this->amz_settings['roundedprices_marketing']) ? $this->amz_settings['roundedprices_marketing'] : 'no', ); } public function get_amazon_variations_nb( $prodvar=array(), $provider='amazon' ) { if ( empty($prodvar) || ! is_array($prodvar) ) { return 0; } if ( 'amazon' == $provider ) { if ( isset($prodvar['ASIN']) ) { return 1; } else { return count( $prodvar ); } } else if ( 'ebay' == $provider ) { if ( $this->ebayHelper->ebay_variation_is_valid($prodvar) ) { //if ( isset($prodvar['VariationSpecifics']) || isset($prodvar['StartPrice']) || isset($prodvar['SKU']) ) { return 1; } else { return count( $prodvar ); } } return 0; } // $retProd must be formated through method 'build_product_data' from amz.helper.class.php public function get_product_type_by_apiresponse( $retProd=array(), $provider='amazon' ) { $ret = array( 'is_variable' => false, 'is_variation_child' => false, 'nb_variations' => 0, 'product_type' => 'simple', ); if ( 'amazon' === $provider ) { $is_variable = isset($retProd['Variations'], $retProd['Variations']['Item']); $is_variation_child = ('' != $retProd['ParentASIN']) && ($retProd['ASIN'] != $retProd['ParentASIN']) ? true : false; $nb_variations = $is_variable ? $this->get_amazon_variations_nb( $retProd['Variations']['Item'] ) : 0; $nb_variations = $nb_variations && isset($retProd['Variations']['TotalVariations']) ? (int) $retProd['Variations']['TotalVariations'] : $nb_variations; } else if ( 'ebay' === $provider ) { $is_variable = isset($retProd['Variations'], $retProd['Variations']['Variation']); $is_variation_child = preg_match('/(?:.+)\/var-(?:.+)/imu', $retProd['ASIN'], $m); $nb_variations = $is_variable ? $this->get_amazon_variations_nb( $retProd['Variations']['Variation'], 'ebay' ) : 0; } $product_type = $is_variable ? 'variable' : 'simple'; if ( $is_variation_child ) { $product_type = 'variation'; } $ret = array_replace_recursive( $ret, array( 'is_variable' => $is_variable, 'is_variation_child' => $is_variation_child, 'nb_variations' => $nb_variations, 'product_type' => $product_type, )); return $ret; } // sync variations childs only if it's a variable product & must have maximum X (default = 10) total variations public function can_sync_variations( $retProd, $provider='amazon' ) { $opProductType = $this->get_product_type_by_apiresponse( $retProd, $provider ); extract( $opProductType ); //is_variable, is_variation_child, nb_variations, product_type if ( ! $is_variable ) { //if ( 'variable' != $product_type ) { return false; } if ( ! $nb_variations || $nb_variations > 10 ) { return false; } return true; } /** * BITLY related - 2018-jan */ public function bitly_api_shorten( $pms=array() ) { $pms = array_replace_recursive(array( 'longUrl' => '', 'domain' => '', ), $pms); extract( $pms ); $ret = array( 'status' => 'invalid', 'msg' => '', 'short_url' => '', ); if ( '' == $longUrl ) { $ret = array_replace_recursive($ret, array( 'msg' => 'longUrl is empty!', )); return $ret; } $access_token = get_option( 'WooZone_bitly_access_token', '' ); if ( '' == $access_token ) { $ret = array_replace_recursive($ret, array( 'msg' => 'bitly access token wasn\'t found!', )); return $ret; } //:: make request to api $longUrl = $this->is_ssl() == true ? 'https:' . $longUrl : 'http:' . $longUrl; $uri = $this->bitly_oauth_api . "v3/shorten?access_token=" . $access_token . "&format=json&longUrl=" . urlencode($longUrl); if ( $domain != '' ) { $uri .= "&domain=" . $domain; } $input_params = array( 'header' => true, 'followlocation' => true, ); $output_params = array( 'parse_headers' => true, 'resp_is_json' => true, 'resp_add_http_code' => true, ); $output = $this->curl( $uri, $input_params, $output_params, true ); //var_dump('
', $output , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; //:: end make request to api if ( $output['status'] === 'invalid' ) { $msg = sprintf( __('curl error; http code: %s; details: %s', 'woozone'), $output['http_code'], $output['data'] ); //var_dump('
', $msg , ''); echo __FILE__ . ":" . __LINE__; die . PHP_EOL; $ret = array_replace_recursive($ret, array( 'msg' => $msg, )); return $ret; } $output = $output['data']; //var_dump('
', $output , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; $output = json_decode( $output, true ); if ( ! is_array($output) || ! isset($output['data'], $output['data']['url']) ) { $msg = 'bitly error; short url was not found in api response!'; if ( is_array($output) && isset($output['status_code']) ) { $msg = sprintf( __('bitly error; status_code: %s; status_txt: %s', 'woozone'), $output['status_code'], $output['status_txt'] ); } $ret = array_replace_recursive($ret, array( 'msg' => $msg, )); return $ret; } if (1) { $result = array(); $result['url'] = $output['data']['url']; //$result['hash'] = $output['data']['hash']; //$result['global_hash'] = $output['data']['global_hash']; //$result['long_url'] = $output['data']['long_url']; //$result['new_hash'] = $output['data']['new_hash']; //$ret['short_url'] = $result['url']; $ret = array_replace_recursive($ret, array( 'status' => 'valid', 'msg' => 'bitly short url was generated successfully.', 'short_url' => $result['url'], )); //var_dump('
', $ret , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; return $ret; } } public function product_url_hash( $data ) { return hash_hmac( 'sha256', $data, 'woozone' ); } public function product_url_from_bitlymeta( $pms=array() ) { $pms = array_replace_recursive(array( 'ret_what' => 'only_get_meta', // only_get_meta | do_request | force_do_request 'product' => null, 'orig_url' => '', 'country' => '', ), $pms); extract( $pms ); //var_dump('
', $ret_what, $orig_url, $country, $product , ''); //echo __FILE__ . ":" . __LINE__;die . PHP_EOL; $ret = array( 'status' => 'invalid', 'msg' => '', 'orig_url' => $orig_url, 'short_url' => $orig_url, ); //:: get product id $product_id = $product; if ( is_object($product) ) { $prod_id = 0; if ( method_exists( $product, 'get_id' ) ) { $prod_id = (int) $product->get_id(); } else if ( isset($product->id) && (int) $product->id > 0 ) { $prod_id = (int) $product->id; } $product_id = $prod_id; } if ( empty($product_id) ) { $ret = array_replace_recursive($ret, array( 'msg' => 'invalid input parameter product!', )); return $ret; } //:: get product current url or amazon link (if not provided as input parameter) if ( '' == $orig_url ) { $prod_link = $this->_product_buy_url_asin( array( 'product_id' => $product_id, )); $orig_url = $prod_link['link']; //$country = $prod_link['country']; } if ( '' == $orig_url ) { $ret = array_replace_recursive($ret, array( 'msg' => 'product url is empty!', )); return $ret; } //:: get amazon store country from product url (if not provided as input parameter) if ( '' == $country ) { $mstat = preg_match('~^//www\.amazon\.([a-z\.]{2,6})/gp/product/~imu', $orig_url, $mfound); //var_dump('
jimmy', $orig_url, $mstat, $mfound , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; if ( $mstat ) { $country = $mfound[1]; } } if ( '' == $country ) { $ret = array_replace_recursive($ret, array( 'msg' => 'country is empty!', )); return $ret; } //var_dump('
', $ret_what, $orig_url, $country, $product_id , ''); //echo __FILE__ . ":" . __LINE__;die . PHP_EOL; //:: product current url $orig_hash = $this->product_url_hash( $orig_url ); $meta = get_post_meta( $product_id, '_amzaff_bitly', true ); $meta2 = is_array($meta) && isset($meta["$country"]) ? $meta["$country"] : false; $meta_short_url = is_array($meta2) && ! empty($meta2['short_url']) ? (string) $meta2['short_url'] : ''; //:: short url is Found! if ( '' != $meta_short_url ) { $meta_orig_hash = is_array($meta2) && ! empty($meta2['orig_hash']) ? (string) $meta2['orig_hash'] : ''; // short url exists & is based on the same original url as the one product currently has! if ( $orig_hash === $meta_orig_hash ) { $ret = array_replace_recursive($ret, array( 'status' => 'valid', 'msg' => 'success.', 'short_url' => $meta_short_url, )); if ( 'only_get_meta' == $ret_what ) { return $ret; } } else { $ret = array_replace_recursive($ret, array( 'msg' => 'current product url hash is different than meta original url hash!', )); if ( 'only_get_meta' == $ret_what ) { return $ret; } } } //:: short url NOT Found! else { $ret = array_replace_recursive($ret, array( 'msg' => 'no meta short url was found!', )); if ( 'only_get_meta' == $ret_what ) { return $ret; } } //:: try to do a request to bitly api if ( ( 'force_do_request' == $ret_what ) || ( ( 'do_request' == $ret_what ) && ( 'invalid' == $ret['status'] ) ) ) { $ret['status'] = 'invalid'; // reset status to be sure we retrieve the right status for bitly request $bitly_stat = $this->bitly_api_shorten(array( 'longUrl' => $orig_url, )); //var_dump('
', $bitly_stat , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; if ( 'invalid' == $bitly_stat['status'] ) { $msg = $ret['msg'] . ' ' . $bitly_stat['msg']; $meta = is_array($meta) ? $meta : array(); $meta["$country"] = array( 'short_url' => '', 'orig_hash' => $orig_hash, 'req_msg' => $msg, ); update_post_meta( $product_id, '_amzaff_bitly', $meta ); $ret = array_replace_recursive($ret, array( 'msg' => $msg, )); return $ret; } $bitly_url = $bitly_stat['short_url']; $meta = is_array($meta) ? $meta : array(); $meta["$country"] = array( 'short_url' => $bitly_url, 'orig_hash' => $orig_hash, ); update_post_meta( $product_id, '_amzaff_bitly', $meta ); $msg = $ret['msg'] . ' ' . 'success.'; $ret = array_replace_recursive($ret, array( 'status' => 'valid', 'msg' => $msg, 'short_url' => $bitly_url, )); } return $ret; } // update 2018-feb private function check_table_generic( $table, $force=false, $pms=array() ) { $pms = array_replace_recursive( array( 'must_have_rows' => true, ), $pms); extract( $pms ); $table_ = $this->db->prefix . $table; $need_check_tables = $this->plugin_integrity_need_verification('check_table_'.$table); if ( ! $need_check_tables['status'] && ! $force ) { return true; // don't need verification yet! } // default sql - tables & tables data! require_once( $this->cfg['paths']['plugin_dir_path'] . 'modules/setup_backup/default-sql.php' ); // retrieve all database tables & clean prefix $dbTables = $this->db->get_results( "show tables;", OBJECT_K ); $dbTables = array_keys( $dbTables ); if ( empty($dbTables) || ! is_array($dbTables) ) { $this->plugin_integrity_update_time('check_table_'.$table, array( 'status' => 'invalid', 'html' => sprintf( __('Check plugin table %s: error requesting tables list.', 'woozone'), $table_ ), )); return false; //something was wrong! } // table exists? if ( ! in_array( $table_, $dbTables) ) { $this->plugin_integrity_update_time('check_table_'.$table, array( 'status' => 'invalid', 'html' => sprintf( __('Check plugin table %s: missing.', 'woozone'), $table_ ), )); return false; //something was wrong! } // table has rows? if ( $must_have_rows ) { $query = "select count(a.ID) as nb from $table_ as a where 1=1;"; $res = $this->db->get_var( $query ); //var_dump('
', $res , ''); echo __FILE__ . ":" . __LINE__;die . PHP_EOL; if ( ($res === false) || ! $res ) { $this->plugin_integrity_update_time('check_table_'.$table, array( 'status' => 'invalid', 'html' => sprintf( __('Check plugin table %s: is empty - no rows found.', 'woozone'), $table_ ), )); return false; //something was wrong! } } // all fine $this->plugin_integrity_update_time('check_table_'.$table, array( 'timeout' => time(), 'status' => 'valid', 'html' => sprintf( __('Check plugin table %s: installed ok.', 'woozone'), $table_ ), )); return true; // all is fine! } public function build_score_html_container( $score=0, $pms=array() ) { $pms = array_replace_recursive(array( 'show_score' => true, 'css_style' => '', ), $pms); extract( $pms ); $_css_style = ( '' != $css_style ? ' ' . $css_style : '' ); $size_class = 'size_'; if ( $score >= 20 && $score < 40 ) { $size_class .= '20_40'; } else if ( $score >= 40 && $score < 60 ) { $size_class .= '40_60'; } else if ( $score >= 60 && $score < 80 ) { $size_class .= '60_80'; } else if ( $score >= 80 && $score <= 100 ) { $size_class .= '80_100'; } else { $size_class .= '0_20'; } $html = array(); $html[] = '