Author Topic: Select skin plugin  (Read 2921 times)

Offline bouba

  • Jr. Member
  • **
  • Posts: 11
Select skin plugin
« on: February 28, 2010, 06:05:23 AM »
Hi all, this is the plugin to change the RC skin on login (now i use a GET var in the page to select the skin, like //url?skin=mobile or //url?skin=default). I read this GET var and i set a hidden field in the login html page. Then, in "login_after" i read this hidden field and I select the right skin.

<?php

/**
 * skin Selector on Logon Page
 *
 * Switch skin from Logon Page 
 */

class skin_sel extends rcube_plugin
{

	
function 
init(){
	
	

	
	
$this->add_hook('startup', array($this'switch_skin_before_login'));
	
	
$this->add_hook('template_object_skinselect', array($this'select_skin_template'));
	
	
$this->add_hook('login_after', array($this'switch_skin_after_login'));
	

	
}

	
function 
select_skin_template($p){

	
	
$content '';

	
	
if(
$_GET["setskin"]=="mobilecube"){
	
	
	
$content .= '<input type="hidden" name="skin_home" value="mobilecube" />';
	
	
}else{
	
	
	
$content .= '<input type="hidden" name="skin_home" value="default" />';
	
	
}
	
	

	
	
$p['content'] = $content;
	
	

	
	
return 
$p;
	

	
}
	

	
function 
switch_skin_before_login($args){
	
	

	
	
$skin "";
	
	
if( 
$_GET['setskin'] == "mobilecube"){
	
	
	
$skin "mobilecube";
	
	
}else{
	
	
	
$skin "default";
	
	
}
	
	
$rcmail rcmail::get_instance();
	
	
$a_prefs $rcmail->user->get_prefs();
	
	
$a_prefs['skin'] = $skin;
	
	
$rcmail->user->save_prefs($a_prefs);  
	
	

	
	
$output $rcmail->load_gui(); <-- 
	
	
$output->set_skin($skin); <--
	
	

	
	
return 
$args;
	

	
}

	
function 
switch_skin_after_login($args){
	
	

	
	
$skin "";
	
	
if( 
get_input_value('skin_home'RCUBE_INPUT_POST) == "mobilecube"){
	
	
	
$skin "mobilecube";
	
	
}else{
	
	
	
$skin "default";
	
	
}
	
	
$rcmail rcmail::get_instance();
	
	
$a_prefs $rcmail->user->get_prefs();
	
	
$a_prefs['skin'] = $skin;
	
	
$rcmail->user->save_prefs($a_prefs);   
	
	
return 
$args;
	

	
}

}

?>


the problem apper if I try to change the skin on "startup". If i don't change the login page skin, it works ( comment out $this->add_hook('startup', array($this, 'switch_skin_before_login')); ). The problem is:

$output = $rcmail->load_gui(); <--
$output->set_skin($skin); <--

without this 2 lines, the login skin doesn't change and RC load the right skin for the webmail. With this 2 lines, RC use the right skin only if i reload the page (F5).
How can i use this 2 lines to change the login skin and tell RC to use the right skin without reload the page?

thanks
Marco

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Select skin plugin
« Reply #1 on: September 16, 2010, 01:13:28 AM »
Check this:

f.e. ./?skin=groupvice4


<?php
/**
 * remember_skin
 *
 * @version 1.0 - 15.09.2010
 * @author 'rosali'
 * @website http://myroundcube.googlecode.com
 * @licence GNU GPL
 * 
 **/
 
/**
 *
 * Usage: http://mail4us.net/myroundcube/
 *
 * Notice: ./config/main.inc.php
 *
 *         Set skin config to: 
 *
 *         $rcmail_config['skin'] = get_input_value('skin', RCUBE_INPUT_GPC);
 *
 **/    
 
class remember_skin extends rcube_plugin {
  
  function 
init(){
    
$this->add_hook('startup', array($this'startup'));
    
$this->add_hook('login_after', array($this'login_after'));
    
$this->add_hook('preferences_save', array($this'preferences_save'));
  }
  
  function 
startup(){
    if(isset(
$_GET['skin']))
      
rcmail::setcookie('skin',$_GET['skin'],time()+60*60*24*365);  
  }
   
  function 
login_after(){
    
$rcmail rcmail::get_instance();
    
$skin $rcmail->config->get('skin');
    
rcmail::setcookie('skin',$skin,time()+60*60*24*365);   
  }
  
  function 
preferences_save($prefs){
    
rcmail::setcookie('skin',$prefs['skin'],time()+60*60*24*365);
    return 
$prefs;
  }
}
?>
Regards,
Rosali
__________________
MyRoundcube Project (commercial)