\n"; // Now we loop over this monstrosity... for($i=0; $i DATE_SUB(NOW(), INTERVAL 3 DAY) ORDER BY post_date DESC LIMIT $each)\n"; if($aget($name); } ////////////////////////////////////////////////////////// // ( cacheObject ) /////////////////////////////////////// // INSERT an object INTO the cache // With name $name and lasting $expire seconds // Return: TRUE on success, else NULL function cacheObject($name, $obj, $expire) { $link = memcacheConnect(); $ins = $link->add($name, $obj, false, $expire); return $ins; } ////////////////////////////////////////////////////////// // ( cachedFile ) //////////////////////////////////////// // This is used to read a file into Memcache. It's probably // somewhat redundant, really. function cachedFile($file, $expire) { $link = memcacheConnect(); $got = $link->get($file); if(!$got) { $handle = fopen($file, 'r'); $got = fread($handle, filesize($file)); $link->add($file, $got, false, $expire) or die("Memcache add failed"); } return $got; } /////////////////////////////////////////////////////////// // ( memcacheConnect ) //////////////////////////////////// // Connect to memcache and return the link function memcacheConnect() { $memcache_obj = new Memcache or die("Create failed"); $memcache_obj->connect('localhost', 11211) or die("Connect failed"); return $memcache_obj; } /////////////////////////////////////////////////////////// // ( memcacheStatus ) ///////////////////////////////////// // Return statistics on memcache // You may wish to print_r($result) when used function memcacheStatus() { $link = memcacheConnect(); return Memcache::getServerStatus('localhost'); } //////////////////////////////////////////////////////////// // ( getAuthor ) /////////////////////////////////////////// // Older function with no caching... Cache around it function getAuthor($id) { $rs = mysql_query("SELECT display_name, user_url FROM wp_users WHERE ID=$id"); // Pull out the info $name = mysql_result($rs, 0, 'display_name'); $url = mysql_result($rs, 0, 'user_url'); return "$name"; } //////////////////////////////////////////////////////////// // ( imageScale ) ////////////////////////////////////////// // In its current incarnation, nothing uses this // Resize an image! // N.B. that this only changes HTML props! function imageScale($link) { $hash = md5($link); $return = getCachedObject($hash); if($return) return $return; // Cache miss! list($width, $height, $type, $attr) = getimagesize($link); if($width>700) { // it's too big! $frac = ($width/$height); $width = 700; $height = ($width * $frac); } $return = ""; cacheObject($hash, $return, '25200'); return $return; } ////////////////////////////////////////////////////////////// // Back out the name of a blog given a GUID function guessBlog($guid) { $path = parse_url($guid,PHP_URL_PATH); // That's the full permalink. We want everything before the second slash... $path = strtok($path, '/'); // Now we gotta think! $gb_query = "SELECT blog_id FROM wp_blogs WHERE path='/$path/';"; $gb_result = mysql_query($gb_query); $gb_result = mysql_result($gb_result,0,'blog_id'); $x = getBlog($gb_result); return $x; } // Get information about a blog given a blog ID function getBlog($id) { $url_q = "SELECT option_value FROM wp_" . $id . "_options WHERE option_name='siteurl'"; $name_q = "SELECT option_value FROM wp_" . $id . "_options WHERE option_name='blogname'"; //$desc_q = "SELECT option_value FROM wp_" . $id . "_options WHERE option_name='blogdescription'"; $r1 = mysql_query($url_q); $r2 = mysql_query($name_q); //$r3 = mysql_query($desc_q); $blog_url = mysql_result($r1, 0, 'option_value'); $blog_name = mysql_result($r2, 0, 'option_value'); $blog_name = stripslashes($blog_name); $full = "$blog_name"; return $full; } ?>