aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMax Kostikov <max@kostikov.co>2020-07-19 14:58:19 +0200
committerMax Kostikov <max@kostikov.co>2020-07-19 14:58:19 +0200
commit5ea7196e78d08550b3ec93d3b708f915b3b0057f (patch)
tree07e5f865b6c83898d7ac508302a227509e8207fd /include
parentd0c7c99d5e1eb27281431231640c7e8c019b90e1 (diff)
parentfcc47e69e424635fa54b2684329623d4f7694436 (diff)
downloadvolse-hubzilla-5ea7196e78d08550b3ec93d3b708f915b3b0057f.tar.gz
volse-hubzilla-5ea7196e78d08550b3ec93d3b708f915b3b0057f.tar.bz2
volse-hubzilla-5ea7196e78d08550b3ec93d3b708f915b3b0057f.zip
Merge branch 'dev' into 'dev'
Dev sync See merge request kostikov/core!1
Diffstat (limited to 'include')
-rw-r--r--include/channel.php4
-rw-r--r--include/help.php2
-rwxr-xr-xinclude/items.php166
-rw-r--r--include/nav.php8
-rw-r--r--include/network.php48
-rw-r--r--include/text.php2
6 files changed, 189 insertions, 41 deletions
diff --git a/include/channel.php b/include/channel.php
index 210b6ae91..05f1bd34b 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -129,10 +129,10 @@ function create_sys_channel() {
* @return array|boolean
*/
function get_sys_channel() {
- $r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_system = 1 limit 1");
+ $r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_system = 1");
if ($r)
- return $r[0];
+ return Libzot::zot_record_preferred($r, 'xchan_network');
return false;
}
diff --git a/include/help.php b/include/help.php
index e82fa96da..affe64495 100644
--- a/include/help.php
+++ b/include/help.php
@@ -223,7 +223,7 @@ function find_doc_file($s) {
*/
function search_doc_files($s) {
- \App::set_pager_itemspage(60);
+ \App::set_pager_itemspage(30);
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
$regexop = db_getfunc('REGEXP');
diff --git a/include/items.php b/include/items.php
index a566ddfd9..dc76af31b 100755
--- a/include/items.php
+++ b/include/items.php
@@ -12,6 +12,7 @@ use Zotlabs\Lib\IConfig;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Libsync;
use Zotlabs\Access\PermissionLimits;
+use Zotlabs\Access\PermissionRoles;
use Zotlabs\Access\AccessList;
use Zotlabs\Daemon\Master;
@@ -290,7 +291,7 @@ function is_item_normal($item) {
*/
function can_comment_on_post($observer_xchan, $item) {
-// logger('Comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG);
+ // logger('Comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG);
$x = [
'observer_hash' => $observer_xchan,
@@ -351,7 +352,8 @@ function can_comment_on_post($observer_xchan, $item) {
return true;
}
break;
- default:
+
+ default:
break;
}
if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red')) {
@@ -2628,6 +2630,12 @@ function get_item_contact($item,$contacts) {
*/
function tag_deliver($uid, $item_id) {
+ $role = get_pconfig($uid,'system','permissions_role');
+ $rolesettings = PermissionRoles::role_perms($role);
+ $channel_type = isset($rolesettings['channel_type']) ? $rolesettings['channel_type'] : 'normal';
+
+ $is_group = (($channel_type === 'group') ? true : false);
+
$mention = false;
/*
@@ -2647,18 +2655,43 @@ function tag_deliver($uid, $item_id) {
if(! $i)
return;
+ xchan_query($i,true);
$i = fetch_post_tags($i);
$item = $i[0];
- if(($item['source_xchan']) && intval($item['item_uplink'])
+ if(intval($item['item_uplink']) && $item['source_xchan']
&& intval($item['item_thread_top']) && ($item['edited'] != $item['created'])) {
// this is an update (edit) to a post which was already processed by us and has a second delivery chain
// Just start the second delivery chain to deliver the updated post
// after resetting ownership and permission bits
logger('updating edited tag_deliver post for ' . $u[0]['channel_address']);
- start_delivery_chain($u[0], $item, $item_id, 0, true);
+ start_delivery_chain($u[0], $item, $item_id, 0, false, true);
+ return;
+ }
+
+ if ($is_group && intval($item['item_private']) === 2 && intval($item['item_thread_top'])) {
+ // group delivery via DM
+ if(perm_is_allowed($uid,$item['owner_xchan'],'post_wall') || perm_is_allowed($uid,$item['owner_xchan'],'tag_deliver')) {
+ logger('group DM delivery for ' . $u[0]['channel_address']);
+ start_delivery_chain($u[0], $item, $item_id, 0, true, (($item['edited'] != $item['created']) || $item['item_deleted']));
+ }
+ return;
+ }
+
+
+ if ($is_group && intval($item['item_thread_top']) && intval($item['item_wall']) && $item['author_xchan'] !== $item['owner_xchan']) {
+ if (strpos($item['body'],'[/share]')) {
+ logger('W2W post already shared');
+ return;
+ }
+ // group delivery via W2W
+ logger('rewriting W2W post for ' . $u[0]['channel_address']);
+ start_delivery_chain($u[0], $item, $item_id, 0, true, (($item['edited'] != $item['created']) || $item['item_deleted']));
+ q("update item set item_wall = 0 where id = %d",
+ intval($item_id)
+ );
return;
}
@@ -2965,6 +2998,13 @@ function item_community_tag($channel,$item) {
*/
function tgroup_check($uid, $item) {
+
+ $role = get_pconfig($uid,'system','permissions_role');
+ $rolesettings = PermissionRoles::role_perms($role);
+ $channel_type = isset($rolesettings['channel_type']) ? $rolesettings['channel_type'] : 'normal';
+
+ $is_group = (($channel_type === 'group') ? true : false);
+
$mention = false;
// check that the message originated elsewhere and is a top-level post
@@ -2981,6 +3021,15 @@ function tgroup_check($uid, $item) {
return false;
}
+ // post to group via DM
+
+ if ($is_group) {
+ if (intval($item['item_private']) === 2 && $item['mid'] === $item['parent_mid']) {
+ return true;
+ }
+ }
+
+
// see if we already have this item. Maybe it is being updated.
$r = q("select id from item where mid = '%s' and uid = %d limit 1",
@@ -3089,7 +3138,7 @@ function tgroup_check($uid, $item) {
* @param boolean $edit (optional) default false
* @return void
*/
-function start_delivery_chain($channel, $item, $item_id, $parent, $edit = false) {
+function start_delivery_chain($channel, $item, $item_id, $parent, $group = false, $edit = false) {
$sourced = check_item_source($channel['channel_id'],$item);
@@ -3136,6 +3185,107 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $edit = false)
}
}
+ if ($group && (! $parent)) {
+
+ $arr = [];
+
+ if ($edit) {
+ // process edit or delete action
+ $r = q("select * from item where source_xchan = '%s' and body like '%s' and uid = %d limit 1",
+ dbesc($item['owner_xchan']),
+ dbesc("%message_id='" . $item['mid'] . "'%"),
+ intval($channel['channel_id'])
+ );
+ if ($r) {
+ if (intval($item['item_deleted'])) {
+ drop_item($r[0]['id'],false,DROPITEM_PHASE1);
+ Master::Summon([ 'Notifier','drop',$r[0]['id'] ]);
+ return;
+ }
+ $arr['id'] = intval($r[0]['id']);
+ $arr['parent'] = intval($r[0]['parent']);
+ $arr['uuid'] = $r[0]['uuid'];
+ $arr['mid'] = $r[0]['mid'];
+ $arr['parent_mid'] = $r[0]['parent_mid'];
+ $arr['edited'] = datetime_convert();
+ }
+ else {
+ logger('unable to locate original group post ' . $item['mid']);
+ return;
+ }
+
+ }
+ else {
+ $arr['uuid'] = item_message_id();
+ $arr['mid'] = z_root() . '/activity/' . $arr['uuid'];
+ $arr['parent_mid'] = $arr['mid'];
+ }
+
+ $arr['aid'] = $channel['channel_account_id'];
+ $arr['uid'] = $channel['channel_id'];
+
+ // WARNING: the presence of both source_xchan and non-zero item_uplink here will cause a delivery loop
+
+ $arr['item_uplink'] = 0;
+ $arr['source_xchan'] = $item['owner_xchan'];
+
+ $arr['item_private'] = (($channel['channel_allow_cid'] || $channel['channel_allow_gid']
+ || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0);
+
+ $arr['item_origin'] = 1;
+ $arr['item_wall'] = 1;
+
+ $arr['item_thread_top'] = 1;
+
+ if (strpos($item['body'], "[/share]") !== false) {
+ $pos = strpos($item['body'], "[share");
+ $bb = substr($item['body'], $pos);
+ } else {
+ $bb = "[share author='" . urlencode($item['author']['xchan_name']).
+ "' profile='" . $item['author']['xchan_url'] .
+ "' portable_id='" . $item['author']['xchan_hash'] .
+ "' avatar='" . $item['author']['xchan_photo_s'] .
+ "' link='" . $item['plink'] .
+ "' auth='" . ((in_array($item['author']['network'], ['zot','zot6'])) ? 'true' : 'false') .
+ "' posted='" . $item['created'] .
+ "' message_id='" . $item['mid'] .
+ "']";
+ if($item['title'])
+ $bb .= '[b]'.$item['title'].'[/b]'."\r\n";
+ $bb .= $item['body'];
+ $bb .= "[/share]";
+ }
+
+ $arr['body'] = $bb;
+
+ $arr['author_xchan'] = $channel['channel_hash'];
+ $arr['owner_xchan'] = $channel['channel_hash'];
+
+ $arr['obj_type'] = $item['obj_type'];
+ $arr['verb'] = ACTIVITY_POST;
+
+ $arr['allow_cid'] = $channel['channel_allow_cid'];
+ $arr['allow_gid'] = $channel['channel_allow_gid'];
+ $arr['deny_cid'] = $channel['channel_deny_cid'];
+ $arr['deny_gid'] = $channel['channel_deny_gid'];
+ $arr['comment_policy'] = map_scope(PermissionLimits::Get($channel['channel_id'],'post_comments'));
+
+ if ($arr['id']) {
+ $post = item_store_update($arr);
+ }
+ else {
+ $post = item_store($arr);
+ }
+
+ $post_id = $post['item_id'];
+
+ if($post_id) {
+ Master::Summon([ 'Notifier','tgroup',$post_id ]);
+ }
+ return;
+ }
+
+
// Change this copy of the post to a forum head message and deliver to all the tgroup members
// also reset all the privacy bits to the forum default permissions
@@ -3225,7 +3375,7 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $edit = false)
function check_item_source($uid, $item) {
logger('source: uid: ' . $uid, LOGGER_DEBUG);
- $xchan = (($item['source_xchan']) ? $item['source_xchan'] : $item['owner_xchan']);
+ $xchan = (($item['source_xchan'] && intval($item['item_uplink'])) ? $item['source_xchan'] : $item['owner_xchan']);
$r = q("select * from source where src_channel_id = %d and ( src_xchan = '%s' or src_xchan = '*' ) limit 1",
intval($uid),
@@ -4386,8 +4536,8 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
// only setup pagination on initial page view
$pager_sql = '';
} else {
- $itemspage = (($channel) ? get_pconfig($uid,'system','itemspage') : 20);
- App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
+ $itemspage = (($channel) ? get_pconfig($uid,'system','itemspage') : 10);
+ App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10));
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
}
diff --git a/include/nav.php b/include/nav.php
index bd4d000f7..b2a061661 100644
--- a/include/nav.php
+++ b/include/nav.php
@@ -296,14 +296,10 @@ function nav($template = 'default') {
$app['active'] = true;
if($is_owner) {
- if(strpos($app['categories'],'nav_pinned_app') === false) {
- $nav_apps[] = Apps::app_render($app,'nav');
- }
+ $nav_apps[] = Apps::app_render($app,'nav');
}
elseif(! $is_owner && strpos($app['requires'], 'local_channel') === false) {
- if(strpos($app['categories'],'nav_pinned_app') === false) {
- $nav_apps[] = Apps::app_render($app,'nav');
- }
+ $nav_apps[] = Apps::app_render($app,'nav');
}
}
}
diff --git a/include/network.php b/include/network.php
index 80d19797b..aada36fba 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1102,29 +1102,6 @@ function discover_by_webbie($webbie, $protocol = '') {
$x = webfinger_rfc7033($webbie, true);
if($x && array_key_exists('links',$x) && $x['links']) {
- foreach($x['links'] as $link) {
- if(array_key_exists('rel',$link)) {
-
- // If we discover zot - don't search further; grab the info and get out of
- // here.
-
- if($link['rel'] === PROTOCOL_ZOT && ((! $protocol) || (strtolower($protocol) === 'zot'))) {
- logger('zot found for ' . $webbie, LOGGER_DEBUG);
- if(array_key_exists('zot',$x) && $x['zot']['success']) {
- $i = import_xchan($x['zot']);
- return true;
- }
- else {
- $z = z_fetch_url($link['href']);
- if($z['success']) {
- $j = json_decode($z['body'],true);
- $i = import_xchan($j);
- return true;
- }
- }
- }
- }
- }
foreach($x['links'] as $link) {
if(array_key_exists('rel',$link)) {
@@ -1150,6 +1127,31 @@ function discover_by_webbie($webbie, $protocol = '') {
}
}
}
+
+ foreach($x['links'] as $link) {
+ if(array_key_exists('rel',$link)) {
+
+ // If we discover zot - don't search further; grab the info and get out of
+ // here.
+
+ if($link['rel'] === PROTOCOL_ZOT && ((! $protocol) || (strtolower($protocol) === 'zot'))) {
+ logger('zot found for ' . $webbie, LOGGER_DEBUG);
+ if(array_key_exists('zot',$x) && $x['zot']['success']) {
+ $i = import_xchan($x['zot']);
+ return true;
+ }
+ else {
+ $z = z_fetch_url($link['href']);
+ if($z['success']) {
+ $j = json_decode($z['body'],true);
+ $i = import_xchan($j);
+ return true;
+ }
+ }
+ }
+ }
+ }
+
}
logger('webfinger: ' . print_r($x,true), LOGGER_DATA, LOG_INFO);
diff --git a/include/text.php b/include/text.php
index 6873cc1c3..92e5807b4 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3751,7 +3751,7 @@ function array_path_exists($str,$arr) {
if($search) {
foreach($search as $s) {
- if(is_array($ptr) && array_key_exists($s,$ptr)) {
+ if ($ptr && is_array($ptr) && array_key_exists($s,$ptr)) {
$ptr = $ptr[$s];
}
else {