Merge branch 'dev' of /home/macgirvin/z into dev

This commit is contained in:
nobody 2021-11-29 15:59:47 -08:00
commit 3afba5f697
8 changed files with 125 additions and 60 deletions

View file

@ -1,3 +1,13 @@
For reasons which will hopefully become obvious over time, I will be migrating a few repositories to PSR-12. PSR-12 is about coding style and in particular whitespace and it conflicts with a lot of our current codebase. This migration will take time. Once the migration has completed we will be adding these constraints to our integration tests.
I will apologise in advance because I actually have a number of serious issues with these conventions and the fact that they are so bloody inconsistent internally. My other gripe is that they actually make it harder for many developers to participate in a project because they might provide working code (the primary currency of open source) only to have it knocked back because the project involved is fascist about whitespace and coding style. I've been on the receiving end of this more time than I count and left a number of promising software projects over these barriers they put in place to reduce free and open collaboration and bury it in layers of bureaucratic muck.
But that is at a project level, and what this kind of standard provides is reduced friction in cross-project collaboration and code re-use across the commons. So it's a "looking at the bigger picture" move. Anyway, we're at kind of a quiet space in development and the target projects have very few external contributors at the moment. As the saying goes, "The best time to plant an oak tree is 25 years ago. The second best time is now."
Developer Certificate of Origin
Version 1.1

View file

@ -1335,6 +1335,9 @@ class Activity {
if ($img) {
for ($pc = 0; $pc < count($ret['attachment']); $pc ++) {
// caution: image attachments use url and links use href, and our own links will be 'attach' links based on the image href
// We could alternatively supply the correct attachment info when item is saved, but by replacing here we will pick up
// any "per-post" or manual changes to the image alt-text before sending.
if ((isset($ret['attachment'][$pc]['href']) && strpos($img[0]['url'],str_replace('/attach/','/photo/',$ret['attachment'][$pc]['href'])) !== false) || (isset($ret['attachment'][$pc]['url']) && $ret['attachment'][$pc]['url'] === $img[0]['url'])) {
// if it's already there, replace it with our alt-text aware version
$ret['attachment'][$pc] = $img[0];
@ -3675,14 +3678,21 @@ class Activity {
return;
}
}
$abook = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($observer_hash),
// fetch allow/deny lists for the sender, author, or both
// if you have them. post_is_importable() assumes true
// and only fails if there was intentional rejection
// due to this channel's filtering rules for content
// provided by either of these entities.
$abook = q("select * from abook where ( abook_xchan = '%s' OR abook_xchan = '%s') and abook_channel = %d ",
dbesc($item['author_xchan']),
dbesc($item['owner_xchan']),
intval($channel['channel_id'])
);
if (! post_is_importable($channel['channel_id'],$item,$abook[0])) {
if (! post_is_importable($channel['channel_id'],$item,$abook)) {
logger('post is filtered');
return;
}

View file

@ -963,14 +963,13 @@ class Libsync {
// match as many fields as possible in case anything at all changed.
$r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_site_id = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
$r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
dbesc($sender['hash']),
dbesc($sender['id']),
dbesc($sender['id_sig']),
dbesc($location['id_url']),
dbesc($location['url']),
dbesc($location['url_sig']),
dbesc($location['site_id']),
dbesc($location['host']),
dbesc($location['address']),
dbesc($location['callback']),
@ -978,7 +977,16 @@ class Libsync {
);
if($r) {
logger('Hub exists: ' . $location['url'], LOGGER_DEBUG);
// generate a new hubloc_site_id if it's wrong due to historical bugs 2021-11-30
if ($r[0]['hubloc_site_id'] !== $location['site_id']) {
q("update hubloc set hubloc_site_id = '%s' where hubloc_id = %d",
dbesc(Libzot::make_xchan_hash($location['url'],$location['sitekey'])),
intval($r[0]['hubloc_id'])
);
}
// update connection timestamp if this is the site we're talking to
// This only happens when called from import_xchan

View file

@ -2078,11 +2078,13 @@ class Libzot {
}
}
$ab = q("select * from abook where abook_channel = %d and abook_xchan = '%s'",
// This is used to fetch allow/deny rules if either the sender
// or owner is a connection. post_is_importable() evaluates all of them
$abook = q("select * from abook where abook_channel = %d and ( abook_xchan = '%s' OR abook_xchan = '%s' )",
intval($channel['channel_id']),
dbesc($arr['owner_xchan'])
dbesc($arr['owner_xchan']),
dbesc($arr['author_xchan'])
);
$abook = (($ab) ? $ab[0] : null);
if (isset($arr['item_deleted']) && intval($arr['item_deleted'])) {
@ -2129,16 +2131,17 @@ class Libzot {
elseif ($arr['edited'] > $r[0]['edited']) {
$arr['id'] = $r[0]['id'];
$arr['uid'] = $channel['channel_id'];
if (($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($channel['channel_id'],$arr,$abook))) {
$DR->update('update ignored');
$result[] = $DR->get();
}
else {
if (post_is_importable($channel['channel_id'],$arr,$abook)) {
$item_result = self::update_imported_item($sender,$arr,$r[0],$channel['channel_id'],$tag_delivery);
$DR->update('updated');
$result[] = $DR->get();
if(! $relay)
if (! $relay) {
add_source_route($item_id,$sender);
}
}
else {
$DR->update('update ignored');
$result[] = $DR->get();
}
}
else {
@ -2185,11 +2188,7 @@ class Libzot {
logger('message summary length exceeds max_import_size: truncated');
}
if (($arr['mid'] == $arr['parent_mid']) && (! post_is_importable($arr['uid'],$arr,$abook))) {
$DR->update('post ignored');
$result[] = $DR->get();
}
else {
if (post_is_importable($arr['uid'],$arr,$abook)) {
// Strip old-style hubzilla bookmarks
if (strpos($arr['body'],"#^[") !== false) {
@ -2222,6 +2221,10 @@ class Libzot {
$DR->update(($item_id) ? 'posted' : 'storage failed: ' . $item_result['message']);
$result[] = $DR->get();
}
else {
$DR->update('post ignored');
$result[] = $DR->get();
}
}
// preserve conversations with which you are involved from expiration

View file

@ -9,6 +9,7 @@ use Zotlabs\Render\Theme;
use Zotlabs\Lib\DB_Upgrade;
use Zotlabs\Lib\System;
use Zotlabs\Lib\PConfig;
use Zotlabs\Lib\Config;
use Zotlabs\Daemon\Run;
/**
@ -1577,11 +1578,13 @@ function fix_system_urls($oldurl, $newurl) {
dbesc($rv['xchan_hash'])
);
$y = q("update hubloc set hubloc_addr = '%s', hubloc_url = '%s', hubloc_id_url = '%s', hubloc_url_sig = '%s', hubloc_host = '%s', hubloc_callback = '%s' where hubloc_hash = '%s' and hubloc_url = '%s'",
$y = q("update hubloc set hubloc_addr = '%s', hubloc_url = '%s', hubloc_id_url = '%s', hubloc_url_sig = '%s', hubloc_site_id = '%s', hubloc_host = '%s', hubloc_callback = '%s' where hubloc_hash = '%s' and hubloc_url = '%s'",
dbesc($channel_address . '@' . $rhs),
dbesc($newurl),
dbesc(str_replace($oldurl,$newurl,$rv['hubloc_id_url'])),
dbesc(Libzot::sign($newurl,$c[0]['channel_prvkey'])),
dbesc(Libzot::make_xchan_hash($newurl,Config::Get('system','pubkey'))),
dbesc($newhost),
dbesc($newurl . '/post'),
dbesc($rv['xchan_hash']),
@ -2065,7 +2068,7 @@ function load_contact_links($uid) {
// logger('load_contact_links');
$r = q("SELECT abook_id, abook_flags, abook_my_perms, abook_their_perms, xchan_hash, xchan_photo_m, xchan_name, xchan_url, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d ",
$r = q("SELECT abook_id, abook_flags, abook_self, abook_incl, abook_excl, abook_my_perms, abook_their_perms, xchan_hash, xchan_photo_m, xchan_name, xchan_url, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d ",
intval($uid)
);
if($r) {

View file

@ -1628,51 +1628,71 @@ function conv_sort($arr, $order) {
foreach ($arr as $item) {
if (LibBlock::fetch_by_entity(local_channel(),$item['author_xchan']) || LibBlock::fetch_by_entity(local_channel(),$item['owner_xchan'])) {
continue;
}
$matches = null;
$found = false;
// perform view filtering if viewer is logged in locally
// This allows blocking and message filters to work on public stream items
// or other channel streams on this site which are not owned by the viewer
$cnt = preg_match_all("/\[share(.*?)portable_id='(.*?)'(.*?)\]/ism", $item['body'], $matches, PREG_SET_ORDER);
if ($cnt) {
foreach ($matches as $match) {
if (LibBlock::fetch_by_entity(local_channel(),$match[2])) {
$found = true;
}
if (local_channel()) {
if (LibBlock::fetch_by_entity(local_channel(),$item['author_xchan']) || LibBlock::fetch_by_entity(local_channel(),$item['owner_xchan'])) {
continue;
}
}
if ($found) {
continue;
}
$message_filter_abook = [];
if (App::$contacts && array_key_exists($item['author_xchan'], App::$contacts)) {
$message_filter_abook[] = App::$contacts[$item['author_xchan']];
}
if (App::$contacts && array_key_exists($item['owner_xchan'], App::$contacts)) {
$message_filter_abook[] = App::$contacts[$item['owner_xchan']];
}
if (! post_is_importable(local_channel(), $item, $message_filter_abook ? $message_filter_abook : false)) {
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'])) {
$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 (LibBlock::fetch_by_entity(local_channel(),$match[2])) {
$found = true;
}
}
}
}
if ($found) {
continue;
}
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

@ -3484,13 +3484,24 @@ function post_is_importable($channel_id,$item,$abook) {
if (! $abook) {
return true;
}
foreach ($abook as $ab) {
// check eligibility
if (intval($ab['abook_self'])) {
continue;
}
if (! ($ab['abook_incl'] || $ab['abook_excl']) ) {
continue;
}
if (! ($abook['abook_incl'] || $abook['abook_excl'])) {
return true;
$evaluator = MessageFilter::evaluate($item,$ab['abook_incl'],$ab['abook_excl']);
// A negative assessment for any individual connections
// is an instant fail
if (! $evaluater) {
return false;
}
}
return MessageFilter::evaluate($item,$abook['abook_incl'],$abook['abook_excl']);
return true;
}

View file

@ -1,2 +1,2 @@
<?php
define ( 'STD_VERSION', '21.11.21' );
define ( 'STD_VERSION', '21.11.30' );