2018-05-14 00:00:10 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
2019-09-25 20:16:45 +02:00
|
|
|
/*
|
|
|
|
| Returns a list of pages and the title contains the query string
|
|
|
|
| The returned list have published, sticky and statics pages
|
|
|
|
|
|
|
|
|
| @_POST['query'] string The string to search in the title of the pages
|
|
|
|
|
|
|
|
|
| @return array
|
|
|
|
*/
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
// $_GET
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// (string) $_GET['query']
|
|
|
|
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
if ($query===false) {
|
2019-01-31 20:07:59 +01:00
|
|
|
ajaxResponse(1, 'Invalid query.');
|
2018-05-14 00:00:10 +02:00
|
|
|
}
|
|
|
|
|
2019-09-25 20:16:45 +02:00
|
|
|
$result = array();
|
|
|
|
$pagesKey = $pages->getDB();
|
2018-10-07 23:11:49 +02:00
|
|
|
foreach ($pagesKey as $pageKey) {
|
|
|
|
try {
|
|
|
|
$page = new Page($pageKey);
|
2019-09-25 20:16:45 +02:00
|
|
|
// Check page status
|
|
|
|
if ($page->published() || $page->sticky() || $page->isStatic()) {
|
|
|
|
// Check if the query contains in the title
|
2018-10-07 23:11:49 +02:00
|
|
|
$lowerTitle = Text::lowercase($page->title());
|
|
|
|
if (Text::stringContains($lowerTitle, $query)) {
|
2019-09-25 20:16:45 +02:00
|
|
|
$tmp = array('disabled'=>false);
|
|
|
|
$tmp['id'] = $page->key();
|
|
|
|
$tmp['text'] = $page->title();
|
|
|
|
$tmp['type'] = $page->type();
|
|
|
|
array_push($result, $tmp);
|
2018-10-07 23:11:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// continue
|
2018-05-14 00:00:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:16:45 +02:00
|
|
|
exit (json_encode(array('results'=>$result)));
|
2018-05-14 00:00:10 +02:00
|
|
|
|
2018-12-31 10:35:27 +01:00
|
|
|
?>
|