PluginProbe ʕ •ᴥ•ʔ
Rich Showcase for Google Reviews / 6.4
Rich Showcase for Google Reviews v6.4
6.9.10 6.9.9 6.9.8 6.9.7 6.9.6 trunk 1.4 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.5 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.7 1.6.8 1.6.9 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.4 2.4.1 2.4.2 2.5 2.5.1 2.6 2.6.1 2.6.2 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.6.1 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.8.1 4.8.2 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.7.1 5.8 5.9 5.9.1 5.9.2 5.9.3 5.9.7 6.0 6.1 6.2 6.3 6.4 6.4.1 6.5 6.6 6.6.1 6.6.2 6.7 6.8 6.8.1 6.8.2 6.9 6.9.1 6.9.2 6.9.3 6.9.4 6.9.4.1 6.9.4.2 6.9.4.3 6.9.4.4 6.9.5
widget-google-reviews / includes / class-reviews-cron.php
widget-google-reviews / includes Last commit date
admin 11 months ago core 11 months ago class-activator.php 11 months ago class-assets.php 11 months ago class-builder-page.php 1 year ago class-deactivator.php 3 years ago class-debug-info.php 2 years ago class-feed-ajax.php 1 year ago class-feed-block.php 1 year ago class-feed-deserializer.php 11 months ago class-feed-old.php 4 years ago class-feed-page.php 11 months ago class-feed-serializer.php 2 years ago class-feed-shortcode.php 2 years ago class-feed-widget.php 4 years ago class-plugin-overview-ajax.php 1 year ago class-plugin-overview.php 11 months ago class-plugin-settings.php 11 months ago class-plugin-support.php 1 year ago class-plugin.php 11 months ago class-post-types.php 3 years ago class-reviews-cron.php 1 year ago class-settings-save.php 1 year ago class-view.php 11 months ago index.php 4 years ago page-setting-advance.php 1 year ago page-setting-fig.php 1 year ago page-setting-support.php 4 years ago
class-reviews-cron.php
134 lines
1 <?php
2
3 namespace WP_Rplg_Google_Reviews\Includes;
4
5 use WP_Rplg_Google_Reviews\Includes\Core\Google_Utils;
6
7 class Reviews_Cron {
8
9 private $google_utils;
10 private $feed_deserializer;
11
12 public function __construct(Google_Utils $google_utils, Feed_Deserializer $feed_deserializer) {
13 $this->google_utils = $google_utils;
14 $this->feed_deserializer = $feed_deserializer;
15 }
16
17 public function register() {
18 add_filter('cron_schedules', array($this, 'add_schedules'));
19 add_action('grw_revupd_schedule', array($this, 'update_schedule'));
20
21 $this->activate();
22 }
23
24 public function activate() {
25 $revupd_cron = get_option('grw_revupd_cron');
26 $next_cron_run = wp_next_scheduled('grw_revupd_schedule');
27
28 if ($revupd_cron !== '0' && !$next_cron_run) {
29 $start_at = rand(0, 60 * 60 * 12);
30 $freq = get_option('grw_freq_revs_upd', 'daily');
31 wp_schedule_event(time(), $freq, 'grw_revupd_schedule');
32 } elseif ($next_cron_run) {
33 update_option('grw_revupd_cron_timeout', $next_cron_run - time());
34 }
35 }
36
37 public function add_schedules($schedules = array()) {
38 $schedules['weekly'] = array(
39 'interval' => 60 * 60 * 24 * 7,
40 'display' => 'Once Weekly'
41 );
42 $schedules['fortnightly'] = array(
43 'interval' => 60 * 60 * 24 * 14,
44 'display' => 'Every two weeks'
45 );
46 $schedules['monthly'] = array(
47 'interval' => 60 * 60 * 24 * 30,
48 'display' => 'Once Monthly'
49 );
50 return $schedules;
51 }
52
53 public function update_schedule() {
54
55 $start_time = floor(microtime(true) * 1000);
56 $end_time = 0;
57 $feed_updated_ids = array();
58
59 $feed_conn_cache = array();
60
61 $feed_ids = get_option('grw_feed_ids');
62 $ids = explode(",", $feed_ids);
63 $ids_count = count($ids);
64
65 if ($ids_count > 0) {
66
67 // Trying to walk by all reviews feed to update these
68 for ($i = 0; $i < $ids_count; $i++) {
69
70 // Get next reviews feed ID
71 $id = array_shift($ids);
72
73 // Get next reviews feed
74 $feed = $this->feed_deserializer->get_feed($id);
75 if ($feed != false && strlen($feed->post_content) > 0) {
76
77 // Parse json content to obtain reviews connectors
78 $json = json_decode($feed->post_content);
79 if ($json->connections && count($json->connections) > 0) {
80
81 // Loop by all connectors without repeatable
82 foreach ($json->connections as $conn) {
83
84 if (isset($conn->refresh) && $conn->refresh) {
85
86 // Create pair 'place_id:lang' to update it
87 $arg_local_img = isset($conn->local_img) ? $conn->local_img : 'false';
88
89 $args = array($conn->id, $conn->lang, $arg_local_img);
90 $args_key = implode(":", $args);
91
92 // If not met, update
93 if (!in_array($args_key, $feed_conn_cache)) {
94 $this->google_utils->refresh($args);
95 array_push($feed_conn_cache, $args_key);
96 }
97 }
98 }
99
100 // Put reviews feed ID to log
101 array_push($feed_updated_ids, $id);
102
103 // Put reviews feed ID to the end of feed_ids option
104 array_push($ids, $id);
105 update_option('grw_feed_ids', implode(",", $ids));
106
107 // Clear feed cache
108 delete_transient('grw_feed_' . GRW_VERSION . '_' . $id . '_reviews', false);
109
110 // Check execution time
111 $end_time = floor(microtime(true) * 1000) - $start_time;
112 if ($end_time > 500) {
113 break;
114 }
115
116 }
117 }
118 }
119
120 }
121
122 // Log information
123 $now = floor(microtime(true) * 1000);
124 update_option('grw_revupd_cron_log', 'Executed at ' . $now . ' in ' . $end_time . 'ms for feeds: ' . implode(", ", $feed_updated_ids));
125 }
126
127 public function deactivate() {
128 $next_scheduled = wp_next_scheduled('grw_revupd_schedule');
129 if ($next_scheduled) {
130 wp_unschedule_event($next_scheduled, 'grw_revupd_schedule');
131 update_option('grw_revupd_cron_timeout', '');
132 }
133 }
134 }