Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.97 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. spl_autoload_register('adsw_autoload');
  5.  
  6. if (!function_exists('pr')) {
  7. function pr($any)
  8. {
  9. print_r('<pre><code>');
  10. print_r($any);
  11. print_r('</code></pre>');
  12. }
  13. }
  14.  
  15. adsw\module\Create::init();
  16. add_action('init', 'adsw_init_db');
  17. adsw\Api\REST::instance();
  18. add_action('init', 'adsw_pays_handler_notify', 1);
  19. add_action('init', 'adsw_pays_handler_cancel', 1);
  20. add_action('add_log', 'adsw_add_activities', 10, 6);
  21. add_action('adsw_output_admin_update_notification_html', 'adsw_output_admin_update_notification_html', 10, 2);
  22. add_action('adsw_output_admin_update_notification_plain', 'adsw_output_admin_update_notification_plain', 10, 2);
  23. add_action('admin_footer', 'adsw_do_show_notify');
  24. add_filter('mce_external_plugins', 'edit_imager_register_tinymce_javascript');
  25. function adsw_autoload($className)
  26. {
  27. $className = ltrim($className, '\\');
  28. $fileName = '';
  29.  
  30. if ($lastNsPos = strrpos($className, '\\')) {
  31. $namespace = substr($className, 0, $lastNsPos);
  32. $className = substr($className, $lastNsPos + 1);
  33. $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
  34. }
  35.  
  36. $fileName .= $className . '.php';
  37. $file = ADSW_PATH . 'includes/' . $fileName;
  38.  
  39. if (file_exists($file)) {
  40. require $file;
  41. }
  42. }
  43.  
  44. function adsw_init_db()
  45. {
  46. global $wpdb;
  47. $wpdb->adsw_ali_meta = $wpdb->prefix . 'adsw_ali_meta';
  48. $wpdb->adsw_activities = $wpdb->prefix . 'adsw_activities';
  49. $wpdb->adsw_search_analytics = $wpdb->prefix . 'adsw_search_analytics';
  50. }
  51.  
  52. function adsw_prepare_attr($attr)
  53. {
  54. if (!$attr || count($attr) <= 0) {
  55. return false;
  56. }
  57.  
  58. $foo = array();
  59.  
  60. foreach ($attr as $item) {
  61. $foo[] = array('name' => sanitize_text_field($item->attr_name), 'value' => sanitize_text_field($item->attr_value));
  62. }
  63.  
  64. return $foo;
  65. }
  66.  
  67. function adsw_prepare_var_slug($str)
  68. {
  69. return substr(md5($str), 0, 22);
  70. }
  71.  
  72. function adsw_get_HtmlElement($html, $startOfElement, $endOfElement)
  73. {
  74. $startingPosition = strpos($html, $startOfElement);
  75. $endPosition = strpos($html, $endOfElement, $startingPosition);
  76. $foundElement = substr($html, $startingPosition, $endPosition);
  77.  
  78. return $foundElement;
  79. }
  80.  
  81. function adsw_is_package($package)
  82. {
  83. return (in_array($package, array('piece', 'lot')) ? $package : 'lot');
  84. }
  85.  
  86. function adsw_get_image_by_id($id, $size = 'thumbnail')
  87. {
  88. $img = wp_get_attachment_image_src($id, $size, false);
  89.  
  90. if ($img) {
  91. return $img[0];
  92. }
  93.  
  94. return false;
  95. }
  96.  
  97. function adsw_list_categories()
  98. {
  99. 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'));
  100. }
  101.  
  102. function adsw_search_category_by_id($id)
  103. {
  104. $foo = adsw_list_categories();
  105.  
  106. return (isset($foo[$id]) ? $foo[$id] : $id);
  107. }
  108.  
  109. function adsw_dropdown_categories($name = 'alicategories', $class = '', $selected = '')
  110. {
  111. $categories = adsw_list_categories();
  112. $output = sprintf('<select name="%1$s" id="%1$s" class="%2$s">', $name, $class);
  113.  
  114. foreach ($categories as $key => $val) {
  115. $select = ($key == $selected ? 'selected="selected"' : '');
  116. $output .= sprintf('<option value="%s" %s>%s</option>', $key, $select, $val);
  117. }
  118. $output .= '</select>';
  119.  
  120. return $output;
  121. }
  122.  
  123. function adsw_get_post_excerpt($text)
  124. {
  125. $text = strip_shortcodes($text);
  126. $text = apply_filters('the_content', $text);
  127. $text = str_replace(']]>', ']]>', $text);
  128. $excerpt_length = apply_filters('excerpt_length', 55);
  129. $text = wp_trim_words($text, $excerpt_length, ' ...');
  130.  
  131. return $text;
  132. }
  133.  
  134. function adsw_list_lang()
  135. {
  136. 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' => 'עִבְרִית');
  137. }
  138.  
  139. function adsw_post_status_colors($status = '', $name = '')
  140. {
  141. $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'));
  142.  
  143. if (isset($foo['colors'][$status])) {
  144. $label = sprintf('<span style="background:%s" class="%s states"><span class="dashicons %s"></span> %s</span>', $foo['colors'][$status], $status, $foo['icons'][$status], $name);
  145.  
  146. return $label;
  147. }
  148.  
  149. return false;
  150. }
  151.  
  152. function adsw_pays_handler_notify()
  153. {
  154. if (!isset($_GET['ads_pays_notify'])) {
  155. return false;
  156. }
  157.  
  158. $key = 'key';
  159. $prefix = 'ads';
  160. $handlers_p = $_GET[$prefix . '_' . $key];
  161. $note = get_option($prefix . '-license');
  162. $uri = md5(get_bloginfo('url') . '/');
  163. $vendor = md5(md5($note . $uri) . $uri);
  164.  
  165. if (isset($handlers_p) && md5($_GET['ads_pays_notify'] . $handlers_p) == $vendor) {
  166. update_option('_random_hash', $vendor, false);
  167. }
  168.  
  169. exit();
  170. }
  171.  
  172. function adsw_pays_handler_cancel()
  173. {
  174. if (!isset($_GET['ads_cancel_notify'])) {
  175. return false;
  176. }
  177.  
  178. $key = 'key';
  179. $prefix = 'ads';
  180. $handlers_p = $_GET[$prefix . '_' . $key];
  181. $note = get_option($prefix . '-license');
  182. $noti = get_option('_random_hash');
  183. $uri = md5(get_bloginfo('url') . '/');
  184. $vendor = md5(md5($note . $uri) . $uri);
  185.  
  186. if (isset($handlers_p) && (md5($_GET['ads_cancel_notify'] . $handlers_p) == $vendor || $noti == md5($_GET['ads_cancel_notify'] . $handlers_p))) {
  187. delete_option('_random_hash');
  188. }
  189.  
  190. exit();
  191. }
  192.  
  193. function adsw_list_tracking()
  194. {
  195. 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='));
  196. }
  197.  
  198. function adsw_list_options_tracking()
  199. {
  200. $foo = array();
  201.  
  202. foreach (adsw_list_tracking() as $key => $val) {
  203. $foo[$key] = $val['title'];
  204. }
  205.  
  206. return $foo;
  207. }
  208.  
  209. function adsw_get_tracking_url($key)
  210. {
  211. $args = adsw_list_tracking();
  212.  
  213. if (!isset($args[$key])) {
  214. $key = '17track';
  215. }
  216.  
  217. return $args[$key]['url'];
  218. }
  219.  
  220. function adsw_listDisappearsProduct()
  221. {
  222. return array('doNothing' => __('Do nothing', 'adsw'), 'zero' => __('Set quantity to zero', 'adsw'), 'draft' => __('Send to Draft/Restore', 'adsw'));
  223. }
  224.  
  225. function adsw_listDisappearsVariant()
  226. {
  227. return array('doNothing' => __('Do nothing', 'adsw'), 'zero' => __('Set quantity to zero', 'adsw'), 'disable' => __('Disable/Enable', 'adsw'));
  228. }
  229.  
  230. function adsw_listCostChanges()
  231. {
  232. return array('doNothing' => __('Do nothing', 'adsw'), 'update' => __('Update Automatically', 'adsw'));
  233. }
  234.  
  235. function adsw_listStockChanges()
  236. {
  237. return array('doNothing' => __('Do nothing', 'adsw'), 'update' => __('Update Automatically', 'adsw'));
  238. }
  239.  
  240. function adsw_listIntervals()
  241. {
  242. return array('daily' => __('Once daily', 'adsw'), 'weekly' => __('Once weekly', 'adsw'), 'month' => __('Once monthly', 'adsw'));
  243. }
  244.  
  245. function adsw_list_prod_type()
  246. {
  247. return array('' => __('All Categories', 'adsw'), 'categories' => __('Select categories', 'adsw'));
  248. }
  249.  
  250. function adsw_listReviewMinRating()
  251. {
  252. 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'));
  253. }
  254.  
  255. function adsw_listReviewCount()
  256. {
  257. 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'));
  258. }
  259.  
  260. function adsw_add_activities($args, $anonce = '', $type = '', $status = 'info', $post_id = 0, $hash = null)
  261. {
  262. global $wpdb;
  263.  
  264. if (is_array($args) || is_object($args)) {
  265. $args = serialize($args);
  266. }
  267.  
  268. $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'));
  269. }
  270.  
  271. function adsw_output_admin_update_notification_html($products, $settings)
  272. {
  273. if (!$products) {
  274. $text = '<table>';
  275. $text .= '<thead>';
  276. $text .= '<tr><th>' . __('All products are up to date.', 'adsw') . '</th></tr>';
  277. $text .= '<thead>';
  278. $text .= '</table>';
  279. .............................................................................
  280. ...............................................
  281. ................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement