aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Daemon')
-rw-r--r--Zotlabs/Daemon/Addon.php7
-rw-r--r--Zotlabs/Daemon/Cache_embeds.php1
-rw-r--r--Zotlabs/Daemon/Checksites.php23
-rw-r--r--Zotlabs/Daemon/Cron.php125
-rw-r--r--Zotlabs/Daemon/Cron_daily.php40
-rw-r--r--Zotlabs/Daemon/Cron_weekly.php21
-rw-r--r--Zotlabs/Daemon/CurlAuth.php24
-rw-r--r--Zotlabs/Daemon/Deliver.php16
-rw-r--r--Zotlabs/Daemon/Deliver_hooks.php11
-rw-r--r--Zotlabs/Daemon/Directory.php40
-rw-r--r--Zotlabs/Daemon/Expire.php35
-rw-r--r--Zotlabs/Daemon/Externals.php53
-rw-r--r--Zotlabs/Daemon/Gprobe.php14
-rwxr-xr-xZotlabs/Daemon/Importdoc.php14
-rw-r--r--Zotlabs/Daemon/Importfile.php23
-rw-r--r--Zotlabs/Daemon/Master.php37
-rw-r--r--Zotlabs/Daemon/Notifier.php414
-rw-r--r--Zotlabs/Daemon/Onedirsync.php23
-rw-r--r--Zotlabs/Daemon/Onepoll.php109
-rw-r--r--Zotlabs/Daemon/Poller.php145
-rw-r--r--Zotlabs/Daemon/Queue.php23
-rw-r--r--Zotlabs/Daemon/Thumbnail.php46
22 files changed, 609 insertions, 635 deletions
diff --git a/Zotlabs/Daemon/Addon.php b/Zotlabs/Daemon/Addon.php
index c2889e596..c6778750d 100644
--- a/Zotlabs/Daemon/Addon.php
+++ b/Zotlabs/Daemon/Addon.php
@@ -2,13 +2,12 @@
namespace Zotlabs\Daemon;
-require_once('include/zot.php');
-
class Addon {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
- call_hooks('daemon_addon',$argv);
+ call_hooks('daemon_addon', $argv);
}
+
}
diff --git a/Zotlabs/Daemon/Cache_embeds.php b/Zotlabs/Daemon/Cache_embeds.php
index 08088abd6..9e5b8d2bb 100644
--- a/Zotlabs/Daemon/Cache_embeds.php
+++ b/Zotlabs/Daemon/Cache_embeds.php
@@ -2,7 +2,6 @@
namespace Zotlabs\Daemon;
-
class Cache_embeds {
static public function run($argc,$argv) {
diff --git a/Zotlabs/Daemon/Checksites.php b/Zotlabs/Daemon/Checksites.php
index 3bcfdd7cf..7227e96e4 100644
--- a/Zotlabs/Daemon/Checksites.php
+++ b/Zotlabs/Daemon/Checksites.php
@@ -6,34 +6,35 @@ require_once('include/hubloc.php');
class Checksites {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
logger('checksites: start');
-
- if(($argc > 1) && ($argv[1]))
+
+ if (($argc > 1) && ($argv[1]))
$site_id = $argv[1];
- if($site_id)
+ if ($site_id)
$sql_options = " and site_url = '" . dbesc($argv[1]) . "' ";
- $days = intval(get_config('system','sitecheckdays'));
- if($days < 1)
+ $days = intval(get_config('system', 'sitecheckdays'));
+ if ($days < 1)
$days = 30;
$r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d $sql_options ",
- db_utcnow(), db_quoteinterval($days . ' DAY'),
+ db_utcnow(),
+ db_quoteinterval($days . ' DAY'),
intval(SITE_TYPE_ZOT)
);
- if(! $r)
+ if (!$r)
return;
- foreach($r as $rr) {
- if(! strcasecmp($rr['site_url'],z_root()))
+ foreach ($r as $rr) {
+ if (!strcasecmp($rr['site_url'], z_root()))
continue;
$x = ping_site($rr['site_url']);
- if($x['success']) {
+ if ($x['success']) {
logger('checksites: ' . $rr['site_url']);
q("update site set site_update = '%s' where site_url = '%s' ",
dbesc(datetime_convert()),
diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php
index 703d6ce08..e8fa3244f 100644
--- a/Zotlabs/Daemon/Cron.php
+++ b/Zotlabs/Daemon/Cron.php
@@ -6,14 +6,14 @@ use Zotlabs\Lib\Libsync;
class Cron {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
- $maxsysload = intval(get_config('system','maxloadavg'));
- if($maxsysload < 1)
+ $maxsysload = intval(get_config('system', 'maxloadavg'));
+ if ($maxsysload < 1)
$maxsysload = 50;
- if(function_exists('sys_getloadavg')) {
+ if (function_exists('sys_getloadavg')) {
$load = sys_getloadavg();
- if(intval($load[0]) > $maxsysload) {
+ if (intval($load[0]) > $maxsysload) {
logger('system: load ' . $load . ' too high. Cron deferred to next scheduled run.');
return;
}
@@ -21,17 +21,18 @@ class Cron {
// Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
$lockfile = 'store/[data]/cron';
- if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
- && (! get_config('system','override_cron_lockfile'))) {
+ if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
+ && (!get_config('system', 'override_cron_lockfile'))) {
logger("cron: Already running");
return;
}
-
+
// Create a lockfile. Needs two vars, but $x doesn't need to contain anything.
+ $x = '';
file_put_contents($lockfile, $x);
logger('cron: start');
-
+
// run queue delivery process in the background
Master::Summon(array('Queue'));
@@ -46,7 +47,7 @@ class Cron {
db_utcnow(),
db_quoteinterval('3 MINUTE')
);
-
+
// expire any expired mail
q("delete from mail where expires > '%s' and expires < %s ",
@@ -54,19 +55,23 @@ class Cron {
db_utcnow()
);
+ $interval = get_config('system', 'delivery_interval', 3);
+
// expire any expired items
$r = q("select id,item_wall from item where expires > '2001-01-01 00:00:00' and expires < %s
and item_deleted = 0 ",
db_utcnow()
);
- if($r) {
+ if ($r) {
require_once('include/items.php');
- foreach($r as $rr) {
- drop_item($rr['id'],false,(($rr['item_wall']) ? DROPITEM_PHASE1 : DROPITEM_NORMAL));
- if($rr['item_wall']) {
+ foreach ($r as $rr) {
+ drop_item($rr['id'], false, (($rr['item_wall']) ? DROPITEM_PHASE1 : DROPITEM_NORMAL));
+ if ($rr['item_wall']) {
// The notifier isn't normally invoked unless item_drop is interactive.
- Master::Summon( [ 'Notifier', 'drop', $rr['id'] ] );
+ Master::Summon(['Notifier', 'drop', $rr['id']]);
+ if ($interval)
+ @time_sleep_until(microtime(true) + (float)$interval);
}
}
}
@@ -78,9 +83,9 @@ class Cron {
dbesc(NULL_DATE),
db_utcnow()
);
- if($r) {
+ if ($r) {
require_once('include/security.php');
- foreach($r as $rr) {
+ foreach ($r as $rr) {
atoken_delete($rr['atoken_id']);
}
}
@@ -90,33 +95,33 @@ class Cron {
// or dead entries.
$r = q("select channel_id from channel where channel_dirdate < %s - INTERVAL %s and channel_removed = 0",
- db_utcnow(),
+ db_utcnow(),
db_quoteinterval('30 DAY')
);
- if($r) {
- foreach($r as $rr) {
- Master::Summon(array('Directory',$rr['channel_id'],'force'));
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
+ if ($r) {
+ foreach ($r as $rr) {
+ Master::Summon(array('Directory', $rr['channel_id'], 'force'));
+ if ($interval)
+ @time_sleep_until(microtime(true) + (float)$interval);
}
}
-
+
// Clean expired photos from cache
-
+
$r = q("SELECT DISTINCT xchan, content FROM photo WHERE photo_usage = %d AND expires < %s - INTERVAL %s",
intval(PHOTO_CACHE),
db_utcnow(),
- db_quoteinterval(get_config('system','active_expire_days', '30') . ' DAY')
+ db_quoteinterval(get_config('system', 'active_expire_days', '30') . ' DAY')
);
- if($r) {
+ if ($r) {
q("DELETE FROM photo WHERE photo_usage = %d AND expires < %s - INTERVAL %s",
intval(PHOTO_CACHE),
db_utcnow(),
- db_quoteinterval(get_config('system','active_expire_days', '30') . ' DAY')
+ db_quoteinterval(get_config('system', 'active_expire_days', '30') . ' DAY')
);
- foreach($r as $rr) {
+ foreach ($r as $rr) {
$file = dbunescbin($rr['content']);
- if(is_file($file)) {
+ if (is_file($file)) {
@unlink($file);
@rmdir(dirname($file));
logger('info: deleted cached photo file ' . $file, LOGGER_DEBUG);
@@ -130,27 +135,29 @@ class Cron {
$r = q("select id from item where item_delayed = 1 and created <= %s and created > '%s' ",
db_utcnow(),
- dbesc(datetime_convert('UTC','UTC','now - 2 days'))
+ dbesc(datetime_convert('UTC', 'UTC', 'now - 2 days'))
);
- if($r) {
- foreach($r as $rr) {
+ if ($r) {
+ foreach ($r as $rr) {
$x = q("update item set item_delayed = 0 where id = %d",
intval($rr['id'])
);
- if($x) {
+ if ($x) {
$z = q("select * from item where id = %d",
- intval($message_id)
+ intval($rr['id'])
);
- if($z) {
+ if ($z) {
xchan_query($z);
$sync_item = fetch_post_tags($z);
Libsync::build_sync_packet($sync_item[0]['uid'],
- [
- 'item' => [ encode_item($sync_item[0],true) ]
+ [
+ 'item' => [encode_item($sync_item[0], true)]
]
);
}
- Master::Summon(array('Notifier','wall-new',$rr['id']));
+ Master::Summon(array('Notifier', 'wall-new', $rr['id']));
+ if ($interval)
+ @time_sleep_until(microtime(true) + (float)$interval);
}
}
}
@@ -163,27 +170,27 @@ class Cron {
require_once('include/attach.php');
attach_upgrade();
- $abandon_days = intval(get_config('system','account_abandon_days'));
- if($abandon_days < 1)
+ $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
// FIXME: add birthday updates, both locally and for xprof for use
// by directory servers
- $d1 = intval(get_config('system','last_expire_day'));
- $d2 = intval(datetime_convert('UTC','UTC','now','d'));
+ $d1 = intval(get_config('system', 'last_expire_day'));
+ $d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd'));
// Allow somebody to staggger daily activities if they have more than one site on their server,
// or if it happens at an inconvenient (busy) hour.
- $h1 = intval(get_config('system','cron_hour'));
- $h2 = intval(datetime_convert('UTC','UTC','now','G'));
+ $h1 = intval(get_config('system', 'cron_hour'));
+ $h2 = intval(datetime_convert('UTC', 'UTC', 'now', 'G'));
- if(($d2 != $d1) && ($h1 == $h2)) {
+ if (($d2 != $d1) && ($h1 == $h2)) {
Master::Summon(array('Cron_daily'));
}
@@ -192,14 +199,14 @@ class Cron {
$r = q("select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = ''
and xchan_photo_date < %s - INTERVAL %s",
- db_utcnow(),
+ db_utcnow(),
db_quoteinterval('1 DAY')
);
- if($r) {
+ if ($r) {
require_once('include/photo/photo_driver.php');
- foreach($r as $rr) {
+ foreach ($r as $rr) {
$photos = import_xchan_photo($rr['xchan_photo_l'], $rr['xchan_hash'], false, true);
- $x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
+ $x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
where xchan_hash = '%s'",
dbesc($photos[0]),
dbesc($photos[1]),
@@ -213,18 +220,18 @@ class Cron {
// pull in some public posts
- $disable_discover_tab = get_config('system','disable_discover_tab') || get_config('system','disable_discover_tab') === false;
- if(! $disable_discover_tab)
+ $disable_discover_tab = get_config('system', 'disable_discover_tab') || get_config('system', 'disable_discover_tab') === false;
+ if (!$disable_discover_tab)
Master::Summon(array('Externals'));
$generation = 0;
- $restart = false;
+ $restart = false;
- if(($argc > 1) && ($argv[1] == 'restart')) {
- $restart = true;
+ if (($argc > 1) && ($argv[1] == 'restart')) {
+ $restart = true;
$generation = intval($argv[2]);
- if(! $generation)
+ if (!$generation)
return;
}
@@ -234,10 +241,10 @@ class Cron {
// TODO check to see if there are any cronhooks before wasting a process
- if(! $restart)
+ if (!$restart)
Master::Summon(array('Cronhooks'));
- set_config('system','lastcron',datetime_convert());
+ set_config('system', 'lastcron', datetime_convert());
//All done - clear the lockfile
@unlink($lockfile);
diff --git a/Zotlabs/Daemon/Cron_daily.php b/Zotlabs/Daemon/Cron_daily.php
index 07533cc6e..1983c68e6 100644
--- a/Zotlabs/Daemon/Cron_daily.php
+++ b/Zotlabs/Daemon/Cron_daily.php
@@ -2,9 +2,11 @@
namespace Zotlabs\Daemon;
+use Zotlabs\Lib\Libzotdir;
+
class Cron_daily {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
logger('cron_daily: start');
@@ -13,15 +15,12 @@ class Cron_daily {
*
*/
-
- require_once('include/dir_fns.php');
- check_upstream_directory();
-
+ Libzotdir::check_upstream_directory();
// Fire off the Cron_weekly process if it's the correct day.
-
- $d3 = intval(datetime_convert('UTC','UTC','now','N'));
- if($d3 == 7) {
+
+ $d3 = intval(datetime_convert('UTC', 'UTC', 'now', 'N'));
+ if ($d3 == 7) {
Master::Summon(array('Cron_weekly'));
}
@@ -52,8 +51,8 @@ class Cron_daily {
// Clean up emdedded content cache
q("DELETE FROM cache WHERE updated < %s - INTERVAL %s",
- db_utcnow(),
- db_quoteinterval(get_config('system','active_expire_days', '30') . ' DAY')
+ db_utcnow(),
+ db_quoteinterval(get_config('system', 'active_expire_days', '30') . ' DAY')
);
//update statistics in config
@@ -67,8 +66,8 @@ class Cron_daily {
// expire old delivery reports
- $keep_reports = intval(get_config('system','expire_delivery_reports'));
- if($keep_reports === 0)
+ $keep_reports = intval(get_config('system', 'expire_delivery_reports'));
+ if ($keep_reports === 0)
$keep_reports = 10;
q("delete from dreport where dreport_time < %s - INTERVAL %s",
@@ -80,18 +79,16 @@ class Cron_daily {
downgrade_accounts();
// If this is a directory server, request a sync with an upstream
- // directory at least once a day, up to once every poll interval.
+ // directory at least once a day, up to once every poll interval.
// Pull remote changes and push local changes.
- // potential issue: how do we keep from creating an endless update loop?
+ // potential issue: how do we keep from creating an endless update loop?
- $dirmode = get_config('system','directory_mode');
+ $dirmode = get_config('system', 'directory_mode');
- if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
- require_once('include/dir_fns.php');
- sync_directories($dirmode);
+ if ($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
+ Libzotdir::sync_directories($dirmode);
}
-
Master::Summon(array('Expire'));
Master::Summon(array('Cli_suggest'));
@@ -99,9 +96,10 @@ class Cron_daily {
z6_discover();
- call_hooks('cron_daily',datetime_convert());
+ $date = datetime_convert();
+ call_hooks('cron_daily', $date);
- set_config('system','last_expire_day',intval(datetime_convert('UTC','UTC','now','d')));
+ set_config('system', 'last_expire_day', intval(datetime_convert('UTC', 'UTC', 'now', 'd')));
/**
* End Cron Daily
diff --git a/Zotlabs/Daemon/Cron_weekly.php b/Zotlabs/Daemon/Cron_weekly.php
index d44400767..407aa40ef 100644
--- a/Zotlabs/Daemon/Cron_weekly.php
+++ b/Zotlabs/Daemon/Cron_weekly.php
@@ -4,21 +4,22 @@ namespace Zotlabs\Daemon;
class Cron_weekly {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
/**
* Cron Weekly
- *
+ *
* Actions in the following block are executed once per day only on Sunday (once per week).
*
*/
- call_hooks('cron_weekly',datetime_convert());
+ $date = datetime_convert();
+ call_hooks('cron_weekly', $date);
z_check_cert();
prune_hub_reinstalls();
-
+
mark_orphan_hubsxchans();
// Find channels that were removed in the last three weeks, but
@@ -31,8 +32,8 @@ class Cron_weekly {
db_utcnow(), db_quoteinterval('21 DAY'),
db_utcnow(), db_quoteinterval('10 DAY')
);
- if($r) {
- foreach($r as $rv) {
+ if ($r) {
+ foreach ($r as $rv) {
channel_remove_final($rv['channel_id']);
}
}
@@ -43,14 +44,14 @@ class Cron_weekly {
db_utcnow(), db_quoteinterval('14 DAY')
);
- $dirmode = intval(get_config('system','directory_mode'));
- if($dirmode === DIRECTORY_MODE_SECONDARY || $dirmode === DIRECTORY_MODE_PRIMARY) {
- logger('regdir: ' . print_r(z_fetch_url(get_directory_primary() . '/regdir?f=&url=' . urlencode(z_root()) . '&realm=' . urlencode(get_directory_realm())),true));
+ $dirmode = intval(get_config('system', 'directory_mode'));
+ if ($dirmode === DIRECTORY_MODE_SECONDARY || $dirmode === DIRECTORY_MODE_PRIMARY) {
+ logger('regdir: ' . print_r(z_fetch_url(get_directory_primary() . '/regdir?f=&url=' . urlencode(z_root()) . '&realm=' . urlencode(get_directory_realm())), true));
}
// Check for dead sites
Master::Summon(array('Checksites'));
-
+
// update searchable doc indexes
Master::Summon(array('Importdoc'));
diff --git a/Zotlabs/Daemon/CurlAuth.php b/Zotlabs/Daemon/CurlAuth.php
index de41382e3..2396da9aa 100644
--- a/Zotlabs/Daemon/CurlAuth.php
+++ b/Zotlabs/Daemon/CurlAuth.php
@@ -2,6 +2,8 @@
namespace Zotlabs\Daemon;
+use App;
+
// generate a curl compatible cookie file with an authenticated session for the given channel_id.
// If this file is then used with curl and the destination url is sent through zid() or manually
// manipulated to add a zid, it should allow curl to provide zot magic-auth across domains.
@@ -10,15 +12,15 @@ namespace Zotlabs\Daemon;
class CurlAuth {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
- if($argc != 2)
+ if ($argc != 2)
return;
- \App::$session->start();
+ App::$session->start();
$_SESSION['authenticated'] = 1;
- $_SESSION['uid'] = $argv[1];
+ $_SESSION['uid'] = $argv[1];
$x = session_id();
@@ -29,14 +31,14 @@ class CurlAuth {
$output = '';
- if($e) {
+ if ($e) {
$lines = file($f);
- if($lines) {
- foreach($lines as $line) {
- if(strlen($line) > 0 && $line[0] != '#' && substr_count($line, "\t") == 6) {
+ if ($lines) {
+ foreach ($lines as $line) {
+ if (strlen($line) > 0 && $line[0] != '#' && substr_count($line, "\t") == 6) {
$tokens = explode("\t", $line);
$tokens = array_map('trim', $tokens);
- if($tokens[4] > time()) {
+ if ($tokens[4] > time()) {
$output .= $line . "\n";
}
}
@@ -46,9 +48,9 @@ class CurlAuth {
}
}
$t = time() + (24 * 3600);
- file_put_contents($f, $output . 'HttpOnly_' . \App::get_hostname() . "\tFALSE\t/\tTRUE\t$t\tPHPSESSID\t" . $x, (($e) ? FILE_APPEND : 0));
+ file_put_contents($f, $output . 'HttpOnly_' . App::get_hostname() . "\tFALSE\t/\tTRUE\t$t\tPHPSESSID\t" . $x, (($e) ? FILE_APPEND : 0));
- file_put_contents($c,$x);
+ file_put_contents($c, $x);
return;
}
diff --git a/Zotlabs/Daemon/Deliver.php b/Zotlabs/Daemon/Deliver.php
index c853af6a8..f8149ee69 100644
--- a/Zotlabs/Daemon/Deliver.php
+++ b/Zotlabs/Daemon/Deliver.php
@@ -5,25 +5,25 @@ namespace Zotlabs\Daemon;
require_once('include/queue_fn.php');
class Deliver {
-
- static public function run($argc,$argv) {
- if($argc < 2)
+ static public function run($argc, $argv) {
+
+ if ($argc < 2)
return;
- logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA);
+ logger('deliver: invoked: ' . print_r($argv, true), LOGGER_DATA);
- for($x = 1; $x < $argc; $x ++) {
+ for ($x = 1; $x < $argc; $x++) {
- if(! $argv[$x])
+ if (!$argv[$x])
continue;
$r = q("select * from outq where outq_hash = '%s'",
dbesc($argv[$x])
);
- if($r) {
- queue_deliver($r[0],true);
+ if ($r) {
+ queue_deliver($r[0], true);
}
}
diff --git a/Zotlabs/Daemon/Deliver_hooks.php b/Zotlabs/Daemon/Deliver_hooks.php
index e8b5acef0..4d3ce4e1d 100644
--- a/Zotlabs/Daemon/Deliver_hooks.php
+++ b/Zotlabs/Daemon/Deliver_hooks.php
@@ -2,21 +2,18 @@
namespace Zotlabs\Daemon;
-require_once('include/zot.php');
-
class Deliver_hooks {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
- if($argc < 2)
+ if ($argc < 2)
return;
-
$r = q("select * from item where id = '%d'",
intval($argv[1])
);
- if($r)
- call_hooks('notifier_normal',$r[0]);
+ if ($r)
+ call_hooks('notifier_normal', $r[0]);
}
}
diff --git a/Zotlabs/Daemon/Directory.php b/Zotlabs/Daemon/Directory.php
index ab58432de..1f307b273 100644
--- a/Zotlabs/Daemon/Directory.php
+++ b/Zotlabs/Daemon/Directory.php
@@ -8,40 +8,40 @@ use Zotlabs\Lib\Queue;
class Directory {
- static public function run($argc,$argv){
+ static public function run($argc, $argv) {
- if($argc < 2)
+ if ($argc < 2)
return;
- $force = false;
+ $force = false;
$pushall = true;
- if($argc > 2) {
- if($argv[2] === 'force')
+ if ($argc > 2) {
+ if ($argv[2] === 'force')
$force = true;
- if($argv[2] === 'nopush')
+ if ($argv[2] === 'nopush')
$pushall = false;
- }
+ }
logger('directory update', LOGGER_DEBUG);
- $dirmode = get_config('system','directory_mode');
- if($dirmode === false)
+ $dirmode = get_config('system', 'directory_mode');
+ if ($dirmode === false)
$dirmode = DIRECTORY_MODE_NORMAL;
$x = q("select * from channel where channel_id = %d limit 1",
intval($argv[1])
);
- if(! $x)
+ if (!$x)
return;
$channel = $x[0];
- if($dirmode != DIRECTORY_MODE_NORMAL) {
+ if ($dirmode != DIRECTORY_MODE_NORMAL) {
// this is an in-memory update and we don't need to send a network packet.
- Libzotdir::local_dir_update($argv[1],$force);
+ Libzotdir::local_dir_update($argv[1], $force);
q("update channel set channel_dirdate = '%s' where channel_id = %d",
dbesc(datetime_convert()),
@@ -49,8 +49,8 @@ class Directory {
);
// Now update all the connections
- if($pushall)
- Master::Summon(array('Notifier','refresh_all',$channel['channel_id']));
+ if ($pushall)
+ Master::Summon(array('Notifier', 'refresh_all', $channel['channel_id']));
return;
}
@@ -63,14 +63,12 @@ class Directory {
// ensure the upstream directory is updated
-
- $packet = Libzot::build_packet($channel,(($force) ? 'force_refresh' : 'refresh'));
- $z = Libzot::zot($url,$packet,$channel);
-
+ $packet = Libzot::build_packet($channel, (($force) ? 'force_refresh' : 'refresh'));
+ $z = Libzot::zot($url, $packet, $channel);
// re-queue if unsuccessful
- if(! $z['success']) {
+ if (!$z['success']) {
/** @FIXME we aren't updating channel_dirdate if we have to queue
* the directory packet. That means we'll try again on the next poll run.
@@ -95,8 +93,8 @@ class Directory {
}
// Now update all the connections
- if($pushall)
- Master::Summon(array('Notifier','refresh_all',$channel['channel_id']));
+ if ($pushall)
+ Master::Summon(array('Notifier', 'refresh_all', $channel['channel_id']));
}
}
diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php
index a688d6f97..8ca92b6c5 100644
--- a/Zotlabs/Daemon/Expire.php
+++ b/Zotlabs/Daemon/Expire.php
@@ -5,23 +5,24 @@ namespace Zotlabs\Daemon;
class Expire {
- static public function run($argc,$argv){
+ static public function run($argc, $argv) {
cli_startup();
-
+
$pid = get_config('expire', 'procid', false);
if ($pid && (function_exists('posix_kill') ? posix_kill($pid, 0) : true)) {
- logger('Expire: procedure already run with pid ' . $pid, LOGGER_DEBUG);
- return;
+ logger('Expire: procedure already run with pid ' . $pid, LOGGER_DEBUG);
+ return;
}
-
+
$pid = getmypid();
set_config('expire', 'procid', $pid);
// perform final cleanup on previously delete items
$r = q("select id from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s",
- db_utcnow(), db_quoteinterval('10 DAY')
+ db_utcnow(),
+ db_quoteinterval('10 DAY')
);
if ($r) {
foreach ($r as $rr) {
@@ -32,23 +33,22 @@ class Expire {
// physically remove anything that has been deleted for more than two months
/** @FIXME - this is a wretchedly inefficient query */
- $r = q("delete from item where item_pending_remove = 1 and changed < %s - INTERVAL %s",
- db_utcnow(), db_quoteinterval('36 DAY')
+ q("delete from item where item_pending_remove = 1 and changed < %s - INTERVAL %s",
+ db_utcnow(),
+ db_quoteinterval('36 DAY')
);
- /** @FIXME make this optional as it could have a performance impact on large sites */
-
if (intval(get_config('system', 'optimize_items')))
q("optimize table item");
logger('expire: start with pid ' . $pid, LOGGER_DEBUG);
- $site_expire = intval(get_config('system', 'default_expire_days'));
- $commented_days = intval(get_config('system','active_expire_days'));
+ $site_expire = intval(get_config('system', 'default_expire_days'));
+ $commented_days = intval(get_config('system', 'active_expire_days'));
logger('site_expire: ' . $site_expire);
- $r = q("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true");
+ $r = dbq("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true");
if ($r) {
foreach ($r as $rr) {
@@ -64,11 +64,12 @@ class Expire {
$channel_expire = $service_class_expire;
else
$channel_expire = $site_expire;
-
+
if (intval($channel_expire) && (intval($channel_expire) < intval($rr['channel_expire_days'])) ||
intval($rr['channel_expire_days'] == 0)) {
$expire_days = $channel_expire;
- } else {
+ }
+ else {
$expire_days = $rr['channel_expire_days'];
}
@@ -93,13 +94,13 @@ class Expire {
}
logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG);
-
+
if ($expire_days)
item_expire($x['channel_id'], $expire_days, $commented_days);
logger('Expire: sys: done', LOGGER_DEBUG);
}
-
+
del_config('expire', 'procid');
}
}
diff --git a/Zotlabs/Daemon/Externals.php b/Zotlabs/Daemon/Externals.php
index a9988a509..b657f9de4 100644
--- a/Zotlabs/Daemon/Externals.php
+++ b/Zotlabs/Daemon/Externals.php
@@ -8,23 +8,22 @@ require_once('include/channel.php');
class Externals {
- static public function run($argc,$argv){
+ static public function run($argc, $argv) {
- $total = 0;
+ $total = 0;
$attempts = 0;
logger('externals: startup', LOGGER_DEBUG);
// pull in some public posts
+ while ($total == 0 && $attempts < 3) {
+ $arr = ['url' => ''];
+ call_hooks('externals_url_select', $arr);
- while($total == 0 && $attempts < 3) {
- $arr = array('url' => '');
- call_hooks('externals_url_select',$arr);
-
- if($arr['url']) {
+ if ($arr['url']) {
$url = $arr['url'];
- }
+ }
else {
$randfunc = db_getfunc('RAND');
@@ -35,36 +34,36 @@ class Externals {
intval(DIRECTORY_MODE_STANDALONE),
intval(SITE_TYPE_ZOT)
);
- if($r)
+ if ($r)
$url = $r[0]['site_url'];
}
$blacklisted = false;
- if(! check_siteallowed($url)) {
+ if (!check_siteallowed($url)) {
logger('blacklisted site: ' . $url);
$blacklisted = true;
}
- $attempts ++;
+ $attempts++;
// make sure we can eventually break out if somebody blacklists all known sites
- if($blacklisted) {
- if($attempts > 20)
+ if ($blacklisted) {
+ if ($attempts > 20)
break;
- $attempts --;
+ $attempts--;
continue;
}
- if($url) {
- if($r[0]['site_pull'] > NULL_DATE)
- $mindate = urlencode(datetime_convert('','',$r[0]['site_pull'] . ' - 1 day'));
+ if ($url) {
+ if ($r[0]['site_pull'] > NULL_DATE)
+ $mindate = urlencode(datetime_convert('', '', $r[0]['site_pull'] . ' - 1 day'));
else {
- $days = get_config('externals','since_days');
- if($days === false)
+ $days = get_config('externals', 'since_days');
+ if ($days === false)
$days = 15;
- $mindate = urlencode(datetime_convert('','','now - ' . intval($days) . ' days'));
+ $mindate = urlencode(datetime_convert('', '', 'now - ' . intval($days) . ' days'));
}
$feedurl = $url . '/zotfeed?f=&mindate=' . $mindate;
@@ -72,22 +71,22 @@ class Externals {
logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG);
$x = z_fetch_url($feedurl);
- if(($x) && ($x['success'])) {
+ if (($x) && ($x['success'])) {
q("update site set site_pull = '%s' where site_url = '%s'",
dbesc(datetime_convert()),
dbesc($url)
);
- $j = json_decode($x['body'],true);
- if($j['success'] && $j['messages']) {
+ $j = json_decode($x['body'], true);
+ if ($j['success'] && $j['messages']) {
$sys = get_sys_channel();
- foreach($j['messages'] as $message) {
+ foreach ($j['messages'] as $message) {
// on these posts, clear any route info.
$message['route'] = '';
- $results = process_delivery(array('hash' => 'undefined'), get_item_elements($message),
- array(array('hash' => $sys['xchan_hash'])), false, true);
- $total ++;
+ process_delivery(['hash' => 'undefined'], get_item_elements($message),
+ [['hash' => $sys['xchan_hash']]], false, true);
+ $total++;
}
logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
}
diff --git a/Zotlabs/Daemon/Gprobe.php b/Zotlabs/Daemon/Gprobe.php
index 9e74eb8b5..29efcf475 100644
--- a/Zotlabs/Daemon/Gprobe.php
+++ b/Zotlabs/Daemon/Gprobe.php
@@ -9,27 +9,27 @@ use Zotlabs\Lib\Zotfinger;
// performs zot_finger on $argv[1], which is a hex_encoded webbie/reddress
class Gprobe {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
- if($argc != 2)
+ if ($argc != 2)
return;
$url = hex2bin($argv[1]);
- if(! strpos($url,'@'))
+ if (!strpos($url, '@'))
return;
$r = q("select * from hubloc where hubloc_addr = '%s' and hubloc_network = 'zot6' limit 1",
dbesc($url)
);
- if(! $r) {
+ if (!$r) {
$href = Webfinger::zot_url(punify($url));
- if($href) {
+ if ($href) {
$zf = Zotfinger::exec($href, null);
}
- if(is_array($zf) && array_path_exists('signature/signer',$zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) {
- $xc = Libzot::import_xchan($zf['data']);
+ if (is_array($zf) && array_path_exists('signature/signer', $zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) {
+ Libzot::import_xchan($zf['data']);
}
}
diff --git a/Zotlabs/Daemon/Importdoc.php b/Zotlabs/Daemon/Importdoc.php
index 0ca589e4a..9e818e2b3 100755
--- a/Zotlabs/Daemon/Importdoc.php
+++ b/Zotlabs/Daemon/Importdoc.php
@@ -5,7 +5,7 @@ namespace Zotlabs\Daemon;
class Importdoc {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
require_once('include/help.php');
@@ -16,20 +16,20 @@ class Importdoc {
static public function update_docs_dir($s) {
$f = basename($s);
$d = dirname($s);
- if($s === 'doc/html')
+ if ($s === 'doc/html')
return;
$files = glob("$d/$f");
- if($files) {
- foreach($files as $fi) {
- if($fi === 'doc/html') {
+ if ($files) {
+ foreach ($files as $fi) {
+ if ($fi === 'doc/html') {
continue;
}
- if(is_dir($fi)) {
+ if (is_dir($fi)) {
self::update_docs_dir("$fi/*");
}
else {
// don't update media content
- if(strpos(z_mime_content_type($fi),'text') === 0) {
+ if (strpos(z_mime_content_type($fi), 'text') === 0) {
store_doc_file($fi);
}
}
diff --git a/Zotlabs/Daemon/Importfile.php b/Zotlabs/Daemon/Importfile.php
index 749949679..299fb1ee5 100644
--- a/Zotlabs/Daemon/Importfile.php
+++ b/Zotlabs/Daemon/Importfile.php
@@ -6,22 +6,21 @@ use Zotlabs\Lib\Libsync;
class Importfile {
- static public function run($argc,$argv){
+ static public function run($argc, $argv) {
- logger('Importfile: ' . print_r($argv,true));
+ logger('Importfile: ' . print_r($argv, true));
- if($argc < 3)
+ if ($argc < 3)
return;
$channel = channelx_by_n($argv[1]);
- if(! $channel)
+ if (!$channel)
return;
$srcfile = $argv[2];
$folder = (($argc > 3) ? $argv[3] : '');
$dstname = (($argc > 4) ? $argv[4] : '');
-
- $hash = random_string();
+ $hash = random_string();
$arr = [
'src' => $srcfile,
@@ -35,15 +34,15 @@ class Importfile {
'replace' => true
];
- if($folder)
+ if ($folder)
$arr['folder'] = $folder;
- attach_store($channel,$channel['channel_hash'],'import',$arr);
+ attach_store($channel, $channel['channel_hash'], 'import', $arr);
+
+ $sync = attach_export_data($channel, $hash);
+ if ($sync)
+ Libsync::build_sync_packet($channel['channel_id'], ['file' => [$sync]]);
- $sync = attach_export_data($channel,$hash);
- if($sync)
- Libsync::build_sync_packet($channel['channel_id'],array('file' => array($sync)));
-
return;
}
}
diff --git a/Zotlabs/Daemon/Master.php b/Zotlabs/Daemon/Master.php
index 8c3a7e570..6fa656be5 100644
--- a/Zotlabs/Daemon/Master.php
+++ b/Zotlabs/Daemon/Master.php
@@ -2,58 +2,57 @@
namespace Zotlabs\Daemon;
-if(array_search( __file__ , get_included_files()) === 0) {
+if (array_search(__file__, get_included_files()) === 0) {
require_once('include/cli_startup.php');
array_shift($argv);
$argc = count($argv);
- if($argc)
- Master::Release($argc,$argv);
+ if ($argc)
+ Master::Release($argc, $argv);
return;
}
-
class Master {
static public function Summon($arr) {
$hookinfo = [
- 'argv'=>$arr
+ 'argv' => $arr
];
- call_hooks ('daemon_master_summon',$hookinfo);
+ call_hooks('daemon_master_summon', $hookinfo);
- $arr = $hookinfo['argv'];
+ $arr = $hookinfo['argv'];
$argc = count($arr);
- if ((!is_array($arr) || (count($arr) < 1))) {
- logger("Summon handled by hook.",LOGGER_DEBUG);
+ if ((!is_array($arr) || ($argc < 1))) {
+ logger("Summon handled by hook.", LOGGER_DEBUG);
return;
}
- $phpbin = get_config('system','phpbin','php');
- proc_run($phpbin,'Zotlabs/Daemon/Master.php',$arr);
+ $phpbin = get_config('system', 'phpbin', 'php');
+ proc_run($phpbin, 'Zotlabs/Daemon/Master.php', $arr);
}
- static public function Release($argc,$argv) {
+ static public function Release($argc, $argv) {
cli_startup();
$hookinfo = [
- 'argv'=>$argv
+ 'argv' => $argv
];
- call_hooks ('daemon_master_release',$hookinfo);
+ call_hooks('daemon_master_release', $hookinfo);
$argv = $hookinfo['argv'];
$argc = count($argv);
- if ((!is_array($argv) || (count($argv) < 1))) {
- logger("Release handled by hook.",LOGGER_DEBUG);
+ if ((!is_array($argv) || ($argc < 1))) {
+ logger("Release handled by hook.", LOGGER_DEBUG);
return;
}
- logger('Master: release: ' . json_encode($argv), LOGGER_ALL,LOG_DEBUG);
- $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
- $cls::run($argc,$argv);
+ logger('Master: release: ' . json_encode($argv), LOGGER_ALL, LOG_DEBUG);
+ $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
+ $cls::run($argc, $argv);
}
}
diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php
index 18fc57118..78e116d68 100644
--- a/Zotlabs/Daemon/Notifier.php
+++ b/Zotlabs/Daemon/Notifier.php
@@ -14,7 +14,6 @@ require_once('include/items.php');
require_once('include/bbcode.php');
-
/*
* This file was at one time responsible for doing all deliveries, but this caused
* big problems on shared hosting systems, where the process might get killed by the
@@ -81,198 +80,198 @@ require_once('include/bbcode.php');
*/
-
class Notifier {
- static public function run($argc,$argv){
+ static public function run($argc, $argv) {
- if($argc < 3)
+ if ($argc < 3)
return;
- logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
+ logger('notifier: invoked: ' . print_r($argv, true), LOGGER_DEBUG);
$cmd = $argv[1];
$item_id = $argv[2];
- if(! $item_id)
+ if (!$item_id)
return;
$sys = get_sys_channel();
- $deliveries = array();
+ $deliveries = [];
- $request = false;
- $mail = false;
- $top_level = false;
- $location = false;
- $recipients = array();
- $url_recipients = array();
- $normal_mode = true;
- $packet_type = 'undefined';
+ $request = false;
+ $mail = false;
+ $location = false;
+ $recipients = [];
+ $normal_mode = true;
+ $packet_type = 'undefined';
- if($cmd === 'mail' || $cmd === 'single_mail') {
+ if ($cmd === 'mail' || $cmd === 'single_mail') {
$normal_mode = false;
- $mail = true;
- $private = true;
- $message = q("SELECT * FROM mail WHERE id = %d LIMIT 1",
- intval($item_id)
+ $mail = true;
+ $private = true;
+ $message = q("SELECT * FROM mail WHERE id = %d LIMIT 1",
+ intval($item_id)
);
- if(! $message) {
+ if (!$message) {
return;
}
xchan_mail_query($message[0]);
- $uid = $message[0]['channel_id'];
+ $uid = $message[0]['channel_id'];
$recipients[] = $message[0]['from_xchan']; // include clones
$recipients[] = $message[0]['to_xchan'];
- $item = $message[0];
-
+ $item = $message[0];
$encoded_item = encode_mail($item);
$s = q("select * from channel where channel_id = %d limit 1",
- intval($item['channel_id'])
+ intval($uid)
);
- if($s)
+ if ($s)
$channel = $s[0];
}
- elseif($cmd === 'request') {
- $channel_id = $item_id;
- $xchan = $argv[3];
+ elseif ($cmd === 'request') {
+ $channel_id = $item_id;
+ $xchan = $argv[3];
$request_message_id = $argv[4];
$s = q("select * from channel where channel_id = %d limit 1",
intval($channel_id)
);
- if($s)
+ if ($s)
$channel = $s[0];
- $private = true;
+ $private = true;
$recipients[] = $xchan;
- $packet_type = 'request';
- $normal_mode = false;
+ $packet_type = 'request';
+ $normal_mode = false;
}
- elseif($cmd === 'keychange') {
+ elseif ($cmd === 'keychange') {
$channel = channelx_by_n($item_id);
- $r = q("select abook_xchan from abook where abook_channel = %d",
+
+ $r = q("select abook_xchan from abook where abook_channel = %d",
intval($item_id)
);
- if($r) {
- foreach($r as $rr) {
+ if ($r) {
+ foreach ($r as $rr) {
$recipients[] = $rr['abook_xchan'];
}
}
- $private = false;
+ $private = false;
$packet_type = 'keychange';
$normal_mode = false;
}
- elseif(in_array($cmd, [ 'permission_update', 'permission_reject', 'permission_accept', 'permission_create' ])) {
+ elseif (in_array($cmd, ['permission_update', 'permission_reject', 'permission_accept', 'permission_create'])) {
// Get the (single) recipient
$r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_self = 0",
intval($item_id)
);
- if($r) {
+ if ($r) {
$uid = $r[0]['abook_channel'];
// Get the sender
$channel = channelx_by_n($uid);
- if($channel) {
- $perm_update = array('sender' => $channel, 'recipient' => $r[0], 'success' => false, 'deliveries' => '');
-
- if($cmd === 'permission_create')
- call_hooks('permissions_create',$perm_update);
- elseif($cmd === 'permission_accept')
- call_hooks('permissions_accept',$perm_update);
- elseif($cmd === 'permission_reject')
- call_hooks('permissions_reject',$perm_update);
+ if ($channel) {
+ $perm_update = ['sender' => $channel, 'recipient' => $r[0], 'success' => false, 'deliveries' => ''];
+
+ if ($cmd === 'permission_create')
+ call_hooks('permissions_create', $perm_update);
+ elseif ($cmd === 'permission_accept')
+ call_hooks('permissions_accept', $perm_update);
+ elseif ($cmd === 'permission_reject')
+ call_hooks('permissions_reject', $perm_update);
else
- call_hooks('permissions_update',$perm_update);
+ call_hooks('permissions_update', $perm_update);
- if($perm_update['success']) {
- if($perm_update['deliveries']) {
+ if ($perm_update['success']) {
+ if ($perm_update['deliveries']) {
$deliveries[] = $perm_update['deliveries'];
do_delivery($deliveries);
}
return;
}
else {
- $recipients[] = $r[0]['abook_xchan'];
- $private = false;
- $packet_type = 'refresh';
- $packet_recips = array(array('guid' => $r[0]['xchan_guid'],'guid_sig' => $r[0]['xchan_guid_sig'],'hash' => $r[0]['xchan_hash']));
+ $recipients[] = $r[0]['abook_xchan'];
+ $private = false;
+ $packet_type = 'refresh';
+ $packet_recips = [['guid' => $r[0]['xchan_guid'], 'guid_sig' => $r[0]['xchan_guid_sig'], 'hash' => $r[0]['xchan_hash']]];
}
}
}
}
- elseif($cmd === 'refresh_all') {
+ elseif ($cmd === 'refresh_all') {
logger('notifier: refresh_all: ' . $item_id);
- $uid = $item_id;
+ $uid = $item_id;
$channel = channelx_by_n($item_id);
- $r = q("select abook_xchan from abook where abook_channel = %d",
- intval($item_id)
+
+ $r = q("select abook_xchan from abook where abook_channel = %d",
+ intval($uid)
);
- if($r) {
- foreach($r as $rr) {
+ if ($r) {
+ foreach ($r as $rr) {
$recipients[] = $rr['abook_xchan'];
}
}
- $private = false;
+ $private = false;
$packet_type = 'refresh';
}
- elseif($cmd === 'location') {
+ elseif ($cmd === 'location') {
logger('notifier: location: ' . $item_id);
$s = q("select * from channel where channel_id = %d limit 1",
intval($item_id)
);
- if($s)
+ if ($s)
$channel = $s[0];
- $uid = $item_id;
- $recipients = array();
- $r = q("select abook_xchan from abook where abook_channel = %d",
- intval($item_id)
+
+ $uid = $item_id;
+ $recipients = [];
+
+ $r = q("select abook_xchan from abook where abook_channel = %d",
+ intval($uid)
);
- if($r) {
- foreach($r as $rr) {
+ if ($r) {
+ foreach ($r as $rr) {
$recipients[] = $rr['abook_xchan'];
}
}
- $encoded_item = array('locations' => Libzot::encode_locations($channel),'type' => 'location', 'encoding' => 'zot');
- $target_item = array('aid' => $channel['channel_account_id'],'uid' => $channel['channel_id']);
- $private = false;
- $packet_type = 'location';
- $location = true;
+ $encoded_item = ['locations' => Libzot::encode_locations($channel), 'type' => 'location', 'encoding' => 'zot'];
+ $target_item = ['aid' => $channel['channel_account_id'], 'uid' => $channel['channel_id']];
+ $private = false;
+ $packet_type = 'location';
+ $location = true;
}
- elseif($cmd === 'purge') {
+ elseif ($cmd === 'purge') {
$xchan = $argv[3];
logger('notifier: purge: ' . $item_id . ' => ' . $xchan);
- if (! $xchan) {
+ if (!$xchan) {
return;
}
- $channel = channelx_by_n($item_id);
- $recipients[] = $xchan;
- $private = true;
- $packet_type = 'purge';
+ $channel = channelx_by_n($item_id);
+ $recipients[] = $xchan;
+ $private = true;
+ $packet_type = 'purge';
$packet_recips[] = ['hash' => $xchan];
}
- elseif($cmd === 'purge_all') {
+ elseif ($cmd === 'purge_all') {
logger('notifier: purge_all: ' . $item_id);
$channel = channelx_by_n($item_id);
$recipients = [];
- $r = q("select abook_xchan from abook where abook_channel = %d and abook_self = 0",
+ $r = q("select abook_xchan from abook where abook_channel = %d and abook_self = 0",
intval($item_id)
);
- if (! $r) {
+ if (!$r) {
return;
}
foreach ($r as $rr) {
- $recipients[] = $rr['abook_xchan'];
+ $recipients[] = $rr['abook_xchan'];
$packet_recips[] = ['hash' => $rr['abook_xchan']];
}
- $private = false;
+ $private = false;
$packet_type = 'purge';
@@ -287,7 +286,7 @@ class Notifier {
intval($item_id)
);
- if(! $r)
+ if (!$r)
return;
xchan_query($r);
@@ -296,25 +295,22 @@ class Notifier {
$target_item = $r[0];
- if(in_array($target_item['author']['xchan_network'], ['rss', 'anon'])) {
+ if (in_array($target_item['author']['xchan_network'], ['rss', 'anon'])) {
logger('notifier: target item author is not a fetchable actor', LOGGER_DEBUG);
return;
}
- $deleted_item = false;
-
- if(intval($target_item['item_deleted'])) {
+ if (intval($target_item['item_deleted'])) {
logger('notifier: target item ITEM_DELETED', LOGGER_DEBUG);
- $deleted_item = true;
}
- if(! in_array(intval($target_item['item_type']), [ ITEM_TYPE_POST ] )) {
- $hookinfo=[
- 'targetitem'=>$target_item,
- 'deliver'=>false
+ if (!in_array(intval($target_item['item_type']), [ITEM_TYPE_POST])) {
+ $hookinfo = [
+ 'targetitem' => $target_item,
+ 'deliver' => false
];
if (intval($target_item['item_type'] == ITEM_TYPE_CUSTOM)) {
- call_hooks('customitem_deliver',$hookinfo);
+ call_hooks('customitem_deliver', $hookinfo);
}
if (!$hookinfo['deliver']) {
@@ -328,14 +324,14 @@ class Notifier {
// Check for non published items, but allow an exclusion for transmitting hidden file activities
- if(intval($target_item['item_unpublished']) || intval($target_item['item_delayed']) ||
+ if (intval($target_item['item_unpublished']) || intval($target_item['item_delayed']) ||
intval($target_item['item_blocked']) ||
- ( intval($target_item['item_hidden']) && ($target_item['obj_type'] !== ACTIVITY_OBJ_FILE))) {
+ (intval($target_item['item_hidden']) && ($target_item['obj_type'] !== ACTIVITY_OBJ_FILE))) {
logger('notifier: target item not published, so not forwardable', LOGGER_DEBUG);
return;
}
- if(strpos($target_item['postopts'],'nodeliver') !== false) {
+ if (strpos($target_item['postopts'], 'nodeliver') !== false) {
logger('notifier: target item is undeliverable', LOGGER_DEBUG);
return;
}
@@ -343,17 +339,17 @@ class Notifier {
$s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
intval($target_item['uid'])
);
- if($s)
+ if ($s)
$channel = $s[0];
- if($channel['channel_hash'] !== $target_item['author_xchan'] && $channel['channel_hash'] !== $target_item['owner_xchan']) {
+ if ($channel['channel_hash'] !== $target_item['author_xchan'] && $channel['channel_hash'] !== $target_item['owner_xchan']) {
logger("notifier: Sending channel {$channel['channel_hash']} is not owner {$target_item['owner_xchan']} or author {$target_item['author_xchan']}", LOGGER_NORMAL, LOG_WARNING);
return;
}
- if($target_item['mid'] === $target_item['parent_mid']) {
- $parent_item = $target_item;
+ if ($target_item['mid'] === $target_item['parent_mid']) {
+ $parent_item = $target_item;
$top_level_post = true;
}
else {
@@ -362,10 +358,10 @@ class Notifier {
intval($target_item['parent'])
);
- if(! $r)
+ if (!$r)
return;
- if(strpos($r[0]['postopts'],'nodeliver') !== false) {
+ if (strpos($r[0]['postopts'], 'nodeliver') !== false) {
logger('notifier: target item is undeliverable', LOGGER_DEBUG, LOG_NOTICE);
return;
}
@@ -373,34 +369,34 @@ class Notifier {
xchan_query($r);
$r = fetch_post_tags($r);
- $parent_item = $r[0];
+ $parent_item = $r[0];
$top_level_post = false;
}
// avoid looping of discover items 12/4/2014
- if($sys && $parent_item['uid'] == $sys['channel_id'])
+ if ($sys && $parent_item['uid'] == $sys['channel_id'])
return;
$encoded_item = encode_item($target_item);
// Re-use existing signature unless the activity type changed to a Tombstone, which won't verify.
- $m = ((intval($target_item['item_deleted'])) ? '' : get_iconfig($target_item,'activitystreams','signed_data'));
+ $m = ((intval($target_item['item_deleted'])) ? '' : get_iconfig($target_item, 'activitystreams', 'signed_data'));
- if($m) {
- $activity = json_decode($m,true);
+ if ($m) {
+ $activity = json_decode($m, true);
}
else {
$activity = array_merge(['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
'https://w3id.org/security/v1',
z_root() . ZOT_APSCHEMA_REV
- ]], Activity::encode_activity($target_item)
+ ]], Activity::encode_activity($target_item)
);
}
- logger('target_item: ' . print_r($target_item,true), LOGGER_DEBUG);
- logger('encoded: ' . print_r($activity,true), LOGGER_DEBUG);
+ logger('target_item: ' . print_r($target_item, true), LOGGER_DEBUG);
+ logger('encoded: ' . print_r($activity, true), LOGGER_DEBUG);
// Send comments to the owner to re-deliver to everybody in the conversation
// We only do this if the item in question originated on this site. This prevents looping.
@@ -411,9 +407,7 @@ class Notifier {
// flag on comments for an extended period. So we'll also call comment_local_origin() which looks at
// the hostname in the message_id and provides a second (fallback) opinion.
- $relay_to_owner = (((! $top_level_post) && (intval($target_item['item_origin'])) && comment_local_origin($target_item)) ? true : false);
-
-
+ $relay_to_owner = (((!$top_level_post) && (intval($target_item['item_origin'])) && comment_local_origin($target_item)) ? true : false);
$uplink = false;
@@ -425,54 +419,46 @@ class Notifier {
// tag_deliver'd post which needs to be sent back to the original author
- if(($cmd === 'uplink') && intval($parent_item['item_uplink']) && (! $top_level_post)) {
+ if (($cmd === 'uplink') && intval($parent_item['item_uplink']) && (!$top_level_post)) {
logger('notifier: uplink');
$uplink = true;
}
- if(($relay_to_owner || $uplink) && ($cmd !== 'relay')) {
+ if (($relay_to_owner || $uplink) && ($cmd !== 'relay')) {
logger('notifier: followup relay', LOGGER_DEBUG);
- $recipients = array(($uplink) ? $parent_item['source_xchan'] : $parent_item['owner_xchan']);
- $private = true;
- if(! $encoded_item['flags'])
- $encoded_item['flags'] = array();
+ $recipients = [($uplink) ? $parent_item['source_xchan'] : $parent_item['owner_xchan']];
+ $private = true;
+ if (!$encoded_item['flags'])
+ $encoded_item['flags'] = [];
$encoded_item['flags'][] = 'relay';
- $upstream = true;
+ $upstream = true;
}
else {
logger('notifier: normal distribution', LOGGER_DEBUG);
- if($cmd === 'relay')
+ if ($cmd === 'relay')
logger('notifier: owner relay');
$upstream = false;
// if our parent is a tag_delivery recipient, uplink to the original author causing
// a delivery fork.
- if(($parent_item) && intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) {
+ if (($parent_item) && intval($parent_item['item_uplink']) && (!$top_level_post) && ($cmd !== 'uplink')) {
// don't uplink a relayed post to the relay owner
- if($parent_item['source_xchan'] !== $parent_item['owner_xchan']) {
+ if ($parent_item['source_xchan'] !== $parent_item['owner_xchan']) {
logger('notifier: uplinking this item');
- Master::Summon(array('Notifier','uplink',$item_id));
+ Master::Summon(['Notifier', 'uplink', $item_id]);
}
}
- $private = false;
- $recipients = collect_recipients($parent_item,$private);
-
+ $private = false;
+ $recipients = collect_recipients($parent_item, $private);
if ($top_level_post) {
// remove clones who will receive the post via sync
- $recipients = array_diff($recipients, [ $target_item['owner_xchan'] ]);
+ $recipients = array_diff($recipients, [$target_item['owner_xchan']]);
}
// FIXME add any additional recipients such as mentions, etc.
- // don't send deletions onward for other people's stuff
- // TODO verify this is needed - copied logic from same place in old code
-
- if(intval($target_item['item_deleted']) && (! intval($target_item['item_wall']))) {
- logger('notifier: ignoring delete notification for non-wall item', LOGGER_NORMAL, LOG_NOTICE);
- return;
- }
}
}
@@ -481,32 +467,31 @@ class Notifier {
// Generic delivery section, we have an encoded item and recipients
// Now start the delivery process
- $x = $encoded_item;
+ $x = $encoded_item;
$x['title'] = 'private';
- $x['body'] = 'private';
- logger('notifier: encoded item: ' . print_r($x,true), LOGGER_DATA, LOG_DEBUG);
+ $x['body'] = 'private';
+ logger('notifier: encoded item: ' . print_r($x, true), LOGGER_DATA, LOG_DEBUG);
//logger('notifier: encoded activity: ' . print_r($activity,true), LOGGER_DATA, LOG_DEBUG);
stringify_array_elms($recipients);
- if(! $recipients) {
+ if (!$recipients) {
logger('no recipients');
return;
}
// logger('notifier: recipients: ' . print_r($recipients,true), LOGGER_NORMAL, LOG_DEBUG);
- $env_recips = (($private) ? array() : null);
+ $env_recips = (($private) ? [] : null);
- $details = q("select xchan_hash, xchan_network, xchan_addr, xchan_guid, xchan_guid_sig from xchan where xchan_hash in (" . protect_sprintf(implode(',',$recipients)) . ")");
+ $details = q("select xchan_hash, xchan_network, xchan_addr, xchan_guid, xchan_guid_sig from xchan where xchan_hash in (" . protect_sprintf(implode(',', $recipients)) . ")");
- $recip_list = array();
-
- if($details) {
- foreach($details as $d) {
+ $recip_list = [];
+ if ($details) {
+ foreach ($details as $d) {
$recip_list[] = $d['xchan_addr'] . ' (' . $d['xchan_hash'] . ')';
- if($private) {
+ if ($private) {
$env_recips[] = [
'guid' => $d['xchan_guid'],
'guid_sig' => $d['xchan_guid_sig'],
@@ -542,8 +527,8 @@ class Notifier {
];
call_hooks('notifier_process', $narr);
- if($narr['queued']) {
- foreach($narr['queued'] as $pq)
+ if ($narr['queued']) {
+ foreach ($narr['queued'] as $pq)
$deliveries[] = $pq;
}
@@ -553,26 +538,26 @@ class Notifier {
$env_recips = $narr['env_recips'];
$packet_recips = $narr['packet_recips'];
- if(($private) && (! $env_recips)) {
+ if (($private) && (!$env_recips)) {
// shouldn't happen
- logger('notifier: private message with no envelope recipients.' . print_r($argv,true), LOGGER_NORMAL, LOG_NOTICE);
+ logger('notifier: private message with no envelope recipients.' . print_r($argv, true), LOGGER_NORMAL, LOG_NOTICE);
}
- logger('notifier: recipients (may be delivered to more if public): ' . print_r($recip_list,true), LOGGER_DEBUG);
+ logger('notifier: recipients (may be delivered to more if public): ' . print_r($recip_list, true), LOGGER_DEBUG);
// Now we have collected recipients (except for external mentions, FIXME)
// Let's reduce this to a set of hubs; checking that the site is not dead.
$hubs = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_version, site.site_project, site.site_dead from hubloc left join site on site_url = hubloc_url
- where hubloc_hash in (" . protect_sprintf(implode(',',$recipients)) . ")
+ where hubloc_hash in (" . protect_sprintf(implode(',', $recipients)) . ")
and hubloc_error = 0 and hubloc_deleted = 0"
);
// public posts won't make it to the local public stream unless there's a recipient on this site.
// This code block sees if it's a public post and localhost is missing, and if so adds an entry for the local sys channel to the $hubs list
- if (! $private) {
+ if (!$private) {
$found_localhost = false;
if ($hubs) {
foreach ($hubs as $h) {
@@ -582,7 +567,7 @@ class Notifier {
}
}
}
- if (! $found_localhost) {
+ if (!$found_localhost) {
$localhub = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_version, site.site_project, site.site_dead from hubloc
left join site on site_url = hubloc_url where hubloc_id_url = '%s' and hubloc_error = 0 and hubloc_deleted = 0",
dbesc(z_root() . '/channel/sys')
@@ -593,7 +578,7 @@ class Notifier {
}
}
- if(! $hubs) {
+ if (!$hubs) {
logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE);
return;
}
@@ -612,17 +597,17 @@ class Notifier {
$hub_env = []; // per-hub envelope so we don't broadcast the entire envelope to all
$dead = []; // known dead hubs - report them as undeliverable
- foreach($hubs as $hub) {
+ foreach ($hubs as $hub) {
if (intval($hub['site_dead'])) {
$dead[] = $hub;
continue;
}
- if($env_recips) {
- foreach($env_recips as $er) {
- if($hub['hubloc_hash'] === $er['hash']) {
- if(! array_key_exists($hub['hubloc_host'] . $hub['hubloc_sitekey'], $hub_env)) {
+ if ($env_recips) {
+ foreach ($env_recips as $er) {
+ if ($hub['hubloc_hash'] === $er['hash']) {
+ if (!array_key_exists($hub['hubloc_host'] . $hub['hubloc_sitekey'], $hub_env)) {
$hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']] = [];
}
$hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']][] = $er;
@@ -631,36 +616,36 @@ class Notifier {
}
- if($hub['hubloc_network'] == 'zot') {
- if(! in_array($hub['hubloc_sitekey'],$keys)) {
+ if ($hub['hubloc_network'] == 'zot') {
+ if (!in_array($hub['hubloc_sitekey'], $keys)) {
$hublist[] = $hub['hubloc_host'] . ' ' . $hub['hubloc_network'];
$dhubs[] = $hub;
$keys[] = $hub['hubloc_sitekey'];
}
}
else {
- if(! in_array($hub['hubloc_url'],$urls)) {
- if($hub['hubloc_url'] === z_root()) {
+ if (!in_array($hub['hubloc_url'], $urls)) {
+ if ($hub['hubloc_url'] === z_root()) {
//deliver to local hub first
array_unshift($hublist, $hub['hubloc_host'] . ' ' . $hub['hubloc_network']);
array_unshift($dhubs, $hub);
}
else {
$hublist[] = $hub['hubloc_host'] . ' ' . $hub['hubloc_network'];
- $dhubs[] = $hub;
+ $dhubs[] = $hub;
}
$urls[] = $hub['hubloc_url'];
}
}
}
- logger('notifier: will notify/deliver to these hubs: ' . print_r($hublist,true), LOGGER_DEBUG, LOG_DEBUG);
+ logger('notifier: will notify/deliver to these hubs: ' . print_r($hublist, true), LOGGER_DEBUG, LOG_DEBUG);
- foreach($dhubs as $hub) {
+ foreach ($dhubs as $hub) {
- logger('notifier_hub: ' . $hub['hubloc_url'],LOGGER_DEBUG);
+ logger('notifier_hub: ' . $hub['hubloc_url'], LOGGER_DEBUG);
- if(! in_array($hub['hubloc_network'], [ 'zot','zot6' ])) {
+ if (!in_array($hub['hubloc_network'], ['zot', 'zot6'])) {
$narr = [
'channel' => $channel,
'upstream' => $upstream,
@@ -687,9 +672,9 @@ class Notifier {
];
- call_hooks('notifier_hub',$narr);
- if($narr['queued']) {
- foreach($narr['queued'] as $pq)
+ call_hooks('notifier_hub', $narr);
+ if ($narr['queued']) {
+ foreach ($narr['queued'] as $pq)
$deliveries[] = $pq;
}
continue;
@@ -705,11 +690,11 @@ class Notifier {
// will invoke a delivery to those connections which are connected to just that
// hub instance.
- if($cmd === 'single_mail' || $cmd === 'single_activity') {
+ if ($cmd === 'single_mail' || $cmd === 'single_activity') {
continue;
}
- if(! in_array($hub['hubloc_network'], [ 'zot','zot6' ])) {
+ if (!in_array($hub['hubloc_network'], ['zot', 'zot6'])) {
continue;
}
@@ -717,31 +702,31 @@ class Notifier {
// in the loop. The signature verification step can't handle dashes in the
// hashes.
- $hash = random_string(48);
+ $hash = random_string(48);
$packet = null;
$pmsg = '';
- if($packet_type === 'refresh' || $packet_type === 'purge') {
- if($hub['hubloc_network'] === 'zot6') {
- $packet = Libzot::build_packet($channel, $packet_type, ids_to_array($packet_recips,'hash'));
+ if ($packet_type === 'refresh' || $packet_type === 'purge') {
+ if ($hub['hubloc_network'] === 'zot6') {
+ $packet = Libzot::build_packet($channel, $packet_type, ids_to_array($packet_recips, 'hash'));
}
else {
- $packet = zot_build_packet($channel,$packet_type,(($packet_recips) ? $packet_recips : null));
+ $packet = zot_build_packet($channel, $packet_type, (($packet_recips) ? $packet_recips : null));
}
}
- if($packet_type === 'keychange' && $hub['hubloc_network'] === 'zot') {
- $pmsg = get_pconfig($channel['channel_id'],'system','keychange');
- $packet = zot_build_packet($channel,$packet_type,(($packet_recips) ? $packet_recips : null));
+ if ($packet_type === 'keychange' && $hub['hubloc_network'] === 'zot') {
+ $pmsg = get_pconfig($channel['channel_id'], 'system', 'keychange');
+ $packet = zot_build_packet($channel, $packet_type, (($packet_recips) ? $packet_recips : null));
}
- elseif($packet_type === 'request' && $hub['hubloc_network'] === 'zot') {
- $env = (($hub_env && $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']]) ? $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']] : '');
- $packet = zot_build_packet($channel,$packet_type,$env,$hub['hubloc_sitekey'],$hub['site_crypto'],
- $hash, array('message_id' => $request_message_id)
+ elseif ($packet_type === 'request' && $hub['hubloc_network'] === 'zot') {
+ $env = (($hub_env && $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']]) ? $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']] : '');
+ $packet = zot_build_packet($channel, $packet_type, $env, $hub['hubloc_sitekey'], $hub['site_crypto'],
+ $hash, ['message_id' => $request_message_id]
);
}
- if($packet) {
+ if ($packet) {
Queue::insert(
[
'hash' => $hash,
@@ -757,11 +742,10 @@ class Notifier {
else {
$env = (($hub_env && $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']]) ? $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']] : '');
-
- if($hub['hubloc_network'] === 'zot6') {
+ if ($hub['hubloc_network'] === 'zot6') {
$zenv = [];
- if($env) {
- foreach($env as $e) {
+ if ($env) {
+ foreach ($env as $e) {
$zenv[] = $e['hash'];
}
}
@@ -774,11 +758,11 @@ class Notifier {
// For public reshares, some comments to the reshare on the zot fork will not make it to zot6
// due to these different message models. This cannot be prevented at this time.
- if($packet_type === 'activity' && $activity['type'] === 'Announce' && intval($target_item['item_private'])) {
+ if ($packet_type === 'activity' && $activity['type'] === 'Announce' && intval($target_item['item_private'])) {
continue;
}
- $packet = Libzot::build_packet($channel,$packet_type,$zenv,$activity,'activitystreams',(($private) ? $hub['hubloc_sitekey'] : null),$hub['site_crypto']);
+ $packet = Libzot::build_packet($channel, $packet_type, $zenv, $activity, 'activitystreams', (($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto']);
}
else {
// currently zot6 delivery is only performed on normal items and not sync items or mail or anything else
@@ -786,28 +770,28 @@ class Notifier {
// with before switching to zot6 as the primary zot6 handler checks for the existence of a message delivery report
// to trigger dequeue'ing
- $z6 = (($encoded_item && $encoded_item['type'] === 'activity' && (! array_key_exists('allow_cid',$encoded_item))) ? true : false);
- if($z6) {
- $packet = zot6_build_packet($channel,'notify',$env, json_encode($encoded_item), (($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto'],$hash);
+ $z6 = (($encoded_item && $encoded_item['type'] === 'activity' && (!array_key_exists('allow_cid', $encoded_item))) ? true : false);
+ if ($z6) {
+ $packet = zot6_build_packet($channel, 'notify', $env, json_encode($encoded_item), (($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto'], $hash);
}
else {
- $packet = zot_build_packet($channel,'notify',$env, (($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto'],$hash);
+ $packet = zot_build_packet($channel, 'notify', $env, (($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto'], $hash);
}
}
// remove this after most hubs have updated to version 5.0
- if(stripos($hub['site_project'], 'hubzilla') !== false && version_compare($hub['site_version'], '4.7.3', '<=')) {
- if($encoded_item['type'] === 'mail') {
- $encoded_item['from']['network'] = 'zot';
+ if (stripos($hub['site_project'], 'hubzilla') !== false && version_compare($hub['site_version'], '4.7.3', '<=')) {
+ if ($encoded_item['type'] === 'mail') {
+ $encoded_item['from']['network'] = 'zot';
$encoded_item['from']['guid_sig'] = str_replace('sha256.', '', $encoded_item['from']['guid_sig']);
}
else {
- $encoded_item['owner']['network'] = 'zot';
+ $encoded_item['owner']['network'] = 'zot';
$encoded_item['owner']['guid_sig'] = str_replace('sha256.', '', $encoded_item['owner']['guid_sig']);
- if(strpos($encoded_item['author']['url'], z_root()) === 0) {
- $encoded_item['author']['network'] = 'zot';
+ if (strpos($encoded_item['author']['url'], z_root()) === 0) {
+ $encoded_item['author']['network'] = 'zot';
$encoded_item['author']['guid_sig'] = str_replace('sha256.', '', $encoded_item['author']['guid_sig']);
}
}
@@ -826,7 +810,7 @@ class Notifier {
);
// only create delivery reports for normal undeleted items
- if(is_array($target_item) && array_key_exists('postopts',$target_item) && (! $target_item['item_deleted']) && (! get_config('system','disable_dreport'))) {
+ if (is_array($target_item) && array_key_exists('postopts', $target_item) && (!$target_item['item_deleted']) && (!get_config('system', 'disable_dreport'))) {
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue ) values ( '%s','%s','%s','%s','%s','%s','%s' ) ",
dbesc($target_item['mid']),
dbesc($hub['hubloc_host']),
@@ -842,21 +826,21 @@ class Notifier {
$deliveries[] = $hash;
}
- if($normal_mode) {
+ if ($normal_mode) {
$x = q("select * from hook where hook = 'notifier_normal'");
- if($x) {
- Master::Summon( [ 'Deliver_hooks', $target_item['id'] ] );
+ if ($x) {
+ Master::Summon(['Deliver_hooks', $target_item['id']]);
}
}
- if($deliveries)
+ if ($deliveries)
do_delivery($deliveries);
logger('notifier: basic loop complete.', LOGGER_DEBUG);
if ($dead) {
foreach ($dead as $deceased) {
- if (is_array($target_item) && (! $target_item['item_deleted']) && (! get_config('system','disable_dreport'))) {
+ if (is_array($target_item) && (!$target_item['item_deleted']) && (!get_config('system', 'disable_dreport'))) {
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan, dreport_queue )
values ( '%s', '%s','%s','%s','%s','%s','%s','%s' ) ",
dbesc($target_item['mid']),
@@ -872,7 +856,7 @@ class Notifier {
}
}
- call_hooks('notifier_end',$target_item);
+ call_hooks('notifier_end', $target_item);
logger('notifer: complete.');
return;
diff --git a/Zotlabs/Daemon/Onedirsync.php b/Zotlabs/Daemon/Onedirsync.php
index 2ad76761d..f29fbe5b8 100644
--- a/Zotlabs/Daemon/Onedirsync.php
+++ b/Zotlabs/Daemon/Onedirsync.php
@@ -3,6 +3,7 @@
namespace Zotlabs\Daemon;
use Zotlabs\Lib\Libzot;
+use Zotlabs\Lib\Libzotdir;
require_once('include/zot.php');
require_once('include/dir_fns.php');
@@ -10,14 +11,14 @@ require_once('include/dir_fns.php');
class Onedirsync {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
logger('onedirsync: start ' . intval($argv[1]));
- if(($argc > 1) && (intval($argv[1])))
+ if (($argc > 1) && (intval($argv[1])))
$update_id = intval($argv[1]);
- if(! $update_id) {
+ if (!$update_id) {
logger('onedirsync: no update');
return;
}
@@ -26,9 +27,9 @@ class Onedirsync {
intval($update_id)
);
- if(! $r)
+ if (!$r)
return;
- if(($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr']))
+ if (($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (!$r[0]['ud_addr']))
return;
// Have we probed this channel more recently than the other directory server
@@ -40,8 +41,8 @@ class Onedirsync {
dbesc($r[0]['ud_date']),
intval(UPDATE_FLAGS_UPDATED)
);
- if($x) {
- $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'",
+ if ($x) {
+ q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'",
intval(UPDATE_FLAGS_UPDATED),
dbesc($r[0]['ud_addr']),
intval(UPDATE_FLAGS_UPDATED),
@@ -58,8 +59,8 @@ class Onedirsync {
$h = Libzot::zot_record_preferred($h);
- if(($h) && ($h['hubloc_status'] & HUBLOC_OFFLINE)) {
- $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ",
+ if (($h) && ($h['hubloc_status'] & HUBLOC_OFFLINE)) {
+ q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ",
intval(UPDATE_FLAGS_UPDATED),
dbesc($r[0]['ud_addr']),
intval(UPDATE_FLAGS_UPDATED)
@@ -71,10 +72,10 @@ class Onedirsync {
// we might have to pull this out some day, but for now update_directory_entry()
// runs zot_finger() and is kind of zot specific
- if($h && ! in_array($h['hubloc_network'], ['zot6', 'zot']))
+ if ($h && !in_array($h['hubloc_network'], ['zot6', 'zot']))
return;
- update_directory_entry($r[0]);
+ Libzotdir::update_directory_entry($r[0]);
return;
}
diff --git a/Zotlabs/Daemon/Onepoll.php b/Zotlabs/Daemon/Onepoll.php
index 93a5412b0..0228f10fb 100644
--- a/Zotlabs/Daemon/Onepoll.php
+++ b/Zotlabs/Daemon/Onepoll.php
@@ -2,6 +2,7 @@
namespace Zotlabs\Daemon;
+use App;
use Zotlabs\Lib\Libzot;
require_once('include/zot.php');
@@ -10,20 +11,18 @@ require_once('include/socgraph.php');
class Onepoll {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
logger('onepoll: start');
-
- if(($argc > 1) && (intval($argv[1])))
+
+ if (($argc > 1) && (intval($argv[1])))
$contact_id = intval($argv[1]);
- if(! $contact_id) {
+ if (!$contact_id) {
logger('onepoll: no contact');
return;
}
- $d = datetime_convert();
-
$contacts = q("SELECT abook.*, xchan.*, account.*
FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan
where abook_id = %d
@@ -32,38 +31,36 @@ class Onepoll {
intval($contact_id),
intval(ACCOUNT_OK),
intval(ACCOUNT_UNVERIFIED)
- );
+ );
- if(! $contacts) {
+ if (!$contacts) {
logger('onepoll: abook_id not found: ' . $contact_id);
return;
}
$contact = $contacts[0];
- $t = $contact['abook_updated'];
-
$importer_uid = $contact['abook_channel'];
-
+
$r = q("SELECT * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
intval($importer_uid)
);
- if(! $r)
+ if (!$r)
return;
$importer = $r[0];
logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}");
- $last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] <= NULL_DATE))
- ? datetime_convert('UTC','UTC','now - 7 days')
- : datetime_convert('UTC','UTC',$contact['abook_updated'] . ' - 2 days')
+ $last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] <= NULL_DATE))
+ ? datetime_convert('UTC', 'UTC', 'now - 7 days')
+ : datetime_convert('UTC', 'UTC', $contact['abook_updated'] . ' - 2 days')
);
- if($contact['xchan_network'] === 'rss') {
+ if ($contact['xchan_network'] === 'rss') {
logger('onepoll: processing feed ' . $contact['xchan_name'], LOGGER_DEBUG);
- $alive = handle_feed($importer['channel_id'],$contact_id,$contact['xchan_hash']);
+ $alive = handle_feed($importer['channel_id'], $contact_id, $contact['xchan_hash']);
if ($alive) {
q("update abook set abook_connected = '%s' where abook_id = %d",
dbesc(datetime_convert()),
@@ -72,22 +69,22 @@ class Onepoll {
}
return;
}
-
- if(! in_array($contact['xchan_network'],['zot','zot6']))
+
+ if (!in_array($contact['xchan_network'], ['zot', 'zot6']))
return;
// update permissions
- if($contact['xchan_network'] === 'zot6')
- $x = Libzot::refresh($contact,$importer);
+ if ($contact['xchan_network'] === 'zot6')
+ $x = Libzot::refresh($contact, $importer);
- if($contact['xchan_network'] === 'zot')
- $x = zot_refresh($contact,$importer);
+ if ($contact['xchan_network'] === 'zot')
+ $x = zot_refresh($contact, $importer);
$responded = false;
$updated = datetime_convert();
$connected = datetime_convert();
- if(! $x) {
+ if (!$x) {
// mark for death by not updating abook_connected, this is caught in include/poller.php
q("update abook set abook_updated = '%s' where abook_id = %d",
dbesc($updated),
@@ -103,38 +100,38 @@ class Onepoll {
$responded = true;
}
- if(! $responded)
+ if (!$responded)
return;
- if($contact['xchan_connurl']) {
+ if ($contact['xchan_connurl']) {
$fetch_feed = true;
- $x = null;
+ $x = null;
// They haven't given us permission to see their stream
- $can_view_stream = intval(get_abconfig($importer_uid,$contact['abook_xchan'],'their_perms','view_stream'));
+ $can_view_stream = intval(get_abconfig($importer_uid, $contact['abook_xchan'], 'their_perms', 'view_stream'));
- if(! $can_view_stream)
+ if (!$can_view_stream)
$fetch_feed = false;
// we haven't given them permission to send us their stream
- $can_send_stream = intval(get_abconfig($importer_uid,$contact['abook_xchan'],'my_perms','send_stream'));
-
- if(! $can_send_stream)
+ $can_send_stream = intval(get_abconfig($importer_uid, $contact['abook_xchan'], 'my_perms', 'send_stream'));
+
+ if (!$can_send_stream)
$fetch_feed = false;
- if($fetch_feed) {
+ if ($fetch_feed) {
- if(strpos($contact['xchan_connurl'],z_root()) === 0) {
+ if (strpos($contact['xchan_connurl'], z_root()) === 0) {
// local channel - save a network fetch
$c = channelx_by_hash($contact['xchan_hash']);
- if($c) {
- $x = [
- 'success' => true,
- 'body' => json_encode( [
- 'success' => true,
- 'messages' => zot_feed($c['channel_id'], $importer['xchan_hash'], [ 'mindate' => $last_update ])
+ if ($c) {
+ $x = [
+ 'success' => true,
+ 'body' => json_encode([
+ 'success' => true,
+ 'messages' => zot_feed($c['channel_id'], $importer['xchan_hash'], ['mindate' => $last_update])
])
];
}
@@ -142,43 +139,43 @@ class Onepoll {
else {
// remote fetch
- $feedurl = str_replace('/poco/','/zotfeed/',$contact['xchan_connurl']);
- $feedurl .= '?f=&mindate=' . urlencode($last_update) . '&zid=' . $importer['channel_address'] . '@' . \App::get_hostname();
+ $feedurl = str_replace('/poco/', '/zotfeed/', $contact['xchan_connurl']);
+ $feedurl .= '?f=&mindate=' . urlencode($last_update) . '&zid=' . $importer['channel_address'] . '@' . App::get_hostname();
$recurse = 0;
- $x = z_fetch_url($feedurl, false, $recurse, [ 'session' => true ]);
+ $x = z_fetch_url($feedurl, false, $recurse, ['session' => true]);
}
- logger('feed_update: ' . print_r($x,true), LOGGER_DATA);
+ logger('feed_update: ' . print_r($x, true), LOGGER_DATA);
}
- if(($x) && ($x['success'])) {
+ if (($x) && ($x['success'])) {
$total = 0;
logger('onepoll: feed update ' . $contact['xchan_name'] . ' ' . $feedurl);
- $j = json_decode($x['body'],true);
- if($j['success'] && $j['messages']) {
- foreach($j['messages'] as $message) {
- $results = process_delivery(array('hash' => $contact['xchan_hash']), get_item_elements($message),
- array(array('hash' => $importer['xchan_hash'])), false);
- logger('onepoll: feed_update: process_delivery: ' . print_r($results,true), LOGGER_DATA);
- $total ++;
+ $j = json_decode($x['body'], true);
+ if ($j['success'] && $j['messages']) {
+ foreach ($j['messages'] as $message) {
+ $results = process_delivery(['hash' => $contact['xchan_hash']], get_item_elements($message),
+ [['hash' => $importer['xchan_hash']]], false);
+ logger('onepoll: feed_update: process_delivery: ' . print_r($results, true), LOGGER_DATA);
+ $total++;
}
logger("onepoll: $total messages processed");
}
}
}
-
+
// update the poco details for this connection
- if($contact['xchan_connurl']) {
+ if ($contact['xchan_connurl']) {
$r = q("SELECT xlink_id from xlink
where xlink_xchan = '%s' and xlink_updated > %s - INTERVAL %s and xlink_static = 0 limit 1",
intval($contact['xchan_hash']),
db_utcnow(), db_quoteinterval('1 DAY')
);
- if(! $r) {
- poco_load($contact['xchan_hash'],$contact['xchan_connurl']);
+ if (!$r) {
+ poco_load($contact['xchan_hash'], $contact['xchan_connurl']);
}
}
diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php
index ebc0584ba..8cbdfab0d 100644
--- a/Zotlabs/Daemon/Poller.php
+++ b/Zotlabs/Daemon/Poller.php
@@ -4,73 +4,67 @@ namespace Zotlabs\Daemon;
class Poller {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
- $maxsysload = intval(get_config('system','maxloadavg'));
- if($maxsysload < 1)
+ $maxsysload = intval(get_config('system', 'maxloadavg'));
+ if ($maxsysload < 1)
$maxsysload = 50;
- if(function_exists('sys_getloadavg')) {
+ if (function_exists('sys_getloadavg')) {
$load = sys_getloadavg();
- if(intval($load[0]) > $maxsysload) {
+ if (intval($load[0]) > $maxsysload) {
logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.');
return;
}
}
- $interval = intval(get_config('system','poll_interval'));
- if(! $interval)
- $interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
+ $interval = intval(get_config('system', 'poll_interval'));
+ if (!$interval)
+ $interval = ((get_config('system', 'delivery_interval') === false) ? 3 : intval(get_config('system', 'delivery_interval')));
// Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
$lockfile = 'store/[data]/poller';
- if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
- && (! get_config('system','override_poll_lockfile'))) {
+ if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
+ && (!get_config('system', 'override_poll_lockfile'))) {
logger("poller: Already running");
return;
}
-
+
// Create a lockfile. Needs two vars, but $x doesn't need to contain anything.
+ $x = '';
file_put_contents($lockfile, $x);
logger('poller: start');
-
- $manual_id = 0;
- $generation = 0;
- $force = false;
- $restart = false;
+ $manual_id = 0;
+ $force = false;
- if(($argc > 1) && ($argv[1] == 'force'))
+ if (($argc > 1) && ($argv[1] == 'force'))
$force = true;
- if(($argc > 1) && ($argv[1] == 'restart')) {
- $restart = true;
+ if (($argc > 1) && ($argv[1] == 'restart')) {
$generation = intval($argv[2]);
- if(! $generation)
+ if (!$generation)
return;
}
- if(($argc > 1) && intval($argv[1])) {
+ if (($argc > 1) && intval($argv[1])) {
$manual_id = intval($argv[1]);
$force = true;
}
-
$sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : "");
reload_plugins();
- $d = datetime_convert();
-
// Only poll from those with suitable relationships
- $abandon_sql = (($abandon_days)
- ? sprintf(" AND account_lastlog > %s - INTERVAL %s ", db_utcnow(), db_quoteinterval(intval($abandon_days).' DAY'))
- : ''
+ $abandon_sql = (($abandon_days)
+ ? sprintf(" AND account_lastlog > %s - INTERVAL %s ", db_utcnow(), db_quoteinterval(intval($abandon_days) . ' DAY'))
+ : ''
);
$randfunc = db_getfunc('RAND');
-
+
$contacts = q("SELECT abook.abook_updated, abook.abook_connected, abook.abook_feed,
abook.abook_channel, abook.abook_id, abook.abook_archived, abook.abook_pending,
abook.abook_ignored, abook.abook_blocked,
@@ -85,118 +79,117 @@ class Poller {
intval(ACCOUNT_UNVERIFIED) // FIXME
);
- if($contacts) {
+ if ($contacts) {
+ foreach ($contacts as $contact) {
- foreach($contacts as $contact) {
-
- $update = false;
+ $update = false;
$t = $contact['abook_updated'];
$c = $contact['abook_connected'];
- if(intval($contact['abook_feed'])) {
- $min = service_class_fetch($contact['abook_channel'],'minimum_feedcheck_minutes');
- if(! $min)
- $min = intval(get_config('system','minimum_feedcheck_minutes'));
- if(! $min)
+ if (intval($contact['abook_feed'])) {
+ $min = service_class_fetch($contact['abook_channel'], 'minimum_feedcheck_minutes');
+ if (!$min)
+ $min = intval(get_config('system', 'minimum_feedcheck_minutes'));
+ if (!$min)
$min = 60;
- $x = datetime_convert('UTC','UTC',"now - $min minutes");
- if($c < $x) {
- Master::Summon(array('Onepoll',$contact['abook_id']));
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
+ $x = datetime_convert('UTC', 'UTC', "now - $min minutes");
+ if ($c < $x) {
+ Master::Summon(['Onepoll', $contact['abook_id']]);
+ if ($interval)
+ @time_sleep_until(microtime(true) + (float)$interval);
}
continue;
}
- if(! in_array($contact['xchan_network'],['zot','zot6']))
+ if (!in_array($contact['xchan_network'], ['zot', 'zot6']))
continue;
- if($c == $t) {
- if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
+ if ($c == $t) {
+ if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day"))
$update = true;
}
else {
-
+
// if we've never connected with them, start the mark for death countdown from now
-
- if($c <= NULL_DATE) {
- $r = q("update abook set abook_connected = '%s' where abook_id = %d",
+
+ if ($c <= NULL_DATE) {
+ q("update abook set abook_connected = '%s' where abook_id = %d",
dbesc(datetime_convert()),
intval($contact['abook_id'])
);
- $c = datetime_convert();
+ $c = datetime_convert();
$update = true;
}
// He's dead, Jim
- if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) {
- $r = q("update abook set abook_archived = 1 where abook_id = %d",
+ if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 30 day")) > 0) {
+ q("update abook set abook_archived = 1 where abook_id = %d",
intval($contact['abook_id'])
);
- $update = false;
continue;
}
- if(intval($contact['abook_archived'])) {
- $update = false;
+ if (intval($contact['abook_archived'])) {
continue;
}
// might be dead, so maybe don't poll quite so often
-
+
// recently deceased, so keep up the regular schedule for 3 days
-
- if((strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 3 day")) > 0)
- && (strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 1 day")) > 0))
+
+ if ((strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 3 day")) > 0)
+ && (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 1 day")) > 0))
$update = true;
// After that back off and put them on a morphine drip
- if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 2 day")) > 0) {
+ if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 2 day")) > 0) {
$update = true;
}
}
- if(intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked']))
+ if (intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked']))
continue;
- if((! $update) && (! $force))
- continue;
+ if ((!$update) && (!$force))
+ continue;
- Master::Summon(array('Onepoll',$contact['abook_id']));
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
+ Master::Summon(['Onepoll', $contact['abook_id']]);
+ if ($interval)
+ @time_sleep_until(microtime(true) + (float)$interval);
}
}
- if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
+ $dirmode = intval(get_config('system', 'directory_mode'));
+
+ if ($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
$r = q("SELECT u.ud_addr, u.ud_id, u.ud_last FROM updates AS u INNER JOIN (SELECT ud_addr, max(ud_id) AS ud_id FROM updates WHERE ( ud_flags & %d ) = 0 AND ud_addr != '' AND ( ud_last <= '%s' OR ud_last > %s - INTERVAL %s ) GROUP BY ud_addr) AS s ON s.ud_id = u.ud_id ",
intval(UPDATE_FLAGS_UPDATED),
dbesc(NULL_DATE),
db_utcnow(), db_quoteinterval('7 DAY')
);
- if($r) {
- foreach($r as $rr) {
+ if ($r) {
+ foreach ($r as $rr) {
// If they didn't respond when we attempted before, back off to once a day
// After 7 days we won't bother anymore
- if($rr['ud_last'] > NULL_DATE)
- if($rr['ud_last'] > datetime_convert('UTC','UTC', 'now - 1 day'))
+ if ($rr['ud_last'] > NULL_DATE)
+ if ($rr['ud_last'] > datetime_convert('UTC', 'UTC', 'now - 1 day'))
continue;
- Master::Summon(array('Onedirsync',$rr['ud_id']));
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
+ Master::Summon(['Onedirsync', $rr['ud_id']]);
+ if ($interval)
+ @time_sleep_until(microtime(true) + (float)$interval);
}
}
- }
+ }
- set_config('system','lastpoll',datetime_convert());
+ set_config('system', 'lastpoll', datetime_convert());
//All done - clear the lockfile
diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php
index 814148404..36bdcfe81 100644
--- a/Zotlabs/Daemon/Queue.php
+++ b/Zotlabs/Daemon/Queue.php
@@ -7,12 +7,12 @@ require_once('include/zot.php');
class Queue {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
require_once('include/items.php');
require_once('include/bbcode.php');
- if($argc > 1)
+ if ($argc > 1)
$queue_id = $argv[1];
else
$queue_id = EMPTY_STR;
@@ -25,10 +25,9 @@ class Queue {
$r = q("select outq_posturl from outq where outq_created < %s - INTERVAL %s",
db_utcnow(), db_quoteinterval('3 DAY')
);
- if($r) {
- foreach($r as $rr) {
- $site_url = '';
- $h = parse_url($rr['outq_posturl']);
+ if ($r) {
+ foreach ($r as $rr) {
+ $h = parse_url($rr['outq_posturl']);
$desturl = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
q("update site set site_dead = 1 where site_dead = 0 and site_url = '%s' and site_update < %s - INTERVAL %s",
dbesc($desturl),
@@ -37,11 +36,11 @@ class Queue {
}
}
- $r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
+ q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
db_utcnow(), db_quoteinterval('3 DAY')
);
- if($queue_id) {
+ if ($queue_id) {
$r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1",
dbesc($queue_id)
);
@@ -54,7 +53,7 @@ class Queue {
// so that we don't start off a thousand deliveries for a couple of dead hubs.
// The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
// Other drivers will have to do something different here and may need their own query.
-
+
// Note: this requires some tweaking as new posts to long dead hubs once a day will keep them in the
// "every 15 minutes" category. We probably need to prioritise them when inserted into the queue
// or just prior to this query based on recent and long-term delivery history. If we have good reason to believe
@@ -67,7 +66,7 @@ class Queue {
db_utcnow()
);
while ($r) {
- foreach($r as $rv) {
+ foreach ($r as $rv) {
queue_deliver($rv);
}
$r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
@@ -75,10 +74,10 @@ class Queue {
);
}
}
- if(! $r)
+ if (!$r)
return;
- foreach($r as $rv) {
+ foreach ($r as $rv) {
queue_deliver($rv);
}
}
diff --git a/Zotlabs/Daemon/Thumbnail.php b/Zotlabs/Daemon/Thumbnail.php
index e1f17c304..72034b870 100644
--- a/Zotlabs/Daemon/Thumbnail.php
+++ b/Zotlabs/Daemon/Thumbnail.php
@@ -5,30 +5,30 @@ namespace Zotlabs\Daemon;
class Thumbnail {
- static public function run($argc,$argv) {
+ static public function run($argc, $argv) {
- if(! $argc == 2)
+ if (!$argc == 2)
return;
$c = q("select * from attach where hash = '%s' ",
dbesc($argv[1])
);
- if(! $c)
+ if (!$c)
return;
$attach = $c[0];
- $preview_style = intval(get_config('system','thumbnail_security',0));
- $preview_width = intval(get_config('system','thumbnail_width',300));
- $preview_height = intval(get_config('system','thumbnail_height',300));
+ $preview_style = intval(get_config('system', 'thumbnail_security', 0));
+ $preview_width = intval(get_config('system', 'thumbnail_width', 300));
+ $preview_height = intval(get_config('system', 'thumbnail_height', 300));
$p = [
'attach' => $attach,
'preview_style' => $preview_style,
'preview_width' => $preview_width,
'preview_height' => $preview_height,
- 'thumbnail' => null
+ 'thumbnail' => null
];
/**
@@ -40,39 +40,39 @@ class Thumbnail {
* * \e string \b thumbnail
*/
- call_hooks('thumbnail',$p);
- if($p['thumbnail']) {
+ call_hooks('thumbnail', $p);
+ if ($p['thumbnail']) {
return;
}
$default_controller = null;
-
+
$files = glob('Zotlabs/Thumbs/*.php');
- if($files) {
- foreach($files as $f) {
- $clsname = '\\Zotlabs\\Thumbs\\' . ucfirst(basename($f,'.php'));
- if(class_exists($clsname)) {
+ if ($files) {
+ foreach ($files as $f) {
+ $clsname = '\\Zotlabs\\Thumbs\\' . ucfirst(basename($f, '.php'));
+ if (class_exists($clsname)) {
$x = new $clsname();
- if(method_exists($x,'Match')) {
+ if (method_exists($x, 'Match')) {
$matched = $x->Match($attach['filetype']);
- if($matched) {
- $x->Thumb($attach,$preview_style,$preview_width,$preview_height);
+ if ($matched) {
+ $x->Thumb($attach, $preview_style, $preview_width, $preview_height);
}
}
- if(method_exists($x,'MatchDefault')) {
- $default_matched = $x->MatchDefault(substr($attach['filetype'],0,strpos($attach['filetype'],'/')));
- if($default_matched) {
+ if (method_exists($x, 'MatchDefault')) {
+ $default_matched = $x->MatchDefault(substr($attach['filetype'], 0, strpos($attach['filetype'], '/')));
+ if ($default_matched) {
$default_controller = $x;
}
}
}
}
}
- if(($default_controller)
- && ((! file_exists(dbunescbin($attach['content']) . '.thumb'))
+ if (($default_controller)
+ && ((!file_exists(dbunescbin($attach['content']) . '.thumb'))
|| (filectime(dbunescbin($attach['content']) . 'thumb') < (time() - 60)))) {
- $default_controller->Thumb($attach,$preview_style,$preview_width,$preview_height);
+ $default_controller->Thumb($attach, $preview_style, $preview_width, $preview_height);
}
}
}