diff --git a/Zotlabs/Daemon/Addon.php b/Zotlabs/Daemon/Addon.php
index 50afea23b..97c473e53 100644
--- a/Zotlabs/Daemon/Addon.php
+++ b/Zotlabs/Daemon/Addon.php
@@ -2,12 +2,12 @@
namespace Zotlabs\Daemon;
+class Addon
+{
-class Addon {
+ public static function run($argc, $argv)
+ {
- public static function run($argc, $argv) {
-
- call_hooks('daemon_addon',$argv);
-
- }
+ call_hooks('daemon_addon', $argv);
+ }
}
diff --git a/Zotlabs/Daemon/CacheThumb.php b/Zotlabs/Daemon/CacheThumb.php
index 75f17b707..94a419b14 100644
--- a/Zotlabs/Daemon/CacheThumb.php
+++ b/Zotlabs/Daemon/CacheThumb.php
@@ -1,50 +1,54 @@
- $max_thumb || $height > $max_thumb) {
- $imagick_path = get_config('system','imagick_convert_path');
- if ($imagick_path && @file_exists($imagick_path)) {
- $tmp_name = $path . '-001';
- $newsize = photo_calculate_scale(array_merge($is,['max' => $max_thumb]));
- $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $path) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name);
+ $max_thumb = get_config('system', 'max_cache_thumbnail', 1024);
- for ($x = 0; $x < 4; $x ++) {
- exec($cmd);
- if (file_exists($tmp_name)) {
- break;
- }
- continue;
- }
-
- if (! file_exists($tmp_name)) {
- return;
- }
- @rename($tmp_name,$path);
- }
- }
- }
-}
\ No newline at end of file
+ if ($width > $max_thumb || $height > $max_thumb) {
+ $imagick_path = get_config('system', 'imagick_convert_path');
+ if ($imagick_path && @file_exists($imagick_path)) {
+ $tmp_name = $path . '-001';
+ $newsize = photo_calculate_scale(array_merge($is, ['max' => $max_thumb]));
+ $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $path) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name);
+
+ for ($x = 0; $x < 4; $x++) {
+ exec($cmd);
+ if (file_exists($tmp_name)) {
+ break;
+ }
+ continue;
+ }
+
+ if (! file_exists($tmp_name)) {
+ return;
+ }
+ @rename($tmp_name, $path);
+ }
+ }
+ }
+}
diff --git a/Zotlabs/Daemon/Cache_embeds.php b/Zotlabs/Daemon/Cache_embeds.php
index 353fd048a..1698f9741 100644
--- a/Zotlabs/Daemon/Cache_embeds.php
+++ b/Zotlabs/Daemon/Cache_embeds.php
@@ -2,33 +2,34 @@
namespace Zotlabs\Daemon;
+class Cache_embeds
+{
-class Cache_embeds {
+ public static function run($argc, $argv)
+ {
- public static function run($argc, $argv) {
+ if (! $argc == 2) {
+ return;
+ }
- if (! $argc == 2) {
- return;
- }
+ $c = q(
+ "select body, html, created from item where id = %d ",
+ dbesc(intval($argv[1]))
+ );
- $c = q("select body, html, created from item where id = %d ",
- dbesc(intval($argv[1]))
- );
+ if (! $c) {
+ return;
+ }
- if (! $c) {
- return;
- }
+ $item = array_shift($c);
- $item = array_shift($c);
+ $cache_expire = intval(get_config('system', 'default_expire_days'));
+ if ($cache_expire <= 0) {
+ $cache_expire = 60;
+ }
+ $cache_enable = ((($cache_expire) && ($item['created'] < datetime_convert('UTC', 'UTC', 'now - ' . $cache_expire . ' days'))) ? false : true);
- $cache_expire = intval(get_config('system', 'default_expire_days'));
- if ($cache_expire <= 0) {
- $cache_expire = 60;
- }
- $cache_enable = ((($cache_expire) && ($item['created'] < datetime_convert('UTC','UTC', 'now - ' . $cache_expire . ' days'))) ? false : true);
-
- $s = bbcode($item['body']);
- $s = sslify($s, $cache_enable);
-
- }
+ $s = bbcode($item['body']);
+ $s = sslify($s, $cache_enable);
+ }
}
diff --git a/Zotlabs/Daemon/Cache_image.php b/Zotlabs/Daemon/Cache_image.php
index e960cf09e..0371c7002 100644
--- a/Zotlabs/Daemon/Cache_image.php
+++ b/Zotlabs/Daemon/Cache_image.php
@@ -4,15 +4,16 @@ namespace Zotlabs\Daemon;
use Zotlabs\Lib\Img_cache;
-class Cache_image {
+class Cache_image
+{
- public static function run($argc, $argv) {
+ public static function run($argc, $argv)
+ {
- cli_startup();
- logger('caching: ' . $argv[1] . ' to ' . $argv[2]);
- if ($argc === 3) {
- Img_cache::url_to_cache($argv[1],$argv[2]);
- }
-
- }
+ cli_startup();
+ logger('caching: ' . $argv[1] . ' to ' . $argv[2]);
+ if ($argc === 3) {
+ Img_cache::url_to_cache($argv[1], $argv[2]);
+ }
+ }
}
diff --git a/Zotlabs/Daemon/Channel_purge.php b/Zotlabs/Daemon/Channel_purge.php
index 0c68c8f86..02f49bb7c 100644
--- a/Zotlabs/Daemon/Channel_purge.php
+++ b/Zotlabs/Daemon/Channel_purge.php
@@ -2,32 +2,35 @@
namespace Zotlabs\Daemon;
+class Channel_purge
+{
-class Channel_purge {
+ public static function run($argc, $argv)
+ {
- public static function run($argc, $argv) {
+ cli_startup();
- cli_startup();
+ $channel_id = intval($argv[1]);
- $channel_id = intval($argv[1]);
+ $channel = q(
+ "select * from channel where channel_id = %d and channel_removed = 1",
+ intval($channel_id)
+ );
- $channel = q("select * from channel where channel_id = %d and channel_removed = 1",
- intval($channel_id)
- );
+ if (! $channel) {
+ return;
+ }
- if (! $channel) {
- return;
- }
-
- do {
- $r = q("select id from item where uid = %d and item_deleted = 0 limit 1000",
- intval($channel_id)
- );
- if ($r) {
- foreach ($r as $rv) {
- drop_item($rv['id'],false);
- }
- }
- } while ($r);
- }
+ do {
+ $r = q(
+ "select id from item where uid = %d and item_deleted = 0 limit 1000",
+ intval($channel_id)
+ );
+ if ($r) {
+ foreach ($r as $rv) {
+ drop_item($rv['id'], false);
+ }
+ }
+ } while ($r);
+ }
}
diff --git a/Zotlabs/Daemon/Checksites.php b/Zotlabs/Daemon/Checksites.php
index 1cb2c48ad..07d632d82 100644
--- a/Zotlabs/Daemon/Checksites.php
+++ b/Zotlabs/Daemon/Checksites.php
@@ -1,54 +1,66 @@
- 1) && ($argv[1]))
- $site_id = $argv[1];
+ logger('checksites: start');
- if($site_id)
- $sql_options = " and site_url = '" . dbesc($argv[1]) . "' ";
+ if (($argc > 1) && ($argv[1])) {
+ $site_id = $argv[1];
+ }
- $days = intval(get_config('system','sitecheckdays'));
- if($days < 1)
- $days = 30;
+ if ($site_id) {
+ $sql_options = " and site_url = '" . dbesc($argv[1]) . "' ";
+ }
- $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'),
- intval(SITE_TYPE_ZOT)
- );
+ $days = intval(get_config('system', 'sitecheckdays'));
+ if ($days < 1) {
+ $days = 30;
+ }
- if(! $r)
- return;
+ $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'),
+ intval(SITE_TYPE_ZOT)
+ );
- foreach($r as $rr) {
- if(! strcasecmp($rr['site_url'],z_root()))
- continue;
+ if (! $r) {
+ return;
+ }
- $x = ping_site($rr['site_url']);
- if($x['success']) {
- logger('checksites: ' . $rr['site_url']);
- q("update site set site_update = '%s' where site_url = '%s' ",
- dbesc(datetime_convert()),
- dbesc($rr['site_url'])
- );
- }
- else {
- logger('marking dead site: ' . $x['message']);
- q("update site set site_dead = 1 where site_url = '%s' ",
- dbesc($rr['site_url'])
- );
- }
- }
+ foreach ($r as $rr) {
+ if (! strcasecmp($rr['site_url'], z_root())) {
+ continue;
+ }
- return;
- }
+ $x = ping_site($rr['site_url']);
+ if ($x['success']) {
+ logger('checksites: ' . $rr['site_url']);
+ q(
+ "update site set site_update = '%s' where site_url = '%s' ",
+ dbesc(datetime_convert()),
+ dbesc($rr['site_url'])
+ );
+ } else {
+ logger('marking dead site: ' . $x['message']);
+ q(
+ "update site set site_dead = 1 where site_url = '%s' ",
+ dbesc($rr['site_url'])
+ );
+ }
+ }
+
+ return;
+ }
}
diff --git a/Zotlabs/Daemon/Content_importer.php b/Zotlabs/Daemon/Content_importer.php
index 08588b26c..c1be35d62 100644
--- a/Zotlabs/Daemon/Content_importer.php
+++ b/Zotlabs/Daemon/Content_importer.php
@@ -8,52 +8,55 @@ require_once('include/cli_startup.php');
require_once('include/attach.php');
require_once('include/import.php');
-class Content_importer {
+class Content_importer
+{
- public static function run($argc, $argv) {
- cli_startup();
+ public static function run($argc, $argv)
+ {
+ cli_startup();
- $page = $argv[1];
- $since = $argv[2];
- $until = $argv[3];
- $channel_address = $argv[4];
- $hz_server = urldecode($argv[5]);
+ $page = $argv[1];
+ $since = $argv[2];
+ $until = $argv[3];
+ $channel_address = $argv[4];
+ $hz_server = urldecode($argv[5]);
- $m = parse_url($hz_server);
+ $m = parse_url($hz_server);
- $channel = channelx_by_nick($channel_address);
- if(! $channel) {
- logger('itemhelper: channel not found');
- killme();
- }
+ $channel = channelx_by_nick($channel_address);
+ if (! $channel) {
+ logger('itemhelper: channel not found');
+ killme();
+ }
- $headers = [
- 'X-API-Token' => random_string(),
- 'X-API-Request' => $hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
- 'Host' => $m['host'],
- '(request-target)' => 'get /api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
- ];
+ $headers = [
+ 'X-API-Token' => random_string(),
+ 'X-API-Request' => $hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
+ 'Host' => $m['host'],
+ '(request-target)' => 'get /api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page ,
+ ];
- $headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], channel_url($channel),true,'sha512');
+ $headers = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), true, 'sha512');
- $x = z_fetch_url($hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page,false,$redirects,[ 'headers' => $headers ]);
+ $x = z_fetch_url($hz_server . '/api/z/1.0/item/export_page?f=&zap_compat=1&since=' . urlencode($since) . '&until=' . urlencode($until) . '&page=' . $page, false, $redirects, [ 'headers' => $headers ]);
- if(! $x['success']) {
- logger('no API response',LOGGER_DEBUG);
- killme();
- }
+ if (! $x['success']) {
+ logger('no API response', LOGGER_DEBUG);
+ killme();
+ }
- $j = json_decode($x['body'],true);
+ $j = json_decode($x['body'], true);
- if (! $j) {
- killme();
- }
+ if (! $j) {
+ killme();
+ }
- if(! ($j['item'] || count($j['item'])))
- killme();
+ if (! ($j['item'] || count($j['item']))) {
+ killme();
+ }
- import_items($channel,$j['item'],false,((array_key_exists('relocate',$j)) ? $j['relocate'] : null));
+ import_items($channel, $j['item'], false, ((array_key_exists('relocate', $j)) ? $j['relocate'] : null));
- killme();
- }
+ killme();
+ }
}
diff --git a/Zotlabs/Daemon/Convo.php b/Zotlabs/Daemon/Convo.php
index b44de178a..7a4f2bd1e 100644
--- a/Zotlabs/Daemon/Convo.php
+++ b/Zotlabs/Daemon/Convo.php
@@ -1,4 +1,4 @@
-get();
+ $obj = new ASCollection($id, $channel);
- if ($messages) {
- foreach ($messages as $message) {
- if (is_string($message)) {
- $message = Activity::fetch($message,$channel);
- }
- // set client flag because comments will probably just be objects and not full blown activities
- // and that lets us use implied_create
- $AS = new ActivityStreams($message, null, true);
- if ($AS->is_valid() && is_array($AS->obj)) {
- $item = Activity::decode_note($AS,true);
- Activity::store($channel,$contact['abook_xchan'],$AS,$item,true,true);
- }
- }
- }
- }
+ $messages = $obj->get();
+
+ if ($messages) {
+ foreach ($messages as $message) {
+ if (is_string($message)) {
+ $message = Activity::fetch($message, $channel);
+ }
+ // set client flag because comments will probably just be objects and not full blown activities
+ // and that lets us use implied_create
+ $AS = new ActivityStreams($message, null, true);
+ if ($AS->is_valid() && is_array($AS->obj)) {
+ $item = Activity::decode_note($AS, true);
+ Activity::store($channel, $contact['abook_xchan'], $AS, $item, true, true);
+ }
+ }
+ }
+ }
}
diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php
index 6d6344cc0..b5672e334 100644
--- a/Zotlabs/Daemon/Cron.php
+++ b/Zotlabs/Daemon/Cron.php
@@ -1,201 +1,221 @@
- $maxsysload) {
- logger('system: load ' . $load . ' too high. Cron deferred to next scheduled run.');
- return;
- }
- }
+ $maxsysload = intval(get_config('system', 'maxloadavg'));
+ if ($maxsysload < 1) {
+ $maxsysload = 50;
+ }
+ if (function_exists('sys_getloadavg')) {
+ $load = sys_getloadavg();
+ if (intval($load[0]) > $maxsysload) {
+ logger('system: load ' . $load . ' too high. Cron deferred to next scheduled run.');
+ return;
+ }
+ }
- // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
- $lockfile = 'cache/cron';
- 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.
- file_put_contents($lockfile, $x);
+ // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
+ $lockfile = 'cache/cron';
+ if (
+ (file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
+ && (! get_config('system', 'override_cron_lockfile'))
+ ) {
+ logger("cron: Already running");
+ return;
+ }
- logger('cron: start');
-
- // run queue delivery process in the background
+ // Create a lockfile. Needs two vars, but $x doesn't need to contain anything.
+ file_put_contents($lockfile, $x);
- Run::Summon( [ 'Queue' ] );
+ logger('cron: start');
- Run::Summon( [ 'Poller' ] );
+ // run queue delivery process in the background
- // maintenance for mod sharedwithme - check for updated items and remove them
+ Run::Summon([ 'Queue' ]);
- require_once('include/sharedwithme.php');
- apply_updates();
-
- // expire any expired items
+ Run::Summon([ 'Poller' ]);
- $r = q("select id,item_wall from item where expires > '2001-01-01 00:00:00' and expires < %s
+ // maintenance for mod sharedwithme - check for updated items and remove them
+
+ require_once('include/sharedwithme.php');
+ apply_updates();
+
+ // 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) {
- 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']) {
- // The notifier isn't normally invoked unless item_drop is interactive.
- Run::Summon( [ 'Notifier', 'drop', $rr['id'] ] );
- }
- }
- }
+ db_utcnow()
+ );
+ 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']) {
+ // The notifier isn't normally invoked unless item_drop is interactive.
+ Run::Summon([ 'Notifier', 'drop', $rr['id'] ]);
+ }
+ }
+ }
- // delete expired access tokens
+ // delete expired access tokens
- $r = q("select atoken_id from atoken where atoken_expires > '%s' and atoken_expires < %s",
- dbesc(NULL_DATE),
- db_utcnow()
- );
- if($r) {
- require_once('include/security.php');
- foreach($r as $rr) {
- atoken_delete($rr['atoken_id']);
- }
- }
+ $r = q(
+ "select atoken_id from atoken where atoken_expires > '%s' and atoken_expires < %s",
+ dbesc(NULL_DATE),
+ db_utcnow()
+ );
+ if ($r) {
+ require_once('include/security.php');
+ foreach ($r as $rr) {
+ atoken_delete($rr['atoken_id']);
+ }
+ }
- // Ensure that every channel pings their directory occasionally.
+ // Ensure that every channel pings their directory occasionally.
- $r = q("select channel_id from channel where channel_dirdate < %s - INTERVAL %s and channel_removed = 0",
- db_utcnow(),
- db_quoteinterval('7 DAY')
- );
- if($r) {
- foreach($r as $rr) {
- Run::Summon( [ 'Directory', $rr['channel_id'], 'force' ] );
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
- }
- }
+ $r = q(
+ "select channel_id from channel where channel_dirdate < %s - INTERVAL %s and channel_removed = 0",
+ db_utcnow(),
+ db_quoteinterval('7 DAY')
+ );
+ if ($r) {
+ foreach ($r as $rr) {
+ Run::Summon([ 'Directory', $rr['channel_id'], 'force' ]);
+ if ($interval) {
+ @time_sleep_until(microtime(true) + (float) $interval);
+ }
+ }
+ }
- // publish any applicable items that were set to be published in the future
- // (time travel posts). Restrict to items that have come of age in the last
- // couple of days to limit the query to something reasonable.
+ // publish any applicable items that were set to be published in the future
+ // (time travel posts). Restrict to items that have come of age in the last
+ // couple of days to limit the query to something reasonable.
- $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'))
- );
- if($r) {
- foreach($r as $rr) {
- $x = q("update item set item_delayed = 0 where id = %d",
- intval($rr['id'])
- );
- if($x) {
- $z = q("select * from item where id = %d",
- intval($message_id)
- );
- 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) ]
- ]
- );
- }
- Run::Summon( [ 'Notifier','wall-new',$rr['id'] ] );
- }
- }
- }
+ $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'))
+ );
+ if ($r) {
+ foreach ($r as $rr) {
+ $x = q(
+ "update item set item_delayed = 0 where id = %d",
+ intval($rr['id'])
+ );
+ if ($x) {
+ $z = q(
+ "select * from item where id = %d",
+ intval($message_id)
+ );
+ 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) ]
+ ]
+ );
+ }
+ Run::Summon([ 'Notifier','wall-new',$rr['id'] ]);
+ }
+ }
+ }
- require_once('include/attach.php');
- attach_upgrade();
+ require_once('include/attach.php');
+ attach_upgrade();
- $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'));
-
- // 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'));
+ $abandon_days = intval(get_config('system', 'account_abandon_days'));
+ if ($abandon_days < 1) {
+ $abandon_days = 0;
+ }
- if(($d2 != $d1) && ($h1 == $h2)) {
- Run::Summon( [ 'Cron_daily' ] );
- }
+ // once daily run birthday_updates and then expire in background
- // update any photos which didn't get imported properly
- // This should be rare
+ // FIXME: add birthday updates, both locally and for xprof for use
+ // by directory servers
- $r = q("select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = ''
+ $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'));
+
+
+ if (($d2 != $d1) && ($h1 == $h2)) {
+ Run::Summon([ 'Cron_daily' ]);
+ }
+
+ // update any photos which didn't get imported properly
+ // This should be rare
+
+ $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_quoteinterval('1 DAY')
- );
- if($r) {
- require_once('include/photo_factory.php');
- foreach($r as $rr) {
- $photos = import_remote_xchan_photo($rr['xchan_photo_l'],$rr['xchan_hash']);
- if ($photos) {
- $x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
+ db_utcnow(),
+ db_quoteinterval('1 DAY')
+ );
+ if ($r) {
+ require_once('include/photo_factory.php');
+ foreach ($r as $rr) {
+ $photos = import_remote_xchan_photo($rr['xchan_photo_l'], $rr['xchan_hash']);
+ if ($photos) {
+ $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]),
- dbesc($photos[2]),
- dbesc($photos[3]),
- dbesc($rr['xchan_hash'])
- );
- }
- }
- }
+ dbesc($photos[0]),
+ dbesc($photos[1]),
+ dbesc($photos[2]),
+ dbesc($photos[3]),
+ dbesc($rr['xchan_hash'])
+ );
+ }
+ }
+ }
- $generation = 0;
+ $generation = 0;
- $restart = false;
+ $restart = false;
- if(($argc > 1) && ($argv[1] == 'restart')) {
- $restart = true;
- $generation = intval($argv[2]);
- if(! $generation)
- return;
- }
+ if (($argc > 1) && ($argv[1] == 'restart')) {
+ $restart = true;
+ $generation = intval($argv[2]);
+ if (! $generation) {
+ return;
+ }
+ }
- reload_plugins();
+ reload_plugins();
- $d = datetime_convert();
+ $d = datetime_convert();
- // TODO check to see if there are any cronhooks before wasting a process
+ // TODO check to see if there are any cronhooks before wasting a process
- if(! $restart)
- Run::Summon( [ 'Cronhooks' ] );
+ if (! $restart) {
+ Run::Summon([ 'Cronhooks' ]);
+ }
- set_config('system','lastcron',datetime_convert());
+ set_config('system', 'lastcron', datetime_convert());
- //All done - clear the lockfile
- @unlink($lockfile);
+ //All done - clear the lockfile
+ @unlink($lockfile);
- return;
- }
+ return;
+ }
}
diff --git a/Zotlabs/Daemon/Cron_daily.php b/Zotlabs/Daemon/Cron_daily.php
index 65c8a6d3d..9ecb02064 100644
--- a/Zotlabs/Daemon/Cron_daily.php
+++ b/Zotlabs/Daemon/Cron_daily.php
@@ -1,110 +1,122 @@
- %s - INTERVAL %s and channel_deleted < %s - INTERVAL %s",
- db_utcnow(), db_quoteinterval('21 DAY'),
- db_utcnow(), db_quoteinterval('10 DAY')
- );
- if($r) {
- foreach($r as $rv) {
- channel_remove_final($rv['channel_id']);
- }
- }
+ db_utcnow(),
+ db_quoteinterval('21 DAY'),
+ db_utcnow(),
+ db_quoteinterval('10 DAY')
+ );
+ if ($r) {
+ foreach ($r as $rv) {
+ channel_remove_final($rv['channel_id']);
+ }
+ }
- // get rid of really old poco records
+ // get rid of really old poco records
- q("delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ",
- db_utcnow(), db_quoteinterval('14 DAY')
- );
+ q(
+ "delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ",
+ db_utcnow(),
+ db_quoteinterval('14 DAY')
+ );
- // Check for dead sites
- Run::Summon( ['Checksites' ] );
+ // Check for dead sites
+ Run::Summon(['Checksites' ]);
- // clean up image cache - use site expiration or 60 days if not set or zero
-
- $files = glob('cache/img/*/*');
- $expire_days = intval(get_config('system','default_expire_days'));
- if ($expire_days <= 0) {
- $expire_days = 60;
- }
- $now = time();
- $maxage = 86400 * $expire_days;
- if ($files) {
- foreach ($files as $file) {
- if (is_file($file)) {
- if ($now - filemtime($file) >= $maxage) {
- unlink($file);
- }
- }
- }
- }
+ // clean up image cache - use site expiration or 60 days if not set or zero
- // update searchable doc indexes
+ $files = glob('cache/img/*/*');
+ $expire_days = intval(get_config('system', 'default_expire_days'));
+ if ($expire_days <= 0) {
+ $expire_days = 60;
+ }
+ $now = time();
+ $maxage = 86400 * $expire_days;
+ if ($files) {
+ foreach ($files as $file) {
+ if (is_file($file)) {
+ if ($now - filemtime($file) >= $maxage) {
+ unlink($file);
+ }
+ }
+ }
+ }
- Run::Summon( [ 'Importdoc'] );
+ // update searchable doc indexes
- /**
- * End Cron Weekly
- */
+ Run::Summon([ 'Importdoc']);
- }
-}
\ No newline at end of file
+ /**
+ * End Cron Weekly
+ */
+ }
+}
diff --git a/Zotlabs/Daemon/Cronhooks.php b/Zotlabs/Daemon/Cronhooks.php
index b0fc4ef38..44d9f159e 100644
--- a/Zotlabs/Daemon/Cronhooks.php
+++ b/Zotlabs/Daemon/Cronhooks.php
@@ -1,17 +1,21 @@
-start();
+ App::$session->start();
- $_SESSION['authenticated'] = 1;
- $_SESSION['uid'] = $argv[1];
+ $_SESSION['authenticated'] = 1;
+ $_SESSION['uid'] = $argv[1];
- $x = session_id();
+ $x = session_id();
- $f = 'cache/cookie_' . $argv[1];
- $c = 'cache/cookien_' . $argv[1];
+ $f = 'cache/cookie_' . $argv[1];
+ $c = 'cache/cookien_' . $argv[1];
- $e = file_exists($f);
+ $e = file_exists($f);
- $output = '';
+ $output = '';
- if($e) {
- $lines = file($f);
- 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()) {
- $output .= $line . "\n";
- }
- }
- else
- $output .= $line;
- }
- }
- }
- $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));
+ if ($e) {
+ $lines = file($f);
+ 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()) {
+ $output .= $line . "\n";
+ }
+ } else {
+ $output .= $line;
+ }
+ }
+ }
+ }
+ $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($c,$x);
+ file_put_contents($c, $x);
- return;
- }
+ return;
+ }
}
diff --git a/Zotlabs/Daemon/Deliver.php b/Zotlabs/Daemon/Deliver.php
index 3a0833562..2aecaa1b9 100644
--- a/Zotlabs/Daemon/Deliver.php
+++ b/Zotlabs/Daemon/Deliver.php
@@ -1,31 +1,36 @@
- 2) {
+ if ($argv[2] === 'force') {
+ $force = true;
+ }
+ if ($argv[2] === 'nopush') {
+ $pushall = false;
+ }
+ }
- $force = false;
- $pushall = true;
-
- if ($argc > 2) {
- if ($argv[2] === 'force') {
- $force = true;
- }
- if ($argv[2] === 'nopush') {
- $pushall = false;
- }
- }
+ logger('directory update', LOGGER_DEBUG);
- logger('directory update', LOGGER_DEBUG);
+ $channel = channelx_by_n($argv[1]);
+ if (! $channel) {
+ return;
+ }
- $channel = channelx_by_n($argv[1]);
- if (! $channel) {
- return;
- }
+ // update the local directory - was optional, but now done regardless
- // update the local directory - was optional, but now done regardless
-
- 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()),
- intval($channel['channel_id'])
- );
+ q(
+ "update channel set channel_dirdate = '%s' where channel_id = %d",
+ dbesc(datetime_convert()),
+ intval($channel['channel_id'])
+ );
- // Now update all the connections
- if ($pushall) {
- Run::Summon( [ 'Notifier','refresh_all',$channel['channel_id'] ] );
- }
- }
+ // Now update all the connections
+ if ($pushall) {
+ Run::Summon([ 'Notifier','refresh_all',$channel['channel_id'] ]);
+ }
+ }
}
diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php
index e48b4922a..d1214fca6 100644
--- a/Zotlabs/Daemon/Expire.php
+++ b/Zotlabs/Daemon/Expire.php
@@ -2,90 +2,94 @@
namespace Zotlabs\Daemon;
+class Expire
+{
-class Expire {
+ public static function run($argc, $argv)
+ {
- public static function run($argc, $argv){
+ cli_startup();
- cli_startup();
+ // perform final cleanup on previously delete items
- // 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')
+ );
+ if ($r) {
+ foreach ($r as $rr) {
+ drop_item($rr['id'], false, DROPITEM_PHASE2);
+ }
+ }
- $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')
- );
- if ($r) {
- foreach ($r as $rr) {
- drop_item($rr['id'], false, DROPITEM_PHASE2);
- }
- }
+ // physically remove anything that has been deleted for more than two months
+ /** @FIXME - this is a wretchedly inefficient query */
- // 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')
+ );
- $r = q("delete from item where item_pending_remove = 1 and changed < %s - INTERVAL %s",
- db_utcnow(), db_quoteinterval('36 DAY')
- );
+ logger('expire: start', LOGGER_DEBUG);
- logger('expire: start', 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);
- logger('site_expire: ' . $site_expire);
+ $r = q("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true");
- $r = q("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true");
+ if ($r) {
+ foreach ($r as $rr) {
+ // expire the sys channel separately
+ if (intval($rr['channel_system'])) {
+ continue;
+ }
- if ($r) {
- foreach ($r as $rr) {
+ // service class default (if non-zero) over-rides the site default
- // expire the sys channel separately
- if (intval($rr['channel_system']))
- continue;
+ $service_class_expire = service_class_fetch($rr['channel_id'], 'expire_days');
+ if (intval($service_class_expire)) {
+ $channel_expire = $service_class_expire;
+ } else {
+ $channel_expire = $site_expire;
+ }
- // service class default (if non-zero) over-rides the site default
+ if (
+ intval($channel_expire) && (intval($channel_expire) < intval($rr['channel_expire_days'])) ||
+ intval($rr['channel_expire_days'] == 0)
+ ) {
+ $expire_days = $channel_expire;
+ } else {
+ $expire_days = $rr['channel_expire_days'];
+ }
- $service_class_expire = service_class_fetch($rr['channel_id'], 'expire_days');
- if (intval($service_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 {
- $expire_days = $rr['channel_expire_days'];
- }
+ // if the site or service class expiration is non-zero and less than person expiration, use that
+ logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $expire_days, LOGGER_DEBUG);
+ item_expire($rr['channel_id'], $expire_days, $commented_days);
+ }
+ }
- // if the site or service class expiration is non-zero and less than person expiration, use that
- logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $expire_days, LOGGER_DEBUG);
- item_expire($rr['channel_id'], $expire_days, $commented_days);
- }
- }
+ $x = get_sys_channel();
+ if ($x) {
+ // this should probably just fetch the channel_expire_days from the sys channel,
+ // but there's no convenient way to set it.
- $x = get_sys_channel();
- if ($x) {
+ $expire_days = get_config('system', 'sys_expire_days', 30);
- // this should probably just fetch the channel_expire_days from the sys channel,
- // but there's no convenient way to set it.
+ if (intval($site_expire) && (intval($site_expire) < intval($expire_days))) {
+ $expire_days = $site_expire;
+ }
- $expire_days = get_config('system', 'sys_expire_days',30);
+ logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG);
- if (intval($site_expire) && (intval($site_expire) < intval($expire_days))) {
- $expire_days = $site_expire;
- }
+ if ($expire_days) {
+ item_expire($x['channel_id'], $expire_days, $commented_days);
+ }
- 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);
- }
- }
+ logger('Expire: sys: done', LOGGER_DEBUG);
+ }
+ }
}
diff --git a/Zotlabs/Daemon/File_importer.php b/Zotlabs/Daemon/File_importer.php
index 60cc57abc..55c4469c6 100644
--- a/Zotlabs/Daemon/File_importer.php
+++ b/Zotlabs/Daemon/File_importer.php
@@ -8,43 +8,45 @@ require_once('include/cli_startup.php');
require_once('include/attach.php');
require_once('include/import.php');
-class File_importer {
+class File_importer
+{
- public static function run($argc, $argv) {
+ public static function run($argc, $argv)
+ {
- cli_startup();
+ cli_startup();
- $attach_id = $argv[1];
- $channel_address = $argv[2];
- $hz_server = urldecode($argv[3]);
+ $attach_id = $argv[1];
+ $channel_address = $argv[2];
+ $hz_server = urldecode($argv[3]);
- $m = parse_url($hz_server);
+ $m = parse_url($hz_server);
- $channel = channelx_by_nick($channel_address);
- if(! $channel) {
- logger('filehelper: channel not found');
- killme();
- }
+ $channel = channelx_by_nick($channel_address);
+ if (! $channel) {
+ logger('filehelper: channel not found');
+ killme();
+ }
- $headers = [
- 'X-API-Token' => random_string(),
- 'X-API-Request' => $hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
- 'Host' => $m['host'],
- '(request-target)' => 'get /api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
- ];
+ $headers = [
+ 'X-API-Token' => random_string(),
+ 'X-API-Request' => $hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
+ 'Host' => $m['host'],
+ '(request-target)' => 'get /api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,
+ ];
- $headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),true,'sha512');
- $x = z_fetch_url($hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id,false,$redirects,[ 'headers' => $headers ]);
+ $headers = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), true, 'sha512');
+ $x = z_fetch_url($hz_server . '/api/z/1.0/file/export?f=&zap_compat=1&file_id=' . $attach_id, false, $redirects, [ 'headers' => $headers ]);
- if(! $x['success']) {
- logger('no API response',LOGGER_DEBUG);
- return;
- }
+ if (! $x['success']) {
+ logger('no API response', LOGGER_DEBUG);
+ return;
+ }
- $j = json_decode($x['body'],true);
+ $j = json_decode($x['body'], true);
- $r = sync_files($channel,[$j]);
+ $r = sync_files($channel, [$j]);
- killme();
- }
+ killme();
+ }
}
diff --git a/Zotlabs/Daemon/Gprobe.php b/Zotlabs/Daemon/Gprobe.php
index d5415265b..88d43b31c 100644
--- a/Zotlabs/Daemon/Gprobe.php
+++ b/Zotlabs/Daemon/Gprobe.php
@@ -1,4 +1,6 @@
- 3) ? $argv[3] : '');
- $dstname = (($argc > 4) ? $argv[4] : '');
+ $srcfile = $argv[2];
+ $folder = (($argc > 3) ? $argv[3] : '');
+ $dstname = (($argc > 4) ? $argv[4] : '');
- $hash = random_string();
+ $hash = random_string();
- $arr = [
- 'src' => $srcfile,
- 'filename' => (($dstname) ? $dstname : basename($srcfile)),
- 'hash' => $hash,
- 'allow_cid' => $channel['channel_allow_cid'],
- 'allow_gid' => $channel['channel_allow_gid'],
- 'deny_cid' => $channel['channel_deny_cid'],
- 'deny_gid' => $channel['channel_deny_gid'],
- 'preserve_original' => true,
- 'replace' => true
- ];
+ $arr = [
+ 'src' => $srcfile,
+ 'filename' => (($dstname) ? $dstname : basename($srcfile)),
+ 'hash' => $hash,
+ 'allow_cid' => $channel['channel_allow_cid'],
+ 'allow_gid' => $channel['channel_allow_gid'],
+ 'deny_cid' => $channel['channel_deny_cid'],
+ 'deny_gid' => $channel['channel_deny_gid'],
+ 'preserve_original' => true,
+ 'replace' => true
+ ];
- if($folder)
- $arr['folder'] = $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'],array('file' => array($sync)));
-
- return;
- }
+ $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/Notifier.php b/Zotlabs/Daemon/Notifier.php
index d9b43189e..81abc908b 100644
--- a/Zotlabs/Daemon/Notifier.php
+++ b/Zotlabs/Daemon/Notifier.php
@@ -1,8 +1,7 @@
- $argv[4] ];
- self::$encoding = 'zot';
- $normal_mode = false;
- }
- elseif ($cmd === 'keychange') {
- self::$channel = channelx_by_n($item_id);
- $r = q("select abook_xchan from abook where abook_channel = %d",
- intval($item_id)
- );
- if ($r) {
- foreach ($r as $rr) {
- self::$recipients[] = $rr['abook_xchan'];
- }
- }
- self::$private = false;
- self::$packet_type = 'keychange';
- self::$encoded_item = get_pconfig(self::$channel['channel_id'],'system','keychange');
- self::$encoding = 'zot';
- $normal_mode = false;
- }
- elseif (in_array($cmd, [ 'permissions_update', 'permissions_reject', 'permissions_accept', 'permissions_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) {
-
- $recip = array_shift($r);
- $uid = $recip['abook_channel'];
- // Get the sender
- self::$channel = channelx_by_n($uid);
- if (self::$channel) {
-
- $perm_update = [ 'sender' => self::$channel, 'recipient' => $recip, 'success' => false, 'deliveries' => '' ];
-
- switch ($cmd) {
- case 'permissions_create':
- ActivityPub::permissions_create($perm_update);
- break;
- case 'permissions_accept':
- ActivityPub::permissions_accept($perm_update);
- break;
- case 'permissions_update':
- ActivityPub::permissions_update($perm_update);
- break;
-
- default:
- break;
- }
- if (! $perm_update['success']) {
- call_hooks($cmd,$perm_update);
- }
-
- if ($perm_update['success']) {
- if ($perm_update['deliveries']) {
- self::$deliveries[] = $perm_update['deliveries'];
- do_delivery(self::$deliveries);
- }
- return;
- }
- else {
- self::$recipients[] = $recip['abook_xchan'];
- self::$private = false;
- self::$packet_type = 'refresh';
- self::$env_recips = [ $recip['xchan_hash'] ];
- }
- }
- }
- }
- elseif ($cmd === 'refresh_all') {
- logger('notifier: refresh_all: ' . $item_id);
-
- self::$channel = channelx_by_n($item_id,true);
- $r = q("select abook_xchan from abook where abook_channel = %d",
- intval($item_id)
- );
- if ($r) {
- foreach ($r as $rr) {
- self::$recipients[] = $rr['abook_xchan'];
- }
- }
- self::$recipients[] = self::$channel['channel_hash'];
- self::$private = false;
- self::$packet_type = 'refresh';
- }
- elseif ($cmd === 'purge') {
- $xchan = $argv[3];
- logger('notifier: purge: ' . $item_id . ' => ' . $xchan);
- if (! $xchan) {
- return;
- }
-
- self::$channel = channelx_by_n($item_id,true);
- self::$recipients = [ $xchan ];
- self::$private = true;
- self::$packet_type = 'purge';
- }
- elseif ($cmd === 'purge_all') {
- logger('notifier: purge_all: ' . $item_id);
- self::$channel = channelx_by_n($item_id,true);
-
- self::$recipients = [];
- $r = q("select abook_xchan from abook where abook_channel = %d and abook_self = 0",
- intval($item_id)
- );
- if (! $r) {
- return;
- }
- foreach ($r as $rr) {
- self::$recipients[] = $rr['abook_xchan'];
- }
-
- self::$private = false;
- self::$packet_type = 'purge';
- }
- else {
-
- // Normal items
-
- // Fetch the target item
-
- $r = q("SELECT * FROM item WHERE id = %d and parent != 0 LIMIT 1",
- intval($item_id)
- );
-
- if (! $r) {
- return;
- }
-
- xchan_query($r);
- $r = fetch_post_tags($r);
-
- $target_item = array_shift($r);
-
- if($target_item['author']['xchan_network'] === 'anon') {
- logger('notifier: target item author is not a fetchable actor', LOGGER_DEBUG);
- return;
- }
-
- $deleted_item = false;
-
- 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, ITEM_TYPE_MAIL ] )) {
-
- if (intval($target_item['item_type'] == ITEM_TYPE_CUSTOM)) {
-
- $hookinfo=[
- 'targetitem' => $target_item,
- 'deliver' => false
- ];
-
- call_hooks('customitem_deliver',$hookinfo);
- }
-
- if (! $hookinfo['deliver']) {
- logger('notifier: target item not forwardable: type ' . $target_item['item_type'], LOGGER_DEBUG);
- return;
- }
- }
-
- // 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']) ||
- intval($target_item['item_blocked']) ||
- ( 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 (in_array($target_item['verb'], [ ACTIVITY_FOLLOW, ACTIVITY_IGNORE ])) {
- logger('not fowarding follow|unfollow->note activity');
- return;
- }
-
- $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) {
- self::$channel = array_shift($s);
- }
-
- if (self::$channel['channel_hash'] !== $target_item['author_xchan'] && self::$channel['channel_hash'] !== $target_item['owner_xchan']) {
- logger("notifier: Sending channel is not owner {$target_item['owner_xchan']} or author {$target_item['author_xchan']}", LOGGER_NORMAL, LOG_WARNING);
- return;
- }
-
- $thread_is_public = false;
-
- if ($target_item['mid'] === $target_item['parent_mid']) {
- $parent_item = $target_item;
- $top_level_post = true;
- }
- else {
-
- // fetch the parent item
- $r = q("SELECT * from item where id = %d order by id asc",
- intval($target_item['parent'])
- );
-
- if (! $r) {
- return;
- }
-
- xchan_query($r);
- $r = fetch_post_tags($r);
-
- $parent_item = array_shift($r);
- $top_level_post = false;
- $thread_is_public = ((intval($parent_item['item_private'])) ? false : true) ;
- }
-
- // avoid looping of discover items 12/4/2014
-
- if ($sys && $parent_item['uid'] == $sys['channel_id']) {
- return;
- }
-
- $m = get_iconfig($target_item,'activitypub','signed_data');
- // Re-use existing signature unless the activity type changed to a Tombstone, which won't verify.
- if ($m && (! intval($target_item['item_deleted']))) {
- self::$encoded_item = json_decode($m,true);
- }
- else {
- self::$encoded_item = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- Activity::ap_schema()
- ]], Activity::encode_activity($target_item,true)
- );
- self::$encoded_item['signature'] = LDSignatures::sign(self::$encoded_item,self::$channel);
- }
-
-
- logger('target_item: ' . print_r($target_item,true), LOGGER_DEBUG);
- logger('encoded: ' . print_r(self::$encoded_item,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.
- // To clarify, a site accepting a new comment is responsible for sending it to the owner for relay.
- // Relaying should never be initiated on a post that arrived from elsewhere.
-
- // We should normally be able to rely on ITEM_ORIGIN, but start_delivery_chain() incorrectly set this
- // 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) && $cmd !== 'hyper') ? true : false);
-
- $uplink = false;
-
- // $cmd === 'relay' indicates the owner is sending it to the original recipients
- // don't allow the item in the relay command to relay to owner under any circumstances, it will loop
-
- logger('notifier: relay_to_owner: ' . (($relay_to_owner) ? 'true' : 'false'), LOGGER_DATA, LOG_DEBUG);
- logger('notifier: top_level_post: ' . (($top_level_post) ? 'true' : 'false'), LOGGER_DATA, LOG_DEBUG);
-
- // 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)) {
- logger('notifier: uplink');
- $uplink = true;
- self::$packet_type = 'response';
- }
-
- if (($relay_to_owner || $uplink) && ($cmd !== 'relay')) {
- logger('followup relay (upstream delivery)', LOGGER_DEBUG);
- $sendto = ($uplink) ? $parent_item['source_xchan'] : $parent_item['owner_xchan'];
- self::$recipients = [ $sendto ];
- // over-ride upstream recipients if 'replyTo' was set in the parent.
- if ($parent_item['replyto'] && (! $uplink)) {
- logger('replyto: over-riding owner ' . $sendto, LOGGER_DEBUG);
- // unserialise is a no-op if presented with data that wasn't serialised.
- $ptr = unserialise($parent_item['replyto']);
- if (is_string($ptr)) {
- if (ActivityStreams::is_url($sendto)) {
- $sendto = $ptr;
- self::$recipients = [ $sendto ];
- }
- }
- elseif (is_array($ptr)) {
- $sendto = [];
- foreach ($ptr as $rto) {
- if (is_string($rto)) {
- $sendto[] = $rto;
- }
- elseif (is_array($rto) && isset($rto['id'])) {
- $sendto[] = $rto['id'];
- }
- }
- self::$recipients = $sendto;
- }
- }
-
- logger('replyto: upstream recipients ' . print_r($sendto,true), LOGGER_DEBUG);
-
-
- self::$private = true;
- $upstream = true;
- self::$packet_type = 'response';
- $is_moderated = their_perms_contains($parent_item['uid'],$sendto,'moderated');
- if ($relay_to_owner && $thread_is_public && (! $is_moderated) && (! is_group($parent_item['uid']))) {
- if (get_pconfig($target_item['uid'],'system','hyperdrive',true)) {
- Run::Summon([ 'Notifier' , 'hyper', $item_id ]);
- }
- }
-
- }
- else {
- if ($cmd === 'relay') {
- logger('owner relay (downstream delivery)');
- }
- else {
- logger('normal (downstream) distribution', LOGGER_DEBUG);
- }
- $upstream = false;
-
- if ($parent_item && $parent_item['item_private'] !== $target_item['item_private']) {
-
- logger('parent_item: ' . $parent_item['id'] . ' item_private: ' . $parent_item['item_private']);
- logger('target_item: ' . $target_item['id'] . ' item_private: ' . $target_item['item_private']);
-
- logger('conversation privacy mismatch - downstream delivery prevented');
- return;
- }
-
- // 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')) {
- // don't uplink a relayed post to the relay owner
- if ($parent_item['source_xchan'] !== $parent_item['owner_xchan']) {
- logger('notifier: uplinking this item');
- Run::Summon( [ 'Notifier','uplink',$item_id ] );
- }
- }
-
- if ($thread_is_public && $cmd === 'hyper') {
- self::$recipients = [];
- $r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 and not abook_xchan in ( '%s', '%s', '%s' ) ",
- intval($target_item['uid']),
- dbesc($target_item['author_xchan']),
- dbesc($target_item['owner_xchan']),
- dbesc($target_item['source_xchan'])
- );
- if ($r) {
- foreach ($r as $rv) {
- self::$recipients[] = $rv['abook_xchan'];
- }
- }
- self::$private = false;
- }
- else {
- self::$private = false;
- self::$recipients = collect_recipients($parent_item,self::$private);
- }
-
- // @FIXME add any additional recipients such as mentions, etc.
-
- if ($top_level_post) {
- // remove clones who will receive the post via sync
- self::$recipients = array_values(array_diff(self::$recipients, [ $target_item['owner_xchan'] ]));
- }
-
- // don't send deletions onward for other people's stuff
-
- 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;
- }
- }
- }
-
- // Generic delivery section, we have an encoded item and recipients
- // Now start the delivery process
-
- logger('encoded item: ' . print_r(self::$encoded_item,true), LOGGER_DATA, LOG_DEBUG);
-
- stringify_array_elms(self::$recipients);
- if (! self::$recipients) {
- logger('no recipients');
- return;
- }
-
- // logger('recipients: ' . print_r(self::$recipients,true), LOGGER_NORMAL, LOG_DEBUG);
-
- if (! count(self::$env_recips)) {
- self::$env_recips = ((self::$private) ? [] : null);
- }
-
- $recip_list = [];
-
- $details = q("select xchan_hash, xchan_network, xchan_addr, xchan_guid, xchan_guid_sig from xchan
- where xchan_hash in (" . protect_sprintf(implode(',',self::$recipients)) . ")");
-
- if ($details) {
- foreach ($details as $d) {
- $recip_list[] = $d['xchan_addr'] . ' (' . $d['xchan_hash'] . ')';
- if (self::$private) {
- self::$env_recips[] = $d['xchan_hash'];
- }
- }
- }
-
-
- $narr = [
- 'channel' => self::$channel,
- 'upstream' => $upstream,
- 'env_recips' => self::$env_recips,
- 'recipients' => self::$recipients,
- 'item' => $item,
- 'target_item' => $target_item,
- 'parent_item' => $parent_item,
- 'top_level_post' => $top_level_post,
- 'private' => self::$private,
- 'relay_to_owner' => $relay_to_owner,
- 'uplink' => $uplink,
- 'cmd' => $cmd,
- 'single' => (($cmd === 'single_activity') ? true : false),
- 'request' => $request,
- 'normal_mode' => $normal_mode,
- 'packet_type' => self::$packet_type,
- 'queued' => []
- ];
-
- call_hooks('notifier_process', $narr);
- if ($narr['queued']) {
- foreach ($narr['queued'] as $pq) {
- self::$deliveries[] = $pq;
- }
- }
-
- // notifier_process can alter the recipient list
-
- self::$recipients = $narr['recipients'];
- self::$env_recips = $narr['env_recips'];
-
- if ((self::$private) && (! self::$env_recips)) {
- // shouldn't happen
- logger('private message with no envelope recipients.' . print_r($argv,true), LOGGER_NORMAL, LOG_NOTICE);
- return;
- }
-
- 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 from hubloc left join site on site_url = hubloc_url
- where hubloc_hash in (" . protect_sprintf(implode(',',self::$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 (! self::$private) {
- $found_localhost = false;
- if ($hubs) {
- foreach ($hubs as $h) {
- if ($h['hubloc_url'] === z_root()) {
- $found_localhost = true;
- break;
- }
- }
- }
- if (! $found_localhost) {
- $localhub = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_dead from hubloc
+class Notifier
+{
+
+ public static $deliveries = [];
+ public static $recipients = [];
+ public static $env_recips = [];
+ public static $packet_type = 'activity';
+ public static $encoding = 'activitystreams';
+ public static $encoded_item = null;
+ public static $channel = null;
+ public static $private = false;
+
+ public static function run($argc, $argv)
+ {
+
+ if ($argc < 3) {
+ return;
+ }
+
+ logger('notifier: invoked: ' . print_r($argv, true), LOGGER_DEBUG, LOG_INFO);
+
+ $cmd = $argv[1];
+
+ $item_id = $argv[2];
+
+ if (! $item_id) {
+ return;
+ }
+
+ self::$deliveries = [];
+ self::$recipients = [];
+ self::$env_recips = [];
+ self::$packet_type = 'activity';
+ self::$encoding = 'activitystreams';
+ self::$encoded_item = null;
+ self::$channel = null;
+ self::$private = false;
+
+ $sys = get_sys_channel();
+
+ $top_level = false;
+
+ $url_recipients = [];
+ $normal_mode = true;
+
+ if ($cmd === 'request') {
+ $xchan = $argv[3];
+ if ($argc < 5) {
+ return;
+ }
+
+ self::$channel = channelx_by_n($item_id);
+
+ self::$private = true;
+ self::$recipients[] = $xchan;
+ self::$packet_type = 'request';
+ self::$encoded_item = [ 'message_id' => $argv[4] ];
+ self::$encoding = 'zot';
+ $normal_mode = false;
+ } elseif ($cmd === 'keychange') {
+ self::$channel = channelx_by_n($item_id);
+ $r = q(
+ "select abook_xchan from abook where abook_channel = %d",
+ intval($item_id)
+ );
+ if ($r) {
+ foreach ($r as $rr) {
+ self::$recipients[] = $rr['abook_xchan'];
+ }
+ }
+ self::$private = false;
+ self::$packet_type = 'keychange';
+ self::$encoded_item = get_pconfig(self::$channel['channel_id'], 'system', 'keychange');
+ self::$encoding = 'zot';
+ $normal_mode = false;
+ } elseif (in_array($cmd, [ 'permissions_update', 'permissions_reject', 'permissions_accept', 'permissions_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) {
+ $recip = array_shift($r);
+ $uid = $recip['abook_channel'];
+ // Get the sender
+ self::$channel = channelx_by_n($uid);
+ if (self::$channel) {
+ $perm_update = [ 'sender' => self::$channel, 'recipient' => $recip, 'success' => false, 'deliveries' => '' ];
+
+ switch ($cmd) {
+ case 'permissions_create':
+ ActivityPub::permissions_create($perm_update);
+ break;
+ case 'permissions_accept':
+ ActivityPub::permissions_accept($perm_update);
+ break;
+ case 'permissions_update':
+ ActivityPub::permissions_update($perm_update);
+ break;
+
+ default:
+ break;
+ }
+ if (! $perm_update['success']) {
+ call_hooks($cmd, $perm_update);
+ }
+
+ if ($perm_update['success']) {
+ if ($perm_update['deliveries']) {
+ self::$deliveries[] = $perm_update['deliveries'];
+ do_delivery(self::$deliveries);
+ }
+ return;
+ } else {
+ self::$recipients[] = $recip['abook_xchan'];
+ self::$private = false;
+ self::$packet_type = 'refresh';
+ self::$env_recips = [ $recip['xchan_hash'] ];
+ }
+ }
+ }
+ } elseif ($cmd === 'refresh_all') {
+ logger('notifier: refresh_all: ' . $item_id);
+
+ self::$channel = channelx_by_n($item_id, true);
+ $r = q(
+ "select abook_xchan from abook where abook_channel = %d",
+ intval($item_id)
+ );
+ if ($r) {
+ foreach ($r as $rr) {
+ self::$recipients[] = $rr['abook_xchan'];
+ }
+ }
+ self::$recipients[] = self::$channel['channel_hash'];
+ self::$private = false;
+ self::$packet_type = 'refresh';
+ } elseif ($cmd === 'purge') {
+ $xchan = $argv[3];
+ logger('notifier: purge: ' . $item_id . ' => ' . $xchan);
+ if (! $xchan) {
+ return;
+ }
+
+ self::$channel = channelx_by_n($item_id, true);
+ self::$recipients = [ $xchan ];
+ self::$private = true;
+ self::$packet_type = 'purge';
+ } elseif ($cmd === 'purge_all') {
+ logger('notifier: purge_all: ' . $item_id);
+ self::$channel = channelx_by_n($item_id, true);
+
+ self::$recipients = [];
+ $r = q(
+ "select abook_xchan from abook where abook_channel = %d and abook_self = 0",
+ intval($item_id)
+ );
+ if (! $r) {
+ return;
+ }
+ foreach ($r as $rr) {
+ self::$recipients[] = $rr['abook_xchan'];
+ }
+
+ self::$private = false;
+ self::$packet_type = 'purge';
+ } else {
+ // Normal items
+
+ // Fetch the target item
+
+ $r = q(
+ "SELECT * FROM item WHERE id = %d and parent != 0 LIMIT 1",
+ intval($item_id)
+ );
+
+ if (! $r) {
+ return;
+ }
+
+ xchan_query($r);
+ $r = fetch_post_tags($r);
+
+ $target_item = array_shift($r);
+
+ if ($target_item['author']['xchan_network'] === 'anon') {
+ logger('notifier: target item author is not a fetchable actor', LOGGER_DEBUG);
+ return;
+ }
+
+ $deleted_item = false;
+
+ 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, ITEM_TYPE_MAIL ])) {
+ if (intval($target_item['item_type'] == ITEM_TYPE_CUSTOM)) {
+ $hookinfo=[
+ 'targetitem' => $target_item,
+ 'deliver' => false
+ ];
+
+ call_hooks('customitem_deliver', $hookinfo);
+ }
+
+ if (! $hookinfo['deliver']) {
+ logger('notifier: target item not forwardable: type ' . $target_item['item_type'], LOGGER_DEBUG);
+ return;
+ }
+ }
+
+ // 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']) ||
+ intval($target_item['item_blocked']) ||
+ ( 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 (in_array($target_item['verb'], [ ACTIVITY_FOLLOW, ACTIVITY_IGNORE ])) {
+ logger('not fowarding follow|unfollow->note activity');
+ return;
+ }
+
+ $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) {
+ self::$channel = array_shift($s);
+ }
+
+ if (self::$channel['channel_hash'] !== $target_item['author_xchan'] && self::$channel['channel_hash'] !== $target_item['owner_xchan']) {
+ logger("notifier: Sending channel is not owner {$target_item['owner_xchan']} or author {$target_item['author_xchan']}", LOGGER_NORMAL, LOG_WARNING);
+ return;
+ }
+
+ $thread_is_public = false;
+
+ if ($target_item['mid'] === $target_item['parent_mid']) {
+ $parent_item = $target_item;
+ $top_level_post = true;
+ } else {
+ // fetch the parent item
+ $r = q(
+ "SELECT * from item where id = %d order by id asc",
+ intval($target_item['parent'])
+ );
+
+ if (! $r) {
+ return;
+ }
+
+ xchan_query($r);
+ $r = fetch_post_tags($r);
+
+ $parent_item = array_shift($r);
+ $top_level_post = false;
+ $thread_is_public = ((intval($parent_item['item_private'])) ? false : true) ;
+ }
+
+ // avoid looping of discover items 12/4/2014
+
+ if ($sys && $parent_item['uid'] == $sys['channel_id']) {
+ return;
+ }
+
+ $m = get_iconfig($target_item, 'activitypub', 'signed_data');
+ // Re-use existing signature unless the activity type changed to a Tombstone, which won't verify.
+ if ($m && (! intval($target_item['item_deleted']))) {
+ self::$encoded_item = json_decode($m, true);
+ } else {
+ self::$encoded_item = array_merge(['@context' => [
+ ACTIVITYSTREAMS_JSONLD_REV,
+ 'https://w3id.org/security/v1',
+ Activity::ap_schema()
+ ]], Activity::encode_activity($target_item, true));
+ self::$encoded_item['signature'] = LDSignatures::sign(self::$encoded_item, self::$channel);
+ }
+
+
+ logger('target_item: ' . print_r($target_item, true), LOGGER_DEBUG);
+ logger('encoded: ' . print_r(self::$encoded_item, 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.
+ // To clarify, a site accepting a new comment is responsible for sending it to the owner for relay.
+ // Relaying should never be initiated on a post that arrived from elsewhere.
+
+ // We should normally be able to rely on ITEM_ORIGIN, but start_delivery_chain() incorrectly set this
+ // 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) && $cmd !== 'hyper') ? true : false);
+
+ $uplink = false;
+
+ // $cmd === 'relay' indicates the owner is sending it to the original recipients
+ // don't allow the item in the relay command to relay to owner under any circumstances, it will loop
+
+ logger('notifier: relay_to_owner: ' . (($relay_to_owner) ? 'true' : 'false'), LOGGER_DATA, LOG_DEBUG);
+ logger('notifier: top_level_post: ' . (($top_level_post) ? 'true' : 'false'), LOGGER_DATA, LOG_DEBUG);
+
+ // 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)) {
+ logger('notifier: uplink');
+ $uplink = true;
+ self::$packet_type = 'response';
+ }
+
+ if (($relay_to_owner || $uplink) && ($cmd !== 'relay')) {
+ logger('followup relay (upstream delivery)', LOGGER_DEBUG);
+ $sendto = ($uplink) ? $parent_item['source_xchan'] : $parent_item['owner_xchan'];
+ self::$recipients = [ $sendto ];
+ // over-ride upstream recipients if 'replyTo' was set in the parent.
+ if ($parent_item['replyto'] && (! $uplink)) {
+ logger('replyto: over-riding owner ' . $sendto, LOGGER_DEBUG);
+ // unserialise is a no-op if presented with data that wasn't serialised.
+ $ptr = unserialise($parent_item['replyto']);
+ if (is_string($ptr)) {
+ if (ActivityStreams::is_url($sendto)) {
+ $sendto = $ptr;
+ self::$recipients = [ $sendto ];
+ }
+ } elseif (is_array($ptr)) {
+ $sendto = [];
+ foreach ($ptr as $rto) {
+ if (is_string($rto)) {
+ $sendto[] = $rto;
+ } elseif (is_array($rto) && isset($rto['id'])) {
+ $sendto[] = $rto['id'];
+ }
+ }
+ self::$recipients = $sendto;
+ }
+ }
+
+ logger('replyto: upstream recipients ' . print_r($sendto, true), LOGGER_DEBUG);
+
+
+ self::$private = true;
+ $upstream = true;
+ self::$packet_type = 'response';
+ $is_moderated = their_perms_contains($parent_item['uid'], $sendto, 'moderated');
+ if ($relay_to_owner && $thread_is_public && (! $is_moderated) && (! is_group($parent_item['uid']))) {
+ if (get_pconfig($target_item['uid'], 'system', 'hyperdrive', true)) {
+ Run::Summon([ 'Notifier' , 'hyper', $item_id ]);
+ }
+ }
+ } else {
+ if ($cmd === 'relay') {
+ logger('owner relay (downstream delivery)');
+ } else {
+ logger('normal (downstream) distribution', LOGGER_DEBUG);
+ }
+ $upstream = false;
+
+ if ($parent_item && $parent_item['item_private'] !== $target_item['item_private']) {
+ logger('parent_item: ' . $parent_item['id'] . ' item_private: ' . $parent_item['item_private']);
+ logger('target_item: ' . $target_item['id'] . ' item_private: ' . $target_item['item_private']);
+
+ logger('conversation privacy mismatch - downstream delivery prevented');
+ return;
+ }
+
+ // 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')) {
+ // don't uplink a relayed post to the relay owner
+ if ($parent_item['source_xchan'] !== $parent_item['owner_xchan']) {
+ logger('notifier: uplinking this item');
+ Run::Summon([ 'Notifier','uplink',$item_id ]);
+ }
+ }
+
+ if ($thread_is_public && $cmd === 'hyper') {
+ self::$recipients = [];
+ $r = q(
+ "select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 and not abook_xchan in ( '%s', '%s', '%s' ) ",
+ intval($target_item['uid']),
+ dbesc($target_item['author_xchan']),
+ dbesc($target_item['owner_xchan']),
+ dbesc($target_item['source_xchan'])
+ );
+ if ($r) {
+ foreach ($r as $rv) {
+ self::$recipients[] = $rv['abook_xchan'];
+ }
+ }
+ self::$private = false;
+ } else {
+ self::$private = false;
+ self::$recipients = collect_recipients($parent_item, self::$private);
+ }
+
+ // @FIXME add any additional recipients such as mentions, etc.
+
+ if ($top_level_post) {
+ // remove clones who will receive the post via sync
+ self::$recipients = array_values(array_diff(self::$recipients, [ $target_item['owner_xchan'] ]));
+ }
+
+ // don't send deletions onward for other people's stuff
+
+ 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;
+ }
+ }
+ }
+
+ // Generic delivery section, we have an encoded item and recipients
+ // Now start the delivery process
+
+ logger('encoded item: ' . print_r(self::$encoded_item, true), LOGGER_DATA, LOG_DEBUG);
+
+ stringify_array_elms(self::$recipients);
+ if (! self::$recipients) {
+ logger('no recipients');
+ return;
+ }
+
+ // logger('recipients: ' . print_r(self::$recipients,true), LOGGER_NORMAL, LOG_DEBUG);
+
+ if (! count(self::$env_recips)) {
+ self::$env_recips = ((self::$private) ? [] : null);
+ }
+
+ $recip_list = [];
+
+ $details = q("select xchan_hash, xchan_network, xchan_addr, xchan_guid, xchan_guid_sig from xchan
+ where xchan_hash in (" . protect_sprintf(implode(',', self::$recipients)) . ")");
+
+ if ($details) {
+ foreach ($details as $d) {
+ $recip_list[] = $d['xchan_addr'] . ' (' . $d['xchan_hash'] . ')';
+ if (self::$private) {
+ self::$env_recips[] = $d['xchan_hash'];
+ }
+ }
+ }
+
+
+ $narr = [
+ 'channel' => self::$channel,
+ 'upstream' => $upstream,
+ 'env_recips' => self::$env_recips,
+ 'recipients' => self::$recipients,
+ 'item' => $item,
+ 'target_item' => $target_item,
+ 'parent_item' => $parent_item,
+ 'top_level_post' => $top_level_post,
+ 'private' => self::$private,
+ 'relay_to_owner' => $relay_to_owner,
+ 'uplink' => $uplink,
+ 'cmd' => $cmd,
+ 'single' => (($cmd === 'single_activity') ? true : false),
+ 'request' => $request,
+ 'normal_mode' => $normal_mode,
+ 'packet_type' => self::$packet_type,
+ 'queued' => []
+ ];
+
+ call_hooks('notifier_process', $narr);
+ if ($narr['queued']) {
+ foreach ($narr['queued'] as $pq) {
+ self::$deliveries[] = $pq;
+ }
+ }
+
+ // notifier_process can alter the recipient list
+
+ self::$recipients = $narr['recipients'];
+ self::$env_recips = $narr['env_recips'];
+
+ if ((self::$private) && (! self::$env_recips)) {
+ // shouldn't happen
+ logger('private message with no envelope recipients.' . print_r($argv, true), LOGGER_NORMAL, LOG_NOTICE);
+ return;
+ }
+
+ 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 from hubloc left join site on site_url = hubloc_url
+ where hubloc_hash in (" . protect_sprintf(implode(',', self::$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 (! self::$private) {
+ $found_localhost = false;
+ if ($hubs) {
+ foreach ($hubs as $h) {
+ if ($h['hubloc_url'] === z_root()) {
+ $found_localhost = true;
+ break;
+ }
+ }
+ }
+ if (! $found_localhost) {
+ $localhub = q(
+ "select hubloc.*, site.site_crypto, site.site_flags, 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')
- );
- if ($localhub) {
- $hubs = array_merge($hubs,$localhub);
- }
- }
- }
+ dbesc(z_root() . '/channel/sys')
+ );
+ if ($localhub) {
+ $hubs = array_merge($hubs, $localhub);
+ }
+ }
+ }
- if (! $hubs) {
- logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE);
- return;
- }
+ if (! $hubs) {
+ logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE);
+ return;
+ }
- /**
- * Reduce the hubs to those that are unique. For zot hubs, we need to verify uniqueness by the sitekey,
- * since it may have been a re-install which has not yet been detected and pruned.
- * For other networks which don't have or require sitekeys, we'll have to use the URL
- */
+ /**
+ * Reduce the hubs to those that are unique. For zot hubs, we need to verify uniqueness by the sitekey,
+ * since it may have been a re-install which has not yet been detected and pruned.
+ * For other networks which don't have or require sitekeys, we'll have to use the URL
+ */
- $hublist = []; // this provides an easily printable list for the logs
- $dhubs = []; // delivery hubs where we store our resulting unique array
- $keys = []; // array of keys to check uniquness for zot hubs
- $urls = []; // array of urls to check uniqueness of hubs from other networks
- $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) {
- if (isset($hub['site_dead']) && intval($hub['site_dead'])) {
- $dead[] = $hub;
- continue;
- }
+ $hublist = []; // this provides an easily printable list for the logs
+ $dhubs = []; // delivery hubs where we store our resulting unique array
+ $keys = []; // array of keys to check uniquness for zot hubs
+ $urls = []; // array of urls to check uniqueness of hubs from other networks
+ $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) {
+ if (isset($hub['site_dead']) && intval($hub['site_dead'])) {
+ $dead[] = $hub;
+ continue;
+ }
- if (self::$env_recips) {
- foreach (self::$env_recips as $er) {
- if ($hub['hubloc_hash'] === $er) {
- if (! array_key_exists($hub['hubloc_site_id'], $hub_env)) {
- $hub_env[$hub['hubloc_site_id']] = [];
- }
- $hub_env[$hub['hubloc_site_id']][] = $er;
- }
- }
- }
-
+ if (self::$env_recips) {
+ foreach (self::$env_recips as $er) {
+ if ($hub['hubloc_hash'] === $er) {
+ if (! array_key_exists($hub['hubloc_site_id'], $hub_env)) {
+ $hub_env[$hub['hubloc_site_id']] = [];
+ }
+ $hub_env[$hub['hubloc_site_id']][] = $er;
+ }
+ }
+ }
+
- if ($hub['hubloc_network'] === 'zot6') {
- 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)) {
- $hublist[] = $hub['hubloc_host'] . ' ' . $hub['hubloc_network'];
- $dhubs[] = $hub;
- $urls[] = $hub['hubloc_url'];
- }
- }
- }
+ if ($hub['hubloc_network'] === 'zot6') {
+ 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)) {
+ $hublist[] = $hub['hubloc_host'] . ' ' . $hub['hubloc_network'];
+ $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) {
-
- logger('notifier_hub: ' . $hub['hubloc_url'],LOGGER_DEBUG, LOG_DEBUG);
+ foreach ($dhubs as $hub) {
+ logger('notifier_hub: ' . $hub['hubloc_url'], LOGGER_DEBUG, LOG_DEBUG);
- // deliver to any non-zot networks
+ // deliver to any non-zot networks
- if ($hub['hubloc_network'] !== 'zot6') {
- $narr = [
- 'channel' => self::$channel,
- 'upstream' => $upstream,
- 'env_recips' => self::$env_recips,
- 'recipients' => self::$recipients,
- 'item' => $item,
- 'target_item' => $target_item,
- 'parent_item' => $parent_item,
- 'hub' => $hub,
- 'top_level_post' => $top_level_post,
- 'private' => self::$private,
- 'relay_to_owner' => $relay_to_owner,
- 'uplink' => $uplink,
- 'cmd' => $cmd,
- 'single' => (($cmd === 'single_activity') ? true : false),
- 'request' => $request,
- 'normal_mode' => $normal_mode,
- 'packet_type' => self::$packet_type,
- 'queued' => []
- ];
+ if ($hub['hubloc_network'] !== 'zot6') {
+ $narr = [
+ 'channel' => self::$channel,
+ 'upstream' => $upstream,
+ 'env_recips' => self::$env_recips,
+ 'recipients' => self::$recipients,
+ 'item' => $item,
+ 'target_item' => $target_item,
+ 'parent_item' => $parent_item,
+ 'hub' => $hub,
+ 'top_level_post' => $top_level_post,
+ 'private' => self::$private,
+ 'relay_to_owner' => $relay_to_owner,
+ 'uplink' => $uplink,
+ 'cmd' => $cmd,
+ 'single' => (($cmd === 'single_activity') ? true : false),
+ 'request' => $request,
+ 'normal_mode' => $normal_mode,
+ 'packet_type' => self::$packet_type,
+ 'queued' => []
+ ];
- ActivityPub::notifier_process($narr);
+ ActivityPub::notifier_process($narr);
- call_hooks('notifier_hub',$narr);
- if($narr['queued']) {
- foreach($narr['queued'] as $pq)
- self::$deliveries[] = $pq;
- }
- continue;
- }
+ call_hooks('notifier_hub', $narr);
+ if ($narr['queued']) {
+ foreach ($narr['queued'] as $pq) {
+ self::$deliveries[] = $pq;
+ }
+ }
+ continue;
+ }
// Single deliveries are for non-nomadic federated networks and we're essentially
- // delivering only to those that have this site url in their abook_instance
- // and only from within a sync operation. This means if you post from a clone,
- // and a connection is connected to one of your other clones; assuming that hub
- // is running it will receive a sync packet. On receipt of this sync packet it
- // will invoke a delivery to those connections which are connected to just that
- // hub instance.
+ // delivering only to those that have this site url in their abook_instance
+ // and only from within a sync operation. This means if you post from a clone,
+ // and a connection is connected to one of your other clones; assuming that hub
+ // is running it will receive a sync packet. On receipt of this sync packet it
+ // will invoke a delivery to those connections which are connected to just that
+ // hub instance.
- if ($cmd === 'single_activity') {
- continue;
- }
+ if ($cmd === 'single_activity') {
+ continue;
+ }
- // default: zot protocol
+ // default: zot protocol
- // Prevent zot6 delivery of group comment boosts, which are not required for conversational platforms.
- // ActivityPub conversational platforms may wish to filter these if they don't want or require them.
- // We will assume here that if $target_item exists and has a verb that it is an actual item structure
- // so we won't need to check the existence of the other item fields prior to evaluation.
+ // Prevent zot6 delivery of group comment boosts, which are not required for conversational platforms.
+ // ActivityPub conversational platforms may wish to filter these if they don't want or require them.
+ // We will assume here that if $target_item exists and has a verb that it is an actual item structure
+ // so we won't need to check the existence of the other item fields prior to evaluation.
- // This shouldn't produce false positives on comment boosts that were generated on other platforms
- // because we won't be delivering them.
-
- if (isset($target_item) && isset($target_item['verb']) && $target_item['verb'] === 'Announce' && $target_item['author_xchan'] === $target_item['owner_xchan'] && ! intval($target_item['item_thread_top'])) {
- continue;
- }
+ // This shouldn't produce false positives on comment boosts that were generated on other platforms
+ // because we won't be delivering them.
+
+ if (isset($target_item) && isset($target_item['verb']) && $target_item['verb'] === 'Announce' && $target_item['author_xchan'] === $target_item['owner_xchan'] && ! intval($target_item['item_thread_top'])) {
+ continue;
+ }
- $hash = new_uuid();
+ $hash = new_uuid();
- $env = (($hub_env && $hub_env[$hub['hubloc_site_id']]) ? $hub_env[$hub['hubloc_site_id']] : '');
- if ((self::$private) && (! $env)) {
- continue;
- }
+ $env = (($hub_env && $hub_env[$hub['hubloc_site_id']]) ? $hub_env[$hub['hubloc_site_id']] : '');
+ if ((self::$private) && (! $env)) {
+ continue;
+ }
- $packet = Libzot::build_packet(self::$channel, self::$packet_type, $env, self::$encoded_item, self::$encoding,
- ((self::$private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto']);
+ $packet = Libzot::build_packet(
+ self::$channel,
+ self::$packet_type,
+ $env,
+ self::$encoded_item,
+ self::$encoding,
+ ((self::$private) ? $hub['hubloc_sitekey'] : null),
+ $hub['site_crypto']
+ );
- Queue::insert(
- [
- 'hash' => $hash,
- 'account_id' => self::$channel['channel_account_id'],
- 'channel_id' => self::$channel['channel_id'],
- 'posturl' => $hub['hubloc_callback'],
- 'notify' => $packet,
- 'msg' => EMPTY_STR
- ]
- );
+ Queue::insert(
+ [
+ 'hash' => $hash,
+ 'account_id' => self::$channel['channel_account_id'],
+ 'channel_id' => self::$channel['channel_id'],
+ 'posturl' => $hub['hubloc_callback'],
+ 'notify' => $packet,
+ 'msg' => EMPTY_STR
+ ]
+ );
- // only create delivery reports for normal undeleted items
- 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, dreport_log )
+ // only create delivery reports for normal undeleted items
+ 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, dreport_log )
values ( '%s', '%s','%s','%s','%s','%s','%s','%s', '%s' ) ",
- dbesc($target_item['mid']),
- dbesc($hub['hubloc_host']),
- dbesc($hub['hubloc_host']),
- dbesc($hub['hubloc_host']),
- dbesc('queued'),
- dbesc(datetime_convert()),
- dbesc(self::$channel['channel_hash']),
- dbesc($hash),
- dbesc(EMPTY_STR)
- );
- }
+ dbesc($target_item['mid']),
+ dbesc($hub['hubloc_host']),
+ dbesc($hub['hubloc_host']),
+ dbesc($hub['hubloc_host']),
+ dbesc('queued'),
+ dbesc(datetime_convert()),
+ dbesc(self::$channel['channel_hash']),
+ dbesc($hash),
+ dbesc(EMPTY_STR)
+ );
+ }
- self::$deliveries[] = $hash;
- }
-
- if ($normal_mode) {
- // This wastes a process if there are no delivery hooks configured, so check this before launching the new process
- $x = q("select * from hook where hook = 'notifier_normal'");
- if ($x) {
- Run::Summon( [ 'Deliver_hooks', $target_item['id'] ] );
- }
- }
+ self::$deliveries[] = $hash;
+ }
+
+ if ($normal_mode) {
+ // This wastes a process if there are no delivery hooks configured, so check this before launching the new process
+ $x = q("select * from hook where hook = 'notifier_normal'");
+ if ($x) {
+ Run::Summon([ 'Deliver_hooks', $target_item['id'] ]);
+ }
+ }
- if (self::$deliveries) {
- do_delivery(self::$deliveries);
- }
+ if (self::$deliveries) {
+ do_delivery(self::$deliveries);
+ }
- if ($dead) {
- foreach ($dead as $deceased) {
- 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, dreport_log )
+ if ($dead) {
+ foreach ($dead as $deceased) {
+ 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, dreport_log )
values ( '%s', '%s','%s','%s','%s','%s','%s','%s','%s' ) ",
- dbesc($target_item['mid']),
- dbesc($deceased['hubloc_host']),
- dbesc($deceased['hubloc_host']),
- dbesc($deceased['hubloc_host']),
- dbesc('undeliverable/unresponsive site'),
- dbesc(datetime_convert()),
- dbesc(self::$channel['channel_hash']),
- dbesc(new_uuid()),
- dbesc(EMPTY_STR)
- );
- }
- }
- }
+ dbesc($target_item['mid']),
+ dbesc($deceased['hubloc_host']),
+ dbesc($deceased['hubloc_host']),
+ dbesc($deceased['hubloc_host']),
+ dbesc('undeliverable/unresponsive site'),
+ dbesc(datetime_convert()),
+ dbesc(self::$channel['channel_hash']),
+ dbesc(new_uuid()),
+ dbesc(EMPTY_STR)
+ );
+ }
+ }
+ }
- call_hooks('notifier_end',$target_item);
+ call_hooks('notifier_end', $target_item);
- logger('notifer: complete.');
-
-
-
-
- return;
-
- }
+ logger('notifer: complete.');
+
+ return;
+ }
}
-
diff --git a/Zotlabs/Daemon/Onedirsync.php b/Zotlabs/Daemon/Onedirsync.php
index bc2e7c4b0..5e3943169 100644
--- a/Zotlabs/Daemon/Onedirsync.php
+++ b/Zotlabs/Daemon/Onedirsync.php
@@ -1,75 +1,87 @@
- 1) && (intval($argv[1])))
- $update_id = intval($argv[1]);
+ if (($argc > 1) && (intval($argv[1]))) {
+ $update_id = intval($argv[1]);
+ }
- if(! $update_id) {
- logger('onedirsync: no update');
- return;
- }
-
- $r = q("select * from updates where ud_id = %d limit 1",
- intval($update_id)
- );
+ if (! $update_id) {
+ logger('onedirsync: no update');
+ return;
+ }
- if(! $r)
- return;
- if(($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr']))
- return;
+ $r = q(
+ "select * from updates where ud_id = %d limit 1",
+ intval($update_id)
+ );
- // Have we probed this channel more recently than the other directory server
- // (where we received this update from) ?
- // If we have, we don't need to do anything except mark any older entries updated
+ if (! $r) {
+ return;
+ }
+ if (($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr'])) {
+ return;
+ }
- $x = q("select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d )>0 order by ud_date desc limit 1",
- dbesc($r[0]['ud_addr']),
- 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'",
- intval(UPDATE_FLAGS_UPDATED),
- dbesc($r[0]['ud_addr']),
- intval(UPDATE_FLAGS_UPDATED),
- dbesc($x[0]['ud_date'])
- );
- return;
- }
+ // Have we probed this channel more recently than the other directory server
+ // (where we received this update from) ?
+ // If we have, we don't need to do anything except mark any older entries updated
- // ignore doing an update if this ud_addr refers to a known dead hubloc
+ $x = q(
+ "select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d )>0 order by ud_date desc limit 1",
+ dbesc($r[0]['ud_addr']),
+ 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'",
+ intval(UPDATE_FLAGS_UPDATED),
+ dbesc($r[0]['ud_addr']),
+ intval(UPDATE_FLAGS_UPDATED),
+ dbesc($x[0]['ud_date'])
+ );
+ return;
+ }
- $h = q("select * from hubloc where hubloc_addr = '%s' limit 1",
- dbesc($r[0]['ud_addr'])
- );
- if(($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) {
- $y = 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)
- );
+ // ignore doing an update if this ud_addr refers to a known dead hubloc
- return;
- }
+ $h = q(
+ "select * from hubloc where hubloc_addr = '%s' limit 1",
+ dbesc($r[0]['ud_addr'])
+ );
+ if (($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) {
+ $y = 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)
+ );
- // we might have to pull this out some day, but for now update_directory_entry()
- // runs zot_finger() and is kind of zot specific
+ return;
+ }
- if($h && $h[0]['hubloc_network'] !== 'zot6')
- return;
+ // we might have to pull this out some day, but for now update_directory_entry()
+ // runs zot_finger() and is kind of zot specific
- Libzotdir::update_directory_entry($r[0]);
+ if ($h && $h[0]['hubloc_network'] !== 'zot6') {
+ return;
+ }
- return;
- }
+ Libzotdir::update_directory_entry($r[0]);
+
+ return;
+ }
}
diff --git a/Zotlabs/Daemon/Onepoll.php b/Zotlabs/Daemon/Onepoll.php
index 6c1372643..b9d48ba13 100644
--- a/Zotlabs/Daemon/Onepoll.php
+++ b/Zotlabs/Daemon/Onepoll.php
@@ -1,4 +1,6 @@
- 1) && (intval($argv[1])))
- $contact_id = intval($argv[1]);
+ logger('onepoll: start');
- if(! $contact_id) {
- logger('onepoll: no contact');
- return;
- }
+ if (($argc > 1) && (intval($argv[1]))) {
+ $contact_id = intval($argv[1]);
+ }
- $d = datetime_convert();
+ if (! $contact_id) {
+ logger('onepoll: no contact');
+ return;
+ }
- $contacts = q("SELECT abook.*, xchan.*, account.*
+ $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
and abook_pending = 0 and abook_archived = 0 and abook_blocked = 0 and abook_ignored = 0
AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1",
- intval($contact_id),
- intval(ACCOUNT_OK),
- intval(ACCOUNT_UNVERIFIED)
- );
+ intval($contact_id),
+ intval(ACCOUNT_OK),
+ intval(ACCOUNT_UNVERIFIED)
+ );
- if(! $contacts) {
- logger('onepoll: abook_id not found: ' . $contact_id);
- return;
- }
+ if (! $contacts) {
+ logger('onepoll: abook_id not found: ' . $contact_id);
+ return;
+ }
- $contact = array_shift($contacts);
+ $contact = array_shift($contacts);
- $t = $contact['abook_updated'];
+ $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)
- );
+ $importer_uid = $contact['abook_channel'];
- if(! $r)
- return;
+ $r = q(
+ "SELECT * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
+ intval($importer_uid)
+ );
- $importer = $r[0];
+ if (! $r) {
+ return;
+ }
- logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}");
+ $importer = $r[0];
- $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')
- );
+ logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}");
- if($contact['xchan_network'] === 'zot6') {
+ $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')
+ );
- // update permissions
+ if ($contact['xchan_network'] === 'zot6') {
+ // update permissions
- $x = Libzot::refresh($contact,$importer);
+ $x = Libzot::refresh($contact, $importer);
- $responded = false;
- $updated = datetime_convert();
- $connected = datetime_convert();
- 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),
- intval($contact['abook_id'])
- );
- }
- else {
- q("update abook set abook_updated = '%s', abook_connected = '%s' where abook_id = %d",
- dbesc($updated),
- dbesc($connected),
- intval($contact['abook_id'])
- );
- $responded = true;
- }
+ $responded = false;
+ $updated = datetime_convert();
+ $connected = datetime_convert();
+ 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),
+ intval($contact['abook_id'])
+ );
+ } else {
+ q(
+ "update abook set abook_updated = '%s', abook_connected = '%s' where abook_id = %d",
+ dbesc($updated),
+ dbesc($connected),
+ intval($contact['abook_id'])
+ );
+ $responded = true;
+ }
- if (! $responded) {
- return;
- }
- }
-
- $fetch_feed = true;
+ if (! $responded) {
+ return;
+ }
+ }
- // They haven't given us permission to see their stream
+ $fetch_feed = true;
- $can_view_stream = intval(get_abconfig($importer_uid,$contact['abook_xchan'],'their_perms','view_stream'));
+ // They haven't given us permission to see their stream
- if (! $can_view_stream) {
- $fetch_feed = false;
- }
+ $can_view_stream = intval(get_abconfig($importer_uid, $contact['abook_xchan'], 'their_perms', 'view_stream'));
- // we haven't given them permission to send us their stream
+ if (! $can_view_stream) {
+ $fetch_feed = false;
+ }
- $can_send_stream = intval(get_abconfig($importer_uid,$contact['abook_xchan'],'my_perms','send_stream'));
-
- if (! $can_send_stream) {
- $fetch_feed = false;
- }
+ // we haven't given them permission to send us their stream
- if ($contact['abook_created'] < datetime_convert('UTC','UTC', 'now - 1 week')) {
- $fetch_feed = false;
- }
+ $can_send_stream = intval(get_abconfig($importer_uid, $contact['abook_xchan'], 'my_perms', 'send_stream'));
- // In previous releases there was a mechanism to fetch 'external' or public stream posts from a site
- // (as opposed to a channel). This mechanism was deprecated as there is no reliable/scalable method
- // for informing downstream publishers when/if the content has expired or been deleted.
- // We can use the ThreadListener interface to implement this on the owner's outbox, however this is still a
- // work in progress and may present scaling issues. Making this work correctly with third-party fetches is
- // prohibitive as deletion requests would need to be relayed over potentially hostile networks.
+ if (! $can_send_stream) {
+ $fetch_feed = false;
+ }
- if($fetch_feed) {
- $max = intval(get_config('system','max_imported_posts',20));
- if (intval($max)) {
- $cl = get_xconfig($xchan,'activitypub','collections');
- if (is_array($cl) && $cl) {
- $url = ((array_key_exists('outbox',$cl)) ? $cl['outbox'] : '');
- if ($url) {
- logger('fetching outbox');
- $url = $url . '?date_begin=' . urlencode($last_update);
- $obj = new ASCollection($url, $importer, 0, $max);
- $messages = $obj->get();
- if ($messages) {
- foreach($messages as $message) {
- if (is_string($message)) {
- $message = Activity::fetch($message,$importer);
- }
- if (is_array($message)) {
- $AS = new ActivityStreams($message,null,true);
- if ($AS->is_valid() && is_array($AS->obj)) {
- $item = Activity::decode_note($AS,true);
- if ($item) {
- Activity::store($importer,$contact['abook_xchan'],$AS, $item, true, true);
- }
- }
- }
- }
- }
- }
- }
- }
- }
+ if ($contact['abook_created'] < datetime_convert('UTC', 'UTC', 'now - 1 week')) {
+ $fetch_feed = false;
+ }
- // update the poco details for this connection
+ // In previous releases there was a mechanism to fetch 'external' or public stream posts from a site
+ // (as opposed to a channel). This mechanism was deprecated as there is no reliable/scalable method
+ // for informing downstream publishers when/if the content has expired or been deleted.
+ // We can use the ThreadListener interface to implement this on the owner's outbox, however this is still a
+ // work in progress and may present scaling issues. Making this work correctly with third-party fetches is
+ // prohibitive as deletion requests would need to be relayed over potentially hostile networks.
- $r = q("SELECT xlink_id from xlink
+ if ($fetch_feed) {
+ $max = intval(get_config('system', 'max_imported_posts', 20));
+ if (intval($max)) {
+ $cl = get_xconfig($xchan, 'activitypub', 'collections');
+ if (is_array($cl) && $cl) {
+ $url = ((array_key_exists('outbox', $cl)) ? $cl['outbox'] : '');
+ if ($url) {
+ logger('fetching outbox');
+ $url = $url . '?date_begin=' . urlencode($last_update);
+ $obj = new ASCollection($url, $importer, 0, $max);
+ $messages = $obj->get();
+ if ($messages) {
+ foreach ($messages as $message) {
+ if (is_string($message)) {
+ $message = Activity::fetch($message, $importer);
+ }
+ if (is_array($message)) {
+ $AS = new ActivityStreams($message, null, true);
+ if ($AS->is_valid() && is_array($AS->obj)) {
+ $item = Activity::decode_note($AS, true);
+ if ($item) {
+ Activity::store($importer, $contact['abook_xchan'], $AS, $item, true, true);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // update the poco details for this connection
+
+ $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('7 DAY')
- );
- if(! $r) {
- poco_load($contact['xchan_hash'],$contact['xchan_connurl']);
- }
- return;
- }
+ intval($contact['xchan_hash']),
+ db_utcnow(),
+ db_quoteinterval('7 DAY')
+ );
+ if (! $r) {
+ poco_load($contact['xchan_hash'], $contact['xchan_connurl']);
+ }
+ return;
+ }
}
diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php
index ace58b35b..d251f2b13 100644
--- a/Zotlabs/Daemon/Poller.php
+++ b/Zotlabs/Daemon/Poller.php
@@ -1,79 +1,90 @@
- $maxsysload) {
- logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.');
- return;
- }
- }
+ $maxsysload = intval(get_config('system', 'maxloadavg'));
+ if ($maxsysload < 1) {
+ $maxsysload = 50;
+ }
+ if (function_exists('sys_getloadavg')) {
+ $load = sys_getloadavg();
+ 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 = 'cache/poller';
- if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
- && (! get_config('system','override_poll_lockfile'))) {
- logger("poller: Already running");
- return;
- }
-
- // Create a lockfile.
- file_put_contents($lockfile, EMPTY_STR);
+ // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
+ $lockfile = 'cache/poller';
+ if (
+ (file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
+ && (! get_config('system', 'override_poll_lockfile'))
+ ) {
+ logger("poller: Already running");
+ return;
+ }
- logger('poller: start');
-
- $manual_id = 0;
- $generation = 0;
+ // Create a lockfile.
+ file_put_contents($lockfile, EMPTY_STR);
- $force = false;
- $restart = false;
+ logger('poller: start');
- if(($argc > 1) && ($argv[1] == 'force'))
- $force = true;
+ $manual_id = 0;
+ $generation = 0;
- if(($argc > 1) && ($argv[1] == 'restart')) {
- $restart = true;
- $generation = intval($argv[2]);
- if(! $generation)
- return;
- }
+ $force = false;
+ $restart = false;
- if(($argc > 1) && intval($argv[1])) {
- $manual_id = intval($argv[1]);
- $force = true;
- }
+ if (($argc > 1) && ($argv[1] == 'force')) {
+ $force = true;
+ }
+
+ if (($argc > 1) && ($argv[1] == 'restart')) {
+ $restart = true;
+ $generation = intval($argv[2]);
+ if (! $generation) {
+ return;
+ }
+ }
+
+ if (($argc > 1) && intval($argv[1])) {
+ $manual_id = intval($argv[1]);
+ $force = true;
+ }
- $sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : "");
+ $sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : "");
- reload_plugins();
+ reload_plugins();
- $d = datetime_convert();
+ $d = datetime_convert();
- // Only poll from those with suitable relationships
+ // 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'))
+// : ''
+// );
- $abandon_sql = EMPTY_STR;
-
- $randfunc = db_getfunc('RAND');
-
- $contacts = q("SELECT abook.abook_updated, abook.abook_connected, abook.abook_feed,
+ $abandon_sql = EMPTY_STR;
+
+ $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,
xchan.xchan_network,
@@ -83,109 +94,116 @@ class Poller {
where abook_self = 0
$sql_extra
AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY $randfunc",
- intval(ACCOUNT_OK),
- intval(ACCOUNT_UNVERIFIED) // FIXME
- );
+ intval(ACCOUNT_OK),
+ intval(ACCOUNT_UNVERIFIED) // FIXME
+ );
- if($contacts) {
+ if ($contacts) {
+ foreach ($contacts as $contact) {
+ $update = false;
- foreach($contacts as $contact) {
+ $t = $contact['abook_updated'];
+ $c = $contact['abook_connected'];
- $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)
- $min = 60;
- $x = datetime_convert('UTC','UTC',"now - $min minutes");
- if($c < $x) {
- Run::Summon( [ 'Onepoll', $contact['abook_id'] ] );
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
- }
- continue;
- }
+ 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) {
+ Run::Summon([ 'Onepoll', $contact['abook_id'] ]);
+ if ($interval) {
+ @time_sleep_until(microtime(true) + (float) $interval);
+ }
+ }
+ continue;
+ }
- if($contact['xchan_network'] !== 'zot6')
- continue;
+ if ($contact['xchan_network'] !== 'zot6') {
+ continue;
+ }
- 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",
- dbesc(datetime_convert()),
- intval($contact['abook_id'])
- );
- $c = datetime_convert();
- $update = true;
- }
+ 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
- // He's dead, Jim
+ if ($c <= NULL_DATE) {
+ $r = q(
+ "update abook set abook_connected = '%s' where abook_id = %d",
+ dbesc(datetime_convert()),
+ intval($contact['abook_id'])
+ );
+ $c = datetime_convert();
+ $update = true;
+ }
- 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",
- intval($contact['abook_id'])
- );
- $update = false;
- continue;
- }
+ // He's dead, Jim
- if(intval($contact['abook_archived'])) {
- $update = false;
- continue;
- }
+ 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",
+ intval($contact['abook_id'])
+ );
+ $update = false;
+ 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))
- $update = true;
+ if (intval($contact['abook_archived'])) {
+ $update = false;
+ continue;
+ }
- // After that back off and put them on a morphine drip
+ // might be dead, so maybe don't poll quite so often
- if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 2 day")) > 0) {
- $update = true;
- }
+ // 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)
+ ) {
+ $update = true;
+ }
- if(intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked']))
- continue;
+ // After that back off and put them on a morphine drip
- if((! $update) && (! $force))
- continue;
+ if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 2 day")) > 0) {
+ $update = true;
+ }
+ }
- Run::Summon( [ 'Onepoll',$contact['abook_id'] ] );
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
+ if (intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked'])) {
+ continue;
+ }
- }
- }
+ if ((! $update) && (! $force)) {
+ continue;
+ }
- // migrate a few photos - eventually we'll migrate them all but without killing somebody's site
- // trying to do them all at once
-
- migrate_xchan_photos(5);
+ Run::Summon([ 'Onepoll',$contact['abook_id'] ]);
+ if ($interval) {
+ @time_sleep_until(microtime(true) + (float) $interval);
+ }
+ }
+ }
- set_config('system','lastpoll',datetime_convert());
+ // migrate a few photos - eventually we'll migrate them all but without killing somebody's site
+ // trying to do them all at once
- //All done - clear the lockfile
- @unlink($lockfile);
+ migrate_xchan_photos(5);
- return;
- }
+ set_config('system', 'lastpoll', datetime_convert());
+
+ //All done - clear the lockfile
+ @unlink($lockfile);
+
+ return;
+ }
}
diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php
index 7e3c50882..7490724a7 100644
--- a/Zotlabs/Daemon/Queue.php
+++ b/Zotlabs/Daemon/Queue.php
@@ -1,82 +1,94 @@
- 1) {
+ $queue_id = $argv[1];
+ } else {
+ $queue_id = EMPTY_STR;
+ }
- if($argc > 1)
- $queue_id = $argv[1];
- else
- $queue_id = EMPTY_STR;
+ logger('queue: start');
- logger('queue: start');
+ // delete all queue items more than 3 days old
+ // but first mark these sites dead if we haven't heard from them in a month
- // delete all queue items more than 3 days old
- // but first mark these sites dead if we haven't heard from them in a month
+ $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']);
+ $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),
+ db_utcnow(),
+ db_quoteinterval('1 MONTH')
+ );
+ }
+ }
- $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']);
- $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),
- db_utcnow(), db_quoteinterval('1 MONTH')
- );
- }
- }
+ $r = q(
+ "DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
+ db_utcnow(),
+ db_quoteinterval('3 DAY')
+ );
- $r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
- db_utcnow(), db_quoteinterval('3 DAY')
- );
+ if ($queue_id) {
+ $r = q(
+ "SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1",
+ dbesc($queue_id)
+ );
+ } else {
+ // For the first 12 hours we'll try to deliver every 15 minutes
+ // After that, we'll only attempt delivery once per hour.
+ // This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
+ // 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.
- if($queue_id) {
- $r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1",
- dbesc($queue_id)
- );
- }
- else {
-
- // For the first 12 hours we'll try to deliver every 15 minutes
- // After that, we'll only attempt delivery once per hour.
- // This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
- // 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
- // the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once
- // or twice a day.
+ // 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
+ // the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once
+ // or twice a day.
$sqlrandfunc = db_getfunc('rand');
-
- $r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
- db_utcnow()
- );
- while ($r) {
- foreach($r as $rv) {
- Zlib\Queue::deliver($rv);
- }
- $r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
- db_utcnow()
- );
- }
- }
- if(! $r)
- return;
- foreach($r as $rv) {
- Zlib\Queue::deliver($rv);
- }
- }
+ $r = q(
+ "SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
+ db_utcnow()
+ );
+ while ($r) {
+ foreach ($r as $rv) {
+ Zlib\Queue::deliver($rv);
+ }
+ $r = q(
+ "SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1",
+ db_utcnow()
+ );
+ }
+ }
+ if (! $r) {
+ return;
+ }
+
+ foreach ($r as $rv) {
+ Zlib\Queue::deliver($rv);
+ }
+ }
}
diff --git a/Zotlabs/Daemon/Run.php b/Zotlabs/Daemon/Run.php
index 5b63d845b..86245852a 100644
--- a/Zotlabs/Daemon/Run.php
+++ b/Zotlabs/Daemon/Run.php
@@ -2,74 +2,76 @@
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);
- require_once('include/cli_startup.php');
- array_shift($argv);
- $argc = count($argv);
-
- if ($argc) {
- Run::Release($argc,$argv);
- }
- return;
+ if ($argc) {
+ Run::Release($argc, $argv);
+ }
+ return;
}
-class Run {
+class Run
+{
- // These processes should be ignored by addons which enforce timeouts (e.g. queueworker)
- // as it could result in corrupt data. Please add additional long running tasks to this list as they arise.
- // Ideally the queueworker should probably be provided an allow list rather than a deny list as it will be easier
- // to maintain. This was a quick hack to fix truncation of very large synced files when the queueworker addon is installed.
-
- public static $long_running = [ 'Addon', 'Channel_purge', 'Checksites', 'Content_importer', 'Convo',
- 'Cron', 'Cron_daily', 'Cron_weekly', 'Delxitems', 'Expire', 'File_importer', 'Importfile'
- ];
+ // These processes should be ignored by addons which enforce timeouts (e.g. queueworker)
+ // as it could result in corrupt data. Please add additional long running tasks to this list as they arise.
+ // Ideally the queueworker should probably be provided an allow list rather than a deny list as it will be easier
+ // to maintain. This was a quick hack to fix truncation of very large synced files when the queueworker addon is installed.
- public static function Summon($arr) {
- if (file_exists('maintenance_lock') || file_exists('cache/maintenance_lock')) {
- return;
- }
+ public static $long_running = [ 'Addon', 'Channel_purge', 'Checksites', 'Content_importer', 'Convo',
+ 'Cron', 'Cron_daily', 'Cron_weekly', 'Delxitems', 'Expire', 'File_importer', 'Importfile'
+ ];
- $hookinfo = [
- 'argv' => $arr,
- 'long_running' => self::$long_running
- ];
+ public static function Summon($arr)
+ {
+ if (file_exists('maintenance_lock') || file_exists('cache/maintenance_lock')) {
+ return;
+ }
- call_hooks('daemon_summon', $hookinfo);
+ $hookinfo = [
+ 'argv' => $arr,
+ 'long_running' => self::$long_running
+ ];
- $arr = $hookinfo['argv'];
- $argc = count($arr);
+ call_hooks('daemon_summon', $hookinfo);
- if ((! is_array($arr) || ($argc < 1))) {
- logger("Summon handled by hook.", LOGGER_DEBUG);
- return;
- }
+ $arr = $hookinfo['argv'];
+ $argc = count($arr);
- proc_run('php','Zotlabs/Daemon/Run.php',$arr);
- }
+ if ((! is_array($arr) || ($argc < 1))) {
+ logger("Summon handled by hook.", LOGGER_DEBUG);
+ return;
+ }
- public static function Release($argc, $argv) {
- cli_startup();
+ proc_run('php', 'Zotlabs/Daemon/Run.php', $arr);
+ }
- $hookinfo = [
- 'argv' => $argv,
- 'long_running' => self::$long_running
- ];
+ public static function Release($argc, $argv)
+ {
+ cli_startup();
- call_hooks('daemon_release', $hookinfo);
+ $hookinfo = [
+ 'argv' => $argv,
+ 'long_running' => self::$long_running
+ ];
- $argv = $hookinfo['argv'];
- $argc = count($argv);
+ call_hooks('daemon_release', $hookinfo);
- if ((! is_array($argv) || ($argc < 1))) {
- logger("Release handled by hook.", LOGGER_DEBUG);
- return;
- }
+ $argv = $hookinfo['argv'];
+ $argc = count($argv);
- logger('Run: release: ' . print_r($argv,true), LOGGER_ALL,LOG_DEBUG);
- $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
- $cls::run($argc,$argv);
- }
+ if ((! is_array($argv) || ($argc < 1))) {
+ logger("Release handled by hook.", LOGGER_DEBUG);
+ return;
+ }
+
+ logger('Run: release: ' . print_r($argv, true), LOGGER_ALL, LOG_DEBUG);
+ $cls = '\\Zotlabs\\Daemon\\' . $argv[0];
+ $cls::run($argc, $argv);
+ }
}
diff --git a/Zotlabs/Daemon/Thumbnail.php b/Zotlabs/Daemon/Thumbnail.php
index 75a9cea92..dfc00f3db 100644
--- a/Zotlabs/Daemon/Thumbnail.php
+++ b/Zotlabs/Daemon/Thumbnail.php
@@ -1,79 +1,85 @@
- $attach,
+ 'preview_style' => $preview_style,
+ 'preview_width' => $preview_width,
+ 'preview_height' => $preview_height,
+ 'thumbnail' => null
+ ];
- $p = [
- 'attach' => $attach,
- 'preview_style' => $preview_style,
- 'preview_width' => $preview_width,
- 'preview_height' => $preview_height,
- 'thumbnail' => null
- ];
+ /**
+ * @hooks thumbnail
+ * * \e array \b attach
+ * * \e int \b preview_style
+ * * \e int \b preview_width
+ * * \e int \b preview_height
+ * * \e string \b thumbnail
+ */
- /**
- * @hooks thumbnail
- * * \e array \b attach
- * * \e int \b preview_style
- * * \e int \b preview_width
- * * \e int \b preview_height
- * * \e string \b thumbnail
- */
+ call_hooks('thumbnail', $p);
+ if ($p['thumbnail']) {
+ return;
+ }
- call_hooks('thumbnail',$p);
- if ($p['thumbnail']) {
- return;
- }
+ $default_controller = null;
- $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)) {
- $x = new $clsname();
- if (method_exists($x,'Match')) {
- $matched = $x->Match($attach['filetype']);
- 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) {
- $default_controller = $x;
- }
- }
- }
- }
- }
- 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);
- }
- }
+ $files = glob('Zotlabs/Thumbs/*.php');
+ 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')) {
+ $matched = $x->Match($attach['filetype']);
+ 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) {
+ $default_controller = $x;
+ }
+ }
+ }
+ }
+ }
+ 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);
+ }
+ }
}
diff --git a/Zotlabs/Daemon/Xchan_photo.php b/Zotlabs/Daemon/Xchan_photo.php
index 8a2b71b6c..f943a498b 100644
--- a/Zotlabs/Daemon/Xchan_photo.php
+++ b/Zotlabs/Daemon/Xchan_photo.php
@@ -1,35 +1,39 @@
- $v) {
- self::register($k,$file,$v);
- }
- }
- }
+ return $r;
+ }
+
+ public static function register_array($file, $arr)
+ {
+ if ($arr) {
+ foreach ($arr as $k => $v) {
+ self::register($k, $file, $v);
+ }
+ }
+ }
- public static function unregister($hook, $file, $function, $version = 1, $priority = 0) {
- if (is_array($function)) {
- $function = serialize($function);
- }
- $r = q("DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s' and priority = %d and hook_version = %d",
- dbesc($hook),
- dbesc($file),
- dbesc($function),
- intval($priority),
- intval($version)
- );
+ public static function unregister($hook, $file, $function, $version = 1, $priority = 0)
+ {
+ if (is_array($function)) {
+ $function = serialize($function);
+ }
+ $r = q(
+ "DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s' and priority = %d and hook_version = %d",
+ dbesc($hook),
+ dbesc($file),
+ dbesc($function),
+ intval($priority),
+ intval($version)
+ );
- return $r;
- }
+ return $r;
+ }
- /**
- * @brief Unregister all hooks with this file component.
- *
- * Useful for addon upgrades where you want to clean out old interfaces.
- *
- * @param string $file
- */
-
- public static function unregister_by_file($file) {
- $r = q("DELETE FROM hook WHERE file = '%s' ",
- dbesc($file)
- );
+ /**
+ * @brief Unregister all hooks with this file component.
+ *
+ * Useful for addon upgrades where you want to clean out old interfaces.
+ *
+ * @param string $file
+ */
- return $r;
- }
+ public static function unregister_by_file($file)
+ {
+ $r = q(
+ "DELETE FROM hook WHERE file = '%s' ",
+ dbesc($file)
+ );
- /**
- * @brief Inserts a hook into a page request.
- *
- * Insert a short-lived hook into the running page request.
- * Hooks are normally persistent so that they can be called
- * across asynchronous processes such as delivery and poll
- * processes.
- *
- * insert_hook lets you attach a hook callback immediately
- * which will not persist beyond the life of this page request
- * or the current process.
- *
- * @param string $hook
- * name of hook to attach callback
- * @param string $fn
- * function name of callback handler
- * @param int $version
- * hook interface version, 0 uses two callback params, 1 uses one callback param
- * @param int $priority
- * currently not implemented in this function, would require the hook array to be resorted
- */
- public static function insert($hook, $fn, $version = 0, $priority = 0) {
- if (is_array($fn)) {
- $fn = serialize($fn);
- }
+ return $r;
+ }
- if (! is_array(App::$hooks)) {
- App::$hooks = [];
- }
+ /**
+ * @brief Inserts a hook into a page request.
+ *
+ * Insert a short-lived hook into the running page request.
+ * Hooks are normally persistent so that they can be called
+ * across asynchronous processes such as delivery and poll
+ * processes.
+ *
+ * insert_hook lets you attach a hook callback immediately
+ * which will not persist beyond the life of this page request
+ * or the current process.
+ *
+ * @param string $hook
+ * name of hook to attach callback
+ * @param string $fn
+ * function name of callback handler
+ * @param int $version
+ * hook interface version, 0 uses two callback params, 1 uses one callback param
+ * @param int $priority
+ * currently not implemented in this function, would require the hook array to be resorted
+ */
+ public static function insert($hook, $fn, $version = 0, $priority = 0)
+ {
+ if (is_array($fn)) {
+ $fn = serialize($fn);
+ }
- if (! array_key_exists($hook, App::$hooks)) {
- App::$hooks[$hook] = [];
- }
+ if (! is_array(App::$hooks)) {
+ App::$hooks = [];
+ }
- App::$hooks[$hook][] = [ '', $fn, $priority, $version ];
- }
-}
\ No newline at end of file
+ if (! array_key_exists($hook, App::$hooks)) {
+ App::$hooks[$hook] = [];
+ }
+
+ App::$hooks[$hook][] = [ '', $fn, $priority, $version ];
+ }
+}
diff --git a/Zotlabs/Extend/Route.php b/Zotlabs/Extend/Route.php
index 096f94598..695c0d2bb 100644
--- a/Zotlabs/Extend/Route.php
+++ b/Zotlabs/Extend/Route.php
@@ -2,7 +2,6 @@
namespace Zotlabs\Extend;
-
class Route
{
@@ -51,4 +50,3 @@ class Route
return set_config('system', 'routes', $r);
}
}
-
diff --git a/Zotlabs/Extend/Widget.php b/Zotlabs/Extend/Widget.php
index 78e3add6d..f261798aa 100644
--- a/Zotlabs/Extend/Widget.php
+++ b/Zotlabs/Extend/Widget.php
@@ -2,7 +2,6 @@
namespace Zotlabs\Extend;
-
class Widget
{
diff --git a/Zotlabs/Identity/OAuth2Server.php b/Zotlabs/Identity/OAuth2Server.php
index 9d1763dce..93628d89c 100644
--- a/Zotlabs/Identity/OAuth2Server.php
+++ b/Zotlabs/Identity/OAuth2Server.php
@@ -8,37 +8,38 @@ use OAuth2\Storage\Memory;
use OAuth2\GrantType\ClientCredentials;
use OAuth2\OpenID\GrantType\AuthorizationCode;
-class OAuth2Server extends Server {
+class OAuth2Server extends Server
+{
- public function __construct(OAuth2Storage $storage, $config = null) {
+ public function __construct(OAuth2Storage $storage, $config = null)
+ {
- if (! is_array($config)) {
- $config = [
-// 'use_openid_connect' => true,
- 'issuer' => System::get_site_name(),
-// 'use_jwt_access_tokens' => true,
-// 'enforce_state' => false
- ];
- }
+ if (! is_array($config)) {
+ $config = [
+// 'use_openid_connect' => true,
+ 'issuer' => System::get_site_name(),
+// 'use_jwt_access_tokens' => true,
+// 'enforce_state' => false
+ ];
+ }
- parent::__construct($storage, $config);
+ parent::__construct($storage, $config);
- // Add the "Client Credentials" grant type (it is the simplest of the grant types)
- $this->addGrantType(new ClientCredentials($storage));
+ // Add the "Client Credentials" grant type (it is the simplest of the grant types)
+ $this->addGrantType(new ClientCredentials($storage));
- // Add the "Authorization Code" grant type (this is where the oauth magic happens)
- // Need to use OpenID\GrantType to return id_token
- // (see:https://github.com/bshaffer/oauth2-server-php/issues/443)
- $this->addGrantType(new AuthorizationCode($storage));
+ // Add the "Authorization Code" grant type (this is where the oauth magic happens)
+ // Need to use OpenID\GrantType to return id_token
+ // (see:https://github.com/bshaffer/oauth2-server-php/issues/443)
+ $this->addGrantType(new AuthorizationCode($storage));
- $keyStorage = new Memory( [
- 'keys' => [
- 'public_key' => get_config('system', 'pubkey'),
- 'private_key' => get_config('system', 'prvkey')
- ]
- ]);
-
- $this->addStorage($keyStorage, 'public_key');
- }
+ $keyStorage = new Memory([
+ 'keys' => [
+ 'public_key' => get_config('system', 'pubkey'),
+ 'private_key' => get_config('system', 'prvkey')
+ ]
+ ]);
+ $this->addStorage($keyStorage, 'public_key');
+ }
}
diff --git a/Zotlabs/Identity/OAuth2Storage.php b/Zotlabs/Identity/OAuth2Storage.php
index d453f84e4..bd76a8704 100644
--- a/Zotlabs/Identity/OAuth2Storage.php
+++ b/Zotlabs/Identity/OAuth2Storage.php
@@ -2,10 +2,10 @@
namespace Zotlabs\Identity;
-
use OAuth2\Storage\Pdo;
-class OAuth2Storage extends Pdo {
+class OAuth2Storage extends Pdo
+{
/**
* @param string $username
@@ -40,9 +40,8 @@ class OAuth2Storage extends Pdo {
protected function checkPassword($user, $password)
{
- $x = account_verify_password($user,$password);
- return((array_key_exists('channel',$x) && ! empty($x['channel'])) ? true : false);
-
+ $x = account_verify_password($user, $password);
+ return((array_key_exists('channel', $x) && ! empty($x['channel'])) ? true : false);
}
/**
@@ -52,77 +51,80 @@ class OAuth2Storage extends Pdo {
public function getUser($username)
{
- $x = channelx_by_n($username);
- if (! $x) {
- return false;
- }
+ $x = channelx_by_n($username);
+ if (! $x) {
+ return false;
+ }
- $a = q("select * from account where account_id = %d",
- intval($x['channel_account_id'])
- );
+ $a = q(
+ "select * from account where account_id = %d",
+ intval($x['channel_account_id'])
+ );
- $n = explode(' ', $x['channel_name']);
+ $n = explode(' ', $x['channel_name']);
- return( [
- 'webfinger' => channel_reddress($x),
- 'portable_id' => $x['channel_hash'],
- 'email' => $a[0]['account_email'],
- 'username' => $x['channel_address'],
- 'user_id' => $x['channel_id'],
- 'name' => $x['channel_name'],
- 'firstName' => ((count($n) > 1) ? $n[1] : $n[0]),
- 'lastName' => ((count($n) > 2) ? $n[count($n) - 1] : ''),
- 'picture' => $x['xchan_photo_l']
- ] );
+ return( [
+ 'webfinger' => channel_reddress($x),
+ 'portable_id' => $x['channel_hash'],
+ 'email' => $a[0]['account_email'],
+ 'username' => $x['channel_address'],
+ 'user_id' => $x['channel_id'],
+ 'name' => $x['channel_name'],
+ 'firstName' => ((count($n) > 1) ? $n[1] : $n[0]),
+ 'lastName' => ((count($n) > 2) ? $n[count($n) - 1] : ''),
+ 'picture' => $x['xchan_photo_l']
+ ] );
}
- public function scopeExists($scope) {
+ public function scopeExists($scope)
+ {
// Report that the scope is valid even if it's not.
// We will only return a very small subset no matter what.
// @TODO: Truly validate the scope
// see vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/ScopeInterface.php and
// vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/Pdo.php
// for more info.
- return true;
+ return true;
}
- public function getDefaultScope($client_id=null) {
+ public function getDefaultScope($client_id = null)
+ {
// Do not REQUIRE a scope
// see vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/ScopeInterface.php and
// for more info.
- return null;
+ return null;
}
- public function getUserClaims ($user_id, $claims) {
- // Populate the CLAIMS requested (if any).
- // @TODO: create a more reasonable/comprehensive list.
- // @TODO: present claims on the AUTHORIZATION screen
+ public function getUserClaims($user_id, $claims)
+ {
+ // Populate the CLAIMS requested (if any).
+ // @TODO: create a more reasonable/comprehensive list.
+ // @TODO: present claims on the AUTHORIZATION screen
$userClaims = [];
- $claims = explode (' ', trim($claims));
+ $claims = explode(' ', trim($claims));
$validclaims = [ "name", "preferred_username", "webfinger", "portable_id", "email", "picture", "firstName", "lastName" ];
$claimsmap = [
- "webfinger" => 'webfinger',
- "portable_id" => 'portable_id',
- "name" => 'name',
- "email" => 'email',
- "preferred_username" => 'username',
- "picture" => 'picture',
- "given_name" => 'firstName',
- "family_name" => 'lastName'
- ];
+ "webfinger" => 'webfinger',
+ "portable_id" => 'portable_id',
+ "name" => 'name',
+ "email" => 'email',
+ "preferred_username" => 'username',
+ "picture" => 'picture',
+ "given_name" => 'firstName',
+ "family_name" => 'lastName'
+ ];
$userinfo = $this->getUser($user_id);
foreach ($validclaims as $validclaim) {
- if (in_array($validclaim,$claims)) {
- $claimkey = $claimsmap[$validclaim];
- $userClaims[$validclaim] = $userinfo[$claimkey];
- }
- else {
- $userClaims[$validclaim] = $validclaim;
+ if (in_array($validclaim, $claims)) {
+ $claimkey = $claimsmap[$validclaim];
+ $userClaims[$validclaim] = $userinfo[$claimkey];
+ } else {
+ $userClaims[$validclaim] = $validclaim;
}
}
- $userClaims["sub"]=$user_id;
- return $userClaims;
+ $userClaims["sub"] = $user_id;
+ return $userClaims;
}
/**
@@ -165,5 +167,4 @@ class OAuth2Storage extends Pdo {
// if grant_types are not defined, then none are restricted
return true;
}
-
}
diff --git a/Zotlabs/Import/Friendica.php b/Zotlabs/Import/Friendica.php
index f6682b568..e2aa81aaa 100644
--- a/Zotlabs/Import/Friendica.php
+++ b/Zotlabs/Import/Friendica.php
@@ -1,4 +1,5 @@
$max_identities) {
@@ -225,12 +226,12 @@ class Friendica
set_abconfig($newuid, $channel['channel_hash'], 'system', 'my_perms', $x);
if (intval($channel['channel_account_id'])) {
-
// Save our permissions role so we can perhaps call it up and modify it later.
if ($role_permissions) {
- if (array_key_exists('online', $role_permissions))
+ if (array_key_exists('online', $role_permissions)) {
set_pconfig($newuid, 'system', 'hide_presence', 1 - intval($role_permissions['online']));
+ }
if (array_key_exists('perms_auto', $role_permissions)) {
$autoperms = intval($role_permissions['perms_auto']);
set_pconfig($newuid, 'system', 'autoperms', $autoperms);
@@ -246,12 +247,14 @@ class Friendica
// if our role_permissions indicate that we're using a default collection ACL, add it.
if (is_array($role_permissions) && $role_permissions['default_collection']) {
- $r = q("select hash from pgrp where uid = %d and gname = '%s' limit 1",
+ $r = q(
+ "select hash from pgrp where uid = %d and gname = '%s' limit 1",
intval($newuid),
dbesc(t('Friends'))
);
if ($r) {
- q("update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d",
+ q(
+ "update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d",
dbesc($r[0]['hash']),
dbesc('<' . $r[0]['hash'] . '>'),
intval($newuid)
@@ -270,14 +273,14 @@ class Friendica
$accts = get_config('system', 'auto_follow');
if (($accts) && (!$total_identities)) {
- if (!is_array($accts))
+ if (!is_array($accts)) {
$accts = array($accts);
+ }
foreach ($accts as $acct) {
if (trim($acct)) {
$f = connect_and_sync($channel, trim($acct));
if ($f['success']) {
-
$can_view_stream = their_perms_contains($channel['channel_id'], $f['abook']['abook_xchan'], 'view_stream');
// If we can view their stream, pull in some posts
@@ -357,8 +360,5 @@ class Friendica
notice(t('Import complete.') . EOL);
goaway(z_root() . '/stream');
-
}
-
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/AConfig.php b/Zotlabs/Lib/AConfig.php
index 5da554691..417f3034d 100644
--- a/Zotlabs/Lib/AConfig.php
+++ b/Zotlabs/Lib/AConfig.php
@@ -4,22 +4,26 @@ namespace Zotlabs\Lib;
// account configuration storage is built on top of the under-utilised xconfig
-class AConfig {
+class AConfig
+{
- public static function Load($account_id) {
- return XConfig::Load('a_' . $account_id);
- }
+ public static function Load($account_id)
+ {
+ return XConfig::Load('a_' . $account_id);
+ }
- public static function Get($account_id, $family, $key, $default = false) {
- return XConfig::Get('a_' . $account_id,$family,$key, $default);
- }
+ public static function Get($account_id, $family, $key, $default = false)
+ {
+ return XConfig::Get('a_' . $account_id, $family, $key, $default);
+ }
- public static function Set($account_id, $family, $key, $value) {
- return XConfig::Set('a_' . $account_id,$family,$key,$value);
- }
-
- public static function Delete($account_id, $family, $key) {
- return XConfig::Delete('a_' . $account_id,$family,$key);
- }
+ public static function Set($account_id, $family, $key, $value)
+ {
+ return XConfig::Set('a_' . $account_id, $family, $key, $value);
+ }
+ public static function Delete($account_id, $family, $key)
+ {
+ return XConfig::Delete('a_' . $account_id, $family, $key);
+ }
}
diff --git a/Zotlabs/Lib/ASCollection.php b/Zotlabs/Lib/ASCollection.php
index c45890673..ac328504e 100644
--- a/Zotlabs/Lib/ASCollection.php
+++ b/Zotlabs/Lib/ASCollection.php
@@ -9,7 +9,7 @@ use Zotlabs\Lib\Activity;
* Class for dealing with fetching ActivityStreams collections (ordered or unordered, normal or paged).
* Construct with either an existing object or url and an optional channel to sign requests.
* $direction is 0 (default) to fetch from the beginning, and 1 to fetch from the end and reverse order the resultant array.
- * An optional limit to the number of records returned may also be specified.
+ * An optional limit to the number of records returned may also be specified.
* Use $class->get() to return an array of collection members.
*/
class ASCollection
diff --git a/Zotlabs/Lib/AbConfig.php b/Zotlabs/Lib/AbConfig.php
index 581aae9e2..391ae1af9 100644
--- a/Zotlabs/Lib/AbConfig.php
+++ b/Zotlabs/Lib/AbConfig.php
@@ -2,74 +2,83 @@
namespace Zotlabs\Lib;
+class AbConfig
+{
-class AbConfig {
-
- public static function Load($chan, $xhash, $family = '') {
- if($family)
- $where = sprintf(" and cat = '%s' ",dbesc($family));
- $r = q("select * from abconfig where chan = %d and xchan = '%s' $where",
- intval($chan),
- dbesc($xhash)
- );
- return $r;
- }
+ public static function Load($chan, $xhash, $family = '')
+ {
+ if ($family) {
+ $where = sprintf(" and cat = '%s' ", dbesc($family));
+ }
+ $r = q(
+ "select * from abconfig where chan = %d and xchan = '%s' $where",
+ intval($chan),
+ dbesc($xhash)
+ );
+ return $r;
+ }
- public static function Get($chan, $xhash, $family, $key, $default = false) {
- $r = q("select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
- intval($chan),
- dbesc($xhash),
- dbesc($family),
- dbesc($key)
- );
- if($r) {
- return unserialise($r[0]['v']);
- }
- return $default;
- }
+ public static function Get($chan, $xhash, $family, $key, $default = false)
+ {
+ $r = q(
+ "select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
+ intval($chan),
+ dbesc($xhash),
+ dbesc($family),
+ dbesc($key)
+ );
+ if ($r) {
+ return unserialise($r[0]['v']);
+ }
+ return $default;
+ }
- public static function Set($chan, $xhash, $family, $key, $value) {
+ public static function Set($chan, $xhash, $family, $key, $value)
+ {
- $dbvalue = ((is_array($value)) ? serialise($value) : $value);
- $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
+ $dbvalue = ((is_array($value)) ? serialise($value) : $value);
+ $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
- if(self::Get($chan,$xhash,$family,$key) === false) {
- $r = q("insert into abconfig ( chan, xchan, cat, k, v ) values ( %d, '%s', '%s', '%s', '%s' ) ",
- intval($chan),
- dbesc($xhash),
- dbesc($family),
- dbesc($key),
- dbesc($dbvalue)
- );
- }
- else {
- $r = q("update abconfig set v = '%s' where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
- dbesc($dbvalue),
- dbesc($chan),
- dbesc($xhash),
- dbesc($family),
- dbesc($key)
- );
- }
-
- if($r)
- return $value;
- return false;
- }
+ if (self::Get($chan, $xhash, $family, $key) === false) {
+ $r = q(
+ "insert into abconfig ( chan, xchan, cat, k, v ) values ( %d, '%s', '%s', '%s', '%s' ) ",
+ intval($chan),
+ dbesc($xhash),
+ dbesc($family),
+ dbesc($key),
+ dbesc($dbvalue)
+ );
+ } else {
+ $r = q(
+ "update abconfig set v = '%s' where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
+ dbesc($dbvalue),
+ dbesc($chan),
+ dbesc($xhash),
+ dbesc($family),
+ dbesc($key)
+ );
+ }
+
+ if ($r) {
+ return $value;
+ }
+ return false;
+ }
- public static function Delete($chan, $xhash, $family, $key) {
+ public static function Delete($chan, $xhash, $family, $key)
+ {
- $r = q("delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
- intval($chan),
- dbesc($xhash),
- dbesc($family),
- dbesc($key)
- );
-
- return $r;
- }
+ $r = q(
+ "delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
+ intval($chan),
+ dbesc($xhash),
+ dbesc($family),
+ dbesc($key)
+ );
+ return $r;
+ }
}
diff --git a/Zotlabs/Lib/AccessList.php b/Zotlabs/Lib/AccessList.php
index 0714ef621..eaddb69cb 100644
--- a/Zotlabs/Lib/AccessList.php
+++ b/Zotlabs/Lib/AccessList.php
@@ -1,10 +1,9 @@
- '', 'hash' => '0', 'selected' => ''];
@@ -323,7 +339,6 @@ class AccessList
foreach ($r as $rr) {
$grps[] = ['name' => $rr['gname'], 'id' => $rr['hash'], 'selected' => (($group == $rr['hash']) ? 'true' : '')];
}
-
}
return replace_macros(get_markup_template('group_selection.tpl'), [
@@ -340,7 +355,8 @@ class AccessList
$groups = [];
- $r = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
+ $r = q(
+ "SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
intval($_SESSION['uid'])
);
$member_of = [];
@@ -379,7 +395,6 @@ class AccessList
'$groups' => $groups,
'$add' => t('add'),
]);
-
}
@@ -393,7 +408,6 @@ class AccessList
$x = [];
foreach ($g as $gv) {
-
// virtual access lists
// connections:abc is all the connection sof the channel with channel_hash abc
// zot:abc is all of abc's zot6 connections
@@ -408,12 +422,14 @@ class AccessList
if (strpos($gv, 'activitypub:') === 0) {
$sql_extra = " and xchan_network = 'activitypub' ";
}
- $r = q("select channel_id from channel where channel_hash = '%s' ",
+ $r = q(
+ "select channel_id from channel where channel_hash = '%s' ",
dbesc($channel_hash)
);
if ($r) {
foreach ($r as $rv) {
- $y = q("select abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 $sql_extra",
+ $y = q(
+ "select abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 $sql_extra",
intval($rv['channel_id'])
);
if ($y) {
@@ -438,7 +454,6 @@ class AccessList
$ret[] = $rv['xchan'];
}
}
-
}
}
return $ret;
@@ -447,7 +462,8 @@ class AccessList
public static function member_of($c)
{
- $r = q("SELECT pgrp.gname, pgrp.id FROM pgrp LEFT JOIN pgrp_member ON pgrp_member.gid = pgrp.id
+ $r = q(
+ "SELECT pgrp.gname, pgrp.id FROM pgrp LEFT JOIN pgrp_member ON pgrp_member.gid = pgrp.id
WHERE pgrp_member.xchan = '%s' AND pgrp.deleted = 0 ORDER BY pgrp.gname ASC ",
dbesc($c)
);
@@ -458,17 +474,19 @@ class AccessList
public static function containing($uid, $c)
{
- $r = q("SELECT gid FROM pgrp_member WHERE uid = %d AND pgrp_member.xchan = '%s' ",
+ $r = q(
+ "SELECT gid FROM pgrp_member WHERE uid = %d AND pgrp_member.xchan = '%s' ",
intval($uid),
dbesc($c)
);
$ret = [];
if ($r) {
- foreach ($r as $rv)
+ foreach ($r as $rv) {
$ret[] = $rv['gid'];
+ }
}
return $ret;
}
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 857e19c67..49bb329ec 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -26,7 +26,7 @@ require_once('include/event.php');
class Activity
{
- static public $ACTOR_CACHE_DAYS = 3;
+ public static $ACTOR_CACHE_DAYS = 3;
// $x (string|array)
// if json string, decode it
@@ -39,7 +39,7 @@ class Activity
if ($x) {
if (is_string($x)) {
$tmp = json_decode($x, true);
- if ($tmp !== NULL) {
+ if ($tmp !== null) {
$x = $tmp;
}
}
@@ -56,7 +56,6 @@ class Activity
return self::fetch_profile($x);
}
if (in_array($x['type'], [ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_ARTICLE])) {
-
// Use Mastodon-specific note and media hacks if nomadic. Else HTML.
// Eventually this needs to be passed in much further up the stack
// and base the decision on whether or not we are encoding for ActivityPub or Zot6
@@ -70,7 +69,6 @@ class Activity
call_hooks('encode_object', $x);
return $x;
-
}
@@ -138,15 +136,16 @@ class Activity
}
if ($x['success']) {
-
$y = json_decode($x['body'], true);
logger('returned: ' . json_encode($y, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$site_url = unparse_url(['scheme' => $parsed['scheme'], 'host' => $parsed['host'], 'port' => ((array_key_exists('port', $parsed) && intval($parsed['port'])) ? $parsed['port'] : 0)]);
- q("update site set site_update = '%s' where site_url = '%s' and site_update < %s - INTERVAL %s",
+ q(
+ "update site set site_update = '%s' where site_url = '%s' and site_update < %s - INTERVAL %s",
dbesc(datetime_convert()),
dbesc($site_url),
- db_utcnow(), db_quoteinterval('1 DAY')
+ db_utcnow(),
+ db_quoteinterval('1 DAY')
);
// check for a valid signature, but only if this is not an actor object. If it is signed, it must be valid.
@@ -180,14 +179,15 @@ class Activity
public static function fetch_profile($x)
{
- $r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s' limit 1",
+ $r = q(
+ "select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s' limit 1",
dbesc($x['id'])
);
if (!$r) {
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
+ $r = q(
+ "select * from xchan where xchan_hash = '%s' limit 1",
dbesc($x['id'])
);
-
}
if (!$r) {
return [];
@@ -199,7 +199,8 @@ class Activity
public static function fetch_thing($x)
{
- $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1",
+ $r = q(
+ "select * from obj where obj_type = %d and obj_obj = '%s' limit 1",
intval(TERM_OBJ_THING),
dbesc($x['id'])
);
@@ -218,7 +219,6 @@ class Activity
$x['image'] = $r[0]['obj_image'];
}
return $x;
-
}
public static function fetch_item($x, $activitypub = false)
@@ -229,7 +229,8 @@ class Activity
return $x;
}
- $r = q("select * from item where mid = '%s' limit 1",
+ $r = q(
+ "select * from item where mid = '%s' limit 1",
dbesc($x['id'])
);
if ($r) {
@@ -258,7 +259,6 @@ class Activity
$ret['last'] = z_root() . '/' . App::$query_string . '?page=' . $lastpage;
return $ret;
-
}
@@ -529,7 +529,8 @@ class Activity
$r = false;
if ($url) {
- $r = q("select xchan_addr from xchan where ( xchan_url = '%s' OR xchan_hash = '%s' ) limit 1",
+ $r = q(
+ "select xchan_addr from xchan where ( xchan_url = '%s' OR xchan_hash = '%s' ) limit 1",
dbesc($url),
dbesc($url)
);
@@ -539,13 +540,13 @@ class Activity
}
}
if ($name) {
- $r = q("select xchan_addr from xchan where xchan_name = '%s' limit 1",
+ $r = q(
+ "select xchan_addr from xchan where xchan_name = '%s' limit 1",
dbesc($name)
);
if ($r) {
return $r[0]['xchan_addr'];
}
-
}
return EMPTY_STR;
@@ -558,7 +559,8 @@ class Activity
// The xchan_url for mastodon is a text/html rendering. This is called from map_mentions where we need
// to convert the mention url to an ActivityPub id. If this fails for any reason, return the url we have
- $r = q("select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
+ $r = q(
+ "select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($url),
dbesc($url)
);
@@ -645,19 +647,22 @@ class Activity
}
foreach ($ptr as $att) {
$entry = [];
- if (array_key_exists('href', $att) && $att['href'])
+ if (array_key_exists('href', $att) && $att['href']) {
$entry['href'] = $att['href'];
- elseif (array_key_exists('url', $att) && $att['url'])
+ } elseif (array_key_exists('url', $att) && $att['url']) {
$entry['href'] = $att['url'];
- if (array_key_exists('mediaType', $att) && $att['mediaType'])
+ }
+ if (array_key_exists('mediaType', $att) && $att['mediaType']) {
$entry['type'] = $att['mediaType'];
- elseif (array_key_exists('type', $att) && $att['type'] === 'Image')
+ } elseif (array_key_exists('type', $att) && $att['type'] === 'Image') {
$entry['type'] = 'image/jpeg';
+ }
if (array_key_exists('name', $att) && $att['name']) {
$entry['name'] = html2plain(purify_html($att['name']), 256);
}
- if ($entry)
+ if ($entry) {
$ret[] = $entry;
+ }
}
} elseif (is_string($item['attachment'])) {
btlogger('not an array: ' . $item['attachment']);
@@ -676,7 +681,6 @@ class Activity
$reply = false;
if (intval($i['item_deleted']) && (!$recurse)) {
-
$is_response = ActivityStreams::is_response_activity($i['verb']);
if ($is_response) {
@@ -689,10 +693,11 @@ class Activity
$ret['id'] = str_replace('/item/', '/activity/', $i['mid']) . $fragment;
$actor = self::encode_person($i['author'], false);
- if ($actor)
+ if ($actor) {
$ret['actor'] = $actor;
- else
+ } else {
return [];
+ }
$obj = (($is_response) ? self::encode_activity($i, $activitypub, true) : self::encode_item($i, $activitypub));
if ($obj) {
@@ -708,7 +713,6 @@ class Activity
$ret['to'] = [ACTIVITY_PUBLIC_INBOX];
return $ret;
-
}
$ret['type'] = self::activity_mapper($i['verb']);
@@ -803,10 +807,11 @@ class Activity
}
$actor = self::encode_person($i['author'], false);
- if ($actor)
+ if ($actor) {
$ret['actor'] = $actor;
- else
+ } else {
return [];
+ }
$replyto = unserialise($i['replyto']);
@@ -862,15 +867,16 @@ class Activity
if ($i['obj']) {
if (is_string($i['obj'])) {
$tmp = json_decode($i['obj'], true);
- if ($tmp !== NULL) {
+ if ($tmp !== null) {
$i['obj'] = $tmp;
}
}
$obj = self::encode_object($i['obj']);
- if ($obj)
+ if ($obj) {
$ret['object'] = $obj;
- else
+ } else {
return [];
+ }
} else {
$obj = self::encode_item($i, $activitypub);
if ($obj) {
@@ -883,7 +889,7 @@ class Activity
if ($i['target']) {
if (is_string($i['target'])) {
$tmp = json_decode($i['target'], true);
- if ($tmp !== NULL) {
+ if ($tmp !== null) {
$i['target'] = $tmp;
}
}
@@ -901,7 +907,6 @@ class Activity
// addressing madness
if ($activitypub) {
-
$parent_i = [];
$public = (($i['item_private']) ? false : true);
$top_level = (($reply) ? false : true);
@@ -928,7 +933,6 @@ class Activity
$ret['cc'] = array_values(array_unique(array_merge($ret['cc'], $parent_i['cc'])));
}
} else {
-
// private activity
if ($top_level) {
@@ -945,7 +949,8 @@ class Activity
if ($ret['tag']) {
foreach ($ret['tag'] as $mention) {
if (is_array($mention) && array_key_exists('ttype', $mention) && in_array($mention['ttype'], [TERM_FORUM, TERM_MENTION]) && array_key_exists('href', $mention) && $mention['href']) {
- $h = q("select * from hubloc where hubloc_id_url = '%s' limit 1",
+ $h = q(
+ "select * from hubloc where hubloc_id_url = '%s' limit 1",
dbesc($mention['href'])
);
if ($h) {
@@ -962,7 +967,8 @@ class Activity
}
}
- $d = q("select hubloc.* from hubloc left join item on hubloc_hash = owner_xchan where item.parent_mid = '%s' and item.uid = %d limit 1",
+ $d = q(
+ "select hubloc.* from hubloc left join item on hubloc_hash = owner_xchan where item.parent_mid = '%s' and item.uid = %d limit 1",
dbesc($i['parent_mid']),
intval($i['uid'])
);
@@ -1006,7 +1012,8 @@ class Activity
public static function nomadic_locations($item)
{
$synchubs = [];
- $h = q("select hubloc.*, site.site_crypto from hubloc left join site on site_url = hubloc_url
+ $h = q(
+ "select hubloc.*, site.site_crypto from hubloc left join site on site_url = hubloc_url
where hubloc_hash = '%s' and hubloc_network = 'zot6' and hubloc_deleted = 0",
dbesc($item['author_xchan'])
);
@@ -1016,7 +1023,8 @@ class Activity
}
foreach ($h as $x) {
- $y = q("select site_dead from site where site_url = '%s' limit 1",
+ $y = q(
+ "select site_dead from site where site_url = '%s' limit 1",
dbesc($x['hubloc_url'])
);
@@ -1051,7 +1059,7 @@ class Activity
if (isset($i['obj']) && $i['obj']) {
if (is_string($i['obj'])) {
$tmp = json_decode($i['obj'], true);
- if ($tmp !== NULL) {
+ if ($tmp !== null) {
$i['obj'] = $tmp;
}
}
@@ -1084,15 +1092,15 @@ class Activity
$ret['id'] = $i['mid'];
-// $token = IConfig::get($i,'ocap','relay');
-// if ($token) {
-// if (defined('USE_BEARCAPS')) {
-// $ret['id'] = 'bear:?u=' . $ret['id'] . '&t=' . $token;
-// }
-// else {
-// $ret['id'] = $ret['id'] . '?token=' . $token;
-// }
-// }
+// $token = IConfig::get($i,'ocap','relay');
+// if ($token) {
+// if (defined('USE_BEARCAPS')) {
+// $ret['id'] = 'bear:?u=' . $ret['id'] . '&t=' . $token;
+// }
+// else {
+// $ret['id'] = $ret['id'] . '?token=' . $token;
+// }
+// }
$ret['published'] = datetime_convert('UTC', 'UTC', $i['created'], ATOM_TIME);
if ($i['created'] !== $i['edited']) {
@@ -1151,7 +1159,8 @@ class Activity
$reply = true;
if ($i['item_private']) {
- $d = q("select xchan_url, xchan_addr, xchan_name from item left join xchan on xchan_hash = author_xchan where id = %d limit 1",
+ $d = q(
+ "select xchan_url, xchan_addr, xchan_name from item left join xchan on xchan_hash = author_xchan where id = %d limit 1",
intval($i['parent'])
);
if ($d) {
@@ -1331,7 +1340,6 @@ class Activity
// addressing madness
if ($activitypub) {
-
$parent_i = [];
$ret['to'] = [];
$ret['cc'] = [];
@@ -1340,12 +1348,12 @@ class Activity
$top_level = (($i['mid'] === $i['parent_mid']) ? true : false);
if (!$top_level) {
-
if (intval($i['parent'])) {
$recips = get_iconfig($i['parent'], 'activitypub', 'recips');
} else {
// if we are encoding this item for storage there won't be a parent.
- $p = q("select parent from item where parent_mid = '%s' and uid = %d",
+ $p = q(
+ "select parent from item where parent_mid = '%s' and uid = %d",
dbesc($i['parent_mid']),
intval($i['uid'])
);
@@ -1371,9 +1379,7 @@ class Activity
if (isset($parent_i['cc']) && is_array($parent_i['cc'])) {
$ret['cc'] = array_values(array_unique(array_merge($ret['cc'], $parent_i['cc'])));
}
-
} else {
-
// private activity
if ($top_level) {
@@ -1389,7 +1395,8 @@ class Activity
if ($ret['tag']) {
foreach ($ret['tag'] as $mention) {
if (is_array($mention) && array_key_exists('ttype', $mention) && in_array($mention['ttype'], [TERM_FORUM, TERM_MENTION]) && array_key_exists('href', $mention) && $mention['href']) {
- $h = q("select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
+ $h = q(
+ "select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($mention['href']),
dbesc($mention['href'])
);
@@ -1408,7 +1415,8 @@ class Activity
}
- $d = q("select hubloc.* from hubloc left join item on hubloc_hash = owner_xchan where item.parent_mid = '%s' and item.uid = %d limit 1",
+ $d = q(
+ "select hubloc.* from hubloc left join item on hubloc_hash = owner_xchan where item.parent_mid = '%s' and item.uid = %d limit 1",
dbesc($i['parent_mid']),
intval($i['uid'])
);
@@ -1487,7 +1495,8 @@ class Activity
}
if ($i['mid'] !== $i['parent_mid']) {
- $i = q("select * from item where parent_mid = '%s' and uid = %d",
+ $i = q(
+ "select * from item where parent_mid = '%s' and uid = %d",
dbesc($i['parent_mid']),
intval($i['uid'])
);
@@ -1535,7 +1544,6 @@ class Activity
}
return array_values(array_unique($ret));
-
}
@@ -1544,8 +1552,9 @@ class Activity
$ret = [];
- if (!$p['xchan_url'])
+ if (!$p['xchan_url']) {
return $ret;
+ }
if (!$extended) {
return $p['xchan_url'];
@@ -1572,8 +1581,9 @@ class Activity
} else {
$ret['id'] = ((strpos($p['xchan_hash'], 'http') === 0) ? $p['xchan_hash'] : $p['xchan_url']);
}
- if ($p['xchan_addr'] && strpos($p['xchan_addr'], '@'))
+ if ($p['xchan_addr'] && strpos($p['xchan_addr'], '@')) {
$ret['preferredUsername'] = substr($p['xchan_addr'], 0, strpos($p['xchan_addr'], '@'));
+ }
$ret['name'] = $p['xchan_name'];
$ret['updated'] = datetime_convert('UTC', 'UTC', $p['xchan_name_date'], ATOM_TIME);
$ret['icon'] = [
@@ -1592,7 +1602,6 @@ class Activity
$ret['tag'] = [['type' => 'PropertyValue', 'name' => 'Protocol', 'value' => 'zot6']];
if ($activitypub && get_config('system', 'activitypub', ACTIVITYPUB_ENABLED)) {
-
if ($c) {
if (get_pconfig($c['channel_id'], 'system', 'activitypub', ACTIVITYPUB_ENABLED)) {
$ret['inbox'] = z_root() . '/inbox/' . $c['channel_address'];
@@ -1654,16 +1663,19 @@ class Activity
}
// only fill in profile information if the profile is publicly visible
if (perm_is_allowed($c['channel_id'], EMPTY_STR, 'view_profile')) {
- $dp = q("select * from profile where uid = %d and is_default = 1",
+ $dp = q(
+ "select * from profile where uid = %d and is_default = 1",
intval($c['channel_id'])
);
if ($dp) {
if ($dp[0]['about']) {
$ret['summary'] = bbcode($dp[0]['about'], ['export' => true]);
}
- foreach (['pdesc', 'address', 'locality', 'region', 'postal_code', 'country_name',
+ foreach (
+ ['pdesc', 'address', 'locality', 'region', 'postal_code', 'country_name',
'hometown', 'gender', 'marital', 'sexual', 'politic', 'religion', 'pronouns',
- 'homepage', 'contact', 'dob'] as $k) {
+ 'homepage', 'contact', 'dob'] as $k
+ ) {
if ($dp[0][$k]) {
$key = $k;
if ($key === 'pdesc') {
@@ -1797,20 +1809,23 @@ class Activity
// Reactions will just map to normal activities
- if (strpos($verb, ACTIVITY_REACT) !== false)
+ if (strpos($verb, ACTIVITY_REACT) !== false) {
return 'Create';
- if (strpos($verb, ACTIVITY_MOOD) !== false)
+ }
+ if (strpos($verb, ACTIVITY_MOOD) !== false) {
return 'Create';
+ }
- if (strpos($verb, ACTIVITY_POKE) !== false)
+ if (strpos($verb, ACTIVITY_POKE) !== false) {
return 'Activity';
+ }
// We should return false, however this will trigger an uncaught exception and crash
// the delivery system if encountered by the JSON-LDSignature library
logger('Unmapped activity: ' . $verb);
return 'Create';
- // return false;
+ // return false;
}
@@ -1853,8 +1868,7 @@ class Activity
logger('Unmapped activity object: ' . $obj);
return 'Note';
- // return false;
-
+ // return false;
}
@@ -1870,11 +1884,11 @@ class Activity
}
/*
- *
- * if $act->type === 'Follow', actor is now following $channel
- * if $act->type === 'Accept', actor has approved a follow request from $channel
- *
- */
+ *
+ * if $act->type === 'Follow', actor is now following $channel
+ * if $act->type === 'Accept', actor has approved a follow request from $channel
+ *
+ */
$person_obj = $act->actor;
@@ -1885,14 +1899,14 @@ class Activity
}
if (is_array($person_obj)) {
-
// store their xchan and hubloc
self::actor_store($person_obj['id'], $person_obj);
// Find any existing abook record
- $r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d limit 1",
+ $r = q(
+ "select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($person_obj['id']),
intval($channel['channel_id'])
);
@@ -1914,15 +1928,12 @@ class Activity
if ($contact && $contact['abook_id']) {
-
// A relationship of some form already exists on this site.
switch ($act->type) {
-
case 'Follow':
case 'Invite':
case 'Join':
-
// A second Follow request, but we haven't approved the first one
if ($contact['abook_pending']) {
@@ -1938,7 +1949,6 @@ class Activity
return;
case 'Accept':
-
// They accepted our Follow request - set default permissions
set_abconfig($channel['channel_id'], $contact['abook_xchan'], 'system', 'their_perms', $their_perms);
@@ -1946,11 +1956,13 @@ class Activity
$abook_instance = $contact['abook_instance'];
if (strpos($abook_instance, z_root()) === false) {
- if ($abook_instance)
+ if ($abook_instance) {
$abook_instance .= ',';
+ }
$abook_instance .= z_root();
- $r = q("update abook set abook_instance = '%s', abook_not_here = 0
+ $r = q(
+ "update abook set abook_instance = '%s', abook_not_here = 0
where abook_id = %d and abook_channel = %d",
dbesc($abook_instance),
intval($contact['abook_id']),
@@ -1961,7 +1973,6 @@ class Activity
return;
default:
return;
-
}
}
@@ -1979,7 +1990,8 @@ class Activity
// The xchan should have been created by actor_store() above
- $r = q("select * from xchan where xchan_hash = '%s' and xchan_network = 'activitypub' limit 1",
+ $r = q(
+ "select * from xchan where xchan_hash = '%s' and xchan_network = 'activitypub' limit 1",
dbesc($person_obj['id'])
);
@@ -2024,17 +2036,20 @@ class Activity
]
);
- if ($my_perms)
+ if ($my_perms) {
AbConfig::Set($channel['channel_id'], $ret['xchan_hash'], 'system', 'my_perms', $my_perms);
+ }
- if ($their_perms)
+ if ($their_perms) {
AbConfig::Set($channel['channel_id'], $ret['xchan_hash'], 'system', 'their_perms', $their_perms);
+ }
if ($r) {
logger("New ActivityPub follower for {$channel['channel_name']}");
- $new_connection = q("select * from abook left join xchan on abook_xchan = xchan_hash left join hubloc on hubloc_hash = xchan_hash where abook_channel = %d and abook_xchan = '%s' order by abook_created desc limit 1",
+ $new_connection = q(
+ "select * from abook left join xchan on abook_xchan = xchan_hash left join hubloc on hubloc_hash = xchan_hash where abook_channel = %d and abook_xchan = '%s' order by abook_created desc limit 1",
intval($channel['channel_id']),
dbesc($ret['xchan_hash'])
);
@@ -2085,7 +2100,6 @@ class Activity
}
return;
-
}
@@ -2099,8 +2113,8 @@ class Activity
$person_obj = $act->actor;
if (is_array($person_obj)) {
-
- $r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d limit 1",
+ $r = q(
+ "select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($person_obj['id']),
intval($channel['channel_id'])
);
@@ -2121,7 +2135,7 @@ class Activity
return;
}
-// logger('person_obj: ' . print_r($person_obj,true));
+// logger('person_obj: ' . print_r($person_obj,true));
if (array_key_exists('movedTo', $person_obj) && $person_obj['movedTo'] && !is_array($person_obj['movedTo'])) {
$tgt = self::fetch($person_obj['movedTo']);
@@ -2173,10 +2187,12 @@ class Activity
XConfig::Set($url, 'system', 'actor_record', $person_obj);
$name = escape_tags($person_obj['name']);
- if (!$name)
+ if (!$name) {
$name = escape_tags($person_obj['preferredUsername']);
- if (!$name)
+ }
+ if (!$name) {
$name = escape_tags(t('Unknown'));
+ }
$username = escape_tags($person_obj['preferredUsername']);
$h = parse_url($url);
@@ -2186,9 +2202,9 @@ class Activity
if ($person_obj['icon']) {
if (is_array($person_obj['icon'])) {
- if (array_key_exists('url', $person_obj['icon']))
+ if (array_key_exists('url', $person_obj['icon'])) {
$icon = $person_obj['icon']['url'];
- else {
+ } else {
if (is_string($person_obj['icon'][0])) {
$icon = $person_obj['icon'][0];
} elseif (array_key_exists('url', $person_obj['icon'][0])) {
@@ -2309,7 +2325,8 @@ class Activity
$xchan_type = self::get_xchan_type($person_obj['type']);
$about = ((isset($person_obj['summary'])) ? html2bbcode(purify_html($person_obj['summary'])) : EMPTY_STR);
- $p = q("select * from xchan where xchan_url = '%s' and xchan_network = 'zot6' limit 1",
+ $p = q(
+ "select * from xchan where xchan_url = '%s' and xchan_network = 'zot6' limit 1",
dbesc($url)
);
if ($p) {
@@ -2322,7 +2339,8 @@ class Activity
// once extended xchan_type directory filtering is implemented.
$censored = ((strpos($profile, 'instance_actor') || strpos($profile, '/internal/fetch')) ? 1 : 0);
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
+ $r = q(
+ "select * from xchan where xchan_hash = '%s' limit 1",
dbesc($url)
);
if (!$r) {
@@ -2350,7 +2368,6 @@ class Activity
]
);
} else {
-
// Record exists. Cache existing records for a set number of days
// then refetch to catch updated profile photos, names, etc.
@@ -2359,7 +2376,8 @@ class Activity
}
// update existing record
- $u = q("update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_pubkey = '%s', xchan_network = '%s', xchan_name_date = '%s', xchan_hidden = %d, xchan_type = %d, xchan_censored = %d where xchan_hash = '%s'",
+ $u = q(
+ "update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_pubkey = '%s', xchan_network = '%s', xchan_name_date = '%s', xchan_hidden = %d, xchan_type = %d, xchan_censored = %d where xchan_hash = '%s'",
dbesc(datetime_convert()),
dbesc($name),
dbesc($pubkey),
@@ -2372,7 +2390,8 @@ class Activity
);
if (strpos($username, '@') && ($r[0]['xchan_addr'] !== $username)) {
- $r = q("update xchan set xchan_addr = '%s' where xchan_hash = '%s'",
+ $r = q(
+ "update xchan set xchan_addr = '%s' where xchan_hash = '%s'",
dbesc($username),
dbesc($url)
);
@@ -2393,11 +2412,13 @@ class Activity
$version = ((array_path_exists('software/version', $ni)) ? $ni['software']['version'] : '');
$register = $ni['openRegistrations'];
- $site = q("select * from site where site_url = '%s'",
+ $site = q(
+ "select * from site where site_url = '%s'",
dbesc($site_url)
);
if ($site) {
- q("update site set site_project = '%s', site_update = '%s', site_version = '%s' where site_url = '%s'",
+ q(
+ "update site set site_project = '%s', site_update = '%s', site_version = '%s' where site_url = '%s'",
dbesc($software),
dbesc(datetime_convert()),
dbesc($version),
@@ -2405,7 +2426,8 @@ class Activity
);
// it may have been saved originally as an unknown type, but we now know what it is
if (intval($site[0]['site_type']) === SITE_TYPE_UNKNOWN) {
- q("update site set site_type = %d where site_url = '%s'",
+ q(
+ "update site set site_type = %d where site_url = '%s'",
intval(SITE_TYPE_NOTZOT),
dbesc($site_url)
);
@@ -2433,7 +2455,8 @@ class Activity
set_xconfig($url, 'activitypub', 'collections', $collections);
}
- $h = q("select * from hubloc where hubloc_hash = '%s' limit 1",
+ $h = q(
+ "select * from hubloc where hubloc_hash = '%s' limit 1",
dbesc($url)
);
@@ -2461,24 +2484,28 @@ class Activity
);
} else {
if (strpos($username, '@') && ($h[0]['hubloc_addr'] !== $username)) {
- $r = q("update hubloc set hubloc_addr = '%s' where hubloc_hash = '%s'",
+ $r = q(
+ "update hubloc set hubloc_addr = '%s' where hubloc_hash = '%s'",
dbesc($username),
dbesc($url)
);
}
if ($inbox !== $h[0]['hubloc_callback']) {
- $r = q("update hubloc set hubloc_callback = '%s' where hubloc_hash = '%s'",
+ $r = q(
+ "update hubloc set hubloc_callback = '%s' where hubloc_hash = '%s'",
dbesc($inbox),
dbesc($url)
);
}
if ($profile !== $h[0]['hubloc_id_url']) {
- $r = q("update hubloc set hubloc_id_url = '%s' where hubloc_hash = '%s'",
+ $r = q(
+ "update hubloc set hubloc_id_url = '%s' where hubloc_hash = '%s'",
dbesc($profile),
dbesc($url)
);
}
- $r = q("update hubloc set hubloc_updated = '%s' where hubloc_hash = '%s'",
+ $r = q(
+ "update hubloc set hubloc_updated = '%s' where hubloc_hash = '%s'",
dbesc(datetime_convert()),
dbesc($url)
);
@@ -2493,7 +2520,8 @@ class Activity
// and adding zot discovery urls to the actor record will cause federation to fail with the 20-30 projects which don't accept arrays in the url field.
if (strpos($url, '/channel/') !== false) {
- $zx = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6'",
+ $zx = q(
+ "select * from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6'",
dbesc($url)
);
if (($username) && strpos($username, '@') && (!$zx)) {
@@ -2502,7 +2530,6 @@ class Activity
}
Run::Summon(['Xchan_photo', bin2hex($icon), bin2hex($url)]);
-
}
public static function update_protocols($xchan, $str)
@@ -2517,7 +2544,8 @@ class Activity
public static function drop($channel, $observer, $act)
{
- $r = q("select * from item where mid = '%s' and uid = %d limit 1",
+ $r = q(
+ "select * from item where mid = '%s' and uid = %d limit 1",
dbesc((is_array($act->obj)) ? $act->obj['id'] : $act->obj),
intval($channel['channel_id'])
);
@@ -2531,7 +2559,6 @@ class Activity
} elseif (in_array($act->actor['id'], [$r[0]['author_xchan'], $r[0]['owner_xchan']])) {
drop_item($r[0]['id'], false);
}
-
}
@@ -2539,8 +2566,9 @@ class Activity
public static function vid_sort($a, $b)
{
- if ($a['width'] === $b['width'])
+ if ($a['width'] === $b['width']) {
return 0;
+ }
return (($a['width'] > $b['width']) ? -1 : 1);
}
@@ -2567,7 +2595,8 @@ class Activity
public static function get_actor_bbmention($id)
{
- $x = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_hash = '%s' or hubloc_id_url = '%s' limit 1",
+ $x = q(
+ "select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_hash = '%s' or hubloc_id_url = '%s' limit 1",
dbesc($id),
dbesc($id)
);
@@ -2581,7 +2610,6 @@ class Activity
return sprintf('@[zrl=%s]%s[/zrl]', $x[0]['xchan_url'], $x[0]['xchan_name']);
}
return '@{' . $id . '}';
-
}
public static function update_poll($item, $post)
@@ -2602,7 +2630,8 @@ class Activity
$multi = true;
}
- $r = q("select mid, title from item where parent_mid = '%s' and author_xchan = '%s' and mid != parent_mid ",
+ $r = q(
+ "select mid, title from item where parent_mid = '%s' and author_xchan = '%s' and mid != parent_mid ",
dbesc($item['mid']),
dbesc($post['author_xchan'])
);
@@ -2675,7 +2704,8 @@ class Activity
logger('updated_poll: ' . print_r($o, true), LOGGER_DATA);
if ($answer_found && !$found) {
- $x = q("update item set obj = '%s', edited = '%s' where id = %d",
+ $x = q(
+ "update item set obj = '%s', edited = '%s' where id = %d",
dbesc(json_encode($o)),
dbesc(datetime_convert()),
intval($item['id'])
@@ -2731,8 +2761,10 @@ class Activity
// These activities should have been handled separately in the Inbox module and should not be turned into posts
- if (in_array($act->type, ['Follow', 'Accept', 'Reject', 'Create', 'Update']) && is_array($act->obj) && array_key_exists('type', $act->obj)
- && ($act->obj['type'] === 'Follow' || ActivityStreams::is_an_actor($act->obj['type']))) {
+ if (
+ in_array($act->type, ['Follow', 'Accept', 'Reject', 'Create', 'Update']) && is_array($act->obj) && array_key_exists('type', $act->obj)
+ && ($act->obj['type'] === 'Follow' || ActivityStreams::is_an_actor($act->obj['type']))
+ ) {
return false;
}
@@ -2794,7 +2826,6 @@ class Activity
}
if (ActivityStreams::is_response_activity($act->type)) {
-
$response_activity = true;
$s['mid'] = $act->id;
@@ -2970,8 +3001,10 @@ class Activity
$generator = $act->get_property_obj('generator', $act->obj);
}
- if ($generator && array_key_exists('type', $generator)
- && in_array($generator['type'], ['Application', 'Service']) && array_key_exists('name', $generator)) {
+ if (
+ $generator && array_key_exists('type', $generator)
+ && in_array($generator['type'], ['Application', 'Service']) && array_key_exists('name', $generator)
+ ) {
$s['app'] = escape_tags($generator['name']);
}
@@ -3041,7 +3074,6 @@ class Activity
if (!$response_activity) {
if ($act->obj['type'] === 'Video') {
-
$vtypes = [
'video/mp4',
'video/ogg',
@@ -3117,7 +3149,6 @@ class Activity
}
if ($act->obj['type'] === 'Audio') {
-
$atypes = [
'audio/mpeg',
'audio/ogg',
@@ -3152,7 +3183,6 @@ class Activity
}
if ($act->obj['type'] === 'Image' && strpos($s['body'], 'zrl=') === false) {
-
$ptr = null;
if (array_key_exists('url', $act->obj)) {
@@ -3178,7 +3208,6 @@ class Activity
if ($act->obj['type'] === 'Page' && !$s['body']) {
-
$ptr = null;
$purl = EMPTY_STR;
@@ -3268,7 +3297,6 @@ class Activity
if ($cacheable) {
if ((!array_key_exists('mimetype', $s)) || (in_array($s['mimetype'], ['text/bbcode', 'text/x-multicode']))) {
-
// preserve the original purified HTML content *unless* we've modified $s['body']
// within this function (to add attachments or reaction descriptions or mention rewrites).
// This avoids/bypasses some markdown rendering issues which can occur when
@@ -3295,7 +3323,6 @@ class Activity
$s = $hookinfo['s'];
return $s;
-
}
public static function rewrite_mentions_sub(&$s, $pref, &$obj = null)
@@ -3306,7 +3333,8 @@ class Activity
$txt = EMPTY_STR;
if (intval($tag['ttype']) === TERM_MENTION) {
// some platforms put the identity url into href rather than the profile url. Accept either form.
- $x = q("select * from xchan where xchan_url = '%s' or xchan_hash = '%s' limit 1",
+ $x = q(
+ "select * from xchan where xchan_url = '%s' or xchan_hash = '%s' limit 1",
dbesc($tag['url']),
dbesc($tag['url'])
);
@@ -3331,43 +3359,75 @@ class Activity
}
if ($txt) {
-
// the Markdown filter will get tripped up and think this is a markdown link
// if $txt begins with parens so put it behind a zero-width space
if (substr($txt, 0, 1) === '(') {
$txt = htmlspecialchars_decode('', ENT_QUOTES) . $txt;
}
- $s['body'] = preg_replace('/\@\[zrl\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/zrl\]/ism',
- '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]', $s['body']);
- $s['body'] = preg_replace('/\@\[url\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/url\]/ism',
- '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]', $s['body']);
- $s['body'] = preg_replace('/\[zrl\=' . preg_quote($x[0]['xchan_url'], '/') . '\]@(.*?)\[\/zrl\]/ism',
- '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]', $s['body']);
- $s['body'] = preg_replace('/\[url\=' . preg_quote($x[0]['xchan_url'], '/') . '\]@(.*?)\[\/url\]/ism',
- '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]', $s['body']);
+ $s['body'] = preg_replace(
+ '/\@\[zrl\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/zrl\]/ism',
+ '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]',
+ $s['body']
+ );
+ $s['body'] = preg_replace(
+ '/\@\[url\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/url\]/ism',
+ '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]',
+ $s['body']
+ );
+ $s['body'] = preg_replace(
+ '/\[zrl\=' . preg_quote($x[0]['xchan_url'], '/') . '\]@(.*?)\[\/zrl\]/ism',
+ '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]',
+ $s['body']
+ );
+ $s['body'] = preg_replace(
+ '/\[url\=' . preg_quote($x[0]['xchan_url'], '/') . '\]@(.*?)\[\/url\]/ism',
+ '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]',
+ $s['body']
+ );
// replace these just in case the sender (in this case Friendica) got it wrong
- $s['body'] = preg_replace('/\@\[zrl\=' . preg_quote($x[0]['xchan_hash'], '/') . '\](.*?)\[\/zrl\]/ism',
- '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]', $s['body']);
- $s['body'] = preg_replace('/\@\[url\=' . preg_quote($x[0]['xchan_hash'], '/') . '\](.*?)\[\/url\]/ism',
- '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]', $s['body']);
- $s['body'] = preg_replace('/\[zrl\=' . preg_quote($x[0]['xchan_hash'], '/') . '\]@(.*?)\[\/zrl\]/ism',
- '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]', $s['body']);
- $s['body'] = preg_replace('/\[url\=' . preg_quote($x[0]['xchan_hash'], '/') . '\]@(.*?)\[\/url\]/ism',
- '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]', $s['body']);
+ $s['body'] = preg_replace(
+ '/\@\[zrl\=' . preg_quote($x[0]['xchan_hash'], '/') . '\](.*?)\[\/zrl\]/ism',
+ '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]',
+ $s['body']
+ );
+ $s['body'] = preg_replace(
+ '/\@\[url\=' . preg_quote($x[0]['xchan_hash'], '/') . '\](.*?)\[\/url\]/ism',
+ '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]',
+ $s['body']
+ );
+ $s['body'] = preg_replace(
+ '/\[zrl\=' . preg_quote($x[0]['xchan_hash'], '/') . '\]@(.*?)\[\/zrl\]/ism',
+ '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]',
+ $s['body']
+ );
+ $s['body'] = preg_replace(
+ '/\[url\=' . preg_quote($x[0]['xchan_hash'], '/') . '\]@(.*?)\[\/url\]/ism',
+ '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]',
+ $s['body']
+ );
if ($obj && $txt) {
if (!is_array($obj)) {
$obj = json_decode($obj, true);
}
if (array_path_exists('source/content', $obj)) {
- $obj['source']['content'] = preg_replace('/\@\[zrl\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/zrl\]/ism',
- '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]', $obj['source']['content']);
- $obj['source']['content'] = preg_replace('/\@\[url\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/url\]/ism',
- '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]', $obj['source']['content']);
+ $obj['source']['content'] = preg_replace(
+ '/\@\[zrl\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/zrl\]/ism',
+ '@[zrl=' . $x[0]['xchan_url'] . ']' . $txt . '[/zrl]',
+ $obj['source']['content']
+ );
+ $obj['source']['content'] = preg_replace(
+ '/\@\[url\=' . preg_quote($x[0]['xchan_url'], '/') . '\](.*?)\[\/url\]/ism',
+ '@[url=' . $x[0]['xchan_url'] . ']' . $txt . '[/url]',
+ $obj['source']['content']
+ );
}
- $obj['content'] = preg_replace('/\@(.*?)\(.*?)\<\/a\>/ism',
- '@$1' . $txt . '', $obj['content']);
+ $obj['content'] = preg_replace(
+ '/\@(.*?)\(.*?)\<\/a\>/ism',
+ '@$1' . $txt . '',
+ $obj['content']
+ );
}
}
}
@@ -3448,7 +3508,8 @@ class Activity
$permit_mentions = intval(PConfig::Get($channel['channel_id'], 'system', 'permit_all_mentions') && i_am_mentioned($channel, $item));
if ($is_child_node) {
- $p = q("select * from item where mid = '%s' and uid = %d and item_wall = 1",
+ $p = q(
+ "select * from item where mid = '%s' and uid = %d and item_wall = 1",
dbesc($item['parent_mid']),
intval($channel['channel_id'])
);
@@ -3498,7 +3559,6 @@ class Activity
$item['item_blocked'] = ITEM_MODERATED;
}
} else {
-
// By default if we allow you to send_stream and comments and this is a comment, it is allowed.
// A side effect of this action is that if you take away send_stream permission, comments to those
// posts you previously allowed will still be accepted. It is possible but might be difficult to fix this.
@@ -3550,7 +3610,6 @@ class Activity
}
if ($is_sys_channel) {
-
if (!check_pubstream_channelallowed($observer_hash)) {
$allowed = false;
$reason[] = 'pubstream channel blocked';
@@ -3558,7 +3617,8 @@ class Activity
// don't allow pubstream posts if the sender even has a clone on a pubstream denied site
- $h = q("select hubloc_url from hubloc where hubloc_hash = '%s'",
+ $h = q(
+ "select hubloc_url from hubloc where hubloc_hash = '%s'",
dbesc($observer_hash)
);
if ($h) {
@@ -3620,7 +3680,8 @@ class Activity
// due to this channel's filtering rules for content
// provided by either of these entities.
- $abook = q("select * from abook where ( abook_xchan = '%s' OR abook_xchan = '%s') and abook_channel = %d ",
+ $abook = q(
+ "select * from abook where ( abook_xchan = '%s' OR abook_xchan = '%s') and abook_channel = %d ",
dbesc($item['author_xchan']),
dbesc($item['owner_xchan']),
intval($channel['channel_id'])
@@ -3661,8 +3722,8 @@ class Activity
$parent = null;
if ($is_child_node) {
-
- $parent = q("select * from item where mid = '%s' and uid = %d limit 1",
+ $parent = q(
+ "select * from item where mid = '%s' and uid = %d limit 1",
dbesc($item['parent_mid']),
intval($item['uid'])
);
@@ -3675,7 +3736,8 @@ class Activity
$fetch = (($fetch_parents) ? self::fetch_and_store_parents($channel, $observer_hash, $act, $item) : false);
}
if ($fetch) {
- $parent = q("select * from item where mid = '%s' and uid = %d limit 1",
+ $parent = q(
+ "select * from item where mid = '%s' and uid = %d limit 1",
dbesc($item['parent_mid']),
intval($item['uid'])
);
@@ -3698,11 +3760,11 @@ class Activity
$item['parent_mid'] = $parent[0]['parent_mid'];
/*
- *
- * Check for conversation privacy mismatches
- * We can only do this if we have a channel and we have fetched the parent
- *
- */
+ *
+ * Check for conversation privacy mismatches
+ * We can only do this if we have a channel and we have fetched the parent
+ *
+ */
// public conversation, but this comment went rogue and was published privately
// hide it from everybody except the channel owner
@@ -3721,12 +3783,12 @@ class Activity
if (intval($parent[0]['item_private']) !== 0 && $act->recips && (in_array(ACTIVITY_PUBLIC_INBOX, $act->recips) || in_array('Public', $act->recips) || in_array('as:Public', $act->recips))) {
$item['item_restrict'] = $item['item_restrict'] | 2;
}
-
}
self::rewrite_mentions($item);
- $r = q("select id, created, edited from item where mid = '%s' and uid = %d limit 1",
+ $r = q(
+ "select id, created, edited from item where mid = '%s' and uid = %d limit 1",
dbesc($item['mid']),
intval($item['uid'])
);
@@ -3747,30 +3809,30 @@ class Activity
// can fetch the 'context'. For other platforms it's a wild guess. Additionally when we tested this, it started an infinite
// recursion and has been disabled until the recursive behaviour is tracked down and fixed.
-// if ($fetch_parents && $parent && ! intval($parent[0]['item_private'])) {
-// logger('topfetch', LOGGER_DEBUG);
-// // if the thread owner is a connnection, we will already receive any additional comments to their posts
-// // but if they are not we can try to fetch others in the background
-// $x = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
-// WHERE abook_channel = %d and abook_xchan = '%s' LIMIT 1",
-// intval($channel['channel_id']),
-// dbesc($parent[0]['owner_xchan'])
-// );
-// if (! $x) {
-// // determine if the top-level post provides a replies collection
-// if ($parent[0]['obj']) {
-// $parent[0]['obj'] = json_decode($parent[0]['obj'],true);
-// }
-// logger('topfetch: ' . print_r($parent[0],true), LOGGER_ALL);
-// $id = ((array_path_exists('obj/replies/id',$parent[0])) ? $parent[0]['obj']['replies']['id'] : false);
-// if (! $id) {
-// $id = ((array_path_exists('obj/replies',$parent[0]) && is_string($parent[0]['obj']['replies'])) ? $parent[0]['obj']['replies'] : false);
-// }
-// if ($id) {
-// Run::Summon( [ 'Convo', $id, $channel['channel_id'], $observer_hash ] );
-// }
-// }
-// }
+// if ($fetch_parents && $parent && ! intval($parent[0]['item_private'])) {
+// logger('topfetch', LOGGER_DEBUG);
+// // if the thread owner is a connnection, we will already receive any additional comments to their posts
+// // but if they are not we can try to fetch others in the background
+// $x = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
+// WHERE abook_channel = %d and abook_xchan = '%s' LIMIT 1",
+// intval($channel['channel_id']),
+// dbesc($parent[0]['owner_xchan'])
+// );
+// if (! $x) {
+// // determine if the top-level post provides a replies collection
+// if ($parent[0]['obj']) {
+// $parent[0]['obj'] = json_decode($parent[0]['obj'],true);
+// }
+// logger('topfetch: ' . print_r($parent[0],true), LOGGER_ALL);
+// $id = ((array_path_exists('obj/replies/id',$parent[0])) ? $parent[0]['obj']['replies']['id'] : false);
+// if (! $id) {
+// $id = ((array_path_exists('obj/replies',$parent[0]) && is_string($parent[0]['obj']['replies'])) ? $parent[0]['obj']['replies'] : false);
+// }
+// if ($id) {
+// Run::Summon( [ 'Convo', $id, $channel['channel_id'], $observer_hash ] );
+// }
+// }
+// }
if (is_array($x) && $x['item_id']) {
if ($is_child_node) {
@@ -3778,7 +3840,8 @@ class Activity
// We are the owner of this conversation, so send all received comments back downstream
Run::Summon(['Notifier', 'comment-import', $x['item_id']]);
}
- $r = q("select * from item where id = %d limit 1",
+ $r = q(
+ "select * from item where id = %d limit 1",
intval($x['item_id'])
);
if ($r) {
@@ -3787,14 +3850,14 @@ class Activity
}
sync_an_item($channel['channel_id'], $x['item_id']);
}
-
}
public static function find_best_identity($xchan)
{
- $r = q("select hubloc_hash from hubloc where hubloc_id_url = '%s' limit 1",
+ $r = q(
+ "select hubloc_hash from hubloc where hubloc_id_url = '%s' limit 1",
dbesc($xchan)
);
if ($r) {
@@ -3821,8 +3884,10 @@ class Activity
}
// set client flag to convert objects to implied activities
$a = new ActivityStreams($n, null, true);
- if ($a->type === 'Announce' && is_array($a->obj)
- && array_key_exists('object', $a->obj) && array_key_exists('actor', $a->obj)) {
+ if (
+ $a->type === 'Announce' && is_array($a->obj)
+ && array_key_exists('object', $a->obj) && array_key_exists('actor', $a->obj)
+ ) {
// This is a relayed/forwarded Activity (as opposed to a shared/boosted object)
// Reparse the encapsulated Activity and use that instead
logger('relayed activity', LOGGER_DEBUG);
@@ -3856,7 +3921,6 @@ class Activity
$item = $hookinfo['item'];
if ($item) {
-
// don't leak any private conversations to the public stream
// even if they contain publicly addressed comments/reactions
@@ -3946,7 +4010,8 @@ class Activity
$s_alt = htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
- if ((strpos($body, ']' . $s . '[/img]') === false) &&
+ if (
+ (strpos($body, ']' . $s . '[/img]') === false) &&
(strpos($body, ']' . $s . '[/zmg]') === false) &&
(strpos($body, ']' . $s . '[/video]') === false) &&
(strpos($body, ']' . $s . '[/zvideo]') === false) &&
@@ -3957,7 +4022,8 @@ class Activity
(strpos($body, ']' . $s_alt . '[/video]') === false) &&
(strpos($body, ']' . $s_alt . '[/zvideo]') === false) &&
(strpos($body, ']' . $s_alt . '[/audio]') === false) &&
- (strpos($body, ']' . $s_alt . '[/zaudio]') === false)) {
+ (strpos($body, ']' . $s_alt . '[/zaudio]') === false)
+ ) {
return true;
}
return false;
@@ -4077,9 +4143,9 @@ class Activity
$content = false;
- if (array_key_exists($field, $act) && $act[$field])
+ if (array_key_exists($field, $act) && $act[$field]) {
$content = (($binary) ? $act[$field] : purify_html($act[$field]));
- elseif (array_key_exists($field . 'Map', $act) && $act[$field . 'Map']) {
+ } elseif (array_key_exists($field . 'Map', $act) && $act[$field . 'Map']) {
foreach ($act[$field . 'Map'] as $k => $v) {
$content[escape_tags($k)] = (($binary) ? $v : purify_html($v));
}
@@ -4090,7 +4156,8 @@ class Activity
public static function send_rejection_activity($channel, $observer_hash, $item)
{
- $recip = q("select * from hubloc where hubloc_hash = '%s' limit 1",
+ $recip = q(
+ "select * from hubloc where hubloc_hash = '%s' limit 1",
dbesc($observer_hash)
);
if (!$recip) {
@@ -4114,7 +4181,6 @@ class Activity
$queue_id = ActivityPub::queue_message(json_encode($msg, JSON_UNESCAPED_SLASHES), $channel, $recip[0]);
do_delivery([$queue_id]);
-
}
// Find either an Authorization: Bearer token or 'token' request variable
@@ -4187,18 +4253,21 @@ class Activity
switch (trim($options_arr[0])) {
case 'activitypub':
- $hublocs = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_hash = '%s' $sql_options ",
+ $hublocs = q(
+ "select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_hash = '%s' $sql_options ",
dbesc($url)
);
break;
case 'zot6':
- $hublocs = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_id_url = '%s' $sql_options ",
+ $hublocs = q(
+ "select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_id_url = '%s' $sql_options ",
dbesc($url)
);
break;
case 'all':
default:
- $hublocs = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where ( hubloc_id_url = '%s' OR hubloc_hash = '%s' ) $sql_options ",
+ $hublocs = q(
+ "select * from hubloc left join xchan on hubloc_hash = xchan_hash where ( hubloc_id_url = '%s' OR hubloc_hash = '%s' ) $sql_options ",
dbesc($url),
dbesc($url)
);
@@ -4261,8 +4330,5 @@ class Activity
'capabilities' => 'litepub:capabilities',
'acceptsJoins' => 'litepub:acceptsJoins',
];
-
}
-
-
}
diff --git a/Zotlabs/Lib/ActivityPub.php b/Zotlabs/Lib/ActivityPub.php
index 101552042..ee09c1ba9 100644
--- a/Zotlabs/Lib/ActivityPub.php
+++ b/Zotlabs/Lib/ActivityPub.php
@@ -1,4 +1,5 @@
channel_url($arr['channel']) . '?operation=delete',
'actor' => channel_url($arr['channel']),
@@ -71,7 +69,6 @@ class ActivityPub
logger('ActivityPub_encoded (purge_all): ' . json_encode($msg, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
-
} else {
$target_item = $arr['target_item'];
@@ -85,7 +82,6 @@ class ActivityPub
if ($signed_msg) {
$jmsg = $signed_msg;
} else {
-
// Rewrite outbound mentions so they match the ActivityPub convention, which
// is to pretend that the preferred display name doesn't exist and instead use
// the username or webfinger address when displaying names. This is likely to
@@ -101,18 +97,18 @@ class ActivityPub
return;
}
-// $token = IConfig::get($target_item['id'],'ocap','relay');
-// if ($token) {
-// if (defined('USE_BEARCAPS')) {
-// $ti['id'] = 'bear:?u=' . $ti['id'] . '&t=' . $token;
-// }
-// else {
-// $ti['id'] = $ti['id'] . '?token=' . $token;
-// }
-// if ($ti['url'] && is_string($ti['url'])) {
-// $ti['url'] .= '?token=' . $token;
-// }
-// }
+// $token = IConfig::get($target_item['id'],'ocap','relay');
+// if ($token) {
+// if (defined('USE_BEARCAPS')) {
+// $ti['id'] = 'bear:?u=' . $ti['id'] . '&t=' . $token;
+// }
+// else {
+// $ti['id'] = $ti['id'] . '?token=' . $token;
+// }
+// if ($ti['url'] && is_string($ti['url'])) {
+// $ti['url'] .= '?token=' . $token;
+// }
+// }
$msg = array_merge(['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
@@ -136,7 +132,8 @@ class ActivityPub
$hashes[] = "'" . $recip . "'";
}
- $r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s'
+ $r = q(
+ "select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s'
and xchan_hash in (" . implode(',', $hashes) . ") and xchan_network = 'activitypub' ",
dbesc($arr['hub']['hubloc_url'])
);
@@ -147,7 +144,6 @@ class ActivityPub
}
foreach ($r as $contact) {
-
// is $contact connected with this channel - and if the channel is cloned, also on this hub?
// 2018-10-19 this probably doesn't apply to activitypub anymore, just send the thing.
// They'll reject it if they don't like it.
@@ -163,9 +159,7 @@ class ActivityPub
}
continue;
}
-
} else {
-
// public message
// See if we can deliver all of them at once
@@ -179,8 +173,8 @@ class ActivityPub
$arr['queued'][] = $qi;
}
} else {
-
- $r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s' and xchan_network = 'activitypub' ",
+ $r = q(
+ "select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s' and xchan_network = 'activitypub' ",
dbesc($arr['hub']['hubloc_url'])
);
@@ -190,7 +184,6 @@ class ActivityPub
}
foreach ($r as $contact) {
-
// $single = deliverable_singleton($arr['channel']['channel_id'],$contact);
$qi = self::queue_message($jmsg, $arr['channel'], $contact, $target_item['mid']);
@@ -202,7 +195,6 @@ class ActivityPub
}
return;
-
}
@@ -233,7 +225,8 @@ class ActivityPub
]);
if ($message_id && (!get_config('system', 'disable_dreport'))) {
- q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue, dreport_log ) values ( '%s','%s','%s','%s','%s','%s','%s','%s' ) ",
+ q(
+ "insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue, dreport_log ) values ( '%s','%s','%s','%s','%s','%s','%s','%s' ) ",
dbesc($message_id),
dbesc($dest_url),
dbesc($dest_url),
@@ -277,18 +270,20 @@ class ActivityPub
$orig_follow = get_abconfig($x['sender']['channel_id'], $x['recipient']['xchan_hash'], 'activitypub', 'their_follow_id');
$orig_follow_type = get_abconfig($x['sender']['channel_id'], $x['recipient']['xchan_hash'], 'activitypub', 'their_follow_type');
- $msg = array_merge(['@context' => [
+ $msg = array_merge(
+ ['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
'https://w3id.org/security/v1',
Activity::ap_schema()
- ]],
+ ]],
[
'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR),
'type' => (($orig_follow_type) ? $orig_follow_type : 'Follow'),
'actor' => $p,
'object' => $x['recipient']['xchan_hash'],
'to' => [$x['recipient']['xchan_hash']]
- ]);
+ ]
+ );
// for Group actors, send both a Follow and a Join because some platforms only support one and there's
// no way of discovering/knowing in advance which type they support
@@ -305,7 +300,8 @@ class ActivityPub
$msg['signature'] = LDSignatures::sign($msg, $x['sender']);
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
- $h = q("select * from hubloc where hubloc_hash = '%s' limit 1",
+ $h = q(
+ "select * from hubloc where hubloc_hash = '%s' limit 1",
dbesc($x['recipient']['xchan_hash'])
);
@@ -348,11 +344,12 @@ class ActivityPub
return;
}
- $msg = array_merge(['@context' => [
+ $msg = array_merge(
+ ['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
'https://w3id.org/security/v1',
Activity::ap_schema()
- ]],
+ ]],
[
'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . '/' . md5($accept),
'type' => 'Accept',
@@ -364,13 +361,15 @@ class ActivityPub
'object' => z_root() . '/channel/' . $x['sender']['channel_address']
],
'to' => [$x['recipient']['xchan_hash']]
- ]);
+ ]
+ );
$msg['signature'] = LDSignatures::sign($msg, $x['sender']);
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
- $h = q("select * from hubloc where hubloc_hash = '%s' limit 1",
+ $h = q(
+ "select * from hubloc where hubloc_hash = '%s' limit 1",
dbesc($x['recipient']['xchan_hash'])
);
@@ -382,18 +381,19 @@ class ActivityPub
}
$x['success'] = true;
-
}
public static function contact_remove($channel_id, $abook)
{
- $recip = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d",
+ $recip = q(
+ "select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d",
intval($abook['abook_id'])
);
- if ((!$recip) || $recip[0]['xchan_network'] !== 'activitypub')
+ if ((!$recip) || $recip[0]['xchan_network'] !== 'activitypub') {
return;
+ }
$channel = channelx_by_n($recip[0]['abook_channel']);
if (!$channel) {
@@ -410,14 +410,14 @@ class ActivityPub
$orig_activity = get_abconfig($recip[0]['abook_channel'], $recip[0]['xchan_hash'], 'activitypub', 'follow_id');
if ($orig_activity && $recip[0]['abook_pending']) {
-
// was never approved
- $msg = array_merge(['@context' => [
+ $msg = array_merge(
+ ['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
'https://w3id.org/security/v1',
Activity::ap_schema()
- ]],
+ ]],
[
'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . '/' . md5($orig_activity) . '?operation=reject',
'type' => 'Reject',
@@ -429,18 +429,18 @@ class ActivityPub
'object' => $p
],
'to' => [$recip[0]['xchan_hash']]
- ]);
+ ]
+ );
del_abconfig($recip[0]['abook_channel'], $recip[0]['xchan_hash'], 'activitypub', 'follow_id');
-
} else {
-
// send an unfollow
- $msg = array_merge(['@context' => [
+ $msg = array_merge(
+ ['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
'https://w3id.org/security/v1',
Activity::ap_schema()
- ]],
+ ]],
[
'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR) . '?operation=unfollow',
'type' => 'Undo',
@@ -452,14 +452,16 @@ class ActivityPub
'object' => $recip[0]['xchan_hash']
],
'to' => [$recip[0]['xchan_hash']]
- ]);
+ ]
+ );
}
$msg['signature'] = LDSignatures::sign($msg, $channel);
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
- $h = q("select * from hubloc where hubloc_hash = '%s' limit 1",
+ $h = q(
+ "select * from hubloc where hubloc_hash = '%s' limit 1",
dbesc($recip[0]['xchan_hash'])
);
@@ -488,7 +490,6 @@ class ActivityPub
}
if (isset($person_obj)) {
-
Activity::actor_store($person_obj['id'], $person_obj, $force);
return $person_obj['id'];
}
@@ -531,13 +532,15 @@ class ActivityPub
if ($approvals) {
foreach ($approvals as $approval) {
if ($approval === $src_xchan) {
- $abooks = q("select abook_channel from abook where abook_xchan = '%s'",
+ $abooks = q(
+ "select abook_channel from abook where abook_xchan = '%s'",
dbesc($src_xchan)
);
if ($abooks) {
foreach ($abooks as $abook) {
// check to see if we already performed this action
- $x = q("select * from abook where abook_xchan = '%s' and abook_channel = %d",
+ $x = q(
+ "select * from abook where abook_xchan = '%s' and abook_channel = %d",
dbesc($dst_xchan),
intval($abook['abook_channel'])
);
@@ -545,23 +548,27 @@ class ActivityPub
continue;
}
// update the local abook
- q("update abconfig set xchan = '%s' where chan = %d and xchan = '%s'",
+ q(
+ "update abconfig set xchan = '%s' where chan = %d and xchan = '%s'",
dbesc($dst_xchan),
intval($abook['abook_channel']),
dbesc($src_xchan)
);
- q("update pgrp_member set xchan = '%s' where uid = %d and xchan = '%s'",
+ q(
+ "update pgrp_member set xchan = '%s' where uid = %d and xchan = '%s'",
dbesc($dst_xchan),
intval($abook['abook_channel']),
dbesc($src_xchan)
);
- $r = q("update abook set abook_xchan = '%s' where abook_xchan = '%s' and abook_channel = %d ",
+ $r = q(
+ "update abook set abook_xchan = '%s' where abook_xchan = '%s' and abook_channel = %d ",
dbesc($dst_xchan),
dbesc($src_xchan),
intval($abook['abook_channel'])
);
- $r = q("SELECT abook.*, xchan.*
+ $r = q(
+ "SELECT abook.*, xchan.*
FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d and abook_id = %d LIMIT 1",
intval(abook['abook_channel']),
@@ -584,5 +591,4 @@ class ActivityPub
}
}
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php
index c42cd8d6c..72342288a 100644
--- a/Zotlabs/Lib/ActivityStreams.php
+++ b/Zotlabs/Lib/ActivityStreams.php
@@ -4,7 +4,6 @@ namespace Zotlabs\Lib;
use Zotlabs\Web\HTTPSig;
-
/**
* @brief ActivityStreams class.
*
@@ -57,7 +56,6 @@ class ActivityStreams
}
if ($this->data) {
-
// verify and unpack JSalmon signature if present
// This will only be the case for Zot6 packets
@@ -90,7 +88,6 @@ class ActivityStreams
$this->valid = false;
}
}
-
}
// Attempt to assemble an Activity from what we were given.
@@ -108,8 +105,10 @@ class ActivityStreams
$this->ldsig = $this->get_compound_property('signature');
if ($this->ldsig) {
$this->signer = $this->get_compound_property('creator', $this->ldsig);
- if ($this->signer && is_array($this->signer) && array_key_exists('publicKey', $this->signer)
- && is_array($this->signer['publicKey']) && $this->signer['publicKey']['publicKeyPem']) {
+ if (
+ $this->signer && is_array($this->signer) && array_key_exists('publicKey', $this->signer)
+ && is_array($this->signer['publicKey']) && $this->signer['publicKey']['publicKeyPem']
+ ) {
$this->sigok = LDSignatures::verify($this->data, $this->signer['publicKey']['publicKeyPem']);
}
}
@@ -199,7 +198,7 @@ class ActivityStreams
}
// not yet ready for prime time
-// $x = $this->expand($x,$base,$namespace);
+// $x = $this->expand($x,$base,$namespace);
return $x;
}
@@ -472,4 +471,4 @@ class ActivityStreams
return (($x) ? true : false);
}
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Api_router.php b/Zotlabs/Lib/Api_router.php
index 5b75698b3..4c238a49d 100644
--- a/Zotlabs/Lib/Api_router.php
+++ b/Zotlabs/Lib/Api_router.php
@@ -2,7 +2,6 @@
namespace Zotlabs\Lib;
-
class Api_router
{
@@ -32,5 +31,4 @@ class Api_router
{
return self::$routes;
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php
index 11158a208..53d3ecfe6 100644
--- a/Zotlabs/Lib/Apps.php
+++ b/Zotlabs/Lib/Apps.php
@@ -53,7 +53,6 @@ class Apps
call_hooks('get_system_apps', $ret);
return $ret;
-
}
public static function get_base_apps()
@@ -107,7 +106,8 @@ class Apps
self::$available_apps = q("select * from app where app_channel = 0");
- self::$installed_apps = q("select * from app where app_channel = %d",
+ self::$installed_apps = q(
+ "select * from app where app_channel = %d",
intval(local_channel())
);
@@ -130,7 +130,8 @@ class Apps
}
if ($id !== true) {
// if we already installed this app, but it changed, preserve any categories we created
- $r = q("select term from term where otype = %d and oid = %d",
+ $r = q(
+ "select term from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($id)
);
@@ -142,7 +143,6 @@ class Apps
$app['guid'] = hash('whirlpool', $app['name']);
$app['system'] = 1;
self::app_install(local_channel(), $app);
-
}
}
}
@@ -161,13 +161,17 @@ class Apps
foreach (self::$available_apps as $iapp) {
if ($iapp['app_id'] == hash('whirlpool', $app['name'])) {
$notfound = false;
- if ((isset($app['version']) && $iapp['app_version'] !== $app['version'])
- || ((isset($app['plugin']) && $app['plugin']) && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))) {
+ if (
+ (isset($app['version']) && $iapp['app_version'] !== $app['version'])
+ || ((isset($app['plugin']) && $app['plugin']) && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))
+ ) {
return intval($iapp['app_id']);
}
- if (($iapp['app_url'] !== $app['url'])
- || ($iapp['app_photo'] !== $app['photo'])) {
+ if (
+ ($iapp['app_url'] !== $app['url'])
+ || ($iapp['app_photo'] !== $app['photo'])
+ ) {
return intval($iapp['app_id']);
}
}
@@ -188,8 +192,10 @@ class Apps
foreach (self::$installed_apps as $iapp) {
if ($iapp['app_id'] == hash('whirlpool', $app['name'])) {
$installed = true;
- if (($iapp['app_version'] != $app['version'])
- || (isset($app['plugin']) && $app['plugin'] && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))) {
+ if (
+ ($iapp['app_version'] != $app['version'])
+ || (isset($app['plugin']) && $app['plugin'] && (!(isset($iapp['app_plugin']) && $iapp['app_plugin'])))
+ ) {
return intval($iapp['app_id']);
}
}
@@ -629,7 +635,8 @@ class Apps
{
if (!is_array($app)) {
- $r = q("select * from app where app_name = '%s' and app_channel = 0",
+ $r = q(
+ "select * from app where app_name = '%s' and app_channel = 0",
dbesc($app)
);
if (!$r) {
@@ -648,14 +655,16 @@ class Apps
}
if ($x['success']) {
- $r = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
+ $r = q(
+ "select * from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($x['app_id']),
intval($uid)
);
if ($r) {
if (($app['uid']) && (!$r[0]['app_system'])) {
if ($app['categories'] && (!$app['term'])) {
- $r[0]['term'] = q("select * from term where otype = %d and oid = %d",
+ $r[0]['term'] = q(
+ "select * from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($r[0]['id'])
);
@@ -695,8 +704,8 @@ class Apps
{
if ($uid && $app['guid']) {
-
- $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
+ $x = q(
+ "select * from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($app['guid']),
intval($uid)
);
@@ -704,17 +713,20 @@ class Apps
if (!intval($x[0]['app_deleted'])) {
$x[0]['app_deleted'] = 1;
if (self::can_delete($uid, $app)) {
- $r = q("delete from app where app_id = '%s' and app_channel = %d",
+ $r = q(
+ "delete from app where app_id = '%s' and app_channel = %d",
dbesc($app['guid']),
intval($uid)
);
- q("delete from term where otype = %d and oid = %d",
+ q(
+ "delete from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($x[0]['id'])
);
call_hooks('app_destroy', $x[0]);
} else {
- $r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
+ $r = q(
+ "update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
dbesc($app['guid']),
intval($uid)
);
@@ -729,7 +741,6 @@ class Apps
}
}
}
-
}
public static function app_undestroy($uid, $app)
@@ -738,14 +749,15 @@ class Apps
// undelete a system app
if ($uid && $app['guid']) {
-
- $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
+ $x = q(
+ "select * from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($app['guid']),
intval($uid)
);
if ($x) {
if ($x[0]['app_system']) {
- $r = q("update app set app_deleted = 0 where app_id = '%s' and app_channel = %d",
+ $r = q(
+ "update app set app_deleted = 0 where app_id = '%s' and app_channel = %d",
dbesc($app['guid']),
intval($uid)
);
@@ -756,19 +768,22 @@ class Apps
public static function app_feature($uid, $app, $term)
{
- $r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
+ $r = q(
+ "select id from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($app['guid']),
intval($uid)
);
- $x = q("select * from term where otype = %d and oid = %d and term = '%s' limit 1",
+ $x = q(
+ "select * from term where otype = %d and oid = %d and term = '%s' limit 1",
intval(TERM_OBJ_APP),
intval($r[0]['id']),
dbesc($term)
);
if ($x) {
- q("delete from term where otype = %d and oid = %d and term = '%s'",
+ q(
+ "delete from term where otype = %d and oid = %d and term = '%s'",
intval(TERM_OBJ_APP),
intval($x[0]['oid']),
dbesc($term)
@@ -781,7 +796,8 @@ class Apps
public static function app_installed($uid, $app, $bypass_filter = false)
{
- $r = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
+ $r = q(
+ "select id from app where app_id = '%s' and app_channel = %d limit 1",
dbesc((array_key_exists('guid', $app)) ? $app['guid'] : ''),
intval($uid)
);
@@ -796,13 +812,13 @@ class Apps
}
return (($r) ? true : false);
-
}
public static function addon_app_installed($uid, $app, $bypass_filter = false)
{
- $r = q("select id from app where app_plugin = '%s' and app_channel = %d limit 1",
+ $r = q(
+ "select id from app where app_plugin = '%s' and app_channel = %d limit 1",
dbesc($app),
intval($uid)
);
@@ -817,13 +833,13 @@ class Apps
}
return (($r) ? true : false);
-
}
public static function system_app_installed($uid, $app, $bypass_filter = false)
{
- $r = q("select id from app where app_id = '%s' and app_channel = %d and app_deleted = 0 limit 1",
+ $r = q(
+ "select id from app where app_id = '%s' and app_channel = %d and app_deleted = 0 limit 1",
dbesc(hash('whirlpool', $app)),
intval($uid)
);
@@ -848,19 +864,20 @@ class Apps
$sql_extra = " and app_deleted = 0 ";
}
if ($cats) {
-
$cat_sql_extra = " and ( ";
foreach ($cats as $cat) {
- if (strpos($cat_sql_extra, 'term'))
+ if (strpos($cat_sql_extra, 'term')) {
$cat_sql_extra .= "or ";
+ }
$cat_sql_extra .= "term = '" . dbesc($cat) . "' ";
}
$cat_sql_extra .= ") ";
- $r = q("select oid from term where otype = %d $cat_sql_extra",
+ $r = q(
+ "select oid from term where otype = %d $cat_sql_extra",
intval(TERM_OBJ_APP)
);
if (!$r) {
@@ -869,7 +886,8 @@ class Apps
$sql_extra .= " and app.id in ( " . array_elm_to_str($r, 'oid') . ') ';
}
- $r = q("select * from app where app_channel = %d $sql_extra order by app_name asc",
+ $r = q(
+ "select * from app where app_channel = %d $sql_extra order by app_name asc",
intval($uid)
);
@@ -881,7 +899,8 @@ class Apps
if (!$r[$x]['app_system']) {
$r[$x]['type'] = 'personal';
}
- $r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
+ $r[$x]['term'] = q(
+ "select * from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($r[$x]['id'])
);
@@ -898,7 +917,8 @@ class Apps
// not yet finished
// somehow need to account for translations
- $r = q("select * from app where app_channel = 0 $sql_extra order by app_name asc",
+ $r = q(
+ "select * from app where app_channel = 0 $sql_extra order by app_name asc",
intval($uid)
);
@@ -909,8 +929,9 @@ class Apps
public static function app_order($uid, $apps, $menu)
{
- if (!$apps)
+ if (!$apps) {
return $apps;
+ }
$conf = (($menu === 'nav_featured_app') ? 'app_order' : 'app_pin_order');
@@ -938,7 +959,6 @@ class Apps
}
}
return $ret;
-
}
public static function find_app_in_array($name, $arr)
@@ -999,7 +1019,6 @@ class Apps
}
set_pconfig($uid, 'system', $conf, implode(',', $narr));
-
}
public static function movedown($uid, $guid, $menu)
@@ -1047,7 +1066,6 @@ class Apps
}
set_pconfig($uid, 'system', $conf, implode(',', $narr));
-
}
public static function app_decode($s)
@@ -1074,7 +1092,6 @@ class Apps
$arr['url'] = str_replace(array('$baseurl', '$nick'), array($baseurl, $address), $arr['url']);
$arr['photo'] = str_replace(array('$baseurl', '$nick'), array($baseurl, $address), $arr['photo']);
-
}
@@ -1128,7 +1145,8 @@ class Apps
$created = datetime_convert();
- $r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_plugin, app_deleted, app_options ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d )",
+ $r = q(
+ "insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_plugin, app_deleted, app_options ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d )",
dbesc($darray['app_id']),
dbesc($darray['app_sig']),
dbesc($darray['app_author']),
@@ -1156,7 +1174,8 @@ class Apps
}
if ($arr['categories']) {
- $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
+ $x = q(
+ "select id from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($darray['app_id']),
intval($darray['app_channel'])
);
@@ -1218,7 +1237,8 @@ class Apps
$edited = datetime_convert();
- $r = q("update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_plugin = '%s', app_deleted = %d, app_options = %d where app_id = '%s' and app_channel = %d",
+ $r = q(
+ "update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_plugin = '%s', app_deleted = %d, app_options = %d where app_id = '%s' and app_channel = %d",
dbesc($darray['app_sig']),
dbesc($darray['app_author']),
dbesc($darray['app_name']),
@@ -1243,18 +1263,21 @@ class Apps
$ret['app_id'] = $darray['app_id'];
}
- $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
+ $x = q(
+ "select id from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($darray['app_id']),
intval($darray['app_channel'])
);
// if updating an embed app and we don't have a 0 channel_id don't mess with any existing categories
- if (array_key_exists('embed', $arr) && intval($arr['embed']) && (intval($darray['app_channel'])))
+ if (array_key_exists('embed', $arr) && intval($arr['embed']) && (intval($darray['app_channel']))) {
return $ret;
+ }
if ($x) {
- q("delete from term where otype = %d and oid = %d",
+ q(
+ "delete from term where otype = %d and oid = %d",
intval(TERM_OBJ_APP),
intval($x[0]['id'])
);
@@ -1272,7 +1295,6 @@ class Apps
}
return $ret;
-
}
@@ -1350,7 +1372,6 @@ class Apps
$j = json_encode($ret);
return '[app]' . chunk_split(base64_encode($j), 72, "\n") . '[/app]';
-
}
@@ -1358,7 +1379,4 @@ class Apps
{
return chunk_split(base64_encode(json_encode($papp)), 72, "\n");
}
-
}
-
-
diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php
index cea075659..f3c227261 100644
--- a/Zotlabs/Lib/Cache.php
+++ b/Zotlabs/Lib/Cache.php
@@ -1,51 +1,63 @@
-= $limit)) {
$ret['message'] = upgrade_message();
return $ret;
}
- if (!array_key_exists('expire', $arr))
+ if (!array_key_exists('expire', $arr)) {
$arr['expire'] = 120; // minutes, e.g. 2 hours
+ }
$created = datetime_convert();
- $x = q("insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid )
+ $x = q(
+ "insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid )
values ( %d, %d , '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s' ) ",
intval($channel['channel_account_id']),
intval($channel['channel_id']),
@@ -67,8 +73,9 @@ class Chatroom
dbesc($arr['deny_gid'])
);
- if ($x)
+ if ($x) {
$ret['success'] = true;
+ }
return $ret;
}
@@ -79,16 +86,17 @@ class Chatroom
$ret = array('success' => false);
- if (intval($arr['cr_id']))
+ if (intval($arr['cr_id'])) {
$sql_extra = " and cr_id = " . intval($arr['cr_id']) . " ";
- elseif (trim($arr['cr_name']))
+ } elseif (trim($arr['cr_name'])) {
$sql_extra = " and cr_name = '" . protect_sprintf(dbesc(trim($arr['cr_name']))) . "' ";
- else {
+ } else {
$ret['message'] = t('Invalid room specifier.');
return $ret;
}
- $r = q("select * from chatroom where cr_uid = %d $sql_extra limit 1",
+ $r = q(
+ "select * from chatroom where cr_uid = %d $sql_extra limit 1",
intval($channel['channel_id'])
);
if (!$r) {
@@ -98,14 +106,17 @@ class Chatroom
Libsync::build_sync_packet($channel['channel_id'], array('chatroom' => $r));
- q("delete from chatroom where cr_id = %d",
+ q(
+ "delete from chatroom where cr_id = %d",
intval($r[0]['cr_id'])
);
if ($r[0]['cr_id']) {
- q("delete from chatpresence where cp_room = %d",
+ q(
+ "delete from chatpresence where cp_room = %d",
intval($r[0]['cr_id'])
);
- q("delete from chat where chat_room = %d",
+ q(
+ "delete from chat where chat_room = %d",
intval($r[0]['cr_id'])
);
}
@@ -118,10 +129,12 @@ class Chatroom
public static function enter($observer_xchan, $room_id, $status, $client)
{
- if (!$room_id || !$observer_xchan)
+ if (!$room_id || !$observer_xchan) {
return;
+ }
- $r = q("select * from chatroom where cr_id = %d limit 1",
+ $r = q(
+ "select * from chatroom where cr_id = %d limit 1",
intval($room_id)
);
if (!$r) {
@@ -131,7 +144,8 @@ class Chatroom
require_once('include/security.php');
$sql_extra = permissions_sql($r[0]['cr_uid']);
- $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1",
+ $x = q(
+ "select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1",
intval($room_id),
intval($r[0]['cr_uid'])
);
@@ -142,7 +156,8 @@ class Chatroom
$limit = service_class_fetch($r[0]['cr_uid'], 'chatters_inroom');
if ($limit !== false) {
- $y = q("select count(*) as total from chatpresence where cp_room = %d",
+ $y = q(
+ "select count(*) as total from chatpresence where cp_room = %d",
intval($room_id)
);
if ($y && $y[0]['total'] > $limit) {
@@ -152,19 +167,22 @@ class Chatroom
}
if (intval($x[0]['cr_expire'])) {
- $r = q("delete from chat where created < %s - INTERVAL %s and chat_room = %d",
+ $r = q(
+ "delete from chat where created < %s - INTERVAL %s and chat_room = %d",
db_utcnow(),
db_quoteinterval(intval($x[0]['cr_expire']) . ' MINUTE'),
intval($x[0]['cr_id'])
);
}
- $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
+ $r = q(
+ "select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
dbesc($observer_xchan),
intval($room_id)
);
if ($r) {
- q("update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'",
+ q(
+ "update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'",
dbesc(datetime_convert()),
intval($r[0]['cp_id']),
dbesc($client)
@@ -172,7 +190,8 @@ class Chatroom
return true;
}
- $r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client )
+ $r = q(
+ "insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client )
values ( %d, '%s', '%s', '%s', '%s' )",
intval($room_id),
dbesc($observer_xchan),
@@ -187,16 +206,19 @@ class Chatroom
public function leave($observer_xchan, $room_id, $client)
{
- if (!$room_id || !$observer_xchan)
+ if (!$room_id || !$observer_xchan) {
return;
+ }
- $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1",
+ $r = q(
+ "select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1",
dbesc($observer_xchan),
intval($room_id),
dbesc($client)
);
if ($r) {
- q("delete from chatpresence where cp_id = %d",
+ q(
+ "delete from chatpresence where cp_id = %d",
intval($r[0]['cp_id'])
);
}
@@ -210,7 +232,8 @@ class Chatroom
require_once('include/security.php');
$sql_extra = permissions_sql($uid);
- $r = q("select allow_cid, allow_gid, deny_cid, deny_gid, cr_name, cr_expire, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d $sql_extra group by cr_name, cr_id order by cr_name",
+ $r = q(
+ "select allow_cid, allow_gid, deny_cid, deny_gid, cr_name, cr_expire, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d $sql_extra group by cr_name, cr_id order by cr_name",
intval($uid)
);
@@ -222,7 +245,8 @@ class Chatroom
require_once('include/security.php');
$sql_extra = permissions_sql($uid);
- $r = q("select count(*) as total from chatroom where cr_uid = %d $sql_extra",
+ $r = q(
+ "select count(*) as total from chatroom where cr_uid = %d $sql_extra",
intval($uid)
);
@@ -245,17 +269,20 @@ class Chatroom
$ret = array('success' => false);
- if (!$text)
+ if (!$text) {
return;
+ }
$sql_extra = permissions_sql($uid);
- $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
+ $r = q(
+ "select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
intval($uid),
intval($room_id)
);
- if (!$r)
+ if (!$r) {
return $ret;
+ }
$arr = [
'chat_room' => $room_id,
@@ -271,7 +298,8 @@ class Chatroom
*/
call_hooks('chat_message', $arr);
- $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text )
+ $x = q(
+ "insert into chat ( chat_room, chat_xchan, created, chat_text )
values( %d, '%s', '%s', '%s' )",
intval($room_id),
dbesc($xchan),
diff --git a/Zotlabs/Lib/Config.php b/Zotlabs/Lib/Config.php
index 5997968cc..6aba9b319 100644
--- a/Zotlabs/Lib/Config.php
+++ b/Zotlabs/Lib/Config.php
@@ -2,163 +2,174 @@
namespace Zotlabs\Lib;
-
use App;
-class Config {
+class Config
+{
- /**
- * @brief Loads the hub's configuration from database to a cached storage.
- *
- * Retrieve a category ($family) of config variables from database to a cached
- * storage in the global App::$config[$family].
- *
- * @param string $family
- * The category of the configuration value
- */
- public static function Load($family) {
- if(! array_key_exists($family, App::$config))
- App::$config[$family] = [];
+ /**
+ * @brief Loads the hub's configuration from database to a cached storage.
+ *
+ * Retrieve a category ($family) of config variables from database to a cached
+ * storage in the global App::$config[$family].
+ *
+ * @param string $family
+ * The category of the configuration value
+ */
+ public static function Load($family)
+ {
+ if (! array_key_exists($family, App::$config)) {
+ App::$config[$family] = [];
+ }
- if(! array_key_exists('config_loaded', App::$config[$family])) {
- $r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family));
- if($r !== false) {
- if($r) {
- foreach($r as $rr) {
- $k = $rr['k'];
- App::$config[$family][$k] = $rr['v'];
- }
- }
- App::$config[$family]['config_loaded'] = true;
- }
- }
- }
+ if (! array_key_exists('config_loaded', App::$config[$family])) {
+ $r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family));
+ if ($r !== false) {
+ if ($r) {
+ foreach ($r as $rr) {
+ $k = $rr['k'];
+ App::$config[$family][$k] = $rr['v'];
+ }
+ }
+ App::$config[$family]['config_loaded'] = true;
+ }
+ }
+ }
- /**
- * @brief Sets a configuration value for the hub.
- *
- * Stores a config value ($value) in the category ($family) under the key ($key).
- *
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to set
- * @param mixed $value
- * The value to store in the configuration
- * @return mixed
- * Return the set value, or false if the database update failed
- */
- public static function Set($family, $key, $value) {
- // manage array value
- $dbvalue = ((is_array($value)) ? serialise($value) : $value);
- $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
+ /**
+ * @brief Sets a configuration value for the hub.
+ *
+ * Stores a config value ($value) in the category ($family) under the key ($key).
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to set
+ * @param mixed $value
+ * The value to store in the configuration
+ * @return mixed
+ * Return the set value, or false if the database update failed
+ */
+ public static function Set($family, $key, $value)
+ {
+ // manage array value
+ $dbvalue = ((is_array($value)) ? serialise($value) : $value);
+ $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
- if(self::Get($family, $key) === false || (! self::get_from_storage($family, $key))) {
- $ret = q("INSERT INTO config ( cat, k, v ) VALUES ( '%s', '%s', '%s' ) ",
- dbesc($family),
- dbesc($key),
- dbesc($dbvalue)
- );
- if($ret) {
- App::$config[$family][$key] = $value;
- $ret = $value;
- }
- return $ret;
- }
+ if (self::Get($family, $key) === false || (! self::get_from_storage($family, $key))) {
+ $ret = q(
+ "INSERT INTO config ( cat, k, v ) VALUES ( '%s', '%s', '%s' ) ",
+ dbesc($family),
+ dbesc($key),
+ dbesc($dbvalue)
+ );
+ if ($ret) {
+ App::$config[$family][$key] = $value;
+ $ret = $value;
+ }
+ return $ret;
+ }
- $ret = q("UPDATE config SET v = '%s' WHERE cat = '%s' AND k = '%s'",
- dbesc($dbvalue),
- dbesc($family),
- dbesc($key)
- );
+ $ret = q(
+ "UPDATE config SET v = '%s' WHERE cat = '%s' AND k = '%s'",
+ dbesc($dbvalue),
+ dbesc($family),
+ dbesc($key)
+ );
- if($ret) {
- App::$config[$family][$key] = $value;
- $ret = $value;
- }
+ if ($ret) {
+ App::$config[$family][$key] = $value;
+ $ret = $value;
+ }
- return $ret;
- }
+ return $ret;
+ }
- /**
- * @brief Get a particular config variable given the category name ($family)
- * and a key.
- *
- * Get a particular config variable from the given category ($family) and the
- * $key from a cached storage in App::$config[$family]. If a key is found in the
- * DB but does not exist in local config cache, pull it into the cache so we
- * do not have to hit the DB again for this item.
- *
- * Returns false if not set.
- *
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to query
- * @param string $default (optional) default false
- * @return mixed Return value or false on error or if not set
- */
- public static function Get($family, $key, $default = false) {
- if((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family])))
- self::Load($family);
+ /**
+ * @brief Get a particular config variable given the category name ($family)
+ * and a key.
+ *
+ * Get a particular config variable from the given category ($family) and the
+ * $key from a cached storage in App::$config[$family]. If a key is found in the
+ * DB but does not exist in local config cache, pull it into the cache so we
+ * do not have to hit the DB again for this item.
+ *
+ * Returns false if not set.
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to query
+ * @param string $default (optional) default false
+ * @return mixed Return value or false on error or if not set
+ */
+ public static function Get($family, $key, $default = false)
+ {
+ if ((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family]))) {
+ self::Load($family);
+ }
- if(array_key_exists('config_loaded', App::$config[$family])) {
- if(! array_key_exists($key, App::$config[$family])) {
- return $default;
- }
- return unserialise(App::$config[$family][$key]);
- }
+ if (array_key_exists('config_loaded', App::$config[$family])) {
+ if (! array_key_exists($key, App::$config[$family])) {
+ return $default;
+ }
+ return unserialise(App::$config[$family][$key]);
+ }
- return $default;
- }
+ return $default;
+ }
- /**
- * @brief Deletes the given key from the hub's configuration database.
- *
- * Removes the configured value from the stored cache in App::$config[$family]
- * and removes it from the database.
- *
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to delete
- * @return mixed
- */
- public static function Delete($family, $key) {
+ /**
+ * @brief Deletes the given key from the hub's configuration database.
+ *
+ * Removes the configured value from the stored cache in App::$config[$family]
+ * and removes it from the database.
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to delete
+ * @return mixed
+ */
+ public static function Delete($family, $key)
+ {
- $ret = false;
+ $ret = false;
- if(array_key_exists($family, App::$config) && array_key_exists($key, App::$config[$family]))
- unset(App::$config[$family][$key]);
+ if (array_key_exists($family, App::$config) && array_key_exists($key, App::$config[$family])) {
+ unset(App::$config[$family][$key]);
+ }
- $ret = q("DELETE FROM config WHERE cat = '%s' AND k = '%s'",
- dbesc($family),
- dbesc($key)
- );
+ $ret = q(
+ "DELETE FROM config WHERE cat = '%s' AND k = '%s'",
+ dbesc($family),
+ dbesc($key)
+ );
- return $ret;
- }
+ return $ret;
+ }
- /**
- * @brief Returns a record directly from the database configuration storage.
- *
- * This function queries directly the database and bypasses the cached storage
- * from get_config($family, $key).
- *
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to query
- * @return mixed
- */
- private static function get_from_storage($family, $key) {
- $ret = q("SELECT * FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1",
- dbesc($family),
- dbesc($key)
- );
-
- return $ret;
- }
+ /**
+ * @brief Returns a record directly from the database configuration storage.
+ *
+ * This function queries directly the database and bypasses the cached storage
+ * from get_config($family, $key).
+ *
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to query
+ * @return mixed
+ */
+ private static function get_from_storage($family, $key)
+ {
+ $ret = q(
+ "SELECT * FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1",
+ dbesc($family),
+ dbesc($key)
+ );
+ return $ret;
+ }
}
diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php
index a855afdd4..30fd33bce 100644
--- a/Zotlabs/Lib/Connect.php
+++ b/Zotlabs/Lib/Connect.php
@@ -1,4 +1,6 @@
- 'sha1',
- 'private_key_bits' => $bits,
- 'encrypt_key' => false
- ];
+ $openssl_options = [
+ 'digest_alg' => 'sha1',
+ 'private_key_bits' => $bits,
+ 'encrypt_key' => false
+ ];
- $conf = get_config('system','openssl_conf_file');
-
- if ($conf) {
- $openssl_options['config'] = $conf;
- }
+ $conf = get_config('system', 'openssl_conf_file');
- $result = openssl_pkey_new($openssl_options);
+ if ($conf) {
+ $openssl_options['config'] = $conf;
+ }
- if (empty($result)) {
- return false;
- }
+ $result = openssl_pkey_new($openssl_options);
- // Get private key
+ if (empty($result)) {
+ return false;
+ }
- $response = [ 'prvkey' => '', 'pubkey' => '' ];
+ // Get private key
- openssl_pkey_export($result, $response['prvkey']);
+ $response = [ 'prvkey' => '', 'pubkey' => '' ];
- // Get public key
- $pkey = openssl_pkey_get_details($result);
- $response['pubkey'] = $pkey["key"];
+ openssl_pkey_export($result, $response['prvkey']);
- return $response;
+ // Get public key
+ $pkey = openssl_pkey_get_details($result);
+ $response['pubkey'] = $pkey["key"];
- }
+ return $response;
+ }
- public static function sign($data, $key, $alg = 'sha256') {
+ public static function sign($data, $key, $alg = 'sha256')
+ {
- if (! $key) {
- return false;
- }
+ if (! $key) {
+ return false;
+ }
- $sig = '';
- openssl_sign($data,$sig,$key,$alg);
- return $sig;
- }
+ $sig = '';
+ openssl_sign($data, $sig, $key, $alg);
+ return $sig;
+ }
- public static function verify($data, $sig, $key, $alg = 'sha256') {
+ public static function verify($data, $sig, $key, $alg = 'sha256')
+ {
- if (! $key) {
- return false;
- }
+ if (! $key) {
+ return false;
+ }
- try {
- $verify = openssl_verify($data,$sig,$key,$alg);
- }
- catch (Exception $e) {
- $verify = (-1);
- }
+ try {
+ $verify = openssl_verify($data, $sig, $key, $alg);
+ } catch (Exception $e) {
+ $verify = (-1);
+ }
- if ($verify === (-1)) {
- while ($msg = openssl_error_string()) {
- logger('openssl_verify: ' . $msg,LOGGER_NORMAL,LOG_ERR);
- }
- btlogger('openssl_verify: key: ' . $key, LOGGER_DEBUG, LOG_ERR);
- }
+ if ($verify === (-1)) {
+ while ($msg = openssl_error_string()) {
+ logger('openssl_verify: ' . $msg, LOGGER_NORMAL, LOG_ERR);
+ }
+ btlogger('openssl_verify: key: ' . $key, LOGGER_DEBUG, LOG_ERR);
+ }
- return (($verify > 0) ? true : false);
- }
+ return (($verify > 0) ? true : false);
+ }
- public static function encapsulate($data, $pubkey, $alg) {
+ public static function encapsulate($data, $pubkey, $alg)
+ {
- if (! ($alg && $pubkey)) {
- return $data;
- }
+ if (! ($alg && $pubkey)) {
+ return $data;
+ }
- $alg_base = $alg;
- $padding = OPENSSL_PKCS1_PADDING;
+ $alg_base = $alg;
+ $padding = OPENSSL_PKCS1_PADDING;
- $exts = explode('.',$alg);
- if (count($exts) > 1) {
- switch ($exts[1]) {
- case 'oaep':
- $padding = OPENSSL_PKCS1_OAEP_PADDING;
- break;
- default:
- break;
- }
- $alg_base = $exts[0];
- }
+ $exts = explode('.', $alg);
+ if (count($exts) > 1) {
+ switch ($exts[1]) {
+ case 'oaep':
+ $padding = OPENSSL_PKCS1_OAEP_PADDING;
+ break;
+ default:
+ break;
+ }
+ $alg_base = $exts[0];
+ }
- $method = null;
+ $method = null;
- foreach (self::$openssl_algorithms as $ossl) {
- if ($ossl[0] === $alg_base) {
- $method = $ossl;
- break;
- }
- }
+ foreach (self::$openssl_algorithms as $ossl) {
+ if ($ossl[0] === $alg_base) {
+ $method = $ossl;
+ break;
+ }
+ }
- if ($method) {
- $result = [ 'encrypted' => true ];
+ if ($method) {
+ $result = [ 'encrypted' => true ];
- $key = openssl_random_pseudo_bytes(256);
- $iv = openssl_random_pseudo_bytes(256);
+ $key = openssl_random_pseudo_bytes(256);
+ $iv = openssl_random_pseudo_bytes(256);
- $key1 = substr($key, 0, $method[2]);
- $iv1 = substr($iv, 0, $method[3]);
+ $key1 = substr($key, 0, $method[2]);
+ $iv1 = substr($iv, 0, $method[3]);
- $result['data'] = base64url_encode(openssl_encrypt($data,$method[1],$key1,OPENSSL_RAW_DATA,$iv1),true);
+ $result['data'] = base64url_encode(openssl_encrypt($data, $method[1], $key1, OPENSSL_RAW_DATA, $iv1), true);
- openssl_public_encrypt($key, $k, $pubkey, $padding);
- openssl_public_encrypt($iv, $i, $pubkey, $padding);
+ openssl_public_encrypt($key, $k, $pubkey, $padding);
+ openssl_public_encrypt($iv, $i, $pubkey, $padding);
- $result['alg'] = $alg;
- $result['key'] = base64url_encode($k,true);
- $result['iv'] = base64url_encode($i,true);
- return $result;
+ $result['alg'] = $alg;
+ $result['key'] = base64url_encode($k, true);
+ $result['iv'] = base64url_encode($i, true);
+ return $result;
+ } else {
+ $x = [ 'data' => $data, 'pubkey' => $pubkey, 'alg' => $alg, 'result' => $data ];
+ call_hooks('crypto_encapsulate', $x);
+ return $x['result'];
+ }
+ }
- }
- else {
- $x = [ 'data' => $data, 'pubkey' => $pubkey, 'alg' => $alg, 'result' => $data ];
- call_hooks('crypto_encapsulate', $x);
- return $x['result'];
- }
- }
+ public static function unencapsulate($data, $prvkey)
+ {
- public static function unencapsulate($data, $prvkey) {
+ if (! (is_array($data) && array_key_exists('encrypted', $data) && array_key_exists('alg', $data) && $data['alg'])) {
+ logger('not encrypted');
- if (! (is_array($data) && array_key_exists('encrypted',$data) && array_key_exists('alg',$data) && $data['alg'])) {
- logger('not encrypted');
+ return $data;
+ }
- return $data;
- }
+ $alg_base = $data['alg'];
+ $padding = OPENSSL_PKCS1_PADDING;
- $alg_base = $data['alg'];
- $padding = OPENSSL_PKCS1_PADDING;
+ $exts = explode('.', $data['alg']);
+ if (count($exts) > 1) {
+ switch ($exts[1]) {
+ case 'oaep':
+ $padding = OPENSSL_PKCS1_OAEP_PADDING;
+ break;
+ default:
+ break;
+ }
+ $alg_base = $exts[0];
+ }
- $exts = explode('.',$data['alg']);
- if (count($exts) > 1) {
- switch ($exts[1]) {
- case 'oaep':
- $padding = OPENSSL_PKCS1_OAEP_PADDING;
- break;
- default:
- break;
- }
- $alg_base = $exts[0];
- }
+ $method = null;
- $method = null;
+ foreach (self::$openssl_algorithms as $ossl) {
+ if ($ossl[0] === $alg_base) {
+ $method = $ossl;
+ break;
+ }
+ }
- foreach (self::$openssl_algorithms as $ossl) {
- if ($ossl[0] === $alg_base) {
- $method = $ossl;
- break;
- }
- }
-
- if ($method) {
- openssl_private_decrypt(base64url_decode($data['key']),$k,$prvkey,$padding);
- openssl_private_decrypt(base64url_decode($data['iv']), $i,$prvkey,$padding);
- return openssl_decrypt(base64url_decode($data['data']),$method[1],substr($k,0,$method[2]),OPENSSL_RAW_DATA,substr($i,0,$method[3]));
- }
- else {
- $x = [ 'data' => $data, 'prvkey' => $prvkey, 'alg' => $data['alg'], 'result' => $data ];
- call_hooks('crypto_unencapsulate',$x);
- return $x['result'];
- }
- }
+ if ($method) {
+ openssl_private_decrypt(base64url_decode($data['key']), $k, $prvkey, $padding);
+ openssl_private_decrypt(base64url_decode($data['iv']), $i, $prvkey, $padding);
+ return openssl_decrypt(base64url_decode($data['data']), $method[1], substr($k, 0, $method[2]), OPENSSL_RAW_DATA, substr($i, 0, $method[3]));
+ } else {
+ $x = [ 'data' => $data, 'prvkey' => $prvkey, 'alg' => $data['alg'], 'result' => $data ];
+ call_hooks('crypto_unencapsulate', $x);
+ return $x['result'];
+ }
+ }
}
diff --git a/Zotlabs/Lib/DB_Upgrade.php b/Zotlabs/Lib/DB_Upgrade.php
index 692ca98fb..56d8fc88b 100644
--- a/Zotlabs/Lib/DB_Upgrade.php
+++ b/Zotlabs/Lib/DB_Upgrade.php
@@ -2,7 +2,6 @@
namespace Zotlabs\Lib;
-
use App;
class DB_Upgrade
@@ -18,8 +17,9 @@ class DB_Upgrade
$this->func_prefix = '_';
$build = get_config('system', 'db_version', 0);
- if (!intval($build))
+ if (!intval($build)) {
$build = set_config('system', 'db_version', $db_revision);
+ }
if ($build == $db_revision) {
// Nothing to be done.
@@ -34,7 +34,6 @@ class DB_Upgrade
$current = intval($db_revision);
if ($stored < $current) {
-
// The last update we performed was $stored.
// Start at $stored + 1 and continue until we have completed $current
@@ -55,8 +54,9 @@ class DB_Upgrade
Config::Load('database');
- if (get_config('database', $s))
+ if (get_config('database', $s)) {
break;
+ }
set_config('database', $s, '1');
@@ -65,8 +65,6 @@ class DB_Upgrade
$retval = $c->run();
if ($retval != UPDATE_SUCCESS) {
-
-
$source = t('Source code of failed update: ') . "\n\n" . @file_get_contents('Zotlabs/Update/' . $s . '.php');
@@ -75,13 +73,15 @@ class DB_Upgrade
$lockfile = 'cache/mailsent';
- if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400)))
+ if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400))) {
return;
+ }
@unlink($lockfile);
//send the administrator an e-mail
file_put_contents($lockfile, $x);
- $r = q("select account_language from account where account_email = '%s' limit 1",
+ $r = q(
+ "select account_language from account where account_email = '%s' limit 1",
dbesc(App::$config['system']['admin_email'])
);
push_lang(($r) ? $r[0]['account_language'] : 'en');
@@ -89,7 +89,8 @@ class DB_Upgrade
[
'toEmail' => App::$config['system']['admin_email'],
'messageSubject' => sprintf(t('Update Error at %s'), z_root()),
- 'textVersion' => replace_macros(get_intltext_template('update_fail_eml.tpl'),
+ 'textVersion' => replace_macros(
+ get_intltext_template('update_fail_eml.tpl'),
[
'$sitename' => App::$config['system']['sitename'],
'$siteurl' => z_root(),
@@ -113,4 +114,4 @@ class DB_Upgrade
set_config('system', 'db_version', $db_revision);
}
}
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/DReport.php b/Zotlabs/Lib/DReport.php
index b023fc7fd..d0330e098 100644
--- a/Zotlabs/Lib/DReport.php
+++ b/Zotlabs/Lib/DReport.php
@@ -1,4 +1,5 @@
' . t('Notification Settings') . '');
- $sender_name = $product;
- $hostname = App::get_hostname();
- if(strpos($hostname,':'))
- $hostname = substr($hostname,0,strpos($hostname,':'));
-
- // Do not translate 'noreply' as it must be a legal 7-bit email address
-
- $reply_email = get_config('system','reply_address');
- if(! $reply_email)
- $reply_email = 'noreply' . '@' . $hostname;
-
- $sender_email = get_config('system','from_email');
- if(! $sender_email)
- $sender_email = 'Administrator' . '@' . $hostname;
-
- $sender_name = get_config('system','from_email_name');
- if(! $sender_name)
- $sender_name = System::get_site_name();
-
-
- $additional_mail_header = "";
-
- if(array_key_exists('item', $params)) {
- require_once('include/conversation.php');
- // if it's a normal item...
- if (array_key_exists('verb', $params['item'])) {
- // localize_item() alters the original item so make a copy first
- $i = $params['item'];
- logger('calling localize');
- localize_item($i);
- $title = $i['title'];
- $body = $i['body'];
- $private = (($i['item_private']) || intval($i['item_obscured']));
- }
- else {
- $title = $params['item']['title'];
- $body = $params['item']['body'];
- }
- if($params['item']['created'] < datetime_convert('UTC','UTC','now - 1 month')) {
- logger('notification invoked for an old item which may have been refetched.',LOGGER_DEBUG,LOG_INFO);
- return;
- }
- }
- else {
- $title = $body = '';
- }
-
-
- $always_show_in_notices = get_pconfig($recip['channel_id'],'system','always_show_in_notices');
- $vnotify = get_pconfig($recip['channel_id'],'system','vnotify');
-
- $salutation = $recip['channel_name'];
-
- // e.g. "your post", "David's photo", etc.
- $possess_desc = t('%s ');
-
- if ($params['type'] == NOTIFY_MAIL) {
- logger('notification: mail');
- $subject = sprintf( t('[$Projectname:Notify] New mail received at %s'),$sitename);
-
- if ($params['item']['mid'] === $params['item']['parent_mid']) {
- $preamble = sprintf( t('%1$s sent you a new private message at %2$s.'), $sender['xchan_name'],$sitename);
- $epreamble = sprintf( t('%1$s sent you %2$s.'),'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', '[zrl=$itemlink]' . t('a private message') . '[/zrl]');
- }
- else {
- $preamble = sprintf( t('%1$s replied to a private message at %2$s.'), $sender['xchan_name'],$sitename);
- $epreamble = sprintf( t('%1$s replied to %2$s.'),'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', '[zrl=$itemlink]' . t('a private message') . '[/zrl]');
- }
- $sitelink = t('Please visit %s to view and/or reply to your private messages.');
-
- $tsitelink = sprintf( $sitelink, $siteurl . '/display/' . gen_link_id($params['item']['mid']) );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- $itemlink = z_root() . '/display/' . gen_link_id($params['item']['mid']);
- }
-
- if (in_array(intval($params['type']), [ NOTIFY_COMMENT, NOTIFY_RESHARE ] )) {
- // logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
-
- $moderated = (($params['item']['item_blocked'] == ITEM_MODERATED) ? true : false);
-
- $itemlink = $params['link'];
-
- $action = t('commented on');
-
- if(array_key_exists('item',$params) && in_array($params['item']['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
-
- if(! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE)) {
- logger('notification: not a visible activity. Ignoring.');
- pop_lang();
- return;
- }
-
- if(activity_match($params['verb'], ACTIVITY_LIKE))
- $action = t('liked');
-
- if(activity_match($params['verb'], ACTIVITY_DISLIKE))
- $action = t('disliked');
-
- }
-
- $parent_mid = $params['parent_mid'];
-
- // Check to see if there was already a notify for this post.
- // If so don't create a second notification
-
- $p = null;
- $p = q("select id from notify where link = '%s' and uid = %d limit 1",
- dbesc($params['link']),
- intval($recip['channel_id'])
- );
- if ($p) {
- logger('notification: comment already notified');
- pop_lang();
- return;
- }
-
-
- // if it's a post figure out who's post it is.
-
- $p = null;
-
- if($params['otype'] === 'item' && $parent_mid) {
- $p = q("select * from item where mid = '%s' and uid = %d limit 1",
- dbesc($parent_mid),
- intval($recip['channel_id'])
- );
- }
-
- xchan_query($p);
-
- $item_post_type = item_post_type($p[0]);
-// $private = $p[0]['item_private'];
- $parent_id = $p[0]['id'];
-
- $parent_item = $p[0];
-
- //$possess_desc = str_replace('',$possess_desc);
-
- // "a post"
- $dest_str = sprintf(t('%1$s %2$s [zrl=%3$s]a %4$s[/zrl]'),
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $action,
- $itemlink,
- $item_post_type);
-
- // "George Bull's post"
- if($p)
- $dest_str = sprintf(t('%1$s %2$s [zrl=%3$s]%4$s\'s %5$s[/zrl]'),
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $action,
- $itemlink,
- $p[0]['author']['xchan_name'],
- $item_post_type);
-
- // "your post"
- if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall']))
- $dest_str = sprintf(t('%1$s %2$s [zrl=%3$s]your %4$s[/zrl]'),
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $action,
- $itemlink,
- $item_post_type);
-
- // Some mail softwares relies on subject field for threading.
- // So, we cannot have different subjects for notifications of the same thread.
- // Before this we have the name of the replier on the subject rendering
- // differents subjects for messages on the same thread.
-
- if($moderated) {
- $subject = sprintf( t('[$Projectname:Notify] Moderated Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
- $itemlink = z_root() . '/moderate/' . gen_link_id($params['item']['mid']);
- }
- else
- $subject = sprintf( t('[$Projectname:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
- $preamble = sprintf( t('%1$s commented on an item/conversation you have been following.'), $sender['xchan_name']);
- $epreamble = $dest_str;
-
- if ($moderated) {
- $epreamble .= ' ' . t('(Moderated)');
- }
-
- $sitelink = t('Please visit %s to view and/or reply to the conversation.');
- $tsitelink = sprintf( $sitelink, $siteurl );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- if($moderated) {
- $tsitelink .= "\n\n" . sprintf( t('Please visit %s to approve or reject this comment.'), z_root() . '/moderate' );
- $hsitelink .= "
" . sprintf( t('Please visit %s to approve or reject this comment.'), '' . z_root() . '/moderate' );
- }
-
- }
-
- if ($params['type'] == NOTIFY_LIKE) {
-// logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
-
- $itemlink = $params['link'];
-
- if (array_key_exists('item',$params) && (! activity_match($params['item']['verb'],ACTIVITY_LIKE))) {
- if(! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE)) {
- logger('notification: not a visible activity. Ignoring.');
- pop_lang();
- return;
- }
- }
-
- $parent_mid = $params['parent_mid'];
-
- // Check to see if there was already a notify for this post.
- // If so don't create a second notification
-
- $p = null;
- $p = q("select id from notify where link = '%s' and uid = %d limit 1",
- dbesc($params['link']),
- intval($recip['channel_id'])
- );
- if ($p) {
- logger('notification: like already notified');
- pop_lang();
- return;
- }
-
-
- // if it's a post figure out who's post it is.
-
- $p = null;
-
- if($params['otype'] === 'item' && $parent_mid) {
- $p = q("select * from item where mid = '%s' and uid = %d limit 1",
- dbesc($parent_mid),
- intval($recip['channel_id'])
- );
- }
-
- xchan_query($p);
-
-
- $item_post_type = item_post_type($p[0]);
-// $private = $p[0]['item_private'];
- $parent_id = $p[0]['id'];
-
- $parent_item = $p[0];
-
-
- // "your post"
- if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall']))
- $dest_str = sprintf(t('%1$s liked [zrl=%2$s]your %3$s[/zrl]'),
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $itemlink,
- $item_post_type);
- else {
- pop_lang();
- return;
- }
-
- // Some mail softwares relies on subject field for threading.
- // So, we cannot have different subjects for notifications of the same thread.
- // Before this we have the name of the replier on the subject rendering
- // differents subjects for messages on the same thread.
-
- $subject = sprintf( t('[$Projectname:Notify] Like received to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
- $preamble = sprintf( t('%1$s liked an item/conversation you created.'), $sender['xchan_name']);
- $epreamble = $dest_str;
-
- $sitelink = t('Please visit %s to view and/or reply to the conversation.');
- $tsitelink = sprintf( $sitelink, $siteurl );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- }
-
-
-
- if($params['type'] == NOTIFY_WALL) {
- $subject = sprintf( t('[$Projectname:Notify] %s posted to your profile wall') , $sender['xchan_name']);
-
- $moderated = (($params['item']['item_blocked'] == ITEM_MODERATED) ? true : false);
-
- $itemlink = (($moderated) ? z_root() . '/moderate/' . gen_link_id($params['item']['mid']) : $params['link']);
-
- $preamble = sprintf( t('%1$s posted to your profile wall at %2$s') , $sender['xchan_name'], $sitename);
-
- $epreamble = sprintf( t('%1$s posted to [zrl=%2$s]your wall[/zrl]') ,
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $itemlink);
-
-
- if($moderated) {
- $subject .= t(' - ') . t('Moderated');
- $epreamble .= t(' - ') . t('Moderated');
- }
-
- $sitelink = t('Please visit %s to view and/or reply to the conversation.');
- $tsitelink = sprintf( $sitelink, $siteurl );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
-
- if($moderated) {
- $tsitelink .= "\n\n" . sprintf( t('Please visit %s to approve or reject this post.'), z_root() . '/moderate' );
- $hsitelink .= "
" . sprintf( t('Please visit %s to approve or reject this post.'), '' . z_root() . '/moderate' );
- }
-
- }
-
- if ($params['type'] == NOTIFY_TAGSELF) {
-
- $p = null;
- $p = q("select id from notify where link = '%s' and uid = %d limit 1",
- dbesc($params['link']),
- intval($recip['channel_id'])
- );
- if ($p) {
- logger('enotify: tag: already notified about this post');
- pop_lang();
- return;
- }
-
- $subject = sprintf( t('[$Projectname:Notify] %s tagged you') , $sender['xchan_name']);
- $preamble = sprintf( t('%1$s tagged you at %2$s') , $sender['xchan_name'], $sitename);
- $epreamble = sprintf( t('%1$s [zrl=%2$s]tagged you[/zrl].') ,
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $params['link']);
-
- $sitelink = t('Please visit %s to view and/or reply to the conversation.');
- $tsitelink = sprintf( $sitelink, $siteurl );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- $itemlink = $params['link'];
- }
-
- if ($params['type'] == NOTIFY_POKE) {
- $subject = sprintf( t('[$Projectname:Notify] %1$s poked you') , $sender['xchan_name']);
- $preamble = sprintf( t('%1$s poked you at %2$s') , $sender['xchan_name'], $sitename);
- $epreamble = sprintf( t('%1$s [zrl=%2$s]poked you[/zrl].') ,
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $params['link']);
-
- $subject = str_replace('poked', t($params['activity']), $subject);
- $preamble = str_replace('poked', t($params['activity']), $preamble);
- $epreamble = str_replace('poked', t($params['activity']), $epreamble);
-
- $sitelink = t('Please visit %s to view and/or reply to the conversation.');
- $tsitelink = sprintf( $sitelink, $siteurl );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- $itemlink = $params['link'];
- }
-
- if ($params['type'] == NOTIFY_TAGSHARE) {
- $subject = sprintf( t('[$Projectname:Notify] %s tagged your post') , $sender['xchan_name']);
- $preamble = sprintf( t('%1$s tagged your post at %2$s'),$sender['xchan_name'], $sitename);
- $epreamble = sprintf( t('%1$s tagged [zrl=%2$s]your post[/zrl]') ,
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
- $itemlink);
-
- $sitelink = t('Please visit %s to view and/or reply to the conversation.');
- $tsitelink = sprintf( $sitelink, $siteurl );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- $itemlink = $params['link'];
- }
-
- if ($params['type'] == NOTIFY_INTRO) {
- $subject = sprintf( t('[$Projectname:Notify] Introduction received'));
- $preamble = sprintf( t('You\'ve received an new connection request from \'%1$s\' at %2$s'), $sender['xchan_name'], $sitename);
- $epreamble = sprintf( t('You\'ve received [zrl=%1$s]a new connection request[/zrl] from %2$s.'),
- $siteurl . '/connections/ifpending',
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]');
- $body = sprintf( t('You may visit their profile at %s'),$sender['xchan_url']);
-
- $sitelink = t('Please visit %s to approve or reject the connection request.');
- $tsitelink = sprintf( $sitelink, $siteurl . '/connections/ifpending');
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- $itemlink = $params['link'];
- }
-
- if ($params['type'] == NOTIFY_SUGGEST) {
- $subject = sprintf( t('[$Projectname:Notify] Friend suggestion received'));
- $preamble = sprintf( t('You\'ve received a friend suggestion from \'%1$s\' at %2$s'), $sender['xchan_name'], $sitename);
- $epreamble = sprintf( t('You\'ve received [zrl=%1$s]a friend suggestion[/zrl] for %2$s from %3$s.'),
- $itemlink,
- '[zrl=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/zrl]',
- '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]');
-
- $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
- $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
- $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
-
- $sitelink = t('Please visit %s to approve or reject the suggestion.');
- $tsitelink = sprintf( $sitelink, $siteurl );
- $hsitelink = sprintf( $sitelink, '' . $sitename . '');
- $itemlink = $params['link'];
- }
-
- if ($params['type'] == NOTIFY_CONFIRM) {
- // ?
- }
-
- if ($params['type'] == NOTIFY_SYSTEM) {
- // ?
- }
-
- $h = array(
- 'params' => $params,
- 'subject' => $subject,
- 'preamble' => $preamble,
- 'epreamble' => $epreamble,
- 'body' => $body,
- 'sitelink' => $sitelink,
- 'sitename' => $sitename,
- 'tsitelink' => $tsitelink,
- 'hsitelink' => $hsitelink,
- 'itemlink' => $itemlink,
- 'sender' => $sender,
- 'recipient' => $recip
- );
-
- call_hooks('enotify', $h);
-
- $subject = $h['subject'];
- $preamble = $h['preamble'];
- $epreamble = $h['epreamble'];
- $body = $h['body'];
- $sitelink = $h['sitelink'];
- $tsitelink = $h['tsitelink'];
- $hsitelink = $h['hsitelink'];
- $itemlink = $h['itemlink'];
-
-
- require_once('include/html2bbcode.php');
-
- do {
- $dups = false;
- $hash = random_string();
- $r = q("SELECT id FROM notify WHERE hash = '%s' LIMIT 1",
- dbesc($hash));
- if ($r)
- $dups = true;
- } while ($dups === true);
-
-
- $datarray = [];
- $datarray['hash'] = $hash;
- $datarray['sender_hash'] = $sender['xchan_hash'];
- $datarray['xname'] = $sender['xchan_name'];
- $datarray['url'] = $sender['xchan_url'];
- $datarray['photo'] = $sender['xchan_photo_s'];
- $datarray['created'] = datetime_convert();
- $datarray['aid'] = $recip['channel_account_id'];
- $datarray['uid'] = $recip['channel_id'];
- $datarray['link'] = $itemlink;
- $datarray['parent'] = $parent_mid;
- $datarray['parent_item'] = $parent_item;
- $datarray['ntype'] = $params['type'];
- $datarray['verb'] = $params['verb'];
- $datarray['otype'] = $params['otype'];
- $datarray['abort'] = false;
-
- $datarray['item'] = $params['item'];
-
- if (LibBlock::fetch_by_entity($datarray['uid'],$datarray['sender_hash'])) {
- pop_lang();
- return;
- }
-
- if (is_array($datarray['parent_item'])) {
- if (LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['author_xchan']) || LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['owner_xchan'])) {
- pop_lang();
- return;
- }
- }
-
- call_hooks('enotify_store', $datarray);
-
- if ($datarray['abort']) {
- pop_lang();
- return;
- }
-
-
- // create notification entry in DB
- $seen = 0;
-
- // Mark some notifications as seen right away
- // Note! The notification have to be created, because they are used to send emails
- // So easiest solution to hide them from Notices is to mark them as seen right away.
- // Another option would be to not add them to the DB, and change how emails are handled
- // (probably would be better that way)
-
- if (!$always_show_in_notices) {
- if (($params['type'] == NOTIFY_WALL) || ($params['type'] == NOTIFY_INTRO)) {
- $seen = 1;
- }
- // set back to unseen for moderated wall posts
- if($params['type'] == NOTIFY_WALL && $params['item']['item_blocked'] == ITEM_MODERATED) {
- $seen = 0;
- }
-
- }
-
- $e = q("select * from notify where otype = '%s' and xname = '%s' and verb = '%s' and link = '%s' and ntype = %d limit 1",
- dbesc($datarray['otype']),
- dbesc($datarray['xname']),
- dbesc($datarray['verb']),
- dbesc($datarray['link']),
- intval($datarray['ntype'])
- );
- if($e) {
- logger('duplicated notification');
- pop_lang();
- return;
- }
-
- $r = q("insert into notify (hash,xname,url,photo,created,msg,aid,uid,link,parent,seen,ntype,verb,otype)
+ dbesc($params['to_xchan'])
+ );
+ }
+ if ($x && $y) {
+ $sender = $x[0];
+ $recip = $y[0];
+ } else {
+ logger('notification: no sender or recipient.');
+ logger('sender: ' . $params['from_xchan']);
+ logger('recip: ' . $params['to_xchan']);
+ return;
+ }
+
+
+
+ // from here on everything is in the recipients language
+
+ push_lang($recip['account_language']); // should probably have a channel language
+
+ $banner = t('$Projectname Notification');
+ $product = t('$projectname'); // PLATFORM_NAME;
+ $siteurl = z_root();
+ $thanks = t('Thank You,');
+ $sitename = get_config('system', 'sitename');
+ $site_admin = sprintf(t('%s Administrator'), $sitename);
+ $opt_out1 = sprintf(t('This email was sent by %1$s at %2$s.'), t('$Projectname'), App::get_hostname());
+ $opt_out2 = sprintf(t('To stop receiving these messages, please adjust your Notification Settings at %s'), z_root() . '/settings');
+ $hopt_out2 = sprintf(t('To stop receiving these messages, please adjust your %s.'), '' . t('Notification Settings') . '');
+ $sender_name = $product;
+ $hostname = App::get_hostname();
+ if (strpos($hostname, ':')) {
+ $hostname = substr($hostname, 0, strpos($hostname, ':'));
+ }
+
+ // Do not translate 'noreply' as it must be a legal 7-bit email address
+
+ $reply_email = get_config('system', 'reply_address');
+ if (! $reply_email) {
+ $reply_email = 'noreply' . '@' . $hostname;
+ }
+
+ $sender_email = get_config('system', 'from_email');
+ if (! $sender_email) {
+ $sender_email = 'Administrator' . '@' . $hostname;
+ }
+
+ $sender_name = get_config('system', 'from_email_name');
+ if (! $sender_name) {
+ $sender_name = System::get_site_name();
+ }
+
+
+ $additional_mail_header = "";
+
+ if (array_key_exists('item', $params)) {
+ require_once('include/conversation.php');
+ // if it's a normal item...
+ if (array_key_exists('verb', $params['item'])) {
+ // localize_item() alters the original item so make a copy first
+ $i = $params['item'];
+ logger('calling localize');
+ localize_item($i);
+ $title = $i['title'];
+ $body = $i['body'];
+ $private = (($i['item_private']) || intval($i['item_obscured']));
+ } else {
+ $title = $params['item']['title'];
+ $body = $params['item']['body'];
+ }
+ if ($params['item']['created'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) {
+ logger('notification invoked for an old item which may have been refetched.', LOGGER_DEBUG, LOG_INFO);
+ return;
+ }
+ } else {
+ $title = $body = '';
+ }
+
+
+ $always_show_in_notices = get_pconfig($recip['channel_id'], 'system', 'always_show_in_notices');
+ $vnotify = get_pconfig($recip['channel_id'], 'system', 'vnotify');
+
+ $salutation = $recip['channel_name'];
+
+ // e.g. "your post", "David's photo", etc.
+ $possess_desc = t('%s ');
+
+ if ($params['type'] == NOTIFY_MAIL) {
+ logger('notification: mail');
+ $subject = sprintf(t('[$Projectname:Notify] New mail received at %s'), $sitename);
+
+ if ($params['item']['mid'] === $params['item']['parent_mid']) {
+ $preamble = sprintf(t('%1$s sent you a new private message at %2$s.'), $sender['xchan_name'], $sitename);
+ $epreamble = sprintf(t('%1$s sent you %2$s.'), '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', '[zrl=$itemlink]' . t('a private message') . '[/zrl]');
+ } else {
+ $preamble = sprintf(t('%1$s replied to a private message at %2$s.'), $sender['xchan_name'], $sitename);
+ $epreamble = sprintf(t('%1$s replied to %2$s.'), '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', '[zrl=$itemlink]' . t('a private message') . '[/zrl]');
+ }
+ $sitelink = t('Please visit %s to view and/or reply to your private messages.');
+
+ $tsitelink = sprintf($sitelink, $siteurl . '/display/' . gen_link_id($params['item']['mid']));
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ $itemlink = z_root() . '/display/' . gen_link_id($params['item']['mid']);
+ }
+
+ if (in_array(intval($params['type']), [ NOTIFY_COMMENT, NOTIFY_RESHARE ])) {
+ // logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
+
+ $moderated = (($params['item']['item_blocked'] == ITEM_MODERATED) ? true : false);
+
+ $itemlink = $params['link'];
+
+ $action = t('commented on');
+
+ if (array_key_exists('item', $params) && in_array($params['item']['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ if (! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE)) {
+ logger('notification: not a visible activity. Ignoring.');
+ pop_lang();
+ return;
+ }
+
+ if (activity_match($params['verb'], ACTIVITY_LIKE)) {
+ $action = t('liked');
+ }
+
+ if (activity_match($params['verb'], ACTIVITY_DISLIKE)) {
+ $action = t('disliked');
+ }
+ }
+
+ $parent_mid = $params['parent_mid'];
+
+ // Check to see if there was already a notify for this post.
+ // If so don't create a second notification
+
+ $p = null;
+ $p = q(
+ "select id from notify where link = '%s' and uid = %d limit 1",
+ dbesc($params['link']),
+ intval($recip['channel_id'])
+ );
+ if ($p) {
+ logger('notification: comment already notified');
+ pop_lang();
+ return;
+ }
+
+
+ // if it's a post figure out who's post it is.
+
+ $p = null;
+
+ if ($params['otype'] === 'item' && $parent_mid) {
+ $p = q(
+ "select * from item where mid = '%s' and uid = %d limit 1",
+ dbesc($parent_mid),
+ intval($recip['channel_id'])
+ );
+ }
+
+ xchan_query($p);
+
+ $item_post_type = item_post_type($p[0]);
+ // $private = $p[0]['item_private'];
+ $parent_id = $p[0]['id'];
+
+ $parent_item = $p[0];
+
+ //$possess_desc = str_replace('',$possess_desc);
+
+ // "a post"
+ $dest_str = sprintf(
+ t('%1$s %2$s [zrl=%3$s]a %4$s[/zrl]'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $action,
+ $itemlink,
+ $item_post_type
+ );
+
+ // "George Bull's post"
+ if ($p) {
+ $dest_str = sprintf(
+ t('%1$s %2$s [zrl=%3$s]%4$s\'s %5$s[/zrl]'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $action,
+ $itemlink,
+ $p[0]['author']['xchan_name'],
+ $item_post_type
+ );
+ }
+
+ // "your post"
+ if ($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall'])) {
+ $dest_str = sprintf(
+ t('%1$s %2$s [zrl=%3$s]your %4$s[/zrl]'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $action,
+ $itemlink,
+ $item_post_type
+ );
+ }
+
+ // Some mail softwares relies on subject field for threading.
+ // So, we cannot have different subjects for notifications of the same thread.
+ // Before this we have the name of the replier on the subject rendering
+ // differents subjects for messages on the same thread.
+
+ if ($moderated) {
+ $subject = sprintf(t('[$Projectname:Notify] Moderated Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
+ $itemlink = z_root() . '/moderate/' . gen_link_id($params['item']['mid']);
+ } else {
+ $subject = sprintf(t('[$Projectname:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
+ }
+ $preamble = sprintf(t('%1$s commented on an item/conversation you have been following.'), $sender['xchan_name']);
+ $epreamble = $dest_str;
+
+ if ($moderated) {
+ $epreamble .= ' ' . t('(Moderated)');
+ }
+
+ $sitelink = t('Please visit %s to view and/or reply to the conversation.');
+ $tsitelink = sprintf($sitelink, $siteurl);
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ if ($moderated) {
+ $tsitelink .= "\n\n" . sprintf(t('Please visit %s to approve or reject this comment.'), z_root() . '/moderate');
+ $hsitelink .= "
" . sprintf(t('Please visit %s to approve or reject this comment.'), '' . z_root() . '/moderate');
+ }
+ }
+
+ if ($params['type'] == NOTIFY_LIKE) {
+ // logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
+
+ $itemlink = $params['link'];
+
+ if (array_key_exists('item', $params) && (! activity_match($params['item']['verb'], ACTIVITY_LIKE))) {
+ if (! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE)) {
+ logger('notification: not a visible activity. Ignoring.');
+ pop_lang();
+ return;
+ }
+ }
+
+ $parent_mid = $params['parent_mid'];
+
+ // Check to see if there was already a notify for this post.
+ // If so don't create a second notification
+
+ $p = null;
+ $p = q(
+ "select id from notify where link = '%s' and uid = %d limit 1",
+ dbesc($params['link']),
+ intval($recip['channel_id'])
+ );
+ if ($p) {
+ logger('notification: like already notified');
+ pop_lang();
+ return;
+ }
+
+
+ // if it's a post figure out who's post it is.
+
+ $p = null;
+
+ if ($params['otype'] === 'item' && $parent_mid) {
+ $p = q(
+ "select * from item where mid = '%s' and uid = %d limit 1",
+ dbesc($parent_mid),
+ intval($recip['channel_id'])
+ );
+ }
+
+ xchan_query($p);
+
+
+ $item_post_type = item_post_type($p[0]);
+ // $private = $p[0]['item_private'];
+ $parent_id = $p[0]['id'];
+
+ $parent_item = $p[0];
+
+
+ // "your post"
+ if ($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall'])) {
+ $dest_str = sprintf(
+ t('%1$s liked [zrl=%2$s]your %3$s[/zrl]'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $itemlink,
+ $item_post_type
+ );
+ } else {
+ pop_lang();
+ return;
+ }
+
+ // Some mail softwares relies on subject field for threading.
+ // So, we cannot have different subjects for notifications of the same thread.
+ // Before this we have the name of the replier on the subject rendering
+ // differents subjects for messages on the same thread.
+
+ $subject = sprintf(t('[$Projectname:Notify] Like received to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
+ $preamble = sprintf(t('%1$s liked an item/conversation you created.'), $sender['xchan_name']);
+ $epreamble = $dest_str;
+
+ $sitelink = t('Please visit %s to view and/or reply to the conversation.');
+ $tsitelink = sprintf($sitelink, $siteurl);
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ }
+
+
+
+ if ($params['type'] == NOTIFY_WALL) {
+ $subject = sprintf(t('[$Projectname:Notify] %s posted to your profile wall'), $sender['xchan_name']);
+
+ $moderated = (($params['item']['item_blocked'] == ITEM_MODERATED) ? true : false);
+
+ $itemlink = (($moderated) ? z_root() . '/moderate/' . gen_link_id($params['item']['mid']) : $params['link']);
+
+ $preamble = sprintf(t('%1$s posted to your profile wall at %2$s'), $sender['xchan_name'], $sitename);
+
+ $epreamble = sprintf(
+ t('%1$s posted to [zrl=%2$s]your wall[/zrl]'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $itemlink
+ );
+
+
+ if ($moderated) {
+ $subject .= t(' - ') . t('Moderated');
+ $epreamble .= t(' - ') . t('Moderated');
+ }
+
+ $sitelink = t('Please visit %s to view and/or reply to the conversation.');
+ $tsitelink = sprintf($sitelink, $siteurl);
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+
+ if ($moderated) {
+ $tsitelink .= "\n\n" . sprintf(t('Please visit %s to approve or reject this post.'), z_root() . '/moderate');
+ $hsitelink .= "
" . sprintf(t('Please visit %s to approve or reject this post.'), '' . z_root() . '/moderate');
+ }
+ }
+
+ if ($params['type'] == NOTIFY_TAGSELF) {
+ $p = null;
+ $p = q(
+ "select id from notify where link = '%s' and uid = %d limit 1",
+ dbesc($params['link']),
+ intval($recip['channel_id'])
+ );
+ if ($p) {
+ logger('enotify: tag: already notified about this post');
+ pop_lang();
+ return;
+ }
+
+ $subject = sprintf(t('[$Projectname:Notify] %s tagged you'), $sender['xchan_name']);
+ $preamble = sprintf(t('%1$s tagged you at %2$s'), $sender['xchan_name'], $sitename);
+ $epreamble = sprintf(
+ t('%1$s [zrl=%2$s]tagged you[/zrl].'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $params['link']
+ );
+
+ $sitelink = t('Please visit %s to view and/or reply to the conversation.');
+ $tsitelink = sprintf($sitelink, $siteurl);
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ $itemlink = $params['link'];
+ }
+
+ if ($params['type'] == NOTIFY_POKE) {
+ $subject = sprintf(t('[$Projectname:Notify] %1$s poked you'), $sender['xchan_name']);
+ $preamble = sprintf(t('%1$s poked you at %2$s'), $sender['xchan_name'], $sitename);
+ $epreamble = sprintf(
+ t('%1$s [zrl=%2$s]poked you[/zrl].'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $params['link']
+ );
+
+ $subject = str_replace('poked', t($params['activity']), $subject);
+ $preamble = str_replace('poked', t($params['activity']), $preamble);
+ $epreamble = str_replace('poked', t($params['activity']), $epreamble);
+
+ $sitelink = t('Please visit %s to view and/or reply to the conversation.');
+ $tsitelink = sprintf($sitelink, $siteurl);
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ $itemlink = $params['link'];
+ }
+
+ if ($params['type'] == NOTIFY_TAGSHARE) {
+ $subject = sprintf(t('[$Projectname:Notify] %s tagged your post'), $sender['xchan_name']);
+ $preamble = sprintf(t('%1$s tagged your post at %2$s'), $sender['xchan_name'], $sitename);
+ $epreamble = sprintf(
+ t('%1$s tagged [zrl=%2$s]your post[/zrl]'),
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $itemlink
+ );
+
+ $sitelink = t('Please visit %s to view and/or reply to the conversation.');
+ $tsitelink = sprintf($sitelink, $siteurl);
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ $itemlink = $params['link'];
+ }
+
+ if ($params['type'] == NOTIFY_INTRO) {
+ $subject = sprintf(t('[$Projectname:Notify] Introduction received'));
+ $preamble = sprintf(t('You\'ve received an new connection request from \'%1$s\' at %2$s'), $sender['xchan_name'], $sitename);
+ $epreamble = sprintf(
+ t('You\'ve received [zrl=%1$s]a new connection request[/zrl] from %2$s.'),
+ $siteurl . '/connections/ifpending',
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'
+ );
+ $body = sprintf(t('You may visit their profile at %s'), $sender['xchan_url']);
+
+ $sitelink = t('Please visit %s to approve or reject the connection request.');
+ $tsitelink = sprintf($sitelink, $siteurl . '/connections/ifpending');
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ $itemlink = $params['link'];
+ }
+
+ if ($params['type'] == NOTIFY_SUGGEST) {
+ $subject = sprintf(t('[$Projectname:Notify] Friend suggestion received'));
+ $preamble = sprintf(t('You\'ve received a friend suggestion from \'%1$s\' at %2$s'), $sender['xchan_name'], $sitename);
+ $epreamble = sprintf(
+ t('You\'ve received [zrl=%1$s]a friend suggestion[/zrl] for %2$s from %3$s.'),
+ $itemlink,
+ '[zrl=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/zrl]',
+ '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'
+ );
+
+ $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
+ $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
+ $body .= sprintf(t('You may visit their profile at %s'), $params['item']['url']);
+
+ $sitelink = t('Please visit %s to approve or reject the suggestion.');
+ $tsitelink = sprintf($sitelink, $siteurl);
+ $hsitelink = sprintf($sitelink, '' . $sitename . '');
+ $itemlink = $params['link'];
+ }
+
+ if ($params['type'] == NOTIFY_CONFIRM) {
+ // ?
+ }
+
+ if ($params['type'] == NOTIFY_SYSTEM) {
+ // ?
+ }
+
+ $h = array(
+ 'params' => $params,
+ 'subject' => $subject,
+ 'preamble' => $preamble,
+ 'epreamble' => $epreamble,
+ 'body' => $body,
+ 'sitelink' => $sitelink,
+ 'sitename' => $sitename,
+ 'tsitelink' => $tsitelink,
+ 'hsitelink' => $hsitelink,
+ 'itemlink' => $itemlink,
+ 'sender' => $sender,
+ 'recipient' => $recip
+ );
+
+ call_hooks('enotify', $h);
+
+ $subject = $h['subject'];
+ $preamble = $h['preamble'];
+ $epreamble = $h['epreamble'];
+ $body = $h['body'];
+ $sitelink = $h['sitelink'];
+ $tsitelink = $h['tsitelink'];
+ $hsitelink = $h['hsitelink'];
+ $itemlink = $h['itemlink'];
+
+
+ require_once('include/html2bbcode.php');
+
+ do {
+ $dups = false;
+ $hash = random_string();
+ $r = q(
+ "SELECT id FROM notify WHERE hash = '%s' LIMIT 1",
+ dbesc($hash)
+ );
+ if ($r) {
+ $dups = true;
+ }
+ } while ($dups === true);
+
+
+ $datarray = [];
+ $datarray['hash'] = $hash;
+ $datarray['sender_hash'] = $sender['xchan_hash'];
+ $datarray['xname'] = $sender['xchan_name'];
+ $datarray['url'] = $sender['xchan_url'];
+ $datarray['photo'] = $sender['xchan_photo_s'];
+ $datarray['created'] = datetime_convert();
+ $datarray['aid'] = $recip['channel_account_id'];
+ $datarray['uid'] = $recip['channel_id'];
+ $datarray['link'] = $itemlink;
+ $datarray['parent'] = $parent_mid;
+ $datarray['parent_item'] = $parent_item;
+ $datarray['ntype'] = $params['type'];
+ $datarray['verb'] = $params['verb'];
+ $datarray['otype'] = $params['otype'];
+ $datarray['abort'] = false;
+
+ $datarray['item'] = $params['item'];
+
+ if (LibBlock::fetch_by_entity($datarray['uid'], $datarray['sender_hash'])) {
+ pop_lang();
+ return;
+ }
+
+ if (is_array($datarray['parent_item'])) {
+ if (LibBlock::fetch_by_entity($datarray['uid'], $datarray['parent_item']['author_xchan']) || LibBlock::fetch_by_entity($datarray['uid'], $datarray['parent_item']['owner_xchan'])) {
+ pop_lang();
+ return;
+ }
+ }
+
+ call_hooks('enotify_store', $datarray);
+
+ if ($datarray['abort']) {
+ pop_lang();
+ return;
+ }
+
+
+ // create notification entry in DB
+ $seen = 0;
+
+ // Mark some notifications as seen right away
+ // Note! The notification have to be created, because they are used to send emails
+ // So easiest solution to hide them from Notices is to mark them as seen right away.
+ // Another option would be to not add them to the DB, and change how emails are handled
+ // (probably would be better that way)
+
+ if (!$always_show_in_notices) {
+ if (($params['type'] == NOTIFY_WALL) || ($params['type'] == NOTIFY_INTRO)) {
+ $seen = 1;
+ }
+ // set back to unseen for moderated wall posts
+ if ($params['type'] == NOTIFY_WALL && $params['item']['item_blocked'] == ITEM_MODERATED) {
+ $seen = 0;
+ }
+ }
+
+ $e = q(
+ "select * from notify where otype = '%s' and xname = '%s' and verb = '%s' and link = '%s' and ntype = %d limit 1",
+ dbesc($datarray['otype']),
+ dbesc($datarray['xname']),
+ dbesc($datarray['verb']),
+ dbesc($datarray['link']),
+ intval($datarray['ntype'])
+ );
+ if ($e) {
+ logger('duplicated notification');
+ pop_lang();
+ return;
+ }
+
+ $r = q(
+ "insert into notify (hash,xname,url,photo,created,msg,aid,uid,link,parent,seen,ntype,verb,otype)
values('%s','%s','%s','%s','%s','%s',%d,%d,'%s','%s',%d,%d,'%s','%s')",
- dbesc($datarray['hash']),
- dbesc($datarray['xname']),
- dbesc($datarray['url']),
- dbesc($datarray['photo']),
- dbesc($datarray['created']),
- dbesc(''), // will fill this in below after the record is created
- intval($datarray['aid']),
- intval($datarray['uid']),
- dbesc($datarray['link']),
- dbesc($datarray['parent']),
- intval($seen),
- intval($datarray['ntype']),
- dbesc($datarray['verb']),
- dbesc($datarray['otype'])
- );
+ dbesc($datarray['hash']),
+ dbesc($datarray['xname']),
+ dbesc($datarray['url']),
+ dbesc($datarray['photo']),
+ dbesc($datarray['created']),
+ dbesc(''), // will fill this in below after the record is created
+ intval($datarray['aid']),
+ intval($datarray['uid']),
+ dbesc($datarray['link']),
+ dbesc($datarray['parent']),
+ intval($seen),
+ intval($datarray['ntype']),
+ dbesc($datarray['verb']),
+ dbesc($datarray['otype'])
+ );
- $r = q("select id from notify where hash = '%s' and uid = %d limit 1",
- dbesc($hash),
- intval($recip['channel_id'])
- );
- if ($r) {
- $notify_id = $r[0]['id'];
- } else {
- logger('notification not found.');
- pop_lang();
- return;
- }
+ $r = q(
+ "select id from notify where hash = '%s' and uid = %d limit 1",
+ dbesc($hash),
+ intval($recip['channel_id'])
+ );
+ if ($r) {
+ $notify_id = $r[0]['id'];
+ } else {
+ logger('notification not found.');
+ pop_lang();
+ return;
+ }
- $itemlink = z_root() . '/notify/view/' . $notify_id;
- $msg = str_replace('$itemlink',$itemlink,$epreamble);
+ $itemlink = z_root() . '/notify/view/' . $notify_id;
+ $msg = str_replace('$itemlink', $itemlink, $epreamble);
- // wretched hack, but we don't want to duplicate all the preamble variations and we also don't want to screw up a translation
+ // wretched hack, but we don't want to duplicate all the preamble variations and we also don't want to screw up a translation
- if ((App::$language === 'en' || (! App::$language)) && strpos($msg,', '))
- $msg = substr($msg,strpos($msg,', ') + 1);
+ if ((App::$language === 'en' || (! App::$language)) && strpos($msg, ', ')) {
+ $msg = substr($msg, strpos($msg, ', ') + 1);
+ }
- $r = q("update notify set msg = '%s' where id = %d and uid = %d",
- dbesc($msg),
- intval($notify_id),
- intval($datarray['uid'])
- );
+ $r = q(
+ "update notify set msg = '%s' where id = %d and uid = %d",
+ dbesc($msg),
+ intval($notify_id),
+ intval($datarray['uid'])
+ );
- // send email notification if notification preferences permit
+ // send email notification if notification preferences permit
- require_once('bbcode.php');
- if ((intval($recip['channel_notifyflags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
+ require_once('bbcode.php');
+ if ((intval($recip['channel_notifyflags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
+ logger('notification: sending notification email');
- logger('notification: sending notification email');
+ $hn = get_pconfig($recip['channel_id'], 'system', 'email_notify_host');
+ if ($hn && (! stristr(App::get_hostname(), $hn))) {
+ // this isn't the email notification host
+ pop_lang();
+ return;
+ }
- $hn = get_pconfig($recip['channel_id'],'system','email_notify_host');
- if($hn && (! stristr(App::get_hostname(),$hn))) {
- // this isn't the email notification host
- pop_lang();
- return;
- }
+ $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r", "\\n"), array( "", "\n"), $body))), ENT_QUOTES, 'UTF-8'));
- $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r", "\\n"), array( "", "\n"), $body))),ENT_QUOTES,'UTF-8'));
-
- $htmlversion = bbcode(stripslashes(str_replace(array("\\r","\\n"), array("","
\n"),$body)));
+ $htmlversion = bbcode(stripslashes(str_replace(array("\\r","\\n"), array("","
\n"), $body)));
- // use $_SESSION['zid_override'] to force zid() to use
- // the recipient address instead of the current observer
+ // use $_SESSION['zid_override'] to force zid() to use
+ // the recipient address instead of the current observer
- $_SESSION['zid_override'] = channel_reddress($recip);
- $_SESSION['zrl_override'] = z_root() . '/channel/' . $recip['channel_address'];
-
- $textversion = zidify_links($textversion);
- $htmlversion = zidify_links($htmlversion);
+ $_SESSION['zid_override'] = channel_reddress($recip);
+ $_SESSION['zrl_override'] = z_root() . '/channel/' . $recip['channel_address'];
- // unset when done to revert to normal behaviour
+ $textversion = zidify_links($textversion);
+ $htmlversion = zidify_links($htmlversion);
- unset($_SESSION['zid_override']);
- unset($_SESSION['zrl_override']);
+ // unset when done to revert to normal behaviour
- $datarray = [];
- $datarray['banner'] = $banner;
- $datarray['product'] = $product;
- $datarray['preamble'] = $preamble;
- $datarray['sitename'] = $sitename;
- $datarray['siteurl'] = $siteurl;
- $datarray['type'] = $params['type'];
- $datarray['parent'] = $params['parent_mid'];
- $datarray['source_name'] = $sender['xchan_name'];
- $datarray['source_link'] = $sender['xchan_url'];
- $datarray['source_photo'] = $sender['xchan_photo_s'];
- $datarray['uid'] = $recip['channel_id'];
- $datarray['username'] = $recip['channel_name'];
- $datarray['hsitelink'] = $hsitelink;
- $datarray['tsitelink'] = $tsitelink;
- $datarray['hitemlink'] = '' . $itemlink . '';
- $datarray['titemlink'] = $itemlink;
- $datarray['thanks'] = $thanks;
- $datarray['site_admin'] = $site_admin;
- $datarray['opt_out1'] = $opt_out1;
- $datarray['opt_out2'] = $opt_out2;
- $datarray['hopt_out2'] = $hopt_out2;
- $datarray['title'] = stripslashes($title);
- $datarray['htmlversion'] = $htmlversion;
- $datarray['textversion'] = $textversion;
- $datarray['subject'] = $subject;
- $datarray['headers'] = $additional_mail_header;
- $datarray['email_secure'] = false;
+ unset($_SESSION['zid_override']);
+ unset($_SESSION['zrl_override']);
- call_hooks('enotify_mail', $datarray);
+ $datarray = [];
+ $datarray['banner'] = $banner;
+ $datarray['product'] = $product;
+ $datarray['preamble'] = $preamble;
+ $datarray['sitename'] = $sitename;
+ $datarray['siteurl'] = $siteurl;
+ $datarray['type'] = $params['type'];
+ $datarray['parent'] = $params['parent_mid'];
+ $datarray['source_name'] = $sender['xchan_name'];
+ $datarray['source_link'] = $sender['xchan_url'];
+ $datarray['source_photo'] = $sender['xchan_photo_s'];
+ $datarray['uid'] = $recip['channel_id'];
+ $datarray['username'] = $recip['channel_name'];
+ $datarray['hsitelink'] = $hsitelink;
+ $datarray['tsitelink'] = $tsitelink;
+ $datarray['hitemlink'] = '' . $itemlink . '';
+ $datarray['titemlink'] = $itemlink;
+ $datarray['thanks'] = $thanks;
+ $datarray['site_admin'] = $site_admin;
+ $datarray['opt_out1'] = $opt_out1;
+ $datarray['opt_out2'] = $opt_out2;
+ $datarray['hopt_out2'] = $hopt_out2;
+ $datarray['title'] = stripslashes($title);
+ $datarray['htmlversion'] = $htmlversion;
+ $datarray['textversion'] = $textversion;
+ $datarray['subject'] = $subject;
+ $datarray['headers'] = $additional_mail_header;
+ $datarray['email_secure'] = false;
- // Default to private - don't disclose message contents over insecure channels (such as email)
- // Might be interesting to use GPG,PGP,S/MIME encryption instead
- // but we'll save that for a clever plugin developer to implement
+ call_hooks('enotify_mail', $datarray);
- $private_activity = false;
+ // Default to private - don't disclose message contents over insecure channels (such as email)
+ // Might be interesting to use GPG,PGP,S/MIME encryption instead
+ // but we'll save that for a clever plugin developer to implement
- if (! $datarray['email_secure']) {
- switch ($params['type']) {
- case NOTIFY_WALL:
- case NOTIFY_TAGSELF:
- case NOTIFY_POKE:
- case NOTIFY_RESHARE:
- case NOTIFY_COMMENT:
- if (! $private)
- break;
- $private_activity = true;
- case NOTIFY_MAIL:
- $datarray['textversion'] = $datarray['htmlversion'] = $datarray['title'] = '';
- $datarray['subject'] = preg_replace('/' . preg_quote(t('[$Projectname:Notify]'), '/') . '/','$0*',$datarray['subject']);
- break;
- default:
- break;
- }
- }
+ $private_activity = false;
- if ($private_activity
- && intval(get_pconfig($datarray['uid'], 'system', 'ignore_private_notifications'))) {
+ if (! $datarray['email_secure']) {
+ switch ($params['type']) {
+ case NOTIFY_WALL:
+ case NOTIFY_TAGSELF:
+ case NOTIFY_POKE:
+ case NOTIFY_RESHARE:
+ case NOTIFY_COMMENT:
+ if (! $private) {
+ break;
+ }
+ $private_activity = true;
+ case NOTIFY_MAIL:
+ $datarray['textversion'] = $datarray['htmlversion'] = $datarray['title'] = '';
+ $datarray['subject'] = preg_replace('/' . preg_quote(t('[$Projectname:Notify]'), '/') . '/', '$0*', $datarray['subject']);
+ break;
+ default:
+ break;
+ }
+ }
- pop_lang();
- return;
- }
+ if (
+ $private_activity
+ && intval(get_pconfig($datarray['uid'], 'system', 'ignore_private_notifications'))
+ ) {
+ pop_lang();
+ return;
+ }
- // load the template for private message notifications
- $tpl = get_markup_template('email_notify_html.tpl');
- $email_html_body = replace_macros($tpl,array(
- '$banner' => $datarray['banner'],
- '$notify_icon' => System::get_site_icon(),
- '$product' => $datarray['product'],
- '$preamble' => $salutation . '
' . $datarray['preamble'],
- '$sitename' => $datarray['sitename'],
- '$siteurl' => $datarray['siteurl'],
- '$source_name' => $datarray['source_name'],
- '$source_link' => $datarray['source_link'],
- '$source_photo' => $datarray['source_photo'],
- '$username' => $datarray['to_name'],
- '$hsitelink' => $datarray['hsitelink'],
- '$hitemlink' => $datarray['hitemlink'],
- '$thanks' => $datarray['thanks'],
- '$site_admin' => $datarray['site_admin'],
- '$opt_out1' => $datarray['opt_out1'],
- '$opt_out2' => $datarray['hopt_out2'],
- '$title' => $datarray['title'],
- '$htmlversion' => $datarray['htmlversion'],
- ));
+ // load the template for private message notifications
+ $tpl = get_markup_template('email_notify_html.tpl');
+ $email_html_body = replace_macros($tpl, array(
+ '$banner' => $datarray['banner'],
+ '$notify_icon' => System::get_site_icon(),
+ '$product' => $datarray['product'],
+ '$preamble' => $salutation . '
' . $datarray['preamble'],
+ '$sitename' => $datarray['sitename'],
+ '$siteurl' => $datarray['siteurl'],
+ '$source_name' => $datarray['source_name'],
+ '$source_link' => $datarray['source_link'],
+ '$source_photo' => $datarray['source_photo'],
+ '$username' => $datarray['to_name'],
+ '$hsitelink' => $datarray['hsitelink'],
+ '$hitemlink' => $datarray['hitemlink'],
+ '$thanks' => $datarray['thanks'],
+ '$site_admin' => $datarray['site_admin'],
+ '$opt_out1' => $datarray['opt_out1'],
+ '$opt_out2' => $datarray['hopt_out2'],
+ '$title' => $datarray['title'],
+ '$htmlversion' => $datarray['htmlversion'],
+ ));
- // load the template for private message notifications
- $tpl = get_markup_template('email_notify_text.tpl');
- $email_text_body = replace_macros($tpl, array(
- '$banner' => $datarray['banner'],
- '$product' => $datarray['product'],
- '$preamble' => $salutation . "\n\n" . $datarray['preamble'],
- '$sitename' => $datarray['sitename'],
- '$siteurl' => $datarray['siteurl'],
- '$source_name' => $datarray['source_name'],
- '$source_link' => $datarray['source_link'],
- '$source_photo' => $datarray['source_photo'],
- '$username' => $datarray['to_name'],
- '$tsitelink' => $datarray['tsitelink'],
- '$titemlink' => $datarray['titemlink'],
- '$thanks' => $datarray['thanks'],
- '$site_admin' => $datarray['site_admin'],
- '$opt_out1' => $datarray['opt_out1'],
- '$opt_out2' => $datarray['opt_out2'],
- '$title' => $datarray['title'],
- '$textversion' => $datarray['textversion'],
- ));
+ // load the template for private message notifications
+ $tpl = get_markup_template('email_notify_text.tpl');
+ $email_text_body = replace_macros($tpl, array(
+ '$banner' => $datarray['banner'],
+ '$product' => $datarray['product'],
+ '$preamble' => $salutation . "\n\n" . $datarray['preamble'],
+ '$sitename' => $datarray['sitename'],
+ '$siteurl' => $datarray['siteurl'],
+ '$source_name' => $datarray['source_name'],
+ '$source_link' => $datarray['source_link'],
+ '$source_photo' => $datarray['source_photo'],
+ '$username' => $datarray['to_name'],
+ '$tsitelink' => $datarray['tsitelink'],
+ '$titemlink' => $datarray['titemlink'],
+ '$thanks' => $datarray['thanks'],
+ '$site_admin' => $datarray['site_admin'],
+ '$opt_out1' => $datarray['opt_out1'],
+ '$opt_out2' => $datarray['opt_out2'],
+ '$title' => $datarray['title'],
+ '$textversion' => $datarray['textversion'],
+ ));
-// logger('text: ' . $email_text_body);
+ // logger('text: ' . $email_text_body);
- // use the EmailNotification library to send the message
+ // use the EmailNotification library to send the message
- $to_email = $recip['account_email'];
+ $to_email = $recip['account_email'];
- $e = get_pconfig($recip['channel_id'],'system','notification_email', false);
- if ($e) {
- $to_email = $e;
- }
+ $e = get_pconfig($recip['channel_id'], 'system', 'notification_email', false);
+ if ($e) {
+ $to_email = $e;
+ }
- $addrs = explode(',', $to_email);
+ $addrs = explode(',', $to_email);
- foreach($addrs as $addr) {
+ foreach ($addrs as $addr) {
+ self::send(array(
+ 'fromName' => $sender_name,
+ 'fromEmail' => $sender_email,
+ 'replyTo' => $reply_email,
+ 'toEmail' => $addr,
+ 'messageSubject' => $datarray['subject'],
+ 'htmlVersion' => $email_html_body,
+ 'textVersion' => $email_text_body,
+ 'additionalMailHeader' => $datarray['headers'],
+ ));
+ }
+ }
- self::send(array(
- 'fromName' => $sender_name,
- 'fromEmail' => $sender_email,
- 'replyTo' => $reply_email,
- 'toEmail' => $addr,
- 'messageSubject' => $datarray['subject'],
- 'htmlVersion' => $email_html_body,
- 'textVersion' => $email_text_body,
- 'additionalMailHeader' => $datarray['headers'],
- ));
- }
- }
+ pop_lang();
+ }
- pop_lang();
-
-}
-
-
- /**
- * @brief Send a multipart/alternative message with Text and HTML versions.
- *
- * @param array $params an assoziative array with:
- * * \e string \b fromName name of the sender
- * * \e string \b fromEmail email of the sender
- * * \e string \b replyTo replyTo address to direct responses
- * * \e string \b toEmail destination email address
- * * \e string \b messageSubject subject of the message
- * * \e string \b htmlVersion html version of the message
- * * \e string \b textVersion text only version of the message
- * * \e string \b additionalMailHeader additions to the smtp mail header
- */
- public static function send($params) {
-
- $params['sent'] = false;
- $params['result'] = false;
-
- call_hooks('email_send', $params);
-
- if($params['sent']) {
- logger("notification: enotify::send (addon) returns " . (($params['result']) ? 'success' : 'failure'), LOGGER_DEBUG);
- return $params['result'];
- }
-
- $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
- $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
-
- // generate a mime boundary
- $mimeBoundary = rand(0, 9) . "-"
- .rand(100000000, 999999999) . "-"
- .rand(100000000, 999999999) . "=:"
- .rand(10000, 99999);
-
- // generate a multipart/alternative message header
- $messageHeader =
- $params['additionalMailHeader'] .
- "From: $fromName <{$params['fromEmail']}>" . PHP_EOL .
- "Reply-To: $fromName <{$params['replyTo']}>" . PHP_EOL .
- "MIME-Version: 1.0" . PHP_EOL .
- "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
-
- // assemble the final multipart message body with the text and html types included
- $textBody = chunk_split(base64_encode($params['textVersion']));
- $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
-
- $multipartMessageBody =
- "--" . $mimeBoundary . PHP_EOL . // plain text section
- "Content-Type: text/plain; charset=UTF-8" . PHP_EOL .
- "Content-Transfer-Encoding: base64" . PHP_EOL . PHP_EOL .
- $textBody . PHP_EOL .
- "--" . $mimeBoundary . PHP_EOL . // text/html section
- "Content-Type: text/html; charset=UTF-8" . PHP_EOL .
- "Content-Transfer-Encoding: base64" . PHP_EOL . PHP_EOL .
- $htmlBody . PHP_EOL .
- "--" . $mimeBoundary . "--" . PHP_EOL; // message ending
-
- // send the message
- $res = mail(
- $params['toEmail'], // send to address
- $messageSubject, // subject
- $multipartMessageBody, // message body
- $messageHeader // message headers
- );
- logger("notification: enotify::send returns " . (($res) ? 'success' : 'failure'), LOGGER_DEBUG);
- return $res;
- }
-
- public static function format($item) {
-
- $ret = '';
-
- $expire = intval(get_config('system','default_expire_days'));
- $expire_date = (($expire) ? datetime_convert('UTC','UTC','now - ' . $expire . ' days') : NULL_DATE);
-
- require_once('include/conversation.php');
-
- // Call localize_item to get a one line status for activities.
- // This should set $item['localize'] to indicate we have a brief summary.
- // and perhaps $item['shortlocalize'] for an even briefer summary
-
- localize_item($item);
-
- if($item['shortlocalize']) {
- $itemem_text = $item['shortlocalize'];
- }
- elseif($item['localize']) {
- $itemem_text = $item['localize'];
- }
- else {
- $itemem_text = (($item['item_thread_top'])
- ? t('created a new post')
- : sprintf( t('reacted to %s\'s conversation'), $item['owner']['xchan_name']));
- if($item['verb'] === 'Announce') {
- $itemem_text = sprintf( t('shared %s\'s post'), $item['owner']['xchan_name']);
- }
- }
- if ($item['item_private'] == 2) {
- $itemem_text = t('sent a direct message');
- }
-
- $edit = false;
-
- if($item['edited'] > $item['created']) {
- if($item['item_thread_top']) {
- $itemem_text = sprintf( t('edited a post dated %s'), relative_date($item['created']));
- $edit = true;
- }
- else {
- $itemem_text = sprintf( t('edited a comment dated %s'), relative_date($item['created']));
- $edit = true;
- }
- }
-
- if (LibBlock::fetch_by_entity(local_channel(),$item['author']['xchan_hash'])) {
- return [];
- }
-
- // convert this logic into a json array just like the system notifications
-
- $x = array(
- 'notify_link' => $item['llink'],
- 'name' => $item['author']['xchan_name'],
- 'addr' => $item['author']['xchan_addr'],
- 'url' => $item['author']['xchan_url'],
- 'photo' => $item['author']['xchan_photo_s'],
- 'when' => relative_date(($edit)? $item['edited'] : $item['created']),
- 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'),
- 'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? gen_link_id($item['thr_parent']) : gen_link_id($item['mid'])),
- 'notify_id' => 'undefined',
- 'thread_top' => (($item['item_thread_top']) ? true : false),
- 'message' => strip_tags(bbcode($itemem_text)),
- // these are for the superblock addon
- 'hash' => $item['author']['xchan_hash'],
- 'uid' => local_channel(),
- 'display' => true
- );
-
- $post_date = (($edit)? $item['edited'] : $item['created']);
- if($post_date && $post_date < $expire_date) {
- return [];
- }
-
- call_hooks('enotify_format',$x);
- if(! $x['display']) {
- return [];
- }
-
- return $x;
- }
+ /**
+ * @brief Send a multipart/alternative message with Text and HTML versions.
+ *
+ * @param array $params an assoziative array with:
+ * * \e string \b fromName name of the sender
+ * * \e string \b fromEmail email of the sender
+ * * \e string \b replyTo replyTo address to direct responses
+ * * \e string \b toEmail destination email address
+ * * \e string \b messageSubject subject of the message
+ * * \e string \b htmlVersion html version of the message
+ * * \e string \b textVersion text only version of the message
+ * * \e string \b additionalMailHeader additions to the smtp mail header
+ */
+ public static function send($params)
+ {
+
+ $params['sent'] = false;
+ $params['result'] = false;
+
+ call_hooks('email_send', $params);
+
+ if ($params['sent']) {
+ logger("notification: enotify::send (addon) returns " . (($params['result']) ? 'success' : 'failure'), LOGGER_DEBUG);
+ return $params['result'];
+ }
+
+ $fromName = email_header_encode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
+ $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8');
+
+ // generate a mime boundary
+ $mimeBoundary = rand(0, 9) . "-"
+ . rand(100000000, 999999999) . "-"
+ . rand(100000000, 999999999) . "=:"
+ . rand(10000, 99999);
+
+ // generate a multipart/alternative message header
+ $messageHeader =
+ $params['additionalMailHeader'] .
+ "From: $fromName <{$params['fromEmail']}>" . PHP_EOL .
+ "Reply-To: $fromName <{$params['replyTo']}>" . PHP_EOL .
+ "MIME-Version: 1.0" . PHP_EOL .
+ "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
+
+ // assemble the final multipart message body with the text and html types included
+ $textBody = chunk_split(base64_encode($params['textVersion']));
+ $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
+
+ $multipartMessageBody =
+ "--" . $mimeBoundary . PHP_EOL . // plain text section
+ "Content-Type: text/plain; charset=UTF-8" . PHP_EOL .
+ "Content-Transfer-Encoding: base64" . PHP_EOL . PHP_EOL .
+ $textBody . PHP_EOL .
+ "--" . $mimeBoundary . PHP_EOL . // text/html section
+ "Content-Type: text/html; charset=UTF-8" . PHP_EOL .
+ "Content-Transfer-Encoding: base64" . PHP_EOL . PHP_EOL .
+ $htmlBody . PHP_EOL .
+ "--" . $mimeBoundary . "--" . PHP_EOL; // message ending
+
+ // send the message
+ $res = mail(
+ $params['toEmail'], // send to address
+ $messageSubject, // subject
+ $multipartMessageBody, // message body
+ $messageHeader // message headers
+ );
+ logger("notification: enotify::send returns " . (($res) ? 'success' : 'failure'), LOGGER_DEBUG);
+ return $res;
+ }
+
+ public static function format($item)
+ {
+
+ $ret = '';
+
+ $expire = intval(get_config('system', 'default_expire_days'));
+ $expire_date = (($expire) ? datetime_convert('UTC', 'UTC', 'now - ' . $expire . ' days') : NULL_DATE);
+
+ require_once('include/conversation.php');
+
+ // Call localize_item to get a one line status for activities.
+ // This should set $item['localize'] to indicate we have a brief summary.
+ // and perhaps $item['shortlocalize'] for an even briefer summary
+
+ localize_item($item);
+
+ if ($item['shortlocalize']) {
+ $itemem_text = $item['shortlocalize'];
+ } elseif ($item['localize']) {
+ $itemem_text = $item['localize'];
+ } else {
+ $itemem_text = (($item['item_thread_top'])
+ ? t('created a new post')
+ : sprintf(t('reacted to %s\'s conversation'), $item['owner']['xchan_name']));
+ if ($item['verb'] === 'Announce') {
+ $itemem_text = sprintf(t('shared %s\'s post'), $item['owner']['xchan_name']);
+ }
+ }
+ if ($item['item_private'] == 2) {
+ $itemem_text = t('sent a direct message');
+ }
+
+ $edit = false;
+
+ if ($item['edited'] > $item['created']) {
+ if ($item['item_thread_top']) {
+ $itemem_text = sprintf(t('edited a post dated %s'), relative_date($item['created']));
+ $edit = true;
+ } else {
+ $itemem_text = sprintf(t('edited a comment dated %s'), relative_date($item['created']));
+ $edit = true;
+ }
+ }
+
+ if (LibBlock::fetch_by_entity(local_channel(), $item['author']['xchan_hash'])) {
+ return [];
+ }
+
+ // convert this logic into a json array just like the system notifications
+
+ $x = array(
+ 'notify_link' => $item['llink'],
+ 'name' => $item['author']['xchan_name'],
+ 'addr' => $item['author']['xchan_addr'],
+ 'url' => $item['author']['xchan_url'],
+ 'photo' => $item['author']['xchan_photo_s'],
+ 'when' => relative_date(($edit) ? $item['edited'] : $item['created']),
+ 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'),
+ 'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? gen_link_id($item['thr_parent']) : gen_link_id($item['mid'])),
+ 'notify_id' => 'undefined',
+ 'thread_top' => (($item['item_thread_top']) ? true : false),
+ 'message' => strip_tags(bbcode($itemem_text)),
+ // these are for the superblock addon
+ 'hash' => $item['author']['xchan_hash'],
+ 'uid' => local_channel(),
+ 'display' => true
+ );
+
+ $post_date = (($edit) ? $item['edited'] : $item['created']);
+ if ($post_date && $post_date < $expire_date) {
+ return [];
+ }
+
+ call_hooks('enotify_format', $x);
+ if (! $x['display']) {
+ return [];
+ }
+
+ return $x;
+ }
}
diff --git a/Zotlabs/Lib/ExtendedZip.php b/Zotlabs/Lib/ExtendedZip.php
index 5bc6db6c8..3b1bea668 100644
--- a/Zotlabs/Lib/ExtendedZip.php
+++ b/Zotlabs/Lib/ExtendedZip.php
@@ -15,45 +15,49 @@ use ZipArchive;
*
* @author andrew
*/
-class ExtendedZip extends ZipArchive {
-
- // Member function to add a whole file system subtree to the archive
- public function addTree($dirname, $localname = '') {
- if ($localname)
- $this->addEmptyDir($localname);
- $this->_addTree($dirname, $localname);
- }
+class ExtendedZip extends ZipArchive
+{
- // Internal function, to recurse
- protected function _addTree($dirname, $localname) {
- $dir = opendir($dirname);
- while ($filename = readdir($dir)) {
- // Discard . and ..
- if ($filename == '.' || $filename == '..')
- continue;
+ // Member function to add a whole file system subtree to the archive
+ public function addTree($dirname, $localname = '')
+ {
+ if ($localname) {
+ $this->addEmptyDir($localname);
+ }
+ $this->_addTree($dirname, $localname);
+ }
- // Proceed according to type
- $path = $dirname . '/' . $filename;
- $localpath = $localname ? ($localname . '/' . $filename) : $filename;
- if (is_dir($path)) {
- // Directory: add & recurse
- $this->addEmptyDir($localpath);
- $this->_addTree($path, $localpath);
- }
- else if (is_file($path)) {
- // File: just add
- $this->addFile($path, $localpath);
- }
- }
- closedir($dir);
- }
+ // Internal function, to recurse
+ protected function _addTree($dirname, $localname)
+ {
+ $dir = opendir($dirname);
+ while ($filename = readdir($dir)) {
+ // Discard . and ..
+ if ($filename == '.' || $filename == '..') {
+ continue;
+ }
- // Helper function
- public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '') {
- $zip = new self();
- $zip->open($zipFilename, $flags);
- $zip->addTree($dirname, $localname);
- $zip->close();
- }
-
+ // Proceed according to type
+ $path = $dirname . '/' . $filename;
+ $localpath = $localname ? ($localname . '/' . $filename) : $filename;
+ if (is_dir($path)) {
+ // Directory: add & recurse
+ $this->addEmptyDir($localpath);
+ $this->_addTree($path, $localpath);
+ } elseif (is_file($path)) {
+ // File: just add
+ $this->addFile($path, $localpath);
+ }
+ }
+ closedir($dir);
+ }
+
+ // Helper function
+ public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '')
+ {
+ $zip = new self();
+ $zip->open($zipFilename, $flags);
+ $zip->addTree($dirname, $localname);
+ $zip->close();
+ }
}
diff --git a/Zotlabs/Lib/Hashpath.php b/Zotlabs/Lib/Hashpath.php
index 1e8c9502f..1f8745b64 100644
--- a/Zotlabs/Lib/Hashpath.php
+++ b/Zotlabs/Lib/Hashpath.php
@@ -1,6 +1,6 @@
$family, 'k' => $key, 'v' => $value, 'sharing' => $sharing);
- if ((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig']))) {
- $item['iconfig'] = [];
- }
+ if (is_null($idx)) {
+ $item['iconfig'][] = $entry;
+ } else {
+ $item['iconfig'][$idx] = $entry;
+ }
+ return $value;
+ }
- if (array_key_exists('item_id',$item)) {
- $iid = $item['item_id'];
- }
- else {
- $iid = ((isset($item['id'])) ? $item['id'] : 0);
- }
-
- if (array_key_exists('iconfig',$item) && is_array($item['iconfig'])) {
- foreach ($item['iconfig'] as $c) {
- if ($c['cat'] == $family && $c['k'] == $key) {
- return $c['v'];
- }
- }
- }
- }
- elseif (intval($item)) {
- $iid = $item;
- }
+ if (intval($item)) {
+ $iid = intval($item);
+ }
- if (! $iid) {
- return $default;
- }
+ if (! $iid) {
+ return false;
+ }
- $r = q("select * from iconfig where iid = %d and cat = '%s' and k = '%s' limit 1",
- intval($iid),
- dbesc($family),
- dbesc($key)
- );
- if ($r) {
- $r[0]['v'] = unserialise($r[0]['v']);
- if ($is_item) {
- $item['iconfig'][] = $r[0];
- }
- return $r[0]['v'];
- }
- return $default;
- }
+ if (self::Get($item, $family, $key) === false) {
+ $r = q(
+ "insert into iconfig( iid, cat, k, v, sharing ) values ( %d, '%s', '%s', '%s', %d ) ",
+ intval($iid),
+ dbesc($family),
+ dbesc($key),
+ dbesc($dbvalue),
+ intval($sharing)
+ );
+ } else {
+ $r = q(
+ "update iconfig set v = '%s', sharing = %d where iid = %d and cat = '%s' and k = '%s' ",
+ dbesc($dbvalue),
+ intval($sharing),
+ intval($iid),
+ dbesc($family),
+ dbesc($key)
+ );
+ }
- /**
- * IConfig::Set(&$item, $family, $key, $value, $sharing = false);
- *
- * $item - item array or item id. If passed an array the iconfig meta information is
- * added to the item structure (which will need to be saved with item_store eventually).
- * If passed an id, the DB is updated, but may not be federated and/or cloned.
- * $family - namespace of meta variable
- * $key - key of meta variable
- * $value - value of meta variable
- * $sharing - boolean (default false); if true the meta information is propagated with the item
- * to other sites/channels, mostly useful when $item is an array and has not yet been stored/delivered.
- * If the meta information is added after delivery and you wish it to be shared, it may be necessary to
- * alter the item edited timestamp and invoke the delivery process on the updated item. The edited
- * timestamp needs to be altered in order to trigger an item_store_update() at the receiving end.
- */
-
+ if (! $r) {
+ return false;
+ }
- public static function Set(&$item, $family, $key, $value, $sharing = false) {
-
- $dbvalue = ((is_array($value)) ? serialise($value) : $value);
- $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
-
- $is_item = false;
- $idx = null;
-
- if(is_array($item)) {
- $is_item = true;
- if((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig'])))
- $item['iconfig'] = [];
- elseif($item['iconfig']) {
- for($x = 0; $x < count($item['iconfig']); $x ++) {
- if($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
- $idx = $x;
- }
- }
- }
- $entry = array('cat' => $family, 'k' => $key, 'v' => $value, 'sharing' => $sharing);
-
- if(is_null($idx))
- $item['iconfig'][] = $entry;
- else
- $item['iconfig'][$idx] = $entry;
- return $value;
- }
-
- if(intval($item))
- $iid = intval($item);
-
- if(! $iid)
- return false;
-
- if(self::Get($item, $family, $key) === false) {
- $r = q("insert into iconfig( iid, cat, k, v, sharing ) values ( %d, '%s', '%s', '%s', %d ) ",
- intval($iid),
- dbesc($family),
- dbesc($key),
- dbesc($dbvalue),
- intval($sharing)
- );
- }
- else {
- $r = q("update iconfig set v = '%s', sharing = %d where iid = %d and cat = '%s' and k = '%s' ",
- dbesc($dbvalue),
- intval($sharing),
- intval($iid),
- dbesc($family),
- dbesc($key)
- );
- }
-
- if(! $r)
- return false;
-
- return $value;
- }
+ return $value;
+ }
- public static function Delete(&$item, $family, $key) {
+ public static function Delete(&$item, $family, $key)
+ {
- $is_item = false;
- $idx = null;
+ $is_item = false;
+ $idx = null;
- if(is_array($item)) {
- $is_item = true;
- if(is_array($item['iconfig'])) {
- for($x = 0; $x < count($item['iconfig']); $x ++) {
- if($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
- unset($item['iconfig'][$x]);
- }
- }
- // re-order the array index
- $item['iconfig'] = array_values($item['iconfig']);
- }
- return true;
- }
+ if (is_array($item)) {
+ $is_item = true;
+ if (is_array($item['iconfig'])) {
+ for ($x = 0; $x < count($item['iconfig']); $x++) {
+ if ($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
+ unset($item['iconfig'][$x]);
+ }
+ }
+ // re-order the array index
+ $item['iconfig'] = array_values($item['iconfig']);
+ }
+ return true;
+ }
- if(intval($item))
- $iid = intval($item);
+ if (intval($item)) {
+ $iid = intval($item);
+ }
- if(! $iid)
- return false;
+ if (! $iid) {
+ return false;
+ }
- return q("delete from iconfig where iid = %d and cat = '%s' and k = '%s' ",
- intval($iid),
- dbesc($family),
- dbesc($key)
- );
-
- }
-
-}
\ No newline at end of file
+ return q(
+ "delete from iconfig where iid = %d and cat = '%s' and k = '%s' ",
+ intval($iid),
+ dbesc($family),
+ dbesc($key)
+ );
+ }
+}
diff --git a/Zotlabs/Lib/Img_cache.php b/Zotlabs/Lib/Img_cache.php
index fe58c6eab..1682d07b2 100644
--- a/Zotlabs/Lib/Img_cache.php
+++ b/Zotlabs/Lib/Img_cache.php
@@ -1,4 +1,5 @@
base64url_encode($key_id, true)
]
]);
-
}
public static function verify($x)
@@ -64,13 +63,10 @@ class JSalmon
}
return $ret;
-
}
public static function unpack($data)
{
return json_decode(base64url_decode($data), true);
}
-
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Keyutils.php b/Zotlabs/Lib/Keyutils.php
index 616ecfcf6..67c6f85fc 100644
--- a/Zotlabs/Lib/Keyutils.php
+++ b/Zotlabs/Lib/Keyutils.php
@@ -9,91 +9,94 @@ use phpseclib\Math\BigInteger;
* Keyutils
* Convert RSA keys between various formats
*/
-class Keyutils {
+class Keyutils
+{
- /**
- * @param string $m modulo
- * @param string $e exponent
- * @return string
- */
- public static function meToPem($m, $e) {
+ /**
+ * @param string $m modulo
+ * @param string $e exponent
+ * @return string
+ */
+ public static function meToPem($m, $e)
+ {
- $rsa = new RSA();
- $rsa->loadKey([
- 'e' => new BigInteger($e, 256),
- 'n' => new BigInteger($m, 256)
- ]);
- return $rsa->getPublicKey();
+ $rsa = new RSA();
+ $rsa->loadKey([
+ 'e' => new BigInteger($e, 256),
+ 'n' => new BigInteger($m, 256)
+ ]);
+ return $rsa->getPublicKey();
+ }
- }
+ /**
+ * @param string key
+ * @return string
+ */
+ public static function rsaToPem($key)
+ {
- /**
- * @param string key
- * @return string
- */
- public static function rsaToPem($key) {
+ $rsa = new RSA();
+ $rsa->setPublicKey($key);
- $rsa = new RSA();
- $rsa->setPublicKey($key);
+ return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8);
+ }
- return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8);
+ /**
+ * @param string key
+ * @return string
+ */
+ public static function pemToRsa($key)
+ {
- }
+ $rsa = new RSA();
+ $rsa->setPublicKey($key);
- /**
- * @param string key
- * @return string
- */
- public static function pemToRsa($key) {
+ return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1);
+ }
- $rsa = new RSA();
- $rsa->setPublicKey($key);
+ /**
+ * @param string $key key
+ * @param string $m reference modulo
+ * @param string $e reference exponent
+ */
+ public static function pemToMe($key, &$m, &$e)
+ {
- return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1);
+ $rsa = new RSA();
+ $rsa->loadKey($key);
+ $rsa->setPublicKey();
- }
+ $m = $rsa->modulus->toBytes();
+ $e = $rsa->exponent->toBytes();
+ }
- /**
- * @param string $key key
- * @param string $m reference modulo
- * @param string $e reference exponent
- */
- public static function pemToMe($key, &$m, &$e) {
+ /**
+ * @param string $pubkey
+ * @return string
+ */
+ public static function salmonKey($pubkey)
+ {
+ self::pemToMe($pubkey, $m, $e);
+ return 'RSA' . '.' . base64url_encode($m, true) . '.' . base64url_encode($e, true);
+ }
- $rsa = new RSA();
- $rsa->loadKey($key);
- $rsa->setPublicKey();
+ /**
+ * @param string $key
+ * @return string
+ */
+ public static function convertSalmonKey($key)
+ {
+ if (strstr($key, ',')) {
+ $rawkey = substr($key, strpos($key, ',') + 1);
+ } else {
+ $rawkey = substr($key, 5);
+ }
- $m = $rsa->modulus->toBytes();
- $e = $rsa->exponent->toBytes();
+ $key_info = explode('.', $rawkey);
- }
+ $m = base64url_decode($key_info[1]);
+ $e = base64url_decode($key_info[2]);
- /**
- * @param string $pubkey
- * @return string
- */
- public static function salmonKey($pubkey) {
- self::pemToMe($pubkey, $m, $e);
- return 'RSA' . '.' . base64url_encode($m, true) . '.' . base64url_encode($e, true);
- }
-
- /**
- * @param string $key
- * @return string
- */
- public static function convertSalmonKey($key) {
- if (strstr($key, ','))
- $rawkey = substr($key, strpos($key, ',') + 1);
- else
- $rawkey = substr($key, 5);
-
- $key_info = explode('.', $rawkey);
-
- $m = base64url_decode($key_info[1]);
- $e = base64url_decode($key_info[2]);
-
- return self::meToPem($m, $e);
- }
-
-}
\ No newline at end of file
+ return self::meToPem($m, $e);
+ }
+}
diff --git a/Zotlabs/Lib/LDSignatures.php b/Zotlabs/Lib/LDSignatures.php
index 737b2b199..ae88db9cd 100644
--- a/Zotlabs/Lib/LDSignatures.php
+++ b/Zotlabs/Lib/LDSignatures.php
@@ -26,7 +26,7 @@ class LDSignatures
public static function dopplesign(&$data, $channel)
{
// remove for the time being - performance issues
- // $data['magicEnv'] = self::salmon_sign($data,$channel);
+ // $data['magicEnv'] = self::salmon_sign($data,$channel);
return self::sign($data, $channel);
}
@@ -89,8 +89,9 @@ class LDSignatures
$data = json_decode($data);
}
- if (!is_object($data))
+ if (!is_object($data)) {
return '';
+ }
jsonld_set_document_loader('jsonld_document_loader');
@@ -133,8 +134,5 @@ class LDSignatures
'meCreator' => channel_url($channel),
'meSignatureValue' => $signature
]);
-
}
-
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/LibBlock.php b/Zotlabs/Lib/LibBlock.php
index 25948ddb8..0e79ea627 100644
--- a/Zotlabs/Lib/LibBlock.php
+++ b/Zotlabs/Lib/LibBlock.php
@@ -2,12 +2,11 @@
namespace Zotlabs\Lib;
-
class LibBlock
{
- static public $cache = [];
- static public $empty = [];
+ public static $cache = [];
+ public static $empty = [];
// This limits the number of DB queries for fetch_by_entity to once per page load.
@@ -46,7 +45,8 @@ class LibBlock
$arr['block_comment'] = ((array_key_exists('block_comment', $arr)) ? escape_tags(trim($arr['block_comment'])) : EMPTY_STR);
if (!intval($arr['block_id'])) {
- $r = q("select * from block where block_channel_id = %d and block_entity = '%s' and block_type = %d limit 1",
+ $r = q(
+ "select * from block where block_channel_id = %d and block_entity = '%s' and block_type = %d limit 1",
intval($arr['block_channel_id']),
dbesc($arr['block_entity']),
intval($arr['block_type'])
@@ -57,7 +57,8 @@ class LibBlock
}
if (intval($arr['block_id'])) {
- return q("UPDATE block set block_channel_id = %d, block_entity = '%s', block_type = %d, block_comment = '%s' where block_id = %d",
+ return q(
+ "UPDATE block set block_channel_id = %d, block_entity = '%s', block_type = %d, block_comment = '%s' where block_id = %d",
intval($arr['block_channel_id']),
dbesc($arr['block_entity']),
intval($arr['block_type']),
@@ -71,7 +72,8 @@ class LibBlock
public static function remove($channel_id, $entity)
{
- return q("delete from block where block_channel_id = %d and block_entity = '%s'",
+ return q(
+ "delete from block where block_channel_id = %d and block_entity = '%s'",
intval($channel_id),
dbesc($entity)
);
@@ -82,7 +84,8 @@ class LibBlock
if (!intval($channel_id)) {
return false;
}
- $r = q("select * from block where block_channel_id = %d and block_id = %d ",
+ $r = q(
+ "select * from block where block_channel_id = %d and block_id = %d ",
intval($channel_id)
);
return (($r) ? array_shift($r) : $r);
@@ -96,7 +99,6 @@ class LibBlock
}
return self::fetch_from_cache($channel_id, $entity);
-
}
public static function fetch($channel_id, $type = false)
@@ -107,10 +109,10 @@ class LibBlock
$sql_extra = (($type === false) ? EMPTY_STR : " and block_type = " . intval($type));
- $r = q("select * from block where block_channel_id = %d $sql_extra",
+ $r = q(
+ "select * from block where block_channel_id = %d $sql_extra",
intval($channel_id)
);
return $r;
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Libprofile.php b/Zotlabs/Lib/Libprofile.php
index 27611f13c..2ce56d17d 100644
--- a/Zotlabs/Lib/Libprofile.php
+++ b/Zotlabs/Lib/Libprofile.php
@@ -27,7 +27,7 @@ class Libprofile
public static function load($nickname, $profile = '')
{
- // logger('Libprofile::load: ' . $nickname . (($profile) ? ' profile: ' . $profile : ''));
+ // logger('Libprofile::load: ' . $nickname . (($profile) ? ' profile: ' . $profile : ''));
$channel = channelx_by_nick($nickname);
@@ -50,25 +50,29 @@ class Libprofile
}
if (!$profile) {
- $r = q("SELECT abook_profile FROM abook WHERE abook_xchan = '%s' and abook_channel = '%d' limit 1",
+ $r = q(
+ "SELECT abook_profile FROM abook WHERE abook_xchan = '%s' and abook_channel = '%d' limit 1",
dbesc(($observer) ? $observer['xchan_hash'] : ''),
intval($channel['channel_id'])
);
- if ($r)
+ if ($r) {
$profile = $r[0]['abook_profile'];
+ }
}
$p = null;
if ($profile) {
- $p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
+ $p = q(
+ "SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
LEFT JOIN channel ON profile.uid = channel.channel_id
WHERE channel.channel_address = '%s' AND profile.profile_guid = '%s' LIMIT 1",
dbesc($nickname),
dbesc($profile)
);
if (!$p) {
- $p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
+ $p = q(
+ "SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
LEFT JOIN channel ON profile.uid = channel.channel_id
WHERE channel.channel_address = '%s' AND profile.id = %d LIMIT 1",
dbesc($nickname),
@@ -78,7 +82,8 @@ class Libprofile
}
if (!$p) {
- $p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
+ $p = q(
+ "SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
LEFT JOIN channel ON profile.uid = channel.channel_id
WHERE channel.channel_address = '%s' and channel_removed = 0
AND profile.is_default = 1 LIMIT 1",
@@ -93,22 +98,23 @@ class Libprofile
return;
}
- $q = q("select * from profext where hash = '%s' and channel_id = %d",
+ $q = q(
+ "select * from profext where hash = '%s' and channel_id = %d",
dbesc($p[0]['profile_guid']),
intval($p[0]['profile_uid'])
);
if ($q) {
-
$extra_fields = [];
$profile_fields_basic = get_profile_fields_basic();
$profile_fields_advanced = get_profile_fields_advanced();
$advanced = ((feature_enabled(local_channel(), 'advanced_profiles')) ? true : false);
- if ($advanced)
+ if ($advanced) {
$fields = $profile_fields_advanced;
- else
+ } else {
$fields = $profile_fields_basic;
+ }
foreach ($q as $qq) {
foreach ($fields as $k => $f) {
@@ -123,7 +129,8 @@ class Libprofile
$p[0]['extra_fields'] = ((isset($extra_fields)) ? $extra_fields : []);
- $z = q("select xchan_photo_date, xchan_addr from xchan where xchan_hash = '%s' limit 1",
+ $z = q(
+ "select xchan_photo_date, xchan_addr from xchan where xchan_hash = '%s' limit 1",
dbesc($p[0]['channel_hash'])
);
if ($z) {
@@ -134,11 +141,13 @@ class Libprofile
// fetch user tags if this isn't the default profile
if (!$p[0]['is_default']) {
- $x = q("select keywords from profile where uid = %d and is_default = 1 limit 1",
+ $x = q(
+ "select keywords from profile where uid = %d and is_default = 1 limit 1",
intval($p[0]['profile_uid'])
);
- if ($x && $can_view_profile)
+ if ($x && $can_view_profile) {
$p[0]['keywords'] = $x[0]['keywords'];
+ }
}
if ($p[0]['keywords']) {
@@ -171,8 +180,7 @@ class Libprofile
* load/reload current theme info
*/
- // $_SESSION['theme'] = $p[0]['channel_theme'];
-
+ // $_SESSION['theme'] = $p[0]['channel_theme'];
}
public static function edit_menu($uid)
@@ -198,14 +206,16 @@ class Libprofile
$ret['edit'] = [z_root() . '/profiles/' . $uid, t('Edit Profile'), '', t('Edit')];
}
- $r = q("SELECT * FROM profile WHERE uid = %d",
+ $r = q(
+ "SELECT * FROM profile WHERE uid = %d",
local_channel()
);
if ($r) {
foreach ($r as $rr) {
- if (!($multi_profiles || $rr['is_default']))
+ if (!($multi_profiles || $rr['is_default'])) {
continue;
+ }
$ret['menu']['entries'][] = [
'photo' => $rr['thumb'],
@@ -252,13 +262,15 @@ class Libprofile
$block = true;
}
- if ((!is_array($profile)) && (!count($profile)))
+ if ((!is_array($profile)) && (!count($profile))) {
return $o;
+ }
head_set_icon($profile['thumb']);
- if (is_sys_channel($profile['uid']))
+ if (is_sys_channel($profile['uid'])) {
$show_connect = false;
+ }
$profile['picdate'] = urlencode($profile['picdate']);
@@ -269,42 +281,46 @@ class Libprofile
call_hooks('profile_sidebar_enter', $profile);
if ($show_connect) {
-
// This will return an empty string if we're already connected.
$connect_url = rconnect_url($profile['uid'], get_observer_hash());
$connect = (($connect_url) ? t('Connect') : '');
- if ($connect_url)
+ if ($connect_url) {
$connect_url = sprintf($connect_url, urlencode(channel_reddress($profile)));
+ }
// premium channel - over-ride
- if ($profile['channel_pageflags'] & PAGE_PREMIUM)
+ if ($profile['channel_pageflags'] & PAGE_PREMIUM) {
$connect_url = z_root() . '/connect/' . $profile['channel_address'];
+ }
}
- if ((x($profile, 'address') == 1)
+ if (
+ (x($profile, 'address') == 1)
|| (x($profile, 'locality') == 1)
|| (x($profile, 'region') == 1)
|| (x($profile, 'postal_code') == 1)
- || (x($profile, 'country_name') == 1))
+ || (x($profile, 'country_name') == 1)
+ ) {
$location = t('Location:');
+ }
$profile['homepage'] = linkify($profile['homepage'], true);
- $gender = ((x($profile, 'gender') == 1) ? t('Gender:') : False);
- $marital = ((x($profile, 'marital') == 1) ? t('Status:') : False);
- $homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : False);
- $pronouns = ((x($profile, 'pronouns') == 1) ? t('Pronouns:') : False);
+ $gender = ((x($profile, 'gender') == 1) ? t('Gender:') : false);
+ $marital = ((x($profile, 'marital') == 1) ? t('Status:') : false);
+ $homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : false);
+ $pronouns = ((x($profile, 'pronouns') == 1) ? t('Pronouns:') : false);
// zap/osada do not have a realtime chat system at this time so don't show online state
- // $profile['online'] = (($profile['online_status'] === 'online') ? t('Online Now') : False);
- // logger('online: ' . $profile['online']);
+ // $profile['online'] = (($profile['online_status'] === 'online') ? t('Online Now') : False);
+ // logger('online: ' . $profile['online']);
$profile['online'] = false;
if (($profile['hidewall'] && (!local_channel()) && (!remote_channel())) || $block) {
- $location = $reddress = $pdesc = $gender = $marital = $homepage = False;
+ $location = $reddress = $pdesc = $gender = $marital = $homepage = false;
}
if ($profile['gender']) {
@@ -327,8 +343,9 @@ class Libprofile
if ($menu && !$block) {
require_once('include/menu.php');
$m = menu_fetch($menu, $profile['uid'], $observer['xchan_hash']);
- if ($m)
+ if ($m) {
$channel_menu = menu_render($m);
+ }
}
$menublock = get_pconfig($profile['uid'], 'system', 'channel_menublock');
if ($menublock && (!$block)) {
@@ -336,10 +353,11 @@ class Libprofile
$channel_menu .= $comanche->block($menublock);
}
- if ($zcard)
+ if ($zcard) {
$tpl = get_markup_template('profile_vcard_short.tpl');
- else
+ } else {
$tpl = get_markup_template('profile_vcard.tpl');
+ }
$o .= replace_macros($tpl, array(
'$zcard' => $zcard,
@@ -383,23 +401,29 @@ class Libprofile
public static function gender_icon($gender)
{
- // logger('gender: ' . $gender);
+ // logger('gender: ' . $gender);
// This can easily get throw off if the observer language is different
// than the channel owner language.
- if (strpos(strtolower($gender), strtolower(t('Female'))) !== false)
+ if (strpos(strtolower($gender), strtolower(t('Female'))) !== false) {
return 'venus';
- if (strpos(strtolower($gender), strtolower(t('Male'))) !== false)
+ }
+ if (strpos(strtolower($gender), strtolower(t('Male'))) !== false) {
return 'mars';
- if (strpos(strtolower($gender), strtolower(t('Trans'))) !== false)
+ }
+ if (strpos(strtolower($gender), strtolower(t('Trans'))) !== false) {
return 'transgender';
- if (strpos(strtolower($gender), strtolower(t('Inter'))) !== false)
+ }
+ if (strpos(strtolower($gender), strtolower(t('Inter'))) !== false) {
return 'transgender';
- if (strpos(strtolower($gender), strtolower(t('Neuter'))) !== false)
+ }
+ if (strpos(strtolower($gender), strtolower(t('Neuter'))) !== false) {
return 'neuter';
- if (strpos(strtolower($gender), strtolower(t('Non-specific'))) !== false)
+ }
+ if (strpos(strtolower($gender), strtolower(t('Non-specific'))) !== false) {
return 'genderless';
+ }
return '';
}
@@ -411,12 +435,15 @@ class Libprofile
// This can easily get throw off if the observer language is different
// than the channel owner language.
- if (strpos(strtolower($pronouns), strtolower(t('She'))) !== false)
+ if (strpos(strtolower($pronouns), strtolower(t('She'))) !== false) {
return 'venus';
- if (strpos(strtolower($pronouns), strtolower(t('Him'))) !== false)
+ }
+ if (strpos(strtolower($pronouns), strtolower(t('Him'))) !== false) {
return 'mars';
- if (strpos(strtolower($pronouns), strtolower(t('Them'))) !== false)
+ }
+ if (strpos(strtolower($pronouns), strtolower(t('Them'))) !== false) {
return 'users';
+ }
return '';
}
@@ -425,19 +452,20 @@ class Libprofile
public static function advanced()
{
- if (!perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_profile'))
+ if (!perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_profile')) {
return '';
+ }
if (App::$profile['fullname']) {
-
$profile_fields_basic = get_profile_fields_basic();
$profile_fields_advanced = get_profile_fields_advanced();
$advanced = ((feature_enabled(App::$profile['profile_uid'], 'advanced_profiles')) ? true : false);
- if ($advanced)
+ if ($advanced) {
$fields = $profile_fields_advanced;
- else
+ } else {
$fields = $profile_fields_basic;
+ }
$clean_fields = [];
if ($fields) {
@@ -453,38 +481,40 @@ class Libprofile
$profile['fullname'] = array(t('Full Name:'), App::$profile['fullname']);
- if (App::$profile['gender']) $profile['gender'] = array(t('Gender:'), App::$profile['gender']);
+ if (App::$profile['gender']) {
+ $profile['gender'] = array(t('Gender:'), App::$profile['gender']);
+ }
$ob_hash = get_observer_hash();
// this may not work at all any more, but definitely won't work correctly if the liked profile belongs to a group
// comment out until we are able to look at it much closer
-// if($ob_hash && perm_is_allowed(App::$profile['profile_uid'],$ob_hash,'post_like')) {
-// $profile['canlike'] = true;
-// $profile['likethis'] = t('Like this channel');
-// $profile['profile_guid'] = App::$profile['profile_guid'];
-// }
+// if($ob_hash && perm_is_allowed(App::$profile['profile_uid'],$ob_hash,'post_like')) {
+// $profile['canlike'] = true;
+// $profile['likethis'] = t('Like this channel');
+// $profile['profile_guid'] = App::$profile['profile_guid'];
+// }
-// $likers = q("select liker, xchan.* from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'",
-// intval(App::$profile['profile_uid']),
-// dbesc(ACTIVITY_OBJ_PROFILE),
-// dbesc(ACTIVITY_LIKE)
-// );
-// $profile['likers'] = [];
-// $profile['like_count'] = count($likers);
-// $profile['like_button_label'] = tt('Like','Likes',$profile['like_count'],'noun');
+// $likers = q("select liker, xchan.* from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'",
+// intval(App::$profile['profile_uid']),
+// dbesc(ACTIVITY_OBJ_PROFILE),
+// dbesc(ACTIVITY_LIKE)
+// );
+// $profile['likers'] = [];
+// $profile['like_count'] = count($likers);
+// $profile['like_button_label'] = tt('Like','Likes',$profile['like_count'],'noun');
-// if($likers) {
-// foreach($likers as $l)
-// $profile['likers'][] = array('name' => $l['xchan_name'],'photo' => zid($l['xchan_photo_s']), 'url' => zid($l['xchan_url']));
-// }
+// if($likers) {
+// foreach($likers as $l)
+// $profile['likers'][] = array('name' => $l['xchan_name'],'photo' => zid($l['xchan_photo_s']), 'url' => zid($l['xchan_url']));
+// }
if ((App::$profile['dob']) && (App::$profile['dob'] != '0000-00-00')) {
-
$val = '';
- if ((substr(App::$profile['dob'], 5, 2) === '00') || (substr(App::$profile['dob'], 8, 2) === '00'))
+ if ((substr(App::$profile['dob'], 5, 2) === '00') || (substr(App::$profile['dob'], 8, 2) === '00')) {
$val = substr(App::$profile['dob'], 0, 4);
+ }
$year_bd_format = t('j F, Y');
$short_bd_format = t('j F');
@@ -497,14 +527,17 @@ class Libprofile
$profile['birthday'] = array(t('Birthday:'), $val);
}
- if ($age = age(App::$profile['dob'], App::$profile['timezone'], ''))
+ if ($age = age(App::$profile['dob'], App::$profile['timezone'], '')) {
$profile['age'] = array(t('Age:'), $age);
+ }
- if (App::$profile['marital'])
+ if (App::$profile['marital']) {
$profile['marital'] = array(t('Status:'), App::$profile['marital']);
+ }
- if (App::$profile['partner'])
+ if (App::$profile['partner']) {
$profile['marital']['partner'] = zidify_links(bbcode(App::$profile['partner']));
+ }
if (strlen(App::$profile['howlong']) && App::$profile['howlong'] > NULL_DATE) {
$profile['howlong'] = relative_date(App::$profile['howlong'], t('for %1$d %2$s'));
@@ -523,51 +556,91 @@ class Libprofile
}
- if (App::$profile['sexual']) $profile['sexual'] = array(t('Sexual Preference:'), App::$profile['sexual']);
+ if (App::$profile['sexual']) {
+ $profile['sexual'] = array(t('Sexual Preference:'), App::$profile['sexual']);
+ }
- if (App::$profile['pronouns']) $profile['pronouns'] = array(t('Pronouns:'), App::$profile['pronouns']);
+ if (App::$profile['pronouns']) {
+ $profile['pronouns'] = array(t('Pronouns:'), App::$profile['pronouns']);
+ }
- if (App::$profile['homepage']) $profile['homepage'] = array(t('Homepage:'), linkify(App::$profile['homepage']));
+ if (App::$profile['homepage']) {
+ $profile['homepage'] = array(t('Homepage:'), linkify(App::$profile['homepage']));
+ }
- if (App::$profile['hometown']) $profile['hometown'] = array(t('Hometown:'), linkify(App::$profile['hometown']));
+ if (App::$profile['hometown']) {
+ $profile['hometown'] = array(t('Hometown:'), linkify(App::$profile['hometown']));
+ }
- if (App::$profile['politic']) $profile['politic'] = array(t('Political Views:'), App::$profile['politic']);
+ if (App::$profile['politic']) {
+ $profile['politic'] = array(t('Political Views:'), App::$profile['politic']);
+ }
- if (App::$profile['religion']) $profile['religion'] = array(t('Religion:'), App::$profile['religion']);
+ if (App::$profile['religion']) {
+ $profile['religion'] = array(t('Religion:'), App::$profile['religion']);
+ }
- if ($txt = prepare_text(App::$profile['about'])) $profile['about'] = array(t('About:'), $txt);
+ if ($txt = prepare_text(App::$profile['about'])) {
+ $profile['about'] = array(t('About:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['interest'])) $profile['interest'] = array(t('Hobbies/Interests:'), $txt);
+ if ($txt = prepare_text(App::$profile['interest'])) {
+ $profile['interest'] = array(t('Hobbies/Interests:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['likes'])) $profile['likes'] = array(t('Likes:'), $txt);
+ if ($txt = prepare_text(App::$profile['likes'])) {
+ $profile['likes'] = array(t('Likes:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['dislikes'])) $profile['dislikes'] = array(t('Dislikes:'), $txt);
+ if ($txt = prepare_text(App::$profile['dislikes'])) {
+ $profile['dislikes'] = array(t('Dislikes:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['contact'])) $profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
+ if ($txt = prepare_text(App::$profile['contact'])) {
+ $profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['channels'])) $profile['channels'] = array(t('My other channels:'), $txt);
+ if ($txt = prepare_text(App::$profile['channels'])) {
+ $profile['channels'] = array(t('My other channels:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['music'])) $profile['music'] = array(t('Musical interests:'), $txt);
+ if ($txt = prepare_text(App::$profile['music'])) {
+ $profile['music'] = array(t('Musical interests:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['book'])) $profile['book'] = array(t('Books, literature:'), $txt);
+ if ($txt = prepare_text(App::$profile['book'])) {
+ $profile['book'] = array(t('Books, literature:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['tv'])) $profile['tv'] = array(t('Television:'), $txt);
+ if ($txt = prepare_text(App::$profile['tv'])) {
+ $profile['tv'] = array(t('Television:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['film'])) $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
+ if ($txt = prepare_text(App::$profile['film'])) {
+ $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['romance'])) $profile['romance'] = array(t('Love/Romance:'), $txt);
+ if ($txt = prepare_text(App::$profile['romance'])) {
+ $profile['romance'] = array(t('Love/Romance:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['employment'])) $profile['employment'] = array(t('Work/employment:'), $txt);
+ if ($txt = prepare_text(App::$profile['employment'])) {
+ $profile['employment'] = array(t('Work/employment:'), $txt);
+ }
- if ($txt = prepare_text(App::$profile['education'])) $profile['education'] = array(t('School/education:'), $txt);
+ if ($txt = prepare_text(App::$profile['education'])) {
+ $profile['education'] = array(t('School/education:'), $txt);
+ }
if (App::$profile['extra_fields']) {
foreach (App::$profile['extra_fields'] as $f) {
- $x = q("select * from profdef where field_name = '%s' limit 1",
+ $x = q(
+ "select * from profdef where field_name = '%s' limit 1",
dbesc($f)
);
- if ($x && $txt = prepare_text(App::$profile[$f]))
+ if ($x && $txt = prepare_text(App::$profile[$f])) {
$profile[$f] = array($x[0]['field_desc'] . ':', $txt);
+ }
}
$profile['extra_fields'] = App::$profile['extra_fields'];
}
@@ -575,9 +648,9 @@ class Libprofile
$things = get_things(App::$profile['profile_guid'], App::$profile['profile_uid']);
- // logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA);
+ // logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA);
- // $exportlink = ((App::$profile['profile_vcard']) ? zid(z_root() . '/profile/' . App::$profile['channel_address'] . '/vcard') : '');
+ // $exportlink = ((App::$profile['profile_vcard']) ? zid(z_root() . '/profile/' . App::$profile['channel_address'] . '/vcard') : '');
return replace_macros($tpl, array(
'$title' => t('Profile'),
@@ -594,6 +667,4 @@ class Libprofile
return '';
}
-
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php
index 5a1efe312..2611364f4 100644
--- a/Zotlabs/Lib/Libsync.php
+++ b/Zotlabs/Lib/Libsync.php
@@ -56,7 +56,8 @@ class Libsync
unset($channel['channel_password']);
unset($channel['channel_salt']);
- $h = q("select hubloc.*, site.site_crypto from hubloc left join site on site_url = hubloc_url
+ $h = q(
+ "select hubloc.*, site.site_crypto from hubloc left join site on site_url = hubloc_url
where hubloc_hash = '%s' and hubloc_network = 'zot6' and hubloc_deleted = 0",
dbesc(($keychange) ? $packet['keychange']['old_hash'] : $channel['channel_hash'])
);
@@ -72,7 +73,8 @@ class Libsync
continue;
}
- $y = q("select site_dead from site where site_url = '%s' limit 1",
+ $y = q(
+ "select site_dead from site where site_url = '%s' limit 1",
dbesc($x['hubloc_url'])
);
@@ -106,7 +108,6 @@ class Libsync
if ($channel) {
$info['channel'] = [];
foreach ($channel as $k => $v) {
-
// filter out any joined tables like xchan
if (strpos($k, 'channel_') !== 0) {
@@ -132,14 +133,16 @@ class Libsync
}
if ($groups_changed) {
- $r = q("select hash as collection, visible, deleted, rule, gname as name from pgrp where uid = %d ",
+ $r = q(
+ "select hash as collection, visible, deleted, rule, gname as name from pgrp where uid = %d ",
intval($uid)
);
if ($r) {
$info['collections'] = $r;
}
- $r = q("select pgrp.hash as collection, pgrp_member.xchan as member from pgrp left join pgrp_member on pgrp.id = pgrp_member.gid
+ $r = q(
+ "select pgrp.hash as collection, pgrp_member.xchan as member from pgrp left join pgrp_member on pgrp.id = pgrp_member.gid
where pgrp_member.uid = %d ",
intval($uid)
);
@@ -203,7 +206,8 @@ class Libsync
return;
}
- $l = q("select link from linkid where ident = '%s' and sigtype = 2",
+ $l = q(
+ "select link from linkid where ident = '%s' and sigtype = 2",
dbesc($channel['channel_hash'])
);
@@ -227,7 +231,8 @@ class Libsync
continue;
}
- $y = q("select site_dead from site where site_url = '%s' limit 1",
+ $y = q(
+ "select site_dead from site where site_url = '%s' limit 1",
dbesc($x['hubloc_url'])
);
@@ -296,19 +301,22 @@ class Libsync
foreach ($deliveries as $d) {
$linked_channel = false;
- $r = q("select * from channel where channel_hash = '%s' limit 1",
+ $r = q(
+ "select * from channel where channel_hash = '%s' limit 1",
dbesc($sender)
);
$DR = new DReport(z_root(), $sender, $d, 'sync');
if (!$r) {
- $l = q("select ident from linkid where link = '%s' and sigtype = 2 limit 1",
+ $l = q(
+ "select ident from linkid where link = '%s' and sigtype = 2 limit 1",
dbesc($sender)
);
if ($l) {
$linked_channel = true;
- $r = q("select * from channel where channel_hash = '%s' limit 1",
+ $r = q(
+ "select * from channel where channel_hash = '%s' limit 1",
dbesc($l[0]['ident'])
);
}
@@ -342,7 +350,8 @@ class Libsync
// if the clone is active, so are we
if (substr($channel['channel_active'], 0, 10) !== substr(datetime_convert(), 0, 10)) {
- q("UPDATE channel set channel_active = '%s' where channel_id = %d",
+ q(
+ "UPDATE channel set channel_active = '%s' where channel_id = %d",
dbesc(datetime_convert()),
intval($channel['channel_id'])
);
@@ -421,19 +430,16 @@ class Libsync
}
if (array_key_exists('channel', $arr) && is_array($arr['channel']) && count($arr['channel'])) {
-
$remote_channel = $arr['channel'];
$remote_channel['channel_id'] = $channel['channel_id'];
if (array_key_exists('channel_pageflags', $arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
-
// Several pageflags are site-specific and cannot be sync'd.
// Only allow those bits which are shareable from the remote and then
// logically OR with the local flags
$arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] & (PAGE_HIDDEN | PAGE_AUTOCONNECT | PAGE_APPLICATION | PAGE_PREMIUM | PAGE_ADULT);
$arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] | $channel['channel_pageflags'];
-
}
$columns = db_columns('channel');
@@ -461,11 +467,11 @@ class Libsync
}
if (array_key_exists('abook', $arr) && is_array($arr['abook']) && count($arr['abook'])) {
-
$total_friends = 0;
$total_feeds = 0;
- $r = q("select abook_id, abook_feed from abook where abook_channel = %d",
+ $r = q(
+ "select abook_id, abook_feed from abook where abook_channel = %d",
intval($channel['channel_id'])
);
if ($r) {
@@ -484,7 +490,6 @@ class Libsync
$fields = db_columns('abook');
foreach ($arr['abook'] as $abook) {
-
// this is here for debugging so we can find the issue source
if (!is_array($abook)) {
@@ -503,7 +508,8 @@ class Libsync
if ($abook['abook_xchan'] && $abook['entry_deleted']) {
logger('Removing abook entry for ' . $abook['abook_xchan']);
- $r = q("select abook_id, abook_feed from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
+ $r = q(
+ "select abook_id, abook_feed from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
dbesc($abook['abook_xchan']),
intval($channel['channel_id'])
);
@@ -546,7 +552,8 @@ class Libsync
$xc[$k] = $v;
}
}
- $r = q("select * from xchan where xchan_hash = '%s'",
+ $r = q(
+ "select * from xchan where xchan_hash = '%s'",
dbesc($xc['xchan_hash'])
);
if (!$r) {
@@ -584,7 +591,8 @@ class Libsync
}
}
- $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
+ $r = q(
+ "select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($clean['abook_xchan']),
intval($channel['channel_id'])
);
@@ -621,7 +629,6 @@ class Libsync
$r = dbq("UPDATE abook set " . dbesc($k) . " = '" . dbesc($v)
. "' where abook_xchan = '" . dbesc($clean['abook_xchan']) . "' and abook_channel = " . intval($channel['channel_id']));
-
}
}
@@ -646,7 +653,8 @@ class Libsync
// sync collections (privacy groups) oh joy...
if (array_key_exists('collections', $arr) && is_array($arr['collections']) && count($arr['collections'])) {
- $x = q("select * from pgrp where uid = %d ",
+ $x = q(
+ "select * from pgrp where uid = %d ",
intval($channel['channel_id'])
);
foreach ($arr['collections'] as $cl) {
@@ -659,10 +667,13 @@ class Libsync
}
}
if ($found) {
- if (($y['gname'] != $cl['name'])
+ if (
+ ($y['gname'] != $cl['name'])
|| ($y['visible'] != $cl['visible'])
- || ($y['deleted'] != $cl['deleted'])) {
- q("update pgrp set gname = '%s', visible = %d, deleted = %d where hash = '%s' and uid = %d",
+ || ($y['deleted'] != $cl['deleted'])
+ ) {
+ q(
+ "update pgrp set gname = '%s', visible = %d, deleted = %d where hash = '%s' and uid = %d",
dbesc($cl['name']),
intval($cl['visible']),
intval($cl['deleted']),
@@ -671,14 +682,16 @@ class Libsync
);
}
if (intval($cl['deleted']) && (!intval($y['deleted']))) {
- q("delete from pgrp_member where gid = %d",
+ q(
+ "delete from pgrp_member where gid = %d",
intval($y['id'])
);
}
}
}
if (!$found) {
- $r = q("INSERT INTO pgrp ( hash, uid, visible, deleted, gname, rule )
+ $r = q(
+ "INSERT INTO pgrp ( hash, uid, visible, deleted, gname, rule )
VALUES( '%s', %d, %d, %d, '%s', '%s' ) ",
dbesc($cl['collection']),
intval($channel['channel_id']),
@@ -703,10 +716,12 @@ class Libsync
}
}
if (!$found_local) {
- q("delete from pgrp_member where gid = %d",
+ q(
+ "delete from pgrp_member where gid = %d",
intval($y['id'])
);
- q("update pgrp set deleted = 1 where id = %d and uid = %d",
+ q(
+ "update pgrp set deleted = 1 where id = %d and uid = %d",
intval($y['id']),
intval($channel['channel_id'])
);
@@ -716,16 +731,18 @@ class Libsync
}
// reload the group list with any updates
- $x = q("select * from pgrp where uid = %d",
+ $x = q(
+ "select * from pgrp where uid = %d",
intval($channel['channel_id'])
);
// now sync the members
- if (array_key_exists('collection_members', $arr)
+ if (
+ array_key_exists('collection_members', $arr)
&& is_array($arr['collection_members'])
- && count($arr['collection_members'])) {
-
+ && count($arr['collection_members'])
+ ) {
// first sort into groups keyed by the group hash
$members = [];
foreach ($arr['collection_members'] as $cm) {
@@ -739,12 +756,12 @@ class Libsync
// our group list is already synchronised
if ($x) {
foreach ($x as $y) {
-
// for each group, loop on members list we just received
if (isset($y['hash']) && isset($members[$y['hash']])) {
foreach ($members[$y['hash']] as $member) {
$found = false;
- $z = q("select xchan from pgrp_member where gid = %d and uid = %d and xchan = '%s' limit 1",
+ $z = q(
+ "select xchan from pgrp_member where gid = %d and uid = %d and xchan = '%s' limit 1",
intval($y['id']),
intval($channel['channel_id']),
dbesc($member)
@@ -756,7 +773,8 @@ class Libsync
// if somebody is in the group that wasn't before - add them
if (!$found) {
- q("INSERT INTO pgrp_member (uid, gid, xchan)
+ q(
+ "INSERT INTO pgrp_member (uid, gid, xchan)
VALUES( %d, %d, '%s' ) ",
intval($channel['channel_id']),
intval($y['id']),
@@ -767,7 +785,8 @@ class Libsync
}
// now retrieve a list of members we have on this site
- $m = q("select xchan from pgrp_member where gid = %d and uid = %d",
+ $m = q(
+ "select xchan from pgrp_member where gid = %d and uid = %d",
intval($y['id']),
intval($channel['channel_id'])
);
@@ -775,7 +794,8 @@ class Libsync
foreach ($m as $mm) {
// if the local existing member isn't in the list we just received - remove them
if (!in_array($mm['xchan'], $members[$y['hash']])) {
- q("delete from pgrp_member where xchan = '%s' and gid = %d and uid = %d",
+ q(
+ "delete from pgrp_member where xchan = '%s' and gid = %d and uid = %d",
dbesc($mm['xchan']),
intval($y['id']),
intval($channel['channel_id'])
@@ -789,12 +809,11 @@ class Libsync
}
if (array_key_exists('profile', $arr) && is_array($arr['profile']) && count($arr['profile'])) {
-
$disallowed = array('id', 'aid', 'uid', 'guid');
foreach ($arr['profile'] as $profile) {
-
- $x = q("select * from profile where profile_guid = '%s' and uid = %d limit 1",
+ $x = q(
+ "select * from profile where profile_guid = '%s' and uid = %d limit 1",
dbesc($profile['profile_guid']),
intval($channel['channel_id'])
);
@@ -807,7 +826,8 @@ class Libsync
]
);
- $x = q("select * from profile where profile_guid = '%s' and uid = %d limit 1",
+ $x = q(
+ "select * from profile where profile_guid = '%s' and uid = %d limit 1",
dbesc($profile['profile_guid']),
intval($channel['channel_id'])
);
@@ -897,7 +917,8 @@ class Libsync
// If a sender reports that the channel has been deleted, delete its hubloc
if (isset($arr['deleted_locally']) && intval($arr['deleted_locally'])) {
- q("UPDATE hubloc SET hubloc_deleted = 1, hubloc_updated = '%s' WHERE hubloc_hash = '%s' AND hubloc_url = '%s'",
+ q(
+ "UPDATE hubloc SET hubloc_deleted = 1, hubloc_updated = '%s' WHERE hubloc_hash = '%s' AND hubloc_url = '%s'",
dbesc(datetime_convert()),
dbesc($sender['hash']),
dbesc($sender['site']['url'])
@@ -905,8 +926,8 @@ class Libsync
}
if ($arr['locations']) {
-
- $x = q("select * from xchan where xchan_hash = '%s'",
+ $x = q(
+ "select * from xchan where xchan_hash = '%s'",
dbesc($sender['hash'])
);
if ($x) {
@@ -917,7 +938,8 @@ class Libsync
Libzot::check_location_move($sender['hash'], $arr['locations']);
}
- $xisting = q("select * from hubloc where hubloc_hash = '%s'",
+ $xisting = q(
+ "select * from hubloc where hubloc_hash = '%s'",
dbesc($sender['hash'])
);
@@ -937,8 +959,9 @@ class Libsync
// Ensure that they have one primary hub
- if (!$has_primary)
+ if (!$has_primary) {
$arr['locations'][0]['primary'] = true;
+ }
foreach ($arr['locations'] as $location) {
if (!Libzot::verify($location['url'], $location['url_sig'], $sender['public_key'])) {
@@ -948,8 +971,10 @@ class Libsync
}
for ($x = 0; $x < count($xisting); $x++) {
- if (($xisting[$x]['hubloc_url'] === $location['url'])
- && ($xisting[$x]['hubloc_sitekey'] === $location['sitekey'])) {
+ if (
+ ($xisting[$x]['hubloc_url'] === $location['url'])
+ && ($xisting[$x]['hubloc_sitekey'] === $location['sitekey'])
+ ) {
$xisting[$x]['updated'] = true;
}
}
@@ -961,7 +986,8 @@ class Libsync
// match as many fields as possible in case anything at all changed.
- $r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
+ $r = q(
+ "select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
dbesc($sender['hash']),
dbesc($sender['id']),
dbesc($sender['id_sig']),
@@ -979,7 +1005,8 @@ class Libsync
// generate a new hubloc_site_id if it's wrong due to historical bugs 2021-11-30
if ($r[0]['hubloc_site_id'] !== $location['site_id']) {
- q("update hubloc set hubloc_site_id = '%s' where hubloc_id = %d",
+ q(
+ "update hubloc set hubloc_site_id = '%s' where hubloc_id = %d",
dbesc(Libzot::make_xchan_hash($location['url'], $location['sitekey'])),
intval($r[0]['hubloc_id'])
);
@@ -993,7 +1020,8 @@ class Libsync
$t = datetime_convert('UTC', 'UTC', 'now - 15 minutes');
if (array_key_exists('site', $arr) && $location['url'] == $arr['site']['url']) {
- q("update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d and hubloc_updated < '%s'",
+ q(
+ "update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d and hubloc_updated < '%s'",
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($r[0]['hubloc_id']),
@@ -1003,15 +1031,18 @@ class Libsync
}
if ($current_site && (intval($r[0]['hubloc_error']) || intval($r[0]['hubloc_deleted']))) {
- q("update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d",
+ q(
+ "update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d",
intval($r[0]['hubloc_id'])
);
if (intval($r[0]['hubloc_orphancheck'])) {
- q("update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d",
+ q(
+ "update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d",
intval($r[0]['hubloc_id'])
);
}
- q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'",
+ q(
+ "update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'",
dbesc($sender['hash'])
);
}
@@ -1019,7 +1050,8 @@ class Libsync
// Remove pure duplicates
if (count($r) > 1) {
for ($h = 1; $h < count($r); $h++) {
- q("delete from hubloc where hubloc_id = %d",
+ q(
+ "delete from hubloc where hubloc_id = %d",
intval($r[$h]['hubloc_id'])
);
$what .= 'duplicate_hubloc_removed ';
@@ -1028,7 +1060,8 @@ class Libsync
}
if (intval($r[0]['hubloc_primary']) && (!$location['primary'])) {
- $m = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id = %d",
+ $m = q(
+ "update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id = %d",
dbesc(datetime_convert()),
intval($r[0]['hubloc_id'])
);
@@ -1037,7 +1070,8 @@ class Libsync
$what .= 'primary_hub ';
$changed = true;
} elseif ((!intval($r[0]['hubloc_primary'])) && ($location['primary'])) {
- $m = q("update hubloc set hubloc_primary = 1, hubloc_updated = '%s' where hubloc_id = %d",
+ $m = q(
+ "update hubloc set hubloc_primary = 1, hubloc_updated = '%s' where hubloc_id = %d",
dbesc(datetime_convert()),
intval($r[0]['hubloc_id'])
);
@@ -1062,7 +1096,8 @@ class Libsync
}
if (intval($r[0]['hubloc_deleted']) && (!intval($location['deleted']))) {
- $n = q("update hubloc set hubloc_deleted = 0, hubloc_updated = '%s' where hubloc_id = %d",
+ $n = q(
+ "update hubloc set hubloc_deleted = 0, hubloc_updated = '%s' where hubloc_id = %d",
dbesc(datetime_convert()),
intval($r[0]['hubloc_id'])
);
@@ -1070,7 +1105,8 @@ class Libsync
$changed = true;
} elseif ((!intval($r[0]['hubloc_deleted'])) && (intval($location['deleted']))) {
logger('deleting hubloc: ' . $r[0]['hubloc_addr']);
- $n = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
+ $n = q(
+ "update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
dbesc(datetime_convert()),
intval($r[0]['hubloc_id'])
);
@@ -1084,7 +1120,8 @@ class Libsync
// New hub claiming to be primary. Make it so by removing any existing primaries.
if (intval($location['primary'])) {
- $r = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_hash = '%s' and hubloc_primary = 1",
+ $r = q(
+ "update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_hash = '%s' and hubloc_primary = 1",
dbesc(datetime_convert()),
dbesc($sender['hash'])
);
@@ -1116,12 +1153,14 @@ class Libsync
$changed = true;
if ($location['primary']) {
- $r = q("select * from hubloc where hubloc_addr = '%s' and hubloc_sitekey = '%s' limit 1",
+ $r = q(
+ "select * from hubloc where hubloc_addr = '%s' and hubloc_sitekey = '%s' limit 1",
dbesc($location['address']),
dbesc($location['sitekey'])
);
- if ($r)
+ if ($r) {
hubloc_change_primary($r[0]);
+ }
}
}
@@ -1131,7 +1170,8 @@ class Libsync
foreach ($xisting as $x) {
if (!array_key_exists('updated', $x)) {
logger('Deleting unreferenced hub location ' . $x['hubloc_addr']);
- $r = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
+ $r = q(
+ "update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d",
dbesc(datetime_convert()),
intval($x['hubloc_id'])
);
@@ -1164,7 +1204,8 @@ class Libsync
$hash = Libzot::make_xchan_hash($channel['channel_guid'], $arr['channel']['channel_pubkey']);
- $r = q("update channel set channel_prvkey = '%s', channel_pubkey = '%s', channel_guid_sig = '%s',
+ $r = q(
+ "update channel set channel_prvkey = '%s', channel_pubkey = '%s', channel_guid_sig = '%s',
channel_hash = '%s' where channel_id = %d",
dbesc($arr['channel']['channel_prvkey']),
dbesc($arr['channel']['channel_pubkey']),
@@ -1177,7 +1218,8 @@ class Libsync
return;
}
- $r = q("select * from channel where channel_id = %d",
+ $r = q(
+ "select * from channel where channel_id = %d",
intval($channel['channel_id'])
);
@@ -1188,7 +1230,8 @@ class Libsync
$channel = $r[0];
- $h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
+ $h = q(
+ "select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
dbesc($arr['keychange']['old_hash']),
dbesc(z_root())
);
@@ -1202,11 +1245,13 @@ class Libsync
}
}
- $x = q("select * from xchan where xchan_hash = '%s' ",
+ $x = q(
+ "select * from xchan where xchan_hash = '%s' ",
dbesc($arr['keychange']['old_hash'])
);
- $check = q("select * from xchan where xchan_hash = '%s'",
+ $check = q(
+ "select * from xchan where xchan_hash = '%s'",
dbesc($hash)
);
@@ -1222,19 +1267,19 @@ class Libsync
}
}
- $a = q("select * from abook where abook_xchan = '%s' and abook_self = 1",
+ $a = q(
+ "select * from abook where abook_xchan = '%s' and abook_self = 1",
dbesc($arr['keychange']['old_hash'])
);
if ($a) {
- q("update abook set abook_xchan = '%s' where abook_id = %d",
+ q(
+ "update abook set abook_xchan = '%s' where abook_id = %d",
dbesc($hash),
intval($a[0]['abook_id'])
);
}
xchan_change_key($oldxchan, $newxchan, $arr['keychange']);
-
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php
index 630fd82a4..5d225bd59 100644
--- a/Zotlabs/Lib/Libzot.php
+++ b/Zotlabs/Lib/Libzot.php
@@ -82,7 +82,8 @@ class Libzot
/* Only search for active hublocs - e.g. those that haven't been marked deleted */
- $ret = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 order by hubloc_url ",
+ $ret = q(
+ "select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 order by hubloc_url ",
dbesc($hash)
);
@@ -234,8 +235,14 @@ class Libzot
'(request-target)' => 'post ' . get_request_string($url)
];
- $h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), false, 'sha512',
- (($crypto) ? ['key' => $crypto['hubloc_sitekey'], 'algorithm' => self::best_algorithm($crypto['site_crypto'])] : false));
+ $h = HTTPSig::create_sig(
+ $headers,
+ $channel['channel_prvkey'],
+ channel_url($channel),
+ false,
+ 'sha512',
+ (($crypto) ? ['key' => $crypto['hubloc_sitekey'], 'algorithm' => self::best_algorithm($crypto['site_crypto'])] : false)
+ );
} else {
$h = [];
}
@@ -299,7 +306,8 @@ class Libzot
// We are looking for the most recently created primary hub, and the most recently created if for some reason we do not have a primary.
// hubloc_id_url is set to the channel home, which corresponds to an ActivityStreams actor id.
- $r = q("select hubloc_id_url, hubloc_primary from hubloc where hubloc_hash = '%s' and hubloc_network = 'zot6' order by hubloc_id desc",
+ $r = q(
+ "select hubloc_id_url, hubloc_primary from hubloc where hubloc_hash = '%s' and hubloc_network = 'zot6' order by hubloc_id desc",
dbesc($them['xchan_hash'])
);
@@ -325,7 +333,8 @@ class Libzot
$site_url = unparse_url(['scheme' => $m['scheme'], 'host' => $m['host']]);
- $s = q("select site_dead from site where site_url = '%s' limit 1",
+ $s = q(
+ "select site_dead from site where site_url = '%s' limit 1",
dbesc($site_url)
);
@@ -377,23 +386,25 @@ class Libzot
// Keep original perms to check if we need to notify them
$previous_perms = get_all_perms($channel['channel_id'], $x['hash']);
- $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
+ $r = q(
+ "select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
dbesc($x['hash']),
intval($channel['channel_id'])
);
if ($r) {
-
// connection exists
// if the dob is the same as what we have stored (disregarding the year), keep the one
// we have as we may have updated the year after sending a notification; and resetting
// to the one we just received would cause us to create duplicated events.
- if (substr($r[0]['abook_dob'], 5) == substr($next_birthday, 5))
+ if (substr($r[0]['abook_dob'], 5) == substr($next_birthday, 5)) {
$next_birthday = $r[0]['abook_dob'];
+ }
- $y = q("update abook set abook_dob = '%s'
+ $y = q(
+ "update abook set abook_dob = '%s'
where abook_xchan = '%s' and abook_channel = %d
and abook_self = 0 ",
dbescdate($next_birthday),
@@ -405,15 +416,16 @@ class Libzot
logger('abook update failed');
} else {
// if we were just granted read stream permission and didn't have it before, try to pull in some posts
- if ((!$old_read_stream_perm) && (intval($permissions['view_stream'])))
+ if ((!$old_read_stream_perm) && (intval($permissions['view_stream']))) {
Run::Summon(['Onepoll', $r[0]['abook_id']]);
+ }
}
} else {
-
// limit the ability to do connection spamming, this limit is per channel
$lim = intval(get_config('system', 'max_connections_per_day', 50));
if ($lim) {
- $n = q("select count(abook_id) as total from abook where abook_channel = %d and abook_created > '%s'",
+ $n = q(
+ "select count(abook_id) as total from abook where abook_channel = %d and abook_created > '%s'",
intval($channel['channel_id']),
dbesc(datetime_convert('UTC', 'UTC', 'now - 24 hours'))
);
@@ -456,7 +468,8 @@ class Libzot
$is_collection = false;
- $cl = q("select channel_id from channel where channel_hash = '%s' and channel_parent = '%s' and channel_account_id = %d limit 1",
+ $cl = q(
+ "select channel_id from channel where channel_hash = '%s' and channel_parent = '%s' and channel_account_id = %d limit 1",
dbesc($x['hash']),
dbesc($channel['channel_hash']),
intval($channel['channel_account_id'])
@@ -487,7 +500,8 @@ class Libzot
// Send a clone sync packet and a permissions update if permissions have changed
- $new_connection = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 order by abook_created desc limit 1",
+ $new_connection = q(
+ "select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 order by abook_created desc limit 1",
dbesc($x['hash']),
intval($channel['channel_id'])
);
@@ -509,9 +523,12 @@ class Libzot
}
if (intval($permissions['view_stream'])) {
- if (intval(get_pconfig($channel['channel_id'], 'perm_limits', 'send_stream') & PERMS_PENDING)
- || (!intval($new_connection[0]['abook_pending'])))
+ if (
+ intval(get_pconfig($channel['channel_id'], 'perm_limits', 'send_stream') & PERMS_PENDING)
+ || (!intval($new_connection[0]['abook_pending']))
+ ) {
Run::Summon(['Onepoll', $new_connection[0]['abook_id']]);
+ }
}
@@ -538,7 +555,6 @@ class Libzot
Libsync::build_sync_packet($channel['channel_id'], ['abook' => $new_connection]);
}
}
-
}
return true;
} else {
@@ -560,7 +576,7 @@ class Libzot
* * \e string \b id_sig => id signed with conversant's private key
* * \e string \b location => URL of the origination hub of this communication
* * \e string \b location_sig => URL signed with conversant's private key
- * @param boolean $multiple (optional) default false
+ * @param bool $multiple (optional) default false
*
* @return array|null
* * null if site is denied or not found
@@ -571,7 +587,6 @@ class Libzot
{
if ($arr['id'] && $arr['id_sig'] && $arr['location'] && $arr['location_sig']) {
-
if (!check_siteallowed($arr['location'])) {
logger('denied site: ' . $arr['location']);
return null;
@@ -579,7 +594,8 @@ class Libzot
$limit = (($multiple) ? '' : ' limit 1 ');
- $r = q("select hubloc.*, site.site_crypto from hubloc left join site on hubloc_url = site_url
+ $r = q(
+ "select hubloc.*, site.site_crypto from hubloc left join site on hubloc_url = site_url
where hubloc_guid = '%s' and hubloc_guid_sig = '%s'
and hubloc_url = '%s' and hubloc_url_sig = '%s'
and hubloc_site_id = '%s' and hubloc_network = 'zot6'
@@ -604,7 +620,8 @@ class Libzot
public static function valid_hub($sender, $site_id)
{
- $r = q("select hubloc.*, site.site_crypto from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_site_id = '%s' limit 1",
+ $r = q(
+ "select hubloc.*, site.site_crypto from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_site_id = '%s' limit 1",
dbesc($sender),
dbesc($site_id)
);
@@ -747,7 +764,8 @@ class Libzot
logger('import_xchan: ' . $xchan_hash, LOGGER_DEBUG);
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
+ $r = q(
+ "select * from xchan where xchan_hash = '%s' limit 1",
dbesc($xchan_hash)
);
@@ -829,15 +847,18 @@ class Libzot
}
- if (($r[0]['xchan_name_date'] != $arr['name_updated'])
+ if (
+ ($r[0]['xchan_name_date'] != $arr['name_updated'])
|| ($r[0]['xchan_connurl'] != $arr['primary_location']['connections_url'])
|| ($r[0]['xchan_addr'] != $arr['primary_location']['address'])
|| ($r[0]['xchan_follow'] != $arr['primary_location']['follow_url'])
|| ($r[0]['xchan_connpage'] != $arr['connect_url'])
|| ($r[0]['xchan_url'] != $arr['primary_location']['url'])
|| ($r[0]['xchan_updated'] < datetime_convert('UTC', 'UTC', 'now - 7 days'))
- || $hidden_changed || $adult_changed || $deleted_changed || $type_changed) {
- $rup = q("update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_name_date = '%s', xchan_connurl = '%s', xchan_follow = '%s',
+ || $hidden_changed || $adult_changed || $deleted_changed || $type_changed
+ ) {
+ $rup = q(
+ "update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_name_date = '%s', xchan_connurl = '%s', xchan_follow = '%s',
xchan_connpage = '%s', xchan_hidden = %d, xchan_selfcensored = %d, xchan_deleted = %d, xchan_type = %d,
xchan_addr = '%s', xchan_url = '%s' where xchan_hash = '%s'",
dbesc(datetime_convert()),
@@ -863,9 +884,11 @@ class Libzot
} else {
$import_photos = true;
- if ((($arr['site']['directory_mode'] === 'standalone')
+ if (
+ (($arr['site']['directory_mode'] === 'standalone')
|| ($dirmode & DIRECTORY_MODE_STANDALONE))
- && ($arr['site']['url'] != z_root())) {
+ && ($arr['site']['url'] != z_root())
+ ) {
$arr['searchable'] = false;
}
@@ -916,12 +939,12 @@ class Libzot
}
if ($import_photos) {
-
require_once('include/photo_factory.php');
// see if this is a channel clone that's hosted locally - which we treat different from other xchans/connections
- $local = q("select channel_account_id, channel_id from channel where channel_hash = '%s' limit 1",
+ $local = q(
+ "select channel_account_id, channel_id from channel where channel_hash = '%s' limit 1",
dbesc($xchan_hash)
);
if ($local) {
@@ -936,7 +959,8 @@ class Libzot
// unless proven otherwise
$is_default_profile = 1;
- $profile = q("select is_default from profile where aid = %d and uid = %d limit 1",
+ $profile = q(
+ "select is_default from profile where aid = %d and uid = %d limit 1",
intval($local[0]['channel_account_id']),
intval($local[0]['channel_id'])
);
@@ -948,7 +972,8 @@ class Libzot
// If setting for the default profile, unset the profile photo flag from any other photos I own
if ($is_default_profile) {
- q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND aid = %d AND uid = %d",
+ q(
+ "UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND aid = %d AND uid = %d",
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
dbesc($hash),
@@ -974,7 +999,8 @@ class Libzot
if ($photos[4]) {
// importing the photo failed somehow. Leave the photo_date alone so we can try again at a later date.
// This often happens when somebody joins the matrix with a bad cert.
- $r = q("update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
+ $r = q(
+ "update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
where xchan_hash = '%s'",
dbesc(datetime_convert()),
dbesc($photos[0]),
@@ -984,7 +1010,8 @@ class Libzot
dbesc($xchan_hash)
);
} else {
- $r = q("update xchan set xchan_updated = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
+ $r = q(
+ "update xchan set xchan_updated = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
where xchan_hash = '%s'",
dbesc(datetime_convert()),
dbesc(datetime_convert('UTC', 'UTC', ((isset($arr['photo_updated'])) ? $arr['photo_updated'] : 'now'))),
@@ -1027,14 +1054,14 @@ class Libzot
$other_realm = false;
-// $realm = get_directory_realm();
-// if (array_key_exists('site',$arr)
-// && array_key_exists('realm',$arr['site'])
-// && (strpos($arr['site']['realm'],$realm) === false))
-// $other_realm = true;
+// $realm = get_directory_realm();
+// if (array_key_exists('site',$arr)
+// && array_key_exists('realm',$arr['site'])
+// && (strpos($arr['site']['realm'],$realm) === false))
+// $other_realm = true;
-// if ($dirmode != DIRECTORY_MODE_NORMAL) {
+// if ($dirmode != DIRECTORY_MODE_NORMAL) {
// We're some kind of directory server. However we can only add directory information
// if the entry is in the same realm (or is a sub-realm). Sub-realms are denoted by
@@ -1050,14 +1077,16 @@ class Libzot
} else {
logger('Profile not available - hiding');
// they may have made it private
- $r = q("delete from xprof where xprof_hash = '%s'",
+ $r = q(
+ "delete from xprof where xprof_hash = '%s'",
dbesc($xchan_hash)
);
- $r = q("delete from xtag where xtag_hash = '%s' and xtag_flags = 0",
+ $r = q(
+ "delete from xtag where xtag_hash = '%s' and xtag_flags = 0",
dbesc($xchan_hash)
);
}
-// }
+// }
if (array_key_exists('site', $arr) && is_array($arr['site'])) {
$profile_changed = self::import_site($arr['site']);
@@ -1073,7 +1102,8 @@ class Libzot
logger('Changed: ' . $what, LOGGER_DEBUG);
} elseif (!$ud_flags) {
// nothing changed but we still need to update the updates record
- q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not (ud_flags & %d) > 0 ",
+ q(
+ "update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not (ud_flags & %d) > 0 ",
intval(UPDATE_FLAGS_UPDATED),
dbesc($address),
intval(UPDATE_FLAGS_UPDATED)
@@ -1128,10 +1158,10 @@ class Libzot
if ($x) {
if (!$x['success']) {
-
// handle remote validation issues
- $b = q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
+ $b = q(
+ "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
dbesc(($x['message']) ? $x['message'] : 'unknown delivery error'),
dbesc(datetime_convert()),
dbesc($outq['outq_hash'])
@@ -1142,7 +1172,8 @@ class Libzot
foreach ($x['delivery_report'] as $xx) {
call_hooks('dreport_process', $xx);
if (is_array($xx) && array_key_exists('message_id', $xx) && DReport::is_storable($xx)) {
- q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan, dreport_log ) values ( '%s', '%s', '%s','%s','%s','%s','%s','%s' ) ",
+ q(
+ "insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan, dreport_log ) values ( '%s', '%s', '%s','%s','%s','%s','%s','%s' ) ",
dbesc($xx['message_id']),
dbesc($xx['location']),
dbesc($xx['recipient']),
@@ -1157,14 +1188,16 @@ class Libzot
// we have a more descriptive delivery report, so discard the per hub 'queue' report.
- q("delete from dreport where dreport_queue = '%s' ",
+ q(
+ "delete from dreport where dreport_queue = '%s' ",
dbesc($outq['outq_hash'])
);
}
}
// update the timestamp for this site
- q("update site set site_dead = 0, site_update = '%s' where site_url = '%s'",
+ q(
+ "update site set site_dead = 0, site_update = '%s' where site_url = '%s'",
dbesc(datetime_convert()),
dbesc(dirname($hub))
);
@@ -1207,7 +1240,6 @@ class Libzot
logger('zot_fetch: ' . print_r($arr, true), LOGGER_DATA, LOG_DEBUG);
return self::import($arr, $hub);
-
}
/**
@@ -1256,10 +1288,11 @@ class Libzot
$AS = null;
if ($env['encoding'] === 'activitystreams') {
-
$AS = new ActivityStreams($data);
- if ($AS->is_valid() && $AS->type === 'Announce' && is_array($AS->obj)
- && array_key_exists('object', $AS->obj) && array_key_exists('actor', $AS->obj)) {
+ if (
+ $AS->is_valid() && $AS->type === 'Announce' && is_array($AS->obj)
+ && array_key_exists('object', $AS->obj) && array_key_exists('actor', $AS->obj)
+ ) {
// This is a relayed/forwarded Activity (as opposed to a shared/boosted object)
// Reparse the encapsulated Activity and use that instead
logger('relayed activity', LOGGER_DEBUG);
@@ -1305,7 +1338,6 @@ class Libzot
logger('activity rejected: create actor');
return;
}
-
}
$deliveries = null;
@@ -1341,7 +1373,6 @@ class Libzot
// We found somebody on this site that's in the recipient list.
} else {
-
logger('public post');
@@ -1360,15 +1391,14 @@ class Libzot
}
if ($has_data) {
-
if (in_array($env['type'], ['activity', 'response'])) {
-
if (!(is_array($AS->actor) && isset($AS->actor['id']))) {
logger('No author!');
return;
}
- $r = q("select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_id_url = '%s'",
+ $r = q(
+ "select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_id_url = '%s'",
dbesc($AS->actor['id'])
);
@@ -1382,7 +1412,8 @@ class Libzot
return;
}
- $s = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1",
+ $s = q(
+ "select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1",
dbesc($env['sender'])
);
@@ -1422,7 +1453,8 @@ class Libzot
if (!array_key_exists('comment_policy', $arr)) {
// set comment policy depending on source hub. Unknown or osada is ActivityPub.
// Anything else we'll say is zot - which could have a range of project names
- $s = q("select site_project from site where site_url = '%s' limit 1",
+ $s = q(
+ "select site_project from site where site_url = '%s' limit 1",
dbesc($r[0]['hubloc_url'])
);
@@ -1448,7 +1480,6 @@ class Libzot
$result = self::process_delivery($env['sender'], $AS, $arr, $deliveries, $relay, false, $message_request);
} elseif ($env['type'] === 'sync') {
-
$arr = json_decode($data, true);
logger('Channel sync received: ' . print_r($arr, true), LOGGER_DATA, LOG_DEBUG);
@@ -1544,7 +1575,6 @@ class Libzot
if ($c) {
foreach ($c as $cc) {
-
// top level activity sent to ourself: ignore. Clones will get a sync activity
// which is a true clone of the original item. Everything else is a duplicate.
@@ -1568,7 +1598,8 @@ class Libzot
// add channels that are following tags
// these will be enumerated and validated in tgroup_check()
- $ft = q("select channel_hash as hash from channel left join pconfig on pconfig.uid = channel_id where cat = 'system' and k = 'followed_tags' and channel_hash != '%s' and channel_removed = 0",
+ $ft = q(
+ "select channel_hash as hash from channel left join pconfig on pconfig.uid = channel_id where cat = 'system' and k = 'followed_tags' and channel_hash != '%s' and channel_removed = 0",
dbesc($msg['sender'])
);
if ($ft) {
@@ -1588,7 +1619,8 @@ class Libzot
if ($tag['type'] === 'Mention' && (strpos($tag['href'], z_root()) !== false)) {
$address = basename($tag['href']);
if ($address) {
- $z = q("select channel_hash as hash from channel where channel_address = '%s'
+ $z = q(
+ "select channel_hash as hash from channel where channel_address = '%s'
and channel_hash != '%s' and channel_removed = 0 limit 1",
dbesc($address),
dbesc($msg['sender'])
@@ -1601,7 +1633,8 @@ class Libzot
if ($tag['type'] === 'topicalCollection' && strpos($tag['name'], App::get_hostname())) {
$address = substr($tag['name'], 0, strpos($tag['name'], '@'));
if ($address) {
- $z = q("select channel_hash as hash from channel where channel_address = '%s'
+ $z = q(
+ "select channel_hash as hash from channel where channel_address = '%s'
and channel_hash != '%s' and channel_removed = 0 limit 1",
dbesc($address),
dbesc($msg['sender'])
@@ -1622,7 +1655,8 @@ class Libzot
$thread_parent = self::find_parent($msg, $act);
if ($thread_parent) {
- $z = q("select channel_hash as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) ",
+ $z = q(
+ "select channel_hash as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) ",
dbesc($thread_parent),
dbesc($thread_parent)
);
@@ -1652,9 +1686,9 @@ class Libzot
* @param ActivityStreams object $act
* @param array $msg_arr
* @param array $deliveries
- * @param boolean $relay
- * @param boolean $public (optional) default false
- * @param boolean $request (optional) default false
+ * @param bool $relay
+ * @param bool $public (optional) default false
+ * @param bool $request (optional) default false
* @return array
*/
@@ -1686,16 +1720,15 @@ class Libzot
}
foreach ($deliveries as $d) {
-
$local_public = $public;
// if any further changes are to be made, change a copy and not the original
$arr = $msg_arr;
-// if (! $msg_arr['mid']) {
-// logger('no mid2: ' . print_r($msg_arr,true));
-// logger('recip: ' . $d);
-// }
+// if (! $msg_arr['mid']) {
+// logger('no mid2: ' . print_r($msg_arr,true));
+// logger('recip: ' . $d);
+// }
$DR = new DReport(z_root(), $sender, $d, $arr['mid']);
@@ -1710,27 +1743,26 @@ class Libzot
$DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>');
-// if ($act->type === 'Tombstone') {
-// $r = q("select * from item where mid in ( '%s', '%s' ) and uid = %d",
-// dbesc($act->id),
-// dbesc(str_replace('/activity/','/item/',$act->id))
-// intval($channel['channel_id'])
-// );
-// if ($r) {
-// if (($r[0]['author_xchan'] === $sender) || ($r[0]['owner_xchan'] === $sender)) {
-// drop_item($r[0]['id'],false);
-// }
-// $DR->update('item deleted');
-// $result[] = $DR->get();
-// continue;
-// }
-// $DR->update('deleted item not found');
-// $result[] = $DR->get();
-// continue;
-// }
+// if ($act->type === 'Tombstone') {
+// $r = q("select * from item where mid in ( '%s', '%s' ) and uid = %d",
+// dbesc($act->id),
+// dbesc(str_replace('/activity/','/item/',$act->id))
+// intval($channel['channel_id'])
+// );
+// if ($r) {
+// if (($r[0]['author_xchan'] === $sender) || ($r[0]['owner_xchan'] === $sender)) {
+// drop_item($r[0]['id'],false);
+// }
+// $DR->update('item deleted');
+// $result[] = $DR->get();
+// continue;
+// }
+// $DR->update('deleted item not found');
+// $result[] = $DR->get();
+// continue;
+// }
if (($act) && ($act->obj) && (!is_array($act->obj))) {
-
// The initial object fetch failed using the sys channel credentials.
// Try again using the delivery channel credentials.
// We will also need to re-parse the $item array,
@@ -1777,7 +1809,8 @@ class Libzot
// don't allow pubstream posts if the sender even has a clone on a pubstream denied site
$siteallowed = true;
- $h = q("select hubloc_url from hubloc where hubloc_hash = '%s'",
+ $h = q(
+ "select hubloc_url from hubloc where hubloc_hash = '%s'",
dbesc($sender)
);
if ($h) {
@@ -1793,7 +1826,8 @@ class Libzot
continue;
}
- $r = q("select xchan_selfcensored from xchan where xchan_hash = '%s' limit 1",
+ $r = q(
+ "select xchan_selfcensored from xchan where xchan_hash = '%s' limit 1",
dbesc($sender)
);
// don't import sys channel posts from selfcensored authors
@@ -1812,8 +1846,9 @@ class Libzot
$tag_delivery = tgroup_check($channel['channel_id'], $arr);
$perm = 'send_stream';
- if (($arr['mid'] !== $arr['parent_mid']) && ($relay))
+ if (($arr['mid'] !== $arr['parent_mid']) && ($relay)) {
$perm = 'post_comments';
+ }
// This is our own post, possibly coming from a channel clone
@@ -1830,7 +1865,8 @@ class Libzot
$blocked = LibBlock::fetch($channel['channel_id'], BLOCKTYPE_SERVER);
if ($blocked) {
- $h = q("select hubloc_url from hubloc where hubloc_hash = '%s'",
+ $h = q(
+ "select hubloc_url from hubloc where hubloc_hash = '%s'",
dbesc($sender)
);
if ($h) {
@@ -1848,7 +1884,8 @@ class Libzot
if (!$allowed) {
if ($perm === 'post_comments') {
- $parent = q("select * from item where mid = '%s' and uid = %d limit 1",
+ $parent = q(
+ "select * from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['parent_mid']),
intval($channel['channel_id'])
);
@@ -1865,13 +1902,11 @@ class Libzot
if ($parent && absolutely_no_comments($parent[0])) {
$allowed = false;
}
-
} elseif ($permit_mentions) {
$allowed = true;
}
}
if ($request) {
-
// Conversation fetches (e.g. $request == true) take place for
// a) new comments on expired posts
// b) hyperdrive (friend-of-friend) conversations
@@ -1916,7 +1951,6 @@ class Libzot
}
if ($arr['mid'] !== $arr['parent_mid']) {
-
if (perm_is_allowed($channel['channel_id'], $sender, 'moderated') && $relay) {
$arr['item_blocked'] = ITEM_MODERATED;
}
@@ -1931,12 +1965,14 @@ class Libzot
$prnt = ((strpos($arr['parent_mid'], 'token=') !== false) ? substr($arr['parent_mid'], 0, strpos($arr['parent_mid'], '?')) : '');
- $r = q("select route, id, parent_mid, mid, owner_xchan, item_private, obj_type from item where mid = '%s' and uid = %d limit 1",
+ $r = q(
+ "select route, id, parent_mid, mid, owner_xchan, item_private, obj_type from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['parent_mid']),
intval($channel['channel_id'])
);
if (!$r) {
- $r = q("select route, id, parent_mid, mid, owner_xchan, item_private, obj_type from item where mid = '%s' and uid = %d limit 1",
+ $r = q(
+ "select route, id, parent_mid, mid, owner_xchan, item_private, obj_type from item where mid = '%s' and uid = %d limit 1",
dbesc($prnt),
intval($channel['channel_id'])
);
@@ -1948,7 +1984,8 @@ class Libzot
$arr['thr_parent'] = $arr['parent_mid'];
$arr['parent_mid'] = $r[0]['parent_mid'];
if ($act->replyto) {
- q("update item set replyto = '%s' where id = %d",
+ q(
+ "update item set replyto = '%s' where id = %d",
dbesc($act->replyto),
intval($r[0]['id'])
);
@@ -1964,7 +2001,6 @@ class Libzot
}
}
} else {
-
// We don't seem to have a copy of this conversation or at least the parent
// - so request a copy of the entire conversation to date.
// Don't do this if it's a relay post as we're the ones who are supposed to
@@ -1976,8 +2012,10 @@ class Libzot
// the top level post is unlikely to be imported and
// this is just an exercise in futility.
- if ((!$relay) && (!$request) && (!$local_public)
- && perm_is_allowed($channel['channel_id'], $sender, 'send_stream')) {
+ if (
+ (!$relay) && (!$request) && (!$local_public)
+ && perm_is_allowed($channel['channel_id'], $sender, 'send_stream')
+ ) {
$reports = self::fetch_conversation($channel, $arr['mid']);
// extract our delivery report from the fetched conversation
@@ -2018,7 +2056,6 @@ class Libzot
$arr['route'] = $r[0]['route'];
$arr['owner_xchan'] = $r[0]['owner_xchan'];
} else {
-
// going downstream check that we have the same upstream provider that
// sent it to us originally. Ignore it if it came from another source
// (with potentially different permissions).
@@ -2058,14 +2095,14 @@ class Libzot
// This is used to fetch allow/deny rules if either the sender
// or owner is a connection. post_is_importable() evaluates all of them
- $abook = q("select * from abook where abook_channel = %d and ( abook_xchan = '%s' OR abook_xchan = '%s' )",
+ $abook = q(
+ "select * from abook where abook_channel = %d and ( abook_xchan = '%s' OR abook_xchan = '%s' )",
intval($channel['channel_id']),
dbesc($arr['owner_xchan']),
dbesc($arr['author_xchan'])
);
if (isset($arr['item_deleted']) && intval($arr['item_deleted'])) {
-
// set these just in case we need to store a fresh copy of the deleted post.
// This could happen if the delete got here before the original post did.
@@ -2088,7 +2125,8 @@ class Libzot
// reactions such as like and dislike could have an mid with /activity/ in it.
// Check for both forms in order to prevent duplicates.
- $r = q("select * from item where mid in ('%s','%s') and uid = %d limit 1",
+ $r = q(
+ "select * from item where mid in ('%s','%s') and uid = %d limit 1",
dbesc($arr['mid']),
dbesc(str_replace(z_root() . '/activity/', z_root() . '/item/', $arr['mid'])),
intval($channel['channel_id'])
@@ -2163,7 +2201,6 @@ class Libzot
}
if (post_is_importable($arr['uid'], $arr, $abook)) {
-
// Strip old-style hubzilla bookmarks
if (strpos($arr['body'], "#^[") !== false) {
$arr['body'] = str_replace("#^[", "[", $arr['body']);
@@ -2203,8 +2240,10 @@ class Libzot
// preserve conversations with which you are involved from expiration
$stored = (($item_result && $item_result['item']) ? $item_result['item'] : false);
- if ((is_array($stored)) && ($stored['id'] != $stored['parent'])
- && ($stored['author_xchan'] === $channel['channel_hash'])) {
+ if (
+ (is_array($stored)) && ($stored['id'] != $stored['parent'])
+ && ($stored['author_xchan'] === $channel['channel_hash'])
+ ) {
retain_item($stored['item']['parent']);
}
@@ -2263,16 +2302,18 @@ class Libzot
$ret = [];
- $signer = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1",
+ $signer = q(
+ "select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1",
dbesc($a['signature']['signer'])
);
foreach ($items as $activity) {
-
$AS = new ActivityStreams($activity);
- if ($AS->is_valid() && $AS->type === 'Announce' && is_array($AS->obj)
- && array_key_exists('object', $AS->obj) && array_key_exists('actor', $AS->obj)) {
+ if (
+ $AS->is_valid() && $AS->type === 'Announce' && is_array($AS->obj)
+ && array_key_exists('object', $AS->obj) && array_key_exists('actor', $AS->obj)
+ ) {
// This is a relayed/forwarded Activity (as opposed to a shared/boosted object)
// Reparse the encapsulated Activity and use that instead
logger('relayed activity', LOGGER_DEBUG);
@@ -2287,7 +2328,8 @@ class Libzot
// logger($AS->debug());
- $r = q("select hubloc_hash from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
+ $r = q(
+ "select hubloc_hash from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($AS->actor['id']),
dbesc($AS->actor['id'])
);
@@ -2295,7 +2337,8 @@ class Libzot
if (!$r) {
$y = import_author_xchan(['url' => $AS->actor['id']]);
if ($y) {
- $r = q("select hubloc_hash from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
+ $r = q(
+ "select hubloc_hash from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($AS->actor['id']),
dbesc($AS->actor['id'])
);
@@ -2361,8 +2404,9 @@ class Libzot
public static function remove_community_tag($sender, $arr, $uid)
{
- if (!(activity_match($arr['verb'], ACTIVITY_TAG) && ($arr['obj_type'] == ACTIVITY_OBJ_TAGTERM)))
+ if (!(activity_match($arr['verb'], ACTIVITY_TAG) && ($arr['obj_type'] == ACTIVITY_OBJ_TAGTERM))) {
return;
+ }
logger('remove_community_tag: invoked');
@@ -2371,7 +2415,8 @@ class Libzot
return;
}
- $r = q("select * from item where mid = '%s' and uid = %d limit 1",
+ $r = q(
+ "select * from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['mid']),
intval($uid)
);
@@ -2400,7 +2445,8 @@ class Libzot
$message_id = $i['target']['id'];
- $r = q("select id from item where mid = '%s' and uid = %d limit 1",
+ $r = q(
+ "select id from item where mid = '%s' and uid = %d limit 1",
dbesc($message_id),
intval($uid)
);
@@ -2409,7 +2455,8 @@ class Libzot
return;
}
- q("delete from term where uid = %d and oid = %d and otype = %d and ttype in ( %d, %d ) and term = '%s' and url = '%s'",
+ q(
+ "delete from term where uid = %d and oid = %d and otype = %d and ttype in ( %d, %d ) and term = '%s' and url = '%s'",
intval($uid),
intval($r[0]['id']),
intval(TERM_OBJ_POST),
@@ -2427,7 +2474,7 @@ class Libzot
* @param array $item
* @param array $orig
* @param int $uid
- * @param boolean $tag_delivery
+ * @param bool $tag_delivery
* @see item_store_update()
*
*/
@@ -2483,8 +2530,8 @@ class Libzot
* * \e string \b hash a xchan_hash
* @param array $item
* @param int $uid
- * @param boolean $relay
- * @return boolean|int post_id
+ * @param bool $relay
+ * @return bool|int post_id
*/
public static function delete_imported_item($sender, $act, $item, $uid, $relay)
@@ -2506,7 +2553,8 @@ class Libzot
// we may have stored either the object id or the activity id if it was a response activity (like, dislike, etc.)
- $r = q("select * from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
+ $r = q(
+ "select * from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
and mid in ('%s','%s') and uid = %d limit 1",
dbesc($sender),
dbesc($sender),
@@ -2526,7 +2574,6 @@ class Libzot
} else {
// this will fail with an ownership issue, so explain the real reason
logger('delete received for non-existent item or not owned by sender - ignoring.');
-
}
if ($ownership_valid === false) {
@@ -2535,13 +2582,15 @@ class Libzot
}
if ($stored['resource_type'] === 'event') {
- $i = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
+ $i = q(
+ "SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
dbesc($stored['resource_id']),
intval($uid)
);
if ($i) {
if ($i[0]['event_xchan'] === $sender) {
- q("delete from event where event_hash = '%s' and uid = %d",
+ q(
+ "delete from event where event_hash = '%s' and uid = %d",
dbesc($stored['resource_id']),
intval($uid)
);
@@ -2566,14 +2615,16 @@ class Libzot
// this information from the metadata should have no other discernible impact.
if (($stored['id'] != $stored['parent']) && intval($stored['item_origin'])) {
- q("update item set item_origin = 0 where id = %d and uid = %d",
+ q(
+ "update item set item_origin = 0 where id = %d and uid = %d",
intval($stored['id']),
intval($stored['uid'])
);
}
} else {
if ($stored['id'] !== $stored['parent']) {
- q("update item set commented = '%s', changed = '%s' where id = %d",
+ q(
+ "update item set commented = '%s', changed = '%s' where id = %d",
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($stored['parent'])
@@ -2607,7 +2658,8 @@ class Libzot
logger('process_profile_delivery', LOGGER_DEBUG);
- $r = q("select xchan_addr from xchan where xchan_hash = '%s' limit 1",
+ $r = q(
+ "select xchan_addr from xchan where xchan_hash = '%s' limit 1",
dbesc($sender['hash'])
);
if ($r) {
@@ -2630,7 +2682,8 @@ class Libzot
// deliveries is irrelevant
logger('process_location_delivery', LOGGER_DEBUG);
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
+ $r = q(
+ "select * from xchan where xchan_hash = '%s' limit 1",
dbesc($sender)
);
if ($r) {
@@ -2680,7 +2733,8 @@ class Libzot
$loc = $locations[0];
- $r = q("select * from channel where channel_hash = '%s' limit 1",
+ $r = q(
+ "select * from channel where channel_hash = '%s' limit 1",
dbesc($sender_hash)
);
@@ -2689,7 +2743,8 @@ class Libzot
}
if ($loc['url'] !== z_root()) {
- $x = q("update channel set channel_moved = '%s' where channel_hash = '%s' limit 1",
+ $x = q(
+ "update channel set channel_moved = '%s' where channel_hash = '%s' limit 1",
dbesc($loc['url']),
dbesc($sender_hash)
);
@@ -2729,7 +2784,6 @@ class Libzot
if ($x && count($x)) {
foreach ($x as $hub) {
-
// if this is a local channel that has been deleted, the hubloc is no good
// - make sure it is marked deleted so that nobody tries to use it.
@@ -2761,7 +2815,7 @@ class Libzot
*
* @param array $arr
* @param string $pubkey
- * @return boolean true if updated or inserted
+ * @return bool true if updated or inserted
*/
public static function import_site($arr)
@@ -2779,7 +2833,8 @@ class Libzot
$update = false;
$exists = false;
- $r = q("select * from site where site_url = '%s' limit 1",
+ $r = q(
+ "select * from site where site_url = '%s' limit 1",
dbesc($arr['url'])
);
if ($r) {
@@ -2836,8 +2891,9 @@ class Libzot
if ($access_policy != ACCESS_PRIVATE) {
$x = z_fetch_url($arr['url'] . '/siteinfo.json');
- if (!$x['success'])
+ if (!$x['success']) {
$access_policy = ACCESS_PRIVATE;
+ }
}
$site_about = EMPTY_STR;
@@ -2875,7 +2931,8 @@ class Libzot
}
if ($exists) {
- if (($siterecord['site_flags'] != $site_flags)
+ if (
+ ($siterecord['site_flags'] != $site_flags)
|| ($siterecord['site_access'] != $access_policy)
|| ($siterecord['site_directory'] != $directory_url)
|| ($siterecord['site_sellpage'] != $sellpage)
@@ -2884,14 +2941,15 @@ class Libzot
|| ($siterecord['site_project'] != $site_project)
|| ($siterecord['site_realm'] != $site_realm)
|| ($siterecord['site_crypto'] != $site_crypto)
- || ($siterecord['site_version'] != $site_version)) {
-
+ || ($siterecord['site_version'] != $site_version)
+ ) {
$update = true;
- // logger('import_site: input: ' . print_r($arr,true));
- // logger('import_site: stored: ' . print_r($siterecord,true));
+ // logger('import_site: input: ' . print_r($arr,true));
+ // logger('import_site: stored: ' . print_r($siterecord,true));
- $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s', site_type = %d, site_project = '%s', site_version = '%s', site_crypto = '%s'
+ $r = q(
+ "update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s', site_type = %d, site_project = '%s', site_version = '%s', site_crypto = '%s'
where site_url = '%s'",
dbesc($site_location),
intval($site_flags),
@@ -2912,7 +2970,8 @@ class Libzot
}
} else {
// update the timestamp to indicate we communicated with this site
- q("update site set site_dead = 0, site_update = '%s' where site_url = '%s'",
+ q(
+ "update site set site_dead = 0, site_update = '%s' where site_url = '%s'",
dbesc(datetime_convert()),
dbesc($url)
);
@@ -2970,7 +3029,7 @@ class Libzot
* @brief
*
* @param array $x
- * @return boolean|string return false or a hash
+ * @return bool|string return false or a hash
*/
public static function import_author_zot($x)
@@ -2990,7 +3049,8 @@ class Libzot
$found_primary = false;
- $r1 = q("select hubloc_url, hubloc_updated, site_dead from hubloc left join site on
+ $r1 = q(
+ "select hubloc_url, hubloc_updated, site_dead from hubloc left join site on
hubloc_url = site_url where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1",
dbesc($x['id']),
dbesc($x['id_sig'])
@@ -2999,7 +3059,8 @@ class Libzot
$found_primary = true;
}
- $r2 = q("select xchan_hash from xchan where xchan_guid = '%s' and xchan_guid_sig = '%s' limit 1",
+ $r2 = q(
+ "select xchan_hash from xchan where xchan_guid = '%s' and xchan_guid_sig = '%s' limit 1",
dbesc($x['id']),
dbesc($x['id_sig'])
);
@@ -3028,7 +3089,8 @@ class Libzot
if ($primary_dead || !$found_primary) {
logger('dead or site - ignoring', LOGGER_DEBUG, LOG_INFO);
- $r = q("select hubloc_id_url from hubloc left join site on hubloc_url = site_url
+ $r = q(
+ "select hubloc_id_url from hubloc left join site on hubloc_url = site_url
where hubloc_hash = '%s' and site_dead = 0",
dbesc($hash)
);
@@ -3065,13 +3127,13 @@ class Libzot
$feed = ((x($arr, 'feed')) ? intval($arr['feed']) : 0);
if ($ztarget) {
- $t = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1",
+ $t = q(
+ "select * from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1",
dbesc($ztarget)
);
if ($t) {
$ztarget_hash = $t[0]['hubloc_hash'];
} else {
-
// should probably perform discovery of the requestor (target) but if they actually had
// permissions we would know about them and we only want to know who they are to
// enumerate their specific permissions
@@ -3083,19 +3145,22 @@ class Libzot
$r = null;
if (strlen($zhash)) {
- $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
+ $r = q(
+ "select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
where channel_hash = '%s' limit 1",
dbesc($zhash)
);
} elseif (strlen($zguid) && strlen($zguid_sig)) {
- $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
+ $r = q(
+ "select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
where channel_guid = '%s' and channel_guid_sig = '%s' limit 1",
dbesc($zguid),
dbesc($zguid_sig)
);
} elseif (strlen($zaddr)) {
if (strpos($zaddr, '[system]') === false) { /* normal address lookup */
- $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
+ $r = q(
+ "select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
where ( channel_address = '%s' or xchan_addr = '%s' ) limit 1",
dbesc($zaddr),
dbesc($zaddr)
@@ -3154,16 +3219,17 @@ class Libzot
$channel_type = isset($rolesettings['channel_type']) ? $rolesettings['channel_type'] : 'normal';
// This is for birthdays and keywords, but must check access permissions
- $p = q("select * from profile where uid = %d and is_default = 1",
+ $p = q(
+ "select * from profile where uid = %d and is_default = 1",
intval($e['channel_id'])
);
$profile = [];
if ($p) {
-
- if (!intval($p[0]['publish']))
+ if (!intval($p[0]['publish'])) {
$searchable = false;
+ }
$profile['description'] = $p[0]['pdesc'];
$profile['birthday'] = $p[0]['dob'];
@@ -3272,7 +3338,8 @@ class Libzot
if ($ztarget_hash) {
$permissions['connected'] = false;
- $b = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
+ $b = q(
+ "select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($ztarget_hash),
intval($e['channel_id'])
);
@@ -3311,7 +3378,6 @@ class Libzot
call_hooks('zotinfo', $ret);
return ($ret);
-
}
@@ -3353,7 +3419,6 @@ class Libzot
// hide detailed site information if you're off the grid
if ($dirmode != DIRECTORY_MODE_STANDALONE || $force) {
-
$register_policy = intval(get_config('system', 'register_policy'));
if ($register_policy == REGISTER_CLOSED) {
@@ -3406,7 +3471,6 @@ class Libzot
}
return $ret['site'];
-
}
/**
@@ -3422,19 +3486,18 @@ class Libzot
{
if ($site_id) {
-
/*
- * This hub has now been proven to be valid.
- * Any hub with the same URL and a different sitekey cannot be valid.
- * Get rid of them (mark them deleted). There's a good chance they were re-installs.
- */
+ * This hub has now been proven to be valid.
+ * Any hub with the same URL and a different sitekey cannot be valid.
+ * Get rid of them (mark them deleted). There's a good chance they were re-installs.
+ */
- q("update hubloc set hubloc_deleted = 1, hubloc_error = 1 where hubloc_hash = '%s' and hubloc_url = '%s' and hubloc_site_id != '%s' ",
+ q(
+ "update hubloc set hubloc_deleted = 1, hubloc_error = 1 where hubloc_hash = '%s' and hubloc_url = '%s' and hubloc_site_id != '%s' ",
dbesc($hub['hubloc_hash']),
dbesc($hub['hubloc_url']),
dbesc($site_id)
);
-
} else {
$site_id = $hub['hubloc_site_id'];
}
@@ -3448,7 +3511,8 @@ class Libzot
$t = datetime_convert('UTC', 'UTC', 'now - 15 minutes');
- $r = q("update hubloc set hubloc_connected = '%s' where hubloc_id = %d and hubloc_site_id = '%s' and hubloc_connected < '%s' ",
+ $r = q(
+ "update hubloc set hubloc_connected = '%s' where hubloc_id = %d and hubloc_site_id = '%s' and hubloc_connected < '%s' ",
dbesc(datetime_convert()),
intval($hub['hubloc_id']),
dbesc($site_id),
@@ -3458,23 +3522,27 @@ class Libzot
// a dead hub came back to life - reset any tombstones we might have
if (intval($hub['hubloc_error']) || intval($hub['hubloc_deleted'])) {
- q("update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d and hubloc_site_id = '%s' ",
+ q(
+ "update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d and hubloc_site_id = '%s' ",
intval($hub['hubloc_id']),
dbesc($site_id)
);
if (intval($hub['hubloc_orphancheck'])) {
- q("update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d and hubloc_site_id = '%s' ",
+ q(
+ "update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d and hubloc_site_id = '%s' ",
intval($hub['hubloc_id']),
dbesc($site_id)
);
}
- q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'",
+ q(
+ "update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'",
dbesc($hub['hubloc_hash'])
);
}
// this site obviously isn't dead because they are trying to communicate with us.
- q("update site set site_dead = 0 where site_dead = 1 and site_url = '%s' ",
+ q(
+ "update site set site_dead = 0 where site_dead = 1 and site_url = '%s' ",
dbesc($hub['hubloc_url'])
);
@@ -3546,5 +3614,4 @@ class Libzot
}
self::refresh(['hubloc_id_url' => $hubloc['hubloc_id_url']]);
}
-
}
diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php
index e9d9eff8a..7414ee4d5 100644
--- a/Zotlabs/Lib/Libzotdir.php
+++ b/Zotlabs/Lib/Libzotdir.php
@@ -39,8 +39,9 @@ class Libzotdir
}
}
- if (!$isadir)
+ if (!$isadir) {
set_config('system', 'directory_server', '');
+ }
}
@@ -48,10 +49,11 @@ class Libzotdir
{
- if ($observer)
+ if ($observer) {
$ret = get_xconfig($observer, 'directory', $setting);
- else
+ } else {
$ret = ((array_key_exists($setting, $_SESSION)) ? intval($_SESSION[$setting]) : false);
+ }
if ($ret === false) {
$ret = get_config('directory', $setting);
@@ -60,8 +62,9 @@ class Libzotdir
}
}
- if ($setting === 'globaldir' && intval(get_config('system', 'localdir_hide')))
+ if ($setting === 'globaldir' && intval(get_config('system', 'localdir_hide'))) {
$ret = 1;
+ }
return $ret;
}
@@ -116,7 +119,7 @@ class Libzotdir
'$forumsurl' => $forumsurl,
'$safemode' => array('safemode', t('Safe Mode'), $safe_mode, '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&safe="+(this.checked ? 1 : 0)\''),
'$pubforums' => array('pubforums', t('Groups Only'), (($pubforums == 1) ? true : false), '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 1 : 0)\''),
-// '$collections' => array('collections', t('Collections Only'),(($pubforums == 2) ? true : false),'',array(t('No'), t('Yes')),' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 2 : 0)\''),
+// '$collections' => array('collections', t('Collections Only'),(($pubforums == 2) ? true : false),'',array(t('No'), t('Yes')),' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 2 : 0)\''),
'$hide_local' => $hide_local,
'$globaldir' => array('globaldir', t('This Website Only'), 1 - intval($globaldir), '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&global="+(this.checked ? 0 : 1)\''),
'$activedir' => array('activedir', t('Recently Updated'), intval($activedir), '', array(t('No'), t('Yes')), ' onchange=\'window.location.href="' . $forumsurl . '&active="+(this.checked ? 1 : 0)\''),
@@ -153,7 +156,8 @@ class Libzotdir
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'], 0, $ud);
} else {
- q("update updates set ud_last = '%s' where ud_addr = '%s'",
+ q(
+ "update updates set ud_last = '%s' where ud_addr = '%s'",
dbesc(datetime_convert()),
dbesc($ud['ud_addr'])
);
@@ -178,7 +182,8 @@ class Libzotdir
logger('local_dir_update: uid: ' . $uid, LOGGER_DEBUG);
- $p = q("select channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1",
+ $p = q(
+ "select channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1",
intval($uid)
);
@@ -190,8 +195,9 @@ class Libzotdir
$profile['description'] = $p[0]['pdesc'];
$profile['birthday'] = $p[0]['dob'];
- if ($age = age($p[0]['dob'], $p[0]['channel_timezone'], ''))
+ if ($age = age($p[0]['dob'], $p[0]['channel_timezone'], '')) {
$profile['age'] = $age;
+ }
$profile['gender'] = $p[0]['gender'];
$profile['marital'] = $p[0]['marital'];
@@ -207,25 +213,31 @@ class Libzotdir
if ($p[0]['keywords']) {
$tags = [];
$k = explode(' ', $p[0]['keywords']);
- if ($k)
- foreach ($k as $kk)
- if (trim($kk))
+ if ($k) {
+ foreach ($k as $kk) {
+ if (trim($kk)) {
$tags[] = trim($kk);
+ }
+ }
+ }
- if ($tags)
+ if ($tags) {
$profile['keywords'] = $tags;
+ }
}
$hidden = (1 - intval($p[0]['publish']));
// logger('hidden: ' . $hidden);
- $r = q("select xchan_hidden from xchan where xchan_hash = '%s' limit 1",
+ $r = q(
+ "select xchan_hidden from xchan where xchan_hash = '%s' limit 1",
dbesc($p[0]['channel_hash'])
);
if (intval($r[0]['xchan_hidden']) != $hidden) {
- $r = q("update xchan set xchan_hidden = %d where xchan_hash = '%s'",
+ $r = q(
+ "update xchan set xchan_hidden = %d where xchan_hash = '%s'",
intval($hidden),
dbesc($p[0]['channel_hash'])
);
@@ -240,14 +252,15 @@ class Libzotdir
self::import_directory_profile($hash, $arr['profile'], $address, 0);
} else {
// they may have made it private
- $r = q("delete from xprof where xprof_hash = '%s'",
+ $r = q(
+ "delete from xprof where xprof_hash = '%s'",
dbesc($hash)
);
- $r = q("delete from xtag where xtag_hash = '%s'",
+ $r = q(
+ "delete from xtag where xtag_hash = '%s'",
dbesc($hash)
);
}
-
}
$ud_hash = random_string() . '@' . App::get_hostname();
@@ -270,8 +283,9 @@ class Libzotdir
{
logger('import_directory_profile', LOGGER_DEBUG);
- if (!$hash)
+ if (!$hash) {
return false;
+ }
$maxlen = get_max_import_size();
@@ -315,19 +329,23 @@ class Libzotdir
if (in_arrayi('nsfw', $clean) || in_arrayi('adult', $clean)) {
- q("update xchan set xchan_selfcensored = 1 where xchan_hash = '%s'",
+ q(
+ "update xchan set xchan_selfcensored = 1 where xchan_hash = '%s'",
dbesc($hash)
);
}
- $r = q("select * from xprof where xprof_hash = '%s' limit 1",
+ $r = q(
+ "select * from xprof where xprof_hash = '%s' limit 1",
dbesc($hash)
);
- if ($arr['xprof_age'] > 150)
+ if ($arr['xprof_age'] > 150) {
$arr['xprof_age'] = 150;
- if ($arr['xprof_age'] < 0)
+ }
+ if ($arr['xprof_age'] < 0) {
$arr['xprof_age'] = 0;
+ }
if ($r) {
$update = false;
@@ -339,7 +357,8 @@ class Libzotdir
}
}
if ($update) {
- q("update xprof set
+ q(
+ "update xprof set
xprof_desc = '%s',
xprof_dob = '%s',
xprof_age = %d,
@@ -377,7 +396,8 @@ class Libzotdir
} else {
$update = true;
logger('New profile');
- q("insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_age, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country, xprof_about, xprof_homepage, xprof_hometown, xprof_keywords, xprof_pronouns) values ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
+ q(
+ "insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_age, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country, xprof_about, xprof_homepage, xprof_hometown, xprof_keywords, xprof_pronouns) values ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
dbesc($arr['xprof_hash']),
dbesc($arr['xprof_desc']),
dbesc($arr['xprof_dob']),
@@ -417,7 +437,8 @@ class Libzotdir
self::update_modtime($arr['xprof_hash'], new_uuid(), $addr, $ud_flags);
}
- q("update xchan set xchan_updated = '%s' where xchan_hash = '%s'",
+ q(
+ "update xchan set xchan_updated = '%s' where xchan_hash = '%s'",
dbesc(datetime_convert()),
dbesc($arr['xprof_hash'])
);
@@ -436,13 +457,15 @@ class Libzotdir
{
$existing = [];
- $r = q("select * from xtag where xtag_hash = '%s' and xtag_flags = 0",
+ $r = q(
+ "select * from xtag where xtag_hash = '%s' and xtag_flags = 0",
dbesc($hash)
);
if ($r) {
- foreach ($r as $rr)
+ foreach ($r as $rr) {
$existing[] = $rr['xtag_term'];
+ }
}
$clean = [];
@@ -453,15 +476,18 @@ class Libzotdir
}
foreach ($existing as $x) {
- if (!in_array($x, $clean))
- $r = q("delete from xtag where xtag_hash = '%s' and xtag_term = '%s' and xtag_flags = 0",
+ if (!in_array($x, $clean)) {
+ $r = q(
+ "delete from xtag where xtag_hash = '%s' and xtag_term = '%s' and xtag_flags = 0",
dbesc($hash),
dbesc($x)
);
+ }
}
foreach ($clean as $x) {
if (!in_array($x, $existing)) {
- $r = q("insert into xtag ( xtag_hash, xtag_term, xtag_flags) values ( '%s' ,'%s', 0 )",
+ $r = q(
+ "insert into xtag ( xtag_hash, xtag_term, xtag_flags) values ( '%s' ,'%s', 0 )",
dbesc($hash),
dbesc($x)
);
@@ -484,11 +510,13 @@ class Libzotdir
$dirmode = intval(get_config('system', 'directory_mode'));
- if ($dirmode == DIRECTORY_MODE_NORMAL)
+ if ($dirmode == DIRECTORY_MODE_NORMAL) {
return;
+ }
if ($flags) {
- q("insert into updates (ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' )",
+ q(
+ "insert into updates (ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' )",
dbesc($hash),
dbesc($guid),
dbesc(datetime_convert()),
@@ -496,13 +524,12 @@ class Libzotdir
dbesc($addr)
);
} else {
- q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 ",
+ q(
+ "update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 ",
intval(UPDATE_FLAGS_UPDATED),
dbesc($addr),
intval(UPDATE_FLAGS_UPDATED)
);
}
}
-
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Markdown.php b/Zotlabs/Lib/Markdown.php
index 6aae98a66..59ae117a5 100644
--- a/Zotlabs/Lib/Markdown.php
+++ b/Zotlabs/Lib/Markdown.php
@@ -1,4 +1,5 @@
getTagName()) {
- case 'tr':
- $line = [];
- $i = 1;
- foreach ($element->getChildren() as $td) {
- $i++;
- $v = $td->getValue();
- $v = trim($v);
- if ($i % 2 === 0 || $v !== '') {
- $line[] = $v;
- }
- }
- return '| ' . implode(' | ', $line) . " |\n";
- case 'td':
- case 'th':
- return trim($element->getValue());
- case 'tbody':
- return trim($element->getValue());
- case 'thead':
- $headerLine = reset($element->getChildren())->getValue();
- $headers = explode(' | ', trim(trim($headerLine, "\n"), '|'));
- $hr = [];
- foreach ($headers as $td) {
- $length = strlen(trim($td)) + 2;
- $hr[] = str_repeat('-', $length > 3 ? $length : 3);
- }
- $hr = '|' . implode('|', $hr) . '|';
- return $headerLine . $hr . "\n";
- case 'table':
- $inner = $element->getValue();
- if (strpos($inner, '-----') === false) {
- $inner = explode("\n", $inner);
- $single = explode(' | ', trim($inner[0], '|'));
- $hr = [];
- foreach ($single as $td) {
- $length = strlen(trim($td)) + 2;
- $hr[] = str_repeat('-', $length > 3 ? $length : 3);
- }
- $hr = '|' . implode('|', $hr) . '|';
- array_splice($inner, 1, 0, $hr);
- $inner = implode("\n", $inner);
- }
- return trim($inner) . "\n\n";
- }
- return $element->getValue();
- }
- /**
- * @return string[]
- */
- public function getSupportedTags()
- {
- return array('table', 'tr', 'thead', 'td', 'tbody');
- }
+ /**
+ * @param ElementInterface $element
+ *
+ * @return string
+ */
+ public function convert(ElementInterface $element)
+ {
+ switch ($element->getTagName()) {
+ case 'tr':
+ $line = [];
+ $i = 1;
+ foreach ($element->getChildren() as $td) {
+ $i++;
+ $v = $td->getValue();
+ $v = trim($v);
+ if ($i % 2 === 0 || $v !== '') {
+ $line[] = $v;
+ }
+ }
+ return '| ' . implode(' | ', $line) . " |\n";
+ case 'td':
+ case 'th':
+ return trim($element->getValue());
+ case 'tbody':
+ return trim($element->getValue());
+ case 'thead':
+ $headerLine = reset($element->getChildren())->getValue();
+ $headers = explode(' | ', trim(trim($headerLine, "\n"), '|'));
+ $hr = [];
+ foreach ($headers as $td) {
+ $length = strlen(trim($td)) + 2;
+ $hr[] = str_repeat('-', $length > 3 ? $length : 3);
+ }
+ $hr = '|' . implode('|', $hr) . '|';
+ return $headerLine . $hr . "\n";
+ case 'table':
+ $inner = $element->getValue();
+ if (strpos($inner, '-----') === false) {
+ $inner = explode("\n", $inner);
+ $single = explode(' | ', trim($inner[0], '|'));
+ $hr = [];
+ foreach ($single as $td) {
+ $length = strlen(trim($td)) + 2;
+ $hr[] = str_repeat('-', $length > 3 ? $length : 3);
+ }
+ $hr = '|' . implode('|', $hr) . '|';
+ array_splice($inner, 1, 0, $hr);
+ $inner = implode("\n", $inner);
+ }
+ return trim($inner) . "\n\n";
+ }
+ return $element->getValue();
+ }
+ /**
+ * @return string[]
+ */
+ public function getSupportedTags()
+ {
+ return array('table', 'tr', 'thead', 'td', 'tbody');
+ }
}
diff --git a/Zotlabs/Lib/MarkdownSoap.php b/Zotlabs/Lib/MarkdownSoap.php
index a08ad6073..304f0cd02 100644
--- a/Zotlabs/Lib/MarkdownSoap.php
+++ b/Zotlabs/Lib/MarkdownSoap.php
@@ -67,7 +67,8 @@ class MarkdownSoap
public function extract_code($s)
{
- $text = preg_replace_callback('{
+ $text = preg_replace_callback(
+ '{
(?:\n\n|\A\n?)
( # $1 = the code block -- one or more lines, starting with a space/tab
(?>
@@ -77,7 +78,9 @@ class MarkdownSoap
)
((?=^[ ]{0,' . '4' . '}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
}xm',
- [$this, 'encode_code'], $s);
+ [$this, 'encode_code'],
+ $s
+ );
return $text;
}
diff --git a/Zotlabs/Lib/MastAPI.php b/Zotlabs/Lib/MastAPI.php
index 724325169..99c5dfddc 100644
--- a/Zotlabs/Lib/MastAPI.php
+++ b/Zotlabs/Lib/MastAPI.php
@@ -5,27 +5,30 @@ namespace Zotlabs\Lib;
use App;
use Zotlabs\Lib\PConfig;
-
class MastAPI
{
public static function format_channel($channel)
{
- $p = q("select * from profile where uid = %d and is_default = 1",
+ $p = q(
+ "select * from profile where uid = %d and is_default = 1",
intval($channel['channel_id'])
);
- $a = q("select * from account where account_id = %d",
+ $a = q(
+ "select * from account where account_id = %d",
intval($channel['channel_account_id'])
);
- $followers = q("select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 ",
+ $followers = q(
+ "select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 ",
intval($channel['channel_id']),
intval($channel['channel_id']),
dbesc($channel['channel_hash'])
);
- $following = q("select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'my_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0",
+ $following = q(
+ "select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'my_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0",
intval($channel['channel_id']),
intval($channel['channel_id']),
dbesc($channel['channel_hash'])
@@ -36,7 +39,8 @@ class MastAPI
$item_normal = item_normal();
// count posts/comments
- $statuses = q("SELECT COUNT(id) as total FROM item
+ $statuses = q(
+ "SELECT COUNT(id) as total FROM item
WHERE uid = %d
AND author_xchan = '%s' $item_normal ",
intval($channel['channel_id']),
@@ -100,7 +104,5 @@ class MastAPI
$ret['contact_account'] = self::format_channel($adminsx);
return $ret;
-
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php
index f6c6c6c30..b7f267b1d 100644
--- a/Zotlabs/Lib/MessageFilter.php
+++ b/Zotlabs/Lib/MessageFilter.php
@@ -2,89 +2,94 @@
namespace Zotlabs\Lib;
+class MessageFilter
+{
-class MessageFilter {
+ public static function evaluate($item, $incl, $excl)
+ {
+ require_once('include/html2plain.php');
- public static function evaluate($item, $incl, $excl) {
+ $text = prepare_text($item['body'], ((isset($item['mimetype'])) ? $item['mimetype'] : 'text/bbcode'));
+ $text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text);
- require_once('include/html2plain.php');
+ $lang = null;
- $text = prepare_text($item['body'],((isset($item['mimetype'])) ? $item['mimetype'] : 'text/bbcode'));
- $text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text);
+ if ((strpos($incl, 'lang=') !== false) || (strpos($excl, 'lang=') !== false) || (strpos($incl, 'lang!=') !== false) || (strpos($excl, 'lang!=') !== false)) {
+ $lang = detect_language($text);
+ }
- $lang = null;
+ $tags = ((isset($item['term']) && is_array($item['term']) && count($item['term'])) ? $item['term'] : false);
- if((strpos($incl,'lang=') !== false) || (strpos($excl,'lang=') !== false) || (strpos($incl,'lang!=') !== false) || (strpos($excl,'lang!=') !== false)) {
- $lang = detect_language($text);
- }
+ // exclude always has priority
- $tags = ((isset($item['term']) && is_array($item['term']) && count($item['term'])) ? $item['term'] : false);
+ $exclude = (($excl) ? explode("\n", $excl) : null);
- // exclude always has priority
+ if ($exclude) {
+ foreach ($exclude as $word) {
+ $word = trim($word);
+ if (! $word) {
+ continue;
+ }
+ if (substr($word, 0, 1) === '#' && $tags) {
+ foreach ($tags as $t) {
+ if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
+ return false;
+ }
+ }
+ } elseif (substr($word, 0, 1) === '$' && $tags) {
+ foreach ($tags as $t) {
+ if (($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
+ return false;
+ }
+ }
+ } elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) {
+ return false;
+ } elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) {
+ return false;
+ } elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) {
+ return false;
+ } elseif (stristr($text, $word) !== false) {
+ return false;
+ }
+ }
+ }
- $exclude = (($excl) ? explode("\n",$excl) : null);
-
- if($exclude) {
- foreach($exclude as $word) {
- $word = trim($word);
- if(! $word)
- continue;
- if(substr($word,0,1) === '#' && $tags) {
- foreach($tags as $t)
- if((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
- return false;
- }
- elseif(substr($word,0,1) === '$' && $tags) {
- foreach($tags as $t)
- if(($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
- return false;
- }
- elseif((strpos($word,'/') === 0) && preg_match($word,$text))
- return false;
- elseif((strpos($word,'lang=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,5))) == 0))
- return false;
- elseif((strpos($word,'lang!=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,6))) != 0))
- return false;
- elseif(stristr($text,$word) !== false)
- return false;
- }
- }
-
- $include = (($incl) ? explode("\n",$incl) : null);
-
- if($include) {
- foreach($include as $word) {
- $word = trim($word);
- if(! $word)
- continue;
- if(substr($word,0,1) === '#' && $tags) {
- foreach($tags as $t)
- if((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
- return true;
- }
- elseif(substr($word,0,1) === '$' && $tags) {
- foreach($tags as $t)
- if(($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
- return true;
- }
- elseif((strpos($word,'/') === 0) && preg_match($word,$text))
- return true;
- elseif((strpos($word,'lang=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,5))) == 0))
- return true;
- elseif((strpos($word,'lang!=') === 0) && ($lang) && (strcasecmp($lang,trim(substr($word,6))) != 0))
- return true;
- elseif(stristr($text,$word) !== false)
- return true;
- }
- }
- else {
- return true;
- }
-
- return false;
- }
+ $include = (($incl) ? explode("\n", $incl) : null);
+ if ($include) {
+ foreach ($include as $word) {
+ $word = trim($word);
+ if (! $word) {
+ continue;
+ }
+ if (substr($word, 0, 1) === '#' && $tags) {
+ foreach ($tags as $t) {
+ if ((($t['ttype'] == TERM_HASHTAG) || ($t['ttype'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
+ return true;
+ }
+ }
+ } elseif (substr($word, 0, 1) === '$' && $tags) {
+ foreach ($tags as $t) {
+ if (($t['ttype'] == TERM_CATEGORY) && (($t['term'] === substr($word, 1)) || (substr($word, 1) === '*'))) {
+ return true;
+ }
+ }
+ } elseif ((strpos($word, '/') === 0) && preg_match($word, $text)) {
+ return true;
+ } elseif ((strpos($word, 'lang=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 5))) == 0)) {
+ return true;
+ } elseif ((strpos($word, 'lang!=') === 0) && ($lang) && (strcasecmp($lang, trim(substr($word, 6))) != 0)) {
+ return true;
+ } elseif (stristr($text, $word) !== false) {
+ return true;
+ }
+ }
+ } else {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/Zotlabs/Lib/Nodeinfo.php b/Zotlabs/Lib/Nodeinfo.php
index 128bb5261..65d5c78a5 100644
--- a/Zotlabs/Lib/Nodeinfo.php
+++ b/Zotlabs/Lib/Nodeinfo.php
@@ -2,43 +2,40 @@
namespace Zotlabs\Lib;
+class Nodeinfo
+{
-
-class Nodeinfo {
-
- public static function fetch($url) {
- $href = EMPTY_STR;
- $m = parse_url($url);
- if ($m['scheme'] && $m['host']) {
- $s = $m['scheme'] . '://' . $m['host'] . '/.well-known/nodeinfo';
- $n = z_fetch_url($s);
- if ($n['success']) {
- $j = json_decode($n['body'], true);
- if ($j && $j['links']) {
- // lemmy just sends one result
- if (isset($j['links']['rel'])) {
- if ($j['links']['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($j['links']['href'])) {
- $href = $j['links']['href'];
- }
- }
- else {
- foreach ($j['links'] as $l) {
- if (isset($l['rel']) && $l['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($l['href'])) {
- $href = $l['href'];
- }
- }
- }
- }
- }
- }
- if ($href) {
- $n = z_fetch_url($href);
- if ($n['success']) {
- return json_decode($n['body'],true);
- }
- }
- return [];
-
- }
-
-}
\ No newline at end of file
+ public static function fetch($url)
+ {
+ $href = EMPTY_STR;
+ $m = parse_url($url);
+ if ($m['scheme'] && $m['host']) {
+ $s = $m['scheme'] . '://' . $m['host'] . '/.well-known/nodeinfo';
+ $n = z_fetch_url($s);
+ if ($n['success']) {
+ $j = json_decode($n['body'], true);
+ if ($j && $j['links']) {
+ // lemmy just sends one result
+ if (isset($j['links']['rel'])) {
+ if ($j['links']['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($j['links']['href'])) {
+ $href = $j['links']['href'];
+ }
+ } else {
+ foreach ($j['links'] as $l) {
+ if (isset($l['rel']) && $l['rel'] === 'http://nodeinfo.diaspora.software/ns/schema/2.0' && isset($l['href'])) {
+ $href = $l['href'];
+ }
+ }
+ }
+ }
+ }
+ }
+ if ($href) {
+ $n = z_fetch_url($href);
+ if ($n['success']) {
+ return json_decode($n['body'], true);
+ }
+ }
+ return [];
+ }
+}
diff --git a/Zotlabs/Lib/PConfig.php b/Zotlabs/Lib/PConfig.php
index 0745080b0..b456be5ca 100644
--- a/Zotlabs/Lib/PConfig.php
+++ b/Zotlabs/Lib/PConfig.php
@@ -18,193 +18,212 @@ use App;
* The old (deprecated?) way to access a PConfig value is:
* @code{.php}$var = get_pconfig(local_channel(), 'category', 'key');@endcode
*/
-class PConfig {
+class PConfig
+{
- /**
- * @brief Loads all configuration values of a channel into a cached storage.
- *
- * All configuration values of the given channel are stored in global cache
- * which is available under the global variable App::$config[$uid].
- *
- * @param string $uid
- * The channel_id
- * @return void|false Nothing or false if $uid is null or false
- */
- public static function Load($uid) {
- if(is_null($uid) || $uid === false)
- return false;
+ /**
+ * @brief Loads all configuration values of a channel into a cached storage.
+ *
+ * All configuration values of the given channel are stored in global cache
+ * which is available under the global variable App::$config[$uid].
+ *
+ * @param string $uid
+ * The channel_id
+ * @return void|false Nothing or false if $uid is null or false
+ */
+ public static function Load($uid)
+ {
+ if (is_null($uid) || $uid === false) {
+ return false;
+ }
- if(! is_array(App::$config)) {
- btlogger('App::$config not an array');
- }
+ if (! is_array(App::$config)) {
+ btlogger('App::$config not an array');
+ }
- if(! array_key_exists($uid, App::$config)) {
- App::$config[$uid] = [];
- }
+ if (! array_key_exists($uid, App::$config)) {
+ App::$config[$uid] = [];
+ }
- if(! is_array(App::$config[$uid])) {
- btlogger('App::$config[$uid] not an array: ' . $uid);
- }
+ if (! is_array(App::$config[$uid])) {
+ btlogger('App::$config[$uid] not an array: ' . $uid);
+ }
- $r = q("SELECT * FROM pconfig WHERE uid = %d",
- intval($uid)
- );
+ $r = q(
+ "SELECT * FROM pconfig WHERE uid = %d",
+ intval($uid)
+ );
- if($r) {
- foreach($r as $rr) {
- $k = $rr['k'];
- $c = $rr['cat'];
- if(! array_key_exists($c, App::$config[$uid])) {
- App::$config[$uid][$c] = [];
- App::$config[$uid][$c]['config_loaded'] = true;
- }
- App::$config[$uid][$c][$k] = $rr['v'];
- }
- }
- }
+ if ($r) {
+ foreach ($r as $rr) {
+ $k = $rr['k'];
+ $c = $rr['cat'];
+ if (! array_key_exists($c, App::$config[$uid])) {
+ App::$config[$uid][$c] = [];
+ App::$config[$uid][$c]['config_loaded'] = true;
+ }
+ App::$config[$uid][$c][$k] = $rr['v'];
+ }
+ }
+ }
- /**
- * @brief Get a particular channel's config variable given the category name
- * ($family) and a key.
- *
- * Get a particular channel's config value from the given category ($family)
- * and the $key from a cached storage in App::$config[$uid].
- *
- * Returns false if not set.
- *
- * @param string $uid
- * The channel_id
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to query
- * @param mixed $default (optional, default false)
- * Default value to return if key does not exist
- * @return mixed Stored value or false if it does not exist
- */
- public static function Get($uid, $family, $key, $default = false) {
+ /**
+ * @brief Get a particular channel's config variable given the category name
+ * ($family) and a key.
+ *
+ * Get a particular channel's config value from the given category ($family)
+ * and the $key from a cached storage in App::$config[$uid].
+ *
+ * Returns false if not set.
+ *
+ * @param string $uid
+ * The channel_id
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to query
+ * @param mixed $default (optional, default false)
+ * Default value to return if key does not exist
+ * @return mixed Stored value or false if it does not exist
+ */
+ public static function Get($uid, $family, $key, $default = false)
+ {
- if(is_null($uid) || $uid === false)
- return $default;
+ if (is_null($uid) || $uid === false) {
+ return $default;
+ }
- if(! array_key_exists($uid, App::$config))
- self::Load($uid);
+ if (! array_key_exists($uid, App::$config)) {
+ self::Load($uid);
+ }
- if((! array_key_exists($family, App::$config[$uid])) || (! array_key_exists($key, App::$config[$uid][$family])))
- return $default;
+ if ((! array_key_exists($family, App::$config[$uid])) || (! array_key_exists($key, App::$config[$uid][$family]))) {
+ return $default;
+ }
- return unserialise(App::$config[$uid][$family][$key]);
- }
+ return unserialise(App::$config[$uid][$family][$key]);
+ }
- /**
- * @brief Sets a configuration value for a channel.
- *
- * Stores a config value ($value) in the category ($family) under the key ($key)
- * for the channel_id $uid.
- *
- * @param string $uid
- * The channel_id
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to set
- * @param string $value
- * The value to store
- * @return mixed Stored $value or false
- */
- public static function Set($uid, $family, $key, $value) {
+ /**
+ * @brief Sets a configuration value for a channel.
+ *
+ * Stores a config value ($value) in the category ($family) under the key ($key)
+ * for the channel_id $uid.
+ *
+ * @param string $uid
+ * The channel_id
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to set
+ * @param string $value
+ * The value to store
+ * @return mixed Stored $value or false
+ */
+ public static function Set($uid, $family, $key, $value)
+ {
- // this catches subtle errors where this function has been called
- // with local_channel() when not logged in (which returns false)
- // and throws an error in array_key_exists below.
- // we provide a function backtrace in the logs so that we can find
- // and fix the calling function.
+ // this catches subtle errors where this function has been called
+ // with local_channel() when not logged in (which returns false)
+ // and throws an error in array_key_exists below.
+ // we provide a function backtrace in the logs so that we can find
+ // and fix the calling function.
- if(is_null($uid) || $uid === false) {
- btlogger('UID is FALSE!', LOGGER_NORMAL, LOG_ERR);
- return;
- }
+ if (is_null($uid) || $uid === false) {
+ btlogger('UID is FALSE!', LOGGER_NORMAL, LOG_ERR);
+ return;
+ }
- // manage array value
- $dbvalue = ((is_array($value)) ? serialise($value) : $value);
- $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
+ // manage array value
+ $dbvalue = ((is_array($value)) ? serialise($value) : $value);
+ $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
- if(self::Get($uid, $family, $key) === false) {
- if(! array_key_exists($uid, App::$config))
- App::$config[$uid] = [];
- if(! array_key_exists($family, App::$config[$uid]))
- App::$config[$uid][$family] = [];
+ if (self::Get($uid, $family, $key) === false) {
+ if (! array_key_exists($uid, App::$config)) {
+ App::$config[$uid] = [];
+ }
+ if (! array_key_exists($family, App::$config[$uid])) {
+ App::$config[$uid][$family] = [];
+ }
- $ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ",
- intval($uid),
- dbesc($family),
- dbesc($key),
- dbesc($dbvalue)
- );
- }
- else {
+ $ret = q(
+ "INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ",
+ intval($uid),
+ dbesc($family),
+ dbesc($key),
+ dbesc($dbvalue)
+ );
+ } else {
+ $ret = q(
+ "UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'",
+ dbesc($dbvalue),
+ intval($uid),
+ dbesc($family),
+ dbesc($key)
+ );
+ }
- $ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'",
- dbesc($dbvalue),
- intval($uid),
- dbesc($family),
- dbesc($key)
- );
- }
+ // keep a separate copy for all variables which were
+ // set in the life of this page. We need this to
+ // synchronise channel clones.
- // keep a separate copy for all variables which were
- // set in the life of this page. We need this to
- // synchronise channel clones.
+ if (! array_key_exists('transient', App::$config[$uid])) {
+ App::$config[$uid]['transient'] = [];
+ }
+ if (! array_key_exists($family, App::$config[$uid]['transient'])) {
+ App::$config[$uid]['transient'][$family] = [];
+ }
- if(! array_key_exists('transient', App::$config[$uid]))
- App::$config[$uid]['transient'] = [];
- if(! array_key_exists($family, App::$config[$uid]['transient']))
- App::$config[$uid]['transient'][$family] = [];
+ App::$config[$uid][$family][$key] = $value;
+ App::$config[$uid]['transient'][$family][$key] = $value;
- App::$config[$uid][$family][$key] = $value;
- App::$config[$uid]['transient'][$family][$key] = $value;
+ if ($ret) {
+ return $value;
+ }
- if($ret)
- return $value;
-
- return $ret;
- }
+ return $ret;
+ }
- /**
- * @brief Deletes the given key from the channel's configuration.
- *
- * Removes the configured value from the stored cache in App::$config[$uid]
- * and removes it from the database.
- *
- * @param string $uid
- * The channel_id
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to delete
- * @return mixed
- */
- public static function Delete($uid, $family, $key) {
+ /**
+ * @brief Deletes the given key from the channel's configuration.
+ *
+ * Removes the configured value from the stored cache in App::$config[$uid]
+ * and removes it from the database.
+ *
+ * @param string $uid
+ * The channel_id
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to delete
+ * @return mixed
+ */
+ public static function Delete($uid, $family, $key)
+ {
- if(is_null($uid) || $uid === false)
- return false;
+ if (is_null($uid) || $uid === false) {
+ return false;
+ }
- $ret = false;
+ $ret = false;
- if(array_key_exists($uid, App::$config)
- && is_array(App::$config['uid'])
- && array_key_exists($family, App::$config['uid'])
- && array_key_exists($key, App::$config[$uid][$family]))
- unset(App::$config[$uid][$family][$key]);
+ if (
+ array_key_exists($uid, App::$config)
+ && is_array(App::$config['uid'])
+ && array_key_exists($family, App::$config['uid'])
+ && array_key_exists($key, App::$config[$uid][$family])
+ ) {
+ unset(App::$config[$uid][$family][$key]);
+ }
- $ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'",
- intval($uid),
- dbesc($family),
- dbesc($key)
- );
-
- return $ret;
- }
+ $ret = q(
+ "DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'",
+ intval($uid),
+ dbesc($family),
+ dbesc($key)
+ );
+ return $ret;
+ }
}
diff --git a/Zotlabs/Lib/Permcat.php b/Zotlabs/Lib/Permcat.php
index e0805c147..c94061586 100644
--- a/Zotlabs/Lib/Permcat.php
+++ b/Zotlabs/Lib/Permcat.php
@@ -21,157 +21,168 @@ use Zotlabs\Access\Permissions;
* These answer the question "Can Joe view *this* album/photo?".
*/
-class Permcat {
+class Permcat
+{
- /**
- * @var array
- */
- private $permcats = [];
+ /**
+ * @var array
+ */
+ private $permcats = [];
- /**
- * @brief Permcat constructor.
- *
- * @param int $channel_id
- */
- public function __construct($channel_id) {
+ /**
+ * @brief Permcat constructor.
+ *
+ * @param int $channel_id
+ */
+ public function __construct($channel_id)
+ {
- $perms = [];
+ $perms = [];
- // first check role perms for a perms_connect setting
+ // first check role perms for a perms_connect setting
- $role = get_pconfig($channel_id,'system','permissions_role');
- if($role) {
- $x = PermissionRoles::role_perms($role);
- if($x['perms_connect']) {
- $perms = Permissions::FilledPerms($x['perms_connect']);
- }
- }
+ $role = get_pconfig($channel_id, 'system', 'permissions_role');
+ if ($role) {
+ $x = PermissionRoles::role_perms($role);
+ if ($x['perms_connect']) {
+ $perms = Permissions::FilledPerms($x['perms_connect']);
+ }
+ }
- // if no role perms it may be a custom role, see if there any autoperms
+ // if no role perms it may be a custom role, see if there any autoperms
- if(! $perms) {
- $perms = Permissions::FilledAutoPerms($channel_id);
- }
+ if (! $perms) {
+ $perms = Permissions::FilledAutoPerms($channel_id);
+ }
- // if no autoperms it may be a custom role with manual perms
+ // if no autoperms it may be a custom role with manual perms
- if(! $perms) {
- $c = channelx_by_n($channel_id);
- if($c) {
- $perms = Permissions::FilledPerms(get_abconfig($channel_id,$c['channel_hash'],'system','my_perms',EMPTY_STR));
- }
- }
+ if (! $perms) {
+ $c = channelx_by_n($channel_id);
+ if ($c) {
+ $perms = Permissions::FilledPerms(get_abconfig($channel_id, $c['channel_hash'], 'system', 'my_perms', EMPTY_STR));
+ }
+ }
- // nothing was found - create a filled permission array where all permissions are 0
+ // nothing was found - create a filled permission array where all permissions are 0
- if(! $perms) {
- $perms = Permissions::FilledPerms([]);
- }
+ if (! $perms) {
+ $perms = Permissions::FilledPerms([]);
+ }
- $this->permcats[] = [
- 'name' => 'default',
- 'localname' => t('default','permcat'),
- 'perms' => Permissions::Operms($perms),
- 'system' => 1
- ];
+ $this->permcats[] = [
+ 'name' => 'default',
+ 'localname' => t('default', 'permcat'),
+ 'perms' => Permissions::Operms($perms),
+ 'system' => 1
+ ];
- $p = $this->load_permcats($channel_id);
- if($p) {
- for($x = 0; $x < count($p); $x++) {
- $this->permcats[] = [
- 'name' => $p[$x][0],
- 'localname' => $p[$x][1],
- 'perms' => Permissions::Operms(Permissions::FilledPerms($p[$x][2])),
- 'system' => intval($p[$x][3])
- ];
- }
- }
- }
+ $p = $this->load_permcats($channel_id);
+ if ($p) {
+ for ($x = 0; $x < count($p); $x++) {
+ $this->permcats[] = [
+ 'name' => $p[$x][0],
+ 'localname' => $p[$x][1],
+ 'perms' => Permissions::Operms(Permissions::FilledPerms($p[$x][2])),
+ 'system' => intval($p[$x][3])
+ ];
+ }
+ }
+ }
- /**
- * @brief Return array with permcats.
- *
- * @return array
- */
- public function listing() {
- return $this->permcats;
- }
+ /**
+ * @brief Return array with permcats.
+ *
+ * @return array
+ */
+ public function listing()
+ {
+ return $this->permcats;
+ }
- /**
- * @brief
- *
- * @param string $name
- * @return array
- * * \e array with permcats
- * * \e bool \b error if $name not found in permcats true
- */
- public function fetch($name) {
- if($name && $this->permcats) {
- foreach($this->permcats as $permcat) {
- if(strcasecmp($permcat['name'], $name) === 0) {
- return $permcat;
- }
- }
- }
+ /**
+ * @brief
+ *
+ * @param string $name
+ * @return array
+ * * \e array with permcats
+ * * \e bool \b error if $name not found in permcats true
+ */
+ public function fetch($name)
+ {
+ if ($name && $this->permcats) {
+ foreach ($this->permcats as $permcat) {
+ if (strcasecmp($permcat['name'], $name) === 0) {
+ return $permcat;
+ }
+ }
+ }
- return ['error' => true];
- }
+ return ['error' => true];
+ }
- public function load_permcats($uid) {
+ public function load_permcats($uid)
+ {
- $permcats = [
- [ 'follower', t('follower','permcat'),
- [ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
- 'post_like' ], 1
- ],
- [ 'contributor', t('contributor','permcat'),
- [ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
- 'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ], 1
- ],
- [ 'publisher', t('publisher','permcat'),
- [ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
- 'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
- 'chat', 'republish' ], 1
- ]
- ];
+ $permcats = [
+ [ 'follower', t('follower', 'permcat'),
+ [ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
+ 'post_like' ], 1
+ ],
+ [ 'contributor', t('contributor', 'permcat'),
+ [ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
+ 'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ], 1
+ ],
+ [ 'publisher', t('publisher', 'permcat'),
+ [ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
+ 'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
+ 'chat', 'republish' ], 1
+ ]
+ ];
- if($uid) {
- $x = q("select * from pconfig where uid = %d and cat = 'permcat'",
- intval($uid)
- );
- if($x) {
- foreach($x as $xv) {
- $value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
- $permcats[] = [ $xv['k'], $xv['k'], $value, 0 ];
- }
- }
- }
+ if ($uid) {
+ $x = q(
+ "select * from pconfig where uid = %d and cat = 'permcat'",
+ intval($uid)
+ );
+ if ($x) {
+ foreach ($x as $xv) {
+ $value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
+ $permcats[] = [ $xv['k'], $xv['k'], $value, 0 ];
+ }
+ }
+ }
- /**
- * @hooks permcats
- * * \e array
- */
- call_hooks('permcats', $permcats);
+ /**
+ * @hooks permcats
+ * * \e array
+ */
+ call_hooks('permcats', $permcats);
- return $permcats;
- }
+ return $permcats;
+ }
- public static function find_permcat($arr, $name) {
- if((! $arr) || (! $name))
- return false;
+ public static function find_permcat($arr, $name)
+ {
+ if ((! $arr) || (! $name)) {
+ return false;
+ }
- foreach($arr as $p)
- if($p['name'] == $name)
- return $p['value'];
- }
+ foreach ($arr as $p) {
+ if ($p['name'] == $name) {
+ return $p['value'];
+ }
+ }
+ }
- public static function update($channel_id, $name, $permarr) {
- PConfig::Set($channel_id, 'permcat', $name, $permarr);
- }
+ public static function update($channel_id, $name, $permarr)
+ {
+ PConfig::Set($channel_id, 'permcat', $name, $permarr);
+ }
- public static function delete($channel_id, $name) {
- PConfig::Delete($channel_id, 'permcat', $name);
- }
-
-}
\ No newline at end of file
+ public static function delete($channel_id, $name)
+ {
+ PConfig::Delete($channel_id, 'permcat', $name);
+ }
+}
diff --git a/Zotlabs/Lib/PermissionDescription.php b/Zotlabs/Lib/PermissionDescription.php
index 101a22b39..58d2ee7f3 100644
--- a/Zotlabs/Lib/PermissionDescription.php
+++ b/Zotlabs/Lib/PermissionDescription.php
@@ -16,148 +16,178 @@ require_once("include/text.php");
* permission settings for an item with an empty ACL.
* i.e the caption, icon, and tooltip for the no-ACL option in the ACL dialog.
*/
-class PermissionDescription {
+class PermissionDescription
+{
- private $global_perm;
- private $channel_perm;
- private $fallback_description;
+ private $global_perm;
+ private $channel_perm;
+ private $fallback_description;
- /**
- * Constructor is private.
- * Use static methods fromGlobalPermission(), fromStandalonePermission(),
- * or fromDescription() to create instances.
- *
- * @internal
- * @param int $global_perm
- * @param int $channel_perm
- * @param string $description (optional) default empty
- */
- private function __construct($global_perm, $channel_perm, $description = '') {
- $this->global_perm = $global_perm;
- $this->channel_perm = $channel_perm;
- $this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description;
- }
+ /**
+ * Constructor is private.
+ * Use static methods fromGlobalPermission(), fromStandalonePermission(),
+ * or fromDescription() to create instances.
+ *
+ * @internal
+ * @param int $global_perm
+ * @param int $channel_perm
+ * @param string $description (optional) default empty
+ */
+ private function __construct($global_perm, $channel_perm, $description = '')
+ {
+ $this->global_perm = $global_perm;
+ $this->channel_perm = $channel_perm;
+ $this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description;
+ }
- /**
- * If the interpretation of an empty ACL can't be summarised with a global default permission
- * or a specific permission setting then use this method and describe what it means instead.
- * Remember to localize the description first.
- *
- * @param string $description - the localized caption for the no-ACL option in the ACL dialog.
- * @return a new instance of PermissionDescription
- */
- public static function fromDescription($description) {
- return new PermissionDescription('', 0x80000, $description);
- }
+ /**
+ * If the interpretation of an empty ACL can't be summarised with a global default permission
+ * or a specific permission setting then use this method and describe what it means instead.
+ * Remember to localize the description first.
+ *
+ * @param string $description - the localized caption for the no-ACL option in the ACL dialog.
+ * @return a new instance of PermissionDescription
+ */
+ public static function fromDescription($description)
+ {
+ return new PermissionDescription('', 0x80000, $description);
+ }
- /**
- * Use this method only if the interpretation of an empty ACL doesn't fall back to a global
- * default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC,
- * PERMS_NETWORK etc.
- *
- * @param int $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc.
- * @return a new instance of PermissionDescription
- */
- public static function fromStandalonePermission($perm) {
+ /**
+ * Use this method only if the interpretation of an empty ACL doesn't fall back to a global
+ * default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC,
+ * PERMS_NETWORK etc.
+ *
+ * @param int $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc.
+ * @return a new instance of PermissionDescription
+ */
+ public static function fromStandalonePermission($perm)
+ {
- $result = new PermissionDescription('', $perm);
+ $result = new PermissionDescription('', $perm);
- $checkPerm = $result->get_permission_description();
- if($checkPerm == $result->fallback_description) {
- $result = null;
- logger('null PermissionDescription from unknown standalone permission: ' . $perm, LOGGER_DEBUG, LOG_ERR);
- }
+ $checkPerm = $result->get_permission_description();
+ if ($checkPerm == $result->fallback_description) {
+ $result = null;
+ logger('null PermissionDescription from unknown standalone permission: ' . $perm, LOGGER_DEBUG, LOG_ERR);
+ }
- return $result;
- }
+ return $result;
+ }
- /**
- * This is the preferred way to create a PermissionDescription, as it provides the most details.
- * Use this method if you know an empty ACL will result in one of the global default permissions
- * being used, such as channel_r_stream (for which you would pass 'view_stream').
- *
- * @param string $permname - a key for the global perms array from get_perms() in permissions.php,
- * e.g. 'view_stream', 'view_profile', etc.
- * @return a new instance of PermissionDescription
- */
- public static function fromGlobalPermission($permname) {
+ /**
+ * This is the preferred way to create a PermissionDescription, as it provides the most details.
+ * Use this method if you know an empty ACL will result in one of the global default permissions
+ * being used, such as channel_r_stream (for which you would pass 'view_stream').
+ *
+ * @param string $permname - a key for the global perms array from get_perms() in permissions.php,
+ * e.g. 'view_stream', 'view_profile', etc.
+ * @return a new instance of PermissionDescription
+ */
+ public static function fromGlobalPermission($permname)
+ {
- $result = null;
+ $result = null;
- $global_perms = Permissions::Perms();
+ $global_perms = Permissions::Perms();
- if(array_key_exists($permname, $global_perms)) {
+ if (array_key_exists($permname, $global_perms)) {
+ $channelPerm = PermissionLimits::Get(App::$channel['channel_id'], $permname);
- $channelPerm = PermissionLimits::Get(App::$channel['channel_id'], $permname);
+ $result = new PermissionDescription('', $channelPerm);
+ } else {
+ // The acl dialog can handle null arguments, but it shouldn't happen
+ logger('null PermissionDescription from unknown global permission: ' . $permname, LOGGER_DEBUG, LOG_ERR);
+ }
- $result = new PermissionDescription('', $channelPerm);
- } else {
- // The acl dialog can handle null arguments, but it shouldn't happen
- logger('null PermissionDescription from unknown global permission: ' . $permname, LOGGER_DEBUG, LOG_ERR);
- }
+ return $result;
+ }
- return $result;
- }
+ /**
+ * Gets a localized description of the permission, or a generic message if the permission
+ * is unknown.
+ *
+ * @return string description
+ */
+ public function get_permission_description()
+ {
- /**
- * Gets a localized description of the permission, or a generic message if the permission
- * is unknown.
- *
- * @return string description
- */
- public function get_permission_description() {
+ switch ($this->channel_perm) {
+ case 0:
+ return t('Only me');
+ case PERMS_PUBLIC:
+ return t('Public');
+ case PERMS_NETWORK:
+ return t('Anybody in the $Projectname network');
+ case PERMS_SITE:
+ return sprintf(t('Any account on %s'), App::get_hostname());
+ case PERMS_CONTACTS:
+ return t('Any of my connections');
+ case PERMS_SPECIFIC:
+ return t('Only connections I specifically allow');
+ case PERMS_AUTHED:
+ return t('Anybody authenticated (could include visitors from other networks)');
+ case PERMS_PENDING:
+ return t('Any connections including those who haven\'t yet been approved');
+ default:
+ return $this->fallback_description;
+ }
+ }
- switch($this->channel_perm) {
- case 0: return t('Only me');
- case PERMS_PUBLIC: return t('Public');
- case PERMS_NETWORK: return t('Anybody in the $Projectname network');
- case PERMS_SITE: return sprintf(t('Any account on %s'), App::get_hostname());
- case PERMS_CONTACTS: return t('Any of my connections');
- case PERMS_SPECIFIC: return t('Only connections I specifically allow');
- case PERMS_AUTHED: return t('Anybody authenticated (could include visitors from other networks)');
- case PERMS_PENDING: return t('Any connections including those who haven\'t yet been approved');
- default: return $this->fallback_description;
- }
- }
+ /**
+ * Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public,
+ * otherwise returns empty string.
+ *
+ * @return string icon css class name (often FontAwesome)
+ */
+ public function get_permission_icon()
+ {
- /**
- * Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public,
- * otherwise returns empty string.
- *
- * @return string icon css class name (often FontAwesome)
- */
- public function get_permission_icon() {
+ switch ($this->channel_perm) {
+ case 0:
+ return 'fa-eye-slash';
+ case PERMS_PUBLIC:
+ return 'fa-globe';
+ case PERMS_NETWORK:
+ return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use
+ case PERMS_SITE:
+ return 'fa-sitemap';
+ case PERMS_CONTACTS:
+ return 'fa-group';
+ case PERMS_SPECIFIC:
+ return 'fa-list';
+ case PERMS_AUTHED:
+ return '';
+ case PERMS_PENDING:
+ return '';
+ default:
+ return '';
+ }
+ }
- switch($this->channel_perm) {
- case 0:/* only me */ return 'fa-eye-slash';
- case PERMS_PUBLIC: return 'fa-globe';
- case PERMS_NETWORK: return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use
- case PERMS_SITE: return 'fa-sitemap';
- case PERMS_CONTACTS: return 'fa-group';
- case PERMS_SPECIFIC: return 'fa-list';
- case PERMS_AUTHED: return '';
- case PERMS_PENDING: return '';
- default: return '';
- }
- }
-
- /**
- * Returns a localized description of where the permission came from, if this is known.
- * If it's not know, or if the permission is standalone and didn't come from a default
- * permission setting, then empty string is returned.
- *
- * @return string description or empty string
- */
- public function get_permission_origin_description() {
-
- switch($this->global_perm) {
- case PERMS_R_STREAM: return t('This is your default setting for the audience of your normal stream, and posts.');
- case PERMS_R_PROFILE: return t('This is your default setting for who can view your default channel profile');
- case PERMS_R_ABOOK: return t('This is your default setting for who can view your connections');
- case PERMS_R_STORAGE: return t('This is your default setting for who can view your file storage and photos');
- case PERMS_R_PAGES: return t('This is your default setting for the audience of your webpages');
- default: return '';
- }
- }
+ /**
+ * Returns a localized description of where the permission came from, if this is known.
+ * If it's not know, or if the permission is standalone and didn't come from a default
+ * permission setting, then empty string is returned.
+ *
+ * @return string description or empty string
+ */
+ public function get_permission_origin_description()
+ {
+ switch ($this->global_perm) {
+ case PERMS_R_STREAM:
+ return t('This is your default setting for the audience of your normal stream, and posts.');
+ case PERMS_R_PROFILE:
+ return t('This is your default setting for who can view your default channel profile');
+ case PERMS_R_ABOOK:
+ return t('This is your default setting for who can view your connections');
+ case PERMS_R_STORAGE:
+ return t('This is your default setting for who can view your file storage and photos');
+ case PERMS_R_PAGES:
+ return t('This is your default setting for the audience of your webpages');
+ default:
+ return '';
+ }
+ }
}
diff --git a/Zotlabs/Lib/Queue.php b/Zotlabs/Lib/Queue.php
index 62ecec61f..c65beb379 100644
--- a/Zotlabs/Lib/Queue.php
+++ b/Zotlabs/Lib/Queue.php
@@ -1,4 +1,6 @@
- $outq, 'base' => $base, 'handled' => false, 'immediate' => $immediate);
call_hooks('queue_deliver', $arr);
- if ($arr['handled'])
+ if ($arr['handled']) {
return;
+ }
// "post" queue driver - used for diaspora and friendica-over-diaspora communications.
@@ -224,12 +237,14 @@ class Queue
if ($result['success'] && $result['return_code'] < 300) {
logger('deliver: queue post success to ' . $outq['outq_posturl'], LOGGER_DEBUG);
if ($base) {
- q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
+ q(
+ "update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
dbesc(datetime_convert()),
dbesc($base)
);
}
- q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
+ q(
+ "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
dbesc('accepted for delivery'),
dbesc(datetime_convert()),
dbesc($outq['outq_hash'])
@@ -241,7 +256,8 @@ class Queue
// immediate delivery otherwise we could get into a queue loop.
if (!$immediate) {
- $x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
+ $x = q(
+ "select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
dbesc($outq['outq_posturl'])
);
@@ -265,7 +281,6 @@ class Queue
}
if ($outq['outq_driver'] === 'asfetch') {
-
$channel = channelx_by_n($outq['outq_channel']);
if (!$channel) {
logger('missing channel: ' . $outq['outq_channel']);
@@ -303,7 +318,8 @@ class Queue
// immediate delivery otherwise we could get into a queue loop.
if (!$immediate) {
- $x = q("select outq_hash from outq where outq_driver = 'asfetch' and outq_channel = %d and outq_delivered = 0",
+ $x = q(
+ "select outq_hash from outq where outq_driver = 'asfetch' and outq_channel = %d and outq_delivered = 0",
dbesc($outq['outq_channel'])
);
@@ -325,7 +341,6 @@ class Queue
}
if ($outq['outq_driver'] === 'activitypub') {
-
$channel = channelx_by_n($outq['outq_channel']);
if (!$channel) {
logger('missing channel: ' . $outq['outq_channel']);
@@ -356,12 +371,14 @@ class Queue
if ($result['success'] && $result['return_code'] < 300) {
logger('deliver: queue post success to ' . $outq['outq_posturl'], LOGGER_DEBUG);
if ($base) {
- q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
+ q(
+ "update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
dbesc(datetime_convert()),
dbesc($base)
);
}
- q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
+ q(
+ "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
dbesc('accepted for delivery'),
dbesc(datetime_convert()),
dbesc($outq['outq_hash'])
@@ -373,7 +390,8 @@ class Queue
// immediate delivery otherwise we could get into a queue loop.
if (!$immediate) {
- $x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
+ $x = q(
+ "select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
dbesc($outq['outq_posturl'])
);
@@ -389,18 +407,21 @@ class Queue
}
} else {
if ($result['return_code'] >= 300) {
- q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
+ q(
+ "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'",
dbesc('delivery rejected' . ' ' . $result['return_code']),
dbesc(datetime_convert()),
dbesc($outq['outq_hash'])
);
} else {
- $dr = q("select * from dreport where dreport_queue = '%s'",
+ $dr = q(
+ "select * from dreport where dreport_queue = '%s'",
dbesc($outq['outq_hash'])
);
if ($dr) {
// update every queue entry going to this site with the most recent communication error
- q("update dreport set dreport_log = '%s' where dreport_site = '%s'",
+ q(
+ "update dreport set dreport_log = '%s' where dreport_site = '%s'",
dbesc(z_curl_error($result)),
dbesc($dr[0]['dreport_site'])
);
@@ -426,7 +447,8 @@ class Queue
Libzot::process_response($outq['outq_posturl'], ['success' => true, 'body' => json_encode($result)], $outq);
if (!$immediate) {
- $x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
+ $x = q(
+ "select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0",
dbesc($outq['outq_posturl'])
);
@@ -451,7 +473,8 @@ class Queue
$host_crypto = null;
if ($channel && $base) {
- $h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1",
+ $h = q(
+ "select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1",
dbesc($base)
);
if ($h) {
@@ -467,12 +490,14 @@ class Queue
logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']);
Libzot::process_response($outq['outq_posturl'], $result, $outq);
} else {
- $dr = q("select * from dreport where dreport_queue = '%s'",
+ $dr = q(
+ "select * from dreport where dreport_queue = '%s'",
dbesc($outq['outq_hash'])
);
// update every queue entry going to this site with the most recent communication error
- q("update dreport set dreport_log = '%s' where dreport_site = '%s'",
+ q(
+ "update dreport set dreport_log = '%s' where dreport_site = '%s'",
dbesc(z_curl_error($result)),
dbesc($dr[0]['dreport_site'])
);
@@ -485,4 +510,3 @@ class Queue
return;
}
}
-
diff --git a/Zotlabs/Lib/SConfig.php b/Zotlabs/Lib/SConfig.php
index 92161fc61..1d4e93a3f 100644
--- a/Zotlabs/Lib/SConfig.php
+++ b/Zotlabs/Lib/SConfig.php
@@ -7,23 +7,27 @@ namespace Zotlabs\Lib;
*
* @see XConfig
*/
-
-class SConfig {
- public static function Load($server_id) {
- return XConfig::Load('s_' . $server_id);
- }
+class SConfig
+{
- public static function Get($server_id, $family, $key, $default = false) {
- return XConfig::Get('s_' . $server_id,$family,$key, $default);
- }
+ public static function Load($server_id)
+ {
+ return XConfig::Load('s_' . $server_id);
+ }
- public static function Set($server_id, $family, $key, $value) {
- return XConfig::Set('s_' . $server_id,$family,$key,$value);
- }
+ public static function Get($server_id, $family, $key, $default = false)
+ {
+ return XConfig::Get('s_' . $server_id, $family, $key, $default);
+ }
- public static function Delete($server_id, $family, $key) {
- return XConfig::Delete('s_' . $server_id,$family,$key);
- }
+ public static function Set($server_id, $family, $key, $value)
+ {
+ return XConfig::Set('s_' . $server_id, $family, $key, $value);
+ }
+ public static function Delete($server_id, $family, $key)
+ {
+ return XConfig::Delete('s_' . $server_id, $family, $key);
+ }
}
diff --git a/Zotlabs/Lib/Share.php b/Zotlabs/Lib/Share.php
index 973922566..70c1fe7c8 100644
--- a/Zotlabs/Lib/Share.php
+++ b/Zotlabs/Lib/Share.php
@@ -6,222 +6,227 @@ use App;
use Zotlabs\Daemon\Run;
use Zotlabs\Lib\Libsync;
-class Share {
+class Share
+{
- private $item = null;
+ private $item = null;
- public function __construct($post_id) {
-
- if (! $post_id) {
- return;
- }
-
- if (is_array($post_id)) {
- $this->item = $post_id;
- return;
- }
-
- if (! (local_channel() || remote_channel())) {
- return;
- }
+ public function __construct($post_id)
+ {
- $r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
- intval($post_id)
- );
- if (! $r) {
- return;
- }
+ if (! $post_id) {
+ return;
+ }
- if (($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss')) {
- return;
- }
-
- $sql_extra = item_permissions_sql($r[0]['uid']);
-
- $r = q("select * from item where id = %d $sql_extra",
- intval($post_id)
- );
- if (! $r) {
- return;
- }
-
- if (! in_array($r[0]['mimetype'], [ 'text/bbcode', 'text/x-multicode' ])) {
- return;
- }
-
- /** @FIXME eventually we want to post remotely via rpost on your home site */
- // When that works remove this next bit:
-
- if (! local_channel()) {
- return;
- }
+ if (is_array($post_id)) {
+ $this->item = $post_id;
+ return;
+ }
- xchan_query($r);
-
- $this->item = array_shift($r);
+ if (! (local_channel() || remote_channel())) {
+ return;
+ }
- $arr = [];
+ $r = q(
+ "SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
+ intval($post_id)
+ );
+ if (! $r) {
+ return;
+ }
- $owner_uid = $this->item['uid'];
- $owner_aid = $this->item['aid'];
+ if (($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss')) {
+ return;
+ }
- $channel = channelx_by_n($this->item['uid']);
- $observer = App::get_observer();
+ $sql_extra = item_permissions_sql($r[0]['uid']);
- $can_comment = false;
- if ((array_key_exists('owner',$this->item)) && intval($this->item['owner']['abook_self'])) {
- $can_comment = perm_is_allowed($this->item['uid'],$observer['xchan_hash'],'post_comments');
- }
- else {
- $can_comment = can_comment_on_post($observer['xchan_hash'],$this->item);
- }
+ $r = q(
+ "select * from item where id = %d $sql_extra",
+ intval($post_id)
+ );
+ if (! $r) {
+ return;
+ }
- if (! $can_comment) {
- return;
- }
+ if (! in_array($r[0]['mimetype'], [ 'text/bbcode', 'text/x-multicode' ])) {
+ return;
+ }
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
- dbesc($this->item['owner_xchan'])
- );
+ /** @FIXME eventually we want to post remotely via rpost on your home site */
+ // When that works remove this next bit:
- if ($r) {
- $thread_owner = array_shift($r);
- }
- else {
- return;
- }
-
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
- dbesc($this->item['author_xchan'])
- );
- if ($r) {
- $item_author = array_shift($r);
- }
- else {
- return;
- }
+ if (! local_channel()) {
+ return;
+ }
- if ($item_author['network'] === 'activitypub') {
+ xchan_query($r);
- // for Mastodon compatibility, send back an ActivityPub Announce activity.
- // We don't need or want these on our own network as there is no mechanism for providing
- // a fair-use defense to copyright claims and frivolous lawsuits.
-
- $arr['aid'] = $owner_aid;
- $arr['uid'] = $owner_uid;
+ $this->item = array_shift($r);
- $arr['item_origin'] = 1;
- $arr['item_wall'] = $this->item['item_wall'];
- $arr['uuid'] = new_uuid();
- $arr['mid'] = z_root() . '/item/' . $arr['uuid'];
- $arr['mid'] = str_replace('/item/','/activity/',$arr['mid']);
- $arr['parent_mid'] = $this->item['mid'];
+ $arr = [];
- $mention = '@[zrl=' . $this->item['author']['xchan_url'] . ']' . $this->item['author']['xchan_name'] . '[/zrl]';
- $arr['body'] = sprintf( t('🔁 Repeated %1$s\'s %2$s'), $mention, $this->item['obj_type']);
+ $owner_uid = $this->item['uid'];
+ $owner_aid = $this->item['aid'];
- $arr['author_xchan'] = $observer['xchan_hash'];
- $arr['owner_xchan'] = $this->item['author_xchan'];
- $arr['obj'] = $this->item['obj'];
- $arr['obj_type'] = $this->item['obj_type'];
- $arr['verb'] = 'Announce';
+ $channel = channelx_by_n($this->item['uid']);
+ $observer = App::get_observer();
- $post = item_store($arr);
+ $can_comment = false;
+ if ((array_key_exists('owner', $this->item)) && intval($this->item['owner']['abook_self'])) {
+ $can_comment = perm_is_allowed($this->item['uid'], $observer['xchan_hash'], 'post_comments');
+ } else {
+ $can_comment = can_comment_on_post($observer['xchan_hash'], $this->item);
+ }
- $post_id = $post['item_id'];
+ if (! $can_comment) {
+ return;
+ }
- $arr['id'] = $post_id;
-
- call_hooks('post_local_end', $arr);
+ $r = q(
+ "select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($this->item['owner_xchan'])
+ );
- $r = q("select * from item where id = %d",
- intval($post_id)
- );
- if ($r) {
- xchan_query($r);
- $sync_item = fetch_post_tags($r);
- Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0],true) ] ]);
- }
+ if ($r) {
+ $thread_owner = array_shift($r);
+ } else {
+ return;
+ }
- Run::Summon([ 'Notifier','like',$post_id ]);
- }
-
- return;
+ $r = q(
+ "select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($this->item['author_xchan'])
+ );
+ if ($r) {
+ $item_author = array_shift($r);
+ } else {
+ return;
+ }
- }
+ if ($item_author['network'] === 'activitypub') {
+ // for Mastodon compatibility, send back an ActivityPub Announce activity.
+ // We don't need or want these on our own network as there is no mechanism for providing
+ // a fair-use defense to copyright claims and frivolous lawsuits.
- public function obj() {
- $obj = [];
+ $arr['aid'] = $owner_aid;
+ $arr['uid'] = $owner_uid;
- if(! $this->item)
- return $obj;
+ $arr['item_origin'] = 1;
+ $arr['item_wall'] = $this->item['item_wall'];
+ $arr['uuid'] = new_uuid();
+ $arr['mid'] = z_root() . '/item/' . $arr['uuid'];
+ $arr['mid'] = str_replace('/item/', '/activity/', $arr['mid']);
+ $arr['parent_mid'] = $this->item['mid'];
- $obj['type'] = $this->item['obj_type'];
- $obj['id'] = $this->item['mid'];
- $obj['content'] = bbcode($this->item['body']);
- $obj['source'] = [
- 'mediaType' => $this->item['mimetype'],
- 'content' => $this->item['body']
- ];
+ $mention = '@[zrl=' . $this->item['author']['xchan_url'] . ']' . $this->item['author']['xchan_name'] . '[/zrl]';
+ $arr['body'] = sprintf(t('🔁 Repeated %1$s\'s %2$s'), $mention, $this->item['obj_type']);
- $obj['name'] = $this->item['title'];
- $obj['published'] = $this->item['created'];
- $obj['updated'] = $this->item['edited'];
- $obj['attributedTo'] = ((strpos($this->item['author']['xchan_hash'],'http') === 0)
- ? $this->item['author']['xchan_hash']
- : $this->item['author']['xchan_url']);
+ $arr['author_xchan'] = $observer['xchan_hash'];
+ $arr['owner_xchan'] = $this->item['author_xchan'];
+ $arr['obj'] = $this->item['obj'];
+ $arr['obj_type'] = $this->item['obj_type'];
+ $arr['verb'] = 'Announce';
- return $obj;
- }
+ $post = item_store($arr);
- public function bbcode() {
- $bb = EMPTY_STR;
+ $post_id = $post['item_id'];
- if (! $this->item)
- return $bb;
+ $arr['id'] = $post_id;
- if (! $this->item['author']) {
- $author = q("select * from xchan where xchan_hash = '%s' limit 1",
- dbesc($this->item['author_xchan'])
- );
- if ($author) {
- $this->item['author'] = array_shift($author);
- }
- }
+ call_hooks('post_local_end', $arr);
- $special_object = (in_array($this->item['obj_type'], [ ACTIVITY_OBJ_PHOTO, 'Event', 'Question' ]) ? true : false);
- if($special_object) {
- $object = json_decode($this->item['obj'],true);
- $special = (($object['source']) ? $object['source']['content'] : $object['body']);
- }
-
- if (strpos($this->item['body'], "[/share]") !== false) {
- $pos = strpos($this->item['body'], "[share");
- $bb = substr($this->item['body'], $pos);
- } else {
- $bb = "[share author='" . urlencode($this->item['author']['xchan_name']).
- "' profile='" . $this->item['author']['xchan_url'] .
- "' portable_id='" . $this->item['author']['xchan_hash'] .
- "' avatar='" . $this->item['author']['xchan_photo_s'] .
- "' link='" . $this->item['plink'] .
- "' auth='" . (($this->item['author']['network'] === 'zot6') ? 'true' : 'false') .
- "' posted='" . $this->item['created'] .
- "' message_id='" . $this->item['mid'] .
- "']";
- if ($this->item['title']) {
- $bb .= '[b]'.$this->item['title'].'[/b]'."\r\n";
- }
- if ($this->item['summary']) {
- $bb .= $this->item['summary'] . "\r\n";
- }
-
- $bb .= (($special_object) ? $special . "\r\n" . $this->item['body'] : $this->item['body']);
- $bb .= "[/share]";
- }
+ $r = q(
+ "select * from item where id = %d",
+ intval($post_id)
+ );
+ if ($r) {
+ xchan_query($r);
+ $sync_item = fetch_post_tags($r);
+ Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0], true) ] ]);
+ }
- return $bb;
+ Run::Summon([ 'Notifier','like',$post_id ]);
+ }
- }
+ return;
+ }
+ public function obj()
+ {
+ $obj = [];
+
+ if (! $this->item) {
+ return $obj;
+ }
+
+ $obj['type'] = $this->item['obj_type'];
+ $obj['id'] = $this->item['mid'];
+ $obj['content'] = bbcode($this->item['body']);
+ $obj['source'] = [
+ 'mediaType' => $this->item['mimetype'],
+ 'content' => $this->item['body']
+ ];
+
+ $obj['name'] = $this->item['title'];
+ $obj['published'] = $this->item['created'];
+ $obj['updated'] = $this->item['edited'];
+ $obj['attributedTo'] = ((strpos($this->item['author']['xchan_hash'], 'http') === 0)
+ ? $this->item['author']['xchan_hash']
+ : $this->item['author']['xchan_url']);
+
+ return $obj;
+ }
+
+ public function bbcode()
+ {
+ $bb = EMPTY_STR;
+
+ if (! $this->item) {
+ return $bb;
+ }
+
+ if (! $this->item['author']) {
+ $author = q(
+ "select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($this->item['author_xchan'])
+ );
+ if ($author) {
+ $this->item['author'] = array_shift($author);
+ }
+ }
+
+ $special_object = (in_array($this->item['obj_type'], [ ACTIVITY_OBJ_PHOTO, 'Event', 'Question' ]) ? true : false);
+ if ($special_object) {
+ $object = json_decode($this->item['obj'], true);
+ $special = (($object['source']) ? $object['source']['content'] : $object['body']);
+ }
+
+ if (strpos($this->item['body'], "[/share]") !== false) {
+ $pos = strpos($this->item['body'], "[share");
+ $bb = substr($this->item['body'], $pos);
+ } else {
+ $bb = "[share author='" . urlencode($this->item['author']['xchan_name']) .
+ "' profile='" . $this->item['author']['xchan_url'] .
+ "' portable_id='" . $this->item['author']['xchan_hash'] .
+ "' avatar='" . $this->item['author']['xchan_photo_s'] .
+ "' link='" . $this->item['plink'] .
+ "' auth='" . (($this->item['author']['network'] === 'zot6') ? 'true' : 'false') .
+ "' posted='" . $this->item['created'] .
+ "' message_id='" . $this->item['mid'] .
+ "']";
+ if ($this->item['title']) {
+ $bb .= '[b]' . $this->item['title'] . '[/b]' . "\r\n";
+ }
+ if ($this->item['summary']) {
+ $bb .= $this->item['summary'] . "\r\n";
+ }
+
+ $bb .= (($special_object) ? $special . "\r\n" . $this->item['body'] : $this->item['body']);
+ $bb .= "[/share]";
+ }
+
+ return $bb;
+ }
}
diff --git a/Zotlabs/Lib/SvgSanitizer.php b/Zotlabs/Lib/SvgSanitizer.php
index 220a7a796..5e21c4f12 100644
--- a/Zotlabs/Lib/SvgSanitizer.php
+++ b/Zotlabs/Lib/SvgSanitizer.php
@@ -7,9 +7,9 @@ use Zotlabs\Lib\Config;
/**
* SVGSantiizer
- *
+ *
* Allowlist-based PHP SVG sanitizer.
- *
+ *
* @link https://github.com/alister-/SVG-Sanitizer}
* @author Alister Norris
* @copyright Copyright (c) 2013 Alister Norris
@@ -108,7 +108,6 @@ class SvgSanitizer
$total = $currentNode->attributes->length;
for ($x = 0; $x < $total; $x++) {
-
// get attributes name
$attrName = $currentNode->attributes->item($x)->nodeName;
@@ -119,8 +118,14 @@ class SvgSanitizer
if (!in_array($attrName, $allowlist_attr_arr)) {
$this->removedattrs[] = $attrName;
} // check for disallowed functions
- elseif (preg_match_all('/([a-zA-Z0-9]+)[\s]*\(/',
- $currentNode->attributes->item($x)->textContent, $matches, PREG_SET_ORDER)) {
+ elseif (
+ preg_match_all(
+ '/([a-zA-Z0-9]+)[\s]*\(/',
+ $currentNode->attributes->item($x)->textContent,
+ $matches,
+ PREG_SET_ORDER
+ )
+ ) {
if ($attrName === 'text') {
continue;
}
@@ -138,7 +143,6 @@ class SvgSanitizer
logger('removed: ' . $attr, LOGGER_DEBUG);
}
}
-
} // else remove element
else {
logger('remove_node: ' . print_r($currentNode, true));
diff --git a/Zotlabs/Lib/System.php b/Zotlabs/Lib/System.php
index 968729aef..3e3010bdf 100644
--- a/Zotlabs/Lib/System.php
+++ b/Zotlabs/Lib/System.php
@@ -4,113 +4,141 @@ namespace Zotlabs\Lib;
use App;
-class System {
+class System
+{
- public static function get_platform_name() {
- if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('platform_name',App::$config['system']))
- return App::$config['system']['platform_name'];
- return PLATFORM_NAME;
- }
+ public static function get_platform_name()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('platform_name', App::$config['system'])) {
+ return App::$config['system']['platform_name'];
+ }
+ return PLATFORM_NAME;
+ }
- public static function get_site_name() {
- if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['sitename'])
- return App::$config['system']['sitename'];
- return '';
- }
+ public static function get_site_name()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['sitename']) {
+ return App::$config['system']['sitename'];
+ }
+ return '';
+ }
- public static function get_banner() {
+ public static function get_banner()
+ {
- if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('banner',App::$config['system']) && App::$config['system']['banner']) {
- return App::$config['system']['banner'];
- }
- return self::get_site_name();
- }
+ if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('banner', App::$config['system']) && App::$config['system']['banner']) {
+ return App::$config['system']['banner'];
+ }
+ return self::get_site_name();
+ }
- public static function get_project_icon() {
- if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('icon',App::$config['system'])) {
- return App::$config['system']['icon'];
- }
- return z_root() . '/images/' . PLATFORM_NAME . '-64.png';
- }
+ public static function get_project_icon()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('icon', App::$config['system'])) {
+ return App::$config['system']['icon'];
+ }
+ return z_root() . '/images/' . PLATFORM_NAME . '-64.png';
+ }
- public static function get_project_favicon() {
- if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('favicon',App::$config['system'])) {
- return App::$config['system']['favicon'];
- }
- return z_root() . '/images/' . PLATFORM_NAME . '.ico';
- }
+ public static function get_project_favicon()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('favicon', App::$config['system'])) {
+ return App::$config['system']['favicon'];
+ }
+ return z_root() . '/images/' . PLATFORM_NAME . '.ico';
+ }
- public static function get_project_version() {
- if(array_path_exists('system/hide_version', App::$config) && intval(App::$config['system']['hide_version']))
- return '';
- if(is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('std_version',App::$config['system']))
- return App::$config['system']['std_version'];
+ public static function get_project_version()
+ {
+ if (array_path_exists('system/hide_version', App::$config) && intval(App::$config['system']['hide_version'])) {
+ return '';
+ }
+ if (is_array(App::$config) && is_array(App::$config['system']) && array_key_exists('std_version', App::$config['system'])) {
+ return App::$config['system']['std_version'];
+ }
- return self::get_std_version();
- }
+ return self::get_std_version();
+ }
- public static function get_update_version() {
- if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['hide_version'])
- return EMPTY_STR;
- return DB_UPDATE_VERSION;
- }
+ public static function get_update_version()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['hide_version']) {
+ return EMPTY_STR;
+ }
+ return DB_UPDATE_VERSION;
+ }
- public static function get_notify_icon() {
- if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['email_notify_icon_url'])
- return App::$config['system']['email_notify_icon_url'];
- return self::get_project_icon();
- }
+ public static function get_notify_icon()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['email_notify_icon_url']) {
+ return App::$config['system']['email_notify_icon_url'];
+ }
+ return self::get_project_icon();
+ }
- public static function get_site_icon() {
- if(is_array(App::$config) && is_array(App::$config['system']) && isset(App::$config['system']['site_icon_url']) && App::$config['system']['site_icon_url'])
- return App::$config['system']['site_icon_url'];
- return self::get_project_icon();
- }
+ public static function get_site_icon()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && isset(App::$config['system']['site_icon_url']) && App::$config['system']['site_icon_url']) {
+ return App::$config['system']['site_icon_url'];
+ }
+ return self::get_project_icon();
+ }
- public static function get_site_favicon() {
- if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['site_favicon_url'])
- return App::$config['system']['site_favicon_url'];
- return self::get_project_favicon();
- }
+ public static function get_site_favicon()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['site_favicon_url']) {
+ return App::$config['system']['site_favicon_url'];
+ }
+ return self::get_project_favicon();
+ }
- public static function get_project_link() {
- if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_link'])
- return App::$config['system']['project_link'];
- return 'https://zotlabs.com/' . PLATFORM_NAME;
- }
+ public static function get_project_link()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_link']) {
+ return App::$config['system']['project_link'];
+ }
+ return 'https://zotlabs.com/' . PLATFORM_NAME;
+ }
- public static function get_project_srclink() {
- if(is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_srclink'])
- return App::$config['system']['project_srclink'];
- return 'https://codeberg.org/zot/' . PLATFORM_NAME;
- }
+ public static function get_project_srclink()
+ {
+ if (is_array(App::$config) && is_array(App::$config['system']) && App::$config['system']['project_srclink']) {
+ return App::$config['system']['project_srclink'];
+ }
+ return 'https://codeberg.org/zot/' . PLATFORM_NAME;
+ }
- public static function ebs() {
- if(defined('EBSSTATE')) {
- return EBSSTATE;
- }
- return 'armed';
- }
+ public static function ebs()
+ {
+ if (defined('EBSSTATE')) {
+ return EBSSTATE;
+ }
+ return 'armed';
+ }
- public static function get_zot_revision() {
- $x = [ 'revision' => ZOT_REVISION ];
- call_hooks('zot_revision',$x);
- return $x['revision'];
- }
+ public static function get_zot_revision()
+ {
+ $x = [ 'revision' => ZOT_REVISION ];
+ call_hooks('zot_revision', $x);
+ return $x['revision'];
+ }
- public static function get_std_version() {
- if(defined('STD_VERSION'))
- return STD_VERSION;
- return '0.0.0';
- }
+ public static function get_std_version()
+ {
+ if (defined('STD_VERSION')) {
+ return STD_VERSION;
+ }
+ return '0.0.0';
+ }
- public static function compatible_project($p) {
+ public static function compatible_project($p)
+ {
- if (in_array(strtolower($p),['hubzilla', 'zap', 'red', 'misty', 'mistpark', 'redmatrix', 'osada', 'roadhouse'])) {
- return true;
- }
- return false;
- }
+ if (in_array(strtolower($p), ['hubzilla', 'zap', 'red', 'misty', 'mistpark', 'redmatrix', 'osada', 'roadhouse'])) {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php
index 22e614002..6b4e32952 100644
--- a/Zotlabs/Lib/ThreadItem.php
+++ b/Zotlabs/Lib/ThreadItem.php
@@ -1,4 +1,6 @@
-data = $data;
- $this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
- $this->threaded = get_config('system','thread_allow',true);
-
- $observer = App::get_observer();
-
- // Prepare the children
- if($data['children']) {
- foreach($data['children'] as $item) {
-
- /*
- * Only add those that will be displayed
- */
-
- if(! visible_activity($item)) {
- continue;
- }
-
- // this is a quick hack to hide ActivityPub DMs that we should not be allowed to see
- // but may have been forwarded as part of a conversation
-
- if(intval($item['item_private']) && (intval($item['item_restrict']) & 1 ) && $item['mid'] !== $item['parent_mid']) {
- if(! $observer) {
- continue;
- }
- }
-
- $child = new ThreadItem($item);
- $this->add_child($child);
- }
- }
-
- // allow a site to configure the order and content of the reaction emoji list
- if($this->toplevel) {
- $x = get_config('system','reactions');
- if($x && is_array($x) && count($x)) {
- $this->reactions = $x;
- }
- }
- }
-
- /**
- * Get data in a form usable by a conversation template
- *
- * Returns:
- * _ The data requested on success
- * _ false on failure
- */
-
- public function get_template_data($conv_responses, $thread_level = 1) {
-
- $result = [];
-
- $item = $this->get_data();
-
- $commentww = '';
- $sparkle = '';
- $buttons = '';
- $dropping = false;
- $star = false;
- $isstarred = "unstarred fa-star-o";
- $is_comment = false;
- $is_item = false;
- $osparkle = '';
- $total_children = $this->count_descendants();
- $unseen_comments = ((isset($item['real_uid']) && $item['real_uid']) ? 0 : $this->count_unseen_descendants());
- $privacy_warning = false;
-
- $conv = $this->get_conversation();
- $observer = $conv->get_observer();
-
- $lock = (((intval($item['item_private'])) || (($item['uid'] == local_channel()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
- || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
- ? t('Private Message')
- : false);
-
- $locktype = $item['item_private'];
-
- $shareable = ((($conv->get_profile_owner() == local_channel() && local_channel()) && (! intval($item['item_private']))) ? true : false);
-
- // allow an exemption for sharing stuff from your private feeds
- if($item['author']['xchan_network'] === 'rss')
- $shareable = true;
-
- // @fixme
- // Have recently added code to properly handle polls in group reshares by redirecting all of the poll responses to the group.
- // Sharing a poll using a regular embedded share is harder because the poll will need to fork. This is due to comment permissions.
- // The original poll author may not accept responses from strangers. Forking the poll will receive responses from the sharer's
- // followers, but there's no elegant way to merge these two sets of results together. For now, we'll disable sharing polls.
-
- if ($item['obj_type'] === 'Question') {
- $shareable = false;
- }
-
-
- if ($item['item_restrict'] & 2) {
- $privacy_warning = true;
- $lock = t('This comment is part of a private conversation, yet was shared with the public. Discretion advised.');
- }
-
- $mode = $conv->get_mode();
-
- $edlink = 'editpost';
-
- if(local_channel() && $observer['xchan_hash'] === $item['author_xchan'])
- $edpost = array(z_root() . '/' . $edlink . '/' . $item['id'], t('Edit'));
- else
- $edpost = false;
-
- if(local_channel() && $observer['xchan_hash'] === $item['owner_xchan'])
- $myconv = true;
- else
- $myconv = false;
-
-
- if($item['verb'] === 'Announce') {
- $edpost = false;
- }
-
-
- if ($observer && $observer['xchan_hash']
- && ( $observer['xchan_hash'] == $this->get_data_value('author_xchan')
- || $observer['xchan_hash'] == $this->get_data_value('owner_xchan')
- || $observer['xchan_hash'] == $this->get_data_value('source_xchan')
- || $this->get_data_value('uid') == local_channel()))
- $dropping = true;
-
-
- if(array_key_exists('real_uid',$item)) {
- $edpost = false;
- $dropping = false;
- }
-
-
- if($dropping) {
- $drop = array(
- 'dropping' => $dropping,
- 'delete' => t('Delete'),
- );
- }
- elseif(is_site_admin()) {
- $drop = [ 'dropping' => true, 'delete' => t('Admin Delete') ];
- }
-
- if(isset($observer_is_pageowner) && $observer_is_pageowner) {
- $multidrop = array(
- 'select' => t('Select'),
- );
- }
-
- $filer = ((($conv->get_profile_owner() == local_channel()) && (! array_key_exists('real_uid',$item))) ? t('Save to Folder') : false);
-
- $profile_avatar = $item['author']['xchan_photo_m'];
- $profile_link = chanlink_hash($item['author_xchan']);
- $profile_name = $item['author']['xchan_name'];
-
- $profile_addr = $item['author']['xchan_addr'] ? $item['author']['xchan_addr'] : $item['author']['xchan_url'];
-
- $location = format_location($item);
- $isevent = false;
- $attend = null;
- $canvote = false;
-
- // process action responses - e.g. like/dislike/attend/agree/whatever
- $response_verbs = [ 'like', 'dislike' ];
-
- if($item['obj_type'] === ACTIVITY_OBJ_EVENT) {
- $response_verbs[] = 'attendyes';
- $response_verbs[] = 'attendno';
- $response_verbs[] = 'attendmaybe';
- if($this->is_commentable() && $observer) {
- $isevent = true;
- $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
- $undo_attend = t('Undo attendance');
- }
- }
-
- $responses = get_responses($conv_responses,$response_verbs,$this,$item);
-
- $my_responses = [];
- foreach($response_verbs as $v) {
- $my_responses[$v] = ((isset($conv_responses[$v][$item['mid'] . '-m']) && $conv_responses[$v][$item['mid'] . '-m']) ? 1 : 0);
- }
-
- $like_count = ((x($conv_responses['like'],$item['mid'])) ? $conv_responses['like'][$item['mid']] : '');
- $like_list = ((x($conv_responses['like'],$item['mid'])) ? $conv_responses['like'][$item['mid'] . '-l'] : '');
- if (($like_list) && (count($like_list) > MAX_LIKERS)) {
- $like_list_part = array_slice($like_list, 0, MAX_LIKERS);
- array_push($like_list_part, '' . t('View all') . '');
- } else {
- $like_list_part = '';
- }
- if(get_config('system','show_like_counts',true)) {
- $like_button_label = tt('Like','Likes',$like_count,'noun');
- }
- else {
- $like_button_label = t('Likes','noun');
- }
-
- $dislike_count = ((x($conv_responses['dislike'],$item['mid'])) ? $conv_responses['dislike'][$item['mid']] : '');
- $dislike_list = ((x($conv_responses['dislike'],$item['mid'])) ? $conv_responses['dislike'][$item['mid'] . '-l'] : '');
- if(get_config('system','show_like_counts',true)) {
- $dislike_button_label = tt('Dislike','Dislikes',$dislike_count,'noun');
- }
- else {
- $dislike_button_label = t('Dislikes','noun');
- }
-
- if (($dislike_list) && (count($dislike_list) > MAX_LIKERS)) {
- $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
- array_push($dislike_list_part, '' . t('View all') . '');
- } else {
- $dislike_list_part = '';
- }
-
-
- $showlike = ((x($conv_responses['like'],$item['mid'])) ? format_like($conv_responses['like'][$item['mid']],$conv_responses['like'][$item['mid'] . '-l'],'like',$item['mid']) : '');
- $showdislike = ((x($conv_responses['dislike'],$item['mid']))
- ? format_like($conv_responses['dislike'][$item['mid']],$conv_responses['dislike'][$item['mid'] . '-l'],'dislike',$item['mid']) : '');
-
- /*
- * We should avoid doing this all the time, but it depends on the conversation mode
- * And the conv mode may change when we change the conv, or it changes its mode
- * Maybe we should establish a way to be notified about conversation changes
- */
-
- $this->check_wall_to_wall();
-
- if($this->is_toplevel()) {
- if(local_channel() && $conv->get_profile_owner() == local_channel() && (! array_key_exists('real_uid',$item))) {
- $star = [
- 'toggle' => t('Save'),
- 'isstarred' => ((intval($item['item_starred'])) ? true : false),
- ];
- }
- }
- else {
- $is_comment = true;
- }
-
-
- $verified = (intval($item['item_verified']) ? t('Message signature validated') : '');
- $forged = ((($item['sig']) && (! intval($item['item_verified']))) ? t('Message signature incorrect') : '');
- $unverified = '' ; // (($this->is_wall_to_wall() && (! intval($item['item_verified']))) ? t('Message cannot be verified') : '');
-
-
- if($conv->get_profile_owner() == local_channel()) {
- $tagger = array(
- 'tagit' => t("Add Tag"),
- 'classtagger' => "",
- );
- }
-
- $has_bookmarks = false;
- if(isset($item['term']) && is_array($item['term'])) {
- foreach($item['term'] as $t) {
- if($t['ttype'] == TERM_BOOKMARK)
- $has_bookmarks = true;
- }
- }
-
- $has_event = false;
- if(($item['obj_type'] === ACTIVITY_OBJ_EVENT) && $conv->get_profile_owner() == local_channel())
- $has_event = true;
-
- if($this->is_commentable() && $observer) {
- $like = array( t('I like this'), t('Undo like'));
- $dislike = array( t('I don\'t like this'), t('Undo dislike') );
- }
-
- $share = $embed = EMPTY_STR;
-
- if ($shareable) {
- $share = t('Repeat This');
- $embed = t('Share this');
- }
-
- $dreport = '';
-
- $keep_reports = intval(get_config('system','expire_delivery_reports'));
- if($keep_reports === 0)
- $keep_reports = 10;
-
- if((! get_config('system','disable_dreport')) && strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC',"now - $keep_reports days")) > 0) {
- $dreport = t('Delivery Report');
- $dreport_link = gen_link_id($item['mid']);
- }
- $is_new = false;
-
- if (strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) {
- $is_new = true;
- }
-
- localize_item($item);
-
- $opts = [];
- if ($this->is_wall_to_wall()) {
- if ($this->owner_censored) {
- $opts['censored'] = true;
- }
- }
-
- $body = prepare_body($item,true,$opts);
-
- // $viewthread (below) is only valid in list mode. If this is a channel page, build the thread viewing link
- // since we can't depend on llink or plink pointing to the right local location.
-
- $owner_address = substr($item['owner']['xchan_addr'],0,strpos($item['owner']['xchan_addr'],'@'));
- $viewthread = $item['llink'];
- if($conv->get_mode() === 'channel')
- $viewthread = z_root() . '/channel/' . $owner_address . '?f=&mid=' . urlencode(gen_link_id($item['mid']));
-
- $comment_count_txt = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
- $list_unseen_txt = (($unseen_comments) ? sprintf( t('%d unseen'),$unseen_comments) : '');
-
- $children = $this->get_children();
-
-
- $has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false);
-
- $dropdown_extras_arr = [ 'item' => $item , 'dropdown_extras' => '' ];
- call_hooks('dropdown_extras',$dropdown_extras_arr);
- $dropdown_extras = $dropdown_extras_arr['dropdown_extras'];
-
- // Pinned item processing
- $allowed_type = (in_array($item['item_type'], get_config('system', 'pin_types', [ ITEM_TYPE_POST ])) ? true : false);
- $pinned_items = ($allowed_type ? get_pconfig($item['uid'], 'pinned', $item['item_type'], []) : []);
- $pinned = ((! empty($pinned_items) && in_array($item['mid'], $pinned_items)) ? true : false);
-
- $tmp_item = array(
- 'template' => $this->get_template(),
- 'mode' => $mode,
- 'item_type' => intval($item['item_type']),
- 'comment_order' => $item['comment_order'],
- 'parent' => $this->get_data_value('parent'),
- 'collapsed' => ((intval($item['comment_order']) > 3) ? true : false),
- 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
- 'body' => $body['html'],
- 'tags' => $body['tags'],
- 'categories' => $body['categories'],
- 'mentions' => $body['mentions'],
- 'attachments' => $body['attachments'],
- 'folders' => $body['folders'],
- 'text' => strip_tags($body['html']),
- 'id' => $this->get_id(),
- 'mid' => $item['mid'],
- 'isevent' => $isevent,
- 'attend' => $attend,
- 'undo_attend' => $undo_attend,
- 'consensus' => '',
- 'conlabels' => '',
- 'canvote' => $canvote,
- 'linktitle' => sprintf( t('View %s\'s profile - %s'), $profile_name, (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url'])),
- 'olinktitle' => sprintf( t('View %s\'s profile - %s'), $this->get_owner_name(), (($item['owner']['xchan_addr']) ? $item['owner']['xchan_addr'] : $item['owner']['xchan_url'])),
- 'llink' => $item['llink'],
- 'viewthread' => $viewthread,
- 'to' => t('to'),
- 'via' => t('via'),
- 'wall' => t('Wall-to-Wall'),
- 'vwall' => t('via Wall-To-Wall:'),
- 'profile_url' => $profile_link,
- 'thread_action_menu' => thread_action_menu($item,$conv->get_mode()),
- 'thread_author_menu' => thread_author_menu($item,$conv->get_mode()),
- 'dreport' => $dreport,
- 'dreport_link' => ((isset($dreport_link) && $dreport_link) ? $dreport_link : EMPTY_STR),
- 'myconv' => $myconv,
- 'name' => $profile_name,
- 'thumb' => $profile_avatar,
- 'osparkle' => $osparkle,
- 'sparkle' => $sparkle,
- 'title' => $item['title'],
- 'title_tosource' => get_pconfig($conv->get_profile_owner(),'system','title_tosource'),
- 'ago' => relative_date($item['created']),
- 'app' => $item['app'],
- 'str_app' => sprintf( t('from %s'), $item['app']),
- 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'),
- 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
- 'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''),
- 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''),
- 'lock' => $lock,
- 'locktype' => $locktype,
- 'delayed' => $item['item_delayed'],
- 'privacy_warning' => $privacy_warning,
- 'verified' => $verified,
- 'unverified' => $unverified,
- 'forged' => $forged,
- 'location' => $location,
- 'divider' => get_pconfig($conv->get_profile_owner(),'system','item_divider'),
- 'attend_label' => t('Attend'),
- 'attend_title' => t('Attendance Options'),
- 'vote_label' => t('Vote'),
- 'vote_title' => t('Voting Options'),
- 'comment_lbl' => (($this->is_commentable() && $observer) ? t('Reply') : ''),
- 'is_comment' => $is_comment,
- 'is_new' => $is_new,
- 'mod_display' => ((argv(0) === 'display') ? true : false), // comments are not collapsed when using mod_display
- 'owner_url' => $this->get_owner_url(),
- 'owner_photo' => $this->get_owner_photo(),
- 'owner_name' => $this->get_owner_name(),
- 'photo' => $body['photo'],
- 'event' => $body['event'],
- 'has_tags' => $has_tags,
- 'reactions' => $this->reactions,
-
- // Item toolbar buttons
-
- 'emojis' => '', // deprecated - use your operating system or a browser plugin
- 'like' => $like,
- 'dislike' => $dislike,
- 'share' => $share,
- 'embed' => $embed,
- 'rawmid' => $item['mid'],
- 'plink' => get_plink($item),
- 'edpost' => $edpost, // ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
- 'star' => $star,
- 'tagger' => ((feature_enabled($conv->get_profile_owner(),'commtag')) ? $tagger : ''),
- 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''),
- 'pinned' => ($pinned ? t('Pinned post') : ''),
- 'pinnable' => (($this->is_toplevel() && local_channel() && $item['owner_xchan'] == $observer['xchan_hash'] && $allowed_type && $item['item_private'] == 0 && $item['item_delayed'] == 0) ? '1' : ''),
- 'pinme' => ($pinned ? t('Unpin this post') : t('Pin this post')),
- 'isdraft' => boolval($item['item_unpublished']),
- 'draft_txt' => t('Saved draft'),
- 'bookmark' => (($conv->get_profile_owner() == local_channel() && local_channel() && $has_bookmarks) ? t('Save Bookmarks') : ''),
- 'addtocal' => (($has_event && ! $item['resource_id']) ? t('Add to Calendar') : ''),
- 'drop' => $drop,
- 'multidrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $multidrop : ''),
- 'dropdown_extras' => $dropdown_extras,
-
- // end toolbar buttons
-
- 'unseen_comments' => $unseen_comments,
- 'comment_count' => $total_children,
- 'comment_count_txt' => $comment_count_txt,
- 'list_unseen_txt' => $list_unseen_txt,
- 'markseen' => t('Mark all seen'),
- 'responses' => $responses,
- 'my_responses' => $my_responses,
- 'like_count' => $like_count,
- 'like_list' => $like_list,
- 'like_list_part' => $like_list_part,
- 'like_button_label' => $like_button_label,
- 'like_modal_title' => t('Likes','noun'),
- 'dislike_modal_title' => t('Dislikes','noun'),
- 'dislike_count' => $dislike_count,
- 'dislike_list' => $dislike_list,
- 'dislike_list_part' => $dislike_list_part,
- 'dislike_button_label' => $dislike_button_label,
- 'modal_dismiss' => t('Close'),
- 'showlike' => $showlike,
- 'showdislike' => $showdislike,
- 'comment' => ($item['item_delayed'] ? '' : $this->get_comment_box()),
- 'previewing' => ($conv->is_preview() ? true : false ),
- 'preview_lbl' => t('This is an unsaved preview'),
- 'wait' => t('Please wait'),
- 'submid' => str_replace(['+','='], ['',''], base64_encode($item['mid'])),
- 'thread_level' => $thread_level,
- 'indentpx' => intval(get_pconfig(local_channel(),'system','thread_indent_px',get_config('system','thread_indent_px',0))),
- 'thread_max' => intval(get_config('system','thread_maxlevel',20)) + 1
- );
-
- $arr = array('item' => $item, 'output' => $tmp_item);
- call_hooks('display_item', $arr);
-
- $result = $arr['output'];
-
- $result['children'] = [];
-
- if (local_channel() && get_pconfig(local_channel(),'system','activitypub',get_config('system','activitypub', ACTIVITYPUB_ENABLED))) {
- // place to store all the author addresses (links if not available) in the thread so we can auto-mention them in JS.
- $result['authors'] = [];
- // fix to add in sub-replies if replying to a comment on your own post from the top level.
- if ($observer && ($profile_addr === $observer['xchan_hash'] || $profile_addr === $observer['xchan_addr'])) {
- // ignore it
- }
- else {
- $result['authors'][] = $profile_addr;
- }
-
- // Add any mentions from the immediate parent, unless they are mentions of the current viewer or duplicates
- if (isset($item['term']) && is_array($item['term'])) {
- $additional_mentions = [];
- foreach ($item['term'] as $t) {
- if ($t['ttype'] == TERM_MENTION) {
- $additional_mentions[] = ((($position = strpos($t['url'],'url=')) !== false) ? urldecode(substr($t['url'],$position + 4)) : $t['url']);
+class ThreadItem
+{
+
+ public $data = [];
+ private $template = 'conv_item.tpl';
+ private $comment_box_template = 'comment_item.tpl';
+ private $commentable = false;
+ // list of supported reaction emojis - a site can over-ride this via config system.reactions
+ // Deprecated. Use your operating system or a browser plugin.
+ private $reactions = ['1f60a','1f44f','1f37e','1f48b','1f61e','2665','1f606','1f62e','1f634','1f61c','1f607','1f608'];
+ private $toplevel = false;
+ private $children = [];
+ private $parent = null;
+ private $conversation = null;
+ private $redirect_url = null;
+ private $owner_url = '';
+ private $owner_photo = '';
+ private $owner_name = '';
+ private $owner_censored = false;
+ private $wall_to_wall = false;
+ private $threaded = false;
+ private $visiting = false;
+ private $channel = null;
+ private $display_mode = 'normal';
+ private $reload = '';
+
+
+ public function __construct($data)
+ {
+
+ $this->data = $data;
+ $this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
+ $this->threaded = get_config('system', 'thread_allow', true);
+
+ $observer = App::get_observer();
+
+ // Prepare the children
+ if ($data['children']) {
+ foreach ($data['children'] as $item) {
+ /*
+ * Only add those that will be displayed
+ */
+
+ if (! visible_activity($item)) {
+ continue;
+ }
+
+ // this is a quick hack to hide ActivityPub DMs that we should not be allowed to see
+ // but may have been forwarded as part of a conversation
+
+ if (intval($item['item_private']) && (intval($item['item_restrict']) & 1 ) && $item['mid'] !== $item['parent_mid']) {
+ if (! $observer) {
+ continue;
}
- }
- if ($additional_mentions) {
- $r = q("select hubloc_addr, hubloc_id_url, hubloc_hash from hubloc where hubloc_id_url in (" . protect_sprintf(stringify_array($additional_mentions, true)) . ") ");
- if ($r) {
- foreach ($r as $rv) {
- $ment = (($r[0]['hubloc_addr']) ? $r[0]['hubloc_addr'] : $r[0]['hubloc_id_url']);
- if ($ment) {
- if ($observer && $observer['xchan_hash'] !== $rv['hubloc_hash'] && ! in_array($ment,$result['authors'])) {
- $result['authors'][] = $ment;
- }
- }
- }
- }
- }
- }
- }
-
- $nb_children = count($children);
-
- $total_children = $this->count_visible_descendants();
-
- $visible_comments = get_config('system', 'expanded_comments', 3);
-
- if(($this->get_display_mode() === 'normal') && ($nb_children > 0)) {
- if ($children) {
- foreach($children as $child) {
- $xz = $child->get_template_data($conv_responses, $thread_level + 1);
- $result['children'][] = $xz;
- }
- }
- // Collapse
- if($total_children > $visible_comments && $thread_level == 1) {
- $result['children'][0]['comment_firstcollapsed'] = true;
- $result['children'][0]['num_comments'] = $comment_count_txt;
- $result['children'][0]['hide_text'] = sprintf( t('%s show all'), '');
- }
- }
-
- $result['private'] = $item['item_private'];
- $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
-
- if($this->is_threaded()) {
- $result['flatten'] = false;
- $result['threaded'] = true;
- }
- else {
- $result['flatten'] = true;
- $result['threaded'] = false;
- }
-
- return $result;
- }
-
- public function get_id() {
- return $this->get_data_value('id');
- }
-
- public function get_display_mode() {
- return $this->display_mode;
- }
-
- public function set_display_mode($mode) {
- $this->display_mode = $mode;
- }
-
- public function is_threaded() {
- return $this->threaded;
- }
-
- public function get_author() {
- $xchan = $this->get_data_value('author');
- if($xchan['xchan_addr']) {
- return $xchan['xchan_addr'];
- }
- return $xchan['xchan_url'];
- }
-
- public function set_reload($val) {
- $this->reload = $val;
- }
-
- public function get_reload() {
- return $this->reload;
- }
-
- public function set_commentable($val) {
- $this->commentable = $val;
- foreach($this->get_children() as $child)
- $child->set_commentable($val);
- }
-
- public function is_commentable() {
- return $this->commentable;
- }
-
- /**
- * Add a child item
- */
- public function add_child($item) {
- $item_id = $item->get_id();
- if(!$item_id) {
- logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
- return false;
- }
- if($this->get_child($item->get_id())) {
- logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
- return false;
- }
-
- /*
- * Only add what will be displayed
- */
-
- if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
- return false;
- }
-
- $item->set_parent($this);
- $this->children[] = $item;
- return end($this->children);
- }
-
- /**
- * Get a child by its ID
- */
-
- public function get_child($id) {
- foreach($this->get_children() as $child) {
- if($child->get_id() == $id)
- return $child;
- }
- return null;
- }
-
- /**
- * Get all our children
- */
-
- public function get_children() {
- return $this->children;
- }
-
- /**
- * Set our parent
- */
- protected function set_parent($item) {
- $parent = $this->get_parent();
- if($parent) {
- $parent->remove_child($this);
- }
- $this->parent = $item;
- $this->set_conversation($item->get_conversation());
- }
-
- /**
- * Remove our parent
- */
-
- protected function remove_parent() {
- $this->parent = null;
- $this->conversation = null;
- }
-
- /**
- * Remove a child
- */
-
- public function remove_child($item) {
- $id = $item->get_id();
- foreach($this->get_children() as $key => $child) {
- if($child->get_id() == $id) {
- $child->remove_parent();
- unset($this->children[$key]);
- // Reindex the array, in order to make sure there won't be any trouble on loops using count()
- $this->children = array_values($this->children);
- return true;
- }
- }
- logger('[WARN] Item::remove_child : Item is not a child ('. $id .').', LOGGER_DEBUG);
- return false;
- }
-
- /**
- * Get parent item
- */
- protected function get_parent() {
- return $this->parent;
- }
-
- /**
- * set conversation
- */
- public function set_conversation($conv) {
- $previous_mode = ($this->conversation ? $this->conversation->get_mode() : '');
-
- $this->conversation = $conv;
-
- // Set it on our children too
- foreach($this->get_children() as $child)
- $child->set_conversation($conv);
- }
-
- /**
- * get conversation
- */
- public function get_conversation() {
- return $this->conversation;
- }
-
- /**
- * Get raw data
- *
- * We shouldn't need this
- */
- public function get_data() {
- return $this->data;
- }
-
- /**
- * Get a data value
- *
- * Returns:
- * _ value on success
- * _ false on failure
- */
- public function get_data_value($name) {
- if(!isset($this->data[$name])) {
-// logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG);
- return false;
- }
-
- return $this->data[$name];
- }
-
- /**
- * Get template
- */
- public function get_template() {
- return $this->template;
- }
-
-
- public function set_template($t) {
- $this->template = $t;
- }
-
- /**
- * Check if this is a toplevel post
- */
- private function is_toplevel() {
- return $this->toplevel;
- }
-
- /**
- * Count the total of our descendants
- */
- private function count_descendants() {
- $children = $this->get_children();
- $total = count($children);
- if($total > 0) {
- foreach($children as $child) {
- $total += $child->count_descendants();
- }
- }
- return $total;
- }
-
- public function count_visible_descendants() {
- $total = 0;
- $children = $this->get_children();
- if ($children) {
- foreach ($children as $child) {
- if (! visible_activity($child->data)) {
- continue;
- }
- $total ++;
- $total += $child->count_visible_descendants();
- }
- }
- return $total;
- }
-
-
- private function label_descendants($count = 0) {
- if(! array_key_exists('sequence',$this->data)) {
- if($count) {
- $count ++;
- }
- $this->data['sequence'] = $count;
- }
- logger('labelled: ' . print_r($this->data,true), LOGGER_DATA);
- $children = $this->get_children();
- $total = count($children);
- if($total > 0) {
- foreach($children as $child) {
- if(! visible_activity($child->data)) {
- continue;
- }
- if(! array_key_exists('sequence',$this->data)) {
- $count ++;
- $child->data['sequence'] = $count;
- logger('labelled_child: ' . print_r($child->data,true), LOGGER_DATA);
- }
- $child->label_descendants($count);
- }
- }
- }
-
- private function count_unseen_descendants() {
- $children = $this->get_children();
- $total = count($children);
- if($total > 0) {
- $total = 0;
- foreach($children as $child) {
- if(! visible_activity($child->data)) {
- continue;
- }
- if(intval($child->data['item_unseen']))
- $total ++;
- }
- }
- return $total;
- }
-
-
- /**
- * Get the template for the comment box
- */
- private function get_comment_box_template() {
- return $this->comment_box_template;
- }
-
- /**
- * Get the comment box
- *
- * Returns:
- * _ The comment box string (empty if no comment box)
- * _ false on failure
- */
- private function get_comment_box($indent = 0) {
-
- if(!$this->is_toplevel() && !get_config('system','thread_allow',true)) {
- return '';
- }
-
- $comment_box = '';
- $conv = $this->get_conversation();
-
-// logger('Commentable conv: ' . $conv->is_commentable());
-
- if(! $this->is_commentable())
- return;
-
- $template = get_markup_template($this->get_comment_box_template());
-
- $observer = $conv->get_observer();
-
- $arr = array('comment_buttons' => '','id' => $this->get_id());
- call_hooks('comment_buttons',$arr);
- $comment_buttons = $arr['comment_buttons'];
-
- $feature_auto_save_draft = ((feature_enabled($conv->get_profile_owner(), 'auto_save_draft')) ? "true" : "false");
- $permanent_draft = ((intval($conv->get_profile_owner()) === intval(local_channel()) && Apps::system_app_installed($conv->get_profile_owner(),'Drafts')) ? ('Save draft') : EMPTY_STR);
-
-
-
- $comment_box = replace_macros($template,array(
- '$return_path' => '',
- '$threaded' => $this->is_threaded(),
- '$jsreload' => $conv->reload,
- '$type' => (($conv->get_mode() === 'channel') ? 'wall-comment' : 'net-comment'),
- '$id' => $this->get_id(),
- '$parent' => $this->get_id(),
- '$comment_buttons' => $comment_buttons,
- '$profile_uid' => $conv->get_profile_owner(),
- '$mylink' => $observer['xchan_url'],
- '$mytitle' => t('This is you'),
- '$myphoto' => $observer['xchan_photo_s'],
- '$comment' => t('Comment'),
- '$submit' => t('Submit'),
- '$edat' => EMPTY_STR,
- '$edbold' => t('Bold'),
- '$editalic' => t('Italic'),
- '$eduline' => t('Underline'),
- '$edquote' => t('Quote'),
- '$edcode' => t('Code'),
- '$edimg' => t('Image'),
- '$edatt' => t('Attach/Upload file'),
- '$edurl' => t('Insert Link'),
- '$edvideo' => t('Video'),
- '$preview' => t('Preview'),
- '$reset' => t('Reset'),
- '$indent' => $indent,
- '$can_upload' => (perm_is_allowed($conv->get_profile_owner(),get_observer_hash(),'write_storage') && $conv->is_uploadable()),
- '$feature_encrypt' => ((Apps::system_app_installed($conv->get_profile_owner(),'Secrets')) ? true : false),
- '$feature_markup' => ((Apps::system_app_installed($conv->get_profile_owner(),'Markup')) ? true : false),
- '$encrypt' => t('Encrypt text'),
- '$cipher' => $conv->get_cipher(),
- '$sourceapp' => App::$sourcename,
- '$observer' => get_observer_hash(),
- '$anoncomments' => ((($conv->get_mode() === 'channel' || $conv->get_mode() === 'display') && perm_is_allowed($conv->get_profile_owner(),'','post_comments')) ? true : false),
- '$anonname' => [ 'anonname', t('Your full name (required)') ],
- '$anonmail' => [ 'anonmail', t('Your email address (required)') ],
- '$anonurl' => [ 'anonurl', t('Your website URL (optional)') ],
- '$auto_save_draft' => $feature_auto_save_draft,
- '$save' => $permanent_draft,
- '$top' => $this->is_toplevel()
- ));
-
- return $comment_box;
- }
-
- private function get_redirect_url() {
- return $this->redirect_url;
- }
-
- /**
- * Check if we are a wall to wall item and set the relevant properties
- */
- protected function check_wall_to_wall() {
- $conv = $this->get_conversation();
- $this->wall_to_wall = false;
- $this->owner_url = '';
- $this->owner_photo = '';
- $this->owner_name = '';
- $this->owner_censored = false;
-
- if($conv->get_mode() === 'channel')
- return;
-
- if($this->is_toplevel() && ($this->get_data_value('author_xchan') != $this->get_data_value('owner_xchan'))) {
- $this->owner_url = chanlink_hash($this->data['owner']['xchan_hash']);
- $this->owner_photo = $this->data['owner']['xchan_photo_m'];
- $this->owner_name = $this->data['owner']['xchan_name'];
- $this->wall_to_wall = true;
- }
-
- // present friend-of-friend conversations from hyperdrive as relayed posts from the first friend
- // we find among the respondents.
-
- if ($this->is_toplevel() && (! $this->data['owner']['abook_id'])) {
- if ($this->data['children']) {
- $friend = $this->find_a_friend($this->data['children']);
- if ($friend) {
- $this->owner_url = $friend['url'];
- $this->owner_photo = $friend['photo'];
- $this->owner_name = $friend['name'];
- $this->owner_censored = $friend['censored'];
- $this->wall_to_wall = true;
- }
- }
- }
- }
-
- private function find_a_friend($items) {
- $ret = null;
- if ($items) {
- foreach ($items as $child) {
- if ($child['author']['abook_id'] && (! intval($child['author']['abook_self']))) {
- return [
- 'url' => chanlink_hash($child['author']['xchan_hash']),
- 'photo' => $child['author']['xchan_photo_m'],
- 'name' => $child['author']['xchan_name'],
- 'censored' => (($child['author']['xchan_censored'] || $child['author']['abook_censor']) ? true : false)
- ];
- if ($child['children']) {
- $ret = $this->find_a_friend($child['children']);
- if ($ret) {
- break;
- }
- }
- }
- }
- }
- return $ret;
- }
-
-
- private function is_wall_to_wall() {
- return $this->wall_to_wall;
- }
-
- private function get_owner_url() {
- return $this->owner_url;
- }
-
- private function get_owner_photo() {
- return $this->owner_photo;
- }
-
- private function get_owner_name() {
- return $this->owner_name;
- }
-
- private function is_visiting() {
- return $this->visiting;
- }
-
-
-
-
+ }
+
+ $child = new ThreadItem($item);
+ $this->add_child($child);
+ }
+ }
+
+ // allow a site to configure the order and content of the reaction emoji list
+ if ($this->toplevel) {
+ $x = get_config('system', 'reactions');
+ if ($x && is_array($x) && count($x)) {
+ $this->reactions = $x;
+ }
+ }
+ }
+
+ /**
+ * Get data in a form usable by a conversation template
+ *
+ * Returns:
+ * _ The data requested on success
+ * _ false on failure
+ */
+
+ public function get_template_data($conv_responses, $thread_level = 1)
+ {
+
+ $result = [];
+
+ $item = $this->get_data();
+
+ $commentww = '';
+ $sparkle = '';
+ $buttons = '';
+ $dropping = false;
+ $star = false;
+ $isstarred = "unstarred fa-star-o";
+ $is_comment = false;
+ $is_item = false;
+ $osparkle = '';
+ $total_children = $this->count_descendants();
+ $unseen_comments = ((isset($item['real_uid']) && $item['real_uid']) ? 0 : $this->count_unseen_descendants());
+ $privacy_warning = false;
+
+ $conv = $this->get_conversation();
+ $observer = $conv->get_observer();
+
+ $lock = (((intval($item['item_private'])) || (($item['uid'] == local_channel()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
+ || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
+ ? t('Private Message')
+ : false);
+
+ $locktype = $item['item_private'];
+
+ $shareable = ((($conv->get_profile_owner() == local_channel() && local_channel()) && (! intval($item['item_private']))) ? true : false);
+
+ // allow an exemption for sharing stuff from your private feeds
+ if ($item['author']['xchan_network'] === 'rss') {
+ $shareable = true;
+ }
+
+ // @fixme
+ // Have recently added code to properly handle polls in group reshares by redirecting all of the poll responses to the group.
+ // Sharing a poll using a regular embedded share is harder because the poll will need to fork. This is due to comment permissions.
+ // The original poll author may not accept responses from strangers. Forking the poll will receive responses from the sharer's
+ // followers, but there's no elegant way to merge these two sets of results together. For now, we'll disable sharing polls.
+
+ if ($item['obj_type'] === 'Question') {
+ $shareable = false;
+ }
+
+
+ if ($item['item_restrict'] & 2) {
+ $privacy_warning = true;
+ $lock = t('This comment is part of a private conversation, yet was shared with the public. Discretion advised.');
+ }
+
+ $mode = $conv->get_mode();
+
+ $edlink = 'editpost';
+
+ if (local_channel() && $observer['xchan_hash'] === $item['author_xchan']) {
+ $edpost = array(z_root() . '/' . $edlink . '/' . $item['id'], t('Edit'));
+ } else {
+ $edpost = false;
+ }
+
+ if (local_channel() && $observer['xchan_hash'] === $item['owner_xchan']) {
+ $myconv = true;
+ } else {
+ $myconv = false;
+ }
+
+
+ if ($item['verb'] === 'Announce') {
+ $edpost = false;
+ }
+
+
+ if (
+ $observer && $observer['xchan_hash']
+ && ( $observer['xchan_hash'] == $this->get_data_value('author_xchan')
+ || $observer['xchan_hash'] == $this->get_data_value('owner_xchan')
+ || $observer['xchan_hash'] == $this->get_data_value('source_xchan')
+ || $this->get_data_value('uid') == local_channel())
+ ) {
+ $dropping = true;
+ }
+
+
+ if (array_key_exists('real_uid', $item)) {
+ $edpost = false;
+ $dropping = false;
+ }
+
+
+ if ($dropping) {
+ $drop = array(
+ 'dropping' => $dropping,
+ 'delete' => t('Delete'),
+ );
+ } elseif (is_site_admin()) {
+ $drop = [ 'dropping' => true, 'delete' => t('Admin Delete') ];
+ }
+
+ if (isset($observer_is_pageowner) && $observer_is_pageowner) {
+ $multidrop = array(
+ 'select' => t('Select'),
+ );
+ }
+
+ $filer = ((($conv->get_profile_owner() == local_channel()) && (! array_key_exists('real_uid', $item))) ? t('Save to Folder') : false);
+
+ $profile_avatar = $item['author']['xchan_photo_m'];
+ $profile_link = chanlink_hash($item['author_xchan']);
+ $profile_name = $item['author']['xchan_name'];
+
+ $profile_addr = $item['author']['xchan_addr'] ? $item['author']['xchan_addr'] : $item['author']['xchan_url'];
+
+ $location = format_location($item);
+ $isevent = false;
+ $attend = null;
+ $canvote = false;
+
+ // process action responses - e.g. like/dislike/attend/agree/whatever
+ $response_verbs = [ 'like', 'dislike' ];
+
+ if ($item['obj_type'] === ACTIVITY_OBJ_EVENT) {
+ $response_verbs[] = 'attendyes';
+ $response_verbs[] = 'attendno';
+ $response_verbs[] = 'attendmaybe';
+ if ($this->is_commentable() && $observer) {
+ $isevent = true;
+ $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
+ $undo_attend = t('Undo attendance');
+ }
+ }
+
+ $responses = get_responses($conv_responses, $response_verbs, $this, $item);
+
+ $my_responses = [];
+ foreach ($response_verbs as $v) {
+ $my_responses[$v] = ((isset($conv_responses[$v][$item['mid'] . '-m']) && $conv_responses[$v][$item['mid'] . '-m']) ? 1 : 0);
+ }
+
+ $like_count = ((x($conv_responses['like'], $item['mid'])) ? $conv_responses['like'][$item['mid']] : '');
+ $like_list = ((x($conv_responses['like'], $item['mid'])) ? $conv_responses['like'][$item['mid'] . '-l'] : '');
+ if (($like_list) && (count($like_list) > MAX_LIKERS)) {
+ $like_list_part = array_slice($like_list, 0, MAX_LIKERS);
+ array_push($like_list_part, '' . t('View all') . '');
+ } else {
+ $like_list_part = '';
+ }
+ if (get_config('system', 'show_like_counts', true)) {
+ $like_button_label = tt('Like', 'Likes', $like_count, 'noun');
+ } else {
+ $like_button_label = t('Likes', 'noun');
+ }
+
+ $dislike_count = ((x($conv_responses['dislike'], $item['mid'])) ? $conv_responses['dislike'][$item['mid']] : '');
+ $dislike_list = ((x($conv_responses['dislike'], $item['mid'])) ? $conv_responses['dislike'][$item['mid'] . '-l'] : '');
+ if (get_config('system', 'show_like_counts', true)) {
+ $dislike_button_label = tt('Dislike', 'Dislikes', $dislike_count, 'noun');
+ } else {
+ $dislike_button_label = t('Dislikes', 'noun');
+ }
+
+ if (($dislike_list) && (count($dislike_list) > MAX_LIKERS)) {
+ $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
+ array_push($dislike_list_part, '' . t('View all') . '');
+ } else {
+ $dislike_list_part = '';
+ }
+
+
+ $showlike = ((x($conv_responses['like'], $item['mid'])) ? format_like($conv_responses['like'][$item['mid']], $conv_responses['like'][$item['mid'] . '-l'], 'like', $item['mid']) : '');
+ $showdislike = ((x($conv_responses['dislike'], $item['mid']))
+ ? format_like($conv_responses['dislike'][$item['mid']], $conv_responses['dislike'][$item['mid'] . '-l'], 'dislike', $item['mid']) : '');
+
+ /*
+ * We should avoid doing this all the time, but it depends on the conversation mode
+ * And the conv mode may change when we change the conv, or it changes its mode
+ * Maybe we should establish a way to be notified about conversation changes
+ */
+
+ $this->check_wall_to_wall();
+
+ if ($this->is_toplevel()) {
+ if (local_channel() && $conv->get_profile_owner() == local_channel() && (! array_key_exists('real_uid', $item))) {
+ $star = [
+ 'toggle' => t('Save'),
+ 'isstarred' => ((intval($item['item_starred'])) ? true : false),
+ ];
+ }
+ } else {
+ $is_comment = true;
+ }
+
+
+ $verified = (intval($item['item_verified']) ? t('Message signature validated') : '');
+ $forged = ((($item['sig']) && (! intval($item['item_verified']))) ? t('Message signature incorrect') : '');
+ $unverified = '' ; // (($this->is_wall_to_wall() && (! intval($item['item_verified']))) ? t('Message cannot be verified') : '');
+
+
+ if ($conv->get_profile_owner() == local_channel()) {
+ $tagger = array(
+ 'tagit' => t("Add Tag"),
+ 'classtagger' => "",
+ );
+ }
+
+ $has_bookmarks = false;
+ if (isset($item['term']) && is_array($item['term'])) {
+ foreach ($item['term'] as $t) {
+ if ($t['ttype'] == TERM_BOOKMARK) {
+ $has_bookmarks = true;
+ }
+ }
+ }
+
+ $has_event = false;
+ if (($item['obj_type'] === ACTIVITY_OBJ_EVENT) && $conv->get_profile_owner() == local_channel()) {
+ $has_event = true;
+ }
+
+ if ($this->is_commentable() && $observer) {
+ $like = array( t('I like this'), t('Undo like'));
+ $dislike = array( t('I don\'t like this'), t('Undo dislike') );
+ }
+
+ $share = $embed = EMPTY_STR;
+
+ if ($shareable) {
+ $share = t('Repeat This');
+ $embed = t('Share this');
+ }
+
+ $dreport = '';
+
+ $keep_reports = intval(get_config('system', 'expire_delivery_reports'));
+ if ($keep_reports === 0) {
+ $keep_reports = 10;
+ }
+
+ if ((! get_config('system', 'disable_dreport')) && strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', "now - $keep_reports days")) > 0) {
+ $dreport = t('Delivery Report');
+ $dreport_link = gen_link_id($item['mid']);
+ }
+ $is_new = false;
+
+ if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
+ $is_new = true;
+ }
+
+ localize_item($item);
+
+ $opts = [];
+ if ($this->is_wall_to_wall()) {
+ if ($this->owner_censored) {
+ $opts['censored'] = true;
+ }
+ }
+
+ $body = prepare_body($item, true, $opts);
+
+ // $viewthread (below) is only valid in list mode. If this is a channel page, build the thread viewing link
+ // since we can't depend on llink or plink pointing to the right local location.
+
+ $owner_address = substr($item['owner']['xchan_addr'], 0, strpos($item['owner']['xchan_addr'], '@'));
+ $viewthread = $item['llink'];
+ if ($conv->get_mode() === 'channel') {
+ $viewthread = z_root() . '/channel/' . $owner_address . '?f=&mid=' . urlencode(gen_link_id($item['mid']));
+ }
+
+ $comment_count_txt = sprintf(tt('%d comment', '%d comments', $total_children), $total_children);
+ $list_unseen_txt = (($unseen_comments) ? sprintf(t('%d unseen'), $unseen_comments) : '');
+
+ $children = $this->get_children();
+
+
+ $has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false);
+
+ $dropdown_extras_arr = [ 'item' => $item , 'dropdown_extras' => '' ];
+ call_hooks('dropdown_extras', $dropdown_extras_arr);
+ $dropdown_extras = $dropdown_extras_arr['dropdown_extras'];
+
+ // Pinned item processing
+ $allowed_type = (in_array($item['item_type'], get_config('system', 'pin_types', [ ITEM_TYPE_POST ])) ? true : false);
+ $pinned_items = ($allowed_type ? get_pconfig($item['uid'], 'pinned', $item['item_type'], []) : []);
+ $pinned = ((! empty($pinned_items) && in_array($item['mid'], $pinned_items)) ? true : false);
+
+ $tmp_item = array(
+ 'template' => $this->get_template(),
+ 'mode' => $mode,
+ 'item_type' => intval($item['item_type']),
+ 'comment_order' => $item['comment_order'],
+ 'parent' => $this->get_data_value('parent'),
+ 'collapsed' => ((intval($item['comment_order']) > 3) ? true : false),
+ 'type' => implode("", array_slice(explode("/", $item['verb']), -1)),
+ 'body' => $body['html'],
+ 'tags' => $body['tags'],
+ 'categories' => $body['categories'],
+ 'mentions' => $body['mentions'],
+ 'attachments' => $body['attachments'],
+ 'folders' => $body['folders'],
+ 'text' => strip_tags($body['html']),
+ 'id' => $this->get_id(),
+ 'mid' => $item['mid'],
+ 'isevent' => $isevent,
+ 'attend' => $attend,
+ 'undo_attend' => $undo_attend,
+ 'consensus' => '',
+ 'conlabels' => '',
+ 'canvote' => $canvote,
+ 'linktitle' => sprintf(t('View %s\'s profile - %s'), $profile_name, (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url'])),
+ 'olinktitle' => sprintf(t('View %s\'s profile - %s'), $this->get_owner_name(), (($item['owner']['xchan_addr']) ? $item['owner']['xchan_addr'] : $item['owner']['xchan_url'])),
+ 'llink' => $item['llink'],
+ 'viewthread' => $viewthread,
+ 'to' => t('to'),
+ 'via' => t('via'),
+ 'wall' => t('Wall-to-Wall'),
+ 'vwall' => t('via Wall-To-Wall:'),
+ 'profile_url' => $profile_link,
+ 'thread_action_menu' => thread_action_menu($item, $conv->get_mode()),
+ 'thread_author_menu' => thread_author_menu($item, $conv->get_mode()),
+ 'dreport' => $dreport,
+ 'dreport_link' => ((isset($dreport_link) && $dreport_link) ? $dreport_link : EMPTY_STR),
+ 'myconv' => $myconv,
+ 'name' => $profile_name,
+ 'thumb' => $profile_avatar,
+ 'osparkle' => $osparkle,
+ 'sparkle' => $sparkle,
+ 'title' => $item['title'],
+ 'title_tosource' => get_pconfig($conv->get_profile_owner(), 'system', 'title_tosource'),
+ 'ago' => relative_date($item['created']),
+ 'app' => $item['app'],
+ 'str_app' => sprintf(t('from %s'), $item['app']),
+ 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'),
+ 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
+ 'editedtime' => (($item['edited'] != $item['created']) ? sprintf(t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''),
+ 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf(t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : ''),
+ 'lock' => $lock,
+ 'locktype' => $locktype,
+ 'delayed' => $item['item_delayed'],
+ 'privacy_warning' => $privacy_warning,
+ 'verified' => $verified,
+ 'unverified' => $unverified,
+ 'forged' => $forged,
+ 'location' => $location,
+ 'divider' => get_pconfig($conv->get_profile_owner(), 'system', 'item_divider'),
+ 'attend_label' => t('Attend'),
+ 'attend_title' => t('Attendance Options'),
+ 'vote_label' => t('Vote'),
+ 'vote_title' => t('Voting Options'),
+ 'comment_lbl' => (($this->is_commentable() && $observer) ? t('Reply') : ''),
+ 'is_comment' => $is_comment,
+ 'is_new' => $is_new,
+ 'mod_display' => ((argv(0) === 'display') ? true : false), // comments are not collapsed when using mod_display
+ 'owner_url' => $this->get_owner_url(),
+ 'owner_photo' => $this->get_owner_photo(),
+ 'owner_name' => $this->get_owner_name(),
+ 'photo' => $body['photo'],
+ 'event' => $body['event'],
+ 'has_tags' => $has_tags,
+ 'reactions' => $this->reactions,
+
+ // Item toolbar buttons
+
+ 'emojis' => '', // deprecated - use your operating system or a browser plugin
+ 'like' => $like,
+ 'dislike' => $dislike,
+ 'share' => $share,
+ 'embed' => $embed,
+ 'rawmid' => $item['mid'],
+ 'plink' => get_plink($item),
+ 'edpost' => $edpost, // ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
+ 'star' => $star,
+ 'tagger' => ((feature_enabled($conv->get_profile_owner(), 'commtag')) ? $tagger : ''),
+ 'filer' => ((feature_enabled($conv->get_profile_owner(), 'filing')) ? $filer : ''),
+ 'pinned' => ($pinned ? t('Pinned post') : ''),
+ 'pinnable' => (($this->is_toplevel() && local_channel() && $item['owner_xchan'] == $observer['xchan_hash'] && $allowed_type && $item['item_private'] == 0 && $item['item_delayed'] == 0) ? '1' : ''),
+ 'pinme' => ($pinned ? t('Unpin this post') : t('Pin this post')),
+ 'isdraft' => boolval($item['item_unpublished']),
+ 'draft_txt' => t('Saved draft'),
+ 'bookmark' => (($conv->get_profile_owner() == local_channel() && local_channel() && $has_bookmarks) ? t('Save Bookmarks') : ''),
+ 'addtocal' => (($has_event && ! $item['resource_id']) ? t('Add to Calendar') : ''),
+ 'drop' => $drop,
+ 'multidrop' => ((feature_enabled($conv->get_profile_owner(), 'multi_delete')) ? $multidrop : ''),
+ 'dropdown_extras' => $dropdown_extras,
+
+ // end toolbar buttons
+
+ 'unseen_comments' => $unseen_comments,
+ 'comment_count' => $total_children,
+ 'comment_count_txt' => $comment_count_txt,
+ 'list_unseen_txt' => $list_unseen_txt,
+ 'markseen' => t('Mark all seen'),
+ 'responses' => $responses,
+ 'my_responses' => $my_responses,
+ 'like_count' => $like_count,
+ 'like_list' => $like_list,
+ 'like_list_part' => $like_list_part,
+ 'like_button_label' => $like_button_label,
+ 'like_modal_title' => t('Likes', 'noun'),
+ 'dislike_modal_title' => t('Dislikes', 'noun'),
+ 'dislike_count' => $dislike_count,
+ 'dislike_list' => $dislike_list,
+ 'dislike_list_part' => $dislike_list_part,
+ 'dislike_button_label' => $dislike_button_label,
+ 'modal_dismiss' => t('Close'),
+ 'showlike' => $showlike,
+ 'showdislike' => $showdislike,
+ 'comment' => ($item['item_delayed'] ? '' : $this->get_comment_box()),
+ 'previewing' => ($conv->is_preview() ? true : false ),
+ 'preview_lbl' => t('This is an unsaved preview'),
+ 'wait' => t('Please wait'),
+ 'submid' => str_replace(['+','='], ['',''], base64_encode($item['mid'])),
+ 'thread_level' => $thread_level,
+ 'indentpx' => intval(get_pconfig(local_channel(), 'system', 'thread_indent_px', get_config('system', 'thread_indent_px', 0))),
+ 'thread_max' => intval(get_config('system', 'thread_maxlevel', 20)) + 1
+ );
+
+ $arr = array('item' => $item, 'output' => $tmp_item);
+ call_hooks('display_item', $arr);
+
+ $result = $arr['output'];
+
+ $result['children'] = [];
+
+ if (local_channel() && get_pconfig(local_channel(), 'system', 'activitypub', get_config('system', 'activitypub', ACTIVITYPUB_ENABLED))) {
+ // place to store all the author addresses (links if not available) in the thread so we can auto-mention them in JS.
+ $result['authors'] = [];
+ // fix to add in sub-replies if replying to a comment on your own post from the top level.
+ if ($observer && ($profile_addr === $observer['xchan_hash'] || $profile_addr === $observer['xchan_addr'])) {
+ // ignore it
+ } else {
+ $result['authors'][] = $profile_addr;
+ }
+
+ // Add any mentions from the immediate parent, unless they are mentions of the current viewer or duplicates
+ if (isset($item['term']) && is_array($item['term'])) {
+ $additional_mentions = [];
+ foreach ($item['term'] as $t) {
+ if ($t['ttype'] == TERM_MENTION) {
+ $additional_mentions[] = ((($position = strpos($t['url'], 'url=')) !== false) ? urldecode(substr($t['url'], $position + 4)) : $t['url']);
+ }
+ }
+ if ($additional_mentions) {
+ $r = q("select hubloc_addr, hubloc_id_url, hubloc_hash from hubloc where hubloc_id_url in (" . protect_sprintf(stringify_array($additional_mentions, true)) . ") ");
+ if ($r) {
+ foreach ($r as $rv) {
+ $ment = (($r[0]['hubloc_addr']) ? $r[0]['hubloc_addr'] : $r[0]['hubloc_id_url']);
+ if ($ment) {
+ if ($observer && $observer['xchan_hash'] !== $rv['hubloc_hash'] && ! in_array($ment, $result['authors'])) {
+ $result['authors'][] = $ment;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ $nb_children = count($children);
+
+ $total_children = $this->count_visible_descendants();
+
+ $visible_comments = get_config('system', 'expanded_comments', 3);
+
+ if (($this->get_display_mode() === 'normal') && ($nb_children > 0)) {
+ if ($children) {
+ foreach ($children as $child) {
+ $xz = $child->get_template_data($conv_responses, $thread_level + 1);
+ $result['children'][] = $xz;
+ }
+ }
+ // Collapse
+ if ($total_children > $visible_comments && $thread_level == 1) {
+ $result['children'][0]['comment_firstcollapsed'] = true;
+ $result['children'][0]['num_comments'] = $comment_count_txt;
+ $result['children'][0]['hide_text'] = sprintf(t('%s show all'), '');
+ }
+ }
+
+ $result['private'] = $item['item_private'];
+ $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
+
+ if ($this->is_threaded()) {
+ $result['flatten'] = false;
+ $result['threaded'] = true;
+ } else {
+ $result['flatten'] = true;
+ $result['threaded'] = false;
+ }
+
+ return $result;
+ }
+
+ public function get_id()
+ {
+ return $this->get_data_value('id');
+ }
+
+ public function get_display_mode()
+ {
+ return $this->display_mode;
+ }
+
+ public function set_display_mode($mode)
+ {
+ $this->display_mode = $mode;
+ }
+
+ public function is_threaded()
+ {
+ return $this->threaded;
+ }
+
+ public function get_author()
+ {
+ $xchan = $this->get_data_value('author');
+ if ($xchan['xchan_addr']) {
+ return $xchan['xchan_addr'];
+ }
+ return $xchan['xchan_url'];
+ }
+
+ public function set_reload($val)
+ {
+ $this->reload = $val;
+ }
+
+ public function get_reload()
+ {
+ return $this->reload;
+ }
+
+ public function set_commentable($val)
+ {
+ $this->commentable = $val;
+ foreach ($this->get_children() as $child) {
+ $child->set_commentable($val);
+ }
+ }
+
+ public function is_commentable()
+ {
+ return $this->commentable;
+ }
+
+ /**
+ * Add a child item
+ */
+ public function add_child($item)
+ {
+ $item_id = $item->get_id();
+ if (!$item_id) {
+ logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
+ return false;
+ }
+ if ($this->get_child($item->get_id())) {
+ logger('[WARN] Item::add_child : Item already exists (' . $item->get_id() . ').', LOGGER_DEBUG);
+ return false;
+ }
+
+ /*
+ * Only add what will be displayed
+ */
+
+ if (activity_match($item->get_data_value('verb'), ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'), ACTIVITY_DISLIKE)) {
+ return false;
+ }
+
+ $item->set_parent($this);
+ $this->children[] = $item;
+ return end($this->children);
+ }
+
+ /**
+ * Get a child by its ID
+ */
+
+ public function get_child($id)
+ {
+ foreach ($this->get_children() as $child) {
+ if ($child->get_id() == $id) {
+ return $child;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get all our children
+ */
+
+ public function get_children()
+ {
+ return $this->children;
+ }
+
+ /**
+ * Set our parent
+ */
+ protected function set_parent($item)
+ {
+ $parent = $this->get_parent();
+ if ($parent) {
+ $parent->remove_child($this);
+ }
+ $this->parent = $item;
+ $this->set_conversation($item->get_conversation());
+ }
+
+ /**
+ * Remove our parent
+ */
+
+ protected function remove_parent()
+ {
+ $this->parent = null;
+ $this->conversation = null;
+ }
+
+ /**
+ * Remove a child
+ */
+
+ public function remove_child($item)
+ {
+ $id = $item->get_id();
+ foreach ($this->get_children() as $key => $child) {
+ if ($child->get_id() == $id) {
+ $child->remove_parent();
+ unset($this->children[$key]);
+ // Reindex the array, in order to make sure there won't be any trouble on loops using count()
+ $this->children = array_values($this->children);
+ return true;
+ }
+ }
+ logger('[WARN] Item::remove_child : Item is not a child (' . $id . ').', LOGGER_DEBUG);
+ return false;
+ }
+
+ /**
+ * Get parent item
+ */
+ protected function get_parent()
+ {
+ return $this->parent;
+ }
+
+ /**
+ * set conversation
+ */
+ public function set_conversation($conv)
+ {
+ $previous_mode = ($this->conversation ? $this->conversation->get_mode() : '');
+
+ $this->conversation = $conv;
+
+ // Set it on our children too
+ foreach ($this->get_children() as $child) {
+ $child->set_conversation($conv);
+ }
+ }
+
+ /**
+ * get conversation
+ */
+ public function get_conversation()
+ {
+ return $this->conversation;
+ }
+
+ /**
+ * Get raw data
+ *
+ * We shouldn't need this
+ */
+ public function get_data()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Get a data value
+ *
+ * Returns:
+ * _ value on success
+ * _ false on failure
+ */
+ public function get_data_value($name)
+ {
+ if (!isset($this->data[$name])) {
+// logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG);
+ return false;
+ }
+
+ return $this->data[$name];
+ }
+
+ /**
+ * Get template
+ */
+ public function get_template()
+ {
+ return $this->template;
+ }
+
+
+ public function set_template($t)
+ {
+ $this->template = $t;
+ }
+
+ /**
+ * Check if this is a toplevel post
+ */
+ private function is_toplevel()
+ {
+ return $this->toplevel;
+ }
+
+ /**
+ * Count the total of our descendants
+ */
+ private function count_descendants()
+ {
+ $children = $this->get_children();
+ $total = count($children);
+ if ($total > 0) {
+ foreach ($children as $child) {
+ $total += $child->count_descendants();
+ }
+ }
+ return $total;
+ }
+
+ public function count_visible_descendants()
+ {
+ $total = 0;
+ $children = $this->get_children();
+ if ($children) {
+ foreach ($children as $child) {
+ if (! visible_activity($child->data)) {
+ continue;
+ }
+ $total++;
+ $total += $child->count_visible_descendants();
+ }
+ }
+ return $total;
+ }
+
+
+ private function label_descendants($count = 0)
+ {
+ if (! array_key_exists('sequence', $this->data)) {
+ if ($count) {
+ $count++;
+ }
+ $this->data['sequence'] = $count;
+ }
+ logger('labelled: ' . print_r($this->data, true), LOGGER_DATA);
+ $children = $this->get_children();
+ $total = count($children);
+ if ($total > 0) {
+ foreach ($children as $child) {
+ if (! visible_activity($child->data)) {
+ continue;
+ }
+ if (! array_key_exists('sequence', $this->data)) {
+ $count++;
+ $child->data['sequence'] = $count;
+ logger('labelled_child: ' . print_r($child->data, true), LOGGER_DATA);
+ }
+ $child->label_descendants($count);
+ }
+ }
+ }
+
+ private function count_unseen_descendants()
+ {
+ $children = $this->get_children();
+ $total = count($children);
+ if ($total > 0) {
+ $total = 0;
+ foreach ($children as $child) {
+ if (! visible_activity($child->data)) {
+ continue;
+ }
+ if (intval($child->data['item_unseen'])) {
+ $total++;
+ }
+ }
+ }
+ return $total;
+ }
+
+
+ /**
+ * Get the template for the comment box
+ */
+ private function get_comment_box_template()
+ {
+ return $this->comment_box_template;
+ }
+
+ /**
+ * Get the comment box
+ *
+ * Returns:
+ * _ The comment box string (empty if no comment box)
+ * _ false on failure
+ */
+ private function get_comment_box($indent = 0)
+ {
+
+ if (!$this->is_toplevel() && !get_config('system', 'thread_allow', true)) {
+ return '';
+ }
+
+ $comment_box = '';
+ $conv = $this->get_conversation();
+
+// logger('Commentable conv: ' . $conv->is_commentable());
+
+ if (! $this->is_commentable()) {
+ return;
+ }
+
+ $template = get_markup_template($this->get_comment_box_template());
+
+ $observer = $conv->get_observer();
+
+ $arr = array('comment_buttons' => '','id' => $this->get_id());
+ call_hooks('comment_buttons', $arr);
+ $comment_buttons = $arr['comment_buttons'];
+
+ $feature_auto_save_draft = ((feature_enabled($conv->get_profile_owner(), 'auto_save_draft')) ? "true" : "false");
+ $permanent_draft = ((intval($conv->get_profile_owner()) === intval(local_channel()) && Apps::system_app_installed($conv->get_profile_owner(), 'Drafts')) ? ('Save draft') : EMPTY_STR);
+
+
+
+ $comment_box = replace_macros($template, array(
+ '$return_path' => '',
+ '$threaded' => $this->is_threaded(),
+ '$jsreload' => $conv->reload,
+ '$type' => (($conv->get_mode() === 'channel') ? 'wall-comment' : 'net-comment'),
+ '$id' => $this->get_id(),
+ '$parent' => $this->get_id(),
+ '$comment_buttons' => $comment_buttons,
+ '$profile_uid' => $conv->get_profile_owner(),
+ '$mylink' => $observer['xchan_url'],
+ '$mytitle' => t('This is you'),
+ '$myphoto' => $observer['xchan_photo_s'],
+ '$comment' => t('Comment'),
+ '$submit' => t('Submit'),
+ '$edat' => EMPTY_STR,
+ '$edbold' => t('Bold'),
+ '$editalic' => t('Italic'),
+ '$eduline' => t('Underline'),
+ '$edquote' => t('Quote'),
+ '$edcode' => t('Code'),
+ '$edimg' => t('Image'),
+ '$edatt' => t('Attach/Upload file'),
+ '$edurl' => t('Insert Link'),
+ '$edvideo' => t('Video'),
+ '$preview' => t('Preview'),
+ '$reset' => t('Reset'),
+ '$indent' => $indent,
+ '$can_upload' => (perm_is_allowed($conv->get_profile_owner(), get_observer_hash(), 'write_storage') && $conv->is_uploadable()),
+ '$feature_encrypt' => ((Apps::system_app_installed($conv->get_profile_owner(), 'Secrets')) ? true : false),
+ '$feature_markup' => ((Apps::system_app_installed($conv->get_profile_owner(), 'Markup')) ? true : false),
+ '$encrypt' => t('Encrypt text'),
+ '$cipher' => $conv->get_cipher(),
+ '$sourceapp' => App::$sourcename,
+ '$observer' => get_observer_hash(),
+ '$anoncomments' => ((($conv->get_mode() === 'channel' || $conv->get_mode() === 'display') && perm_is_allowed($conv->get_profile_owner(), '', 'post_comments')) ? true : false),
+ '$anonname' => [ 'anonname', t('Your full name (required)') ],
+ '$anonmail' => [ 'anonmail', t('Your email address (required)') ],
+ '$anonurl' => [ 'anonurl', t('Your website URL (optional)') ],
+ '$auto_save_draft' => $feature_auto_save_draft,
+ '$save' => $permanent_draft,
+ '$top' => $this->is_toplevel()
+ ));
+
+ return $comment_box;
+ }
+
+ private function get_redirect_url()
+ {
+ return $this->redirect_url;
+ }
+
+ /**
+ * Check if we are a wall to wall item and set the relevant properties
+ */
+ protected function check_wall_to_wall()
+ {
+ $conv = $this->get_conversation();
+ $this->wall_to_wall = false;
+ $this->owner_url = '';
+ $this->owner_photo = '';
+ $this->owner_name = '';
+ $this->owner_censored = false;
+
+ if ($conv->get_mode() === 'channel') {
+ return;
+ }
+
+ if ($this->is_toplevel() && ($this->get_data_value('author_xchan') != $this->get_data_value('owner_xchan'))) {
+ $this->owner_url = chanlink_hash($this->data['owner']['xchan_hash']);
+ $this->owner_photo = $this->data['owner']['xchan_photo_m'];
+ $this->owner_name = $this->data['owner']['xchan_name'];
+ $this->wall_to_wall = true;
+ }
+
+ // present friend-of-friend conversations from hyperdrive as relayed posts from the first friend
+ // we find among the respondents.
+
+ if ($this->is_toplevel() && (! $this->data['owner']['abook_id'])) {
+ if ($this->data['children']) {
+ $friend = $this->find_a_friend($this->data['children']);
+ if ($friend) {
+ $this->owner_url = $friend['url'];
+ $this->owner_photo = $friend['photo'];
+ $this->owner_name = $friend['name'];
+ $this->owner_censored = $friend['censored'];
+ $this->wall_to_wall = true;
+ }
+ }
+ }
+ }
+
+ private function find_a_friend($items)
+ {
+ $ret = null;
+ if ($items) {
+ foreach ($items as $child) {
+ if ($child['author']['abook_id'] && (! intval($child['author']['abook_self']))) {
+ return [
+ 'url' => chanlink_hash($child['author']['xchan_hash']),
+ 'photo' => $child['author']['xchan_photo_m'],
+ 'name' => $child['author']['xchan_name'],
+ 'censored' => (($child['author']['xchan_censored'] || $child['author']['abook_censor']) ? true : false)
+ ];
+ if ($child['children']) {
+ $ret = $this->find_a_friend($child['children']);
+ if ($ret) {
+ break;
+ }
+ }
+ }
+ }
+ }
+ return $ret;
+ }
+
+
+ private function is_wall_to_wall()
+ {
+ return $this->wall_to_wall;
+ }
+
+ private function get_owner_url()
+ {
+ return $this->owner_url;
+ }
+
+ private function get_owner_photo()
+ {
+ return $this->owner_photo;
+ }
+
+ private function get_owner_name()
+ {
+ return $this->owner_name;
+ }
+
+ private function is_visiting()
+ {
+ return $this->visiting;
+ }
}
-
diff --git a/Zotlabs/Lib/ThreadListener.php b/Zotlabs/Lib/ThreadListener.php
index ed2ed8f48..1bf4cbe98 100644
--- a/Zotlabs/Lib/ThreadListener.php
+++ b/Zotlabs/Lib/ThreadListener.php
@@ -2,52 +2,62 @@
namespace Zotlabs\Lib;
-class ThreadListener {
+class ThreadListener
+{
- public static function store($target_id, $portable_id, $ltype = 0) {
- $x = self::fetch($target_id,$portable_id,$ltype = 0);
- if(! $x) {
- $r = q("insert into listeners ( target_id, portable_id, ltype ) values ( '%s', '%s' , %d ) ",
- dbesc($target_id),
- dbesc($portable_id),
- intval($ltype)
- );
- }
- }
+ public static function store($target_id, $portable_id, $ltype = 0)
+ {
+ $x = self::fetch($target_id, $portable_id, $ltype = 0);
+ if (! $x) {
+ $r = q(
+ "insert into listeners ( target_id, portable_id, ltype ) values ( '%s', '%s' , %d ) ",
+ dbesc($target_id),
+ dbesc($portable_id),
+ intval($ltype)
+ );
+ }
+ }
- public static function fetch($target_id, $portable_id, $ltype = 0) {
- $x = q("select * from listeners where target_id = '%s' and portable_id = '%s' and ltype = %d limit 1",
- dbesc($target_id),
- dbesc($portable_id),
- intval($ltype)
- );
- if($x) {
- return $x[0];
- }
- return false;
- }
+ public static function fetch($target_id, $portable_id, $ltype = 0)
+ {
+ $x = q(
+ "select * from listeners where target_id = '%s' and portable_id = '%s' and ltype = %d limit 1",
+ dbesc($target_id),
+ dbesc($portable_id),
+ intval($ltype)
+ );
+ if ($x) {
+ return $x[0];
+ }
+ return false;
+ }
- public static function fetch_by_target($target_id, $ltype = 0) {
- $x = q("select * from listeners where target_id = '%s' and ltype = %d",
- dbesc($target_id),
- intval($ltype)
- );
+ public static function fetch_by_target($target_id, $ltype = 0)
+ {
+ $x = q(
+ "select * from listeners where target_id = '%s' and ltype = %d",
+ dbesc($target_id),
+ intval($ltype)
+ );
- return $x;
- }
+ return $x;
+ }
- public static function delete_by_target($target_id, $ltype = 0) {
- return q("delete from listeners where target_id = '%s' and ltype = %d",
- dbesc($target_id),
- intval($ltype)
- );
- }
-
- public static function delete_by_pid($portable_id, $ltype = 0) {
- return q("delete from listeners where portable_id = '%s' and ltype = %d",
- dbesc($portable_id),
- intval($ltype)
- );
- }
+ public static function delete_by_target($target_id, $ltype = 0)
+ {
+ return q(
+ "delete from listeners where target_id = '%s' and ltype = %d",
+ dbesc($target_id),
+ intval($ltype)
+ );
+ }
+ public static function delete_by_pid($portable_id, $ltype = 0)
+ {
+ return q(
+ "delete from listeners where portable_id = '%s' and ltype = %d",
+ dbesc($portable_id),
+ intval($ltype)
+ );
+ }
}
diff --git a/Zotlabs/Lib/ThreadStream.php b/Zotlabs/Lib/ThreadStream.php
index 092e572a0..bbbb882e6 100644
--- a/Zotlabs/Lib/ThreadStream.php
+++ b/Zotlabs/Lib/ThreadStream.php
@@ -1,4 +1,6 @@
-set_mode($mode);
- $this->preview = $preview;
- $this->uploadable = $uploadable;
- $this->prepared_item = $prepared_item;
- $c = ((local_channel()) ? get_pconfig(local_channel(),'system','default_cipher') : '');
- if($c)
- $this->cipher = $c;
- }
+ public function __construct($mode, $preview, $uploadable, $prepared_item = '')
+ {
+ $this->set_mode($mode);
+ $this->preview = $preview;
+ $this->uploadable = $uploadable;
+ $this->prepared_item = $prepared_item;
+ $c = ((local_channel()) ? get_pconfig(local_channel(), 'system', 'default_cipher') : '');
+ if ($c) {
+ $this->cipher = $c;
+ }
+ }
- /**
- * Set the mode we'll be displayed on
- */
- private function set_mode($mode) {
- if($this->get_mode() == $mode)
- return;
+ /**
+ * Set the mode we'll be displayed on
+ */
+ private function set_mode($mode)
+ {
+ if ($this->get_mode() == $mode) {
+ return;
+ }
- $this->observer = App::get_observer();
- $ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
+ $this->observer = App::get_observer();
+ $ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
- switch($mode) {
- case 'stream':
- $this->profile_owner = local_channel();
- $this->writable = true;
- break;
- case 'pubstream':
- $this->profile_owner = local_channel();
- $this->writable = ((local_channel()) ? true : false);
- break;
- case 'hq':
- $this->profile_owner = local_channel();
- $this->writable = true;
- break;
- case 'channel':
- $this->profile_owner = App::$profile['profile_uid'];
- $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
- break;
- case 'cards':
- $this->profile_owner = App::$profile['profile_uid'];
- $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
- $this->reload = $_SESSION['return_url'];
- break;
- case 'articles':
- $this->profile_owner = App::$profile['profile_uid'];
- $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
- $this->reload = $_SESSION['return_url'];
- break;
- case 'display':
- // in this mode we set profile_owner after initialisation (from conversation()) and then
- // pull some trickery which allows us to re-invoke this function afterward
- // it's an ugly hack so @FIXME
- $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
- $this->uploadable = perm_is_allowed($this->profile_owner,$ob_hash,'write_storage');
- break;
- case 'page':
- $this->profile_owner = App::$profile['uid'];
- $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
- break;
- default:
- logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
- return false;
- break;
- }
- $this->mode = $mode;
- }
+ switch ($mode) {
+ case 'stream':
+ $this->profile_owner = local_channel();
+ $this->writable = true;
+ break;
+ case 'pubstream':
+ $this->profile_owner = local_channel();
+ $this->writable = ((local_channel()) ? true : false);
+ break;
+ case 'hq':
+ $this->profile_owner = local_channel();
+ $this->writable = true;
+ break;
+ case 'channel':
+ $this->profile_owner = App::$profile['profile_uid'];
+ $this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
+ break;
+ case 'cards':
+ $this->profile_owner = App::$profile['profile_uid'];
+ $this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
+ $this->reload = $_SESSION['return_url'];
+ break;
+ case 'articles':
+ $this->profile_owner = App::$profile['profile_uid'];
+ $this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
+ $this->reload = $_SESSION['return_url'];
+ break;
+ case 'display':
+ // in this mode we set profile_owner after initialisation (from conversation()) and then
+ // pull some trickery which allows us to re-invoke this function afterward
+ // it's an ugly hack so @FIXME
+ $this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
+ $this->uploadable = perm_is_allowed($this->profile_owner, $ob_hash, 'write_storage');
+ break;
+ case 'page':
+ $this->profile_owner = App::$profile['uid'];
+ $this->writable = perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments');
+ break;
+ default:
+ logger('[ERROR] Conversation::set_mode : Unhandled mode (' . $mode . ').', LOGGER_DEBUG);
+ return false;
+ break;
+ }
+ $this->mode = $mode;
+ }
- /**
- * Get mode
- */
- public function get_mode() {
- return $this->mode;
- }
+ /**
+ * Get mode
+ */
+ public function get_mode()
+ {
+ return $this->mode;
+ }
- /**
- * Check if page is writable
- */
- public function is_writable() {
- return $this->writable;
- }
+ /**
+ * Check if page is writable
+ */
+ public function is_writable()
+ {
+ return $this->writable;
+ }
- public function is_commentable() {
- return $this->commentable;
- }
+ public function is_commentable()
+ {
+ return $this->commentable;
+ }
- public function is_uploadable() {
- return $this->uploadable;
- }
+ public function is_uploadable()
+ {
+ return $this->uploadable;
+ }
- /**
- * Check if page is a preview
- */
- public function is_preview() {
- return $this->preview;
- }
+ /**
+ * Check if page is a preview
+ */
+ public function is_preview()
+ {
+ return $this->preview;
+ }
- /**
- * Get profile owner
- */
- public function get_profile_owner() {
- return $this->profile_owner;
- }
+ /**
+ * Get profile owner
+ */
+ public function get_profile_owner()
+ {
+ return $this->profile_owner;
+ }
- public function set_profile_owner($uid) {
- $this->profile_owner = $uid;
- $mode = $this->get_mode();
- $this->mode = null;
- $this->set_mode($mode);
- }
+ public function set_profile_owner($uid)
+ {
+ $this->profile_owner = $uid;
+ $mode = $this->get_mode();
+ $this->mode = null;
+ $this->set_mode($mode);
+ }
- public function get_observer() {
- return $this->observer;
- }
+ public function get_observer()
+ {
+ return $this->observer;
+ }
- public function get_cipher() {
- return $this->cipher;
- }
+ public function get_cipher()
+ {
+ return $this->cipher;
+ }
- /**
- * Add a thread to the conversation
- *
- * Returns:
- * _ The inserted item on success
- * _ false on failure
- */
- public function add_thread($item) {
- $item_id = $item->get_id();
- if(!$item_id) {
- logger('Item has no ID!!', LOGGER_DEBUG, LOG_ERR);
- return false;
- }
- if($this->get_thread($item->get_id())) {
- logger('Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG, LOG_WARNING);
- return false;
- }
+ /**
+ * Add a thread to the conversation
+ *
+ * Returns:
+ * _ The inserted item on success
+ * _ false on failure
+ */
+ public function add_thread($item)
+ {
+ $item_id = $item->get_id();
+ if (!$item_id) {
+ logger('Item has no ID!!', LOGGER_DEBUG, LOG_ERR);
+ return false;
+ }
+ if ($this->get_thread($item->get_id())) {
+ logger('Thread already exists (' . $item->get_id() . ').', LOGGER_DEBUG, LOG_WARNING);
+ return false;
+ }
- /*
- * Only add things that will be displayed
- */
-
-
- if(($item->get_data_value('id') != $item->get_data_value('parent')) && (activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE))) {
- return false;
- }
-
- $item->set_commentable(false);
- $ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
-
- if(! comments_are_now_closed($item->get_data())) {
- if(($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash))
- $item->set_commentable(true);
-
- if(intval($item->get_data_value('item_nocomment'))) {
- $item->set_commentable(false);
- }
- elseif(! $item->is_commentable()) {
- if((array_key_exists('owner',$item->data)) && intval($item->data['owner']['abook_self']))
- $item->set_commentable(perm_is_allowed($this->profile_owner,$ob_hash,'post_comments'));
- else
- $item->set_commentable(can_comment_on_post($ob_hash,$item->data));
- }
- }
- if($this->mode === 'pubstream' && (! local_channel())) {
- $item->set_commentable(false);
- }
+ /*
+ * Only add things that will be displayed
+ */
- $item->set_conversation($this);
- $this->threads[] = $item;
- return end($this->threads);
- }
+ if (($item->get_data_value('id') != $item->get_data_value('parent')) && (activity_match($item->get_data_value('verb'), ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'), ACTIVITY_DISLIKE))) {
+ return false;
+ }
- /**
- * Get data in a form usable by a conversation template
- *
- * We should find a way to avoid using those arguments (at least most of them)
- *
- * Returns:
- * _ The data requested on success
- * _ false on failure
- */
- public function get_template_data($conv_responses) {
- $result = [];
+ $item->set_commentable(false);
+ $ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
- foreach($this->threads as $item) {
+ if (! comments_are_now_closed($item->get_data())) {
+ if (($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash)) {
+ $item->set_commentable(true);
+ }
- if(($item->get_data_value('id') == $item->get_data_value('parent')) && $this->prepared_item) {
- $item_data = $this->prepared_item;
- }
- else {
- $item_data = $item->get_template_data($conv_responses);
- }
- if(!$item_data) {
- logger('Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG, LOG_ERR);
- return false;
- }
- $result[] = $item_data;
- }
+ if (intval($item->get_data_value('item_nocomment'))) {
+ $item->set_commentable(false);
+ } elseif (! $item->is_commentable()) {
+ if ((array_key_exists('owner', $item->data)) && intval($item->data['owner']['abook_self'])) {
+ $item->set_commentable(perm_is_allowed($this->profile_owner, $ob_hash, 'post_comments'));
+ } else {
+ $item->set_commentable(can_comment_on_post($ob_hash, $item->data));
+ }
+ }
+ }
+ if ($this->mode === 'pubstream' && (! local_channel())) {
+ $item->set_commentable(false);
+ }
- return $result;
- }
- /**
- * Get a thread based on its item id
- *
- * Returns:
- * _ The found item on success
- * _ false on failure
- */
- private function get_thread($id) {
- foreach($this->threads as $item) {
- if($item->get_id() == $id)
- return $item;
- }
+ $item->set_conversation($this);
+ $this->threads[] = $item;
+ return end($this->threads);
+ }
- return false;
- }
+ /**
+ * Get data in a form usable by a conversation template
+ *
+ * We should find a way to avoid using those arguments (at least most of them)
+ *
+ * Returns:
+ * _ The data requested on success
+ * _ false on failure
+ */
+ public function get_template_data($conv_responses)
+ {
+ $result = [];
+
+ foreach ($this->threads as $item) {
+ if (($item->get_data_value('id') == $item->get_data_value('parent')) && $this->prepared_item) {
+ $item_data = $this->prepared_item;
+ } else {
+ $item_data = $item->get_template_data($conv_responses);
+ }
+ if (!$item_data) {
+ logger('Failed to get item template data (' . $item->get_id() . ').', LOGGER_DEBUG, LOG_ERR);
+ return false;
+ }
+ $result[] = $item_data;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Get a thread based on its item id
+ *
+ * Returns:
+ * _ The found item on success
+ * _ false on failure
+ */
+ private function get_thread($id)
+ {
+ foreach ($this->threads as $item) {
+ if ($item->get_id() == $id) {
+ return $item;
+ }
+ }
+
+ return false;
+ }
}
diff --git a/Zotlabs/Lib/Verify.php b/Zotlabs/Lib/Verify.php
index e1b8f9b2a..04b4114eb 100644
--- a/Zotlabs/Lib/Verify.php
+++ b/Zotlabs/Lib/Verify.php
@@ -2,13 +2,13 @@
namespace Zotlabs\Lib;
-
class Verify
{
public static function create($type, $channel_id, $token, $meta)
{
- return q("insert into verify ( vtype, channel, token, meta, created ) values ( '%s', %d, '%s', '%s', '%s' )",
+ return q(
+ "insert into verify ( vtype, channel, token, meta, created ) values ( '%s', %d, '%s', '%s', '%s' )",
dbesc($type),
intval($channel_id),
dbesc($token),
@@ -19,14 +19,16 @@ class Verify
public static function match($type, $channel_id, $token, $meta)
{
- $r = q("select id from verify where vtype = '%s' and channel = %d and token = '%s' and meta = '%s' limit 1",
+ $r = q(
+ "select id from verify where vtype = '%s' and channel = %d and token = '%s' and meta = '%s' limit 1",
dbesc($type),
intval($channel_id),
dbesc($token),
dbesc($meta)
);
if ($r) {
- q("delete from verify where id = %d",
+ q(
+ "delete from verify where id = %d",
intval($r[0]['id'])
);
return true;
@@ -36,13 +38,15 @@ class Verify
public static function get_meta($type, $channel_id, $token)
{
- $r = q("select id, meta from verify where vtype = '%s' and channel = %d and token = '%s' limit 1",
+ $r = q(
+ "select id, meta from verify where vtype = '%s' and channel = %d and token = '%s' limit 1",
dbesc($type),
intval($channel_id),
dbesc($token)
);
if ($r) {
- q("delete from verify where id = %d",
+ q(
+ "delete from verify where id = %d",
intval($r[0]['id'])
);
return $r[0]['meta'];
@@ -58,11 +62,11 @@ class Verify
*/
public static function purge($type, $interval)
{
- q("delete from verify where vtype = '%s' and created < ( %s - INTERVAL %s )",
+ q(
+ "delete from verify where vtype = '%s' and created < ( %s - INTERVAL %s )",
dbesc($type),
db_utcnow(),
db_quoteinterval($interval)
);
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/Webfinger.php b/Zotlabs/Lib/Webfinger.php
index fa7aac96c..10d67b62b 100644
--- a/Zotlabs/Lib/Webfinger.php
+++ b/Zotlabs/Lib/Webfinger.php
@@ -105,4 +105,4 @@ class Webfinger
}
return false;
}
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Lib/XConfig.php b/Zotlabs/Lib/XConfig.php
index 0b20b7b5c..a9d86fc88 100644
--- a/Zotlabs/Lib/XConfig.php
+++ b/Zotlabs/Lib/XConfig.php
@@ -24,153 +24,169 @@ use App;
* $var = get_xconfig($observer, 'category', 'key');
* }@endcode
*/
-class XConfig {
+class XConfig
+{
- /**
- * @brief Loads a full xchan's configuration into a cached storage.
- *
- * All configuration values of the given observer hash are stored in global
- * cache which is available under the global variable App::$config[$xchan].
- *
- * @param string $xchan
- * The observer's hash
- * @return void|false Returns false if xchan is not set
- */
- public static function Load($xchan) {
+ /**
+ * @brief Loads a full xchan's configuration into a cached storage.
+ *
+ * All configuration values of the given observer hash are stored in global
+ * cache which is available under the global variable App::$config[$xchan].
+ *
+ * @param string $xchan
+ * The observer's hash
+ * @return void|false Returns false if xchan is not set
+ */
+ public static function Load($xchan)
+ {
- if(! $xchan)
- return false;
+ if (! $xchan) {
+ return false;
+ }
- if(! array_key_exists($xchan, App::$config))
- App::$config[$xchan] = [];
+ if (! array_key_exists($xchan, App::$config)) {
+ App::$config[$xchan] = [];
+ }
- $r = q("SELECT * FROM xconfig WHERE xchan = '%s'",
- dbesc($xchan)
- );
+ $r = q(
+ "SELECT * FROM xconfig WHERE xchan = '%s'",
+ dbesc($xchan)
+ );
- if($r) {
- foreach($r as $rr) {
- $k = $rr['k'];
- $c = $rr['cat'];
- if(! array_key_exists($c, App::$config[$xchan])) {
- App::$config[$xchan][$c] = [];
- App::$config[$xchan][$c]['config_loaded'] = true;
- }
- App::$config[$xchan][$c][$k] = $rr['v'];
- }
- }
- }
+ if ($r) {
+ foreach ($r as $rr) {
+ $k = $rr['k'];
+ $c = $rr['cat'];
+ if (! array_key_exists($c, App::$config[$xchan])) {
+ App::$config[$xchan][$c] = [];
+ App::$config[$xchan][$c]['config_loaded'] = true;
+ }
+ App::$config[$xchan][$c][$k] = $rr['v'];
+ }
+ }
+ }
- /**
- * @brief Get a particular observer's config variable given the category
- * name ($family) and a key.
- *
- * Get a particular observer's config value from the given category ($family)
- * and the $key from a cached storage in App::$config[$xchan].
- *
- * Returns false if not set.
- *
- * @param string $xchan
- * The observer's hash
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to query
- * @param bool $default (optional) default false
- * @return mixed Stored $value or false if it does not exist
- */
- public static function Get($xchan, $family, $key, $default = false) {
+ /**
+ * @brief Get a particular observer's config variable given the category
+ * name ($family) and a key.
+ *
+ * Get a particular observer's config value from the given category ($family)
+ * and the $key from a cached storage in App::$config[$xchan].
+ *
+ * Returns false if not set.
+ *
+ * @param string $xchan
+ * The observer's hash
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to query
+ * @param bool $default (optional) default false
+ * @return mixed Stored $value or false if it does not exist
+ */
+ public static function Get($xchan, $family, $key, $default = false)
+ {
- if(! $xchan)
- return $default;
+ if (! $xchan) {
+ return $default;
+ }
- if(! array_key_exists($xchan, App::$config))
- load_xconfig($xchan);
+ if (! array_key_exists($xchan, App::$config)) {
+ load_xconfig($xchan);
+ }
- if((! array_key_exists($family, App::$config[$xchan])) || (! array_key_exists($key, App::$config[$xchan][$family])))
- return $default;
+ if ((! array_key_exists($family, App::$config[$xchan])) || (! array_key_exists($key, App::$config[$xchan][$family]))) {
+ return $default;
+ }
- return unserialise(App::$config[$xchan][$family][$key]);
- }
+ return unserialise(App::$config[$xchan][$family][$key]);
+ }
- /**
- * @brief Sets a configuration value for an observer.
- *
- * Stores a config value ($value) in the category ($family) under the key ($key)
- * for the observer's $xchan hash.
- *
- * @param string $xchan
- * The observer's hash
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to set
- * @param string $value
- * The value to store
- * @return mixed Stored $value or false
- */
- public static function Set($xchan, $family, $key, $value) {
+ /**
+ * @brief Sets a configuration value for an observer.
+ *
+ * Stores a config value ($value) in the category ($family) under the key ($key)
+ * for the observer's $xchan hash.
+ *
+ * @param string $xchan
+ * The observer's hash
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to set
+ * @param string $value
+ * The value to store
+ * @return mixed Stored $value or false
+ */
+ public static function Set($xchan, $family, $key, $value)
+ {
- // manage array value
- $dbvalue = ((is_array($value)) ? serialise($value) : $value);
- $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
+ // manage array value
+ $dbvalue = ((is_array($value)) ? serialise($value) : $value);
+ $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
- if(self::Get($xchan, $family, $key) === false) {
- if(! array_key_exists($xchan, App::$config))
- App::$config[$xchan] = [];
- if(! array_key_exists($family, App::$config[$xchan]))
- App::$config[$xchan][$family] = [];
+ if (self::Get($xchan, $family, $key) === false) {
+ if (! array_key_exists($xchan, App::$config)) {
+ App::$config[$xchan] = [];
+ }
+ if (! array_key_exists($family, App::$config[$xchan])) {
+ App::$config[$xchan][$family] = [];
+ }
- $ret = q("INSERT INTO xconfig ( xchan, cat, k, v ) VALUES ( '%s', '%s', '%s', '%s' )",
- dbesc($xchan),
- dbesc($family),
- dbesc($key),
- dbesc($dbvalue)
- );
- }
- else {
- $ret = q("UPDATE xconfig SET v = '%s' WHERE xchan = '%s' and cat = '%s' AND k = '%s'",
- dbesc($dbvalue),
- dbesc($xchan),
- dbesc($family),
- dbesc($key)
- );
- }
+ $ret = q(
+ "INSERT INTO xconfig ( xchan, cat, k, v ) VALUES ( '%s', '%s', '%s', '%s' )",
+ dbesc($xchan),
+ dbesc($family),
+ dbesc($key),
+ dbesc($dbvalue)
+ );
+ } else {
+ $ret = q(
+ "UPDATE xconfig SET v = '%s' WHERE xchan = '%s' and cat = '%s' AND k = '%s'",
+ dbesc($dbvalue),
+ dbesc($xchan),
+ dbesc($family),
+ dbesc($key)
+ );
+ }
- App::$config[$xchan][$family][$key] = $value;
+ App::$config[$xchan][$family][$key] = $value;
- if($ret)
- return $value;
+ if ($ret) {
+ return $value;
+ }
- return $ret;
- }
+ return $ret;
+ }
- /**
- * @brief Deletes the given key from the observer's config.
- *
- * Removes the configured value from the stored cache in App::$config[$xchan]
- * and removes it from the database.
- *
- * @param string $xchan
- * The observer's hash
- * @param string $family
- * The category of the configuration value
- * @param string $key
- * The configuration key to delete
- * @return mixed
- */
- public static function Delete($xchan, $family, $key) {
+ /**
+ * @brief Deletes the given key from the observer's config.
+ *
+ * Removes the configured value from the stored cache in App::$config[$xchan]
+ * and removes it from the database.
+ *
+ * @param string $xchan
+ * The observer's hash
+ * @param string $family
+ * The category of the configuration value
+ * @param string $key
+ * The configuration key to delete
+ * @return mixed
+ */
+ public static function Delete($xchan, $family, $key)
+ {
- if(isset(App::$config[$xchan]) && isset(App::$config[$xchan][$family]) && isset(App::$config[$xchan][$family][$key]))
- unset(App::$config[$xchan][$family][$key]);
+ if (isset(App::$config[$xchan]) && isset(App::$config[$xchan][$family]) && isset(App::$config[$xchan][$family][$key])) {
+ unset(App::$config[$xchan][$family][$key]);
+ }
- $ret = q("DELETE FROM xconfig WHERE xchan = '%s' AND cat = '%s' AND k = '%s'",
- dbesc($xchan),
- dbesc($family),
- dbesc($key)
- );
-
- return $ret;
- }
+ $ret = q(
+ "DELETE FROM xconfig WHERE xchan = '%s' AND cat = '%s' AND k = '%s'",
+ dbesc($xchan),
+ dbesc($family),
+ dbesc($key)
+ );
+ return $ret;
+ }
}
diff --git a/Zotlabs/Lib/ZotURL.php b/Zotlabs/Lib/ZotURL.php
index 5110410dc..1c221cb95 100644
--- a/Zotlabs/Lib/ZotURL.php
+++ b/Zotlabs/Lib/ZotURL.php
@@ -4,123 +4,123 @@ namespace Zotlabs\Lib;
use Zotlabs\Web\HTTPSig;
+class ZotURL
+{
-class ZotURL {
+ public static function fetch($url, $channel, $hub = null)
+ {
- public static function fetch($url, $channel, $hub = null) {
+ $ret = [ 'success' => false ];
- $ret = [ 'success' => false ];
-
- if(strpos($url,'x-zot:') !== 0) {
- return $ret;
- }
+ if (strpos($url, 'x-zot:') !== 0) {
+ return $ret;
+ }
- if(! $url) {
- return $ret;
- }
+ if (! $url) {
+ return $ret;
+ }
- $portable_url = substr($url,6);
- $u = explode('/',$portable_url);
- $portable_id = $u[0];
+ $portable_url = substr($url, 6);
+ $u = explode('/', $portable_url);
+ $portable_id = $u[0];
- $hosts = self::lookup($portable_id,$hub);
+ $hosts = self::lookup($portable_id, $hub);
- if(! $hosts) {
- return $ret;
- }
+ if (! $hosts) {
+ return $ret;
+ }
- foreach($hosts as $h) {
- $newurl = $h . '/id/' . $portable_url;
+ foreach ($hosts as $h) {
+ $newurl = $h . '/id/' . $portable_url;
- $m = parse_url($newurl);
+ $m = parse_url($newurl);
- $data = json_encode([ 'zot_token' => random_string() ]);
+ $data = json_encode([ 'zot_token' => random_string() ]);
- if($channel && $m) {
+ if ($channel && $m) {
+ $headers = [
+ 'Accept' => 'application/x-zot+json',
+ 'Content-Type' => 'application/x-zot+json',
+ 'X-Zot-Token' => random_string(),
+ 'Digest' => HTTPSig::generate_digest_header($data),
+ 'Host' => $m['host'],
+ '(request-target)' => 'post ' . get_request_string($newurl)
+ ];
+ $h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), false);
+ } else {
+ $h = [ 'Accept: application/x-zot+json' ];
+ }
- $headers = [
- 'Accept' => 'application/x-zot+json',
- 'Content-Type' => 'application/x-zot+json',
- 'X-Zot-Token' => random_string(),
- 'Digest' => HTTPSig::generate_digest_header($data),
- 'Host' => $m['host'],
- '(request-target)' => 'post ' . get_request_string($newurl)
- ];
- $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),false);
- }
- else {
- $h = [ 'Accept: application/x-zot+json' ];
- }
-
- $result = [];
+ $result = [];
- $redirects = 0;
- $x = z_post_url($newurl,$data,$redirects, [ 'headers' => $h ] );
- if($x['success']) {
- return $x;
- }
- }
+ $redirects = 0;
+ $x = z_post_url($newurl, $data, $redirects, [ 'headers' => $h ]);
+ if ($x['success']) {
+ return $x;
+ }
+ }
- return $ret;
+ return $ret;
+ }
- }
+ public static function is_zoturl($s)
+ {
- public static function is_zoturl($s) {
-
- if(strpos($url,'x-zot:') === 0) {
- return true;
- }
- return false;
- }
+ if (strpos($url, 'x-zot:') === 0) {
+ return true;
+ }
+ return false;
+ }
- public static function lookup($portable_id, $hub) {
+ public static function lookup($portable_id, $hub)
+ {
- $r = q("select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0 order by hubloc_primary desc",
- dbesc($portable_id)
- );
+ $r = q(
+ "select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0 order by hubloc_primary desc",
+ dbesc($portable_id)
+ );
- if(! $r) {
+ if (! $r) {
+ // extend to network lookup
- // extend to network lookup
+ $path = '/q/' . $portable_id;
- $path = '/q/' . $portable_id;
+ // first check sending hub since they have recently communicated with this object
- // first check sending hub since they have recently communicated with this object
+ $redirects = 0;
- $redirects = 0;
+ if ($hub) {
+ $x = z_fetch_url($hub['hubloc_url'] . $path, false, $redirects);
+ $u = self::parse_response($x);
+ if ($u) {
+ return $u;
+ }
+ }
- if($hub) {
- $x = z_fetch_url($hub['hubloc_url'] . $path, false, $redirects);
- $u = self::parse_response($x);
- if($u) {
- return $u;
- }
- }
+ // If this fails, fallback on directory servers
- // If this fails, fallback on directory servers
-
- return false;
- }
- return ids_to_array($r,'hubloc_url');
- }
+ return false;
+ }
+ return ids_to_array($r, 'hubloc_url');
+ }
- public static function parse_response($arr) {
- if(! $arr['success']) {
- return false;
- }
- $a = json_decode($arr['body'],true);
- if($a['success'] && array_key_exists('results', $a) && is_array($a['results']) && count($a['results'])) {
- foreach($a['results'] as $b) {
- $m = discover_by_webbie($b);
- if($m) {
- return([ $b ]);
- }
- }
- }
- return false;
- }
-
-}
\ No newline at end of file
+ public static function parse_response($arr)
+ {
+ if (! $arr['success']) {
+ return false;
+ }
+ $a = json_decode($arr['body'], true);
+ if ($a['success'] && array_key_exists('results', $a) && is_array($a['results']) && count($a['results'])) {
+ foreach ($a['results'] as $b) {
+ $m = discover_by_webbie($b);
+ if ($m) {
+ return([ $b ]);
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/Zotlabs/Lib/Zotfinger.php b/Zotlabs/Lib/Zotfinger.php
index 9ebc7e0c8..4d7d2fd7b 100644
--- a/Zotlabs/Lib/Zotfinger.php
+++ b/Zotlabs/Lib/Zotfinger.php
@@ -24,7 +24,6 @@ class Zotfinger
$data = json_encode(['zot_token' => random_string()]);
if ($channel && $m) {
-
$headers = [
'Accept' => 'application/x-zot+json',
'Content-Type' => 'application/x-zot+json',
@@ -44,7 +43,6 @@ class Zotfinger
$x = z_post_url($resource, $data, $redirects, ['headers' => $h]);
if ($x['success']) {
-
if ($verify) {
$result['signature'] = HTTPSig::verify($x, EMPTY_STR, 'zot6');
}
@@ -60,5 +58,4 @@ class Zotfinger
return false;
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Module/Acl.php b/Zotlabs/Module/Acl.php
index 76661a00d..e0f764ae9 100644
--- a/Zotlabs/Module/Acl.php
+++ b/Zotlabs/Module/Acl.php
@@ -70,11 +70,11 @@ class Acl extends Controller
$permitted = [];
if (in_array($type, ['m', 'a', 'f'])) {
-
// These queries require permission checking. We'll create a simple array of xchan_hash for those with
// the requisite permissions which we can check against.
- $x = q("select xchan from abconfig where chan = %d and cat = 'system' and k = 'their_perms' and v like '%s'",
+ $x = q(
+ "select xchan from abconfig where chan = %d and cat = 'system' and k = 'their_perms' and v like '%s'",
intval(local_channel()),
dbesc(($type === 'm') ? '%post_mail%' : '%tag_deliver%')
);
@@ -102,8 +102,6 @@ class Acl extends Controller
$sql_extra3 = "AND ( xchan_addr like " . protect_sprintf("'%" . dbesc(punify($search)) . "%'") . " OR xchan_name like " . protect_sprintf("'%" . dbesc($search) . "%'") . " OR abook_alias like " . protect_sprintf("'%" . dbesc($search) . "%'") . " ) ";
$sql_extra4 = "AND ( xchan_name LIKE " . protect_sprintf("'%" . dbesc($search) . "%'") . " OR xchan_addr LIKE " . protect_sprintf("'%" . dbesc(punify($search)) . ((strpos($search, '@') === false) ? "%@%'" : "%'")) . " OR abook_alias LIKE " . protect_sprintf("'%" . dbesc($search) . "%'") . ") ";
-
-
} else {
$sql_extra = $sql_extra2 = $sql_extra3 = $sql_extra4 = "";
}
@@ -113,10 +111,10 @@ class Acl extends Controller
$contacts = [];
if ($type == '' || $type == 'g') {
-
// Normal privacy groups
- $r = q("SELECT pgrp.id, pgrp.hash, pgrp.gname
+ $r = q(
+ "SELECT pgrp.id, pgrp.hash, pgrp.gname
FROM pgrp, pgrp_member
WHERE pgrp.deleted = 0 AND pgrp.uid = %d
AND pgrp_member.gid = pgrp.id
@@ -131,7 +129,7 @@ class Acl extends Controller
if ($r) {
foreach ($r as $g) {
- // logger('acl: group: ' . $g['gname'] . ' members: ' . AccessList::members_xchan(local_channel(),$g['id']));
+ // logger('acl: group: ' . $g['gname'] . ' members: ' . AccessList::members_xchan(local_channel(),$g['id']));
$groups[] = [
"type" => "g",
"photo" => "images/twopeople.png",
@@ -146,40 +144,36 @@ class Acl extends Controller
}
if ($type == '' || $type == 'c' || $type === 'f') {
-
// Getting info from the abook is better for local users because it contains info about permissions
if (local_channel()) {
-
// add connections
- $r = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, xchan_type, abook_flags, abook_self
+ $r = q(
+ "SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, xchan_type, abook_flags, abook_self
FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d AND abook_blocked = 0 and abook_pending = 0 and xchan_deleted = 0 $sql_extra4 order by xchan_name asc limit $count",
intval(local_channel())
);
-
} else { // Visitors
- $r = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_flags, 0 as abook_self
+ $r = q(
+ "SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_flags, 0 as abook_self
FROM xchan left join xlink on xlink_link = xchan_hash
WHERE xlink_xchan = '%s' AND xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc limit $count",
dbesc(get_observer_hash())
);
-
}
if ((count($r) < 100) && $type == 'c') {
$r2 = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_flags, 0 as abook_self
- FROM xchan WHERE xchan_deleted = 0 and xchan_network != 'unknown' $sql_extra2 order by $order_extra2 xchan_name asc limit $count"
- );
+ FROM xchan WHERE xchan_deleted = 0 and xchan_network != 'unknown' $sql_extra2 order by $order_extra2 xchan_name asc limit $count");
if ($r2) {
$r = array_merge($r, $r2);
$r = unique_multidim_array($r, 'hash');
}
}
-
} elseif ($type == 'm') {
-
$r = [];
- $z = q("SELECT xchan_hash as hash, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url
+ $z = q(
+ "SELECT xchan_hash as hash, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url
FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d
and xchan_deleted = 0
@@ -194,19 +188,18 @@ class Acl extends Controller
}
}
}
-
} elseif ($type == 'a') {
-
- $r = q("SELECT abook_id as id, xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM abook left join xchan on abook_xchan = xchan_hash
+ $r = q(
+ "SELECT abook_id as id, xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d
and xchan_deleted = 0
$sql_extra3
ORDER BY xchan_name ASC ",
intval(local_channel())
);
-
} elseif ($type == 'z') {
- $r = q("SELECT xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM xchan left join abook on xchan_hash = abook_xchan
+ $r = q(
+ "SELECT xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM xchan left join abook on xchan_hash = abook_xchan
WHERE ( abook_channel = %d OR abook_channel IS NULL )
and xchan_deleted = 0
$sql_extra3
@@ -240,7 +233,6 @@ class Acl extends Controller
if ($r) {
foreach ($r as $g) {
-
if (isset($g['network']) && in_array($g['network'], ['rss', 'anon', 'unknown']) && ($type != 'a')) {
continue;
}
@@ -301,7 +293,7 @@ class Acl extends Controller
public function navbar_complete()
{
- // logger('navbar_complete');
+ // logger('navbar_complete');
if (observer_prohibited()) {
return;
diff --git a/Zotlabs/Module/Activity.php b/Zotlabs/Module/Activity.php
index 1051ace07..84d45de7d 100644
--- a/Zotlabs/Module/Activity.php
+++ b/Zotlabs/Module/Activity.php
@@ -1,4 +1,5 @@
[
ACTIVITYSTREAMS_JSONLD_REV,
@@ -279,11 +293,9 @@ class Activity extends Controller
HTTPSig::set_headers($h);
echo $ret;
killme();
-
}
goaway(z_root() . '/item/' . argv(1));
}
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php
index b7f1f733f..dcba31e2d 100644
--- a/Zotlabs/Module/Admin.php
+++ b/Zotlabs/Module/Admin.php
@@ -1,4 +1,5 @@
0 THEN 1 ELSE NULL END) AS total, COUNT(CASE WHEN account_expires > %s THEN 1 ELSE NULL END) AS expiring, COUNT(CASE WHEN account_expires < %s AND account_expires > '%s' THEN 1 ELSE NULL END) AS expired, COUNT(CASE WHEN (account_flags & %d)>0 THEN 1 ELSE NULL END) AS blocked FROM account",
+ $r = q(
+ "SELECT COUNT(CASE WHEN account_id > 0 THEN 1 ELSE NULL END) AS total, COUNT(CASE WHEN account_expires > %s THEN 1 ELSE NULL END) AS expiring, COUNT(CASE WHEN account_expires < %s AND account_expires > '%s' THEN 1 ELSE NULL END) AS expired, COUNT(CASE WHEN (account_flags & %d)>0 THEN 1 ELSE NULL END) AS blocked FROM account",
db_utcnow(),
db_utcnow(),
dbesc(NULL_DATE),
@@ -127,7 +128,8 @@ class Admin extends Controller
// pending registrations
- $pdg = q("SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) > 0 ",
+ $pdg = q(
+ "SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) > 0 ",
intval(ACCOUNT_PENDING)
);
@@ -189,5 +191,4 @@ class Admin extends Controller
'$build' => Config::Get('system', 'db_version')
]);
}
-
}
diff --git a/Zotlabs/Module/Admin/Account_edit.php b/Zotlabs/Module/Admin/Account_edit.php
index 5f3847c34..00262f8fa 100644
--- a/Zotlabs/Module/Admin/Account_edit.php
+++ b/Zotlabs/Module/Admin/Account_edit.php
@@ -2,7 +2,6 @@
namespace Zotlabs\Module\Admin;
-
class Account_edit
{
@@ -11,38 +10,42 @@ class Account_edit
$account_id = $_REQUEST['aid'];
- if (!$account_id)
+ if (!$account_id) {
return;
+ }
$pass1 = trim($_REQUEST['pass1']);
$pass2 = trim($_REQUEST['pass2']);
if ($pass1 && $pass2 && ($pass1 === $pass2)) {
$salt = random_string(32);
$password_encoded = hash('whirlpool', $salt . $pass1);
- $r = q("update account set account_salt = '%s', account_password = '%s',
+ $r = q(
+ "update account set account_salt = '%s', account_password = '%s',
account_password_changed = '%s' where account_id = %d",
dbesc($salt),
dbesc($password_encoded),
dbesc(datetime_convert()),
intval($account_id)
);
- if ($r)
+ if ($r) {
info(sprintf(t('Password changed for account %d.'), $account_id) . EOL);
-
+ }
}
$service_class = trim($_REQUEST['service_class']);
$account_language = trim($_REQUEST['account_language']);
- $r = q("update account set account_service_class = '%s', account_language = '%s'
+ $r = q(
+ "update account set account_service_class = '%s', account_language = '%s'
where account_id = %d",
dbesc($service_class),
dbesc($account_language),
intval($account_id)
);
- if ($r)
+ if ($r) {
info(t('Account settings updated.') . EOL);
+ }
goaway(z_root() . '/admin/accounts');
}
@@ -50,10 +53,12 @@ class Account_edit
public function get()
{
- if (argc() > 2)
+ if (argc() > 2) {
$account_id = argv(2);
+ }
- $x = q("select * from account where account_id = %d limit 1",
+ $x = q(
+ "select * from account where account_id = %d limit 1",
intval($account_id)
);
@@ -71,13 +76,8 @@ class Account_edit
'$account_language' => ['account_language', t('Account language (for emails)'), $x[0]['account_language'], '', language_list()],
'$service_class' => ['service_class', t('Service class'), $x[0]['account_service_class'], ''],
'$submit' => t('Submit'),
- ]
- );
+ ]);
return $a;
-
-
}
-
-
-}
\ No newline at end of file
+}
diff --git a/Zotlabs/Module/Admin/Accounts.php b/Zotlabs/Module/Admin/Accounts.php
index 1c703c93d..b59e33bee 100644
--- a/Zotlabs/Module/Admin/Accounts.php
+++ b/Zotlabs/Module/Admin/Accounts.php
@@ -31,7 +31,8 @@ class Accounts
for ($i = 0; $i < count($users); $i++) {
// if account is blocked remove blocked bit-flag, otherwise add blocked bit-flag
$op = ($blocked[$i]) ? '& ~' : '| ';
- q("UPDATE account SET account_flags = (account_flags $op %d) WHERE account_id = %d",
+ q(
+ "UPDATE account SET account_flags = (account_flags $op %d) WHERE account_id = %d",
intval(ACCOUNT_BLOCKED),
intval($users[$i])
);
@@ -78,7 +79,8 @@ class Accounts
{
if (argc() > 2) {
$uid = argv(3);
- $account = q("SELECT * FROM account WHERE account_id = %d",
+ $account = q(
+ "SELECT * FROM account WHERE account_id = %d",
intval($uid)
);
@@ -97,7 +99,8 @@ class Accounts
notice(sprintf(t("Account '%s' deleted"), $account[0]['account_email']) . EOL);
break;
case 'block':
- q("UPDATE account SET account_flags = ( account_flags | %d ) WHERE account_id = %d",
+ q(
+ "UPDATE account SET account_flags = ( account_flags | %d ) WHERE account_id = %d",
intval(ACCOUNT_BLOCKED),
intval($uid)
);
@@ -105,7 +108,8 @@ class Accounts
notice(sprintf(t("Account '%s' blocked"), $account[0]['account_email']) . EOL);
break;
case 'unblock':
- q("UPDATE account SET account_flags = ( account_flags & ~ %d ) WHERE account_id = %d",
+ q(
+ "UPDATE account SET account_flags = ( account_flags & ~ %d ) WHERE account_id = %d",
intval(ACCOUNT_BLOCKED),
intval($uid)
);
@@ -118,7 +122,8 @@ class Accounts
}
/* get pending */
- $pending = q("SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) != 0 ",
+ $pending = q(
+ "SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) != 0 ",
intval(ACCOUNT_PENDING)
);
@@ -141,7 +146,8 @@ class Accounts
$base = z_root() . '/admin/accounts?f=';
$odir = (($dir === 'asc') ? '0' : '1');
- $users = q("SELECT account_id , account_email, account_lastlog, account_created, account_expires, account_service_class, ( account_flags & %d ) > 0 as blocked,
+ $users = q(
+ "SELECT account_id , account_email, account_lastlog, account_created, account_expires, account_service_class, ( account_flags & %d ) > 0 as blocked,
(SELECT %s FROM channel as ch WHERE ch.channel_account_id = ac.account_id and ch.channel_removed = 0 ) as channels FROM account as ac
where true $serviceclass and account_flags != %d order by $key $dir limit %d offset %d ",
intval(ACCOUNT_BLOCKED),
diff --git a/Zotlabs/Module/Admin/Addons.php b/Zotlabs/Module/Admin/Addons.php
index 5fe8e1c3a..62f57c364 100644
--- a/Zotlabs/Module/Admin/Addons.php
+++ b/Zotlabs/Module/Admin/Addons.php
@@ -226,7 +226,7 @@ class Addons
foreach ($git->git->tree('master') as $object) {
if ($object['type'] == 'blob' && (strtolower($object['file']) === 'readme.md' || strtolower($object['file']) === 'readme')) {
$repo['readme'] = MarkdownExtra::defaultTransform($git->git->cat->blob($object['hash']));
- } else if ($object['type'] == 'blob' && strtolower($object['file']) === 'manifest.json') {
+ } elseif ($object['type'] == 'blob' && strtolower($object['file']) === 'manifest.json') {
$repo['manifest'] = $git->git->cat->blob($object['hash']);
}
}
@@ -297,8 +297,9 @@ class Addons
if ($pinstalled) {
@require_once("addon/$plugin/$plugin.php");
- if (function_exists($plugin . '_plugin_admin'))
+ if (function_exists($plugin . '_plugin_admin')) {
goaway(z_root() . '/admin/addons/' . $plugin);
+ }
}
goaway(z_root() . '/admin/addons');
}
@@ -317,13 +318,14 @@ class Addons
if (is_file("addon/$plugin/README.md")) {
$readme = file_get_contents("addon/$plugin/README.md");
$readme = MarkdownExtra::defaultTransform($readme);
- } else if (is_file("addon/$plugin/README")) {
+ } elseif (is_file("addon/$plugin/README")) {
$readme = "
" . file_get_contents("addon/$plugin/README") . ""; } $admin_form = ''; - $r = q("select * from addon where plugin_admin = 1 and aname = '%s' limit 1", + $r = q( + "select * from addon where plugin_admin = 1 and aname = '%s' limit 1", dbesc($plugin) ); @@ -409,7 +411,8 @@ class Addons } $admin_plugins_add_repo_form = replace_macros( - get_markup_template('admin_plugins_addrepo.tpl'), array( + get_markup_template('admin_plugins_addrepo.tpl'), + array( '$post' => 'admin/addons/addrepo', '$desc' => t('Enter the public git repository URL of the addon repo.'), '$repoURL' => array('repoURL', t('Addon repo git URL'), '', ''), @@ -419,7 +422,8 @@ class Addons ); $newRepoModalID = random_string(3); $newRepoModal = replace_macros( - get_markup_template('generic_modal.tpl'), array( + get_markup_template('generic_modal.tpl'), + array( '$id' => $newRepoModalID, '$title' => t('Install new repo'), '$ok' => t('Install'), @@ -480,5 +484,4 @@ class Addons { return (strcmp(strtolower($a[2]['name']), strtolower($b[2]['name']))); } - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Admin/Channels.php b/Zotlabs/Module/Admin/Channels.php index 78047daf4..b34bcd182 100644 --- a/Zotlabs/Module/Admin/Channels.php +++ b/Zotlabs/Module/Admin/Channels.php @@ -27,7 +27,8 @@ class Channels if (x($_POST, 'page_channels_block')) { foreach ($channels as $uid) { - q("UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d", + q( + "UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d", intval(PAGE_CENSORED), intval($uid) ); @@ -37,7 +38,8 @@ class Channels } if (x($_POST, 'page_channels_code')) { foreach ($channels as $uid) { - q("UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d", + q( + "UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d", intval(PAGE_ALLOWCODE), intval($uid) ); @@ -63,7 +65,8 @@ class Channels { if (argc() > 2) { $uid = argv(3); - $channel = q("SELECT * FROM channel WHERE channel_id = %d", + $channel = q( + "SELECT * FROM channel WHERE channel_id = %d", intval($uid) ); @@ -80,34 +83,36 @@ class Channels channel_remove($uid, true); notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL); - } + } break; case "block": { check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); $pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED; - q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", + q( + "UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid) ); Run::Summon(['Directory', $uid, 'nopush']); notice(sprintf((($pflags & PAGE_CENSORED) ? t("Channel '%s' censored") : t("Channel '%s' uncensored")), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL); - } + } break; case "code": { check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); $pflags = $channel[0]['channel_pageflags'] ^ PAGE_ALLOWCODE; - q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", + q( + "UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid) ); notice(sprintf((($pflags & PAGE_ALLOWCODE) ? t("Channel '%s' code allowed") : t("Channel '%s' code disallowed")), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL); - } + } break; default: @@ -118,8 +123,9 @@ class Channels $key = (($_REQUEST['key']) ? dbesc($_REQUEST['key']) : 'channel_id'); $dir = 'asc'; - if (array_key_exists('dir', $_REQUEST)) + if (array_key_exists('dir', $_REQUEST)) { $dir = ((intval($_REQUEST['dir'])) ? 'asc' : 'desc'); + } $base = z_root() . '/admin/channels?f='; $odir = (($dir === 'asc') ? '0' : '1'); @@ -132,22 +138,25 @@ class Channels App::set_pager_itemspage(100); } - $channels = q("SELECT * from channel where channel_removed = 0 and channel_system = 0 order by $key $dir limit %d offset %d ", + $channels = q( + "SELECT * from channel where channel_removed = 0 and channel_system = 0 order by $key $dir limit %d offset %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']) ); if ($channels) { for ($x = 0; $x < count($channels); $x++) { - if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) + if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) { $channels[$x]['blocked'] = true; - else + } else { $channels[$x]['blocked'] = false; + } - if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE) + if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE) { $channels[$x]['allowcode'] = true; - else + } else { $channels[$x]['allowcode'] = false; + } $channels[$x]['channel_link'] = z_root() . '/channel/' . $channels[$x]['channel_address']; } @@ -187,5 +196,4 @@ class Channels return $o; } - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Admin/Cover_photo.php b/Zotlabs/Module/Admin/Cover_photo.php index 27b1d390c..d411e92bf 100644 --- a/Zotlabs/Module/Admin/Cover_photo.php +++ b/Zotlabs/Module/Admin/Cover_photo.php @@ -1,4 +1,5 @@ 0 order by imgscale asc LIMIT 1", + $r = q( + "SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND imgscale > 0 order by imgscale asc LIMIT 1", dbesc($image_id), intval($channel['channel_id']) ); if ($r) { - $max_thumb = intval(get_config('system', 'max_thumbnail', 1600)); $iscaled = false; if (intval($r[0]['height']) > $max_thumb || intval($r[0]['width']) > $max_thumb) { $imagick_path = get_config('system', 'imagick_convert_path'); if ($imagick_path && @file_exists($imagick_path) && intval($r[0]['os_storage'])) { - $fname = dbunescbin($r[0]['content']); $tmp_name = $fname . '-001'; $newsize = photo_calculate_scale(array_merge(getimagesize($fname), ['max' => $max_thumb])); $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $fname) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name); - // logger('imagick thumbnail command: ' . $cmd); + // logger('imagick thumbnail command: ' . $cmd); for ($x = 0; $x < 4; $x++) { exec($cmd); if (file_exists($tmp_name)) { @@ -128,14 +128,14 @@ class Cover_photo $im = photo_factory($base_image['content'], $base_image['mimetype']); if ($im->is_valid()) { - // We are scaling and cropping the relative pixel locations to the original photo instead of the // scaled photo we operated on. // First load the scaled photo to check its size. (Should probably pass this in the post form and save // a query.) - $g = q("select width, height from photo where resource_id = '%s' and uid = %d and imgscale = 3", + $g = q( + "select width, height from photo where resource_id = '%s' and uid = %d and imgscale = 3", dbesc($image_id), intval($channel['channel_id']) ); @@ -151,7 +151,8 @@ class Cover_photo // unset all other cover photos - q("update photo set photo_usage = %d where photo_usage = %d and uid = %d", + q( + "update photo set photo_usage = %d where photo_usage = %d and uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_COVER), intval($channel['channel_id']) @@ -196,19 +197,19 @@ class Cover_photo if ($r1 === false || $r2 === false || $r3 === false) { // if one failed, delete them all so we can start over. notice(t('Image resize failed.') . EOL); - $x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale >= 7 ", + $x = q( + "delete from photo where resource_id = '%s' and uid = %d and imgscale >= 7 ", dbesc($base_image['resource_id']), intval($channel['channel_id']) ); return; } - - } else + } else { notice(t('Unable to process image') . EOL); + } } goaway(z_root() . '/admin'); - } @@ -260,7 +261,6 @@ class Cover_photo logger('attach_store: ' . print_r($res, true), LOGGER_DEBUG); json_return_and_die(['message' => $hash]); - } @@ -284,12 +284,14 @@ class Cover_photo $newuser = false; - if (argc() == 3 && argv(1) === 'new') + if (argc() == 3 && argv(1) === 'new') { $newuser = true; + } if (argv(2) === 'reset') { - q("update photo set photo_usage = %d where photo_usage = %d and uid = %d", + q( + "update photo set photo_usage = %d where photo_usage = %d and uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_COVER), intval($channel['channel_id']) @@ -302,11 +304,12 @@ class Cover_photo return; } - // check_form_security_token_redirectOnErr('/cover_photo', 'cover_photo'); + // check_form_security_token_redirectOnErr('/cover_photo', 'cover_photo'); $resource_id = argv(3); - $r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and imgscale > 0 ORDER BY imgscale ASC", + $r = q( + "SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and imgscale > 0 ORDER BY imgscale ASC", intval($channel['channel_id']), dbesc($resource_id) ); @@ -321,10 +324,10 @@ class Cover_photo } } - $r = q("SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", + $r = q( + "SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval($channel['channel_id']) - ); if (!$r) { notice(t('Photo not available.') . EOL); @@ -341,7 +344,8 @@ class Cover_photo $smallest = 0; if ($ph->is_valid()) { // go ahead as if we have just uploaded a new photo to crop - $i = q("select resource_id, imgscale from photo where resource_id = '%s' and uid = %d and imgscale = 0", + $i = q( + "select resource_id, imgscale from photo where resource_id = '%s' and uid = %d and imgscale = 0", dbesc($r[0]['resource_id']), intval($channel['channel_id']) ); @@ -359,7 +363,6 @@ class Cover_photo if (!array_key_exists('imagecrop', App::$data)) { - $o .= replace_macros(get_markup_template('admin_cover_photo.tpl'), [ '$user' => $channel['channel_address'], '$channel_id' => $channel['channel_id'], @@ -438,6 +441,4 @@ class Cover_photo App::$page['htmlhead'] .= replace_macros(get_markup_template('crophead.tpl'), []); return; } - - } diff --git a/Zotlabs/Module/Admin/Dbsync.php b/Zotlabs/Module/Admin/Dbsync.php index 8d8cda46e..4e7519a0b 100644 --- a/Zotlabs/Module/Admin/Dbsync.php +++ b/Zotlabs/Module/Admin/Dbsync.php @@ -2,7 +2,6 @@ namespace Zotlabs\Module\Admin; - class Dbsync { @@ -15,14 +14,14 @@ class Dbsync // remove the old style config if it exists del_config('database', 'update_r' . intval(argv(3))); set_config('database', '_' . intval(argv(3)), 'success'); - if (intval(get_config('system', 'db_version')) < intval(argv(3))) + if (intval(get_config('system', 'db_version')) < intval(argv(3))) { set_config('system', 'db_version', intval(argv(3))); + } info(t('Update has been marked successful') . EOL); goaway(z_root() . '/admin/dbsync'); } if (argc() > 3 && intval(argv(3)) && argv(2) === 'verify') { - $s = '_' . intval(argv(3)); $cls = '\\Zotlabs\Update\\' . $s; if (class_exists($cls)) { @@ -34,13 +33,15 @@ class Dbsync } elseif ($retval === UPDATE_SUCCESS) { $o .= sprintf(t('Update %s was successfully applied.'), $s); set_config('database', $s, 'success'); - } else + } else { $o .= sprintf(t('Verifying update %s did not return a status. Unknown if it succeeded.'), $s); + } } else { $o .= sprintf(t('Update %s does not contain a verification function.'), $s); } - } else + } else { $o .= sprintf(t('Update function %s could not be found.'), $s); + } return $o; @@ -48,8 +49,9 @@ class Dbsync // remove the old style config if it exists del_config('database', 'update_r' . intval(argv(3))); set_config('database', '_' . intval(argv(3)), 'success'); - if (intval(get_config('system', 'db_version')) < intval(argv(3))) + if (intval(get_config('system', 'db_version')) < intval(argv(3))) { set_config('system', 'db_version', intval(argv(3))); + } info(t('Update has been marked successful') . EOL); goaway(z_root() . '/admin/dbsync'); } @@ -66,10 +68,12 @@ class Dbsync } elseif ($retval === UPDATE_SUCCESS) { $o .= sprintf(t('Update %s was successfully applied.'), $s); set_config('database', $s, 'success'); - } else + } else { $o .= sprintf(t('Update %s did not return a status. It cannot be determined if it was successful.'), $s); - } else + } + } else { $o .= sprintf(t('Update function %s could not be found.'), $s); + } return $o; } @@ -79,8 +83,9 @@ class Dbsync if (count($r)) { foreach ($r as $rr) { $upd = intval(substr($rr['k'], -4)); - if ($rr['v'] === 'success') + if ($rr['v'] === 'success') { continue; + } $failed[] = $upd; } } @@ -100,4 +105,4 @@ class Dbsync return $o; } -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Admin/Logs.php b/Zotlabs/Module/Admin/Logs.php index f5c5fa325..e41b80675 100644 --- a/Zotlabs/Module/Admin/Logs.php +++ b/Zotlabs/Module/Admin/Logs.php @@ -2,7 +2,6 @@ namespace Zotlabs\Module\Admin; - class Logs { @@ -64,13 +63,15 @@ class Logs $fstat = fstat($fp); $size = $fstat['size']; if ($size != 0) { - if ($size > 5000000 || $size < 0) + if ($size > 5000000 || $size < 0) { $size = 5000000; + } $seek = fseek($fp, 0 - $size, SEEK_END); if ($seek === 0) { $data = escape_tags(fread($fp, $size)); - while (!feof($fp)) + while (!feof($fp)) { $data .= escape_tags(fread($fp, 4096)); + } } } fclose($fp); @@ -94,6 +95,4 @@ class Logs '$form_security_token' => get_form_security_token('admin_logs'), )); } - - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Admin/Profile_photo.php b/Zotlabs/Module/Admin/Profile_photo.php index a888503ec..bfe966ddb 100644 --- a/Zotlabs/Module/Admin/Profile_photo.php +++ b/Zotlabs/Module/Admin/Profile_photo.php @@ -1,4 +1,5 @@ is_valid()) { - $im->cropImage(300, $srcX, $srcY, $srcW, $srcH); $aid = 0; @@ -144,7 +143,8 @@ class Profile_photo if ($r1 === false || $r2 === false || $r3 === false) { // if one failed, delete them all so we can start over. notice(t('Image resize failed.') . EOL); - $x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale in ( %d, %d, %d ) ", + $x = q( + "delete from photo where resource_id = '%s' and uid = %d and imgscale in ( %d, %d, %d ) ", dbesc($base_image['resource_id']), $channel['channel_id'], intval(PHOTO_RES_PROFILE_300), @@ -155,7 +155,8 @@ class Profile_photo } - $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d + $r = q( + "UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), @@ -169,7 +170,8 @@ class Profile_photo // changed to a generic URL by a clone operation. Otherwise the new photo may // not get pushed to other sites correctly. - $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s' + $r = q( + "UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s' where xchan_hash = '%s'", dbesc($im->getType()), dbesc(datetime_convert()), @@ -185,7 +187,6 @@ class Profile_photo Config::Set('system', 'site_icon_url', z_root() . '/photo/profile/m/' . $channel['channel_id']); info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL); - } else { notice(t('Unable to process image') . EOL); } @@ -207,7 +208,6 @@ class Profile_photo $hash = $_REQUEST['importfile']; $importing = true; } else { - $matches = []; $partial = false; @@ -256,7 +256,8 @@ class Profile_photo } if (($res && intval($res['data']['is_photo'])) || $importing) { - $i = q("select * from photo where resource_id = '%s' and uid = %d order by imgscale", + $i = q( + "select * from photo where resource_id = '%s' and uid = %d order by imgscale", dbesc($hash), intval($channel['channel_hash']) ); @@ -330,7 +331,8 @@ class Profile_photo $pf = (($_REQUEST['pf']) ? intval($_REQUEST['pf']) : 0); - $c = q("select id, is_default from profile where uid = %d", + $c = q( + "select id, is_default from profile where uid = %d", intval($channel['channel_id']) ); @@ -343,7 +345,8 @@ class Profile_photo $_REQUEST['profile'] = $pf; } - $r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY imgscale ASC", + $r = q( + "SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY imgscale ASC", intval($channel['channel_id']), dbesc($resource_id) ); @@ -362,19 +365,22 @@ class Profile_photo if ($havescale) { // unset any existing profile photos - $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", + $r = q( + "UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($channel['channel_id']) ); - $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", + $r = q( + "UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval($channel['channel_id']), dbesc($resource_id) ); - $r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", + $r = q( + "UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($channel['xchan_hash']) ); @@ -382,10 +388,10 @@ class Profile_photo goaway(z_root() . '/admin'); } - $r = q("SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", + $r = q( + "SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval($channel['channel_id']) - ); if (!$r) { notice(t('Photo not available.') . EOL); @@ -402,7 +408,8 @@ class Profile_photo $smallest = 0; if ($ph->is_valid()) { // go ahead as if we have just uploaded a new photo to crop - $i = q("select resource_id, imgscale from photo where resource_id = '%s' and uid = %d order by imgscale", + $i = q( + "select resource_id, imgscale from photo where resource_id = '%s' and uid = %d order by imgscale", dbesc($r[0]['resource_id']), intval($channel['channel_id']) ); @@ -424,12 +431,12 @@ class Profile_photo } // falls through with App::$data['imagecrop'] set so we go straight to the cropping section - } // present an upload form - $profiles = q("select id, profile_name as name, is_default from profile where uid = %d order by id asc", + $profiles = q( + "select id, profile_name as name, is_default from profile where uid = %d order by id asc", intval($channel['channel_id']) ); @@ -448,7 +455,6 @@ class Profile_photo $importing = ((array_key_exists('importfile', App::$data)) ? true : false); if (!array_key_exists('imagecrop', App::$data)) { - $tpl = get_markup_template('admin_profile_photo.tpl'); $o .= replace_macros($tpl, [ @@ -480,7 +486,6 @@ class Profile_photo call_hooks('profile_photo_content_end', $o); return $o; } else { - // present a cropping form $filename = App::$data['imagecrop'] . '-' . App::$data['imagecrop_resolution']; diff --git a/Zotlabs/Module/Admin/Profs.php b/Zotlabs/Module/Admin/Profs.php index 9a42444dc..4a09d372c 100644 --- a/Zotlabs/Module/Admin/Profs.php +++ b/Zotlabs/Module/Admin/Profs.php @@ -2,7 +2,6 @@ namespace Zotlabs\Module\Admin; - class Profs { @@ -20,10 +19,11 @@ class Profs } } } - if (!$narr) + if (!$narr) { del_config('system', 'profile_fields_basic'); - else + } else { set_config('system', 'profile_fields_basic', $narr); + } if (array_key_exists('advanced', $_REQUEST)) { @@ -37,11 +37,11 @@ class Profs } } } - if (!$narr) + if (!$narr) { del_config('system', 'profile_fields_advanced'); - else + } else { set_config('system', 'profile_fields_advanced', $narr); - + } } goaway(z_root() . '/admin/profs'); } @@ -49,7 +49,8 @@ class Profs if (array_key_exists('field_name', $_REQUEST)) { if ($_REQUEST['id']) { - $r = q("update profdef set field_name = '%s', field_type = '%s', field_desc = '%s' field_help = '%s', field_inputs = '%s' where id = %d", + $r = q( + "update profdef set field_name = '%s', field_type = '%s', field_desc = '%s' field_help = '%s', field_inputs = '%s' where id = %d", dbesc($_REQUEST['field_name']), dbesc($_REQUEST['field_type']), dbesc($_REQUEST['field_desc']), @@ -58,7 +59,8 @@ class Profs intval($_REQUEST['id']) ); } else { - $r = q("insert into profdef ( field_name, field_type, field_desc, field_help, field_inputs ) values ( '%s' , '%s', '%s', '%s', '%s' )", + $r = q( + "insert into profdef ( field_name, field_type, field_desc, field_help, field_inputs ) values ( '%s' , '%s', '%s', '%s', '%s' )", dbesc($_REQUEST['field_name']), dbesc($_REQUEST['field_type']), dbesc($_REQUEST['field_desc']), @@ -78,7 +80,8 @@ class Profs { if ((argc() > 3) && argv(2) == 'drop' && intval(argv(3))) { - $r = q("delete from profdef where id = %d", + $r = q( + "delete from profdef where id = %d", intval(argv(3)) ); // remove from allowed fields @@ -98,7 +101,8 @@ class Profs } if ((argc() > 2) && intval(argv(2))) { - $r = q("select * from profdef where id = %d limit 1", + $r = q( + "select * from profdef where id = %d limit 1", intval(argv(2)) ); if (!$r) { @@ -121,12 +125,14 @@ class Profs $barr = []; $fields = get_profile_fields_basic(); - if (!$fields) + if (!$fields) { $fields = get_profile_fields_basic(1); + } if ($fields) { foreach ($fields as $k => $v) { - if ($basic) + if ($basic) { $basic .= ', '; + } $basic .= trim($k); $barr[] = trim($k); } @@ -134,14 +140,17 @@ class Profs $advanced = ''; $fields = get_profile_fields_advanced(); - if (!$fields) + if (!$fields) { $fields = get_profile_fields_advanced(1); + } if ($fields) { foreach ($fields as $k => $v) { - if (in_array(trim($k), $barr)) + if (in_array(trim($k), $barr)) { continue; - if ($advanced) + } + if ($advanced) { $advanced .= ', '; + } $advanced .= trim($k); } } @@ -150,8 +159,9 @@ class Profs $fields = get_profile_fields_advanced(1); if ($fields) { foreach ($fields as $k => $v) { - if ($all) + if ($all) { $all .= ', '; + } $all .= trim($k); } } @@ -159,8 +169,9 @@ class Profs $r = q("select * from profdef where true"); if ($r) { foreach ($r as $rr) { - if ($all) + if ($all) { $all .= ', '; + } $all .= $rr['field_name']; } } @@ -181,9 +192,5 @@ class Profs )); return $o; - - } - - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Admin/Queue.php b/Zotlabs/Module/Admin/Queue.php index b6fd6b291..136dd46f5 100644 --- a/Zotlabs/Module/Admin/Queue.php +++ b/Zotlabs/Module/Admin/Queue.php @@ -46,6 +46,4 @@ class Queue return $o; } - - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Admin/Security.php b/Zotlabs/Module/Admin/Security.php index b966322ce..70c5673fe 100644 --- a/Zotlabs/Module/Admin/Security.php +++ b/Zotlabs/Module/Admin/Security.php @@ -2,7 +2,6 @@ namespace Zotlabs\Module\Admin; - class Security { @@ -19,13 +18,13 @@ class Security $anonymous_comments = ((x($_POST, 'anonymous_comments')) ? intval($_POST['anonymous_comments']) : 0); set_config('system', 'anonymous_comments', $anonymous_comments); - $block_public = ((x($_POST, 'block_public')) ? True : False); + $block_public = ((x($_POST, 'block_public')) ? true : false); set_config('system', 'block_public', $block_public); $block_public_search = ((x($_POST, 'block_public_search')) ? 1 : 0); set_config('system', 'block_public_search', $block_public_search); - $block_public_dir = ((x($_POST, 'block_public_directory')) ? True : False); + $block_public_dir = ((x($_POST, 'block_public_directory')) ? true : false); set_config('system', 'block_public_directory', $block_public_dir); $localdir_hide = ((x($_POST, 'localdir_hide')) ? 1 : 0); @@ -67,7 +66,7 @@ class Security $bc = $this->trim_array_elems(explode("\n", $_POST['pubstream_denied_channels'])); set_config('system', 'pubstream_denied_channels', $bc); - $embed_sslonly = ((x($_POST, 'embed_sslonly')) ? True : False); + $embed_sslonly = ((x($_POST, 'embed_sslonly')) ? true : false); set_config('system', 'embed_sslonly', $embed_sslonly); $we = $this->trim_array_elems(explode("\n", $_POST['embed_allow'])); @@ -76,10 +75,10 @@ class Security $be = $this->trim_array_elems(explode("\n", $_POST['embed_deny'])); set_config('system', 'embed_deny', $be); - $ts = ((x($_POST, 'transport_security')) ? True : False); + $ts = ((x($_POST, 'transport_security')) ? true : false); set_config('system', 'transport_security_header', $ts); - $cs = ((x($_POST, 'content_security')) ? True : False); + $cs = ((x($_POST, 'content_security')) ? true : false); set_config('system', 'content_security_policy', $cs); goaway(z_root() . '/admin/security'); @@ -165,7 +164,7 @@ class Security '$embed_allow' => array('embed_allow', t('Allow unfiltered embedded HTML content only from these domains'), $allowedembeds_str, t('One site per line. By default embedded content is filtered.')), '$embed_deny' => array('embed_deny', t('Block embedded HTML from these domains'), $deniedembeds_str, ''), -// '$embed_coop' => array('embed_coop', t('Cooperative embed security'), $embed_coop, t('Enable to share embed security with other compatible sites/hubs')), +// '$embed_coop' => array('embed_coop', t('Cooperative embed security'), $embed_coop, t('Enable to share embed security with other compatible sites/hubs')), '$submit' => t('Submit') )); @@ -179,12 +178,11 @@ class Security if ($arr && is_array($arr)) { for ($x = 0; $x < count($arr); $x++) { $y = trim($arr[$x]); - if ($y) + if ($y) { $narr[] = $y; + } } } return $narr; } - - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index 5e0326759..f31f3a58f 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -34,14 +34,14 @@ class Site $siteinfo = ((x($_POST, 'siteinfo')) ? trim($_POST['siteinfo']) : ''); $language = ((x($_POST, 'language')) ? notags(trim($_POST['language'])) : 'en'); $theme = ((x($_POST, 'theme')) ? notags(trim($_POST['theme'])) : ''); -// $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : ''); -// $site_channel = ((x($_POST,'site_channel')) ? notags(trim($_POST['site_channel'])) : ''); +// $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : ''); +// $site_channel = ((x($_POST,'site_channel')) ? notags(trim($_POST['site_channel'])) : ''); $maximagesize = ((x($_POST, 'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0); $register_policy = ((x($_POST, 'register_policy')) ? intval(trim($_POST['register_policy'])) : 0); $minimum_age = ((x($_POST, 'minimum_age')) ? intval(trim($_POST['minimum_age'])) : 13); $access_policy = ((x($_POST, 'access_policy')) ? intval(trim($_POST['access_policy'])) : 0); - $invite_only = ((x($_POST, 'invite_only')) ? True : False); + $invite_only = ((x($_POST, 'invite_only')) ? true : false); $abandon_days = ((x($_POST, 'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0); $register_text = ((x($_POST, 'register_text')) ? notags(trim($_POST['register_text'])) : ''); @@ -56,14 +56,14 @@ class Site } $mirror_frontpage = ((x($_POST, 'mirror_frontpage')) ? intval(trim($_POST['mirror_frontpage'])) : 0); $directory_server = ((x($_POST, 'directory_server')) ? trim($_POST['directory_server']) : ''); - $force_publish = ((x($_POST, 'publish_all')) ? True : False); - $open_pubstream = ((x($_POST, 'open_pubstream')) ? True : False); + $force_publish = ((x($_POST, 'publish_all')) ? true : false); + $open_pubstream = ((x($_POST, 'open_pubstream')) ? true : false); $public_stream_mode = ((x($_POST, 'public_stream_mode')) ? intval($_POST['public_stream_mode']) : PUBLIC_STREAM_NONE); - $animations = ((x($_POST, 'animations')) ? True : False); - $login_on_homepage = ((x($_POST, 'login_on_homepage')) ? True : False); - $enable_context_help = ((x($_POST, 'enable_context_help')) ? True : False); + $animations = ((x($_POST, 'animations')) ? true : false); + $login_on_homepage = ((x($_POST, 'login_on_homepage')) ? true : false); + $enable_context_help = ((x($_POST, 'enable_context_help')) ? true : false); $global_directory = ((x($_POST, 'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : ''); - $no_community_page = !((x($_POST, 'no_community_page')) ? True : False); + $no_community_page = !((x($_POST, 'no_community_page')) ? true : false); $default_expire_days = ((array_key_exists('default_expire_days', $_POST)) ? intval($_POST['default_expire_days']) : 0); $active_expire_days = ((array_key_exists('active_expire_days', $_POST)) ? intval($_POST['active_expire_days']) : 7); $max_imported_follow = ((x($_POST, 'max_imported_follow')) ? intval(trim($_POST['max_imported_follow'])) : MAX_IMPORTED_FOLLOW); @@ -72,7 +72,7 @@ class Site $from_email = ((array_key_exists('from_email', $_POST) && trim($_POST['from_email'])) ? trim($_POST['from_email']) : 'Administrator@' . App::get_hostname()); $from_email_name = ((array_key_exists('from_email_name', $_POST) && trim($_POST['from_email_name'])) ? trim($_POST['from_email_name']) : System::get_site_name()); - $verifyssl = ((x($_POST, 'verifyssl')) ? True : False); + $verifyssl = ((x($_POST, 'verifyssl')) ? true : false); $proxyuser = ((x($_POST, 'proxyuser')) ? notags(trim($_POST['proxyuser'])) : ''); $proxy = ((x($_POST, 'proxy')) ? notags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST, 'timeout')) ? intval(trim($_POST['timeout'])) : 60); @@ -83,7 +83,7 @@ class Site $delivery_batch_count = ((x($_POST, 'delivery_batch_count') && $_POST['delivery_batch_count'] > 0) ? intval(trim($_POST['delivery_batch_count'])) : 3); $poll_interval = ((x($_POST, 'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); $maxloadavg = ((x($_POST, 'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); -// $feed_contacts = ((x($_POST,'feed_contacts')) ? intval($_POST['feed_contacts']) : 0); +// $feed_contacts = ((x($_POST,'feed_contacts')) ? intval($_POST['feed_contacts']) : 0); $ap_contacts = ((x($_POST, 'ap_contacts')) ? intval($_POST['ap_contacts']) : 0); $verify_email = ((x($_POST, 'verify_email')) ? 1 : 0); $imagick_path = ((x($_POST, 'imagick_path')) ? trim($_POST['imagick_path']) : ''); @@ -93,7 +93,7 @@ class Site $permissions_role = escape_tags(trim($_POST['permissions_role'])); -// set_config('system', 'feed_contacts', $feed_contacts); +// set_config('system', 'feed_contacts', $feed_contacts); set_config('system', 'activitypub', $ap_contacts); set_config('system', 'delivery_interval', $delivery_interval); set_config('system', 'delivery_batch_count', $delivery_batch_count); @@ -138,19 +138,23 @@ class Site // sync sitename and siteinfo updates to the system channel - q("update profile set about = '%s' where uid = %d and is_default = 1", + q( + "update profile set about = '%s' where uid = %d and is_default = 1", dbesc($siteinfo), intval($sys['channel_id']) ); - q("update profile set fullname = '%s' where uid = %d and is_default = 1", + q( + "update profile set fullname = '%s' where uid = %d and is_default = 1", dbesc($sitename), intval($sys['channel_id']) ); - q("update channel set channel_name = '%s' where channel_id = %d", + q( + "update channel set channel_name = '%s' where channel_id = %d", dbesc($sitename), intval($sys['channel_id']) ); - q("update xchan set xchan_name = '%s' , xchan_name_updated = '%s' where xchan_hash = '%s'", + q( + "update xchan set xchan_name = '%s' , xchan_name_updated = '%s' where xchan_hash = '%s'", dbesc($sitename), dbesc(datetime_convert()), dbesc($sys['channel_hash']) @@ -158,7 +162,7 @@ class Site set_config('system', 'language', $language); set_config('system', 'theme', $theme); - // set_config('system','site_channel', $site_channel); + // set_config('system','site_channel', $site_channel); set_config('system', 'maximagesize', $maximagesize); set_config('system', 'register_policy', $register_policy); @@ -203,8 +207,9 @@ class Site $langs = glob('view/*/strings.php'); if (is_array($langs) && count($langs)) { - if (!in_array('view/en/strings.php', $langs)) + if (!in_array('view/en/strings.php', $langs)) { $langs[] = 'view/en/'; + } asort($langs); foreach ($langs as $l) { $t = explode("/", $l); @@ -228,14 +233,18 @@ class Site continue; } - if (file_exists($file . '/library')) + if (file_exists($file . '/library')) { continue; - if (file_exists($file . '/mobile')) + } + if (file_exists($file . '/mobile')) { $vars = t('mobile'); - if (file_exists($file . '/experimental')) + } + if (file_exists($file . '/experimental')) { $vars .= t('experimental'); - if (file_exists($file . '/unsupported')) + } + if (file_exists($file . '/unsupported')) { $vars .= t('unsupported'); + } if ($vars) { $theme_choices[$f] = $f . ' (' . $vars . ')'; $theme_choices_mobile[$f] = $f . ' (' . $vars . ')'; @@ -254,7 +263,8 @@ class Site // avoid older redmatrix servers which don't have modern encryption if ($dirmode == DIRECTORY_MODE_NORMAL) { - $x = q("select site_url from site where site_flags in (%d,%d) and site_realm = '%s' and site_dead = 0", + $x = q( + "select site_url from site where site_flags in (%d,%d) and site_realm = '%s' and site_dead = 0", intval(DIRECTORY_MODE_SECONDARY), intval(DIRECTORY_MODE_PRIMARY), dbesc($realm) @@ -311,8 +321,8 @@ class Site '$siteinfo' => ['siteinfo', t('Site Information'), get_config('system', 'siteinfo'), t("Publicly visible description of this site. Displayed on siteinfo page. BBCode may be used here.")], '$language' => ['language', t("System language"), get_config('system', 'language', 'en'), "", $lang_choices], '$theme' => ['theme', t("System theme"), get_config('system', 'theme'), t("Default system theme - may be over-ridden by user profiles - change theme settings"), $theme_choices], -// '$theme_mobile' => [ 'theme_mobile', t("Mobile system theme"), get_config('system','mobile_theme'), t("Theme for mobile devices"), $theme_choices_mobile ], -// '$site_channel' => [ 'site_channel', t("Channel to use for this website's static pages"), get_config('system','site_channel'), t("Site Channel") ], +// '$theme_mobile' => [ 'theme_mobile', t("Mobile system theme"), get_config('system','mobile_theme'), t("Theme for mobile devices"), $theme_choices_mobile ], +// '$site_channel' => [ 'site_channel', t("Channel to use for this website's static pages"), get_config('system','site_channel'), t("Site Channel") ], '$ap_contacts' => ['ap_contacts', t('ActivityPub protocol'), get_config('system', 'activitypub', ACTIVITYPUB_ENABLED), t('Provides access to software supporting the ActivityPub protocol.')], '$maximagesize' => ['maximagesize', t("Maximum image size"), intval(get_config('system', 'maximagesize')), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")], '$cache_images' => ['cache_images', t('Cache all public images'), intval(get_config('system', 'cache_images', 1)), t('If disabled, proxy non-SSL images, but do not store locally')], @@ -366,5 +376,4 @@ class Site '$form_security_token' => get_form_security_token("admin_site"), ]); } - } diff --git a/Zotlabs/Module/Admin/Themes.php b/Zotlabs/Module/Admin/Themes.php index 2f30f1618..20bbd508b 100644 --- a/Zotlabs/Module/Admin/Themes.php +++ b/Zotlabs/Module/Admin/Themes.php @@ -27,8 +27,9 @@ class Themes } } info(t('Theme settings updated.')); - if (is_ajax()) + if (is_ajax()) { return; + } goaway(z_root() . '/admin/themes/' . $theme); } @@ -44,10 +45,13 @@ class Themes $allowed_themes_str = get_config('system', 'allowed_themes'); $allowed_themes_raw = explode(',', $allowed_themes_str); $allowed_themes = []; - if (count($allowed_themes_raw)) - foreach ($allowed_themes_raw as $x) - if (strlen(trim($x))) + if (count($allowed_themes_raw)) { + foreach ($allowed_themes_raw as $x) { + if (strlen(trim($x))) { $allowed_themes[] = trim($x); + } + } + } $themes = []; $files = glob('view/theme/*'); @@ -84,10 +88,11 @@ class Themes $this->toggle_theme($themes, $theme, $result); $s = $this->rebuild_theme_table($themes); - if ($result) + if ($result) { info(sprintf('Theme %s enabled.', $theme)); - else + } else { info(sprintf('Theme %s disabled.', $theme)); + } set_config('system', 'allowed_themes', $s); goaway(z_root() . '/admin/themes'); @@ -103,11 +108,11 @@ class Themes $action = t("Enable"); } - $readme = Null; + $readme = null; if (is_file("view/theme/$theme/README.md")) { $readme = file_get_contents("view/theme/$theme/README.md"); $readme = MarkdownExtra::defaultTransform($readme); - } else if (is_file("view/theme/$theme/README")) { + } elseif (is_file("view/theme/$theme/README")) { $readme = '
' . file_get_contents("view/theme/$theme/README") . ''; } @@ -120,8 +125,9 @@ class Themes } $screenshot = array(get_theme_screenshot($theme), t('Screenshot')); - if (!stristr($screenshot[0], $theme)) + if (!stristr($screenshot[0], $theme)) { $screenshot = null; + } $t = get_markup_template('admin_plugins_details.tpl'); return replace_macros($t, array( @@ -223,13 +229,13 @@ class Themes if (count($themes)) { foreach ($themes as $th) { if ($th['allowed']) { - if (strlen($o)) + if (strlen($o)) { $o .= ','; + } $o .= $th['name']; } } } return $o; } - } diff --git a/Zotlabs/Module/Affinity.php b/Zotlabs/Module/Affinity.php index 052245114..1df26928b 100644 --- a/Zotlabs/Module/Affinity.php +++ b/Zotlabs/Module/Affinity.php @@ -18,20 +18,20 @@ class Affinity extends Controller if ($_POST['affinity-submit']) { $cmax = intval($_POST['affinity_cmax']); - if ($cmax < 0 || $cmax > 99) + if ($cmax < 0 || $cmax > 99) { $cmax = 99; + } $cmin = intval($_POST['affinity_cmin']); - if ($cmin < 0 || $cmin > 99) + if ($cmin < 0 || $cmin > 99) { $cmin = 0; + } set_pconfig(local_channel(), 'affinity', 'cmin', 0); set_pconfig(local_channel(), 'affinity', 'cmax', $cmax); info(t('Friend Zoom settings updated.') . EOL); - } Libsync::build_sync_packet(); - } @@ -52,12 +52,11 @@ class Affinity extends Controller $cmax = intval(get_pconfig(local_channel(), 'affinity', 'cmax')); $cmax = (($cmax) ? $cmax : 99); -// $setting_fields .= replace_macros(get_markup_template('field_input.tpl'), array( -// '$field' => array('affinity_cmax', t('Default maximum affinity level'), $cmax, t('0-99 default 99')) -// )); +// $setting_fields .= replace_macros(get_markup_template('field_input.tpl'), array( +// '$field' => array('affinity_cmax', t('Default maximum affinity level'), $cmax, t('0-99 default 99')) +// )); if (Apps::system_app_installed(local_channel(), 'Friend Zoom')) { - $labels = array( 0 => t('Me'), 20 => t('Family'), @@ -90,6 +89,4 @@ class Affinity extends Controller return $s; } - - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Album.php b/Zotlabs/Module/Album.php index 81dd48a26..dda4d9bce 100644 --- a/Zotlabs/Module/Album.php +++ b/Zotlabs/Module/Album.php @@ -1,4 +1,5 @@ 2) { $folder = argv(2); - $r = q("select * from attach where is_dir = 1 and hash = '%s' and uid = %d $sql_extra limit 1", + $r = q( + "select * from attach where is_dir = 1 and hash = '%s' and uid = %d $sql_extra limit 1", dbesc($folder), intval($channel['channel_id']) ); @@ -73,7 +74,8 @@ class Album extends Controller http_status_exit(403, 'Permission denied.'); } - $x = q("select * from attach where folder = '%s' and uid = %d $sql_extra", + $x = q( + "select * from attach where folder = '%s' and uid = %d $sql_extra", dbesc($folder), intval($channel['channel_id']) ); @@ -96,8 +98,6 @@ class Album extends Controller $obj = Activity::encode_simple_collection($contents, App::$query_string, 'OrderedCollection', count($contents)); as_return_and_die($obj, $channel); - } - } -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Ap_probe.php b/Zotlabs/Module/Ap_probe.php index ee60ab8e8..478a1eb62 100644 --- a/Zotlabs/Module/Ap_probe.php +++ b/Zotlabs/Module/Ap_probe.php @@ -1,4 +1,5 @@ ' . str_replace('\\n', "\n", htmlspecialchars(json_encode($x, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT))) . ''; } - } return $o; } - } diff --git a/Zotlabs/Module/Api.php b/Zotlabs/Module/Api.php index 6a6874412..a64a7fad6 100644 --- a/Zotlabs/Module/Api.php +++ b/Zotlabs/Module/Api.php @@ -1,4 +1,5 @@ oauth_get_client($request); - if (is_null($app)) + if (is_null($app)) { return "Invalid request. Unknown token."; + } $consumer = new OAuth1Consumer($app['client_id'], $app['pw'], $app['redirect_uri']); @@ -74,8 +72,9 @@ class Api extends Controller if ($consumer->callback_url != null) { $params = $request->get_parameters(); $glue = '?'; - if (strstr($consumer->callback_url, $glue)) + if (strstr($consumer->callback_url, $glue)) { $glue = '?'; + } goaway($consumer->callback_url . $glue . "oauth_token=" . OAuth1Util::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuth1Util::urlencode_rfc3986($verifier)); killme(); } @@ -98,8 +97,9 @@ class Api extends Controller } $app = $this->oauth_get_client($request); - if (is_null($app)) + if (is_null($app)) { return "Invalid request. Unknown token."; + } $tpl = get_markup_template('oauth_authorize.tpl'); $o = replace_macros($tpl, array( @@ -125,15 +125,15 @@ class Api extends Controller $params = $request->get_parameters(); $token = $params['oauth_token']; - $r = q("SELECT clients.* FROM clients, tokens WHERE clients.client_id = tokens.client_id + $r = q( + "SELECT clients.* FROM clients, tokens WHERE clients.client_id = tokens.client_id AND tokens.id = '%s' AND tokens.auth_scope = 'request' ", dbesc($token) ); - if ($r) + if ($r) { return $r[0]; + } return null; - } - } diff --git a/Zotlabs/Module/Appman.php b/Zotlabs/Module/Appman.php index 105aa7792..8963b3f6b 100644 --- a/Zotlabs/Module/Appman.php +++ b/Zotlabs/Module/Appman.php @@ -1,6 +1,6 @@ $embed, '$submit' => t('Submit') ]); - } - } diff --git a/Zotlabs/Module/Apps.php b/Zotlabs/Module/Apps.php index 6f5d14fc0..99cfacc64 100644 --- a/Zotlabs/Module/Apps.php +++ b/Zotlabs/Module/Apps.php @@ -1,4 +1,5 @@ (($available) ? EMPTY_STR : t('Manage apps')), '$create' => (($mode == 'edit') ? t('Create Custom App') : '') )); - } - } diff --git a/Zotlabs/Module/Apschema.php b/Zotlabs/Module/Apschema.php index 53e7f0dbe..9b5c68e0b 100644 --- a/Zotlabs/Module/Apschema.php +++ b/Zotlabs/Module/Apschema.php @@ -18,8 +18,5 @@ class Apschema extends Controller header('Content-Type: application/ld+json'); echo json_encode($arr, JSON_UNESCAPED_SLASHES); killme(); - } - - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Attach.php b/Zotlabs/Module/Attach.php index 9aa254bc8..4c45b2bee 100644 --- a/Zotlabs/Module/Attach.php +++ b/Zotlabs/Module/Attach.php @@ -1,4 +1,5 @@ send(); killme(); } - } diff --git a/Zotlabs/Module/Block.php b/Zotlabs/Module/Block.php index 1dfdae59a..4b16d03bd 100644 --- a/Zotlabs/Module/Block.php +++ b/Zotlabs/Module/Block.php @@ -1,4 +1,5 @@ 1) + if (argc() > 1) { $which = argv(1); - else + } else { return; + } Libprofile::load($which); - } @@ -64,7 +65,8 @@ class Blocks extends Controller if (!$owner) { // Figure out who the page owner is. - $r = q("select channel_id from channel where channel_address = '%s'", + $r = q( + "select channel_id from channel where channel_address = '%s'", dbesc($which) ); if ($r) { @@ -109,17 +111,21 @@ class Blocks extends Controller 'bbcode' => true ); - if ($_REQUEST['title']) + if ($_REQUEST['title']) { $x['title'] = $_REQUEST['title']; - if ($_REQUEST['body']) + } + if ($_REQUEST['body']) { $x['body'] = $_REQUEST['body']; - if ($_REQUEST['pagetitle']) + } + if ($_REQUEST['pagetitle']) { $x['pagetitle'] = $_REQUEST['pagetitle']; + } $editor = status_editor($x); - $r = q("select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig + $r = q( + "select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig left join item on iconfig.iid = item.id where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK' and item_type = %d order by item.created desc", @@ -176,5 +182,4 @@ class Blocks extends Controller return $o; } - } diff --git a/Zotlabs/Module/Ca.php b/Zotlabs/Module/Ca.php index 749c082bb..96caace69 100644 --- a/Zotlabs/Module/Ca.php +++ b/Zotlabs/Module/Ca.php @@ -1,7 +1,9 @@ var profile_uid = " . ((App::$data['channel']) ? App::$data['channel']['channel_id'] : 0) . "; "; - } return; @@ -115,26 +113,29 @@ class Cal extends Controller } if ($mode == 'view') { - /* edit/create form */ if ($event_id) { - $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", + $r = q( + "SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", dbesc($event_id), intval($channel['channel_id']) ); - if (count($r)) + if (count($r)) { $orig_event = $r[0]; + } } // Passed parameters overrides anything found in the DB - if (!x($orig_event)) + if (!x($orig_event)) { $orig_event = []; + } $tz = date_default_timezone_get(); - if (x($orig_event)) + if (x($orig_event)) { $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); + } $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); @@ -157,8 +158,9 @@ class Cal extends Controller $type = ((x($orig_event)) ? $orig_event['etype'] : 'event'); $f = get_config('system', 'event_input_format'); - if (!$f) + if (!$f) { $f = 'ymd'; + } $catsenabled = Apps::system_app_installed(local_channel(), 'Categories'); @@ -173,18 +175,22 @@ class Cal extends Controller $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y'); $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm'); - if (!$y) + if (!$y) { $y = intval($thisyear); - if (!$m) + } + if (!$m) { $m = intval($thismonth); + } // Put some limits on dates. The PHP date functions don't seem to do so well before 1900. // An upper limit was chosen to keep search engines from exploring links millions of years in the future. - if ($y < 1901) + if ($y < 1901) { $y = 1900; - if ($y > 2099) + } + if ($y > 2099) { $y = 2100; + } $nextyear = $y; $nextmonth = $m + 1; @@ -194,9 +200,9 @@ class Cal extends Controller } $prevyear = $y; - if ($m > 1) + if ($m > 1) { $prevmonth = $m - 1; - else { + } else { $prevmonth = 12; $prevyear--; } @@ -207,8 +213,12 @@ class Cal extends Controller if (argv(2) === 'json') { - if (x($_GET, 'start')) $start = $_GET['start']; - if (x($_GET, 'end')) $finish = $_GET['end']; + if (x($_GET, 'start')) { + $start = $_GET['start']; + } + if (x($_GET, 'end')) { + $finish = $_GET['end']; + } } $start = datetime_convert('UTC', 'UTC', $start); @@ -218,11 +228,13 @@ class Cal extends Controller $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); - if (!perm_is_allowed(App::$profile['uid'], get_observer_hash(), 'view_contacts')) + if (!perm_is_allowed(App::$profile['uid'], get_observer_hash(), 'view_contacts')) { $sql_extra .= " and etype != 'birthday' "; + } if (x($_GET, 'id')) { - $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan + $r = q( + "SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d $sql_extra limit 1", intval($channel['channel_id']), intval($_GET['id']) @@ -233,7 +245,8 @@ class Cal extends Controller // Noting this for now - it will need to be fixed here and in Friendica. // Ultimately the finish date shouldn't be involved in the query. - $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan + $r = q( + "SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan from event left join item on event_hash = resource_id where resource_type = 'event' and event.uid = %d and event.uid = item.uid $ignored AND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) @@ -244,7 +257,6 @@ class Cal extends Controller dbesc($adjust_start), dbesc($adjust_finish) ); - } $links = []; @@ -259,8 +271,9 @@ class Cal extends Controller if ($r) { foreach ($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j')); - if (!x($links, $j)) + if (!x($links, $j)) { $links[$j] = z_root() . '/' . App::$cmd . '#link-' . $j; + } } } @@ -270,9 +283,7 @@ class Cal extends Controller $fmt = t('l, F j'); if ($r) { - foreach ($r as $rr) { - $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j')); $d = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt)); $d = day_translate($d); @@ -319,8 +330,6 @@ class Cal extends Controller 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''), ); - - } } @@ -362,7 +371,5 @@ class Cal extends Controller return $o; } - } - } diff --git a/Zotlabs/Module/Calendar.php b/Zotlabs/Module/Calendar.php index 31cb47209..5794d0bbf 100644 --- a/Zotlabs/Module/Calendar.php +++ b/Zotlabs/Module/Calendar.php @@ -1,4 +1,5 @@ 2) && (argv(1) === 'ignore') && intval(argv(2))) { - $r = q("update event set dismissed = 1 where id = %d and uid = %d", + $r = q( + "update event set dismissed = 1 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()) ); } if ((argc() > 2) && (argv(1) === 'unignore') && intval(argv(2))) { - $r = q("update event set dismissed = 0 where id = %d and uid = %d", + $r = q( + "update event set dismissed = 0 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()) ); @@ -309,10 +315,10 @@ class Calendar extends Controller } if ($mode == 'view') { - /* edit/create form */ if ($event_id) { - $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", + $r = q( + "SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", dbesc($event_id), intval(local_channel()) ); @@ -339,14 +345,16 @@ class Calendar extends Controller $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); if (x($_GET, 'id')) { - $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan, item.id as item_id + $r = q( + "SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan, item.id as item_id from event left join item on item.resource_id = event.event_hash where item.resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_channel()), intval($_GET['id']) ); } elseif ($export) { - $r = q("SELECT * from event where uid = %d", + $r = q( + "SELECT * from event where uid = %d", intval(local_channel()) ); } else { @@ -355,7 +363,8 @@ class Calendar extends Controller // Noting this for now - it will need to be fixed here and in Friendica. // Ultimately the finish date shouldn't be involved in the query. - $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan, item.id as item_id + $r = q( + "SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan, item.id as item_id from event left join item on event.event_hash = item.resource_id where item.resource_type = 'event' and event.uid = %d and event.uid = item.uid $ignored AND (( event.adjust = 0 AND ( event.dtend >= '%s' or event.nofinish = 1 ) AND event.dtstart <= '%s' ) @@ -366,7 +375,6 @@ class Calendar extends Controller dbesc($adjust_start), dbesc($adjust_finish) ); - } if ($r && !$export) { @@ -379,7 +387,6 @@ class Calendar extends Controller $events = []; if ($r) { - foreach ($r as $rr) { $start = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c')); if ($rr['nofinish']) { @@ -390,8 +397,9 @@ class Calendar extends Controller // give a fake end to birthdays so they get crammed into a // single day on the calendar - if ($rr['etype'] === 'birthday') + if ($rr['etype'] === 'birthday') { $end = null; + } } $catsenabled = Apps::system_app_installed($x['profile_uid'], 'Categories'); @@ -405,10 +413,12 @@ class Calendar extends Controller $allDay = false; // allDay event rules - if (!strpos($start, 'T') && !strpos($end, 'T')) + if (!strpos($start, 'T') && !strpos($end, 'T')) { $allDay = true; - if (strpos($start, 'T00:00:00') && strpos($end, 'T00:00:00')) + } + if (strpos($start, 'T00:00:00') && strpos($end, 'T00:00:00')) { $allDay = true; + } $edit = ((local_channel() && $rr['author_xchan'] == get_observer_hash()) ? array(z_root() . '/events/' . $rr['event_hash'] . '?expandform=1', t('Edit event'), '', '') : false); @@ -452,7 +462,8 @@ class Calendar extends Controller if ($mode === 'drop' && $event_id) { - $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", + $r = q( + "SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", dbesc($event_id), intval(local_channel()) ); @@ -460,12 +471,14 @@ class Calendar extends Controller $sync_event = $r[0]; if ($r) { - $r = q("delete from event where event_hash = '%s' and uid = %d", + $r = q( + "delete from event where event_hash = '%s' and uid = %d", dbesc($event_id), intval(local_channel()) ); if ($r) { - $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", + $r = q( + "update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", dbesc($event_id), intval(local_channel()) ); @@ -477,7 +490,5 @@ class Calendar extends Controller killme(); } } - } - } diff --git a/Zotlabs/Module/Card_edit.php b/Zotlabs/Module/Card_edit.php index bd6246591..6be63109d 100644 --- a/Zotlabs/Module/Card_edit.php +++ b/Zotlabs/Module/Card_edit.php @@ -1,4 +1,5 @@ 1) + if (argc() > 1) { $which = argv(1); - else + } else { return; + } Libprofile::load($which); - } /** @@ -103,7 +104,6 @@ class Cards extends Controller if (perm_is_allowed($owner, $ob_hash, 'write_pages')) { - $x = [ 'webpage' => ITEM_TYPE_CARD, 'is_owner' => true, @@ -112,8 +112,11 @@ class Cards extends Controller 'nickname' => $channel['channel_address'], 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), - 'acl' => (($is_owner) ? populate_acl($channel_acl, false, - PermissionDescription::fromGlobalPermission('view_pages')) : ''), + 'acl' => (($is_owner) ? populate_acl( + $channel_acl, + false, + PermissionDescription::fromGlobalPermission('view_pages') + ) : ''), 'permissions' => $channel_acl, 'showacl' => (($is_owner) ? true : false), 'visitor' => true, @@ -130,10 +133,12 @@ class Cards extends Controller 'bbcode' => true ]; - if ($_REQUEST['title']) + if ($_REQUEST['title']) { $x['title'] = $_REQUEST['title']; - if ($_REQUEST['body']) + } + if ($_REQUEST['body']) { $x['body'] = $_REQUEST['body']; + } $editor = status_editor($x); } else { @@ -150,7 +155,8 @@ class Cards extends Controller $sql_item = ''; if ($selected_card) { - $r = q("select * from iconfig where iconfig.cat = 'system' and iconfig.k = 'CARD' and iconfig.v = '%s' limit 1", + $r = q( + "select * from iconfig where iconfig.cat = 'system' and iconfig.k = 'CARD' and iconfig.v = '%s' limit 1", dbesc($selected_card) ); if ($r) { @@ -158,7 +164,8 @@ class Cards extends Controller } } - $r = q("select * from item + $r = q( + "select * from item where uid = %d and item_type = %d $sql_extra $sql_item order by item.created desc $pager_sql", intval($owner), @@ -171,12 +178,12 @@ class Cards extends Controller $items_result = []; if ($r) { - $pager_total = count($r); $parents_str = ids_to_querystr($r, 'id'); - $items = q("SELECT item.*, item.id AS item_id + $items = q( + "SELECT item.*, item.id AS item_id FROM item WHERE item.uid = %d $item_normal AND item.parent IN ( %s ) @@ -193,10 +200,11 @@ class Cards extends Controller $mode = 'cards'; - if (get_pconfig(local_channel(), 'system', 'articles_list_mode') && (!$selected_card)) + if (get_pconfig(local_channel(), 'system', 'articles_list_mode') && (!$selected_card)) { $page_mode = 'pager_list'; - else + } else { $page_mode = 'traditional'; + } $content = conversation($items_result, $mode, false, $page_mode); @@ -209,5 +217,4 @@ class Cards extends Controller return $o; } - } diff --git a/Zotlabs/Module/Categories.php b/Zotlabs/Module/Categories.php index 284352b9c..e168bc6fe 100644 --- a/Zotlabs/Module/Categories.php +++ b/Zotlabs/Module/Categories.php @@ -22,7 +22,6 @@ class Categories extends Controller } Libprofile::load($which, 0); } - } @@ -39,8 +38,5 @@ class Categories extends Controller $c = new Comanche(); return $c->widget('catcloud', EMPTY_STR); - } - - } diff --git a/Zotlabs/Module/Cdav.php b/Zotlabs/Module/Cdav.php index 206f6852f..ceb364c6e 100644 --- a/Zotlabs/Module/Cdav.php +++ b/Zotlabs/Module/Cdav.php @@ -1,4 +1,5 @@ setRealm(ucfirst(System::get_platform_name()) . ' ' . 'CalDAV/CardDAV'); if (local_channel()) { - logger('loggedin'); if ((argv(1) == 'addressbooks') && (!Apps::system_app_installed(local_channel(), 'CardDAV'))) { @@ -179,7 +180,6 @@ class Cdav extends Controller return; } } - } @@ -235,16 +235,15 @@ class Cdav extends Controller $server->exec(); killme(); - } - } public function post() { - if (!local_channel()) + if (!local_channel()) { return; + } if ((argv(1) === 'addressbook') && (!Apps::system_app_installed(local_channel(), 'CardDAV'))) { return; @@ -253,15 +252,15 @@ class Cdav extends Controller $channel = App::get_channel(); $principalUri = 'principals/' . $channel['channel_address']; - if (!cdav_principal($principalUri)) + if (!cdav_principal($principalUri)) { return; + } $pdo = DBA::$dba->db; require_once 'vendor/autoload.php'; if (argc() == 2 && argv(1) === 'calendar') { - $caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo); $calendars = $caldavBackend->getCalendarsForUser($principalUri); @@ -271,7 +270,8 @@ class Cdav extends Controller $duplicate = false; $calendarUri = random_string(40); - $r = q("SELECT uri FROM calendarinstances WHERE principaluri = '%s' AND uri = '%s' LIMIT 1", + $r = q( + "SELECT uri FROM calendarinstances WHERE principaluri = '%s' AND uri = '%s' LIMIT 1", dbesc($principalUri), dbesc($calendarUri) ); @@ -295,11 +295,11 @@ class Cdav extends Controller //create new calendar object via ajax request if ($_REQUEST['submit'] === 'create_event' && $_REQUEST['title'] && $_REQUEST['target'] && $_REQUEST['dtstart']) { - $id = explode(':', $_REQUEST['target']); - if (!cdav_perms($id[0], $calendars, true)) + if (!cdav_perms($id[0], $calendars, true)) { return; + } $title = $_REQUEST['title']; $start = datetime_convert(App::$timezone, 'UTC', $_REQUEST['dtstart']); @@ -315,13 +315,15 @@ class Cdav extends Controller $duplicate = false; $objectUri = random_string(40) . '.ics'; - $r = q("SELECT uri FROM calendarobjects WHERE calendarid = %s AND uri = '%s' LIMIT 1", + $r = q( + "SELECT uri FROM calendarobjects WHERE calendarid = %s AND uri = '%s' LIMIT 1", intval($id[0]), dbesc($objectUri) ); - if (count($r)) + if (count($r)) { $duplicate = true; + } } while ($duplicate == true); @@ -335,10 +337,12 @@ class Cdav extends Controller $vcalendar->VEVENT->add('DTEND', $dtend); $vcalendar->VEVENT->DTEND['TZID'] = App::$timezone; } - if ($description) + if ($description) { $vcalendar->VEVENT->add('DESCRIPTION', $description); - if ($location) + } + if ($location) { $vcalendar->VEVENT->add('LOCATION', $location); + } $vcalendar->VEVENT->DTSTART['TZID'] = App::$timezone; @@ -351,7 +355,6 @@ class Cdav extends Controller // edit calendar name and color if ($_REQUEST['{DAV:}displayname'] && $_REQUEST['edit'] && $_REQUEST['id']) { - $id = explode(':', $_REQUEST['id']); if (!cdav_perms($id[0], $calendars)) { @@ -372,11 +375,11 @@ class Cdav extends Controller // edit calendar object via ajax request if ($_REQUEST['submit'] === 'update_event' && $_REQUEST['uri'] && $_REQUEST['title'] && $_REQUEST['target'] && $_REQUEST['dtstart']) { - $id = explode(':', $_REQUEST['target']); - if (!cdav_perms($id[0], $calendars, true)) + if (!cdav_perms($id[0], $calendars, true)) { return; + } $uri = $_REQUEST['uri']; $title = $_REQUEST['title']; @@ -419,7 +422,6 @@ class Cdav extends Controller // delete calendar object via ajax request if ($_REQUEST['delete'] && $_REQUEST['uri'] && $_REQUEST['target']) { - $id = explode(':', $_REQUEST['target']); if (!cdav_perms($id[0], $calendars, true)) { @@ -434,7 +436,6 @@ class Cdav extends Controller // edit calendar object date/timeme via ajax request (drag and drop) if ($_REQUEST['update'] && $_REQUEST['id'] && $_REQUEST['uri']) { - $id = [$_REQUEST['id'][0], $_REQUEST['id'][1]]; if (!cdav_perms($id[0], $calendars, true)) { @@ -471,7 +472,6 @@ class Cdav extends Controller // share a calendar - this only works on local system (with channels on the same server) if ($_REQUEST['sharee'] && $_REQUEST['share']) { - $id = [intval($_REQUEST['calendarid']), intval($_REQUEST['instanceid'])]; if (!cdav_perms($id[0], $calendars)) { @@ -494,7 +494,6 @@ class Cdav extends Controller } if (argc() >= 2 && argv(1) === 'addressbook') { - $carddavBackend = new PDO($pdo); $addressbooks = $carddavBackend->getAddressBooksForUser($principalUri); @@ -504,7 +503,8 @@ class Cdav extends Controller $duplicate = false; $addressbookUri = random_string(20); - $r = q("SELECT uri FROM addressbooks WHERE principaluri = '%s' AND uri = '%s' LIMIT 1", + $r = q( + "SELECT uri FROM addressbooks WHERE principaluri = '%s' AND uri = '%s' LIMIT 1", dbesc($principalUri), dbesc($addressbookUri) ); @@ -521,7 +521,6 @@ class Cdav extends Controller // edit addressbook if ($_REQUEST['{DAV:}displayname'] && $_REQUEST['edit'] && intval($_REQUEST['id'])) { - $id = $_REQUEST['id']; if (!cdav_perms($id, $addressbooks)) { @@ -547,7 +546,8 @@ class Cdav extends Controller $duplicate = false; $uri = random_string(40) . '.vcf'; - $r = q("SELECT uri FROM cards WHERE addressbookid = %s AND uri = '%s' LIMIT 1", + $r = q( + "SELECT uri FROM cards WHERE addressbookid = %s AND uri = '%s' LIMIT 1", intval($id), dbesc($uri) ); @@ -645,12 +645,10 @@ class Cdav extends Controller $cardData = $vcard->serialize(); $carddavBackend->createCard($id, $uri, $cardData); - } // edit addressbook card if ($_REQUEST['update'] && $_REQUEST['uri'] && $_REQUEST['target']) { - $id = $_REQUEST['target']; if (!cdav_perms($id, $addressbooks)) { @@ -771,7 +769,6 @@ class Cdav extends Controller // delete addressbook card if ($_REQUEST['delete'] && $_REQUEST['uri'] && $_REQUEST['target']) { - $id = $_REQUEST['target']; if (!cdav_perms($id, $addressbooks)) { @@ -786,11 +783,9 @@ class Cdav extends Controller // Import calendar or addressbook if (($_FILES) && array_key_exists('userfile', $_FILES) && intval($_FILES['userfile']['size']) && $_REQUEST['target']) { - $src = $_FILES['userfile']['tmp_name']; if ($src) { - if ($_REQUEST['c_upload']) { if ($_REQUEST['target'] == 'calendar') { $result = parse_ical_file($src, local_channel()); @@ -824,7 +819,6 @@ class Cdav extends Controller } while ($object = $objects->getNext()) { - if ($_REQUEST['a_upload']) { $object = $object->convert(Document::VCARD40); } @@ -840,7 +834,8 @@ class Cdav extends Controller $duplicate = false; $objectUri = random_string(40) . '.' . $ext; - $r = q("SELECT uri FROM $table WHERE $column = %d AND uri = '%s' LIMIT 1", + $r = q( + "SELECT uri FROM $table WHERE $column = %d AND uri = '%s' LIMIT 1", dbesc($id[0]), dbesc($objectUri) ); @@ -862,15 +857,13 @@ class Cdav extends Controller notice('' . t('INVALID EVENT DISMISSED!') . '' . EOL . '' . t('Summary: ') . '' . (($object->VEVENT->SUMMARY) ? $object->VEVENT->SUMMARY : t('Unknown')) . EOL . '' . t('Date: ') . '' . (($object->VEVENT->DTSTART) ? $object->VEVENT->DTSTART : t('Unknown')) . EOL . - '' . t('Reason: ') . '' . $ret[0]['message'] . EOL - ); + '' . t('Reason: ') . '' . $ret[0]['message'] . EOL); } if ($_REQUEST['a_upload']) { notice('' . t('INVALID CARD DISMISSED!') . '' . EOL . '' . t('Name: ') . '' . (($object->FN) ? $object->FN : t('Unknown')) . EOL . - '' . t('Reason: ') . '' . $ret[0]['message'] . EOL - ); + '' . t('Reason: ') . '' . $ret[0]['message'] . EOL); } } } @@ -921,7 +914,6 @@ class Cdav extends Controller // Display calendar(s) here if (argc() <= 3 && argv(1) === 'calendar') { - head_add_css('/library/fullcalendar/packages/core/main.min.css'); head_add_css('/library/fullcalendar/packages/daygrid/main.min.css'); head_add_css('/library/fullcalendar/packages/timegrid/main.min.css'); @@ -943,7 +935,8 @@ class Cdav extends Controller } if ($resource_id) { - $r = q("SELECT event.*, item.author_xchan, item.owner_xchan, item.plink, item.id as item_id FROM event LEFT JOIN item ON event.event_hash = item.resource_id + $r = q( + "SELECT event.*, item.author_xchan, item.owner_xchan, item.plink, item.id as item_id FROM event LEFT JOIN item ON event.event_hash = item.resource_id WHERE event.uid = %d AND event.event_hash = '%s' LIMIT 1", intval(local_channel()), dbesc($resource_id) @@ -969,7 +962,8 @@ class Cdav extends Controller } if ($r[0]['dismissed'] == 0) { - q("UPDATE event SET dismissed = 1 WHERE event.uid = %d AND event.event_hash = '%s'", + q( + "UPDATE event SET dismissed = 1 WHERE event.uid = %d AND event.event_hash = '%s'", intval(local_channel()), dbesc($resource_id) ); @@ -1080,12 +1074,10 @@ class Cdav extends Controller ]); return $o; - } // Provide json data for calendar if (argc() == 5 && argv(1) === 'calendar' && argv(2) === 'json' && intval(argv(3)) && intval(argv(4))) { - $events = []; $id = [argv(3), argv(4)]; @@ -1112,7 +1104,6 @@ class Cdav extends Controller if ($uris) { $objects = $caldavBackend->getMultipleCalendarObjects($id, $uris); foreach ($objects as $object) { - $vcalendar = Reader::read($object['calendardata']); if (isset($vcalendar->VEVENT->RRULE)) { @@ -1193,7 +1184,6 @@ class Cdav extends Controller // drop sharee if (argc() == 6 && argv(1) === 'calendar' && argv(2) === 'dropsharee' && intval(argv(3)) && intval(argv(4))) { - $id = [argv(3), argv(4)]; $hash = argv(5); @@ -1222,7 +1212,6 @@ class Cdav extends Controller // Display Adressbook here if (argc() == 3 && argv(1) === 'addressbook' && intval(argv(2))) { - $id = argv(2); $displayname = cdav_perms($id, $addressbooks); @@ -1400,7 +1389,6 @@ class Cdav extends Controller $carddavBackend->deleteAddressBook($id); killme(); } - } public function activate($pdo, $channel) @@ -1413,17 +1401,20 @@ class Cdav extends Controller $uri = 'principals/' . $channel['channel_address']; - $r = q("select * from principals where uri = '%s' limit 1", + $r = q( + "select * from principals where uri = '%s' limit 1", dbesc($uri) ); if ($r) { - $r = q("update principals set email = '%s', displayname = '%s' where uri = '%s' ", + $r = q( + "update principals set email = '%s', displayname = '%s' where uri = '%s' ", dbesc($channel['xchan_addr']), dbesc($channel['channel_name']), dbesc($uri) ); } else { - $r = q("insert into principals ( uri, email, displayname ) values('%s','%s','%s') ", + $r = q( + "insert into principals ( uri, email, displayname ) values('%s','%s','%s') ", dbesc($uri), dbesc($channel['xchan_addr']), dbesc($channel['channel_name']) @@ -1445,8 +1436,6 @@ class Cdav extends Controller $carddavBackend = new PDO($pdo); $properties = ['{DAV:}displayname' => t('Default Addressbook')]; $carddavBackend->createAddressBook($uri, 'default', $properties); - } } - } diff --git a/Zotlabs/Module/Changeaddr.php b/Zotlabs/Module/Changeaddr.php index e79b6f9bc..5e4ad254d 100644 --- a/Zotlabs/Module/Changeaddr.php +++ b/Zotlabs/Module/Changeaddr.php @@ -30,14 +30,17 @@ class Changeaddr extends Controller return; } - if ((!x($_POST, 'qxz_password')) || (!strlen(trim($_POST['qxz_password'])))) + if ((!x($_POST, 'qxz_password')) || (!strlen(trim($_POST['qxz_password'])))) { return; + } - if ((!x($_POST, 'verify')) || (!strlen(trim($_POST['verify'])))) + if ((!x($_POST, 'verify')) || (!strlen(trim($_POST['verify'])))) { return; + } - if ($_POST['verify'] !== $_SESSION['remove_account_verify']) + if ($_POST['verify'] !== $_SESSION['remove_account_verify']) { return; + } $account = App::get_account(); @@ -58,8 +61,9 @@ class Changeaddr extends Controller $new_address = trim($_POST['newname']); - if ($new_address === $channel['channel_address']) + if ($new_address === $channel['channel_address']) { return; + } if ($new_address === 'sys') { notice(t('Reserved nickname. Please choose another.') . EOL); @@ -74,7 +78,6 @@ class Changeaddr extends Controller channel_change_address($channel, $new_address); goaway(z_root() . '/changeaddr'); - } @@ -109,7 +112,5 @@ class Changeaddr extends Controller ]); return $o; - } - } diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 8cd0994cf..1c41364fb 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -10,7 +10,6 @@ use Zotlabs\Lib\LDSignatures; use Zotlabs\Lib\Crypto; use Zotlabs\Lib\PConfig; use Zotlabs\Web\HTTPSig; - use App; use Zotlabs\Web\Controller; use Zotlabs\Lib\PermissionDescription; @@ -102,7 +101,6 @@ class Channel extends Controller // fork of Zap; which disables ActivityPub connectivity by default. if (ActivityStreams::is_as_request()) { - // Somebody may attempt an ActivityStreams fetch on one of our message permalinks // Make it do the right thing. @@ -134,12 +132,12 @@ class Channel extends Controller // handle zot6 channel discovery if (Libzot::is_zot_request()) { - $sigdata = HTTPSig::verify(file_get_contents('php://input'), EMPTY_STR, 'zot6'); if ($sigdata && $sigdata['signer'] && $sigdata['header_valid']) { $data = json_encode(Libzot::zotinfo(['guid_hash' => $channel['channel_hash'], 'target_url' => $sigdata['signer']])); - $s = q("select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", + $s = q( + "select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", dbesc($sigdata['signer']) ); @@ -168,7 +166,6 @@ class Channel extends Controller Libprofile::load($which, $profile); if (!$_REQUEST['mid']) { - App::$meta->set('og:title', $channel['channel_name']); App::$meta->set('og:image', $channel['xchan_photo_l']); App::$meta->set('og:type', 'webpage'); @@ -223,7 +220,6 @@ class Channel extends Controller if ($this->loading && !$mid) { - $_SESSION['loadtime_channel'] = datetime_convert(); if ($is_owner) { PConfig::Set(local_channel(), 'system', 'loadtime_channel', $_SESSION['loadtime_channel']); @@ -243,7 +239,6 @@ class Channel extends Controller if (!$this->updating) { - nav_set_selected('Channel Home'); $static = channel_manual_conv_update(App::$profile['profile_uid']); @@ -273,7 +268,6 @@ class Channel extends Controller if ($perms['post_wall']) { - $x = array( 'is_owner' => $is_owner, 'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig(App::$profile['profile_uid'], 'system', 'use_browser_location')))) ? true : false), @@ -310,8 +304,9 @@ class Channel extends Controller $item_normal = " and item.item_hidden = 0 and item.item_type = 0 and item.item_deleted = 0 and item.item_unpublished = 0 and item.item_pending_remove = 0 and item.item_blocked = 0 "; - if (!$is_owner) + if (!$is_owner) { $item_normal .= "and item.item_delayed = 0 "; + } $item_normal_update = item_normal_update(); $sql_extra = item_permissions_sql(App::$profile['profile_uid']); @@ -330,7 +325,8 @@ class Channel extends Controller if (strpos($search, '#') === 0) { $sql_extra .= term_query('item', substr($search, 1), TERM_HASHTAG, TERM_COMMUNITYTAG); } else { - $sql_extra .= sprintf(" AND (item.body like '%s' OR item.title like '%s') ", + $sql_extra .= sprintf( + " AND (item.body like '%s' OR item.title like '%s') ", dbesc(protect_sprintf('%' . $search . '%')), dbesc(protect_sprintf('%' . $search . '%')) ); @@ -358,13 +354,15 @@ class Channel extends Controller if (($this->updating) && (!$this->loading)) { if ($mid) { - $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal_update + $r = q( + "SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal_update AND item_wall = 1 $simple_update $sql_extra limit 1", dbesc($mid . '%'), intval(App::$profile['profile_uid']) ); } else { - $r = q("SELECT parent AS item_id from item + $r = q( + "SELECT parent AS item_id from item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) WHERE uid = %d $item_normal_update AND item_wall = 1 $simple_update @@ -375,7 +373,6 @@ class Channel extends Controller ); } } else { - if (x($category)) { $sql_extra2 .= protect_sprintf(term_item_parent_query(App::$profile['profile_uid'], 'item', $category, TERM_CATEGORY)); } @@ -407,7 +404,8 @@ class Channel extends Controller if ($noscript_content || $this->loading) { if ($mid) { - $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal + $r = q( + "SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal AND item_wall = 1 $sql_extra limit 1", dbesc($mid . '%'), intval(App::$profile['profile_uid']) @@ -416,7 +414,8 @@ class Channel extends Controller notice(t('Permission denied.') . EOL); } } else { - $r = q("SELECT DISTINCT item.parent AS item_id, $ordering FROM item + $r = q( + "SELECT DISTINCT item.parent AS item_id, $ordering FROM item left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) WHERE true and item.uid = %d $item_normal AND (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -431,10 +430,10 @@ class Channel extends Controller } } if ($r) { - $parents_str = ids_to_querystr($r, 'item_id'); - $items = q("SELECT item.*, item.id AS item_id + $items = q( + "SELECT item.*, item.id AS item_id FROM item WHERE item.uid = %d $item_normal AND item.parent IN ( %s ) @@ -452,19 +451,18 @@ class Channel extends Controller // to view the parent item (or the item itself if it is toplevel) notice(t('Permission denied.') . EOL); } - } else { $items = []; } if ((!$this->updating) && (!$this->loading)) { - // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. $maxheight = get_pconfig(App::$profile['profile_uid'], 'system', 'channel_divmore_height'); - if (!$maxheight) + if (!$maxheight) { $maxheight = 400; + } $o .= '' . "\r\n"; $o .= "\n"; if (argc() == 3) { - $contact_id = intval(argv(1)); if (!$contact_id) { return; @@ -363,7 +366,8 @@ class Connedit extends Controller $cmd = argv(2); - $orig_record = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash + $orig_record = q( + "SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_id = %d AND abook_channel = %d AND abook_self = 0 LIMIT 1", intval($contact_id), intval(local_channel()) @@ -406,7 +410,8 @@ class Connedit extends Controller if ($cmd === 'resetphoto') { - q("update xchan set xchan_photo_date = '2001-01-01 00:00:00' where xchan_hash = '%s'", + q( + "update xchan set xchan_photo_date = '2001-01-01 00:00:00' where xchan_hash = '%s'", dbesc($orig_record['xchan_hash']) ); $cmd = 'refresh'; @@ -444,7 +449,8 @@ class Connedit extends Controller 'block_type' => BLOCKTYPE_CHANNEL, 'block_comment' => t('Added by Connedit') ]); - $z = q("insert into xign ( uid, xchan ) values ( %d , '%s' ) ", + $z = q( + "insert into xign ( uid, xchan ) values ( %d , '%s' ) ", intval(local_channel()), dbesc($orig_record['abook_xchan']) ); @@ -505,14 +511,14 @@ class Connedit extends Controller } if (App::$poi) { - $abook_prev = 0; $abook_next = 0; $contact_id = App::$poi['abook_id']; $contact = App::$poi; - $cn = q("SELECT abook_id, xchan_name from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and xchan_deleted = 0 order by xchan_name", + $cn = q( + "SELECT abook_id, xchan_name from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and xchan_deleted = 0 order by xchan_name", intval(local_channel()) ); @@ -645,14 +651,14 @@ class Connedit extends Controller $vctmp = (($vc) ? Reader::read($vc) : null); $vcard = (($vctmp) ? get_vcard_array($vctmp, $contact['abook_id']) : []); - if (!$vcard) + if (!$vcard) { $vcard['fn'] = $contact['xchan_name']; + } $tpl = get_markup_template("abook_edit.tpl"); if (Apps::system_app_installed(local_channel(), 'Friend Zoom')) { - $sections['affinity'] = [ 'label' => t('Friend Zoom'), 'url' => z_root() . '/connedit/' . $contact['abook_id'] . '/?f=§ion=affinity', @@ -693,7 +699,8 @@ class Connedit extends Controller $rating_val = 0; $rating_text = ''; - $xl = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1", + $xl = q( + "select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1", dbesc($channel['channel_hash']), dbesc($contact['xchan_hash']) ); @@ -726,22 +733,26 @@ class Connedit extends Controller $multiprofs = ((feature_enabled(local_channel(), 'multi_profiles')) ? true : false); - if ($slide && !$multiprofs) + if ($slide && !$multiprofs) { $affinity = t('Set Friend Zoom'); + } - if (!$slide && $multiprofs) + if (!$slide && $multiprofs) { $affinity = t('Set Profile'); + } - if ($slide && $multiprofs) + if ($slide && $multiprofs) { $affinity = t('Set Friend Zoom & Profile'); + } $theirs = get_abconfig(local_channel(), $contact['abook_xchan'], 'system', 'their_perms', EMPTY_STR); $their_perms = Permissions::FilledPerms(explode(',', $theirs)); foreach ($global_perms as $k => $v) { - if (!array_key_exists($k, $their_perms)) + if (!array_key_exists($k, $their_perms)) { $their_perms[$k] = 1; + } } $my_perms = explode(',', get_abconfig(local_channel(), $contact['abook_xchan'], 'system', 'my_perms', EMPTY_STR)); @@ -753,8 +764,9 @@ class Connedit extends Controller // For auto permissions (when $self is true) we don't want to look at existing // permissions because they are enabled for the channel owner - if ((!$self) && ($existing[$k])) + if ((!$self) && ($existing[$k])) { $thisperm = "1"; + } $perms[] = array('perms_' . $k, $v, ((array_key_exists($k, $their_perms)) ? intval($their_perms[$k]) : ''), $thisperm, 1, (($checkinherited & PERMS_SPECIFIC) ? '' : '1'), '', $checkinherited); } @@ -769,8 +781,9 @@ class Connedit extends Controller } $locstr = locations_by_netid($contact['xchan_hash']); - if (!$locstr) + if (!$locstr) { $locstr = unpunify($contact['xchan_url']); + } $clone_warn = ''; $clonable = (in_array($contact['xchan_network'], ['zot6', 'zot', 'rss']) ? true : false); @@ -784,8 +797,9 @@ class Connedit extends Controller } - if (intval($contact['abook_not_here']) && $unclonable) + if (intval($contact['abook_not_here']) && $unclonable) { $not_here = t('This connection is unreachable from this location. Location independence is not supported by their network.'); + } $o .= replace_macros($tpl, [ '$header' => (($self) ? t('Connection Default Permissions') : sprintf(t('Connection: %s'), $contact['xchan_name']) . (($contact['abook_alias']) ? ' <' . $contact['abook_alias'] . '>' : '')), @@ -879,7 +893,6 @@ class Connedit extends Controller call_hooks('contact_edit', $arr); return $arr['output']; - } } } diff --git a/Zotlabs/Module/Contactgroup.php b/Zotlabs/Module/Contactgroup.php index b6fd42cd0..50100be78 100644 --- a/Zotlabs/Module/Contactgroup.php +++ b/Zotlabs/Module/Contactgroup.php @@ -1,4 +1,5 @@ 1) && (intval(argv(1)))) { - $group = AccessList::by_id(local_channel(), argv(1)); if (!$group) { diff --git a/Zotlabs/Module/Content_filter.php b/Zotlabs/Module/Content_filter.php index 8da4a26a1..a6a3e6915 100644 --- a/Zotlabs/Module/Content_filter.php +++ b/Zotlabs/Module/Content_filter.php @@ -17,7 +17,6 @@ class Content_filter extends Controller } if ($_POST['content_filter-submit']) { - $incl = ((x($_POST['message_filter_incl'])) ? htmlspecialchars_decode(trim($_POST['message_filter_incl']), ENT_QUOTES) : ''); $excl = ((x($_POST['message_filter_excl'])) ? htmlspecialchars_decode(trim($_POST['message_filter_excl']), ENT_QUOTES) : ''); @@ -25,11 +24,9 @@ class Content_filter extends Controller set_pconfig(local_channel(), 'system', 'message_filter_excl', $excl); info(t('Content Filter settings updated.') . EOL); - } Libsync::build_sync_packet(); - } @@ -72,6 +69,4 @@ class Content_filter extends Controller return $s; } - - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Conversation.php b/Zotlabs/Module/Conversation.php index d7395693b..03f664a0d 100644 --- a/Zotlabs/Module/Conversation.php +++ b/Zotlabs/Module/Conversation.php @@ -1,4 +1,5 @@ 0 order by imgscale asc LIMIT 1", + $r = q( + "SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND imgscale > 0 order by imgscale asc LIMIT 1", dbesc($image_id), intval(local_channel()) ); if ($r) { - $max_thumb = intval(get_config('system', 'max_thumbnail', 1600)); $iscaled = false; if (intval($r[0]['height']) > $max_thumb || intval($r[0]['width']) > $max_thumb) { $imagick_path = get_config('system', 'imagick_convert_path'); if ($imagick_path && @file_exists($imagick_path) && intval($r[0]['os_storage'])) { - $fname = dbunescbin($r[0]['content']); $tmp_name = $fname . '-001'; $newsize = photo_calculate_scale(array_merge(getimagesize($fname), ['max' => $max_thumb])); $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $fname) . ' -resize ' . $newsize . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmp_name); - // logger('imagick thumbnail command: ' . $cmd); + // logger('imagick thumbnail command: ' . $cmd); for ($x = 0; $x < 4; $x++) { exec($cmd); if (file_exists($tmp_name)) { @@ -128,14 +128,14 @@ class Cover_photo extends Controller $im = photo_factory($base_image['content'], $base_image['mimetype']); if ($im && $im->is_valid()) { - // We are scaling and cropping the relative pixel locations to the original photo instead of the // scaled photo we operated on. // First load the scaled photo to check its size. (Should probably pass this in the post form and save // a query.) - $g = q("select width, height from photo where resource_id = '%s' and uid = %d and imgscale = 3", + $g = q( + "select width, height from photo where resource_id = '%s' and uid = %d and imgscale = 3", dbesc($image_id), intval(local_channel()) ); @@ -151,7 +151,8 @@ class Cover_photo extends Controller // unset all other cover photos - q("update photo set photo_usage = %d where photo_usage = %d and uid = %d", + q( + "update photo set photo_usage = %d where photo_usage = %d and uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_COVER), intval(local_channel()) @@ -196,7 +197,8 @@ class Cover_photo extends Controller if ($r1 === false || $r2 === false || $r3 === false) { // if one failed, delete them all so we can start over. notice(t('Image resize failed.') . EOL); - $x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale >= 7 ", + $x = q( + "delete from photo where resource_id = '%s' and uid = %d and imgscale >= 7 ", dbesc($base_image['resource_id']), local_channel() ); @@ -205,14 +207,12 @@ class Cover_photo extends Controller $channel = App::get_channel(); $this->send_cover_photo_activity($channel, $base_image, $profile); - - - } else + } else { notice(t('Unable to process image') . EOL); + } } goaway(z_root() . '/channel/' . $channel['channel_address']); - } @@ -264,7 +264,6 @@ class Cover_photo extends Controller logger('attach_store: ' . print_r($res, true), LOGGER_DEBUG); json_return_and_die(['message' => $hash]); - } public function send_cover_photo_activity($channel, $photo, $profile) @@ -319,8 +318,6 @@ class Cover_photo extends Controller $arr['author_xchan'] = $channel['channel_hash']; post_activity_item($arr); - - } @@ -344,8 +341,9 @@ class Cover_photo extends Controller $newuser = false; - if (argc() == 2 && argv(1) === 'new') + if (argc() == 2 && argv(1) === 'new') { $newuser = true; + } if (argv(1) === 'use') { if (argc() < 3) { @@ -353,11 +351,12 @@ class Cover_photo extends Controller return; } - // check_form_security_token_redirectOnErr('/cover_photo', 'cover_photo'); + // check_form_security_token_redirectOnErr('/cover_photo', 'cover_photo'); $resource_id = argv(2); - $r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and imgscale > 0 ORDER BY imgscale ASC", + $r = q( + "SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' and imgscale > 0 ORDER BY imgscale ASC", intval(local_channel()), dbesc($resource_id) ); @@ -372,10 +371,10 @@ class Cover_photo extends Controller } } - $r = q("SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", + $r = q( + "SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_channel()) - ); if (!$r) { notice(t('Photo not available.') . EOL); @@ -392,7 +391,8 @@ class Cover_photo extends Controller $smallest = 0; if ($ph && $ph->is_valid()) { // go ahead as if we have just uploaded a new photo to crop - $i = q("select resource_id, imgscale from photo where resource_id = '%s' and uid = %d and imgscale = 0", + $i = q( + "select resource_id, imgscale from photo where resource_id = '%s' and uid = %d and imgscale = 0", dbesc($r[0]['resource_id']), intval(local_channel()) ); @@ -410,7 +410,6 @@ class Cover_photo extends Controller if (!array_key_exists('imagecrop', App::$data)) { - $o .= replace_macros(get_markup_template('cover_photo.tpl'), [ '$user' => App::$channel['channel_address'], '$info' => t('Your cover photo may be visible to anybody on the internet'), @@ -487,6 +486,4 @@ class Cover_photo extends Controller App::$page['htmlhead'] .= replace_macros(get_markup_template('crophead.tpl'), []); return; } - - } diff --git a/Zotlabs/Module/Dav.php b/Zotlabs/Module/Dav.php index e406bc3dd..d98b4680c 100644 --- a/Zotlabs/Module/Dav.php +++ b/Zotlabs/Module/Dav.php @@ -1,4 +1,5 @@ 1) + if (argc() > 1) { Libprofile::load(argv(1), 0); + } $auth = new BasicAuth(); -// $auth->observer = get_observer_hash(); +// $auth->observer = get_observer_hash(); $auth->setRealm(ucfirst(System::get_platform_name()) . ' ' . 'WebDAV'); @@ -140,5 +143,4 @@ class Dav extends Controller killme(); } - } diff --git a/Zotlabs/Module/Defperms.php b/Zotlabs/Module/Defperms.php index 95b9b406c..ec714b10e 100644 --- a/Zotlabs/Module/Defperms.php +++ b/Zotlabs/Module/Defperms.php @@ -1,4 +1,5 @@ \n"; if (App::$poi) { - $sections = []; $self = false; @@ -267,7 +270,6 @@ class Defperms extends Controller call_hooks('contact_edit', $arr); return $arr['output']; - } } } diff --git a/Zotlabs/Module/Dircensor.php b/Zotlabs/Module/Dircensor.php index ac1e71096..a4348b862 100644 --- a/Zotlabs/Module/Dircensor.php +++ b/Zotlabs/Module/Dircensor.php @@ -5,7 +5,6 @@ namespace Zotlabs\Module; use App; use Zotlabs\Web\Controller; - class Dircensor extends Controller { @@ -26,7 +25,8 @@ class Dircensor extends Controller return; } - $r = q("select * from xchan where xchan_hash = '%s'", + $r = q( + "select * from xchan where xchan_hash = '%s'", dbesc($xchan) ); @@ -36,7 +36,8 @@ class Dircensor extends Controller $val = (($r[0]['xchan_censored']) ? 0 : 1); - q("update xchan set xchan_censored = $val where xchan_hash = '%s'", + q( + "update xchan set xchan_censored = $val where xchan_hash = '%s'", dbesc($xchan) ); @@ -47,7 +48,5 @@ class Dircensor extends Controller } goaway(z_root() . '/directory'); - } - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Directory.php b/Zotlabs/Module/Directory.php index 426f2f6e7..091e1099c 100644 --- a/Zotlabs/Module/Directory.php +++ b/Zotlabs/Module/Directory.php @@ -12,7 +12,7 @@ require_once('include/socgraph.php'); require_once('include/bbcode.php'); require_once('include/html2plain.php'); -define( 'DIRECTORY_PAGESIZE', 60); +define('DIRECTORY_PAGESIZE', 60); class Directory extends Controller { @@ -22,7 +22,8 @@ class Directory extends Controller App::set_pager_itemspage(DIRECTORY_PAGESIZE); if (x($_GET, 'ignore') && local_channel()) { - q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ", + q( + "insert into xign ( uid, xchan ) values ( %d, '%s' ) ", intval(local_channel()), dbesc($_GET['ignore']) ); @@ -86,7 +87,6 @@ class Directory extends Controller set_xconfig($observer, 'directory', 'activedir', $active); } } - } public function get() @@ -136,7 +136,6 @@ class Directory extends Controller $suggest = (local_channel() && x($_REQUEST, 'suggest')) ? $_REQUEST['suggest'] : ''; if ($suggest) { - // the directory options have no effect in suggestion mode $globaldir = 1; @@ -177,7 +176,6 @@ class Directory extends Controller } // Remove last space in the advanced query $advanced = rtrim($advanced); - } $tpl = get_markup_template('directory_header.tpl'); @@ -194,7 +192,8 @@ class Directory extends Controller $contacts = []; if (local_channel()) { - $x = q("select abook_xchan from abook where abook_channel = %d", + $x = q( + "select abook_xchan from abook where abook_channel = %d", intval(local_channel()) ); if ($x) { @@ -205,7 +204,6 @@ class Directory extends Controller } if ($url) { - $numtags = get_config('system', 'directorytags'); $kw = ((intval($numtags) > 0) ? intval($numtags) : 50); @@ -270,9 +268,7 @@ class Directory extends Controller $t = 0; $j = json_decode($x['body'], true); if ($j) { - if ($j['results']) { - $results = $j['results']; if ($suggest) { // change order to "number of common friends descending" @@ -284,7 +280,6 @@ class Directory extends Controller $photo = 'thumb'; foreach ($results as $rr) { - $profile_link = chanlink_url($rr['url']); $pdesc = (($rr['description']) ? $rr['description'] . '
"; var_dump(\App::$argv); killme(); @@ -34,12 +38,12 @@ class Fbrowser extends Controller $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10"; if (App::$argc == 2) { - $albums = q("SELECT distinct(album) AS album FROM photo WHERE uid = %d ", + $albums = q( + "SELECT distinct(album) AS album FROM photo WHERE uid = %d ", intval(local_channel()) ); // anon functions only from 5.3.0... meglio tardi che mai.. $albums = array_map("self::folder1", $albums); - } $album = ""; @@ -50,7 +54,8 @@ class Fbrowser extends Controller $path[] = array(z_root() . "/fbrowser/image/" . App::$argv[2] . "/", $album); } - $r = q("SELECT resource_id, id, filename, type, min(imgscale) AS hiq,max(imgscale) AS loq, description + $r = q( + "SELECT resource_id, id, filename, type, min(imgscale) AS hiq,max(imgscale) AS loq, description FROM photo WHERE uid = %d $sql_extra GROUP BY resource_id $sql_extra2", intval(local_channel()) @@ -72,7 +77,8 @@ class Fbrowser extends Controller break; case "file": if (App::$argc == 2) { - $files = q("SELECT id, filename, filetype FROM attach WHERE uid = %d ", + $files = q( + "SELECT id, filename, filetype FROM attach WHERE uid = %d ", intval(local_channel()) ); @@ -89,7 +95,6 @@ class Fbrowser extends Controller '$files' => $files, '$cancel' => t('Cancel'), )); - } break; @@ -97,7 +102,6 @@ class Fbrowser extends Controller killme(); - } private static function folder1($el) @@ -135,6 +139,4 @@ class Fbrowser extends Controller return array(z_root() . '/attach/' . $rr['id'], $filename_e, z_root() . '/images/icons/16/' . $filetype . '.png'); } - - } diff --git a/Zotlabs/Module/Fedi_id.php b/Zotlabs/Module/Fedi_id.php index f69455b6d..cb4328070 100644 --- a/Zotlabs/Module/Fedi_id.php +++ b/Zotlabs/Module/Fedi_id.php @@ -4,7 +4,6 @@ namespace Zotlabs\Module; use Zotlabs\Web\Controller; - class Fedi_id extends Controller { @@ -17,7 +16,8 @@ class Fedi_id extends Controller if ($_REQUEST['address']) { $x = discover_by_webbie(trim($_REQUEST['address'])); if ($x) { - $ab = q("select * from abook where abook_xchan = '%s' and abook_channel = %d", + $ab = q( + "select * from abook where abook_xchan = '%s' and abook_channel = %d", dbesc($x), intval($channel['channel_id']) ); @@ -25,7 +25,8 @@ class Fedi_id extends Controller notice(t('You are already connected with this channel.')); goaway(channel_url($channel)); } - $r = q("select * from xchan where xchan_hash = '%s'", + $r = q( + "select * from xchan where xchan_hash = '%s'", dbesc($x) ); if ($r && $r[0]['xchan_follow']) { @@ -41,7 +42,8 @@ class Fedi_id extends Controller public function get() { - return replace_macros(get_markup_template('fedi_id.tpl'), + return replace_macros( + get_markup_template('fedi_id.tpl'), [ '$title' => t('Home instance'), '$address' => ['address', t('Enter your channel address or fediverse ID (e.g. channel@example.com)'), '', t('If you do not have a fediverse ID, please use your browser \'back\' button to return to the previous page')], @@ -50,7 +52,5 @@ class Fedi_id extends Controller '$submit' => t('Connect') ] ); - } - -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Feed.php b/Zotlabs/Module/Feed.php index 8966ff598..69347ba69 100644 --- a/Zotlabs/Module/Feed.php +++ b/Zotlabs/Module/Feed.php @@ -1,4 +1,5 @@ 1) { - if (observer_prohibited(true)) { killme(); } @@ -45,7 +45,5 @@ class Feed extends Controller killme(); } - } - } diff --git a/Zotlabs/Module/File_upload.php b/Zotlabs/Module/File_upload.php index a9d92e648..7e10c9c52 100644 --- a/Zotlabs/Module/File_upload.php +++ b/Zotlabs/Module/File_upload.php @@ -1,4 +1,5 @@ array($sync))); } goaway(z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['data']['display_path']); - } } else { - $matches = []; $partial = false; @@ -97,13 +96,11 @@ class File_upload extends Controller $r = attach_store($channel, get_observer_hash(), '', $_REQUEST); if ($r['success']) { $sync = attach_export_data($channel, $r['data']['hash']); - if ($sync) + if ($sync) { Libsync::build_sync_packet($channel['channel_id'], array('file' => array($sync))); - + } } } goaway(z_root() . '/' . $_REQUEST['return_url']); - } - } diff --git a/Zotlabs/Module/Filer.php b/Zotlabs/Module/Filer.php index 7ab4a0fb2..6596dcd8a 100644 --- a/Zotlabs/Module/Filer.php +++ b/Zotlabs/Module/Filer.php @@ -1,4 +1,5 @@ 1) ? intval(App::$argv[1]) : 0); logger('filerm: tag ' . $term . ' item ' . $item_id); if ($item_id && strlen($term)) { - $r = q("delete from term where uid = %d and ttype = %d and oid = %d and term = '%s'", + $r = q( + "delete from term where uid = %d and ttype = %d and oid = %d and term = '%s'", intval(local_channel()), intval(($category) ? TERM_CATEGORY : TERM_FILE), intval($item_id), @@ -35,10 +37,10 @@ class Filerm extends Controller ); } - if (x($_SESSION, 'return_url')) + if (x($_SESSION, 'return_url')) { goaway(z_root() . '/' . $_SESSION['return_url']); + } killme(); } - } diff --git a/Zotlabs/Module/Filestorage.php b/Zotlabs/Module/Filestorage.php index 21efd1452..2acef08c3 100644 --- a/Zotlabs/Module/Filestorage.php +++ b/Zotlabs/Module/Filestorage.php @@ -1,6 +1,6 @@ array($sync))); } -// file_activity($channel_id, $object, $x['allow_cid'], $x['allow_gid'], $x['deny_cid'], $x['deny_gid'], 'post', $notify); +// file_activity($channel_id, $object, $x['allow_cid'], $x['allow_gid'], $x['deny_cid'], $x['deny_gid'], 'post', $notify); goaway(dirname($url)); } @@ -114,7 +114,6 @@ class Filestorage extends Controller if (argc() > 3 && argv(3) === 'delete') { - if (argc() > 4 && argv(4) === 'json') { $json_return = true; } @@ -134,7 +133,8 @@ class Filestorage extends Controller } $file = intval(argv(2)); - $r = q("SELECT hash, creator FROM attach WHERE id = %d AND uid = %d LIMIT 1", + $r = q( + "SELECT hash, creator FROM attach WHERE id = %d AND uid = %d LIMIT 1", dbesc($file), intval($owner) ); @@ -199,7 +199,8 @@ class Filestorage extends Controller $file = intval(argv(2)); - $r = q("select id, uid, folder, filename, revision, flags, is_dir, os_storage, hash, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and uid = %d limit 1", + $r = q( + "select id, uid, folder, filename, revision, flags, is_dir, os_storage, hash, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and uid = %d limit 1", intval($file), intval($owner) ); diff --git a/Zotlabs/Module/Finger.php b/Zotlabs/Module/Finger.php index 44665ea67..bdfeff2cb 100644 --- a/Zotlabs/Module/Finger.php +++ b/Zotlabs/Module/Finger.php @@ -25,7 +25,6 @@ class Finger extends Controller ]); if ($_GET['resource']) { - $resource = trim(escape_tags($_GET['resource'])); $result = Webfinger::exec($resource); @@ -34,5 +33,4 @@ class Finger extends Controller } return $o; } - } diff --git a/Zotlabs/Module/Follow.php b/Zotlabs/Module/Follow.php index 65feca08c..a97d50b92 100644 --- a/Zotlabs/Module/Follow.php +++ b/Zotlabs/Module/Follow.php @@ -1,4 +1,5 @@ = 2) { $abook_id = intval(argv(1)); - if (!$abook_id) + if (!$abook_id) { return; + } - $r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d", + $r = q( + "select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d", intval($abook_id) ); if (!$r) { @@ -56,7 +59,6 @@ class Follow extends Controller 'actor' => $actor, 'object' => $r[0]['xchan_url'] ], $chan); - } @@ -77,8 +79,10 @@ class Follow extends Controller if ($n && isset($n['type']) && !ActivityStreams::is_an_actor($n['type'])) { // set client flag to convert objects to implied activities $a = new ActivityStreams($n, null, true); - if ($a->type === 'Announce' && is_array($a->obj) - && array_key_exists('object', $a->obj) && array_key_exists('actor', $a->obj)) { + if ( + $a->type === 'Announce' && is_array($a->obj) + && array_key_exists('object', $a->obj) && array_key_exists('actor', $a->obj) + ) { // This is a relayed/forwarded Activity (as opposed to a shared/boosted object) // Reparse the encapsulated Activity and use that instead logger('relayed activity', LOGGER_DEBUG); @@ -86,7 +90,6 @@ class Follow extends Controller } if ($a->is_valid()) { - if (is_array($a->actor) && array_key_exists('id', $a->actor)) { Activity::actor_store($a->actor['id'], $a->actor); } @@ -97,7 +100,8 @@ class Follow extends Controller if ($item) { Activity::store($channel, get_observer_hash(), $a, $item, true); - $r = q("select * from item where mid = '%s' and uid = %d", + $r = q( + "select * from item where mid = '%s' and uid = %d", dbesc($item['mid']), intval($uid) ); @@ -118,7 +122,6 @@ class Follow extends Controller $result = Connect::connect($channel, $url); if ($result['success'] == false) { - if ($result['message']) { notice($result['message']); } @@ -160,7 +163,6 @@ class Follow extends Controller } else { json_return_and_die(['success' => true]); } - } public function get() diff --git a/Zotlabs/Module/Followers.php b/Zotlabs/Module/Followers.php index 378ef4de8..19485452d 100644 --- a/Zotlabs/Module/Followers.php +++ b/Zotlabs/Module/Followers.php @@ -30,9 +30,9 @@ class Followers extends Controller http_status_exit(404, 'Not found'); } -// if (intval($channel['channel_system'])) { -// http_status_exit(403,'Permission denied'); -// } +// if (intval($channel['channel_system'])) { +// http_status_exit(403,'Permission denied'); +// } Libprofile::load(argv(1)); @@ -46,7 +46,8 @@ class Followers extends Controller http_status_exit(403, 'Forbidden'); } - $t = q("select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 ", + $t = q( + "select count(xchan_hash) as total from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 ", intval($channel['channel_id']), intval($channel['channel_id']), dbesc($channel['channel_hash']) @@ -61,7 +62,8 @@ class Followers extends Controller } else { $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); - $r = q("select * from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 $pager_sql", + $r = q( + "select * from xchan left join abconfig on abconfig.xchan = xchan_hash left join abook on abook_xchan = xchan_hash where abook_channel = %d and abconfig.chan = %d and abconfig.cat = 'system' and abconfig.k = 'their_perms' and abconfig.v like '%%send_stream%%' and xchan_hash != '%s' and xchan_orphan = 0 and xchan_deleted = 0 and abook_hidden = 0 and abook_pending = 0 and abook_self = 0 $pager_sql", intval($channel['channel_id']), intval($channel['channel_id']), dbesc($channel['channel_hash']) @@ -73,7 +75,5 @@ class Followers extends Controller if (ActivityStreams::is_as_request()) { as_return_and_die($ret, $channel); } - } - } diff --git a/Zotlabs/Module/Following.php b/Zotlabs/Module/Following.php index 1de7a269e..ec6171add 100644 --- a/Zotlabs/Module/Following.php +++ b/Zotlabs/Module/Following.php @@ -1,4 +1,5 @@ ' . $desc . ''; return $text; - } - } diff --git a/Zotlabs/Module/Getfile.php b/Zotlabs/Module/Getfile.php index a2be961c0..a2cd7c40f 100644 --- a/Zotlabs/Module/Getfile.php +++ b/Zotlabs/Module/Getfile.php @@ -1,4 +1,5 @@ 0) { - $r = q("select * from photo where resource_id = '%s' and uid = %d and imgscale = %d limit 1", + $r = q( + "select * from photo where resource_id = '%s' and uid = %d and imgscale = %d limit 1", dbesc($resource), intval($channel['channel_id']), intval($resolution) @@ -97,10 +98,11 @@ class Getfile extends Controller if (intval($r[0]['os_storage'])) { $fname = dbunescbin($r[0]['content']); - if (strpos($fname, 'store') !== false) + if (strpos($fname, 'store') !== false) { $istream = fopen($fname, 'rb'); - else + } else { $istream = fopen('store/' . $channel['channel_address'] . '/' . $fname, 'rb'); + } $ostream = fopen('php://output', 'wb'); if ($istream && $ostream) { pipe_streams($istream, $ostream); @@ -126,10 +128,11 @@ class Getfile extends Controller header('Content-Disposition: attachment; filename="' . $r['data']['filename'] . '"'); if (intval($r['data']['os_storage'])) { $fname = dbunescbin($r['data']['content']); - if (strpos($fname, 'store') !== false) + if (strpos($fname, 'store') !== false) { $istream = fopen($fname, 'rb'); - else + } else { $istream = fopen('store/' . $channel['channel_address'] . '/' . $fname, 'rb'); + } $ostream = fopen('php://output', 'wb'); if ($istream && $ostream) { pipe_streams($istream, $ostream); diff --git a/Zotlabs/Module/Hashtags.php b/Zotlabs/Module/Hashtags.php index ccf7d76ec..9b8ee35f4 100644 --- a/Zotlabs/Module/Hashtags.php +++ b/Zotlabs/Module/Hashtags.php @@ -17,10 +17,12 @@ class Hashtags extends Controller $result = []; $t = escape_tags($_REQUEST['t']); - if (!$t) + if (!$t) { json_return_and_die($result); + } - $r = q("select distinct(term) from term where term like '%s' and ttype = %d order by term", + $r = q( + "select distinct(term) from term where term like '%s' and ttype = %d order by term", dbesc($t . '%'), intval(TERM_HASHTAG) ); @@ -32,4 +34,4 @@ class Hashtags extends Controller json_return_and_die($result); } -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Hcard.php b/Zotlabs/Module/Hcard.php index fab97a6a3..14f078021 100644 --- a/Zotlabs/Module/Hcard.php +++ b/Zotlabs/Module/Hcard.php @@ -1,4 +1,5 @@ 1) + if (argc() > 1) { $which = argv(1); - else { + } else { notice(t('Requested profile is not available.') . EOL); App::$error = 404; return; @@ -27,12 +28,14 @@ class Hcard extends Controller if ((local_channel()) && (argc() > 2) && (argv(2) === 'view')) { $which = $channel['channel_address']; $profile = argv(1); - $r = q("select profile_guid from profile where id = %d and uid = %d limit 1", + $r = q( + "select profile_guid from profile where id = %d and uid = %d limit 1", intval($profile), intval(local_channel()) ); - if (!$r) + if (!$r) { $profile = ''; + } $profile = $r[0]['profile_guid']; } @@ -52,7 +55,8 @@ class Hcard extends Controller if (!$profile) { - $x = q("select channel_id as profile_uid from channel where channel_address = '%s' limit 1", + $x = q( + "select channel_id as profile_uid from channel where channel_address = '%s' limit 1", dbesc(argv(1)) ); if ($x) { @@ -61,8 +65,6 @@ class Hcard extends Controller } Libprofile::load($which, $profile); - - } @@ -71,8 +73,5 @@ class Hcard extends Controller $x = new \Zotlabs\Widget\Profile(); return $x->widget([]); - } - - } diff --git a/Zotlabs/Module/Help.php b/Zotlabs/Module/Help.php index d761b4c36..151d70c64 100644 --- a/Zotlabs/Module/Help.php +++ b/Zotlabs/Module/Help.php @@ -1,4 +1,5 @@ 2 && argv(argc() - 2) === 'assets') { $path = ''; for ($x = 1; $x < argc(); $x++) { - if (strlen($path)) + if (strlen($path)) { $path .= '/'; + } $path .= argv($x); } $realpath = 'doc/' . $path; @@ -137,6 +139,4 @@ class Help extends Controller closedir($handle); return $results; } - - } diff --git a/Zotlabs/Module/Home.php b/Zotlabs/Module/Home.php index 51c25cd89..69305efcb 100644 --- a/Zotlabs/Module/Home.php +++ b/Zotlabs/Module/Home.php @@ -1,4 +1,5 @@ $channel['channel_hash'], 'target_url' => $sigdata['signer']])); - $s = q("select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", + $s = q( + "select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", dbesc($sigdata['signer']) ); @@ -94,7 +95,8 @@ class Home extends Controller } if (remote_channel() && (!$splash) && $_SESSION['atoken']) { - $r = q("select * from atoken where atoken_id = %d", + $r = q( + "select * from atoken where atoken_id = %d", intval($_SESSION['atoken']) ); if ($r) { @@ -109,7 +111,6 @@ class Home extends Controller if (get_account_id() && !$splash) { goaway(z_root() . '/new_channel'); } - } diff --git a/Zotlabs/Module/Hostxrd.php b/Zotlabs/Module/Hostxrd.php index ea6740d47..2aa569c64 100644 --- a/Zotlabs/Module/Hostxrd.php +++ b/Zotlabs/Module/Hostxrd.php @@ -1,6 +1,6 @@ loading) + if ($this->loading) { $_SESSION['loadtime_hq'] = datetime_convert(); + } if (argc() > 1 && argv(1) !== 'load') { $item_hash = argv(1); } - if ($_REQUEST['mid']) + if ($_REQUEST['mid']) { $item_hash = $_REQUEST['mid']; + } $item_normal = item_normal(); $item_normal_update = item_normal_update(); if (!$item_hash) { - $r = q("SELECT mid FROM item + $r = q( + "SELECT mid FROM item WHERE uid = %d $item_normal AND mid = parent_mid ORDER BY created DESC LIMIT 1", @@ -80,12 +87,12 @@ class Hq extends Controller } if ($item_hash) { - $item_hash = unpack_link_id($item_hash); $target_item = null; - $r = q("select id, uid, mid, parent_mid, thr_parent, verb, item_type, item_deleted, item_blocked from item where mid like '%s' limit 1", + $r = q( + "select id, uid, mid, parent_mid, thr_parent, verb, item_type, item_deleted, item_blocked from item where mid like '%s' limit 1", dbesc($item_hash . '%') ); @@ -102,17 +109,18 @@ class Hq extends Controller $simple_update = (($this->updating) ? " AND item_unseen = 1 " : ''); - if ($this->updating && $_SESSION['loadtime_hq']) + if ($this->updating && $_SESSION['loadtime_hq']) { $simple_update = " AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime_hq']) . "' "; + } - if ($static && $simple_update) + if ($static && $simple_update) { $simple_update .= " and item_thread_top = 0 and author_xchan = '" . protect_sprintf(get_observer_hash()) . "' "; + } $sys = get_sys_channel(); $sql_extra = item_permissions_sql($sys['channel_id']); $sys_item = false; - } if (!$this->updating) { @@ -145,18 +153,17 @@ class Hq extends Controller 'reset' => t('Reset form') ]; - $o = replace_macros(get_markup_template("hq.tpl"), + $o = replace_macros( + get_markup_template("hq.tpl"), [ '$no_messages' => (($target_item) ? false : true), '$no_messages_label' => [t('Welcome to $Projectname!'), t('You have got no unseen posts...')], '$editor' => status_editor($x) ] ); - } if (!$this->updating && !$this->loading) { - nav_set_selected('HQ'); $static = ((local_channel()) ? channel_manual_conv_update(local_channel()) : 1); @@ -214,7 +221,8 @@ class Hq extends Controller if ($this->loading && $target_item) { $r = null; - $r = q("SELECT item.id AS item_id FROM item + $r = q( + "SELECT item.id AS item_id FROM item WHERE uid = %d AND mid = '%s' $item_normal @@ -230,7 +238,8 @@ class Hq extends Controller if (!$r) { $sys_item = true; - $r = q("SELECT item.id AS item_id FROM item + $r = q( + "SELECT item.id AS item_id FROM item LEFT JOIN abook ON item.author_xchan = abook.abook_xchan WHERE mid = '%s' AND item.uid = %d $item_normal AND (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -242,7 +251,8 @@ class Hq extends Controller } elseif ($this->updating && $target_item) { $r = null; - $r = q("SELECT item.parent AS item_id FROM item + $r = q( + "SELECT item.parent AS item_id FROM item WHERE uid = %d AND parent_mid = '%s' $item_normal_update @@ -259,7 +269,8 @@ class Hq extends Controller if (!$r) { $sys_item = true; - $r = q("SELECT item.parent AS item_id FROM item + $r = q( + "SELECT item.parent AS item_id FROM item LEFT JOIN abook ON item.author_xchan = abook.abook_xchan WHERE mid = '%s' AND item.uid = %d $item_normal_update $simple_update AND (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -275,7 +286,8 @@ class Hq extends Controller } if ($r) { - $items = q("SELECT item.*, item.id AS item_id + $items = q( + "SELECT item.*, item.id AS item_id FROM item WHERE parent = '%s' $item_normal ", dbesc($r[0]['item_id']) @@ -291,7 +303,8 @@ class Hq extends Controller $o .= conversation($items, 'hq', $this->updating, 'client'); if ($updateable) { - $x = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d AND parent = %d ", + $x = q( + "UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d AND parent = %d ", intval(local_channel()), intval($r[0]['item_id']) ); @@ -300,7 +313,5 @@ class Hq extends Controller $o .= ''; return $o; - } - } diff --git a/Zotlabs/Module/Id.php b/Zotlabs/Module/Id.php index 283327ce0..53b126fe3 100644 --- a/Zotlabs/Module/Id.php +++ b/Zotlabs/Module/Id.php @@ -7,8 +7,8 @@ namespace Zotlabs\Module; * Controller for responding to x-zot: protocol requests * x-zot:_jkfRG85nJ-714zn-LW_VbTFW8jSjGAhAydOcJzHxqHkvEHWG2E0RbA_pbch-h4R63RG1YJZifaNzgccoLa3MQ/453c1678-1a79-4af7-ab65-6b012f6cab77 - * - */ + * + */ use Zotlabs\Lib\Libsync; use Zotlabs\Lib\Activity; @@ -34,7 +34,6 @@ class Id extends Controller { if (Libzot::is_zot_request()) { - $conversation = false; $request_portable_id = argv(1); @@ -69,13 +68,14 @@ class Id extends Controller $sql_extra = item_permissions_sql(0); - $r = q("select * from item where uuid = '%s' $item_normal $sql_extra and uid = %d limit 1", + $r = q( + "select * from item where uuid = '%s' $item_normal $sql_extra and uid = %d limit 1", dbesc($item_id), intval($channel_id) ); if (!$r) { - - $r = q("select * from item where uuid = '%s' $item_normal and uid = %d limit 1", + $r = q( + "select * from item where uuid = '%s' $item_normal and uid = %d limit 1", dbesc($item_id), intval($channel_id) ); @@ -85,16 +85,18 @@ class Id extends Controller http_status_exit(404, 'Not found'); } - if (!perm_is_allowed($chan['channel_id'], get_observer_hash(), 'view_stream')) + if (!perm_is_allowed($chan['channel_id'], get_observer_hash(), 'view_stream')) { http_status_exit(403, 'Forbidden'); + } xchan_query($r, true); $items = fetch_post_tags($r, true); $i = Activity::encode_item($items[0], (get_config('system', 'activitypub', ACTIVITYPUB_ENABLED) ? true : false)); - if (!$i) + if (!$i) { http_status_exit(404, 'Not found'); + } $x = array_merge(['@context' => [ ACTIVITYSTREAMS_JSONLD_REV, @@ -111,11 +113,6 @@ class Id extends Controller HTTPSig::set_headers($h); echo $ret; killme(); - } - } - } - - diff --git a/Zotlabs/Module/Impel.php b/Zotlabs/Module/Impel.php index 0a2c248d0..4e2cd2524 100644 --- a/Zotlabs/Module/Impel.php +++ b/Zotlabs/Module/Impel.php @@ -1,5 +1,8 @@ false); - if (!local_channel()) + if (!local_channel()) { json_return_and_die($ret); + } logger('impel: ' . print_r($_REQUEST, true), LOGGER_DATA); $elm = $_REQUEST['element']; $x = base64url_decode($elm); - if (!$x) + if (!$x) { json_return_and_die($ret); + } $j = json_decode($x, true); - if (!$j) + if (!$j) { json_return_and_die($ret); + } // logger('element: ' . print_r($j,true)); @@ -76,18 +82,21 @@ class Impel extends Controller $m['menu_channel_id'] = local_channel(); $m['menu_name'] = $j['pagetitle']; $m['menu_desc'] = $j['desc']; - if ($j['created']) + if ($j['created']) { $m['menu_created'] = datetime_convert($j['created']); - if ($j['edited']) + } + if ($j['edited']) { $m['menu_edited'] = datetime_convert($j['edited']); + } $m['menu_flags'] = 0; if ($j['flags']) { - if (in_array('bookmark', $j['flags'])) + if (in_array('bookmark', $j['flags'])) { $m['menu_flags'] |= MENU_BOOKMARK; - if (in_array('system', $j['flags'])) + } + if (in_array('system', $j['flags'])) { $m['menu_flags'] |= MENU_SYSTEM; - + } } $menu_id = menu_create($m); @@ -106,17 +115,21 @@ class Impel extends Controller $mitem['mitem_order'] = intval($it['order']); if (is_array($it['flags'])) { $mitem['mitem_flags'] = 0; - if (in_array('zid', $it['flags'])) + if (in_array('zid', $it['flags'])) { $mitem['mitem_flags'] |= MENU_ITEM_ZID; - if (in_array('new-window', $it['flags'])) + } + if (in_array('new-window', $it['flags'])) { $mitem['mitem_flags'] |= MENU_ITEM_NEWWIN; - if (in_array('chatroom', $it['flags'])) + } + if (in_array('chatroom', $it['flags'])) { $mitem['mitem_flags'] |= MENU_ITEM_CHATROOM; + } } menu_add_item($menu_id, local_channel(), $mitem); } if ($j['edited']) { - $x = q("update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", + $x = q( + "update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", dbesc(datetime_convert('UTC', 'UTC', $j['edited'])), intval($menu_id), intval(local_channel()) @@ -156,7 +169,8 @@ class Impel extends Controller $execflag = ((intval($channel['channel_id']) == intval(local_channel()) && ($channel['channel_pageflags'] & PAGE_ALLOWCODE)) ? true : false); - $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", + $i = q( + "select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval(local_channel()) ); @@ -166,17 +180,20 @@ class Impel extends Controller if ($i) { $arr['id'] = $i[0]['id']; // don't update if it has the same timestamp as the original - if ($arr['edited'] > $i[0]['edited']) + if ($arr['edited'] > $i[0]['edited']) { $x = item_store_update($arr, $execflag); + } } else { if (($i) && (intval($i[0]['item_deleted']))) { // was partially deleted already, finish it off - q("delete from item where mid = '%s' and uid = %d", + q( + "delete from item where mid = '%s' and uid = %d", dbesc($arr['mid']), intval(local_channel()) ); - } else + } else { $x = item_store($arr, $execflag); + } } if ($x && $x['success']) { @@ -194,7 +211,5 @@ class Impel extends Controller //??? should perhaps return ret? json_return_and_die(true); - } - } diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index 9040c0f96..5e006bba4 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -9,10 +9,8 @@ use Zotlabs\Web\HTTPSig; use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Connect; use Zotlabs\Daemon\Run; - use Zotlabs\Import\Friendica; - require_once('include/import.php'); require_once('include/photo_factory.php'); @@ -53,7 +51,6 @@ class Import extends Controller // import channel from file if ($src) { - // This is OS specific and could also fail if your tmpdir isn't very // large mostly used for Diaspora which exports gzipped files. @@ -123,7 +120,6 @@ class Import extends Controller // handle Friendica export if (array_path_exists('user/parent-uid', $data)) { - $settings = ['account_id' => $account_id, 'sieze' => 1, 'newname' => $newname]; $f = new Friendica($data, $settings); @@ -153,11 +149,11 @@ class Import extends Controller $relocate = ((array_key_exists('relocate', $data)) ? $data['relocate'] : null); if (array_key_exists('channel', $data)) { - $max_identities = account_service_class_fetch($account_id, 'total_identities'); if ($max_identities !== false) { - $r = q("select channel_id from channel where channel_account_id = %d and channel_removed = 0 ", + $r = q( + "select channel_id from channel where channel_account_id = %d and channel_removed = 0 ", intval($account_id) ); if ($r && count($r) > $max_identities) { @@ -215,10 +211,10 @@ class Import extends Controller // This *must* be done before importing hublocs if (array_key_exists('channel', $data) && $seize) { - // replace any existing xchan we may have on this site if we're seizing control - $r = q("delete from xchan where xchan_hash = '%s'", + $r = q( + "delete from xchan where xchan_hash = '%s'", dbesc($channel['channel_hash']) ); @@ -250,7 +246,6 @@ class Import extends Controller $xchans = $data['xchan']; if ($xchans) { foreach ($xchans as $xchan) { - // Provide backward compatibility for zot11 based projects if ($xchan['xchan_network'] === 'nomad' && version_compare(ZOT_REVISION, '10.0') <= 0) { @@ -264,7 +259,8 @@ class Import extends Controller continue; } - $r = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", + $r = q( + "select xchan_hash from xchan where xchan_hash = '%s' limit 1", dbesc($xchan['xchan_hash']) ); if ($r) { @@ -274,7 +270,8 @@ class Import extends Controller if ($xchan['xchan_hash'] === $channel['channel_hash']) { - $r = q("update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s' where xchan_hash = '%s'", + $r = q( + "update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc(z_root() . '/photo/profile/l/' . $channel['channel_id']), dbesc(z_root() . '/photo/profile/m/' . $channel['channel_id']), @@ -290,7 +287,8 @@ class Import extends Controller $photodate = $xchan['xchan_photo_date']; } - $r = q("update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' where xchan_hash = '%s'", + $r = q( + "update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($photos[0]), dbesc($photos[1]), @@ -341,7 +339,8 @@ class Import extends Controller // reset the original primary hubloc if it is being seized if ($seize) { - $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ", + $r = q( + "update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ", dbesc($channel['channel_hash']), dbesc(z_root()) ); @@ -356,7 +355,6 @@ class Import extends Controller $abooks = $data['abook']; if ($abooks) { foreach ($abooks as $abook) { - $abook_copy = $abook; $abconfig = null; @@ -393,7 +391,8 @@ class Import extends Controller $ctype = 1; } if ($ctype) { - q("update xchan set xchan_type = %d where xchan_hash = '%s' ", + q( + "update xchan set xchan_type = %d where xchan_hash = '%s' ", intval($ctype), dbesc($abook['abook_xchan']) ); @@ -407,7 +406,8 @@ class Import extends Controller } } - $r = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1", + $r = q( + "select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1", dbesc($abook['abook_xchan']), intval($channel['channel_id']) ); @@ -418,7 +418,8 @@ class Import extends Controller if (!in_array($k, $columns)) { continue; } - $r = q("UPDATE abook SET " . TQUOT . "%s" . TQUOT . " = '%s' WHERE abook_xchan = '%s' AND abook_channel = %d", + $r = q( + "UPDATE abook SET " . TQUOT . "%s" . TQUOT . " = '%s' WHERE abook_xchan = '%s' AND abook_channel = %d", dbesc($k), dbesc($v), dbesc($abook['abook_xchan']), @@ -462,7 +463,8 @@ class Import extends Controller create_table_from_array('pgrp', $group); } - $r = q("select * from pgrp where uid = %d", + $r = q( + "select * from pgrp where uid = %d", intval($channel['channel_id']) ); if ($r) { @@ -514,27 +516,27 @@ class Import extends Controller if (is_array($data['chatroom'])) { import_chatrooms($channel, $data['chatroom']); } -// if (is_array($data['conv'])) { -// import_conv($channel,$data['conv']); -// } -// if (is_array($data['mail'])) { -// import_mail($channel,$data['mail']); -// } +// if (is_array($data['conv'])) { +// import_conv($channel,$data['conv']); +// } +// if (is_array($data['mail'])) { +// import_mail($channel,$data['mail']); +// } if (is_array($data['event'])) { import_events($channel, $data['event']); } if (is_array($data['event_item'])) { import_items($channel, $data['event_item'], false, $relocate); } -// if (is_array($data['menu'])) { -// import_menus($channel,$data['menu']); -// } -// if (is_array($data['wiki'])) { -// import_items($channel,$data['wiki'],false,$relocate); -// } -// if (is_array($data['webpages'])) { -// import_items($channel,$data['webpages'],false,$relocate); -// } +// if (is_array($data['menu'])) { +// import_menus($channel,$data['menu']); +// } +// if (is_array($data['wiki'])) { +// import_items($channel,$data['wiki'],false,$relocate); +// } +// if (is_array($data['webpages'])) { +// import_items($channel,$data['webpages'],false,$relocate); +// } $addon = array('channel' => $channel, 'data' => $data); call_hooks('import_channel', $addon); @@ -544,7 +546,6 @@ class Import extends Controller } if ($api_path && $import_posts) { // we are importing from a server and not a file - $m = parse_url($api_path); $hz_server = $m['scheme'] . '://' . $m['host']; @@ -630,7 +631,6 @@ class Import extends Controller } notice(t('Files and Posts imported.') . EOL); - } notifications_on($channel['channel_id'], $saved_notification_flags); @@ -703,5 +703,4 @@ class Import extends Controller '$submit' => t('Submit') ]); } - } diff --git a/Zotlabs/Module/Import_items.php b/Zotlabs/Module/Import_items.php index 87be5cb8f..e489f9fe9 100644 --- a/Zotlabs/Module/Import_items.php +++ b/Zotlabs/Module/Import_items.php @@ -1,4 +1,5 @@ $email . ':' . $password); $url = $scheme . $servername . $api_path; $ret = z_fetch_url($url, $binary, $redirects, $opts); - if (!$ret['success']) + if (!$ret['success']) { $ret = z_fetch_url('http://' . $servername . $api_path, $binary, $redirects, $opts); - if ($ret['success']) + } + if ($ret['success']) { $data = $ret['body']; - else + } else { notice(t('Unable to download data from old server') . EOL); + } } if (!$data) { @@ -88,17 +91,18 @@ class Import_items extends Controller //logger('import: data: ' . print_r($data,true)); //print_r($data); - if (!is_array($data)) + if (!is_array($data)) { return; + } -// if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) { -// $v1 = substr($data['compatibility']['database'],-4); -// $v2 = substr(DB_UPDATE_VERSION,-4); -// if($v2 > $v1) { -// $t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 ); -// notice($t . EOL); -// } -// } +// if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) { +// $v1 = substr($data['compatibility']['database'],-4); +// $v2 = substr(DB_UPDATE_VERSION,-4); +// if($v2 > $v1) { +// $t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 ); +// notice($t . EOL); +// } +// } $codebase = 'zap'; @@ -140,5 +144,4 @@ class Import_items extends Controller return $o; } - } diff --git a/Zotlabs/Module/Inbox.php b/Zotlabs/Module/Inbox.php index 953443ae0..3a5e70782 100644 --- a/Zotlabs/Module/Inbox.php +++ b/Zotlabs/Module/Inbox.php @@ -1,4 +1,5 @@ is_valid() && $AS->type === 'Announce' && is_array($AS->obj) - && array_key_exists('object', $AS->obj) && array_key_exists('actor', $AS->obj)) { + if ( + $AS->is_valid() && $AS->type === 'Announce' && is_array($AS->obj) + && array_key_exists('object', $AS->obj) && array_key_exists('actor', $AS->obj) + ) { // This is a relayed/forwarded Activity (as opposed to a shared/boosted object) // Reparse the encapsulated Activity and use that instead logger('relayed activity', LOGGER_DEBUG); @@ -113,7 +118,6 @@ class Inbox extends Controller // AND the signature is valid AND the signer is the actor. if ($hsig['header_valid'] && $hsig['content_valid'] && $hsig['portable_id']) { - // if the sender has the ability to send messages over zot/nomad, ignore messages sent via activitypub // as observer aware features and client side markup will be unavailable @@ -142,14 +146,12 @@ class Inbox extends Controller // The activity signature isn't valid. return; } - } if ($v) { // The sender has been validated and stored $observer_hash = $hsig['portable_id']; } - } if (!$observer_hash) { @@ -165,7 +167,8 @@ class Inbox extends Controller http_status_exit(403, 'Permission denied'); } // this site obviously isn't dead because they are trying to communicate with us. - $test = q("update site set site_dead = 0 where site_dead = 1 and site_url = '%s' ", + $test = q( + "update site set site_dead = 0 where site_dead = 1 and site_url = '%s' ", dbesc($m['scheme'] . '://' . $m['host']) ); } @@ -175,7 +178,8 @@ class Inbox extends Controller // update the hubloc_connected timestamp, ignore failures - $test = q("update hubloc set hubloc_connected = '%s' where hubloc_hash = '%s' and hubloc_network = 'activitypub'", + $test = q( + "update hubloc set hubloc_connected = '%s' where hubloc_hash = '%s' and hubloc_network = 'activitypub'", dbesc(datetime_convert()), dbesc($observer_hash) ); @@ -184,15 +188,16 @@ class Inbox extends Controller // Now figure out who the recipients are if ($is_public) { - if (in_array($AS->type, ['Follow', 'Join']) && is_array($AS->obj) && ActivityStreams::is_an_actor($AS->obj['type'])) { - $channels = q("SELECT * from channel where channel_address = '%s' and channel_removed = 0 ", + $channels = q( + "SELECT * from channel where channel_address = '%s' and channel_removed = 0 ", dbesc(basename($AS->obj['id'])) ); } else { // deliver to anybody following $AS->actor - $channels = q("SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network = 'activitypub' and xchan_hash = '%s' ) and channel_removed = 0 ", + $channels = q( + "SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network = 'activitypub' and xchan_hash = '%s' ) and channel_removed = 0 ", dbesc($observer_hash) ); if (!$channels) { @@ -202,7 +207,8 @@ class Inbox extends Controller $parent = $AS->parent_id; if ($parent) { // this is a comment - deliver to everybody who owns the parent - $owners = q("SELECT * from channel where channel_id in ( SELECT uid from item where mid = '%s' ) ", + $owners = q( + "SELECT * from channel where channel_id in ( SELECT uid from item where mid = '%s' ) ", dbesc($parent) ); if ($owners) { @@ -216,7 +222,6 @@ class Inbox extends Controller } if (in_array(ACTIVITY_PUBLIC_INBOX, $AS->recips) || in_array('Public', $AS->recips) || in_array('as:Public', $AS->recips)) { - // look for channels with send_stream = PERMS_PUBLIC (accept posts from anybody on the internet) $r = q("select * from channel where channel_id in (select uid from pconfig where cat = 'perm_limits' and k = 'send_stream' and v = '1' ) and channel_removed = 0 "); @@ -235,9 +240,7 @@ class Inbox extends Controller if (!$sys_disabled) { $channels[] = get_sys_channel(); } - } - } // $channels represents all "potential" recipients. If they are not in this array, they will not receive the activity. @@ -260,7 +263,6 @@ class Inbox extends Controller foreach ($channels as $channel) { - // Even though activitypub may be enabled for the site, check if the channel has specifically disabled it if (!PConfig::Get($channel['channel_id'], 'system', 'activitypub', Config::Get('system', 'activitypub', ACTIVITYPUB_ENABLED))) { continue; @@ -298,10 +300,8 @@ class Inbox extends Controller break; case 'Reject': - default: break; - } // These activities require permissions @@ -367,15 +367,16 @@ class Inbox extends Controller break; case 'Move': - if ($observer_hash && $observer_hash === $AS->actor + if ( + $observer_hash && $observer_hash === $AS->actor && is_array($AS->obj) && array_key_exists('type', $AS->obj) && ActivityStream::is_an_actor($AS->obj['type']) - && is_array($AS->tgt) && array_key_exists('type', $AS->tgt) && ActivityStream::is_an_actor($AS->tgt['type'])) { + && is_array($AS->tgt) && array_key_exists('type', $AS->tgt) && ActivityStream::is_an_actor($AS->tgt['type']) + ) { ActivityPub::move($AS->obj, $AS->tgt); } break; case 'Add': case 'Remove': - // for writeable collections as target, it's best to provide an array and include both the type and the id in the target element. // If it's just a string id, we'll try to fetch the collection when we receive it and that's wasteful since we don't actually need // the contents. @@ -386,14 +387,12 @@ class Inbox extends Controller } default: break; - } if ($item) { logger('parsed_item: ' . print_r($item, true), LOGGER_DATA); Activity::store($channel, $observer_hash, $AS, $item); } - } http_status_exit(200, 'OK'); @@ -401,10 +400,5 @@ class Inbox extends Controller public function get() { - } - } - - - diff --git a/Zotlabs/Module/Inspect.php b/Zotlabs/Module/Inspect.php index 6ccb5066b..dfa8d02fa 100644 --- a/Zotlabs/Module/Inspect.php +++ b/Zotlabs/Module/Inspect.php @@ -35,7 +35,8 @@ class Inspect extends Controller } if ($item_type === 'item') { - $r = q("select * from item where uuid = '%s' or id = %d ", + $r = q( + "select * from item where uuid = '%s' or id = %d ", dbesc($item_id), intval($item_id) ); @@ -65,13 +66,12 @@ class Inspect extends Controller $output .= '' . escape_tags(json_encode(Activity::encode_activity($item, true), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) . '' . EOL . EOL; $output .= '' . escape_tags(json_encode(json_decode(get_iconfig($item['id'], 'activitypub', 'rawmsg'), true), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) . '' . EOL . EOL; - } - } if ($item_type === 'xchan') { - $items = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_hash = '%s' or hubloc_addr = '%s' ", + $items = q( + "select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_hash = '%s' or hubloc_addr = '%s' ", dbesc($item_id), dbesc($item_id) ); @@ -88,6 +88,4 @@ class Inspect extends Controller return $output; } - - } diff --git a/Zotlabs/Module/Invite.php b/Zotlabs/Module/Invite.php index 4a1b0b193..f400e1ebd 100644 --- a/Zotlabs/Module/Invite.php +++ b/Zotlabs/Module/Invite.php @@ -1,4 +1,5 @@ = 0) + if ($x >= 0) { set_pconfig(local_channel(), 'system', 'invites_remaining', $x); - else + } else { return; + } } } $ob = App::get_observer(); - if (!$ob) + if (!$ob) { return $o; + } $channel = App::get_channel(); @@ -165,5 +170,4 @@ class Invite extends Controller return $o; } - } diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index eeea9fde5..f4f096bc3 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -8,16 +8,16 @@ namespace Zotlabs\Module; * acts as a permalink for local content. * * Otherwise this is the POST destination for most all locally posted - * text stuff. This function handles status, wall-to-wall status, - * local comments, and remote coments that are posted on this site + * text stuff. This function handles status, wall-to-wall status, + * local comments, and remote coments that are posted on this site * (as opposed to being delivered in a feed). - * Also processed here are posts and comments coming through the API. - * All of these become an "item" which is our basic unit of + * Also processed here are posts and comments coming through the API. + * All of these become an "item" which is our basic unit of * information. - * Posts that originate externally or do not fall into the above - * posting categories go through item_store() instead of this function. + * Posts that originate externally or do not fall into the above + * posting categories go through item_store() instead of this function. * - */ + */ use Zotlabs\Lib\Libsync; use Zotlabs\Lib\Activity; @@ -69,7 +69,8 @@ class Item extends Controller // do we have the item (at all)? // add preferential bias to item owners (item_wall = 1) - $r = q("select * from item where (mid = '%s' or uuid = '%s') $item_normal order by item_wall desc limit 1", + $r = q( + "select * from item where (mid = '%s' or uuid = '%s') $item_normal order by item_wall desc limit 1", dbesc(z_root() . '/item/' . $item_uuid), dbesc($item_uuid) ); @@ -92,7 +93,8 @@ class Item extends Controller } observer_auth($portable_id); - $i = q("select id as item_id from item where mid = '%s' $item_normal and owner_xchan = '%s' limit 1 ", + $i = q( + "select id as item_id from item where mid = '%s' $item_normal and owner_xchan = '%s' limit 1 ", dbesc($r[0]['parent_mid']), dbesc($portable_id) ); @@ -106,7 +108,8 @@ class Item extends Controller $sql_extra = item_permissions_sql(0); if (!$i) { - $i = q("select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1", + $i = q( + "select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1", dbesc($r[0]['parent_mid']) ); } @@ -115,11 +118,13 @@ class Item extends Controller if ($bear) { logger('bear: ' . $bear, LOGGER_DEBUG); if (!$i) { - $t = q("select * from iconfig where cat = 'ocap' and k = 'relay' and v = '%s'", + $t = q( + "select * from iconfig where cat = 'ocap' and k = 'relay' and v = '%s'", dbesc($bear) ); if ($t) { - $i = q("select id as item_id from item where uuid = '%s' and id = %d $item_normal limit 1", + $i = q( + "select id as item_id from item where uuid = '%s' and id = %d $item_normal limit 1", dbesc($item_uuid), intval($t[0]['iid']) ); @@ -154,7 +159,8 @@ class Item extends Controller if ($portable_id && (!intval($items[0]['item_private']))) { - $c = q("select abook_id from abook where abook_channel = %d and abook_xchan = '%s'", + $c = q( + "select abook_id from abook where abook_channel = %d and abook_xchan = '%s'", intval($items[0]['uid']), dbesc($portable_id) ); @@ -167,7 +173,6 @@ class Item extends Controller } if (Libzot::is_zot_request()) { - $item_uuid = argv(1); if (!$item_uuid) { @@ -182,7 +187,8 @@ class Item extends Controller // do we have the item (at all)? - $r = q("select * from item where (mid = '%s' or uuid = '%s') $item_normal limit 1", + $r = q( + "select * from item where (mid = '%s' or uuid = '%s') $item_normal limit 1", dbesc(z_root() . '/item/' . $item_uuid), dbesc($item_uuid) ); @@ -204,7 +210,8 @@ class Item extends Controller } observer_auth($portable_id); - $i = q("select id as item_id from item where mid = '%s' $item_normal and owner_xchan = '%s' limit 1", + $i = q( + "select id as item_id from item where mid = '%s' $item_normal and owner_xchan = '%s' limit 1", dbesc($r[0]['parent_mid']), dbesc($portable_id) ); @@ -218,7 +225,8 @@ class Item extends Controller $sql_extra = item_permissions_sql(0); if (!$i) { - $i = q("select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1", + $i = q( + "select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1", dbesc($r[0]['parent_mid']) ); } @@ -227,11 +235,13 @@ class Item extends Controller if ($bear) { logger('bear: ' . $bear, LOGGER_DEBUG); if (!$i) { - $t = q("select * from iconfig where cat = 'ocap' and k = 'relay' and v = '%s'", + $t = q( + "select * from iconfig where cat = 'ocap' and k = 'relay' and v = '%s'", dbesc($bear) ); if ($t) { - $i = q("select id as item_id from item where uuid = '%s' and id = %d $item_normal limit 1", + $i = q( + "select id as item_id from item where uuid = '%s' and id = %d $item_normal limit 1", dbesc($item_uuid), intval($t[0]['iid']) ); @@ -245,7 +255,8 @@ class Item extends Controller $parents_str = ids_to_querystr($i, 'item_id'); - $items = q("SELECT item.*, item.id AS item_id FROM item WHERE item.parent IN ( %s ) $item_normal order by item.id asc", + $items = q( + "SELECT item.*, item.id AS item_id FROM item WHERE item.parent IN ( %s ) $item_normal order by item.id asc", dbesc($parents_str) ); @@ -293,7 +304,6 @@ class Item extends Controller HTTPSig::set_headers($h); echo $ret; killme(); - } // if it isn't a drop command and isn't a post method and wasn't handled already, @@ -301,7 +311,8 @@ class Item extends Controller // the text/html page of the item. if (argc() > 1 && argv(1) !== 'drop') { - $x = q("select uid, item_wall, llink, mid from item where mid = '%s' or mid = '%s' or uuid = '%s'", + $x = q( + "select uid, item_wall, llink, mid from item where mid = '%s' or mid = '%s' or uuid = '%s'", dbesc(z_root() . '/item/' . argv(1)), dbesc(z_root() . '/activity/' . argv(1)), dbesc(argv(1)) @@ -478,10 +489,12 @@ class Item extends Controller $ret = $this->item_check_service_class($uid, (($_REQUEST['webpage'] == ITEM_TYPE_WEBPAGE) ? true : false)); if (!$ret['success']) { notice(t($ret['message']) . EOL); - if ($api_source) + if ($api_source) { return (['success' => false, 'message' => 'service class exception']); - if (x($_REQUEST, 'return')) + } + if (x($_REQUEST, 'return')) { goaway(z_root() . "/" . $return_path); + } killme(); } } @@ -504,7 +517,6 @@ class Item extends Controller // If this is a comment, find the parent and preset some stuff if ($parent || $parent_mid) { - if (!x($_REQUEST, 'type')) { $_REQUEST['type'] = 'net-comment'; } @@ -515,12 +527,14 @@ class Item extends Controller // fetch the parent item if ($parent) { - $r = q("SELECT * FROM item WHERE id = %d LIMIT 1", + $r = q( + "SELECT * FROM item WHERE id = %d LIMIT 1", intval($parent) ); } elseif ($parent_mid && $uid) { // This is coming from an API source, and we are logged in - $r = q("SELECT * FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", + $r = q( + "SELECT * FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($parent_mid), intval($uid) ); @@ -531,7 +545,8 @@ class Item extends Controller $parid = $r[0]['parent']; $parent_mid = $r[0]['mid']; if ($r[0]['id'] != $r[0]['parent']) { - $r = q("SELECT * FROM item WHERE id = parent AND parent = %d LIMIT 1", + $r = q( + "SELECT * FROM item WHERE id = parent AND parent = %d LIMIT 1", intval($parid) ); } @@ -572,7 +587,6 @@ class Item extends Controller $thr_parent = $parent_mid; $route = $parent_item['route']; - } if ($parent_item && isset($parent_item['replyto']) && $parent_item['replyto']) { @@ -617,20 +631,24 @@ class Item extends Controller if (!$can_comment) { notice(t('Permission denied.') . EOL); - if ($api_source) + if ($api_source) { return (['success' => false, 'message' => 'permission denied']); - if (x($_REQUEST, 'return')) + } + if (x($_REQUEST, 'return')) { goaway(z_root() . "/" . $return_path); + } killme(); } } else { // fixme - $webpage could also be a wiki page or article and require a different permission to be checked. if (!perm_is_allowed($profile_uid, $observer['xchan_hash'], ($webpage) ? 'write_pages' : 'post_wall')) { notice(t('Permission denied.') . EOL); - if ($api_source) + if ($api_source) { return (['success' => false, 'message' => 'permission denied']); - if (x($_REQUEST, 'return')) + } + if (x($_REQUEST, 'return')) { goaway(z_root() . "/" . $return_path); + } killme(); } } @@ -653,25 +671,30 @@ class Item extends Controller if ($namespace && $remote_id) { // It wasn't an internally generated post - see if we've got an item matching this remote service id - $i = q("select iid from iconfig where cat = 'system' and k = '%s' and v = '%s' limit 1", + $i = q( + "select iid from iconfig where cat = 'system' and k = '%s' and v = '%s' limit 1", dbesc($namespace), dbesc($remote_id) ); - if ($i) + if ($i) { $post_id = $i[0]['iid']; + } } $iconfig = null; if ($post_id) { - $i = q("SELECT * FROM item WHERE uid = %d AND id = %d LIMIT 1", + $i = q( + "SELECT * FROM item WHERE uid = %d AND id = %d LIMIT 1", intval($profile_uid), intval($post_id) ); - if (!count($i)) + if (!count($i)) { killme(); + } $orig_post = $i[0]; - $iconfig = q("select * from iconfig where iid = %d", + $iconfig = q( + "select * from iconfig where iid = %d", intval($post_id) ); } @@ -682,45 +705,53 @@ class Item extends Controller $channel = App::get_channel(); } else { // posting as yourself but not necessarily to a channel you control - $r = q("select * from channel left join account on channel_account_id = account_id where channel_id = %d LIMIT 1", + $r = q( + "select * from channel left join account on channel_account_id = account_id where channel_id = %d LIMIT 1", intval($profile_uid) ); - if ($r) + if ($r) { $channel = $r[0]; + } } } if (!$channel) { logger("mod_item: no channel."); - if ($api_source) + if ($api_source) { return (['success' => false, 'message' => 'no channel']); - if (x($_REQUEST, 'return')) + } + if (x($_REQUEST, 'return')) { goaway(z_root() . "/" . $return_path); + } killme(); } $owner_xchan = null; - $r = q("select * from xchan where xchan_hash = '%s' limit 1", + $r = q( + "select * from xchan where xchan_hash = '%s' limit 1", dbesc($channel['channel_hash']) ); if ($r && count($r)) { $owner_xchan = $r[0]; } else { logger("mod_item: no owner."); - if ($api_source) + if ($api_source) { return (['success' => false, 'message' => 'no owner']); - if (x($_REQUEST, 'return')) + } + if (x($_REQUEST, 'return')) { goaway(z_root() . "/" . $return_path); + } killme(); } $walltowall = false; $walltowall_comment = false; - if ($remote_xchan && !$moderated) + if ($remote_xchan && !$moderated) { $observer = $remote_observer; + } if ($observer) { logger('mod_item: post accepted from ' . $observer['xchan_name'] . ' for ' . $owner_xchan['xchan_name'], LOGGER_DEBUG); @@ -755,13 +786,14 @@ class Item extends Controller $comment_policy = ((isset($_REQUEST['comments_from']) && intval($_REQUEST['comments_from'])) ? intval($_REQUEST['comments_from']) : PermissionLimits::Get($channel['channel_id'], 'post_comments')); $public_policy = ((x($_REQUEST, 'public_policy')) ? escape_tags($_REQUEST['public_policy']) : map_scope($view_policy, true)); - if ($webpage) + if ($webpage) { $public_policy = ''; - if ($public_policy) + } + if ($public_policy) { $private = 1; + } if ($orig_post) { - $private = 0; // webpages and unpublished drafts are allowed to change ACLs after the fact. Normal conversation items aren't. if ($webpage || intval($orig_post['item_unpublished'])) { @@ -814,16 +846,16 @@ class Item extends Controller $mid = $orig_post['mid']; $parent_mid = $orig_post['parent_mid']; $plink = $orig_post['plink']; - } else { if (!$walltowall) { - if ((array_key_exists('contact_allow', $_REQUEST)) + if ( + (array_key_exists('contact_allow', $_REQUEST)) || (array_key_exists('group_allow', $_REQUEST)) || (array_key_exists('contact_deny', $_REQUEST)) - || (array_key_exists('group_deny', $_REQUEST))) { + || (array_key_exists('group_deny', $_REQUEST)) + ) { $acl->set_from_array($_REQUEST); } elseif (!$api_source) { - // if no ACL has been defined and we aren't using the API, the form // didn't send us any parameters. This means there's no ACL or it has // been reset to the default audience. @@ -863,13 +895,16 @@ class Item extends Controller } if ((!$allow_empty) && (!strlen($body))) { - if ($preview) + if ($preview) { killme(); + } info(t('Empty post discarded.') . EOL); - if ($api_source) + if ($api_source) { return (['success' => false, 'message' => 'no content']); - if (x($_REQUEST, 'return')) + } + if (x($_REQUEST, 'return')) { goaway(z_root() . "/" . $return_path); + } killme(); } } @@ -878,15 +913,17 @@ class Item extends Controller if (Apps::system_app_installed($profile_uid, 'Expire Posts')) { if (x($_REQUEST, 'expire')) { $expires = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['expire']); - if ($expires <= datetime_convert()) + if ($expires <= datetime_convert()) { $expires = NULL_DATE; + } } } $mimetype = notags(trim($_REQUEST['mimetype'])); - if (!$mimetype) + if (!$mimetype) { $mimetype = 'text/bbcode'; + } $execflag = ((intval($uid) == intval($profile_uid) @@ -968,7 +1005,6 @@ class Item extends Controller if ($mimetype === 'text/bbcode') { - // BBCODE alert: the following functions assume bbcode input // and will require alternatives for alternative content-types (text/html, text/markdown, text/plain, etc.) // we may need virtual or template classes to implement the possible alternatives @@ -992,9 +1028,7 @@ class Item extends Controller $comment_tags = linkify_tags($hidden_mentions, ($uid) ? $uid : $profile_uid); foreach ([$summary_tags, $body_tags, $comment_tags] as $results) { - if ($results) { - // Set permissions based on tag replacements set_linkified_perms($results, $str_contact_allow, $str_group_allow, $profile_uid, $parent_item, $private); @@ -1004,7 +1038,6 @@ class Item extends Controller foreach ($results as $result) { $success = $result['success']; if ($success['replaced']) { - // suppress duplicate mentions/tags $already_tagged = false; foreach ($post_tags as $pt) { @@ -1030,7 +1063,8 @@ class Item extends Controller // this is checked inside tag_deliver() to create a second delivery chain if ($success['termtype'] === TERM_HASHTAG) { - $r = q("select xchan_url from channel left join xchan on xchan_hash = channel_hash where channel_address = '%s' and channel_parent = '%s' and channel_removed = 0", + $r = q( + "select xchan_url from channel left join xchan on xchan_hash = channel_hash where channel_address = '%s' and channel_parent = '%s' and channel_removed = 0", dbesc($success['term']), dbesc(get_observer_hash()) ); @@ -1056,7 +1090,8 @@ class Item extends Controller if (array_key_exists('collections', $_REQUEST) && is_array($_REQUEST['collections']) && count($_REQUEST['collections'])) { foreach ($_REQUEST['collections'] as $clct) { - $r = q("select xchan_url, xchan_hash from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1", + $r = q( + "select xchan_url, xchan_hash from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1", dbesc($clct) ); if ($r) { @@ -1080,7 +1115,6 @@ class Item extends Controller } if ($private) { - // for edited posts, re-use any existing OCAP token (if found). // Otherwise generate a new one. @@ -1157,7 +1191,6 @@ class Item extends Controller $i++; } } - } // BBCODE end alert @@ -1169,7 +1202,6 @@ class Item extends Controller $cats = explode(',', $categories); foreach ($cats as $cat) { - if ($webpage == ITEM_TYPE_CARD) { $catlink = z_root() . '/cards/' . $channel['channel_address'] . '?f=&cat=' . urlencode(trim($cat)); } elseif ($webpage == ITEM_TYPE_ARTICLE) { @@ -1190,7 +1222,8 @@ class Item extends Controller if ($orig_post) { // preserve original tags - $t = q("select * from term where oid = %d and otype = %d and uid = %d and ttype in ( %d, %d, %d )", + $t = q( + "select * from term where oid = %d and otype = %d and uid = %d and ttype in ( %d, %d, %d )", intval($orig_post['id']), intval(TERM_OBJ_POST), intval($profile_uid), @@ -1233,12 +1266,14 @@ class Item extends Controller } - if ($moderated) + if ($moderated) { $item_blocked = ITEM_MODERATED; + } - if (!strlen($verb)) + if (!strlen($verb)) { $verb = ACTIVITY_POST; + } $notify_type = (($parent) ? 'comment-new' : 'wall-new'); @@ -1283,14 +1318,16 @@ class Item extends Controller $parent_mid = $mid; } - if ($parent_item) + if ($parent_item) { $parent_mid = $parent_item['mid']; + } // Fallback so that we alway have a thr_parent - if (!$thr_parent) + if (!$thr_parent) { $thr_parent = $mid; + } $item_thread_top = ((!$parent) ? 1 : 0); @@ -1302,7 +1339,8 @@ class Item extends Controller $plink = z_root() . '/cards/' . $channel['channel_address'] . '/' . (($pagetitle) ? $pagetitle : $uuid); } if (($parent_item) && ($parent_item['item_type'] == ITEM_TYPE_CARD)) { - $r = q("select v from iconfig where iconfig.cat = 'system' and iconfig.k = 'CARD' and iconfig.iid = %d limit 1", + $r = q( + "select v from iconfig where iconfig.cat = 'system' and iconfig.k = 'CARD' and iconfig.iid = %d limit 1", intval($parent_item['id']) ); if ($r) { @@ -1314,7 +1352,8 @@ class Item extends Controller $plink = z_root() . '/articles/' . $channel['channel_address'] . '/' . (($pagetitle) ? $pagetitle : $uuid); } if (($parent_item) && ($parent_item['item_type'] == ITEM_TYPE_ARTICLE)) { - $r = q("select v from iconfig where iconfig.cat = 'system' and iconfig.k = 'ARTICLE' and iconfig.iid = %d limit 1", + $r = q( + "select v from iconfig where iconfig.cat = 'system' and iconfig.k = 'ARTICLE' and iconfig.iid = %d limit 1", intval($parent_item['id']) ); if ($r) { @@ -1395,8 +1434,9 @@ class Item extends Controller // A specific ACL over-rides public_policy completely - if (!empty_acl($datarray)) + if (!empty_acl($datarray)) { $datarray['public_policy'] = ''; + } if ($iconfig) { $datarray['iconfig'] = $iconfig; @@ -1431,7 +1471,7 @@ class Item extends Controller $datarray['author'] = $observer; $datarray['attach'] = json_encode($datarray['attach']); $o = conversation(array($datarray), 'search', false, 'preview'); - // logger('preview: ' . $o, LOGGER_DEBUG); + // logger('preview: ' . $o, LOGGER_DEBUG); echo json_encode(array('preview' => $o)); killme(); } @@ -1448,8 +1488,8 @@ class Item extends Controller // some attribute besides the content, such as title or categories. if (PConfig::Get($profile_uid, 'system', 'suppress_duplicates', true) && (!$orig_post)) { - - $z = q("select created from item where uid = %d and created > %s - INTERVAL %s and body = '%s' limit 1", + $z = q( + "select created from item where uid = %d and created > %s - INTERVAL %s and body = '%s' limit 1", intval($profile_uid), db_utcnow(), db_quoteinterval('2 MINUTE'), @@ -1482,15 +1522,26 @@ class Item extends Controller } - if (mb_strlen($datarray['title']) > 191) + if (mb_strlen($datarray['title']) > 191) { $datarray['title'] = mb_substr($datarray['title'], 0, 191); + } if ($webpage) { - IConfig::Set($datarray, 'system', webpage_to_namespace($webpage), - (($pagetitle) ? $pagetitle : basename($datarray['mid'])), true); + IConfig::Set( + $datarray, + 'system', + webpage_to_namespace($webpage), + (($pagetitle) ? $pagetitle : basename($datarray['mid'])), + true + ); } elseif ($namespace) { - IConfig::Set($datarray, 'system', $namespace, - (($remote_id) ? $remote_id : basename($datarray['mid'])), true); + IConfig::Set( + $datarray, + 'system', + $namespace, + (($remote_id) ? $remote_id : basename($datarray['mid'])), + true + ); } if (intval($datarray['item_unpublished'])) { @@ -1502,7 +1553,8 @@ class Item extends Controller $x = item_store_update($datarray, $execflag); if (!$parent) { - $r = q("select * from item where id = %d", + $r = q( + "select * from item where id = %d", intval($post_id) ); if ($r) { @@ -1530,8 +1582,9 @@ class Item extends Controller goaway(z_root() . "/" . $return_path); } killme(); - } else + } else { $post_id = 0; + } $post = item_store($datarray, $execflag); @@ -1547,11 +1600,11 @@ class Item extends Controller logger('mod_item: saved item ' . $post_id); if ($parent) { - // prevent conversations which you are involved from being expired - if (local_channel()) + if (local_channel()) { retain_item($parent); + } // only send comment notification if this is a wall-to-wall comment and not a DM, // otherwise it will happen during delivery @@ -1568,7 +1621,6 @@ class Item extends Controller 'parent' => $parent, 'parent_mid' => $parent_item['mid'] )); - } } else { $parent = $post_id; @@ -1586,7 +1638,8 @@ class Item extends Controller } if ($uid && $uid == $profile_uid && (is_item_normal($datarray))) { - q("update channel set channel_lastpost = '%s' where channel_id = %d", + q( + "update channel set channel_lastpost = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($uid) ); @@ -1598,17 +1651,20 @@ class Item extends Controller // They will show up as people comment on them. if (intval($parent_item['item_hidden'])) { - $r = q("UPDATE item SET item_hidden = 0 WHERE id = %d", + $r = q( + "UPDATE item SET item_hidden = 0 WHERE id = %d", intval($parent_item['id']) ); } } else { logger('mod_item: unable to retrieve post that was just stored.'); notice(t('System error. Post not saved.') . EOL); - if ($return_path) + if ($return_path) { goaway(z_root() . "/" . $return_path); - if ($api_source) + } + if ($api_source) { return (['success' => false, 'message' => 'system error']); + } killme(); } @@ -1618,7 +1674,8 @@ class Item extends Controller //$ditem['author'] = $observer; //store_diaspora_comment_sig($ditem,$channel,$parent_item, $post_id, (($walltowall_comment) ? 1 : 0)); } else { - $r = q("select * from item where id = %d", + $r = q( + "select * from item where id = %d", intval($post_id) ); if ($r) { @@ -1648,8 +1705,9 @@ class Item extends Controller // figure out how to return, depending on from whence we came - if ($api_source) + if ($api_source) { return $post; + } if (intval($datarray['item_unpublished'])) { info($draft_msg); @@ -1660,8 +1718,9 @@ class Item extends Controller } $json = array('success' => 1); - if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) + if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) { $json['reload'] = z_root() . '/' . $_REQUEST['jsreload']; + } logger('post_json: ' . print_r($json, true), LOGGER_DEBUG); @@ -1680,8 +1739,9 @@ class Item extends Controller return; } - if ((!local_channel()) && (!remote_channel())) + if ((!local_channel()) && (!remote_channel())) { return; + } // allow pinned items to be dropped. 'pin-' was prepended to the id of these // items so that they would have a unique html id even if the pinned item @@ -1690,8 +1750,8 @@ class Item extends Controller $drop_id = str_replace('pin-', '', argv(2)); if ((argc() == 3) && (argv(1) === 'drop') && intval($drop_id)) { - - $i = q("select * from item where id = %d limit 1", + $i = q( + "select * from item where id = %d limit 1", intval($drop_id) ); @@ -1716,8 +1776,9 @@ class Item extends Controller if (is_site_admin()) { $local_delete = true; - if (intval($i[0]['item_origin'])) + if (intval($i[0]['item_origin'])) { $can_delete = true; + } } @@ -1728,13 +1789,15 @@ class Item extends Controller if ($i[0]['resource_type'] === 'event') { // delete and sync the event separately - $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", + $r = q( + "SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1", dbesc($i[0]['resource_id']), intval($i[0]['uid']) ); if ($r && $regular_delete) { $sync_event = $r[0]; - q("delete from event WHERE event_hash = '%s' AND uid = %d LIMIT 1", + q( + "delete from event WHERE event_hash = '%s' AND uid = %d LIMIT 1", dbesc($i[0]['resource_id']), intval($i[0]['uid']) ); @@ -1768,7 +1831,8 @@ class Item extends Controller $complex = true; } - $r = q("select * from item where id = %d", + $r = q( + "select * from item where id = %d", intval($i[0]['id']) ); if ($r) { @@ -1790,14 +1854,16 @@ class Item extends Controller $ret = array('success' => false, 'message' => ''); if ($iswebpage) { - $r = q("select count(i.id) as total from item i + $r = q( + "select count(i.id) as total from item i right join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id ) and i.parent=i.id and i.item_type = %d and i.item_deleted = 0 and i.uid= %d ", intval(ITEM_TYPE_WEBPAGE), intval($channel_id) ); } else { - $r = q("select count(id) as total from item where parent = id and item_wall = 1 and uid = %d " . item_normal(), + $r = q( + "select count(id) as total from item where parent = id and item_wall = 1 and uid = %d " . item_normal(), intval($channel_id) ); } @@ -1880,7 +1946,6 @@ class Item extends Controller } return $obj; - } public function extract_poll_data($poll, $item) @@ -1898,8 +1963,9 @@ class Item extends Controller $obj['content'] = bbcode($question); foreach ($answers as $answer) { - if (trim($answer)) + if (trim($answer)) { $ptr[] = ['name' => escape_tags($answer), 'type' => 'Note', 'replies' => ['type' => 'Collection', 'totalItems' => 0]]; + } } if ($multiple) { @@ -1917,7 +1983,5 @@ class Item extends Controller } return $obj; - } - } diff --git a/Zotlabs/Module/Jwks.php b/Zotlabs/Module/Jwks.php index 8bb6de47b..3e0dd544f 100644 --- a/Zotlabs/Module/Jwks.php +++ b/Zotlabs/Module/Jwks.php @@ -58,6 +58,5 @@ class Jwks extends Controller } json_return_and_die($ret, 'application/jwk-set+json'); - } -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Lang.php b/Zotlabs/Module/Lang.php index 46034a5ff..53f7081af 100644 --- a/Zotlabs/Module/Lang.php +++ b/Zotlabs/Module/Lang.php @@ -1,4 +1,5 @@ 1) + if (argc() > 1) { $which = argv(1); - else + } else { return; + } Libprofile::load($which); - } public function get() @@ -64,7 +63,8 @@ class Layouts extends Controller if (!$owner) { // Figure out who the page owner is. - $r = q("select channel_id from channel where channel_address = '%s'", + $r = q( + "select channel_id from channel where channel_address = '%s'", dbesc($which) ); if ($r) { @@ -104,7 +104,8 @@ class Layouts extends Controller // Use the buildin share/install feature instead. if ((argc() > 3) && (argv(2) === 'share') && (argv(3))) { - $r = q("select iconfig.v, iconfig.k, mimetype, title, body from iconfig + $r = q( + "select iconfig.v, iconfig.k, mimetype, title, body from iconfig left join item on item.id = iconfig.iid where uid = %d and mid = '%s' and iconfig.cat = 'system' and iconfig.k = 'PDL' order by iconfig.v asc", intval($owner), @@ -143,16 +144,20 @@ class Layouts extends Controller 'bbco_autocomplete' => 'comanche' ); - if ($_REQUEST['title']) + if ($_REQUEST['title']) { $x['title'] = $_REQUEST['title']; - if ($_REQUEST['body']) + } + if ($_REQUEST['body']) { $x['body'] = $_REQUEST['body']; - if ($_REQUEST['pagetitle']) + } + if ($_REQUEST['pagetitle']) { $x['pagetitle'] = $_REQUEST['pagetitle']; + } $editor = status_editor($x); - $r = q("select iconfig.iid, iconfig.v, mid, title, body, mimetype, created, edited, item_type from iconfig + $r = q( + "select iconfig.iid, iconfig.v, mid, title, body, mimetype, created, edited, item_type from iconfig left join item on iconfig.iid = item.id where uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d order by item.created desc", intval($owner), @@ -208,7 +213,5 @@ class Layouts extends Controller )); return $o; - } - } diff --git a/Zotlabs/Module/Like.php b/Zotlabs/Module/Like.php index 5954040b3..df0758568 100644 --- a/Zotlabs/Module/Like.php +++ b/Zotlabs/Module/Like.php @@ -1,4 +1,5 @@ 1 && $test[0] === 'Undo') { - $undo = true; - $activity = $test[1]; - } + $activity = ((array_key_exists('verb', $_GET)) ? notags(trim($_GET['verb'])) : EMPTY_STR); - if (! in_array($activity, [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept' ])) { - killme(); - } + if (! $activity) { + return EMPTY_STR; + } - $is_rsvp = in_array($activity, [ 'Accept', 'Reject', 'TentativeAccept' ]); + // Check for negative (undo) condition + // eg: 'Undo/Like' results in $undo conditional and $activity set to 'Like' - // Check for when target is something besides messages, where argv(1) is the type of thing - // and argv(2) is an identifier of things of that type - // We currently only recognise 'profile' but other types could be handled - - - if (! $observer) { - killme(); - } + $test = explode('/', $activity); + if (count($test) > 1 && $test[0] === 'Undo') { + $undo = true; + $activity = $test[1]; + } - // this is used to like an item or comment - - $item_id = ((argc() == 2) ? notags(trim(argv(1))) : 0); + if (! in_array($activity, [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept' ])) { + killme(); + } - logger('like: undo: ' . (($undo) ? 'true' : 'false')); - logger('like: verb ' . $activity . ' item ' . $item_id, LOGGER_DEBUG); - - // get the item. Allow linked photos (which are normally hidden) to be liked + $is_rsvp = in_array($activity, [ 'Accept', 'Reject', 'TentativeAccept' ]); - $r = q("SELECT * FROM item WHERE id = %d + // Check for when target is something besides messages, where argv(1) is the type of thing + // and argv(2) is an identifier of things of that type + // We currently only recognise 'profile' but other types could be handled + + + if (! $observer) { + killme(); + } + + // this is used to like an item or comment + + $item_id = ((argc() == 2) ? notags(trim(argv(1))) : 0); + + logger('like: undo: ' . (($undo) ? 'true' : 'false')); + logger('like: verb ' . $activity . ' item ' . $item_id, LOGGER_DEBUG); + + // get the item. Allow linked photos (which are normally hidden) to be liked + + $r = q( + "SELECT * FROM item WHERE id = %d and item_type in (0,6,7) and item_deleted = 0 and item_unpublished = 0 and item_delayed = 0 and item_pending_remove = 0 and item_blocked = 0 LIMIT 1", - intval($item_id) - ); + intval($item_id) + ); - // if interacting with a pubstream item, - // create a copy of the parent in your stream. + // if interacting with a pubstream item, + // create a copy of the parent in your stream. - if ($r) { - if (local_channel() && (! is_sys_channel(local_channel()))) { - $r = [ copy_of_pubitem(App::get_channel(), $r[0]['mid']) ]; - } - } + if ($r) { + if (local_channel() && (! is_sys_channel(local_channel()))) { + $r = [ copy_of_pubitem(App::get_channel(), $r[0]['mid']) ]; + } + } - if(! $item_id || (! $r)) { - logger('like: no item ' . $item_id); - killme(); - } + if (! $item_id || (! $r)) { + logger('like: no item ' . $item_id); + killme(); + } - xchan_query($r,true); + xchan_query($r, true); - $item = array_shift($r); + $item = array_shift($r); - $owner_uid = $item['uid']; - $owner_aid = $item['aid']; + $owner_uid = $item['uid']; + $owner_aid = $item['aid']; $can_comment = false; - if ((array_key_exists('owner',$item)) && intval($item['owner']['abook_self'])) { - $can_comment = perm_is_allowed($item['uid'],$observer['xchan_hash'],'post_comments'); - } - else { - $can_comment = can_comment_on_post($observer['xchan_hash'],$item); - } + if ((array_key_exists('owner', $item)) && intval($item['owner']['abook_self'])) { + $can_comment = perm_is_allowed($item['uid'], $observer['xchan_hash'], 'post_comments'); + } else { + $can_comment = can_comment_on_post($observer['xchan_hash'], $item); + } - if (! $can_comment) { - notice( t('Permission denied') . EOL); - killme(); - } + if (! $can_comment) { + notice(t('Permission denied') . EOL); + killme(); + } - $r = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($item['owner_xchan']) - ); + $r = q( + "select * from xchan where xchan_hash = '%s' limit 1", + dbesc($item['owner_xchan']) + ); - if ($r) { - $thread_owner = array_shift($r); - } - else { - killme(); - } - $r = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($item['author_xchan']) - ); - if ($r) { - $item_author = array_shift($r); - } - else { - killme(); - } + if ($r) { + $thread_owner = array_shift($r); + } else { + killme(); + } + $r = q( + "select * from xchan where xchan_hash = '%s' limit 1", + dbesc($item['author_xchan']) + ); + if ($r) { + $item_author = array_shift($r); + } else { + killme(); + } - if ($undo) { - $r = q("select * from item where thr_parent = '%s' and verb = '%s' and author_xchan = '%s' and uid = %d and item_deleted = 0 limit 1", - dbesc($item['thr_parent']), - dbesc($activity), - dbesc($observer['xchan_hash']), - intval($owner_uid) - ); + if ($undo) { + $r = q( + "select * from item where thr_parent = '%s' and verb = '%s' and author_xchan = '%s' and uid = %d and item_deleted = 0 limit 1", + dbesc($item['thr_parent']), + dbesc($activity), + dbesc($observer['xchan_hash']), + intval($owner_uid) + ); - xchan_query($r,true); - $r = fetch_post_tags($r,true); - $r[0]['obj'] = json_decode($r[0]['obj'],true); - $object = Activity::encode_activity($r[0],true); - - // do not do either a federated or hard delete on the original reaction - // as we are going to send an Undo to perform this task - // just set item_deleted to update the local conversation + xchan_query($r, true); + $r = fetch_post_tags($r, true); + $r[0]['obj'] = json_decode($r[0]['obj'], true); + $object = Activity::encode_activity($r[0], true); - $retval = q("update item set item_deleted = 1 where id = %d", - intval($r[0]['id']) - ); + // do not do either a federated or hard delete on the original reaction + // as we are going to send an Undo to perform this task + // just set item_deleted to update the local conversation - } - else { - $object = Activity::fetch_item( [ 'id' => $item['mid'] ]); - } + $retval = q( + "update item set item_deleted = 1 where id = %d", + intval($r[0]['id']) + ); + } else { + $object = Activity::fetch_item([ 'id' => $item['mid'] ]); + } - if (! $object) { - killme(); - } + if (! $object) { + killme(); + } - $uuid = new_uuid(); + $uuid = new_uuid(); - // we have everything we need - start building our new item + // we have everything we need - start building our new item - $arr = []; + $arr = []; - $arr['uuid'] = $uuid; + $arr['uuid'] = $uuid; $arr['mid'] = z_root() . (($is_rsvp) ? '/activity/' : '/item/' ) . $uuid; - $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); - if ($item['obj_type'] === ACTIVITY_OBJ_EVENT) { - $post_type = t('event'); - } - - $objtype = $item['obj_type']; + $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); + if ($item['obj_type'] === ACTIVITY_OBJ_EVENT) { + $post_type = t('event'); + } - $body = $item['body']; - - - if (! intval($item['item_thread_top'])) { - $post_type = 'comment'; - } - - $arr['item_origin'] = 1; - $arr['item_notshown'] = 1; - $arr['item_type'] = $item['item_type']; - - if (intval($item['item_wall'])) { - $arr['item_wall'] = 1; - } - - // if this was a linked photo and was hidden, unhide it and distribute it. - - if (intval($item['item_hidden'])) { - $r = q("update item set item_hidden = 0 where id = %d", - intval($item['id']) - ); + $objtype = $item['obj_type']; - $r = q("select * from item where id = %d", - intval($item['id']) - ); - if ($r) { - xchan_query($r); - $sync_item = fetch_post_tags($r); - Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0],true) ] ]); - } - - Run::Summon( [ 'Notifier','wall-new',$item['id'] ] ); - } + $body = $item['body']; - if ($undo) { - $arr['body'] = t('Undo a previous action'); - $arr['item_notshown'] = 1; - } - else { - if ($activity === 'Like') { - $bodyverb = t('%1$s likes %2$s\'s %3$s'); - } - if ($activity === 'Dislike') { - $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); - } - if ($activity === 'Accept') { - $bodyverb = t('%1$s is attending %2$s\'s %3$s'); - } - if ($activity === 'Reject') { - $bodyverb = t('%1$s is not attending %2$s\'s %3$s'); - } - if ($activity === 'TentativeAccept') { - $bodyverb = t('%1$s may attend %2$s\'s %3$s'); - } - - if (! isset($bodyverb)) { - killme(); - } + if (! intval($item['item_thread_top'])) { + $post_type = 'comment'; + } - $ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]'; - $alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]'; - $plink = '[zrl=' . z_root() . '/display/' . gen_link_id($item['mid']) . ']' . $post_type . '[/zrl]'; + $arr['item_origin'] = 1; + $arr['item_notshown'] = 1; + $arr['item_type'] = $item['item_type']; - $arr['body'] = sprintf( $bodyverb, $alink, $ulink, $plink ); + if (intval($item['item_wall'])) { + $arr['item_wall'] = 1; + } - } + // if this was a linked photo and was hidden, unhide it and distribute it. + + if (intval($item['item_hidden'])) { + $r = q( + "update item set item_hidden = 0 where id = %d", + intval($item['id']) + ); + + $r = q( + "select * from item where id = %d", + intval($item['id']) + ); + if ($r) { + xchan_query($r); + $sync_item = fetch_post_tags($r); + Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0], true) ] ]); + } + + Run::Summon([ 'Notifier','wall-new',$item['id'] ]); + } - if (local_channel() && $activity === 'Accept') { - event_addtocal($item['id'],$channel['channel_id']); - } - - $arr['parent'] = $item['id']; - $arr['thr_parent'] = $item['mid']; - $allow_cid = $item['allow_cid']; - $allow_gid = $item['allow_gid']; - $deny_cid = $item['deny_cid']; - $deny_gid = $item['deny_gid']; - $private = $item['private']; - - $arr['aid'] = $owner_aid; - $arr['uid'] = $owner_uid; + if ($undo) { + $arr['body'] = t('Undo a previous action'); + $arr['item_notshown'] = 1; + } else { + if ($activity === 'Like') { + $bodyverb = t('%1$s likes %2$s\'s %3$s'); + } + if ($activity === 'Dislike') { + $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); + } + if ($activity === 'Accept') { + $bodyverb = t('%1$s is attending %2$s\'s %3$s'); + } + if ($activity === 'Reject') { + $bodyverb = t('%1$s is not attending %2$s\'s %3$s'); + } + if ($activity === 'TentativeAccept') { + $bodyverb = t('%1$s may attend %2$s\'s %3$s'); + } - $arr['item_flags'] = $item['item_flags']; - $arr['item_wall'] = $item['item_wall']; - $arr['parent_mid'] = $item['mid']; - $arr['owner_xchan'] = $thread_owner['xchan_hash']; - $arr['author_xchan'] = $observer['xchan_hash']; - - - - $arr['verb'] = (($undo) ? 'Undo' : $activity); - $arr['obj_type'] = (($undo) ? $activity : $objtype); - $arr['obj'] = $object; - - if ($target) { - $arr['tgt_type'] = $tgttype; - $arr['target'] = $target; - } - - $arr['allow_cid'] = $allow_cid; - $arr['allow_gid'] = $allow_gid; - $arr['deny_cid'] = $deny_cid; - $arr['deny_gid'] = $deny_gid; - $arr['item_private'] = $private; - - call_hooks('post_local',$arr); - - $post = item_store($arr); - $post_id = $post['item_id']; + if (! isset($bodyverb)) { + killme(); + } - // save the conversation from expiration + $ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]'; + $alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]'; + $plink = '[zrl=' . z_root() . '/display/' . gen_link_id($item['mid']) . ']' . $post_type . '[/zrl]'; - if (local_channel() && array_key_exists('item',$post) && (intval($post['item']['id']) != intval($post['item']['parent']))) { - retain_item($post['item']['parent']); - } - - $arr['id'] = $post_id; - - call_hooks('post_local_end', $arr); - - $r = q("select * from item where id = %d", - intval($post_id) - ); - if ($r) { - xchan_query($r); - $sync_item = fetch_post_tags($r); - Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0],true) ] ]); - } + $arr['body'] = sprintf($bodyverb, $alink, $ulink, $plink); + } - Run::Summon( [ 'Notifier', 'like', $post_id ] ); - - killme(); - } - - - + + if (local_channel() && $activity === 'Accept') { + event_addtocal($item['id'], $channel['channel_id']); + } + + $arr['parent'] = $item['id']; + $arr['thr_parent'] = $item['mid']; + $allow_cid = $item['allow_cid']; + $allow_gid = $item['allow_gid']; + $deny_cid = $item['deny_cid']; + $deny_gid = $item['deny_gid']; + $private = $item['private']; + + $arr['aid'] = $owner_aid; + $arr['uid'] = $owner_uid; + + $arr['item_flags'] = $item['item_flags']; + $arr['item_wall'] = $item['item_wall']; + $arr['parent_mid'] = $item['mid']; + $arr['owner_xchan'] = $thread_owner['xchan_hash']; + $arr['author_xchan'] = $observer['xchan_hash']; + + + + $arr['verb'] = (($undo) ? 'Undo' : $activity); + $arr['obj_type'] = (($undo) ? $activity : $objtype); + $arr['obj'] = $object; + + if ($target) { + $arr['tgt_type'] = $tgttype; + $arr['target'] = $target; + } + + $arr['allow_cid'] = $allow_cid; + $arr['allow_gid'] = $allow_gid; + $arr['deny_cid'] = $deny_cid; + $arr['deny_gid'] = $deny_gid; + $arr['item_private'] = $private; + + call_hooks('post_local', $arr); + + $post = item_store($arr); + $post_id = $post['item_id']; + + // save the conversation from expiration + + if (local_channel() && array_key_exists('item', $post) && (intval($post['item']['id']) != intval($post['item']['parent']))) { + retain_item($post['item']['parent']); + } + + $arr['id'] = $post_id; + + call_hooks('post_local_end', $arr); + + $r = q( + "select * from item where id = %d", + intval($post_id) + ); + if ($r) { + xchan_query($r); + $sync_item = fetch_post_tags($r); + Libsync::build_sync_packet($channel['channel_id'], [ 'item' => [ encode_item($sync_item[0], true) ] ]); + } + + Run::Summon([ 'Notifier', 'like', $post_id ]); + + killme(); + } } diff --git a/Zotlabs/Module/Linkinfo.php b/Zotlabs/Module/Linkinfo.php index 1eb537089..9df5300f0 100644 --- a/Zotlabs/Module/Linkinfo.php +++ b/Zotlabs/Module/Linkinfo.php @@ -1,4 +1,5 @@ is_valid() && $y->type === 'Announce' && is_array($y->obj) - && array_key_exists('object', $y->obj) && array_key_exists('actor', $y->obj)) { + if ( + $y->is_valid() && $y->type === 'Announce' && is_array($y->obj) + && array_key_exists('object', $y->obj) && array_key_exists('actor', $y->obj) + ) { // This is a relayed/forwarded Activity (as opposed to a shared/boosted object) // Reparse the encapsulated Activity and use that instead logger('relayed activity', LOGGER_DEBUG); @@ -223,7 +235,8 @@ class Linkinfo extends Controller if ($y && $y->is_valid()) { $z = Activity::decode_note($y); - $r = q("select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_hash = '%s' OR hubloc_id_url = '%s'", + $r = q( + "select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_hash = '%s' OR hubloc_id_url = '%s'", dbesc(is_array($y->actor) ? $y->actor['id'] : $y->actor), dbesc(is_array($y->actor) ? $y->actor['id'] : $y->actor) ); @@ -236,7 +249,6 @@ class Linkinfo extends Controller } if ($z) { - // do not allow somebody to embed a post that was blocked by the site admin // We *will* let them over-rule any blocks they created themselves @@ -252,7 +264,6 @@ class Linkinfo extends Controller if ($url && $title && $text) { - $text = $br . '[quote]' . trim($text) . '[/quote]' . $br; $title = str_replace(array("\r", "\n"), array('', ''), $title); @@ -269,8 +280,9 @@ class Linkinfo extends Controller // If the site uses this platform, use zrl rather than url so they get zids sent to them by default - if (is_matrix_url($url)) + if (is_matrix_url($url)) { $template = str_replace('url', 'zrl', $template); + } if ($siteinfo["title"] == "") { echo sprintf($template, $url, $url, '') . $str_tags; @@ -287,10 +299,11 @@ class Linkinfo extends Controller $total_images = 0; $max_images = get_config('system', 'max_bookmark_images'); - if ($max_images === false) + if ($max_images === false) { $max_images = 2; - else + } else { $max_images = intval($max_images); + } foreach ($siteinfo["images"] as $imagedata) { if ($url) { @@ -302,8 +315,9 @@ class Linkinfo extends Controller } $image .= "\n"; $total_images++; - if ($max_images && $max_images >= $total_images) + if ($max_images && $max_images >= $total_images) { break; + } } } @@ -322,7 +336,6 @@ class Linkinfo extends Controller echo trim($result); killme(); - } @@ -330,34 +343,40 @@ class Linkinfo extends Controller { $xpath = new DomXPath($doc); $list = $xpath->query("//" . $node); - foreach ($list as $child) + foreach ($list as $child) { $child->parentNode->removeChild($child); + } } public static function completeurl($url, $scheme) { $urlarr = parse_url($url); - if (isset($urlarr["scheme"])) + if (isset($urlarr["scheme"])) { return ($url); + } $schemearr = parse_url($scheme); $complete = $schemearr["scheme"] . "://" . $schemearr["host"]; - if ($schemearr["port"] != "") + if ($schemearr["port"] != "") { $complete .= ":" . $schemearr["port"]; + } - if (strpos($urlarr['path'], '/') !== 0) + if (strpos($urlarr['path'], '/') !== 0) { $complete .= '/'; + } $complete .= $urlarr["path"]; - if ($urlarr["query"] != "") + if ($urlarr["query"] != "") { $complete .= "?" . $urlarr["query"]; + } - if ($urlarr["fragment"] != "") + if ($urlarr["fragment"] != "") { $complete .= "#" . $urlarr["fragment"]; + } return ($complete); } @@ -381,10 +400,10 @@ class Linkinfo extends Controller $u = channelx_by_nick($nick); if ($u && $p) { - $sql_extra = permissions_sql(intval($u['channel_id'])); - $r = q("select hash, content from attach where display_path = '%s' and uid = %d and os_storage = 1 $sql_extra limit 1", + $r = q( + "select hash, content from attach where display_path = '%s' and uid = %d and os_storage = 1 $sql_extra limit 1", dbesc($p), intval($u['channel_id']) ); @@ -405,16 +424,18 @@ class Linkinfo extends Controller $result = z_fetch_url($url, false, 0, array('novalidate' => true)); - if (!$result['success']) + if (!$result['success']) { return $siteinfo; + } $header = $result['header']; $body = $result['body']; // Check codepage in HTTP headers or HTML if not exist $cp = (preg_match('/Content-Type: text\/html; charset=(.+)\r\n/i', $header, $o) ? $o[1] : ''); - if (empty($cp)) + if (empty($cp)) { $cp = (preg_match('/meta.+content=["|\']text\/html; charset=([^"|\']+)/i', $body, $o) ? $o[1] : 'AUTO'); + } $body = mb_convert_encoding($body, 'UTF-8', $cp); $body = mb_convert_encoding($body, 'HTML-ENTITIES', "UTF-8"); @@ -438,16 +459,19 @@ class Linkinfo extends Controller //$list = $xpath->query("head/title"); $list = $xpath->query("//title"); - foreach ($list as $node) + foreach ($list as $node) { $siteinfo["title"] = html_entity_decode($node->nodeValue, ENT_QUOTES, "UTF-8"); + } //$list = $xpath->query("head/meta[@name]"); $list = $xpath->query("//meta[@name]"); foreach ($list as $node) { $attr = []; - if ($node->attributes->length) - foreach ($node->attributes as $attribute) + if ($node->attributes->length) { + foreach ($node->attributes as $attribute) { $attr[$attribute->name] = $attribute->value; + } + } $attr["content"] = html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"); @@ -497,9 +521,11 @@ class Linkinfo extends Controller $list = $xpath->query("//meta[@property]"); foreach ($list as $node) { $attr = []; - if ($node->attributes->length) - foreach ($node->attributes as $attribute) + if ($node->attributes->length) { + foreach ($node->attributes as $attribute) { $attr[$attribute->name] = $attribute->value; + } + } $attr["content"] = html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"); @@ -520,9 +546,11 @@ class Linkinfo extends Controller $list = $xpath->query("//img[@src]"); foreach ($list as $node) { $attr = []; - if ($node->attributes->length) - foreach ($node->attributes as $attribute) + if ($node->attributes->length) { + foreach ($node->attributes as $attribute) { $attr[$attribute->name] = $attribute->value; + } + } $src = self::completeurl($attr["src"], $url); $photodata = @getimagesize($src); @@ -540,7 +568,6 @@ class Linkinfo extends Controller "width" => $photodata[0], "height" => $photodata[1]); } - } } else { $src = self::completeurl($siteinfo["image"], $url); @@ -549,40 +576,48 @@ class Linkinfo extends Controller $photodata = @getimagesize($src); - if (($photodata) && ($photodata[0] > 10) and ($photodata[1] > 10)) + if (($photodata) && ($photodata[0] > 10) and ($photodata[1] > 10)) { $siteinfo["images"][] = array("src" => $src, "width" => $photodata[0], "height" => $photodata[1]); + } } if ($siteinfo["text"] == "") { $text = ""; $list = $xpath->query("//div[@class='article']"); - foreach ($list as $node) - if (strlen($node->nodeValue) > 40) + foreach ($list as $node) { + if (strlen($node->nodeValue) > 40) { $text .= " " . trim($node->nodeValue); + } + } if ($text == "") { $list = $xpath->query("//div[@class='content']"); - foreach ($list as $node) - if (strlen($node->nodeValue) > 40) + foreach ($list as $node) { + if (strlen($node->nodeValue) > 40) { $text .= " " . trim($node->nodeValue); + } + } } // If none text was found then take the paragraph content if ($text == "") { $list = $xpath->query("//p"); - foreach ($list as $node) - if (strlen($node->nodeValue) > 40) + foreach ($list as $node) { + if (strlen($node->nodeValue) > 40) { $text .= " " . trim($node->nodeValue); + } + } } if ($text != "") { $text = trim(str_replace(array("\n", "\r"), array(" ", " "), $text)); - while (strpos($text, " ")) + while (strpos($text, " ")) { $text = trim(str_replace(" ", " ", $text)); + } $siteinfo["text"] = html_entity_decode(substr($text, 0, 350), ENT_QUOTES, "UTF-8") . '...'; } @@ -598,5 +633,4 @@ class Linkinfo extends Controller $item = '#' . $item; } } - } diff --git a/Zotlabs/Module/Lists.php b/Zotlabs/Module/Lists.php index 1b5210087..a71373b50 100644 --- a/Zotlabs/Module/Lists.php +++ b/Zotlabs/Module/Lists.php @@ -1,4 +1,5 @@ 2 && argv(1) === 'view') { $grp = argv(2); if ($grp) { - $r = q("select * from pgrp where hash = '%s' and deleted = 0", + $r = q( + "select * from pgrp where hash = '%s' and deleted = 0", dbesc($grp) ); if ($r) { @@ -206,10 +209,10 @@ class Lists extends Controller $switchtotext = get_pconfig(local_channel(), 'system', 'listedit_image_limit', get_config('system', 'listedit_image_limit', 1000)); if ((argc() == 1) || ((argc() == 2) && (argv(1) === 'new'))) { - $new = (((argc() == 2) && (argv(1) === 'new')) ? true : false); - $groups = q("SELECT id, gname FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC", + $groups = q( + "SELECT id, gname FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC", intval(local_channel()) ); @@ -241,7 +244,6 @@ class Lists extends Controller ]); return $o; - } $context = array('$submit' => t('Submit')); @@ -251,16 +253,19 @@ class Lists extends Controller check_form_security_token_redirectOnErr('/lists', 'group_drop', 't'); if (intval(argv(2))) { - $r = q("SELECT gname FROM pgrp WHERE id = %d AND uid = %d LIMIT 1", + $r = q( + "SELECT gname FROM pgrp WHERE id = %d AND uid = %d LIMIT 1", intval(argv(2)), intval(local_channel()) ); - if ($r) + if ($r) { $result = AccessList::remove(local_channel(), $r[0]['gname']); - if ($result) + } + if ($result) { info(t('Access list removed.') . EOL); - else + } else { notice(t('Unable to remove access list.') . EOL); + } } goaway(z_root() . '/lists'); // NOTREACHED @@ -268,38 +273,40 @@ class Lists extends Controller if ((argc() > 2) && intval(argv(1)) && argv(2)) { - check_form_security_token_ForbiddenOnErr('group_member_change', 't'); - $r = q("SELECT abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 limit 1", + $r = q( + "SELECT abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 limit 1", dbesc(base64url_decode(argv(2))), intval(local_channel()) ); - if (count($r)) + if (count($r)) { $change = base64url_decode(argv(2)); - + } } if (argc() > 1) { - require_once('include/acl_selectors.php'); if (strlen(argv(1)) <= 11 && intval(argv(1))) { - $r = q("SELECT * FROM pgrp WHERE id = %d AND uid = %d AND deleted = 0 LIMIT 1", + $r = q( + "SELECT * FROM pgrp WHERE id = %d AND uid = %d AND deleted = 0 LIMIT 1", intval(argv(1)), intval(local_channel()) ); } else { - $r = q("SELECT * FROM pgrp WHERE hash = '%s' AND uid = %d AND deleted = 0 LIMIT 1", + $r = q( + "SELECT * FROM pgrp WHERE hash = '%s' AND uid = %d AND deleted = 0 LIMIT 1", dbesc(argv(1)), intval(local_channel()) ); } if (!$r) { - $r = q("SELECT * FROM pgrp WHERE id = %d AND deleted = 0 LIMIT 1", + $r = q( + "SELECT * FROM pgrp WHERE id = %d AND deleted = 0 LIMIT 1", intval(argv(1)), - ); + ); if ($r) { notice(t('Permission denied.') . EOL); } else { @@ -313,13 +320,14 @@ class Lists extends Controller $preselected = []; if (count($members)) { - foreach ($members as $member) - if (!in_array($member['xchan_hash'], $preselected)) + foreach ($members as $member) { + if (!in_array($member['xchan_hash'], $preselected)) { $preselected[] = $member['xchan_hash']; + } + } } if ($change) { - if (in_array($change, $preselected)) { AccessList::member_remove(local_channel(), $group['gname'], $change); } else { @@ -330,8 +338,9 @@ class Lists extends Controller $preselected = []; if (count($members)) { - foreach ($members as $member) + foreach ($members as $member) { $preselected[] = $member['xchan_hash']; + } } } @@ -346,11 +355,11 @@ class Lists extends Controller '$delete' => t('Delete access list'), '$form_security_token_drop' => get_form_security_token("group_drop"), ); - } - if (!isset($group)) + if (!isset($group)) { return; + } $groupeditor = array( 'label_members' => t('List members'), @@ -366,11 +375,13 @@ class Lists extends Controller $member['archived'] = (intval($member['abook_archived']) ? true : false); $member['click'] = 'groupChangeMember(' . $group['id'] . ',\'' . base64url_encode($member['xchan_hash']) . '\',\'' . $sec_token . '\'); return false;'; $groupeditor['members'][] = micropro($member, true, 'mpgroup', $textmode); - } else + } else { AccessList::member_remove(local_channel(), $group['gname'], $member['xchan_hash']); + } } - $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_self = 0 and abook_blocked = 0 and abook_pending = 0 and xchan_deleted = 0 order by xchan_name asc", + $r = q( + "SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_self = 0 and abook_blocked = 0 and abook_pending = 0 and xchan_deleted = 0 order by xchan_name asc", intval(local_channel()) ); @@ -395,8 +406,5 @@ class Lists extends Controller } return replace_macros($tpl, $context); - } - - } diff --git a/Zotlabs/Module/Lockview.php b/Zotlabs/Module/Lockview.php index 3e9056f94..6bb6bce31 100644 --- a/Zotlabs/Module/Lockview.php +++ b/Zotlabs/Module/Lockview.php @@ -1,4 +1,5 @@ 2) ? intval(argv(2)) : 0); } - if (!$item_id) + if (!$item_id) { killme(); + } - if (!in_array($type, array('item', 'photo', 'attach', 'event', 'menu_item', 'chatroom'))) + if (!in_array($type, array('item', 'photo', 'attach', 'event', 'menu_item', 'chatroom'))) { killme(); + } // we have different naming in in menu_item table and chatroom table switch ($type) { @@ -51,13 +55,15 @@ class Lockview extends Controller break; } - $r = q("SELECT * FROM %s WHERE $id = %d LIMIT 1", + $r = q( + "SELECT * FROM %s WHERE $id = %d LIMIT 1", dbesc($type), intval($item_id) ); - if (!$r) + if (!$r) { killme(); + } $item = $r[0]; @@ -102,9 +108,10 @@ class Lockview extends Controller } - if (intval($item['item_private']) && (!strlen($item['allow_cid'])) && (!strlen($item['allow_gid'])) - && (!strlen($item['deny_cid'])) && (!strlen($item['deny_gid']))) { - + if ( + intval($item['item_private']) && (!strlen($item['allow_cid'])) && (!strlen($item['allow_gid'])) + && (!strlen($item['deny_cid'])) && (!strlen($item['deny_gid'])) + ) { if ($item['mid'] === $item['parent_mid']) { echo '' . translate_scope('specific') . ''; killme(); @@ -127,15 +134,19 @@ class Lockview extends Controller if (count($allowed_groups)) { $r = q("SELECT gname FROM pgrp WHERE hash IN ( " . implode(', ', $allowed_groups) . " )"); - if ($r) - foreach ($r as $rr) + if ($r) { + foreach ($r as $rr) { $l[] = '' . $rr['gname'] . ''; + } + } } if (count($allowed_users)) { $r = q("SELECT xchan_name FROM xchan WHERE xchan_hash IN ( " . implode(', ', $allowed_users) . " )"); - if ($r) - foreach ($r as $rr) + if ($r) { + foreach ($r as $rr) { $l[] = '' . $rr['xchan_name'] . ''; + } + } if ($atokens) { foreach ($atokens as $at) { if (in_array("'" . $at['xchan_hash'] . "'", $allowed_users)) { @@ -147,15 +158,19 @@ class Lockview extends Controller if (count($deny_groups)) { $r = q("SELECT gname FROM pgrp WHERE hash IN ( " . implode(', ', $deny_groups) . " )"); - if ($r) - foreach ($r as $rr) + if ($r) { + foreach ($r as $rr) { $l[] = ''; + } + } } if (count($deny_users)) { $r = q("SELECT xchan_name FROM xchan WHERE xchan_hash IN ( " . implode(', ', $deny_users) . " )"); - if ($r) - foreach ($r as $rr) + if ($r) { + foreach ($r as $rr) { $l[] = '' . $rr['gname'] . ''; + } + } if ($atokens) { foreach ($atokens as $at) { @@ -164,14 +179,9 @@ class Lockview extends Controller } } } - - } echo $o . implode($l); killme(); - - } - } diff --git a/Zotlabs/Module/Locs.php b/Zotlabs/Module/Locs.php index 23a2211f0..b95d8ad46 100644 --- a/Zotlabs/Module/Locs.php +++ b/Zotlabs/Module/Locs.php @@ -1,27 +1,28 @@ nuke(); } goaway(z_root()); - } } diff --git a/Zotlabs/Module/Lostpass.php b/Zotlabs/Module/Lostpass.php index 372a9a7a1..b274372e2 100644 --- a/Zotlabs/Module/Lostpass.php +++ b/Zotlabs/Module/Lostpass.php @@ -1,8 +1,7 @@ sprintf(t('Site Member (%s)'), $email), '$email' => $email, '$new_password' => $new_password, - '$uid' => $newuid) - ); + '$uid' => $newuid)); $res = z_mail( [ @@ -127,7 +131,6 @@ class Lostpass extends Controller return $o; } - } else { $tpl = get_markup_template('lostpass.tpl'); @@ -140,7 +143,5 @@ class Lostpass extends Controller return $o; } - } - } diff --git a/Zotlabs/Module/Magic.php b/Zotlabs/Module/Magic.php index 99d8a4ca7..6cc5e6e72 100644 --- a/Zotlabs/Module/Magic.php +++ b/Zotlabs/Module/Magic.php @@ -1,6 +1,6 @@ 2) { if (argv(2) === 'default') { - $r = q("select channel_id from channel where channel_id = %d and channel_account_id = %d limit 1", + $r = q( + "select channel_id from channel where channel_id = %d and channel_account_id = %d limit 1", intval($change_channel), intval(get_account_id()) ); if ($r) { - q("update account set account_default_channel = %d where account_id = %d", + q( + "update account set account_default_channel = %d where account_id = %d", intval($change_channel), intval(get_account_id()) ); @@ -41,12 +44,10 @@ class Manage extends Controller PConfig::set($change_channel, 'system', 'include_in_menu', 1 - $state); goaway(z_root() . '/manage'); } - } if ($change_channel) { - $r = change_channel($change_channel); if ((argc() > 2) && !(argv(2) === 'default')) { @@ -59,14 +60,14 @@ class Manage extends Controller $channels = null; - $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and channel_removed = 0 order by channel_name ", + $r = q( + "select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and channel_removed = 0 order by channel_name ", intval(get_account_id()) ); $account = App::get_account(); if ($r && count($r)) { - $channels = ((is_site_admin()) ? array_merge([get_sys_channel()], $r) : $r); for ($x = 0; $x < count($channels); $x++) { $channels[$x]['link'] = 'manage/' . intval($channels[$x]['channel_id']); @@ -76,7 +77,8 @@ class Manage extends Controller $channels[$x]['collections_label'] = t('Collection'); $channels[$x]['forum_label'] = t('Group'); - $c = q("SELECT id, item_wall FROM item + $c = q( + "SELECT id, item_wall FROM item WHERE item_unseen = 1 and uid = %d " . item_normal(), intval($channels[$x]['channel_id']) ); @@ -92,7 +94,8 @@ class Manage extends Controller } - $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", + $intr = q( + "SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", intval($channels[$x]['channel_id']) ); @@ -100,7 +103,8 @@ class Manage extends Controller $channels[$x]['intros'] = intval($intr[0]['total']); } - $events = q("SELECT etype, dtstart, adjust FROM event + $events = q( + "SELECT etype, dtstart, adjust FROM event WHERE event.uid = %d AND dtstart < '%s' AND dtstart > '%s' and dismissed = 0 ORDER BY dtstart ASC ", intval($channels[$x]['channel_id']), @@ -133,10 +137,10 @@ class Manage extends Controller } } } - } - $r = q("select count(channel_id) as total from channel where channel_account_id = %d and channel_removed = 0", + $r = q( + "select count(channel_id) as total from channel where channel_account_id = %d and channel_removed = 0", intval(get_account_id()) ); $limit = account_service_class_fetch(get_account_id(), 'total_identities'); @@ -152,7 +156,8 @@ class Manage extends Controller $delegates = null; if (local_channel()) { - $delegates = q("select * from abook left join xchan on abook_xchan = xchan_hash where + $delegates = q( + "select * from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_xchan in ( select xchan from abconfig where chan = %d and cat = 'system' and k = 'their_perms' and v like '%s' )", intval(local_channel()), intval(local_channel()), @@ -168,7 +173,6 @@ class Manage extends Controller $delegates[$x]['delegate'] = 1; $delegates[$x]['collections_label'] = t('Collection'); $delegates[$x]['forum_label'] = t('Group'); - } } else { $delegates = null; @@ -192,5 +196,4 @@ class Manage extends Controller '$delegates' => $delegates ]); } - } diff --git a/Zotlabs/Module/Manifest.php b/Zotlabs/Module/Manifest.php index 67e271be1..ab3163196 100644 --- a/Zotlabs/Module/Manifest.php +++ b/Zotlabs/Module/Manifest.php @@ -1,11 +1,11 @@ ' . $desc . ''; return $text; - } - } diff --git a/Zotlabs/Module/Menu.php b/Zotlabs/Module/Menu.php index d810d1c8d..8879a448c 100644 --- a/Zotlabs/Module/Menu.php +++ b/Zotlabs/Module/Menu.php @@ -1,4 +1,5 @@ 1) + if (argc() > 1) { $which = argv(1); - else + } else { return; + } Libprofile::load($which); - } @@ -50,15 +51,18 @@ class Menu extends Controller App::$is_sys = true; } - if (!$uid) + if (!$uid) { return; + } $_REQUEST['menu_channel_id'] = $uid; - if ($_REQUEST['menu_bookmark']) + if ($_REQUEST['menu_bookmark']) { $_REQUEST['menu_flags'] |= MENU_BOOKMARK; - if ($_REQUEST['menu_system']) + } + if ($_REQUEST['menu_system']) { $_REQUEST['menu_flags'] |= MENU_SYSTEM; + } $menu_id = ((argc() > 1) ? intval(argv(1)) : 0); if ($menu_id) { @@ -68,8 +72,9 @@ class Menu extends Controller menu_sync_packet($uid, get_observer_hash(), $menu_id); //info( t('Menu updated.') . EOL); goaway(z_root() . '/mitem/' . $which . '/' . $menu_id . ((App::$is_sys) ? '?f=&sys=1' : '')); - } else + } else { notice(t('Unable to update menu.') . EOL); + } } else { $r = menu_create($_REQUEST); if ($r) { @@ -77,9 +82,9 @@ class Menu extends Controller //info( t('Menu created.') . EOL); goaway(z_root() . '/mitem/' . $which . '/' . $r . ((App::$is_sys) ? '?f=&sys=1' : '')); - } else + } else { notice(t('Unable to create menu.') . EOL); - + } } } @@ -143,7 +148,6 @@ class Menu extends Controller } if (argc() == 2) { - $channel = (($sys) ? $sys : channelx_by_n($owner)); // list menus @@ -151,8 +155,9 @@ class Menu extends Controller if ($x) { for ($y = 0; $y < count($x); $y++) { $m = menu_fetch($x[$y]['menu_name'], $owner, get_observer_hash()); - if ($m) + if ($m) { $x[$y]['element'] = '[element]' . base64url_encode(json_encode(menu_element($channel, $m))) . '[/element]'; + } $x[$y]['bookmark'] = (($x[$y]['menu_flags'] & MENU_BOOKMARK) ? true : false); } } @@ -188,17 +193,16 @@ class Menu extends Controller )); return $o; - } if (argc() > 2) { if (intval(argv(2))) { - if (argc() == 4 && argv(3) == 'drop') { menu_sync_packet($owner, get_observer_hash(), intval(argv(1)), true); $r = menu_delete_id(intval(argv(2)), $owner); - if (!$r) + if (!$r) { notice(t('Menu could not be deleted.') . EOL); + } goaway(z_root() . '/menu/' . $which . ((App::$is_sys) ? '?f=&sys=1' : '')); } @@ -226,13 +230,10 @@ class Menu extends Controller )); return $o; - } else { notice(t('Not found.') . EOL); return; } } - } - } diff --git a/Zotlabs/Module/Mitem.php b/Zotlabs/Module/Mitem.php index a9a34a160..e0df97a52 100644 --- a/Zotlabs/Module/Mitem.php +++ b/Zotlabs/Module/Mitem.php @@ -1,4 +1,5 @@ 1) + if (argc() > 1) { $which = argv(1); - else + } else { return; + } Libprofile::load($which); - if (argc() < 3) + if (argc() < 3) { return; + } $m = menu_fetch_id(intval(argv(2)), App::$profile['channel_id']); if (!$m) { @@ -39,7 +42,6 @@ class Mitem extends Controller return ''; } App::$data['menu'] = $m; - } public function post() @@ -60,12 +62,14 @@ class Mitem extends Controller App::$is_sys = true; } - if (!$uid) + if (!$uid) { return; + } - if (!App::$data['menu']) + if (!App::$data['menu']) { return; + } if (!$_REQUEST['mitem_desc'] || !$_REQUEST['mitem_link']) { notice(t('Unable to create element.') . EOL); @@ -76,10 +80,12 @@ class Mitem extends Controller $_REQUEST['menu_id'] = App::$data['menu']['menu_id']; $_REQUEST['mitem_flags'] = 0; - if ($_REQUEST['usezid']) + if ($_REQUEST['usezid']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_ZID; - if ($_REQUEST['newwin']) + } + if ($_REQUEST['newwin']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN; + } $mitem_id = ((argc() > 3) ? intval(argv(3)) : 0); @@ -90,9 +96,9 @@ class Mitem extends Controller menu_sync_packet($uid, get_observer_hash(), $_REQUEST['menu_id']); //info( t('Menu element updated.') . EOL); goaway(z_root() . '/mitem/' . $which . '/' . $_REQUEST['menu_id'] . ((App::$is_sys) ? '?f=&sys=1' : '')); - } else + } else { notice(t('Unable to update menu element.') . EOL); - + } } else { $r = menu_add_item($_REQUEST['menu_id'], $uid, $_REQUEST); if ($r) { @@ -104,11 +110,10 @@ class Mitem extends Controller if ($_REQUEST['submit-more']) { goaway(z_root() . '/mitem/' . $which . '/' . $_REQUEST['menu_id'] . '?f=&display=block' . ((App::$is_sys) ? '&sys=1' : '')); } - } else + } else { notice(t('Unable to add menu element.') . EOL); - + } } - } @@ -147,8 +152,9 @@ class Mitem extends Controller $menu_list = menu_list($owner); foreach ($menu_list as $menus) { - if ($menus['menu_name'] != $m['menu']['menu_name']) + if ($menus['menu_name'] != $m['menu']['menu_name']) { $menu_names[] = $menus['menu_name']; + } } $acl = new AccessControl($channel); @@ -156,7 +162,8 @@ class Mitem extends Controller $lockstate = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'); if (argc() == 3) { - $r = q("select * from menu_item where mitem_menu_id = %d and mitem_channel_id = %d order by mitem_order asc, mitem_desc asc", + $r = q( + "select * from menu_item where mitem_menu_id = %d and mitem_channel_id = %d order by mitem_order asc, mitem_desc asc", intval(App::$data['menu']['menu_id']), intval($owner) ); @@ -215,10 +222,9 @@ class Mitem extends Controller if (argc() > 3) { - if (intval(argv(3))) { - - $m = q("select * from menu_item where mitem_id = %d and mitem_channel_id = %d limit 1", + $m = q( + "select * from menu_item where mitem_id = %d and mitem_channel_id = %d limit 1", intval(argv(3)), intval($owner) ); @@ -236,10 +242,11 @@ class Mitem extends Controller menu_sync_packet($owner, get_observer_hash(), $mitem['mitem_menu_id']); $r = menu_del_item($mitem['mitem_menu_id'], $owner, intval(argv(3))); menu_sync_packet($owner, get_observer_hash(), $mitem['mitem_menu_id']); - if ($r) + if ($r) { info(t('Menu item deleted.') . EOL); - else + } else { notice(t('Menu item could not be deleted.') . EOL); + } goaway(z_root() . '/mitem/' . $which . '/' . $mitem['mitem_menu_id'] . ((App::$is_sys) ? '?f=&sys=1' : '')); } @@ -271,5 +278,4 @@ class Mitem extends Controller } } } - } diff --git a/Zotlabs/Module/Moderate.php b/Zotlabs/Module/Moderate.php index ababeae17..3397991fe 100644 --- a/Zotlabs/Module/Moderate.php +++ b/Zotlabs/Module/Moderate.php @@ -26,21 +26,22 @@ class Moderate extends Controller //show all items if (argc() == 1) { - $r = q("select item.id as item_id, item.* from item where item.uid = %d and item_blocked = %d and item_deleted = 0 order by created desc $pager_sql", + $r = q( + "select item.id as item_id, item.* from item where item.uid = %d and item_blocked = %d and item_deleted = 0 order by created desc $pager_sql", intval(local_channel()), intval(ITEM_MODERATED) ); if (!$r) { info(t('No entries.') . EOL); } - } // show a single item if (argc() == 2) { $post_id = unpack_link_id(escape_tags(argv(1))); - $r = q("select item.id as item_id, item.* from item where item.mid = '%s' and item.uid = %d and item_blocked = %d and item_deleted = 0 order by created desc $pager_sql", + $r = q( + "select item.id as item_id, item.* from item where item.mid = '%s' and item.uid = %d and item_blocked = %d and item_deleted = 0 order by created desc $pager_sql", dbesc($post_id), intval(local_channel()), intval(ITEM_MODERATED) @@ -49,12 +50,14 @@ class Moderate extends Controller if (argc() > 2) { $post_id = intval(argv(1)); - if (!$post_id) + if (!$post_id) { goaway(z_root() . '/moderate'); + } $action = argv(2); - $r = q("select * from item where uid = %d and id = %d and item_blocked = %d limit 1", + $r = q( + "select * from item where uid = %d and id = %d and item_blocked = %d limit 1", intval(local_channel()), intval($post_id), intval(ITEM_MODERATED) @@ -64,7 +67,8 @@ class Moderate extends Controller $item = $r[0]; if ($action === 'approve') { - q("update item set item_blocked = 0 where uid = %d and id = %d", + q( + "update item set item_blocked = 0 where uid = %d and id = %d", intval(local_channel()), intval($post_id) ); @@ -81,7 +85,8 @@ class Moderate extends Controller // refetch the item after changes have been made - $r = q("select * from item where id = %d", + $r = q( + "select * from item where id = %d", intval($post_id) ); if ($r) { @@ -118,7 +123,5 @@ class Moderate extends Controller $o = conversation($items, 'moderate', false, 'traditional'); $o .= alt_pager(count($items)); return $o; - } - } diff --git a/Zotlabs/Module/Mood.php b/Zotlabs/Module/Mood.php index 407558a99..d3e170ecb 100644 --- a/Zotlabs/Module/Mood.php +++ b/Zotlabs/Module/Mood.php @@ -1,4 +1,5 @@ $v) - if ($v !== 'NOTRANSLATION') + foreach ($verbs as $k => $v) { + if ($v !== 'NOTRANSLATION') { $shortlist[] = array($k, $v); + } + } $tpl = get_markup_template('mood_content.tpl'); @@ -159,7 +167,5 @@ class Mood extends Controller )); return $o; - } - } diff --git a/Zotlabs/Module/New_channel.php b/Zotlabs/Module/New_channel.php index 6547ff392..4d1f4007a 100644 --- a/Zotlabs/Module/New_channel.php +++ b/Zotlabs/Module/New_channel.php @@ -1,6 +1,6 @@ 64) + if ((!$x) || strlen($x) > 64) { $x = strtolower(URLify::transliterate($n)); + } $test = []; // first name - if (strpos($x, ' ')) + if (strpos($x, ' ')) { $test[] = legal_webbie(substr($x, 0, strpos($x, ' '))); + } if ($test[0]) { // first name plus first initial of last $test[] = ((strpos($x, ' ')) ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : ''); @@ -64,15 +66,17 @@ class New_channel extends Controller $x = punify(mb_strtolower($n)); } - if ((!$x) || strlen($x) > 64) + if ((!$x) || strlen($x) > 64) { $x = strtolower(URLify::transliterate($n)); + } $test = []; // first name - if (strpos($x, ' ')) + if (strpos($x, ' ')) { $test[] = legal_webbie(substr($x, 0, strpos($x, ' '))); + } if ($test[0]) { // first name plus first initial of last $test[] = ((strpos($x, ' ')) ? $test[0] . legal_webbie(trim(substr($x, strpos($x, ' '), 2))) : ''); @@ -86,13 +90,12 @@ class New_channel extends Controller $test[] = $n . mt_rand(1000, 9999); } - for ($y = 0; $y < 100; $y++) + for ($y = 0; $y < 100; $y++) { $test[] = 'id' . mt_rand(1000, 9999); + } json_return_and_die(check_webbie($test)); } - - } public function post() @@ -133,7 +136,6 @@ class New_channel extends Controller $next_page = get_config('system', 'workflow_channel_next', 'profiles'); goaway(z_root() . '/' . $next_page); - } public function get() @@ -149,7 +151,8 @@ class New_channel extends Controller $default_role = ''; $aid = get_account_id(); if ($aid) { - $r = q("select count(channel_id) as total from channel where channel_account_id = %d", + $r = q( + "select count(channel_id) as total from channel where channel_account_id = %d", intval($aid) ); if ($r && (!intval($r[0]['total']))) { @@ -202,8 +205,5 @@ class New_channel extends Controller )); return $o; - } - - } diff --git a/Zotlabs/Module/Notes.php b/Zotlabs/Module/Notes.php index 8a82ee113..5040d4e3b 100644 --- a/Zotlabs/Module/Notes.php +++ b/Zotlabs/Module/Notes.php @@ -1,5 +1,8 @@ true); if (array_key_exists('note_text', $_REQUEST)) { @@ -24,8 +28,9 @@ class Notes extends Controller if (!$body) { $old_text = get_pconfig(local_channel(), 'notes', 'text'); - if ($old_text) + if ($old_text) { set_pconfig(local_channel(), 'notes', 'text.bak', $old_text); + } } set_pconfig(local_channel(), 'notes', 'text', $body); @@ -38,7 +43,6 @@ class Notes extends Controller logger('notes saved.', LOGGER_DEBUG); json_return_and_die($ret); - } } @@ -58,8 +62,5 @@ class Notes extends Controller $text = '' . $rr['xchan_name'] . '' . $desc . ''; return $text; - } - - } diff --git a/Zotlabs/Module/Notifications.php b/Zotlabs/Module/Notifications.php index b107c4d20..5b9abde5c 100644 --- a/Zotlabs/Module/Notifications.php +++ b/Zotlabs/Module/Notifications.php @@ -1,4 +1,5 @@ 49) { - $r = q("select * from notify where uid = %d + $r = q( + "select * from notify where uid = %d and seen = 0 order by created desc limit 50", intval(local_channel()) ); } else { - $r1 = q("select * from notify where uid = %d + $r1 = q( + "select * from notify where uid = %d and seen = 0 order by created desc limit 50", intval(local_channel()) ); - $r2 = q("select * from notify where uid = %d + $r2 = q( + "select * from notify where uid = %d and seen = 1 order by created desc limit %d", intval(local_channel()), intval(50 - intval($n[0]['total'])) @@ -71,5 +76,4 @@ class Notifications extends Controller return $o; } - } diff --git a/Zotlabs/Module/Notify.php b/Zotlabs/Module/Notify.php index 02d91da3c..3bafdfc6a 100644 --- a/Zotlabs/Module/Notify.php +++ b/Zotlabs/Module/Notify.php @@ -1,10 +1,10 @@ 2 && argv(1) === 'view' && intval(argv(2))) { - $r = q("select * from notify where id = %d and uid = %d limit 1", + $r = q( + "select * from notify where id = %d and uid = %d limit 1", intval(argv(2)), intval(local_channel()) ); @@ -28,7 +29,8 @@ class Notify extends Controller $x = ['channel_id' => local_channel(), 'update' => 'unset']; call_hooks('update_unseen', $x); if ((!$_SESSION['sudo']) && ($x['update'] === 'unset' || intval($x['update']))) { - q("update notify set seen = 1 where (( parent != '' and parent = '%s' and otype = '%s' ) or link = '%s' ) and uid = %d", + q( + "update notify set seen = 1 where (( parent != '' and parent = '%s' and otype = '%s' ) or link = '%s' ) and uid = %d", dbesc($r[0]['parent']), dbesc($r[0]['otype']), dbesc($r[0]['link']), @@ -40,8 +42,6 @@ class Notify extends Controller notice(sprintf(t('A notification with that id was not found for channel \'%s\''), $channel['channel_name'])); goaway(z_root()); } - - } @@ -55,7 +55,8 @@ class Notify extends Controller $not_tpl = get_markup_template('notify.tpl'); - $r = q("SELECT * from notify where uid = %d and seen = 0 order by created desc", + $r = q( + "SELECT * from notify where uid = %d and seen = 0 order by created desc", intval(local_channel()) ); @@ -79,6 +80,5 @@ class Notify extends Controller )); return $o; - } } diff --git a/Zotlabs/Module/Nullbox.php b/Zotlabs/Module/Nullbox.php index 1f3e0ad1c..02e90258e 100644 --- a/Zotlabs/Module/Nullbox.php +++ b/Zotlabs/Module/Nullbox.php @@ -11,6 +11,4 @@ class Nullbox extends Controller { http_status_exit(404, 'Permission Denied'); } - } - diff --git a/Zotlabs/Module/Oauthinfo.php b/Zotlabs/Module/Oauthinfo.php index d2205d4cf..7f67f6731 100644 --- a/Zotlabs/Module/Oauthinfo.php +++ b/Zotlabs/Module/Oauthinfo.php @@ -1,4 +1,5 @@