<?php
+
+use Friendica\App;
+
require_once("include/bbcode.php");
require_once('include/security.php');
require_once('include/conversation.php');
intval(local_user()),
dbesc($search)
);
- if (! dbm::is_result($r)) {
- q("INSERT INTO `search` (`uid`,`term`) VALUES ( %d, '%s')",
- intval(local_user()),
- dbesc($search)
- );
+ if (!dbm::is_result($r)) {
+ dbm::insert('search', array('uid' => local_user(), 'term' => $search));
}
}
if (x($_GET,'remove') && $search) {
- q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1",
- intval(local_user()),
- dbesc($search)
- );
+ dbm::delete('search', array('uid' => local_user(), 'term' => $search));
}
$a->page['aside'] .= search_saved_searches();
- }
- else {
+ } else {
unset($_SESSION['theme']);
unset($_SESSION['mobile-theme']);
}
function search_content(App $a) {
- if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
- notice( t('Public access denied.') . EOL);
+ if (get_config('system','block_public') && !local_user() && !remote_user()) {
+ notice(t('Public access denied.') . EOL);
return;
}
- if (get_config('system','local_search') AND !local_user()) {
+ if (get_config('system','local_search') && !local_user() && !remote_user()) {
http_status_exit(403,
array("title" => t("Public access denied."),
"description" => t("Only logged in users are permitted to perform a search.")));
//return;
}
- if (get_config('system','permit_crawling') AND !local_user()) {
+ if (get_config('system','permit_crawling') && !local_user() && !remote_user()) {
// Default values:
// 10 requests are "free", after the 11th only a call per minute is allowed
$result = Cache::get("remote_search:".$remote);
if (!is_null($result)) {
$resultdata = json_decode($result);
- if (($resultdata->time > (time() - $crawl_permit_period)) AND ($resultdata->accesses > $free_crawls)) {
+ if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) {
http_status_exit(429,
array("title" => t("Too Many Requests"),
"description" => t("Only one search per minute is permitted for not logged in users.")));
} else {
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
- // Disabled until finally is decided how to proceed with this
- //if (get_config('system','use_fulltext_engine')) {
- // $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
- //} else {
- $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
- //}
+ $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
$r = q("SELECT %s
FROM `item` %s
WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`))
$sql_extra
- GROUP BY `item`.`uri` ORDER BY `item`.`id` DESC LIMIT %d , %d",
+ GROUP BY `item`.`uri`, `item`.`id` ORDER BY `item`.`id` DESC LIMIT %d , %d",
item_fieldlists(), item_joins(), item_condition(),
intval(local_user()),
intval($a->pager['start']), intval($a->pager['itemspage']));