4 +-----------------------------------------------------------------------+
5 | program/include/rcube_template.php |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2006-2009, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Class to handle HTML page output using a skin template. |
13 | Extends rcube_html_page class from rcube_shared.inc |
15 +-----------------------------------------------------------------------+
16 | Author: Thomas Bruederli <roundcube@gmail.com> |
17 +-----------------------------------------------------------------------+
25 * Class to create HTML page output using a skin template
29 * @uses rcube_html_page
31 class rcube_template extends rcube_html_page
39 var $js_env = array();
40 var $js_commands = array();
41 var $object_handlers = array();
43 public $type = 'html';
44 public $ajax_call = false;
49 * @todo Use jQuery's $(document).ready() here.
50 * @todo Replace $this->config with the real rcube_config object
52 public function __construct($task, $framed = false)
54 parent::__construct();
56 $this->app = rcmail::get_instance();
57 $this->config = $this->app->config->all();
58 $this->browser = new rcube_browser();
60 //$this->framed = $framed;
61 $this->set_env('task', $task);
62 $this->set_env('request_token', $this->app->get_request_token());
64 // load the correct skin (in case user-defined)
65 $this->set_skin($this->config['skin']);
67 // add common javascripts
68 $javascript = 'var '.JS_OBJECT_NAME.' = new rcube_webmail();';
70 // don't wait for page onload. Call init at the bottom of the page (delayed)
71 $javascript_foot = '$(document).ready(function(){ '.JS_OBJECT_NAME.'.init(); });';
73 $this->add_script($javascript, 'head_top');
74 $this->add_script($javascript_foot, 'foot');
75 $this->scripts_path = 'program/js/';
76 $this->include_script('jquery-1.3.min.js');
77 $this->include_script('common.js');
78 $this->include_script('app.js');
80 // register common UI objects
81 $this->add_handlers(array(
82 'loginform' => array($this, 'login_form'),
83 'username' => array($this, 'current_username'),
84 'message' => array($this, 'message_container'),
85 'charsetselector' => array($this, 'charset_selector'),
90 * Set environment variable
92 * @param string Property name
93 * @param mixed Property value
94 * @param boolean True if this property should be added to client environment
96 public function set_env($name, $value, $addtojs = true)
98 $this->env[$name] = $value;
99 if ($addtojs || isset($this->js_env[$name])) {
100 $this->js_env[$name] = $value;
106 * Set page title variable
108 public function set_pagetitle($title)
110 $this->pagetitle = $title;
115 * Getter for the current page title
117 * @return string The page title
119 public function get_pagetitle()
121 if (!empty($this->pagetitle)) {
122 $title = $this->pagetitle;
124 else if ($this->env['task'] == 'login') {
125 $title = rcube_label(array('name' => 'welcome', 'vars' => array('product' => $this->config['product_name'])));
128 $title = ucfirst($this->env['task']);
138 public function set_skin($skin)
140 if (!empty($skin) && is_dir('skins/'.$skin) && is_readable('skins/'.$skin))
141 $skin_path = 'skins/'.$skin;
143 $skin_path = $this->config['skin_path'] ? $this->config['skin_path'] : 'skins/default';
145 $this->app->config->set('skin_path', $skin_path);
146 $this->config['skin_path'] = $skin_path;
150 * Check if a specific template exists
152 * @param string Template name
153 * @return boolean True if template exists
155 public function template_exists($name)
157 $filename = $this->config['skin_path'] . '/templates/' . $name . '.html';
159 return (is_file($filename) && is_readable($filename));
163 * Register a template object handler
165 * @param string Object name
166 * @param string Function name to call
169 public function add_handler($obj, $func)
171 $this->object_handlers[$obj] = $func;
175 * Register a list of template object handlers
177 * @param array Hash array with object=>handler pairs
180 public function add_handlers($arr)
182 $this->object_handlers = array_merge($this->object_handlers, $arr);
186 * Register a GUI object to the client script
188 * @param string Object name
189 * @param string Object ID
192 public function add_gui_object($obj, $id)
194 $this->add_script(JS_OBJECT_NAME.".gui_object('$obj', '$id');");
198 * Call a client method
200 * @param string Method to call
201 * @param ... Additional arguments
203 public function command()
205 $cmd = func_get_args();
206 if (strpos($cmd[0], 'plugin.') === false)
207 $this->js_commands[] = $cmd;
212 * Add a localized label to the client environment
214 public function add_label()
216 $args = func_get_args();
217 if (count($args) == 1 && is_array($args[0]))
220 foreach ($args as $name) {
221 $this->command('add_label', $name, rcube_label($name));
227 * Invoke display_message command
229 * @param string Message to display
230 * @param string Message type [notice|confirm|error]
231 * @param array Key-value pairs to be replaced in localized text
232 * @param boolean Override last set message
233 * @uses self::command()
235 public function show_message($message, $type='notice', $vars=null, $override=true)
237 if ($override || !$this->message) {
238 $this->message = $message;
241 rcube_label(array('name' => $message, 'vars' => $vars)),
248 * Delete all stored env variables and commands
251 * @uses rcube_html::reset()
253 * @uses self::$js_env
254 * @uses self::$js_commands
255 * @uses self::$object_handlers
257 public function reset()
259 $this->env = array();
260 $this->js_env = array();
261 $this->js_commands = array();
262 $this->object_handlers = array();
268 * Redirect to a certain url
270 * @param mixed Either a string with the action or url parameters as key-value pairs
273 public function redirect($p = array())
275 $location = $this->app->url($p);
276 header('Location: ' . $location);
282 * Send the request output to the client.
283 * This will either parse a skin tempalte or send an AJAX response
285 * @param string Template name
286 * @param boolean True if script should terminate (default)
288 public function send($templ = null, $exit = true)
290 if ($templ != 'iframe') {
291 // prevent from endless loops
292 if ($exit != 'recur' && $this->app->plugins->is_processing('render_page')) {
293 raise_error(array('code' => 505, 'type' => 'php', 'message' => 'Recursion alert: ignoring output->send()'), true, false);
296 $this->parse($templ, false);
299 $this->framed = $templ == 'iframe' ? true : $this->framed;
313 * Process template and write to stdOut
315 * @param string HTML template
316 * @see rcube_html_page::write()
319 public function write($template = '')
321 // unlock interface after iframe load
323 array_unshift($this->js_commands, array('set_busy', false));
325 // write all env variables to client
326 $js = $this->framed ? "if(window.parent) {\n" : '';
327 $js .= $this->get_js_commands() . ($this->framed ? ' }' : '');
328 $this->add_script($js, 'head_top');
330 // make sure all <form> tags have a valid request token
331 $template = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $template);
332 $this->footer = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $this->footer);
335 parent::write($template, $this->config['skin_path']);
339 * Parse a specific skin template and deliver to stdout
341 * Either returns nothing, or exists hard (exit();)
343 * @param string Template name
344 * @param boolean Exit script
346 * @link http://php.net/manual/en/function.exit.php
348 private function parse($name = 'main', $exit = true)
350 $skin_path = $this->config['skin_path'];
353 $temp = explode(".", $name, 2);
354 if (count($temp) > 1) {
357 $skin_dir = $plugin . '/skins/' . $this->config['skin'];
358 $skin_path = $this->app->plugins->dir . $skin_dir;
359 if (!is_dir($skin_path)) { // fallback to default skin
360 $skin_dir = $plugin . '/skins/default';
361 $skin_path = $this->app->plugins->dir . $skin_dir;
365 $path = "$skin_path/templates/$name.html";
367 // read template file
368 if (($templ = @file_get_contents($path)) === false) {
374 'message' => 'Error loading template for '.$name
379 // replace all path references to plugins/... with the configured plugins dir
380 // and /this/ to the current plugin skin directory
382 $templ = preg_replace(array('/\bplugins\//', '/(["\']?)\/this\//'), array($this->app->plugins->url, '\\1'.$this->app->plugins->url.$skin_dir.'/'), $templ);
385 // parse for specialtags
386 $output = $this->parse_conditions($templ);
387 $output = $this->parse_xml($output);
389 // trigger generic hook where plugins can put additional content to the page
390 $hook = $this->app->plugins->exec_hook("render_page", array('template' => $name, 'content' => $output));
393 if ($this->config['debug_level'] & 8) {
394 $this->add_footer('<div id="console" style="position:absolute;top:5px;left:5px;width:405px;padding:2px;background:white;z-index:9000;">
395 <a href="#toggle" onclick="con=document.getElementById(\'dbgconsole\');con.style.display=(con.style.display==\'none\'?\'block\':\'none\');return false">console</a>
396 <form action="/" name="debugform" style="display:inline"><textarea name="console" id="dbgconsole" rows="20" cols="40" wrap="off" style="display:none;width:400px;border:none;font-size:x-small" spellcheck="false"></textarea></form></div>'
400 $output = $this->parse_with_globals($hook['content']);
401 $this->write(trim($output));
409 * Return executable javascript code for all registered commands
411 * @return string $out
413 private function get_js_commands()
416 if (!$this->framed && !empty($this->js_env)) {
417 $out .= JS_OBJECT_NAME . '.set_env('.json_serialize($this->js_env).");\n";
419 foreach ($this->js_commands as $i => $args) {
420 $method = array_shift($args);
421 foreach ($args as $i => $arg) {
422 $args[$i] = json_serialize($arg);
424 $parent = $this->framed || preg_match('/^parent\./', $method);
427 ($parent ? 'if(window.parent && parent.'.JS_OBJECT_NAME.') parent.' : '') . JS_OBJECT_NAME,
428 preg_replace('/^parent\./', '', $method),
437 * Make URLs starting with a slash point to skin directory
439 * @param string Input string
442 public function abs_url($str)
444 return preg_replace('/^\//', $this->config['skin_path'].'/', $str);
448 /***** Template parsing methods *****/
451 * Replace all strings ($varname)
452 * with the content of the according global variable.
454 private function parse_with_globals($input)
456 $GLOBALS['__version'] = Q(RCMAIL_VERSION);
457 $GLOBALS['__comm_path'] = Q($this->app->comm_path);
458 return preg_replace('/\$(__[a-z0-9_\-]+)/e', '$GLOBALS["\\1"]', $input);
462 * Public wrapper to dipp into template parsing.
464 * @param string $input
466 * @uses rcube_template::parse_xml()
469 public function just_parse($input)
471 return $this->parse_xml($input);
475 * Parse for conditional tags
477 * @param string $input
480 private function parse_conditions($input)
482 $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE);
483 if ($matches && count($matches) == 4) {
484 if (preg_match('/^(else|endif)$/i', $matches[1])) {
485 return $matches[0] . $this->parse_conditions($matches[3]);
487 $attrib = parse_attrib_string($matches[2]);
488 if (isset($attrib['condition'])) {
489 $condmet = $this->check_condition($attrib['condition']);
490 $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE);
492 $result = $submatches[0];
493 $result.= ($submatches[1] != 'endif' ? preg_replace('/.*<roundcube:endif\s+[^>]+>/Uis', '', $submatches[3], 1) : $submatches[3]);
496 $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3];
498 return $matches[0] . $this->parse_conditions($result);
505 'message' => "Unable to parse conditional tag " . $matches[2]
513 * Determines if a given condition is met
515 * @todo Get rid off eval() once I understand what this does.
516 * @todo Extend this to allow real conditions, not just "set"
517 * @param string Condition statement
518 * @return boolean True if condition is met, False if not
520 private function check_condition($condition)
522 return eval("return (".$this->parse_expression($condition).");");
529 private function alter_form_tag($matches)
532 $attrib = parse_attrib_string($matches[1]);
534 if (strtolower($attrib['method']) == 'post') {
535 $hidden = new html_hiddenfield(array('name' => '_token', 'value' => $this->app->get_request_token()));
536 $out .= "\n" . $hidden->show();
544 * Parses expression and replaces variables
546 * @param string Expression statement
547 * @return string Expression statement
549 private function parse_expression($expression)
553 '/session:([a-z0-9_]+)/i',
554 '/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i',
555 '/env:([a-z0-9_]+)/i',
556 '/request:([a-z0-9_]+)/i',
557 '/cookie:([a-z0-9_]+)/i',
558 '/browser:([a-z0-9_]+)/i'
562 "\$this->app->config->get('\\1',get_boolean('\\3'))",
563 "\$this->env['\\1']",
564 "get_input_value('\\1', RCUBE_INPUT_GPC)",
566 "\$this->browser->{'\\1'}"
573 * Search for special tags in input and replace them
574 * with the appropriate content
576 * @param string Input string to parse
577 * @return string Altered input string
578 * @todo Use DOM-parser to traverse template HTML
579 * @todo Maybe a cache.
581 private function parse_xml($input)
583 return preg_replace_callback('/<roundcube:([-_a-z]+)\s+([^>]+)>/Ui', array($this, 'xml_command'), $input);
588 * Callback function for parsing an xml command tag
589 * and turn it into real html content
591 * @param array Matches array of preg_replace_callback
592 * @return string Tag/Object content
594 private function xml_command($matches)
596 $command = strtolower($matches[1]);
597 $attrib = parse_attrib_string($matches[2]);
599 // empty output if required condition is not met
600 if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
608 if ($attrib['name'] || $attrib['command']) {
609 return $this->button($attrib);
615 if ($attrib['name'] || $attrib['command']) {
616 return Q(rcube_label($attrib + array('vars' => array('product' => $this->config['product_name']))));
622 $path = realpath($this->config['skin_path'].$attrib['file']);
623 if (is_readable($path)) {
624 if ($this->config['skin_include_php']) {
625 $incl = $this->include_php($path);
628 $incl = file_get_contents($path);
630 $incl = $this->parse_conditions($incl);
631 return $this->parse_xml($incl);
635 case 'plugin.include':
636 $hook = $this->app->plugins->exec_hook("template_plugin_include", $attrib);
637 return $hook['content'];
640 // define a container block
642 if ($attrib['name'] && $attrib['id']) {
643 $this->command('gui_container', $attrib['name'], $attrib['id']);
644 // let plugins insert some content here
645 $hook = $this->app->plugins->exec_hook("template_container", $attrib);
646 return $hook['content'];
650 // return code for a specific application object
652 $object = strtolower($attrib['name']);
655 // we are calling a class/method
656 if (($handler = $this->object_handlers[$object]) && is_array($handler)) {
657 if ((is_object($handler[0]) && method_exists($handler[0], $handler[1])) ||
658 (is_string($handler[0]) && class_exists($handler[0])))
659 $content = call_user_func($handler, $attrib);
661 // execute object handler function
662 else if (function_exists($handler)) {
663 $content = call_user_func($handler, $attrib);
665 else if ($object == 'productname') {
666 $name = !empty($this->config['product_name']) ? $this->config['product_name'] : 'RoundCube Webmail';
669 else if ($object == 'version') {
670 $ver = (string)RCMAIL_VERSION;
671 if (is_file(INSTALL_PATH . '.svn/entries')) {
672 if (preg_match('/Revision:\s(\d+)/', @shell_exec('svn info'), $regs))
673 $ver .= ' [SVN r'.$regs[1].']';
677 else if ($object == 'steptitle') {
678 $content = Q($this->get_pagetitle());
680 else if ($object == 'pagetitle') {
681 $title = !empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : '';
682 $title .= $this->get_pagetitle();
683 $content = Q($title);
686 // exec plugin hooks for this template object
687 $hook = $this->app->plugins->exec_hook("template_object_$object", $attrib + array('content' => $content));
688 return $hook['content'];
690 // return code for a specified eval expression
692 $value = $this->parse_expression($attrib['expression']);
693 return eval("return Q($value);");
697 $var = explode(':', $attrib['name']);
703 $value = $this->env[$name];
706 $value = $this->config[$name];
707 if (is_array($value) && $value[$_SESSION['imap_host']]) {
708 $value = $value[$_SESSION['imap_host']];
712 $value = get_input_value($name, RCUBE_INPUT_GPC);
715 $value = $_SESSION[$name];
718 $value = htmlspecialchars($_COOKIE[$name]);
721 $value = $this->browser->{$name};
725 if (is_array($value)) {
726 $value = implode(', ', $value);
736 * Include a specific file and return it's contents
738 * @param string File path
739 * @return string Contents of the processed file
741 private function include_php($file)
745 $out = ob_get_contents();
752 * Create and register a button
754 * @param array Named button attributes
755 * @return string HTML button
756 * @todo Remove all inline JS calls and use jQuery instead.
757 * @todo Remove all sprintf()'s - they are pretty, but also slow.
759 public function button($attrib)
761 static $sa_buttons = array();
762 static $s_button_count = 100;
764 // these commands can be called directly via url
765 $a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities');
767 if (!($attrib['command'] || $attrib['name'])) {
771 // try to find out the button type
772 if ($attrib['type']) {
773 $attrib['type'] = strtolower($attrib['type']);
776 $attrib['type'] = ($attrib['image'] || $attrib['imagepas'] || $attrib['imageact']) ? 'image' : 'link';
778 $command = $attrib['command'];
780 // take the button from the stack
781 if ($attrib['name'] && $sa_buttons[$attrib['name']]) {
782 $attrib = $sa_buttons[$attrib['name']];
784 else if($attrib['image'] || $attrib['imageact'] || $attrib['imagepas'] || $attrib['class']) {
785 // add button to button stack
786 if (!$attrib['name']) {
787 $attrib['name'] = $command;
789 if (!$attrib['image']) {
790 $attrib['image'] = $attrib['imagepas'] ? $attrib['imagepas'] : $attrib['imageact'];
792 $sa_buttons[$attrib['name']] = $attrib;
794 else if ($command && $sa_buttons[$command]) {
795 // get saved button for this command/name
796 $attrib = $sa_buttons[$command];
799 if (!$attrib['id']) {
800 $attrib['id'] = sprintf('rcmbtn%d', $s_button_count++);
802 // get localized text for labels and titles
803 if ($attrib['title']) {
804 $attrib['title'] = Q(rcube_label($attrib['title'], $attrib['domain']));
806 if ($attrib['label']) {
807 $attrib['label'] = Q(rcube_label($attrib['label'], $attrib['domain']));
809 if ($attrib['alt']) {
810 $attrib['alt'] = Q(rcube_label($attrib['alt'], $attrib['domain']));
813 // set title to alt attribute for IE browsers
814 if ($this->browser->ie && !$attrib['title'] && $attrib['alt']) {
815 $attrib['title'] = $attrib['alt'];
818 // add empty alt attribute for XHTML compatibility
819 if (!isset($attrib['alt'])) {
823 // register button in the system
824 if ($attrib['command']) {
825 $this->add_script(sprintf(
826 "%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');",
831 $attrib['imageact'] ? $this->abs_url($attrib['imageact']) : $attrib['classact'],
832 $attrib['imagesel'] ? $this->abs_url($attrib['imagesel']) : $attrib['classsel'],
833 $attrib['imageover'] ? $this->abs_url($attrib['imageover']) : ''
836 // make valid href to specific buttons
837 if (in_array($attrib['command'], rcmail::$main_tasks)) {
838 $attrib['href'] = rcmail_url(null, null, $attrib['command']);
840 else if (in_array($attrib['command'], $a_static_commands)) {
841 $attrib['href'] = rcmail_url($attrib['command']);
843 else if ($attrib['command'] == 'permaurl' && !empty($this->env['permaurl'])) {
844 $attrib['href'] = $this->env['permaurl'];
848 // overwrite attributes
849 if (!$attrib['href']) {
850 $attrib['href'] = '#';
853 $attrib['onclick'] = sprintf(
854 "return %s.command('%s','%s',this)",
863 // generate image tag
864 if ($attrib['type']=='image') {
865 $attrib_str = html::attrib_string(
868 'style', 'class', 'id', 'width', 'height', 'border', 'hspace',
869 'vspace', 'align', 'alt', 'tabindex', 'title'
872 $btn_content = sprintf('<img src="%s"%s />', $this->abs_url($attrib['image']), $attrib_str);
873 if ($attrib['label']) {
874 $btn_content .= ' '.$attrib['label'];
876 $link_attrib = array('href', 'onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'target');
878 else if ($attrib['type']=='link') {
879 $btn_content = isset($attrib['content']) ? $attrib['content'] : ($attrib['label'] ? $attrib['label'] : $attrib['command']);
880 $link_attrib = array('href', 'onclick', 'title', 'id', 'class', 'style', 'tabindex', 'target');
882 else if ($attrib['type']=='input') {
883 $attrib['type'] = 'button';
885 if ($attrib['label']) {
886 $attrib['value'] = $attrib['label'];
889 $attrib_str = html::attrib_string(
892 'type', 'value', 'onclick', 'id', 'class', 'style', 'tabindex'
895 $out = sprintf('<input%s disabled="disabled" />', $attrib_str);
898 // generate html code for button
900 $attrib_str = html::attrib_string($attrib, $link_attrib);
901 $out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content);
908 /* ************* common functions delivering gui objects ************** */
912 * Create a form tag with the necessary hidden fields
914 * @param array Named tag parameters
915 * @return string HTML code for the form
917 public function form_tag($attrib, $content = null)
919 if ($this->framed || !empty($_REQUEST['_framed'])) {
920 $hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1'));
921 $hidden = $hiddenfield->show();
925 $attrib['noclose'] = true;
927 return html::tag('form',
928 $attrib + array('action' => "./", 'method' => "get"),
930 array('id','class','style','name','method','action','enctype','onsubmit'));
935 * Build a form tag with a unique request token
937 * @param array Named tag parameters including 'action' and 'task' values which will be put into hidden fields
938 * @param string Form content
939 * @return string HTML code for the form
941 public function request_form($attrib, $content = '')
943 $hidden = new html_hiddenfield();
944 if ($attrib['task']) {
945 $hidden->add(array('name' => '_task', 'value' => $attrib['task']));
947 if ($attrib['action']) {
948 $hidden->add(array('name' => '_action', 'value' => $attrib['action']));
951 unset($attrib['task'], $attrib['request']);
952 $attrib['action'] = './';
954 // we already have a <form> tag
956 return $hidden->show() . $content;
958 return $this->form_tag($attrib, $hidden->show() . $content);
963 * GUI object 'username'
964 * Showing IMAP username of the current session
966 * @param array Named tag parameters (currently not used)
967 * @return string HTML code for the gui object
969 public function current_username($attrib)
974 if (!empty($username)) {
978 // get e-mail address form default identity
979 if ($sql_arr = $this->app->user->get_identity()) {
980 $username = $sql_arr['email'];
983 $username = $this->app->user->get_username();
991 * GUI object 'loginform'
992 * Returns code for the webmail login form
994 * @param array Named parameters
995 * @return string HTML code for the gui object
997 private function login_form($attrib)
999 $default_host = $this->config['default_host'];
1001 $_SESSION['temp'] = true;
1003 // save original url
1004 $url = get_input_value('_url', RCUBE_INPUT_POST);
1005 if (empty($url) && !preg_match('/_(task|action)=logout/', $_SERVER['QUERY_STRING']))
1006 $url = $_SERVER['QUERY_STRING'];
1008 $input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30) + $attrib);
1009 $input_pass = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30) + $attrib);
1010 $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
1011 $input_tzone = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
1012 $input_url = new html_hiddenfield(array('name' => '_url', 'id' => 'rcmloginurl', 'value' => $url));
1015 if (is_array($default_host)) {
1016 $input_host = new html_select(array('name' => '_host', 'id' => 'rcmloginhost'));
1018 foreach ($default_host as $key => $value) {
1019 if (!is_array($value)) {
1020 $input_host->add($value, (is_numeric($key) ? $value : $key));
1028 else if (empty($default_host)) {
1029 $input_host = new html_inputfield(array('name' => '_host', 'id' => 'rcmloginhost', 'size' => 30));
1032 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
1033 $this->add_gui_object('loginform', $form_name);
1035 // create HTML table with two cols
1036 $table = new html_table(array('cols' => 2));
1038 $table->add('title', html::label('rcmloginuser', Q(rcube_label('username'))));
1039 $table->add(null, $input_user->show(get_input_value('_user', RCUBE_INPUT_POST)));
1041 $table->add('title', html::label('rcmloginpwd', Q(rcube_label('password'))));
1042 $table->add(null, $input_pass->show());
1044 // add host selection row
1045 if (is_object($input_host)) {
1046 $table->add('title', html::label('rcmloginhost', Q(rcube_label('server'))));
1047 $table->add(null, $input_host->show(get_input_value('_host', RCUBE_INPUT_POST)));
1050 $out = $input_action->show();
1051 $out .= $input_tzone->show();
1052 $out .= $input_url->show();
1053 $out .= $table->show();
1055 // surround html output with a form tag
1056 if (empty($attrib['form'])) {
1057 $out = $this->form_tag(array('name' => $form_name, 'method' => "post"), $out);
1065 * GUI object 'searchform'
1066 * Returns code for search function
1068 * @param array Named parameters
1069 * @return string HTML code for the gui object
1071 private function search_form($attrib)
1073 // add some labels to client
1074 $this->add_label('searching');
1076 $attrib['name'] = '_q';
1078 if (empty($attrib['id'])) {
1079 $attrib['id'] = 'rcmqsearchbox';
1081 if ($attrib['type'] == 'search' && !$this->browser->khtml) {
1082 unset($attrib['type'], $attrib['results']);
1085 $input_q = new html_inputfield($attrib);
1086 $out = $input_q->show();
1088 $this->add_gui_object('qsearchbox', $attrib['id']);
1090 // add form tag around text field
1091 if (empty($attrib['form'])) {
1092 $out = $this->form_tag(array(
1093 'name' => "rcmqsearchform",
1094 'onsubmit' => JS_OBJECT_NAME . ".command('search');return false;",
1095 'style' => "display:inline"),
1104 * Builder for GUI object 'message'
1106 * @param array Named tag parameters
1107 * @return string HTML code for the gui object
1109 private function message_container($attrib)
1111 if (isset($attrib['id']) === false) {
1112 $attrib['id'] = 'rcmMessageContainer';
1115 $this->add_gui_object('message', $attrib['id']);
1116 return html::div($attrib, "");
1121 * GUI object 'charsetselector'
1123 * @param array Named parameters for the select tag
1124 * @return string HTML code for the gui object
1126 static function charset_selector($attrib)
1128 // pass the following attributes to the form class
1129 $field_attrib = array('name' => '_charset');
1130 foreach ($attrib as $attr => $value) {
1131 if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) {
1132 $field_attrib[$attr] = $value;
1136 'US-ASCII' => 'ASCII (English)',
1137 'EUC-JP' => 'EUC-JP (Japanese)',
1138 'EUC-KR' => 'EUC-KR (Korean)',
1139 'BIG5' => 'BIG5 (Chinese)',
1140 'GB2312' => 'GB2312 (Chinese)',
1141 'ISO-2022-JP' => 'ISO-2022-JP (Japanese)',
1142 'ISO-8859-1' => 'ISO-8859-1 (Latin-1)',
1143 'ISO-8859-2' => 'ISO-8895-2 (Central European)',
1144 'ISO-8859-7' => 'ISO-8859-7 (Greek)',
1145 'ISO-8859-9' => 'ISO-8859-9 (Turkish)',
1146 'Windows-1251' => 'Windows-1251 (Cyrillic)',
1147 'Windows-1252' => 'Windows-1252 (Western)',
1148 'Windows-1255' => 'Windows-1255 (Hebrew)',
1149 'Windows-1256' => 'Windows-1256 (Arabic)',
1150 'Windows-1257' => 'Windows-1257 (Baltic)',
1154 $select = new html_select($field_attrib);
1155 $select->add(array_values($charsets), array_keys($charsets));
1157 $set = $_POST['_charset'] ? $_POST['_charset'] : $this->get_charset();
1158 return $select->show($set);
1161 } // end class rcube_template