Permalink
Browse files

modify loadUrl

  • Loading branch information...
tontof committed May 2, 2013
1 parent 091eb48 commit 808e240e8471a667018df45d1a29452a6b241af4
Showing with 29 additions and 1 deletion.
  1. +29 −1 src/class/Feed.php
View
@@ -1134,11 +1134,19 @@ public function loadUrl($url, $opts = array()){
*/
public function curl_exec_follow(&$ch, $redirects = 20, $curloptHeader = false) {
if ((!ini_get('open_basedir') && !ini_get('safe_mode')) || $redirects < 1) {
- curl_setopt($ch, CURLOPT_HEADER, $curloptHeader);
+ curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $redirects > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $redirects);
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, readHeader));
$data = curl_exec($ch);
+
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $header = substr($data, 0, $header_size);
+
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+ $data = substr($data, strpos($data, "\r\n\r\n")+4);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, true);
@@ -1173,6 +1181,9 @@ public function curl_exec_follow(&$ch, $redirects = 20, $curloptHeader = false)
return array(
'data' => $data,
+ 'header' => $header,
+ 'code' => $code,
+ 'error' => curl_error(),
'isnew' => $code != 304, // really new (2XX) and errors (4XX and 5XX) are considered new
'etag' => $this->_headers['etag'],
'last-modified' => $this->_headers['last-modified']
@@ -1230,6 +1241,7 @@ public function loadXml($xmlUrl, &$etag, &$lastModified)
$etag = $output['etag'];
$lastModified = $output['last-modified'];
}
+
$document->loadXML($output['data']);
} else {
// try using libxml
@@ -1257,6 +1269,13 @@ public function addChannel($xmlUrl)
$feedHash = MyTool::smallHash($xmlUrl);
if (!isset($this->_data['feeds'][$feedHash])) {
$xml = $this->loadXml($xmlUrl, $this->_data['feeds'][$feedHash]['etag'], $this->_data['feeds'][$feedHash]['lastModified']);
+ if (empty($this->_data['feeds'][$feedHash]['etag'])) {
+ unset($this->_data['feeds'][$feedHash]['etag']);
+ }
+
+ if (empty($this->_data['feeds'][$feedHash]['lastModified'])) {
+ unset($this->_data['feeds'][$feedHash]['lastModified']);
+ }
if (!$xml) {
return false;
@@ -1291,6 +1310,8 @@ public function addChannel($xmlUrl)
$channel['nbAll'] = count($items);
$channel['timeUpdate'] = 'auto';
$channel['lastUpdate'] = time();
+ $channel['etag'] = $this->_data['feeds'][$feedHash]['etag'];
+ $channel['lastModified'] = $this->_data['feeds'][$feedHash]['lastModified'];
$this->_data['feeds'][$feedHash] = $channel;
$this->_data['needSort'] = true;
@@ -1367,6 +1388,13 @@ public function updateChannel($feedHash)
unset($this->_data['feeds'][$feedHash]['error']);
$xmlUrl = $this->_data['feeds'][$feedHash]['xmlUrl'];
$xml = $this->loadXml($xmlUrl, $this->_data['feeds'][$feedHash]['etag'], $this->_data['feeds'][$feedHash]['lastModified']);
+ if (empty($this->_data['feeds'][$feedHash]['etag'])) {
+ unset($this->_data['feeds'][$feedHash]['etag']);
+ }
+
+ if (empty($this->_data['feeds'][$feedHash]['lastModified'])) {
+ unset($this->_data['feeds'][$feedHash]['lastModified']);
+ }
if (!$xml) {
if (file_exists($this->cacheDir.'/'.$feedHash.'.php')) {

0 comments on commit 808e240

Please sign in to comment.