123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- class OpenMeetingsRestService
- {
- function call($request, $returnAttribute = "return")
- {
-
-
-
-
-
-
-
-
-
-
-
- $session = curl_init ( $request );
-
-
-
- curl_setopt ( $session, CURLOPT_HEADER, true );
-
-
- curl_setopt ( $session, CURLOPT_RETURNTRANSFER, true );
-
-
- $response = curl_exec ( $session );
-
-
- curl_close ( $session );
-
-
- if (! $response) {
- die ( "Request OpenMeetings! OpenMeetings Service failed and no response was returned in ".__CLASS__.'::'.__FUNCTION__.'()' );
- }
-
-
- $status_code = array ();
-
-
- preg_match ( '/\d\d\d/', $response, $status_code );
- $bt = debug_backtrace();
- $caller = array_shift($bt);
- $extra = ' (from '.$caller['file'].' at line '.$caller['line'].') ';
-
- switch ($status_code [0]) {
- case 200 :
-
- break;
- case 503 :
- error_log( 'Your call to OpenMeetings Web Services '.$extra.' failed and returned an HTTP status of 503.
- That means: Service unavailable. An internal problem prevented us from returning data to you.' );
- return false;
- break;
- case 403 :
- error_log( 'Your call to OpenMeetings Web Services '.$extra.' failed and returned an HTTP status of 403.
- That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.' );
- return false;
- break;
- case 400 :
-
- error_log( 'Your call to OpenMeetings Web Services '.$extra.' failed and returned an HTTP status of 400.
- That means: Bad request. The parameters passed to the service did not match as expected.
- The exact error is returned in the XML response.' );
- return false;
- break;
- default :
- error_log( 'Your call to OpenMeetings Web Services '.$extra.' returned an unexpected HTTP status of: ' . $status_code [0] . " Request " . $request );
- return false;
- }
-
-
- if (!($xml = strstr($response, '<ns'))) {
- $xml = null;
- }
-
- $dom = new DOMDocument();
- $dom->loadXML($xml);
-
- if ($returnAttribute == "") {
-
- return $this->getArray($dom);
- } else {
- $returnNodeList = $dom->getElementsByTagName($returnAttribute);
- $ret = array();
- foreach ($returnNodeList as $returnNode) {
- if ($returnNodeList->length == 1) {
- return $this->getArray($returnNode);
- } else {
- $ret[] = $this->getArray($returnNode);
- }
- }
- return $ret;
- }
-
- }
- function getArray($node)
- {
- if (is_null($node) || !is_object($node)) {
- return $node;
- }
- $array = false;
-
- if ($node->hasChildNodes()) {
- foreach ($node->childNodes as $childNode) {
- if ($childNode->nodeType != XML_TEXT_NODE) {
- if ($node->hasAttributes()) {
- foreach ($node->attributes as $attr) {
- if ($attr->localName == "nil") {
- return null;
- }
- }
- }
- if ($childNode->childNodes->length == 1) {
- $array[$childNode->localName] = $this->getArray($childNode);
- } else {
- $array[$childNode->localName][] = $this->getArray($childNode);
- }
- } else {
- return $childNode->nodeValue;
-
-
- }
- }
- }
- return $array;
- }
- function getError()
- {
- return false;
- }
- function fault()
- {
- return false;
- }
- }
|