Merge pull request #7714 from MrPetovan/task/4090-move-search-to-src
Move mod/search to src/Module/Search/Index
This commit is contained in:
commit
0c4ab89bc3
|
@ -40,22 +40,6 @@ function network_init(App $a)
|
|||
|
||||
Hook::add('head', __FILE__, 'network_infinite_scroll_head');
|
||||
|
||||
$search = (!empty($_GET['search']) ? Strings::escapeHtml($_GET['search']) : '');
|
||||
|
||||
if (($search != '') && !empty($_GET['submit'])) {
|
||||
$a->internalRedirect('search?search=' . urlencode($search));
|
||||
}
|
||||
|
||||
if (!empty($_GET['save'])) {
|
||||
$exists = DBA::exists('search', ['uid' => local_user(), 'term' => $search]);
|
||||
if (!$exists) {
|
||||
DBA::insert('search', ['uid' => local_user(), 'term' => $search]);
|
||||
}
|
||||
}
|
||||
if (!empty($_GET['remove'])) {
|
||||
DBA::delete('search', ['uid' => local_user(), 'term' => $search]);
|
||||
}
|
||||
|
||||
$is_a_date_query = false;
|
||||
|
||||
$group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
|
||||
|
@ -155,47 +139,10 @@ function network_init(App $a)
|
|||
$a->page['aside'] .= ForumManager::widget(local_user(), $cid);
|
||||
$a->page['aside'] .= Widget::postedByYear('network', local_user(), false);
|
||||
$a->page['aside'] .= Widget::networks('network', defaults($_GET, 'nets', '') );
|
||||
$a->page['aside'] .= saved_searches($search);
|
||||
$a->page['aside'] .= Widget\SavedSearches::getHTML($a->query_string);
|
||||
$a->page['aside'] .= Widget::fileAs('network', defaults($_GET, 'file', '') );
|
||||
}
|
||||
|
||||
function saved_searches($search)
|
||||
{
|
||||
$srchurl = '/network?f='
|
||||
. (!empty($_GET['cid']) ? '&cid=' . rawurlencode($_GET['cid']) : '')
|
||||
. (!empty($_GET['star']) ? '&star=' . rawurlencode($_GET['star']) : '')
|
||||
. (!empty($_GET['bmark']) ? '&bmark=' . rawurlencode($_GET['bmark']) : '')
|
||||
. (!empty($_GET['conv']) ? '&conv=' . rawurlencode($_GET['conv']) : '')
|
||||
. (!empty($_GET['nets']) ? '&nets=' . rawurlencode($_GET['nets']) : '')
|
||||
. (!empty($_GET['cmin']) ? '&cmin=' . rawurlencode($_GET['cmin']) : '')
|
||||
. (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '')
|
||||
. (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '');
|
||||
;
|
||||
|
||||
$terms = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
|
||||
$saved = [];
|
||||
|
||||
while ($rr = DBA::fetch($terms)) {
|
||||
$saved[] = [
|
||||
'id' => $rr['id'],
|
||||
'term' => $rr['term'],
|
||||
'encodedterm' => urlencode($rr['term']),
|
||||
'delete' => L10n::t('Remove term'),
|
||||
'selected' => ($search == $rr['term']),
|
||||
];
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('saved_searches_aside.tpl');
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
'$title' => L10n::t('Saved Searches'),
|
||||
'$add' => L10n::t('add'),
|
||||
'$searchbox' => HTML::search($search, 'netsearch-box', $srchurl),
|
||||
'$saved' => $saved,
|
||||
]);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return selected tab from query
|
||||
*
|
||||
|
|
242
mod/search.php
242
mod/search.php
|
@ -1,242 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file mod/search.php
|
||||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Content\Nav;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Module\BaseSearchModule;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
function search_saved_searches() {
|
||||
$o = '';
|
||||
$search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
|
||||
|
||||
$r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
if (DBA::isResult($r)) {
|
||||
$saved = [];
|
||||
foreach ($r as $rr) {
|
||||
$saved[] = [
|
||||
'id' => $rr['id'],
|
||||
'term' => $rr['term'],
|
||||
'encodedterm' => urlencode($rr['term']),
|
||||
'delete' => L10n::t('Remove term'),
|
||||
'selected' => ($search==$rr['term']),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate("saved_searches_aside.tpl");
|
||||
|
||||
$o .= Renderer::replaceMacros($tpl, [
|
||||
'$title' => L10n::t('Saved Searches'),
|
||||
'$add' => '',
|
||||
'$searchbox' => '',
|
||||
'$saved' => $saved,
|
||||
]);
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
function search_init(App $a) {
|
||||
$search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
|
||||
|
||||
if (local_user()) {
|
||||
if (!empty($_GET['save']) && $search) {
|
||||
$r = q("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1",
|
||||
intval(local_user()),
|
||||
DBA::escape($search)
|
||||
);
|
||||
if (!DBA::isResult($r)) {
|
||||
DBA::insert('search', ['uid' => local_user(), 'term' => $search]);
|
||||
}
|
||||
}
|
||||
if (!empty($_GET['remove']) && $search) {
|
||||
DBA::delete('search', ['uid' => local_user(), 'term' => $search]);
|
||||
}
|
||||
|
||||
/// @todo Check if there is a case at all that "aside" is prefilled here
|
||||
if (!isset($a->page['aside'])) {
|
||||
$a->page['aside'] = '';
|
||||
}
|
||||
|
||||
$a->page['aside'] .= search_saved_searches();
|
||||
}
|
||||
}
|
||||
|
||||
function search_content(App $a) {
|
||||
if (Config::get('system','block_public') && !Session::isAuthenticated()) {
|
||||
notice(L10n::t('Public access denied.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config::get('system','local_search') && !Session::isAuthenticated()) {
|
||||
$e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t("Only logged in users are permitted to perform a search."));
|
||||
$e->httpdesc = L10n::t("Public access denied.");
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (Config::get('system','permit_crawling') && !Session::isAuthenticated()) {
|
||||
// Default values:
|
||||
// 10 requests are "free", after the 11th only a call per minute is allowed
|
||||
|
||||
$free_crawls = intval(Config::get('system','free_crawls'));
|
||||
if ($free_crawls == 0)
|
||||
$free_crawls = 10;
|
||||
|
||||
$crawl_permit_period = intval(Config::get('system','crawl_permit_period'));
|
||||
if ($crawl_permit_period == 0)
|
||||
$crawl_permit_period = 10;
|
||||
|
||||
$remote = $_SERVER["REMOTE_ADDR"];
|
||||
$result = Cache::get("remote_search:".$remote);
|
||||
if (!is_null($result)) {
|
||||
$resultdata = json_decode($result);
|
||||
if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) {
|
||||
throw new \Friendica\Network\HTTPException\TooManyRequestsException(L10n::t("Only one search per minute is permitted for not logged in users."));
|
||||
}
|
||||
Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), Cache::HOUR);
|
||||
} else
|
||||
Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => 1]), Cache::HOUR);
|
||||
}
|
||||
|
||||
Nav::setSelected('search');
|
||||
|
||||
$search = (!empty($_REQUEST['search']) ? Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) : '');
|
||||
|
||||
$tag = false;
|
||||
if (!empty($_GET['tag'])) {
|
||||
$tag = true;
|
||||
$search = (!empty($_GET['tag']) ? '#' . Strings::escapeTags(trim(rawurldecode($_GET['tag']))) : '');
|
||||
}
|
||||
|
||||
// contruct a wrapper for the search header
|
||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate("content_wrapper.tpl"),[
|
||||
'name' => "search-header",
|
||||
'$title' => L10n::t("Search"),
|
||||
'$title_size' => 3,
|
||||
'$content' => HTML::search($search,'search-box','search', false)
|
||||
]);
|
||||
|
||||
if (strpos($search,'#') === 0) {
|
||||
$tag = true;
|
||||
$search = substr($search,1);
|
||||
}
|
||||
if (strpos($search,'@') === 0) {
|
||||
return BaseSearchModule::performSearch();
|
||||
}
|
||||
if (strpos($search,'!') === 0) {
|
||||
return BaseSearchModule::performSearch();
|
||||
}
|
||||
|
||||
if (parse_url($search, PHP_URL_SCHEME) != '') {
|
||||
$id = Item::fetchByLink($search);
|
||||
if (!empty($id)) {
|
||||
$item = Item::selectFirst(['guid'], ['id' => $id]);
|
||||
if (DBA::isResult($item)) {
|
||||
$a->internalRedirect('display/' . $item['guid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_GET['search-option']))
|
||||
switch($_GET['search-option']) {
|
||||
case 'fulltext':
|
||||
break;
|
||||
case 'tags':
|
||||
$tag = true;
|
||||
break;
|
||||
case 'contacts':
|
||||
return BaseSearchModule::performSearch('@');
|
||||
case 'forums':
|
||||
return BaseSearchModule::performSearch('!');
|
||||
}
|
||||
|
||||
if (!$search)
|
||||
return $o;
|
||||
|
||||
if (Config::get('system','only_tag_search'))
|
||||
$tag = true;
|
||||
|
||||
// Here is the way permissions work in the search module...
|
||||
// Only public posts can be shown
|
||||
// OR your own posts if you are a logged in member
|
||||
// No items will be shown if the member has a blocked profile wall.
|
||||
|
||||
$pager = new Pager($a->query_string);
|
||||
|
||||
if ($tag) {
|
||||
Logger::log("Start tag search for '".$search."'", Logger::DEBUG);
|
||||
|
||||
$condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))
|
||||
AND `otype` = ? AND `type` = ? AND `term` = ?",
|
||||
local_user(), TERM_OBJ_POST, TERM_HASHTAG, $search];
|
||||
$params = ['order' => ['received' => true],
|
||||
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
||||
$terms = DBA::select('term', ['oid'], $condition, $params);
|
||||
|
||||
$itemids = [];
|
||||
while ($term = DBA::fetch($terms)) {
|
||||
$itemids[] = $term['oid'];
|
||||
}
|
||||
DBA::close($terms);
|
||||
|
||||
if (!empty($itemids)) {
|
||||
$params = ['order' => ['id' => true]];
|
||||
$items = Item::selectForUser(local_user(), [], ['id' => $itemids], $params);
|
||||
$r = Item::inArray($items);
|
||||
} else {
|
||||
$r = [];
|
||||
}
|
||||
} else {
|
||||
Logger::log("Start fulltext search for '".$search."'", Logger::DEBUG);
|
||||
|
||||
$condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))
|
||||
AND `body` LIKE CONCAT('%',?,'%')",
|
||||
local_user(), $search];
|
||||
$params = ['order' => ['id' => true],
|
||||
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
||||
$items = Item::selectForUser(local_user(), [], $condition, $params);
|
||||
$r = Item::inArray($items);
|
||||
}
|
||||
|
||||
if (!DBA::isResult($r)) {
|
||||
info(L10n::t('No results.') . EOL);
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
if ($tag) {
|
||||
$title = L10n::t('Items tagged with: %s', $search);
|
||||
} else {
|
||||
$title = L10n::t('Results for: %s', $search);
|
||||
}
|
||||
|
||||
$o .= Renderer::replaceMacros(Renderer::getMarkupTemplate("section_title.tpl"),[
|
||||
'$title' => $title
|
||||
]);
|
||||
|
||||
Logger::log("Start Conversation for '".$search."'", Logger::DEBUG);
|
||||
$o .= conversation($a, $r, $pager, 'search', false, false, 'commented', local_user());
|
||||
|
||||
$o .= $pager->renderMinimal(count($r));
|
||||
|
||||
Logger::log("Done '".$search."'", Logger::DEBUG);
|
||||
|
||||
return $o;
|
||||
}
|
|
@ -120,7 +120,7 @@ abstract class BaseModule extends BaseObject
|
|||
$a = \get_app();
|
||||
|
||||
$x = explode('.', $hash);
|
||||
if (time() > (IntVal($x[0]) + $max_livetime)) {
|
||||
if (time() > (intval($x[0]) + $max_livetime)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -893,9 +893,9 @@ class HTML
|
|||
* @param bool $aside Display the search widgit aside.
|
||||
*
|
||||
* @return string Formatted HTML.
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function search($s, $id = 'search-box', $url = 'search', $aside = true)
|
||||
public static function search($s, $id = 'search-box', $aside = true)
|
||||
{
|
||||
$mode = 'text';
|
||||
|
||||
|
@ -906,23 +906,24 @@ class HTML
|
|||
|
||||
$values = [
|
||||
'$s' => $s,
|
||||
'$q' => urlencode($s),
|
||||
'$id' => $id,
|
||||
'$action_url' => $url,
|
||||
'$search_label' => L10n::t('Search'),
|
||||
'$save_label' => $save_label,
|
||||
'$savedsearch' => 'savedsearch',
|
||||
'$search_hint' => L10n::t('@name, !forum, #tags, content'),
|
||||
'$mode' => $mode
|
||||
'$mode' => $mode,
|
||||
'$return_url' => urlencode('search?q=' . $s),
|
||||
];
|
||||
|
||||
if (!$aside) {
|
||||
$values['$searchoption'] = [
|
||||
L10n::t("Full Text"),
|
||||
L10n::t("Tags"),
|
||||
L10n::t("Contacts")];
|
||||
$values['$search_options'] = [
|
||||
'fulltext' => L10n::t('Full Text'),
|
||||
'tags' => L10n::t('Tags'),
|
||||
'contacts' => L10n::t('Contacts')
|
||||
];
|
||||
|
||||
if (Config::get('system', 'poco_local_search')) {
|
||||
$values['$searchoption'][] = L10n::t("Forums");
|
||||
$values['$searchoption']['forums'] = L10n::t('Forums');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Content\Widget;
|
||||
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
|
||||
class SavedSearches
|
||||
{
|
||||
/**
|
||||
* @param string $return_url
|
||||
* @param string $search
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getHTML($return_url, $search = '')
|
||||
{
|
||||
$o = '';
|
||||
|
||||
$saved_searches = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
|
||||
if (DBA::isResult($saved_searches)) {
|
||||
$saved = [];
|
||||
foreach ($saved_searches as $saved_search) {
|
||||
$saved[] = [
|
||||
'id' => $saved_search['id'],
|
||||
'term' => $saved_search['term'],
|
||||
'encodedterm' => urlencode($saved_search['term']),
|
||||
'delete' => L10n::t('Remove term'),
|
||||
'selected' => $search == $saved_search['term'],
|
||||
];
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('widget/saved_searches.tpl');
|
||||
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
'$title' => L10n::t('Saved Searches'),
|
||||
'$add' => '',
|
||||
'$searchbox' => '',
|
||||
'$saved' => $saved,
|
||||
'$return_url' => urlencode($return_url),
|
||||
]);
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\App\Arguments;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Pager;
|
||||
|
@ -23,13 +24,14 @@ class BaseSearchModule extends BaseModule
|
|||
/**
|
||||
* Performs a search with an optional prefix
|
||||
*
|
||||
* @param string $search Search query
|
||||
* @param string $prefix A optional prefix (e.g. @ or !) for searching
|
||||
*
|
||||
* @return string
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function performSearch($prefix = '')
|
||||
public static function performSearch($search, $prefix = '')
|
||||
{
|
||||
$a = self::getApp();
|
||||
$config = $a->getConfig();
|
||||
|
@ -38,7 +40,7 @@ class BaseSearchModule extends BaseModule
|
|||
|
||||
$localSearch = $config->get('system', 'poco_local_search');
|
||||
|
||||
$search = $prefix . Strings::escapeTags(trim(defaults($_REQUEST, 'search', '')));
|
||||
$search = $prefix . $search;
|
||||
|
||||
if (!$search) {
|
||||
return '';
|
||||
|
@ -62,7 +64,9 @@ class BaseSearchModule extends BaseModule
|
|||
$header = L10n::t('Forum Search - %s', $search);
|
||||
}
|
||||
|
||||
$pager = new Pager($a->query_string);
|
||||
/** @var Arguments $args */
|
||||
$args = self::getClass(Arguments::class);
|
||||
$pager = new Pager($args->getQueryString());
|
||||
|
||||
if ($localSearch && empty($results)) {
|
||||
$pager->setItemsPerPage(80);
|
||||
|
|
|
@ -6,6 +6,7 @@ use Friendica\Content\Widget;
|
|||
use Friendica\Core\L10n;
|
||||
use Friendica\Module\BaseSearchModule;
|
||||
use Friendica\Module\Login;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
/**
|
||||
* Directory search module
|
||||
|
@ -19,6 +20,8 @@ class Directory extends BaseSearchModule
|
|||
return Login::form();
|
||||
}
|
||||
|
||||
$search = Strings::escapeTags(trim(rawurldecode($_REQUEST['search'] ?? '')));
|
||||
|
||||
$a = self::getApp();
|
||||
|
||||
if (empty($a->page['aside'])) {
|
||||
|
@ -28,6 +31,6 @@ class Directory extends BaseSearchModule
|
|||
$a->page['aside'] .= Widget::findPeople();
|
||||
$a->page['aside'] .= Widget::follow();
|
||||
|
||||
return self::performSearch();
|
||||
return self::performSearch($search);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module\Search;
|
||||
|
||||
use Friendica\App\Arguments;
|
||||
use Friendica\Content\Nav;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Content\Widget;
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Cache\Cache as CacheClass;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Module\BaseSearchModule;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class Index extends BaseSearchModule
|
||||
{
|
||||
public static function content()
|
||||
{
|
||||
$search = (!empty($_GET['q']) ? Strings::escapeTags(trim(rawurldecode($_GET['q']))) : '');
|
||||
|
||||
if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
|
||||
throw new HTTPException\ForbiddenException(L10n::t('Public access denied.'));
|
||||
}
|
||||
|
||||
if (Config::get('system', 'local_search') && !Session::isAuthenticated()) {
|
||||
$e = new HTTPException\ForbiddenException(L10n::t('Only logged in users are permitted to perform a search.'));
|
||||
$e->httpdesc = L10n::t('Public access denied.');
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (Config::get('system', 'permit_crawling') && !Session::isAuthenticated()) {
|
||||
// Default values:
|
||||
// 10 requests are "free", after the 11th only a call per minute is allowed
|
||||
|
||||
$free_crawls = intval(Config::get('system', 'free_crawls'));
|
||||
if ($free_crawls == 0)
|
||||
$free_crawls = 10;
|
||||
|
||||
$crawl_permit_period = intval(Config::get('system', 'crawl_permit_period'));
|
||||
if ($crawl_permit_period == 0)
|
||||
$crawl_permit_period = 10;
|
||||
|
||||
$remote = $_SERVER['REMOTE_ADDR'];
|
||||
$result = Cache::get('remote_search:' . $remote);
|
||||
if (!is_null($result)) {
|
||||
$resultdata = json_decode($result);
|
||||
if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) {
|
||||
throw new HTTPException\TooManyRequestsException(L10n::t('Only one search per minute is permitted for not logged in users.'));
|
||||
}
|
||||
Cache::set('remote_search:' . $remote, json_encode(['time' => time(), 'accesses' => $resultdata->accesses + 1]), CacheClass::HOUR);
|
||||
} else {
|
||||
Cache::set('remote_search:' . $remote, json_encode(['time' => time(), 'accesses' => 1]), CacheClass::HOUR);
|
||||
}
|
||||
}
|
||||
|
||||
if (local_user()) {
|
||||
self::getApp()->page['aside'] .= Widget\SavedSearches::getHTML('search?q=' . $search, $search);
|
||||
}
|
||||
|
||||
Nav::setSelected('search');
|
||||
|
||||
$tag = false;
|
||||
if (!empty($_GET['tag'])) {
|
||||
$tag = true;
|
||||
$search = '#' . Strings::escapeTags(trim(rawurldecode($_GET['tag'])));
|
||||
}
|
||||
|
||||
// contruct a wrapper for the search header
|
||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('content_wrapper.tpl'), [
|
||||
'name' => 'search-header',
|
||||
'$title' => L10n::t('Search'),
|
||||
'$title_size' => 3,
|
||||
'$content' => HTML::search($search, 'search-box', false)
|
||||
]);
|
||||
|
||||
if (strpos($search, '#') === 0) {
|
||||
$tag = true;
|
||||
$search = substr($search, 1);
|
||||
}
|
||||
|
||||
if (strpos($search, '@') === 0 || strpos($search, '!') === 0) {
|
||||
return self::performSearch($search);
|
||||
}
|
||||
|
||||
if (parse_url($search, PHP_URL_SCHEME) != '') {
|
||||
$id = Item::fetchByLink($search);
|
||||
if (!empty($id)) {
|
||||
$item = Item::selectFirst(['guid'], ['id' => $id]);
|
||||
if (DBA::isResult($item)) {
|
||||
self::getApp()->internalRedirect('display/' . $item['guid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_GET['search-option'])) {
|
||||
switch ($_GET['search-option']) {
|
||||
case 'fulltext':
|
||||
break;
|
||||
case 'tags':
|
||||
$tag = true;
|
||||
break;
|
||||
case 'contacts':
|
||||
return self::performSearch($search, '@');
|
||||
case 'forums':
|
||||
return self::performSearch($search, '!');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$search) {
|
||||
return $o;
|
||||
}
|
||||
|
||||
$tag = $tag || Config::get('system', 'only_tag_search');
|
||||
|
||||
// Here is the way permissions work in the search module...
|
||||
// Only public posts can be shown
|
||||
// OR your own posts if you are a logged in member
|
||||
// No items will be shown if the member has a blocked profile wall.
|
||||
|
||||
/** @var Arguments $args */
|
||||
$args = self::getClass(Arguments::class);
|
||||
$pager = new Pager($args->getQueryString());
|
||||
|
||||
if ($tag) {
|
||||
Logger::info('Start tag search.', ['q' => $search]);
|
||||
|
||||
$condition = [
|
||||
"(`uid` = 0 OR (`uid` = ? AND NOT `global`))
|
||||
AND `otype` = ? AND `type` = ? AND `term` = ?",
|
||||
local_user(), Term::OBJECT_TYPE_POST, Term::HASHTAG, $search
|
||||
];
|
||||
$params = [
|
||||
'order' => ['received' => true],
|
||||
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]
|
||||
];
|
||||
$terms = DBA::select('term', ['oid'], $condition, $params);
|
||||
|
||||
$itemids = [];
|
||||
while ($term = DBA::fetch($terms)) {
|
||||
$itemids[] = $term['oid'];
|
||||
}
|
||||
|
||||
DBA::close($terms);
|
||||
|
||||
if (!empty($itemids)) {
|
||||
$params = ['order' => ['id' => true]];
|
||||
$items = Item::selectForUser(local_user(), [], ['id' => $itemids], $params);
|
||||
$r = Item::inArray($items);
|
||||
} else {
|
||||
$r = [];
|
||||
}
|
||||
} else {
|
||||
Logger::info('Start fulltext search.', ['q' => $search]);
|
||||
|
||||
$condition = [
|
||||
"(`uid` = 0 OR (`uid` = ? AND NOT `global`))
|
||||
AND `body` LIKE CONCAT('%',?,'%')",
|
||||
local_user(), $search
|
||||
];
|
||||
$params = [
|
||||
'order' => ['id' => true],
|
||||
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]
|
||||
];
|
||||
$items = Item::selectForUser(local_user(), [], $condition, $params);
|
||||
$r = Item::inArray($items);
|
||||
}
|
||||
|
||||
if (!DBA::isResult($r)) {
|
||||
info(L10n::t('No results.'));
|
||||
return $o;
|
||||
}
|
||||
|
||||
if ($tag) {
|
||||
$title = L10n::t('Items tagged with: %s', $search);
|
||||
} else {
|
||||
$title = L10n::t('Results for: %s', $search);
|
||||
}
|
||||
|
||||
$o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
|
||||
'$title' => $title
|
||||
]);
|
||||
|
||||
Logger::info('Start Conversation.', ['q' => $search]);
|
||||
|
||||
$o .= conversation(self::getApp(), $r, $pager, 'search', false, false, 'commented', local_user());
|
||||
|
||||
$o .= $pager->renderMinimal(count($r));
|
||||
|
||||
return $o;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module\Search;
|
||||
|
||||
use Friendica\App\Arguments;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class Saved extends BaseModule
|
||||
{
|
||||
public static function rawContent()
|
||||
{
|
||||
/** @var Arguments $args */
|
||||
$args = self::getClass(Arguments::class);
|
||||
|
||||
$action = $args->get(2, 'none');
|
||||
$search = Strings::escapeTags(trim(rawurldecode($args->get(3, ''))));
|
||||
|
||||
$return_url = $_GET['return_url'] ?? 'search?q=' . urlencode($search);
|
||||
|
||||
if (local_user()) {
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
$fields = ['uid' => local_user(), 'term' => $search];
|
||||
if (!DBA::exists('search', $fields)) {
|
||||
DBA::insert('search', $fields);
|
||||
info(L10n::t('Search term successfully saved.'));
|
||||
} else {
|
||||
info(L10n::t('Search term already saved.'));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'remove':
|
||||
DBA::delete('search', ['uid' => local_user(), 'term' => $search]);
|
||||
info(L10n::t('Search term successfully removed.'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
self::getApp()->internalRedirect($return_url);
|
||||
}
|
||||
}
|
|
@ -189,7 +189,10 @@ return [
|
|||
],
|
||||
|
||||
'/search' => [
|
||||
'[/]' => [Module\Search\Index::class, [R::GET]],
|
||||
'/acl' => [Module\Search\Acl::class, [R::GET, R::POST]],
|
||||
'/saved/add/{term}' => [Module\Search\Saved::class, [R::GET]],
|
||||
'/saved/remove/{term}' => [Module\Search\Saved::class, [R::GET]],
|
||||
],
|
||||
|
||||
'/settings' => [
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
<div class="widget" id="saved-search-list">
|
||||
<h3 id="search">{{$title}}</h3>
|
||||
{{$searchbox nofilter}}
|
||||
|
||||
<ul role="menu" id="saved-search-ul">
|
||||
{{foreach $saved as $search}}
|
||||
<li role="menuitem" class="saved-search-li clear">
|
||||
<a title="{{$search.delete}}" onclick="return confirmDelete();" id="drop-saved-search-term-{{$search.id}}" class="iconspacer savedsearchdrop " href="network?remove=1&search={{$search.encodedterm}}"></a>
|
||||
<a id="saved-search-term-{{$search.id}}" class="savedsearchterm" href="search?search={{$search.encodedterm}}">{{$search.term}}</a>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
<div class="clear"></div>
|
||||
</div>
|
|
@ -1,19 +1,17 @@
|
|||
<div id="{{$id}}" class="input-group">
|
||||
<form action="{{$action_url}}" method="get" >
|
||||
<form action="search" method="get">
|
||||
{{strip}}
|
||||
<input type="text" name="search" id="search-text" placeholder="{{$search_label}}" value="{{$s}}" />
|
||||
{{if $searchoption}}
|
||||
<input type="text" name="q" id="search-text" placeholder="{{$search_label}}" value="{{$s}}">
|
||||
{{if $search_options}}
|
||||
<select name="search-option" id="search-options">
|
||||
<option value="fulltext">{{$searchoption.0}}</option>
|
||||
<option value="tags">{{$searchoption.1}}</option>
|
||||
<option value="contacts">{{$searchoption.2}}</option>
|
||||
{{if $searchoption.3}}<option value="forums">{{$searchoption.3}}</option>{{/if}}
|
||||
{{foreach $search_options as $value => $label}}
|
||||
<option value="{{$value}}">{{$label}}</option>
|
||||
{{/foreach}}
|
||||
</select>
|
||||
{{/if}}
|
||||
|
||||
<input type="submit" name="submit" id="search-submit" value="{{$search_label}}"/>
|
||||
{{if $savedsearch}}
|
||||
<input type="submit" name="save" id="search-save" value="{{$save_label}}" />
|
||||
{{if $s}}
|
||||
<a href="search/saved/add/{{$q}}?return_url={{$return_url}}">{{$save_label}}</a>
|
||||
{{/if}}
|
||||
{{/strip}}
|
||||
</form>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
<div class="widget" id="saved-search-list">
|
||||
<h3 id="search">{{$title}}</h3>
|
||||
{{$searchbox nofilter}}
|
||||
|
||||
<ul role="menu" id="saved-search-ul">
|
||||
{{foreach $saved as $search}}
|
||||
<li role="menuitem" class="saved-search-li clear">
|
||||
<a href="search/saved/remove/{{$search.encodedterm}}?return_url={{$return_url}}" title="{{$search.delete}}" onclick="return confirmDelete();" id="drop-saved-search-term-{{$search.id}}" class="iconspacer savedsearchdrop"></a>
|
||||
<a href="search?q={{$search.encodedterm}}" id="saved-search-term-{{$search.id}}" class="savedsearchterm">{{$search.term}}</a>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
<div class="clear"></div>
|
||||
</div>
|
|
@ -265,7 +265,7 @@
|
|||
<form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}">
|
||||
<!-- <img class="hidden-xs" src="{{$nav.userinfo.icon}}" alt="{{$nav.userinfo.name}}" style="max-width:33px; max-height:33px; min-width:33px; min-height:33px; width:33px; height:33px;"> -->
|
||||
<div class="form-group form-group-search">
|
||||
<input id="nav-search-input-field-mobile" class="form-control form-search" type="text" name="search" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$nav.search.1}}">
|
||||
<input id="nav-search-input-field-mobile" class="form-control form-search" type="text" name="q" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$nav.search.1}}">
|
||||
<button class="btn btn-default btn-sm form-button-search" type="submit">{{$nav.search.1}}</button>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
{{if $saved}}
|
||||
<div class="widget" id="saved-search-list">
|
||||
<h3 id="search">{{$title}}</h3>
|
||||
|
||||
<ul role="menu" id="saved-search-ul">
|
||||
{{foreach $saved as $search}}
|
||||
<li role="menuitem" class="saved-search-li clear">
|
||||
<a title="{{$search.delete}}" onclick="return confirmDelete();" id="drop-saved-search-term-{{$search.id}}" class="savedsearchdrop pull-right widget-action faded-icon" href="network?remove=1&search={{$search.encodedterm}}">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i>
|
||||
</a>
|
||||
<a id="saved-search-term-{{$search.id}}" class="savedsearchterm" href="search?search={{$search.encodedterm}}">{{$search.term}}</a>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
{{/if}}
|
|
@ -4,34 +4,32 @@ Some parts of this template will be moved by js to other places (see theme.js) -
|
|||
|
||||
<div id="{{$id}}" {{* class="input-group" *}}>
|
||||
<div id="search-wrapper">
|
||||
<form action="{{$action_url}}" method="get" >
|
||||
<form action="search" method="get">
|
||||
<div class="row">
|
||||
<div class="col-md-2"></div>
|
||||
<div class="col-md-8 ">
|
||||
|
||||
<div class="form-group form-group-search">
|
||||
<input type="text" name="search" id="search-text" class="search-input form-control form-search" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$search_label}}" value="{{$s}}" />
|
||||
<input type="text" name="q" id="search-text" class="search-input form-control form-search" data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$search_label}}" value="{{$s}}" />
|
||||
<button id="search-submit" class="btn btn-default btn-sm form-button-search" type="submit">{{$search_label}}</button>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4"></div>
|
||||
<div class="col-md-8">
|
||||
{{* The button to save searches *}}
|
||||
{{if $savedsearch}}
|
||||
<button class="btn btn-primary btn-small pull-right" type="submit" name="save" value="{{$save_label}}">{{$save_label}}</button>
|
||||
{{if $s}}
|
||||
<a href="search/saved/add/{{$q}}?return_url={{$return_url}}" class="btn btn-primary btn-small pull-right">{{$save_label}}</a>
|
||||
{{/if}}
|
||||
|
||||
{{* The select popup menu to select what kind of results the user would like to search for *}}
|
||||
{{if $searchoption}}
|
||||
{{if $search_options}}
|
||||
<div class="col-md-6 pull-right">
|
||||
<div class="form-group field select">
|
||||
<select name="search-option" id="search-options" class="form-control form-control-sm">
|
||||
<option value="fulltext">{{$searchoption.0}}</option>
|
||||
<option value="tags">{{$searchoption.1}}</option>
|
||||
<option value="contacts">{{$searchoption.2}}</option>
|
||||
{{if $searchoption.3}}<option value="forums">{{$searchoption.3}}</option>{{/if}}
|
||||
{{foreach $search_options as $value => $label}}
|
||||
<option value="{{$value}}">{{$label}}</option>
|
||||
{{/foreach}}
|
||||
</select>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
@ -47,10 +45,10 @@ Some parts of this template will be moved by js to other places (see theme.js) -
|
|||
</form>
|
||||
</div>
|
||||
|
||||
{{if $savedsearch}}
|
||||
<form id="search-save-form" action="{{$action_url}}" method="get" >
|
||||
<input type="hidden" name="search" value="{{$s}}" />
|
||||
<button class="btn btn-sm btn-main pull-right" type="submit" name="save" id="search-save" title="{{$save_label}}" aria-label="{{$save_label}}" value="{{$save_label}}" data-toggle="tooltip">
|
||||
{{if $s}}
|
||||
<form id="search-save-form" action="search/saved/add/{{$q}}" method="get">
|
||||
<input type="hidden" name="return_url" value="{{$return_url}}">
|
||||
<button class="btn btn-sm btn-main pull-right" type="submit" id="search-save" title="{{$save_label}}" aria-label="{{$save_label}}" value="{{$save_label}}" data-toggle="tooltip">
|
||||
{{if $mode == "tag"}}
|
||||
<i class="fa fa-plus fa-2x" aria-hidden="true"></i>
|
||||
{{else}}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
{{if $saved}}
|
||||
<div class="widget" id="saved-search-list">
|
||||
<h3 id="search">{{$title}}</h3>
|
||||
|
||||
<ul role="menu" id="saved-search-ul">
|
||||
{{foreach $saved as $search}}
|
||||
<li role="menuitem" class="saved-search-li clear">
|
||||
<a href="search/saved/remove/{{$search.encodedterm}}?return_url={{$return_url}}" title="{{$search.delete}}" onclick="return confirmDelete();" id="drop-saved-search-term-{{$search.id}}" class="savedsearchdrop pull-right widget-action faded-icon">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i>
|
||||
</a>
|
||||
<a href="search?q={{$search.encodedterm}}" id="saved-search-term-{{$search.id}}" class="savedsearchterm">{{$search.term}}</a>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
{{/if}}
|
|
@ -1,15 +0,0 @@
|
|||
<div id="saved-search-list" class="widget">
|
||||
<h3 class="title">{{$title}}</h3>
|
||||
|
||||
<ul id="saved-search-ul">
|
||||
{{foreach $saved as $search}}
|
||||
<li class="tool {{if $search.selected}}selected{{/if}}">
|
||||
<a href="search?search={{$search.encodedterm}}" class="label" >{{$search.term}}</a>
|
||||
<a href="network?remove=1&search={{$search.encodedterm}}" class="action icon s10 delete" title="{{$search.delete}}" onclick="return confirmDelete();"></a>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
|
||||
{{$searchbox nofilter}}
|
||||
|
||||
</div>
|
|
@ -0,0 +1,15 @@
|
|||
<div id="saved-search-list" class="widget">
|
||||
<h3 class="title">{{$title}}</h3>
|
||||
|
||||
<ul id="saved-search-ul">
|
||||
{{foreach $saved as $search}}
|
||||
<li class="tool {{if $search.selected}}selected{{/if}}">
|
||||
<a href="search?q={{$search.encodedterm}}" class="label">{{$search.term}}</a>
|
||||
<a href="search/saved/remove/{{$search.encodedterm}}?return_url={{$return_url}}" class="action icon s10 delete" title="{{$search.delete}}" onclick="return confirmDelete();"></a>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
|
||||
{{$searchbox nofilter}}
|
||||
|
||||
</div>
|
|
@ -111,7 +111,7 @@
|
|||
{{if $nav.search}}
|
||||
<li role="search" id="nav-search-box">
|
||||
<form method="get" action="{{$nav.search.0}}">
|
||||
<input accesskey="s" id="nav-search-text" class="nav-menu-search" type="text" value="" name="search" placeholder=" {{$search_hint}}">
|
||||
<input accesskey="s" id="nav-search-text" class="nav-menu-search" type="text" value="" name="q" placeholder=" {{$search_hint}}">
|
||||
<select name="search-option">
|
||||
<option value="fulltext">{{$nav.searchoption.0}}</option>
|
||||
<option value="tags">{{$nav.searchoption.1}}</option>
|
||||
|
|
Loading…
Reference in New Issue
Block a user