[wp-hackers] Version RPC

Peter Westwood peter.westwood at ftwr.co.uk
Mon Aug 22 19:11:26 GMT 2005


David House wrote:

>On 21/08/05, Peter Westwood <peter.westwood at ftwr.co.uk> wrote:
>  
>
>>These look good.
>>
>>I've made a first pass at creating a patch to use this (for
>>http://trac.wordpress.org/ticket/1476 patch also attached there) which
>>will display a message on the dashboard the returned version is
>>different from the installed version.
>>
>>I've also attached a screenshot of how it looks at present
>>
>>Comments??
>>    
>>
>
>Perhaps change the text to something like 'A [[new WordPress
>version]], version 1.5.2, was released 7 days ago.' (the words 'new
>WordPress version' should be linked to the dev blog announcement).
>Most end users will just be confused by the presence of a 'svn' link.
>  
>
Thanks for the feedback.

I've updated the patch to change the text and dropped the svn link for 
now - the information is still requested and stored although if it's not 
going to be used that can be dropped as well.

--
westi
-------------- next part --------------
Index: wp-admin/wp-admin.css
===================================================================
--- wp-admin/wp-admin.css	(revision 2800)
+++ wp-admin/wp-admin.css	(working copy)
@@ -757,3 +757,14 @@
 	-khtml-opacity: 0.8;
 	filter: alpha(opacity=80);
 }
+
+#updatemessage {
+	display:inline;
+	padding:1em;
+	border: 1px solid #69c;
+	background: #ebb;
+	text-align:center;
+	position:absolute;
+	top: 120px;
+	right:65px;
+}
Index: wp-admin/admin-functions.php
===================================================================
--- wp-admin/admin-functions.php	(revision 2800)
+++ wp-admin/admin-functions.php	(working copy)
@@ -1394,4 +1394,62 @@
 	return $wp_importers;
 }
 
-?>
\ No newline at end of file
+function check_version_and_get_message()
+{
+	if (get_option('lastest_version_info'))
+	{
+		$latest_version_info = get_option('latest_version_info');
+	} else {
+		//Defaults
+		$latest_version_info = array("last_update" => 0, 
+									 "last_version" => "0.0.0", 
+									 "last_url" => "http://wordpress.org", 
+									 "last_date" => "19800101", 
+									 "last_svn" => "http://svn.automattic.com/wordpress/tags/1.5.2/" );
+	}
+	
+	//Check every 15 minutes for now - maybe up this to 1 hour or so ??
+	if (($latest_version_info["last_update"] + ( 15 * 60)) < time())
+	{
+		$version_snoopy = _fetch_remote_file("http://rpc.wordpress.org/latest-stable/version/");
+		$date_snoopy = _fetch_remote_file("http://rpc.wordpress.org/latest-stable/date/");
+		$link_snoopy = _fetch_remote_file("http://rpc.wordpress.org/latest-stable/link/");
+		$svn_snoopy = _fetch_remote_file("http://rpc.wordpress.org/latest-stable/svn/");
+		
+		if (_check_snoopy_get_results($version_snoopy, $latest_version_info["last_version"]) and
+			_check_snoopy_get_results($date_snoopy, $latest_version_info["last_date"]) and
+			_check_snoopy_get_results($link_snoopy, $latest_version_info["last_url"]) and
+			_check_snoopy_get_results($svn_snoopy, $latest_version_info["last_svn"]))
+		{
+			//All suceeded so update timestamp
+			$latest_version_info["last_update"] = time();
+			update_option('latest_version_info',$latest_version_info);
+		}
+		
+	}
+
+	if ( $wp_version != $latest_version_info["last_version"])
+	{
+		$message = sprintf(__('A <a href="%s">new WordPress version</a>, version %s, was released %s ago.'), $latest_version_info["last_url"], $latest_version_info["last_version"], human_time_diff(strtotime($latest_version_info["last_date"])));
+	} else {
+		$message = "";
+	}
+
+	return $message;
+					
+} //end check_version_and_get_message()
+
+function _check_snoopy_get_results(&$snoopy, &$value) 
+{
+	if (isset($snoopy) and $snoopy )
+	{
+		if (200 == $snoopy->status)
+		{
+			$value = $snoopy->results;
+			return true;
+		}
+	}
+	return false;
+}
+
+?>
Index: wp-admin/index.php
===================================================================
--- wp-admin/index.php	(revision 2800)
+++ wp-admin/index.php	(working copy)
@@ -11,6 +11,12 @@
 
 <h2><?php _e('Dashboard'); ?></h2>
 
+<?php if ("" != check_version_and_get_message()) { ?>
+<div id="updatemessage">
+<?php echo check_version_and_get_message(); ?>
+</div>
+<?php } ?>
+
 <div id="zeitgeist">
 <h2><?php _e('Latest Activity'); ?></h2>
 
@@ -157,4 +163,4 @@
 
 <?php
 require('./admin-footer.php');
-?>
\ No newline at end of file
+?>


More information about the wp-hackers mailing list