Recent Topics

1 Dec 11, 2010 18:09    

With 3.x and above, there's opportunity to make hundreds of settings available for skins.Not that many skins have those settings or have "that many" settings, but once this feature is common and a lot of skins have a lot of settings, it will be a pain to re-arrange tens/hundreds of settings per each blog using the same skin.
I wanna make a plugin for that but i am not very good with mysql.Dont know how long would it take, but it sounded like a fairly easy task to me.I just dont know where to start.
If anybody needs this and wants to chip in we could do it together, and also i would appreciate any pointers for starters.

2 Dec 11, 2010 21:24

You don't need SQL at all

- Create a new tab in Tools
- Allow access to admins only
- Add a "Copy from" and "Apply to" dropdowns with blog name/id, and a submit button
- Once submitted, get skin settings from blog X, apply them to blog Y
- For even more coolness, add a multiselect dropdown list (or checkboxes) for target blogs, and apply settings to several blogs.

Not tested!


// Dropdown list
$BlogCache = & get_BlogCache();
$BlogCache->load_all();

$Form->select_object( 'blog_ID_FROM', NULL, $BlogCache, T_('From'), 'blah from' );
$Form->select_object( 'blog_ID_TO', NULL, $BlogCache, T_('To'), 'blah to' );


$blog_ID_FROM = 1;
$blog_ID_TO = 3;

$BlogCache = & get_BlogCache();

$Blog_FROM = & $BlogCache->get_by_ID( $blog_ID_FROM );
$Blog_TO = & $BlogCache->get_by_ID( $blog_ID_TO );

$SkinCache = & get_SkinCache();

if( ($Skin_FROM = & $SkinCache->get_by_ID( $Blog_FROM->skin_ID, false )) === false )
{	// We could not find the skin to edit:
	$Messages->add( T_('Requested skin is not installed any longer.'), 'error' );
}

if( ($Skin_TO = & $SkinCache->get_by_ID( $Blog_TO->skin_ID, false )) === false )
{	// We could not find the skin to edit:
	$Messages->add( T_('Requested skin is not installed any longer.'), 'error' );
}

load_funcs('plugins/_plugin.funcs.php');

$params_FROM = $Skin_FROM->get_param_definitions( array('for_editing'=>true) );

// Loop through all widget params:
foreach( $params_FROM as $parname => $parmeta )
{
	autoform_set_param_from_request( $parname, $parmeta, $Skin_TO, 'Skin' );
}

if( ! param_errors_detected() )
{	// Update settings:
	$Skin_TO->dbupdate_settings();
	$Messages->add( T_('Skin settings have been updated'), 'success' );
}

// All done

3 Dec 11, 2010 21:27

sam2kb wrote:

You don't need SQL at all

- Create a new tab in Tools

Stuck at first step P: i dont know how to create a new tab in admin.. i have to look into that.but the stuff above seems great and probable to work. i will try and let you know the results once i figure out how to.

4 Dec 11, 2010 21:44

function AdminAfterMenuInit()
{
	$this->register_menu_entry( $this->name );
}

Just open any of these plugins and see how they do it
Mail sender, Feed importer, Democracy poll

5 Dec 16, 2010 21:54

i might be doing sth horribly wrong, i got the following errors:

Notice: Undefined variable: Form in C:\wamp\www\b41\plugins\_skin_setting_duplicator.plugin.php on line 67

Fatal error: Call to a member function select_object() on a non-object in C:\wamp\www\b41\plugins\_skin_setting_duplicator.plugin.php on line 67

here is the plugin:

http://emin.pastebin.com/yccz5NGf

<?php
/**
 *
 * This file implements the Skin Settings Duplicator plugin for {@link http://b2evolution.net/}.
 *
 * @package plugins
 *
 * @copyright (c)2010 by Russian b2evolution - {@link http://ru.b2evo.net/}.
 *
 * @license GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
 *
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


class skin_setting_duplicator_plugin extends Plugin
{
	/**
	 * Variables below MUST be overriden by plugin implementations,
	 * either in the subclass declaration or in the subclass constructor.
	 */
	var $name = 'Skin Settings Duplicator';
	/**
	 * Code, if this is a renderer or pingback plugin.
	 */
	var $code = 'skin_setting_dup';
	var $priority = 50;
	var $version = '0.1';
	var $help_url = '';

	var $apply_rendering = 'never';
	var $number_of_installs = 1;
	
	/**
	 * Init
	 *
	 * This gets called after a plugin has been registered/instantiated.
	 */
	function PluginInit( & $params )
	{
		$this->short_desc = $this->T_('Copy skin settings');
		$this->long_desc = $this->T_('Copy skin settings from one to another');
	}
	
		function AdminAfterMenuInit()
	{
		// add our tab
		$this->register_menu_entry( 'Skin Settings Copier' );
	}
	function AdminTabPayload()
	{
		global $BlogCache;
		// Dropdown list
	$BlogCache = & get_BlogCache();
	$BlogCache->load_all();

	$Form->select_object( 'blog_ID_FROM', NULL, $BlogCache, T_('From'), 'blah from' );
	$Form->select_object( 'blog_ID_TO', NULL, $BlogCache, T_('To'), 'blah to' ); 
	}
	function copy_settings()
	{		
		// Loop through all widget params:
		foreach( $params_FROM as $parname => $parmeta )
		{
    	autoform_set_param_from_request( $parname, $parmeta, $Skin_TO, 'Skin' );
		}

		if( ! param_errors_detected() )
		{    // Update settings:
		    $Skin_TO->dbupdate_settings();
		    $Messages->add( T_('Skin settings have been updated'), 'success' );
		}
	}
// All done 
	
}

?>

and i guess this would not work in 3.3 right ? Did 3.3 have cache ?

6 Dec 17, 2010 04:00

you don't need this

global $BlogCache;

add this

$Form = & new Form('params here');

$Form->select_object

and i guess this would not work in 3.3 right ? Did 3.3 have cache ?


global $app_version;
if ( version_compare( $app_version, '4' ) > 0 )
{	// b2evo 4 and up
	$ItemCache = & get_ItemCache();
	load_class( 'items/model/_item.class.php', 'Item' );
}
else
{
	$ItemCache = & get_Cache( 'ItemCache' );
	load_class( 'items/model/_item.class.php' );
}

You also need to add new event and do form processing there

function AdminTabAction()

Again, Mail sender and Feed importer do similar stuff (submit a form and process its data)

7 Dec 23, 2010 00:57

well, i genuinely tried but i just cant do this one.. While you are halfway there, let me know if you finish making this :D

8 Dec 23, 2010 05:03

I don't work on this plugin. Anyway, post here what you've done.

9 Dec 27, 2010 22:24

sam2kb wrote:

I don't work on this plugin. Anyway, post here what you've done.

Well i practically done nothing other than what you said, and i ve gotten nowhere, and i ve given up :D it'd be kind of you if you ever complete it


Form is loading...