Example #1
0
 function ApiMethod()
 {
     $tp = $this->task_parts;
     if (!isset($_GET['q'])) {
         return ["Search API Options (GET parameters)" => ['q' => "(String) Search term [Required]", "l" => "(Int) Limit results", "o" => "(Int) Offset results", "d" => "(Array[String]) Collections to search", "c" => "(String) Restrict search results to those matching one category"], "Define which collections are searchable in config.php"];
     }
     $q = $_GET['q'];
     $data = ["generated" => time(), "search_term" => $q];
     $options = ["sort" => ["date" => -1]];
     if (isset($_GET['l'])) {
         $limit = (int) $_GET['l'];
         $options['limit'] = $limit;
         $data['limit'] = $limit;
     }
     if (isset($_GET['o'])) {
         $offset = (int) $_GET['o'];
         $options['skip'] = $offset;
         $data['offset'] = $offset;
     }
     $regex = new MongoDB\BSON\Regex("^{$q}", 'i');
     //ob_end_clean();
     //var_dump($regex);
     $filter = ['$or' => [["title" => ['$regex' => $regex]], ["tags" => ['$regex' => $regex]], ["description" => ['$regex' => $regex]], ["content" => ['$regex' => $regex]]]];
     //var_dump($filter);
     //return $filter;
     if (isset($_GET['c'])) {
         $category = $_GET['c'];
         $c_imp = new category_implementation();
         $all_cats = $c_imp->ReadMany();
         //Translate title to ID
         foreach ($all_cats as $cat) {
             if (strtolower($category) == strtolower($cat->title)) {
                 $category = $cat->_id;
             }
         }
         $filter = ['$and' => [$filter, ['category' => $category]]];
         $data['category'] = $category;
     }
     //return $filter;
     $results = [];
     $num_results = 0;
     foreach ($this->searchable as $col_name) {
         $v_cname = View::loadViewByEndpoint($col_name);
         if (class_exists($v_cname)) {
             $i_imp = new $v_cname();
             $col_results = $i_imp->implementation->ReadMany($filter, $options);
             $num_results += count($col_results);
             $results[$col_name] = $col_results;
             try {
                 $col_controller = Controller::loadControllerByName($col_name);
                 $data['typenames'][$col_name] = $col_controller::$title;
             } catch (Exception $e) {
                 $data['typenames'][$col_name] = $col_name;
             }
         }
     }
     $data['number_of_results'] = $num_results;
     $data['results'] = $results;
     return $data;
 }
Example #2
0
<?php

/* 
 * LOCAL DATA CONTROLLER API 
 * 
 * Read/write API requiring authentication
 */
//Ensure no whitespace is output
ob_start();
header('Content-Type:application/json');
require 'init.php';
if ($config['enable_auth']) {
    $auth = new authenticator();
}
//$auth = new Authenticator();
$task = $_GET['a'];
$task_parts = explode('/', $task);
$api_controller_name = Controller::loadControllerByName($task_parts[0]);
if (class_exists($api_controller_name)) {
    $api_controller = new $api_controller_name($task);
    $data = $api_controller->APIMethod();
} else {
    $data = ["ResponseStatus" => "Error", "ErrorName" => "InvalidTask", "Task" => $task];
}
ob_end_clean();
echo json_encode($data);
Example #3
0
<?php

/* Initialise app */
require 'init.php';
if ($config['enable_auth']) {
    $auth = new authenticator();
}
if (!isset($_GET['a'])) {
    header('location:./?a=home');
    die;
}
$task = $_GET['a'];
$task_parts = explode('/', $task);
$controller_name = $task_parts[0];
$ui_controller_class = Controller::loadControllerByName($controller_name);
if (class_exists($ui_controller_class)) {
    $ui_controller = new $ui_controller_class($task);
} else {
    header('HTTP/1.1 404 Not Found');
    die;
}
?>
<!doctype html>
<html>
    <head>
        <!-- Styling -->
        
        <link rel="stylesheet" href="bower_components/material-design-icons/iconfont/material-icons.css" />
        <!-- <link rel="stylesheet" href="bower_components/jquery-ui/themes/base/jquery-ui.min.css" />      -->  
        <!-- <link rel="stylesheet" href="bower_components/sceditor/minified/jquery.sceditor.default.min.css" /> -->
        <link rel="stylesheet" href="bower_components/foundation-sites/dist/foundation.min.css" />