Third Party Contributions > API Based Plugins

Problem with mobile plugin

(1/2) > >>

macior:
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: ---<?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'] == 1 || 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'] == 1 || rcmail::get_instance()->config->get('logout_redirect_lock_default_login',false))&& $p['template'] == 'login') 
      $this->goto_url(rcube_label('sessionerror')); 
    return $p; 
  }  
}
?>


--- End code ---


Mobile plugin

--- Code: ---<?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') > 0 ||
isset($_SERVER['HTTP_X_WAP_PROFILE']) ||
isset($_SERVER['HTTP_PROFILE']) ||
strpos(strtolower(@$_SERVER['ALL_HTTP']),'operamini') > 0 ||
in_array(strtolower(substr(@$_SERVER['HTTP_USER_AGENT'], 0, 4)), 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($theme, 0, -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();
  }

}

--- End code ---

macior:
Nobody can help me?

I do not know much about programming but it seems to me that this is a problem with "$this-> add_hook ('login_after', ar ..."


I beg you, help me!

SKaero:
Well for starters whats in your error log?

macior:
There are no errors associated with these plugins.

There are only errors resulting from poorly completed login form.

For example,


--- Code: ---[31-May-2012 09:10:47 +0200]: IMAP Error: Login failed for test@regioxcvzmail.pl from 89.191.168.123. AUTHENTICATE PLAIN: Authentication failed. in /var/www/html/roundcubemail-0.7.2/program/include/rcube_imap.php on line 205 (POST /?_task=&_action=login)
--- End code ---

:/

SKaero:
Which plugin do you have first in the plugins array, and does it work if you reverse the order of the to plugins?

Navigation

[0] Message Index

[#] Next page

Go to full version