X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=mod%2Fsearch.php;h=4a911b4fd9828a51aaf05459bdad0dfc67174c15;hb=b2d685482928363ce86c3c0519c8ff39d0af43ca;hp=2cdfd6e12826cdbb81e39e0b1871a77d0942ffd0;hpb=acaee626f5f23f4c1dc19c31896a0797a251b58f;p=friendica.git diff --git a/mod/search.php b/mod/search.php index 2cdfd6e128..4a911b4fd9 100644 --- a/mod/search.php +++ b/mod/search.php @@ -4,7 +4,6 @@ */ use Friendica\App; -use Friendica\Content\Feature; use Friendica\Content\Nav; use Friendica\Content\Pager; use Friendica\Content\Text\HTML; @@ -13,15 +12,12 @@ 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\Module\BaseSearchModule; use Friendica\Util\Strings; -require_once 'mod/dirfind.php'; - function search_saved_searches() { - $o = ''; $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : ''); @@ -53,12 +49,10 @@ function search_saved_searches() { } return $o; - } function search_init(App $a) { - $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : ''); if (local_user()) { @@ -86,25 +80,18 @@ function search_init(App $a) { unset($_SESSION['theme']); unset($_SESSION['mobile-theme']); } - - - } function search_content(App $a) { - if (Config::get('system','block_public') && !local_user() && !remote_user()) { notice(L10n::t('Public access denied.') . EOL); return; } if (Config::get('system','local_search') && !local_user() && !remote_user()) { - System::httpExit(403, - ["title" => L10n::t("Public access denied."), - "description" => L10n::t("Only logged in users are permitted to perform a search.")]); - killme(); - //notice(L10n::t('Public access denied.').EOL); - //return; + $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') && !local_user() && !remote_user()) { @@ -124,10 +111,7 @@ function search_content(App $a) { if (!is_null($result)) { $resultdata = json_decode($result); if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) { - 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(); + 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 @@ -157,10 +141,20 @@ function search_content(App $a) { $search = substr($search,1); } if (strpos($search,'@') === 0) { - return dirfind_content($a); + return BaseSearchModule::performSearch(); } if (strpos($search,'!') === 0) { - return dirfind_content($a); + 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'])) @@ -171,11 +165,9 @@ function search_content(App $a) { $tag = true; break; case 'contacts': - return dirfind_content($a, "@"); - break; + return BaseSearchModule::performSearch('@'); case 'forums': - return dirfind_content($a, "!"); - break; + return BaseSearchModule::performSearch('!'); } if (!$search) @@ -197,7 +189,7 @@ function search_content(App $a) { $condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `otype` = ? AND `type` = ? AND `term` = ?", local_user(), TERM_OBJ_POST, TERM_HASHTAG, $search]; - $params = ['order' => ['created' => true], + $params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $terms = DBA::select('term', ['oid'], $condition, $params);