| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/include/rcube_template.php | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the RoundCube Webmail client | |
|---|
| 8 | | Copyright (C) 2006-2008, RoundCube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 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 | { |
|---|
| 33 | var $app; |
|---|
| 34 | var $config; |
|---|
| 35 | var $framed = false; |
|---|
| 36 | var $pagetitle = ''; |
|---|
| 37 | var $env = array(); |
|---|
| 38 | var $js_env = array(); |
|---|
| 39 | var $js_commands = array(); |
|---|
| 40 | var $object_handlers = array(); |
|---|
| 41 | |
|---|
| 42 | public $ajax_call = false; |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Constructor |
|---|
| 46 | * |
|---|
| 47 | * @todo Use jQuery's $(document).ready() here. |
|---|
| 48 | * @todo Replace $this->config with the real rcube_config object |
|---|
| 49 | */ |
|---|
| 50 | public function __construct($task, $framed = false) |
|---|
| 51 | { |
|---|
| 52 | parent::__construct(); |
|---|
| 53 | |
|---|
| 54 | $this->app = rcmail::get_instance(); |
|---|
| 55 | $this->config = $this->app->config->all(); |
|---|
| 56 | |
|---|
| 57 | //$this->framed = $framed; |
|---|
| 58 | $this->set_env('task', $task); |
|---|
| 59 | |
|---|
| 60 | // load the correct skin (in case user-defined) |
|---|
| 61 | $this->set_skin($this->config['skin']); |
|---|
| 62 | |
|---|
| 63 | // add common javascripts |
|---|
| 64 | $javascript = 'var '.JS_OBJECT_NAME.' = new rcube_webmail();'; |
|---|
| 65 | |
|---|
| 66 | // don't wait for page onload. Call init at the bottom of the page (delayed) |
|---|
| 67 | $javascript_foot = "if (window.call_init)\n call_init('".JS_OBJECT_NAME."');"; |
|---|
| 68 | |
|---|
| 69 | $this->add_script($javascript, 'head_top'); |
|---|
| 70 | $this->add_script($javascript_foot, 'foot'); |
|---|
| 71 | $this->scripts_path = 'program/js/'; |
|---|
| 72 | $this->include_script('common.js'); |
|---|
| 73 | $this->include_script('app.js'); |
|---|
| 74 | |
|---|
| 75 | // register common UI objects |
|---|
| 76 | $this->add_handlers(array( |
|---|
| 77 | 'loginform' => array($this, 'login_form'), |
|---|
| 78 | 'username' => array($this, 'current_username'), |
|---|
| 79 | 'message' => array($this, 'message_container'), |
|---|
| 80 | 'charsetselector' => array($this, 'charset_selector'), |
|---|
| 81 | )); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Set environment variable |
|---|
| 86 | * |
|---|
| 87 | * @param string Property name |
|---|
| 88 | * @param mixed Property value |
|---|
| 89 | * @param boolean True if this property should be added to client environment |
|---|
| 90 | */ |
|---|
| 91 | public function set_env($name, $value, $addtojs = true) |
|---|
| 92 | { |
|---|
| 93 | $this->env[$name] = $value; |
|---|
| 94 | if ($addtojs || isset($this->js_env[$name])) { |
|---|
| 95 | $this->js_env[$name] = $value; |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | /** |
|---|
| 101 | * Set page title variable |
|---|
| 102 | */ |
|---|
| 103 | public function set_pagetitle($title) |
|---|
| 104 | { |
|---|
| 105 | $this->pagetitle = $title; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * Set skin |
|---|
| 110 | */ |
|---|
| 111 | public function set_skin($skin) |
|---|
| 112 | { |
|---|
| 113 | if (!empty($skin) && is_dir('skins/'.$skin) && is_readable('skins/'.$skin)) |
|---|
| 114 | $skin_path = 'skins/'.$skin; |
|---|
| 115 | else |
|---|
| 116 | $skin_path = $this->config['skin_path'] ? $this->config['skin_path'] : 'skins/default'; |
|---|
| 117 | |
|---|
| 118 | $this->app->config->set('skin_path', $skin_path); |
|---|
| 119 | $this->config['skin_path'] = $skin_path; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | * Check if a specific template exists |
|---|
| 124 | * |
|---|
| 125 | * @param string Template name |
|---|
| 126 | * @return boolean True if template exists |
|---|
| 127 | */ |
|---|
| 128 | public function template_exists($name) |
|---|
| 129 | { |
|---|
| 130 | $filename = $this->config['skin_path'] . '/templates/' . $name . '.html'; |
|---|
| 131 | |
|---|
| 132 | return (is_file($filename) && is_readable($filename)); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | /** |
|---|
| 136 | * Register a template object handler |
|---|
| 137 | * |
|---|
| 138 | * @param string Object name |
|---|
| 139 | * @param string Function name to call |
|---|
| 140 | * @return void |
|---|
| 141 | */ |
|---|
| 142 | public function add_handler($obj, $func) |
|---|
| 143 | { |
|---|
| 144 | $this->object_handlers[$obj] = $func; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * Register a list of template object handlers |
|---|
| 149 | * |
|---|
| 150 | * @param array Hash array with object=>handler pairs |
|---|
| 151 | * @return void |
|---|
| 152 | */ |
|---|
| 153 | public function add_handlers($arr) |
|---|
| 154 | { |
|---|
| 155 | $this->object_handlers = array_merge($this->object_handlers, $arr); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /** |
|---|
| 159 | * Register a GUI object to the client script |
|---|
| 160 | * |
|---|
| 161 | * @param string Object name |
|---|
| 162 | * @param string Object ID |
|---|
| 163 | * @return void |
|---|
| 164 | */ |
|---|
| 165 | public function add_gui_object($obj, $id) |
|---|
| 166 | { |
|---|
| 167 | $this->add_script(JS_OBJECT_NAME.".gui_object('$obj', '$id');"); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | /** |
|---|
| 171 | * Call a client method |
|---|
| 172 | * |
|---|
| 173 | * @param string Method to call |
|---|
| 174 | * @param ... Additional arguments |
|---|
| 175 | */ |
|---|
| 176 | public function command() |
|---|
| 177 | { |
|---|
| 178 | $this->js_commands[] = func_get_args(); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | /** |
|---|
| 183 | * Add a localized label to the client environment |
|---|
| 184 | */ |
|---|
| 185 | public function add_label() |
|---|
| 186 | { |
|---|
| 187 | $arg_list = func_get_args(); |
|---|
| 188 | foreach ($arg_list as $i => $name) { |
|---|
| 189 | $this->command('add_label', $name, rcube_label($name)); |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | /** |
|---|
| 195 | * Invoke display_message command |
|---|
| 196 | * |
|---|
| 197 | * @param string Message to display |
|---|
| 198 | * @param string Message type [notice|confirm|error] |
|---|
| 199 | * @param array Key-value pairs to be replaced in localized text |
|---|
| 200 | * @uses self::command() |
|---|
| 201 | */ |
|---|
| 202 | public function show_message($message, $type='notice', $vars=NULL) |
|---|
| 203 | { |
|---|
| 204 | $this->command( |
|---|
| 205 | 'display_message', |
|---|
| 206 | rcube_label(array('name' => $message, 'vars' => $vars)), |
|---|
| 207 | $type); |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | /** |
|---|
| 212 | * Delete all stored env variables and commands |
|---|
| 213 | * |
|---|
| 214 | * @return void |
|---|
| 215 | * @uses rcube_html::reset() |
|---|
| 216 | * @uses self::$env |
|---|
| 217 | * @uses self::$js_env |
|---|
| 218 | * @uses self::$js_commands |
|---|
| 219 | * @uses self::$object_handlers |
|---|
| 220 | */ |
|---|
| 221 | public public function reset() |
|---|
| 222 | { |
|---|
| 223 | $this->env = array(); |
|---|
| 224 | $this->js_env = array(); |
|---|
| 225 | $this->js_commands = array(); |
|---|
| 226 | $this->object_handlers = array(); |
|---|
| 227 | parent::reset(); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | /** |
|---|
| 232 | * Send the request output to the client. |
|---|
| 233 | * This will either parse a skin tempalte or send an AJAX response |
|---|
| 234 | * |
|---|
| 235 | * @param string Template name |
|---|
| 236 | * @param boolean True if script should terminate (default) |
|---|
| 237 | */ |
|---|
| 238 | public function send($templ = null, $exit = true) |
|---|
| 239 | { |
|---|
| 240 | if ($templ != 'iframe') { |
|---|
| 241 | $this->parse($templ, false); |
|---|
| 242 | } |
|---|
| 243 | else { |
|---|
| 244 | $this->framed = $templ == 'iframe' ? true : $this->framed; |
|---|
| 245 | $this->write(); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | if ($exit) { |
|---|
| 249 | exit; |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | /** |
|---|
| 254 | * Process template and write to stdOut |
|---|
| 255 | * |
|---|
| 256 | * @param string HTML template |
|---|
| 257 | * @see rcube_html_page::write() |
|---|
| 258 | * @override |
|---|
| 259 | */ |
|---|
| 260 | public function write($template = '') |
|---|
| 261 | { |
|---|
| 262 | // unlock interface after iframe load |
|---|
| 263 | if ($this->framed) { |
|---|
| 264 | array_unshift($this->js_commands, array('set_busy', false)); |
|---|
| 265 | } |
|---|
| 266 | // write all env variables to client |
|---|
| 267 | $js = $this->framed ? "if(window.parent) {\n" : ''; |
|---|
| 268 | $js .= $this->get_js_commands() . ($this->framed ? ' }' : ''); |
|---|
| 269 | $this->add_script($js, 'head_top'); |
|---|
| 270 | |
|---|
| 271 | // call super method |
|---|
| 272 | parent::write($template, $this->config['skin_path']); |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | /** |
|---|
| 276 | * Parse a specific skin template and deliver to stdout |
|---|
| 277 | * |
|---|
| 278 | * Either returns nothing, or exists hard (exit();) |
|---|
| 279 | * |
|---|
| 280 | * @param string Template name |
|---|
| 281 | * @param boolean Exit script |
|---|
| 282 | * @return void |
|---|
| 283 | * @link http://php.net/manual/en/function.exit.php |
|---|
| 284 | */ |
|---|
| 285 | private function parse($name = 'main', $exit = true) |
|---|
| 286 | { |
|---|
| 287 | $skin_path = $this->config['skin_path']; |
|---|
| 288 | |
|---|
| 289 | // read template file |
|---|
| 290 | $templ = ''; |
|---|
| 291 | $path = "$skin_path/templates/$name.html"; |
|---|
| 292 | |
|---|
| 293 | if (($fp = fopen($path, 'r')) === false) { |
|---|
| 294 | $message = ''; |
|---|
| 295 | ob_start(); |
|---|
| 296 | fopen($path, 'r'); |
|---|
| 297 | $message.= ob_get_contents(); |
|---|
| 298 | ob_end_clean(); |
|---|
| 299 | raise_error(array( |
|---|
| 300 | 'code' => 501, |
|---|
| 301 | 'type' => 'php', |
|---|
| 302 | 'line' => __LINE__, |
|---|
| 303 | 'file' => __FILE__, |
|---|
| 304 | 'message' => 'Error loading template for '.$name.': '.$message |
|---|
| 305 | ), true, true); |
|---|
| 306 | return false; |
|---|
| 307 | } |
|---|
| 308 | $templ = fread($fp, filesize($path)); |
|---|
| 309 | fclose($fp); |
|---|
| 310 | |
|---|
| 311 | // parse for specialtags |
|---|
| 312 | $output = $this->parse_conditions($templ); |
|---|
| 313 | $output = $this->parse_xml($output); |
|---|
| 314 | |
|---|
| 315 | // add debug console |
|---|
| 316 | if ($this->config['debug_level'] & 8) { |
|---|
| 317 | $this->add_footer('<div style="position:absolute;top:5px;left:5px;width:400px;padding:0.2em;background:white;opacity:0.8;z-index:9000"> |
|---|
| 318 | <a href="#toggle" onclick="con=document.getElementById(\'dbgconsole\');con.style.display=(con.style.display==\'none\'?\'block\':\'none\');return false">console</a> |
|---|
| 319 | <form action="/" name="debugform"><textarea name="console" id="dbgconsole" rows="20" cols="40" wrap="off" style="display:none;width:400px;border:none;font-size:x-small"></textarea></form></div>' |
|---|
| 320 | ); |
|---|
| 321 | } |
|---|
| 322 | $output = $this->parse_with_globals($output); |
|---|
| 323 | $this->write(trim($output), $skin_path); |
|---|
| 324 | if ($exit) { |
|---|
| 325 | exit; |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | /** |
|---|
| 331 | * Return executable javascript code for all registered commands |
|---|
| 332 | * |
|---|
| 333 | * @return string $out |
|---|
| 334 | */ |
|---|
| 335 | private function get_js_commands() |
|---|
| 336 | { |
|---|
| 337 | $out = ''; |
|---|
| 338 | if (!$this->framed && !empty($this->js_env)) { |
|---|
| 339 | $out .= JS_OBJECT_NAME . '.set_env('.json_serialize($this->js_env).");\n"; |
|---|
| 340 | } |
|---|
| 341 | foreach ($this->js_commands as $i => $args) { |
|---|
| 342 | $method = array_shift($args); |
|---|
| 343 | foreach ($args as $i => $arg) { |
|---|
| 344 | $args[$i] = json_serialize($arg); |
|---|
| 345 | } |
|---|
| 346 | $parent = $this->framed || preg_match('/^parent\./', $method); |
|---|
| 347 | $out .= sprintf( |
|---|
| 348 | "%s.%s(%s);\n", |
|---|
| 349 | ($parent ? 'parent.' : '') . JS_OBJECT_NAME, |
|---|
| 350 | preg_replace('/^parent\./', '', $method), |
|---|
| 351 | implode(',', $args) |
|---|
| 352 | ); |
|---|
| 353 | } |
|---|
| 354 | // add command to set page title |
|---|
| 355 | if ($this->ajax_call && !empty($this->pagetitle)) { |
|---|
| 356 | $out .= sprintf( |
|---|
| 357 | "this.set_pagetitle('%s');\n", |
|---|
| 358 | JQ((!empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : '') . $this->pagetitle) |
|---|
| 359 | ); |
|---|
| 360 | } |
|---|
| 361 | return $out; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | /** |
|---|
| 365 | * Make URLs starting with a slash point to skin directory |
|---|
| 366 | * |
|---|
| 367 | * @param string Input string |
|---|
| 368 | * @return string |
|---|
| 369 | */ |
|---|
| 370 | public function abs_url($str) |
|---|
| 371 | { |
|---|
| 372 | return preg_replace('/^\//', $this->config['skin_path'].'/', $str); |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | /***** Template parsing methods *****/ |
|---|
| 377 | |
|---|
| 378 | /** |
|---|
| 379 | * Replace all strings ($varname) |
|---|
| 380 | * with the content of the according global variable. |
|---|
| 381 | */ |
|---|
| 382 | private function parse_with_globals($input) |
|---|
| 383 | { |
|---|
| 384 | $GLOBALS['__comm_path'] = Q($this->app->comm_path); |
|---|
| 385 | return preg_replace('/\$(__[a-z0-9_\-]+)/e', '$GLOBALS["\\1"]', $input); |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | /** |
|---|
| 389 | * Public wrapper to dipp into template parsing. |
|---|
| 390 | * |
|---|
| 391 | * @param string $input |
|---|
| 392 | * @return string |
|---|
| 393 | * @uses rcube_template::parse_xml() |
|---|
| 394 | * @since 0.1-rc1 |
|---|
| 395 | */ |
|---|
| 396 | public function just_parse($input) |
|---|
| 397 | { |
|---|
| 398 | return $this->parse_xml($input); |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | /** |
|---|
| 402 | * Parse for conditional tags |
|---|
| 403 | * |
|---|
| 404 | * @param string $input |
|---|
| 405 | * @return string |
|---|
| 406 | */ |
|---|
| 407 | private function parse_conditions($input) |
|---|
| 408 | { |
|---|
| 409 | $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE); |
|---|
| 410 | if ($matches && count($matches) == 4) { |
|---|
| 411 | if (preg_match('/^(else|endif)$/i', $matches[1])) { |
|---|
| 412 | return $matches[0] . $this->parse_conditions($matches[3]); |
|---|
| 413 | } |
|---|
| 414 | $attrib = parse_attrib_string($matches[2]); |
|---|
| 415 | if (isset($attrib['condition'])) { |
|---|
| 416 | $condmet = $this->check_condition($attrib['condition']); |
|---|
| 417 | $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE); |
|---|
| 418 | if ($condmet) { |
|---|
| 419 | $result = $submatches[0]; |
|---|
| 420 | $result.= ($submatches[1] != 'endif' ? preg_replace('/.*<roundcube:endif\s+[^>]+>/Uis', '', $submatches[3], 1) : $submatches[3]); |
|---|
| 421 | } |
|---|
| 422 | else { |
|---|
| 423 | $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3]; |
|---|
| 424 | } |
|---|
| 425 | return $matches[0] . $this->parse_conditions($result); |
|---|
| 426 | } |
|---|
| 427 | raise_error(array( |
|---|
| 428 | 'code' => 500, |
|---|
| 429 | 'type' => 'php', |
|---|
| 430 | 'line' => __LINE__, |
|---|
| 431 | 'file' => __FILE__, |
|---|
| 432 | 'message' => "Unable to parse conditional tag " . $matches[2] |
|---|
| 433 | ), true, false); |
|---|
| 434 | } |
|---|
| 435 | return $input; |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | /** |
|---|
| 440 | * Determines if a given condition is met |
|---|
| 441 | * |
|---|
| 442 | * @todo Get rid off eval() once I understand what this does. |
|---|
| 443 | * @todo Extend this to allow real conditions, not just "set" |
|---|
| 444 | * @param string Condition statement |
|---|
| 445 | * @return boolean True if condition is met, False is not |
|---|
| 446 | */ |
|---|
| 447 | private function check_condition($condition) |
|---|
| 448 | { |
|---|
| 449 | $condition = preg_replace( |
|---|
| 450 | array( |
|---|
| 451 | '/session:([a-z0-9_]+)/i', |
|---|
| 452 | '/config:([a-z0-9_]+)/i', |
|---|
| 453 | '/env:([a-z0-9_]+)/i', |
|---|
| 454 | '/request:([a-z0-9_]+)/ie' |
|---|
| 455 | ), |
|---|
| 456 | array( |
|---|
| 457 | "\$_SESSION['\\1']", |
|---|
| 458 | "\$this->config['\\1']", |
|---|
| 459 | "\$this->env['\\1']", |
|---|
| 460 | "get_input_value('\\1', RCUVE_INPUT_GPC)" |
|---|
| 461 | ), |
|---|
| 462 | $condition); |
|---|
| 463 | |
|---|
| 464 | return eval("return (".$condition.");"); |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | /** |
|---|
| 469 | * Search for special tags in input and replace them |
|---|
| 470 | * with the appropriate content |
|---|
| 471 | * |
|---|
| 472 | * @param string Input string to parse |
|---|
| 473 | * @return string Altered input string |
|---|
| 474 | * @todo Maybe a cache. |
|---|
| 475 | */ |
|---|
| 476 | private function parse_xml($input) |
|---|
| 477 | { |
|---|
| 478 | return preg_replace('/<roundcube:([-_a-z]+)\s+([^>]+)>/Uie', "\$this->xml_command('\\1', '\\2')", $input); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | /** |
|---|
| 483 | * Convert a xml command tag into real content |
|---|
| 484 | * |
|---|
| 485 | * @param string Tag command: object,button,label, etc. |
|---|
| 486 | * @param string Attribute string |
|---|
| 487 | * @return string Tag/Object content |
|---|
| 488 | */ |
|---|
| 489 | private function xml_command($command, $str_attrib, $add_attrib = array()) |
|---|
| 490 | { |
|---|
| 491 | $command = strtolower($command); |
|---|
| 492 | $attrib = parse_attrib_string($str_attrib) + $add_attrib; |
|---|
| 493 | |
|---|
| 494 | // empty output if required condition is not met |
|---|
| 495 | if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) { |
|---|
| 496 | return ''; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | // execute command |
|---|
| 500 | switch ($command) { |
|---|
| 501 | // return a button |
|---|
| 502 | case 'button': |
|---|
| 503 | if ($attrib['name'] || $attrib['command']) { |
|---|
| 504 | return $this->button($attrib); |
|---|
| 505 | } |
|---|
| 506 | break; |
|---|
| 507 | |
|---|
| 508 | // show a label |
|---|
| 509 | case 'label': |
|---|
| 510 | if ($attrib['name'] || $attrib['command']) { |
|---|
| 511 | return Q(rcube_label($attrib + array('vars' => array('product' => $this->config['product_name'])))); |
|---|
| 512 | } |
|---|
| 513 | break; |
|---|
| 514 | |
|---|
| 515 | // include a file |
|---|
| 516 | case 'include': |
|---|
| 517 | $path = realpath($this->config['skin_path'].$attrib['file']); |
|---|
| 518 | if ($fsize = filesize($path)) { |
|---|
| 519 | if ($this->config['skin_include_php']) { |
|---|
| 520 | $incl = $this->include_php($path); |
|---|
| 521 | } |
|---|
| 522 | else if ($fp = fopen($path, 'r')) { |
|---|
| 523 | $incl = fread($fp, $fsize); |
|---|
| 524 | fclose($fp); |
|---|
| 525 | } |
|---|
| 526 | return $this->parse_xml($incl); |
|---|
| 527 | } |
|---|
| 528 | break; |
|---|
| 529 | |
|---|
| 530 | case 'plugin.include': |
|---|
| 531 | //rcube::tfk_debug(var_export($this->config['skin_path'], true)); |
|---|
| 532 | $path = realpath($this->config['skin_path'].$attrib['file']); |
|---|
| 533 | if (!$path) { |
|---|
| 534 | //rcube::tfk_debug("Does not exist:"); |
|---|
| 535 | //rcube::tfk_debug($this->config['skin_path']); |
|---|
| 536 | //rcube::tfk_debug($attrib['file']); |
|---|
| 537 | //rcube::tfk_debug($path); |
|---|
| 538 | } |
|---|
| 539 | $incl = file_get_contents($path); |
|---|
| 540 | if ($incl) { |
|---|
| 541 | return $this->parse_xml($incl); |
|---|
| 542 | } |
|---|
| 543 | break; |
|---|
| 544 | |
|---|
| 545 | // return code for a specific application object |
|---|
| 546 | case 'object': |
|---|
| 547 | $object = strtolower($attrib['name']); |
|---|
| 548 | |
|---|
| 549 | // we are calling a class/method |
|---|
| 550 | if (($handler = $this->object_handlers[$object]) && is_array($handler)) { |
|---|
| 551 | if ((is_object($handler[0]) && method_exists($handler[0], $handler[1])) || |
|---|
| 552 | (is_string($handler[0]) && class_exists($handler[0]))) |
|---|
| 553 | return call_user_func($handler, $attrib); |
|---|
| 554 | } |
|---|
| 555 | else if (function_exists($handler)) { |
|---|
| 556 | // execute object handler function |
|---|
| 557 | return call_user_func($handler, $attrib); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | if ($object=='productname') { |
|---|
| 561 | $name = !empty($this->config['product_name']) ? $this->config['product_name'] : 'RoundCube Webmail'; |
|---|
| 562 | return Q($name); |
|---|
| 563 | } |
|---|
| 564 | if ($object=='version') { |
|---|
| 565 | $ver = (string)RCMAIL_VERSION; |
|---|
| 566 | if (is_file(INSTALL_PATH . '.svn/entries')) { |
|---|
| 567 | if (preg_match('/Revision:\s(\d+)/', @shell_exec('svn info'), $regs)) |
|---|
| 568 | $ver .= ' [SVN r'.$regs[1].']'; |
|---|
| 569 | } |
|---|
| 570 | return $ver; |
|---|
| 571 | } |
|---|
| 572 | if ($object=='pagetitle') { |
|---|
| 573 | $task = $this->env['task']; |
|---|
| 574 | $title = !empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : ''; |
|---|
| 575 | |
|---|
| 576 | if (!empty($this->pagetitle)) { |
|---|
| 577 | $title .= $this->pagetitle; |
|---|
| 578 | } |
|---|
| 579 | else if ($task == 'login') { |
|---|
| 580 | $title = rcube_label(array('name' => 'welcome', 'vars' => array('product' => $this->config['product_name']))); |
|---|
| 581 | } |
|---|
| 582 | else { |
|---|
| 583 | $title .= ucfirst($task); |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | return Q($title); |
|---|
| 587 | } |
|---|
| 588 | break; |
|---|
| 589 | |
|---|
| 590 | // return variable |
|---|
| 591 | case 'var': |
|---|
| 592 | $var = explode(':', $attrib['name']); |
|---|
| 593 | $name = $var[1]; |
|---|
| 594 | $value = ''; |
|---|
| 595 | |
|---|
| 596 | switch ($var[0]) { |
|---|
| 597 | case 'env': |
|---|
| 598 | $value = $this->env[$name]; |
|---|
| 599 | break; |
|---|
| 600 | case 'config': |
|---|
| 601 | $value = $this->config[$name]; |
|---|
| 602 | if (is_array($value) && $value[$_SESSION['imap_host']]) { |
|---|
| 603 | $value = $value[$_SESSION['imap_host']]; |
|---|
| 604 | } |
|---|
| 605 | break; |
|---|
| 606 | case 'request': |
|---|
| 607 | $value = get_input_value($name, RCUBE_INPUT_GPC); |
|---|
| 608 | break; |
|---|
| 609 | case 'session': |
|---|
| 610 | $value = $_SESSION[$name]; |
|---|
| 611 | break; |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | if (is_array($value)) { |
|---|
| 615 | $value = implode(', ', $value); |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | return Q($value); |
|---|
| 619 | break; |
|---|
| 620 | } |
|---|
| 621 | return ''; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | /** |
|---|
| 625 | * Include a specific file and return it's contents |
|---|
| 626 | * |
|---|
| 627 | * @param string File path |
|---|
| 628 | * @return string Contents of the processed file |
|---|
| 629 | */ |
|---|
| 630 | private function include_php($file) |
|---|
| 631 | { |
|---|
| 632 | ob_start(); |
|---|
| 633 | include $file; |
|---|
| 634 | $out = ob_get_contents(); |
|---|
| 635 | ob_end_clean(); |
|---|
| 636 | |
|---|
| 637 | return $out; |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | /** |
|---|
| 641 | * Create and register a button |
|---|
| 642 | * |
|---|
| 643 | * @param array Named button attributes |
|---|
| 644 | * @return string HTML button |
|---|
| 645 | * @todo Remove all inline JS calls and use jQuery instead. |
|---|
| 646 | * @todo Remove all sprintf()'s - they are pretty, but also slow. |
|---|
| 647 | */ |
|---|
| 648 | private function button($attrib) |
|---|
| 649 | { |
|---|
| 650 | static $sa_buttons = array(); |
|---|
| 651 | static $s_button_count = 100; |
|---|
| 652 | |
|---|
| 653 | // these commands can be called directly via url |
|---|
| 654 | $a_static_commands = array('compose', 'list'); |
|---|
| 655 | |
|---|
| 656 | if (!($attrib['command'] || $attrib['name'])) { |
|---|
| 657 | return ''; |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | $browser = new rcube_browser(); |
|---|
| 661 | |
|---|
| 662 | // try to find out the button type |
|---|
| 663 | if ($attrib['type']) { |
|---|
| 664 | $attrib['type'] = strtolower($attrib['type']); |
|---|
| 665 | } |
|---|
| 666 | else { |
|---|
| 667 | $attrib['type'] = ($attrib['image'] || $attrib['imagepas'] || $attrib['imageact']) ? 'image' : 'link'; |
|---|
| 668 | } |
|---|
| 669 | $command = $attrib['command']; |
|---|
| 670 | |
|---|
| 671 | // take the button from the stack |
|---|
| 672 | if ($attrib['name'] && $sa_buttons[$attrib['name']]) { |
|---|
| 673 | $attrib = $sa_buttons[$attrib['name']]; |
|---|
| 674 | } |
|---|
| 675 | else if($attrib['image'] || $attrib['imageact'] || $attrib['imagepas'] || $attrib['class']) { |
|---|
| 676 | // add button to button stack |
|---|
| 677 | if (!$attrib['name']) { |
|---|
| 678 | $attrib['name'] = $command; |
|---|
| 679 | } |
|---|
| 680 | if (!$attrib['image']) { |
|---|
| 681 | $attrib['image'] = $attrib['imagepas'] ? $attrib['imagepas'] : $attrib['imageact']; |
|---|
| 682 | } |
|---|
| 683 | $sa_buttons[$attrib['name']] = $attrib; |
|---|
| 684 | } |
|---|
| 685 | else if ($command && $sa_buttons[$command]) { |
|---|
| 686 | // get saved button for this command/name |
|---|
| 687 | $attrib = $sa_buttons[$command]; |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | // set border to 0 because of the link arround the button |
|---|
| 691 | if ($attrib['type']=='image' && !isset($attrib['border'])) { |
|---|
| 692 | $attrib['border'] = 0; |
|---|
| 693 | } |
|---|
| 694 | if (!$attrib['id']) { |
|---|
| 695 | $attrib['id'] = sprintf('rcmbtn%d', $s_button_count++); |
|---|
| 696 | } |
|---|
| 697 | // get localized text for labels and titles |
|---|
| 698 | if ($attrib['title']) { |
|---|
| 699 | $attrib['title'] = Q(rcube_label($attrib['title'])); |
|---|
| 700 | } |
|---|
| 701 | if ($attrib['label']) { |
|---|
| 702 | $attrib['label'] = Q(rcube_label($attrib['label'])); |
|---|
| 703 | } |
|---|
| 704 | if ($attrib['alt']) { |
|---|
| 705 | $attrib['alt'] = Q(rcube_label($attrib['alt'])); |
|---|
| 706 | } |
|---|
| 707 | // set title to alt attribute for IE browsers |
|---|
| 708 | if ($browser->ie && $attrib['title'] && !$attrib['alt']) { |
|---|
| 709 | $attrib['alt'] = $attrib['title']; |
|---|
| 710 | unset($attrib['title']); |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | // add empty alt attribute for XHTML compatibility |
|---|
| 714 | if (!isset($attrib['alt'])) { |
|---|
| 715 | $attrib['alt'] = ''; |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | // register button in the system |
|---|
| 719 | if ($attrib['command']) { |
|---|
| 720 | $this->add_script(sprintf( |
|---|
| 721 | "%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');", |
|---|
| 722 | JS_OBJECT_NAME, |
|---|
| 723 | $command, |
|---|
| 724 | $attrib['id'], |
|---|
| 725 | $attrib['type'], |
|---|
| 726 | $attrib['imageact'] ? $this->abs_url($attrib['imageact']) : $attrib['classact'], |
|---|
| 727 | $attrib['imagesel'] ? $this->abs_url($attrib['imagesel']) : $attrib['classsel'], |
|---|
| 728 | $attrib['imageover'] ? $this->abs_url($attrib['imageover']) : '' |
|---|
| 729 | )); |
|---|
| 730 | |
|---|
| 731 | // make valid href to specific buttons |
|---|
| 732 | if (in_array($attrib['command'], rcmail::$main_tasks)) { |
|---|
| 733 | $attrib['href'] = Q(rcmail_url(null, null, $attrib['command'])); |
|---|
| 734 | } |
|---|
| 735 | else if (in_array($attrib['command'], $a_static_commands)) { |
|---|
| 736 | $attrib['href'] = Q(rcmail_url($attrib['command'])); |
|---|
| 737 | } |
|---|
| 738 | } |
|---|
| 739 | |
|---|
| 740 | // overwrite attributes |
|---|
| 741 | if (!$attrib['href']) { |
|---|
| 742 | $attrib['href'] = '#'; |
|---|
| 743 | } |
|---|
| 744 | if ($command) { |
|---|
| 745 | $attrib['onclick'] = sprintf( |
|---|
| 746 | "return %s.command('%s','%s',this)", |
|---|
| 747 | JS_OBJECT_NAME, |
|---|
| 748 | $command, |
|---|
| 749 | $attrib['prop'] |
|---|
| 750 | ); |
|---|
| 751 | } |
|---|
| 752 | if ($command && $attrib['imageover']) { |
|---|
| 753 | $attrib['onmouseover'] = sprintf( |
|---|
| 754 | "return %s.button_over('%s','%s')", |
|---|
| 755 | JS_OBJECT_NAME, |
|---|
| 756 | $command, |
|---|
| 757 | $attrib['id'] |
|---|
| 758 | ); |
|---|
| 759 | $attrib['onmouseout'] = sprintf( |
|---|
| 760 | "return %s.button_out('%s','%s')", |
|---|
| 761 | JS_OBJECT_NAME, |
|---|
| 762 | $command, |
|---|
| 763 | $attrib['id'] |
|---|
| 764 | ); |
|---|
| 765 | } |
|---|
| 766 | |
|---|
| 767 | if ($command && $attrib['imagesel']) { |
|---|
| 768 | $attrib['onmousedown'] = sprintf( |
|---|
| 769 | "return %s.button_sel('%s','%s')", |
|---|
| 770 | JS_OBJECT_NAME, |
|---|
| 771 | $command, |
|---|
| 772 | $attrib['id'] |
|---|
| 773 | ); |
|---|
| 774 | $attrib['onmouseup'] = sprintf( |
|---|
| 775 | "return %s.button_out('%s','%s')", |
|---|
| 776 | JS_OBJECT_NAME, |
|---|
| 777 | $command, |
|---|
| 778 | $attrib['id'] |
|---|
| 779 | ); |
|---|
| 780 | } |
|---|
| 781 | |
|---|
| 782 | $out = ''; |
|---|
| 783 | |
|---|
| 784 | // generate image tag |
|---|
| 785 | if ($attrib['type']=='image') { |
|---|
| 786 | $attrib_str = html::attrib_string( |
|---|
| 787 | $attrib, |
|---|
| 788 | array( |
|---|
| 789 | 'style', 'class', 'id', 'width', |
|---|
| 790 | 'height', 'border', 'hspace', |
|---|
| 791 | 'vspace', 'align', 'alt', 'tabindex' |
|---|
| 792 | ) |
|---|
| 793 | ); |
|---|
| 794 | $btn_content = sprintf('<img src="%s"%s />', $this->abs_url($attrib['image']), $attrib_str); |
|---|
| 795 | if ($attrib['label']) { |
|---|
| 796 | $btn_content .= ' '.$attrib['label']; |
|---|
| 797 | } |
|---|
| 798 | $link_attrib = array('href', 'onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'title'); |
|---|
| 799 | } |
|---|
| 800 | else if ($attrib['type']=='link') { |
|---|
| 801 | $btn_content = $attrib['label'] ? $attrib['label'] : $attrib['command']; |
|---|
| 802 | $link_attrib = array('href', 'onclick', 'title', 'id', 'class', 'style', 'tabindex'); |
|---|
| 803 | } |
|---|
| 804 | else if ($attrib['type']=='input') { |
|---|
| 805 | $attrib['type'] = 'button'; |
|---|
| 806 | |
|---|
| 807 | if ($attrib['label']) { |
|---|
| 808 | $attrib['value'] = $attrib['label']; |
|---|
| 809 | } |
|---|
| 810 | |
|---|
| 811 | $attrib_str = html::attrib_string( |
|---|
| 812 | $attrib, |
|---|
| 813 | array( |
|---|
| 814 | 'type', 'value', 'onclick', |
|---|
| 815 | 'id', 'class', 'style', 'tabindex' |
|---|
| 816 | ) |
|---|
| 817 | ); |
|---|
| 818 | $out = sprintf('<input%s disabled="disabled" />', $attrib_str); |
|---|
| 819 | } |
|---|
| 820 | |
|---|
| 821 | // generate html code for button |
|---|
| 822 | if ($btn_content) { |
|---|
| 823 | $attrib_str = html::attrib_string($attrib, $link_attrib); |
|---|
| 824 | $out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content); |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | return $out; |
|---|
| 828 | } |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | /* ************* common functions delivering gui objects ************** */ |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | /** |
|---|
| 835 | * Create a form tag with the necessary hidden fields |
|---|
| 836 | * |
|---|
| 837 | * @param array Named tag parameters |
|---|
| 838 | * @return string HTML code for the form |
|---|
| 839 | */ |
|---|
| 840 | public function form_tag($attrib, $content = null) |
|---|
| 841 | { |
|---|
| 842 | if ($this->framed) { |
|---|
| 843 | $hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1')); |
|---|
| 844 | $hidden = $hiddenfield->show(); |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | if (!$content) |
|---|
| 848 | $attrib['noclose'] = true; |
|---|
| 849 | |
|---|
| 850 | return html::tag('form', |
|---|
| 851 | $attrib + array('action' => "./", 'method' => "get"), |
|---|
| 852 | $hidden . $content); |
|---|
| 853 | } |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | /** |
|---|
| 857 | * GUI object 'username' |
|---|
| 858 | * Showing IMAP username of the current session |
|---|
| 859 | * |
|---|
| 860 | * @param array Named tag parameters (currently not used) |
|---|
| 861 | * @return string HTML code for the gui object |
|---|
| 862 | */ |
|---|
| 863 | public function current_username($attrib) |
|---|
| 864 | { |
|---|
| 865 | static $username; |
|---|
| 866 | |
|---|
| 867 | // alread fetched |
|---|
| 868 | if (!empty($username)) { |
|---|
| 869 | return $username; |
|---|
| 870 | } |
|---|
| 871 | |
|---|
| 872 | // get e-mail address form default identity |
|---|
| 873 | if ($sql_arr = $this->app->user->get_identity()) { |
|---|
| 874 | $username = $sql_arr['email']; |
|---|
| 875 | } |
|---|
| 876 | else { |
|---|
| 877 | $username = $this->app->user->get_username(); |
|---|
| 878 | } |
|---|
| 879 | |
|---|
| 880 | return $username; |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | /** |
|---|
| 885 | * GUI object 'loginform' |
|---|
| 886 | * Returns code for the webmail login form |
|---|
| 887 | * |
|---|
| 888 | * @param array Named parameters |
|---|
| 889 | * @return string HTML code for the gui object |
|---|
| 890 | */ |
|---|
| 891 | private function login_form($attrib) |
|---|
| 892 | { |
|---|
| 893 | $default_host = $this->config['default_host']; |
|---|
| 894 | |
|---|
| 895 | $_SESSION['temp'] = true; |
|---|
| 896 | |
|---|
| 897 | $input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30, 'autocomplete' => 'off')); |
|---|
| 898 | $input_pass = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30)); |
|---|
| 899 | $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login')); |
|---|
| 900 | $input_host = null; |
|---|
| 901 | |
|---|
| 902 | if (is_array($default_host)) { |
|---|
| 903 | $input_host = new html_select(array('name' => '_host', 'id' => 'rcmloginhost')); |
|---|
| 904 | |
|---|
| 905 | foreach ($default_host as $key => $value) { |
|---|
| 906 | if (!is_array($value)) { |
|---|
| 907 | $input_host->add($value, (is_numeric($key) ? $value : $key)); |
|---|
| 908 | } |
|---|
| 909 | else { |
|---|
| 910 | $input_host = null; |
|---|
| 911 | break; |
|---|
| 912 | } |
|---|
| 913 | } |
|---|
| 914 | } |
|---|
| 915 | else if (!strlen($default_host)) { |
|---|
| 916 | $input_host = new html_inputfield(array('name' => '_host', 'id' => 'rcmloginhost', 'size' => 30)); |
|---|
| 917 | } |
|---|
| 918 | |
|---|
| 919 | $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form'; |
|---|
| 920 | $this->add_gui_object('loginform', $form_name); |
|---|
| 921 | |
|---|
| 922 | // create HTML table with two cols |
|---|
| 923 | $table = new html_table(array('cols' => 2)); |
|---|
| 924 | |
|---|
| 925 | $table->add('title', html::label('rcmloginuser', Q(rcube_label('username')))); |
|---|
| 926 | $table->add(null, $input_user->show(get_input_value('_user', RCUVE_INPUT_POST))); |
|---|
| 927 | |
|---|
| 928 | $table->add('title', html::label('rcmloginpwd', Q(rcube_label('password')))); |
|---|
| 929 | $table->add(null, $input_pass->show()); |
|---|
| 930 | |
|---|
| 931 | // add host selection row |
|---|
| 932 | if (is_object($input_host)) { |
|---|
| 933 | $table->add('title', html::label('rcmloginhost', Q(rcube_label('server')))); |
|---|
| 934 | $table->add(null, $input_host->show(get_input_value('_host', RCUVE_INPUT_POST))); |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | $out = $input_action->show(); |
|---|
| 938 | $out .= $table->show(); |
|---|
| 939 | |
|---|
| 940 | // surround html output with a form tag |
|---|
| 941 | if (empty($attrib['form'])) { |
|---|
| 942 | $out = $this->form_tag(array('name' => $form_name, 'method' => "post"), $out); |
|---|
| 943 | } |
|---|
| 944 | |
|---|
| 945 | return $out; |
|---|
| 946 | } |
|---|
| 947 | |
|---|
| 948 | |
|---|
| 949 | /** |
|---|
| 950 | * GUI object 'searchform' |
|---|
| 951 | * Returns code for search function |
|---|
| 952 | * |
|---|
| 953 | * @param array Named parameters |
|---|
| 954 | * @return string HTML code for the gui object |
|---|
| 955 | */ |
|---|
| 956 | private function search_form($attrib) |
|---|
| 957 | { |
|---|
| 958 | // add some labels to client |
|---|
| 959 | $this->add_label('searching'); |
|---|
| 960 | |
|---|
| 961 | $attrib['name'] = '_q'; |
|---|
| 962 | |
|---|
| 963 | if (empty($attrib['id'])) { |
|---|
| 964 | $attrib['id'] = 'rcmqsearchbox'; |
|---|
| 965 | } |
|---|
| 966 | $input_q = new html_inputfield($attrib); |
|---|
| 967 | $out = $input_q->show(); |
|---|
| 968 | |
|---|
| 969 | $this->add_gui_object('qsearchbox', $attrib['id']); |
|---|
| 970 | |
|---|
| 971 | // add form tag around text field |
|---|
| 972 | if (empty($attrib['form'])) { |
|---|
| 973 | $out = $this->form_tag(array( |
|---|
| 974 | 'name' => "rcmqsearchform", |
|---|
| 975 | 'onsubmit' => JS_OBJECT_NAME . ".command('search');return false;", |
|---|
| 976 | 'style' => "display:inline"), |
|---|
| 977 | $out); |
|---|
| 978 | } |
|---|
| 979 | |
|---|
| 980 | return $out; |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | |
|---|
| 984 | /** |
|---|
| 985 | * Builder for GUI object 'message' |
|---|
| 986 | * |
|---|
| 987 | * @param array Named tag parameters |
|---|
| 988 | * @return string HTML code for the gui object |
|---|
| 989 | */ |
|---|
| 990 | private function message_container($attrib) |
|---|
| 991 | { |
|---|
| 992 | if (isset($attrib['id']) === false) { |
|---|
| 993 | $attrib['id'] = 'rcmMessageContainer'; |
|---|
| 994 | } |
|---|
| 995 | |
|---|
| 996 | $this->add_gui_object('message', $attrib['id']); |
|---|
| 997 | return html::div($attrib, ""); |
|---|
| 998 | } |
|---|
| 999 | |
|---|
| 1000 | |
|---|
| 1001 | /** |
|---|
| 1002 | * GUI object 'charsetselector' |
|---|
| 1003 | * |
|---|
| 1004 | * @param array Named parameters for the select tag |
|---|
| 1005 | * @return string HTML code for the gui object |
|---|
| 1006 | */ |
|---|
| 1007 | static function charset_selector($attrib) |
|---|
| 1008 | { |
|---|
| 1009 | // pass the following attributes to the form class |
|---|
| 1010 | $field_attrib = array('name' => '_charset'); |
|---|
| 1011 | foreach ($attrib as $attr => $value) { |
|---|
| 1012 | if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) { |
|---|
| 1013 | $field_attrib[$attr] = $value; |
|---|
| 1014 | } |
|---|
| 1015 | } |
|---|
| 1016 | $charsets = array( |
|---|
| 1017 | 'US-ASCII' => 'ASCII (English)', |
|---|
| 1018 | 'EUC-JP' => 'EUC-JP (Japanese)', |
|---|
| 1019 | 'EUC-KR' => 'EUC-KR (Korean)', |
|---|
| 1020 | 'BIG5' => 'BIG5 (Chinese)', |
|---|
| 1021 | 'GB2312' => 'GB2312 (Chinese)', |
|---|
| 1022 | 'ISO-2022-JP' => 'ISO-2022-JP (Japanese)', |
|---|
| 1023 | 'ISO-8859-1' => 'ISO-8859-1 (Latin-1)', |
|---|
| 1024 | 'ISO-8859-2' => 'ISO-8895-2 (Central European)', |
|---|
| 1025 | 'ISO-8859-7' => 'ISO-8859-7 (Greek)', |
|---|
| 1026 | 'ISO-8859-9' => 'ISO-8859-9 (Turkish)', |
|---|
| 1027 | 'Windows-1251' => 'Windows-1251 (Cyrillic)', |
|---|
| 1028 | 'Windows-1252' => 'Windows-1252 (Western)', |
|---|
| 1029 | 'Windows-1255' => 'Windows-1255 (Hebrew)', |
|---|
| 1030 | 'Windows-1256' => 'Windows-1256 (Arabic)', |
|---|
| 1031 | 'Windows-1257' => 'Windows-1257 (Baltic)', |
|---|
| 1032 | 'UTF-8' => 'UTF-8' |
|---|
| 1033 | ); |
|---|
| 1034 | |
|---|
| 1035 | $select = new html_select($field_attrib); |
|---|
| 1036 | $select->add(array_values($charsets), array_keys($charsets)); |
|---|
| 1037 | |
|---|
| 1038 | $set = $_POST['_charset'] ? $_POST['_charset'] : $this->get_charset(); |
|---|
| 1039 | return $select->show($set); |
|---|
| 1040 | } |
|---|
| 1041 | |
|---|
| 1042 | } // end class rcube_template |
|---|
| 1043 | |
|---|
| 1044 | |
|---|