alecpl
2012-01-06 e86a21bd83a0ae6cadfe9c919582951f306d3b64
commit | author | age
47124c 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/include/rcube_template.php                                    |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
044d66 8  | Copyright (C) 2006-2011, The Roundcube Dev Team                       |
47124c 9  | Licensed under the GNU GPL                                            |
T 10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Class to handle HTML page output using a skin template.             |
13  |   Extends rcube_html_page class from rcube_shared.inc                 |
14  |                                                                       |
15  +-----------------------------------------------------------------------+
16  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
17  +-----------------------------------------------------------------------+
18
19  $Id$
20
21  */
22
23
24 /**
25  * Class to create HTML page output using a skin template
26  *
27  * @package View
28  * @todo Documentation
29  * @uses rcube_html_page
30  */
31 class rcube_template extends rcube_html_page
32 {
1ac543 33     private $app;
A 34     private $config;
35     private $pagetitle = '';
36     private $message = null;
37     private $js_env = array();
4dcd43 38     private $js_labels = array();
1ac543 39     private $js_commands = array();
A 40     private $object_handlers = array();
fbe24e 41     private $plugin_skin_path;
8e99ff 42     private $template_name;
47124c 43
115158 44     public $browser;
1ac543 45     public $framed = false;
A 46     public $env = array();
c8a21d 47     public $type = 'html';
47124c 48     public $ajax_call = false;
T 49
7fcb56 50     // deprecated names of templates used before 0.5
T 51     private $deprecated_templates = array(
52         'contact' => 'showcontact',
53         'contactadd' => 'addcontact',
54         'contactedit' => 'editcontact',
55         'identityedit' => 'editidentity',
56         'messageprint' => 'printmessage',
57     );
58
47124c 59     /**
T 60      * Constructor
61      *
197601 62      * @todo   Replace $this->config with the real rcube_config object
47124c 63      */
197601 64     public function __construct($task, $framed = false)
47124c 65     {
T 66         parent::__construct();
67
197601 68         $this->app = rcmail::get_instance();
T 69         $this->config = $this->app->config->all();
a3f149 70         $this->browser = new rcube_browser();
ad334a 71
197601 72         //$this->framed = $framed;
83a763 73         $this->set_env('task', $task);
10e2db 74         $this->set_env('x_frame_options', $this->app->config->get('x_frame_options', 'sameorigin'));
47124c 75
423065 76         // load the correct skin (in case user-defined)
T 77         $this->set_skin($this->config['skin']);
e58df3 78
47124c 79         // add common javascripts
79cd6c 80         $this->add_script('var '.JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top');
47124c 81
T 82         // don't wait for page onload. Call init at the bottom of the page (delayed)
044d66 83         $this->add_script(JS_OBJECT_NAME.'.init();', 'docready');
47124c 84
T 85         $this->scripts_path = 'program/js/';
79275b 86         $this->include_script('jquery.min.js');
47124c 87         $this->include_script('common.js');
T 88         $this->include_script('app.js');
89
90         // register common UI objects
91         $this->add_handlers(array(
92             'loginform'       => array($this, 'login_form'),
8e211a 93             'preloader'       => array($this, 'preloader'),
47124c 94             'username'        => array($this, 'current_username'),
T 95             'message'         => array($this, 'message_container'),
96             'charsetselector' => array($this, 'charset_selector'),
1a0f60 97             'aboutcontent'    => array($this, 'about_content'),
47124c 98         ));
T 99     }
100
101     /**
102      * Set environment variable
103      *
104      * @param string Property name
105      * @param mixed Property value
106      * @param boolean True if this property should be added to client environment
107      */
108     public function set_env($name, $value, $addtojs = true)
109     {
110         $this->env[$name] = $value;
111         if ($addtojs || isset($this->js_env[$name])) {
112             $this->js_env[$name] = $value;
113         }
114     }
115
116     /**
117      * Set page title variable
118      */
119     public function set_pagetitle($title)
120     {
121         $this->pagetitle = $title;
122     }
f645ce 123
T 124     /**
125      * Getter for the current page title
126      *
127      * @return string The page title
128      */
129     public function get_pagetitle()
130     {
131         if (!empty($this->pagetitle)) {
132             $title = $this->pagetitle;
133         }
134         else if ($this->env['task'] == 'login') {
135             $title = rcube_label(array('name' => 'welcome', 'vars' => array('product' => $this->config['product_name'])));
136         }
137         else {
138             $title = ucfirst($this->env['task']);
139         }
ad334a 140
f645ce 141         return $title;
T 142     }
143
e58df3 144     /**
A 145      * Set skin
146      */
147     public function set_skin($skin)
148     {
62c791 149         $valid = false;
ad334a 150
62c791 151         if (!empty($skin) && is_dir('skins/'.$skin) && is_readable('skins/'.$skin)) {
423065 152             $skin_path = 'skins/'.$skin;
62c791 153             $valid = true;
T 154         }
155         else {
423065 156             $skin_path = $this->config['skin_path'] ? $this->config['skin_path'] : 'skins/default';
62c791 157             $valid = !$skin;
T 158         }
423065 159
T 160         $this->app->config->set('skin_path', $skin_path);
161         $this->config['skin_path'] = $skin_path;
ad334a 162
62c791 163         return $valid;
e58df3 164     }
A 165
166     /**
167      * Check if a specific template exists
168      *
169      * @param string Template name
170      * @return boolean True if template exists
171      */
172     public function template_exists($name)
173     {
423065 174         $filename = $this->config['skin_path'] . '/templates/' . $name . '.html';
7fcb56 175         return (is_file($filename) && is_readable($filename)) || ($this->deprecated_templates[$name] && $this->template_exists($this->deprecated_templates[$name]));
e58df3 176     }
47124c 177
T 178     /**
179      * Register a template object handler
180      *
181      * @param  string Object name
182      * @param  string Function name to call
183      * @return void
184      */
185     public function add_handler($obj, $func)
186     {
187         $this->object_handlers[$obj] = $func;
188     }
189
190     /**
191      * Register a list of template object handlers
192      *
193      * @param  array Hash array with object=>handler pairs
194      * @return void
195      */
196     public function add_handlers($arr)
197     {
198         $this->object_handlers = array_merge($this->object_handlers, $arr);
199     }
200
201     /**
202      * Register a GUI object to the client script
203      *
204      * @param  string Object name
205      * @param  string Object ID
206      * @return void
207      */
208     public function add_gui_object($obj, $id)
209     {
210         $this->add_script(JS_OBJECT_NAME.".gui_object('$obj', '$id');");
211     }
212
213     /**
214      * Call a client method
215      *
216      * @param string Method to call
217      * @param ... Additional arguments
218      */
219     public function command()
220     {
0e99d3 221         $cmd = func_get_args();
f66383 222         if (strpos($cmd[0], 'plugin.') !== false)
T 223           $this->js_commands[] = array('triggerEvent', $cmd[0], $cmd[1]);
224         else
0e99d3 225           $this->js_commands[] = $cmd;
47124c 226     }
T 227
228     /**
229      * Add a localized label to the client environment
230      */
231     public function add_label()
232     {
cc97ea 233         $args = func_get_args();
T 234         if (count($args) == 1 && is_array($args[0]))
235           $args = $args[0];
ad334a 236
cc97ea 237         foreach ($args as $name) {
4dcd43 238             $this->js_labels[$name] = rcube_label($name);
47124c 239         }
T 240     }
241
242     /**
243      * Invoke display_message command
244      *
7f5a84 245      * @param string  $message  Message to display
A 246      * @param string  $type     Message type [notice|confirm|error]
247      * @param array   $vars     Key-value pairs to be replaced in localized text
248      * @param boolean $override Override last set message
249      * @param int     $timeout  Message display time in seconds
47124c 250      * @uses self::command()
T 251      */
7f5a84 252     public function show_message($message, $type='notice', $vars=null, $override=true, $timeout=0)
47124c 253     {
69f18a 254         if ($override || !$this->message) {
8dd172 255             if (rcube_label_exists($message)) {
A 256                 if (!empty($vars))
257                     $vars = array_map('Q', $vars);
258                 $msgtext = rcube_label(array('name' => $message, 'vars' => $vars));
259             }
260             else
261                 $msgtext = $message;
262
69f18a 263             $this->message = $message;
7f5a84 264             $this->command('display_message', $msgtext, $type, $timeout * 1000);
69f18a 265         }
47124c 266     }
T 267
268     /**
269      * Delete all stored env variables and commands
270      *
271      * @return void
272      * @uses   rcube_html::reset()
273      * @uses   self::$env
274      * @uses   self::$js_env
275      * @uses   self::$js_commands
276      * @uses   self::$object_handlers
277      */
c719f3 278     public function reset()
47124c 279     {
T 280         $this->env = array();
281         $this->js_env = array();
4dcd43 282         $this->js_labels = array();
47124c 283         $this->js_commands = array();
T 284         $this->object_handlers = array();
285         parent::reset();
286     }
287
288     /**
c719f3 289      * Redirect to a certain url
T 290      *
291      * @param mixed Either a string with the action or url parameters as key-value pairs
292      * @see rcmail::url()
293      */
294     public function redirect($p = array())
295     {
296         $location = $this->app->url($p);
297         header('Location: ' . $location);
298         exit;
299     }
300
301     /**
47124c 302      * Send the request output to the client.
T 303      * This will either parse a skin tempalte or send an AJAX response
304      *
305      * @param string  Template name
306      * @param boolean True if script should terminate (default)
307      */
308     public function send($templ = null, $exit = true)
309     {
310         if ($templ != 'iframe') {
a366a3 311             // prevent from endless loops
f78dab 312             if ($exit != 'recur' && $this->app->plugins->is_processing('render_page')) {
10eedb 313                 raise_error(array('code' => 505, 'type' => 'php',
030db5 314                   'file' => __FILE__, 'line' => __LINE__,
T 315                   'message' => 'Recursion alert: ignoring output->send()'), true, false);
a366a3 316                 return;
T 317             }
47124c 318             $this->parse($templ, false);
T 319         }
320         else {
321             $this->framed = $templ == 'iframe' ? true : $this->framed;
322             $this->write();
323         }
324
c6514e 325         // set output asap
T 326         ob_flush();
327         flush();
ad334a 328
c6514e 329         if ($exit) {
47124c 330             exit;
T 331         }
332     }
333
334     /**
335      * Process template and write to stdOut
336      *
337      * @param string HTML template
338      * @see rcube_html_page::write()
339      * @override
340      */
341     public function write($template = '')
342     {
343         // unlock interface after iframe load
5bfa44 344         $unlock = preg_replace('/[^a-z0-9]/i', '', $_REQUEST['_unlock']);
47124c 345         if ($this->framed) {
ad334a 346             array_unshift($this->js_commands, array('set_busy', false, null, $unlock));
A 347         }
348         else if ($unlock) {
349             array_unshift($this->js_commands, array('hide_message', $unlock));
47124c 350         }
ef27a6 351
49dac9 352         if (!empty($this->script_files))
T 353           $this->set_env('request_token', $this->app->get_request_token());
ef27a6 354
47124c 355         // write all env variables to client
T 356         $js = $this->framed ? "if(window.parent) {\n" : '';
357         $js .= $this->get_js_commands() . ($this->framed ? ' }' : '');
358         $this->add_script($js, 'head_top');
ad334a 359
c170bf 360         // send clickjacking protection headers
T 361         $iframe = $this->framed || !empty($_REQUEST['_framed']);
362         if (!headers_sent() && ($xframe = $this->app->config->get('x_frame_options', 'sameorigin')))
363             header('X-Frame-Options: ' . ($iframe && $xframe == 'deny' ? 'sameorigin' : $xframe));
47124c 364
T 365         // call super method
366         parent::write($template, $this->config['skin_path']);
367     }
368
369     /**
c739c7 370      * Parse a specific skin template and deliver to stdout (or return)
47124c 371      *
T 372      * @param  string  Template name
373      * @param  boolean Exit script
c739c7 374      * @param  boolean Don't write to stdout, return parsed content instead
A 375      *
47124c 376      * @link   http://php.net/manual/en/function.exit.php
T 377      */
c739c7 378     function parse($name = 'main', $exit = true, $write = true)
47124c 379     {
T 380         $skin_path = $this->config['skin_path'];
ca18a9 381         $plugin    = false;
A 382         $realname  = $name;
383         $temp      = explode('.', $name, 2);
8e99ff 384
fbe24e 385         $this->plugin_skin_path = null;
8e99ff 386         $this->template_name    = $realname;
ad334a 387
e7008c 388         if (count($temp) > 1) {
ca18a9 389             $plugin    = $temp[0];
A 390             $name      = $temp[1];
391             $skin_dir  = $plugin . '/skins/' . $this->config['skin'];
fbe24e 392             $skin_path = $this->plugin_skin_path = $this->app->plugins->dir . $skin_dir;
ca18a9 393
A 394             // fallback to default skin
395             if (!is_dir($skin_path)) {
20d50d 396                 $skin_dir = $plugin . '/skins/default';
fbe24e 397                 $skin_path = $this->plugin_skin_path = $this->app->plugins->dir . $skin_dir;
20d50d 398             }
e7008c 399         }
ad334a 400
e7008c 401         $path = "$skin_path/templates/$name.html";
47124c 402
ca18a9 403         if (!is_readable($path) && $this->deprecated_templates[$realname]) {
A 404             $path = "$skin_path/templates/".$this->deprecated_templates[$realname].".html";
7fcb56 405             if (is_readable($path))
T 406                 raise_error(array('code' => 502, 'type' => 'php',
407                     'file' => __FILE__, 'line' => __LINE__,
ca18a9 408                     'message' => "Using deprecated template '".$this->deprecated_templates[$realname]
A 409                         ."' in ".$this->config['skin_path']."/templates. Please rename to '".$realname."'"),
7fcb56 410                 true, false);
T 411         }
412
ff73e0 413         // read template file
7f22f2 414         if (($templ = @file_get_contents($path)) === false) {
f92b2f 415             raise_error(array(
47124c 416                 'code' => 501,
T 417                 'type' => 'php',
418                 'line' => __LINE__,
419                 'file' => __FILE__,
ca18a9 420                 'message' => 'Error loading template for '.$realname
47124c 421                 ), true, true);
T 422             return false;
423         }
ad334a 424
66f68e 425         // replace all path references to plugins/... with the configured plugins dir
T 426         // and /this/ to the current plugin skin directory
e7008c 427         if ($plugin) {
20d50d 428             $templ = preg_replace(array('/\bplugins\//', '/(["\']?)\/this\//'), array($this->app->plugins->url, '\\1'.$this->app->plugins->url.$skin_dir.'/'), $templ);
e7008c 429         }
47124c 430
T 431         // parse for specialtags
432         $output = $this->parse_conditions($templ);
433         $output = $this->parse_xml($output);
ad334a 434
742d61 435         // trigger generic hook where plugins can put additional content to the page
ca18a9 436         $hook = $this->app->plugins->exec_hook("render_page", array('template' => $realname, 'content' => $output));
47124c 437
e4a4ca 438         // save some memory
A 439         $output = $hook['content'];
440         unset($hook['content']);
441
442         $output = $this->parse_with_globals($output);
c739c7 443
5172ac 444         // make sure all <form> tags have a valid request token
T 445         $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output);
446         $this->footer = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $this->footer);
447
c739c7 448         if ($write) {
A 449             // add debug console
9e443d 450             if ($realname != 'error' && ($this->config['debug_level'] & 8)) {
909a3a 451                 $this->add_footer('<div id="console" style="position:absolute;top:5px;left:5px;width:405px;padding:2px;background:white;z-index:9000;display:none">
c739c7 452                     <a href="#toggle" onclick="con=$(\'#dbgconsole\');con[con.is(\':visible\')?\'hide\':\'show\']();return false">console</a>
f23073 453                     <textarea name="console" id="dbgconsole" rows="20" cols="40" style="display:none;width:400px;border:none;font-size:10px" spellcheck="false"></textarea></div>'
c739c7 454                 );
909a3a 455                 $this->add_script(
A 456                     "if (!window.console || !window.console.log) {\n".
457                     "  window.console = new rcube_console();\n".
458                     "  $('#console').show();\n".
459                     "}", 'foot');
c739c7 460             }
A 461             $this->write(trim($output));
462         }
463         else {
464             return $output;
47124c 465         }
ad334a 466
47124c 467         if ($exit) {
T 468             exit;
469         }
470     }
471
472     /**
473      * Return executable javascript code for all registered commands
474      *
475      * @return string $out
476      */
477     private function get_js_commands()
478     {
479         $out = '';
480         if (!$this->framed && !empty($this->js_env)) {
2717f9 481             $out .= JS_OBJECT_NAME . '.set_env('.json_serialize($this->js_env).");\n";
47124c 482         }
4dcd43 483         if (!empty($this->js_labels)) {
T 484             $this->command('add_label', $this->js_labels);
485         }
47124c 486         foreach ($this->js_commands as $i => $args) {
T 487             $method = array_shift($args);
488             foreach ($args as $i => $arg) {
2717f9 489                 $args[$i] = json_serialize($arg);
47124c 490             }
T 491             $parent = $this->framed || preg_match('/^parent\./', $method);
492             $out .= sprintf(
493                 "%s.%s(%s);\n",
cc97ea 494                 ($parent ? 'if(window.parent && parent.'.JS_OBJECT_NAME.') parent.' : '') . JS_OBJECT_NAME,
T 495                 preg_replace('/^parent\./', '', $method),
496                 implode(',', $args)
47124c 497             );
T 498         }
ad334a 499
47124c 500         return $out;
T 501     }
502
503     /**
504      * Make URLs starting with a slash point to skin directory
505      *
506      * @param  string Input string
507      * @return string
508      */
509     public function abs_url($str)
510     {
2aa2b3 511         if ($str[0] == '/')
A 512             return $this->config['skin_path'] . $str;
513         else
514             return $str;
47124c 515     }
T 516
517
518     /*****  Template parsing methods  *****/
519
520     /**
521      * Replace all strings ($varname)
522      * with the content of the according global variable.
523      */
524     private function parse_with_globals($input)
525     {
533e86 526         $GLOBALS['__version'] = Q(RCMAIL_VERSION);
197601 527         $GLOBALS['__comm_path'] = Q($this->app->comm_path);
5740c0 528         return preg_replace_callback('/\$(__[a-z0-9_\-]+)/',
A 529         array($this, 'globals_callback'), $input);
530     }
531
532     /**
533      * Callback funtion for preg_replace_callback() in parse_with_globals()
534      */
535     private function globals_callback($matches)
536     {
537         return $GLOBALS[$matches[1]];
47124c 538     }
T 539
540     /**
541      * Public wrapper to dipp into template parsing.
542      *
543      * @param  string $input
544      * @return string
545      * @uses   rcube_template::parse_xml()
546      * @since  0.1-rc1
547      */
548     public function just_parse($input)
549     {
550         return $this->parse_xml($input);
551     }
552
553     /**
554      * Parse for conditional tags
555      *
556      * @param  string $input
557      * @return string
558      */
559     private function parse_conditions($input)
560     {
84581e 561         $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>\n?/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE);
47124c 562         if ($matches && count($matches) == 4) {
T 563             if (preg_match('/^(else|endif)$/i', $matches[1])) {
564                 return $matches[0] . $this->parse_conditions($matches[3]);
565             }
566             $attrib = parse_attrib_string($matches[2]);
567             if (isset($attrib['condition'])) {
568                 $condmet = $this->check_condition($attrib['condition']);
84581e 569                 $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>\n?/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE);
47124c 570                 if ($condmet) {
T 571                     $result = $submatches[0];
84581e 572                     $result.= ($submatches[1] != 'endif' ? preg_replace('/.*<roundcube:endif\s+[^>]+>\n?/Uis', '', $submatches[3], 1) : $submatches[3]);
47124c 573                 }
T 574                 else {
575                     $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3];
576                 }
577                 return $matches[0] . $this->parse_conditions($result);
578             }
f92b2f 579             raise_error(array(
47124c 580                 'code' => 500,
T 581                 'type' => 'php',
582                 'line' => __LINE__,
583                 'file' => __FILE__,
584                 'message' => "Unable to parse conditional tag " . $matches[2]
585             ), true, false);
586         }
587         return $input;
588     }
589
590
591     /**
592      * Determines if a given condition is met
593      *
594      * @todo   Get rid off eval() once I understand what this does.
595      * @todo   Extend this to allow real conditions, not just "set"
596      * @param  string Condition statement
8e1d4a 597      * @return boolean True if condition is met, False if not
47124c 598      */
T 599     private function check_condition($condition)
600     {
549933 601         return eval("return (".$this->parse_expression($condition).");");
T 602     }
ad334a 603
A 604
549933 605     /**
2eb794 606      * Inserts hidden field with CSRF-prevention-token into POST forms
549933 607      */
T 608     private function alter_form_tag($matches)
609     {
610         $out = $matches[0];
611         $attrib  = parse_attrib_string($matches[1]);
ad334a 612
549933 613         if (strtolower($attrib['method']) == 'post') {
T 614             $hidden = new html_hiddenfield(array('name' => '_token', 'value' => $this->app->get_request_token()));
615             $out .= "\n" . $hidden->show();
616         }
ad334a 617
549933 618         return $out;
8e1d4a 619     }
A 620
621
622     /**
623      * Parses expression and replaces variables
624      *
625      * @param  string Expression statement
030db5 626      * @return string Expression value
8e1d4a 627      */
A 628     private function parse_expression($expression)
629     {
630         return preg_replace(
47124c 631             array(
T 632                 '/session:([a-z0-9_]+)/i',
f645ce 633                 '/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i',
40353f 634                 '/env:([a-z0-9_]+)/i',
A 635                 '/request:([a-z0-9_]+)/i',
636                 '/cookie:([a-z0-9_]+)/i',
8e99ff 637                 '/browser:([a-z0-9_]+)/i',
A 638                 '/template:name/i',
47124c 639             ),
T 640             array(
641                 "\$_SESSION['\\1']",
f645ce 642                 "\$this->app->config->get('\\1',get_boolean('\\3'))",
47124c 643                 "\$this->env['\\1']",
ea373f 644                 "get_input_value('\\1', RCUBE_INPUT_GPC)",
a17fe6 645                 "\$_COOKIE['\\1']",
8e99ff 646                 "\$this->browser->{'\\1'}",
A 647                 $this->template_name,
47124c 648             ),
8e1d4a 649             $expression);
47124c 650     }
T 651
652
653     /**
654      * Search for special tags in input and replace them
655      * with the appropriate content
656      *
657      * @param  string Input string to parse
658      * @return string Altered input string
06655a 659      * @todo   Use DOM-parser to traverse template HTML
47124c 660      * @todo   Maybe a cache.
T 661      */
662     private function parse_xml($input)
663     {
6af593 664         return preg_replace_callback('/<roundcube:([-_a-z]+)\s+((?:[^>]|\\\\>)+)(?<!\\\\)>/Ui', array($this, 'xml_command'), $input);
6f488b 665     }
A 666
667
668     /**
cc97ea 669      * Callback function for parsing an xml command tag
T 670      * and turn it into real html content
47124c 671      *
cc97ea 672      * @param  array Matches array of preg_replace_callback
47124c 673      * @return string Tag/Object content
T 674      */
cc97ea 675     private function xml_command($matches)
47124c 676     {
cc97ea 677         $command = strtolower($matches[1]);
T 678         $attrib  = parse_attrib_string($matches[2]);
47124c 679
T 680         // empty output if required condition is not met
681         if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
682             return '';
683         }
684
685         // execute command
686         switch ($command) {
687             // return a button
688             case 'button':
875a48 689                 if ($attrib['name'] || $attrib['command']) {
47124c 690                     return $this->button($attrib);
T 691                 }
692                 break;
693
694             // show a label
695             case 'label':
696                 if ($attrib['name'] || $attrib['command']) {
c87806 697                     $vars = $attrib + array('product' => $this->config['product_name']);
T 698                     unset($vars['name'], $vars['command']);
699                     $label = rcube_label($attrib + array('vars' => $vars));
0c1cb2 700                     return !$attrib['noshow'] ? (get_boolean((string)$attrib['html']) ? $label : Q($label)) : '';
47124c 701                 }
T 702                 break;
703
704             // include a file
705             case 'include':
fbe24e 706                 if (!$this->plugin_skin_path || !is_file($path = realpath($this->plugin_skin_path . $attrib['file'])))
T 707                     $path = realpath(($attrib['skin_path'] ? $attrib['skin_path'] : $this->config['skin_path']).$attrib['file']);
708                 
ff73e0 709                 if (is_readable($path)) {
47124c 710                     if ($this->config['skin_include_php']) {
T 711                         $incl = $this->include_php($path);
712                     }
ff73e0 713                     else {
cc97ea 714                       $incl = file_get_contents($path);
T 715                     }
b4f7c6 716                     $incl = $this->parse_conditions($incl);
47124c 717                     return $this->parse_xml($incl);
T 718                 }
719                 break;
720
721             case 'plugin.include':
cc97ea 722                 $hook = $this->app->plugins->exec_hook("template_plugin_include", $attrib);
T 723                 return $hook['content'];
724                 break;
ad334a 725
cc97ea 726             // define a container block
T 727             case 'container':
728                 if ($attrib['name'] && $attrib['id']) {
729                     $this->command('gui_container', $attrib['name'], $attrib['id']);
730                     // let plugins insert some content here
731                     $hook = $this->app->plugins->exec_hook("template_container", $attrib);
732                     return $hook['content'];
47124c 733                 }
T 734                 break;
735
736             // return code for a specific application object
737             case 'object':
738                 $object = strtolower($attrib['name']);
cc97ea 739                 $content = '';
47124c 740
T 741                 // we are calling a class/method
742                 if (($handler = $this->object_handlers[$object]) && is_array($handler)) {
743                     if ((is_object($handler[0]) && method_exists($handler[0], $handler[1])) ||
744                     (is_string($handler[0]) && class_exists($handler[0])))
cc97ea 745                     $content = call_user_func($handler, $attrib);
47124c 746                 }
cc97ea 747                 // execute object handler function
47124c 748                 else if (function_exists($handler)) {
cc97ea 749                     $content = call_user_func($handler, $attrib);
47124c 750                 }
f23073 751                 else if ($object == 'doctype') {
T 752                     $content = html::doctype($attrib['value']);
753                 }
ae39c4 754                 else if ($object == 'logo') {
T 755                     $attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"')));
756                     if ($this->config['skin_logo'])
757                         $attrib['src'] = $this->config['skin_logo'];
758                     $content = html::img($attrib);
759                 }
cc97ea 760                 else if ($object == 'productname') {
e019f2 761                     $name = !empty($this->config['product_name']) ? $this->config['product_name'] : 'Roundcube Webmail';
cc97ea 762                     $content = Q($name);
47124c 763                 }
cc97ea 764                 else if ($object == 'version') {
c8fb2b 765                     $ver = (string)RCMAIL_VERSION;
T 766                     if (is_file(INSTALL_PATH . '.svn/entries')) {
767                         if (preg_match('/Revision:\s(\d+)/', @shell_exec('svn info'), $regs))
768                           $ver .= ' [SVN r'.$regs[1].']';
769                     }
cc97ea 770                     $content = Q($ver);
47124c 771                 }
cc97ea 772                 else if ($object == 'steptitle') {
T 773                   $content = Q($this->get_pagetitle());
f645ce 774                 }
cc97ea 775                 else if ($object == 'pagetitle') {
159763 776                     if (!empty($this->config['devel_mode']) && !empty($_SESSION['username']))
A 777                       $title = $_SESSION['username'].' :: ';
778                     else if (!empty($this->config['product_name']))
779                       $title = $this->config['product_name'].' :: ';
780                     else
781                       $title = '';
f645ce 782                     $title .= $this->get_pagetitle();
cc97ea 783                     $content = Q($title);
47124c 784                 }
ad334a 785
cc97ea 786                 // exec plugin hooks for this template object
T 787                 $hook = $this->app->plugins->exec_hook("template_object_$object", $attrib + array('content' => $content));
788                 return $hook['content'];
8e1d4a 789
A 790             // return code for a specified eval expression
791             case 'exp':
cc97ea 792                 $value = $this->parse_expression($attrib['expression']);
8e1d4a 793                 return eval("return Q($value);");
ad334a 794
47124c 795             // return variable
T 796             case 'var':
797                 $var = explode(':', $attrib['name']);
798                 $name = $var[1];
799                 $value = '';
800
801                 switch ($var[0]) {
802                     case 'env':
803                         $value = $this->env[$name];
804                         break;
805                     case 'config':
806                         $value = $this->config[$name];
807                         if (is_array($value) && $value[$_SESSION['imap_host']]) {
808                             $value = $value[$_SESSION['imap_host']];
809                         }
810                         break;
811                     case 'request':
812                         $value = get_input_value($name, RCUBE_INPUT_GPC);
813                         break;
814                     case 'session':
815                         $value = $_SESSION[$name];
816                         break;
d4273b 817                     case 'cookie':
A 818                         $value = htmlspecialchars($_COOKIE[$name]);
819                         break;
a17fe6 820                     case 'browser':
A 821                         $value = $this->browser->{$name};
822                         break;
47124c 823                 }
T 824
825                 if (is_array($value)) {
826                     $value = implode(', ', $value);
827                 }
828
829                 return Q($value);
830                 break;
831         }
832         return '';
833     }
834
835     /**
836      * Include a specific file and return it's contents
837      *
838      * @param string File path
839      * @return string Contents of the processed file
840      */
841     private function include_php($file)
842     {
843         ob_start();
844         include $file;
845         $out = ob_get_contents();
846         ob_end_clean();
847
848         return $out;
849     }
850
851     /**
852      * Create and register a button
853      *
854      * @param  array Named button attributes
855      * @return string HTML button
856      * @todo   Remove all inline JS calls and use jQuery instead.
857      * @todo   Remove all sprintf()'s - they are pretty, but also slow.
858      */
ed132e 859     public function button($attrib)
47124c 860     {
T 861         static $s_button_count = 100;
862
863         // these commands can be called directly via url
cc97ea 864         $a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities');
47124c 865
T 866         if (!($attrib['command'] || $attrib['name'])) {
867             return '';
868         }
ae0c82 869
47124c 870         // try to find out the button type
T 871         if ($attrib['type']) {
872             $attrib['type'] = strtolower($attrib['type']);
873         }
874         else {
875             $attrib['type'] = ($attrib['image'] || $attrib['imagepas'] || $attrib['imageact']) ? 'image' : 'link';
876         }
e9b5a6 877
47124c 878         $command = $attrib['command'];
T 879
e9b5a6 880         if ($attrib['task'])
T 881           $command = $attrib['task'] . '.' . $command;
ad334a 882
af3cf8 883         if (!$attrib['image']) {
T 884             $attrib['image'] = $attrib['imagepas'] ? $attrib['imagepas'] : $attrib['imageact'];
885         }
47124c 886
T 887         if (!$attrib['id']) {
888             $attrib['id'] =  sprintf('rcmbtn%d', $s_button_count++);
889         }
890         // get localized text for labels and titles
891         if ($attrib['title']) {
1c932d 892             $attrib['title'] = Q(rcube_label($attrib['title'], $attrib['domain']));
47124c 893         }
T 894         if ($attrib['label']) {
1c932d 895             $attrib['label'] = Q(rcube_label($attrib['label'], $attrib['domain']));
47124c 896         }
T 897         if ($attrib['alt']) {
1c932d 898             $attrib['alt'] = Q(rcube_label($attrib['alt'], $attrib['domain']));
47124c 899         }
9b2ccd 900
47124c 901         // set title to alt attribute for IE browsers
c9e9fe 902         if ($this->browser->ie && !$attrib['title'] && $attrib['alt']) {
A 903             $attrib['title'] = $attrib['alt'];
47124c 904         }
T 905
906         // add empty alt attribute for XHTML compatibility
907         if (!isset($attrib['alt'])) {
908             $attrib['alt'] = '';
909         }
910
911         // register button in the system
912         if ($attrib['command']) {
913             $this->add_script(sprintf(
914                 "%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');",
915                 JS_OBJECT_NAME,
916                 $command,
917                 $attrib['id'],
918                 $attrib['type'],
ae0c82 919                 $attrib['imageact'] ? $this->abs_url($attrib['imageact']) : $attrib['classact'],
A 920                 $attrib['imagesel'] ? $this->abs_url($attrib['imagesel']) : $attrib['classsel'],
921                 $attrib['imageover'] ? $this->abs_url($attrib['imageover']) : ''
47124c 922             ));
T 923
924             // make valid href to specific buttons
197601 925             if (in_array($attrib['command'], rcmail::$main_tasks)) {
203ee4 926                 $attrib['href'] = rcmail_url(null, null, $attrib['command']);
ef22ee 927                 $attrib['onclick'] = sprintf("%s.switch_task('%s');return false", JS_OBJECT_NAME, $attrib['command']);
47124c 928             }
e9b5a6 929             else if ($attrib['task'] && in_array($attrib['task'], rcmail::$main_tasks)) {
T 930                 $attrib['href'] = rcmail_url($attrib['command'], null, $attrib['task']);
931             }
47124c 932             else if (in_array($attrib['command'], $a_static_commands)) {
203ee4 933                 $attrib['href'] = rcmail_url($attrib['command']);
a25d39 934             }
29f977 935             else if ($attrib['command'] == 'permaurl' && !empty($this->env['permaurl'])) {
T 936               $attrib['href'] = $this->env['permaurl'];
937             }
47124c 938         }
T 939
940         // overwrite attributes
941         if (!$attrib['href']) {
942             $attrib['href'] = '#';
943         }
e9b5a6 944         if ($attrib['task']) {
T 945             if ($attrib['classact'])
946                 $attrib['class'] = $attrib['classact'];
947         }
948         else if ($command && !$attrib['onclick']) {
47124c 949             $attrib['onclick'] = sprintf(
T 950                 "return %s.command('%s','%s',this)",
951                 JS_OBJECT_NAME,
952                 $command,
953                 $attrib['prop']
954             );
955         }
956
957         $out = '';
958
959         // generate image tag
960         if ($attrib['type']=='image') {
961             $attrib_str = html::attrib_string(
962                 $attrib,
963                 array(
c9e9fe 964                     'style', 'class', 'id', 'width', 'height', 'border', 'hspace',
A 965                     'vspace', 'align', 'alt', 'tabindex', 'title'
47124c 966                 )
T 967             );
ae0c82 968             $btn_content = sprintf('<img src="%s"%s />', $this->abs_url($attrib['image']), $attrib_str);
47124c 969             if ($attrib['label']) {
T 970                 $btn_content .= ' '.$attrib['label'];
971             }
c9e9fe 972             $link_attrib = array('href', 'onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'target');
47124c 973         }
T 974         else if ($attrib['type']=='link') {
356a67 975             $btn_content = isset($attrib['content']) ? $attrib['content'] : ($attrib['label'] ? $attrib['label'] : $attrib['command']);
203ee4 976             $link_attrib = array('href', 'onclick', 'title', 'id', 'class', 'style', 'tabindex', 'target');
5587b3 977             if ($attrib['innerclass'])
T 978                 $btn_content = html::span($attrib['innerclass'], $btn_content);
47124c 979         }
T 980         else if ($attrib['type']=='input') {
981             $attrib['type'] = 'button';
982
983             if ($attrib['label']) {
984                 $attrib['value'] = $attrib['label'];
985             }
f94e44 986             if ($attrib['command']) {
T 987               $attrib['disabled'] = 'disabled';
988             }
47124c 989
f94e44 990             $out = html::tag('input', $attrib, '', array('type', 'value', 'onclick', 'id', 'class', 'style', 'tabindex', 'disabled'));
47124c 991         }
T 992
993         // generate html code for button
994         if ($btn_content) {
995             $attrib_str = html::attrib_string($attrib, $link_attrib);
996             $out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content);
997         }
998
999         return $out;
1000     }
1001
1002
1003     /*  ************* common functions delivering gui objects **************  */
1004
1005
1006     /**
197601 1007      * Create a form tag with the necessary hidden fields
T 1008      *
1009      * @param array Named tag parameters
1010      * @return string HTML code for the form
1011      */
1012     public function form_tag($attrib, $content = null)
1013     {
57f0c8 1014       if ($this->framed || !empty($_REQUEST['_framed'])) {
197601 1015         $hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1'));
T 1016         $hidden = $hiddenfield->show();
1017       }
ad334a 1018
197601 1019       if (!$content)
T 1020         $attrib['noclose'] = true;
ad334a 1021
197601 1022       return html::tag('form',
T 1023         $attrib + array('action' => "./", 'method' => "get"),
57f0c8 1024         $hidden . $content,
T 1025         array('id','class','style','name','method','action','enctype','onsubmit'));
1026     }
ad334a 1027
A 1028
57f0c8 1029     /**
T 1030      * Build a form tag with a unique request token
1031      *
1032      * @param array Named tag parameters including 'action' and 'task' values which will be put into hidden fields
1033      * @param string Form content
1034      * @return string HTML code for the form
1035      */
747797 1036     public function request_form($attrib, $content = '')
57f0c8 1037     {
T 1038         $hidden = new html_hiddenfield();
1039         if ($attrib['task']) {
1040             $hidden->add(array('name' => '_task', 'value' => $attrib['task']));
1041         }
1042         if ($attrib['action']) {
1043             $hidden->add(array('name' => '_action', 'value' => $attrib['action']));
1044         }
ad334a 1045
57f0c8 1046         unset($attrib['task'], $attrib['request']);
T 1047         $attrib['action'] = './';
ad334a 1048
57f0c8 1049         // we already have a <form> tag
0501b6 1050         if ($attrib['form']) {
T 1051             if ($this->framed || !empty($_REQUEST['_framed']))
1052                 $hidden->add(array('name' => '_framed', 'value' => '1'));
57f0c8 1053             return $hidden->show() . $content;
0501b6 1054         }
57f0c8 1055         else
T 1056             return $this->form_tag($attrib, $hidden->show() . $content);
197601 1057     }
T 1058
1059
1060     /**
47124c 1061      * GUI object 'username'
T 1062      * Showing IMAP username of the current session
1063      *
1064      * @param array Named tag parameters (currently not used)
1065      * @return string HTML code for the gui object
1066      */
197601 1067     public function current_username($attrib)
47124c 1068     {
T 1069         static $username;
1070
1071         // alread fetched
1072         if (!empty($username)) {
1073             return $username;
1074         }
1075
e99991 1076         // Current username is an e-mail address
A 1077         if (strpos($_SESSION['username'], '@')) {
1078             $username = $_SESSION['username'];
1079         }
929a50 1080         // get e-mail address from default identity
e99991 1081         else if ($sql_arr = $this->app->user->get_identity()) {
7e9cec 1082             $username = $sql_arr['email'];
47124c 1083         }
T 1084         else {
7e9cec 1085             $username = $this->app->user->get_username();
47124c 1086         }
T 1087
e8d5bd 1088         return rcube_idn_to_utf8($username);
47124c 1089     }
T 1090
1091
1092     /**
1093      * GUI object 'loginform'
1094      * Returns code for the webmail login form
1095      *
1096      * @param array Named parameters
1097      * @return string HTML code for the gui object
1098      */
1099     private function login_form($attrib)
1100     {
197601 1101         $default_host = $this->config['default_host'];
1cca4f 1102         $autocomplete = (int) $this->config['login_autocomplete'];
47124c 1103
T 1104         $_SESSION['temp'] = true;
ad334a 1105
cc97ea 1106         // save original url
T 1107         $url = get_input_value('_url', RCUBE_INPUT_POST);
3a2b27 1108         if (empty($url) && !preg_match('/_(task|action)=logout/', $_SERVER['QUERY_STRING']))
cc97ea 1109             $url = $_SERVER['QUERY_STRING'];
47124c 1110
1cca4f 1111         // set atocomplete attribute
A 1112         $user_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
1113         $host_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
1114         $pass_attrib = $autocomplete > 1 ? array() : array('autocomplete' => 'off');
1115
c3be8e 1116         $input_task   = new html_hiddenfield(array('name' => '_task', 'value' => 'login'));
47124c 1117         $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
c8ae24 1118         $input_tzone  = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
65082b 1119         $input_dst    = new html_hiddenfield(array('name' => '_dstactive', 'id' => 'rcmlogindst', 'value' => '_default_'));
cc97ea 1120         $input_url    = new html_hiddenfield(array('name' => '_url', 'id' => 'rcmloginurl', 'value' => $url));
1cca4f 1121         $input_user   = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser')
A 1122             + $attrib + $user_attrib);
1123         $input_pass   = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd')
1124             + $attrib + $pass_attrib);
47124c 1125         $input_host   = null;
T 1126
f3e101 1127         if (is_array($default_host) && count($default_host) > 1) {
47124c 1128             $input_host = new html_select(array('name' => '_host', 'id' => 'rcmloginhost'));
T 1129
1130             foreach ($default_host as $key => $value) {
1131                 if (!is_array($value)) {
1132                     $input_host->add($value, (is_numeric($key) ? $value : $key));
1133                 }
1134                 else {
1135                     $input_host = null;
1136                     break;
1137                 }
1138             }
f3e101 1139         }
A 1140         else if (is_array($default_host) && ($host = array_pop($default_host))) {
1141             $hide_host = true;
1142             $input_host = new html_hiddenfield(array(
1143                 'name' => '_host', 'id' => 'rcmloginhost', 'value' => $host) + $attrib);
47124c 1144         }
e3e597 1145         else if (empty($default_host)) {
1cca4f 1146             $input_host = new html_inputfield(array('name' => '_host', 'id' => 'rcmloginhost')
A 1147                 + $attrib + $host_attrib);
47124c 1148         }
T 1149
1150         $form_name  = !empty($attrib['form']) ? $attrib['form'] : 'form';
1151         $this->add_gui_object('loginform', $form_name);
1152
1153         // create HTML table with two cols
1154         $table = new html_table(array('cols' => 2));
1155
1156         $table->add('title', html::label('rcmloginuser', Q(rcube_label('username'))));
497013 1157         $table->add('input', $input_user->show(get_input_value('_user', RCUBE_INPUT_GPC)));
47124c 1158
T 1159         $table->add('title', html::label('rcmloginpwd', Q(rcube_label('password'))));
497013 1160         $table->add('input', $input_pass->show());
47124c 1161
T 1162         // add host selection row
f3e101 1163         if (is_object($input_host) && !$hide_host) {
47124c 1164             $table->add('title', html::label('rcmloginhost', Q(rcube_label('server'))));
497013 1165             $table->add('input', $input_host->show(get_input_value('_host', RCUBE_INPUT_GPC)));
47124c 1166         }
T 1167
c3be8e 1168         $out  = $input_task->show();
T 1169         $out .= $input_action->show();
c8ae24 1170         $out .= $input_tzone->show();
65082b 1171         $out .= $input_dst->show();
cc97ea 1172         $out .= $input_url->show();
47124c 1173         $out .= $table->show();
ad334a 1174
f3e101 1175         if ($hide_host) {
A 1176             $out .= $input_host->show();
1177         }
47124c 1178
T 1179         // surround html output with a form tag
1180         if (empty($attrib['form'])) {
f3e101 1181             $out = $this->form_tag(array('name' => $form_name, 'method' => 'post'), $out);
47124c 1182         }
T 1183
1184         return $out;
1185     }
1186
1187
1188     /**
8e211a 1189      * GUI object 'preloader'
A 1190      * Loads javascript code for images preloading
1191      *
1192      * @param array Named parameters
1193      * @return void
1194      */
1195     private function preloader($attrib)
1196     {
1197         $images = preg_split('/[\s\t\n,]+/', $attrib['images'], -1, PREG_SPLIT_NO_EMPTY);
1198         $images = array_map(array($this, 'abs_url'), $images);
1199
1200         if (empty($images) || $this->app->task == 'logout')
1201             return;
1202
044d66 1203         $this->add_script('var images = ' . json_serialize($images) .';
8e211a 1204             for (var i=0; i<images.length; i++) {
A 1205                 img = new Image();
1206                 img.src = images[i];
044d66 1207             }', 'docready');
8e211a 1208     }
A 1209
1210
1211     /**
47124c 1212      * GUI object 'searchform'
T 1213      * Returns code for search function
1214      *
1215      * @param array Named parameters
1216      * @return string HTML code for the gui object
1217      */
1218     private function search_form($attrib)
1219     {
1220         // add some labels to client
1221         $this->add_label('searching');
1222
1223         $attrib['name'] = '_q';
1224
1225         if (empty($attrib['id'])) {
1226             $attrib['id'] = 'rcmqsearchbox';
1227         }
a3f149 1228         if ($attrib['type'] == 'search' && !$this->browser->khtml) {
2eb794 1229             unset($attrib['type'], $attrib['results']);
a3f149 1230         }
ad334a 1231
47124c 1232         $input_q = new html_inputfield($attrib);
T 1233         $out = $input_q->show();
1234
1235         $this->add_gui_object('qsearchbox', $attrib['id']);
1236
1237         // add form tag around text field
1238         if (empty($attrib['form'])) {
197601 1239             $out = $this->form_tag(array(
T 1240                 'name' => "rcmqsearchform",
1241                 'onsubmit' => JS_OBJECT_NAME . ".command('search');return false;",
1242                 'style' => "display:inline"),
2eb794 1243                 $out);
47124c 1244         }
T 1245
1246         return $out;
1247     }
1248
1249
1250     /**
1251      * Builder for GUI object 'message'
1252      *
1253      * @param array Named tag parameters
1254      * @return string HTML code for the gui object
1255      */
1256     private function message_container($attrib)
1257     {
1258         if (isset($attrib['id']) === false) {
1259             $attrib['id'] = 'rcmMessageContainer';
1260         }
1261
1262         $this->add_gui_object('message', $attrib['id']);
1263         return html::div($attrib, "");
1264     }
1265
1266
1267     /**
1268      * GUI object 'charsetselector'
1269      *
1270      * @param array Named parameters for the select tag
1271      * @return string HTML code for the gui object
1272      */
e55ab0 1273     function charset_selector($attrib)
47124c 1274     {
T 1275         // pass the following attributes to the form class
1276         $field_attrib = array('name' => '_charset');
1277         foreach ($attrib as $attr => $value) {
e55ab0 1278             if (in_array($attr, array('id', 'name', 'class', 'style', 'size', 'tabindex'))) {
47124c 1279                 $field_attrib[$attr] = $value;
T 1280             }
1281         }
e55ab0 1282
47124c 1283         $charsets = array(
e55ab0 1284             'UTF-8'        => 'UTF-8 ('.rcube_label('unicode').')',
A 1285             'US-ASCII'     => 'ASCII ('.rcube_label('english').')',
1286             'ISO-8859-1'   => 'ISO-8859-1 ('.rcube_label('westerneuropean').')',
d8d467 1287             'ISO-8859-2'   => 'ISO-8859-2 ('.rcube_label('easterneuropean').')',
A 1288             'ISO-8859-4'   => 'ISO-8859-4 ('.rcube_label('baltic').')',
e55ab0 1289             'ISO-8859-5'   => 'ISO-8859-5 ('.rcube_label('cyrillic').')',
A 1290             'ISO-8859-6'   => 'ISO-8859-6 ('.rcube_label('arabic').')',
1291             'ISO-8859-7'   => 'ISO-8859-7 ('.rcube_label('greek').')',
1292             'ISO-8859-8'   => 'ISO-8859-8 ('.rcube_label('hebrew').')',
1293             'ISO-8859-9'   => 'ISO-8859-9 ('.rcube_label('turkish').')',
1294             'ISO-8859-10'   => 'ISO-8859-10 ('.rcube_label('nordic').')',
1295             'ISO-8859-11'   => 'ISO-8859-11 ('.rcube_label('thai').')',
1296             'ISO-8859-13'   => 'ISO-8859-13 ('.rcube_label('baltic').')',
1297             'ISO-8859-14'   => 'ISO-8859-14 ('.rcube_label('celtic').')',
1298             'ISO-8859-15'   => 'ISO-8859-15 ('.rcube_label('westerneuropean').')',
1299             'ISO-8859-16'   => 'ISO-8859-16 ('.rcube_label('southeasterneuropean').')',
1300             'WINDOWS-1250' => 'Windows-1250 ('.rcube_label('easterneuropean').')',
1301             'WINDOWS-1251' => 'Windows-1251 ('.rcube_label('cyrillic').')',
1302             'WINDOWS-1252' => 'Windows-1252 ('.rcube_label('westerneuropean').')',
1303             'WINDOWS-1253' => 'Windows-1253 ('.rcube_label('greek').')',
1304             'WINDOWS-1254' => 'Windows-1254 ('.rcube_label('turkish').')',
1305             'WINDOWS-1255' => 'Windows-1255 ('.rcube_label('hebrew').')',
1306             'WINDOWS-1256' => 'Windows-1256 ('.rcube_label('arabic').')',
1307             'WINDOWS-1257' => 'Windows-1257 ('.rcube_label('baltic').')',
1308             'WINDOWS-1258' => 'Windows-1258 ('.rcube_label('vietnamese').')',
1309             'ISO-2022-JP'  => 'ISO-2022-JP ('.rcube_label('japanese').')',
1310             'ISO-2022-KR'  => 'ISO-2022-KR ('.rcube_label('korean').')',
1311             'ISO-2022-CN'  => 'ISO-2022-CN ('.rcube_label('chinese').')',
1312             'EUC-JP'       => 'EUC-JP ('.rcube_label('japanese').')',
1313             'EUC-KR'       => 'EUC-KR ('.rcube_label('korean').')',
1314             'EUC-CN'       => 'EUC-CN ('.rcube_label('chinese').')',
1315             'BIG5'         => 'BIG5 ('.rcube_label('chinese').')',
1316             'GB2312'       => 'GB2312 ('.rcube_label('chinese').')',
1317         );
47124c 1318
e55ab0 1319         if (!empty($_POST['_charset']))
2eb794 1320             $set = $_POST['_charset'];
A 1321         else if (!empty($attrib['selected']))
1322             $set = $attrib['selected'];
1323         else
1324             $set = $this->get_charset();
47124c 1325
2eb794 1326         $set = strtoupper($set);
A 1327         if (!isset($charsets[$set]))
1328             $charsets[$set] = $set;
e55ab0 1329
A 1330         $select = new html_select($field_attrib);
1331         $select->add(array_values($charsets), array_keys($charsets));
1332
1333         return $select->show($set);
47124c 1334     }
T 1335
1a0f60 1336     /**
T 1337      * Include content from config/about.<LANG>.html if available
1338      */
1339     private function about_content($attrib)
1340     {
1341         $content = '';
1342         $filenames = array(
1343             'about.' . $_SESSION['language'] . '.html',
1344             'about.' . substr($_SESSION['language'], 0, 2) . '.html',
1345             'about.html',
1346         );
1347         foreach ($filenames as $file) {
1348             $fn = RCMAIL_CONFIG_DIR . '/' . $file;
1349             if (is_readable($fn)) {
1350                 $content = file_get_contents($fn);
1351                 $content = $this->parse_conditions($content);
1352                 $content = $this->parse_xml($content);
1353                 break;
1354             }
1355         }
1356
1357         return $content;
1358     }
1359
47124c 1360 }  // end class rcube_template
T 1361
1362