streams/mod/directory.php

184 lines
4.2 KiB
PHP
Raw Normal View History

<?php
require_once('include/dir_fns.php');
function directory_init(&$a) {
$a->set_pager_itemspage(60);
2010-07-10 07:45:18 +00:00
}
2012-10-24 00:14:50 +00:00
function directory_aside(&$a) {
2012-10-24 00:14:50 +00:00
if(local_user()) {
require_once('include/contact_widgets.php');
$a->set_widget('find_people',findpeople_widget());
}
}
function directory_content(&$a) {
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
notice( t('Public access denied.') . EOL);
return;
}
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']))) : '');
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);
2010-07-09 10:10:28 +00:00
if($directory) {
$url = $directory['url'];
}
else {
2013-01-19 03:00:41 +00:00
$url = DIRECTORY_FALLBACK_MASTER . '/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-01-19 03:00:41 +00:00
if($url) {
2013-01-19 03:28:16 +00:00
$query = $url . '?f=' ;
if($search)
2013-01-19 03:18:36 +00:00
$query .= '&name=' . urlencode($search);
if(strpos($search,'@'))
$query .= '&address=' . urlencode($search);
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);
logger('directory: return from upstream: ' . print_r($x,true));
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-01-19 03:00:41 +00:00
$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 ;
}
if(strlen($rr['gender']))
$details .= '<br />' . t('Gender: ') . $rr['gender'];
$page_type = '';
$profile = $rr;
if ((x($profile,'locale') == 1)
|| (x($profile,'region') == 1)
|| (x($profile,'postcode') == 1)
|| (x($profile,'country') == 1))
$location = t('Location:');
$gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
2013-01-19 03:00:41 +00:00
$marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
2013-01-19 03:00:41 +00:00
$homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
$about = ((x($profile,'about') == 1) ? t('About:') : False);
2013-01-19 03:00:41 +00:00
$entry = array(
'id' => ++$t,
'profile_link' => $profile_link,
'photo' => $rr['photo'],
'alttext' => $rr['name'] . ' ' . $rr['address'],
'name' => $rr['name'],
'details' => $pdesc . $details,
'profile' => $profile,
'location' => $location,
'gender' => $gender,
'pdesc' => $pdesc,
'marital' => $marital,
'homepage' => $homepage,
'about' => $about,
);
$arr = array('contact' => $rr, 'entry' => $entry);
2013-01-19 03:00:41 +00:00
call_hooks('directory_item', $arr);
$entries[] = $entry;
unset($profile);
unset($location);
2010-07-09 08:17:20 +00:00
}
2013-01-19 03:00:41 +00:00
logger('mod_directory: entries: ' . print_r($entries,true), LOGGER_DATA);
$o .= replace_macros($tpl, array(
'$search' => $search,
'$desc' => t('Find'),
'$finddsc' => t('Finding:'),
'$safetxt' => htmlspecialchars($search,ENT_QUOTES,'UTF-8'),
'$entries' => $entries,
'$dirlbl' => t('Directory'),
'$submit' => t('Find')
));
2010-12-25 23:01:02 +00:00
$o .= alt_pager($a,$j['records'], t('more'), t('back'));
2010-12-25 23:01:02 +00:00
}
else {
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