Recent Topics

1 Aug 09, 2007 23:57    

This will display a update note message if a update is available, update checking will happen every 3 days. Update checking can be disabled via the 'Check for Updates' setting that is added to the plugin.


	# =============================================================================
	# UPDATE FUNCTIONALITY
	
	
	function update__has_permission ( )
	{
		global $current_User;
		if ( empty($current_User) || empty($current_User->ID) || (int)$current_User->Group->ID !== 1 || !$this->Settings->get('check_for_updates') )
			return false;
		return true;
	}
	
	function update__check ( )
	{
		$update_needed = false;
		$update_message = $this->Settings->get('last_update_message');
		$update_version = $this->Settings->get('last_update_version');
		
		if ( !empty($update_message) && !empty($update_version) )
		{	// We know there is an update
			$update_needed = version_compare($update_version, $this->version);
			if ( !$update_needed )
			{	// We have been updated!
				$this->Settings->set('next_update_check', strtotime('+3 days', time()));
				$this->Settings->set('last_update_message', '');
				$this->Settings->set('last_update_version', '');
				$this->Settings->dbupdate();
			}
		}
		elseif ( $this->update__has_permission() && time() >= $this->Settings->get('next_update_check') )
		{	// Check for update
			
			// Get update url
			if ( empty($this->update_url) )
				return NULL;
			$update_url = $this->update_url;
			
			// Get the update contents
			$update_contents = @file_get_contents($update_url);
			if ( empty($update_contents) )
			{	// This server does not support updating
				return NULL;
			}
			
			// Get the vars
			$parts = explode('|', $update_contents);
			for ( $i = 0, $n = sizeof($parts); $i < $n; ++$i )
			{
				$part = $parts[$i];
				$split = strpos($part, ':');
				if ( !$split ) continue;
				$key = substr($part, 0, $split);
				$value = substr($part, $split+1);
				
				$var = 'update_'.$key;
				$$var = $value;
			}
			
			if ( empty($update_version) )
			{	// error
				$this->msg(
					'<strong>Failed to check for updates for the ['.$this->name.'] plugin.</strong>'.
					 '&nbsp;&nbsp;&nbsp;<span style="font-size:10px; font-style:italic;">'.
						'(Could not get the version of the update)'.
					 '</span>',
					'error'
				);
				return NULL;
			}
			
			if ( empty($update_message) )
				$update_message = '';
			else
				$update_message = '<br />'.$update_message;
			
			if ( empty($update_url) )
				$update_url = $this->get_help_url();
			
			// Compare
			$update_needed = version_compare($update_version, $this->version);
			
			// Update timer
			$this->Settings->set('next_update_check', strtotime('+3 days', time()));
			
			// Update check stuff
			if ( $update_needed )
			{
				$update_message =
				'<a href="'.$update_url.'"><strong>A newer version of the plugin ['.$this->name.'] is available.</strong></a >'.
				'<br />'.
				'<span style="font-size: 90%; font-style:italic;">'.
					'(You are currently running v'.$this->version.', the new version is v'.$update_version.')'.
				'</span>'.
				$update_message;
				
				$this->Settings->set('last_update_message', $update_message);
				$this->Settings->set('last_update_version', $update_version);
				$this->Settings->dbupdate();
			}
			
		}
		
		if ( $update_needed && !empty($update_message) )
			$this->msg($update_message, 'status');
		
		return true;
	}
	
	function update__settings ( & $settings, & $params )
	{
		$settings['last_update_version'] = array(
			'label' => 'Last Update Version',
			'defaultvalue' => '',
			'type' => 'text'
		);
		
		$settings['last_update_message'] = array(
			'label' => 'Last Update Message',
			'defaultvalue' => '',
			'type' => 'text'
		);
		
		$settings['next_update_check'] = array(
			'label' => 'Last Update',
			'defaultvalue' => time(),
			'type' => 'integer'
		);
		
		$settings['check_for_updates'] = array(
			'label' => 'Check for Updates',
			'defaultvalue' => '1',
			'type' => 'checkbox',
		);
		
		if ( $params['for_editing'] )
		{	// Editing changes
			$settings['last_update_version']['no_edit'] = true;
			$settings['last_update_version']['disabled'] = !$this->update__has_permission();
			
			$settings['last_update_message']['no_edit'] = true;
			$settings['last_update_message']['disabled'] = !$this->update__has_permission();
			
			$settings['next_update_check']['no_edit'] = true;
			$settings['next_update_check']['disabled'] = !$this->update__has_permission();
			
			$settings['check_for_updates']['disabled'] = !$this->update__has_permission();
		}
		
		return true;
	}

And change the end of your GetDefaultSetting function to


		
		// EXTRA FUNCTIONALITY
		$this->update__settings($r, $params);
		
		
		// Return settings
		return $r;
	}

Then create a update.txt containing something like

version:1.0.0.1-final|message:This update brings many changes to your shit

And add the following vars (changed of course)


	// Where should the user go for help
	var $help_url = 'http://www.balupton.com/blogs/b2evo?title=sample_renderer_plugin';
	// What is the author's url
	var $author_url = 'http://www.balupton.com/';
	// The update url, which is a txt file with format [verion:x.x.x.x-tag|message:a message to show for this update|url:http://....] message and url are optional
	var $update_url = 'http://www.balupton.com/blogs/plugins/sample_renderer_plugin/update.txt';

Things to do:
1) Add "Perform Automatic Update to this Version" link.

4 Aug 11, 2007 06:41

Just installed it, and this is what I get:

AstonishMe - Back-Office Plug-In Tool (AM-BOPIT)

Items in red are OLD. Items in green are OKAY.

Error : No version information received from the server or no supported plugins/skins installed

5 Aug 11, 2007 11:03

Good to know the plugin works in 1.10.x :D

Unfortunately, because we haven't played with it for a tad, I've not made a version file for the 1.10 series yet :p

When I get a moment I'll create one so you can see how it works ;)

¥

6 Aug 11, 2007 16:52

looks like the first update will be to the plugin :p

for some reason it won't talk to sourceforge and I haven't had time to look into "why" .... so, if you want to see it in action then you need to change the plugin settings to the following :

Update url : http://astonishme.co.uk/version_info/version_

Host Name : astonishme.co.uk

¥


Form is loading...