From 9a3a2819c11cccdbce72adbe611f45e559e36655 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 26 Mar 2014 17:05:45 -0700 Subject: add admin/channels --- boot.php | 1 + include/security.php | 6 +- mod/admin.php | 162 ++++++++++++++++++++++++++++++++++++++++++-- view/tpl/admin_aside.tpl | 1 + view/tpl/admin_channels.tpl | 50 ++++++++++++++ 5 files changed, 210 insertions(+), 10 deletions(-) create mode 100755 view/tpl/admin_channels.tpl diff --git a/boot.php b/boot.php index 4c024309b..115b5cd0c 100755 --- a/boot.php +++ b/boot.php @@ -205,6 +205,7 @@ define ( 'PAGE_APPLICATION', 0x0004 ); define ( 'PAGE_DIRECTORY_CHANNEL', 0x0008 ); // system channel used for directory synchronisation define ( 'PAGE_PREMIUM', 0x0010 ); define ( 'PAGE_ADULT', 0x0020 ); +define ( 'PAGE_CENSORED', 0x0040 ); // Site admin has blocked this channel from appearing in casual search results and site feeds define ( 'PAGE_SYSTEM', 0x1000 ); define ( 'PAGE_REMOVED', 0x8000 ); diff --git a/include/security.php b/include/security.php index 6b20e2904..d974efb8f 100644 --- a/include/security.php +++ b/include/security.php @@ -346,9 +346,9 @@ function stream_perms_api_uids($perms_min = PERMS_SITE) { $ret = array(); if(local_user()) $ret[] = local_user(); - $r = q("select channel_id from channel where channel_r_stream > 0 and channel_r_stream <= %d and not (channel_pageflags & %d) ", + $r = q("select channel_id from channel where channel_r_stream > 0 and channel_r_stream <= %d and not (channel_pageflags & %d)", intval($perms_min), - intval(PAGE_ADULT) + intval(PAGE_CENSORED) ); if($r) foreach($r as $rr) @@ -373,7 +373,7 @@ function stream_perms_xchans($perms_min = PERMS_SITE) { $r = q("select channel_hash from channel where channel_r_stream > 0 and channel_r_stream <= %d and not (channel_pageflags & %d)", intval($perms_min), - intval(PAGE_ADULT) + intval(PAGE_CENSORED) ); if($r) foreach($r as $rr) diff --git a/mod/admin.php b/mod/admin.php index c4a284941..f603525d2 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -24,6 +24,10 @@ function admin_post(&$a){ case 'users': admin_page_users_post($a); break; + case 'channels': + admin_page_channels_post($a); + break; + case 'plugins': if (argc() > 2 && is_file("addon/" . argv(2) . "/" . argv(2) . ".php")){ @@ -85,12 +89,13 @@ function admin_content(&$a) { // array( url, name, extra css classes ) $aside = Array( - 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"), - 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"), - 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"), - 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"), - 'hubloc' => Array($a->get_baseurl(true)."/admin/hubloc/", t("Server") , "server"), - 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync") + 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"), + 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Accounts") , "users"), + 'channels' => Array($a->get_baseurl(true)."/admin/channels/", t("Channels") , "channels"), + 'plugins' => Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"), + 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"), + 'hubloc' => Array($a->get_baseurl(true)."/admin/hubloc/", t("Server") , "server"), + 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync") ); /* get plugins admin page */ @@ -132,6 +137,9 @@ function admin_content(&$a) { case 'users': $o = admin_page_users($a); break; + case 'channels': + $o = admin_page_channels($a); + break; case 'plugins': $o = admin_page_plugins($a); break; @@ -671,7 +679,7 @@ function admin_page_users(&$a){ intval( $uid ) ); - notice( sprintf( (($account['account_flags'] & ACCOUNT_BLOCKED) ? t("User '%s' unblocked"):t("User '%s' blocked")) , $account[0]['account_email']) . EOL); + notice( sprintf( (($account[0]['account_flags'] & ACCOUNT_BLOCKED) ? t("User '%s' unblocked"):t("User '%s' blocked")) , $account[0]['account_email']) . EOL); }; break; } goaway($a->get_baseurl(true) . '/admin/users' ); @@ -766,6 +774,146 @@ function admin_page_users(&$a){ } +/** + * Channels admin page + * + * @param App $a + */ +function admin_page_channels_post(&$a){ + $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() ); + $users = ( x($_POST, 'user') ? $_POST['user'] : Array() ); + + check_form_security_token_redirectOnErr('/admin/users', 'admin_users'); + + if (x($_POST,'page_users_block')){ + foreach($users as $uid){ + q("UPDATE account SET account_flags = (account_flags & %d) where account_id = %d limit 1", + intval(ACCOUNT_BLOCKED), + intval( $uid ) + ); + } + notice( sprintf( tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)) ); + } + if (x($_POST,'page_users_delete')){ + require_once("include/Contact.php"); + foreach($users as $uid){ + account_remove($uid,true); + } + notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) ); + } + + if (x($_POST,'page_users_approve')){ + require_once('include/account.php'); + foreach($pending as $hash){ + user_allow($hash); + } + } + if (x($_POST,'page_users_deny')){ + require_once('include/account.php'); + foreach($pending as $hash){ + user_deny($hash); + } + } + goaway($a->get_baseurl(true) . '/admin/users' ); + return; // NOTREACHED +} + +/** + * @param App $a + * @return string + */ +function admin_page_channels(&$a){ + if (argc() > 2) { + $uid = argv(3); + $channel = q("SELECT * FROM channel WHERE channel_id = %d", + intval($uid) + ); + + if (! $channel) { + notice( t('Channel not found') . EOL); + goaway($a->get_baseurl(true) . '/admin/channels' ); + } + + switch(argv(2)){ +// case "delete":{ + // check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); + // delete user + // require_once("include/Contact.php"); + // account_remove($uid,true); + + // notice( sprintf(t("User '%s' deleted"), $account[0]['account_email']) . EOL); + // }; break; + + case "block":{ + check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); + q("UPDATE channel SET channel_pageflags = ( channel_pageflags ^ %d ) where channel_id = %d", + intval(PAGE_CENSORED), + intval( $uid ) + ); + + notice( sprintf( (($channel[0]['channel_pageflags'] & PAGE_CENSORED) ? t("Channel '%s' uncensored"): t("Channel '%s' censored")) , $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')' ) . EOL); + }; break; + } + goaway($a->get_baseurl(true) . '/admin/users' ); + return ''; // NOTREACHED + + } + + /* get channels */ + + $total = q("SELECT count(*) as total FROM channel where not (channel_pageflags & %d)", + intval(PAGE_REMOVED) + ); + if($total) { + $a->set_pager_total($total[0]['total']); + $a->set_pager_itemspage(100); + } + + $order = " order by channel_name asc "; + + $users = q("SELECT * from channel where not ( channel_pageflags & %d ) $order limit %d , %d ", + intval(PAGE_REMOVED), + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); + + if($users) { + for($x = 0; $x < count($users); $x ++) { + if($users[$x]['channel_pageflags'] & PAGE_CENSORED) + $users[$x]['blocked'] = true; + else + $users[$x]['blocked'] = false; + } + } + + $t = get_markup_template("admin_channels.tpl"); + $o = replace_macros($t, array( + // strings // + '$title' => t('Administration'), + '$page' => t('Channels'), + '$submit' => t('Submit'), + '$select_all' => t('select all'), + '$delete' => t('Delete'), + '$block' => t('Censor'), + '$unblock' => t('Uncensor'), + + '$h_users' => t('Channel'), + '$th_users' => array( t('UID'), t('Name'), t('Address')), + + '$confirm_delete_multi' => t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'), + '$confirm_delete' => t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'), + + '$form_security_token' => get_form_security_token("admin_channels"), + + // values // + '$baseurl' => $a->get_baseurl(true), + '$users' => $users, + )); + $o .= paginate($a); + return $o; +} + + /** * Plugins admin page * diff --git a/view/tpl/admin_aside.tpl b/view/tpl/admin_aside.tpl index fdf070aa2..cb3827bf2 100755 --- a/view/tpl/admin_aside.tpl +++ b/view/tpl/admin_aside.tpl @@ -14,6 +14,7 @@