streams/Code/Module/Moderate.php

145 lines
4.6 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2021-04-13 03:49:58 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Libsync;
use Code\Daemon\Run;
2022-09-04 00:01:52 +00:00
use Code\Access\PermissionRoles;
2018-06-01 04:05:09 +00:00
require_once('include/conversation.php');
2021-12-02 23:02:31 +00:00
class Moderate extends Controller
{
public function get()
{
if (!local_channel()) {
notice(t('Permission denied.') . EOL);
2022-09-04 00:01:52 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
App::set_pager_itemspage(60);
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
2022-07-20 11:26:28 +00:00
$mid = ((!empty($_REQUEST['mid'])) ? $_REQUEST['mid'] : '');
2021-12-02 23:02:31 +00:00
//show all items
2022-07-20 11:26:28 +00:00
if (argc() == 1 && !$mid) {
2021-12-03 03:01:39 +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",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
intval(ITEM_MODERATED)
);
if (!$r) {
2022-09-22 10:34:28 +00:00
info(t('No posts requiring approval at this time.') . EOL);
2021-12-02 23:02:31 +00:00
}
}
// show a single item
2022-07-20 11:26:28 +00:00
$action = '';
if (argc() == 1 && $mid) {
$action = 'view';
}
if (argc() == 2 && !$mid) {
$mid = argv(1);
$action = 'view';
}
if ($action) {
$post_id = unpack_link_id(escape_tags($mid));
2021-12-02 23:02:31 +00:00
2021-12-03 03:01:39 +00:00
$r = q(
"select item.id as item_id, item.* from item where item.mid = '%s' and item.uid = %d and item_blocked = %d and item_deleted = 0 order by created desc $pager_sql",
2021-12-02 23:02:31 +00:00
dbesc($post_id),
intval(local_channel()),
intval(ITEM_MODERATED)
);
}
2022-07-20 11:26:28 +00:00
$action = '';
if (argc() > 2 && !$mid) {
$mid = intval(argv(1));
$action = argv(2);
}
elseif (argc() == 2 && $mid) {
$action = argv(1);
}
$post_id = $mid;
if ($action) {
2021-12-03 03:01:39 +00:00
if (!$post_id) {
2021-12-02 23:02:31 +00:00
goaway(z_root() . '/moderate');
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
2021-12-03 03:01:39 +00:00
$r = q(
"select * from item where uid = %d and id = %d and item_blocked = %d limit 1",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
intval($post_id),
intval(ITEM_MODERATED)
);
if ($r) {
$item = $r[0];
if ($action === 'approve') {
2021-12-03 03:01:39 +00:00
q(
"update item set item_blocked = 0 where uid = %d and id = %d",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
intval($post_id)
);
$item['item_blocked'] = 0;
item_update_parent_commented($item);
2022-11-30 06:23:24 +00:00
// \Code\Lib\Activity::send_accept_activity(App::get_channel(),$item['author'], $item, $parent_item);
2021-12-02 23:02:31 +00:00
notice(t('Comment approved') . EOL);
} elseif ($action === 'drop') {
drop_item($post_id);
2021-12-02 23:02:31 +00:00
notice(t('Comment deleted') . EOL);
}
// refetch the item after changes have been made
2021-12-03 03:01:39 +00:00
$r = q(
"select * from item where id = %d",
2021-12-02 23:02:31 +00:00
intval($post_id)
);
if ($r) {
xchan_query($r);
$sync_item = fetch_post_tags($r);
2022-09-04 00:01:52 +00:00
Libsync::build_sync_packet(local_channel(), ['item' => [encode_item($sync_item[0], true)]]);
2021-12-02 23:02:31 +00:00
}
if ($action === 'approve') {
if ($item['id'] !== $item['parent']) {
// if this is a group comment, call tag_deliver() to generate the associated
// Announce activity so microblog destinations will see it in their home timeline
$role = get_pconfig(local_channel(), 'system', 'permissions_role');
$rolesettings = PermissionRoles::role_perms($role);
$channel_type = $rolesettings['channel_type'] ?? 'normal';
2021-12-02 23:02:31 +00:00
$is_group = $channel_type === 'group';
2021-12-02 23:02:31 +00:00
if ($is_group) {
tag_deliver(local_channel(), $post_id);
}
}
Run::Summon(['Notifier', 'comment-new', $post_id]);
}
goaway(z_root() . '/moderate');
}
}
if ($r) {
xchan_query($r);
$items = fetch_post_tags($r);
2021-12-02 23:02:31 +00:00
} else {
$items = [];
}
$o = conversation($items, 'moderate', false);
2021-12-02 23:02:31 +00:00
$o .= alt_pager(count($items));
return $o;
}
2017-10-06 20:25:53 +00:00
}