Repository navigation
Expand file tree
/
Copy pathsync_handler.php
More file actions
88 lines (78 loc) · 3.19 KB
/
Copy pathsync_handler.php
File metadata and controls
88 lines (78 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
function channel_timer($cron_time, $id){
//timer for each channel
$cackle_api = new CackleAPI();
global $wpdb;
$id = (int) $id;
$get_last_time = $wpdb->get_results($wpdb->prepare("
SELECT *
FROM {$wpdb->prefix}cackle_channel
WHERE id = %d
ORDER BY ID ASC
LIMIT 1
", $id));
//print_r($get_last_time);die();
//$get_last_time = $cackle_api->cackle_get_param("last_time_" . $schedule . "_" . $_SERVER['HTTP_HOST'],0);
$now = time();
if (count($get_last_time)==0) {
$sql = "INSERT INTO {$wpdb->prefix}cackle_channel (id, time) VALUES (%d,%d) ON DUPLICATE KEY UPDATE time = %d";
$sql = $wpdb->prepare($sql,$id,$now,$now);
$wpdb->query($sql);
return $now;
} else {
$get_last_time = $get_last_time['0']->time;
if ($get_last_time + $cron_time > $now) {
return false;
}
if ($get_last_time + $cron_time < $now) {
$sql = "INSERT INTO {$wpdb->prefix}cackle_channel (id, time) VALUES (%d,%d) ON DUPLICATE KEY UPDATE time = %d";
$sql = $wpdb->prepare($sql,$id,$now,$now);
$wpdb->query($sql);
return $cron_time;
}
}
}
class SyncHandler{
public static function init() {
if(get_option('cackle_sync') == 1){
if (version_compare(get_bloginfo('version'), '2.9', '>=')) {
//initialize monitor object if not exist
if( !get_option('cackle_monitor') ) {
$object = new stdClass();
$object->post_id = 0;
$object->time = 0;
$object->mode = "by_channel";
$object->status = "finish";
$object->counter = 0;
update_option('cackle_monitor',$object);
}
if( !get_option('cackle_monitor_short') ) {
$object = new stdClass();
$object->post_id = 0;
$object->time = 0;
$object->mode = "by_channel";
$object->status = "finish";
update_option('cackle_monitor_short',$object);
}
//initialize modified triger object if not exist
if(!get_option('cackle_modified_trigger')){
$modified_triger = new stdClass();
update_option('cackle_modified_trigger',$modified_triger);
}
// INITIALIZE POSTS UPDATE OBJECT
if(!get_option('cackle_posts_update')){
$posts_update = new stdClass();
update_option('cackle_posts_update',$posts_update);
}
$monitor = CackleMonitor::check_monitor();
if(is_object($monitor)){
if ($monitor->post_id == NULL) return;
channel_timer(time(),$monitor->post_id);
$sync = new Sync();
$sync->init($monitor->post_id,$monitor->mode);
}
}
}
}
}
?>