bludit/bl-kernel/ajax/get-published.php

46 lines
1.3 KiB
PHP
Raw Normal View History

2018-05-14 00:00:10 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
/*
| 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
}
$result = array();
$pagesKey = $pages->getDB();
foreach ($pagesKey as $pageKey) {
try {
$page = new Page($pageKey);
// 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);
}
}
} catch (Exception $e) {
// continue
2018-05-14 00:00:10 +02:00
}
}
exit (json_encode(array('results'=>$result)));
2018-05-14 00:00:10 +02:00
2018-12-31 10:35:27 +01:00
?>