annotate program/include/rcmail_output_html.php @ 22:303b85d5b561

More cleaning up php8 Warnings/deprecations
author Charlie Root
date Wed, 15 Oct 2025 14:06:27 -0400
parents b631c1c7a3ce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 | program/include/rcmail_output_html.php |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 | This file is part of the Roundcube Webmail client |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 | Copyright (C) 2006-2014, The Roundcube Dev Team |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 | Licensed under the GNU General Public License version 3 or |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 | any later version with exceptions for skins & plugins. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 | See the README file for a full license statement. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 | PURPOSE: |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 | Class to handle HTML page output using a skin template. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 * Class to create HTML page output using a skin template
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 * @package Webmail
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 * @subpackage View
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 class rcmail_output_html extends rcmail_output
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 public $type = 'html';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 protected $message;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 protected $template_name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 protected $objects = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 protected $js_env = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 protected $js_labels = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 protected $js_commands = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 protected $skin_paths = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 protected $scripts_path = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 protected $script_files = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 protected $css_files = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 protected $scripts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 protected $default_template = "<html>\n<head><title></title></head>\n<body></body>\n</html>";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 protected $header = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 protected $footer = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 protected $body = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 protected $base_path = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 protected $assets_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 protected $assets_dir = RCUBE_INSTALL_PATH;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 protected $devel_mode = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 // deprecated names of templates used before 0.5
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 protected $deprecated_templates = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 'contact' => 'showcontact',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 'contactadd' => 'addcontact',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 'contactedit' => 'editcontact',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 'identityedit' => 'editidentity',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 'messageprint' => 'printmessage',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 * Constructor
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 public function __construct($task = null, $framed = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 parent::__construct();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 $this->devel_mode = $this->config->get('devel_mode');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 $this->set_env('task', $task);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 $this->set_env('x_frame_options', $this->config->get('x_frame_options', 'sameorigin'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 $this->set_env('standard_windows', (bool) $this->config->get('standard_windows'));
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
73 $this->set_env('locale', !empty($_SESSION['language']) ? $_SESSION['language'] : 'en_US');
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 $this->set_env('devel_mode', $this->devel_mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 // add cookie info
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 $this->set_env('cookie_domain', ini_get('session.cookie_domain'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 $this->set_env('cookie_path', ini_get('session.cookie_path'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 $this->set_env('cookie_secure', filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 // load the correct skin (in case user-defined)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 $skin = $this->config->get('skin');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 $this->set_skin($skin);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 $this->set_env('skin', $skin);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 $this->set_assets_path($this->config->get('assets_path'), $this->config->get('assets_dir'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
88 if (!empty($_REQUEST['_extwin'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 $this->set_env('extwin', 1);
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
90 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
91
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
92 if ($this->framed || $framed) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 $this->set_env('framed', 1);
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
94 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 $lic = <<<EOF
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 /*
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 @licstart The following is the entire license notice for the
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 JavaScript code in this page.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 Copyright (C) 2005-2014 The Roundcube Dev Team
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 The JavaScript code in this page is free software: you can redistribute
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 it and/or modify it under the terms of the GNU General Public License
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 as published by the Free Software Foundation, either version 3 of
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 the License, or (at your option) any later version.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 The code is distributed WITHOUT ANY WARRANTY; without even the implied
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 See the GNU GPL for more details.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 @licend The above is the entire license notice
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 for the JavaScript code in this page.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 EOF;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 // add common javascripts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 $this->add_script($lic, 'head_top');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 $this->add_script('var '.self::JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 // don't wait for page onload. Call init at the bottom of the page (delayed)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 $this->add_script(self::JS_OBJECT_NAME.'.init();', 'docready');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 $this->scripts_path = 'program/js/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 $this->include_script('jquery.min.js');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 $this->include_script('common.js');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 $this->include_script('app.js');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 // register common UI objects
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 $this->add_handlers(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 'loginform' => array($this, 'login_form'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131 'preloader' => array($this, 'preloader'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 'username' => array($this, 'current_username'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 'message' => array($this, 'message_container'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 'charsetselector' => array($this, 'charset_selector'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 'aboutcontent' => array($this, 'about_content'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 * Set environment variable
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 * @param string $name Property name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 * @param mixed $value Property value
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 * @param boolean $addtojs True if this property should be added
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 * to client environment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 public function set_env($name, $value, $addtojs = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 $this->env[$name] = $value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 if ($addtojs || isset($this->js_env[$name])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 $this->js_env[$name] = $value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 * Parse and set assets path
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 * @param string $path Assets path URL (relative or absolute)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 * @param string $fs_dif Assets path in filesystem
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 public function set_assets_path($path, $fs_dir = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 if (empty($path)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 $path = rtrim($path, '/') . '/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 // handle relative assets path
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 if (!preg_match('|^https?://|', $path) && $path[0] != '/') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 // save the path to search for asset files later
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 $this->assets_dir = $path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175 $base = preg_replace('/[?#&].*$/', '', $_SERVER['REQUEST_URI']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 $base = rtrim($base, '/');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 // remove url token if exists
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 if ($len = intval($this->config->get('use_secure_urls'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 $_base = explode('/', $base);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 $last = count($_base) - 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 $length = $len > 1 ? $len : 16; // as in rcube::get_secure_url_token()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 // we can't use real token here because it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 // does not exists in unauthenticated state,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 // hope this will not produce false-positive matches
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 if ($last > -1 && preg_match('/^[a-f0-9]{' . $length . '}$/', $_base[$last])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 $path = '../' . $path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 // set filesystem path for assets
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 if ($fs_dir) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 if ($fs_dir[0] != '/') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 $fs_dir = realpath(RCUBE_INSTALL_PATH . $fs_dir);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 // ensure the path ends with a slash
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 $this->assets_dir = rtrim($fs_dir, '/') . '/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 $this->assets_path = $path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 $this->set_env('assets_path', $path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 * Getter for the current page title
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 * @return string The page title
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 protected function get_pagetitle()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 if (!empty($this->pagetitle)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 $title = $this->pagetitle;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
216 else if (isset($this->env['task'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
217 if ($this->env['task'] == 'login') {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
218 $title = $this->app->gettext([
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
219 'name' => 'welcome',
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
220 'vars' => ['product' => $this->config->get('product_name')]
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
221 ]);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
222 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
223 else {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
224 $title = ucfirst($this->env['task']);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
225 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 else {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
228 $title = '';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 return $title;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 * Set skin
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 * @param string $skin Skin name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 * @return bool True if the skin exist and is readable, False otherwise
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 public function set_skin($skin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 // Sanity check to prevent from path traversal vulnerability (#1490620)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 if (strpos($skin, '/') !== false || strpos($skin, "\\") !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 rcube::raise_error(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 'file' => __FILE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 'line' => __LINE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 'message' => 'Invalid skin name'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 ), true, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 $valid = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 $path = RCUBE_INSTALL_PATH . 'skins/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 if (!empty($skin) && is_dir($path . $skin) && is_readable($path . $skin)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 $skin_path = 'skins/' . $skin;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 $valid = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 $skin_path = $this->config->get('skin_path');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 if (!$skin_path) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 $skin_path = 'skins/' . rcube_config::DEFAULT_SKIN;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 $valid = !$skin;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 $skin_path = rtrim($skin_path, '/');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 $this->config->set('skin_path', $skin_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 $this->base_path = $skin_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274 // register skin path(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 $this->skin_paths = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 $this->load_skin($skin_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 return $valid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 * Helper method to recursively read skin meta files and register search paths
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 private function load_skin($skin_path)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 $this->skin_paths[] = $skin_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 // read meta file and check for dependencies
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 $meta = @file_get_contents(RCUBE_INSTALL_PATH . $skin_path . '/meta.json');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 $meta = @json_decode($meta, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 $meta['path'] = $skin_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 $path_elements = explode('/', $skin_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 $skin_id = end($path_elements);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
296 if (empty($meta['name'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 $meta['name'] = $skin_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 $this->skins[$skin_id] = $meta;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
302 if (!empty($meta['extends'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 $path = RCUBE_INSTALL_PATH . 'skins/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 if (is_dir($path . $meta['extends']) && is_readable($path . $meta['extends'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 $this->load_skin('skins/' . $meta['extends']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 * Check if a specific template exists
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 * @param string $name Template name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315 * @return boolean True if template exists
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 public function template_exists($name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 foreach ($this->skin_paths as $skin_path) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 $filename = RCUBE_INSTALL_PATH . $skin_path . '/templates/' . $name . '.html';
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
321 if (
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
322 (is_file($filename) && is_readable($filename))
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
323 || (!empty($this->deprecated_templates[$name]) && $this->template_exists($this->deprecated_templates[$name]))
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 * Find the given file in the current skin path stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 * @param string $file File name/path to resolve (starting with /)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 * @param string &$skin_path Reference to the base path of the matching skin
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337 * @param string $add_path Additional path to search in
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 * @return mixed Relative path to the requested file or False if not found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 public function get_skin_file($file, &$skin_path = null, $add_path = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 $skin_paths = $this->skin_paths;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 if ($add_path) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 array_unshift($skin_paths, $add_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 foreach ($skin_paths as $skin_path) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 $path = realpath(RCUBE_INSTALL_PATH . $skin_path . $file);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 if ($path && is_file($path)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 return $skin_path . $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 if ($this->assets_dir != RCUBE_INSTALL_PATH) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 $path = realpath($this->assets_dir . $skin_path . $file);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 if ($path && is_file($path)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359 return $skin_path . $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368 * Register a GUI object to the client script
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 * @param string $obj Object name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371 * @param string $id Object ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 public function add_gui_object($obj, $id)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 $this->add_script(self::JS_OBJECT_NAME.".gui_object('$obj', '$id');");
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 * Call a client method
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381 * @param string Method to call
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 * @param ... Additional arguments
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384 public function command()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386 $cmd = func_get_args();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 if (strpos($cmd[0], 'plugin.') !== false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388 $this->js_commands[] = array('triggerEvent', $cmd[0], $cmd[1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390 $this->js_commands[] = $cmd;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 * Add a localized label to the client environment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 public function add_label()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 $args = func_get_args();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 if (count($args) == 1 && is_array($args[0])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 $args = $args[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 foreach ($args as $name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405 $this->js_labels[$name] = $this->app->gettext($name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410 * Invoke display_message command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 * @param string $message Message to display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 * @param string $type Message type [notice|confirm|error]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 * @param array $vars Key-value pairs to be replaced in localized text
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 * @param boolean $override Override last set message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 * @param int $timeout Message display time in seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 * @uses self::command()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 public function show_message($message, $type='notice', $vars=null, $override=true, $timeout=0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 if ($override || !$this->message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 if ($this->app->text_exists($message)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 if (!empty($vars))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425 $vars = array_map(array('rcube','Q'), $vars);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 $msgtext = $this->app->gettext(array('name' => $message, 'vars' => $vars));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
428 else {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 $msgtext = $message;
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
430 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 $this->message = $message;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433 $this->command('display_message', $msgtext, $type, $timeout * 1000);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438 * Delete all stored env variables and commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 * @param bool $all Reset all env variables (including internal)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 public function reset($all = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 $framed = $this->framed;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 $env = $all ? null : array_intersect_key($this->env, array('extwin'=>1, 'framed'=>1));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447 parent::reset();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449 // let some env variables survive
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 $this->env = $this->js_env = $env;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 $this->framed = $framed || $this->env['framed'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452 $this->js_labels = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 $this->js_commands = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 $this->script_files = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455 $this->scripts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 $this->header = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457 $this->footer = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458 $this->body = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460 // load defaults
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 if (!$all) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462 $this->__construct();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 * Redirect to a certain url
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469 * @param mixed $p Either a string with the action or url parameters as key-value pairs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470 * @param int $delay Delay in seconds
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471 * @param bool $secure Redirect to secure location (see rcmail::url())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473 public function redirect($p = array(), $delay = 1, $secure = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474 {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
475 if (!empty($this->env['extwin']))
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476 $p['extwin'] = 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 $location = $this->app->url($p, false, false, $secure);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478 header('Location: ' . $location);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 exit;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483 * Send the request output to the client.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 * This will either parse a skin tempalte or send an AJAX response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 * @param string $templ Template name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487 * @param boolean $exit True if script should terminate (default)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489 public function send($templ = null, $exit = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491 if ($templ != 'iframe') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 // prevent from endless loops
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493 if ($exit != 'recur' && $this->app->plugins->is_processing('render_page')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 rcube::raise_error(array('code' => 505, 'type' => 'php',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495 'file' => __FILE__, 'line' => __LINE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496 'message' => 'Recursion alert: ignoring output->send()'), true, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499 $this->parse($templ, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 $this->framed = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503 $this->write();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506 // set output asap
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507 ob_flush();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508 flush();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510 if ($exit) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 exit;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516 * Process template and write to stdOut
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 * @param string $template HTML template content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520 public function write($template = '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 if (!empty($this->script_files)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523 $this->set_env('request_token', $this->app->get_request_token());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526 $commands = $this->get_js_commands($framed);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 // if all js commands go to parent window we can ignore all
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 // script files and skip rcube_webmail initialization (#1489792)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530 if ($framed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 $this->scripts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 $this->script_files = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 $this->header = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 $this->footer = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 // write all javascript commands
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
538 if (!empty($commands)) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
539 $this->add_script($commands, 'head_top');
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
540 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 // allow (legal) iframe content to be loaded
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
543 $iframe = $this->framed || !empty($this->env['framed']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544 if (!headers_sent() && $iframe && ($xopt = $this->app->config->get('x_frame_options', 'sameorigin'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 if (strtolower($xopt) != 'sameorigin') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 header('X-Frame-Options: sameorigin', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 // call super method
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551 $this->_write($template, $this->config->get('skin_path'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555 * Parse a specific skin template and deliver to stdout (or return)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 * @param string $name Template name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 * @param boolean $exit Exit script
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 * @param boolean $write Don't write to stdout, return parsed content instead
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 * @link http://php.net/manual/en/function.exit.php
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563 function parse($name = 'main', $exit = true, $write = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565 $plugin = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 $realname = $name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567 $plugin_skin_paths = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 $this->template_name = $realname;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 $temp = explode('.', $name, 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572 if (count($temp) > 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 $plugin = $temp[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574 $name = $temp[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 $skin_dir = $plugin . '/skins/' . $this->config->get('skin');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 // apply skin search escalation list to plugin directory
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 foreach ($this->skin_paths as $skin_path) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579 $plugin_skin_paths[] = $this->app->plugins->url . $plugin . '/' . $skin_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 // add fallback to default skin
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583 if (is_dir($this->app->plugins->dir . $plugin . '/skins/default')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 $skin_dir = $plugin . '/skins/default';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 $plugin_skin_paths[] = $this->app->plugins->url . $skin_dir;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588 // prepend plugin skin paths to search list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 $this->skin_paths = array_merge($plugin_skin_paths, $this->skin_paths);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592 // find skin template
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
593 $path = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594 foreach ($this->skin_paths as $skin_path) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 $path = RCUBE_INSTALL_PATH . "$skin_path/templates/$name.html";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 // fallback to deprecated template names
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
598 if (!is_readable($path) && !empty($this->deprecated_templates[$realname])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
599 $dname = $this->deprecated_templates[$realname];
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
600 $path = RCUBE_INSTALL_PATH . "$skin_path/templates/$dname.html";
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 if (is_readable($path)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 rcube::raise_error(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604 'code' => 502, 'file' => __FILE__, 'line' => __LINE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605 'message' => "Using deprecated template '$dname' in $skin_path/templates. Please rename to '$realname'"
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606 ), true, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610 if (is_readable($path)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611 $this->config->set('skin_path', $skin_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612 // set base_path to core skin directory (not plugin's skin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613 $this->base_path = preg_replace('!plugins/\w+/!', '', $skin_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614 $skin_dir = preg_replace('!^plugins/!', '', $skin_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618 $path = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 }
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
621 #rcube::write_log('mail',"skin: $skin_path $realname $path");
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623 // read template file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 if (!$path || ($templ = @file_get_contents($path)) === false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625 rcube::raise_error(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626 'code' => 404,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 'type' => 'php',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628 'line' => __LINE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 'file' => __FILE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630 'message' => 'Error loading template for '.$realname
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631 ), true, $write);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633 $this->skin_paths = array_slice($this->skin_paths, count($plugin_skin_paths));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 // replace all path references to plugins/... with the configured plugins dir
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638 // and /this/ to the current plugin skin directory
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 if ($plugin) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 $templ = preg_replace(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641 array('/\bplugins\//', '/(["\']?)\/this\//'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642 array($this->app->plugins->url, '\\1'.$this->app->plugins->url.$skin_dir.'/'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 $templ
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
647 // parse for special tags
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648 $output = $this->parse_conditions($templ);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 $output = $this->parse_xml($output);
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
650 #rcube::write_log('mail',"px: ".strlen($output));
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 // trigger generic hook where plugins can put additional content to the page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653 $hook = $this->app->plugins->exec_hook("render_page", array('template' => $realname, 'content' => $output));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 // save some memory
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656 $output = $hook['content'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 unset($hook['content']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 // remove plugin skin paths from current context
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 $this->skin_paths = array_slice($this->skin_paths, count($plugin_skin_paths));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662 if (!$write) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663 return $this->postrender($output);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 $this->write(trim($output));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
668 if ($exit) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
669 exit;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
670 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
671 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
672
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
674 * Return executable javascript code for all registered commands
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
675 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
676 protected function get_js_commands(&$framed = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
678 $out = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
679 $parent_commands = 0;
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
680 $parent_prefix = '';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681 $top_commands = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683 // these should be always on top,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 // e.g. hide_message() below depends on env.framed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
685 if (!$this->framed && !empty($this->js_env)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
686 $top_commands[] = array('set_env', $this->js_env);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
687 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688 if (!empty($this->js_labels)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
689 $top_commands[] = array('add_label', $this->js_labels);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
690 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
691
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 // unlock interface after iframe load
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
693 $unlock = isset($_REQUEST['_unlock']) ? preg_replace('/[^a-z0-9]/i', '', $_REQUEST['_unlock']) : 0;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
694 if ($this->framed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
695 $top_commands[] = array('iframe_loaded', $unlock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
697 else if ($unlock) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
698 $top_commands[] = array('hide_message', $unlock);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
699 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 $commands = array_merge($top_commands, $this->js_commands);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 foreach ($commands as $i => $args) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
704 $method = array_shift($args);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 $parent = $this->framed || preg_match('/^parent\./', $method);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
707 foreach ($args as $i => $arg) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
708 $args[$i] = self::json_serialize($arg, $this->devel_mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
709 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
710
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
711 if ($parent) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
712 $parent_commands++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 $method = preg_replace('/^parent\./', '', $method);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714 $parent_prefix = 'if (window.parent && parent.' . self::JS_OBJECT_NAME . ') parent.';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715 $method = $parent_prefix . self::JS_OBJECT_NAME . '.' . $method;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718 $method = self::JS_OBJECT_NAME . '.' . $method;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721 $out .= sprintf("%s(%s);\n", $method, implode(',', $args));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
723
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
724 $framed = $parent_prefix && $parent_commands == count($commands);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
725
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
726 // make the output more compact if all commands go to parent window
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
727 if ($framed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
728 $out = "if (window.parent && parent." . self::JS_OBJECT_NAME . ") {\n"
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
729 . str_replace($parent_prefix, "\tparent.", $out)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730 . "}\n";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
731 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
732
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733 return $out;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
734 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
737 * Make URLs starting with a slash point to skin directory
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
738 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
739 * @param string $str Input string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
740 * @param bool $search_path True if URL should be resolved using the current skin path stack
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
741 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742 * @return string URL
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
743 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
744 public function abs_url($str, $search_path = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
745 {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
746 if (isset($str[0]) && $str[0] == '/') {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
747 if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
748 return $file_url;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
749 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
750
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751 return $this->base_path . $str;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754 return $str;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758 * Show error page and terminate script execution
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760 * @param int $code Error code
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 * @param string $message Error message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763 public function raise_error($code, $message)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 global $__page_content, $ERROR_CODE, $ERROR_MESSAGE;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 $ERROR_CODE = $code;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 $ERROR_MESSAGE = $message;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770 include RCUBE_INSTALL_PATH . 'program/steps/utils/error.inc';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771 exit;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775 * Modify path by adding URL prefix if configured
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 public function asset_url($path)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779 // iframe content can't be in a different domain
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 // @TODO: check if assests are on a different domain
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782 if (!$this->assets_path || in_array($path[0], array('?', '/', '.')) || strpos($path, '://')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783 return $path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 return $this->assets_path . $path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 /***** Template parsing methods *****/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 * Replace all strings ($varname)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 * with the content of the according global variable.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796 protected function parse_with_globals($input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 $GLOBALS['__version'] = html::quote(RCMAIL_VERSION);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799 $GLOBALS['__comm_path'] = html::quote($this->app->comm_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 $GLOBALS['__skin_path'] = html::quote($this->base_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802 return preg_replace_callback('/\$(__[a-z0-9_\-]+)/',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 array($this, 'globals_callback'), $input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 * Callback function for preg_replace_callback() in parse_with_globals()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809 protected function globals_callback($matches)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 return $GLOBALS[$matches[1]];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815 * Correct absolute paths in images and other tags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 * add timestamp to .js and .css filename
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 protected function fix_paths($output)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820 return preg_replace_callback(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821 '!(src|href|background)=(["\']?)([a-z0-9/_.-]+)(["\'\s>])!i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822 array($this, 'file_callback'), $output);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
823 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826 * Callback function for preg_replace_callback in fix_paths()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 * @return string Parsed string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830 protected function file_callback($matches)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 $file = $matches[3];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 $file = preg_replace('!^/this/!', '/', $file);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835 // correct absolute paths
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 if ($file[0] == '/') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837 $file = $this->base_path . $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 // add file modification timestamp
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841 if (preg_match('/\.(js|css)$/', $file, $m)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842 $file = $this->file_mod($file);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845 return $matches[1] . '=' . $matches[2] . $file . $matches[4];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
848 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849 * Correct paths of asset files according to assets_path
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851 protected function fix_assets_paths($output)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 return preg_replace_callback(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 '!(src|href|background)=(["\']?)([a-z0-9/_.?=-]+)(["\'\s>])!i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855 array($this, 'assets_callback'), $output);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859 * Callback function for preg_replace_callback in fix_assets_paths()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861 * @return string Parsed string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863 protected function assets_callback($matches)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865 $file = $this->asset_url($matches[3]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 return $matches[1] . '=' . $matches[2] . $file . $matches[4];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871 * Modify file by adding mtime indicator
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873 protected function file_mod($file)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875 $fs = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876 $ext = substr($file, strrpos($file, '.') + 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878 // use minified file if exists (not in development mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879 if (!$this->devel_mode && !preg_match('/\.min\.' . $ext . '$/', $file)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 $minified_file = substr($file, 0, strlen($ext) * -1) . 'min.' . $ext;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881 if ($fs = @filemtime($this->assets_dir . $minified_file)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882 return $minified_file . '?s=' . $fs;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 if ($fs = @filemtime($this->assets_dir . $file)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887 $file .= '?s=' . $fs;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890 return $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893 /**
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
894 * Public wrapper to dip into template parsing.
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896 * @param string $input Template content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 * @return string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899 * @uses rcmail_output_html::parse_xml()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900 * @since 0.1-rc1
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902 public function just_parse($input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904 $input = $this->parse_conditions($input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905 $input = $this->parse_xml($input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906 $input = $this->postrender($input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908 return $input;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912 * Parse for conditional tags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 protected function parse_conditions($input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>\n?/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 if ($matches && count($matches) == 4) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918 if (preg_match('/^(else|endif)$/i', $matches[1])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 return $matches[0] . $this->parse_conditions($matches[3]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 $attrib = html::parse_attrib_string($matches[2]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924 if (isset($attrib['condition'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925 $condmet = $this->check_condition($attrib['condition']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>\n?/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 if ($condmet) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929 $result = $submatches[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930 if ($submatches[1] != 'endif') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 $result .= preg_replace('/.*<roundcube:endif\s+[^>]+>\n?/Uis', '', $submatches[3], 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
934 $result .= $submatches[3];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938 $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941 return $matches[0] . $this->parse_conditions($result);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 rcube::raise_error(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945 'code' => 500, 'line' => __LINE__, 'file' => __FILE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946 'message' => "Unable to parse conditional tag " . $matches[2]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 ), true, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950 return $input;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954 * Determines if a given condition is met
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956 * @param string $condition Condition statement
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958 * @return boolean True if condition is met, False if not
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 * @todo Extend this to allow real conditions, not just "set"
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 protected function check_condition($condition)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963 return $this->eval_expression($condition);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 * Inserts hidden field with CSRF-prevention-token into POST forms
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 protected function alter_form_tag($matches)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 $out = $matches[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972 $attrib = html::parse_attrib_string($matches[1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
974 if (!empty($attrib['method']) && strtolower($attrib['method']) == 'post') {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975 $hidden = new html_hiddenfield(array('name' => '_token', 'value' => $this->app->get_request_token()));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976 $out .= "\n" . $hidden->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979 return $out;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983 * Parse & evaluate a given expression and return its result.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 * @param string $expression Expression statement
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987 * @return mixed Expression result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 protected function eval_expression($expression)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 $expression = preg_replace(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992 array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993 '/session:([a-z0-9_]+)/i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994 '/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995 '/env:([a-z0-9_]+)/i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 '/request:([a-z0-9_]+)/i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 '/cookie:([a-z0-9_]+)/i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998 '/browser:([a-z0-9_]+)/i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999 '/template:name/i',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 "\$_SESSION['\\1']",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003 "\$this->app->config->get('\\1',rcube_utils::get_boolean('\\3'))",
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1004 "(\$this->env['\\1'] ?? null)",
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005 "rcube_utils::get_input_value('\\1', rcube_utils::INPUT_GPC)",
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1006 "(\$_COOKIE['\\1'] ?? null)",
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1007 "(\$this->browser->{'\\1'} ?? null)",
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008 "'{$this->template_name}'",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 ),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010 $expression
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 // Note: We used create_function() before but it's deprecated in PHP 7.2
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014 // and really it was just a wrapper on eval().
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015 return eval("return ($expression);");
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019 * Search for special tags in input and replace them
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 * with the appropriate content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 * @param string $input Input string to parse
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024 * @return string Altered input string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 * @todo Use DOM-parser to traverse template HTML
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026 * @todo Maybe a cache.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028 protected function parse_xml($input)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030 return preg_replace_callback('/<roundcube:([-_a-z]+)\s+((?:[^>]|\\\\>)+)(?<!\\\\)>/Ui', array($this, 'xml_command'), $input);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 * Callback function for parsing an xml command tag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035 * and turn it into real html content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 * @param array $matches Matches array of preg_replace_callback
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 * @return string Tag/Object content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041 protected function xml_command($matches)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043 $command = strtolower($matches[1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044 $attrib = html::parse_attrib_string($matches[2]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 // empty output if required condition is not met
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047 if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048 return '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051 // localize title and summary attributes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052 if ($command != 'button' && !empty($attrib['title']) && $this->app->text_exists($attrib['title'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053 $attrib['title'] = $this->app->gettext($attrib['title']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 if ($command != 'button' && !empty($attrib['summary']) && $this->app->text_exists($attrib['summary'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056 $attrib['summary'] = $this->app->gettext($attrib['summary']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 // execute command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060 switch ($command) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 // return a button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062 case 'button':
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1063 if (!empty($attrib['name']) || !empty($attrib['command'])) {
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1064 #rcube::write_log('lab',"button in: ".print_r($attrib,true));
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1065 $but = $this->button($attrib);
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1066 #rcube::write_log('lab',"button out:\n$but");
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1067 return $but;
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1068
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072 // frame
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073 case 'frame':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 return $this->frame($attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077 // show a label
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078 case 'label':
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1079 if (!empty($attrib['expression'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080 $attrib['name'] = $this->eval_expression($attrib['expression']);
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1081 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1083 if (!empty($attrib['name']) || !empty($attrib['command'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1084 $vars = $attrib + ['product' => $this->config->get('product_name')];
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085 unset($vars['name'], $vars['command']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1087 $label = $this->app->gettext($attrib + ['vars' => $vars]);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1088 $quoting = null;
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1089
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1090 if (!empty($attrib['quoting'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1091 $quoting = strtolower($attrib['quoting']);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1092 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1093 else if (isset($attrib['html'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1094 $quoting = rcube_utils::get_boolean((string) $attrib['html']) ? 'no' : '';
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1095 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 // 'noshow' can be used in skins to define new labels
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1098 if (!empty($attrib['noshow'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 return '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 switch ($quoting) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 case 'no':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104 case 'raw':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106 case 'javascript':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107 case 'js':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 $label = rcube::JQ($label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110 default:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111 $label = html::quote($label);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115 return $label;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 case 'add_label':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120 $this->add_label($attrib['name']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1122
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1123 // include a file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1124 case 'include':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1125 $old_base_path = $this->base_path;
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1126 $attr_skin_path = !empty($attrib['skinpath']) ? $attrib['skinpath'] : null;
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1127
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1128 if (!empty($attrib['skin_path'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1129 $attr_skin_path = $attrib['skin_path'];
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1130 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1131
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1132 if ($path = $this->get_skin_file($attrib['file'], $skin_path, $attr_skin_path)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1133 // set base_path to core skin directory (not plugin's skin)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1134 $this->base_path = preg_replace('!plugins/\w+/!', '', $skin_path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1135 $path = realpath(RCUBE_INSTALL_PATH . $path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1136 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1137
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1138 if (is_readable($path)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1139 if ($this->config->get('skin_include_php')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1140 $incl = $this->include_php($path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1141 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1142 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1143 $incl = file_get_contents($path);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1144 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1145 $incl = $this->parse_conditions($incl);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1146 $incl = $this->parse_xml($incl);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1147 $incl = $this->fix_paths($incl);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1148 $this->base_path = $old_base_path;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1149 return $incl;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1150 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1151 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1152
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1153 case 'plugin.include':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1154 $hook = $this->app->plugins->exec_hook("template_plugin_include", $attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1155 return $hook['content'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1156
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1157 // define a container block
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1158 case 'container':
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1159 if (!empty($attrib['name']) && !empty($attrib['id'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1160 $this->command('gui_container', $attrib['name'], $attrib['id']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1161 // let plugins insert some content here
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1162 $hook = $this->app->plugins->exec_hook("template_container", $attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1163 return $hook['content'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1164 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1165 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1166
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1167 // return code for a specific application object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1168 case 'object':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1169 $object = strtolower($attrib['name']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1170 $content = '';
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1171 $handler = null;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1172
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1173 if (!empty($this->object_handlers[$object])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1174 $handler = $this->object_handlers[$object];
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1175 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1176 // execute object handler function
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1177 if (is_callable($handler)) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1178
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1179 // We assume that objects with src attribute are internal (in most
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1180 // cases this is a watermark frame). We need this to make sure assets_path
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1181 // is added to the internal assets paths
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1182 $external = empty($attrib['src']);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1183 $content = call_user_func($handler, $attrib);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1184 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1185 else if ($object == 'doctype') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1186 $content = html::doctype($attrib['value']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1187 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1188 else if ($object == 'logo') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1189 $attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"')));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1190
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1191 if ($logo = $this->config->get('skin_logo')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1192 if (is_array($logo)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1193 if ($template_logo = $logo[$this->template_name]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1194 $attrib['src'] = $template_logo;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1195 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1196 elseif ($template_logo = $logo['*']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1197 $attrib['src'] = $template_logo;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1198 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1199 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1200 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1201 $attrib['src'] = $logo;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1202 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1203 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1204
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1205 $content = html::img($attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1206 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1207 else if ($object == 'productname') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1208 $name = $this->config->get('product_name', 'Roundcube Webmail');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1209 $content = html::quote($name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1210 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1211 else if ($object == 'version') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1212 $ver = (string)RCMAIL_VERSION;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1213 if (is_file(RCUBE_INSTALL_PATH . '.svn/entries')) {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1214 if (preg_match('/Revision:\s(\d+)/', (string) @shell_exec('svn info'), $regs))
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1215 $ver .= ' [SVN r'.$regs[1].']';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1216 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1217 else if (is_file(RCUBE_INSTALL_PATH . '.git/index')) {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1218 if (preg_match('/Date:\s+([^\n]+)/', (string) @shell_exec('git log -1'), $regs)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1219 if ($date = date('Ymd.Hi', strtotime($regs[1]))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1220 $ver .= ' [GIT '.$date.']';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1221 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1222 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1223 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1224 $content = html::quote($ver);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1225 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1226 else if ($object == 'steptitle') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1227 $content = html::quote($this->get_pagetitle());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1228 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1229 else if ($object == 'pagetitle') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1230 if ($this->devel_mode && !empty($_SESSION['username']))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1231 $title = $_SESSION['username'].' :: ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1232 else if ($prod_name = $this->config->get('product_name'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1233 $title = $prod_name . ' :: ';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1234 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1235 $title = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1236 $title .= $this->get_pagetitle();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1237 $content = html::quote($title);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1238 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1239
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1240 // exec plugin hooks for this template object
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1241 $hook = $this->app->plugins->exec_hook("template_object_$object", $attrib + array('content' => (string) $content));
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1242
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1243 if (strlen($hook['content']) && !empty($external)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1244 $object_id = uniqid('TEMPLOBJECT:', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1245 $this->objects[$object_id] = $hook['content'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1246 $hook['content'] = $object_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1247 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1248
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1249 return $hook['content'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1250
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1251 // return code for a specified eval expression
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1252 case 'exp':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1253 return html::quote($this->eval_expression($attrib['expression']));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1254
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1255 // return variable
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1256 case 'var':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1257 $var = explode(':', $attrib['name']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1258 $name = $var[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1259 $value = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1260
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1261 switch ($var[0]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1262 case 'env':
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1263 $value = $this->env[$name] ?? null;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1264 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1265 case 'config':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1266 $value = $this->config->get($name);
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1267 if (is_array($value) && !empty($value[$_SESSION['storage_host']])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1268 $value = $value[$_SESSION['storage_host']];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1269 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1270 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1271 case 'request':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1272 $value = rcube_utils::get_input_value($name, rcube_utils::INPUT_GPC);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1273 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1274 case 'session':
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1275 $value = $_SESSION[$name] ?? '';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1276 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1277 case 'cookie':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1278 $value = htmlspecialchars($_COOKIE[$name]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1279 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1280 case 'browser':
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1281 $value = $this->browser->{$name} ?? '';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1282 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1283 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1284
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1285 if (is_array($value)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1286 $value = implode(', ', $value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1287 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1288
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1289 return html::quote($value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1290
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1291 case 'form':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1292 return $this->form_tag($attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1293 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1294 return '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1295 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1296
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1297 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1298 * Include a specific file and return it's contents
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1299 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1300 * @param string $file File path
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1301 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1302 * @return string Contents of the processed file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1303 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1304 protected function include_php($file)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1305 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1306 ob_start();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1307 include $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1308 $out = ob_get_contents();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1309 ob_end_clean();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1310
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1311 return $out;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1312 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1313
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1314 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1315 * Put objects' content back into template output
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1316 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1317 protected function postrender($output)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1318 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1319 // insert objects' contents
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1320 foreach ($this->objects as $key => $val) {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1321 $output = str_replace($key, (string) $val, $output, $count);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1322 if ($count) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1323 $this->objects[$key] = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1324 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1325 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1326
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1327 // make sure all <form> tags have a valid request token
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1328 $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1329
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1330 return $output;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1331 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1332
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1333 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1334 * Create and register a button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1335 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1336 * @param array $attrib Named button attributes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1337 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1338 * @return string HTML button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1339 * @todo Remove all inline JS calls and use jQuery instead.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1340 * @todo Remove all sprintf()'s - they are pretty, but also slow.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1341 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1342 public function button($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1343 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1344 static $s_button_count = 100;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1345 static $disabled_actions = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1346
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1347 // these commands can be called directly via url
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1348 $a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1349
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1350 if (empty($attrib['command']) && empty($attrib['name']) && empty($attrib['href'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1351 return '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1352 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1353
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1354 // try to find out the button type
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1355 if (!empty($attrib['type'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1356 $attrib['type'] = strtolower($attrib['type']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1357 if ($pos = strpos($attrib['type'], '-menuitem')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1358 $attrib['type'] = substr($attrib['type'], 0, -9);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1359 $menuitem = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1360 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1361 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1362 else {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1363 $attrib['type'] = (!empty($attrib['image']) || !empty($attrib['imagepas']) || !empty($attrib['imageact'])) ? 'image' : 'link';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1364 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1365
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1366 $command = $attrib['command']??'';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1367
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1368 if (!empty($attrib['task'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1369 $element = $command = $attrib['task'] . '.' . $command;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1370 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1371 else {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1372 $element = (!empty($this->env['task']) ? $this->env['task'] . '.' : '') . $command;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1373 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1374
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1375 if ($disabled_actions === null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1376 $disabled_actions = (array) $this->config->get('disabled_actions');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1377 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1378
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1379 // remove buttons for disabled actions
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1380 if (in_array($element, $disabled_actions)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1381 return '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1382 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1383
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1384 if (empty($attrib['image'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1385 if (!empty($attrib['imagepas'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1386 $attrib['image'] = $attrib['imagepas'];
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1387 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1388 else if (!empty($attrib['imageact'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1389 $attrib['image'] = $attrib['imageact'];
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1390 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1391 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1392
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1393 if (empty($attrib['id'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1394 $attrib['id'] = sprintf('rcmbtn%d', $s_button_count++);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1395 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1396 // get localized text for labels and titles
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1397 $domain = !empty($attrib['domain']) ? $attrib['domain'] : null;
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1398 if (!empty($attrib['title'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1399 $attrib['title'] = html::quote($this->app->gettext($attrib['title'], $domain));
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1400 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1401 if (!empty($attrib['label'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1402 $attrib['label'] = html::quote($this->app->gettext($attrib['label'], $domain));
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1403 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1404 if (!empty($attrib['alt'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1405 $attrib['alt'] = html::quote($this->app->gettext($attrib['alt'], $domain));
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1406 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1407
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1408 // set accessibility attributes
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1409 if (empty($attrib['role'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1410 $attrib['role'] = 'button';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1411 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1412 if (!empty($attrib['class']) && !empty($attrib['classact']) || !empty($attrib['imagepas']) && !empty($attrib['imageact'])) {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1413 if (array_key_exists('tabindex', $attrib)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1414 $attrib['data-tabindex'] = $attrib['tabindex'];
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1415 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1416 $attrib['tabindex'] = '-1'; // disable button by default
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1417 $attrib['aria-disabled'] = 'true';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1418 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1419
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1420 // set title to alt attribute for IE browsers
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1421 if ($this->browser->ie && empty($attrib['title']) && !empty($attrib['alt'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1422 $attrib['title'] = $attrib['alt'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1423 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1424
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1425 // add empty alt attribute for XHTML compatibility
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1426 if (!isset($attrib['alt'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1427 $attrib['alt'] = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1428 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1429
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1430 // register button in the system
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1431 if (!empty($attrib['command'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1432 $this->add_script(sprintf(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1433 "%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1434 self::JS_OBJECT_NAME,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1435 $command,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1436 $attrib['id'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1437 $attrib['type'],
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1438 !empty($attrib['imageact']) ? $this->abs_url($attrib['imageact']) : (!empty($attrib['classact']) ? $attrib['classact'] : ''),
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1439 !empty($attrib['imagesel']) ? $this->abs_url($attrib['imagesel']) : (!empty($attrib['classsel']) ? $attrib['classsel'] : ''),
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1440 !empty($attrib['imageover']) ? $this->abs_url($attrib['imageover']) : ''
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1441 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1442
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1443 // make valid href to specific buttons
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1444 if (in_array($attrib['command'], rcmail::$main_tasks)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1445 $attrib['href'] = $this->app->url(array('task' => $attrib['command']));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1446 $attrib['onclick'] = sprintf("return %s.command('switch-task','%s',this,event)", self::JS_OBJECT_NAME, $attrib['command']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1447 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1448 else if (!empty($attrib['task']) && in_array($attrib['task'], rcmail::$main_tasks)) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1449 $attrib['href'] = $this->app->url(['action' => $attrib['command'], 'task' => $attrib['task']]);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1450 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1451 else if (in_array($attrib['command'], $a_static_commands)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1452 $attrib['href'] = $this->app->url(array('action' => $attrib['command']));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1453 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1454 else if (($attrib['command'] == 'permaurl' || $attrib['command'] == 'extwin') && !empty($this->env['permaurl'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1455 $attrib['href'] = $this->env['permaurl'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1456 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1457 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1458
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1459 // overwrite attributes
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1460 if (empty($attrib['href'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1461 $attrib['href'] = '#';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1462 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1463
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1464 if (!empty($attrib['task'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1465 if (!empty($attrib['classact'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1466 $attrib['class'] = $attrib['classact'];
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1467 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1468 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1469 else if ($command && empty($attrib['onclick'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1470 $attrib['onclick'] = sprintf(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1471 "return %s.command('%s','%s',this,event)",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1472 self::JS_OBJECT_NAME,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1473 $command,
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1474 !empty($attrib['prop']) ? $attrib['prop'] : ''
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1475 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1476 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1477
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1478 $out = '';
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1479 $btn_content = null;
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1480 $link_attrib = [];
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1481
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1482 // generate image tag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1483 if ($attrib['type'] == 'image') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1484 $attrib_str = html::attrib_string(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1485 $attrib,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1486 array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1487 'style', 'class', 'id', 'width', 'height', 'border', 'hspace',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1488 'vspace', 'align', 'alt', 'tabindex', 'title'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1489 )
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1490 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1491 $btn_content = sprintf('<img src="%s"%s />', $this->abs_url($attrib['image']), $attrib_str);
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1492 if (!empty($attrib['label'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1493 $btn_content .= ' '.$attrib['label'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1494 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1495 $link_attrib = array('href', 'onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'target');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1496 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1497 else if ($attrib['type'] == 'link') {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1498 $btn_content = $attrib['content'] ?? (!empty($attrib['label']) ? $attrib['label'] : $attrib['command']);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1499 $link_attrib = array_merge(html::$common_attrib, ['href', 'onclick', 'tabindex', 'target', 'rel']);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1500 if (!empty($attrib['innerclass'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1501 $btn_content = html::span($attrib['innerclass'], $btn_content);
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1502 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1503 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1504 else if ($attrib['type'] == 'input') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1505 $attrib['type'] = 'button';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1506
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1507 if (!empty($attrib['label'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1508 $attrib['value'] = $attrib['label'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1509 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1510 if (!empty($attrib['command'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1511 $attrib['disabled'] = 'disabled';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1512 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1513
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1514 $out = html::tag('input', $attrib, null, ['type', 'value', 'onclick', 'id', 'class', 'style', 'tabindex', 'disabled']);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1515 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1516 else {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1517 if (!empty($attrib['label'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1518 $attrib['value'] = $attrib['label'];
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1519 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1520 if (!empty($attrib['command'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1521 $attrib['disabled'] = 'disabled';
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1522 }
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1523
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1524 $content = $attrib['content'] ?? $attrib['label'];
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1525 $out = html::tag('button', $attrib, $content, ['type', 'value', 'onclick', 'id', 'class', 'style', 'tabindex', 'disabled']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1526 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1527
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1528 // generate html code for button
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1529 if ($btn_content) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1530 $attrib_str = html::attrib_string($attrib, $link_attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1531 $out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1532 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1533
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1534 if (!empty($attrib['wrapper'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1535 $out = html::tag($attrib['wrapper'], null, $out);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1536 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1537
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1538 if (!empty($menuitem)) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1539 $class = !empty($attrib['menuitem-class']) ? ' class="' . $attrib['menuitem-class'] . '"' : '';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1540 $out = '<li role="menuitem"' . $class . '>' . $out . '</li>';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1541 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1542
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1543 return $out;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1544 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1545
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1546 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1547 * Link an external script file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1548 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1549 * @param string $file File URL
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1550 * @param string $position Target position [head|foot]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1551 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1552 public function include_script($file, $position='head')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1553 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1554 if (!preg_match('|^https?://|i', $file) && $file[0] != '/') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1555 $file = $this->file_mod($this->scripts_path . $file);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1556 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1557
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1558 if (!isset($this->script_files[$position]) || !is_array($this->script_files[$position])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1559 $this->script_files[$position] = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1560 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1561
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1562 if (!in_array($file, $this->script_files[$position])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1563 $this->script_files[$position][] = $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1564 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1565 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1566
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1567 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1568 * Add inline javascript code
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1569 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1570 * @param string $script JS code snippet
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1571 * @param string $position Target position [head|head_top|foot]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1572 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1573 public function add_script($script, $position='head')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1574 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1575 if (!isset($this->scripts[$position])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1576 $this->scripts[$position] = "\n" . rtrim($script);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1577 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1578 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1579 $this->scripts[$position] .= "\n" . rtrim($script);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1580 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1581 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1582
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1583 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1584 * Link an external css file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1585 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1586 * @param string $file File URL
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1587 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1588 public function include_css($file)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1589 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1590 $this->css_files[] = $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1591 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1592
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1593 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1594 * Add HTML code to the page header
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1595 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1596 * @param string $str HTML code
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1597 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1598 public function add_header($str)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1599 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1600 $this->header .= "\n" . $str;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1601 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1602
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1603 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1604 * Add HTML code to the page footer
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1605 * To be added right before </body>
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1606 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1607 * @param string $str HTML code
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1608 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1609 public function add_footer($str)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1610 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1611 $this->footer .= "\n" . $str;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1612 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1613
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1614 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1615 * Process template and write to stdOut
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1616 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1617 * @param string $templ HTML template
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1618 * @param string $base_path Base for absolute paths
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1619 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1620 protected function _write($templ = '', $base_path = '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1621 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1622 $output = trim($templ);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1623
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1624 if (empty($output)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1625 $output = html::doctype('html5') . "\n" . $this->default_template;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1626 $is_empty = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1627 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1628
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1629 // set default page title
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1630 if (empty($this->pagetitle)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1631 $this->pagetitle = 'Roundcube Mail';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1632 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1633
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1634 // declare page language
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1635 if (!empty($_SESSION['language'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1636 $lang = substr($_SESSION['language'], 0, 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1637 $output = preg_replace('/<html/', '<html lang="' . html::quote($lang) . '"', $output, 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1638 if (!headers_sent()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1639 header('Content-Language: ' . $lang);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1640 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1641 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1642
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1643 // replace specialchars in content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1644 $page_title = html::quote($this->pagetitle);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1645 $page_header = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1646 $page_footer = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1647
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1648 // include meta tag with charset
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1649 if (!empty($this->charset)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1650 if (!headers_sent()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1651 header('Content-Type: text/html; charset=' . $this->charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1652 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1653 $page_header = '<meta http-equiv="content-type"';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1654 $page_header.= ' content="text/html; charset=';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1655 $page_header.= $this->charset . '" />'."\n";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1656 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1657
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1658 // definition of the code to be placed in the document header and footer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1659 if (is_array($this->script_files['head'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1660 foreach ($this->script_files['head'] as $file) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1661 $page_header .= html::script($file);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1662 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1663 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1664
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1665 $head_script = $this->scripts['head_top'] . $this->scripts['head'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1666 if (!empty($head_script)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1667 $page_header .= html::script(array(), $head_script);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1668 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1669
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1670 if (!empty($this->header)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1671 $page_header .= $this->header;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1672 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1673
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1674 // put docready commands into page footer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1675 if (!empty($this->scripts['docready'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1676 $this->add_script('$(document).ready(function(){ ' . $this->scripts['docready'] . "\n});", 'foot');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1677 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1678
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1679 if (!empty($this->script_files['foot'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1680 foreach ($this->script_files['foot'] as $file) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1681 $page_footer .= html::script($file);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1682 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1683 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1684
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1685 if (!empty($this->footer)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1686 $page_footer .= $this->footer . "\n";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1687 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1688
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1689 if (!empty($this->scripts['foot'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1690 $page_footer .= html::script(array(), $this->scripts['foot']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1691 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1692
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1693 // find page header
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1694 if ($hpos = stripos($output, '</head>')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1695 $page_header .= "\n";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1696 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1697 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1698 if (!is_numeric($hpos)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1699 $hpos = stripos($output, '<body');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1700 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1701 if (!is_numeric($hpos) && ($hpos = stripos($output, '<html'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1702 while ($output[$hpos] != '>') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1703 $hpos++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1704 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1705 $hpos++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1706 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1707 $page_header = "<head>\n<title>$page_title</title>\n$page_header\n</head>\n";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1708 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1709
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1710 // add page header
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1711 if ($hpos) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1712 $output = substr_replace($output, $page_header, $hpos, 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1713 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1714 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1715 $output = $page_header . $output;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1716 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1717
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1718 // add page footer
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1719 if (($fpos = strripos($output, '</body>')) || ($fpos = strripos($output, '</html>'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1720 $output = substr_replace($output, $page_footer."\n", $fpos, 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1721 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1722 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1723 $output .= "\n".$page_footer;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1724 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1725
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1726 // add css files in head, before scripts, for speed up with parallel downloads
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1727 if (!empty($this->css_files) && empty($is_empty)
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1728 && (($pos = stripos($output, '<script ')) || ($pos = stripos($output, '</head>')))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1729 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1730 $css = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1731 foreach ($this->css_files as $file) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1732 $css .= html::tag('link', array('rel' => 'stylesheet',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1733 'type' => 'text/css', 'href' => $file, 'nl' => true));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1734 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1735 $output = substr_replace($output, $css, $pos, 0);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1736 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1737
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1738 $output = $this->parse_with_globals($this->fix_paths($output));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1739
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1740 if ($this->assets_path) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1741 $output = $this->fix_assets_paths($output);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1742 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1743
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1744 $output = $this->postrender($output);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1745
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1746 // trigger hook with final HTML content to be sent
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1747 $hook = $this->app->plugins->exec_hook("send_page", array('content' => $output));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1748 if (!$hook['abort']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1749 if ($this->charset != RCUBE_CHARSET) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1750 echo rcube_charset::convert($hook['content'], RCUBE_CHARSET, $this->charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1751 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1752 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1753 echo $hook['content'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1754 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1755 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1756 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1757
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1758 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1759 * Returns iframe object, registers some related env variables
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1760 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1761 * @param array $attrib HTML attributes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1762 * @param boolean $is_contentframe Register this iframe as the 'contentframe' gui object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1763 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1764 * @return string IFRAME element
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1765 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1766 public function frame($attrib, $is_contentframe = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1767 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1768 static $idcount = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1769
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1770 if (empty($attrib['id'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1771 $attrib['id'] = 'rcmframe' . ++$idcount;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1772 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1773
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1774 $attrib['name'] = $attrib['id'];
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1775 $attrib['src'] = !empty($attrib['src']) ? $this->abs_url($attrib['src'], true) : 'program/resources/blank.gif';
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1776
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1777 // register as 'contentframe' object
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1778 if ($is_contentframe || !empty($attrib['contentframe'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1779 $this->set_env('contentframe', !empty($attrib['contentframe']) ? $attrib['contentframe'] : $attrib['name']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1780 $this->set_env('blankpage', $this->asset_url($attrib['src']));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1781 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1782
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1783 return html::iframe($attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1784 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1785
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1786
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1787 /* ************* common functions delivering gui objects ************** */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1788
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1789 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1790 * Create a form tag with the necessary hidden fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1791 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1792 * @param array $attrib Named tag parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1793 * @param string $content HTML content of the form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1794 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1795 * @return string HTML code for the form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1796 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1797 public function form_tag($attrib, $content = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1798 {
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1799 $hidden = '';
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1800
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1801 if (!empty($this->env['extwin'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1802 $hiddenfield = new html_hiddenfield(['name' => '_extwin', 'value' => '1']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1803 $hidden = $hiddenfield->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1804 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1805 else if ($this->framed || !empty($this->env['framed'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1806 $hiddenfield = new html_hiddenfield(['name' => '_framed', 'value' => '1']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1807 $hidden = $hiddenfield->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1808 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1809
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1810 if (!$content) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1811 $attrib['noclose'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1812 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1813
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1814 return html::tag('form',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1815 $attrib + array('action' => $this->app->comm_path, 'method' => "get"),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1816 $hidden . $content,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1817 array('id','class','style','name','method','action','enctype','onsubmit')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1818 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1819 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1820
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1821 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1822 * Build a form tag with a unique request token
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1823 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1824 * @param array $attrib Named tag parameters including 'action' and 'task' values
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1825 * which will be put into hidden fields
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1826 * @param string $content Form content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1827 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1828 * @return string HTML code for the form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1829 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1830 public function request_form($attrib, $content = '')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1831 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1832 $hidden = new html_hiddenfield();
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1833
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1834 if (!empty($attrib['task'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1835 $hidden->add(['name' => '_task', 'value' => $attrib['task']]);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1836 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1837
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1838 if (!empty($attrib['action'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1839 $hidden->add(['name' => '_action', 'value' => $attrib['action']]);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1840 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1841
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1842 // we already have a <form> tag
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1843 if (!empty($attrib['form'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1844 if ($this->framed || !empty($this->env['framed'])) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1845 $hidden->add(['name' => '_framed', 'value' => '1']);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1846 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1847
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1848 return $hidden->show() . $content;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1849 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1850
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1851 unset($attrib['task'], $attrib['request']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1852 $attrib['action'] = './';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1853
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1854 return $this->form_tag($attrib, $hidden->show() . $content);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1855 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1856
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1857 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1858 * GUI object 'username'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1859 * Showing IMAP username of the current session
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1860 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1861 * @param array $attrib Named tag parameters (currently not used)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1862 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1863 * @return string HTML code for the gui object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1864 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1865 public function current_username($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1866 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1867 static $username;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1868
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1869 // already fetched
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1870 if (!empty($username)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1871 return $username;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1872 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1873
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1874 // Current username is an e-mail address
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1875 if (isset($_SESSION['username']) && strpos($_SESSION['username'], '@')) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1876 $username = $_SESSION['username'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1877 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1878 // get e-mail address from default identity
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1879 else if ($sql_arr = $this->app->user->get_identity()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1880 $username = $sql_arr['email'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1881 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1882 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1883 $username = $this->app->user->get_username();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1884 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1885
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1886 $username = rcube_utils::idn_to_utf8($username);
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1887
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1888 return html::quote($username);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1889 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1890
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1891 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1892 * GUI object 'loginform'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1893 * Returns code for the webmail login form
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1894 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1895 * @param array $attrib Named parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1896 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1897 * @return string HTML code for the gui object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1898 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1899 protected function login_form($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1900 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1901 $default_host = $this->config->get('default_host');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1902 $autocomplete = (int) $this->config->get('login_autocomplete');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1903
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1904 $_SESSION['temp'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1905
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1906 // save original url
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1907 $url = rcube_utils::get_input_value('_url', rcube_utils::INPUT_POST);
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1908 if (empty($url)
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1909 && !empty($_SERVER['QUERY_STRING'])
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1910 && !preg_match('/_(task|action)=logout/', $_SERVER['QUERY_STRING'])
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1911 ) {
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1912 $url = $_SERVER['QUERY_STRING'];
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
1913 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1914
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1915 // Disable autocapitalization on iPad/iPhone (#1488609)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1916 $attrib['autocapitalize'] = 'off';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1917
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1918 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1919
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1920 // set atocomplete attribute
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1921 $user_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1922 $host_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1923 $pass_attrib = $autocomplete > 1 ? array() : array('autocomplete' => 'off');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1924
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1925 $input_task = new html_hiddenfield(array('name' => '_task', 'value' => 'login'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1926 $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1927 $input_tzone = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1928 $input_url = new html_hiddenfield(array('name' => '_url', 'id' => 'rcmloginurl', 'value' => $url));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1929 $input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'required' => 'required')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1930 + $attrib + $user_attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1931 $input_pass = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'required' => 'required')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1932 + $attrib + $pass_attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1933 $input_host = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1934
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1935 if (is_array($default_host) && count($default_host) > 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1936 $input_host = new html_select(array('name' => '_host', 'id' => 'rcmloginhost'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1937
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1938 foreach ($default_host as $key => $value) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1939 if (!is_array($value)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1940 $input_host->add($value, (is_numeric($key) ? $value : $key));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1941 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1942 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1943 $input_host = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1944 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1945 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1946 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1947 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1948 else if (is_array($default_host) && ($host = key($default_host)) !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1949 $hide_host = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1950 $input_host = new html_hiddenfield(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1951 'name' => '_host', 'id' => 'rcmloginhost', 'value' => is_numeric($host) ? $default_host[$host] : $host) + $attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1952 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1953 else if (empty($default_host)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1954 $input_host = new html_inputfield(array('name' => '_host', 'id' => 'rcmloginhost')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1955 + $attrib + $host_attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1956 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1957
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1958 $this->add_gui_object('loginform', $form_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1959
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1960 // create HTML table with two cols
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1961 $table = new html_table(array('cols' => 2));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1962
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1963 $table->add('title', html::label('rcmloginuser', html::quote($this->app->gettext('username'))));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1964 $table->add('input', $input_user->show(rcube_utils::get_input_value('_user', rcube_utils::INPUT_GPC)));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1965
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1966 $table->add('title', html::label('rcmloginpwd', html::quote($this->app->gettext('password'))));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1967 $table->add('input', $input_pass->show());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1969 // add host selection row
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1970 if (is_object($input_host) && !$hide_host) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1971 $table->add('title', html::label('rcmloginhost', html::quote($this->app->gettext('server'))));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1972 $table->add('input', $input_host->show(rcube_utils::get_input_value('_host', rcube_utils::INPUT_GPC)));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1973 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1974
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1975 $out = $input_task->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1976 $out .= $input_action->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1977 $out .= $input_tzone->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1978 $out .= $input_url->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1979 $out .= $table->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1980
22
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 18
diff changeset
1981 if (isset($hide_host)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1982 $out .= $input_host->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1983 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1984
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1985 if (rcube_utils::get_boolean($attrib['submit'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1986 $submit = new html_inputfield(array('type' => 'submit', 'id' => 'rcmloginsubmit',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1987 'class' => 'button mainaction', 'value' => $this->app->gettext('login')));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1988 $out .= html::p('formbuttons', $submit->show());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1989 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1990
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1991 // surround html output with a form tag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1992 if (empty($attrib['form'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1993 $out = $this->form_tag(array('name' => $form_name, 'method' => 'post'), $out);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1994 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1995
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1996 // include script for timezone detection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1997 $this->include_script('jstz.min.js');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1998
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1999 return $out;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2000 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2001
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2002 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2003 * GUI object 'preloader'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2004 * Loads javascript code for images preloading
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2005 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2006 * @param array $attrib Named parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2007 * @return void
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2008 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2009 protected function preloader($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2010 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2011 $images = preg_split('/[\s\t\n,]+/', $attrib['images'], -1, PREG_SPLIT_NO_EMPTY);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2012 $images = array_map(array($this, 'abs_url'), $images);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2013 $images = array_map(array($this, 'asset_url'), $images);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2014
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
2015 if (empty($images) || (isset($_REQUEST['_task']) && $_REQUEST['_task'] == 'logout')) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2016 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2017 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2018
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2019 $this->add_script('var images = ' . self::json_serialize($images, $this->devel_mode) .';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2020 for (var i=0; i<images.length; i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2021 img = new Image();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2022 img.src = images[i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2023 }', 'docready');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2024 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2025
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2026 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2027 * GUI object 'searchform'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2028 * Returns code for search function
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2029 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2030 * @param array $attrib Named parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2031 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2032 * @return string HTML code for the gui object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2033 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2034 protected function search_form($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2035 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2036 // add some labels to client
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2037 $this->add_label('searching');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2038
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2039 $attrib['name'] = '_q';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2040
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2041 if (empty($attrib['id'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2042 $attrib['id'] = 'rcmqsearchbox';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2043 }
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
2044 if (isset($attrib['type']) && $attrib['type'] == 'search' && !$this->browser->khtml) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2045 unset($attrib['type'], $attrib['results']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2046 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2047
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2048 $input_q = new html_inputfield($attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2049 $out = $input_q->show();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2050
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2051 $this->add_gui_object('qsearchbox', $attrib['id']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2052
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2053 // add form tag around text field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2054 if (empty($attrib['form'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2055 $out = $this->form_tag(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2056 'name' => "rcmqsearchform",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2057 'onsubmit' => self::JS_OBJECT_NAME . ".command('search'); return false",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2058 'style' => "display:inline"
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2059 ), $out);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2060 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2061
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2062 return $out;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2063 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2064
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2065 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2066 * Builder for GUI object 'message'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2067 *
18
b631c1c7a3ce More cleaning up more php8 Warnings/deprecations,
Charlie Root
parents: 5
diff changeset
2068 * @param array $attrib Named tag parameters
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2069 * @return string HTML code for the gui object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2070 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2071 protected function message_container($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2072 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2073 if (isset($attrib['id']) === false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2074 $attrib['id'] = 'rcmMessageContainer';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2075 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2076
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2077 $this->add_gui_object('message', $attrib['id']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2078
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2079 return html::div($attrib, '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2080 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2081
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2082 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2083 * GUI object 'charsetselector'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2084 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2085 * @param array $attrib Named parameters for the select tag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2086 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2087 * @return string HTML code for the gui object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2088 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2089 public function charset_selector($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2090 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2091 // pass the following attributes to the form class
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2092 $field_attrib = array('name' => '_charset');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2093 foreach ($attrib as $attr => $value) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2094 if (in_array($attr, array('id', 'name', 'class', 'style', 'size', 'tabindex'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2095 $field_attrib[$attr] = $value;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2096 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2097 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2098
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2099 $charsets = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2100 'UTF-8' => 'UTF-8 ('.$this->app->gettext('unicode').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2101 'US-ASCII' => 'ASCII ('.$this->app->gettext('english').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2102 'ISO-8859-1' => 'ISO-8859-1 ('.$this->app->gettext('westerneuropean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2103 'ISO-8859-2' => 'ISO-8859-2 ('.$this->app->gettext('easterneuropean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2104 'ISO-8859-4' => 'ISO-8859-4 ('.$this->app->gettext('baltic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2105 'ISO-8859-5' => 'ISO-8859-5 ('.$this->app->gettext('cyrillic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2106 'ISO-8859-6' => 'ISO-8859-6 ('.$this->app->gettext('arabic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2107 'ISO-8859-7' => 'ISO-8859-7 ('.$this->app->gettext('greek').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2108 'ISO-8859-8' => 'ISO-8859-8 ('.$this->app->gettext('hebrew').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2109 'ISO-8859-9' => 'ISO-8859-9 ('.$this->app->gettext('turkish').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2110 'ISO-8859-10' => 'ISO-8859-10 ('.$this->app->gettext('nordic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2111 'ISO-8859-11' => 'ISO-8859-11 ('.$this->app->gettext('thai').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2112 'ISO-8859-13' => 'ISO-8859-13 ('.$this->app->gettext('baltic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2113 'ISO-8859-14' => 'ISO-8859-14 ('.$this->app->gettext('celtic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2114 'ISO-8859-15' => 'ISO-8859-15 ('.$this->app->gettext('westerneuropean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2115 'ISO-8859-16' => 'ISO-8859-16 ('.$this->app->gettext('southeasterneuropean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2116 'WINDOWS-1250' => 'Windows-1250 ('.$this->app->gettext('easterneuropean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2117 'WINDOWS-1251' => 'Windows-1251 ('.$this->app->gettext('cyrillic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2118 'WINDOWS-1252' => 'Windows-1252 ('.$this->app->gettext('westerneuropean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2119 'WINDOWS-1253' => 'Windows-1253 ('.$this->app->gettext('greek').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2120 'WINDOWS-1254' => 'Windows-1254 ('.$this->app->gettext('turkish').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2121 'WINDOWS-1255' => 'Windows-1255 ('.$this->app->gettext('hebrew').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2122 'WINDOWS-1256' => 'Windows-1256 ('.$this->app->gettext('arabic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2123 'WINDOWS-1257' => 'Windows-1257 ('.$this->app->gettext('baltic').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2124 'WINDOWS-1258' => 'Windows-1258 ('.$this->app->gettext('vietnamese').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2125 'ISO-2022-JP' => 'ISO-2022-JP ('.$this->app->gettext('japanese').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2126 'ISO-2022-KR' => 'ISO-2022-KR ('.$this->app->gettext('korean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2127 'ISO-2022-CN' => 'ISO-2022-CN ('.$this->app->gettext('chinese').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2128 'EUC-JP' => 'EUC-JP ('.$this->app->gettext('japanese').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2129 'EUC-KR' => 'EUC-KR ('.$this->app->gettext('korean').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2130 'EUC-CN' => 'EUC-CN ('.$this->app->gettext('chinese').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2131 'BIG5' => 'BIG5 ('.$this->app->gettext('chinese').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2132 'GB2312' => 'GB2312 ('.$this->app->gettext('chinese').')',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2133 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2134
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2135 if ($post = rcube_utils::get_input_value('_charset', rcube_utils::INPUT_POST)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2136 $set = $post;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2137 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2138 else if (!empty($attrib['selected'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2139 $set = $attrib['selected'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2140 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2141 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2142 $set = $this->get_charset();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2143 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2144
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2145 $set = strtoupper($set);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2146 if (!isset($charsets[$set]) && preg_match('/^[A-Z0-9-]+$/', $set)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2147 $charsets[$set] = $set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2148 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2149
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2150 $select = new html_select($field_attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2151 $select->add(array_values($charsets), array_keys($charsets));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2152
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2153 return $select->show($set);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2154 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2155
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2156 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2157 * Include content from config/about.<LANG>.html if available
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2158 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2159 protected function about_content($attrib)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2160 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2161 $content = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2162 $filenames = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2163 'about.' . $_SESSION['language'] . '.html',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2164 'about.' . substr($_SESSION['language'], 0, 2) . '.html',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2165 'about.html',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2166 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2167 foreach ($filenames as $file) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2168 $fn = RCUBE_CONFIG_DIR . $file;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2169 if (is_readable($fn)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2170 $content = file_get_contents($fn);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2171 $content = $this->parse_conditions($content);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2172 $content = $this->parse_xml($content);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2173 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2174 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2175 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2176
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2177 return $content;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2178 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2179 }