/** * 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); }