git.cweiske.de
/
phinde.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Do not throw exception but send 400
[phinde.git]
/
www
/
index.php
diff --git
a/www/index.php
b/www/index.php
index 6bdaf9d2d4ff2a79974cc9f9427b2bcef0c63449..c1acfdf301c99cadbf5ef491e2404f3ec656e8fa 100644
(file)
--- a/
www/index.php
+++ b/
www/index.php
@@
-15,6
+15,14
@@
if (isset($_GET['page'])) {
}
//PEAR Pager begins at 1
$page = (int)$_GET['page'] - 1;
}
//PEAR Pager begins at 1
$page = (int)$_GET['page'] - 1;
+
+ if ($page >= 100) {
+ //Elasticsearch by default only allows 100 pages
+ // we do not want exceptions in our logs
+ header('HTTP/1.0 400 Bad Request');
+ echo "List page number is too large\n";
+ exit(1);
+ }
}
$perPage = 10;//$GLOBALS['phinde']['perPage'];
}
$perPage = 10;//$GLOBALS['phinde']['perPage'];
@@
-35,11
+43,16
@@
if (preg_match('#site:([^ ]*)#', $query, $matches)) {
$cleanQuery = $query;
}
$cleanQuery = $query;
}
-if (isset($_GET['sort']) && $_GET['sort'] == 'date') {
- $sort = 'date';
- $baseLink .= '&sort=date';
+if (isset($_GET['sort'])
+ && ($_GET['sort'] === 'date' || $_GET['sort'] === 'score')
+) {
+ $sortMode = $_GET['sort'];
} else {
} else {
- $sort = '';
+ $sortMode = $GLOBALS['phinde']['defaultSort'];
+}
+$sort = $sortMode;
+if ($sortMode !== $GLOBALS['phinde']['defaultSort']) {
+ $baseLink .= '&sort=' . $sortMode;
}
$filters = array();
}
$filters = array();
@@
-93,7
+106,7
@@
$timeEnd = microtime(true);
$pager = new Html_Pager(
$res->hits->total, $perPage, $page + 1,
$pager = new Html_Pager(
$res->hits->total, $perPage, $page + 1,
- $baseLink
+ buildLink($baseLink, $filters, null, null)
);
foreach ($res->hits->hits as &$hit) {
);
foreach ($res->hits->hits as &$hit) {
@@
-115,8
+128,8
@@
foreach ($res->hits->hits as &$hit) {
$doc->extra = new \stdClass();
$doc->extra->cleanUrl = preg_replace('#^.*://#', '', $doc->url);
$doc->extra = new \stdClass();
$doc->extra->cleanUrl = preg_replace('#^.*://#', '', $doc->url);
- if (isset($doc->modate)) {
- $doc->extra->day = substr($doc->modate, 0, 10);
+ if (isset($doc->
status->
modate)) {
+ $doc->extra->day = substr($doc->
status->
modate, 0, 10);
}
}
}
}
@@
-132,10
+145,17
@@
if ($site !== null) {
$urlNoSite = null;
}
$urlNoSite = null;
}
-$urlSort
Relevanc
e = buildLink(
-
str_replace('&sort=date
', '', $baseLink), $filters, null, null
+$urlSort
Bas
e = buildLink(
+
preg_replace('#&sort=[^&]+#
', '', $baseLink), $filters, null, null
);
);
-$urlSortDate = $urlSortRelevance . '&sort=date';
+$urlSorts = [];
+foreach (['date', 'score'] as $sortMode) {
+ if ($sortMode === $GLOBALS['phinde']['defaultSort']) {
+ $urlSorts[$sortMode] = $urlSortBase;
+ } else {
+ $urlSorts[$sortMode] = $urlSortBase . '&sort=' . $sortMode;
+ }
+}
if (isset($_GET['format']) && $_GET['format'] == 'opensearch') {
$template = 'opensearch';
if (isset($_GET['format']) && $_GET['format'] == 'opensearch') {
$template = 'opensearch';
@@
-161,8
+181,9
@@
render(
'activeFilters' => $activeFilters,
'pager' => $pager,
'sort' => $sort,
'activeFilters' => $activeFilters,
'pager' => $pager,
'sort' => $sort,
- 'urlSortRelevance' => $urlSortRelevance,
- 'urlSortDate' => $urlSortDate,
+ 'urlSorts' => $urlSorts,
+ 'hitTemplate' => 'search/' . $GLOBALS['phinde']['hitTemplate'],
+ 'sidebarinclude' => $GLOBALS['phinde']['sidebarinclude'],
)
);
?>
)
);
?>