aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Moderate.php
blob: 2103684abf0ebe3c92b0bf2ee798d8bf31df6dc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

namespace Zotlabs\Module;

use Zotlabs\Lib\Libsync;

require_once('include/conversation.php');


class Moderate extends \Zotlabs\Web\Controller {


	function get() {
		if(! local_channel()) {
			notice( t('Permission denied.') . EOL);
			return;
		}

		\App::set_pager_itemspage(30);
		$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));

		//show all items
		if(argc() == 1) {
			$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",
				intval(local_channel()),
				intval(ITEM_MODERATED)
			);
		}

		//show a single item
		if(argc() == 2) {
			$post_id = intval(argv(1));

			$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",
				intval($post_id),
				intval(local_channel()),
				intval(ITEM_MODERATED)
			);
		}

		if(argc() > 2) {
			$post_id = intval(argv(1));
			if(! $post_id) {
				if (is_ajax()) {
					killme();
				}

				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) {
				$item = $r[0];

				if($action === 'approve') {
					q("update item set item_blocked = 0 where uid = %d and id = %d",
						intval(local_channel()),
						intval($post_id)
					);

					$item['item_blocked'] = 0;
					item_update_parent_commented($item);
					notice( t('Item approved') . EOL);
				}
				elseif($action === 'drop') {
					// TODO: not implemented
					// let the sender know we received their comment but we don't permit spam here.
					// Activity::send_rejection_activity(App::get_channel(), $item['author_xchan'], $item);

					drop_item($post_id);
					notice( t('Item deleted') . EOL);
				}

				// refetch the item after changes have been made

				$r = q("select * from item where id = %d",
					intval($post_id)
				);
				if($r) {
					xchan_query($r);
					$sync_item = fetch_post_tags($r);
					Libsync::build_sync_packet(local_channel(),array('item' => array(encode_item($sync_item[0],true))));
				}
				if($action === 'approve') {
					\Zotlabs\Daemon\Master::Summon(array('Notifier', 'comment-new', $post_id));
				}

				if (is_ajax()) {
					killme();
				}

				goaway(z_root() . '/moderate');
			}
		}

		if($r) {
			xchan_query($r);
			$items = fetch_post_tags($r,true);
		}
		else {
			$items = array();
		}

		$o = conversation($items,'moderate',false,'traditional');
		$o .= alt_pager(count($items));
		return $o;

	}

}