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