示例#1
0
 protected function printXml()
 {
     header("Content-Type:text/xml; charset=utf-8");
     $xml = new array2xml('response');
     $xml->createNode($this->response);
     echo $xml;
 }
示例#2
0
 public function queryMenuTree($resource, $request, $response)
 {
     $DOName = $this->getDOName($resource);
     if (empty($DOName)) {
         $response->status(404);
         $response->body("Resource '{$resource}' is not found.");
         return;
     }
     // get page and sort parameters
     $allGetVars = $request->get();
     $queryParams = array();
     foreach ($allGetVars as $key => $value) {
         if ($key == 'depth' || $key == 'format') {
             continue;
         }
         //if ($value !== null && $value !== '') {
         $queryParams[$key] = $value;
         //}
     }
     $depth = $request->params('depth');
     if (!$depth) {
         $depth = 1;
     }
     $dataObj = BizSystem::getObject($DOName);
     $tree = $dataObj->fetchTreeByQueryParams($queryParams, $depth);
     /*
     // include app tab - PId's sibling nodes
     $PId = $request->params('PId');
     // first find the menu record with Id=PId and get its app_root_menu_PId
     $appRootMenuRec = $dataObj->fetchById($PId);
     $appRootMenuRecPId = $appRootMenuRec['PId'];
     // then find menu records whose PId=app_root_menu_PId
     $appTab = $dataObj->fetchTreeBySearchRule("[PId]='$appRootMenuRecPId' AND [published]=1", 1);
     
     $comboMenus = array('tree'=>$tree,'tab'=>$appTab);
     */
     $format = strtolower($request->params('format'));
     $response->status(200);
     if ($format == 'json') {
         $response['Content-Type'] = 'application/json';
         $response->body(json_encode($tree));
     } else {
         $response['Content-Type'] = "text/xml; charset=utf-8";
         $xml = new array2xml('Data');
         $xml->createNode($tree);
         $response->body($xml);
     }
     return;
 }
示例#3
0
 /**
  * Convert an Array to XML
  * @param string $node_name - name of the root node to be converted
  * @param array $arr - aray to be converterd
  * @return DomDocument
  */
 public static function &createXML($node_name, $arr = array())
 {
     $xml = self::getXMLRoot();
     $xml->appendChild(self::convert($node_name, $arr));
     self::$xml = null;
     // clear the xml node in the class for 2nd time use.
     return $xml;
 }
示例#4
0
 private function response_xml($array)
 {
     require_once 'array2xml.php';
     try {
         //            header("Content-type: text/xml");
         $xml = new array2xml('my_node');
         $xml->createNode($array);
         return $xml;
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
     } catch (Exception $e) {
         echo $e->getMessage();
     } catch (SoapFault $soapfault) {
         echo $soapfault->getMessage();
     }
 } else {
     if ($action == 'isValidMentorUser') {
         header('Content-Type: text/xml');
         if (isset($_POST['username'])) {
             $username = $_POST['username'];
         } else {
             $action = "";
         }
         try {
             $result = isValidMentorUser($username);
             $xml = new array2xml('results');
             $xml->createNode($result);
             echo $xml;
         } catch (Exception $e) {
             echo $e->getMessage();
         } catch (SoapFault $soapfault) {
             echo $soapfault->getMessage();
         }
     } else {
         if ($action == 'emailUserAppointmentInfo') {
             header('Content-Type: text/x-json');
             $success = false;
             if (isset($_POST['username'])) {
                 $emailtype = $_POST['emailtype'];
                 $resource = $_POST['resource'];
                 $course = $_POST['course'];
示例#6
0
 public function post($resource, $request, $response)
 {
     $DOName = $this->getDOName($resource);
     if (empty($DOName)) {
         $response->status(404);
         $response->body("Resource '{$resource}' is not found.");
         return;
     }
     $dataObj = Openbiz::getObject($DOName);
     $dataRec = new DataRecord(null, $dataObj);
     $inputRecord = json_decode($request->getBody());
     foreach ($inputRecord as $k => $v) {
         $dataRec[$k] = $v;
         // or $dataRec->$k = $v;
     }
     try {
         $dataRec->save();
     } catch (Openbiz\Validation\Exception $e) {
         $response->status(400);
         $errmsg = implode("\n", $e->errors);
         $response->body($errmsg);
         return;
     } catch (Openbiz\data\Exception $e) {
         $response->status(400);
         $response->body($e->getMessage());
         return;
     }
     $format = strtolower($request->params('format'));
     $response->status(200);
     if ($format == 'json') {
         $response['Content-Type'] = 'application/json';
         $response->body(json_encode($dataRec->toArray()));
     } else {
         $response['Content-Type'] = "text/xml; charset=utf-8";
         $xml = new array2xml('Data');
         $xml->createNode($dataRec->toArray());
         $response->body($xml);
     }
     return;
 }
示例#7
0
    //if (! is_numeric($arr['maxadd']) ) $arr['maxadd'] = null;
}
if (count($arr) > 0) {
    $response = makeArray($arr);
}
if (!is_array($response)) {
    $response = array('head' => array('status' => '0', 'error_number' => '404', 'error_message' => 'No data found - Please check the format of your data request. '), 'body' => array());
}
if ($format == '') {
    $format = 'json';
}
//will return JSON if format not specified
switch ($format) {
    case 'xml':
        header("content-type: text/xml");
        $xml = new array2xml('root');
        $xml->createNode($response);
        echo $xml;
        break;
    case 'json':
        // Setting up JSON headers
        header("content-type: text/json charset=utf-8");
        //Printing the JSON Object
        echo json_encode($response);
        break;
    case 'php':
        // Setting up PHP headers
        header("content-type: text/php charset=utf-8");
        // Printing the PHP serialized Object
        echo serialize($response);
    case 'html':
示例#8
0
<?php

include 'array2xml.php';
$array = array('some' => 'info', 'more' => 'info2');
$obj = new array2xml($array);
//$array is now stored in this class... but you can access method from $obj
echo $obj->generateXML($array);
//this way you are passing array
echo $obj->generateXMLInternally();
//using array which you init in array2xml object.
<?php

require_once '../thinkedit.init.php';
require_once ROOT . '/class/array2xml.class.php';
$array2xml = new array2xml();
$config = $thinkedit->config;
echo '<h1>Config xml</h1>';
echo '<code>';
echo '<pre>';
print_r($array2xml->convert($config));
echo '</pre>';
echo '<hr>';
echo '<h1>Config array</h1>';
echo '<pre>';
print_r($config);
echo '</pre>';
示例#10
0
function getID3($params)
{
    global $fileDir;
    // Initialize getID3 engine
    $getid3 = new getID3();
    $array2xml = new array2xml();
    // Tell getID3() to use UTF-8 encoding - must send proper header as well.
    $getid3->encoding = 'UTF-8';
    // Tell browser telling it use UTF-8 encoding as well.
    header("Content-type: text/xml");
    // Analyze file
    if (isset($params['file'])) {
        $file = $fileDir . $params["file"];
        try {
            $info = $getid3->Analyze($file);
            $array2xml->formatarray2xml($info);
            echo $array2xml->output;
        } catch (Exception $e) {
            die('An error occured: ' . $e->message);
        }
    } else {
        die("invalid file");
    }
}
示例#11
0
 protected function setErrorResponse($errorCode, $errors, $response, $format)
 {
     $response->status($errorCode);
     //$message = "Successfully deleted record of $resource $id";
     if ($format == 'json') {
         $response['Content-Type'] = 'application/json';
         $response->body(json_encode($errors));
     } else {
         if ($format == 'xml') {
             $response['Content-Type'] = "text/xml; charset=utf-8";
             $xml = new array2xml('Results');
             $xml->createNode($errors);
             $response->body($xml);
         } else {
             $response['Content-Type'] = 'application/text';
             $errmsg = implode("\n", $errors);
             $response->body($errmsg);
         }
     }
 }