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