- if(($argc > 1) && ($argv[1] == 'restart')) {
- $restart = true;
- $generation = intval($argv[2]);
- if(! $generation)
- killme();
- }
-
- if(($argc > 1) && intval($argv[1])) {
- $manual_id = intval($argv[1]);
- $force = true;
- }
-
- $interval = intval(get_config('system','poll_interval'));
- if(! $interval)
- $interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
-
- $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
-
- reload_plugins();
-
- $d = datetime_convert();
-
- if(! $restart)
- proc_run('php','include/cronhooks.php');
-
- // Only poll from those with suitable relationships,
- // 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` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `rel` IN (%d, %d) AND `poll` != '' AND `network` IN ('%s', '%s', '%s', '%s', '%s', '%s')
- $sql_extra
- AND NOT `self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly` AND NOT `contact`.`archive`
- AND NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()",
- intval(CONTACT_IS_SHARING),
- intval(CONTACT_IS_FRIEND),
- dbesc(NETWORK_DFRN),
- dbesc(NETWORK_ZOT),
- dbesc(NETWORK_OSTATUS),
- dbesc(NETWORK_FEED),
- dbesc(NETWORK_MAIL),
- dbesc(NETWORK_MAIL2)
- );
-
- if(! count($contacts)) {
- return;
- }
-
- foreach($contacts as $c) {
-
- $res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
- intval($c['id'])
- );
-
- if((! $res) || (! count($res)))