| 1 |
<?php // -*-php-*- |
<?php // -*-php-*- |
| 2 |
/* $Id: fa_simplexml.module,v 1.1.2.9 2007/11/23 23:07:16 alaa Exp $ */ |
/* $Id: fa_simplexml.module,v 1.1.2.10 2007/11/24 14:04:38 alaa Exp $ */ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_fooaggregatorapi() |
* Implementation of hook_fooaggregatorapi() |
| 18 |
/** |
/** |
| 19 |
* Refresh a feed |
* Refresh a feed |
| 20 |
* @param $feed a fooaggregator_feed node to refresh |
* @param $feed a fooaggregator_feed node to refresh |
| 21 |
* @return false in case of an error otherwse true |
* @param $xml predownloaded feed content |
| 22 |
|
* @return false in case of an error otherwise true |
| 23 |
*/ |
*/ |
| 24 |
function _fa_simplexml_refresh(&$feed, $xml = null) { |
function _fa_simplexml_refresh(&$feed, $xml = NULL) { |
| 25 |
if ($xml == null && !_fooaggregator_download($feed, $xml)) { |
if ($xml == NULL && !_fooaggregator_download($feed, $xml)) { |
| 26 |
drupal_set_message(t("failed to download feed %title", array('%title' => $feed->title)), 'error'); |
drupal_set_message(t("failed to download feed %title", array('%title' => $feed->title)), 'error'); |
| 27 |
return false; |
return false; |
| 28 |
} |
} |
| 33 |
} |
} |
| 34 |
|
|
| 35 |
//parse |
//parse |
|
$temp = $xml; |
|
| 36 |
if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) { |
if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) { |
| 37 |
@ $parsed_xml = simplexml_load_string($xml, NULL); |
@ $parsed_xml = simplexml_load_string($xml, NULL); |
| 38 |
} |
} |
| 42 |
|
|
| 43 |
// We got a malformed XML |
// We got a malformed XML |
| 44 |
if ($parsed_xml === FALSE || $parsed_xml == NULL) { |
if ($parsed_xml === FALSE || $parsed_xml == NULL) { |
|
$error = libxml_get_last_error(); |
|
| 45 |
|
|
| 46 |
//unicode errors are the most common cause of failed parsing |
//unicode errors are common cause of parse errors unfortuneately can't be detected by checking libxml error |
| 47 |
if (function_exists('iconv')) { |
if (function_exists('iconv')) { |
| 48 |
$xml = iconv("UTF-8", "UTF-8//IGNORE", $xml); |
$xml = iconv("UTF-8", "UTF-8//IGNORE", $xml); |
| 49 |
_fa_simplexml_refresh($feed, $xml); |
//reparse |
| 50 |
$xml = null; |
if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) { |
| 51 |
return true; |
@ $parsed_xml = simplexml_load_string($xml, NULL); |
| 52 |
|
} |
| 53 |
|
else { |
| 54 |
|
@ $parsed_xml = simplexml_load_string($xml, NULL, LIBXML_NOERROR | LIBXML_NOWARNING); |
| 55 |
|
} |
| 56 |
} |
} |
| 57 |
|
$error = libxml_get_last_error(); |
| 58 |
$message = t('Failed to parse %title, %error', array('%title' => $feed->title, '%error' => $error->message)); |
$message = t('Failed to parse %title, %error', array('%title' => $feed->title, '%error' => $error->message)); |
| 59 |
_fooaggregator_log_error($message); |
_fooaggregator_log_error($message); |
| 60 |
$xml = null; |
$xml = null; |
| 64 |
_fa_simplexml_update_feed_info($feed, $parsed_xml); |
_fa_simplexml_update_feed_info($feed, $parsed_xml); |
| 65 |
|
|
| 66 |
_fa_simplexml_update_nodes($feed, $parsed_xml); |
_fa_simplexml_update_nodes($feed, $parsed_xml); |
| 67 |
|
|
| 68 |
_fooaggregator_feed_update($feed); |
_fooaggregator_feed_update($feed); |
| 69 |
|
|
| 70 |
$parsed_xml = NULL; |
$parsed_xml = NULL; |