aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Dircensor.php
blob: 90759e58dac3264ee125a0d8893f3f956e7be3a5 (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
<?php

namespace Zotlabs\Module;

use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Libzotdir;


class Dircensor extends Controller {

	function get() {
		if(! is_site_admin()) {
			return;
		}

		$dirmode = intval(get_config('system','directory_mode'));

		if(!in_array($dirmode, [DIRECTORY_MODE_PRIMARY, DIRECTORY_MODE_SECONDARY, DIRECTORY_MODE_STANDALONE])) {
			return;
		}

		$xchan = argv(1);

		if(! $xchan) {
			return;
		}

		$r = q("select * from xchan where xchan_hash = '%s'",
			dbesc($xchan)
		);

		if(! $r) {
			return;
		}

		$severity = intval($_REQUEST['severity'] ?? 0);
		$flag = DIRECTORY_FLAG_OK;

		if ($severity === 1) {
			$flag = DIRECTORY_FLAG_UNSAFE;
		}

		if ($severity === 2) {
			$flag = DIRECTORY_FLAG_HIDDEN;
		}
hz_syslog('flag: '. print_r($flag, true));
		Libzotdir::update($xchan, $r[0]['xchan_url'], true, $flag);

		q("update xchan set xchan_censored = %d where xchan_hash = '%s'",
			intval($flag),
			dbesc($xchan)
		);

		if($flag) {
			info( t('Entry censored') . EOL);
		}
		else {
			info( t('Entry OK') . EOL);
		}

		goaway(z_root() . '/directory');

	}

}