]> git.mxchange.org Git - friendica.git/blobdiff - include/poller.php
nets widget - allow all children of specified parent net regardless of network
[friendica.git] / include / poller.php
index dbae1deec9713a80af16a19a2877b988a00fcfd4..89e4488b92c2239ae09ddb68a3f5c5563fead479 100644 (file)
@@ -24,6 +24,7 @@ function poller_run($argv, $argc){
        require_once('include/items.php');
        require_once('include/Contact.php');
        require_once('include/email.php');
+       require_once('include/socgraph.php');
 
        load_config('config');
        load_config('system');
@@ -38,19 +39,35 @@ function poller_run($argv, $argc){
 
        proc_run('php',"include/queue.php");
        
-       // once daily run expire in background
+       // expire any expired accounts
+
+       q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 
+               AND `account_expires_on` != '0000-00-00 00:00:00' 
+               AND `account_expires_on` < UTC_TIMESTAMP() ");
+  
+       $abandon_days = intval(get_config('system','account_abandon_days'));
+       if($abandon_days < 1)
+               $abandon_days = 0;
+
+       
+
+       // once daily run birthday_updates and then expire in background
 
        $d1 = get_config('system','last_expire_day');
        $d2 = intval(datetime_convert('UTC','UTC','now','d'));
 
        if($d2 != intval($d1)) {
+
+               update_contact_birthdays();
+
+               update_suggestions();
+
                set_config('system','last_expire_day',$d2);
                proc_run('php','include/expire.php');
        }
 
        // clear old cache
-       q("DELETE FROM `cache` WHERE `updated` < '%s'",
-               dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
+       Cache::clear();
 
        $manual_id  = 0;
        $generation = 0;
@@ -86,15 +103,21 @@ function poller_run($argv, $argc){
        // and which have a polling address and ignore Diaspora since 
        // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
 
+       $abandon_sql = (($abandon_days) 
+               ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days)) 
+               : '' 
+       );
+
        $contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` 
                WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
-               AND `network` != '%s'
+               AND NOT `network` IN ( '%s', '%s' )
                $sql_extra 
                AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 
-               AND `user`.`account_expired` = 0 ORDER BY RAND()",
+               AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()",
                intval(CONTACT_IS_SHARING),
                intval(CONTACT_IS_FRIEND),
-               dbesc(NETWORK_DIASPORA)
+               dbesc(NETWORK_DIASPORA),
+               dbesc(NETWORK_FACEBOOK)
        );
 
        if(! count($contacts)) {
@@ -117,6 +140,9 @@ function poller_run($argv, $argc){
                        if($manual_id)
                                $contact['last-update'] = '0000-00-00 00:00:00';
 
+                       if($contact['network'] === NETWORK_DFRN || $contact['network'] === NETWORK_OSTATUS)
+                               $contact['priority'] = 2;
+
                        if($contact['priority'] || $contact['subhub']) {
 
                                $hub_update = true;
@@ -138,6 +164,8 @@ function poller_run($argv, $argc){
                                        if((datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) || $force)
                                                        $hub_update = true;
                                }
+                               else
+                                       $hub_update = false;
 
                                /**
                                 * Based on $contact['priority'], should we poll this site now? Or later?
@@ -196,7 +224,7 @@ function poller_run($argv, $argc){
 
                        $importer = $r[0];
 
-                       logger("poller: poll: IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
+                       logger("poller: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
 
                        $last_update = (($contact['last-update'] === '0000-00-00 00:00:00') 
                                ? datetime_convert('UTC','UTC','now - 30 days', ATOM_TIME)
@@ -277,6 +305,13 @@ function poller_run($argv, $argc){
                                if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
                                        continue;
 
+                               if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) {
+                                       q("update contact set poco = '%s' where id = %d limit 1",
+                                               dbesc(str_replace('/profile/','/poco/', $contact['url'])),
+                                               intval($contact['id'])
+                                       );
+                               }
+
                                $postvars = array();
 
                                $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
@@ -467,27 +502,31 @@ function poller_run($argv, $argc){
                                }
 
 
-                               consume_feed($xml,$importer,$contact,$hub,1, true);
+                               consume_feed($xml,$importer,$contact,$hub,1,1);
 
                                // do it twice. Ensures that children of parents which may be later in the stream aren't tossed
        
-                               consume_feed($xml,$importer,$contact,$hub,1);
+                               consume_feed($xml,$importer,$contact,$hub,1,2);
 
+                               $hubmode = 'subscribe';
+                               if($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly'])
+                                       $hubmode = 'unsubscribe';
 
-                               if((strlen($hub)) && ($hub_update) && (($contact['rel'] == CONTACT_IS_FRIEND) || (($contact['network'] === NETWORK_OSTATUS) && (! $contact['readonly'])))) {
-                                       logger('poller: subscribing to hub(s) : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
+                               if((strlen($hub)) && ($hub_update) && ($contact['rel'] != CONTACT_IS_FOLLOWER)) {
+                                       logger('poller: hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
                                        $hubs = explode(',', $hub);
                                        if(count($hubs)) {
                                                foreach($hubs as $h) {
                                                        $h = trim($h);
                                                        if(! strlen($h))
                                                                continue;
-                                                       subscribe_to_hub($h,$importer,$contact);
+                                                       subscribe_to_hub($h,$importer,$contact,$hubmode);
                                                }
                                        }
                                }
                        }
 
+
                        $updated = datetime_convert();
 
                        $r = q("UPDATE `contact` SET `last-update` = '%s', `success_update` = '%s' WHERE `id` = %d LIMIT 1",
@@ -496,6 +535,21 @@ function poller_run($argv, $argc){
                                intval($contact['id'])
                        );
 
+
+                       // load current friends if possible.
+
+                       if($contact['poco']) {  
+                               $r = q("SELECT count(*) as total from glink 
+                                       where `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
+                                       intval($contact['id'])
+                               );
+                       }
+                       if(count($r)) {
+                               if(! $r[0]['total']) {
+                                       poco_load($contact['id'],$importer_uid,$contact['poco']);
+                               }
+                       }
+
                        // loop - next contact
                }
        }