aboutsummaryrefslogblamecommitdiffstats
path: root/Zotlabs/Module/Moderate.php
blob: b4709f3bd0bcd0fc0ee44b3e0b43cd5d06a6b87a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                               

















                                                                                                                                                                                            













                                                                                                             





                                                                                                        













                                                                                                                                                       





                                                                             












                                                                                                                                   
                         
                 








                                                          
                                                                         



                          
 
<?php

namespace Zotlabs\Module;

require_once('include/conversation.php');


class Moderate extends \Zotlabs\Web\Controller {


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

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

		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) {
				if($action === 'approve') {
					q("update item set item_blocked = 0 where uid = %d and id = %d",
						intval(local_channel()),
						intval($post_id)
					);

					// update the parent's commented timestamp

					$z = q("select max(created) as commented from item where parent_mid = '%s' and uid = %d and item_delayed = 0 ",
						dbesc($r[0]['parent_mid']),
						intval(local_channel())
					);

					q("UPDATE item set commented = '%s', changed = '%s' WHERE id = %d",
						dbesc(($z) ? $z[0]['commented'] : (datetime_convert())),
						dbesc(datetime_convert()),
						intval($r[0]['parent'])
					);

					notice( t('Comment approved') . EOL);
				}
				elseif($action === 'drop') {
					drop_item($post_id,false);
					notice( t('Comment deleted') . EOL);
				} 
			
				$r = q("select * from item where id = %d",
					intval($post_id)
				);
				if($r) {
					xchan_query($r);
					$sync_item = fetch_post_tags($r);
					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));
				}
				goaway(z_root() . '/moderate');
			}
		}

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

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

	}

}