summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-includes/rss-functions.php
diff options
context:
space:
mode:
authormatt <matt@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-05-15 03:19:56 +0000
committermatt <matt@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-05-15 03:19:56 +0000
commit034694eb53dd71a980745f5594509890fd761998 (patch)
treec85517e8af3fce163f1d183afdf7c9ac7094d84e /wp-inst/wp-includes/rss-functions.php
parenta72266931b88c8fa300d2e29a69a2bb38a70654a (diff)
downloadwordpress-mu-034694eb53dd71a980745f5594509890fd761998.tar.gz
wordpress-mu-034694eb53dd71a980745f5594509890fd761998.tar.xz
wordpress-mu-034694eb53dd71a980745f5594509890fd761998.zip
Lots and lots of changes.
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@543 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-inst/wp-includes/rss-functions.php')
-rw-r--r--wp-inst/wp-includes/rss-functions.php67
1 files changed, 38 insertions, 29 deletions
diff --git a/wp-inst/wp-includes/rss-functions.php b/wp-inst/wp-includes/rss-functions.php
index 0c37c5a..94aa1d7 100644
--- a/wp-inst/wp-includes/rss-functions.php
+++ b/wp-inst/wp-includes/rss-functions.php
@@ -373,6 +373,11 @@ class MagpieRSS {
}
}
+
+function map_attrs($k, $v) {
+ return "$k=\"$v\"";
+}
+
require_once( dirname(__FILE__) . '/class-snoopy.php');
function fetch_rss ($url) {
@@ -384,6 +389,13 @@ function fetch_rss ($url) {
return false;
}
+ $parts = parse_url($url);
+ if ( strstr($parts['host'], 'wordpress.com') && !preg_match('!/(feed|atom|rss|rss2)/?$|/feed/(feed|atom|rss|rss2)/?$|\.xml$!i', $parts['path']) )
+ $url = trim($url, '/') . '/feed/';
+
+ if ( $rss = wp_cache_get($url, 'rss') )
+ return $rss;
+
// if cache is disabled
if ( !MAGPIE_CACHE_ON ) {
// fetch file, and parse it
@@ -464,6 +476,7 @@ function fetch_rss ($url) {
}
// add object to cache
$cache->set( $url, $rss );
+ wp_cache_set($url, $rss, 'rss', 3600);
return $rss;
}
}
@@ -478,10 +491,12 @@ function fetch_rss ($url) {
else {
$errormsg .= "(HTTP Response: " . $resp->response_code .')';
}
+ wp_cache_set($url, $errormsg, 'rss', 3600);
}
}
else {
$errormsg = "Unable to retrieve RSS file for unknown reasons.";
+ wp_cache_set($url, $errormsg, 'rss', 3600);
}
// else fetch failed
@@ -491,6 +506,7 @@ function fetch_rss ($url) {
if ( MAGPIE_DEBUG ) {
debug("Returning STALE object for $url");
}
+ wp_cache_set($url, $rss, 'rss', 7200);
return $rss;
}
@@ -505,6 +521,7 @@ function fetch_rss ($url) {
function _fetch_remote_file ($url, $headers = "" ) {
// Snoopy is an HTTP client in PHP
$client = new Snoopy();
+ $client->referer = 'http'.($_SERVER['HTTPS']?'s':'').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$client->agent = MAGPIE_USER_AGENT;
$client->read_timeout = MAGPIE_FETCH_TIME_OUT;
$client->use_gzip = MAGPIE_USE_GZIP;
@@ -660,20 +677,15 @@ class RSSCache {
\*=======================================================================*/
function set ($url, $rss) {
global $wpdb;
- $cache_option = 'rss_' . $this->file_name( $url );
- $cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts';
-
- if ( !$wpdb->get_var("SELECT meta_key FROM $wpdb->sitemeta WHERE meta_key = '$cache_option'") )
- add_site_option($cache_option, '');
- if ( !$wpdb->get_var("SELECT meta_key FROM $wpdb->sitemeta WHERE meta_key = '$cache_timestamp'") )
- add_site_option($cache_timestamp, '');
-
- update_site_option($cache_option, $rss);
- update_site_option($cache_timestamp, time() );
-
- return $cache_option;
- }
+ $file = $this->file_name( $url );
+ $f = fopen( $file, 'w' );
+ fwrite( $f, serialize( $rss ) );
+ fclose( $f );
+
+ return true;
+ }
+
/*=======================================================================*\
Function: get
Purpose: fetch an item from the cache
@@ -682,17 +694,17 @@ class RSSCache {
\*=======================================================================*/
function get ($url) {
$this->ERROR = "";
- $cache_option = 'rss_' . $this->file_name( $url );
-
- if ( ! get_site_option( $cache_option ) ) {
+ $file = $this->file_name( $url );
+
+ if ( ! $contents = file_get_contents( $file ) ) {
$this->debug(
"Cache doesn't contain: $url (cache option: $cache_option)"
);
return 0;
}
-
- $rss = get_site_option( $cache_option );
-
+
+ $rss = unserialize( $contents );
+
return $rss;
}
@@ -705,26 +717,23 @@ class RSSCache {
\*=======================================================================*/
function check_cache ( $url ) {
$this->ERROR = "";
- $cache_option = $this->file_name( $url );
- $cache_timestamp = 'rss_' . $this->file_name( $url ) . '_ts';
+ $file = $this->file_name( $url );
+
+ if ( !file_exists( $file ) )
+ return 'MISS';
- if ( $mtime = get_site_option($cache_timestamp) ) {
+ if ( $mtime = filemtime($file) ) {
// find how long ago the file was added to the cache
// and whether that is longer then MAX_AGE
$age = time() - $mtime;
if ( $this->MAX_AGE > $age ) {
// object exists and is current
return 'HIT';
- }
- else {
+ } else {
// object exists but is old
return 'STALE';
}
}
- else {
- // object does not exist
- return 'MISS';
- }
}
/*=======================================================================*\
@@ -748,7 +757,7 @@ class RSSCache {
Output: a file name
\*=======================================================================*/
function file_name ($url) {
- return md5( $url );
+ return '/home/wpcom/cache/rss/' . md5( $url );
}
/*=======================================================================*\