koblog/bl-kernel/ajax/content-get-list.php

44 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php defined('KOBLOG') or die('Koblog CMS.');
2019-05-18 11:54:39 +02:00
header('Content-Type: application/json');
/*
| Search for pages that have in the title the string $query and returns the array of pages
|
| @_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
|
| @return array
*/
2019-05-18 11:54:39 +02:00
// $_GET
// ----------------------------------------------------------------------------
$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;
$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)) {
$tmp[$page->key()] = $page->json(true);
2019-05-18 11:54:39 +02:00
}
} catch (Exception $e) {
// continue
}
}
exit (json_encode($tmp));
?>