Author Topic: Problem with mobile plugin  (Read 4958 times)

Offline macior

  • Newbie
  • *
  • Posts: 5
Problem with mobile plugin
« on: May 22, 2012, 12:54:19 PM »
Hi!

I have a mobile plugin - which changes the theme to mobile.
If I turn on logout_redirect plugin - mobile plugin it stops working.

Can you help me fix this?

I paste the code below

Sorry for my english


Redirect login/logout plugin
Code: [Select]
<?php
/**
 * Redirect on logout / optionally lock login page
 *
 * @version 1.7 - 12.10.2011
 * @author Roland 'rosali' Liebl
 * @website http://myroundcube.googlecode.com
 * @licence GNU GPL
 *
 **/
 
/**
 *
 * Usage: http://mail4us.net/myroundcube/
 *
 **/ 
 
class logout_redirect extends rcube_plugin
{
  public 
$task 'login|logout';
  
  function 
init()
  {
    
$rcmail rcmail::get_instance();
    
$plugins $rcmail->config->get('plugins');
    
$plugins array_flip($plugins);
    if(!isset(
$plugins['global_config'])){
      
$this->load_config();
    }    
    
$this->add_hook('authenticate', array($this'authenticate'));
    
$this->add_hook('render_page', array($this'login_page'));
    
$this->add_hook('login_after', array($this,'login_after'));
    
$this->add_hook('login_failed', array($this,'login_failed'));
    
$this->add_hook('logout_after', array($this,'logout_after'));
  }
  
  function 
goto_url($v$args null)
  { 
    
$rcmail rcmail::get_instance(); 
    
setcookie ('ajax_login','',time()-3600);
    
$url $rcmail->config->get('logout_redirect_url','http://roundcube.net?domain=%d&user=%n');
    
$name '';
    
$domain '';
    if(
$args == null) {
      list(
$name$domain) = explode('@'$_POST['_user']);
    }
    else{
      
$sql_result $rcmail->db->query("SELECT t2.email FROM ".$rcmail->config->get('db_table_users')." as t1 join ".$rcmail->config->get('db_table_identities')." as t2 on t1.user_id = t2.user_id where t1.username=? and t2.standard=1"$args['user']);
      if (
$sql_result && ($sql_arr $rcmail->db->fetch_assoc($sql_result))) {
        list(
$name,$domain) = explode('@'$sql_arr['email']);
      }
    }
    
$url str_replace('%d'$domain$url);
    
$url str_replace('%n'$name$url);
    
$con '?';
    if(
strpos($url'?'))
      
$con '&';
    
$rcmail->output->add_script('location.href="' $url $con 'message=' urlencode($v) . '";');
    
$rcmail->output->send('plugin'); 
    exit; 
  }
  
  function 
authenticate($args)
  {
    if(!empty(
$_POST['ajax']) && !empty($_POST['_user']) && !empty($_POST['_pass'])){
      
$rcmail rcmail::get_instance();
      if(
$rcmail->config->get('logout_redirect_referer'false)){
        if(
stristr($_SERVER['HTTP_REFERER'],$rcmail->config->get('logout_redirect_referer'))){
          
$args['valid'] = true;
        }
      }
      else{
        
$args['valid'] = true;
      }
      
$args['cookiecheck'] = false;
    }
    return 
$args;
  }
     
  
// ajax cookie 
  
function login_after($args)  
  {  
    if(!empty(
$_POST['ajax']))  
      
setcookie ('ajax_login',1,time()+60*60*24*365);  
    else  
      
setcookie ('ajax_login','',time()-3600);  
    return 
$args;  
  }

  
// login failed
  
function login_failed($args)
  { 
    if(!empty(
$_POST['ajax'])){
      if(isset(
$_SERVER['HTTP_REFERER'])){
        
rcmail::get_instance()->config->set('logout_redirect_url'$_SERVER['HTTP_REFERER']);
        
$this->goto_url(rcube_label('loginfailed'));
      }
      elseif(
rcmail::get_instance()->config->get('logout_redirect_url','http://roundcube.net?domain=%d&user=%n')){
        
$this->goto_url(rcube_label('loginfailed'));
      }
      else{
        echo 
"<html><head><title></title><script type='text/javascript'> history.back(-1) </script></head><body></body></html>";
      }
      exit;
    }
    if(
rcmail::get_instance()->config->get('logout_redirect_lock_default_login',false))
      
$this->goto_url(rcube_label('loginfailed'));
    return 
$args;  
  }  
     
  
// user logout 
  
function logout_after($args)  
  {        
    if(
$_COOKIE['ajax_login'] == || rcmail::get_instance()->config->get('logout_redirect_lock_default_logout',false)) 
      
$this->goto_url(rcube_label('loggedout'), $args);
    return 
$args
  } 
     
  
// auto logout (session error) 
  
function login_page($p)  
  {
    if((
$_COOKIE['ajax_login'] == || rcmail::get_instance()->config->get('logout_redirect_lock_default_login',false))&& $p['template'] == 'login'
      
$this->goto_url(rcube_label('sessionerror')); 
    return 
$p
  }  
}
?>




Mobile plugin
Code: [Select]
<?php

/**
 * NutsMail Theme Selector Plugin
 * 
 * Copyright (c) 2011 NutsMail.com
 *
 * @version 1.0
 * @author Chris Kulbacki (http://chriskulbacki.com)
 * @url http://nutsmail.com
 * 
 **/

class nutsmail_theme_selector extends rcube_plugin
{
  public 
$noajax true;
  public 
$noframe true;
private $mobile false;
private $themeName false;
  
  function 
init()
  {
    
$this->add_hook('startup', array($this'startup'));
    
$this->add_hook('login_after', array($this'loginAfter'));
  }

  private function 
setThemeName($theme)
  {
    
$isMobile preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android|ipad)/i',
 strtolower(@$_SERVER['HTTP_USER_AGENT'])) || 
strpos(strtolower(@$_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > ||
isset($_SERVER['HTTP_X_WAP_PROFILE']) ||
isset($_SERVER['HTTP_PROFILE']) ||
strpos(strtolower(@$_SERVER['ALL_HTTP']),'operamini') > ||
in_array(strtolower(substr(@$_SERVER['HTTP_USER_AGENT'], 04)), array(
    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
    'newt','noki','palm','pana','pant','phil','play','port','prox',
    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
    'wapr','webc','winw','winw','xda ','xda-'));

//$isMobile = true;

if (substr($theme, -7) == "_mobile")
$theme substr($theme0, -7);

$this->mobile $isMobile && is_dir("skins/{$theme}_mobile");
$this->themeName $this->mobile $theme "_mobile" $theme;
  }
  
private function overrideTheme()
{
// the only way to set the skin successfully for all the parts of the program is to actually set it in the preferences
// we're setting it with every access, switching between mobile and not-mobile depending on the browser
global $RCMAIL;
    
$prefs $RCMAIL->user->get_prefs();
$this->setThemeName($prefs['skin']);
$prefs['skin'] = $this->themeName;
$RCMAIL->user->save_prefs($prefs);
}

  function 
startup()
  {
    
$rcmail rcmail::get_instance();
    
$output $rcmail->load_gui();
$this->setThemeName($rcmail->config->get('skin'));
    
$output->set_skin($this->themeName);
$this->overrideTheme();
  }
   
  function 
loginAfter()
  {
$this->overrideTheme();
  }

}