Separate the very application-specific output classes from the Roundcube framework; add autoloader for rmail* classes

pull/66/head
Thomas Bruederli 12 years ago
parent 10da75f364
commit 60226a75d8

@ -31,7 +31,7 @@ define('RCUBE_INPUT_GET', rcube_utils::INPUT_GET);
define('RCUBE_INPUT_POST', rcube_utils::INPUT_POST); define('RCUBE_INPUT_POST', rcube_utils::INPUT_POST);
define('RCUBE_INPUT_GPC', rcube_utils::INPUT_GPC); define('RCUBE_INPUT_GPC', rcube_utils::INPUT_GPC);
define('JS_OBJECT_NAME', rcmail::JS_OBJECT_NAME); define('JS_OBJECT_NAME', rcmail_output::JS_OBJECT_NAME);
define('RCMAIL_CHARSET', RCUBE_CHARSET); define('RCMAIL_CHARSET', RCUBE_CHARSET);
function get_table_name($table) function get_table_name($table)
@ -126,7 +126,7 @@ function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col)
function rcmail_get_edit_field($col, $value, $attrib, $type='text') function rcmail_get_edit_field($col, $value, $attrib, $type='text')
{ {
return rcube_utils::get_edit_field($col, $value, $attrib, $type); return rcube_output::get_edit_field($col, $value, $attrib, $type);
} }
function rcmail_mod_css_styles($source, $container_id, $allow_remote=false) function rcmail_mod_css_styles($source, $container_id, $allow_remote=false)

@ -72,8 +72,26 @@ if (set_include_path($include_path) === false) {
// include Roundcube Framework // include Roundcube Framework
require_once 'Roundcube/bootstrap.php'; require_once 'Roundcube/bootstrap.php';
// backward compatybility (to be removed) // register autoloader for rcmail app classes
require_once INSTALL_PATH . 'program/include/rcmail.php'; spl_autoload_register('rcmail_autoload');
// backward compatybility (to be removed) // backward compatybility (to be removed)
require_once INSTALL_PATH . 'program/include/bc.php'; require_once INSTALL_PATH . 'program/include/bc.php';
/**
* PHP5 autoloader routine for dynamic class loading
*/
function rcmail_autoload($classname)
{
if (strpos($classname, 'rcmail') === 0) {
$filepath = INSTALL_PATH . "program/include/$classname.php";
if (is_readable($filepath)) {
include_once $filepath;
return true;
}
}
return false;
}

@ -56,8 +56,6 @@ class rcmail extends rcube
private $action_map = array(); private $action_map = array();
const JS_OBJECT_NAME = 'rcmail';
const ERROR_STORAGE = -2; const ERROR_STORAGE = -2;
const ERROR_INVALID_REQUEST = 1; const ERROR_INVALID_REQUEST = 1;
const ERROR_INVALID_HOST = 2; const ERROR_INVALID_HOST = 2;
@ -321,17 +319,17 @@ class rcmail extends rcube
/** /**
* Init output object for GUI and add common scripts. * Init output object for GUI and add common scripts.
* This will instantiate a rcube_output_html object and set * This will instantiate a rcmail_output_html object and set
* environment vars according to the current session and configuration * environment vars according to the current session and configuration
* *
* @param boolean True if this request is loaded in a (i)frame * @param boolean True if this request is loaded in a (i)frame
* @return rcube_output_html Reference to HTML output object * @return rcube_output Reference to HTML output object
*/ */
public function load_gui($framed = false) public function load_gui($framed = false)
{ {
// init output page // init output page
if (!($this->output instanceof rcube_output_html)) if (!($this->output instanceof rcmail_output_html))
$this->output = new rcube_output_html($this->task, $framed); $this->output = new rcmail_output_html($this->task, $framed);
// set refresh interval // set refresh interval
$this->output->set_env('refresh_interval', $this->config->get('refresh_interval', 0)); $this->output->set_env('refresh_interval', $this->config->get('refresh_interval', 0));
@ -357,12 +355,12 @@ class rcmail extends rcube
/** /**
* Create an output object for JSON responses * Create an output object for JSON responses
* *
* @return rcube_output_json Reference to JSON output object * @return rcube_output Reference to JSON output object
*/ */
public function json_init() public function json_init()
{ {
if (!($this->output instanceof rcube_output_json)) if (!($this->output instanceof rcmail_output_json))
$this->output = new rcube_output_json($this->task); $this->output = new rcmail_output_json($this->task);
return $this->output; return $this->output;
} }
@ -1566,7 +1564,7 @@ class rcmail extends rcube
$html_name = $this->Q($foldername) . ($unread ? html::span('unreadcount', sprintf($attrib['unreadwrap'], $unread)) : ''); $html_name = $this->Q($foldername) . ($unread ? html::span('unreadcount', sprintf($attrib['unreadwrap'], $unread)) : '');
$link_attrib = $folder['virtual'] ? array() : array( $link_attrib = $folder['virtual'] ? array() : array(
'href' => $this->url(array('_mbox' => $folder['id'])), 'href' => $this->url(array('_mbox' => $folder['id'])),
'onclick' => sprintf("return %s.command('list','%s',this)", rcmail::JS_OBJECT_NAME, $js_name), 'onclick' => sprintf("return %s.command('list','%s',this)", rcmail_output::JS_OBJECT_NAME, $js_name),
'rel' => $folder['id'], 'rel' => $folder['id'],
'title' => $title, 'title' => $title,
); );
@ -1579,7 +1577,7 @@ class rcmail extends rcube
(!empty($folder['folders']) ? html::div(array( (!empty($folder['folders']) ? html::div(array(
'class' => ($is_collapsed ? 'collapsed' : 'expanded'), 'class' => ($is_collapsed ? 'collapsed' : 'expanded'),
'style' => "position:absolute", 'style' => "position:absolute",
'onclick' => sprintf("%s.command('collapse-folder', '%s')", rcmail::JS_OBJECT_NAME, $js_name) 'onclick' => sprintf("%s.command('collapse-folder', '%s')", rcmail_output::JS_OBJECT_NAME, $js_name)
), ' ') : '')); ), ' ') : ''));
$jslist[$folder_id] = array( $jslist[$folder_id] = array(

@ -0,0 +1,120 @@
<?php
/*
+-----------------------------------------------------------------------+
| program/include/rcmail_output.php |
| |
| This file is part of the Roundcube PHP suite |
| Copyright (C) 2005-2012 The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| CONTENTS: |
| Abstract class for output generation |
| |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
/**
* Class for output generation
*
* @package Core
* @subpackage View
*/
abstract class rcmail_output extends rcube_output
{
const JS_OBJECT_NAME = 'rcmail';
public $type = 'html';
public $ajax_call = false;
public $framed = false;
protected $pagetitle = '';
protected $object_handlers = array();
/**
* Object constructor
*/
public function __construct($task = null, $framed = false)
{
parent::__construct();
}
/**
* Setter for page title
*
* @param string $title Page title
*/
public function set_pagetitle($title)
{
$this->pagetitle = $title;
}
/**
* Getter for the current skin path property
*/
public function get_skin_path()
{
return $this->config->get('skin_path');
}
/**
* Delete all stored env variables and commands
*/
public function reset()
{
parent::reset();
$this->object_handlers = array();
$this->pagetitle = '';
}
/**
* Call a client method
*
* @param string Method to call
* @param ... Additional arguments
*/
abstract function command();
/**
* Add a localized label to the client environment
*/
abstract function add_label();
/**
* Register a template object handler
*
* @param string Object name
* @param string Function name to call
* @return void
*/
public function add_handler($obj, $func)
{
$this->object_handlers[$obj] = $func;
}
/**
* Register a list of template object handlers
*
* @param array Hash array with object=>handler pairs
* @return void
*/
public function add_handlers($arr)
{
$this->object_handlers = array_merge($this->object_handlers, $arr);
}
}

@ -2,7 +2,7 @@
/* /*
+-----------------------------------------------------------------------+ +-----------------------------------------------------------------------+
| program/include/rcubeoutput_html.php | | program/include/rcmail_output_html.php |
| | | |
| This file is part of the Roundcube Webmail client | | This file is part of the Roundcube Webmail client |
| Copyright (C) 2006-2012, The Roundcube Dev Team | | Copyright (C) 2006-2012, The Roundcube Dev Team |
@ -23,10 +23,10 @@
/** /**
* Class to create HTML page output using a skin template * Class to create HTML page output using a skin template
* *
* @package Framework * @package Core
* @subpackage View * @subpackage View
*/ */
class rcube_output_html extends rcube_output class rcmail_output_html extends rcmail_output
{ {
public $type = 'html'; public $type = 'html';
@ -82,10 +82,10 @@ class rcube_output_html extends rcube_output
$this->set_env('extwin', 1); $this->set_env('extwin', 1);
// add common javascripts // add common javascripts
$this->add_script('var '.rcmail::JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top'); $this->add_script('var '.self::JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top');
// don't wait for page onload. Call init at the bottom of the page (delayed) // don't wait for page onload. Call init at the bottom of the page (delayed)
$this->add_script(rcmail::JS_OBJECT_NAME.'.init();', 'docready'); $this->add_script(self::JS_OBJECT_NAME.'.init();', 'docready');
$this->scripts_path = 'program/js/'; $this->scripts_path = 'program/js/';
$this->include_script('jquery.min.js'); $this->include_script('jquery.min.js');
@ -240,7 +240,7 @@ class rcube_output_html extends rcube_output
*/ */
public function add_gui_object($obj, $id) public function add_gui_object($obj, $id)
{ {
$this->add_script(rcmail::JS_OBJECT_NAME.".gui_object('$obj', '$id');"); $this->add_script(self::JS_OBJECT_NAME.".gui_object('$obj', '$id');");
} }
@ -536,7 +536,7 @@ class rcube_output_html extends rcube_output
{ {
$out = ''; $out = '';
if (!$this->framed && !empty($this->js_env)) { if (!$this->framed && !empty($this->js_env)) {
$out .= rcmail::JS_OBJECT_NAME . '.set_env('.self::json_serialize($this->js_env).");\n"; $out .= self::JS_OBJECT_NAME . '.set_env('.self::json_serialize($this->js_env).");\n";
} }
if (!empty($this->js_labels)) { if (!empty($this->js_labels)) {
$this->command('add_label', $this->js_labels); $this->command('add_label', $this->js_labels);
@ -549,7 +549,7 @@ class rcube_output_html extends rcube_output
$parent = $this->framed || preg_match('/^parent\./', $method); $parent = $this->framed || preg_match('/^parent\./', $method);
$out .= sprintf( $out .= sprintf(
"%s.%s(%s);\n", "%s.%s(%s);\n",
($parent ? 'if(window.parent && parent.'.rcmail::JS_OBJECT_NAME.') parent.' : '') . rcmail::JS_OBJECT_NAME, ($parent ? 'if(window.parent && parent.'.self::JS_OBJECT_NAME.') parent.' : '') . self::JS_OBJECT_NAME,
preg_replace('/^parent\./', '', $method), preg_replace('/^parent\./', '', $method),
implode(',', $args) implode(',', $args)
); );
@ -1079,7 +1079,7 @@ class rcube_output_html extends rcube_output
if ($attrib['command']) { if ($attrib['command']) {
$this->add_script(sprintf( $this->add_script(sprintf(
"%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');", "%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');",
rcmail::JS_OBJECT_NAME, self::JS_OBJECT_NAME,
$command, $command,
$attrib['id'], $attrib['id'],
$attrib['type'], $attrib['type'],
@ -1091,7 +1091,7 @@ class rcube_output_html extends rcube_output
// make valid href to specific buttons // make valid href to specific buttons
if (in_array($attrib['command'], rcmail::$main_tasks)) { if (in_array($attrib['command'], rcmail::$main_tasks)) {
$attrib['href'] = $this->app->url(array('task' => $attrib['command'])); $attrib['href'] = $this->app->url(array('task' => $attrib['command']));
$attrib['onclick'] = sprintf("return %s.command('switch-task','%s',this,event)", rcmail::JS_OBJECT_NAME, $attrib['command']); $attrib['onclick'] = sprintf("return %s.command('switch-task','%s',this,event)", self::JS_OBJECT_NAME, $attrib['command']);
} }
else if ($attrib['task'] && in_array($attrib['task'], rcmail::$main_tasks)) { else if ($attrib['task'] && in_array($attrib['task'], rcmail::$main_tasks)) {
$attrib['href'] = $this->app->url(array('action' => $attrib['command'], 'task' => $attrib['task'])); $attrib['href'] = $this->app->url(array('action' => $attrib['command'], 'task' => $attrib['task']));
@ -1115,7 +1115,7 @@ class rcube_output_html extends rcube_output
else if ($command && !$attrib['onclick']) { else if ($command && !$attrib['onclick']) {
$attrib['onclick'] = sprintf( $attrib['onclick'] = sprintf(
"return %s.command('%s','%s',this,event)", "return %s.command('%s','%s',this,event)",
rcmail::JS_OBJECT_NAME, self::JS_OBJECT_NAME,
$command, $command,
$attrib['prop'] $attrib['prop']
); );
@ -1648,7 +1648,7 @@ class rcube_output_html extends rcube_output
if (empty($attrib['form'])) { if (empty($attrib['form'])) {
$out = $this->form_tag(array( $out = $this->form_tag(array(
'name' => "rcmqsearchform", 'name' => "rcmqsearchform",
'onsubmit' => rcmail::JS_OBJECT_NAME . ".command('search'); return false", 'onsubmit' => self::JS_OBJECT_NAME . ".command('search'); return false",
'style' => "display:inline"), 'style' => "display:inline"),
$out); $out);
} }

@ -2,7 +2,7 @@
/* /*
+-----------------------------------------------------------------------+ +-----------------------------------------------------------------------+
| program/include/rcube_output_json.php | | program/include/rc,aiö_output_json.php |
| | | |
| This file is part of the Roundcube Webmail client | | This file is part of the Roundcube Webmail client |
| Copyright (C) 2008-2012, The Roundcube Dev Team | | Copyright (C) 2008-2012, The Roundcube Dev Team |
@ -23,10 +23,10 @@
/** /**
* View class to produce JSON responses * View class to produce JSON responses
* *
* @package Framework * @package Core
* @subpackage View * @subpackage View
*/ */
class rcube_output_json extends rcube_output class rcmail_output_json extends rcmail_output
{ {
protected $texts = array(); protected $texts = array();
protected $commands = array(); protected $commands = array();
@ -158,7 +158,7 @@ class rcube_output_json extends rcube_output
{ {
$location = $this->app->url($p); $location = $this->app->url($p);
$this->remote_response(sprintf("window.setTimeout(function(){ %s.redirect('%s',true); }, %d);", $this->remote_response(sprintf("window.setTimeout(function(){ %s.redirect('%s',true); }, %d);",
rcmail::JS_OBJECT_NAME, $location, $delay)); self::JS_OBJECT_NAME, $location, $delay));
exit; exit;
} }

@ -0,0 +1,54 @@
<?php
/*
+-----------------------------------------------------------------------+
| program/include/rcmail_string_replacer.php |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2012, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Turn URLs and email addresses into clickable links |
| |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
*/
/**
* Helper class for turning URLs and email addresses in plaintext content
* into clickable links.
*
* @package Core
* @subpackage Utils
*/
class rcmail_string_replacer extends rcube_string_replacer
{
/**
* Callback function used to build mailto: links around e-mail strings
*
* This also adds an onclick-handler to open the Rouncube compose message screen on such links
*
* @param array Matches result from preg_replace_callback
* @return int Index of saved string value
* @see rcube_string_replacer::mailto_callback()
*/
public function mailto_callback($matches)
{
$href = $matches[1];
$suffix = $this->parse_url_brackets($href);
$i = $this->add(html::a(array(
'href' => 'mailto:' . $href,
'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('compose','".rcube::JQ($href)."',this)",
), rcube::Q($href)) . $suffix);
return $i >= 0 ? $this->get_replacement($i) : '';
}
}

@ -28,22 +28,17 @@
abstract class rcube_output abstract class rcube_output
{ {
public $browser; public $browser;
public $type = 'html';
public $ajax_call = false;
public $framed = false;
protected $app; protected $app;
protected $config; protected $config;
protected $charset = RCUBE_CHARSET; protected $charset = RCMAIL_CHARSET;
protected $env = array(); protected $env = array();
protected $pagetitle = '';
protected $object_handlers = array();
/** /**
* Object constructor * Object constructor
*/ */
public function __construct($task = null, $framed = false) public function __construct()
{ {
$this->app = rcube::get_instance(); $this->app = rcube::get_instance();
$this->config = $this->app->config; $this->config = $this->app->config;
@ -63,16 +58,6 @@ abstract class rcube_output
return null; return null;
} }
/**
* Setter for page title
*
* @param string $title Page title
*/
public function set_pagetitle($title)
{
$this->pagetitle = $title;
}
/** /**
* Setter for output charset. * Setter for output charset.
@ -97,15 +82,6 @@ abstract class rcube_output
} }
/**
* Getter for the current skin path property
*/
public function get_skin_path()
{
return $this->config->get('skin_path');
}
/** /**
* Set environment variable * Set environment variable
* *
@ -137,26 +113,9 @@ abstract class rcube_output
public function reset() public function reset()
{ {
$this->env = array(); $this->env = array();
$this->object_handlers = array();
$this->pagetitle = '';
} }
/**
* Call a client method
*
* @param string Method to call
* @param ... Additional arguments
*/
abstract function command();
/**
* Add a localized label to the client environment
*/
abstract function add_label();
/** /**
* Invoke display_message command * Invoke display_message command
* *
@ -184,31 +143,6 @@ abstract class rcube_output
abstract function send(); abstract function send();
/**
* Register a template object handler
*
* @param string Object name
* @param string Function name to call
* @return void
*/
public function add_handler($obj, $func)
{
$this->object_handlers[$obj] = $func;
}
/**
* Register a list of template object handlers
*
* @param array Hash array with object=>handler pairs
* @return void
*/
public function add_handlers($arr)
{
$this->object_handlers = array_merge($this->object_handlers, $arr);
}
/** /**
* Send HTTP headers to prevent caching a page * Send HTTP headers to prevent caching a page
*/ */
@ -265,6 +199,59 @@ abstract class rcube_output
} }
/**
* Create an edit field for inclusion on a form
*
* @param string col field name
* @param string value field value
* @param array attrib HTML element attributes for field
* @param string type HTML element type (default 'text')
*
* @return string HTML field definition
*/
public static function get_edit_field($col, $value, $attrib, $type = 'text')
{
static $colcounts = array();
$fname = '_'.$col;
$attrib['name'] = $fname . ($attrib['array'] ? '[]' : '');
$attrib['class'] = trim($attrib['class'] . ' ff_' . $col);
if ($type == 'checkbox') {
$attrib['value'] = '1';
$input = new html_checkbox($attrib);
}
else if ($type == 'textarea') {
$attrib['cols'] = $attrib['size'];
$input = new html_textarea($attrib);
}
else if ($type == 'select') {
$input = new html_select($attrib);
$input->add('---', '');
$input->add(array_values($attrib['options']), array_keys($attrib['options']));
}
else if ($attrib['type'] == 'password') {
$input = new html_passwordfield($attrib);
}
else {
if ($attrib['type'] != 'text' && $attrib['type'] != 'hidden') {
$attrib['type'] = 'text';
}
$input = new html_inputfield($attrib);
}
// use value from post
if (isset($_POST[$fname])) {
$postvalue = rcube_utils::get_input_value($fname, rcube_utils::INPUT_POST, true);
$value = $attrib['array'] ? $postvalue[intval($colcounts[$col]++)] : $postvalue;
}
$out = $input->show($value);
return $out;
}
/** /**
* Convert a variable into a javascript object notation * Convert a variable into a javascript object notation
* *

@ -5,7 +5,7 @@
| program/include/rcube_string_replacer.php | | program/include/rcube_string_replacer.php |
| | | |
| This file is part of the Roundcube Webmail client | | This file is part of the Roundcube Webmail client |
| Copyright (C) 2009, The Roundcube Dev Team | | Copyright (C) 2009-2012, The Roundcube Dev Team |
| | | |
| Licensed under the GNU General Public License version 3 or | | Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. | | any later version with exceptions for skins & plugins. |
@ -113,11 +113,7 @@ class rcube_string_replacer
{ {
$href = $matches[1]; $href = $matches[1];
$suffix = $this->parse_url_brackets($href); $suffix = $this->parse_url_brackets($href);
$i = $this->add(html::a('mailto:' . $href, rcube::Q($href)) . $suffix);
$i = $this->add(html::a(array(
'href' => 'mailto:' . $href,
'onclick' => "return ".rcmail::JS_OBJECT_NAME.".command('compose','".rcube::JQ($href)."',this)",
), rcmail::Q($href)) . $suffix);
return $i >= 0 ? $this->get_replacement($i) : ''; return $i >= 0 ? $this->get_replacement($i) : '';
} }

@ -433,59 +433,6 @@ class rcube_utils
} }
/**
* Create an edit field for inclusion on a form
*
* @param string col field name
* @param string value field value
* @param array attrib HTML element attributes for field
* @param string type HTML element type (default 'text')
*
* @return string HTML field definition
*/
public static function get_edit_field($col, $value, $attrib, $type = 'text')
{
static $colcounts = array();
$fname = '_'.$col;
$attrib['name'] = $fname . ($attrib['array'] ? '[]' : '');
$attrib['class'] = trim($attrib['class'] . ' ff_' . $col);
if ($type == 'checkbox') {
$attrib['value'] = '1';
$input = new html_checkbox($attrib);
}
else if ($type == 'textarea') {
$attrib['cols'] = $attrib['size'];
$input = new html_textarea($attrib);
}
else if ($type == 'select') {
$input = new html_select($attrib);
$input->add('---', '');
$input->add(array_values($attrib['options']), array_keys($attrib['options']));
}
else if ($attrib['type'] == 'password') {
$input = new html_passwordfield($attrib);
}
else {
if ($attrib['type'] != 'text' && $attrib['type'] != 'hidden') {
$attrib['type'] = 'text';
}
$input = new html_inputfield($attrib);
}
// use value from post
if (isset($_POST[$fname])) {
$postvalue = self::get_input_value($fname, self::INPUT_POST, true);
$value = $attrib['array'] ? $postvalue[intval($colcounts[$col]++)] : $postvalue;
}
$out = $input->show($value);
return $out;
}
/** /**
* Replace all css definitions with #container [def] * Replace all css definitions with #container [def]
* and remove css-inlined scripting * and remove css-inlined scripting

@ -790,7 +790,7 @@ function rcmail_plain_body($body, $flowed=false)
global $RCMAIL; global $RCMAIL;
// make links and email-addresses clickable // make links and email-addresses clickable
$replacer = new rcube_string_replacer; $replacer = new rcmail_string_replacer;
// search for patterns like links and e-mail addresses and replace with tokens // search for patterns like links and e-mail addresses and replace with tokens
$body = $replacer->replace($body); $body = $replacer->replace($body);

Loading…
Cancel
Save