X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fsearch.php;h=9a70bcac908d179d3512761284bd8dd64b431a17;hb=da710999e032ad01aa91822f1b80de729e15de25;hp=852043f3000f06606656af1a7aee683896d313df;hpb=14fde5dc9b1915392601fb94efc6224c01f2b216;p=friendica.git diff --git a/mod/search.php b/mod/search.php index 852043f300..9a70bcac90 100644 --- a/mod/search.php +++ b/mod/search.php @@ -4,27 +4,25 @@ */ use Friendica\App; -use Friendica\Content\Feature; 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\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Item; +use Friendica\Util\Strings; -require_once 'include/conversation.php'; require_once 'mod/dirfind.php'; function search_saved_searches() { $o = ''; - $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); - - if (!Feature::isEnabled(local_user(),'savedsearch')) - return $o; + $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : ''); $r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d", intval(local_user()) @@ -43,9 +41,9 @@ function search_saved_searches() { } - $tpl = get_markup_template("saved_searches_aside.tpl"); + $tpl = Renderer::getMarkupTemplate("saved_searches_aside.tpl"); - $o .= replace_macros($tpl, [ + $o .= Renderer::replaceMacros($tpl, [ '$title' => L10n::t('Saved Searches'), '$add' => '', '$searchbox' => '', @@ -60,10 +58,10 @@ function search_saved_searches() { function search_init(App $a) { - $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); + $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : ''); if (local_user()) { - if (x($_GET,'save') && $search) { + if (!empty($_GET['save']) && $search) { $r = q("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1", intval(local_user()), DBA::escape($search) @@ -72,7 +70,7 @@ function search_init(App $a) { DBA::insert('search', ['uid' => local_user(), 'term' => $search]); } } - if (x($_GET,'remove') && $search) { + if (!empty($_GET['remove']) && $search) { DBA::delete('search', ['uid' => local_user(), 'term' => $search]); } @@ -92,14 +90,6 @@ function search_init(App $a) { } - - -function search_post(App $a) { - if (x($_POST,'search')) - $a->data['search'] = $_POST['search']; -} - - function search_content(App $a) { if (Config::get('system','block_public') && !local_user() && !remote_user()) { @@ -111,7 +101,7 @@ function search_content(App $a) { System::httpExit(403, ["title" => L10n::t("Public access denied."), "description" => L10n::t("Only logged in users are permitted to perform a search.")]); - killme(); + exit(); //notice(L10n::t('Public access denied.').EOL); //return; } @@ -136,7 +126,7 @@ function search_content(App $a) { System::httpExit(429, ["title" => L10n::t("Too Many Requests"), "description" => L10n::t("Only one search per minute is permitted for not logged in users.")]); - killme(); + exit(); } Cache::set("remote_search:".$remote, json_encode(["time" => time(), "accesses" => $resultdata->accesses + 1]), Cache::HOUR); } else @@ -145,24 +135,20 @@ function search_content(App $a) { Nav::setSelected('search'); - $search = ''; - if (x($a->data,'search')) - $search = notags(trim($a->data['search'])); - else - $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); + $search = (!empty($_REQUEST['search']) ? Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) : ''); $tag = false; - if (x($_GET,'tag')) { + if (!empty($_GET['tag'])) { $tag = true; - $search = (x($_GET,'tag') ? '#' . notags(trim(rawurldecode($_GET['tag']))) : ''); + $search = (!empty($_GET['tag']) ? '#' . Strings::escapeTags(trim(rawurldecode($_GET['tag']))) : ''); } // contruct a wrapper for the search header - $o = replace_macros(get_markup_template("content_wrapper.tpl"),[ + $o = Renderer::replaceMacros(Renderer::getMarkupTemplate("content_wrapper.tpl"),[ 'name' => "search-header", '$title' => L10n::t("Search"), '$title_size' => 3, - '$content' => search($search,'search-box','search',((local_user()) ? true : false), false) + '$content' => HTML::search($search,'search-box','search', false) ]); if (strpos($search,'#') === 0) { @@ -176,7 +162,7 @@ function search_content(App $a) { return dirfind_content($a); } - if (x($_GET,'search-option')) + if (!empty($_GET['search-option'])) switch($_GET['search-option']) { case 'fulltext': break; @@ -205,7 +191,7 @@ function search_content(App $a) { $pager = new Pager($a->query_string); if ($tag) { - Logger::log("Start tag search for '".$search."'", LOGGER_DEBUG); + Logger::log("Start tag search for '".$search."'", Logger::DEBUG); $condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `otype` = ? AND `type` = ? AND `term` = ?", @@ -228,7 +214,7 @@ function search_content(App $a) { $r = []; } } else { - Logger::log("Start fulltext search for '".$search."'", LOGGER_DEBUG); + Logger::log("Start fulltext search for '".$search."'", Logger::DEBUG); $condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `body` LIKE CONCAT('%',?,'%')", @@ -251,16 +237,16 @@ function search_content(App $a) { $title = L10n::t('Results for: %s', $search); } - $o .= replace_macros(get_markup_template("section_title.tpl"),[ + $o .= Renderer::replaceMacros(Renderer::getMarkupTemplate("section_title.tpl"),[ '$title' => $title ]); - Logger::log("Start Conversation for '".$search."'", LOGGER_DEBUG); + 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); + Logger::log("Done '".$search."'", Logger::DEBUG); return $o; }