data; return $xmls[$url]; } // Enable user error handling. libxml_use_internal_errors(TRUE); // Load the document $xml = simplexml_load_file($url); if (!$xml) { foreach (libxml_get_errors() as $error) { $params = array('%url' => $url, '%error' => $error->message); // Handle errors here. if ($display_errors) { drupal_set_message(t('Error retrieving XML from %url: %error', $params), 'error'); } watchdog('media', 'Error retrieving XML from %url: %error', $params, WATCHDOG_WARNING); } // Clear our error cache. libxml_clear_errors(); // Set the static cache, but not Drupal's cache, so we can attempt to // retrieve the file another time if possible. $xmls[$url] = FALSE; } else { $xmls[$url] = _media_unserialize_xml($xml); cache_set('media:xml:' . $url, $xmls[$url], 'cache_media_xml', media_variable_get('xml_cache_expire', 3600)); } return $xmls[$url]; } /** * Recursively converts a SimpleXMLElement object into an array. * @param $xml * The original XML object. */ function _media_unserialize_xml($xml) { if ($xml instanceof SimpleXMLElement) { $xml = (array) $xml; } if (is_array($xml)) { foreach ($xml as $key => $item) { $xml[$key] = _media_unserialize_xml($item); } } return $xml; }