PluginProbe
Content Egg – Affiliate Product Importer & Price Comparison / 11.2.0
Content Egg – Affiliate Product Importer & Price Comparison v11.2.0
11.8.1 11.8.0 11.7.0 11.6.0 11.5.0 11.4.0 11.3.0 11.2.0 11.1.0 trunk 1.6.0 1.6.1 1.7.1 1.8.0 1.9.0 10.0.0 10.1.0 11.0.0 2.0.1 2.1.0 2.2.0 2.3.0 2.4.0 2.4.2 2.5.1 All 65 releases
content-egg / application / ModuleUpdateVisit.php

ModuleUpdateVisit.php in Content Egg – Affiliate Product Importer & Price Comparison 11.2.0, at application/ModuleUpdateVisit.php

118 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ContentEgg\application;
4
5 defined('\ABSPATH') || exit;
6
7 use ContentEgg\application\components\ModuleManager;
8 use ContentEgg\application\components\ContentManager;
9 use ContentEgg\application\admin\GeneralConfig;
10 use ContentEgg\application\vendor\CrawlerDetect\CrawlerDetect;
11
12 /**
13 * ModuleUpdateVisit class file
14 *
15 * @author keywordrush.com <support@keywordrush.com>
16 * @link https://www.keywordrush.com
17 * @copyright Copyright &copy; 2026 keywordrush.com
18 */
19 class ModuleUpdateVisit
20 {
21
22 private static $instance = null;
23
24 public static function getInstance()
25 {
26 if (self::$instance == null)
27 self::$instance = new self;
28
29 return self::$instance;
30 }
31
32 private function __construct()
33 {
34 }
35
36 public function init()
37 {
38 if (defined('\WP_CLI') && \WP_CLI)
39 return;
40
41 if (GeneralConfig::getInstance()->option('filter_bots'))
42 {
43 $cd = new CrawlerDetect();
44 if ($cd->isCrawler())
45 {
46 return;
47 }
48 }
49 // exec before post layout
50 \add_filter('template_redirect', array($this, 'update'), 10);
51 }
52
53 public function update()
54 {
55 if (!is_single() && !is_page())
56 return;
57
58 $this->updateByKeyword();
59 $this->updateItems();
60 }
61
62 private function updateByKeyword()
63 {
64 global $post;
65
66 if (empty($post))
67 return;
68
69 foreach (ModuleManager::getInstance()->getParsers(true) as $module)
70 {
71 $is_visit_update = in_array($module->config('update_mode'), array('visit', 'visit_cron'));
72 $is_data_exists = ContentManager::isDataExists($post->ID, $module->getId());
73
74 // parse data if not exists in any case
75 if (!$is_visit_update && $is_data_exists)
76 continue;
77
78 $ttl = $module->config('ttl');
79 if (!$ttl && $is_data_exists)
80 continue;
81
82 if (!ContentManager::getAutoupdateKeyword($post->ID, $module->getId()))
83 continue;
84
85 $last_update = (int) \get_post_meta($post->ID, ContentManager::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module->getId(), true);
86 if ($last_update && time() - $last_update < $ttl)
87 continue;
88
89 ContentManager::updateByKeyword($post->ID, $module->getId());
90 }
91 }
92
93 private function updateItems()
94 {
95 global $post;
96
97 if (empty($post))
98 return;
99
100 foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module)
101 {
102 if (!in_array($module->config('update_mode'), array('visit', 'visit_cron')))
103 continue;
104
105 if (!$module->isItemsUpdateAvailable())
106 continue;
107
108 if (!$ttl_items = $module->config('ttl_items'))
109 continue;
110
111 $last_items_update = (int) \get_post_meta($post->ID, ContentManager::META_PREFIX_LAST_ITEMS_UPDATE . $module->getId(), true);
112 if (!$last_items_update || time() - $last_items_update < $ttl_items)
113 continue;
114 ContentManager::updateItems($post->ID, $module->getId());
115 }
116 }
117 }
118