public static function get() { $response = new XMLElement('response'); foreach (self::$_sections as $section) { $section_xml = new XMLElement('section'); $meta = $section->get(); foreach ($meta as $key => $value) { $section_xml->setAttribute(Lang::createHandle($key), $value); } $fields = $section->fetchFields(); foreach ($fields as $field) { $meta = $field->get(); unset($meta['field_id']); $field_xml = new XMLElement($meta['element_name'], null); foreach (self::$_field_attributes as $attr) { $field_xml->setAttribute(Lang::createHandle($attr), $meta[$attr]); } foreach ($meta as $key => $value) { if (in_array($key, self::$_field_attributes)) { continue; } $value = General::sanitize($value); if ($value != '') { $field_xml->appendChild(new XMLElement(Lang::createHandle($key), General::sanitize($value))); } } $section_xml->appendChild($field_xml); } $response->appendChild($section_xml); } 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); }
public static function sendOutput($xml) { switch (REST_API::getHTTPMethod()) { case 'get': $xml = $xml->getChildrenByName('response'); if (is_array($xml)) { $xml = reset($xml); } REST_API::sendOutput($xml); break; case 'post': $xml = $xml->getChildrenByName('events'); if (is_array($xml)) { $xml = reset($xml); } $xml = $xml->getChildrenByName('response'); if (is_array($xml)) { $xml = reset($xml); } REST_API::sendOutput($xml); break; } }