Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- spl_autoload_register('adsw_autoload');
- if (!function_exists('pr')) {
- function pr($any)
- {
- print_r('<pre><code>');
- print_r($any);
- print_r('</code></pre>');
- }
- }
- adsw\module\Create::init();
- add_action('init', 'adsw_init_db');
- adsw\Api\REST::instance();
- add_action('init', 'adsw_pays_handler_notify', 1);
- add_action('init', 'adsw_pays_handler_cancel', 1);
- add_action('add_log', 'adsw_add_activities', 10, 6);
- add_action('adsw_output_admin_update_notification_html', 'adsw_output_admin_update_notification_html', 10, 2);
- add_action('adsw_output_admin_update_notification_plain', 'adsw_output_admin_update_notification_plain', 10, 2);
- add_action('admin_footer', 'adsw_do_show_notify');
- add_filter('mce_external_plugins', 'edit_imager_register_tinymce_javascript');
- function adsw_autoload($className)
- {
- $className = ltrim($className, '\\');
- $fileName = '';
- if ($lastNsPos = strrpos($className, '\\')) {
- $namespace = substr($className, 0, $lastNsPos);
- $className = substr($className, $lastNsPos + 1);
- $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
- }
- $fileName .= $className . '.php';
- $file = ADSW_PATH . 'includes/' . $fileName;
- if (file_exists($file)) {
- require $file;
- }
- }
- function adsw_init_db()
- {
- global $wpdb;
- $wpdb->adsw_ali_meta = $wpdb->prefix . 'adsw_ali_meta';
- $wpdb->adsw_activities = $wpdb->prefix . 'adsw_activities';
- $wpdb->adsw_search_analytics = $wpdb->prefix . 'adsw_search_analytics';
- }
- function adsw_prepare_attr($attr)
- {
- if (!$attr || count($attr) <= 0) {
- return false;
- }
- $foo = array();
- foreach ($attr as $item) {
- $foo[] = array('name' => sanitize_text_field($item->attr_name), 'value' => sanitize_text_field($item->attr_value));
- }
- return $foo;
- }
- function adsw_prepare_var_slug($str)
- {
- return substr(md5($str), 0, 22);
- }
- function adsw_get_HtmlElement($html, $startOfElement, $endOfElement)
- {
- $startingPosition = strpos($html, $startOfElement);
- $endPosition = strpos($html, $endOfElement, $startingPosition);
- $foundElement = substr($html, $startingPosition, $endPosition);
- return $foundElement;
- }
- function adsw_is_package($package)
- {
- return (in_array($package, array('piece', 'lot')) ? $package : 'lot');
- }
- function adsw_get_image_by_id($id, $size = 'thumbnail')
- {
- $img = wp_get_attachment_image_src($id, $size, false);
- if ($img) {
- return $img[0];
- }
- return false;
- }
- function adsw_list_categories()
- {
- return array(3 => __('Apparel & accessories', 'adsw'), 34 => __('Automobiles & motorcycles', 'adsw'), 66 => __('Beauty & Health', 'adsw'), 7 => __('Computer & Networking', 'adsw'), 44 => __('Consumer Electronics', 'adsw'), __('Electrical Equipment & Supplies', 'adsw'), 200214161 => __('Fine & Fashion Jewelry', 'adsw'), 2 => __('Food', 'adsw'), 1503 => __('Furniture', 'adsw'), 200003655 => __('Hair & Accessories', 'adsw'), 42 => __('Hardware', 'adsw'), 6 => __('Home Appliances', 'adsw'), 13 => __('Home Improvement', 'adsw'), 200003590 => __('Industry & Business', 'adsw'), 1509 => __('Jewelry & Accessories', 'adsw'), 39 => __('Lights & Lighting', 'adsw'), 1524 => __('Luggage & Bags', 'adsw'), 200060006 => __('Market', 'adsw'), 100003070 => __("Men's Clothing & Accessories", 'adsw'), 200214151 => __("Men's Fashion", 'adsw'), 1501 => __('Mother & Kids', 'adsw'), 200000875 => __('Novelty & Special Use', 'adsw'), 21 => __('Office & School Supplies', 'adsw'), 30 => __('Security & Protection', 'adsw'), 322 => __('Shoes', 'adsw'), 18 => __('Sports & Entertainment', 'adsw'), 1420 => __('Tools', 'adsw'), 26 => __('Toys & Hobbies', 'adsw'), 1511 => __('Watches', 'adsw'), 100003235 => __('Weddings & Events', 'adsw'), 100003109 => __("Women's Clothing & Accessories", 'adsw'), 200214142 => __("Women's Fashion", 'adsw'));
- }
- function adsw_search_category_by_id($id)
- {
- $foo = adsw_list_categories();
- return (isset($foo[$id]) ? $foo[$id] : $id);
- }
- function adsw_dropdown_categories($name = 'alicategories', $class = '', $selected = '')
- {
- $categories = adsw_list_categories();
- $output = sprintf('<select name="%1$s" id="%1$s" class="%2$s">', $name, $class);
- foreach ($categories as $key => $val) {
- $select = ($key == $selected ? 'selected="selected"' : '');
- $output .= sprintf('<option value="%s" %s>%s</option>', $key, $select, $val);
- }
- $output .= '</select>';
- return $output;
- }
- function adsw_get_post_excerpt($text)
- {
- $text = strip_shortcodes($text);
- $text = apply_filters('the_content', $text);
- $text = str_replace(']]>', ']]>', $text);
- $excerpt_length = apply_filters('excerpt_length', 55);
- $text = wp_trim_words($text, $excerpt_length, ' ...');
- return $text;
- }
- function adsw_list_lang()
- {
- return array('en' => 'English', 'ar' => 'العربية', 'de' => 'Deutsch', 'es' => 'Español', 'fr' => 'Français', 'id' => 'Indonesia', 'it' => 'Italiano', 'ja' => '日本語', 'ko' => '한국어', 'nl' => 'Nederlands', 'pl' => 'Polskie', 'pt' => 'Português do Brasil', 'ru' => 'Русский', 'th' => 'ไทย', 'tr' => 'Türkçe', 'vi' => 'Tiếng Việt', 'he' => 'עִבְרִית');
- }
- function adsw_post_status_colors($status = '', $name = '')
- {
- $foo = array('colors' => array('importlist' => '#5cb85c', 'draft' => '#2ea2cc', 'pending' => '#7ad03a', 'private' => '#ffba00', 'future' => '#aaaaaa', 'protected' => '#d54e21', 'sticky' => '#9859b9', 'page_on_front' => '#000000', 'page_for_posts' => '#000000', 'archive' => '#a67c52'), 'icons' => array('importlist' => 'dashicons-clipboard', 'draft' => 'dashicons-edit', 'pending' => 'dashicons-format-chat', 'private' => 'dashicons-lock', 'future' => 'dashicons-calendar-alt', 'protected' => 'dashicons-admin-network', 'sticky' => 'dashicons-star-filled', 'page_on_front' => 'dashicons-admin-home', 'page_for_posts' => 'dashicons-admin-post', 'archive' => 'dashicons-archive'));
- if (isset($foo['colors'][$status])) {
- $label = sprintf('<span style="background:%s" class="%s states"><span class="dashicons %s"></span> %s</span>', $foo['colors'][$status], $status, $foo['icons'][$status], $name);
- return $label;
- }
- return false;
- }
- function adsw_pays_handler_notify()
- {
- if (!isset($_GET['ads_pays_notify'])) {
- return false;
- }
- $key = 'key';
- $prefix = 'ads';
- $handlers_p = $_GET[$prefix . '_' . $key];
- $note = get_option($prefix . '-license');
- $uri = md5(get_bloginfo('url') . '/');
- $vendor = md5(md5($note . $uri) . $uri);
- if (isset($handlers_p) && md5($_GET['ads_pays_notify'] . $handlers_p) == $vendor) {
- update_option('_random_hash', $vendor, false);
- }
- exit();
- }
- function adsw_pays_handler_cancel()
- {
- if (!isset($_GET['ads_cancel_notify'])) {
- return false;
- }
- $key = 'key';
- $prefix = 'ads';
- $handlers_p = $_GET[$prefix . '_' . $key];
- $note = get_option($prefix . '-license');
- $noti = get_option('_random_hash');
- $uri = md5(get_bloginfo('url') . '/');
- $vendor = md5(md5($note . $uri) . $uri);
- if (isset($handlers_p) && (md5($_GET['ads_cancel_notify'] . $handlers_p) == $vendor || $noti == md5($_GET['ads_cancel_notify'] . $handlers_p))) {
- delete_option('_random_hash');
- }
- exit();
- }
- function adsw_list_tracking()
- {
- return array('17track' => array('title' => '17Track', 'url' => 'http://www.17track.net/?nums='), 'aftership' => array('title' => 'Aftership', 'url' => 'https://track.aftership.com/'), 'сainiao' => array('title' => 'Cainiao', 'url' => 'https://global.cainiao.com/detail.htm?mailNoList='));
- }
- function adsw_list_options_tracking()
- {
- $foo = array();
- foreach (adsw_list_tracking() as $key => $val) {
- $foo[$key] = $val['title'];
- }
- return $foo;
- }
- function adsw_get_tracking_url($key)
- {
- $args = adsw_list_tracking();
- if (!isset($args[$key])) {
- $key = '17track';
- }
- return $args[$key]['url'];
- }
- function adsw_listDisappearsProduct()
- {
- return array('doNothing' => __('Do nothing', 'adsw'), 'zero' => __('Set quantity to zero', 'adsw'), 'draft' => __('Send to Draft/Restore', 'adsw'));
- }
- function adsw_listDisappearsVariant()
- {
- return array('doNothing' => __('Do nothing', 'adsw'), 'zero' => __('Set quantity to zero', 'adsw'), 'disable' => __('Disable/Enable', 'adsw'));
- }
- function adsw_listCostChanges()
- {
- return array('doNothing' => __('Do nothing', 'adsw'), 'update' => __('Update Automatically', 'adsw'));
- }
- function adsw_listStockChanges()
- {
- return array('doNothing' => __('Do nothing', 'adsw'), 'update' => __('Update Automatically', 'adsw'));
- }
- function adsw_listIntervals()
- {
- return array('daily' => __('Once daily', 'adsw'), 'weekly' => __('Once weekly', 'adsw'), 'month' => __('Once monthly', 'adsw'));
- }
- function adsw_list_prod_type()
- {
- return array('' => __('All Categories', 'adsw'), 'categories' => __('Select categories', 'adsw'));
- }
- function adsw_listReviewMinRating()
- {
- return array(5 => __('Only 5 stars', 'adsw'), 4 => __('4 stars and higher', 'adsw'), 3 => __('3 stars and higher', 'adsw'), 2 => __('2 stars and higher', 'adsw'), 1 => __('1 star and higher', 'adsw'));
- }
- function adsw_listReviewCount()
- {
- return array(20 => __('up to 20', 'adsw'), 40 => __('up to 40', 'adsw'), 60 => __('up to 60', 'adsw'), 80 => __('up to 80', 'adsw'), 100 => __('up to 100', 'adsw'));
- }
- function adsw_add_activities($args, $anonce = '', $type = '', $status = 'info', $post_id = 0, $hash = null)
- {
- global $wpdb;
- if (is_array($args) || is_object($args)) {
- $args = serialize($args);
- }
- $wpdb->insert($wpdb->adsw_activities, array('post_id' => $post_id, 'product_data' => $args, 'type' => $type, 'date' => date('Y-m-d H:i:s'), 'status' => $status, 'anonce' => $anonce), array('%d', '%s', '%s', '%s', '%s', '%s'));
- }
- function adsw_output_admin_update_notification_html($products, $settings)
- {
- if (!$products) {
- $text = '<table>';
- $text .= '<thead>';
- $text .= '<tr><th>' . __('All products are up to date.', 'adsw') . '</th></tr>';
- $text .= '<thead>';
- $text .= '</table>';
- .............................................................................
- ...............................................
- ................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement