From 83ea120ac96c1f565a227a670023aa3128534e45 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sun, 7 Dec 2014 12:39:50 +0100 Subject: Revert "Revert "Directory shows channel suggestions by default"" This reverts commit bfde28f28eae1f4b00aac03b2714254d14ab7464. --- mod/directory.php | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'mod/directory.php') diff --git a/mod/directory.php b/mod/directory.php index c06a14d9e..c64c3386c 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -1,5 +1,6 @@ set_pager_itemspage(60); + if(x($_GET,'ignore')) { + q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ", + intval(local_user()), + dbesc($_GET['ignore']) + ); + } } function directory_content(&$a) { @@ -43,11 +50,33 @@ function directory_content(&$a) { else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); + if(strpos($search,'=') && local_user() && get_pconfig(local_user(),'feature','expert')) $advanced = $search; + $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\" "; + } + + } + $tpl = get_markup_template('directory_header.tpl'); @@ -238,19 +267,28 @@ function directory_content(&$a) { '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); call_hooks('directory_item', $arr); - $entries[] = $arr['entry']; + 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); } + ksort($entries); // Sort array by key so that foreach-constructs work as expected + if($j['keywords']) { $a->data['directory_keywords'] = $j['keywords']; } @@ -279,7 +317,7 @@ function directory_content(&$a) { '$finddsc' => t('Finding:'), '$safetxt' => htmlspecialchars($search,ENT_QUOTES,'UTF-8'), '$entries' => $entries, - '$dirlbl' => t('Directory'), + '$dirlbl' => $suggest ? t('Channel Suggestions') : t('Directory'), '$submit' => t('Find'), '$next' => alt_pager($a,$j['records'], t('next page'), t('previous page')) -- cgit v1.2.3 From c8818d83498d19262ba90f7f2954828c24cf03cb Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sun, 7 Dec 2014 13:38:38 +0100 Subject: Suggestions in dir redux. Suggestions are now showed in directory if suggest=1 parameter is given to directory. --- mod/directory.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mod/directory.php') diff --git a/mod/directory.php b/mod/directory.php index c64c3386c..79c1e99c9 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -58,13 +58,14 @@ function directory_content(&$a) { $keywords = (($_GET['keywords']) ? $_GET['keywords'] : ''); // Suggest channels if no search terms or keywords are given - $suggest = ($search == '' && $keywords == '' && local_user()); + $suggest = (local_user() && x($_REQUEST,'suggest')) ? $_REQUEST['suggest'] : ''; if($suggest) { $r = suggestion_query(local_user(),get_observer_hash()); // Remember in which order the suggestions were $addresses = array(); + $index = 0; foreach($r as $rr) { $addresses[$rr['xchan_addr']] = $index++; } @@ -74,12 +75,13 @@ function directory_content(&$a) { 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)) { -- cgit v1.2.3