2017-06-19 05:25:41 +00:00
< ? php
namespace Zotlabs\Module ;
2018-06-05 01:40:11 +00:00
use Zotlabs\Lib\Libsync ;
2018-06-01 04:05:09 +00:00
2017-06-19 05:25:41 +00:00
require_once ( 'include/conversation.php' );
class Moderate extends \Zotlabs\Web\Controller {
function get () {
if ( ! local_channel ()) {
notice ( t ( 'Permission denied.' ) . EOL );
return ;
}
2018-04-18 06:36:35 +00:00
\App :: set_pager_itemspage ( 60 );
$pager_sql = sprintf ( " LIMIT %d OFFSET %d " , intval ( \App :: $pager [ 'itemspage' ]), intval ( \App :: $pager [ 'start' ]));
2017-10-19 09:20:09 +00:00
//show all items
if ( argc () == 1 ) {
2018-04-18 06:36:35 +00:00
$r = q ( " select item.id as item_id, item.* from item where item.uid = %d and item_blocked = %d and item_deleted = 0 order by created desc $pager_sql " ,
2017-10-19 09:20:09 +00:00
intval ( local_channel ()),
intval ( ITEM_MODERATED )
);
}
//show a single item
if ( argc () == 2 ) {
$post_id = intval ( argv ( 1 ));
2018-04-18 06:36:35 +00:00
$r = q ( " select item.id as item_id, item.* from item where item.id = %d and item.uid = %d and item_blocked = %d and item_deleted = 0 order by created desc $pager_sql " ,
2017-10-19 09:20:09 +00:00
intval ( $post_id ),
intval ( local_channel ()),
intval ( ITEM_MODERATED )
);
}
2017-06-19 05:25:41 +00:00
if ( argc () > 2 ) {
$post_id = intval ( argv ( 1 ));
if ( ! $post_id )
goaway ( z_root () . '/moderate' );
$action = argv ( 2 );
$r = q ( " select * from item where uid = %d and id = %d and item_blocked = %d limit 1 " ,
intval ( local_channel ()),
intval ( $post_id ),
intval ( ITEM_MODERATED )
);
if ( $r ) {
2018-03-24 09:22:24 +00:00
$item = $r [ 0 ];
2017-06-19 05:25:41 +00:00
if ( $action === 'approve' ) {
q ( " update item set item_blocked = 0 where uid = %d and id = %d " ,
intval ( local_channel ()),
intval ( $post_id )
);
2018-03-22 05:52:24 +00:00
2018-03-24 09:22:24 +00:00
$item [ 'item_blocked' ] = 0 ;
2018-03-22 05:52:24 +00:00
2018-03-24 09:22:24 +00:00
item_update_parent_commented ( $item );
2018-03-22 05:52:24 +00:00
2017-06-19 05:25:41 +00:00
notice ( t ( 'Comment approved' ) . EOL );
}
elseif ( $action === 'drop' ) {
drop_item ( $post_id , false );
notice ( t ( 'Comment deleted' ) . EOL );
}
2018-03-24 09:22:24 +00:00
// refetch the item after changes have been made
2017-06-20 19:45:05 +00:00
$r = q ( " select * from item where id = %d " ,
intval ( $post_id )
);
if ( $r ) {
xchan_query ( $r );
$sync_item = fetch_post_tags ( $r );
2018-06-05 01:40:11 +00:00
Libsync :: build_sync_packet ( local_channel (), array ( 'item' => array ( encode_item ( $sync_item [ 0 ], true ))));
2017-06-20 19:45:05 +00:00
}
if ( $action === 'approve' ) {
\Zotlabs\Daemon\Master :: Summon ( array ( 'Notifier' , 'comment-new' , $post_id ));
}
goaway ( z_root () . '/moderate' );
2017-06-19 05:25:41 +00:00
}
}
if ( $r ) {
xchan_query ( $r );
$items = fetch_post_tags ( $r , true );
}
else {
$items = array ();
}
2017-06-20 22:53:01 +00:00
$o = conversation ( $items , 'moderate' , false , 'traditional' );
2018-04-18 06:36:35 +00:00
$o .= alt_pager ( count ( $items ));
2017-06-19 05:25:41 +00:00
return $o ;
}
2017-10-06 20:25:53 +00:00
}