diff options
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Daemon/Externals.php | 4 | ||||
-rw-r--r-- | Zotlabs/Lib/Activity.php | 54 | ||||
-rw-r--r-- | Zotlabs/Lib/ActivityStreams.php | 2 | ||||
-rw-r--r-- | Zotlabs/Lib/Enotify.php | 6 | ||||
-rw-r--r-- | Zotlabs/Lib/LDSignatures.php | 11 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzot.php | 4 | ||||
-rw-r--r-- | Zotlabs/Module/Directory.php | 12 | ||||
-rw-r--r-- | Zotlabs/Module/Hq.php | 5 | ||||
-rw-r--r-- | Zotlabs/Module/Setup.php | 14 | ||||
-rw-r--r-- | Zotlabs/Photo/PhotoDriver.php | 10 | ||||
-rw-r--r-- | Zotlabs/Web/HTTPSig.php | 23 | ||||
-rw-r--r-- | Zotlabs/Web/SessionHandler.php | 4 | ||||
-rw-r--r-- | Zotlabs/Widget/Messages.php | 19 |
13 files changed, 128 insertions, 40 deletions
diff --git a/Zotlabs/Daemon/Externals.php b/Zotlabs/Daemon/Externals.php index 81414d02d..fb35a65c7 100644 --- a/Zotlabs/Daemon/Externals.php +++ b/Zotlabs/Daemon/Externals.php @@ -133,7 +133,9 @@ class Externals { continue; } - Libzot::fetch_conversation($importer, $message['object']['id']); + $obj_id = isset($message['object']['id']) ?? $message['object']; + + Libzot::fetch_conversation($importer, $obj_id); $total++; continue; } diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 159f2a46f..fe5ee0ec7 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -116,6 +116,11 @@ class Activity { $y = json_decode($x['body'], true); logger('returned: ' . json_encode($y, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOGGER_DEBUG); + + if (ActivityStreams::is_an_actor($y['type'])) { + XConfig::Set($y['id'], 'system', 'actor_record', $y); + } + return json_decode($x['body'], true); } else { @@ -603,10 +608,10 @@ class Activity { $ptr = [$ptr]; } foreach ($ptr as $t) { - if (!array_key_exists('type', $t)) + if (is_array($t) && !array_key_exists('type', $t)) $t['type'] = 'Hashtag'; - if (array_key_exists('href', $t) && array_key_exists('name', $t)) { + if (is_array($t) && array_key_exists('href', $t) && array_key_exists('name', $t)) { switch ($t['type']) { case 'Hashtag': $ret[] = ['ttype' => TERM_HASHTAG, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '#') ? substr($t['name'], 1) : $t['name'])]; @@ -2330,6 +2335,16 @@ class Activity { $s['summary'] = self::bb_content($content, 'summary'); $s['body'] = ((self::bb_content($content, 'bbcode') && (!$response_activity)) ? self::bb_content($content, 'bbcode') : self::bb_content($content, 'content')); + if (isset($act->obj['quoteUrl'])) { + $quote_bbcode = self::get_quote_bbcode($act->obj['quoteUrl']); + + if ($s['body']) { + $s['body'] .= "\r\n\r\n"; + } + + $s['body'] .= $quote_bbcode; + } + $s['verb'] = self::activity_decode_mapper($act->type); // Mastodon does not provide update timestamps when updating poll tallies which means race conditions may occur here. @@ -3709,7 +3724,10 @@ class Activity { } static function get_cached_actor($id) { - $actor = XConfig::Get($id, 'system', 'actor_record'); + + // remove any fragments like #main-key since these won't be present in our cached data + $cache_url = ((strpos($id, '#')) ? substr($id, 0, strpos($id, '#')) : $id); + $actor = XConfig::Get($cache_url, 'system', 'actor_record'); if ($actor) { return $actor; @@ -3718,7 +3736,7 @@ class Activity { // try other get_cached_actor providers (e.g. diaspora) $hookdata = [ 'id' => $id, - 'actor' => false + 'actor' => null ]; call_hooks('get_cached_actor_provider', $hookdata); @@ -3789,4 +3807,32 @@ class Activity { return $ret; } + + static function get_quote_bbcode($url) { + + $ret = ''; + + $a = self::fetch($url); + if ($a) { + $act = new ActivityStreams($a); + + if ($act->is_valid()) { + $content = self::get_content($act->obj); + + $ret .= "[share author='" . urlencode($act->actor['name']) . + "' profile='" . $act->actor['id'] . + "' avatar='" . $act->actor['icon']['url'] . + "' link='" . $act->obj['id'] . + "' auth='" . ((is_matrix_url($act->actor['id'])) ? 'true' : 'false') . + "' posted='" . $act->obj['published'] . + "' message_id='" . $act->obj['id'] . + "']"; + $ret .= self::bb_content($content, 'content'); + $ret .= '[/share]'; + } + } + + return $ret; + } + } diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index b86203a34..275f6eff4 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -92,7 +92,7 @@ class ActivityStreams { $this->ldsig = $this->get_compound_property('signature'); if ($this->ldsig) { - $this->signer = $this->get_compound_property('creator', $this->ldsig); + $this->signer = $this->get_actor('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']) { $this->sigok = LDSignatures::verify($this->data, $this->signer['publicKey']['publicKeyPem']); } diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 2e483cb92..1421c72ae 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -845,6 +845,10 @@ class Enotify { // convert this logic into a json array just like the system notifications $who = (($item['verb'] === ACTIVITY_SHARE) ? 'owner' : 'author'); + $body = html2plain(bbcode($item['body'], ['drop_media']), 75, true); + if ($body) { + $body = htmlentities($body, ENT_QUOTES, 'UTF-8', false); + } $x = array( 'notify_link' => $item['llink'], @@ -858,7 +862,7 @@ class Enotify { //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? gen_link_id($item['thr_parent']) : gen_link_id($item['mid'])), 'thread_top' => (($item['item_thread_top']) ? true : false), 'message' => bbcode(escape_tags($itemem_text)), - 'body' => htmlentities(html2plain(bbcode($item['body'], ['drop_media', true]), 75, true), ENT_QUOTES, 'UTF-8', false), + 'body' => $body, // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], 'uid' => $item['uid'], diff --git a/Zotlabs/Lib/LDSignatures.php b/Zotlabs/Lib/LDSignatures.php index 1c2095f10..00042bc7a 100644 --- a/Zotlabs/Lib/LDSignatures.php +++ b/Zotlabs/Lib/LDSignatures.php @@ -75,22 +75,23 @@ class LDSignatures { } static function hash($obj) { - - return hash('sha256',self::normalise($obj)); + return hash('sha256', self::normalise($obj)); } static function normalise($data) { + $ret = ''; + if(is_string($data)) { $data = json_decode($data); } if(! is_object($data)) - return ''; + return $ret; jsonld_set_document_loader('jsonld_document_loader'); try { - $d = jsonld_normalize($data,[ 'algorithm' => 'URDNA2015', 'format' => 'application/nquads' ]); + $ret = jsonld_normalize($data,[ 'algorithm' => 'URDNA2015', 'format' => 'application/nquads' ]); } catch (\Exception $e) { // Don't log the exception - this can exhaust memory @@ -98,7 +99,7 @@ class LDSignatures { logger('normalise error: ' . print_r($data,true)); } - return $d; + return $ret; } static function salmon_sign($data,$channel) { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index e78cb4568..83536a033 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1003,7 +1003,7 @@ class Libzot { $x = Crypto::unencapsulate($x, get_config('system', 'prvkey')); - if (!is_array($x)) { + if ($x && !is_array($x)) { $x = json_decode($x, true); } @@ -3172,7 +3172,7 @@ class Libzot { } static function update_cached_hubloc($hubloc) { - if ($hubloc['hubloc_updated'] > datetime_convert('UTC','UTC','now - 1 week') || $hubloc['hubloc_url'] === z_root()) { + if ($hubloc['hubloc_updated'] > datetime_convert('UTC','UTC','now - 3 days') || $hubloc['hubloc_url'] === z_root()) { return; } self::refresh( [ 'hubloc_id_url' => $hubloc['hubloc_id_url'] ] ); diff --git a/Zotlabs/Module/Directory.php b/Zotlabs/Module/Directory.php index b39887c9e..da37c582f 100644 --- a/Zotlabs/Module/Directory.php +++ b/Zotlabs/Module/Directory.php @@ -254,21 +254,21 @@ class Directory extends Controller { $connect_link = ''; $location = ''; - if(strlen($rr['locale'])) + if(isset($rr['locale'])) $location .= $rr['locale']; - if(strlen($rr['region'])) { - if(strlen($rr['locale'])) + if(isset($rr['region'])) { + if($location) $location .= ', '; $location .= $rr['region']; } - if(strlen($rr['country'])) { - if(strlen($location)) + if(isset($rr['country'])) { + if($location) $location .= ', '; $location .= $rr['country']; } $age = ''; - if(strlen($rr['birthday'])) { + if(isset($rr['birthday'])) { if(($years = age($rr['birthday'],'UTC','')) > 0) $age = $years; } diff --git a/Zotlabs/Module/Hq.php b/Zotlabs/Module/Hq.php index 29b0df739..5001bbe62 100644 --- a/Zotlabs/Module/Hq.php +++ b/Zotlabs/Module/Hq.php @@ -27,6 +27,8 @@ class Hq extends \Zotlabs\Web\Controller { return; } + $item_hash = ''; + if(argc() > 1 && argv(1) !== 'load') { $item_hash = unpack_link_id(argv(1)); } @@ -97,7 +99,7 @@ class Hq extends \Zotlabs\Web\Controller { 'allow_location' => ((intval(get_pconfig($channel['channel_id'],'system','use_browser_location'))) ? '1' : ''), 'default_location' => $channel['channel_location'], 'nickname' => $channel['channel_address'], - 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), 'acl' => populate_acl($channel_acl,true, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post'), 'permissions' => $channel_acl, 'bang' => '', @@ -112,6 +114,7 @@ class Hq extends \Zotlabs\Web\Controller { 'reset' => t('Reset form') ]; + $a = ''; $o = status_editor($a, $x, true); } diff --git a/Zotlabs/Module/Setup.php b/Zotlabs/Module/Setup.php index ca8c19600..04b31e27b 100644 --- a/Zotlabs/Module/Setup.php +++ b/Zotlabs/Module/Setup.php @@ -69,17 +69,22 @@ class Setup extends \Zotlabs\Web\Controller { $dbpass = ((isset($_POST['dbpass'])) ? trim($_POST['dbpass']) : ''); $dbdata = ((isset($_POST['dbdata'])) ? trim($_POST['dbdata']) : ''); $dbtype = ((isset($_POST['dbtype'])) ? intval(trim($_POST['dbtype'])) : 0); + $phpath = ((isset($_POST['phpath'])) ? trim($_POST['phpath']) : ''); $adminmail = ((isset($_POST['adminmail'])) ? trim($_POST['adminmail']) : ''); $siteurl = ((isset($_POST['siteurl'])) ? trim($_POST['siteurl']) : ''); + if (empty($db_charset)) { + $db_charset = ((intval($db_type) === 0) ? 'utf8mb4' : 'UTF8'); + } + // $siteurl should not have a trailing slash $siteurl = rtrim($siteurl,'/'); require_once('include/dba/dba_driver.php'); - $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); + $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, $db_charset, true); if(! \DBA::$dba->connected) { echo 'Database Connect failed: ' . \DBA::$dba->error; @@ -94,11 +99,16 @@ class Setup extends \Zotlabs\Web\Controller { $dbpass = ((isset($_POST['dbpass'])) ? trim($_POST['dbpass']) : ''); $dbdata = ((isset($_POST['dbdata'])) ? trim($_POST['dbdata']) : ''); $dbtype = ((isset($_POST['dbtype'])) ? intval(trim($_POST['dbtype'])) : 0); + $phpath = ((isset($_POST['phpath'])) ? trim($_POST['phpath']) : ''); $timezone = ((isset($_POST['timezone'])) ? trim($_POST['timezone']) : ''); $adminmail = ((isset($_POST['adminmail'])) ? trim($_POST['adminmail']) : ''); $siteurl = ((isset($_POST['siteurl'])) ? trim($_POST['siteurl']) : ''); + if (empty($db_charset)) { + $db_charset = ((intval($db_type) === 0) ? 'utf8mb4' : 'UTF8'); + } + if($siteurl != z_root()) { $test = z_fetch_url($siteurl."/setup/testrewrite"); if((! $test['success']) || ($test['body'] != 'ok')) { @@ -112,7 +122,7 @@ class Setup extends \Zotlabs\Web\Controller { if(! isset(\DBA::$dba->connected)) { // connect to db - $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); + $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, $db_charset, true); } if(! isset(\DBA::$dba->connected)) { diff --git a/Zotlabs/Photo/PhotoDriver.php b/Zotlabs/Photo/PhotoDriver.php index 4c4f26e32..6bdb89ab1 100644 --- a/Zotlabs/Photo/PhotoDriver.php +++ b/Zotlabs/Photo/PhotoDriver.php @@ -2,7 +2,7 @@ namespace Zotlabs\Photo; -use Zotlabs\Lib\Hashpath; +use Zotlabs\Lib\Hashpath; /** * @brief Abstract photo driver class. @@ -494,11 +494,11 @@ abstract class PhotoDriver { ( aid, uid, xchan, resource_id, created, edited, filename, mimetype, album, height, width, content, os_storage, filesize, imgscale, photo_usage, title, description, os_path, display_path, allow_cid, allow_gid, deny_cid, deny_gid, expires, profile ) VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", intval($p['aid']), intval($p['uid']), dbesc($p['xchan']), dbesc($p['resource_id']), dbescdate($p['created']), dbescdate($p['edited']), dbesc(basename($p['filename'])), dbesc($p['mimetype']), dbesc($p['album']), intval($p['height']), intval($p['width']), (intval($p['os_storage']) ? dbescbin($p['os_syspath']) : dbescbin($this->imageString())), intval($p['os_storage']), (intval($p['os_storage']) ? @filesize($p['os_syspath']) : strlen($this->imageString())), intval($p['imgscale']), intval($p['photo_usage']), dbesc($p['title']), dbesc($p['description']), dbesc($p['os_path']), dbesc($p['display_path']), dbesc($p['allow_cid']), dbesc($p['allow_gid']), dbesc($p['deny_cid']), dbesc($p['deny_gid']), dbescdate($p['expires']), intval($p['profile'])); } - logger('Photo save imgscale ' . $p['imgscale'] . ' returned ' . intval($r)); + logger('Photo save imgscale ' . $p['imgscale'] . ' returned: ' . (($r) ? 1 : 0)); return $r; } - + /** * @brief Stores thumbnail to database or filesystem. * @@ -530,13 +530,13 @@ abstract class PhotoDriver { } else $arr['os_storage'] = 0; - + if(! $this->save($arr)) { if(array_key_exists('os_syspath', $arr)) @unlink($arr['os_syspath']); return false; } - + return true; } diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 7da9acabf..660fdc4ce 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -156,6 +156,7 @@ class HTTPSig { $cached_key = self::get_key($key, $keytype, $result['signer']); + if (!($cached_key && $cached_key['public_key'])) { return $result; } @@ -243,7 +244,12 @@ class HTTPSig { } } - $key = self::get_activitystreams_key($id, $force); + $delete = false; + if ($keytype === 'delete') { + $delete = true; + } + + $key = self::get_activitystreams_key($id, $force, $delete); return $key; @@ -274,7 +280,7 @@ class HTTPSig { * false if no pub key found, otherwise return an array with the pub key */ - static function get_activitystreams_key($id, $force = false) { + static function get_activitystreams_key($id, $force = false, $delete = false) { // Check the local cache first, but remove any fragments like #main-key since these won't be present in our cached data $url = ((strpos($id, '#')) ? substr($id, 0, strpos($id, '#')) : $id); @@ -294,6 +300,12 @@ class HTTPSig { } } + if ($delete) { + // If we received a delete and we do not have the record cached, + // we probably never saw this actor. Do not try to fetch it now. + return false; + } + // The record wasn't in cache. Fetch it now. $r = ActivityStreams::fetch($id); @@ -516,11 +528,14 @@ class HTTPSig { if ($head) { foreach ($head as $k => $v) { - $headers .= strtolower($k) . ': ' . trim($v) . "\n"; + $k = strtolower($k); + $v = (($v) ? trim($v) : ''); + + $headers .= $k . ': ' . $v . "\n"; if ($fields) $fields .= ' '; - $fields .= strtolower($k); + $fields .= $k; } // strip the trailing linefeed $headers = rtrim($headers, "\n"); diff --git a/Zotlabs/Web/SessionHandler.php b/Zotlabs/Web/SessionHandler.php index 392cab1ae..6beb36795 100644 --- a/Zotlabs/Web/SessionHandler.php +++ b/Zotlabs/Web/SessionHandler.php @@ -15,7 +15,7 @@ class SessionHandler implements \SessionHandlerInterface { // some which call read explicitly and some that do not. So we call it explicitly // just after sid regeneration to force a record to exist. - function read ($id) : string|false { + function read ($id) : string { if($id) { $r = q("SELECT sess_data FROM session WHERE sid= '%s'", dbesc($id)); @@ -86,7 +86,7 @@ class SessionHandler implements \SessionHandlerInterface { } - function gc($expire) : int|false { + function gc($expire) : int { q("DELETE FROM session WHERE expire < %d", dbesc(time())); return true; } diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 71f4bd310..86ce2fa29 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -17,8 +17,8 @@ class Messages { $tpl = get_markup_template('messages_widget.tpl'); $o = replace_macros($tpl, [ - '$entries' => $page['entries'], - '$offset' => $page['offset'], + '$entries' => $page['entries'] ?? [], + '$offset' => $page['offset'] ?? 0, '$feature_star' => feature_enabled(local_channel(), 'star_posts'), '$strings' => [ 'messages_title' => t('Public and restricted messages'), @@ -37,11 +37,11 @@ class Messages { if (!local_channel()) return; - if ($options['offset'] == -1) { + if (isset($options['offset']) && $options['offset'] == -1) { return; } - if ($options['type'] == 'notification') { + if (isset($options['type']) && $options['type'] == 'notification') { return self::get_notices_page($options); } @@ -103,13 +103,20 @@ class Messages { if (!$summary) { $summary = $item['summary']; } + if (!$summary) { - $summary = htmlentities(html2plain(bbcode($item['body'], ['drop_media' => true]), 75, true), ENT_QUOTES, 'UTF-8', false); + $summary = html2plain(bbcode($item['body'], ['drop_media' => true]), 75, true); + if ($summary) { + $summary = htmlentities($summary, ENT_QUOTES, 'UTF-8', false); + } } + if (!$summary) { $summary = '...'; } - $summary = substr_words($summary, 68); + else { + $summary = substr_words($summary, 68); + } switch(intval($item['item_private'])) { case 1: |