Пример #1
0
function directory_content(&$a)
{
    if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    $observer = get_observer_hash();
    $globaldir = get_globaldir_setting($observer);
    $safe_mode = get_safemode_setting($observer);
    $pubforums = null;
    if (array_key_exists('pubforums', $_REQUEST)) {
        $pubforums = intval($_REQUEST['pubforums']);
    }
    if (!$pubforums) {
        $pubforums = null;
    }
    $o = '';
    nav_set_selected('directory');
    if (x($_POST, 'search')) {
        $search = notags(trim($_POST['search']));
    } else {
        $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
    }
    if (strpos($search, '=') && local_channel() && get_pconfig(local_channel(), 'feature', 'expert')) {
        $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) {
        $r = suggestion_query(local_channel(), get_observer_hash());
        // Remember in which order the suggestions were
        $addresses = array();
        $index = 0;
        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}\" ";
        }
        // Remove last space in the advanced query
        $advanced = rtrim($advanced);
    }
    $tpl = get_markup_template('directory_header.tpl');
    $dirmode = intval(get_config('system', 'directory_mode'));
    if ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE) {
        $url = z_root() . '/dirsearch';
    }
    if (!$url) {
        $directory = find_upstream_directory($dirmode);
        $url = $directory['url'] . '/dirsearch';
    }
    $token = get_config('system', 'realm_token');
    logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
    $contacts = array();
    if (local_channel()) {
        $x = q("select abook_xchan from abook where abook_channel = %d", intval(local_channel()));
        if ($x) {
            foreach ($x as $xx) {
                $contacts[] = $xx['abook_xchan'];
            }
        }
    }
    if ($url) {
        // We might want to make the tagadelic count (&kw=) configurable or turn it off completely.
        $numtags = get_config('system', 'directorytags');
        $kw = intval($numtags) ? $numtags : 50;
        $query = $url . '?f=&kw=' . $kw . ($safe_mode != 1 ? '&safe=' . $safe_mode : '');
        if ($token) {
            $query .= '&t=' . $token;
        }
        if (!$globaldir) {
            $query .= '&hub=' . get_app()->get_hostname();
        }
        if ($search) {
            $query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search);
        }
        if (strpos($search, '@')) {
            $query .= '&address=' . urlencode($search);
        }
        if ($keywords) {
            $query .= '&keywords=' . urlencode($keywords);
        }
        if ($advanced) {
            $query .= '&query=' . urlencode($advanced);
        }
        if (!is_null($pubforums)) {
            $query .= '&pubforums=' . intval($pubforums);
        }
        $sort_order = x($_REQUEST, 'order') ? $_REQUEST['order'] : 'date';
        if ($sort_order) {
            $query .= '&order=' . urlencode($sort_order);
        }
        if ($a->pager['page'] != 1) {
            $query .= '&p=' . $a->pager['page'];
        }
        logger('mod_directory: query: ' . $query);
        $x = z_fetch_url($query);
        logger('directory: return from upstream: ' . print_r($x, true), LOGGER_DATA);
        if ($x['success']) {
            $t = 0;
            $j = json_decode($x['body'], true);
            if ($j) {
                if ($j['results']) {
                    $entries = array();
                    $photo = 'thumb';
                    foreach ($j['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
                        //$online = remote_online_status($rr['address']);
                        $online = '';
                        if (in_array($rr['hash'], $contacts)) {
                            $connect_link = '';
                        }
                        $details = '';
                        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 = '';
                        if ($rr['total_ratings']) {
                            $total_ratings = sprintf(tt("%d rating", "%d ratings", $rr['total_ratings']), $rr['total_ratings']);
                        } else {
                            $total_ratings = '';
                        }
                        $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: ') . $profile['gender'] : False;
                        $marital = x($profile, 'marital') == 1 ? t('Status: ') . $profile['marital'] : False;
                        $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;
                        $about = x($profile, 'about') == 1 ? t('About: ') . bbcode($profile['about']) : False;
                        $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()) {
                                    $r = q("select keywords from profile where uid = %d and is_default = 1 limit 1", intval(local_channel()));
                                    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'] . (local_channel() || remote_channel() ? ' ' . $rr['address'] : ''), 'name' => $rr['name'], 'details' => $pdesc . $details, 'profile' => $profile, 'address' => $rr['address'], 'nickname' => substr($rr['address'], 0, strpos($rr['address'], '@')), 'location' => $location, 'gender' => $gender, 'total_ratings' => $total_ratings, 'viewrate' => true, 'canrate' => local_channel() ? true : false, 'pdesc' => $pdesc, 'marital' => $marital, 'homepage' => $homepage, 'homepageurl' => linkify($homepageurl), 'hometown' => $hometown, 'about' => $about, 'conn_label' => t('Connect'), 'forum_label' => t('Public Forum:'), 'connect' => $connect_link, 'online' => $online, 'kw' => $out ? t('Keywords: ') : '', 'keywords' => $out, 'ignlink' => $suggest ? $a->get_baseurl() . '/directory?ignore=' . $rr['hash'] : '', 'ignore_label' => "Don't suggest", 'safe' => $safe_mode);
                        $arr = array('contact' => $rr, 'entry' => $entry);
                        call_hooks('directory_item', $arr);
                        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']) {
                        $a->data['directory_keywords'] = $j['keywords'];
                    }
                    logger('mod_directory: entries: ' . print_r($entries, true), LOGGER_DATA);
                    if ($_REQUEST['aj']) {
                        if ($entries) {
                            $o = replace_macros(get_markup_template('directajax.tpl'), array('$entries' => $entries));
                        } else {
                            $o = '<div id="content-complete"></div>';
                        }
                        echo $o;
                        killme();
                    } else {
                        $maxheight = 175;
                        $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; divmore_height = " . intval($maxheight) . ";  </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'))));
                    }
                } 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);
                }
            }
        }
    }
    return $o;
}
Пример #2
0
/**
 * @brief Called by the directory_sort widget.
 */
function dir_sort_links()
{
    $safe_mode = 1;
    $observer = get_observer_hash();
    $safe_mode = get_safemode_setting($observer);
    $globaldir = get_globaldir_setting($observer);
    // Build urls without order and pubforums so it's easy to tack on the changed value
    // Probably there's an easier way to do this
    $current_order = $_REQUEST['order'] ? $_REQUEST['order'] : 'date';
    $url = 'directory?f=';
    $tmp = array_merge($_GET, $_POST);
    unset($tmp['order']);
    unset($tmp['q']);
    unset($tmp['f']);
    $sorturl = $url . http_build_query($tmp);
    $tmp = array_merge($_GET, $_POST);
    unset($tmp['pubforums']);
    unset($tmp['global']);
    unset($tmp['safe']);
    unset($tmp['q']);
    unset($tmp['f']);
    $forumsurl = $url . http_build_query($tmp);
    $o = replace_macros(get_markup_template('dir_sort_links.tpl'), array('$header' => t('Directory Options'), '$normal' => t('Alphabetic'), '$reverse' => t('Reverse Alphabetic'), '$date' => t('Newest to Oldest'), '$reversedate' => t('Oldest to Newest'), '$sort' => t('Sort'), '$selected_sort' => $current_order, '$sorturl' => $sorturl, '$forumsurl' => $forumsurl, '$safemode' => array('safemode', t('Safe Mode'), $safe_mode, '', '', ' onchange=\'window.location.href="' . $forumsurl . '&safe="+(this.checked ? 1 : 0)\''), '$pubforums' => array('pubforums', t('Public Forums Only'), x($_REQUEST, 'pubforums') ? $_REQUEST['pubforums'] : '', '', '', ' onchange=\'window.location.href="' . $forumsurl . '&pubforums="+(this.checked ? 1 : 0)\''), '$globaldir' => array('globaldir', t('This Website Only'), 1 - intval($globaldir), '', '', ' onchange=\'window.location.href="' . $forumsurl . '&global="+(this.checked ? 0 : 1)\'')));
    return $o;
}