commit | author | age
|
f11541
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/include/rcmail_template.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
|
8 |
| Copyright (C) 2007, RoundCube Dev. - Switzerland | |
|
9 |
| Licensed under the GNU GPL | |
|
10 |
| | |
|
11 |
| PURPOSE: | |
|
12 |
| Class to handle HTML page output using a skin template. | |
6d969b
|
13 |
| Extends rcube_html_page class from rcube_html.inc | |
f11541
|
14 |
| | |
T |
15 |
+-----------------------------------------------------------------------+ |
|
16 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
|
|
19 |
$Id: $ |
|
20 |
|
|
21 |
*/ |
|
22 |
|
6d969b
|
23 |
|
T |
24 |
/** |
|
25 |
* Classes and functions for HTML output |
|
26 |
* |
|
27 |
* @package View |
|
28 |
*/ |
|
29 |
|
|
30 |
require_once('include/rcube_html.inc'); |
f11541
|
31 |
|
T |
32 |
|
6d969b
|
33 |
/** |
T |
34 |
* Class to create HTML page output using a skin template |
|
35 |
*/ |
f11541
|
36 |
class rcmail_template extends rcube_html_page |
T |
37 |
{ |
|
38 |
var $config; |
|
39 |
var $task = ''; |
|
40 |
var $framed = false; |
|
41 |
var $ajax_call = false; |
|
42 |
var $pagetitle = ''; |
|
43 |
var $env = array(); |
|
44 |
var $js_env = array(); |
|
45 |
var $js_commands = array(); |
|
46 |
var $object_handlers = array(); |
|
47 |
|
|
48 |
|
6d969b
|
49 |
/** |
T |
50 |
* Constructor |
|
51 |
* |
|
52 |
* @param array Configuration array |
|
53 |
* @param string Current task |
|
54 |
*/ |
f11541
|
55 |
function __construct(&$config, $task) |
T |
56 |
{ |
|
57 |
$this->task = $task; |
|
58 |
$this->config = $config; |
|
59 |
$this->ajax_call = !empty($_GET['_remote']) || !empty($_POST['_remote']); |
|
60 |
|
|
61 |
// add common javascripts |
|
62 |
if (!$this->ajax_call) |
|
63 |
{ |
|
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 |
} |
|
76 |
|
6d969b
|
77 |
/** |
T |
78 |
* PHP 4 compatibility |
|
79 |
* @see rcmail_template::__construct() |
|
80 |
*/ |
f11541
|
81 |
function rcmail_template(&$config, $task) |
T |
82 |
{ |
|
83 |
$this->__construct($config, $task); |
|
84 |
} |
|
85 |
|
|
86 |
|
|
87 |
/** |
|
88 |
* Set environment variable |
6d969b
|
89 |
* |
T |
90 |
* @param string Property name |
|
91 |
* @param mixed Property value |
|
92 |
* @param boolean True if this property should be added to client environment |
f11541
|
93 |
*/ |
T |
94 |
function set_env($name, $value, $addtojs=true) |
|
95 |
{ |
|
96 |
$this->env[$name] = $value; |
|
97 |
if ($addtojs || isset($this->js_env[$name])) |
|
98 |
$this->js_env[$name] = $value; |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
/** |
|
103 |
* Set page title variable |
|
104 |
*/ |
|
105 |
function set_pagetitle($title) |
|
106 |
{ |
|
107 |
$this->pagetitle = $title; |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
/** |
|
112 |
* Register a template object handler |
|
113 |
* |
|
114 |
* @param string Object name |
|
115 |
* @param string Function name to call |
|
116 |
*/ |
|
117 |
function add_handler($obj, $func) |
|
118 |
{ |
|
119 |
$this->object_handlers[$obj] = $func; |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Register a list of template object handlers |
|
124 |
* |
|
125 |
* @param array Hash array with object=>handler pairs |
|
126 |
*/ |
|
127 |
function add_handlers($arr) |
|
128 |
{ |
|
129 |
$this->object_handlers = array_merge($this->object_handlers, $arr); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Register a GUI object to the client script |
|
134 |
* |
|
135 |
* @param string Object name |
|
136 |
* @param string Object ID |
|
137 |
*/ |
|
138 |
function add_gui_object($obj, $id) |
|
139 |
{ |
|
140 |
$this->add_script(JS_OBJECT_NAME.".gui_object('$obj', '$id');"); |
|
141 |
} |
|
142 |
|
|
143 |
|
|
144 |
/** |
|
145 |
* Call a client method |
|
146 |
* |
|
147 |
* @param string Method to call |
|
148 |
* @param ... Additional arguments |
|
149 |
*/ |
|
150 |
function command() |
|
151 |
{ |
|
152 |
$this->js_commands[] = func_get_args(); |
|
153 |
} |
|
154 |
|
|
155 |
|
|
156 |
/** |
|
157 |
* Invoke display_message command |
6d969b
|
158 |
* |
T |
159 |
* @param string Message to display |
|
160 |
* @param string Message type [notice|confirm|error] |
|
161 |
* @param array Key-value pairs to be replaced in localized text |
f11541
|
162 |
*/ |
T |
163 |
function show_message($message, $type='notice', $vars=NULL) |
|
164 |
{ |
|
165 |
$this->command( |
|
166 |
'display_message', |
|
167 |
rcube_label(array('name' => $message, 'vars' => $vars)), |
|
168 |
$type); |
|
169 |
} |
|
170 |
|
|
171 |
|
|
172 |
/** |
|
173 |
* Delete all stored env variables and commands |
|
174 |
*/ |
|
175 |
function reset() |
|
176 |
{ |
|
177 |
$this->env = array(); |
|
178 |
$this->js_env = array(); |
|
179 |
$this->js_commands = array(); |
|
180 |
$this->object_handlers = array(); |
|
181 |
parent::reset(); |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Send the request output to the client. |
|
186 |
* This will either parse a skin tempalte or send an AJAX response |
|
187 |
* |
|
188 |
* @param string Template name |
|
189 |
* @param boolean True if script should terminate (default) |
|
190 |
*/ |
|
191 |
function send($templ=null, $exit=true) |
|
192 |
{ |
|
193 |
if ($this->ajax_call) |
|
194 |
$this->remote_response('', !$exit); |
|
195 |
else if ($templ != 'iframe') |
|
196 |
$this->parse($templ, false); |
|
197 |
else |
|
198 |
{ |
|
199 |
$this->framed = $templ == 'iframe' ? true : $this->framed; |
|
200 |
$this->write(); |
|
201 |
} |
|
202 |
|
|
203 |
if ($exit) |
|
204 |
exit; |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
/** |
|
209 |
* Send an AJAX response with executable JS code |
|
210 |
* |
|
211 |
* @param string Additional JS code |
|
212 |
* @param boolean True if output buffer should be flushed |
|
213 |
*/ |
|
214 |
function remote_response($add='', $flush=false) |
|
215 |
{ |
|
216 |
static $s_header_sent = FALSE; |
|
217 |
|
|
218 |
if (!$s_header_sent) |
|
219 |
{ |
|
220 |
$s_header_sent = TRUE; |
|
221 |
send_nocacheing_headers(); |
|
222 |
header('Content-Type: application/x-javascript; charset='.RCMAIL_CHARSET); |
|
223 |
print '/** ajax response ['.date('d/M/Y h:i:s O')."] **/\n"; |
|
224 |
} |
|
225 |
|
|
226 |
// unset default env vars |
|
227 |
unset($this->js_env['task'], $this->js_env['action'], $this->js_env['comm_path']); |
|
228 |
|
|
229 |
// send response code |
|
230 |
print rcube_charset_convert($this->get_js_commands() . $add, RCMAIL_CHARSET, $this->get_charset()); |
|
231 |
|
|
232 |
if ($flush) // flush the output buffer |
|
233 |
flush(); |
|
234 |
} |
|
235 |
|
|
236 |
|
|
237 |
/** |
6d969b
|
238 |
* Process template and write to stdOut |
T |
239 |
* |
|
240 |
* @param string HTML template |
|
241 |
* @see rcube_html_page::write() |
f11541
|
242 |
*/ |
T |
243 |
function write($template='') |
|
244 |
{ |
|
245 |
// write all env variables to client |
|
246 |
$js = $this->framed ? "if(window.parent) {\n" : ''; |
|
247 |
$js .= $this->get_js_commands() . ($this->framed ? ' }' : ''); |
|
248 |
$this->add_script($js, 'head_top'); |
|
249 |
|
|
250 |
// call super method |
|
251 |
parent::write($template, $this->config['skin_path']); |
|
252 |
} |
|
253 |
|
|
254 |
|
|
255 |
/** |
|
256 |
* Parse a specific skin template and deliver to stdout |
|
257 |
* |
|
258 |
* @param string Template name |
|
259 |
* @param boolean Exit script |
|
260 |
*/ |
|
261 |
function parse($name='main', $exit=true) |
|
262 |
{ |
|
263 |
$skin_path = $this->config['skin_path']; |
|
264 |
|
|
265 |
// read template file |
|
266 |
$templ = ''; |
|
267 |
$path = "$skin_path/templates/$name.html"; |
|
268 |
|
|
269 |
if($fp = @fopen($path, 'r')) |
|
270 |
{ |
|
271 |
$templ = fread($fp, filesize($path)); |
|
272 |
fclose($fp); |
|
273 |
} |
|
274 |
else |
|
275 |
{ |
|
276 |
raise_error(array( |
|
277 |
'code' => 501, |
|
278 |
'type' => 'php', |
|
279 |
'line' => __LINE__, |
|
280 |
'file' => __FILE__, |
|
281 |
'message' => "Error loading template for '$name'"), TRUE, TRUE); |
|
282 |
return FALSE; |
|
283 |
} |
|
284 |
|
|
285 |
// parse for specialtags |
|
286 |
$output = $this->parse_xml($this->parse_conditions($templ)); |
|
287 |
|
|
288 |
// add debug console |
|
289 |
if ($this->config['debug_level'] & 8) |
|
290 |
$this->add_footer('<div style="position:absolute;top:5px;left:5px;width:400px;padding:0.2em;background:white;opacity:0.8;z-index:9000"> |
|
291 |
<a href="#toggle" onclick="con=document.getElementById(\'dbgconsole\');con.style.display=(con.style.display==\'none\'?\'block\':\'none\');return false">console</a> |
|
292 |
<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>'); |
|
293 |
|
|
294 |
$this->write(trim($this->parse_with_globals($output)), $skin_path); |
|
295 |
|
|
296 |
if ($exit) |
|
297 |
exit; |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
/** |
|
302 |
* Return executable javascript code for all registered commands |
6d969b
|
303 |
* @access private |
f11541
|
304 |
*/ |
T |
305 |
function get_js_commands() |
|
306 |
{ |
|
307 |
$out = ''; |
|
308 |
if (!$this->framed) |
|
309 |
$out .= ($this->ajax_call ? 'this' : JS_OBJECT_NAME) . '.set_env('.json_serialize($this->js_env).");\n"; |
|
310 |
|
|
311 |
foreach ($this->js_commands as $i => $args) |
|
312 |
{ |
|
313 |
$method = array_shift($args); |
|
314 |
foreach ($args as $i => $arg) |
|
315 |
$args[$i] = json_serialize($arg); |
|
316 |
|
|
317 |
$parent = $this->framed || preg_match('/^parent\./', $method); |
|
318 |
$out .= sprintf( |
|
319 |
"%s.%s(%s);\n", |
|
320 |
$this->ajax_call ? 'this' : ($parent ? 'parent.' : '') . JS_OBJECT_NAME, |
|
321 |
preg_replace('/^parent\./', '', $method), |
|
322 |
join(',', $args)); |
|
323 |
} |
|
324 |
|
|
325 |
return $out; |
|
326 |
} |
|
327 |
|
|
328 |
/** |
|
329 |
* Make URLs starting with a slash point to skin directory |
6d969b
|
330 |
* @access private |
f11541
|
331 |
*/ |
T |
332 |
function abs_url($str) |
|
333 |
{ |
|
334 |
return preg_replace('/^\//', $this->config['skin_path'].'/', $str); |
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
/***** Template parsing methods *****/ |
|
340 |
|
|
341 |
/** |
6d969b
|
342 |
* Replace all strings ($varname) |
T |
343 |
* with the content of the according global variable. |
|
344 |
* @access private |
f11541
|
345 |
*/ |
T |
346 |
function parse_with_globals($input) |
|
347 |
{ |
|
348 |
$GLOBALS['__comm_path'] = $GLOBALS['COMM_PATH']; |
|
349 |
return preg_replace('/\$(__[a-z0-9_\-]+)/e', '$GLOBALS["\\1"]', $input); |
|
350 |
} |
|
351 |
|
|
352 |
|
|
353 |
/** |
|
354 |
* Parse for conditional tags |
6d969b
|
355 |
* @access private |
f11541
|
356 |
*/ |
T |
357 |
function parse_conditions($input) |
|
358 |
{ |
|
359 |
if (($matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE)) && count($matches)==4) |
|
360 |
{ |
|
361 |
if (preg_match('/^(else|endif)$/i', $matches[1])) |
|
362 |
return $matches[0] . $this->parse_conditions($matches[3]); |
|
363 |
else |
|
364 |
{ |
|
365 |
$attrib = parse_attrib_string($matches[2]); |
|
366 |
if (isset($attrib['condition'])) |
|
367 |
{ |
|
368 |
$condmet = $this->check_condition($attrib['condition']); |
|
369 |
$submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE); |
|
370 |
|
|
371 |
if ($condmet) |
719804
|
372 |
$result = $submatches[0] . ($submatches[1] != 'endif' ? preg_replace('/.*<roundcube:endif\s+[^>]+>/Uis', '', $submatches[3], 1) : $submatches[3]); |
f11541
|
373 |
else |
T |
374 |
$result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3]; |
|
375 |
|
|
376 |
return $matches[0] . $this->parse_conditions($result); |
|
377 |
} |
|
378 |
else |
|
379 |
{ |
|
380 |
raise_error(array('code' => 500, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__, |
|
381 |
'message' => "Unable to parse conditional tag " . $matches[2]), TRUE, FALSE); |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
385 |
|
|
386 |
return $input; |
|
387 |
} |
|
388 |
|
|
389 |
|
|
390 |
/** |
|
391 |
* Determines if a given condition is met |
|
392 |
* |
|
393 |
* @return True if condition is valid, False is not |
6d969b
|
394 |
* @access private |
f11541
|
395 |
*/ |
T |
396 |
function check_condition($condition) |
|
397 |
{ |
|
398 |
$condition = preg_replace( |
|
399 |
array('/session:([a-z0-9_]+)/i', '/config:([a-z0-9_]+)/i', '/env:([a-z0-9_]+)/i', '/request:([a-z0-9_]+)/ie'), |
|
400 |
array("\$_SESSION['\\1']", "\$this->config['\\1']", "\$this->env['\\1']", "get_input_value('\\1', RCUBE_INPUT_GPC)"), |
|
401 |
$condition); |
|
402 |
|
|
403 |
return @eval("return (".$condition.");"); |
|
404 |
} |
|
405 |
|
|
406 |
|
|
407 |
/** |
|
408 |
* Search for special tags in input and replace them |
|
409 |
* with the appropriate content |
|
410 |
* |
|
411 |
* @param string Input string to parse |
|
412 |
* @return Altered input string |
6d969b
|
413 |
* @access private |
f11541
|
414 |
*/ |
T |
415 |
function parse_xml($input) |
|
416 |
{ |
|
417 |
return preg_replace('/<roundcube:([-_a-z]+)\s+([^>]+)>/Uie', "\$this->xml_command('\\1', '\\2')", $input); |
|
418 |
} |
|
419 |
|
|
420 |
|
|
421 |
/** |
|
422 |
* Convert a xml command tag into real content |
|
423 |
* |
|
424 |
* @param string Tag command: object,button,label, etc. |
|
425 |
* @param string Attribute string |
|
426 |
* @return Tag/Object content string |
6d969b
|
427 |
* @access private |
f11541
|
428 |
*/ |
T |
429 |
function xml_command($command, $str_attrib, $add_attrib=array()) |
6d969b
|
430 |
{ |
f11541
|
431 |
$command = strtolower($command); |
T |
432 |
$attrib = parse_attrib_string($str_attrib) + $add_attrib; |
|
433 |
|
|
434 |
// empty output if required condition is not met |
|
435 |
if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) |
|
436 |
return ''; |
|
437 |
|
|
438 |
// execute command |
|
439 |
switch ($command) |
|
440 |
{ |
|
441 |
// return a button |
|
442 |
case 'button': |
|
443 |
if ($attrib['command']) |
|
444 |
return $this->button($attrib); |
|
445 |
break; |
|
446 |
|
|
447 |
// show a label |
|
448 |
case 'label': |
|
449 |
if ($attrib['name'] || $attrib['command']) |
|
450 |
return Q(rcube_label($attrib + array('vars' => array('product' => $this->config['product_name'])))); |
|
451 |
break; |
|
452 |
|
|
453 |
// include a file |
|
454 |
case 'include': |
|
455 |
$path = realpath($this->config['skin_path'].$attrib['file']); |
|
456 |
if ($fp = @fopen($path, 'r')) |
|
457 |
{ |
|
458 |
$incl = fread($fp, filesize($path)); |
|
459 |
fclose($fp); |
|
460 |
return $this->parse_xml($incl); |
|
461 |
} |
|
462 |
break; |
|
463 |
|
|
464 |
// return code for a specific application object |
|
465 |
case 'object': |
|
466 |
$object = strtolower($attrib['name']); |
|
467 |
|
|
468 |
// execute object handler function |
|
469 |
if ($this->object_handlers[$object] && function_exists($this->object_handlers[$object])) |
|
470 |
return call_user_func($this->object_handlers[$object], $attrib); |
|
471 |
|
|
472 |
else if ($object=='productname') |
6d969b
|
473 |
{ |
f11541
|
474 |
$name = !empty($this->config['product_name']) ? $this->config['product_name'] : 'RoundCube Webmail'; |
T |
475 |
return Q($name); |
6d969b
|
476 |
} |
f11541
|
477 |
else if ($object=='version') |
6d969b
|
478 |
{ |
f11541
|
479 |
return (string)RCMAIL_VERSION; |
6d969b
|
480 |
} |
f11541
|
481 |
else if ($object=='pagetitle') |
6d969b
|
482 |
{ |
f11541
|
483 |
$task = $this->task; |
T |
484 |
$title = !empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : ''; |
|
485 |
|
|
486 |
if (!empty($this->pagetitle)) |
|
487 |
$title .= $this->pagetitle; |
|
488 |
else if ($task == 'login') |
|
489 |
$title = rcube_label(array('name' => 'welcome', 'vars' => array('product' => $this->config['product_name']))); |
|
490 |
else |
|
491 |
$title .= ucfirst($task); |
|
492 |
|
|
493 |
return Q($title); |
6d969b
|
494 |
} |
f11541
|
495 |
|
T |
496 |
break; |
|
497 |
} |
|
498 |
|
|
499 |
return ''; |
6d969b
|
500 |
} |
f11541
|
501 |
|
T |
502 |
|
|
503 |
/** |
|
504 |
* Create and register a button |
|
505 |
* |
|
506 |
* @param array Button attributes |
|
507 |
* @return HTML button |
6d969b
|
508 |
* @access private |
f11541
|
509 |
*/ |
T |
510 |
function button($attrib) |
6d969b
|
511 |
{ |
f11541
|
512 |
global $CONFIG, $OUTPUT, $BROWSER, $MAIN_TASKS; |
T |
513 |
static $sa_buttons = array(); |
|
514 |
static $s_button_count = 100; |
|
515 |
|
|
516 |
// these commands can be called directly via url |
|
517 |
$a_static_commands = array('compose', 'list'); |
|
518 |
|
|
519 |
$skin_path = $this->config['skin_path']; |
|
520 |
|
|
521 |
if (!($attrib['command'] || $attrib['name'])) |
|
522 |
return ''; |
|
523 |
|
|
524 |
// try to find out the button type |
|
525 |
if ($attrib['type']) |
|
526 |
$attrib['type'] = strtolower($attrib['type']); |
|
527 |
else |
|
528 |
$attrib['type'] = ($attrib['image'] || $attrib['imagepas'] || $attrib['imageact']) ? 'image' : 'link'; |
|
529 |
|
|
530 |
$command = $attrib['command']; |
|
531 |
|
|
532 |
// take the button from the stack |
|
533 |
if($attrib['name'] && $sa_buttons[$attrib['name']]) |
|
534 |
$attrib = $sa_buttons[$attrib['name']]; |
|
535 |
|
|
536 |
// add button to button stack |
|
537 |
else if($attrib['image'] || $attrib['imageact'] || $attrib['imagepas'] || $attrib['class']) |
|
538 |
{ |
|
539 |
if (!$attrib['name']) |
|
540 |
$attrib['name'] = $command; |
|
541 |
|
|
542 |
if (!$attrib['image']) |
|
543 |
$attrib['image'] = $attrib['imagepas'] ? $attrib['imagepas'] : $attrib['imageact']; |
|
544 |
|
|
545 |
$sa_buttons[$attrib['name']] = $attrib; |
|
546 |
} |
|
547 |
|
|
548 |
// get saved button for this command/name |
|
549 |
else if ($command && $sa_buttons[$command]) |
|
550 |
$attrib = $sa_buttons[$command]; |
|
551 |
|
|
552 |
//else |
|
553 |
// return ''; |
|
554 |
|
|
555 |
|
|
556 |
// set border to 0 because of the link arround the button |
|
557 |
if ($attrib['type']=='image' && !isset($attrib['border'])) |
|
558 |
$attrib['border'] = 0; |
|
559 |
|
|
560 |
if (!$attrib['id']) |
|
561 |
$attrib['id'] = sprintf('rcmbtn%d', $s_button_count++); |
|
562 |
|
|
563 |
// get localized text for labels and titles |
|
564 |
if ($attrib['title']) |
|
565 |
$attrib['title'] = Q(rcube_label($attrib['title'])); |
|
566 |
if ($attrib['label']) |
|
567 |
$attrib['label'] = Q(rcube_label($attrib['label'])); |
|
568 |
|
|
569 |
if ($attrib['alt']) |
|
570 |
$attrib['alt'] = Q(rcube_label($attrib['alt'])); |
|
571 |
|
|
572 |
// set title to alt attribute for IE browsers |
|
573 |
if ($BROWSER['ie'] && $attrib['title'] && !$attrib['alt']) |
|
574 |
{ |
|
575 |
$attrib['alt'] = $attrib['title']; |
|
576 |
unset($attrib['title']); |
|
577 |
} |
|
578 |
|
|
579 |
// add empty alt attribute for XHTML compatibility |
|
580 |
if (!isset($attrib['alt'])) |
|
581 |
$attrib['alt'] = ''; |
|
582 |
|
|
583 |
|
|
584 |
// register button in the system |
|
585 |
if ($attrib['command']) |
|
586 |
{ |
|
587 |
$this->add_script(sprintf( |
|
588 |
"%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');", |
|
589 |
JS_OBJECT_NAME, |
|
590 |
$command, |
|
591 |
$attrib['id'], |
|
592 |
$attrib['type'], |
|
593 |
$attrib['imageact'] ? $skin_path.$attrib['imageact'] : $attrib['classact'], |
|
594 |
$attrib['imagesel'] ? $skin_path.$attrib['imagesel'] : $attrib['classsel'], |
|
595 |
$attrib['imageover'] ? $skin_path.$attrib['imageover'] : '') |
|
596 |
); |
|
597 |
|
|
598 |
// make valid href to specific buttons |
|
599 |
if (in_array($attrib['command'], $MAIN_TASKS)) |
41bece
|
600 |
$attrib['href'] = Q(rcmail_url(null, null, $attrib['command'])); |
f11541
|
601 |
else if (in_array($attrib['command'], $a_static_commands)) |
41bece
|
602 |
$attrib['href'] = Q(rcmail_url($attrib['command'])); |
f11541
|
603 |
} |
T |
604 |
|
|
605 |
// overwrite attributes |
|
606 |
if (!$attrib['href']) |
|
607 |
$attrib['href'] = '#'; |
|
608 |
|
|
609 |
if ($command) |
|
610 |
$attrib['onclick'] = sprintf("return %s.command('%s','%s',this)", JS_OBJECT_NAME, $command, $attrib['prop']); |
|
611 |
|
|
612 |
if ($command && $attrib['imageover']) |
|
613 |
{ |
|
614 |
$attrib['onmouseover'] = sprintf("return %s.button_over('%s','%s')", JS_OBJECT_NAME, $command, $attrib['id']); |
|
615 |
$attrib['onmouseout'] = sprintf("return %s.button_out('%s','%s')", JS_OBJECT_NAME, $command, $attrib['id']); |
|
616 |
} |
|
617 |
|
|
618 |
if ($command && $attrib['imagesel']) |
|
619 |
{ |
|
620 |
$attrib['onmousedown'] = sprintf("return %s.button_sel('%s','%s')", JS_OBJECT_NAME, $command, $attrib['id']); |
|
621 |
$attrib['onmouseup'] = sprintf("return %s.button_out('%s','%s')", JS_OBJECT_NAME, $command, $attrib['id']); |
|
622 |
} |
|
623 |
|
|
624 |
$out = ''; |
|
625 |
|
|
626 |
// generate image tag |
|
627 |
if ($attrib['type']=='image') |
|
628 |
{ |
|
629 |
$attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'width', 'height', 'border', 'hspace', 'vspace', 'align', 'alt')); |
|
630 |
$img_tag = sprintf('<img src="%%s"%s />', $attrib_str); |
|
631 |
$btn_content = sprintf($img_tag, $skin_path.$attrib['image']); |
|
632 |
if ($attrib['label']) |
|
633 |
$btn_content .= ' '.$attrib['label']; |
|
634 |
|
|
635 |
$link_attrib = array('href', 'onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'title'); |
|
636 |
} |
|
637 |
else if ($attrib['type']=='link') |
|
638 |
{ |
|
639 |
$btn_content = $attrib['label'] ? $attrib['label'] : $attrib['command']; |
|
640 |
$link_attrib = array('href', 'onclick', 'title', 'id', 'class', 'style'); |
|
641 |
} |
|
642 |
else if ($attrib['type']=='input') |
|
643 |
{ |
|
644 |
$attrib['type'] = 'button'; |
|
645 |
|
|
646 |
if ($attrib['label']) |
|
647 |
$attrib['value'] = $attrib['label']; |
|
648 |
|
|
649 |
$attrib_str = create_attrib_string($attrib, array('type', 'value', 'onclick', 'id', 'class', 'style')); |
|
650 |
$out = sprintf('<input%s disabled />', $attrib_str); |
|
651 |
} |
|
652 |
|
|
653 |
// generate html code for button |
|
654 |
if ($btn_content) |
|
655 |
{ |
|
656 |
$attrib_str = create_attrib_string($attrib, $link_attrib); |
|
657 |
$out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content); |
|
658 |
} |
|
659 |
|
|
660 |
return $out; |
|
661 |
} |
|
662 |
|
6d969b
|
663 |
} // end class rcmail_template |
f11541
|
664 |
|
6d969b
|
665 |
|
T |
666 |
|
|
667 |
// ************** common functions delivering gui objects ************** |
|
668 |
|
|
669 |
|
|
670 |
/** |
|
671 |
* Builder for GUI object 'message' |
|
672 |
* |
|
673 |
* @param array Named tag parameters |
|
674 |
* @return string HTML code for the gui object |
|
675 |
*/ |
|
676 |
function rcmail_message_container($attrib) |
|
677 |
{ |
|
678 |
global $OUTPUT; |
|
679 |
|
|
680 |
if (!$attrib['id']) |
|
681 |
$attrib['id'] = 'rcmMessageContainer'; |
|
682 |
|
|
683 |
// allow the following attributes to be added to the <table> tag |
|
684 |
$attrib_str = create_attrib_string($attrib, array('style', 'class', 'id')); |
|
685 |
$out = '<div' . $attrib_str . "></div>"; |
|
686 |
|
|
687 |
$OUTPUT->add_gui_object('message', $attrib['id']); |
|
688 |
|
|
689 |
return $out; |
|
690 |
} |
|
691 |
|
|
692 |
|
|
693 |
/** |
|
694 |
* GUI object 'username' |
|
695 |
* Showing IMAP username of the current session |
|
696 |
* |
|
697 |
* @param array Named tag parameters (currently not used) |
|
698 |
* @return string HTML code for the gui object |
|
699 |
*/ |
|
700 |
function rcmail_current_username($attrib) |
|
701 |
{ |
|
702 |
global $DB; |
|
703 |
static $s_username; |
|
704 |
|
|
705 |
// alread fetched |
|
706 |
if (!empty($s_username)) |
|
707 |
return $s_username; |
|
708 |
|
|
709 |
// get e-mail address form default identity |
|
710 |
$sql_result = $DB->query( |
|
711 |
"SELECT email AS mailto |
|
712 |
FROM ".get_table_name('identities')." |
|
713 |
WHERE user_id=? |
|
714 |
AND standard=1 |
|
715 |
AND del<>1", |
|
716 |
$_SESSION['user_id']); |
|
717 |
|
|
718 |
if ($DB->num_rows($sql_result)) |
|
719 |
{ |
|
720 |
$sql_arr = $DB->fetch_assoc($sql_result); |
|
721 |
$s_username = $sql_arr['mailto']; |
|
722 |
} |
|
723 |
else if (strstr($_SESSION['username'], '@')) |
|
724 |
$s_username = $_SESSION['username']; |
|
725 |
else |
|
726 |
$s_username = $_SESSION['username'].'@'.$_SESSION['imap_host']; |
|
727 |
|
|
728 |
return $s_username; |
|
729 |
} |
|
730 |
|
|
731 |
|
|
732 |
/** |
|
733 |
* GUI object 'loginform' |
|
734 |
* Returns code for the webmail login form |
|
735 |
* |
|
736 |
* @param array Named parameters |
|
737 |
* @return string HTML code for the gui object |
|
738 |
*/ |
|
739 |
function rcmail_login_form($attrib) |
|
740 |
{ |
|
741 |
global $CONFIG, $OUTPUT, $SESS_HIDDEN_FIELD; |
|
742 |
|
|
743 |
$labels = array(); |
|
744 |
$labels['user'] = rcube_label('username'); |
|
745 |
$labels['pass'] = rcube_label('password'); |
|
746 |
$labels['host'] = rcube_label('server'); |
|
747 |
|
719a25
|
748 |
$input_user = new textfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30) + $attrib); |
T |
749 |
$input_pass = new passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30) + $attrib); |
6d969b
|
750 |
$input_action = new hiddenfield(array('name' => '_action', 'value' => 'login')); |
T |
751 |
|
|
752 |
$fields = array(); |
|
753 |
$fields['user'] = $input_user->show(get_input_value('_user', RCUBE_INPUT_POST)); |
|
754 |
$fields['pass'] = $input_pass->show(); |
|
755 |
$fields['action'] = $input_action->show(); |
|
756 |
|
|
757 |
if (is_array($CONFIG['default_host'])) |
|
758 |
{ |
|
759 |
$select_host = new select(array('name' => '_host', 'id' => 'rcmloginhost')); |
|
760 |
|
|
761 |
foreach ($CONFIG['default_host'] as $key => $value) |
|
762 |
{ |
|
763 |
if (!is_array($value)) |
|
764 |
$select_host->add($value, (is_numeric($key) ? $value : $key)); |
|
765 |
else |
|
766 |
{ |
|
767 |
unset($select_host); |
|
768 |
break; |
|
769 |
} |
|
770 |
} |
|
771 |
|
|
772 |
$fields['host'] = isset($select_host) ? $select_host->show($_POST['_host']) : null; |
|
773 |
} |
|
774 |
else if (!strlen($CONFIG['default_host'])) |
|
775 |
{ |
|
776 |
$input_host = new textfield(array('name' => '_host', 'id' => 'rcmloginhost', 'size' => 30)); |
|
777 |
$fields['host'] = $input_host->show($_POST['_host']); |
|
778 |
} |
|
779 |
|
|
780 |
$form_name = strlen($attrib['form']) ? $attrib['form'] : 'form'; |
|
781 |
$form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : ''; |
|
782 |
$form_end = !strlen($attrib['form']) ? '</form>' : ''; |
|
783 |
|
|
784 |
if ($fields['host']) |
|
785 |
$form_host = <<<EOF |
|
786 |
|
|
787 |
</tr><tr> |
|
788 |
|
|
789 |
<td class="title"><label for="rcmloginhost">$labels[host]</label></td> |
|
790 |
<td>$fields[host]</td> |
|
791 |
|
|
792 |
EOF; |
|
793 |
|
|
794 |
$OUTPUT->add_gui_object('loginform', $form_name); |
|
795 |
|
|
796 |
$out = <<<EOF |
|
797 |
$form_start |
|
798 |
$SESS_HIDDEN_FIELD |
|
799 |
$fields[action] |
|
800 |
<table><tr> |
|
801 |
|
|
802 |
<td class="title"><label for="rcmloginuser">$labels[user]</label></td> |
|
803 |
<td>$fields[user]</td> |
|
804 |
|
|
805 |
</tr><tr> |
|
806 |
|
|
807 |
<td class="title"><label for="rcmloginpwd">$labels[pass]</label></td> |
|
808 |
<td>$fields[pass]</td> |
|
809 |
$form_host |
|
810 |
</tr></table> |
|
811 |
$form_end |
|
812 |
EOF; |
|
813 |
|
|
814 |
return $out; |
|
815 |
} |
|
816 |
|
|
817 |
|
|
818 |
/** |
|
819 |
* GUI object 'charsetselector' |
|
820 |
* |
|
821 |
* @param array Named parameters for the select tag |
|
822 |
* @return string HTML code for the gui object |
|
823 |
*/ |
|
824 |
function rcmail_charset_selector($attrib) |
|
825 |
{ |
|
826 |
global $OUTPUT; |
|
827 |
|
|
828 |
// pass the following attributes to the form class |
|
829 |
$field_attrib = array('name' => '_charset'); |
|
830 |
foreach ($attrib as $attr => $value) |
|
831 |
if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) |
|
832 |
$field_attrib[$attr] = $value; |
|
833 |
|
|
834 |
$charsets = array( |
|
835 |
'US-ASCII' => 'ASCII (English)', |
|
836 |
'EUC-JP' => 'EUC-JP (Japanese)', |
|
837 |
'EUC-KR' => 'EUC-KR (Korean)', |
|
838 |
'BIG5' => 'BIG5 (Chinese)', |
|
839 |
'GB2312' => 'GB2312 (Chinese)', |
|
840 |
'ISO-2022-JP' => 'ISO-2022-JP (Japanese)', |
|
841 |
'ISO-8859-1' => 'ISO-8859-1 (Latin-1)', |
|
842 |
'ISO-8859-2' => 'ISO-8895-2 (Central European)', |
|
843 |
'ISO-8859-7' => 'ISO-8859-7 (Greek)', |
|
844 |
'ISO-8859-9' => 'ISO-8859-9 (Turkish)', |
|
845 |
'Windows-1251' => 'Windows-1251 (Cyrillic)', |
|
846 |
'Windows-1252' => 'Windows-1252 (Western)', |
|
847 |
'Windows-1255' => 'Windows-1255 (Hebrew)', |
|
848 |
'Windows-1256' => 'Windows-1256 (Arabic)', |
|
849 |
'Windows-1257' => 'Windows-1257 (Baltic)', |
|
850 |
'UTF-8' => 'UTF-8' |
|
851 |
); |
|
852 |
|
|
853 |
$select = new select($field_attrib); |
|
854 |
$select->add(array_values($charsets), array_keys($charsets)); |
|
855 |
|
|
856 |
$set = $_POST['_charset'] ? $_POST['_charset'] : $OUTPUT->get_charset(); |
|
857 |
return $select->show($set); |
|
858 |
} |
|
859 |
|
|
860 |
|
|
861 |
/** |
|
862 |
* GUI object 'searchform' |
|
863 |
* Returns code for search function |
|
864 |
* |
|
865 |
* @param array Named parameters |
|
866 |
* @return string HTML code for the gui object |
|
867 |
*/ |
|
868 |
function rcmail_search_form($attrib) |
|
869 |
{ |
|
870 |
global $OUTPUT; |
|
871 |
|
|
872 |
// add some labels to client |
|
873 |
rcube_add_label('searching'); |
|
874 |
|
|
875 |
$attrib['name'] = '_q'; |
|
876 |
|
|
877 |
if (empty($attrib['id'])) |
|
878 |
$attrib['id'] = 'rcmqsearchbox'; |
|
879 |
|
|
880 |
$input_q = new textfield($attrib); |
|
881 |
$out = $input_q->show(); |
|
882 |
|
|
883 |
$OUTPUT->add_gui_object('qsearchbox', $attrib['id']); |
|
884 |
|
|
885 |
// add form tag around text field |
|
886 |
if (empty($attrib['form'])) |
|
887 |
$out = sprintf( |
|
888 |
'<form name="rcmqsearchform" action="./" '. |
|
889 |
'onsubmit="%s.command(\'search\');return false" style="display:inline;">%s</form>', |
|
890 |
JS_OBJECT_NAME, |
|
891 |
$out); |
|
892 |
|
|
893 |
return $out; |
|
894 |
} |
|
895 |
|
|
896 |
|
|
897 |
?> |