2016-04-19 03:38:38 +00:00
|
|
|
<?php
|
2016-10-13 03:41:59 +00:00
|
|
|
|
2022-02-16 04:08:28 +00:00
|
|
|
namespace Code\Module;
|
2016-04-19 03:38:38 +00:00
|
|
|
|
2019-05-01 06:46:08 +00:00
|
|
|
use App;
|
2022-02-16 04:08:28 +00:00
|
|
|
use Code\Web\Controller;
|
2022-09-04 01:35:50 +00:00
|
|
|
use Code\Lib\Activity;
|
2022-06-21 21:51:29 +00:00
|
|
|
use Code\Lib\Config;
|
2022-02-16 04:08:28 +00:00
|
|
|
use Code\Lib\Libzotdir;
|
|
|
|
use Code\Lib\Libsync;
|
|
|
|
use Code\Lib\LibBlock;
|
|
|
|
use Code\Lib\Channel;
|
|
|
|
use Code\Lib\Navbar;
|
|
|
|
use Code\Lib\Socgraph;
|
2022-06-21 21:35:48 +00:00
|
|
|
use Code\Lib\XConfig;
|
2024-01-03 00:17:40 +00:00
|
|
|
use Code\Lib\JcsEddsa2022;
|
2022-09-04 01:35:50 +00:00
|
|
|
use Code\Web\HTTPSig;
|
2022-02-16 04:08:28 +00:00
|
|
|
use Code\Extend\Hook;
|
|
|
|
use Code\Render\Theme;
|
2022-06-23 07:38:34 +00:00
|
|
|
use Code\Lib\Url;
|
2022-02-12 20:43:29 +00:00
|
|
|
|
2018-06-05 06:19:16 +00:00
|
|
|
|
2016-04-19 03:38:38 +00:00
|
|
|
require_once('include/bbcode.php');
|
2019-05-05 20:06:15 +00:00
|
|
|
require_once('include/html2plain.php');
|
2016-04-19 03:38:38 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
define('DIRECTORY_PAGESIZE', 60);
|
2016-04-19 03:38:38 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
class Directory extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
App::set_pager_itemspage(DIRECTORY_PAGESIZE);
|
|
|
|
|
|
|
|
if (x($_GET, 'ignore') && local_channel()) {
|
2021-12-03 03:01:39 +00:00
|
|
|
q(
|
|
|
|
"insert into xign ( uid, xchan ) values ( %d, '%s' ) ",
|
2021-12-02 23:02:31 +00:00
|
|
|
intval(local_channel()),
|
|
|
|
dbesc($_GET['ignore'])
|
|
|
|
);
|
|
|
|
|
|
|
|
Libsync::build_sync_packet(local_channel(), ['xign' => [['uid' => local_channel(), 'xchan' => $_GET['ignore']]]]);
|
|
|
|
if ($_REQUEST['return']) {
|
|
|
|
goaway(z_root() . '/' . base64_decode($_REQUEST['return']));
|
|
|
|
}
|
|
|
|
goaway(z_root() . '/directory?f=&suggest=1');
|
|
|
|
}
|
|
|
|
|
|
|
|
$observer = get_observer_hash();
|
|
|
|
$global_changed = false;
|
2022-06-21 21:35:48 +00:00
|
|
|
$covers_changed = false;
|
2021-12-02 23:02:31 +00:00
|
|
|
$safe_changed = false;
|
|
|
|
$type_changed = false;
|
|
|
|
$active_changed = false;
|
|
|
|
|
|
|
|
if (array_key_exists('global', $_REQUEST)) {
|
|
|
|
$globaldir = intval($_REQUEST['global']);
|
|
|
|
if (get_config('system', 'localdir_hide')) {
|
|
|
|
$globaldir = 1;
|
|
|
|
}
|
|
|
|
$global_changed = true;
|
|
|
|
}
|
|
|
|
if ($global_changed) {
|
|
|
|
$_SESSION['globaldir'] = $globaldir;
|
|
|
|
if ($observer) {
|
|
|
|
set_xconfig($observer, 'directory', 'globaldir', $globaldir);
|
|
|
|
}
|
|
|
|
}
|
2022-06-21 21:51:29 +00:00
|
|
|
|
2022-06-21 21:35:48 +00:00
|
|
|
if (array_key_exists('covers', $_REQUEST)) {
|
|
|
|
$covers = intval($_REQUEST['covers']);
|
|
|
|
$covers_changed = true;
|
|
|
|
}
|
|
|
|
if ($covers_changed) {
|
|
|
|
$_SESSION['covers'] = $covers;
|
|
|
|
if ($observer) {
|
|
|
|
set_xconfig($observer, 'directory', 'covers', $covers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
if (array_key_exists('safe', $_REQUEST)) {
|
|
|
|
$safemode = intval($_REQUEST['safe']);
|
|
|
|
$safe_changed = true;
|
|
|
|
}
|
|
|
|
if ($safe_changed) {
|
|
|
|
$_SESSION['safemode'] = $safemode;
|
|
|
|
if ($observer) {
|
|
|
|
set_xconfig($observer, 'directory', 'safemode', $safemode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('type', $_REQUEST)) {
|
|
|
|
$type = intval($_REQUEST['type']);
|
|
|
|
$type_changed = true;
|
|
|
|
}
|
|
|
|
if ($type_changed) {
|
|
|
|
$_SESSION['chantype'] = $type;
|
|
|
|
if ($observer) {
|
|
|
|
set_xconfig($observer, 'directory', 'chantype', $type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('active', $_REQUEST)) {
|
|
|
|
$active = intval($_REQUEST['active']);
|
|
|
|
$active_changed = true;
|
|
|
|
}
|
|
|
|
if ($active_changed) {
|
|
|
|
$_SESSION['activedir'] = $active;
|
|
|
|
if ($observer) {
|
|
|
|
set_xconfig($observer, 'directory', 'activedir', $active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get()
|
|
|
|
{
|
|
|
|
$observer = get_observer_hash();
|
2022-09-04 05:51:24 +00:00
|
|
|
$token = '';
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
if (get_config('system', 'block_public_directory', true) && (!$observer)) {
|
|
|
|
notice(t('Public access denied.') . EOL);
|
|
|
|
return login(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
$globaldir = Libzotdir::get_directory_setting($observer, 'globaldir');
|
|
|
|
|
|
|
|
// override your personal global search pref if we're doing a navbar search of the directory
|
|
|
|
if (intval($_REQUEST['navsearch'])) {
|
|
|
|
$globaldir = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$safe_mode = Libzotdir::get_directory_setting($observer, 'safemode');
|
|
|
|
|
2022-06-26 22:40:09 +00:00
|
|
|
// replace with system.remote_cover_photos once work on this feature is complete
|
|
|
|
|
|
|
|
if (Config::Get('system','remote_cover_photos_directory')) {
|
2022-06-21 21:51:29 +00:00
|
|
|
$covers = Libzotdir::get_directory_setting($observer, 'covers');
|
|
|
|
} else {
|
|
|
|
$covers = false;
|
|
|
|
}
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$type = Libzotdir::get_directory_setting($observer, 'chantype');
|
|
|
|
|
|
|
|
$active = Libzotdir::get_directory_setting($observer, 'activedir');
|
|
|
|
|
|
|
|
$o = '';
|
2022-01-25 04:16:38 +00:00
|
|
|
Navbar::set_selected('Directory');
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
if (x($_POST, 'search')) {
|
|
|
|
$search = notags(trim($_POST['search']));
|
|
|
|
} else {
|
|
|
|
$search = ((x($_GET, 'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($search, '=')) {
|
|
|
|
$advanced = $search;
|
|
|
|
}
|
|
|
|
|
|
|
|
$keywords = (($_GET['keywords']) ? $_GET['keywords'] : '');
|
|
|
|
|
|
|
|
// Suggest channels if no search terms or keywords are given
|
|
|
|
$suggest = (local_channel() && x($_REQUEST, 'suggest')) ? $_REQUEST['suggest'] : '';
|
|
|
|
|
|
|
|
if ($suggest) {
|
|
|
|
// the directory options have no effect in suggestion mode
|
|
|
|
|
|
|
|
$globaldir = 1;
|
|
|
|
$safe_mode = 1;
|
|
|
|
$active = 1;
|
|
|
|
$type = 0;
|
|
|
|
|
|
|
|
// only return DIRECTORY_PAGESIZE suggestions as the suggestion sorting
|
|
|
|
// only works if the suggestion query and the directory query have the
|
|
|
|
// same number of results
|
|
|
|
|
|
|
|
App::set_pager_itemspage(60);
|
2022-02-14 19:55:01 +00:00
|
|
|
$r = Socgraph::suggestion_query(local_channel(), get_observer_hash(), App::$pager['start'], DIRECTORY_PAGESIZE);
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
if (!$r) {
|
|
|
|
if ($_REQUEST['aj']) {
|
|
|
|
echo '<div id="content-complete"></div>';
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
notice(t('No default suggestions were found.') . EOL);
|
2022-09-04 05:51:24 +00:00
|
|
|
return '';
|
2021-12-02 23:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remember in which order the suggestions were
|
|
|
|
$addresses = [];
|
|
|
|
$common = [];
|
|
|
|
$index = 0;
|
|
|
|
foreach ($r as $rr) {
|
|
|
|
$common[$rr['xchan_hash']] = ((intval($rr['total']) > 0) ? intval($rr['total']) - 1 : 0);
|
|
|
|
$addresses[$rr['xchan_hash']] = $index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build query to get info about suggested people
|
|
|
|
$advanced = '';
|
|
|
|
foreach (array_keys($addresses) as $address) {
|
|
|
|
$advanced .= "xhash=\"$address\" ";
|
|
|
|
}
|
|
|
|
// Remove last space in the advanced query
|
|
|
|
$advanced = rtrim($advanced);
|
|
|
|
}
|
|
|
|
|
2022-02-12 20:43:29 +00:00
|
|
|
$tpl = Theme::get_template('directory_header.tpl');
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
$dirmode = intval(get_config('system', 'directory_mode'));
|
|
|
|
|
|
|
|
$directory_admin = false;
|
|
|
|
|
|
|
|
$url = z_root() . '/dirsearch';
|
2022-01-25 01:26:12 +00:00
|
|
|
if (Channel::is_system(local_channel())) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$directory_admin = true;
|
|
|
|
}
|
|
|
|
|
2023-11-25 10:03:21 +00:00
|
|
|
$sys = Channel::get_system();
|
|
|
|
$sys_channel = $sys['channel_id'];
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$contacts = [];
|
|
|
|
|
|
|
|
if (local_channel()) {
|
2021-12-03 03:01:39 +00:00
|
|
|
$x = q(
|
|
|
|
"select abook_xchan from abook where abook_channel = %d",
|
2021-12-02 23:02:31 +00:00
|
|
|
intval(local_channel())
|
|
|
|
);
|
|
|
|
if ($x) {
|
|
|
|
foreach ($x as $xx) {
|
|
|
|
$contacts[] = $xx['abook_xchan'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($url) {
|
|
|
|
$numtags = get_config('system', 'directorytags');
|
|
|
|
|
|
|
|
$kw = ((intval($numtags) > 0) ? intval($numtags) : 50);
|
|
|
|
|
|
|
|
if (get_config('system', 'disable_directory_keywords')) {
|
|
|
|
$kw = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = $url . '?f=&kw=' . $kw . (($safe_mode != 1) ? '&safe=' . $safe_mode : '');
|
|
|
|
|
|
|
|
if ($token) {
|
|
|
|
$query .= '&t=' . $token;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$globaldir) {
|
|
|
|
$query .= '&hub=' . App::get_hostname();
|
|
|
|
}
|
|
|
|
if ($search) {
|
|
|
|
$query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search);
|
|
|
|
}
|
|
|
|
if (strpos($search, '@')) {
|
|
|
|
$query .= '&address=' . urlencode($search);
|
|
|
|
}
|
2022-09-04 01:35:50 +00:00
|
|
|
if (str_starts_with($search, 'http')) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$query .= '&url=' . urlencode($search);
|
|
|
|
}
|
|
|
|
if ($keywords) {
|
|
|
|
$query .= '&keywords=' . urlencode($keywords);
|
|
|
|
}
|
2023-10-24 09:51:45 +00:00
|
|
|
// if ($advanced) {
|
|
|
|
// $query .= '&query=' . urlencode($advanced);
|
|
|
|
// }
|
2021-12-02 23:02:31 +00:00
|
|
|
if (!is_null($type)) {
|
|
|
|
$query .= '&type=' . intval($type);
|
|
|
|
}
|
|
|
|
$directory_sort_order = get_config('system', 'directory_sort_order');
|
|
|
|
if (!$directory_sort_order) {
|
|
|
|
$directory_sort_order = 'date';
|
|
|
|
}
|
|
|
|
|
|
|
|
$sort_order = ((x($_REQUEST, 'order')) ? $_REQUEST['order'] : $directory_sort_order);
|
|
|
|
|
|
|
|
if ($sort_order) {
|
|
|
|
$query .= '&order=' . urlencode($sort_order);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (App::$pager['page'] != 1) {
|
|
|
|
$query .= '&p=' . App::$pager['page'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($active)) {
|
|
|
|
$query .= '&active=' . intval($active);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// logger('mod_directory: query: ' . $query);
|
|
|
|
|
2023-10-24 09:51:45 +00:00
|
|
|
$x = Url::post($query, [ 'query' => $advanced]);
|
2021-12-02 23:02:31 +00:00
|
|
|
// logger('directory: return from upstream: ' . print_r($x,true), LOGGER_DATA);
|
|
|
|
|
|
|
|
if ($x['success']) {
|
2022-09-04 05:51:24 +00:00
|
|
|
/** Experimental
|
2022-05-19 20:47:30 +00:00
|
|
|
if ($format === 'json') {
|
|
|
|
|
|
|
|
$chan = Channel::get_system();
|
|
|
|
|
|
|
|
//$i = Activity::encode_actor_collection($items, 'search?' . $saved_id , 'OrderedCollection', true, count($items));
|
|
|
|
|
2022-12-15 21:24:47 +00:00
|
|
|
$x = array_merge(Activity::ap_context(), $i);
|
2022-05-19 20:47:30 +00:00
|
|
|
|
|
|
|
$headers = [];
|
|
|
|
$headers['Content-Type'] = 'application/x-nomad+json';
|
2024-01-05 19:31:03 +00:00
|
|
|
$x['proof'] = (new JcsEddsa2022)->sign($x, $chan);
|
2022-05-19 20:47:30 +00:00
|
|
|
$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();
|
|
|
|
}
|
2022-09-04 05:51:24 +00:00
|
|
|
**/
|
2022-05-19 20:47:30 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$t = 0;
|
|
|
|
$j = json_decode($x['body'], true);
|
|
|
|
if ($j) {
|
|
|
|
if ($j['results']) {
|
|
|
|
$results = $j['results'];
|
|
|
|
if ($suggest) {
|
|
|
|
// change order to "number of common friends descending"
|
|
|
|
$results = self::reorder_results($results, $addresses);
|
|
|
|
}
|
|
|
|
|
|
|
|
$entries = [];
|
|
|
|
|
|
|
|
$photo = 'thumb';
|
|
|
|
|
|
|
|
foreach ($results as $rr) {
|
|
|
|
$profile_link = chanlink_url($rr['url']);
|
|
|
|
|
|
|
|
$pdesc = (($rr['description']) ? $rr['description'] . '<br>' : '');
|
|
|
|
$connect_link = ((local_channel()) ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : '');
|
|
|
|
|
|
|
|
// Checking status is disabled ATM until someone checks the performance impact more carefully
|
2022-01-25 01:26:12 +00:00
|
|
|
//$online = Channel::remote_online_status($rr['address']);
|
2021-12-02 23:02:31 +00:00
|
|
|
$online = '';
|
|
|
|
|
|
|
|
if (in_array($rr['hash'], $contacts)) {
|
|
|
|
$connect_link = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$location = '';
|
|
|
|
if (strlen($rr['locale'])) {
|
|
|
|
$location .= $rr['locale'];
|
|
|
|
}
|
|
|
|
if (strlen($rr['region'])) {
|
|
|
|
if (strlen($rr['locale'])) {
|
|
|
|
$location .= ', ';
|
|
|
|
}
|
|
|
|
$location .= $rr['region'];
|
|
|
|
}
|
|
|
|
if (strlen($rr['country'])) {
|
|
|
|
if (strlen($location)) {
|
|
|
|
$location .= ', ';
|
|
|
|
}
|
|
|
|
$location .= $rr['country'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$age = '';
|
|
|
|
if (strlen($rr['birthday'])) {
|
|
|
|
if (($years = age($rr['birthday'], 'UTC', '')) > 0) {
|
|
|
|
$age = $years;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page_type = '';
|
|
|
|
|
|
|
|
$total_ratings = '';
|
|
|
|
|
|
|
|
$profile = $rr;
|
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$gender = ((x($profile, 'gender') == 1) ? t('Gender: ') . $profile['gender'] : false);
|
|
|
|
$marital = ((x($profile, 'marital') == 1) ? t('Status: ') . $profile['marital'] : false);
|
|
|
|
$homepage = ((x($profile, 'homepage') == 1) ? t('Homepage: ') : false);
|
2021-12-02 23:02:31 +00:00
|
|
|
$homepageurl = ((x($profile, 'homepage') == 1) ? html2plain($profile['homepage']) : '');
|
2021-12-03 03:01:39 +00:00
|
|
|
$hometown = ((x($profile, 'hometown') == 1) ? html2plain($profile['hometown']) : false);
|
|
|
|
$about = ((x($profile, 'about') == 1) ? zidify_links(bbcode($profile['about'])) : false);
|
2021-12-02 23:02:31 +00:00
|
|
|
|
2023-11-18 21:10:44 +00:00
|
|
|
$author_menu = thread_author_menu(['xchan_author' => $rr['hash'], ['author' => ['xchan_network' => $rr['network']]]]);
|
2021-12-02 23:02:31 +00:00
|
|
|
$keywords = ((x($profile, 'keywords')) ? $profile['keywords'] : '');
|
|
|
|
|
|
|
|
$out = '';
|
|
|
|
|
|
|
|
if ($keywords) {
|
|
|
|
$keywords = str_replace(',', ' ', $keywords);
|
|
|
|
$keywords = str_replace(' ', ' ', $keywords);
|
|
|
|
$karr = explode(' ', $keywords);
|
|
|
|
|
|
|
|
if ($karr) {
|
|
|
|
if (local_channel()) {
|
2021-12-03 03:01:39 +00:00
|
|
|
$pk = q(
|
|
|
|
"select keywords from profile where uid = %d and is_default = 1 limit 1",
|
2021-12-02 23:02:31 +00:00
|
|
|
intval(local_channel())
|
|
|
|
);
|
|
|
|
if ($pk) {
|
|
|
|
$keywords = str_replace(',', ' ', $pk[0]['keywords']);
|
|
|
|
$keywords = str_replace(' ', ' ', $keywords);
|
|
|
|
$marr = explode(' ', $keywords);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($karr as $k) {
|
|
|
|
if (strlen($out)) {
|
|
|
|
$out .= ', ';
|
|
|
|
}
|
|
|
|
if ($marr && in_arrayi($k, $marr)) {
|
|
|
|
$out .= '<a href="' . z_root() . '/directory/f=&keywords=' . urlencode($k) . '"><strong>' . $k . '</strong></a>';
|
|
|
|
} else {
|
|
|
|
$out .= '<a href="' . z_root() . '/directory/f=&keywords=' . urlencode($k) . '">' . $k . '</a>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$entry = [
|
|
|
|
'id' => ++$t,
|
|
|
|
'profile_link' => $profile_link,
|
|
|
|
'type' => $rr['type'],
|
2023-11-18 21:10:44 +00:00
|
|
|
'photo' => $rr['photo_l'],
|
|
|
|
'photo_l' => $rr['photo_l'],
|
2022-06-21 21:35:48 +00:00
|
|
|
'cover' => (($covers) ? XConfig::Get($rr['hash'],'system','cover_photo') : false),
|
|
|
|
'altcover' => t('Cover photo for this directory entry'),
|
2021-12-02 23:02:31 +00:00
|
|
|
'hash' => $rr['hash'],
|
2023-10-13 01:23:54 +00:00
|
|
|
'md5hash' => md5($rr['hash']),
|
2021-12-02 23:02:31 +00:00
|
|
|
'alttext' => $rr['name'] . ((local_channel() || remote_channel()) ? ' ' . $rr['address'] : ''),
|
|
|
|
'name' => $rr['name'],
|
|
|
|
'age' => $age,
|
|
|
|
'age_label' => t('Age:'),
|
|
|
|
'profile' => $profile,
|
|
|
|
'address' => $rr['address'],
|
|
|
|
'nickname' => substr($rr['address'], 0, strpos($rr['address'], '@')),
|
|
|
|
'location' => $location,
|
|
|
|
'location_label' => t('Location:'),
|
|
|
|
'gender' => $gender,
|
|
|
|
'pdesc' => $pdesc,
|
|
|
|
'pdesc_label' => t('Description:'),
|
2023-11-18 21:10:44 +00:00
|
|
|
'author_menu' => $author_menu,
|
2023-11-25 06:48:08 +00:00
|
|
|
'censor' => (($directory_admin) ? 'dircensor/' . bin2hex($rr['hash']) : ''),
|
2021-12-02 23:02:31 +00:00
|
|
|
'censor_label' => (($rr['censored']) ? t('Uncensor') : t('Censor')),
|
2023-11-25 10:03:21 +00:00
|
|
|
'block' => (($directory_admin) ? urlencode($rr['hash']) : ''),
|
|
|
|
'block_label' => t('Block'),
|
2021-12-02 23:02:31 +00:00
|
|
|
'marital' => $marital,
|
|
|
|
'homepage' => $homepage,
|
|
|
|
'homepageurl' => (($safe_mode) ? $homepageurl : linkify($homepageurl)),
|
|
|
|
'hometown' => $hometown,
|
|
|
|
'hometown_label' => t('Hometown:'),
|
|
|
|
'about' => $about,
|
|
|
|
'about_label' => t('About:'),
|
2022-04-10 21:00:37 +00:00
|
|
|
'conn_label' => intval($rr['type']) === 1 ? t('Join') : t('Connect'),
|
2021-12-02 23:02:31 +00:00
|
|
|
'forum_label' => t('Group'),
|
|
|
|
'collections_label' => t('Collection'),
|
|
|
|
'connect' => $connect_link,
|
|
|
|
'online' => $online,
|
|
|
|
'kw' => (($out) ? t('Keywords: ') : ''),
|
|
|
|
'keywords' => $out,
|
|
|
|
'ignlink' => $suggest ? z_root() . '/directory?ignore=' . $rr['hash'] : '',
|
|
|
|
'ignore_label' => t('Don\'t suggest'),
|
|
|
|
'common_friends' => (($common[$rr['hash']]) ? intval($common[$rr['hash']]) : ''),
|
|
|
|
'common_label' => t('Suggestion ranking:'),
|
|
|
|
'common_count' => intval($common[$rr['hash']]),
|
|
|
|
'safe' => $safe_mode
|
|
|
|
];
|
|
|
|
|
2022-09-04 06:28:17 +00:00
|
|
|
$blocked = LibBlock::fetch(local_channel(), BLOCKTYPE_SERVER);
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
$found_block = false;
|
|
|
|
if ($blocked) {
|
|
|
|
foreach ($blocked as $b) {
|
2022-09-04 01:35:50 +00:00
|
|
|
if (str_contains($rr['site_url'], $b['block_entity'])) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$found_block = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($found_block) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LibBlock::fetch_by_entity(local_channel(), $entry['hash'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-11-25 10:03:21 +00:00
|
|
|
$blocked = LibBlock::fetch($sys_channel, BLOCKTYPE_SERVER);
|
|
|
|
|
|
|
|
$found_block = false;
|
|
|
|
if ($blocked) {
|
|
|
|
foreach ($blocked as $b) {
|
|
|
|
if (str_contains($rr['site_url'], $b['block_entity'])) {
|
|
|
|
$found_block = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($found_block) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LibBlock::fetch_by_entity($sys_channel, $entry['hash'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-04 01:35:50 +00:00
|
|
|
$arr = ['contact' => $rr, 'entry' => $entry];
|
2021-12-02 23:02:31 +00:00
|
|
|
|
2022-02-12 08:50:48 +00:00
|
|
|
Hook::call('directory_item', $arr);
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
unset($profile);
|
|
|
|
unset($location);
|
|
|
|
|
|
|
|
if (!$arr['entry']) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sort_order == '' && $suggest) {
|
|
|
|
$entries[$addresses[$rr['address']]] = $arr['entry']; // Use the same indexes as originally to get the best suggestion first
|
|
|
|
} else {
|
|
|
|
$entries[] = $arr['entry'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ksort($entries); // Sort array by key so that foreach-constructs work as expected
|
|
|
|
|
|
|
|
if ($j['keywords']) {
|
|
|
|
App::$data['directory_keywords'] = $j['keywords'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// logger('mod_directory: entries: ' . print_r($entries,true), LOGGER_DATA);
|
|
|
|
|
|
|
|
|
|
|
|
if ($_REQUEST['aj']) {
|
|
|
|
if ($entries) {
|
2022-02-12 20:43:29 +00:00
|
|
|
$o = replace_macros(Theme::get_template('directajax.tpl'), ['$entries' => $entries]);
|
2021-12-02 23:02:31 +00:00
|
|
|
} else {
|
|
|
|
$o = '<div id="content-complete"></div>';
|
|
|
|
}
|
|
|
|
echo $o;
|
|
|
|
killme();
|
|
|
|
} else {
|
2023-11-18 21:10:44 +00:00
|
|
|
$maxheight = 180;
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
$dirtitle = (($globaldir) ? t('Directory') : t('Local Directory'));
|
2023-10-08 11:06:10 +00:00
|
|
|
$item_scroll = get_pconfig(local_channel(), 'system', 'item_scroll');
|
|
|
|
|
|
|
|
|
|
|
|
$o .= "<script> let page_query = '" . escape_tags(urlencode($_GET['req'])) . "'; let extra_args = '" . extra_query_args() . "' ; divmore_height = " . intval($maxheight)
|
|
|
|
. "; itemScroll = '" . (($item_scroll) ? 'auto' : 'hidden' ) . "' ;</script>\r\n";
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
$o .= replace_macros($tpl, [
|
|
|
|
'$search' => $search,
|
|
|
|
'$desc' => t('Find'),
|
|
|
|
'$finddsc' => t('Finding:'),
|
|
|
|
'$safetxt' => htmlspecialchars($search, ENT_QUOTES, 'UTF-8'),
|
|
|
|
'$entries' => $entries,
|
|
|
|
'$dirlbl' => $suggest ? t('Channel Suggestions') : $dirtitle,
|
|
|
|
'$submit' => t('Find'),
|
|
|
|
'$next' => alt_pager($j['records'], t('next page'), t('previous page')),
|
|
|
|
'$sort' => t('Sort options'),
|
|
|
|
'$normal' => t('Alphabetic'),
|
|
|
|
'$reverse' => t('Reverse Alphabetic'),
|
|
|
|
'$date' => t('Newest to Oldest'),
|
|
|
|
'$reversedate' => t('Oldest to Newest'),
|
|
|
|
'$suggest' => $suggest ? '&suggest=1' : ''
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($_REQUEST['aj']) {
|
|
|
|
$o = '<div id="content-complete"></div>';
|
|
|
|
echo $o;
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
if ($search && App::$pager['page'] == 1 && $j['records'] == 0) {
|
|
|
|
if (strpos($search, '@')) {
|
|
|
|
goaway(z_root() . '/chanview/?f=&address=' . $search);
|
2022-09-04 01:35:50 +00:00
|
|
|
} elseif (str_starts_with($search, 'http')) {
|
2021-12-02 23:02:31 +00:00
|
|
|
goaway(z_root() . '/chanview/?f=&url=' . $search);
|
|
|
|
} else {
|
2021-12-03 03:01:39 +00:00
|
|
|
$r = q(
|
|
|
|
"select xchan_hash from xchan where xchan_name = '%s' limit 1",
|
2021-12-02 23:02:31 +00:00
|
|
|
dbesc($search)
|
|
|
|
);
|
|
|
|
if ($r) {
|
|
|
|
goaway(z_root() . '/chanview/?f=&hash=' . urlencode($r[0]['xchan_hash']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info(t("No entries (some entries may be hidden).") . EOL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function reorder_results($results, $suggests)
|
|
|
|
{
|
|
|
|
if (!$suggests) {
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = [];
|
|
|
|
foreach ($suggests as $k => $v) {
|
|
|
|
foreach ($results as $rv) {
|
|
|
|
if ($k == $rv['hash']) {
|
|
|
|
$out[intval($v)] = $rv;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2016-04-19 03:38:38 +00:00
|
|
|
}
|