Example #1
0
function pubsites_content(&$a)
{
    require_once 'include/dir_fns.php';
    $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';
    }
    $url .= '/sites';
    $o .= '<h1>' . t('Public Sites') . '</h1>';
    $o .= '<div class="descriptive-text">' . t('The listed sites allow public registration into the Red Matrix. All sites in the matrix are interlinked so membership on any of them conveys membership in the matrix as a whole. Some sites may require subscription or provide tiered service plans. The provider links <strong>may</strong> provide additional details.') . '</div>' . EOL;
    $ret = z_fetch_url($url);
    if ($ret['success']) {
        $j = json_decode($ret['body'], true);
        if ($j) {
            $rate_meta = local_channel() ? '<td>' . t('Rate this hub') . '</td>' : '';
            $o .= '<table border="1"><tr><td>' . t('Site URL') . '</td><td>' . t('Access Type') . '</td><td>' . t('Registration Policy') . '</td><td>' . t('Location') . '</td><td>' . t('View hub ratings') . '</td>' . $rate_meta . '</tr>';
            if ($j['sites']) {
                foreach ($j['sites'] as $jj) {
                    $host = strtolower(substr($jj['url'], strpos($jj['url'], '://') + 3));
                    $rate_links = local_channel() ? '<td><a href="rate?f=&target=' . $host . '" class="btn-btn-default"><i class="icon-check"></i> ' . t('Rate') . '</a></td>' : '';
                    $o .= '<tr><td>' . '<a href="' . ($jj['sellpage'] ? $jj['sellpage'] : $jj['url'] . '/register') . '" >' . $jj['url'] . '</a>' . '</td><td>' . $jj['access'] . '</td><td>' . $jj['register'] . '</td><td>' . $jj['location'] . '</td><td><a href="ratings/' . $host . '" class="btn-btn-default"><i class="icon-eye-open"></i> ' . t('View ratings') . '</a></td>' . $rate_links . '</tr>';
                }
            }
            $o .= '</table>';
        }
    }
    return $o;
}
Example #2
0
 function get()
 {
     require_once 'include/dir_fns.php';
     $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';
     }
     $url .= '/sites';
     $rating_enabled = get_config('system', 'rating_enabled');
     $o .= '<div class="generic-content-wrapper">';
     $o .= '<div class="section-title-wrapper"><h2>' . t('Public Hubs') . '</h2></div>';
     $o .= '<div class="section-content-tools-wrapper"><div class="descriptive-text">' . t('The listed hubs allow public registration for the $Projectname network. All hubs in the network are interlinked so membership on any of them conveys membership in the network as a whole. Some hubs may require subscription or provide tiered service plans. The hub itself <strong>may</strong> provide additional details.') . '</div>' . EOL;
     $ret = z_fetch_url($url);
     if ($ret['success']) {
         $j = json_decode($ret['body'], true);
         if ($j) {
             $o .= '<table class="table table-striped table-hover"><tr><td>' . t('Hub URL') . '</td><td>' . t('Access Type') . '</td><td>' . t('Registration Policy') . '</td><td>' . t('Stats') . '</td><td>' . t('Software') . '</td>';
             if ($rating_enabled) {
                 $o .= '<td colspan="2">' . t('Ratings') . '</td>';
             }
             $o .= '</tr>';
             if ($j['sites']) {
                 foreach ($j['sites'] as $jj) {
                     if (!$jj['project']) {
                         continue;
                     }
                     if (strpos($jj['version'], ' ')) {
                         $x = explode(' ', $jj['version']);
                         if ($x[1]) {
                             $jj['version'] = $x[1];
                         }
                     }
                     $m = parse_url($jj['url']);
                     $host = strtolower(substr($jj['url'], strpos($jj['url'], '://') + 3));
                     $rate_links = local_channel() ? '<td><a href="rate?f=&target=' . $host . '" class="btn-btn-default"><i class="fa fa-check-square-o"></i> ' . t('Rate') . '</a></td>' : '';
                     $location = '';
                     if (!empty($jj['location'])) {
                         $location = '<p title="' . t('Location') . '" style="margin: 5px 5px 0 0; text-align: right"><i class="fa fa-globe"></i> ' . $jj['location'] . '</p>';
                     } else {
                         $location = '<br />&nbsp;';
                     }
                     $urltext = str_replace(array('https://'), '', $jj['url']);
                     $o .= '<tr><td><a href="' . ($jj['sellpage'] ? $jj['sellpage'] : $jj['url'] . '/register') . '" ><i class="fa fa-link"></i> ' . $urltext . '</a>' . $location . '</td><td>' . $jj['access'] . '</td><td>' . $jj['register'] . '</td><td>' . '<a target="stats" href="https://hubchart-tarine.rhcloud.com/hub.jsp?hubFqdn=' . $m['host'] . '"><i class="fa fa-area-chart"></i></a></td><td>' . ucwords($jj['project']) . ($jj['version'] ? ' ' . $jj['version'] : '') . '</td>';
                     if ($rating_enabled) {
                         $o .= '<td><a href="ratings/' . $host . '" class="btn-btn-default"><i class="fa fa-eye"></i> ' . t('View') . '</a></td>' . $rate_links;
                     }
                     $o .= '</tr>';
                 }
             }
             $o .= '</table>';
             $o .= '</div></div>';
         }
     }
     return $o;
 }
Example #3
0
 function init()
 {
     if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
         return;
     }
     if (local_channel()) {
         load_contact_links(local_channel());
     }
     $dirmode = intval(get_config('system', 'directory_mode'));
     $x = find_upstream_directory($dirmode);
     if ($x) {
         $url = $x['url'];
     }
     $poco_rating = get_config('system', 'poco_rating_enable');
     // if unset default to enabled
     if ($poco_rating === false) {
         $poco_rating = true;
     }
     if (!$poco_rating) {
         return;
     }
     if (argc() > 1) {
         $hash = argv(1);
     }
     if (!$hash) {
         notice('Must supply a channel identififier.');
         return;
     }
     $results = false;
     $x = z_fetch_url($url . '/ratingsearch/' . urlencode($hash));
     if ($x['success']) {
         $results = json_decode($x['body'], true);
     }
     if (!$results || !$results['success']) {
         notice('No results.');
         return;
     }
     if (array_key_exists('xchan_hash', $results['target'])) {
         \App::$poi = $results['target'];
     }
     $friends = array();
     $others = array();
     if ($results['ratings']) {
         foreach ($results['ratings'] as $n) {
             if (is_array(\App::$contacts) && array_key_exists($n['xchan_hash'], \App::$contacts)) {
                 $friends[] = $n;
             } else {
                 $others[] = $n;
             }
         }
     }
     \App::$data = array('target' => $results['target'], 'results' => array_merge($friends, $others));
     if (!\App::$data['results']) {
         notice(t('No ratings') . EOL);
     }
     return;
 }
Example #4
0
/**
 * @brief
 *
 * @param array $argv
 * @param array $argc
 */
function directory_run($argv, $argc)
{
    cli_startup();
    if ($argc < 2) {
        return;
    }
    $force = false;
    $pushall = true;
    if ($argc > 2) {
        if ($argv[2] === 'force') {
            $force = true;
        }
        if ($argv[2] === 'nopush') {
            $pushall = false;
        }
    }
    logger('directory update', LOGGER_DEBUG);
    $dirmode = get_config('system', 'directory_mode');
    if ($dirmode === false) {
        $dirmode = DIRECTORY_MODE_NORMAL;
    }
    $x = q("select * from channel where channel_id = %d limit 1", intval($argv[1]));
    if (!$x) {
        return;
    }
    $channel = $x[0];
    if ($dirmode != DIRECTORY_MODE_NORMAL) {
        // this is an in-memory update and we don't need to send a network packet.
        local_dir_update($argv[1], $force);
        q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
        // Now update all the connections
        if ($pushall) {
            proc_run('php', 'include/notifier.php', 'refresh_all', $channel['channel_id']);
        }
        return;
    }
    // otherwise send the changes upstream
    $directory = find_upstream_directory($dirmode);
    $url = $directory['url'] . '/post';
    // ensure the upstream directory is updated
    $packet = zot_build_packet($channel, $force ? 'force_refresh' : 'refresh');
    $z = zot_zot($url, $packet);
    // re-queue if unsuccessful
    if (!$z['success']) {
        /** @FIXME we aren't updating channel_dirdate if we have to queue
         * the directory packet. That means we'll try again on the next poll run.
         */
        $hash = random_string();
        q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) \n\t\t\tvalues ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", dbesc($hash), intval($channel['channel_account_id']), intval($channel['channel_id']), dbesc('zot'), dbesc($url), intval(1), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($packet), dbesc(''));
    } else {
        q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
    }
    // Now update all the connections
    if ($pushall) {
        proc_run('php', 'include/notifier.php', 'refresh_all', $channel['channel_id']);
    }
}
Example #5
0
 public static function run($argc, $argv)
 {
     if ($argc < 2) {
         return;
     }
     $force = false;
     $pushall = true;
     if ($argc > 2) {
         if ($argv[2] === 'force') {
             $force = true;
         }
         if ($argv[2] === 'nopush') {
             $pushall = false;
         }
     }
     logger('directory update', LOGGER_DEBUG);
     $dirmode = get_config('system', 'directory_mode');
     if ($dirmode === false) {
         $dirmode = DIRECTORY_MODE_NORMAL;
     }
     $x = q("select * from channel where channel_id = %d limit 1", intval($argv[1]));
     if (!$x) {
         return;
     }
     $channel = $x[0];
     if ($dirmode != DIRECTORY_MODE_NORMAL) {
         // this is an in-memory update and we don't need to send a network packet.
         local_dir_update($argv[1], $force);
         q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
         // Now update all the connections
         if ($pushall) {
             Master::Summon(array('Notifier', 'refresh_all', $channel['channel_id']));
         }
         return;
     }
     // otherwise send the changes upstream
     $directory = find_upstream_directory($dirmode);
     $url = $directory['url'] . '/post';
     // ensure the upstream directory is updated
     $packet = zot_build_packet($channel, $force ? 'force_refresh' : 'refresh');
     $z = zot_zot($url, $packet);
     // re-queue if unsuccessful
     if (!$z['success']) {
         /** @FIXME we aren't updating channel_dirdate if we have to queue
          * the directory packet. That means we'll try again on the next poll run.
          */
         $hash = random_string();
         queue_insert(array('hash' => $hash, 'account_id' => $channel['channel_account_id'], 'channel_id' => $channel['channel_id'], 'posturl' => $url, 'notify' => $packet));
     } else {
         q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
     }
     // Now update all the connections
     if ($pushall) {
         Master::Summon(array('Notifier', 'refresh_all', $channel['channel_id']));
     }
 }
Example #6
0
 function get()
 {
     if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     $observer = get_observer_hash();
     $globaldir = 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 = get_directory_setting($observer, 'safemode');
     $pubforums = get_directory_setting($observer, 'pubforums');
     $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();
         $common = array();
         $index = 0;
         foreach ($r as $rr) {
             $common[$rr['xchan_addr']] = $rr['total'];
             $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);
         if (!$directory || !array_key_exists('url', $directory) || !$directory['url']) {
             logger('CRITICAL: No directory server URL');
         }
         $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) {
         $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);
         }
         if ($keywords) {
             $query .= '&keywords=' . urlencode($keywords);
         }
         if ($advanced) {
             $query .= '&query=' . urlencode($advanced);
         }
         if (!is_null($pubforums)) {
             $query .= '&pubforums=' . intval($pubforums);
         }
         $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'];
         }
         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 = '';
                         }
                         $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 = '';
                         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) {
                             $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 ? $profile['hometown'] : False;
                         $about = x($profile, 'about') == 1 ? 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'], '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, 'total_ratings' => $total_ratings, 'viewrate' => true, 'canrate' => local_channel() ? true : false, 'pdesc' => $pdesc, 'pdesc_label' => t('Description:'), 'marital' => $marital, 'homepage' => $homepage, 'homepageurl' => linkify($homepageurl), 'hometown' => $hometown, 'hometown_label' => t('Hometown:'), 'about' => $about, 'about_label' => t('About:'), 'conn_label' => t('Connect'), 'forum_label' => t('Public Forum:'), '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['address']] ? intval($common[$rr['address']]) : '', 'common_label' => t('Common connections:'), 'common_count' => intval($common[$rr['address']]), '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']) {
                         \App::$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 = 94;
                         $dirtitle = $globaldir ? t('Global Directory') : t('Local Directory');
                         $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') : $dirtitle, '$submit' => t('Find'), '$next' => alt_pager($a, $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 (\App::$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;
 }
Example #7
0
function update_suggestions()
{
    $dirmode = get_config('system', 'directory_mode');
    if ($dirmode === false) {
        $dirmode = DIRECTORY_MODE_NORMAL;
    }
    if ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE) {
        $url = z_root() . '/sitelist';
    } else {
        $directory = find_upstream_directory($dirmode);
        $url = $directory['url'] . '/sitelist';
    }
    if (!$url) {
        return;
    }
    $ret = z_fetch_url($url);
    if ($ret['success']) {
        // We will grab fresh data once a day via the poller. Remove anything over a week old because
        // the targets may have changed their preferences and don't want to be suggested - and they
        // may have simply gone away.
        $r = q("delete from xlink where xlink_xchan = '' and xlink_updated < %s - INTERVAL %s and xlink_static = 0", db_utcnow(), db_quoteinterval('7 DAY'));
        $j = json_decode($ret['body'], true);
        if ($j && $j['success']) {
            foreach ($j['entries'] as $host) {
                poco_load('', $host['url'] . '/poco');
            }
        }
    }
}
Example #8
0
 function navbar_complete(&$a)
 {
     //	logger('navbar_complete');
     if (observer_prohibited()) {
         return;
     }
     $dirmode = intval(get_config('system', 'directory_mode'));
     $search = x($_REQUEST, 'search') ? htmlentities($_REQUEST['search'], ENT_COMPAT, 'UTF-8', false) : '';
     if (!$search || mb_strlen($search) < 2) {
         return array();
     }
     $star = false;
     $address = false;
     if (substr($search, 0, 1) === '@') {
         $search = substr($search, 1);
     }
     if (substr($search, 0, 1) === '*') {
         $star = true;
         $search = substr($search, 1);
     }
     if (strpos($search, '@') !== false) {
         $address = true;
     }
     if ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE) {
         $url = z_root() . '/dirsearch';
     }
     if (!$url) {
         require_once "include/dir_fns.php";
         $directory = find_upstream_directory($dirmode);
         $url = $directory['url'] . '/dirsearch';
     }
     $count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 100;
     if ($url) {
         $query = $url . '?f=';
         $query .= '&name=' . urlencode($search) . "&limit={$count}" . ($address ? '&address=' . urlencode($search) : '');
         $x = z_fetch_url($query);
         if ($x['success']) {
             $t = 0;
             $j = json_decode($x['body'], true);
             if ($j && $j['results']) {
                 return $j['results'];
             }
         }
     }
     return array();
 }
Example #9
0
function dirprofile_init(&$a)
{
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    $hash = $_REQUEST['hash'];
    if (!$hash) {
        return '';
    }
    $o = '';
    $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';
    }
    logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
    $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'];
            }
        }
    }
    if ($url) {
        $query = $url . '?f=&hash=' . $hash;
        $x = z_fetch_url($query);
        logger('dirprofile: 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 />' : '';
                        $qrlink = zid($rr['url']);
                        $connect_link = local_user() ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : '';
                        $online = remote_online_status($rr['address']);
                        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;
                            }
                        }
                        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:');
                        }
                        $marital = x($profile, 'marital') == 1 ? t('Status: ') . $profile['marital'] : False;
                        $sexual = x($profile, 'sexual') == 1 ? t('Sexual Preference: ') . $profile['sexual'] : False;
                        $homepage = x($profile, 'homepage') == 1 ? t('Homepage: ') . linkify($profile['homepage']) : False;
                        $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'] : '';
                        if ($keywords) {
                            $keywords = str_replace(',', ' ', $keywords);
                            $keywords = str_replace('  ', ' ', $keywords);
                            $karr = explode(' ', $keywords);
                            $out = '';
                            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 = replace_macros(get_markup_template('direntry_large.tpl'), array('$id' => ++$t, '$profile_link' => $profile_link, '$qrlink' => $qrlink, '$photo' => $rr['photo_l'], '$alttext' => $rr['name'] . ' ' . $rr['address'], '$name' => $rr['name'], '$online' => $online ? t('Online Now') : '', '$details' => $pdesc . $details, '$profile' => $profile, '$address' => $rr['address'], '$location' => $location, '$gender' => $gender, '$pdesc' => $pdesc, '$marital' => $marital, '$homepage' => $homepage, '$hometown' => $hometown, '$about' => $about, '$kw' => $out ? t('Keywords: ') : '', '$keywords' => $out, '$conn_label' => t('Connect'), '$connect' => $connect_link));
                        echo $entry;
                        killme();
                    }
                } else {
                    info(t("Not found.") . EOL);
                }
            }
        }
    }
}
Example #10
0
function directory_content(&$a)
{
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    $safe_mode = 1;
    $observer = get_observer_hash();
    if ($observer) {
        $safe_mode = get_xconfig($observer, 'directory', 'safe_mode');
    }
    if ($safe_mode === false) {
        $safe_mode = 1;
    } else {
        $safe_mode = intval($safe_mode);
    }
    if (x($_REQUEST, 'safe')) {
        $safe_mode = intval($_REQUEST['safe']);
    }
    $o = '';
    nav_set_selected('directory');
    if (x($_POST, 'search')) {
        $search = notags(trim($_POST['search']));
    } else {
        $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
    }
    $advanced = x($_REQUEST, 'query') ? notags(trim($_REQUEST['query'])) : '';
    $keywords = $_GET['keywords'] ? $_GET['keywords'] : '';
    $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';
    }
    logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
    $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'];
            }
        }
    }
    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 : 24;
        $query = $url . '?f=&kw=' . $kw . ($safe_mode != 1 ? '&safe=' . $safe_mode : '');
        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);
        }
        $sort_order = x($_REQUEST, 'order') ? $_REQUEST['order'] : '';
        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_user() ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : '';
                        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;
                            }
                        }
                        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;
                        $marital = x($profile, 'marital') == 1 ? t('Status:') : False;
                        $homepage = x($profile, 'homepage') == 1 ? t('Homepage:') : False;
                        $about = x($profile, 'about') == 1 ? t('About:') : False;
                        $entry = array('id' => ++$t, 'profile_link' => $profile_link, 'photo' => $rr['photo'], 'hash' => $rr['hash'], 'alttext' => $rr['name'] . ' ' . $rr['address'], 'name' => $rr['name'], 'details' => $pdesc . $details, 'profile' => $profile, 'address' => $rr['address'], 'location' => $location, 'gender' => $gender, 'pdesc' => $pdesc, 'marital' => $marital, 'homepage' => $homepage, 'about' => $about, 'conn_label' => t('Connect'), 'connect' => $connect_link);
                        $arr = array('contact' => $rr, 'entry' => $entry);
                        call_hooks('directory_item', $arr);
                        $entries[] = $arr['entry'];
                        unset($profile);
                        unset($location);
                    }
                    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 {
                        $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' => 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;
}