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