コード例 #1
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);
 }
コード例 #2
0
 public function load()
 {
     if (is_array($_POST['fields'][0])) {
         $this->eParamFILTERS = array('expect-multiple');
     } elseif (!is_null(REST_Entries::getEntryId())) {
         $_POST['id'] = REST_Entries::getEntryId();
     }
     return $this->__trigger();
 }
コード例 #3
0
 public function grab(array &$param_pool = NULL)
 {
     // remove placeholder elements
     unset($this->dsParamINCLUDEDELEMENTS);
     // fill with all included elements if none are set
     if (is_null(REST_Entries::getDatasourceParam('included_elements'))) {
         // get all fields in this section
         $fields = FieldManager::fetchFieldsSchema(REST_Entries::getSectionId());
         // add them to the data source
         foreach ($fields as $field) {
             $this->dsParamINCLUDEDELEMENTS[] = $field['element_name'];
         }
         // also add pagination
         $this->dsParamINCLUDEDELEMENTS[] = 'system:pagination';
     } else {
         $this->dsParamINCLUDEDELEMENTS = explode(',', REST_Entries::getDatasourceParam('included_elements'));
     }
     // fill the other parameters
     if (!is_null(REST_Entries::getDatasourceParam('limit'))) {
         $this->dsParamLIMIT = REST_Entries::getDatasourceParam('limit');
     }
     if (!is_null(REST_Entries::getDatasourceParam('page'))) {
         $this->dsParamSTARTPAGE = REST_Entries::getDatasourceParam('page');
     }
     if (!is_null(REST_Entries::getDatasourceParam('sort'))) {
         $this->dsParamSORT = REST_Entries::getDatasourceParam('sort');
     }
     if (!is_null(REST_Entries::getDatasourceParam('order'))) {
         $this->dsParamORDER = REST_Entries::getDatasourceParam('order');
     }
     // Do grouping
     if (!is_null(REST_Entries::getDatasourceParam('groupby'))) {
         $field_id = FieldManager::fetchFieldIDFromElementName(REST_Entries::getDatasourceParam('groupby'), REST_Entries::getSectionId());
         if ($field_id) {
             $this->dsParamGROUP = $field_id;
         }
     }
     // if API is calling a known entry, filter on System ID only
     if (!is_null(REST_Entries::getEntryId())) {
         $this->dsParamFILTERS['id'] = REST_Entries::getEntryId();
     } elseif (REST_Entries::getDatasourceParam('filters')) {
         foreach (REST_Entries::getDatasourceParam('filters') as $field_handle => $filter_value) {
             $filter_value = rawurldecode($filter_value);
             $field_id = FieldManager::fetchFieldIDFromElementName($field_handle, REST_Entries::getSectionId());
             if (is_numeric($field_id)) {
                 $this->dsParamFILTERS[$field_id] = $filter_value;
             }
         }
     }
     return $this->execute($param_pool);
 }
コード例 #4
0
 public function frontendOutputPreGenerate($context)
 {
     if (class_exists('REST_API') && class_exists('REST_Entries') && REST_API::isFrontendPageRequest()) {
         REST_Entries::sendOutput($context['xml']);
     }
 }