3 require_once("boot.php");
6 function poller_run($argv, $argc){
14 @include(".htconfig.php");
15 require_once("dba.php");
16 $db = new dba($db_host, $db_user, $db_pass, $db_data);
17 unset($db_host, $db_user, $db_pass, $db_data);
21 require_once('include/session.php');
22 require_once('include/datetime.php');
23 require_once('library/simplepie/simplepie.inc');
24 require_once('include/items.php');
25 require_once('include/Contact.php');
26 require_once('include/email.php');
27 require_once('include/socgraph.php');
28 require_once('include/pidfile.php');
30 load_config('config');
31 load_config('system');
33 $lockpath = get_config('system','lockpath');
34 if ($lockpath != '') {
35 $pidfile = new pidfile($lockpath, 'poller.lck');
36 if($pidfile->is_already_running()) {
37 logger("poller: Already running");
42 $a->set_baseurl(get_config('system','url'));
46 logger('poller: start');
48 // run queue delivery process in the background
50 proc_run('php',"include/queue.php");
52 // expire any expired accounts
54 q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0
55 AND `account_expires_on` != '0000-00-00 00:00:00'
56 AND `account_expires_on` < UTC_TIMESTAMP() ");
58 $abandon_days = intval(get_config('system','account_abandon_days'));
64 // once daily run birthday_updates and then expire in background
66 $d1 = get_config('system','last_expire_day');
67 $d2 = intval(datetime_convert('UTC','UTC','now','d'));
69 if($d2 != intval($d1)) {
71 update_contact_birthdays();
75 set_config('system','last_expire_day',$d2);
76 proc_run('php','include/expire.php');
82 // clear item cache files if they are older than one day
83 $cache = get_config('system','itemcache');
84 if (($cache != '') and is_dir($cache)) {
85 if ($dh = opendir($cache)) {
86 while (($file = readdir($dh)) !== false) {
87 $fullpath = $cache."/".$file;
88 if ((filetype($fullpath) == "file") and filectime($fullpath) < (time() - 86400))
101 if(($argc > 1) && ($argv[1] == 'force'))
104 if(($argc > 1) && ($argv[1] == 'restart')) {
106 $generation = intval($argv[2]);
111 if(($argc > 1) && intval($argv[1])) {
112 $manual_id = intval($argv[1]);
116 $interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
118 $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
122 $d = datetime_convert();
125 proc_run('php','include/cronhooks.php');
127 // Only poll from those with suitable relationships,
128 // and which have a polling address and ignore Diaspora since
129 // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
131 $abandon_sql = (($abandon_days)
132 ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days))
136 $contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
137 WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
138 AND NOT `network` IN ( '%s', '%s' )
140 AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0
141 AND `contact`.`archive` = 0
142 AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()",
143 intval(CONTACT_IS_SHARING),
144 intval(CONTACT_IS_FRIEND),
145 dbesc(NETWORK_DIASPORA),
146 dbesc(NETWORK_FACEBOOK)
149 if(! count($contacts)) {
153 foreach($contacts as $c) {
155 $res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
159 if((! $res) || (! count($res)))
162 foreach($res as $contact) {
167 $contact['last-update'] = '0000-00-00 00:00:00';
169 if($contact['network'] === NETWORK_DFRN)
170 $contact['priority'] = 2;
172 if(!get_config('system','ostatus_use_priority') and ($contact['network'] === NETWORK_OSTATUS))
173 $contact['priority'] = 2;
175 if($contact['priority'] || $contact['subhub']) {
180 $t = $contact['last-update'];
182 // We should be getting everything via a hub. But just to be sure, let's check once a day.
183 // (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
184 // This also lets us update our subscription to the hub, and add or replace hubs in case it
185 // changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'.
188 if($contact['subhub']) {
189 $interval = get_config('system','pushpoll_frequency');
190 $contact['priority'] = (($interval !== false) ? intval($interval) : 3);
193 if((datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) || $force)
200 * Based on $contact['priority'], should we poll this site now? Or later?
203 switch ($contact['priority']) {
205 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month"))
209 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week"))
213 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
217 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour"))
222 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour"))
226 if((! $update) && (! $force))
230 proc_run('php','include/onepoll.php',$contact['id']);
232 @time_sleep_until(microtime(true) + (float) $interval);
239 if (array_search(__file__,get_included_files())===0){
240 poller_run($argv,$argc);