コード例 #1
0
ファイル: EXmlParser.class.php プロジェクト: KDE/ocs-server
 /**
  * Convert an xml tree to an associative array, supporting also duplicate keys
  *
  * @input	$data		give always an empty array
  * @input	&$tags		declarative array generated from xml_parse_into_struct()
  * @returns	$data		associative array
  */
 public static function parse_array($data, &$tags, $force_multiple = array())
 {
     do {
         if (is_array($tags)) {
             $entry = array_shift($tags);
         } else {
             return array();
         }
         if (isset($entry["tag"])) {
             $tag = $entry["tag"];
         }
         if (isset($entry["type"])) {
             $type = $entry["type"];
         }
         if (isset($entry["value"])) {
             $value = $entry["value"];
         } else {
             $value = '';
         }
         //just add value
         if ($type == 'complete') {
             $data[$tag] = $value;
         }
         //open new tag
         if ($type == 'open') {
             if (isset($data[$tag])) {
                 //if array is associative, it means it's not a collection of nodes with the same name
                 if (EXmlParser::is_assoc($data[$tag])) {
                     $prev = $data[$tag];
                     $new = EXmlParser::parse_array(array(), $tags, $force_multiple);
                     $data[$tag] = array();
                     $data[$tag][] = $prev;
                     $data[$tag][] = $new;
                 } else {
                     //it's already a collection
                     $new = EXmlParser::parse_array(array(), $tags, $force_multiple);
                     $data[$tag][] = $new;
                 }
             } else {
                 if (is_array($force_multiple) and in_array($tag, $force_multiple)) {
                     $data[$tag] = array();
                     $data[$tag][] = EXmlParser::parse_array($data[$tag], $tags, $force_multiple);
                 } else {
                     $data[$tag] = array();
                     $data[$tag] = EXmlParser::parse_array($data[$tag], $tags, $force_multiple);
                 }
             }
         }
         //close tags
         if ($type == 'close') {
             return $data;
         }
     } while (count($tags) > 0);
     return $data;
 }
コード例 #2
0
ファイル: OCSClient.class.php プロジェクト: KDE/ocs-server
 /**
  * Send a post request to the server.
  * $data should be provided as an associative array
  * following this example:
  * "name" => "value"
  */
 public function post($url, $data = "")
 {
     $server = $this->generate_server();
     $socket = new ENetworkSocket($server);
     //deprecated. use OCSClient->set_post_data($data) instead
     if (!empty($data)) {
         $socket->set_post_data($data);
     }
     //use this instead
     if ($this->postdata) {
         $socket->set_post_data($this->postdata);
     }
     //eventual uploaded file
     if ($this->uploaded_file) {
         $socket->set_upload_file($this->uploaded_file);
     }
     $raw_data = $socket->post($url);
     //if result is in json format, parse json
     // else parse xml
     if ($this->is_json_encoded($raw_data)) {
         return json_decode($raw_data);
     } else {
         $this->last_raw_result = $raw_data;
         $data = EXmlParser::to_array($raw_data, $this->ocs_data_fields);
         return $data;
     }
 }