Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public static function init()
 {
     if (REST_API::getOutputFormat() == 'csv' && !REST_API::getHTTPMethod() == 'get') {
         REST_API::sendError(sprintf('%s output format not supported for %s requests.', strtoupper(REST_API::getOutputFormat()), strtoupper(REST_API::getHTTPMethod())), 401, 'xml');
     }
     $request_uri = REST_API::getRequestURI();
     self::$_section_handle = $request_uri[0];
     self::$_entry_id = $request_uri[1];
     $section_id = SectionManager::fetchIDFromHandle(self::$_section_handle);
     if (!$section_id) {
         REST_API::sendError('Section not found.', 404);
     }
     self::$_section_id = $section_id;
     self::setDatasourceParam('included_elements', $_REQUEST['fields']);
     self::setDatasourceParam('limit', $_REQUEST['limit']);
     self::setDatasourceParam('page', $_REQUEST['page']);
     self::setDatasourceParam('sort', $_REQUEST['sort']);
     self::setDatasourceParam('order', $_REQUEST['order']);
     self::setDatasourceParam('groupby', $_REQUEST['groupby']);
     $filters = $_REQUEST['filter'];
     if (!is_null($filters) && !is_array($filters)) {
         $filters = array($filters);
     }
     self::setDatasourceParam('filters', $filters);
 }
Esempio n. 3
0
 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);
 }