2025-01-18 09:06:54 +01:00
|
|
|
<?php defined('KOBLOG') or die('Koblog CMS.');
|
2019-05-18 11:54:39 +02:00
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
2019-05-24 19:00:22 +02:00
|
|
|
/*
|
|
|
|
| Search for pages that have in the title the string $query and returns the array of pages
|
|
|
|
|
|
2025-01-25 12:28:59 +01:00
|
|
|
| @_GET['type'] the type to search in the database
|
|
|
|
| @_GET['state'] the state to search in the database
|
|
|
|
| @_GET['sticky'] boolean False to not search sticky post
|
2019-05-24 19:00:22 +02:00
|
|
|
|
|
|
|
|
| @return array
|
|
|
|
*/
|
|
|
|
|
2019-05-18 11:54:39 +02:00
|
|
|
// $_GET
|
|
|
|
// ----------------------------------------------------------------------------
|
2025-01-25 12:28:59 +01:00
|
|
|
$type = empty($GET_['type']) ? ['article'] : explode(",", $GET_['type']);
|
|
|
|
$state = empty($GET_['state']) ? ['published'] : explode(",", $GET_['state']);
|
|
|
|
$sticky = isset($_GET['sticky']) ? $_GET['sticky'] != false:true; // True by default
|
2019-05-18 11:54:39 +02:00
|
|
|
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ($query===false) {
|
|
|
|
ajaxResponse(1, 'Invalid query.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$pageNumber = 1;
|
|
|
|
$numberOfItems = -1;
|
2025-01-25 12:28:59 +01:00
|
|
|
$pagesKey = $pages->getList($pageNumber, $numberOfItems, $type, $state, $sticky);
|
2019-05-18 11:54:39 +02:00
|
|
|
$tmp = array();
|
|
|
|
foreach ($pagesKey as $pageKey) {
|
|
|
|
try {
|
|
|
|
$page = new Page($pageKey);
|
|
|
|
$lowerTitle = Text::lowercase($page->title());
|
|
|
|
if (Text::stringContains($lowerTitle, $query)) {
|
2019-05-24 19:00:22 +02:00
|
|
|
$tmp[$page->key()] = $page->json(true);
|
2019-05-18 11:54:39 +02:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit (json_encode($tmp));
|
|
|
|
|
|
|
|
?>
|