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

51 lines
1.9 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');
/*
2020-11-01 11:55:34 +01:00
| Returns a list of pages that the title contains the query string.
| The returned list have published, sticky and statics pages.
| It's possible to filter the pages are parents by the flag "checkIsParent".
|
2020-11-01 11:55:34 +01:00
| @_POST['query'] string The string to search in the title of the pages.
| @_POST['checkIsParent'] boolean TRUE returns only parent pages, FALSE returns all pages.
|
2020-11-01 11:55:34 +01:00
| @return json Ex. {"results":[{"disabled":false,"id":"follow-bludit","text":"Follow Bludit","type":"published"}]}
*/
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) {
2021-09-05 16:18:01 +02:00
ajaxResponse(1, 'Invalid query.');
2018-05-14 00:00:10 +02:00
}
$result = array();
$pagesKey = $pages->getDB();
foreach ($pagesKey as $pageKey) {
2021-09-05 16:18:01 +02:00
try {
$page = new Page($pageKey);
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);
}
}
}
} catch (Exception $e) {
// continue
}
2018-05-14 00:00:10 +02:00
}
exit (json_encode(array('results'=>$result)));