summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/controllers/album.php6
-rw-r--r--core/controllers/item.php6
-rw-r--r--core/controllers/photo.php6
-rw-r--r--core/controllers/rest.php13
-rw-r--r--core/helpers/xml.php35
5 files changed, 51 insertions, 15 deletions
diff --git a/core/controllers/album.php b/core/controllers/album.php
index 1701e283..a5853fa7 100644
--- a/core/controllers/album.php
+++ b/core/controllers/album.php
@@ -23,13 +23,13 @@ class Album_Controller extends Item_Controller {
* @see Rest_Controller::_form($resource)
*/
public function _form($comment) {
- throw new Exception("@todo Comment_Controller::_get NOT IMPLEMENTED");
+ throw new Exception("@todo Album_Controller::_form NOT IMPLEMENTED");
}
/**
- * @see Rest_Controller::_get($resource)
+ * @see Rest_Controller::_get($resource, $output_format)
*/
- public function _get($item) {
+ public function _get($item, $output_format) {
// @todo: these need to be pulled from the database
$theme_name = "default";
$page_size = 9;
diff --git a/core/controllers/item.php b/core/controllers/item.php
index 053acc92..70af9d95 100644
--- a/core/controllers/item.php
+++ b/core/controllers/item.php
@@ -23,11 +23,11 @@ class Item_Controller extends REST_Controller {
/**
* @see Rest_Controller::_form($resource)
*/
- public function _form($comment) {
- throw new Exception("@todo Comment_Controller::_get NOT IMPLEMENTED");
+ public function _form($item) {
+ throw new Exception("@todo Comment_Controller::_form NOT IMPLEMENTED");
}
- public function _get($item) {
+ public function _get($item, $format) {
// Redirect to the more specific resource type, since it will render
// differently. We could also just delegate here, but it feels more appropriate
// to have a single canonical resource mapping.
diff --git a/core/controllers/photo.php b/core/controllers/photo.php
index 2a0153a2..819af133 100644
--- a/core/controllers/photo.php
+++ b/core/controllers/photo.php
@@ -23,13 +23,13 @@ class Photo_Controller extends Item_Controller {
* @see Rest_Controller::_form($resource)
*/
public function _form($comment) {
- throw new Exception("@todo Comment_Controller::_get NOT IMPLEMENTED");
+ throw new Exception("@todo Comment_Controller::_form NOT IMPLEMENTED");
}
/**
- * @see Rest_Controller::_get($resource)
+ * @see Rest_Controller::_get($resource, $output_format)
*/
- public function _get($item) {
+ public function _get($item, $output_format) {
$template = new View("page.html");
// @todo: this needs to be data-driven
diff --git a/core/controllers/rest.php b/core/controllers/rest.php
index 82262f3b..3b630f2d 100644
--- a/core/controllers/rest.php
+++ b/core/controllers/rest.php
@@ -24,19 +24,19 @@
* class Comment_Controller extends REST_Controller {
* protected $resource_type = "comment"; // this tells REST which model to use
*
- * public function _get(ORM $comment) {
+ * public function _get(ORM $comment, $output_format) {
* // Handle GET request
* }
*
- * public function _put(ORM $comment) {
+ * public function _put(ORM $comment, $output_format) {
* // Handle PUT request
* }
*
- * public function _post(ORM $comment) {
+ * public function _post(ORM $comment, $output_format) {
* // Handle POST request
* }
*
- * public function _delete(ORM $comment) {
+ * public function _delete(ORM $comment, $output_format) {
* // Handle DELETE request
* }
*
@@ -67,8 +67,9 @@ abstract class REST_Controller extends Controller {
* We're expecting to run in an environment that only supports GET/POST, so expect to tunnel
* PUT/DELETE through POST.
*/
+ $output_format = $this->input->get("_format", $this->input->post("_format", "html"));
if (request::method() == "get") {
- $this->_get($resource);
+ $this->_get($resource, $output_format);
if (Session::instance()->get("use_profiler", false)) {
$profiler = new Profiler();
@@ -107,7 +108,7 @@ abstract class REST_Controller extends Controller {
* Perform a GET request on this resource
* @param ORM $resource the instance of this resource type
*/
- abstract public function _get($resource);
+ abstract public function _get($resource, $output_format);
/**
* Perform a PUT request on this resource
diff --git a/core/helpers/xml.php b/core/helpers/xml.php
new file mode 100644
index 00000000..2700b5ae
--- /dev/null
+++ b/core/helpers/xml.php
@@ -0,0 +1,35 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Xml_Core {
+ public static function to_xml($array, $element_names) {
+ $xml = "<$element_names[0]>\n";
+ foreach ($array as $key => $value) {
+ if (is_array($value)) {
+ $xml .= xml::to_xml($value, array_slice($element_names, 1));
+ } else if (is_object($value)) {
+ $xml .= xml::to_xml($value->as_array(), array_slice($element_names, 1));
+ } else {
+ $xml .= "<$key>$value</$key>\n";
+ }
+ }
+ $xml .= "</$element_names[0]>\n";
+ return $xml;
+ }
+}