aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r--Zotlabs/Module/Admin/Security.php61
-rw-r--r--Zotlabs/Module/Admin/Site.php18
-rw-r--r--Zotlabs/Module/Conversation.php188
-rw-r--r--Zotlabs/Module/Dircensor.php38
-rw-r--r--Zotlabs/Module/Directory.php25
-rw-r--r--Zotlabs/Module/Dirsearch.php63
-rw-r--r--Zotlabs/Module/Item.php99
-rw-r--r--Zotlabs/Module/Like.php6
-rw-r--r--Zotlabs/Module/Owa.php3
-rw-r--r--Zotlabs/Module/Photo.php3
-rw-r--r--Zotlabs/Module/Profiles.php7
-rw-r--r--Zotlabs/Module/Search.php4
-rw-r--r--Zotlabs/Module/Wfinger.php9
13 files changed, 372 insertions, 152 deletions
diff --git a/Zotlabs/Module/Admin/Security.php b/Zotlabs/Module/Admin/Security.php
index 16045f9ed..499572170 100644
--- a/Zotlabs/Module/Admin/Security.php
+++ b/Zotlabs/Module/Admin/Security.php
@@ -7,12 +7,12 @@ class Security {
function post() {
check_form_security_token_redirectOnErr('/admin/security', 'admin_security');
-
+
$allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
$not_allowed_email = ((x($_POST,'not_allowed_email')) ? notags(trim($_POST['not_allowed_email'])) : '');
set_config('system','allowed_email', $allowed_email);
- set_config('system','not_allowed_email', $not_allowed_email);
+ set_config('system','not_allowed_email', $not_allowed_email);
$block_public = ((x($_POST,'block_public')) ? True : False);
set_config('system','block_public',$block_public);
@@ -25,22 +25,22 @@ class Security {
$ws = $this->trim_array_elems(explode("\n",$_POST['whitelisted_sites']));
set_config('system','whitelisted_sites',$ws);
-
+
$bs = $this->trim_array_elems(explode("\n",$_POST['blacklisted_sites']));
set_config('system','blacklisted_sites',$bs);
-
+
$wc = $this->trim_array_elems(explode("\n",$_POST['whitelisted_channels']));
set_config('system','whitelisted_channels',$wc);
-
+
$bc = $this->trim_array_elems(explode("\n",$_POST['blacklisted_channels']));
set_config('system','blacklisted_channels',$bc);
-
+
$embed_sslonly = ((x($_POST,'embed_sslonly')) ? True : False);
set_config('system','embed_sslonly',$embed_sslonly);
-
+
$we = $this->trim_array_elems(explode("\n",$_POST['embed_allow']));
set_config('system','embed_allow',$we);
-
+
$be = $this->trim_array_elems(explode("\n",$_POST['embed_deny']));
set_config('system','embed_deny',$be);
@@ -49,47 +49,54 @@ class Security {
$inline_pdf = ((x($_POST,'inline_pdf')) ? intval($_POST['inline_pdf']) : 0);
set_config('system', 'inline_pdf' , $inline_pdf);
-
+
$ts = ((x($_POST,'transport_security')) ? True : False);
set_config('system','transport_security_header',$ts);
$cs = ((x($_POST,'content_security')) ? True : False);
set_config('system','content_security_policy',$cs);
+ $trusted_directory_servers = $this->trim_array_elems(explode("\n", $_POST['trusted_directory_servers']));
+ set_config('system', 'trusted_directory_servers', $trusted_directory_servers);
+
goaway(z_root() . '/admin/security');
}
-
-
+
+
function get() {
-
+
$whitesites = get_config('system','whitelisted_sites');
$whitesites_str = ((is_array($whitesites)) ? implode("\n",$whitesites) : '');
-
+
$blacksites = get_config('system','blacklisted_sites');
$blacksites_str = ((is_array($blacksites)) ? implode("\n",$blacksites) : '');
-
-
+
+
$whitechannels = get_config('system','whitelisted_channels');
$whitechannels_str = ((is_array($whitechannels)) ? implode("\n",$whitechannels) : '');
-
+
$blackchannels = get_config('system','blacklisted_channels');
$blackchannels_str = ((is_array($blackchannels)) ? implode("\n",$blackchannels) : '');
-
-
+
+
$whiteembeds = get_config('system','embed_allow');
$whiteembeds_str = ((is_array($whiteembeds)) ? implode("\n",$whiteembeds) : '');
-
+
$blackembeds = get_config('system','embed_deny');
$blackembeds_str = ((is_array($blackembeds)) ? implode("\n",$blackembeds) : '');
-
+
+ $trusted_directory_servers = get_config('system', 'trusted_directory_servers');
+ $trusted_directory_servers_str = ((is_array($trusted_directory_servers)) ? implode("\n", $trusted_directory_servers) : '');
+ $is_dir = (intval(get_config('system', 'directory_mode', DIRECTORY_MODE_NORMAL)) !== DIRECTORY_MODE_NORMAL);
+
$embed_coop = intval(get_config('system','embed_coop'));
-
+
if((! $whiteembeds) && (! $blackembeds)) {
$embedhelp1 = t("By default, unfiltered HTML is allowed in embedded media. This is inherently insecure.");
}
- $embedhelp2 = t("The recommended setting is to only allow unfiltered HTML from the following sites:");
+ $embedhelp2 = t("The recommended setting is to only allow unfiltered HTML from the following sites:");
$embedhelp3 = t("https://youtube.com/<br />https://www.youtube.com/<br />https://youtu.be/<br />https://vimeo.com/<br />https://soundcloud.com/<br />");
$embedhelp4 = t("All other embedded content will be filtered, <strong>unless</strong> embedded content from that site is explicitly blocked.");
@@ -99,7 +106,7 @@ class Security {
'$page' => t('Security'),
'$form_security_token' => get_form_security_token('admin_security'),
'$block_public' => array('block_public', t("Block public"), get_config('system','block_public'), t("Check to block public access to all otherwise public personal pages on this site unless you are currently authenticated.")),
- '$cloud_noroot' => [ 'cloud_noroot', t('Provide a cloud root directory'), 1 - intval(get_config('system','cloud_disable_siteroot')), t('The cloud root directory lists all channel names which provide public files') ],
+ '$cloud_noroot' => [ 'cloud_noroot', t('Provide a cloud root directory'), 1 - intval(get_config('system','cloud_disable_siteroot')), t('The cloud root directory lists all channel names which provide public files') ],
'$cloud_disksize' => [ 'cloud_disksize', t('Show total disk space available to cloud uploads'), intval(get_config('system','cloud_report_disksize')), '' ],
'$transport_security' => array('transport_security', t('Set "Transport Security" HTTP header'),intval(get_config('system','transport_security_header')),''),
'$content_security' => array('content_security', t('Set "Content Security Policy" HTTP header'),intval(get_config('system','content_security_policy')),''),
@@ -115,6 +122,8 @@ class Security {
'$thumbnail_security' => [ 'thumbnail_security', t("Allow SVG thumbnails in file browser"), get_config('system','thumbnail_security',0), t("WARNING: SVG images may contain malicious code.") ],
'$inline_pdf' => [ 'inline_pdf', t("Allow embedded (inline) PDF files"), get_config('system','inline_pdf',0), '' ],
+ '$trusted_directory_servers' => (($is_dir) ? ['trusted_directory_servers', t('Additional trusted directory server URLs'), $trusted_directory_servers_str, t('Accept directory flags (spam, nsfw) from those servers. One per line like https://example.tld')] : ''),
+
// '$embed_coop' => array('embed_coop', t('Cooperative embed security'), $embed_coop, t('Enable to share embed security with other compatible sites/hubs')),
'$submit' => t('Submit')
@@ -124,7 +133,7 @@ class Security {
function trim_array_elems($arr) {
$narr = array();
-
+
if($arr && is_array($arr)) {
for($x = 0; $x < count($arr); $x ++) {
$y = trim($arr[$x]);
@@ -134,6 +143,6 @@ class Security {
}
return $narr;
}
-
-
+
+
}
diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php
index 42cf064c9..b24821b28 100644
--- a/Zotlabs/Module/Admin/Site.php
+++ b/Zotlabs/Module/Admin/Site.php
@@ -67,7 +67,6 @@ class Site {
$open_pubstream = ((x($_POST,'open_pubstream')) ? True : False);
$login_on_homepage = ((x($_POST,'login_on_homepage')) ? True : False);
$enable_context_help = ((x($_POST,'enable_context_help')) ? True : False);
- $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
$no_community_page = !((x($_POST,'no_community_page')) ? True : False);
$default_expire_days = ((array_key_exists('default_expire_days',$_POST)) ? intval($_POST['default_expire_days']) : 0);
$active_expire_days = ((array_key_exists('active_expire_days',$_POST)) ? intval($_POST['active_expire_days']) : 7);
@@ -181,7 +180,7 @@ class Site {
set_config('system', 'admininfo', $admininfo);
}
set_config('system','siteinfo',$siteinfo);
- set_config('system', 'language', $language);
+ //set_config('system', 'language', $language);
set_config('system', 'theme', $theme);
// if ( $theme_mobile === '---' ) {
// del_config('system', 'mobile_theme');
@@ -206,11 +205,6 @@ class Site {
set_config('system','site_firehose', $site_firehose);
set_config('system','open_pubstream', $open_pubstream);
//set_config('system','force_queue_threshold', $force_queue);
- if ($global_directory == '') {
- del_config('system', 'directory_submit_url');
- } else {
- set_config('system', 'directory_submit_url', $global_directory);
- }
set_config('system','no_community_page', $no_community_page);
set_config('system','no_utf', $no_utf);
@@ -283,7 +277,7 @@ class Site {
}
$dir_choices = null;
- $dirmode = get_config('system','directory_mode');
+ $dirmode = get_config('system', 'directory_mode', DIRECTORY_MODE_NORMAL);
$realm = get_directory_realm();
// directory server should not be set or settable unless we are a directory client
@@ -301,6 +295,12 @@ class Site {
$dir_choices[$xx['site_url']] = $xx['site_url'];
}
}
+ if ($realm === DIRECTORY_REALM) {
+ $fallback_servers = get_directory_fallback_servers();
+ foreach ($fallback_servers as $fallback_server) {
+ $dir_choices[$fallback_server] = $fallback_server;
+ }
+ }
}
/* Banner */
@@ -425,7 +425,7 @@ class Site {
'$banner' => array('banner', t("Banner/Logo"), $banner, t('Unfiltered HTML/CSS/JS is allowed')),
'$admininfo' => array('admininfo', t("Administrator Information"), $admininfo, t("Contact information for site administrators. Displayed on siteinfo page. BBCode can be used here")),
'$siteinfo' => array('siteinfo', t('Site Information'), get_config('system','siteinfo'), t("Publicly visible description of this site. Displayed on siteinfo page. BBCode can be used here")),
- '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
+ //'$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
'$theme' => array('theme', t("System theme"), get_config('system','theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices),
// '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile_theme'), t("Theme for mobile devices"), $theme_choices_mobile),
// '$site_channel' => array('site_channel', t("Channel to use for this website's static pages"), get_config('system','site_channel'), t("Site Channel")),
diff --git a/Zotlabs/Module/Conversation.php b/Zotlabs/Module/Conversation.php
new file mode 100644
index 000000000..86ce66caa
--- /dev/null
+++ b/Zotlabs/Module/Conversation.php
@@ -0,0 +1,188 @@
+<?php
+
+namespace Zotlabs\Module;
+
+use Zotlabs\Web\Controller;
+use Zotlabs\Lib\ActivityStreams;
+use Zotlabs\Lib\Activity;
+use Zotlabs\Lib\Libzot;
+use Zotlabs\Web\HTTPSig;
+use Zotlabs\Lib\LDSignatures;
+use Zotlabs\Lib\ThreadListener;
+use Zotlabs\Lib\Config;
+use App;
+
+class Conversation extends Controller {
+
+ public function init() {
+
+ if (ActivityStreams::is_as_request()) {
+ $item_id = argv(1);
+
+ if (!$item_id) {
+ http_status_exit(404, 'Not found');
+ }
+
+ $portable_id = EMPTY_STR;
+
+ $item_normal_extra = sprintf(" and not verb in ('%s', '%s') ",
+ dbesc(ACTIVITY_FOLLOW),
+ dbesc(ACTIVITY_UNFOLLOW)
+ );
+
+ $item_normal = " and item.item_hidden = 0 and item.item_type = 0 and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_blocked = 0 $item_normal_extra ";
+
+ $i = null;
+
+ // do we have the item (at all)?
+
+ $r = q("select parent_mid from item where mid = '%s' or uuid = '%s' $item_normal order by item_wall desc limit 1",
+ dbesc(z_root() . '/item/' . $item_id),
+ dbesc($item_id)
+ );
+
+ if (!$r) {
+ http_status_exit(404, 'Not found');
+ }
+
+ // process an authenticated fetch
+
+ $sigdata = HTTPSig::verify(EMPTY_STR);
+ if ($sigdata['portable_id'] && $sigdata['header_valid']) {
+ $portable_id = $sigdata['portable_id'];
+ observer_auth($portable_id);
+
+ // first see if we have a copy of this item's parent owned by the current signer
+ // include xchans for all zot-like networks - these will have the same guid and public key
+
+ $x = q(
+ "select * from xchan where xchan_hash = '%s'",
+ dbesc($sigdata['portable_id'])
+ );
+
+ if ($x) {
+ $xchans = q(
+ "select xchan_hash from xchan where xchan_hash = '%s' OR ( xchan_guid = '%s' AND xchan_pubkey = '%s' ) ",
+ dbesc($sigdata['portable_id']),
+ dbesc($x[0]['xchan_guid']),
+ dbesc($x[0]['xchan_pubkey'])
+ );
+
+ if ($xchans) {
+ $hashes = ids_to_querystr($xchans, 'xchan_hash', true);
+ $i = q(
+ "select id as item_id from item where mid = '%s' $item_normal and owner_xchan in ( " . protect_sprintf($hashes) . " ) limit 1",
+ dbesc($r[0]['parent_mid'])
+ );
+ }
+ }
+ }
+ elseif (Config::get('system', 'require_authenticated_fetch', false)) {
+ http_status_exit(403, 'Permission denied');
+ }
+
+ // if we don't have a parent id belonging to the signer see if we can obtain one as a visitor that we have permission to access
+ // with a bias towards those items owned by channels on this site (item_wall = 1)
+
+ $sql_extra = item_permissions_sql(0);
+
+ if (!$i) {
+ $i = q("select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1",
+ dbesc($r[0]['parent_mid'])
+ );
+ }
+
+ if (!$i) {
+ http_status_exit(403, 'Forbidden');
+ }
+
+ $parents_str = ids_to_querystr($i, 'item_id');
+ $itemspage = 30;
+ $page = $_REQUEST['page'] ?? 1;
+ $offset = (intval($page) - 1) * $itemspage;
+
+ $items = dbq("SELECT item.*,
+ item.id AS item_id,
+ (SELECT count(*) FROM item WHERE item.parent IN ( $parents_str ) $item_normal) AS total
+ FROM item WHERE item.parent IN ( $parents_str ) $item_normal order by item.id LIMIT $itemspage OFFSET $offset"
+ );
+
+ if (!$items) {
+ http_status_exit(404, 'Not found');
+ }
+
+ xchan_query($items, true);
+ $items = fetch_post_tags($items);
+
+ $observer = App::get_observer();
+ $parent = $items[0];
+ $recips = (($parent['owner']['xchan_network'] === 'activitypub') ? get_iconfig($parent['id'], 'activitypub', 'recips', []) : []);
+ $to = (($recips && array_key_exists('to', $recips) && is_array($recips['to'])) ? $recips['to'] : null);
+ $nitems = [];
+ foreach ($items as $i) {
+ $mids = [];
+
+ if (intval($i['item_private'])) {
+ if (!$observer) {
+ continue;
+ }
+ /*
+ // ignore private reshare, possibly from hubzilla
+ if ($i['verb'] === 'Announce') {
+ if (!in_array($i['thr_parent'], $mids)) {
+ $mids[] = $i['thr_parent'];
+ }
+ continue;
+ }
+ // also ignore any children of the private reshares
+ if (in_array($i['thr_parent'], $mids)) {
+ continue;
+ }
+ */
+
+ if ((!$to) || (!in_array($observer['xchan_url'], $to))) {
+ continue;
+ }
+ }
+ $nitems[] = $i;
+ }
+
+ if (!$nitems) {
+ http_status_exit(404, 'Not found');
+ }
+
+ App::set_pager_total($nitems[0]['total']);
+ App::set_pager_itemspage($itemspage);
+
+ $channel = channelx_by_n($nitems[0]['uid']);
+
+ if (!$channel) {
+ http_status_exit(404, 'Not found');
+ }
+
+ if (!perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_stream')) {
+ http_status_exit(403, 'Forbidden');
+ }
+
+ $i = Activity::encode_item_collection($nitems, App::$query_string, 'OrderedCollection', $nitems[0]['total']);
+
+ if (!$i) {
+ http_status_exit(404, 'Not found');
+ }
+
+ if ($portable_id && (!intval($nitems[0]['item_private']))) {
+ $c = q("select abook_id from abook where abook_channel = %d and abook_xchan = '%s'",
+ intval($nitems[0]['uid']),
+ dbesc($portable_id)
+ );
+ if (!$c) {
+ ThreadListener::store(z_root() . '/item/' . $item_id, $portable_id);
+ }
+ }
+
+ as_return_and_die($i, $channel);
+ }
+
+ goaway(z_root() . '/item/' . argv(1));
+ }
+}
diff --git a/Zotlabs/Module/Dircensor.php b/Zotlabs/Module/Dircensor.php
index 0fa65e948..4ce3a81c4 100644
--- a/Zotlabs/Module/Dircensor.php
+++ b/Zotlabs/Module/Dircensor.php
@@ -4,6 +4,7 @@ namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
+use Zotlabs\Lib\Libzotdir;
class Dircensor extends Controller {
@@ -15,11 +16,12 @@ class Dircensor extends Controller {
$dirmode = intval(get_config('system','directory_mode'));
- if (! ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE)) {
+ if(!in_array($dirmode, [DIRECTORY_MODE_PRIMARY, DIRECTORY_MODE_SECONDARY, DIRECTORY_MODE_STANDALONE])) {
return;
}
$xchan = argv(1);
+
if(! $xchan) {
return;
}
@@ -32,19 +34,43 @@ class Dircensor extends Controller {
return;
}
- $val = (($r[0]['xchan_censored']) ? 0 : 1);
+ $severity = intval($_REQUEST['severity'] ?? 0);
+ $flag = DIRECTORY_FLAG_OK;
+
+ if ($severity === 1) {
+ $flag = DIRECTORY_FLAG_UNSAFE;
+ }
+
+ if ($severity === 2) {
+ $flag = DIRECTORY_FLAG_HIDDEN;
+ }
+
+ Libzotdir::update($xchan, $r[0]['xchan_url'], true, $flag);
- q("update xchan set xchan_censored = $val where xchan_hash = '%s'",
+ q("UPDATE xchan SET xchan_censored = %d WHERE xchan_hash = '%s'",
+ intval($flag),
dbesc($xchan)
);
- if($val) {
+ q("UPDATE xtag SET xtag_flags = %d WHERE xtag_hash = '%s'",
+ intval($flag),
+ dbesc($xchan)
+ );
+
+ if($flag) {
info( t('Entry censored') . EOL);
}
else {
- info( t('Entry uncensored') . EOL);
+ info( t('Entry OK') . EOL);
}
-
+
+ if (isset($_REQUEST['aj'])) {
+ json_return_and_die([
+ 'success' => 1,
+ 'flag' => $flag
+ ]);
+ }
+
goaway(z_root() . '/directory');
}
diff --git a/Zotlabs/Module/Directory.php b/Zotlabs/Module/Directory.php
index 2958e80dc..13353c108 100644
--- a/Zotlabs/Module/Directory.php
+++ b/Zotlabs/Module/Directory.php
@@ -151,7 +151,7 @@ class Directory extends Controller {
$url = '';
- if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
+ if(in_array($dirmode, [DIRECTORY_MODE_PRIMARY, DIRECTORY_MODE_SECONDARY, DIRECTORY_MODE_STANDALONE])) {
$url = z_root() . '/dirsearch';
if (is_site_admin()) {
$directory_admin = true;
@@ -191,7 +191,10 @@ class Directory extends Controller {
if(get_config('system','disable_directory_keywords'))
$kw = 0;
- $query = $url . '?f=&kw=' . $kw . (($safe_mode != 1) ? '&safe=' . $safe_mode : '');
+ if (intval($safe_mode) === 0 && $directory_admin)
+ $safe_mode = -1;
+
+ $query = $url . '?f=&kw=' . $kw . (($safe_mode < 1) ? '&safe=' . $safe_mode : '');
if($token)
$query .= '&t=' . $token;
@@ -296,10 +299,11 @@ class Directory extends Controller {
$hometown = ((x($profile,'hometown') == 1) ? html2plain($profile['hometown']) : False);
$about = ((x($profile,'about') == 1) ? zidify_links(bbcode($profile['about'], ['tryoembed' => false])) : False);
- if ($about && $safe_mode) {
- $about = html2plain($about);
+ if ($about && $safe_mode > 0) {
+ $about = strip_tags($about, '<br>');
}
+
$keywords = ((x($profile,'keywords')) ? $profile['keywords'] : '');
@@ -351,11 +355,15 @@ class Directory extends Controller {
'gender' => $gender,
'pdesc' => $pdesc,
'pdesc_label' => t('Description:'),
- 'censor' => (($directory_admin) ? 'dircensor/' . $rr['hash'] : ''),
- 'censor_label' => (($rr['censored']) ? t('Uncensor') : t('Censor')),
+ 'censor' => (($directory_admin) ? 'dircensor/' . $rr['hash'] . '?severity=' . ((intval($rr['censored']) > 0) ? 0 : 1) : ''),
+ 'censor_label' => t('Unsafe'),
+ 'censor_class' => ((intval($rr['censored']) === 1) ? 'active' : ''),
+ 'censor_2' => (($directory_admin) ? 'dircensor/' . $rr['hash'] . '?severity=' . ((intval($rr['censored']) > 1) ? 0 : 2) : ''),
+ 'censor_2_label' => t('Spam'),
+ 'censor_2_class' => ((intval($rr['censored']) > 1) ? 'active' : ''),
'marital' => $marital,
'homepage' => $homepage,
- 'homepageurl' => (($safe_mode) ? $homepageurl : linkify($homepageurl)),
+ 'homepageurl' => (($safe_mode > 0) ? $homepageurl : linkify($homepageurl)),
'hometown' => $hometown,
'hometown_label' => t('Hometown:'),
'about' => $about,
@@ -436,7 +444,8 @@ class Directory extends Controller {
'$reverse' => t('Reverse Alphabetic'),
'$date' => t('Newest to Oldest'),
'$reversedate' => t('Oldest to Newest'),
- '$suggest' => $suggest ? '&suggest=1' : ''
+ '$suggest' => $suggest ? '&suggest=1' : '',
+ '$directory_admin' => $directory_admin
));
diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php
index c0df8a1e3..7efac6345 100644
--- a/Zotlabs/Module/Dirsearch.php
+++ b/Zotlabs/Module/Dirsearch.php
@@ -15,8 +15,7 @@ class Dirsearch extends Controller {
$ret = array('success' => false);
- // logger('request: ' . print_r($_REQUEST,true));
-
+ // logger('request: ' . print_r($_REQUEST,true));
$dirmode = intval(get_config('system','directory_mode'));
@@ -25,7 +24,6 @@ class Dirsearch extends Controller {
json_return_and_die($ret);
}
-
$access_token = $_REQUEST['t'] ?? '';
$token = get_config('system','realm_token');
@@ -41,7 +39,8 @@ class Dirsearch extends Controller {
}
$sql_extra = '';
-
+ $keywords_query = '';
+ $hub_query = '';
$tables = array('name','address','locale','region','postcode','country','gender','marital','sexual','keywords');
@@ -85,9 +84,7 @@ class Dirsearch extends Controller {
// by default use a safe search
- $safe = ((x($_REQUEST,'safe'))); // ? intval($_REQUEST['safe']) : 1 );
- if ($safe === false)
- $safe = 1;
+ $safe = $_REQUEST['safe'] ?? 1;
if(array_key_exists('sync',$_REQUEST)) {
if($_REQUEST['sync'])
@@ -102,10 +99,10 @@ class Dirsearch extends Controller {
$hub = \App::get_hostname();
}
- if($hub)
- $hub_query = " and xchan_hash in (select hubloc_hash from hubloc where hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') ";
- else
- $hub_query = '';
+ if($hub) {
+ $hub_query = " and xchan_hash in (select hubloc_hash from hubloc where hubloc_deleted = 0 and hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') ";
+ }
+
$sort_order = ((x($_REQUEST,'order')) ? $_REQUEST['order'] : '');
@@ -131,9 +128,16 @@ class Dirsearch extends Controller {
$sql_extra .= $this->dir_query_build($joiner,'xprof_marital',$marital);
if($sexual)
$sql_extra .= $this->dir_query_build($joiner,'xprof_sexual',$sexual);
- if($keywords)
+ if($keywords && $name) {
+ // this is a general search
$sql_extra .= $this->dir_query_build($joiner,'xprof_keywords',$keywords);
-
+ }
+ if($keywords && !$name) {
+ // this is a search for keywords only
+ $keywords_arr = explode(',', $keywords);
+ stringify_array_elms($keywords_arr, true);
+ $keywords_query = " AND xchan_hash IN (SELECT xtag_hash FROM xtag WHERE xtag_term IN (" . protect_sprintf(implode(',', $keywords_arr)) . ")) ";
+ }
// we only support an age range currently. You must set both agege
// (greater than or equal) and agele (less than or equal)
@@ -177,9 +181,15 @@ class Dirsearch extends Controller {
$sql_extra .= " and xchan_addr like '%%" . \App::get_hostname() . "' ";
}
- $safesql = (($safe > 0) ? " and xchan_censored = 0 and xchan_selfcensored = 0 " : '');
+ $safesql = '';
+ if($safe > 0)
+ $safesql = " and xchan_censored = 0 and xchan_selfcensored = 0 ";
+
+ if($safe < 1)
+ $safesql = " and xchan_censored < 2 and xchan_selfcensored < 2 ";
+
if($safe < 0)
- $safesql = " and ( xchan_censored = 1 OR xchan_selfcensored = 1 ) ";
+ $safesql = " and xchan_censored < 3 and xchan_selfcensored < 2 ";
if($forums)
$safesql .= " and xchan_pubforum = " . ((intval($forums)) ? '1 ' : '0 ');
@@ -215,26 +225,25 @@ class Dirsearch extends Controller {
if($sync) {
$spkt = array('transactions' => array());
- $r = q("select * from updates where ud_date >= '%s' and ud_guid != '' and ud_addr != '' order by ud_date desc",
+
+ $r = q("SELECT * FROM updates WHERE ud_update = 0 AND ud_last = '%s' AND ud_date >= '%s' ORDER BY ud_date DESC",
+ dbesc(NULL_DATE),
dbesc($sync)
);
+
if($r) {
foreach($r as $rr) {
- $flags = array();
- if($rr['ud_flags'] & UPDATE_FLAGS_DELETED)
- $flags[] = 'deleted';
- if($rr['ud_flags'] & UPDATE_FLAGS_FORCED)
- $flags[] = 'forced';
-
- $spkt['transactions'][] = array(
+ $spkt['transactions'][] = [
'hash' => $rr['ud_hash'],
'address' => $rr['ud_addr'],
- 'transaction_id' => $rr['ud_guid'],
+ 'host' => $rr['ud_host'],
+ 'transaction_id' => $rr['ud_host'], // deprecated 2023-04-12 - can be removed after dir servers at version >= 8.4
'timestamp' => $rr['ud_date'],
- 'flags' => $flags
- );
+ 'flags' => $rr['ud_flags']
+ ];
}
}
+
json_return_and_die($spkt);
}
else {
@@ -264,7 +273,7 @@ class Dirsearch extends Controller {
xprof.xprof_hometown as hometown,
xprof.xprof_keywords as keywords
from xchan left join xprof on xchan_hash = xprof_hash left join hubloc on (hubloc_id_url = xchan_url and hubloc_hash = xchan_hash)
- where hubloc_primary = 1 and hubloc_updated > %s - INTERVAL %s and ( $logic $sql_extra ) $hub_query and xchan_network = 'zot6' and xchan_system = 0 and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0
+ where hubloc_primary = 1 and hubloc_updated > %s - INTERVAL %s and ( $logic $sql_extra ) $hub_query $keywords_query and xchan_network = 'zot6' and xchan_system = 0 and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0
$safesql $order $qlimit",
db_utcnow(),
db_quoteinterval('30 DAY')
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index b3b040e96..a5f66d72e 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -63,8 +63,8 @@ class Item extends Controller {
// do we have the item (at all)?
- $r = q("select * from item where mid = '%s' $item_normal limit 1",
- dbesc(z_root() . '/item/' . $item_id)
+ $r = q("select parent_mid from item where uuid = '%s' $item_normal limit 1",
+ dbesc($item_id)
);
if (!$r) {
@@ -84,7 +84,7 @@ class Item extends Controller {
}
observer_auth($portable_id);
- $i = q("select id as item_id from item where mid = '%s' $item_normal and owner_xchan = '%s' limit 1",
+ $i = q("select id as item_id, uid from item where mid = '%s' $item_normal and owner_xchan = '%s' limit 1",
dbesc($r[0]['parent_mid']),
dbesc($portable_id)
);
@@ -99,7 +99,7 @@ class Item extends Controller {
$sql_extra = item_permissions_sql(0);
if (!$i) {
- $i = q("select id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1",
+ $i = q("select id as item_id, uid from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1",
dbesc($r[0]['parent_mid'])
);
}
@@ -108,57 +108,53 @@ class Item extends Controller {
http_status_exit(403, 'Forbidden');
}
- $parents_str = ids_to_querystr($i, 'item_id');
-
- $items = q("SELECT item.*, item.id AS item_id FROM item WHERE item.parent IN ( %s ) $item_normal order by item.id asc",
- dbesc($parents_str)
- );
+ $chan = channelx_by_n($i[0]['uid']);
- if (!$items) {
+ if (!$chan) {
http_status_exit(404, 'Not found');
}
- xchan_query($items, true);
- $items = fetch_post_tags($items, true);
-
- if (!$items)
- http_status_exit(404, 'Not found');
+ if (!perm_is_allowed($chan['channel_id'], get_observer_hash(), 'view_stream')) {
+ http_status_exit(403, 'Forbidden');
+ }
- $chan = channelx_by_n($items[0]['uid']);
+ $parents_str = ids_to_querystr($i, 'item_id');
- if (!$chan)
- http_status_exit(404, 'Not found');
+ $total = q("SELECT count(*) AS count FROM item WHERE parent = %d $item_normal",
+ intval($parents_str)
+ );
- if (!perm_is_allowed($chan['channel_id'], get_observer_hash(), 'view_stream'))
- http_status_exit(403, 'Forbidden');
+ App::set_pager_total($total[0]['count']);
+ App::set_pager_itemspage(30);
+ if (App::$pager['total'] > App::$pager['itemspage']) {
+ // let mod conversation handle this request
+ App::$query_string = str_replace('item', 'conversation', App::$query_string);
+ $i = Activity::paged_collection_init(App::$pager['total'], App::$query_string);
+ as_return_and_die($i ,$chan);
+ }
+ else {
+ $items = q("SELECT item.*, item.id AS item_id FROM item WHERE item.parent = %d $item_normal ORDER BY item.id",
+ intval($parents_str)
+ );
- $i = Activity::encode_item_collection($items, 'conversation/' . $item_id, 'OrderedCollection');
+ xchan_query($items, true);
+ $items = fetch_post_tags($items, true);
- if (!$i)
- http_status_exit(404, 'Not found');
+ $i = Activity::encode_item_collection($items, App::$query_string, 'OrderedCollection', App::$pager['total']);
+ }
if ($portable_id && (!intval($items[0]['item_private']))) {
- ThreadListener::store(z_root() . '/item/' . $item_id, $portable_id);
+ $c = q("select abook_id from abook where abook_channel = %d and abook_xchan = '%s'",
+ intval($items[0]['uid']),
+ dbesc($portable_id)
+ );
+ if (!$c) {
+ ThreadListener::store(z_root() . '/item/' . $item_id, $portable_id);
+ }
}
- $x = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]], $i);
-
- $headers = [];
- $headers['Content-Type'] = 'application/x-zot+json';
- $x['signature'] = LDSignatures::sign($x, $chan);
- $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
- $headers['Digest'] = HTTPSig::generate_digest_header($ret);
- $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
- $h = HTTPSig::create_sig($headers, $chan['channel_prvkey'], channel_url($chan));
- HTTPSig::set_headers($h);
- echo $ret;
- killme();
-
+ as_return_and_die($i ,$chan);
}
if (ActivityStreams::is_as_request()) {
@@ -181,8 +177,7 @@ class Item extends Controller {
// do we have the item (at all)?
// add preferential bias to item owners (item_wall = 1)
- $r = q("select * from item where mid = '%s' or uuid = '%s' $item_normal order by item_wall desc limit 1",
- dbesc(z_root() . '/item/' . $item_id),
+ $r = q("select * from item where uuid = '%s' $item_normal order by item_wall desc limit 1",
dbesc($item_id)
);
@@ -255,23 +250,7 @@ class Item extends Controller {
}
}
- $x = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]], $i);
-
- $headers = [];
- $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
- $x['signature'] = LDSignatures::sign($x, $chan);
- $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
- $headers['Date'] = datetime_convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T');
- $headers['Digest'] = HTTPSig::generate_digest_header($ret);
- $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
- $h = HTTPSig::create_sig($headers, $chan['channel_prvkey'], channel_url($chan));
- HTTPSig::set_headers($h);
- echo $ret;
- killme();
+ as_return_and_die($i ,$chan);
}
diff --git a/Zotlabs/Module/Like.php b/Zotlabs/Module/Like.php
index 2cf792c8d..5779faa19 100644
--- a/Zotlabs/Module/Like.php
+++ b/Zotlabs/Module/Like.php
@@ -451,7 +451,7 @@ class Like extends Controller {
}
else {
$post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status'));
- if ($item['obj_type'] === ACTIVITY_OBJ_EVENT)
+ if (in_array($item['obj_type'], ['Event', ACTIVITY_OBJ_EVENT]))
$post_type = t('event');
$obj_type = (($item['resource_type'] === 'photo') ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE);
@@ -507,7 +507,7 @@ class Like extends Controller {
$private = (($public) ? 0 : 1);
}
else {
- $arr['parent'] = $item['id'];
+ $arr['parent'] = $item['parent'];
$arr['thr_parent'] = $item['mid'];
$ulink = '[zrl=' . $item_author['xchan_url'] . '][bdi]' . $item_author['xchan_name'] . '[/bdi][/zrl]';
$alink = '[zrl=' . $observer['xchan_url'] . '][bdi]' . $observer['xchan_name'] . '[/bdi][/zrl]';
@@ -524,7 +524,7 @@ class Like extends Controller {
$arr['uid'] = $owner_uid;
$arr['item_flags'] = $item['item_flags'];
$arr['item_wall'] = $item['item_wall'];
- $arr['parent_mid'] = (($extended_like) ? $arr['mid'] : $item['mid']);
+ $arr['parent_mid'] = (($extended_like) ? $arr['mid'] : $item['parent_mid']);
$arr['owner_xchan'] = (($extended_like) ? $ch[0]['xchan_hash'] : $thread_owner['xchan_hash']);
$arr['author_xchan'] = $observer['xchan_hash'];
$arr['body'] = sprintf($bodyverb, $alink, $ulink, $plink);
diff --git a/Zotlabs/Module/Owa.php b/Zotlabs/Module/Owa.php
index 3400defd7..02997d3f1 100644
--- a/Zotlabs/Module/Owa.php
+++ b/Zotlabs/Module/Owa.php
@@ -32,7 +32,8 @@ class Owa extends Controller {
$keyId = $sigblock['keyId'];
if ($keyId) {
$r = q("SELECT * FROM hubloc LEFT JOIN xchan ON hubloc_hash = xchan_hash
- WHERE hubloc_id_url = '%s' AND hubloc_deleted = 0 AND xchan_pubkey != '' ORDER BY hubloc_id DESC",
+ WHERE ( hubloc_addr = '%s' OR hubloc_id_url = '%s' ) AND hubloc_deleted = 0 AND xchan_pubkey != '' ORDER BY hubloc_id DESC",
+ dbesc(str_replace('acct:', '', $keyId)),
dbesc($keyId)
);
if (! $r) {
diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php
index 10d2e8f47..fa87d96e5 100644
--- a/Zotlabs/Module/Photo.php
+++ b/Zotlabs/Module/Photo.php
@@ -271,7 +271,6 @@ class Photo extends \Zotlabs\Web\Controller {
$modified = time();
header_remove('Pragma');
-
if((isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag) || (!isset($_SERVER['HTTP_IF_NONE_MATCH']) && isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] === gmdate("D, d M Y H:i:s", $modified) . " GMT")) {
header_remove('Expires');
header_remove('Cache-Control');
@@ -307,6 +306,8 @@ class Photo extends \Zotlabs\Web\Controller {
// This has performance considerations but we highly recommend you
// leave it alone.
+
+
$maxage = $cache_mode['age'];
if($cache_mode['exp'] || (! isset($expires)) || (isset($expires) && $expires - 60 < time()))
diff --git a/Zotlabs/Module/Profiles.php b/Zotlabs/Module/Profiles.php
index e248cd028..ce496252b 100644
--- a/Zotlabs/Module/Profiles.php
+++ b/Zotlabs/Module/Profiles.php
@@ -217,7 +217,6 @@ class Profiles extends \Zotlabs\Web\Controller {
check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
-
$is_default = (($orig[0]['is_default']) ? 1 : 0);
$profile_name = notags(trim($_POST['profile_name']));
@@ -579,12 +578,12 @@ class Profiles extends \Zotlabs\Web\Controller {
$channel = \App::get_channel();
if($namechanged && $is_default) {
- // change name on all associated xchans by matching the url
- q("UPDATE xchan SET xchan_name = '%s', xchan_name_date = '%s' WHERE xchan_url = '%s'",
+ q("UPDATE xchan SET xchan_name = '%s', xchan_name_date = '%s' WHERE xchan_hash = '%s'",
dbesc($name),
dbesc(datetime_convert()),
- dbesc(z_root() . '/channel/' . $channel['channel_address'])
+ dbesc($channel['xchan_hash'])
);
+
q("UPDATE channel SET channel_name = '%s' WHERE channel_hash = '%s'",
dbesc($name),
dbesc($channel['xchan_hash'])
diff --git a/Zotlabs/Module/Search.php b/Zotlabs/Module/Search.php
index 6601da29d..6b1060570 100644
--- a/Zotlabs/Module/Search.php
+++ b/Zotlabs/Module/Search.php
@@ -58,7 +58,7 @@ class Search extends Controller {
$o .= search($search, 'search-box', '/search', ((local_channel()) ? true : false));
- if (local_channel() && strpos($search, 'https://') === 0 && !$update && !$load) {
+ if (local_channel() && str_starts_with($search, 'https://') && !$update && !$load) {
$url = htmlspecialchars_decode($search);
@@ -75,7 +75,7 @@ class Search extends Controller {
if ($f) {
$mid = $f[0]['message_id'];
foreach ($f as $m) {
- if (strpos($search, $m['message_id']) === 0) {
+ if (str_starts_with($url, $m['message_id'])) {
$mid = $m['message_id'];
break;
}
diff --git a/Zotlabs/Module/Wfinger.php b/Zotlabs/Module/Wfinger.php
index 048fcde3f..43b039530 100644
--- a/Zotlabs/Module/Wfinger.php
+++ b/Zotlabs/Module/Wfinger.php
@@ -76,7 +76,10 @@ class Wfinger extends \Zotlabs\Web\Controller {
}
}
else {
- $r = channelx_by_nick($channel);
+ // Also provide already deleted channels info here.
+ // This is required in the case where we need to verify keys
+ // of updates which we have got via directory sync.
+ $r = channelx_by_nick($channel, true);
}
}
@@ -94,10 +97,6 @@ class Wfinger extends \Zotlabs\Web\Controller {
'href' => z_root() . '/owa',
],
];
-
-
-
-
}
if($resource && $r) {