aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorManuel Jiménez Friaza <mjfriaza@openmailbox.org>2018-11-24 13:01:01 +0100
committerManuel Jiménez Friaza <mjfriaza@openmailbox.org>2018-11-24 13:01:01 +0100
commitf865d6e5dab19122fffc677da495b21d3d5e93e7 (patch)
tree8631750db2c385438207326479350ea909a625b4 /include
parent0bba9482dfbcc0fd8bea880ac3820548281ecfc2 (diff)
parentbc9f2922e0e255e97cb607d099f60c8a81c4736f (diff)
downloadvolse-hubzilla-f865d6e5dab19122fffc677da495b21d3d5e93e7.tar.gz
volse-hubzilla-f865d6e5dab19122fffc677da495b21d3d5e93e7.tar.bz2
volse-hubzilla-f865d6e5dab19122fffc677da495b21d3d5e93e7.zip
Resolved merge conflicts
Diffstat (limited to 'include')
-rw-r--r--include/activities.php3
-rw-r--r--include/attach.php18
-rw-r--r--include/channel.php82
-rw-r--r--include/crypto.php9
-rw-r--r--include/event.php7
-rw-r--r--include/help.php3
-rw-r--r--include/import.php3
-rwxr-xr-xinclude/items.php64
-rw-r--r--include/network.php4
-rw-r--r--include/photos.php8
-rw-r--r--include/queue_fn.php98
-rw-r--r--include/text.php44
-rw-r--r--include/xchan.php5
-rw-r--r--include/zot.php25
14 files changed, 264 insertions, 109 deletions
diff --git a/include/activities.php b/include/activities.php
index 9b83f7a5c..68c995338 100644
--- a/include/activities.php
+++ b/include/activities.php
@@ -16,7 +16,8 @@ function profile_activity($changed, $value) {
return;
$arr = array();
- $arr['mid'] = $arr['parent_mid'] = item_message_id();
+ $arr['uuid'] = item_message_id();
+ $arr['mid'] = $arr['parent_mid'] = z_root() . '/item/' . $arr['uuid'];
$arr['uid'] = local_channel();
$arr['aid'] = $self['channel_account_id'];
$arr['owner_xchan'] = $arr['author_xchan'] = $self['xchan_hash'];
diff --git a/include/attach.php b/include/attach.php
index 4db5bc435..dd718aa14 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -739,7 +739,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
}
if(! $hash)
- $hash = random_string();
+ $hash = new_uuid();
// Check storage limits
if($options !== 'update') {
@@ -1122,7 +1122,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
return $ret;
}
- $arr['hash'] = (($arr['hash']) ? $arr['hash'] : random_string());
+ $arr['hash'] = (($arr['hash']) ? $arr['hash'] : new_uuid());
// Check for duplicate name.
// Check both the filename and the hash as we will be making use of both.
@@ -1759,16 +1759,18 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
$arr_allow_cid = check_list_permissions($channel_id, $arr_allow_cid, 'view_storage');
}
- $mid = item_message_id();
+ $uuid = item_message_id();
+ $mid = z_root() . '/item/' . $uuid;
$objtype = ACTIVITY_OBJ_FILE;
$arr = array();
$arr['aid'] = get_account_id();
$arr['uid'] = $channel_id;
- $arr['item_wall'] = 1;
- $arr['item_origin'] = 1;
- $arr['item_unseen'] = 1;
+ $arr['uuid'] = $uuid;
+ $arr['item_wall'] = 1;
+ $arr['item_origin'] = 1;
+ $arr['item_unseen'] = 1;
$arr['author_xchan'] = $poster['xchan_hash'];
$arr['owner_xchan'] = $poster['xchan_hash'];
$arr['title'] = '';
@@ -1813,8 +1815,10 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
$private = (($u_arr_allow_cid[0] || $u_arr_allow_gid[0] || $u_arr_deny_cid[0] || $u_arr_deny_gid[0]) ? 1 : 0);
- $u_mid = item_message_id();
+ $uuid = item_message_id();
+ $u_mid = z_root() . '/item/' . $uuid;
+ $arr['uuid'] = $uuid;
$arr['mid'] = $u_mid;
$arr['parent_mid'] = $u_mid;
$arr['allow_cid'] = perms2str($u_arr_allow_cid);
diff --git a/include/channel.php b/include/channel.php
index 22cdb9fe7..1e5570f6b 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -10,6 +10,7 @@ use Zotlabs\Access\Permissions;
use Zotlabs\Daemon\Master;
use Zotlabs\Lib\System;
use Zotlabs\Render\Comanche;
+use Zotlabs\Lib\Libzot;
require_once('include/zot.php');
require_once('include/crypto.php');
@@ -232,6 +233,7 @@ function create_identity($arr) {
$sig = base64url_encode(rsa_sign($guid,$key['prvkey']));
$hash = make_xchan_hash($guid,$sig);
+ $zhash = Libzot::make_xchan_hash($guid,$key['pubkey']);
// Force a few things on the short term until we can provide a theme or app with choice
@@ -265,6 +267,7 @@ function create_identity($arr) {
'channel_guid' => $guid,
'channel_guid_sig' => $sig,
'channel_hash' => $hash,
+ 'channel_portable_id' => $zhash,
'channel_prvkey' => $key['prvkey'],
'channel_pubkey' => $key['pubkey'],
'channel_pageflags' => intval($pageflags),
@@ -345,30 +348,76 @@ function create_identity($arr) {
if(! $r)
logger('Unable to store hub location');
+ $r = hubloc_store_lowlevel(
+ [
+ 'hubloc_guid' => $guid,
+ 'hubloc_guid_sig' => 'sha256.' . $sig,
+ 'hubloc_hash' => $zhash,
+ 'hubloc_id_url' => channel_url($ret['channel']),
+ 'hubloc_addr' => channel_reddress($ret['channel']),
+ 'hubloc_primary' => intval($primary),
+ 'hubloc_url' => z_root(),
+ 'hubloc_url_sig' => 'sha256.' . base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey'])),
+ 'hubloc_site_id' => Libzot::make_xchan_hash(z_root(),get_config('system','pubkey')),
+ 'hubloc_host' => App::get_hostname(),
+ 'hubloc_callback' => z_root() . '/zot',
+ 'hubloc_sitekey' => get_config('system','pubkey'),
+ 'hubloc_network' => 'zot6',
+ 'hubloc_updated' => datetime_convert()
+ ]
+ );
+ if(! $r)
+ logger('Unable to store hub location');
+
+
$newuid = $ret['channel']['channel_id'];
$r = xchan_store_lowlevel(
[
- 'xchan_hash' => $hash,
- 'xchan_guid' => $guid,
- 'xchan_guid_sig' => $sig,
- 'xchan_pubkey' => $key['pubkey'],
+ 'xchan_hash' => $hash,
+ 'xchan_guid' => $guid,
+ 'xchan_guid_sig' => $sig,
+ 'xchan_pubkey' => $key['pubkey'],
'xchan_photo_mimetype' => (($photo_type) ? $photo_type : 'image/png'),
- 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}",
- 'xchan_photo_m' => z_root() . "/photo/profile/m/{$newuid}",
- 'xchan_photo_s' => z_root() . "/photo/profile/s/{$newuid}",
- 'xchan_addr' => channel_reddress($ret['channel']),
- 'xchan_url' => z_root() . '/channel/' . $ret['channel']['channel_address'],
- 'xchan_follow' => z_root() . '/follow?f=&url=%s',
- 'xchan_connurl' => z_root() . '/poco/' . $ret['channel']['channel_address'],
- 'xchan_name' => $ret['channel']['channel_name'],
- 'xchan_network' => 'zot',
- 'xchan_photo_date' => datetime_convert(),
- 'xchan_name_date' => datetime_convert(),
- 'xchan_system' => $system
+ 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}",
+ 'xchan_photo_m' => z_root() . "/photo/profile/m/{$newuid}",
+ 'xchan_photo_s' => z_root() . "/photo/profile/s/{$newuid}",
+ 'xchan_addr' => channel_reddress($ret['channel']),
+ 'xchan_url' => z_root() . '/channel/' . $ret['channel']['channel_address'],
+ 'xchan_follow' => z_root() . '/follow?f=&url=%s',
+ 'xchan_connurl' => z_root() . '/poco/' . $ret['channel']['channel_address'],
+ 'xchan_name' => $ret['channel']['channel_name'],
+ 'xchan_network' => 'zot',
+ 'xchan_photo_date' => datetime_convert(),
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_system' => $system
]
);
+ $r = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $zhash,
+ 'xchan_guid' => $guid,
+ 'xchan_guid_sig' => 'sha256.' . $sig,
+ 'xchan_pubkey' => $key['pubkey'],
+ 'xchan_photo_mimetype' => (($photo_type) ? $photo_type : 'image/png'),
+ 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}",
+ 'xchan_photo_m' => z_root() . "/photo/profile/m/{$newuid}",
+ 'xchan_photo_s' => z_root() . "/photo/profile/s/{$newuid}",
+ 'xchan_addr' => channel_reddress($ret['channel']),
+ 'xchan_url' => z_root() . '/channel/' . $ret['channel']['channel_address'],
+ 'xchan_follow' => z_root() . '/follow?f=&url=%s',
+ 'xchan_connurl' => z_root() . '/poco/' . $ret['channel']['channel_address'],
+ 'xchan_name' => $ret['channel']['channel_name'],
+ 'xchan_network' => 'zot6',
+ 'xchan_photo_date' => datetime_convert(),
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_system' => $system
+ ]
+ );
+
+
+
// Not checking return value.
// It's ok for this to fail if it's an imported channel, and therefore the hash is a duplicate
@@ -2355,6 +2404,7 @@ function channel_store_lowlevel($arr) {
'channel_guid' => ((array_key_exists('channel_guid',$arr)) ? $arr['channel_guid'] : ''),
'channel_guid_sig' => ((array_key_exists('channel_guid_sig',$arr)) ? $arr['channel_guid_sig'] : ''),
'channel_hash' => ((array_key_exists('channel_hash',$arr)) ? $arr['channel_hash'] : ''),
+ 'channel_portable_id' => ((array_key_exists('channel_portable_id',$arr)) ? $arr['channel_portable_id'] : ''),
'channel_timezone' => ((array_key_exists('channel_timezone',$arr)) ? $arr['channel_timezone'] : 'UTC'),
'channel_location' => ((array_key_exists('channel_location',$arr)) ? $arr['channel_location'] : ''),
'channel_theme' => ((array_key_exists('channel_theme',$arr)) ? $arr['channel_theme'] : ''),
diff --git a/include/crypto.php b/include/crypto.php
index 1040ac29b..39bfd8d43 100644
--- a/include/crypto.php
+++ b/include/crypto.php
@@ -225,9 +225,14 @@ function crypto_unencapsulate($data,$prvkey) {
if(! $data)
return;
- $alg = ((array_key_exists('alg',$data)) ? $data['alg'] : 'aes256cbc');
- if($alg === 'aes256cbc')
+ $alg = ((is_array($data) && (array_key_exists('encrypted',$data) || array_key_exists('iv',$data))) ? $data['alg'] : '');
+ if(! $alg) {
+ return $data;
+ }
+
+ if($alg === 'aes256cbc') {
return aes_unencapsulate($data,$prvkey);
+ }
return other_unencapsulate($data,$prvkey,$alg);
diff --git a/include/event.php b/include/event.php
index 84a16e8be..a34250e7a 100644
--- a/include/event.php
+++ b/include/event.php
@@ -1125,11 +1125,14 @@ function event_store_item($arr, $event) {
}
}
- if(! $arr['mid'])
- $arr['mid'] = item_message_id();
+ if(! $arr['mid']) {
+ $arr['uuid'] = item_message_id();
+ $arr['mid'] = z_root() . '/item/' . $arr['uuid'];
+ }
$item_arr['aid'] = $z[0]['channel_account_id'];
$item_arr['uid'] = $arr['uid'];
+ $item_arr['uuid'] = $arr['uuid'];
$item_arr['author_xchan'] = $arr['event_xchan'];
$item_arr['mid'] = $arr['mid'];
$item_arr['parent_mid'] = $arr['mid'];
diff --git a/include/help.php b/include/help.php
index 3b56a7238..f2aa4add3 100644
--- a/include/help.php
+++ b/include/help.php
@@ -351,7 +351,8 @@ function store_doc_file($s) {
$x = item_store_update($item);
}
else {
- $item['mid'] = $item['parent_mid'] = item_message_id();
+ $item['uuid'] = $item_message_id();
+ $item['mid'] = $item['parent_mid'] = z_root() . '/item/' . $item['uuid'];
$x = item_store($item);
}
diff --git a/include/import.php b/include/import.php
index 6476aa688..53b21c317 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1520,7 +1520,8 @@ function import_webpage_element($element, $channel, $type) {
}
else { // otherwise, generate the creation times and unique id
$arr['created'] = datetime_convert('UTC', 'UTC');
- $arr['mid'] = $arr['parent_mid'] = item_message_id();
+ $arr['uuid'] = item_message_id();
+ $arr['mid'] = $arr['parent_mid'] = z_root() . '/item/' . $arr['uuid'];
}
// Update the edited time whether or not the element already exists
$arr['edited'] = datetime_convert('UTC', 'UTC');
diff --git a/include/items.php b/include/items.php
index d8a9e8e56..2cee376d0 100755
--- a/include/items.php
+++ b/include/items.php
@@ -393,7 +393,11 @@ function post_activity_item($arr, $allow_code = false, $deliver = true) {
if(! array_key_exists('mimetype',$arr))
$arr['mimetype'] = 'text/bbcode';
- $arr['mid'] = ((x($arr,'mid')) ? $arr['mid'] : item_message_id());
+
+ if(! $arr['mid']) {
+ $arr['uuid'] = ((x($arr,'uuid')) ? $arr['uuid'] : item_message_id());
+ }
+ $arr['mid'] = ((x($arr,'mid')) ? $arr['mid'] : z_root() . '/item/' . $arr['uuid']);
$arr['parent_mid'] = ((x($arr,'parent_mid')) ? $arr['parent_mid'] : $arr['mid']);
$arr['thr_parent'] = ((x($arr,'thr_parent')) ? $arr['thr_parent'] : $arr['mid']);
@@ -597,6 +601,7 @@ function get_item_elements($x,$allow_code = false) {
$arr = array();
$arr['body'] = $x['body'];
+ $arr['summary'] = $x['summary'];
$maxlen = get_max_import_size();
@@ -605,6 +610,11 @@ function get_item_elements($x,$allow_code = false) {
logger('get_item_elements: message length exceeds max_import_size: truncated');
}
+ if($maxlen && mb_strlen($arr['summary']) > $maxlen) {
+ $arr['summary'] = mb_substr($arr['summary'],0,$maxlen,'UTF-8');
+ logger('get_item_elements: message summary length exceeds max_import_size: truncated');
+ }
+
$arr['created'] = datetime_convert('UTC','UTC',$x['created']);
$arr['edited'] = datetime_convert('UTC','UTC',$x['edited']);
@@ -627,6 +637,7 @@ function get_item_elements($x,$allow_code = false) {
if(mb_strlen($arr['title']) > 255)
$arr['title'] = mb_substr($arr['title'],0,255);
+ $arr['uuid'] = (($x['uuid']) ? htmlspecialchars($x['uuid'], ENT_COMPAT,'UTF-8',false) : '');
$arr['app'] = (($x['app']) ? htmlspecialchars($x['app'], ENT_COMPAT,'UTF-8',false) : '');
$arr['route'] = (($x['route']) ? htmlspecialchars($x['route'], ENT_COMPAT,'UTF-8',false) : '');
$arr['mid'] = (($x['message_id']) ? htmlspecialchars($x['message_id'], ENT_COMPAT,'UTF-8',false) : '');
@@ -747,9 +758,10 @@ function get_item_elements($x,$allow_code = false) {
// Do this after signature checking as the original signature
// was generated on the escaped content.
- if($arr['mimetype'] === 'text/markdown')
+ if($arr['mimetype'] === 'text/markdown') {
+ $arr['summary'] = MarkdownSoap::unescape($arr['summary']);
$arr['body'] = MarkdownSoap::unescape($arr['body']);
-
+ }
if(array_key_exists('revision',$x)) {
// extended export encoding
@@ -1061,6 +1073,7 @@ function encode_item($item,$mirror = false) {
$x['item_blocked'] = $item['item_blocked'];
}
+ $x['uuid'] = $item['uuid'];
$x['message_id'] = $item['mid'];
$x['message_top'] = $item['parent_mid'];
$x['message_parent'] = $item['thr_parent'];
@@ -1071,6 +1084,7 @@ function encode_item($item,$mirror = false) {
$x['commented'] = $item['commented'];
$x['mimetype'] = $item['mimetype'];
$x['title'] = $item['title'];
+ $x['summary'] = $item['summary'];
$x['body'] = $item['body'];
$x['app'] = $item['app'];
$x['verb'] = $item['verb'];
@@ -1629,6 +1643,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
}
$arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : '');
+ $arr['summary'] = ((array_key_exists('summary',$arr) && strlen($arr['summary'])) ? trim($arr['summary']) : '');
$arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : '');
$arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
@@ -1637,6 +1652,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
$arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
$arr['postopts'] = ((x($arr,'postopts')) ? trim($arr['postopts']) : '');
$arr['route'] = ((x($arr,'route')) ? trim($arr['route']) : '');
+ $arr['uuid'] = ((x($arr,'uuid')) ? trim($arr['uuid']) : '');
$arr['item_private'] = ((x($arr,'item_private')) ? intval($arr['item_private']) : 0 );
$arr['item_wall'] = ((x($arr,'item_wall')) ? intval($arr['item_wall']) : 0 );
$arr['item_type'] = ((x($arr,'item_type')) ? intval($arr['item_type']) : 0 );
@@ -1649,6 +1665,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
// apply the input filter here
+ $arr['summary'] = trim(z_input_filter($arr['summary'],$arr['mimetype'],$allow_exec));
$arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec));
item_sign($arr);
@@ -2094,6 +2111,7 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
// apply the input filter here
+ $arr['summary'] = trim(z_input_filter($arr['summary'],$arr['mimetype'],$allow_exec));
$arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec));
item_sign($arr);
@@ -2170,6 +2188,7 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
$arr['route'] = ((array_key_exists('route',$arr)) ? trim($arr['route']) : $orig[0]['route']);
$arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : $orig[0]['location']);
+ $arr['uuid'] = ((x($arr,'uuid')) ? notags(trim($arr['uuid'])) : $orig[0]['uuid']);
$arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : $orig[0]['coord']);
$arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : $orig[0]['verb']);
$arr['obj_type'] = ((x($arr,'obj_type')) ? notags(trim($arr['obj_type'])) : $orig[0]['obj_type']);
@@ -2625,28 +2644,30 @@ function tag_deliver($uid, $item_id) {
$plustagged = false;
$matches = array();
- $pattern = '/[\!@]\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'],'/') . '\[\/zrl\]/';
+ $pattern = '/[\!@]\!?\[[uz]rl\=' . preg_quote($term['url'],'/') . '\](.*?)\[\/[uz]rl\]/';
if(preg_match($pattern,$body,$matches))
$tagged = true;
- // original red forum tagging sequence @forumname+
+ $pattern = '/\[url\=' . preg_quote($term['url'],'/') . '\]\@(.*?)\[\/url\]/';
+ if(preg_match($pattern,$body,$matches))
+ $tagged = true;
+
+
// standard forum tagging sequence !forumname
- $pluspattern = '/@\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\+\[\/zrl\]/';
+ $forumpattern = '/\!\!?\[[uz]rl\=([^\]]*?)\]((?:.(?!\[[uz]rl\=))*?)\[\/[uz]rl\]/';
- $forumpattern = '/\!\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\[\/zrl\]/';
+ $forumpattern2 = '/\[[uz]rl\=([^\]]*?)\]\!((?:.(?!\[[uz]rl\=))*?)\[\/[uz]rl\]/';
- $found = false;
$matches = array();
- if(preg_match_all($pluspattern,$body,$matches,PREG_SET_ORDER)) {
+ if(preg_match_all($forumpattern,$body,$matches,PREG_SET_ORDER)) {
foreach($matches as $match) {
$matched_forums ++;
- if($term['url'] === $match[1] && $term['term'] === $match[2] && intval($term['ttype']) === TERM_MENTION) {
+ if($term['url'] === $match[1] && intval($term['ttype']) === TERM_FORUM) {
if($matched_forums <= $max_forums) {
$plustagged = true;
- $found = true;
break;
}
logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring');
@@ -2654,13 +2675,12 @@ function tag_deliver($uid, $item_id) {
}
}
- if(preg_match_all($forumpattern,$body,$matches,PREG_SET_ORDER)) {
+ if(preg_match_all($forumpattern2,$body,$matches,PREG_SET_ORDER)) {
foreach($matches as $match) {
$matched_forums ++;
- if($term['url'] === $match[1] && $term['term'] === $match[2] && intval($term['ttype']) === TERM_FORUM) {
+ if($term['url'] === $match[1] && intval($term['ttype']) === TERM_FORUM) {
if($matched_forums <= $max_forums) {
$plustagged = true;
- $found = true;
break;
}
logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring');
@@ -2882,18 +2902,19 @@ function tgroup_check($uid, $item) {
$body = preg_replace('/\[share(.*?)\[\/share\]/','',$item['body']);
- $pluspattern = '/@\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\+\[\/zrl\]/';
-
$forumpattern = '/\!\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\[\/zrl\]/';
+ $forumpattern2 = '/\[zrl\=([^\]]*?)\]\!((?:.(?!\[zrl\=))*?)\[\/zrl\]/';
+
+
$found = false;
$matches = array();
- if(preg_match_all($pluspattern,$body,$matches,PREG_SET_ORDER)) {
+ if(preg_match_all($forumpattern,$body,$matches,PREG_SET_ORDER)) {
foreach($matches as $match) {
$matched_forums ++;
- if($term['url'] === $match[1] && $term['term'] === $match[2] && intval($term['ttype']) === TERM_MENTION) {
+ if($term['url'] === $match[1] && intval($term['ttype']) === TERM_FORUM) {
if($matched_forums <= $max_forums) {
$found = true;
break;
@@ -2903,10 +2924,10 @@ function tgroup_check($uid, $item) {
}
}
- if(preg_match_all($forumpattern,$body,$matches,PREG_SET_ORDER)) {
+ if(preg_match_all($forumpattern2,$body,$matches,PREG_SET_ORDER)) {
foreach($matches as $match) {
$matched_forums ++;
- if($term['url'] === $match[1] && $term['term'] === $match[2] && intval($term['ttype']) === TERM_FORUM) {
+ if($term['url'] === $match[1] && intval($term['ttype']) === TERM_FORUM) {
if($matched_forums <= $max_forums) {
$found = true;
break;
@@ -4744,7 +4765,8 @@ function item_create_edit_activity($post) {
$new_item['id'] = 0;
$new_item['parent'] = 0;
- $new_item['mid'] = item_message_id();
+ $new_item['uuid'] = item_message_id();
+ $new_item['mid'] = z_root() . '/item/' . $new_item['uuid'];
$new_item['body'] = sprintf( t('[Edited %s]'), (($update_item['item_thread_top']) ? t('Post','edit_activity') : t('Comment','edit_activity')));
diff --git a/include/network.php b/include/network.php
index d37da05f7..183a47105 100644
--- a/include/network.php
+++ b/include/network.php
@@ -153,7 +153,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
// Pull out multiple headers, e.g. proxy and continuation headers
// allow for HTTP/2.x without fixing code
- while(preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) {
+ while(preg_match('/^HTTP\/[1-3].+? [1-5][0-9][0-9]/',$base)) {
$chunk = substr($base,0,strpos($base,"\r\n\r\n")+4);
$header .= $chunk;
$base = substr($base,strlen($chunk));
@@ -319,7 +319,7 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) {
// Pull out multiple headers, e.g. proxy and continuation headers
// allow for HTTP/2.x without fixing code
- while(preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) {
+ while(preg_match('/^HTTP\/[1-3].+? [1-5][0-9][0-9]/',$base)) {
$chunk = substr($base,0,strpos($base,"\r\n\r\n")+4);
$header .= $chunk;
$base = substr($base,strlen($chunk));
diff --git a/include/photos.php b/include/photos.php
index d5553b495..ae51703e0 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -441,11 +441,13 @@ function photo_upload($channel, $observer, $args) {
}
}
else {
- $mid = item_message_id();
+ $uuid = item_message_id();
+ $mid = z_root() . '/item/' . $uuid;
$arr = [
'aid' => $account_id,
'uid' => $channel_id,
+ 'uuid' => $uuid,
'mid' => $mid,
'parent_mid' => $mid,
'item_hidden' => $item_hidden,
@@ -827,12 +829,14 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) {
$item_hidden = (($visible) ? 0 : 1 );
- $mid = item_message_id();
+ $uuid = item_message_id();
+ $mid = z_root() . '/item/' . $uuid;
$arr = array();
$arr['aid'] = $channel['channel_account_id'];
$arr['uid'] = $channel['channel_id'];
+ $arr['uuid'] = $uuid;
$arr['mid'] = $mid;
$arr['parent_mid'] = $mid;
$arr['item_wall'] = 1;
diff --git a/include/queue_fn.php b/include/queue_fn.php
index f05bac5b0..f7e2922c6 100644
--- a/include/queue_fn.php
+++ b/include/queue_fn.php
@@ -1,5 +1,9 @@
<?php /** @file */
+use Zotlabs\Lib\Libzot;
+use Zotlabs\Zot6\Receiver;
+use Zotlabs\Zot6\Zot6Handler;
+
function update_queue_item($id, $add_priority = 0) {
logger('queue: requeue item ' . $id,LOGGER_DEBUG);
$x = q("select outq_created, outq_posturl from outq where outq_hash = '%s' limit 1",
@@ -226,37 +230,85 @@ function queue_deliver($outq, $immediate = false) {
logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG);
- $channel = null;
+ if($outq['outq_driver'] === 'zot6') {
+
+ if($outq['outq_posturl'] === z_root() . '/zot') {
+ // local delivery
+ $zot = new Receiver(new Zot6Handler(),$outq['outq_notify']);
+ $result = $zot->run(true);
+ logger('returned_json: ' . json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES), LOGGER_DATA);
+ logger('deliver: local zot6 delivery succeeded to ' . $outq['outq_posturl']);
+ Libzot::process_response($outq['outq_posturl'],[ 'success' => true, 'body' => json_encode($result) ], $outq);
+ }
+ else {
+ logger('remote');
+ $channel = null;
+
+ if($outq['outq_channel']) {
+ $channel = channelx_by_n($outq['outq_channel']);
+ }
+
+ $host_crypto = null;
+ if($channel && $base) {
+ $h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1",
+ dbesc($base)
+ );
+ if($h) {
+ $host_crypto = $h[0];
+ }
+ }
+
+ $msg = $outq['outq_notify'];
+
+ $result = Libzot::zot($outq['outq_posturl'],$msg,$channel,$host_crypto);
+
+ if($result['success']) {
+ logger('deliver: remote zot6 delivery succeeded to ' . $outq['outq_posturl']);
+ Libzot::process_response($outq['outq_posturl'],$result, $outq);
+ }
+ else {
+ logger('deliver: remote zot6 delivery failed to ' . $outq['outq_posturl']);
+ logger('deliver: remote zot6 delivery fail data: ' . print_r($result,true), LOGGER_DATA);
+ update_queue_item($outq['outq_hash'],10);
+ }
- if($outq['outq_msg'] && $outq['outq_channel']) {
- $channel = channelx_by_n($outq['outq_channel']);
+ }
+ return;
}
+ else {
- $host_crypto = null;
+ $channel = null;
- if($channel && $base) {
- $h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' order by hubloc_id desc limit 1",
- dbesc($base)
- );
- if($h) {
- $host_crypto = $h[0];
+ if($outq['outq_msg'] && $outq['outq_channel']) {
+ $channel = channelx_by_n($outq['outq_channel']);
}
- }
- $msg = $outq['outq_notify'];
+ $host_crypto = null;
- $result = zot_zot($outq['outq_posturl'],$msg,$channel,$host_crypto);
+ if($channel && $base) {
+ $h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' order by hubloc_id desc limit 1",
+ dbesc($base)
+ );
+ if($h) {
+ $host_crypto = $h[0];
+ }
+ }
+ $msg = $outq['outq_notify'];
- if($result['success']) {
- logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']);
- zot_process_response($outq['outq_posturl'],$result, $outq);
- }
- else {
- logger('deliver: remote zot delivery failed to ' . $outq['outq_posturl']);
- logger('deliver: remote zot delivery fail data: ' . print_r($result,true), LOGGER_DATA);
- update_queue_item($outq['outq_hash'],10);
+ $result = zot_zot($outq['outq_posturl'],$msg,$channel,$host_crypto);
+
+
+ if($result['success']) {
+ logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']);
+ zot_process_response($outq['outq_posturl'],$result, $outq);
+ }
+ else {
+ logger('deliver: remote zot delivery failed to ' . $outq['outq_posturl']);
+ logger('deliver: remote zot delivery fail data: ' . print_r($result,true), LOGGER_DATA);
+ update_queue_item($outq['outq_hash'],10);
+ }
+ return;
}
- return;
-}
+} \ No newline at end of file
diff --git a/include/text.php b/include/text.php
index 076c98407..646bfe749 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3,8 +3,11 @@
* @file include/text.php
*/
-use \Zotlabs\Lib as Zlib;
-use \Michelf\MarkdownExtra;
+use Zotlabs\Lib as Zlib;
+
+use Michelf\MarkdownExtra;
+use Ramsey\Uuid\Uuid;
+use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
require_once("include/bbcode.php");
@@ -571,18 +574,9 @@ function alt_pager($i, $more = '', $less = '') {
* @return string a unique id
*/
function item_message_id() {
- do {
- $dups = false;
- $hash = random_string();
- $mid = $hash . '@' . App::get_hostname();
- $r = q("SELECT id FROM item WHERE mid = '%s' LIMIT 1",
- dbesc($mid));
- if($r)
- $dups = true;
- } while($dups == true);
+ return new_uuid();
- return $mid;
}
/**
@@ -593,17 +587,9 @@ function item_message_id() {
* @return string a uniqe hash
*/
function photo_new_resource() {
- do {
- $found = false;
- $resource = hash('md5', uniqid(mt_rand(), true));
- $r = q("SELECT id FROM photo WHERE resource_id = '%s' LIMIT 1",
- dbesc($resource));
- if($r)
- $found = true;
- } while($found === true);
+ return new_uuid();
- return $resource;
}
/**
@@ -3480,3 +3466,19 @@ function print_val($v) {
return $v;
}
+
+/**
+ * @brief Generate a unique ID.
+ *
+ * @return string
+ */
+function new_uuid() {
+
+ try {
+ $hash = Uuid::uuid4()->toString();
+ } catch (UnsatisfiedDependencyException $e) {
+ $hash = random_string(48);
+ }
+
+ return $hash;
+}
diff --git a/include/xchan.php b/include/xchan.php
index eb5f1b4a3..4cbfb42c5 100644
--- a/include/xchan.php
+++ b/include/xchan.php
@@ -5,6 +5,11 @@ use Zotlabs\Zot6\HTTPSig;
function xchan_store_lowlevel($arr) {
+ if(! $arr['xchan_hash']) {
+ logger('No xchan_hash');
+ return false;
+ }
+
$store = [
'xchan_hash' => ((array_key_exists('xchan_hash',$arr)) ? $arr['xchan_hash'] : ''),
'xchan_guid' => ((array_key_exists('xchan_guid',$arr)) ? $arr['xchan_guid'] : ''),
diff --git a/include/zot.php b/include/zot.php
index 3ccf0a81f..d031b4a96 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -8,6 +8,8 @@
*
*/
+use Zotlabs\Lib\DReport;
+
require_once('include/crypto.php');
require_once('include/items.php');
require_once('include/queue_fn.php');
@@ -81,7 +83,7 @@ function zot_get_hublocs($hash) {
/* Only search for active hublocs - e.g. those that haven't been marked deleted */
- $ret = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 order by hubloc_url ",
+ $ret = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 and hubloc_network = 'zot' order by hubloc_url ",
dbesc($hash)
);
@@ -654,7 +656,7 @@ function zot_gethub($arr, $multiple = false) {
$r = q("select hubloc.*, site.site_crypto from hubloc left join site on hubloc_url = site_url
where hubloc_guid = '%s' and hubloc_guid_sig = '%s'
- and hubloc_url = '%s' and hubloc_url_sig = '%s'
+ and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_network = 'zot'
$sitekey $limit",
dbesc($arr['guid']),
dbesc($arr['guid_sig']),
@@ -1119,14 +1121,15 @@ function zot_process_response($hub, $arr, $outq) {
}
foreach($x['delivery_report'] as $xx) {
- call_hooks('dreport_process',$xx);
- if(is_array($xx) && array_key_exists('message_id',$xx) && delivery_report_is_storable($xx)) {
- q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ",
+ call_hooks('dreport_process',$xx);
+ if(is_array($xx) && array_key_exists('message_id',$xx) && DReport::is_storable($xx)) {
+ q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s','%s' ) ",
dbesc($xx['message_id']),
dbesc($xx['location']),
dbesc($xx['recipient']),
+ dbesc($xx['name']),
dbesc($xx['status']),
- dbesc(datetime_convert($xx['date'])),
+ dbesc(datetime_convert('UTC','UTC',$xx['date'])),
dbesc($xx['sender'])
);
}
@@ -1188,6 +1191,7 @@ function zot_fetch($arr) {
$zret = zot6_check_sig();
if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $arr['sender']['guid'] && $arr['msg']) {
+
logger('zot6_delivery',LOGGER_DEBUG);
logger('zot6_data: ' . print_r($arr,true),LOGGER_DATA);
@@ -1748,7 +1752,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
}
$channel = $r[0];
- $DR->addto_recipient($channel['channel_name'] . ' <' . channel_reddress($channel) . '>');
+ $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>');
/* blacklisted channels get a permission denied, no special message to tip them off */
@@ -2297,7 +2301,7 @@ function process_mail_delivery($sender, $arr, $deliveries) {
}
$channel = $r[0];
- $DR->addto_recipient($channel['channel_name'] . ' <' . channel_reddress($channel) . '>');
+ $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>');
/* blacklisted channels get a permission denied, no special message to tip them off */
@@ -3987,7 +3991,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
if(array_key_exists('item',$arr) && is_array($arr['item'][0])) {
$DR = new Zotlabs\Lib\DReport(z_root(),$d['hash'],$d['hash'],$arr['item'][0]['message_id'],'channel sync processed');
- $DR->addto_recipient($channel['channel_name'] . ' <' . channel_reddress($channel) . '>');
+ $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>');
}
else
$DR = new Zotlabs\Lib\DReport(z_root(),$d['hash'],$d['hash'],'sync packet','channel sync delivered');
@@ -5185,7 +5189,7 @@ function zot6_check_sig() {
$sigblock = \Zotlabs\Web\HTTPSig::parse_sigheader($_SERVER['HTTP_SIGNATURE']);
if($sigblock) {
$keyId = $sigblock['keyId'];
-
+ logger('keyID: ' . $keyId);
if($keyId) {
$r = q("select hubloc.*, site_crypto from hubloc left join site on hubloc_url = site_url
where hubloc_addr = '%s' ",
@@ -5195,6 +5199,7 @@ function zot6_check_sig() {
foreach($r as $hubloc) {
$verified = \Zotlabs\Web\HTTPSig::verify('',$hubloc['xchan_pubkey']);
if($verified && $verified['header_signed'] && $verified['header_valid'] && $verified['content_signed'] && $verified['content_valid']) {
+ logger('zot6 verified');
$ret['hubloc'] = $hubloc;
$ret['success'] = true;
return $ret;