streams/Code/Module/Admin/Channels.php

172 lines
5.7 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module\Admin;
2020-02-26 00:30:12 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\Channel;
use Code\Daemon\Run;
use Code\Extend\Hook;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2019-06-17 06:38:43 +00:00
/**
* @brief Admin Module for Channels.
*
*/
2021-12-02 23:02:31 +00:00
class Channels
{
/**
* @brief Handle POST actions on channels admin page.
*
*/
public function post()
{
$channels = (x($_POST, 'channel') ? $_POST['channel'] : array());
check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels');
$xor = db_getfunc('^');
if (x($_POST, 'page_channels_block')) {
foreach ($channels as $uid) {
2021-12-03 03:01:39 +00:00
q(
"UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d",
2021-12-02 23:02:31 +00:00
intval(PAGE_CENSORED),
intval($uid)
);
Run::Summon(['Directory', $uid, 'nopush']);
}
notice(sprintf(tt("%s channel censored/uncensored", "%s channels censored/uncensored", count($channels)), count($channels)));
}
if (x($_POST, 'page_channels_delete')) {
foreach ($channels as $uid) {
2022-01-25 01:26:12 +00:00
Channel::channel_remove($uid, true);
2021-12-02 23:02:31 +00:00
}
notice(sprintf(tt("%s channel deleted", "%s channels deleted", count($channels)), count($channels)));
}
goaway(z_root() . '/admin/channels');
}
/**
* @brief Generate channels admin page and handle single item operations.
*
* @return string with parsed HTML
*/
public function get()
{
if (argc() > 2) {
$uid = argv(3);
2021-12-03 03:01:39 +00:00
$channel = q(
"SELECT * FROM channel WHERE channel_id = %d",
2021-12-02 23:02:31 +00:00
intval($uid)
);
if (!$channel) {
notice(t('Channel not found') . EOL);
goaway(z_root() . '/admin/channels');
}
switch (argv(2)) {
case "delete":
{
check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
// delete channel
2022-01-25 01:26:12 +00:00
Channel::channel_remove($uid, true);
2021-12-02 23:02:31 +00:00
notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
2021-12-03 03:01:39 +00:00
}
2021-12-02 22:33:36 +00:00
break;
2021-12-02 23:02:31 +00:00
case "block":
{
check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
$pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED;
2021-12-03 03:01:39 +00:00
q(
"UPDATE channel SET channel_pageflags = %d where channel_id = %d",
2021-12-02 23:02:31 +00:00
intval($pflags),
intval($uid)
);
Run::Summon(['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);
2021-12-03 03:01:39 +00:00
}
2021-12-02 22:33:36 +00:00
break;
2021-12-02 23:02:31 +00:00
default:
break;
}
goaway(z_root() . '/admin/channels');
}
$key = (($_REQUEST['key']) ? dbesc($_REQUEST['key']) : 'channel_id');
$dir = 'asc';
2021-12-03 03:01:39 +00:00
if (array_key_exists('dir', $_REQUEST)) {
2021-12-02 23:02:31 +00:00
$dir = ((intval($_REQUEST['dir'])) ? 'asc' : 'desc');
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$base = z_root() . '/admin/channels?f=';
$odir = (($dir === 'asc') ? '0' : '1');
/* get channels */
$total = q("SELECT count(*) as total FROM channel where channel_removed = 0 and channel_system = 0");
if ($total) {
App::set_pager_total($total[0]['total']);
App::set_pager_itemspage(100);
}
2021-12-03 03:01:39 +00:00
$channels = q(
"SELECT * from channel where channel_removed = 0 and channel_system = 0 order by $key $dir limit %d offset %d ",
2021-12-02 23:02:31 +00:00
intval(App::$pager['itemspage']),
intval(App::$pager['start'])
);
if ($channels) {
for ($x = 0; $x < count($channels); $x++) {
2021-12-03 03:01:39 +00:00
if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
2021-12-02 23:02:31 +00:00
$channels[$x]['blocked'] = true;
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$channels[$x]['blocked'] = false;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$channels[$x]['channel_link'] = z_root() . '/channel/' . $channels[$x]['channel_address'];
}
}
Hook::call('admin_channels', $channels);
2021-12-02 23:02:31 +00:00
2022-02-12 20:43:29 +00:00
$o = replace_macros(Theme::get_template('admin_channels.tpl'), [
2021-12-02 23:02:31 +00:00
// 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_channels' => t('Channel'),
'$base' => $base,
'$odir' => $odir,
'$th_channels' => array(
[t('UID'), 'channel_id'],
[t('Name'), 'channel_name'],
[t('Address'), 'channel_address']),
'$confirm_delete_multi' => t('Selected channels will be deleted!\n\nEverything that was posted in these channels on this site will be permanently deleted!\n\nAre you sure?'),
'$confirm_delete' => t('The channel {0} will be deleted!\n\nEverything that was posted in this channel on this site will be permanently deleted!\n\nAre you sure?'),
'$form_security_token' => get_form_security_token('admin_channels'),
// values //
'$baseurl' => z_root(),
'$channels' => $channels,
]);
$o .= paginate($a);
return $o;
}
2021-12-03 03:01:39 +00:00
}