Beispiel #1
0
 function xtestFromXmlUnbound()
 {
     $xml = '<payload><title>title</title><body>body</body><mediaURL type="movie" mimeType="video/quicktime">http://www.gnipcentral.com</mediaURL>' . '<mediaURL type="graphic" mimeType="image/png">http://flickr.com/tour</mediaURL>' . '<raw>H4sIAAAAAAAAAytKLAcAVduzGgMAAAA=</raw></payload>';
     $payload = Services_Gnip_Payload::fromXML($xml);
     $this->assertEquals("title", $payload->title);
     $this->assertEquals("body", $payload->body);
     $this->assertContains(array("mediaURL" => "http://www.gnipcentral.com", "type" => "movie", "mimeType" => "video/quicktime"), $payload->mediaURL);
     $this->assertContains(array("mediaURL" => "http://flickr.com/tour", "type" => "graphic", "mimeType" => "image/png"), $payload->mediaURL);
     $this->assertEquals("raw", $payload->decodedRaw());
 }
Beispiel #2
0
 /**
  * Converts XML formatted payload to Services_Gnip_Payload object.
  * 
  * @param string $xml XML data
  * @return object Services_Gnip_Payload
  */
 public static function fromXML($xml)
 {
     $xml_element = new SimpleXMLElement($xml);
     $found_title = strlen(strval($xml_element->title)) ? strval($xml_element->title) : null;
     $found_body = strlen(strval($xml_element->body)) ? strval($xml_element->body) : null;
     $result = $xml_element->xpath('mediaURL');
     $nodes_num = count($result);
     $found_mediaURL = array();
     if (!empty($result)) {
         if ($nodes_num >= 1) {
             foreach ($result as $key => $val) {
                 if (is_object($val)) {
                     $media_stuff['mediaURL'] = strval($val[0]);
                     foreach ($val[0]->attributes() as $attr_name => $attr_val) {
                         if (strlen(strval($attr_val))) {
                             $media_stuff[$attr_name] = strval($attr_val);
                         }
                     }
                     $found_mediaURL[] = $media_stuff;
                 }
             }
         } else {
             $found_mediaURL = null;
         }
     } else {
         $found_mediaURL = null;
     }
     $possibly_encoded = @Services_Gnip_Payload::gzdecode(base64_decode($xml_element->raw));
     if (strlen(mb_detect_encoding($possibly_encoded, "auto", TRUE))) {
         $found_raw = Services_Gnip_Payload::gzdecode(base64_decode($xml_element->raw));
     } else {
         $found_raw = $xml_element->raw;
     }
     return new Services_Gnip_Payload($found_raw, $found_title, $found_body, $found_mediaURL);
 }
Beispiel #3
0
 /**
  * Converts XML formatted activity to Services_Gnip_Activity object.    
  * 
  * @param string $xml XML data
  * @return object Services_Gnip_Activity
  */
 public static function fromXML($xml)
 {
     $xml_element = new SimpleXMLElement($xml);
     $found_at = strval($xml_element->at);
     $found_action = strval($xml_element->action);
     $found_activityID = strval($xml_element->activityID);
     $found_URL = strval($xml_element->URL);
     $found_source = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('source'), 'source');
     $found_keyword = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('keyword'), 'keyword');
     $place_result = $xml_element->xpath('place');
     if (array_key_exists(0, $place_result)) {
         foreach ($place_result as $k => $v) {
             $found_place[] = Services_Gnip_Place::fromXML($v->asXML());
         }
     } else {
         $found_place = null;
     }
     $found_actor = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('actor'), 'actor', array('metaURL', 'uid'));
     $found_destinationURL = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('destinationURL'), 'destinationURL', array('metaURL'));
     $found_tag = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('tag'), 'tag', array('metaURL'));
     $found_to = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('to'), 'to', array('metaURL'));
     $found_regardingURL = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('regardingURL'), 'regardingURL', array('metaURL'));
     $payload_result = $xml_element->xpath('payload');
     if (array_key_exists(0, $payload_result)) {
         foreach ($payload_result as $k => $v) {
             $found_payload = Services_Gnip_Payload::fromXML($v->asXML());
         }
     } else {
         $found_payload = null;
     }
     return new Services_Gnip_Activity(new DateTime($found_at), $found_action, $found_activityID, $found_URL, $found_source, $found_keyword, $found_place, $found_actor, $found_destinationURL, $found_tag, $found_to, $found_regardingURL, $found_payload);
 }