Recent Topics

1 Apr 18, 2006 04:33    

Hey, is there a way to disable/enable a setting if that settings requirements are not met.

E.g.

function GetDefaultSettings()
	{
		$Settings = array();
		//Lots of cut out settings
			
		if( $error = $this->validate_gd_requirements() )
		{
			$Settings['createthumbnails'] = 
			array(
				'label' => T_('Create Thumbnails'),
				'note' => T_('When a image is uploaded this will create a resized copy of the image to save bandwidth.<br /><strong>'.$error.'</strong>'),
				'enabled' => false,
				'defaultvalue' => '1',
				'type' => 'checkbox',
				);
		}else{
			$Settings['createthumbnails'] = 
			array(
				'label' => T_('Create Thumbnails'),
				'note' => T_('When a image is uploaded this will create a resized copy of the image to save bandwidth.'),
				'enabled' => true,
				'defaultvalue' => '1',
				'type' => 'checkbox',
				);
		}
		
		return $Settings;
	}

Notice the enabled attribute that i am trying to apply.

Because the createthumbnails setting is optional, but can only be enabled if the gd library is installed.

Thanks

2 Apr 18, 2006 11:48

Allright i've implemented what I wanted to do above into b2evolution 1.8, heres how;

Add this to line 151 of blogs\inc\_misc\_plugins.funcs.php

	// Be aloud to disable settings
	if( isset($set_meta['disabled']) )
		$params['disabled'] = $set_meta['disabled'];

Will allow this to work

			$Settings['createthumbnails'] = 
			array(
				'label' => T_('Create Thumbnails'),
				'note' => T_('When a image is uploaded this will create a resized copy of the image to save bandwidth.<br /><strong>'.$error.'</strong>'),
				'disabled' => 'disabled',
				'defaultvalue' => '1',
				'type' => 'checkbox',
				);

3 Apr 18, 2006 12:09

Also when a setting is disabled it passes a null value back to the form so to fix that the following addition is made;

Change [Around line 272 - \blogs\inc\_misc\_plugins.funcs.php]

function set_Settings_for_Plugin_from_params( & $Plugin, & $use_Plugins, $set_type )
{
	global $Request, $Messages;

	$method = 'GetDefault'.$set_type;

	foreach( $Plugin->$method() as $l_name => $l_meta )
	{
		if( isset($l_meta['layout']) )
		{ // a layout "setting"
			continue;
		}

to

function set_Settings_for_Plugin_from_params( & $Plugin, & $use_Plugins, $set_type )
{
	global $Request, $Messages;

	$method = 'GetDefault'.$set_type;

	foreach( $Plugin->$method() as $l_name => $l_meta )
	{
		if( isset($l_meta['layout']) )
		{ // a layout "setting"
			continue;
		}
		
		if( isset($l_meta['disabled']) )
		{ // when a setting is disabled we don't want a null value
			$l_value = $Plugin->$set_type->get( $l_name );
			continue;
		}

4 Apr 18, 2006 15:19

balupton,

Grab blueyed's captcha plugin from the same repository where my youtube plugin is. He uses the BeforeEnable event to check to see if the server has GD installed. If not it gives an error message and fails to enable the plugin. You should be able to modify his method for your purposes.

5 Apr 18, 2006 15:30

Yes i know but the GD library is optional in this plugin not like the captcha plugin.

Having the GD library installed is a benefit because then they can enable thumbnails, if the admin wants.
But the plugin will work fine without thumbnails

6 Apr 18, 2006 19:07

Thanks balupton.

I've slightly changed your code and just committed it.

Your code should still work, though you should say

'disabled' => true

in your GetDefaultSettings method.


Form is loading...