aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/acl_selectors.php47
-rw-r--r--include/bbcode.php14
-rw-r--r--include/channel.php45
-rw-r--r--include/connections.php17
-rw-r--r--include/conversation.php20
-rw-r--r--include/dir_fns.php21
-rw-r--r--include/event.php2
-rw-r--r--include/hubloc.php8
-rwxr-xr-xinclude/items.php3
-rw-r--r--include/network.php26
-rw-r--r--include/socgraph.php2
-rw-r--r--include/text.php61
-rw-r--r--include/xchan.php4
-rw-r--r--include/zid.php42
-rw-r--r--include/zot.php51
15 files changed, 261 insertions, 102 deletions
diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index 35e385058..a3476439a 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -79,24 +79,44 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti
$custom = false;
}
- $r = q("SELECT id, profile_guid, profile_name from profile where is_default = 0 and uid = %d order by profile_name",
+ $r = q("SELECT id, hash, gname FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
intval(local_channel())
);
+
if($r) {
- foreach($r as $rv) {
- $selected = (($single_group && 'vp.' . $rv['profile_guid'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
- $groups .= '<option id="' . 'vp' . $rv['id'] . '" value="' . 'vp.' . $rv['profile_guid'] . '"' . $selected . '>' . t('Profile','acl') . ' ' . $rv['profile_name'] . '</option>' . "\r\n";
+ $groups .= '<optgroup label = "' . t('Privacy Groups').'">';
+ foreach($r as $rr) {
+ $selected = (($single_group && $rr['hash'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
+ $groups .= '<option id="' . $rr['id'] . '" value="' . $rr['hash'] . '"' . $selected . '>' . $rr['gname'] . '</option>' . "\r\n";
}
+ $groups .= '</optgroup>';
}
- $r = q("SELECT id, hash, gname FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
+ $r = q("SELECT id, profile_guid, profile_name from profile where is_default = 0 and uid = %d order by profile_name",
intval(local_channel())
);
if($r) {
- foreach($r as $rr) {
- $selected = (($single_group && $rr['hash'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
- $groups .= '<option id="' . $rr['id'] . '" value="' . $rr['hash'] . '"' . $selected . '>' . $rr['gname'] . '</option>' . "\r\n";
+ $groups .= '<optgroup label = "' . t('Profile-Based Privacy Groups').'">';
+ foreach($r as $rv) {
+ $selected = (($single_group && 'vp.' . $rv['profile_guid'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
+ $groups .= '<option id="' . 'vp' . $rv['id'] . '" value="' . 'vp.' . $rv['profile_guid'] . '"' . $selected . '>' . $rv['profile_name'] . '</option>' . "\r\n";
+ }
+ $groups .= '</optgroup>';
+ }
+
+ // $dialog_description is only set in places where we set permissions for a post.
+ // Abuse this fact to decide if forums should be displayed or not.
+ if($dialog_description) {
+ $forums = get_forum_channels(local_channel(),1);
+ if($forums) {
+ $groups .= '<optgroup label = "' . t('Forums').'">';
+ foreach($forums as $f) {
+ $private = (($f['private_forum']) ? ' (' . t('Private Forum') . ')' : '');
+ $selected = (($single_group && $f['hash'] === $allow_cid[0]) ? ' selected = "selected" ' : '');
+ $groups .= '<option id="^' . $f['abook_id'] . '" value="^' . $f['xchan_hash'] . '"' . $selected . '>' . $f['xchan_name'] . $private . '</option>' . "\r\n";
+ }
+ $groups .= '</optgroup>';
}
}
@@ -104,17 +124,18 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti
$o = replace_macros($tpl, array(
'$showall' => $showall_caption,
'$onlyme' => t('Only me'),
- '$groups' => $groups,
+ '$groups' => $groups,
'$public_selected' => (($has_acl) ? false : true),
'$justme_selected' => $just_me,
'$custom_selected' => $custom,
'$showallOrigin' => $showall_origin,
'$showallIcon' => $showall_icon,
- '$select_label' => t('Who can see this?'),
+ '$select_label' => t('Share with'),
'$custom' => t('Custom selection'),
- '$showlimitedDesc' => t('Select "Show" to allow viewing. "Don\'t show" lets you override and limit the scope of "Show".'),
- '$show' => t('Show'),
- '$hide' => t("Don't show"),
+ '$custom_label' => t('Advanced'),
+ '$showlimitedDesc' => t('Select "Allow" to allow viewing. "Don\'t allow" lets you override and limit the scope of "Allow".'),
+ '$show' => t('Allow'),
+ '$hide' => t("Don't allow"),
'$search' => t('Search'),
'$allowcid' => json_encode($allow_cid),
'$allowgid' => json_encode($allow_gid),
diff --git a/include/bbcode.php b/include/bbcode.php
index e5b2a068a..d79429719 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -218,7 +218,7 @@ function bb_replace_images($body, $images) {
// We're depending on the property of 'foreach' (specified on the PHP website) that
// it loops over the array starting from the first element and going sequentially
// to the last element
- $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '<img src="' . $image .'" alt="' . t('Image/photo') . '" />', $newbody);
+ $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '<img src="' . $image .'" alt="' . t('Image/photo') . '" loading="eager" />', $newbody);
$cnt++;
}
// logger('replace_images: ' . $newbody);
@@ -513,7 +513,7 @@ function bb_ShareAttributes($match) {
$headline = '<div id="shared_container_' . $rnd . '" class="shared_container"> <div id="shared_header_' . $rnd . '" class="shared_header">';
if ($avatar != "")
- $headline .= '<a href="' . (($auth) ? zid($profile) : $profile) . '" ><img src="' . $avatar . '" alt="' . $author . '" height="32" width="32" /></a>';
+ $headline .= '<a href="' . (($auth) ? zid($profile) : $profile) . '" ><img src="' . $avatar . '" alt="' . $author . '" height="32" width="32" loading="lazy" /></a>';
if(strpos($link,'/cards/'))
$type = t('card');
@@ -881,7 +881,7 @@ function bb_imgoptions($match) {
// now assemble the resulting img tag from these components
- $output = '<img ' . (($match[1] === 'z') ? 'class="zrl" ' : '') . ' ';
+ $output = '<img ' . (($match[1] === 'z') ? 'class="zrl" loading="eager"' : '') . ' ';
if ($width) {
$style .= 'width: 100%; max-width: ' . $width . 'px; ';
@@ -1483,19 +1483,19 @@ function bbcode($Text, $options = []) {
// Images
// [img]pathtoimage[/img]
if (strpos($Text,'[/img]') !== false) {
- $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img style="max-width: 100%;" src="$1" alt="' . t('Image/photo') . '" />', $Text);
+ $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img style="max-width: 100%;" src="$1" alt="' . t('Image/photo') . '" loading="eager" />', $Text);
}
// [img=pathtoimage]image description[/img]
if (strpos($Text,'[/img]') !== false) {
- $Text = preg_replace("/\[img=http(.*?)\](.*?)\[\/img\]/ism", '<img style="max-width: 100%;" src="http$1" alt="$2" title="$2"/>', $Text);
+ $Text = preg_replace("/\[img=http(.*?)\](.*?)\[\/img\]/ism", '<img style="max-width: 100%;" src="http$1" alt="$2" title="$2" loading="eager" />', $Text);
}
// [zmg]pathtoimage[/zmg]
if (strpos($Text,'[/zmg]') !== false) {
- $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img class="zrl" style="max-width: 100%;" src="$1" alt="' . t('Image/photo') . '" />', $Text);
+ $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img class="zrl" style="max-width: 100%;" src="$1" alt="' . t('Image/photo') . '" loading="eager" />', $Text);
}
// [zmg=pathtoimage]image description[/zmg]
if (strpos($Text,'[/zmg]') !== false) {
- $Text = preg_replace("/\[zmg=http(.*?)\](.*?)\[\/zmg\]/ism", '<img class="zrl" style="max-width: 100%;" src="http$1" alt="$2" title="$2"/>', $Text);
+ $Text = preg_replace("/\[zmg=http(.*?)\](.*?)\[\/zmg\]/ism", '<img class="zrl" style="max-width: 100%;" src="http$1" alt="$2" title="$2" loading="eager" />', $Text);
}
$Text = preg_replace_callback("/\[([zi])mg([ \=])(.*?)\](.*?)\[\/[zi]mg\]/ism",'bb_imgoptions',$Text);
diff --git a/include/channel.php b/include/channel.php
index 05f1bd34b..e2be4d8a8 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -341,6 +341,7 @@ function create_identity($arr) {
'hubloc_guid' => $guid,
'hubloc_guid_sig' => $zsig,
'hubloc_hash' => $zhash,
+ 'hubloc_id_url' => channel_url($ret['channel']),
'hubloc_addr' => channel_reddress($ret['channel']),
'hubloc_primary' => intval($primary),
'hubloc_url' => z_root(),
@@ -360,7 +361,7 @@ function create_identity($arr) {
'hubloc_guid' => $guid,
'hubloc_guid_sig' => $sig,
'hubloc_hash' => $hash,
- 'hubloc_id_url' => channel_url($ret['channel']),
+ 'hubloc_id_url' => channel_url($ret['channel']),
'hubloc_addr' => channel_reddress($ret['channel']),
'hubloc_primary' => intval($primary),
'hubloc_url' => z_root(),
@@ -1924,7 +1925,7 @@ function zid_init() {
call_hooks('zid_init', $arr);
if(! local_channel()) {
- $r = q("select * from hubloc where hubloc_addr = '%s' order by hubloc_connected desc",
+ $r = q("select hubloc_url, hubloc_hash, hubloc_network from hubloc where hubloc_addr = '%s' order by hubloc_connected desc",
dbesc($tmp_str)
);
if(! $r) {
@@ -1933,6 +1934,7 @@ function zid_init() {
if($r) {
$r = Libzot::zot_record_preferred($r);
}
+
if($r && remote_channel() && remote_channel() === $r['hubloc_hash'])
return;
@@ -2382,8 +2384,8 @@ function get_zcard($channel, $observer_hash = '', $args = array()) {
$cover = $r[0];
$cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['imgscale'];
} else {
- $default_cover = get_config('system','default_cover_photo','pexels-94622');
- $cover = [ 'href' => z_root() . '/images/default_cover_photos/' . $default_cover . '/' . $cover_width . '.jpg' ];
+ $default_cover = get_config('system','default_cover_photo','bggenerator');
+ $cover = [ 'href' => z_root() . '/images/default_cover_photos/' . $default_cover . '/' . $cover_width . '.png' ];
}
$o .= replace_macros(get_markup_template('zcard.tpl'), array(
@@ -2456,8 +2458,8 @@ function get_zcard_embed($channel, $observer_hash = '', $args = array()) {
$cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['imgscale'];
}
else {
- $default_cover = get_config('system','default_cover_photo','pexels-94622');
- $cover = [ 'href' => z_root() . '/images/default_cover_photos/' . $default_cover . '/' . $cover_width . '.jpg' ];
+ $default_cover = get_config('system','default_cover_photo','bggenerator');
+ $cover = [ 'href' => z_root() . '/images/default_cover_photos/' . $default_cover . '/' . $cover_width . '.png' ];
}
$o .= replace_macros(get_markup_template('zcard_embed.tpl'),array(
@@ -2714,6 +2716,9 @@ function account_remove($account_id, $local = true, $unset_session = true) {
logger('account_remove: ' . $account_id);
+ // Global removal (all clones) not currently supported
+ $local = true;
+
if(! intval($account_id)) {
logger('No account.');
return false;
@@ -2774,6 +2779,11 @@ function channel_remove($channel_id, $local = true, $unset_session = false) {
if(! $channel_id)
return;
+ // global removal (all clones) not currently supported
+ // hence this operation _may_ leave orphan data on remote servers
+
+ $local = true;
+
logger('Removing channel: ' . $channel_id);
logger('local only: ' . intval($local));
@@ -2792,6 +2802,7 @@ function channel_remove($channel_id, $local = true, $unset_session = false) {
*/
call_hooks('channel_remove', $r[0]);
+/*
if(! $local) {
if(intval($r[0]['channel_removed'])) {
@@ -2811,17 +2822,20 @@ function channel_remove($channel_id, $local = true, $unset_session = false) {
logger('deleting hublocs',LOGGER_DEBUG);
- $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'",
- dbesc($channel['channel_hash'])
+ $r = q("UPDATE hubloc SET hubloc_deleted = 1 WHERE hubloc_hash = '%s' OR hubloc_hash = '%s'",
+ dbesc($channel['channel_hash']),
+ dbesc($channel['channel_portable_id'])
+
);
- $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'",
- dbesc($channel['channel_hash'])
+ $r = q("UPDATE xchan SET xchan_deleted = 1 WHERE xchan_hash = '%s' OR xchan_hash = '%s'",
+ dbesc($channel['channel_hash']),
+ dbesc($channel['channel_portable_id'])
);
Master::Summon(array('Notifier','purge_all',$channel_id));
}
-
+*/
$r = q("select iid from iconfig left join item on item.id = iconfig.iid
where item.uid = %d",
@@ -2900,8 +2914,9 @@ function channel_remove($channel_id, $local = true, $unset_session = false) {
logger('deleting hublocs',LOGGER_DEBUG);
- $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s' and hubloc_url = '%s' ",
+ $r = q("UPDATE hubloc SET hubloc_deleted = 1 WHERE (hubloc_hash = '%s' OR hubloc_hash = '%s') AND hubloc_url = '%s' ",
dbesc($channel['channel_hash']),
+ dbesc($channel['channel_portable_id']),
dbesc(z_root())
);
@@ -2916,14 +2931,14 @@ function channel_remove($channel_id, $local = true, $unset_session = false) {
$hublocs = count($r);
if(! $hublocs) {
- $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s' ",
- dbesc($channel['channel_hash'])
+ $r = q("UPDATE xchan SET xchan_deleted = 1 WHERE xchan_hash = '%s' OR xchan_hash = '%s'",
+ dbesc($channel['channel_hash']),
+ dbesc($channel['channel_portable_id'])
);
}
//remove from file system
-
$f = 'store/' . $channel['channel_address'];
if(is_dir($f)) {
@rrmdir($f);
diff --git a/include/connections.php b/include/connections.php
index c7ec163c8..658fb6ee6 100644
--- a/include/connections.php
+++ b/include/connections.php
@@ -446,8 +446,13 @@ function contact_remove($channel_id, $abook_id) {
);
$r = q("delete from abconfig where chan = %d and xchan = '%s'",
- intval($channel_id),
- dbesc($abook['abook_xchan'])
+ intval($channel_id),
+ dbesc($abook['abook_xchan'])
+ );
+
+ $r = q("delete from source where src_channel_id = %d and src_xchan = '%s'",
+ intval($channel_id),
+ dbesc($abook['abook_xchan'])
);
return true;
@@ -775,7 +780,7 @@ function vcard_query(&$r) {
function z6trans_connections() {
- $r = q("SELECT DISTINCT abook.abook_xchan, hubloc.hubloc_addr, hubloc.hubloc_url, hubloc.hubloc_guid, site.site_project, site.site_version FROM abook
+ $r = dbq("SELECT DISTINCT abook.abook_xchan, hubloc.hubloc_addr, hubloc.hubloc_url, hubloc.hubloc_guid, site.site_project, site.site_version FROM abook
LEFT JOIN hubloc ON abook_xchan = hubloc_hash
LEFT JOIN site ON hubloc_url = site_url
WHERE abook.abook_self = 0 AND hubloc.hubloc_network = 'zot'
@@ -806,7 +811,7 @@ function z6trans_connections() {
logger("z6trans_connections: transition $zot_xchan to $zot6_xchan");
- q("START TRANSACTION");
+ dbq("START TRANSACTION");
$q1 = q("UPDATE abook set abook_xchan = '%s' WHERE abook_xchan = '%s'",
dbesc($zot6_xchan),
@@ -824,13 +829,13 @@ function z6trans_connections() {
);
if($q1 && $q2 && $q3) {
- q("COMMIT");
+ dbq("COMMIT");
logger("z6trans_connections: completed");
continue;
}
logger("z6trans_connections: failed - performing rollback");
- q("ROLLBACK");
+ dbq("ROLLBACK");
}
}
diff --git a/include/conversation.php b/include/conversation.php
index b43a6f47e..e77404cff 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -102,22 +102,33 @@ function localize_item(&$item){
logger('localize_item: failed to decode object: ' . print_r($item['obj'],true));
}
- if($obj['author'] && $obj['author']['link'])
+ if(is_array($obj['author']) && $obj['author']['link'])
$author_link = get_rel_link($obj['author']['link'],'alternate');
+ elseif(is_array($obj['actor']) && $obj['actor']['url'])
+ $author_link = ((is_array($obj['actor']['url'])) ? $obj['actor']['url'][0]['href'] : $obj['actor']['url']);
else
$author_link = '';
$author_name = (($obj['author'] && $obj['author']['name']) ? $obj['author']['name'] : '');
- $item_url = get_rel_link($obj['link'],'alternate');
+ if(!$author_name)
+ $author_name = ((is_array($obj['actor']) && $obj['actor']['name']) ? $obj['actor']['name'] : '');
+
+ if(is_array($obj['link']))
+ $item_url = get_rel_link($obj['link'],'alternate');
+
+ if(!$item_url)
+ $item_url = $obj['id'];
$Bphoto = '';
switch($obj['type']) {
case ACTIVITY_OBJ_PHOTO:
+ case 'Photo':
$post_type = t('photo');
break;
case ACTIVITY_OBJ_EVENT:
+ case 'Event':
$post_type = t('event');
break;
case ACTIVITY_OBJ_PERSON:
@@ -142,9 +153,10 @@ function localize_item(&$item){
break;
case ACTIVITY_OBJ_NOTE:
+ case 'Note':
default:
- $post_type = t('status');
- if($obj['id'] != $obj['parent'])
+ $post_type = t('post');
+ if(($obj['parent'] && $obj['id'] != $obj['parent']) || $obj['inReplyTo'])
$post_type = t('comment');
break;
}
diff --git a/include/dir_fns.php b/include/dir_fns.php
index 34a6f13cd..f477b35dd 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -3,6 +3,10 @@
* @file include/dir_fns.php
*/
+use Zotlabs\Lib\Libzot;
+use Zotlabs\Lib\Webfinger;
+use Zotlabs\Lib\Zotfinger;
+
require_once('include/permissions.php');
/**
@@ -67,15 +71,10 @@ function check_upstream_directory() {
$isadir = true;
if ($directory) {
- $h = parse_url($directory);
- if ($h) {
- $j = Zotlabs\Zot\Finger::run('[system]@' . $h['host']);
- if ($j['success']) {
- if (array_key_exists('site', $j) && array_key_exists('directory_mode', $j['site'])) {
- if ($j['site']['directory_mode'] === 'normal') {
- $isadir = false;
- }
- }
+ $j = Zotfinger::exec($directory);
+ if (array_path_exists('data/directory_mode',$j)) {
+ if ($j['data']['directory_mode'] === 'normal') {
+ $isadir = false;
}
}
}
@@ -341,9 +340,9 @@ function update_directory_entry($ud) {
// Hubzilla channels running traditional zot which have not upgraded can or will be dropped from the directory or
// "not found" at the end of the transition period as the directory will only serve zot6 entries at that time.
- $uri = \Zotlabs\Lib\Webfinger::zot_url($ud['ud_addr']);
+ $uri = Webfinger::zot_url($ud['ud_addr']);
if($uri) {
- $record = \Zotlabs\Lib\Zotfinger::exec($uri);
+ $record = Zotfinger::exec($uri);
// Check the HTTP signature
diff --git a/include/event.php b/include/event.php
index 679440726..765086167 100644
--- a/include/event.php
+++ b/include/event.php
@@ -1247,7 +1247,7 @@ function event_store_item($arr, $event) {
$item_arr['deny_cid'] = $arr['deny_cid'];
$item_arr['deny_gid'] = $arr['deny_gid'];
$item_arr['item_private'] = $private;
- $item_arr['verb'] = ACTIVITY_POST;
+ $item_arr['verb'] = 'Invite';
$item_arr['item_wall'] = $item_wall;
$item_arr['item_origin'] = $item_origin;
$item_arr['item_thread_top'] = $item_thread_top;
diff --git a/include/hubloc.php b/include/hubloc.php
index 059a4dadc..6b896c627 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -247,6 +247,7 @@ function hubloc_change_primary($hubloc) {
*
* We use the post url to distinguish between http and https hublocs.
* The https might be alive, and the http dead.
+ * Also set site_dead for the corresponding entry in the site table.
*
* @param string $posturl Hubloc callback url which to disable
*/
@@ -255,6 +256,13 @@ function hubloc_mark_as_down($posturl) {
intval(HUBLOC_OFFLINE),
dbesc($posturl)
);
+
+ // extract the baseurl and set site.site_dead to match
+ $m = parse_url($posturl);
+ $h = $m['scheme'] . '://' . $m['host'];
+ $r = q("update site set site_dead = 1 where site_url = '%s'",
+ dbesc($h)
+ );
}
diff --git a/include/items.php b/include/items.php
index 0cfa2a340..960aa3580 100755
--- a/include/items.php
+++ b/include/items.php
@@ -3175,6 +3175,7 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
// This MAY cause you to run afoul of copyright law.
$rewrite_author = intval(get_abconfig($channel['channel_id'],$item['owner_xchan'],'system','rself'));
+
if($rewrite_author) {
$item['author_xchan'] = $channel['channel_hash'];
@@ -3246,7 +3247,7 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
"' 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') .
+ "' auth='" . ((in_array($item['author']['xchan_network'], ['zot6','zot'])) ? 'true' : 'false') .
"' posted='" . $item['created'] .
"' message_id='" . $item['mid'] .
"']";
diff --git a/include/network.php b/include/network.php
index d9d534cd7..4457f59bc 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1120,9 +1120,9 @@ function discover_by_webbie($webbie, $protocol = '') {
continue;
}
- $x = Libzot::import_xchan($record['data']);
- if($x['success']) {
- return $x['hash'];
+ $y = Libzot::import_xchan($record['data']);
+ if($y['success']) {
+ return $y['hash'];
}
}
}
@@ -2061,3 +2061,23 @@ function get_request_string($url) {
return '/' . ((count($a) > 3) ? $a[3] : EMPTY_STR);
}
+
+
+/*
+ *
+ * Takes the output of parse_url and builds a URL from it
+ *
+ */
+
+function unparse_url($parsed_url) {
+ $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
+ $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
+ $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
+ $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
+ $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
+ $pass = ($user || $pass) ? "$pass@" : '';
+ $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
+ $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
+ $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
+ return "$scheme$user$pass$host$port$path$query$fragment";
+}
diff --git a/include/socgraph.php b/include/socgraph.php
index 3d26f5cfd..3da4dce63 100644
--- a/include/socgraph.php
+++ b/include/socgraph.php
@@ -158,7 +158,7 @@ function poco_load($xchan = '', $url = null) {
if($address) {
if($network === 'zot6') {
$j = Zotfinger::exec($profile_url);
- if(is_array($j) && array_path_exists('signature/signer',$j) && $j['signature']['signer'] === $profile_url && intval($j['signature']['header_valid'])) {
+ if(array_path_exists('signature/signer',$j) && $j['signature']['signer'] === $profile_url && intval($j['signature']['header_valid'])) {
Libzot::import_xchan($j['data']);
}
$x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1",
diff --git a/include/text.php b/include/text.php
index e798bf8f8..a300ccf58 100644
--- a/include/text.php
+++ b/include/text.php
@@ -659,6 +659,26 @@ function hz_syslog($msg, $priority = LOG_INFO) {
closelog();
}
+/**
+ * @brief like hz_syslog() but with a function backtrace to pinpoint certain classes
+ * of problems which show up deep in the calling stack.
+ *
+ * @param string $msg Message to log
+ * @param int $priority - compatible with syslog
+ */
+function bt_syslog($msg, $priority = LOG_INFO) {
+ $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ if($stack) {
+ for($x = 1; $x < count($stack); $x ++) {
+ $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()';
+ openlog("bt-log", LOG_PID | LOG_PERROR, LOG_LOCAL0);
+ syslog($priority, $msg);
+ closelog();
+ }
+ }
+}
+
+
/**
* @brief Logging function for Hubzilla.
@@ -742,7 +762,6 @@ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
for($x = 1; $x < count($stack); $x ++) {
$s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()';
logger($s,$level, $priority);
-
if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) {
@file_put_contents(BTLOGGER_DEBUG_FILE, $s . PHP_EOL, FILE_APPEND);
}
@@ -2236,7 +2255,7 @@ function item_post_type($item) {
$post_type = t('event');
break;
default:
- $post_type = t('status');
+ $post_type = t('post');
if($item['mid'] != $item['parent_mid'])
$post_type = t('comment');
break;
@@ -3661,11 +3680,15 @@ function get_forum_channels($uid) {
if(! $uid)
return;
- $xf = false;
+ if(App::$data['forum_channels'])
+ return App::$data['forum_channels'];
+
+ $xf = '';
$x1 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'send_stream' and v = '0'",
intval($uid)
);
+
if($x1) {
$xc = ids_to_querystr($x1,'xchan',true);
@@ -3673,22 +3696,21 @@ function get_forum_channels($uid) {
intval($uid)
);
- if($x2) {
- $xf = ids_to_querystr($x2,'xchan',true);
+ $xf = ids_to_querystr($x2,'xchan',true);
+ $sql_extra = (($xf) ? ' and not xchan in (' . $xf . ')' : '');
- // private forums
- $x3 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'post_wall' and v = '1' and xchan in (" . $xc . ") and not xchan in (" . $xf . ") ",
- intval(local_channel())
- );
- if($x3) {
- $xf = ids_to_querystr(array_merge($x2,$x3),'xchan',true);
- }
+ // private forums
+ $x3 = q("select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'post_wall' and v = '1' and xchan in (" . $xc . ") $sql_extra ",
+ intval(local_channel())
+ );
+ if($x3) {
+ $xf = ids_to_querystr(array_merge($x2,$x3),'xchan',true);
}
}
- $sql_extra = (($xf) ? " and ( xchan_hash in (" . $xf . ") or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 ");
+ $sql_extra_1 = (($xf) ? " and ( xchan_hash in (" . $xf . ") or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 ");
- $r = q("select abook_id, xchan_hash, xchan_name, xchan_url, xchan_addr, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_deleted = 0 and abook_channel = %d and abook_pending = 0 and abook_ignored = 0 and abook_blocked = 0 and abook_archived = 0 $sql_extra order by xchan_name",
+ $r = q("select abook_id, xchan_hash, xchan_name, xchan_url, xchan_addr, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_deleted = 0 and abook_channel = %d and abook_pending = 0 and abook_ignored = 0 and abook_blocked = 0 and abook_archived = 0 $sql_extra_1 order by xchan_name",
intval($uid)
);
@@ -3702,6 +3724,8 @@ function get_forum_channels($uid) {
}
}
+ App::$data['forum_channels'] = $r;
+
return $r;
}
@@ -3816,3 +3840,12 @@ function unserialise($x) {
return ((is_array($y)) ? $y : $x);
}
+/**
+ * @brief Remove new lines and tabs from strings.
+ *
+ * @return string
+ */
+function sanitize_text_field($str) {
+ return preg_replace('/\s+/S', ' ', $str);
+}
+
diff --git a/include/xchan.php b/include/xchan.php
index d69d707aa..5de828e7f 100644
--- a/include/xchan.php
+++ b/include/xchan.php
@@ -25,7 +25,7 @@ function xchan_store_lowlevel($arr) {
'xchan_connurl' => ((array_key_exists('xchan_connurl',$arr)) ? $arr['xchan_connurl'] : ''),
'xchan_follow' => ((array_key_exists('xchan_follow',$arr)) ? $arr['xchan_follow'] : ''),
'xchan_connpage' => ((array_key_exists('xchan_connpage',$arr)) ? $arr['xchan_connpage'] : ''),
- 'xchan_name' => ((array_key_exists('xchan_name',$arr)) ? $arr['xchan_name'] : ''),
+ 'xchan_name' => ((array_key_exists('xchan_name',$arr)) ? sanitize_text_field($arr['xchan_name']) : ''),
'xchan_network' => ((array_key_exists('xchan_network',$arr)) ? $arr['xchan_network'] : ''),
'xchan_instance_url' => ((array_key_exists('xchan_instance_url',$arr)) ? $arr['xchan_instance_url'] : ''),
'xchan_flags' => ((array_key_exists('xchan_flags',$arr)) ? intval($arr['xchan_flags']) : 0),
@@ -264,4 +264,4 @@ function xchan_change_key($oldx,$newx,$data) {
foreach($acls as $k => $v) {
xchan_keychange_acl($k,$v,$oldx,$newx);
}
-} \ No newline at end of file
+}
diff --git a/include/zid.php b/include/zid.php
index 10e09e212..538adcc41 100644
--- a/include/zid.php
+++ b/include/zid.php
@@ -2,7 +2,6 @@
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Verify;
-use Zotlabs\Zot\Finger;
function is_matrix_url($url) {
@@ -280,44 +279,39 @@ function owt_init($token) {
Verify::purge('owt', '3 MINUTE');
- $key = Verify::get_meta('owt', 0, $token);
+ $ob_hash = Verify::get_meta('owt', 0, $token);
- if($key === false) {
- return;
- }
-
- $parts = explode(',',$key,2);
- if(count($parts) < 2) {
+ if($ob_hash === false) {
return;
}
$r = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash
- where hubloc_network = '%s' and hubloc_addr = '%s' order by hubloc_id desc",
- dbesc($parts[0]),
- dbesc($parts[1])
+ where hubloc_addr = '%s' or hubloc_id_url = '%s' or hubloc_hash = '%s' order by hubloc_id desc",
+ dbesc($ob_hash),
+ dbesc($ob_hash),
+ dbesc($ob_hash)
);
if(! $r) {
-
// finger them if they can't be found.
- // @todo check that this is still needed. Discovery should have been performed in the Owa module.
-
- $j = \Zotlabs\Zot\Finger::run($parts[1], null);
- if ($j['success']) {
- import_xchan($j);
+ $wf = discover_by_webbie($ob_hash);
+ if($wf) {
$r = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash
- where hubloc_network = '%s' and hubloc_addr = '%s' order by hubloc_id desc",
- dbesc($parts[0]),
- dbesc($parts[1])
+ where hubloc_addr = '%s' or hubloc_id_url = '%s' or hubloc_hash = '%s' order by hubloc_id desc",
+ dbesc($ob_hash),
+ dbesc($ob_hash),
+ dbesc($ob_hash)
);
}
}
if(! $r) {
- logger('owt: unable to finger ' . $key);
+ logger('owt: unable to finger ' . $ob_hash);
return;
}
-
- $hubloc = $r[0];
+
+ $r = Libzot::zot_record_preferred($r);
+
+ $hubloc = $r;
$_SESSION['authenticated'] = 1;
@@ -343,7 +337,7 @@ function owt_init($token) {
if (! $delegate_success) {
// normal visitor (remote_channel) login session credentials
$_SESSION['visitor_id'] = $hubloc['xchan_hash'];
- $_SESSION['my_url'] = $hubloc['xchan_url'];
+ $_SESSION['my_url'] = $hubloc['xchan_url'];
$_SESSION['my_address'] = $hubloc['hubloc_addr'];
$_SESSION['remote_hub'] = $hubloc['hubloc_url'];
$_SESSION['DNT'] = 1;
diff --git a/include/zot.php b/include/zot.php
index e10ef6fd7..8a2177de7 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -9,6 +9,8 @@
*/
use Zotlabs\Lib\DReport;
+use Zotlabs\Lib\Libzot;
+use Zotlabs\Lib\Activity;
require_once('include/crypto.php');
require_once('include/items.php');
@@ -1952,6 +1954,34 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
intval($channel['channel_id']),
dbesc($arr['owner_xchan'])
);
+
+ if(! $ab) {
+
+ $best_owner_xchan = find_best_zot_identity($arr['owner_xchan']);
+
+ $ab = q("select * from abook where abook_channel = %d and abook_xchan = '%s'",
+ intval($channel['channel_id']),
+ dbesc($best_owner_xchan)
+ );
+
+ if($ab) {
+ logger('rewrite owner: ' . $arr['owner_xchan'] . ' > ' . $best_owner_xchan);
+ $arr['owner_xchan'] = $best_owner_xchan;
+ }
+ }
+
+ $best_author_xchan = find_best_zot_identity($arr['author_xchan']);
+
+ $ab_author = q("select * from abook where abook_channel = %d and abook_xchan = '%s'",
+ intval($channel['channel_id']),
+ dbesc($best_author_xchan)
+ );
+
+ if($ab_author) {
+ logger('rewrite author: ' . $arr['author_xchan'] . ' > ' . $best_author_xchan);
+ $arr['author_xchan'] = $best_author_xchan;
+ }
+
$abook = (($ab) ? $ab[0] : null);
if(intval($arr['item_deleted'])) {
@@ -5341,3 +5371,24 @@ function zot_record_preferred($arr, $check = 'hubloc_network') {
return $arr[0];
}
+
+function find_best_zot_identity($xchan) {
+
+ $r = q("select hubloc_addr from hubloc where hubloc_hash = '%s' and hubloc_network in ('zot6', 'zot') and hubloc_deleted = 0",
+ dbesc($xchan)
+ );
+
+ if ($r) {
+
+ $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_addr = '%s' and hubloc_network in ('zot6', 'zot') and hubloc_deleted = 0",
+ dbesc($r[0]['hubloc_addr'])
+ );
+ if ($r) {
+ $r = Libzot::zot_record_preferred($r);
+ logger('find_best_zot_identity: ' . $xchan . ' > ' . $r['hubloc_hash']);
+ return $r['hubloc_hash'];
+ }
+ }
+
+ return $xchan;
+}