streams/mod/directory.php

347 lines
9.2 KiB
PHP
Raw Normal View History

<?php
require_once('include/socgraph.php');
require_once('include/dir_fns.php');
require_once('include/widgets.php');
2014-11-11 23:50:27 +00:00
require_once('include/bbcode.php');
function directory_init(&$a) {
$a->set_pager_itemspage(60);
if(x($_GET,'ignore')) {
q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ",
intval(local_user()),
dbesc($_GET['ignore'])
);
}
2010-07-10 07:45:18 +00:00
}
function directory_content(&$a) {
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
notice( t('Public access denied.') . EOL);
return;
}
2013-09-20 04:45:09 +00:00
$safe_mode = 1;
$observer = get_observer_hash();
if($observer) {
$safe_mode = get_xconfig($observer,'directory','safe_mode');
2013-09-20 04:45:09 +00:00
}
if($safe_mode === false)
$safe_mode = 1;
else
$safe_mode = intval($safe_mode);
2013-09-20 04:51:52 +00:00
if(x($_REQUEST,'safe'))
$safe_mode = (intval($_REQUEST['safe']));
$pubforums = null;
if(array_key_exists('pubforums',$_REQUEST))
$pubforums = intval($_REQUEST['pubforums']);
2013-09-20 04:45:09 +00:00
2010-10-31 23:38:22 +00:00
$o = '';
nav_set_selected('directory');
2010-07-10 10:26:21 +00:00
2012-10-24 00:14:50 +00:00
if(x($_POST,'search'))
$search = notags(trim($_POST['search']));
else
2010-12-20 03:55:03 +00:00
$search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
if(strpos($search,'=') && local_user() && get_pconfig(local_user(),'feature','expert'))
$advanced = $search;
2014-03-09 01:39:20 +00:00
$keywords = (($_GET['keywords']) ? $_GET['keywords'] : '');
// Suggest channels if no search terms or keywords are given
$suggest = ($search == '' && $keywords == '' && local_user());
if($suggest) {
$r = suggestion_query(local_user(),get_observer_hash());
// Remember in which order the suggestions were
$addresses = array();
foreach($r as $rr) {
$addresses[$rr['xchan_addr']] = $index++;
}
// Build query to get info about suggested people
$advanced = '';
foreach(array_keys($addresses) as $address) {
$advanced .= "address=\"$address\" ";
}
}
2011-05-11 11:37:13 +00:00
$tpl = get_markup_template('directory_header.tpl');
$dirmode = intval(get_config('system','directory_mode'));
2013-01-19 03:00:41 +00:00
if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
$url = z_root() . '/dirsearch';
}
if(! $url) {
$directory = find_upstream_directory($dirmode);
$url = $directory['url'] . '/dirsearch';
}
2013-01-27 23:21:05 +00:00
logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
2010-07-10 05:47:32 +00:00
2013-08-03 23:35:55 +00:00
$contacts = array();
if(local_user()) {
$x = q("select abook_xchan from abook where abook_channel = %d",
intval(local_user())
);
if($x) {
foreach($x as $xx)
$contacts[] = $xx['abook_xchan'];
}
}
2013-01-19 03:00:41 +00:00
if($url) {
// We might want to make the tagadelic count (&kw=) configurable or turn it off completely.
2014-03-09 01:39:20 +00:00
2013-09-20 02:24:38 +00:00
$numtags = get_config('system','directorytags');
2013-09-20 01:38:59 +00:00
$kw = ((intval($numtags)) ? $numtags : 24);
2013-09-20 04:45:09 +00:00
$query = $url . '?f=&kw=' . $kw . (($safe_mode != 1) ? '&safe=' . $safe_mode : '');
2013-11-09 18:45:52 +00:00
if($search)
$query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search);
if(strpos($search,'@'))
$query .= '&address=' . urlencode($search);
if($keywords)
$query .= '&keywords=' . urlencode($keywords);
2014-03-09 01:39:20 +00:00
if($advanced)
$query .= '&query=' . urlencode($advanced);
if(! is_null($pubforums))
$query .= '&pubforums=' . intval($pubforums);
2014-03-09 01:39:20 +00:00
if(! is_null($pubforums))
$query .= '&pubforums=' . intval($pubforums);
$sort_order = ((x($_REQUEST,'order')) ? $_REQUEST['order'] : '');
if($pubforums)
$sort_order = 'normal';
if($sort_order)
$query .= '&order=' . urlencode($sort_order);
2010-07-10 07:45:18 +00:00
2013-01-19 03:00:41 +00:00
if($a->pager['page'] != 1)
$query .= '&p=' . $a->pager['page'];
2010-07-10 07:45:18 +00:00
2013-01-19 03:28:16 +00:00
logger('mod_directory: query: ' . $query);
2013-01-19 03:00:41 +00:00
$x = z_fetch_url($query);
2013-06-03 23:29:33 +00:00
logger('directory: return from upstream: ' . print_r($x,true), LOGGER_DATA);
2013-01-19 03:00:41 +00:00
if($x['success']) {
$t = 0;
$j = json_decode($x['body'],true);
if($j) {
if($j['results']) {
$entries = array();
2010-07-31 09:18:37 +00:00
$photo = 'thumb';
foreach($j['results'] as $rr) {
$profile_link = chanlink_url($rr['url']);
2011-01-19 03:25:28 +00:00
$pdesc = (($rr['description']) ? $rr['description'] . '<br />' : '');
2013-08-03 23:35:55 +00:00
$connect_link = ((local_user()) ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : '');
2014-11-08 23:18:26 +00:00
// Checking status is disabled ATM until someone checks the performance impact more carefully
//$online = remote_online_status($rr['address']);
$online = '';
2013-08-03 23:35:55 +00:00
if(in_array($rr['hash'],$contacts))
$connect_link = '';
$details = '';
2013-01-19 03:00:41 +00:00
if(strlen($rr['locale']))
$details .= $rr['locale'];
if(strlen($rr['region'])) {
if(strlen($rr['locale']))
$details .= ', ';
$details .= $rr['region'];
}
if(strlen($rr['country'])) {
if(strlen($details))
$details .= ', ';
$details .= $rr['country'];
}
if(strlen($rr['birthday'])) {
if(($years = age($rr['birthday'],'UTC','')) != 0)
$details .= '<br />' . t('Age: ') . $years ;
}
$page_type = '';
$profile = $rr;
if ((x($profile,'locale') == 1)
|| (x($profile,'region') == 1)
|| (x($profile,'postcode') == 1)
|| (x($profile,'country') == 1))
$location = t('Location:');
2014-11-08 23:18:26 +00:00
$gender = ((x($profile,'gender') == 1) ? t('Gender: ') . $profile['gender']: False);
2013-01-19 03:00:41 +00:00
2014-11-08 23:18:26 +00:00
$marital = ((x($profile,'marital') == 1) ? t('Status: ') . $profile['marital']: False);
2013-01-19 03:00:41 +00:00
2014-11-08 23:18:26 +00:00
$homepage = ((x($profile,'homepage') == 1) ? t('Homepage: ') : False);
$homepageurl = ((x($profile,'homepage') == 1) ? $profile['homepage'] : '');
$hometown = ((x($profile,'hometown') == 1) ? t('Hometown: ') . $profile['hometown'] : False);
2014-11-11 23:50:27 +00:00
$about = ((x($profile,'about') == 1) ? t('About: ') . bbcode($profile['about']) : False);
2014-11-08 23:18:26 +00:00
$keywords = ((x($profile,'keywords')) ? $profile['keywords'] : '');
$out = '';
2014-11-08 23:18:26 +00:00
if($keywords) {
$keywords = str_replace(',',' ', $keywords);
$keywords = str_replace(' ',' ', $keywords);
$karr = explode(' ', $keywords);
2014-11-10 00:11:56 +00:00
2014-11-08 23:18:26 +00:00
if($karr) {
if(local_user()) {
$r = q("select keywords from profile where uid = %d and is_default = 1 limit 1",
intval(local_user())
);
if($r) {
$keywords = str_replace(',',' ', $r[0]['keywords']);
$keywords = str_replace(' ',' ', $keywords);
$marr = explode(' ', $keywords);
}
}
foreach($karr as $k) {
if(strlen($out))
$out .= ', ';
if($marr && in_arrayi($k,$marr))
$out .= '<strong>' . $k . '</strong>';
else
$out .= $k;
}
}
}
$entry = array(
'id' => ++$t,
'profile_link' => $profile_link,
'public_forum' => $rr['public_forum'],
'photo' => $rr['photo'],
'hash' => $rr['hash'],
'alttext' => $rr['name'] . ' ' . $rr['address'],
'name' => $rr['name'],
'details' => $pdesc . $details,
'profile' => $profile,
2014-01-22 02:45:40 +00:00
'address' => $rr['address'],
'nickname' => substr($rr['address'],0,strpos($rr['address'],'@')),
'location' => $location,
'gender' => $gender,
'pdesc' => $pdesc,
'marital' => $marital,
'homepage' => $homepage,
'homepageurl' => linkify($homepageurl),
2014-11-08 23:18:26 +00:00
'hometown' => $hometown,
'about' => $about,
2013-08-03 23:35:55 +00:00
'conn_label' => t('Connect'),
'forum_label' => t('Public Forum:'),
2013-08-03 23:35:55 +00:00
'connect' => $connect_link,
2014-11-08 23:18:26 +00:00
'online' => $online,
'kw' => (($out) ? t('Keywords: ') : ''),
'keywords' => $out,
'ignlink' => $suggest ? $a->get_baseurl() . '/directory?ignore=' . $rr['hash'] : '',
'ignore_label' => "Don't suggest",
);
$arr = array('contact' => $rr, 'entry' => $entry);
2013-01-19 03:00:41 +00:00
call_hooks('directory_item', $arr);
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'];
}
unset($profile);
unset($location);
2010-07-09 08:17:20 +00:00
}
2013-01-19 03:00:41 +00:00
ksort($entries); // Sort array by key so that foreach-constructs work as expected
if($j['keywords']) {
$a->data['directory_keywords'] = $j['keywords'];
}
logger('mod_directory: entries: ' . print_r($entries,true), LOGGER_DATA);
2014-08-06 04:48:13 +00:00
if($_REQUEST['aj']) {
if($entries) {
$o = replace_macros(get_markup_template('directajax.tpl'),array(
'$entries' => $entries
));
}
else {
$o = '<div id="content-complete"></div>';
}
2014-08-06 04:48:13 +00:00
echo $o;
killme();
}
else {
2014-09-06 07:48:00 +00:00
$o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
$o .= replace_macros($tpl, array(
'$search' => $search,
'$desc' => t('Find'),
'$finddsc' => t('Finding:'),
'$safetxt' => htmlspecialchars($search,ENT_QUOTES,'UTF-8'),
'$entries' => $entries,
'$dirlbl' => $suggest ? t('Channel Suggestions') : t('Directory'),
'$submit' => t('Find'),
'$next' => alt_pager($a,$j['records'], t('next page'), t('previous page'))
));
}
2010-12-25 23:01:02 +00:00
}
else {
if($_REQUEST['aj']) {
$o = '<div id="content-complete"></div>';
echo $o;
killme();
}
if($a->pager['page'] == 1 && $j['records'] == 0 && strpos($search,'@')) {
goaway(z_root() . '/chanview/?f=&address=' . $search);
}
info( t("No entries (some entries may be hidden).") . EOL);
}
2013-01-19 03:00:41 +00:00
}
}
}
2010-07-09 10:10:28 +00:00
return $o;
}
2013-01-19 03:00:41 +00:00