2016-09-06 04:00:00 +00:00
< ? php
namespace Zotlabs\Module\Admin ;
2016-10-01 22:41:25 +00:00
/**
* @ brief Admin Module for Channels .
*
*/
2016-09-06 04:00:00 +00:00
class Channels {
/**
2016-10-01 22:41:25 +00:00
* @ brief Handle POST actions on channels admin page .
2016-09-06 04:00:00 +00:00
*
*/
function post () {
$channels = ( x ( $_POST , 'channel' ) ? $_POST [ 'channel' ] : Array () );
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
check_form_security_token_redirectOnErr ( '/admin/channels' , 'admin_channels' );
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
$xor = db_getfunc ( '^' );
2016-10-01 22:41:25 +00:00
if ( x ( $_POST , 'page_channels_block' )) {
foreach ( $channels as $uid ) {
2016-09-06 04:00:00 +00:00
q ( " UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d " ,
intval ( PAGE_CENSORED ),
intval ( $uid )
);
2016-10-01 22:41:25 +00:00
\Zotlabs\Daemon\Master :: Summon ( array ( 'Directory' , $uid , 'nopush' ));
2016-09-06 04:00:00 +00:00
}
notice ( sprintf ( tt ( " %s channel censored/uncensored " , " %s channels censored/uncensored " , count ( $channels )), count ( $channels )) );
}
2016-10-01 22:41:25 +00:00
if ( x ( $_POST , 'page_channels_code' )) {
foreach ( $channels as $uid ) {
2016-09-06 04:00:00 +00:00
q ( " UPDATE channel SET channel_pageflags = ( channel_pageflags $xor %d ) where channel_id = %d " ,
intval ( PAGE_ALLOWCODE ),
intval ( $uid )
);
}
notice ( sprintf ( tt ( " %s channel code allowed/disallowed " , " %s channels code allowed/disallowed " , count ( $channels )), count ( $channels )) );
}
2016-10-01 22:41:25 +00:00
if ( x ( $_POST , 'page_channels_delete' )) {
foreach ( $channels as $uid ) {
channel_remove ( $uid , true );
2016-09-06 04:00:00 +00:00
}
notice ( sprintf ( tt ( " %s channel deleted " , " %s channels deleted " , count ( $channels )), count ( $channels )) );
}
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
goaway ( z_root () . '/admin/channels' );
}
/**
2016-10-01 22:41:25 +00:00
* @ brief Generate channels admin page and handle single item operations .
2016-09-06 04:00:00 +00:00
*
2016-10-01 22:41:25 +00:00
* @ return string with parsed HTML
2016-09-06 04:00:00 +00:00
*/
function get () {
if ( argc () > 2 ) {
$uid = argv ( 3 );
$channel = q ( " SELECT * FROM channel WHERE channel_id = %d " ,
intval ( $uid )
);
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
if ( ! $channel ) {
notice ( t ( 'Channel not found' ) . EOL );
goaway ( z_root () . '/admin/channels' );
}
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
switch ( argv ( 2 )) {
case " delete " : {
check_form_security_token_redirectOnErr ( '/admin/channels' , 'admin_channels' , 't' );
// delete channel
channel_remove ( $uid , true );
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
notice ( sprintf ( t ( " Channel '%s' deleted " ), $channel [ 0 ][ 'channel_name' ]) . EOL );
}; break ;
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
case " block " : {
check_form_security_token_redirectOnErr ( '/admin/channels' , 'admin_channels' , 't' );
2016-10-01 22:41:25 +00:00
$pflags = $channel [ 0 ][ 'channel_pageflags' ] ^ PAGE_CENSORED ;
2016-09-06 04:00:00 +00:00
q ( " UPDATE channel SET channel_pageflags = %d where channel_id = %d " ,
intval ( $pflags ),
intval ( $uid )
);
\Zotlabs\Daemon\Master :: Summon ( array ( 'Directory' , $uid , 'nopush' ));
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
notice ( sprintf ( (( $pflags & PAGE_CENSORED ) ? t ( " Channel '%s' censored " ) : t ( " Channel '%s' uncensored " )) , $channel [ 0 ][ 'channel_name' ] . ' (' . $channel [ 0 ][ 'channel_address' ] . ')' ) . EOL );
}; break ;
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
case " code " : {
check_form_security_token_redirectOnErr ( '/admin/channels' , 'admin_channels' , 't' );
2016-10-01 22:41:25 +00:00
$pflags = $channel [ 0 ][ 'channel_pageflags' ] ^ PAGE_ALLOWCODE ;
2016-09-06 04:00:00 +00:00
q ( " UPDATE channel SET channel_pageflags = %d where channel_id = %d " ,
intval ( $pflags ),
intval ( $uid )
);
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
notice ( sprintf ( (( $pflags & PAGE_ALLOWCODE ) ? t ( " Channel '%s' code allowed " ) : t ( " Channel '%s' code disallowed " )) , $channel [ 0 ][ 'channel_name' ] . ' (' . $channel [ 0 ][ 'channel_address' ] . ')' ) . EOL );
}; break ;
2016-10-01 22:41:25 +00:00
default :
2016-09-06 04:00:00 +00:00
break ;
}
goaway ( z_root () . '/admin/channels' );
}
$key = (( $_REQUEST [ 'key' ]) ? dbesc ( $_REQUEST [ 'key' ]) : 'channel_id' );
$dir = 'asc' ;
if ( array_key_exists ( 'dir' , $_REQUEST ))
$dir = (( intval ( $_REQUEST [ 'dir' ])) ? 'asc' : 'desc' );
$base = z_root () . '/admin/channels?f=' ;
$odir = (( $dir === 'asc' ) ? '0' : '1' );
/* get channels */
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
$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 );
}
$channels = q ( " SELECT * from channel where channel_removed = 0 and channel_system = 0 order by $key $dir limit %d offset %d " ,
intval ( \App :: $pager [ 'itemspage' ]),
intval ( \App :: $pager [ 'start' ])
);
if ( $channels ) {
for ( $x = 0 ; $x < count ( $channels ); $x ++ ) {
if ( $channels [ $x ][ 'channel_pageflags' ] & PAGE_CENSORED )
$channels [ $x ][ 'blocked' ] = true ;
else
$channels [ $x ][ 'blocked' ] = false ;
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
if ( $channels [ $x ][ 'channel_pageflags' ] & PAGE_ALLOWCODE )
$channels [ $x ][ 'allowcode' ] = true ;
else
$channels [ $x ][ 'allowcode' ] = false ;
}
}
2016-10-01 22:41:25 +00:00
$t = get_markup_template ( 'admin_channels.tpl' );
2016-09-06 04:00:00 +00:00
$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' ),
'$code' => t ( 'Allow Code' ),
'$uncode' => t ( 'Disallow Code' ),
'$h_channels' => t ( 'Channel' ),
'$base' => $base ,
'$odir' => $odir ,
2016-10-01 22:41:25 +00:00
'$th_channels' => array (
2016-09-06 04:00:00 +00:00
[ t ( 'UID' ), 'channel_id' ],
[ t ( 'Name' ), 'channel_name' ],
[ t ( 'Address' ), 'channel_address' ]),
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
'$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?' ),
2016-10-01 22:41:25 +00:00
'$form_security_token' => get_form_security_token ( 'admin_channels' ),
2016-09-06 04:00:00 +00:00
// values //
'$baseurl' => z_root (),
'$channels' => $channels ,
));
$o .= paginate ( $a );
2016-10-01 22:41:25 +00:00
2016-09-06 04:00:00 +00:00
return $o ;
}
}