From 5e4d0f45fc04a0e0fad698b4590f68de8145ce63 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 May 2023 16:42:12 +0000 Subject: check if var is set and escape $ sign in ru translation --- Zotlabs/Lib/Activity.php | 2 +- view/ru/hstrings.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 58b7f95a2..9f957c988 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2414,7 +2414,7 @@ class Activity { $s['edited'] = datetime_convert(); } - if (in_array($act->type, ['Delete', 'Undo', 'Tombstone']) || ($act->type === 'Create' && $act->obj['type'] === 'Tombstone')) { + if (in_array($act->type, ['Delete', 'Undo', 'Tombstone']) || ($act->type === 'Create' && (isset($act->obj['type']) && $act->obj['type'] === 'Tombstone'))) { $s['item_deleted'] = 1; } diff --git a/view/ru/hstrings.php b/view/ru/hstrings.php index 132fee24b..1ccc301bc 100644 --- a/view/ru/hstrings.php +++ b/view/ru/hstrings.php @@ -3098,7 +3098,7 @@ App::$strings["0 or blank to use the website limit."] = "0 или пусто - App::$strings["This website expires after %d days."] = "Срок хранения содержимого этого сайта истекает через %d дней"; App::$strings["This website does not expire imported content."] = "Срок хранения импортированного содержимого этого сайта не ограничен."; App::$strings["The website limit takes precedence if lower than your limit."] = "Ограничение сайта имеет приоритет если ниже вашего значения."; -App::$strings["Words one per line or #tags, \$categories, /patterns/, lang=xx, lang!=xx - leave blank to import all posts"] = "Слова, по одному на строку, или #теги, $категории, /шаблоны/, lang=xx, lang!=xx - оставьте пустым для импорта всех публикаций"; +App::$strings["Words one per line or #tags, \$categories, /patterns/, lang=xx, lang!=xx - leave blank to import all posts"] = "Слова, по одному на строку, или #теги, \$категории, /шаблоны/, lang=xx, lang!=xx - оставьте пустым для импорта всех публикаций"; App::$strings["Not valid email."] = "Не действительный адрес email."; App::$strings["Protected email address. Cannot change to that email."] = "Защищенный адрес электронной почты. Нельзя изменить."; App::$strings["System failure storing new email. Please try again."] = "Системная ошибка сохранения email. Пожалуйста попробуйте ещё раз."; -- cgit v1.2.3 From 01f8cb698d9e94f442ae4aa53b92127bb088c458 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 May 2023 18:38:43 +0000 Subject: check if we have a type and a href --- Zotlabs/Lib/Activity.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9f957c988..81a199cb2 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -622,6 +622,10 @@ class Activity { $atts = ((is_array($item['attach'])) ? $item['attach'] : json_decode($item['attach'], true)); if ($atts) { foreach ($atts as $att) { + if (!isset($att['type'], $att['href'])) { + continue; + } + if (isset($att['type']) && strpos($att['type'], 'image')) { $ret[] = ['type' => 'Image', 'url' => $att['href']]; } -- cgit v1.2.3 From abc3545ef9eac4f66571d01ce75251139751fcc7 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 May 2023 20:11:54 +0000 Subject: use act->objprop() in decode_note() --- Zotlabs/Lib/Activity.php | 72 +++++++++++++++++++---------------------- Zotlabs/Lib/ActivityStreams.php | 2 +- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 81a199cb2..c2e719554 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2233,9 +2233,7 @@ class Activity { 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'])) + ($act->objprop('type') === 'Follow' || ActivityStreams::is_an_actor($act->objprop('type'))) ) { return false; } @@ -2265,7 +2263,7 @@ class Activity { $content = self::get_content($act->obj); } - $s['mid'] = ((is_array($act->obj) && isset($act->obj['id'])) ? $act->obj['id'] : $act->obj); + $s['mid'] = $act->objprop('id') ?: $act->obj; if (!$s['mid']) { return false; @@ -2273,7 +2271,7 @@ class Activity { // Friendica sends the diaspora guid in a nonstandard field via AP // If no uuid is provided we will create an uuid v5 from the mid - $s['uuid'] = ((is_array($act->obj) && isset($act->obj['diaspora:guid'])) ? $act->obj['diaspora:guid'] : uuid_from_url($s['mid'])); + $s['uuid'] = (($act->objprop('diaspora:guid')) ?: uuid_from_url($s['mid'])); $s['parent_mid'] = $act->parent_id; @@ -2281,24 +2279,24 @@ class Activity { $s['created'] = datetime_convert('UTC', 'UTC', $act->data['published']); $s['commented'] = $s['created']; } - elseif (is_array($act->obj) && array_key_exists('published', $act->obj)) { + elseif ($act->objprop('published')) { $s['created'] = datetime_convert('UTC', 'UTC', $act->obj['published']); $s['commented'] = $s['created']; } if (array_key_exists('updated', $act->data)) { $s['edited'] = datetime_convert('UTC', 'UTC', $act->data['updated']); } - elseif (is_array($act->obj) && array_key_exists('updated', $act->obj)) { + elseif ($act->objprop('updated')) { $s['edited'] = datetime_convert('UTC', 'UTC', $act->obj['updated']); } if (array_key_exists('expires', $act->data)) { $s['expires'] = datetime_convert('UTC', 'UTC', $act->data['expires']); } - elseif (is_array($act->obj) && array_key_exists('expires', $act->obj)) { + elseif ($act->objprop('expires')) { $s['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']); } - if ($act->type === 'Invite' && is_array($act->obj) && array_key_exists('type', $act->obj) && $act->obj['type'] === 'Event') { + if ($act->type === 'Invite' && $act->objprop('type') === 'Event') { $s['mid'] = $s['parent_mid'] = $act->id; } @@ -2307,9 +2305,9 @@ class Activity { $response_activity = true; $s['mid'] = $act->id; - $s['uuid'] = ((is_array($act->data) && isset($act->data['diaspora:guid'])) ? $act->data['diaspora:guid'] : uuid_from_url($s['mid'])); + $s['uuid'] = ((is_array($act->data) && isset($act->data['diaspora:guid'])) ?: uuid_from_url($s['mid'])); - $s['parent_mid'] = ((is_array($act->obj) && isset($act->obj['id'])) ? $act->obj['id'] : $act->obj); + $s['parent_mid'] = $act->objprop('id') ?: $act->obj; // over-ride the object timestamp with the activity @@ -2321,7 +2319,7 @@ class Activity { $s['edited'] = datetime_convert('UTC', 'UTC', $act->data['updated']); } - $obj_actor = ((isset($act->obj['actor'])) ? $act->obj['actor'] : $act->get_actor('attributedTo', $act->obj)); + $obj_actor = $act->objprop('actor') ?: $act->get_actor('attributedTo', $act->obj); if (!isset($obj_actor['id'])) { return false; @@ -2340,7 +2338,7 @@ class Activity { } // handle event RSVPs - if (($act->obj['type'] === 'Event') || ($act->obj['type'] === 'Invite' && array_path_exists('object/type', $act->obj) && $act->obj['object']['type'] === 'Event')) { + if (($act->objprop('type') === 'Event') || ($act->objprop('type') === 'Invite' && array_path_exists('object/type', $act->obj) && $act->obj['object']['type'] === 'Event')) { if ($act->type === 'Accept') { $content['content'] = sprintf(t('Will attend %s\'s event'), $mention) . EOL . EOL . $content['content']; } @@ -2375,7 +2373,7 @@ class Activity { $s['item_thread_top'] = 1; // it is a parent node - decode the comment policy info if present - if (isset($act->obj['commentPolicy'])) { + if ($act->objprop('commentPolicy')) { $until = strpos($act->obj['commentPolicy'], 'until='); if ($until !== false) { $s['comments_closed'] = datetime_convert('UTC', 'UTC', substr($act->obj['commentPolicy'], $until + 6)); @@ -2401,7 +2399,7 @@ 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'])) { + if ($act->objprop('quoteUrl')) { $quote_bbcode = self::get_quote_bbcode($act->obj['quoteUrl']); if ($s['body']) { @@ -2414,7 +2412,7 @@ class Activity { $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. - if ($act->type === 'Update' && $act->obj['type'] === 'Question' && $s['edited'] === $s['created']) { + if ($act->type === 'Update' && $act->objprop('type') === 'Question' && $s['edited'] === $s['created']) { $s['edited'] = datetime_convert(); } @@ -2431,7 +2429,7 @@ class Activity { } $s['obj'] = $act->obj; - if (is_array($s['obj']) && array_path_exists('actor/id', $s['obj'])) { + if (array_path_exists('actor/id', $s['obj'])) { $s['obj']['actor'] = $s['obj']['actor']['id']; } @@ -2513,23 +2511,21 @@ class Activity { } } - if (array_key_exists('type', $act->obj)) { - // Objects that might have media attachments which aren't already provided in the content element. - // We'll check specific media objects separately. + // Objects that might have media attachments which aren't already provided in the content element. + // We'll check specific media objects separately. - if (in_array($act->obj['type'], ['Article', 'Document', 'Event', 'Note', 'Page', 'Place', 'Question']) && isset($s['attach']) && $s['attach']) { - $s = self::bb_attach($s); - } + if (in_array($act->objprop('type',''), ['Article', 'Document', 'Event', 'Note', 'Page', 'Place', 'Question']) && !empty($s['attach'])) { + $s = self::bb_attach($s); + } - if ($act->obj['type'] === 'Question' && in_array($act->type, ['Create', 'Update'])) { - if (array_key_exists('endTime', $act->obj)) { - $s['comments_closed'] = datetime_convert('UTC', 'UTC', $act->obj['endTime']); - } + if ($act->objprop('type') === 'Question' && in_array($act->type, ['Create', 'Update'])) { + if ($act->objprop['endTime']) { + $s['comments_closed'] = datetime_convert('UTC', 'UTC', $act->obj['endTime']); } } - if (array_key_exists('closed', $act->obj)) { + if ($act->objprop('closed')) { $s['comments_closed'] = datetime_convert('UTC', 'UTC', $act->obj['closed']); } @@ -2548,7 +2544,7 @@ class Activity { // right now just link to the largest mp4 we find that will fit in our // standard content region - if ($act->obj['type'] === 'Video') { + if ($act->objprop('type') === 'Video') { $vtypes = [ 'video/mp4', @@ -2562,7 +2558,7 @@ class Activity { // try to find a poster to display on the video element - if (array_key_exists('icon',$act->obj)) { + if ($act->objprop('icon')) { if (is_array($act->obj['icon'])) { if (array_key_exists(0,$act->obj['icon'])) { $ptr = $act->obj['icon']; @@ -2583,7 +2579,7 @@ class Activity { $tag = (($poster) ? '[video poster="' . $poster . '"]' : '[video]' ); $ptr = null; - if (array_key_exists('url',$act->obj)) { + if ($act->objprop('url')) { if (is_array($act->obj['url'])) { if (array_key_exists(0,$act->obj['url'])) { $ptr = $act->obj['url']; @@ -2629,7 +2625,7 @@ class Activity { } } - if ($act->obj['type'] === 'Audio') { + if ($act->objprop('type') === 'Audio') { $atypes = [ 'audio/mpeg', @@ -2661,7 +2657,7 @@ class Activity { } - if ($act->obj['type'] === 'Image' && strpos($s['body'], 'zrl=') === false) { + if ($act->objprop('type') === 'Image' && strpos($s['body'], 'zrl=') === false) { $ptr = null; @@ -2690,7 +2686,7 @@ class Activity { } - if ($act->obj['type'] === 'Page' && !$s['body']) { + if ($act->objprop('type') === 'Page' && !$s['body']) { $ptr = null; $purl = EMPTY_STR; @@ -2730,7 +2726,7 @@ class Activity { } } - if (in_array($act->obj['type'], ['Note', 'Article', 'Page'])) { + if (in_array($act->objprop('type', ''), ['Note', 'Article', 'Page'])) { $ptr = null; if (array_key_exists('url', $act->obj)) { @@ -2765,10 +2761,8 @@ class Activity { $s['item_private'] = 0; } - if (is_array($act->obj)) { - if (array_key_exists('directMessage', $act->obj) && intval($act->obj['directMessage'])) { - $s['item_private'] = 2; - } + if ($act->objprop('directMessage')) { + $s['item_private'] = 2; } $ap_rawmsg = ''; diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index cfed53b3c..9e460ff75 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -154,7 +154,7 @@ class ActivityStreams { * @return mixed */ public function objprop(string $property, mixed $default = false): mixed { - $x = $this->get_property_obj($property,$this->obj); + $x = $this->get_property_obj($property, $this->obj); return (isset($x)) ? $x : $default; } -- cgit v1.2.3 From 3658975b69753f7383e7157806dab6c8214e2008 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 May 2023 20:22:18 +0000 Subject: typo --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index c2e719554..29986e4a5 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2520,7 +2520,7 @@ class Activity { } if ($act->objprop('type') === 'Question' && in_array($act->type, ['Create', 'Update'])) { - if ($act->objprop['endTime']) { + if ($act->objprop('endTime')) { $s['comments_closed'] = datetime_convert('UTC', 'UTC', $act->obj['endTime']); } } -- cgit v1.2.3 From 8ac4547e73f708b1275bdd3b726c63a276dc8d25 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 May 2023 20:33:38 +0000 Subject: php warnings --- include/items.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/items.php b/include/items.php index 316ab4b23..f6a93cc2c 100644 --- a/include/items.php +++ b/include/items.php @@ -719,12 +719,12 @@ function get_item_elements($x,$allow_code = false) { $arr['comment_policy'] = (($x['comment_scope']) ? htmlspecialchars($x['comment_scope'], ENT_COMPAT,'UTF-8',false) : 'contacts'); - $arr['sig'] = (($x['signature']) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : ''); - $arr['obj'] = activity_sanitise($x['object']); - $arr['target'] = activity_sanitise($x['target']); - $arr['attach'] = activity_sanitise($x['attach']); - $arr['term'] = decode_tags($x['tags']); - $arr['iconfig'] = decode_item_meta($x['meta']); + $arr['sig'] = ((!empty($x['signature'])) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : ''); + $arr['obj'] = ((!empty($x['object'])) ? activity_sanitise($x['object']) : ''); + $arr['target'] = ((!empty($x['target'])) ? activity_sanitise($x['target']) : ''); + $arr['attach'] = ((!empty($x['attach'])) ? activity_sanitise($x['attach']) : ''); + $arr['term'] = ((!empty($x['tags'])) ? decode_tags($x['tags']) : ''); + $arr['iconfig'] = ((!empty($x['meta'])) ? decode_item_meta($x['meta']) : ''); $arr['item_flags'] = 0; if(array_key_exists('flags',$x)) { -- cgit v1.2.3 From 5b80d57a542da0aa221dd69bf6c7f8d6af04956c Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 May 2023 20:40:10 +0000 Subject: php warning --- include/feedutils.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/feedutils.php b/include/feedutils.php index b657c28d0..a2d52c698 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1829,11 +1829,11 @@ function atom_author($tag, $nick, $name, $uri, $h, $w, $type, $photo) { */ function atom_render_author($tag, $xchan) { - $nick = xmlify(substr($xchan['xchan_addr'], 0, strpos($xchan['xchan_addr'], '@'))); - $id = xmlify($xchan['xchan_url']); - $name = xmlify($xchan['xchan_name']); - $photo = xmlify($xchan['xchan_photo_l']); - $type = xmlify($xchan['xchan_photo_mimetype']); + $nick = ((!empty($xchan['xchan_addr'])) ? xmlify(substr($xchan['xchan_addr'], 0, strpos($xchan['xchan_addr'], '@'))) : ''); + $id = ((!empty($xchan['xchan_url'])) ? xmlify($xchan['xchan_url']) : ''); + $name = ((!empty($xchan['xchan_name'])) ? xmlify($xchan['xchan_name']) : ''); + $photo = ((!empty($xchan['xchan_photo_l'])) ? xmlify($xchan['xchan_photo_l']) : ''); + $type = ((!empty($xchan['xchan_photo_mimetype'])) ? xmlify($xchan['xchan_photo_mimetype']) : ''); $w = $h = 300; $o = "<$tag>\r\n"; -- cgit v1.2.3