Initial commit.
This is to be the new HashRU website based on the Aaronweb.net/Kabuki CMS.
This commit is contained in:
41
controllers/ProvideAutoSuggest.php
Normal file
41
controllers/ProvideAutoSuggest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/*****************************************************************************
|
||||
* ProvideAutoSuggest.php
|
||||
* Contains the autosuggest provider.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class ProvideAutoSuggest extends JSONController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// Ensure it's just admins at this point.
|
||||
if (!Registry::get('user')->isAdmin())
|
||||
throw new NotAllowedException();
|
||||
|
||||
if (!isset($_GET['type']))
|
||||
throw new UnexpectedValueException('Unsupported autosuggest request.');
|
||||
|
||||
if ($_GET['type'] === 'tags' && isset($_GET['data']))
|
||||
{
|
||||
$data = array_unique(explode(' ', urldecode($_GET['data'])));
|
||||
$data = array_filter($data, function($item) {
|
||||
return strlen($item) >= 3;
|
||||
});
|
||||
|
||||
$this->payload = ['items' => []];
|
||||
|
||||
// Nothing to look for?
|
||||
if (count($data) === 0)
|
||||
return;
|
||||
|
||||
$results = Tag::match($data);
|
||||
foreach ($results as $id_tag => $tag)
|
||||
$this->payload['items'][] = [
|
||||
'label' => $tag,
|
||||
'id_tag' => $id_tag,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user