aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-08-03 21:03:11 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-08-03 21:03:11 +0200
commit649cc2fa898968b78e249d594e846c84c3695d8d (patch)
tree69d42f0eabaf11ce18ad14acd223553c424c93db /lib/private
parentcd1bfd7eb67e95d5fcd3336b8a4d4109459f27d4 (diff)
downloadnextcloud-server-649cc2fa898968b78e249d594e846c84c3695d8d.tar.gz
nextcloud-server-649cc2fa898968b78e249d594e846c84c3695d8d.zip
Remove duplicate and unused code
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/api.php50
-rw-r--r--lib/private/ocs.php126
2 files changed, 30 insertions, 146 deletions
diff --git a/lib/private/api.php b/lib/private/api.php
index 125c547aebf..6f44401576b 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -357,24 +357,9 @@ class OC_API {
}
}
- $response = array(
- 'ocs' => array(
- 'meta' => $result->getMeta(),
- 'data' => $result->getData(),
- ),
- );
- if ($format == 'json') {
- OC_JSON::encodedPrint($response);
- } else if ($format == 'xml') {
- header('Content-type: text/xml; charset=UTF-8');
- $writer = new XMLWriter();
- $writer->openMemory();
- $writer->setIndent( true );
- $writer->startDocument();
- self::toXML($response, $writer);
- $writer->endDocument();
- echo $writer->outputMemory(true);
- }
+ self::setContentType($format);
+ $body = self::renderResult($result, $format);
+ echo $body;
}
/**
@@ -411,8 +396,8 @@ class OC_API {
/**
* Based on the requested format the response content type is set
*/
- public static function setContentType() {
- $format = self::requestedFormat();
+ public static function setContentType($format = null) {
+ $format = is_null($format) ? self::requestedFormat() : $format;
if ($format === 'xml') {
header('Content-type: text/xml; charset=UTF-8');
return;
@@ -464,4 +449,29 @@ class OC_API {
}
return null;
}
+
+ /**
+ * @param OC_OCS_Result $result
+ * @param string $format
+ * @return string
+ */
+ public static function renderResult($result, $format) {
+ $response = array(
+ 'ocs' => array(
+ 'meta' => $result->getMeta(),
+ 'data' => $result->getData(),
+ ),
+ );
+ if ($format == 'json') {
+ return OC_JSON::encode($response);
+ }
+
+ $writer = new XMLWriter();
+ $writer->openMemory();
+ $writer->setIndent(true);
+ $writer->startDocument();
+ self::toXML($response, $writer);
+ $writer->endDocument();
+ return $writer->outputMemory(true);
+ }
}
diff --git a/lib/private/ocs.php b/lib/private/ocs.php
index 1b5ec2f35ac..bb1aabf8f18 100644
--- a/lib/private/ocs.php
+++ b/lib/private/ocs.php
@@ -99,130 +99,4 @@ class OC_OCS {
if(isset($_POST)) foreach($_POST as $key=>$value) $txt.='post parameter: '.$key.'->'.$value."\n";
return($txt);
}
-
-
- /**
- * generates the xml or json response for the API call from an multidimenional data array.
- * @param string $format
- * @param string $status
- * @param string $statuscode
- * @param string $message
- * @param array $data
- * @param string $tag
- * @param string $tagattribute
- * @param int $dimension
- * @param int|string $itemscount
- * @param int|string $itemsperpage
- * @return string xml/json
- */
- public static function generateXml($format, $status, $statuscode,
- $message, $data=array(), $tag='', $tagattribute='', $dimension=-1, $itemscount='', $itemsperpage='') {
- if($format=='json') {
- $json=array();
- $json['status']=$status;
- $json['statuscode']=$statuscode;
- $json['message']=$message;
- $json['totalitems']=$itemscount;
- $json['itemsperpage']=$itemsperpage;
- $json['data']=$data;
- return(json_encode($json));
- }else{
- $txt='';
- $writer = xmlwriter_open_memory();
- xmlwriter_set_indent( $writer, 2 );
- xmlwriter_start_document($writer );
- xmlwriter_start_element($writer, 'ocs');
- xmlwriter_start_element($writer, 'meta');
- xmlwriter_write_element($writer, 'status', $status);
- xmlwriter_write_element($writer, 'statuscode', $statuscode);
- xmlwriter_write_element($writer, 'message', $message);
- if($itemscount<>'') xmlwriter_write_element($writer, 'totalitems', $itemscount);
- if(!empty($itemsperpage)) xmlwriter_write_element($writer, 'itemsperpage', $itemsperpage);
- xmlwriter_end_element($writer);
- if($dimension=='0') {
- // 0 dimensions
- xmlwriter_write_element($writer, 'data', $data);
-
- }elseif($dimension=='1') {
- xmlwriter_start_element($writer, 'data');
- foreach($data as $key=>$entry) {
- xmlwriter_write_element($writer, $key, $entry);
- }
- xmlwriter_end_element($writer);
-
- }elseif($dimension=='2') {
- xmlwriter_start_element($writer, 'data');
- foreach($data as $entry) {
- xmlwriter_start_element($writer, $tag);
- if(!empty($tagattribute)) {
- xmlwriter_write_attribute($writer, 'details', $tagattribute);
- }
- foreach($entry as $key=>$value) {
- if(is_array($value)) {
- foreach($value as $k=>$v) {
- xmlwriter_write_element($writer, $k, $v);
- }
- } else {
- xmlwriter_write_element($writer, $key, $value);
- }
- }
- xmlwriter_end_element($writer);
- }
- xmlwriter_end_element($writer);
-
- }elseif($dimension=='3') {
- xmlwriter_start_element($writer, 'data');
- foreach($data as $entrykey=>$entry) {
- xmlwriter_start_element($writer, $tag);
- if(!empty($tagattribute)) {
- xmlwriter_write_attribute($writer, 'details', $tagattribute);
- }
- foreach($entry as $key=>$value) {
- if(is_array($value)) {
- xmlwriter_start_element($writer, $entrykey);
- foreach($value as $k=>$v) {
- xmlwriter_write_element($writer, $k, $v);
- }
- xmlwriter_end_element($writer);
- } else {
- xmlwriter_write_element($writer, $key, $value);
- }
- }
- xmlwriter_end_element($writer);
- }
- xmlwriter_end_element($writer);
- }elseif($dimension=='dynamic') {
- xmlwriter_start_element($writer, 'data');
- OC_OCS::toxml($writer, $data, 'comment');
- xmlwriter_end_element($writer);
- }
-
- xmlwriter_end_element($writer);
-
- xmlwriter_end_document( $writer );
- $txt.=xmlwriter_output_memory( $writer );
- unset($writer);
- return($txt);
- }
- }
-
- /**
- * @param resource $writer
- * @param array $data
- * @param string $node
- */
- public static function toXml($writer, $data, $node) {
- foreach($data as $key => $value) {
- if (is_numeric($key)) {
- $key = $node;
- }
- if (is_array($value)) {
- xmlwriter_start_element($writer, $key);
- OC_OCS::toxml($writer, $value, $node);
- xmlwriter_end_element($writer);
- }else{
- xmlwriter_write_element($writer, $key, $value);
- }
- }
- }
}