move superblock to core

This commit is contained in:
zotlabs 2020-03-19 21:08:50 -07:00
parent d5e78ab494
commit 72601039d2
8 changed files with 247 additions and 16 deletions

View file

@ -2,6 +2,8 @@
namespace Zotlabs\Lib;
use Zotlabs\Lib\LibBlock;
/**
* @brief File with functions and a class for generating system and email notifications.
*/
@ -512,6 +514,18 @@ class Enotify {
$datarray['item'] = $params['item'];
if (LibBlock::fetch_by_entity($datarray['uid'],$datarray['sender_hash'])) {
pop_lang();
return;
}
if (is_array($datarray['parent_item'])) {
if (LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['owner_xchan']) || LibBlock::fetch_by_entity($datarray['uid'],$datarray['parent_item']['owner_xchan'])) {
pop_lang();
return;
}
}
call_hooks('enotify_store', $datarray);
if ($datarray['abort']) {
@ -881,7 +895,9 @@ class Enotify {
}
}
if (LibBlock::fetch_by_entity(local_channel(),$item['author']['xchan_hash'])) {
return [];
}
// convert this logic into a json array just like the system notifications

View file

@ -6,6 +6,7 @@ use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Libzotdir;
use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\LibBlock;
require_once('include/socgraph.php');
require_once('include/bbcode.php');
@ -404,6 +405,10 @@ class Directory extends Controller {
'safe' => $safe_mode
];
if (LibBlock::fetch_by_entity(local_channel(), $entry['hash'])) {
continue;
}
$arr = array('contact' => $rr, 'entry' => $entry);
call_hooks('directory_item', $arr);

View file

@ -0,0 +1,113 @@
<?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;
}
$handled = false;
$ignored = [];
if (array_key_exists('block',$_GET) && trim($_GET['block'])) {
$handled = true;
$r = q("select id from item where id = %d and author_xchan = '%s' limit 1",
intval($_GET['item']),
dbesc($_GET['block'])
);
if ($r) {
$bl = [
'block_channel_id' => local_channel(),
'block_entity' => trim($_GET['block']),
'block_type' => BLOCKTYPE_CHANNEL,
'block_comment' => t('Added by Superblock')
];
LibBlock::store($bl);
$sync = LibBlock::fetch_by_entity(local_channel(),trim($_GET['block']));
$z = q("insert into xign ( uid, xchan ) values ( %d , '%s' ) ",
intval(local_channel()),
dbesc(trim($_GET['block']))
);
$ignored = [ 'uid' => local_channel(), 'xchan' => $_GET['block'] ];
Libsync::build_sync_packet(0, [ 'xign' => [ $ignored ], 'block' => $sync ] );
}
}
if (array_key_exists('unblock',$_GET) && trim($_GET['unblock'])) {
$handled = true;
if (check_form_security_token('superblock','sectok')) {
$r = LibBlock::fetch_by_entity(local_channel(), trim($_GET['unblock']));
if ($r) {
LibBlock::remove(local_channel(), trim($_GET['unblock']));
$z = q("delete from xign where uid = %d and xchan = '%s' ",
intval(local_channel()),
dbesc($_GET['block'])
);
$ignored = [ 'uid' => local_channel(), 'xchan' => $_GET['block'], 'deleted' => true ];
$r['deleted'] = true;
Libsync::build_sync_packet(0, [ 'xign' => [ $ignored ], 'block' => $r ] );
}
}
}
if ($handled) {
info( t('superblock settings updated') . EOL );
if ($_GET['unblock']) {
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'), [
'$blocked' => t('Currently blocked'),
'$entries' => $r,
'$nothing' => (($r) ? '' : t('No channels currently blocked')),
'$token' => get_form_security_token('superblock'),
'$remove' => t('Remove')
]);
$s .= replace_macros(get_markup_template('generic_app_settings.tpl'), [
'$addon' => array('superblock', t('Superblock Settings'), '', t('Submit')),
'$content' => $sc
]);
return $s;
}
}

View file

@ -2,19 +2,25 @@
namespace Zotlabs\Widget;
use Zotlabs\Lib\LibBlock;
class Activity {
function widget($arr) {
if(! local_channel())
if (! local_channel()) {
return '';
}
$o = '';
$o = EMPTY_STR;
if(is_array($arr) && array_key_exists('limit',$arr))
if (is_array($arr) && array_key_exists('limit',$arr)) {
$limit = " limit " . intval($limit) . " ";
else
$limit = '';
}
else {
$limit = EMPTY_STR;
}
$perms_sql = item_permissions_sql(local_channel()) . item_normal();
@ -25,9 +31,9 @@ class Activity {
$contributors = [];
$arr = [];
if($r) {
foreach($r as $rv) {
if(array_key_exists($rv['author_xchan'],$contributors)) {
if ($r) {
foreach ($r as $rv) {
if (array_key_exists($rv['author_xchan'],$contributors)) {
$contributors[$rv['author_xchan']] ++;
}
else {
@ -35,7 +41,9 @@ class Activity {
}
}
foreach($contributors as $k => $v) {
$arr[] = [ 'author_xchan' => $k, 'total' => $v ];
if (! LibBlock::fetch_by_entity(local_channel(), $k)) {
$arr[] = [ 'author_xchan' => $k, 'total' => $v ];
}
}
usort($arr,'total_sort');
xchan_query($arr);

View file

@ -1,6 +1,7 @@
<?php /** @file */
use Zotlabs\Lib\Apps;
use Zotlabs\Lib\LibBlock;
function item_extract_images($body) {
@ -992,12 +993,14 @@ function thread_author_menu($item, $mode = '') {
$menu = [];
$local_channel = local_channel();
$blocked = false;
if($local_channel) {
if(! count(App::$contacts))
load_contact_links($local_channel);
$channel = App::get_channel();
$channel_hash = (($channel) ? $channel['channel_hash'] : '');
$blocked = LibBlock::fetch_by_entity($local_channel,$item['author_xchan']);
}
$profile_link = chanlink_hash($item['author_xchan']);
@ -1012,10 +1015,6 @@ function thread_author_menu($item, $mode = '') {
$follow_url = z_root() . '/follow/?f=&url=' . urlencode(($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']) . '&interactive=0';
}
}
// if($item['uid'] > 0 && author_is_pmable($item['author'],$contact)) {
// $pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']);
// }
}
if($contact) {
@ -1078,6 +1077,16 @@ function thread_author_menu($item, $mode = '') {
];
}
if (! $blocked) {
$menu[] = [
'menu' => 'superblock',
'title' => t('Block completely'),
'icon' => 'fw',
'action' => 'superblock(\'' . urlencode($item['author_xchan']) . '\',' . $item['id'] . '); return false;',
'href' => '#'
];
}
$args = [ 'item' => $item, 'mode' => $mode, 'menu' => $menu ];
call_hooks('thread_author_menu', $args);
@ -1580,7 +1589,56 @@ function conv_sort($arr, $order) {
return $ret;
}
$data = [ 'items' => $arr, 'order' => $order ];
$narr = [];
foreach ($arr as $item) {
if (LibBlock::fetch_by_entity(local_channel(),$item['author_xchan']) || LibBlock::fetch_by_entity(local_channel(),$item['author_xchan'])) {
continue;
}
$matches = null;
$found = false;
$cnt = preg_match_all("/\[share(.*?)portable_id='(.*?)'(.*?)\]/ism", $item['body'], $matches, PREG_SET_ORDER);
if ($cnt) {
foreach ($matches as $match) {
if ($sb->match($match[2])) {
$found = true;
}
}
}
if ($found) {
continue;
}
$matches = null;
$found = false;
$cnt = preg_match_all("/\[share(.*?)profile='(.*?)'(.*?)\]/ism", $item['body'], $matches, PREG_SET_ORDER);
if ($cnt) {
foreach ($matches as $match) {
$r = q("select hubloc_hash from hubloc where hubloc_id_url = '%s'",
dbesc($match[2])
);
if ($r) {
if (LibBlock::fetch_by_entity(local_channel(),$r[0]['hubloc_hash'])) {
$found = true;
}
}
}
}
if ($found) {
continue;
}
$narr[] = $item;
}
$data = [ 'items' => $narr, 'order' => $order ];
call_hooks('conv_sort', $data);

View file

@ -1780,10 +1780,17 @@ function item_store($arr, $allow_exec = false, $deliver = true, $linkid = true)
return $ret;
}
if (LibBlock::fetch_by_entity($arr['uid'],$arr['owner_chan']) || LibBlock::fetch_by_entity($arr['uid'],$arr['author_xchan'])) {
logger('Post cancelled by block rule.');
$ret['message'] = 'cancelled.';
return $ret;
}
/**
* @hooks item_store
* Called when item_store() stores a record of type item.
*/
call_hooks('item_store', $arr);
/**

View file

@ -231,6 +231,12 @@ var activeCommentText = '';
}
}
function superblock(author,item) {
$.get('superblock?f=&item=' + item + '&block=' + author, function(data) {
location.reload(true);
});
}
function jotGetExpiry() {
//reply = prompt("{{$expirewhen}}", $('#jot-expire').val());
$('#expiryModal').modal();

View file

@ -0,0 +1,18 @@
<h3>{{$blocked}}</h3>
<br>
{{if $nothing}}
<div class="descriptive-text">{{$nothing}}</div>
<br>
{{/if}}
{{if $entries}}
<ul style="list-style-type: none;">
{{foreach $entries as $e}}
<li>
<div>
<a class="pull-right" href="superblock?f=&unblock={{$e.encoded_hash}}&sectok={{$token}}" title="{{$remove}}"><i class="fa fa-trash"></i></a>
<a class="zid" href="{{$e.xchan_url}}"><img src="{{$e.xchan_photo_s}}" alt="{{$e.encoded_hash}}">&nbsp;{{$e.xchan_name}}</a>
</div>
</li>
{{/foreach}}
</ul>
{{/if}}