public static function init() { if (REST_API::getOutputFormat() == 'csv') { REST_API::sendError(sprintf('%s output format not supported.', strtoupper(REST_API::getOutputFormat())), 401, 'xml'); } $request_uri = REST_API::getRequestURI(); $section_reference = $request_uri[0]; $sections = NULL; if (is_null($section_reference)) { $sections = SectionManager::fetch(); } elseif (is_numeric($section_reference)) { $sections = SectionManager::fetch($section_reference); } else { $section_id = SectionManager::fetchIDFromHandle($section_reference); if ($section_id) { $sections = SectionManager::fetch($section_id); } } if (!is_array($sections)) { $sections = array($sections); } if (!reset($sections) instanceof Section) { REST_API::sendError(sprintf("Section '%s' not found.", $section_reference), 404); } self::$_sections = $sections; }
public static function init() { // store request parameters for later self::$_token = trim($_REQUEST['token']); self::$_output_type = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'xml'; self::$_uri = explode('/', trim($_REQUEST['url'], '/')); self::$_http_method = strtolower($_SERVER['REQUEST_METHOD']); // get plugin name from the first segment in the URL // and remove it from the URL segments list $plugin_name = strtolower(self::$_uri[0]); self::$_plugin_name = $plugin_name; self::$_plugin_class = 'REST_' . ucfirst($plugin_name); array_shift(self::$_uri); // include the plugin! require_once EXTENSIONS . "/rest_api/plugins/{$plugin_name}/rest.{$plugin_name}.php"; if (!class_exists(self::$_plugin_class)) { REST_API::sendError(sprintf("Plugin '%s' does not exist.", self::$_plugin_class), 404); } // perform global API authentication self::__authenticate($plugin_class); // initialise the plugin if (method_exists(self::$_plugin_class, 'init')) { call_user_func(array(self::$_plugin_class, 'init')); } // perform plugin authentication if (method_exists(self::$_plugin_class, 'authenticate')) { call_user_func(array(self::$_plugin_class, 'authenticate')); } if (method_exists(self::$_plugin_class, self::$_http_method)) { call_user_func(array(self::$_plugin_class, self::$_http_method)); } else { REST_API::sendError(sprintf("Plugin '%s' does not support HTTP %s.", self::$_plugin_class, strtoupper($method)), 401); } }
public static function delete() { $entry = EntryManager::fetch(self::$_entry_id); if (!$entry) { REST_API::sendError('Entry not found.', 404); } else { EntryManager::delete(self::$_entry_id); $response = new XMLElement('response', NULL, array('id' => self::$_entry_id, 'result' => 'success', 'type' => 'deleted')); $response->appendChild(new XMLElement('message', 'Entry deleted successfully.')); REST_API::sendOutput($response); } }
public static function get() { $url_parts = REST_API::getRequestURI(); $author_url = $url_parts[0]; $response = new XMLElement('response'); if (isset($author_url)) { if (is_numeric($author_url)) { $author = AuthorManager::fetchByID($author_url); } else { $author = AuthorManager::fetchByUsername($author_url); } if (!$author) { REST_API::sendError('Author not found.', 404); } $response->appendChild(self::__buildAuthorXML($author)); } else { $authors = AuthorManager::fetch(); foreach ($authors as $author) { $response->appendChild(self::__buildAuthorXML($author)); } } REST_API::sendOutput($response); }