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