From de0d2afc154196ed80960435ac9c74ce37635576 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 2 Jan 2023 21:56:20 +0000 Subject: fix issues with pubstream tagcloud --- Zotlabs/Module/Pubstream.php | 21 +++++++--- Zotlabs/Widget/Pubtagcloud.php | 17 +++----- include/taxonomy.php | 92 +++++++++++++++++++++--------------------- 3 files changed, 69 insertions(+), 61 deletions(-) diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index d9156e4bf..7b8d75727 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -161,10 +161,12 @@ class Pubstream extends \Zotlabs\Web\Controller { $uids = " and item.uid = " . intval($sys['channel_id']) . " "; $abook_uids = " and abook.abook_channel = " . intval($sys['channel_id']) . " "; $sql_extra = item_permissions_sql($sys['channel_id']); + $sql_extra_order = ''; $site_firehose_sql = ''; + $thread_top = " and item.item_thread_top = 1 "; if($site_firehose) { - $site_firehose_sql = " and author_xchan in (select channel_hash from channel where channel_system = 0 and channel_removed = 0) "; + $site_firehose_sql = " and owner_xchan in (select channel_hash from channel where channel_system = 0 and channel_removed = 0) "; } if(get_config('system','public_list_mode')) @@ -175,6 +177,8 @@ class Pubstream extends \Zotlabs\Web\Controller { if(x($hashtags)) { $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG)); + $sql_extra_order = " ORDER BY item.created DESC "; + $thread_top = ''; } $net_query = (($net) ? " left join xchan on xchan_hash = author_xchan " : ''); @@ -209,7 +213,7 @@ class Pubstream extends \Zotlabs\Web\Controller { $r = dbq("SELECT parent AS item_id FROM item left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) $net_query - WHERE item.item_private = 0 and item.item_thread_top = 1 + WHERE item.item_private = 0 $thread_top $uids $site_firehose_sql $item_normal and (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -234,7 +238,7 @@ class Pubstream extends \Zotlabs\Web\Controller { $r = dbq("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan $net_query - WHERE item.item_private = 0 and item.item_thread_top = 1 + WHERE item.item_private = 0 $thread_top $uids $site_firehose_sql $item_normal_update $simple_update and (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -253,15 +257,22 @@ class Pubstream extends \Zotlabs\Web\Controller { $items = dbq("SELECT item.*, item.id AS item_id FROM item WHERE true $uids $item_normal AND item.parent IN ( $parents_str ) - $sql_extra" + $sql_extra $sql_extra_order" ); + + // use effective_uid param of xchan_query to help sort out comment permission // for sys_channel owned items. xchan_query($items, true, local_channel()); $items = fetch_post_tags($items,true); - $items = conv_sort($items,$ordering); + + if (!$hashtags) { + $items = conv_sort($items, $ordering); + } + + } } diff --git a/Zotlabs/Widget/Pubtagcloud.php b/Zotlabs/Widget/Pubtagcloud.php index db7ea02e7..90bf5eb97 100644 --- a/Zotlabs/Widget/Pubtagcloud.php +++ b/Zotlabs/Widget/Pubtagcloud.php @@ -22,24 +22,19 @@ class Pubtagcloud { } } - $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); - $net_firehose = ((get_config('system','disable_discover_tab',1)) ? false : true); + $net_firehose = ((get_config('system','disable_discover_tab',1)) ? false : true); - if(! ($site_firehose || $net_firehose)) { - return EMPTY_STR; - } + if(!$net_firehose) { + return ''; + } - if($net_firehose) { - $site_firehose = false; - } + $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); $safemode = get_xconfig(get_observer_hash(),'directory','safemode',1); - - $limit = ((array_key_exists('limit', $arr)) ? intval($arr['limit']) : 75); - return pubtagblock($net_firehose,$site_firehose, $limit, $trending, $safemode); + return pubtagblock($net_firehose, $site_firehose, $limit, $trending, $safemode); return ''; } diff --git a/include/taxonomy.php b/include/taxonomy.php index 1eded055a..18cc39cd9 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -322,7 +322,7 @@ function pubtagblock($net,$site,$limit,$recent = 0,$safemode = 1, $type = TERM_H if($r) { $o = '

' . (($recent) ? t('Trending') : t('Tags')) . '

'; foreach($r as $rr) { - $o .= '#'.$rr[0].' ' . "\r\n"; + $o .= '#'.$rr[0].' ' . "\r\n"; } $o .= '
'; } @@ -335,53 +335,55 @@ function pub_tagadelic($net, $site, $limit, $recent, $safemode, $type) { $item_normal = item_normal(); $count = intval($limit); - $sql_extra = ""; - if($site) - $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 "; - } - - if($recent) - $sql_extra .= " and item.created > NOW() - INTERVAL " . db_quoteinterval(intval($recent) . ' DAY') . " "; - - - if($safemode) { - $unsafetags = get_config('system','unsafepubtags', [ 'boobs', 'bot', 'rss', 'girl','girls', 'nsfw', 'sexy', 'nude' ]); - if($unsafetags) { - $sql_extra .= " and not term.term in ( " . stringify_array($unsafetags,true) . ") "; - } - } - - $key = __FUNCTION__ . "-" . md5($site . $recent . $safemode . $limit . $type); - - $content = Cache::get($key, '5 MINUTE'); - if(! $content) { - - $content = Cache::get($key, '1 MONTH'); - $arr = [ - "SELECT term, count(term) AS total FROM term LEFT JOIN item ON term.oid = item.id - WHERE term.ttype = %d - AND otype = %d - AND item_type = %d - $sql_extra $uids $item_normal - GROUP BY term ORDER BY total DESC %s", - intval($type), - intval(TERM_OBJ_POST), - intval(ITEM_TYPE_POST), - (intval($count) ? "LIMIT $count" : '') - ]; - - \Zotlabs\Daemon\Master::Summon([ 'Cache_query', $key, base64_encode(json_encode($arr)) ]); + $sys = get_sys_channel(); + $uids = " and item.uid = " . intval($sys['channel_id']) . " "; + $sql_extra = item_permissions_sql($sys['channel_id']); + + $site_firehose_sql = ''; + + if ($site) { + $site_firehose_sql = " and author_xchan in (select channel_hash from channel where channel_system = 0 and channel_removed = 0) "; + } + + if($recent) { + $sql_extra .= " and item.created > NOW() - INTERVAL " . db_quoteinterval(intval($recent) . ' DAY') . " "; + } + + if($safemode) { + $unsafetags = get_config('system','unsafepubtags', [ 'boobs', 'bot', 'rss', 'girl','girls', 'nsfw', 'sexy', 'nude' ]); + if($unsafetags) { + $sql_extra .= " and not term.term in ( " . stringify_array($unsafetags,true) . ") "; } + } + + $key = __FUNCTION__ . "-" . md5($site . $recent . $safemode . $limit . $type); - $r = unserialize($content); - if(! $r) - return []; + $content = Cache::get($key, '5 MINUTE'); + if(! $content) { - return Zotlabs\Text\Tagadelic::calc($r); + $content = Cache::get($key, '1 MONTH'); + $arr = [ + "SELECT term, count(term) AS total FROM term LEFT JOIN item ON term.oid = item.id + WHERE term.ttype = %d + AND otype = %d + AND item_type = %d + AND item_private = 0 + $uids $item_normal $site_firehose_sql $sql_extra + GROUP BY term ORDER BY total DESC %s", + intval($type), + intval(TERM_OBJ_POST), + intval(ITEM_TYPE_POST), + (intval($count) ? "LIMIT $count" : '') + ]; + + \Zotlabs\Daemon\Master::Summon([ 'Cache_query', $key, base64_encode(json_encode($arr)) ]); + } + + $r = unserialize($content); + if(! $r) + return []; + + return Zotlabs\Text\Tagadelic::calc($r); } -- cgit v1.2.3