From de902d179e1c032f8d3cbe801d38072efcd36ef1 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 3 Oct 2019 18:25:57 +0200 Subject: [PATCH 01/15] Allow processing of forum posts through mentions in addons --- Zotlabs/Lib/Libzot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 0c90ff34d..100d45c05 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1764,7 +1764,7 @@ class Libzot { // if it's a sourced post, call the post_local hooks as if it were // posted locally so that crosspost connectors will be triggered. - if(check_item_source($arr['uid'], $arr)) { + if(check_item_source($arr['uid'], $arr) || ($channel['xchan_pubforum'] == 1)) { /** * @hooks post_local * Called when an item has been posted on this machine via mod/item.php (also via API). From b6db1898b12aac45ce40b49ab36acf5e74902dc3 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 3 Oct 2019 18:27:25 +0200 Subject: [PATCH 02/15] Get extended channel info using channelx_by_hash() --- include/zot.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/zot.php b/include/zot.php index bd85dd755..eab75e235 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1776,17 +1776,14 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $DR = new Zotlabs\Lib\DReport(z_root(),$sender['hash'],$d['hash'],$arr['mid']); - $r = q("select * from channel where channel_hash = '%s' limit 1", - dbesc($d['hash']) - ); + $channel = channelx_by_hash($d['hash']); - if(! $r) { + if(! $channel) { $DR->update('recipient not found'); $result[] = $DR->get(); continue; } - $channel = $r[0]; $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); /* blacklisted channels get a permission denied, no special message to tip them off */ From 6feb864c384a46208c94824797eb2b4b92549840 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 3 Oct 2019 18:28:29 +0200 Subject: [PATCH 03/15] Allow processing of forum posts through mentions in addons --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zot.php b/include/zot.php index eab75e235..d08146287 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2029,7 +2029,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ // if it's a sourced post, call the post_local hooks as if it were // posted locally so that crosspost connectors will be triggered. - if(check_item_source($arr['uid'], $arr)) { + if(check_item_source($arr['uid'], $arr) || ($channel['xchan_pubforum'] == 1)) { /** * @hooks post_local * Called when an item has been posted on this machine via mod/item.php (also via API). From 5c4c6e68f600d50deed8ddb32dd6702af9b52853 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sun, 6 Oct 2019 12:02:45 +0200 Subject: [PATCH 04/15] Remove visible channels list from pubstream tags cloud creation procedure --- include/taxonomy.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/taxonomy.php b/include/taxonomy.php index b0304de5b..a9991b617 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -334,13 +334,14 @@ function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { $count = intval($limit); if($site) { - $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; + //$uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; } else { $sys = get_sys_channel(); $uids = " and item.uid = " . intval($sys['channel_id']) . " "; - $sql_extra = " and item_private = 0 "; } + + $sql_extra = " and item_private = 0 "; if($recent) $sql_extra .= " and item.created > '" . datetime_convert('UTC','UTC', 'now - ' . intval($recent) . ' days ') . "' "; From aa44da35bad02fda6c123a7961993ad687353031 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sun, 6 Oct 2019 19:24:28 +0200 Subject: [PATCH 05/15] Revert "Remove visible channels list from pubstream tags cloud creation procedure" This reverts commit 5c4c6e68f600d50deed8ddb32dd6702af9b52853 --- include/taxonomy.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/taxonomy.php b/include/taxonomy.php index a9991b617..b0304de5b 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -334,14 +334,13 @@ function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { $count = intval($limit); if($site) { - //$uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; + $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; } else { $sys = get_sys_channel(); $uids = " and item.uid = " . intval($sys['channel_id']) . " "; + $sql_extra = " and item_private = 0 "; } - - $sql_extra = " and item_private = 0 "; if($recent) $sql_extra .= " and item.created > '" . datetime_convert('UTC','UTC', 'now - ' . intval($recent) . ' days ') . "' "; From 3881ebcce062b6857d13f98212c50cdcd6b8b49d Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 11 Oct 2019 00:46:02 +0200 Subject: [PATCH 06/15] Better Opengraph markup for channel --- Zotlabs/Module/Channel.php | 49 +++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index b1639b213..e83b42d67 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -111,17 +111,6 @@ class Channel extends Controller { // we start loading content profile_load($which,$profile); - - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - - if(App::$profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) { - App::$page['htmlhead'] .= '' . "\r\n"; - } - else { - App::$page['htmlhead'] .= '' . "\r\n"; - } - } function get($update = 0, $load = false) { @@ -385,6 +374,44 @@ class Channel extends Controller { $items = array(); } + // Add Opengraph markup + // + if(! empty($items) && isset($decoded)) { + // get post data + if(! empty($r[0]['title'])) + $ogtitle = $r[0]['title']; + + if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $r[0]['body'], $matches)) + $ogimage = $matches[2]; + + $ogdesc = bbcode($r[0]['body'], [ 'tryoembed' => false ]); + $ogdesc = trim(html2plain($ogdesc, 0, true)); + $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8'); + $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc); + $ogdesc = substr($ogdesc, 0, 280); + $ogdesc = str_replace("\n", " ", $ogdesc); + while (strpos($ogdesc, " ") !== false) + $ogdesc = str_replace(" ", " ", $ogdesc); + if (substr($ogdesc, -1) != "\n") + $ogdesc = rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."; + } + + $channel = channelx_by_n(App::$profile['profile_uid']); + + if(! isset($ogdesc)) { + if(App::$profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) { + $ogdesc = App::$profile['about']; + } + else { + $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']); + } + } + + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + + if((! $update) && (! $load)) { if($decoded) From 125de855efd5fefdd25b47e7c9c7a4eca064f2b0 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 11 Oct 2019 09:55:06 +0200 Subject: [PATCH 07/15] Add Opengraph og:type object --- Zotlabs/Module/Channel.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index e83b42d67..e981257bc 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -394,6 +394,7 @@ class Channel extends Controller { $ogdesc = str_replace(" ", " ", $ogdesc); if (substr($ogdesc, -1) != "\n") $ogdesc = rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."; + $ogtype = "article"; } $channel = channelx_by_n(App::$profile['profile_uid']); @@ -410,6 +411,7 @@ class Channel extends Controller { App::$page['htmlhead'] .= '' . "\r\n"; App::$page['htmlhead'] .= '' . "\r\n"; App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; if((! $update) && (! $load)) { From 3bc44ee451b5c10b1635ac340f425f2b2a98aa43 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 11 Oct 2019 19:29:40 +0200 Subject: [PATCH 08/15] Minor Opengraph improvements --- Zotlabs/Module/Channel.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index e981257bc..0121e6689 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -381,14 +381,16 @@ class Channel extends Controller { if(! empty($r[0]['title'])) $ogtitle = $r[0]['title']; - if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $r[0]['body'], $matches)) + $ogdesc = str_replace("#^[", "[", $r[0]['body']); + + if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $ogdesc, $matches)) $ogimage = $matches[2]; - $ogdesc = bbcode($r[0]['body'], [ 'tryoembed' => false ]); + $ogdesc = bbcode($ogdesc, [ 'tryoembed' => false ]); $ogdesc = trim(html2plain($ogdesc, 0, true)); $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8'); $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc); - $ogdesc = substr($ogdesc, 0, 280); + $ogdesc = substr($ogdesc, 0, 300); $ogdesc = str_replace("\n", " ", $ogdesc); while (strpos($ogdesc, " ") !== false) $ogdesc = str_replace(" ", " ", $ogdesc); From f7e665c42f3f4678cce512416eeca6f032146fe1 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 12 Oct 2019 19:03:21 +0200 Subject: [PATCH 09/15] Add Opengraph function --- include/opengraph.php | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 include/opengraph.php diff --git a/include/opengraph.php b/include/opengraph.php new file mode 100644 index 000000000..b177673ac --- /dev/null +++ b/include/opengraph.php @@ -0,0 +1,68 @@ + false ]); + $ogdesc = trim(html2plain($ogdesc, 0, true)); + $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8'); + + // remove all URLs + $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc); + + // shorten description + $ogdesc = substr($ogdesc, 0, 300); + $ogdesc = str_replace("\n", " ", $ogdesc); + while (strpos($ogdesc, " ") !== false) + $ogdesc = str_replace(" ", " ", $ogdesc); + if (substr($ogdesc, -1) != "\n") + $ogdesc = rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."; + + $ogtype = "article"; + } + + $channel = channelx_by_n($profile['profile_uid']); + + if(! isset($ogdesc)) { + if($profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) { + $ogdesc = $profile['about']; + } + else { + $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']); + } + } + + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + + return true; + } + \ No newline at end of file From 2f26badb846d6ff9ef27bcabfe50c8da8838510f Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 12 Oct 2019 19:05:20 +0200 Subject: [PATCH 10/15] Move Opengraph functions to common libraries --- Zotlabs/Module/Channel.php | 42 ++------------------------------------ 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 0121e6689..2fd27fe5b 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -13,6 +13,7 @@ require_once('include/items.php'); require_once('include/security.php'); require_once('include/conversation.php'); require_once('include/acl_selectors.php'); +require_once('include/opengraph.php'); /** @@ -375,46 +376,7 @@ class Channel extends Controller { } // Add Opengraph markup - // - if(! empty($items) && isset($decoded)) { - // get post data - if(! empty($r[0]['title'])) - $ogtitle = $r[0]['title']; - - $ogdesc = str_replace("#^[", "[", $r[0]['body']); - - if(preg_match("/\[[zi]mg(=[0-9]+x[0-9]+)?\]([^\[]+)/is", $ogdesc, $matches)) - $ogimage = $matches[2]; - - $ogdesc = bbcode($ogdesc, [ 'tryoembed' => false ]); - $ogdesc = trim(html2plain($ogdesc, 0, true)); - $ogdesc = html_entity_decode($ogdesc, ENT_QUOTES, 'UTF-8'); - $ogdesc = preg_replace("/https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+/", "", $ogdesc); - $ogdesc = substr($ogdesc, 0, 300); - $ogdesc = str_replace("\n", " ", $ogdesc); - while (strpos($ogdesc, " ") !== false) - $ogdesc = str_replace(" ", " ", $ogdesc); - if (substr($ogdesc, -1) != "\n") - $ogdesc = rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."; - $ogtype = "article"; - } - - $channel = channelx_by_n(App::$profile['profile_uid']); - - if(! isset($ogdesc)) { - if(App::$profile['about'] && perm_is_allowed($channel['channel_id'],get_observer_hash(),'view_profile')) { - $ogdesc = App::$profile['about']; - } - else { - $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']); - } - } - - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; - + opengraph_add_meta((isset($decoded) && (! empty($items)) ? $r[0] : array()), App::$profile); if((! $update) && (! $load)) { From db7cbdfc44465e4f6c115fcb4269b060cd5c48cb Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 12 Oct 2019 19:23:14 +0200 Subject: [PATCH 11/15] Add Opengraph markup for articles --- Zotlabs/Module/Articles.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Zotlabs/Module/Articles.php b/Zotlabs/Module/Articles.php index ca132c01e..e3ad54be8 100644 --- a/Zotlabs/Module/Articles.php +++ b/Zotlabs/Module/Articles.php @@ -9,6 +9,7 @@ use Zotlabs\Lib\PermissionDescription; require_once('include/channel.php'); require_once('include/conversation.php'); require_once('include/acl_selectors.php'); +require_once('include/opengraph.php'); class Articles extends Controller { @@ -192,7 +193,7 @@ class Articles extends Controller { $parents_str = ids_to_querystr($r,'id'); - $items = q("SELECT item.*, item.id AS item_id + $r = q("SELECT item.*, item.id AS item_id FROM item WHERE item.uid = %d $item_normal AND item.parent IN ( %s ) @@ -200,15 +201,18 @@ class Articles extends Controller { intval(App::$profile['profile_uid']), dbesc($parents_str) ); - if($items) { - xchan_query($items); - $items = fetch_post_tags($items, true); + if($r) { + xchan_query($r); + $items = fetch_post_tags($r, true); $items = conv_sort($items,'updated'); } else $items = []; } + // Add Opengraph markup + opengraph_add_meta(((! empty($items)) ? $r[0] : array()), App::$profile); + $mode = 'articles'; if(get_pconfig(local_channel(),'system','articles_list_mode') && (! $selected_card)) From 6a25548097dbf65936519fd078ca4b3065ceadae Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 12 Oct 2019 19:26:17 +0200 Subject: [PATCH 12/15] Update Channel.php --- Zotlabs/Module/Channel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 2fd27fe5b..3f617fd18 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -352,7 +352,7 @@ class Channel extends Controller { $parents_str = ids_to_querystr($r,'item_id'); - $items = q("SELECT item.*, item.id AS item_id + $r = q("SELECT item.*, item.id AS item_id FROM item WHERE item.uid = %d $item_normal AND item.parent IN ( %s ) @@ -361,8 +361,8 @@ class Channel extends Controller { dbesc($parents_str) ); - xchan_query($items); - $items = fetch_post_tags($items, true); + xchan_query($r); + $items = fetch_post_tags($r, true); $items = conv_sort($items,$ordering); if($load && $mid && (! count($items))) { From e4c57e80318b6e95751f825a9a7c0bf63f69f35d Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 12 Oct 2019 21:22:42 +0200 Subject: [PATCH 13/15] Update opengraph.php --- include/opengraph.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/opengraph.php b/include/opengraph.php index b177673ac..ab1c90e57 100644 --- a/include/opengraph.php +++ b/include/opengraph.php @@ -41,8 +41,7 @@ $ogdesc = str_replace("\n", " ", $ogdesc); while (strpos($ogdesc, " ") !== false) $ogdesc = str_replace(" ", " ", $ogdesc); - if (substr($ogdesc, -1) != "\n") - $ogdesc = rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."; + $ogdesc = rtrim(substr($ogdesc, 0, strrpos($ogdesc, " ")), "?.,:;!-") . "..."; $ogtype = "article"; } From 0c2657df78b9fe65e01ba4dc027a24d143b6c863 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 12 Oct 2019 23:42:35 +0200 Subject: [PATCH 14/15] Add Opengraph image type detection --- include/opengraph.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/opengraph.php b/include/opengraph.php index ab1c90e57..2d72ffca1 100644 --- a/include/opengraph.php +++ b/include/opengraph.php @@ -56,9 +56,13 @@ $ogdesc = sprintf( t('This is the home page of %s.'), $channel['channel_name']); } } + + if(! isset($ogimage)) + $ogimage = $channel['xchan_photo_l']; App::$page['htmlhead'] .= '' . "\r\n"; - App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; + App::$page['htmlhead'] .= '' . "\r\n"; App::$page['htmlhead'] .= '' . "\r\n"; App::$page['htmlhead'] .= '' . "\r\n"; From 5bf3114e6f4f8d78eec887467f93beb2ab34724b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 14 Oct 2019 11:09:53 +0200 Subject: [PATCH 15/15] Better plural function detection --- util/po2php.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/po2php.php b/util/po2php.php index 73d9b454e..535e5567c 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -52,7 +52,7 @@ function po2php_run($argc,$argv) { if ($l[0]=="#") $l=""; if (substr($l,0,15)=='"Plural-Forms: '){ $match=Array(); - preg_match("|nplurals=([0-9]*);\s*plural=(.*)[;\\\\]|", $l, $match); + preg_match("|nplurals=([0-9]*);\s*plural=([^;\\\\]*)|", $l, $match); $cond = str_replace('n','$n',$match[2]); $out .= 'if(! function_exists("' . 'string_plural_select_' . $lang .'")) {' . "\n"; $out .= 'function string_plural_select_' . $lang . '($n){'."\n";