aboutsummaryrefslogtreecommitdiffstats
path: root/include/items.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/items.php')
-rw-r--r--[-rwxr-xr-x]include/items.php152
1 files changed, 91 insertions, 61 deletions
diff --git a/include/items.php b/include/items.php
index 2426c189f..83108455f 100755..100644
--- a/include/items.php
+++ b/include/items.php
@@ -11,6 +11,7 @@ use Zotlabs\Lib\ThreadListener;
use Zotlabs\Lib\IConfig;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Libsync;
+use Zotlabs\Lib\Libzot;
use Zotlabs\Access\PermissionLimits;
use Zotlabs\Access\PermissionRoles;
use Zotlabs\Access\AccessList;
@@ -130,7 +131,7 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) {
case 'sit':
case 'any':
case 'con':
- if($rr['xchan_network'] != 'zot')
+ if(!in_array($rr['xchan_network'], ['zot6', 'zot']))
break;
case 'pub':
case '':
@@ -790,8 +791,8 @@ function get_item_elements($x,$allow_code = false) {
dbesc($arr['author_xchan'])
);
if($r) {
- if($r[0]['xchan_pubkey'] && $r[0]['xchan_network'] === 'zot') {
- if(rsa_verify($x['body'],base64url_decode($arr['sig']),$r[0]['xchan_pubkey'])) {
+ if($r[0]['xchan_pubkey'] && $r[0]['xchan_network'] === 'zot6') {
+ if(Libzot::verify($x['body'], $arr['sig'], $r[0]['xchan_pubkey'])) {
$arr['item_verified'] = 1;
}
else {
@@ -2206,6 +2207,7 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
return $ret;
}
+
// override the unseen flag with the original
$arr['item_unseen'] = $orig[0]['item_unseen'];
@@ -2672,6 +2674,11 @@ function tag_deliver($uid, $item_id) {
}
if ($is_group && intval($item['item_private']) === 2 && intval($item['item_thread_top'])) {
+
+ // do not turn the groups own direkt messages into group items
+ if($item['item_wall'] && $item['author_xchan'] === $u[0]['channel_hash'])
+ return;
+
// 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']);
@@ -2682,6 +2689,12 @@ function tag_deliver($uid, $item_id) {
if ($is_group && intval($item['item_thread_top']) && intval($item['item_wall']) && $item['author_xchan'] !== $item['owner_xchan']) {
+
+ if($item['resource_type'] === 'group_item') {
+ logger('resource_type group_item: already shared');
+ return;
+ }
+
if (strpos($item['body'],'[/share]')) {
logger('W2W post already shared');
return;
@@ -3113,11 +3126,12 @@ function tgroup_check($uid, $item) {
}
}
}
-*/
+
if(! $found) {
logger('tgroup_check: mention was in a reshare or exceeded max_tagged_forums - ignoring');
continue;
}
+*/
return true;
}
@@ -3203,16 +3217,18 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
$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'])
+ $r = q("select * from item where uid = %d and resource_id = '%s' and source_xchan = '%s' and resource_type = 'group_item' limit 1",
+ intval($channel['channel_id']),
+ dbesc($item['mid']),
+ dbesc($item['author_xchan'])
);
+
if ($r) {
if (intval($item['item_deleted'])) {
- drop_item($r[0]['id'],false,DROPITEM_PHASE1);
- Master::Summon([ 'Notifier','drop',$r[0]['id'] ]);
+ drop_item($r[0]['id'], false, DROPITEM_PHASE1);
+ Master::Summon([ 'Notifier', 'drop', $r[0]['id'] ]);
return;
}
$arr['id'] = intval($r[0]['id']);
@@ -3242,6 +3258,9 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
$arr['item_uplink'] = 0;
$arr['source_xchan'] = $item['owner_xchan'];
+ $arr['resource_id'] = $item['mid'];
+ $arr['resource_type'] = 'group_item';
+
$arr['item_private'] = (($channel['channel_allow_cid'] || $channel['channel_allow_gid']
|| $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0);
@@ -3263,12 +3282,13 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
"' message_id='" . $item['mid'] .
"']";
if($item['title'])
- $bb .= '[b]'.$item['title'].'[/b]'."\r\n";
+ $bb .= '[h3][b]'.$item['title'].'[/b][/h3]'."\r\n";
$bb .= $item['body'];
$bb .= "[/share]";
}
$arr['body'] = $bb;
+ $arr['term'] = $item['term'];
$arr['author_xchan'] = $channel['channel_hash'];
$arr['owner_xchan'] = $channel['channel_hash'];
@@ -3950,10 +3970,10 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL) {
);
if($items) {
foreach($items as $i)
- delete_item_lowlevel($i,$stage,$force);
+ delete_item_lowlevel($i, $stage);
}
else
- delete_item_lowlevel($item,$stage,$force);
+ delete_item_lowlevel($item, $stage);
if(! $interactive)
return 1;
@@ -3987,7 +4007,6 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL) {
*
* @param array $item
* @param int $stage
- * @param boolean $force
* @return boolean
*/
function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL) {
@@ -4299,54 +4318,54 @@ function fetch_post_tags($items, $link = false) {
*/
function zot_feed($uid, $observer_hash, $arr) {
- $result = array();
- $mindate = null;
+ $result = [];
+ $mindate = null;
$message_id = null;
- $wall = true;
+ $wall = true;
require_once('include/security.php');
- if(array_key_exists('mindate',$arr)) {
- $mindate = datetime_convert('UTC','UTC',$arr['mindate']);
+ if (array_key_exists('mindate', $arr)) {
+ $mindate = datetime_convert('UTC', 'UTC', $arr['mindate']);
}
- if(array_key_exists('message_id',$arr)) {
+ if (array_key_exists('message_id', $arr)) {
$message_id = $arr['message_id'];
}
- if(array_key_exists('wall',$arr)) {
+ if (array_key_exists('wall', $arr)) {
$wall = intval($arr['wall']);
}
- if(! $mindate)
+ if (!$mindate)
$mindate = NULL_DATE;
$mindate = dbesc($mindate);
logger('zot_feed: requested for uid ' . $uid . ' from observer ' . $observer_hash, LOGGER_DEBUG);
- if($message_id)
- logger('message_id: ' . $message_id,LOGGER_DEBUG);
+ if ($message_id)
+ logger('message_id: ' . $message_id, LOGGER_DEBUG);
- if(! perm_is_allowed($uid,$observer_hash,'view_stream')) {
+ if (!perm_is_allowed($uid, $observer_hash, 'view_stream')) {
logger('zot_feed: permission denied.');
return $result;
}
- if(! is_sys_channel($uid))
- $sql_extra = item_permissions_sql($uid,$observer_hash);
+ if (!is_sys_channel($uid))
+ $sql_extra = item_permissions_sql($uid, $observer_hash);
$limit = " LIMIT 5000 ";
- if($mindate > NULL_DATE) {
+ if ($mindate > NULL_DATE) {
$sql_extra .= " and ( created > '$mindate' or changed > '$mindate' ) ";
}
- if($message_id) {
+ if ($message_id) {
$sql_extra .= " and mid = '" . dbesc($message_id) . "' ";
- $limit = '';
+ $limit = '';
}
- if($wall) {
+ if ($wall) {
$sql_extra .= " and item_wall = 1 ";
}
@@ -4355,17 +4374,17 @@ function zot_feed($uid, $observer_hash, $arr) {
$item_normal = item_normal();
- if(is_sys_channel($uid)) {
+ if (is_sys_channel($uid)) {
- $nonsys_uids = q("SELECT channel_id FROM channel WHERE channel_system = 0");
- $nonsys_uids_str = ids_to_querystr($nonsys_uids,'channel_id');
+ $nonsys_uids = q("SELECT channel_id FROM channel WHERE channel_system = 0");
+ $nonsys_uids_str = ids_to_querystr($nonsys_uids, 'channel_id');
$r = q("SELECT parent, postopts FROM item
WHERE uid IN ( %s )
AND item_private = 0
$item_normal
$sql_extra ORDER BY created ASC $limit",
- intval($nonsys_uids_str)
+ dbesc($nonsys_uids_str)
);
}
else {
@@ -4379,19 +4398,19 @@ function zot_feed($uid, $observer_hash, $arr) {
$parents = [];
- if($r) {
- foreach($r as $rv) {
- if(array_key_exists($rv['parent'],$parents))
+ if ($r) {
+ foreach ($r as $rv) {
+ if (array_key_exists($rv['parent'], $parents))
continue;
- if(strpos($rv['postopts'],'nodeliver') !== false)
+ if (strpos($rv['postopts'], 'nodeliver') !== false)
continue;
$parents[$rv['parent']] = $rv;
- if(count($parents) > 200)
+ if (count($parents) > 200)
break;
}
- $parents_str = ids_to_querystr($parents,'parent');
- $sys_query = ((is_sys_channel($uid)) ? $sql_extra : '');
+ $parents_str = ids_to_querystr($parents, 'parent');
+ $sys_query = ((is_sys_channel($uid)) ? $sql_extra : '');
$item_normal = item_normal();
$items = q("SELECT item.*, item.id AS item_id FROM item
@@ -4400,25 +4419,23 @@ function zot_feed($uid, $observer_hash, $arr) {
);
}
- if($items) {
+ if ($items) {
xchan_query($items);
$items = fetch_post_tags($items);
require_once('include/conversation.php');
- $items = conv_sort($items,'ascending');
+ $items = conv_sort($items, 'ascending');
}
else
- $items = array();
+ $items = [];
- logger('zot_feed: number items: ' . count($items),LOGGER_DEBUG);
+ logger('zot_feed: number items: ' . count($items), LOGGER_DEBUG);
- foreach($items as $item)
+ foreach ($items as $item)
$result[] = encode_item($item);
return $result;
}
-
-
function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = CLIENT_MODE_NORMAL,$module = 'network') {
$result = array('success' => false);
@@ -4458,7 +4475,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
$sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE $item_uids and item_thread_top = 1 $sql_options $item_normal ) ";
if($arr['since_id'])
- $sql_extra .= " and item.id > " . $since_id . " ";
+ $sql_extra .= " and item.id > " . intval($arr['since_id']) . " ";
if($arr['cat'])
$sql_extra .= protect_sprintf(term_query('item', $arr['cat'], TERM_CATEGORY));
@@ -4543,9 +4560,11 @@ 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') : 10);
- App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10));
- $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
+ if(! $arr['total']) {
+ $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']));
+ }
}
if (isset($arr['start']) && isset($arr['records']))
@@ -4581,7 +4600,6 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
require_once('include/security.php');
$sql_extra .= item_permissions_sql($channel['channel_id'],$observer_hash);
-
if($arr['pages'])
$item_restrict = " AND item_type = " . ITEM_TYPE_WEBPAGE . " ";
else
@@ -4594,11 +4612,23 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
// "New Item View" - show all items unthreaded in reverse created date order
- $items = q("SELECT item.*, item.id AS item_id FROM item
+ if ($arr['total']) {
+ $items = dbq("SELECT count(item.id) AS total FROM item
WHERE $item_uids $item_restrict
$simple_update
- $sql_extra $sql_nets $sql_extra3
- ORDER BY item.received DESC $pager_sql"
+ $sql_extra $sql_nets $sql_extra3"
+ );
+ if ($items) {
+ return intval($items[0]['total']);
+ }
+ return 0;
+ }
+
+ $items = dbq("SELECT item.*, item.id AS item_id FROM item
+ WHERE $item_uids $item_restrict
+ $simple_update
+ $sql_extra $sql_nets $sql_extra3
+ ORDER BY item.received DESC $pager_sql"
);
require_once('include/items.php');
@@ -4619,7 +4649,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
// Fetch a page full of parent items for this page
- $r = q("SELECT distinct item.id AS item_id, item.$ordering FROM item
+ $r = dbq("SELECT distinct item.id AS item_id, item.$ordering FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE $item_uids $item_restrict
AND item.parent = item.id
@@ -4630,7 +4660,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
}
else {
// update
- $r = q("SELECT item.parent AS item_id FROM item
+ $r = dbq("SELECT item.parent AS item_id FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE $item_uids $item_restrict $simple_update
and (abook.abook_blocked = 0 or abook.abook_flags is null)
@@ -4705,7 +4735,7 @@ function webpage_to_namespace($webpage) {
function update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid) {
- if(! $post_id)
+ if(! intval($post_id))
return;
$page_type = webpage_to_namespace($webpage);
@@ -4727,7 +4757,7 @@ function update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remo
// as the entire mid. If it were the post_id the link would be less portable.
IConfig::Set(
- intval($post_id),
+ $post_id,
'system',
$page_type,
($pagetitle) ? $pagetitle : substr($mid,0,16),