/**
  * Configure and set the URL to use, along with any request parameters.
  *
  * @param resource $ch The cURL connection resource
  * @see modRestClient::request for parameter documentation.
  */
 public function setUrl($ch,$host,$path,$method = 'GET',array $params = array(),array $options = array()) {
     $q = http_build_query($params);
     switch ($method) {
         case 'GET':
             $path .= '?'.$q;
             break;
         case 'POST':
             curl_setopt($ch,CURLOPT_POST,1);
             $contentType = $this->modx->getOption('contentType',$options,'xml');
             switch ($contentType) {
                 case 'json':
                     $json = $this->modx->toJSON($params);
                     curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
                     curl_setopt($ch,CURLOPT_POSTFIELDS,$json);
                     break;
                 case 'xml':
                     curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
                     $xml = ArrayToXML::toXML($params,!empty($options['rootNode']) ? $options['rootNode'] : 'request');
                     curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
                     break;
                 default:
                     curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
                     break;
             }
             break;
     }
     /* prevent invalid xhtml ampersands in request path */
     $url = str_replace('&', '&', $host.$path);
     return curl_setopt($ch, CURLOPT_URL,$url);
 }
 public function format(array $result, $pretty = false)
 {
     //debug_op($result, true);
     $xml = ArrayToXML::toXML($result, Response::XML_ROOT);
     if ($pretty) {
         $doc = new \DOMDocument('1.0');
         $doc->preserveWhiteSpace = false;
         $doc->loadXML($xml);
         $doc->formatOutput = true;
         return $doc->saveXML();
     } else {
         return $xml;
     }
 }
예제 #3
0
<?php

header('Content-type: text/xml; charset=UTF-8');
require dirname(__FILE__) . '/../lib/functions.php';
$total = intval($_GET['total']);
if ($total <= 0) {
    throw new PubwichAPIError('Missing parameters');
}
$data = array();
$compteur = 0;
while ($compteur < $total) {
    $timestamp = strtotime('+' . $compteur . ' day');
    $data[] = array('year' => date('Y', $timestamp), 'month' => date('m', $timestamp), 'day' => date('d', $timestamp));
    $compteur++;
}
echo ArrayToXML::toXML($data, 'days');
예제 #4
0
 public function __call($name, $arguments)
 {
     $name = strtolower($name);
     $valid_methods = array('balancesheet', 'bankstatement', 'banksummary', 'accounts', 'contacts', 'creditnotes', 'currencies', 'invoices', 'organisation', 'payments', 'taxrates', 'trackingcategories');
     $valid_post_methods = array('contacts', 'creditnotes', 'invoices');
     $valid_put_methods = array('payments');
     $valid_get_methods = array('balancesheet', 'bankstatement', 'banksummary', 'contacts', 'creditnotes', 'invoices', 'accounts', 'currencies', 'organisation', 'taxrates', 'trackingcategories');
     $methods_map = array('accounts' => 'Accounts', 'contacts' => 'Contacts', 'creditnotes' => 'CreditNotes', 'currencies' => 'Currencies', 'invoices' => 'Invoices', 'organisation' => 'Organisation', 'payments' => 'Payments', 'taxrates' => 'TaxRates', 'trackingcategories' => 'TrackingCategories', 'balancesheet' => 'Reports/BalanceSheet', 'bankstatement' => 'Reports/BankStatement', 'banksummary' => 'Reports/BankSummary');
     if (!in_array($name, $valid_methods)) {
         return false;
     }
     if (count($arguments) == 0 || is_string($arguments[0]) || is_numeric($arguments[0]) || $arguments[0] === false) {
         //it's a GET request
         $method = $methods_map[$name];
         $xero_url = self::ENDPOINT . $method;
         if (count($arguments) == 1) {
             $xero_url .= $arguments[0];
         }
         // echo "xero_url = $xero_url\n";
         $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'GET', $xero_url);
         $req->sign_request($this->signature_method, $this->consumer, $this->token);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_URL, $req->to_url());
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $temp_xero_response = curl_exec($ch);
         $xero_xml = simplexml_load_string($temp_xero_response);
         curl_close($ch);
         if (!$xero_xml) {
             return $temp_xero_response;
         }
         if ($this->format == 'xml') {
             return $xero_xml;
         } else {
             return ArrayToXML::toArray($xero_xml);
         }
     } elseif (count($arguments) == 1 || is_array($arguments[0]) || is_a($arguments[0], 'SimpleXMLElement')) {
         //it's a POST or PUT request
         if (!(in_array($name, $valid_post_methods) || in_array($name, $valid_put_methods))) {
             return false;
         }
         $method = $methods_map[$name];
         if (is_a($arguments[0], 'SimpleXMLElement')) {
             $post_body = $arguments[0]->asXML();
         } elseif (is_array($arguments[0])) {
             $post_body = ArrayToXML::toXML($arguments[0], $rootNodeName = $method);
         }
         $post_body = trim(substr($post_body, stripos($post_body, ">") + 1));
         if (in_array($name, $valid_post_methods)) {
             $xero_url = self::ENDPOINT . $method;
             $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $xero_url, array('xml' => $post_body));
             $req->sign_request($this->signature_method, $this->consumer, $this->token);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_URL, $xero_url);
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $req->to_postdata());
             curl_setopt($ch, CURLOPT_HEADER, $req->to_header());
         } else {
             $xero_url = self::ENDPOINT . $method;
             $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'PUT', $xero_url);
             $req->sign_request($this->signature_method, $this->consumer, $this->token);
             $xml = $post_body;
             $fh = fopen('php://memory', 'w+');
             fwrite($fh, $xml);
             rewind($fh);
             $ch = curl_init($req->to_url());
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_PUT, true);
             curl_setopt($ch, CURLOPT_INFILE, $fh);
             curl_setopt($ch, CURLOPT_INFILESIZE, strlen($xml));
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             fclose($fh);
         }
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $xero_response = curl_exec($ch);
         $xero_xml = simplexml_load_string($xero_response);
         if (!$xero_xml) {
             return $xero_response;
         }
         curl_close($ch);
         if (!$xero_xml) {
             return false;
         }
         if ($this->format == 'xml') {
             return $xero_xml;
         } else {
             return ArrayToXML::toArray($xero_xml);
         }
     } else {
         return false;
     }
 }
예제 #5
0
 private function _reroute_request($url, $options = [], $verb = '')
 {
     if (isset($options['xml'])) {
         if (is_array($options['xml']) && !isset($options['body'])) {
             $body = $options['xml'];
             $cutpos = strpos($url, '?');
             $node = $url;
             if ($cutpos !== false) {
                 $node = substr($node, 0, $cutpos);
             }
             $node = trim($node, '/');
             //Override body
             $options['body'] = \ArrayToXML::toXML($body, $node);
         }
         //Always remove the xml key from options.. even if it doesn't work.
         unset($options['xml']);
     }
     return parent::$verb($url, $options);
 }
예제 #6
0
 public function __call($name, $arguments)
 {
     $name = strtolower($name);
     $valid_methods = array('accounts', 'contacts', 'creditnotes', 'currencies', 'invoices', 'organisation', 'payments', 'taxrates', 'trackingcategories', 'items', 'banktransactions', 'brandingthemes');
     $valid_post_methods = array('banktransactions', 'contacts', 'creditnotes', 'expenseclaims', 'invoices', 'items', 'manualjournals', 'receipts');
     $valid_put_methods = array('payments');
     $valid_get_methods = array('accounts', 'banktransactions', 'brandingthemes', 'contacts', 'creditnotes', 'currencies', 'employees', 'expenseclaims', 'invoices', 'items', 'journals', 'manualjournals', 'organisation', 'payments', 'receipts', 'taxrates', 'trackingcategories', 'users');
     $methods_map = array('accounts' => 'Accounts', 'banktransactions' => 'BankTransactions', 'brandingthemes' => 'BrandingThemes', 'contacts' => 'Contacts', 'creditnotes' => 'CreditNotes', 'currencies' => 'Currencies', 'employees' => 'Employees', 'expenseclaims' => 'ExpenseClaims', 'invoices' => 'Invoices', 'items' => 'Items', 'journals' => 'Journals', 'manualjournals' => 'ManualJournals', 'organisation' => 'Organisation', 'payments' => 'Payments', 'receipts' => 'Receipts', 'taxrates' => 'TaxRates', 'trackingcategories' => 'TrackingCategories', 'users' => 'Users');
     if (!in_array($name, $valid_methods)) {
         throw new XeroException('The selected method does not exist. Please use one of the following methods: ' . implode(', ', $methods_map));
     }
     if (count($arguments) == 0 || is_string($arguments[0]) || is_numeric($arguments[0]) || $arguments[0] === false) {
         //it's a GET request
         if (!in_array($name, $valid_get_methods)) {
             return false;
         }
         $filterid = count($arguments) > 0 ? strip_tags(strval($arguments[0])) : false;
         if ($arguments[1] != false) {
             $modified_after = count($arguments) > 1 ? str_replace('X', 'T', date('Y-m-dXH:i:s', strtotime($arguments[1]))) : false;
         }
         if ($arguments[2] != false) {
             $where = count($arguments) > 2 ? $arguments[2] : false;
         }
         if (is_array($where) && count($where) > 0) {
             $temp_where = '';
             foreach ($where as $wf => $wv) {
                 if (is_bool($wv)) {
                     $wv = $wv ? "%3d%3dtrue" : "%3d%3dfalse";
                 } else {
                     if (is_array($wv)) {
                         if (is_bool($wv[1])) {
                             $wv = $wv[1] ? rawurlencode($wv[0]) . "true" : rawurlencode($wv[0]) . "false";
                         } else {
                             $wv = rawurlencode($wv[0]) . "%22{$wv[1]}%22";
                         }
                     } else {
                         $wv = "%3d%3d%22{$wv}%22";
                     }
                 }
                 $temp_where .= "%26%26{$wf}{$wv}";
             }
             $where = strip_tags(substr($temp_where, 6));
         } else {
             $where = strip_tags(strval($where));
         }
         $order = count($arguments) > 3 ? strip_tags(strval($arguments[3])) : false;
         $acceptHeader = !empty($arguments[4]) ? $arguments[4] : '';
         $method = $methods_map[$name];
         $xero_url = self::ENDPOINT . $method;
         if ($filterid) {
             $xero_url .= "/{$filterid}";
         }
         if (isset($where)) {
             $xero_url .= "?where={$where}";
         }
         if ($order) {
             $xero_url .= "&order={$order}";
         }
         $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'GET', $xero_url);
         $req->sign_request($this->signature_method, $this->consumer, $this->token);
         $ch = curl_init();
         if ($acceptHeader == 'pdf') {
             curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/" . $acceptHeader));
         }
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_URL, $req->to_url());
         if (isset($modified_after) && $modified_after != false) {
             curl_setopt($ch, CURLOPT_HTTPHEADER, array("If-Modified-Since: {$modified_after}"));
         }
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $temp_xero_response = curl_exec($ch);
         curl_close($ch);
         if ($acceptHeader == 'pdf') {
             return $temp_xero_response;
         }
         try {
             if (@simplexml_load_string($temp_xero_response) == false) {
                 throw new XeroException($temp_xero_response);
                 $xero_xml = false;
             } else {
                 $xero_xml = simplexml_load_string($temp_xero_response);
             }
         } catch (XeroException $e) {
             return $e->getMessage() . "<br/>";
         }
         if ($this->format == 'xml' && isset($xero_xml)) {
             return $xero_xml;
         } elseif (isset($xero_xml)) {
             return ArrayToXML::toArray($xero_xml);
         }
     } elseif (count($arguments) == 1 || is_array($arguments[0]) || is_a($arguments[0], 'SimpleXMLElement')) {
         //it's a POST or PUT request
         if (!(in_array($name, $valid_post_methods) || in_array($name, $valid_put_methods))) {
             return false;
         }
         $method = $methods_map[$name];
         if (is_a($arguments[0], 'SimpleXMLElement')) {
             $post_body = $arguments[0]->asXML();
         } elseif (is_array($arguments[0])) {
             $post_body = ArrayToXML::toXML($arguments[0], $rootNodeName = $method);
         }
         $post_body = trim(substr($post_body, stripos($post_body, ">") + 1));
         if (in_array($name, $valid_post_methods)) {
             $xero_url = self::ENDPOINT . $method;
             $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $xero_url, array('xml' => $post_body));
             $req->sign_request($this->signature_method, $this->consumer, $this->token);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_URL, $xero_url);
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $req->to_postdata());
             curl_setopt($ch, CURLOPT_HEADER, $req->to_header());
         } else {
             $xero_url = self::ENDPOINT . $method;
             $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'PUT', $xero_url);
             $req->sign_request($this->signature_method, $this->consumer, $this->token);
             $xml = $post_body;
             $fh = fopen('php://memory', 'w+');
             fwrite($fh, $xml);
             rewind($fh);
             $ch = curl_init($req->to_url());
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_PUT, true);
             curl_setopt($ch, CURLOPT_INFILE, $fh);
             curl_setopt($ch, CURLOPT_INFILESIZE, strlen($xml));
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         }
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $xero_response = curl_exec($ch);
         if (isset($fh)) {
             fclose($fh);
         }
         try {
             if (@simplexml_load_string($xero_response) == false) {
                 throw new XeroException($xero_response);
             } else {
                 $xero_xml = simplexml_load_string($xero_response);
             }
         } catch (XeroException $e) {
             //display custom message
             return $e->getMessage() . "<br/>";
         }
         curl_close($ch);
         if (!isset($xero_xml)) {
             return false;
         }
         if ($this->format == 'xml' && isset($xero_xml)) {
             return $xero_xml;
         } elseif (isset($xero_xml)) {
             return ArrayToXML::toArray($xero_xml);
         }
     } else {
         return false;
     }
 }
예제 #7
0
 public function getResult()
 {
     $recipe = (array) $this;
     foreach ($recipe as $key => $value) {
         $newkey = trim(str_replace('*', '', $key));
         $recipe[$newkey] = $value;
         unset($recipe[$key]);
     }
     //needs cleaning up
     $new_variables = array();
     $i = 0;
     //print __LINE__ . '-getResult<pre>'.htmlentities(var_export($recipe['variables'], true)).'</pre>';
     $recipe['variable'] = $recipe['variables'];
     unset($recipe['variables']);
     foreach ($recipe['variable'] as $variable) {
         $new_variables = array_merge($new_variables, $variable->renderArray());
     }
     $recipe['variable'] = $new_variables;
     unset($recipe['curlKeepAlive']);
     unset($recipe['ingredients']);
     unset($recipe['requires']);
     $recipe['updated'] = date('c');
     return ArrayToXML::toXML($recipe);
 }
예제 #8
0
 function __construct($msg)
 {
     $error = array('message' => $msg);
     echo ArrayToXML::toXML($error, 'error');
     die;
 }
예제 #9
0
파일: xero.php 프로젝트: addmers/PHP-Xero
 public function __call($name, $arguments)
 {
     $name = strtolower($name);
     $valid_methods = array('accounts', 'contacts', 'creditnotes', 'currencies', 'invoices', 'organisation', 'payments', 'taxrates', 'trackingcategories');
     $valid_post_methods = array('contacts', 'creditnotes', 'invoices');
     $valid_put_methods = array('payments');
     $valid_get_methods = array('contacts', 'creditnotes', 'invoices', 'accounts', 'currencies', 'organisation', 'taxrates', 'trackingcategories');
     $methods_map = array('accounts' => 'Accounts', 'contacts' => 'Contacts', 'creditnotes' => 'CreditNotes', 'currencies' => 'Currencies', 'invoices' => 'Invoices', 'organisation' => 'Organisation', 'payments' => 'Payments', 'taxrates' => 'TaxRates', 'trackingcategories' => 'TrackingCategories');
     if (!in_array($name, $valid_methods)) {
         return false;
     }
     if (count($arguments) == 0 || is_string($arguments[0]) || is_numeric($arguments[0]) || $arguments[0] === false) {
         //it's a GET request
         if (!in_array($name, $valid_get_methods)) {
             return false;
         }
         $filterid = count($arguments) > 0 ? strip_tags(strval($arguments[0])) : false;
         $modified_after = count($arguments) > 1 ? str_replace('X', 'T', date('Y-m-dXH:i:s', strtotime($arguments[1]))) : false;
         $where = count($arguments) > 2 ? $arguments[2] : false;
         if (is_array($where) && count($where) > 0) {
             $temp_where = '';
             foreach ($where as $wf => $wv) {
                 if (is_bool($wv)) {
                     $wv = $wv ? "%3d%3dtrue" : "%3d%3dfalse";
                 } else {
                     if (is_array($wv)) {
                         if (is_bool($wv[1])) {
                             $wv = $wv[1] ? rawurlencode($wv[0]) . "true" : rawurlencode($wv[0]) . "false";
                         } else {
                             $wv = rawurlencode($wv[0]) . "%22{$wv[1]}%22";
                         }
                     } else {
                         $wv = "%3d%3d%22{$wv}%22";
                     }
                 }
                 $temp_where .= "%26%26{$wf}{$wv}";
             }
             $where = strip_tags(substr($temp_where, 6));
         } else {
             $where = strip_tags(strval($where));
         }
         $order = count($arguments) > 3 ? strip_tags(strval($arguments[3])) : false;
         $method = $methods_map[$name];
         $xero_url = self::ENDPOINT . $method;
         if ($filterid) {
             $xero_url .= "/{$filterid}";
         }
         if ($where) {
             $xero_url .= "?where={$where}";
         }
         if ($order) {
             $xero_url .= "&order={$order}";
         }
         $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'GET', $xero_url);
         $req->sign_request($this->signature_method, $this->consumer, $this->token);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_URL, $req->to_url());
         if ($modified_after) {
             curl_setopt($ch, CURLOPT_HEADER, "If-Modified-Since: {$modified_after}");
         }
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $temp_xero_response = curl_exec($ch);
         $xero_xml = simplexml_load_string($temp_xero_response);
         curl_close($ch);
         if (!$xero_xml) {
             return $temp_xero_response;
         }
         if ($this->format == 'xml') {
             return $xero_xml;
         } else {
             return ArrayToXML::toArray($xero_xml);
         }
     } elseif (count($arguments) == 1 || is_array($arguments[0]) || is_a($arguments[0], 'SimpleXMLElement')) {
         //it's a POST or PUT request
         if (!(in_array($name, $valid_post_methods) || in_array($name, $valid_put_methods))) {
             return false;
         }
         $method = $methods_map[$name];
         if (is_a($arguments[0], 'SimpleXMLElement')) {
             $post_body = $arguments[0]->asXML();
         } elseif (is_array($arguments[0])) {
             $post_body = ArrayToXML::toXML($arguments[0], $rootNodeName = $method);
         }
         $post_body = trim(substr($post_body, stripos($post_body, ">") + 1));
         if (in_array($name, $valid_post_methods)) {
             $xero_url = self::ENDPOINT . $method;
             $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $xero_url, array('xml' => $post_body));
             $req->sign_request($this->signature_method, $this->consumer, $this->token);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_URL, $xero_url);
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $req->to_postdata());
             curl_setopt($ch, CURLOPT_HEADER, $req->to_header());
         } else {
             $xero_url = self::ENDPOINT . $method;
             $req = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'PUT', $xero_url);
             $req->sign_request($this->signature_method, $this->consumer, $this->token);
             $xml = $post_body;
             $fh = fopen('php://memory', 'w+');
             fwrite($fh, $xml);
             rewind($fh);
             $ch = curl_init($req->to_url());
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_PUT, true);
             curl_setopt($ch, CURLOPT_INFILE, $fh);
             curl_setopt($ch, CURLOPT_INFILESIZE, strlen($xml));
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             fclose($fh);
         }
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $xero_response = curl_exec($ch);
         $xero_xml = simplexml_load_string($xero_response);
         if (!$xero_xml) {
             return $xero_response;
         }
         curl_close($ch);
         if (!$xero_xml) {
             return false;
         }
         if ($this->format == 'xml') {
             return $xero_xml;
         } else {
             return ArrayToXML::toArray($xero_xml);
         }
     } else {
         return false;
     }
 }
예제 #10
0
<?php

header('Content-type: text/xml; charset=UTF-8');
require dirname(__FILE__) . '/../lib/functions.php';
$min = intval($_GET['min']);
$max = intval($_GET['max']);
if (!$min || !$max) {
    throw new PubwichAPIError('Missing parameters');
}
$data = array();
$data[] = rand($min, $max);
echo ArrayToXML::toXML($data, 'number');