2020-03-20 04:08:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Module;
|
|
|
|
|
|
|
|
use App;
|
|
|
|
use Zotlabs\Web\Controller;
|
|
|
|
use Zotlabs\Lib\Apps;
|
|
|
|
use Zotlabs\Lib\Libsync;
|
|
|
|
use Zotlabs\Lib\LibBlock;
|
|
|
|
|
|
|
|
class Superblock extends Controller {
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
|
|
|
|
if (! local_channel()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-17 11:08:04 +00:00
|
|
|
|
|
|
|
$type = BLOCKTYPE_CHANNEL;
|
|
|
|
$blocked = trim($_GET['block']);
|
|
|
|
if (! $blocked) {
|
|
|
|
$blocked = trim($_GET['blocksite']);
|
|
|
|
if ($blocked) {
|
|
|
|
$type = BLOCKTYPE_SERVER;
|
|
|
|
}
|
|
|
|
}
|
2020-03-20 04:08:50 +00:00
|
|
|
|
|
|
|
$handled = false;
|
|
|
|
$ignored = [];
|
2020-04-17 11:08:04 +00:00
|
|
|
|
|
|
|
if ($blocked) {
|
2020-03-20 04:08:50 +00:00
|
|
|
$handled = true;
|
2020-04-17 11:08:04 +00:00
|
|
|
$r = q("select xchan_url from xchan where xchan_hash = '%s' limit 1",
|
|
|
|
dbesc($blocked)
|
2020-03-20 04:08:50 +00:00
|
|
|
);
|
|
|
|
if ($r) {
|
2020-04-17 11:08:04 +00:00
|
|
|
if ($type === BLOCKTYPE_SERVER) {
|
|
|
|
$m = parse_url($r[0]['xchan_url']);
|
|
|
|
if ($m) {
|
|
|
|
$blocked = $m['host'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 04:08:50 +00:00
|
|
|
$bl = [
|
|
|
|
'block_channel_id' => local_channel(),
|
2020-04-18 03:36:29 +00:00
|
|
|
'block_entity' => $blocked,
|
|
|
|
'block_type' => $type,
|
|
|
|
'block_comment' => t('Added by Superblock')
|
2020-03-20 04:08:50 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
LibBlock::store($bl);
|
|
|
|
|
2020-04-18 03:36:29 +00:00
|
|
|
$sync = LibBlock::fetch_by_entity(local_channel(),$blocked);
|
|
|
|
|
|
|
|
if ($type === BLOCKTYPE_CHANNEL) {
|
|
|
|
$z = q("insert into xign ( uid, xchan ) values ( %d , '%s' ) ",
|
|
|
|
intval(local_channel()),
|
|
|
|
dbesc($blocked)
|
|
|
|
);
|
2020-03-20 04:08:50 +00:00
|
|
|
|
2020-04-18 03:36:29 +00:00
|
|
|
$ignored = [ 'uid' => local_channel(), 'xchan' => $_GET['block'] ];
|
|
|
|
Libsync::build_sync_packet(0, [ 'xign' => [ $ignored ], 'block' => [ $sync ]] );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Libsync::build_sync_packet(0, [ 'block' => [ $sync ]] );
|
|
|
|
}
|
2020-03-20 04:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-18 03:36:29 +00:00
|
|
|
|
|
|
|
$type = BLOCKTYPE_CHANNEL;
|
|
|
|
$unblocked = trim($_GET['unblock']);
|
|
|
|
if (! $unblocked) {
|
|
|
|
$unblocked = trim($_GET['unblocksite']);
|
|
|
|
if ($unblocked) {
|
|
|
|
$type = BLOCKTYPE_SERVER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($unblocked) {
|
2020-03-20 04:08:50 +00:00
|
|
|
$handled = true;
|
|
|
|
if (check_form_security_token('superblock','sectok')) {
|
2020-04-18 03:36:29 +00:00
|
|
|
$r = LibBlock::fetch_by_entity(local_channel(), $unblocked);
|
2020-03-20 04:08:50 +00:00
|
|
|
if ($r) {
|
2020-04-18 03:36:29 +00:00
|
|
|
LibBlock::remove(local_channel(), $unblocked);
|
|
|
|
if ($type === BLOCKTYPE_CHANNEL) {
|
|
|
|
$z = q("delete from xign where uid = %d and xchan = '%s' ",
|
|
|
|
intval(local_channel()),
|
|
|
|
dbesc($unblocked)
|
|
|
|
);
|
|
|
|
$ignored = [ 'uid' => local_channel(), 'xchan' => $unblocked, 'deleted' => true ];
|
|
|
|
$r['deleted'] = true;
|
|
|
|
Libsync::build_sync_packet(0, [ 'xign' => [ $ignored ], 'block' => [ $r ]] );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$r['deleted'] = true;
|
|
|
|
Libsync::build_sync_packet(0, [ 'block' => [ $r ]] );
|
|
|
|
}
|
2020-03-20 04:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($handled) {
|
|
|
|
|
|
|
|
info( t('superblock settings updated') . EOL );
|
|
|
|
|
2020-04-18 03:36:29 +00:00
|
|
|
if ($unblocked) {
|
2020-03-20 04:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function get() {
|
|
|
|
|
|
|
|
$l = LibBlock::fetch(local_channel(),BLOCKTYPE_CHANNEL);
|
|
|
|
$list = ids_to_array($l,'block_entity');
|
|
|
|
|
|
|
|
stringify_array_elms($list,true);
|
|
|
|
$query_str = implode(',',$list);
|
|
|
|
if ($query_str) {
|
|
|
|
$r = q("select * from xchan where xchan_hash in ( " . $query_str . " ) ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$r = [];
|
|
|
|
}
|
|
|
|
if ($r) {
|
|
|
|
for ($x = 0; $x < count($r); $x ++) {
|
|
|
|
$r[$x]['encoded_hash'] = urlencode($r[$x]['xchan_hash']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sc .= replace_macros(get_markup_template('superblock_list.tpl'), [
|
2020-04-18 03:36:29 +00:00
|
|
|
'$blocked' => t('Blocked channels'),
|
2020-03-20 04:08:50 +00:00
|
|
|
'$entries' => $r,
|
|
|
|
'$nothing' => (($r) ? '' : t('No channels currently blocked')),
|
|
|
|
'$token' => get_form_security_token('superblock'),
|
|
|
|
'$remove' => t('Remove')
|
|
|
|
]);
|
|
|
|
|
2020-04-18 03:36:29 +00:00
|
|
|
$l = LibBlock::fetch(local_channel(),BLOCKTYPE_SERVER);
|
|
|
|
$list = ids_to_array($l,'block_entity');
|
|
|
|
if ($list) {
|
|
|
|
for ($x = 0; $x < count($list); $x ++ ) {
|
|
|
|
$list[$x] = [ $list[$x], urlencode($list[$x]) ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sc .= replace_macros(get_markup_template('superblock_serverlist.tpl'), [
|
|
|
|
'$blocked' => t('Blocked servers'),
|
|
|
|
'$entries' => $list,
|
|
|
|
'$nothing' => (($list) ? '' : t('No servers currently blocked')),
|
|
|
|
'$token' => get_form_security_token('superblock'),
|
|
|
|
'$remove' => t('Remove')
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-20 04:08:50 +00:00
|
|
|
$s .= replace_macros(get_markup_template('generic_app_settings.tpl'), [
|
2020-04-18 03:36:29 +00:00
|
|
|
'$addon' => array('superblock', t('Manage Blocks'), '', t('Submit')),
|
2020-03-20 04:08:50 +00:00
|
|
|
'$content' => $sc
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $s;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|