]> git.mxchange.org Git - friendica.git/blob - include/poller.php
New config options if ostatus polling should use the priority in the contacts
[friendica.git] / include / poller.php
1 <?php
2
3 require_once("boot.php");
4
5
6 function poller_run($argv, $argc){
7         global $a, $db;
8
9         if(is_null($a)) {
10                 $a = new App;
11         }
12   
13         if(is_null($db)) {
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);
18         };
19
20
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
29         load_config('config');
30         load_config('system');
31
32         $a->set_baseurl(get_config('system','url'));
33
34         load_hooks();
35
36         logger('poller: start');
37         
38         // run queue delivery process in the background
39
40         proc_run('php',"include/queue.php");
41         
42         // expire any expired accounts
43
44         q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 
45                 AND `account_expires_on` != '0000-00-00 00:00:00' 
46                 AND `account_expires_on` < UTC_TIMESTAMP() ");
47   
48         $abandon_days = intval(get_config('system','account_abandon_days'));
49         if($abandon_days < 1)
50                 $abandon_days = 0;
51
52         
53
54         // once daily run birthday_updates and then expire in background
55
56         $d1 = get_config('system','last_expire_day');
57         $d2 = intval(datetime_convert('UTC','UTC','now','d'));
58
59         if($d2 != intval($d1)) {
60
61                 update_contact_birthdays();
62
63                 update_suggestions();
64
65                 set_config('system','last_expire_day',$d2);
66                 proc_run('php','include/expire.php');
67         }
68
69         // clear old cache
70         Cache::clear();
71
72         $manual_id  = 0;
73         $generation = 0;
74         $hub_update = false;
75         $force      = false;
76         $restart    = false;
77
78         if(($argc > 1) && ($argv[1] == 'force'))
79                 $force = true;
80
81         if(($argc > 1) && ($argv[1] == 'restart')) {
82                 $restart = true;
83                 $generation = intval($argv[2]);
84                 if(! $generation)
85                         killme();               
86         }
87
88         if(($argc > 1) && intval($argv[1])) {
89                 $manual_id = intval($argv[1]);
90                 $force     = true;
91         }
92
93         $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
94
95         reload_plugins();
96
97         $d = datetime_convert();
98
99         if(! $restart)
100                 proc_run('php','include/cronhooks.php');
101
102         // Only poll from those with suitable relationships,
103         // and which have a polling address and ignore Diaspora since 
104         // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
105
106         $abandon_sql = (($abandon_days) 
107                 ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days)) 
108                 : '' 
109         );
110
111         $contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` 
112                 WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
113                 AND NOT `network` IN ( '%s', '%s' )
114                 $sql_extra 
115                 AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 
116                 AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()",
117                 intval(CONTACT_IS_SHARING),
118                 intval(CONTACT_IS_FRIEND),
119                 dbesc(NETWORK_DIASPORA),
120                 dbesc(NETWORK_FACEBOOK)
121         );
122
123         if(! count($contacts)) {
124                 return;
125         }
126
127         foreach($contacts as $c) {
128
129                 $res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
130                         intval($c['id'])
131                 );
132
133                 if((! $res) || (! count($res)))
134                         continue;
135
136                 foreach($res as $contact) {
137
138                         $xml = false;
139
140                         if($manual_id)
141                                 $contact['last-update'] = '0000-00-00 00:00:00';
142
143                         if($contact['network'] === NETWORK_DFRN)
144                                 $contact['priority'] = 2;
145
146                         if(!get_config('system','ostatus_use_priority') and ($contact['network'] === NETWORK_OSTATUS))
147                                 $contact['priority'] = 2;
148
149                         if($contact['priority'] || $contact['subhub']) {
150
151                                 $hub_update = true;
152                                 $update     = false;
153
154                                 $t = $contact['last-update'];
155
156                                 // We should be getting everything via a hub. But just to be sure, let's check once a day.
157                                 // (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
158                                 // This also lets us update our subscription to the hub, and add or replace hubs in case it
159                                 // changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'. 
160
161
162                                 if($contact['subhub']) {
163                                         $interval = get_config('system','pushpoll_frequency');
164                                         $contact['priority'] = (($interval !== false) ? intval($interval) : 3);
165                                         $hub_update = false;
166         
167                                         if((datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) || $force)
168                                                         $hub_update = true;
169                                 }
170                                 else
171                                         $hub_update = false;
172
173                                 /**
174                                  * Based on $contact['priority'], should we poll this site now? Or later?
175                                  */                     
176
177                                 switch ($contact['priority']) {
178                                         case 5:
179                                                 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month"))
180                                                         $update = true;
181                                                 break;                                  
182                                         case 4:
183                                                 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week"))
184                                                         $update = true;
185                                                 break;
186                                         case 3:
187                                                 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
188                                                         $update = true;
189                                                 break;
190                                         case 2:
191                                                 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour"))
192                                                         $update = true;
193                                                 break;
194                                         case 1:
195                                         default:
196                                                 if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour"))
197                                                         $update = true;
198                                                 break;
199                                 }
200                                 if((! $update) && (! $force))
201                                         continue;
202                         }
203
204                         // Check to see if we are running out of memory - if so spawn a new process and kill this one
205
206                         $avail_memory = return_bytes(ini_get('memory_limit'));
207                         $memused = memory_get_peak_usage(true);
208                         if(intval($avail_memory)) {
209                                 if(($memused / $avail_memory) > 0.95) {
210                                         if($generation + 1 > 10) {
211                                                 logger('poller: maximum number of spawns exceeded. Terminating.');
212                                                 killme();
213                                         }
214                                         logger('poller: memory exceeded. ' . $memused . ' bytes used. Spawning new poll.');
215                                         proc_run('php', 'include/poller.php', 'restart', (string) $generation + 1);
216                                         killme();
217                                 }
218                         }
219
220                         $importer_uid = $contact['uid'];
221                 
222                         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
223                                 intval($importer_uid)
224                         );
225                         if(! count($r))
226                                 continue;
227
228                         $importer = $r[0];
229
230                         logger("poller: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
231
232                         $last_update = (($contact['last-update'] === '0000-00-00 00:00:00') 
233                                 ? datetime_convert('UTC','UTC','now - 30 days', ATOM_TIME)
234                                 : datetime_convert('UTC','UTC',$contact['last-update'], ATOM_TIME)
235                         );
236
237                         if($contact['network'] === NETWORK_DFRN) {
238
239                                 $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
240
241                                 if(intval($contact['duplex']) && $contact['dfrn-id'])
242                                         $idtosend = '0:' . $orig_id;
243                                 if(intval($contact['duplex']) && $contact['issued-id'])
244                                         $idtosend = '1:' . $orig_id;
245
246                                 // they have permission to write to us. We already filtered this in the contact query.
247                                 $perm = 'rw';
248
249                                 $url = $contact['poll'] . '?dfrn_id=' . $idtosend 
250                                         . '&dfrn_version=' . DFRN_PROTOCOL_VERSION 
251                                         . '&type=data&last_update=' . $last_update 
252                                         . '&perm=' . $perm ;
253         
254                                 $handshake_xml = fetch_url($url);
255
256                                 logger('poller: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA);
257
258
259                                 if(! $handshake_xml) {
260                                         logger("poller: $url appears to be dead - marking for death ");
261                                         // dead connection - might be a transient event, or this might
262                                         // mean the software was uninstalled or the domain expired. 
263                                         // Will keep trying for one month.
264                                         mark_for_death($contact);
265
266                                         // set the last-update so we don't keep polling
267
268                                         $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
269                                                 dbesc(datetime_convert()),
270                                                 intval($contact['id'])
271                                         );
272
273                                         continue;
274                                 }
275
276                                 if(! strstr($handshake_xml,'<?xml')) {
277                                         logger('poller: response from ' . $url . ' did not contain XML.');
278                                         $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
279                                                 dbesc(datetime_convert()),
280                                                 intval($contact['id'])
281                                         );
282                                         continue;
283                                 }
284
285
286                                 $res = parse_xml_string($handshake_xml);
287         
288                                 if(intval($res->status) == 1) {
289                                         logger("poller: $url replied status 1 - marking for death ");
290
291                                         // we may not be friends anymore. Will keep trying for one month.
292                                         // set the last-update so we don't keep polling
293
294                                         $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
295                                                 dbesc(datetime_convert()),
296                                                 intval($contact['id'])
297                                         );
298
299                                         mark_for_death($contact);
300                                 }
301                                 else {
302                                         if($contact['term-date'] != '0000-00-00 00:00:00') {
303                                                 logger("poller: $url back from the dead - removing mark for death");
304                                                 unmark_for_death($contact);
305                                         }
306                                 }
307
308                                 if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
309                                         continue;
310
311                                 if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) {
312                                         q("update contact set poco = '%s' where id = %d limit 1",
313                                                 dbesc(str_replace('/profile/','/poco/', $contact['url'])),
314                                                 intval($contact['id'])
315                                         );
316                                 }
317
318                                 $postvars = array();
319
320                                 $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
321                                 $challenge    = hex2bin((string) $res->challenge);
322
323                                 $final_dfrn_id = '';
324
325                                 if(($contact['duplex']) && strlen($contact['prvkey'])) {
326                                         openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
327                                         openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
328                                 }
329                                 else {
330                                         openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
331                                         openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
332                                 }
333
334                                 $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
335
336                                 if(strpos($final_dfrn_id,':') == 1)
337                                         $final_dfrn_id = substr($final_dfrn_id,2);
338
339                                 if($final_dfrn_id != $orig_id) {
340                                         logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);    
341                                         // did not decode properly - cannot trust this site 
342                                         continue;
343                                 }
344
345                                 $postvars['dfrn_id'] = $idtosend;
346                                 $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
347                                 $postvars['perm'] = 'rw';
348
349                                 $xml = post_url($contact['poll'],$postvars);
350                         }
351                         elseif(($contact['network'] === NETWORK_OSTATUS) 
352                                 || ($contact['network'] === NETWORK_DIASPORA)
353                                 || ($contact['network'] === NETWORK_FEED) ) {
354
355                                 // Upgrading DB fields from an older Friendica version
356                                 // Will only do this once per notify-enabled OStatus contact
357                                 // or if relationship changes
358
359                                 $stat_writeable = ((($contact['notify']) && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND)) ? 1 : 0);
360
361                                 if($stat_writeable != $contact['writable']) {
362                                         q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1",
363                                                 intval($stat_writeable),
364                                                 intval($contact['id'])
365                                         );
366                                 }
367
368                                 // Are we allowed to import from this person?
369
370                                 if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly'])
371                                         continue;
372
373                                 $xml = fetch_url($contact['poll']);
374                         }
375                         elseif($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) {
376
377                                 logger("Mail: Fetching");
378
379                                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
380                                 if($mail_disabled)
381                                         continue;
382
383                                 logger("Mail: Enabled");
384
385                                 $mbox = null;
386                                 $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
387                                         intval($importer_uid)
388                                 );
389                                 $mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1",
390                                         intval($importer_uid)
391                                 );
392                                 if(count($x) && count($mailconf)) {
393                                     $mailbox = construct_mailbox_name($mailconf[0]);
394                                         $password = '';
395                                         openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']);
396                                         $mbox = email_connect($mailbox,$mailconf[0]['user'],$password);
397                                         unset($password);
398                                         logger("Mail: Connect");
399                                         if($mbox) {
400                                                 q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
401                                                         dbesc(datetime_convert()),
402                                                         intval($mailconf[0]['id']),
403                                                         intval($importer_uid)
404                                                 );
405                                         }
406                                 }
407                                 if($mbox) {
408                                         logger("Mail: mbox");
409
410                                         $msgs = email_poll($mbox,$contact['addr']);
411
412                                         if(count($msgs)) {
413                                                 logger("Mail: Parsing ".count($msgs)." mails.");
414
415                                                 foreach($msgs as $msg_uid) {
416                                                         logger("Mail: Parsing mail ".$msg_uid);
417
418                                                         $datarray = array();
419                                                         $meta = email_msg_meta($mbox,$msg_uid);
420                                                         $headers = email_msg_headers($mbox,$msg_uid);
421
422                                                         // look for a 'references' header and try and match with a parent item we have locally.
423
424                                                         $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
425                                                         $datarray['uri'] = msgid2iri(trim($meta->message_id,'<>'));
426
427                                                         if($raw_refs) {
428                                                                 $refs_arr = explode(' ', $raw_refs);
429                                                                 if(count($refs_arr)) {
430                                                                         for($x = 0; $x < count($refs_arr); $x ++)
431                                                                                 $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
432                                                                 }
433                                                                 $qstr = implode(',',$refs_arr);
434                                                                 $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
435                                                                         intval($importer_uid)
436                                                                 );
437                                                                 if(count($r))
438                                                                         $datarray['parent-uri'] = $r[0]['uri'];
439                                                         }
440
441
442                                                         if(! x($datarray,'parent-uri'))
443                                                                 $datarray['parent-uri'] = $datarray['uri'];
444
445                                                         // Have we seen it before?
446                                                         $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
447                                                                 intval($importer_uid),
448                                                                 dbesc($datarray['uri'])
449                                                         );
450
451                                                         if(count($r)) {
452                                                                 logger("Mail: Seen before ".$msg_uid);
453                                                                 if($meta->deleted && ! $r[0]['deleted']) {
454                                                                         q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
455                                                                                 dbesc(datetime_convert()),
456                                                                                 intval($r[0]['id'])
457                                                                         );
458                                                                 }
459                                                                 switch ($mailconf[0]['action']) {
460                                                                         case 0:
461                                                                                 break;
462                                                                         case 1:
463                                                                                 logger("Mail: Deleting ".$msg_uid);
464                                                                                 imap_delete($mbox, $msg_uid, FT_UID);
465                                                                                 break;
466                                                                         case 2:
467                                                                                 logger("Mail: Mark as seen ".$msg_uid);
468                                                                                 imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
469                                                                                 break;
470                                                                         case 3:
471                                                                                 logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']);
472                                                                                 imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
473                                                                                 if ($mailconf[0]['movetofolder'] != "")
474                                                                                         imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
475                                                                                 break;
476                                                                 }
477                                                                 continue;
478                                                         }
479
480                                                         // Decoding the header
481                                                         $subject = imap_mime_header_decode($meta->subject);
482                                                         $datarray['title'] = "";
483                                                         foreach($subject as $subpart)
484                                                                 if ($subpart->charset != "default")
485                                                                         $datarray['title'] .= iconv($subpart->charset, 'UTF-8//IGNORE', $subpart->text);
486                                                                 else
487                                                                         $datarray['title'] .= $subpart->text;
488
489                                                         $datarray['title'] = notags(trim($datarray['title']));
490
491                                                         //$datarray['title'] = notags(trim($meta->subject));
492                                                         $datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
493
494                                                         $r = email_get_msg($mbox,$msg_uid);
495                                                         if(! $r) {
496                                                                 logger("Mail: can't fetch msg ".$msg_uid);
497                                                                 continue;
498                                                         }
499                                                         $datarray['body'] = escape_tags($r['body']);
500
501                                                         logger("Mail: Importing ".$msg_uid);
502
503                                                         // some mailing lists have the original author as 'from' - add this sender info to msg body.
504                                                         // todo: adding a gravatar for the original author would be cool
505
506                                                         if(! stristr($meta->from,$contact['addr'])) {
507                                                                 $from = imap_mime_header_decode($meta->from);
508                                                                 $fromdecoded = "";
509                                                                 foreach($from as $frompart)
510                                                                         if ($frompart->charset != "default")
511                                                                                 $fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text);
512                                                                         else
513                                                                                 $fromdecoded .= $frompart->text;
514
515                                                                 $datarray['body'] = "[b]".t('From: ') . escape_tags($fromdecoded) . "[/b]\n\n" . $datarray['body'];
516                                                         }
517
518                                                         $datarray['uid'] = $importer_uid;
519                                                         $datarray['contact-id'] = $contact['id'];
520                                                         if($datarray['parent-uri'] === $datarray['uri'])
521                                                                 $datarray['private'] = 1;
522                                                         if(($contact['network'] === NETWORK_MAIL) && (! get_pconfig($importer_uid,'system','allow_public_email_replies'))) {
523                                                                 $datarray['private'] = 1;
524                                                                 $datarray['allow_cid'] = '<' . $contact['id'] . '>';
525                                                         }
526                                                         $datarray['author-name'] = $contact['name'];
527                                                         $datarray['author-link'] = 'mailbox';
528                                                         $datarray['author-avatar'] = $contact['photo'];
529
530                                                         $stored_item = item_store($datarray);
531                                                         q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d",
532                                                                 dbesc($datarray['parent-uri']),
533                                                                 intval($importer_uid)
534                                                         );
535                                                         q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
536                                                                 intval($stored_item)
537                                                         );
538                                                         switch ($mailconf[0]['action']) {
539                                                                 case 0:
540                                                                         break;
541                                                                 case 1:
542                                                                         logger("Mail: Deleting ".$msg_uid);
543                                                                         imap_delete($mbox, $msg_uid, FT_UID);
544                                                                         break;
545                                                                 case 2:
546                                                                         logger("Mail: Mark as seen ".$msg_uid);
547                                                                         imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
548                                                                         break;
549                                                                 case 3:
550                                                                         logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']);
551                                                                         imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
552                                                                         if ($mailconf[0]['movetofolder'] != "")
553                                                                                 imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
554                                                                         break;
555                                                         }
556                                                 }
557                                         }
558
559                                         imap_close($mbox);
560                                 }
561                         }
562                         elseif($contact['network'] === NETWORK_FACEBOOK) {
563                                 // This is picked up by the Facebook plugin on a cron hook.
564                                 // Ignored here.
565                         }
566
567                         if($xml) {
568                                 logger('poller: received xml : ' . $xml, LOGGER_DATA);
569
570                                 if(! strstr($xml,'<?xml')) {
571                                         logger('poller: post_handshake: response from ' . $url . ' did not contain XML.');
572                                         $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
573                                                 dbesc(datetime_convert()),
574                                                 intval($contact['id'])
575                                         );
576                                         continue;
577                                 }
578
579
580                                 consume_feed($xml,$importer,$contact,$hub,1,1);
581
582                                 // do it twice. Ensures that children of parents which may be later in the stream aren't tossed
583         
584                                 consume_feed($xml,$importer,$contact,$hub,1,2);
585
586                                 $hubmode = 'subscribe';
587                                 if($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly'])
588                                         $hubmode = 'unsubscribe';
589
590                                 if((strlen($hub)) && ($hub_update) && ($contact['rel'] != CONTACT_IS_FOLLOWER)) {
591                                         logger('poller: hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
592                                         $hubs = explode(',', $hub);
593                                         if(count($hubs)) {
594                                                 foreach($hubs as $h) {
595                                                         $h = trim($h);
596                                                         if(! strlen($h))
597                                                                 continue;
598                                                         subscribe_to_hub($h,$importer,$contact,$hubmode);
599                                                 }
600                                         }
601                                 }
602                         }
603
604
605                         $updated = datetime_convert();
606
607                         $r = q("UPDATE `contact` SET `last-update` = '%s', `success_update` = '%s' WHERE `id` = %d LIMIT 1",
608                                 dbesc($updated),
609                                 dbesc($updated),
610                                 intval($contact['id'])
611                         );
612
613
614                         // load current friends if possible.
615
616                         if($contact['poco']) {  
617                                 $r = q("SELECT count(*) as total from glink 
618                                         where `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
619                                         intval($contact['id'])
620                                 );
621                         }
622                         if(count($r)) {
623                                 if(! $r[0]['total']) {
624                                         poco_load($contact['id'],$importer_uid,$contact['poco']);
625                                 }
626                         }
627
628                         // loop - next contact
629                 }
630         }
631
632                 
633         return;
634 }
635
636 if (array_search(__file__,get_included_files())===0){
637   poller_run($argv,$argc);
638   killme();
639 }