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