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;
|
2019-10-05 21:20:58 +02:00
|
|
|
// (boolean) $_GET['checkIsParent']
|
|
|
|
$checkIsParent = empty($_GET['checkIsParent']) ? false : true;
|
2018-05-14 00:00:10 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
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-10-05 21:20:58 +02:00
|
|
|
if ($page->isParent() || !$checkIsParent) {
|
|
|
|
// Check page status
|
|
|
|
if ($page->published() || $page->sticky() || $page->isStatic()) {
|
|
|
|
// Check if the query contains in the title
|
|
|
|
$lowerTitle = Text::lowercase($page->title());
|
|
|
|
if (Text::stringContains($lowerTitle, $query)) {
|
|
|
|
$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
|
|
|
?>
|