You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rcmail_output_html.php 71KB

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