From 8ae6e785f3cb8b6e5334e0442ac4a1348e42fc9b Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 25 Jun 2024 09:27:59 +0000 Subject: reflect the censored state in the local xchan and exclude toplevel posts by censored channels in the public stream --- Zotlabs/Module/Admin/Channels.php | 52 ++++++++++++++++++++++++++++----------- Zotlabs/Module/Pubstream.php | 13 ++++++---- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/Zotlabs/Module/Admin/Channels.php b/Zotlabs/Module/Admin/Channels.php index c6b7ad17a..52b661420 100644 --- a/Zotlabs/Module/Admin/Channels.php +++ b/Zotlabs/Module/Admin/Channels.php @@ -14,7 +14,7 @@ class Channels { */ function post() { - $channels = ( x($_POST, 'channel') ? $_POST['channel'] : Array() ); + $channels = (x($_POST, 'channel') ? $_POST['channel'] : []); check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels'); @@ -22,11 +22,28 @@ 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", - intval(PAGE_CENSORED), - intval( $uid ) + $channel = channelx_by_n($uid); + + if (!$channel) { + notice( t('Channel not found') . EOL); + continue; + } + + $pflags = $channel['channel_pageflags'] ^ PAGE_CENSORED; + + q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", + intval($pflags), + intval($uid) ); + \Zotlabs\Daemon\Master::Summon(array('Directory', $uid, 'nopush')); + + $censored = (($pflags & PAGE_CENSORED) ? 1 : 0); + + q("UPDATE xchan SET xchan_censored = %d WHERE xchan_hash = '%s'", + intval($censored), + dbesc($channel['channel_hash']) + ); } notice( sprintf( tt("%s channel censored/uncensored", "%s channels censored/uncensored", count($channels)), count($channels)) ); } @@ -57,11 +74,9 @@ class Channels { function get() { if(argc() > 2) { $uid = argv(3); - $channel = q("SELECT * FROM channel WHERE channel_id = %d", - intval($uid) - ); + $channel = channelx_by_n($uid); - if(! $channel) { + if(!$channel) { notice( t('Channel not found') . EOL); goaway(z_root() . '/admin/channels' ); } @@ -72,30 +87,37 @@ class Channels { // delete channel channel_remove($uid,true); - notice( sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL); + notice( sprintf(t("Channel '%s' deleted"), $channel['channel_name']) . EOL); }; break; case "block":{ check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); - $pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED; + $pflags = $channel['channel_pageflags'] ^ PAGE_CENSORED; q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), - intval( $uid ) + intval($uid) ); \Zotlabs\Daemon\Master::Summon(array('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); + $censored = (($pflags & PAGE_CENSORED) ? 1 : 0); + + q("UPDATE xchan SET xchan_censored = %d WHERE xchan_hash = '%s'", + intval($censored), + dbesc($channel['channel_hash']) + ); + + notice( sprintf( (($censored) ? t("Channel '%s' censored"): t("Channel '%s' uncensored")) , $channel['channel_name'] . ' (' . $channel['channel_address'] . ')' ) . EOL); }; break; case "code":{ check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); - $pflags = $channel[0]['channel_pageflags'] ^ PAGE_ALLOWCODE; + $pflags = $channel['channel_pageflags'] ^ PAGE_ALLOWCODE; q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), - intval( $uid ) + 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); + notice( sprintf( (($pflags & PAGE_ALLOWCODE) ? t("Channel '%s' code allowed"): t("Channel '%s' code disallowed")) , $channel['channel_name'] . ' (' . $channel['channel_address'] . ')' ) . EOL); }; break; default: diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index d60eb88df..6d8edf4d8 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -185,7 +185,6 @@ class Pubstream extends \Zotlabs\Web\Controller { $thread_top = ''; } - $net_query = (($net) ? " left join xchan on xchan_hash = author_xchan " : ''); $net_query2 = (($net) ? " and xchan_network = '" . protect_sprintf(dbesc($net)) . "' " : ''); if($update && $_SESSION['loadtime']) @@ -203,10 +202,11 @@ class Pubstream extends \Zotlabs\Web\Controller { if($mid) { $r = q("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan - $net_query + left join xchan on item.author_xchan = xchan.xchan_hash WHERE item.$identifier = '%s' and item.item_private = 0 $uids $site_firehose_sql $item_normal + and xchan.xchan_censored = 0 and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2", dbesc($mid) @@ -216,10 +216,11 @@ class Pubstream extends \Zotlabs\Web\Controller { // Fetch a page full of parent items for this page $r = dbq("SELECT parent AS item_id FROM item left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) - $net_query + left join xchan on item.author_xchan = xchan.xchan_hash WHERE item.item_private = 0 $thread_top $uids $site_firehose_sql $item_normal + and xchan.xchan_censored = 0 and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2 ORDER BY $ordering DESC $pager_sql " @@ -230,9 +231,10 @@ class Pubstream extends \Zotlabs\Web\Controller { if($mid) { $r = q("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan - $net_query + left join xchan on item.author_xchan = xchan.xchan_hash WHERE item.$identifier = '%s' and item.item_private = 0 $uids $site_firehose_sql $item_normal_update $simple_update + and xchan.xchan_censored = 0 and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2", dbesc($mid) @@ -241,10 +243,11 @@ class Pubstream extends \Zotlabs\Web\Controller { else { $r = dbq("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan - $net_query + left join xchan on item.author_xchan = xchan.xchan_hash WHERE item.item_private = 0 $thread_top $uids $site_firehose_sql $item_normal_update $simple_update + and xchan.xchan_censored = 0 and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2" ); -- cgit v1.2.3