X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Finclude%2Frcube_html_page.php;h=77b7ff2d86db642ceab0a37b901419ce6e311c54;hb=76507f7c63a660742e76889ad6e3919f3dde3bb0;hp=6a197036bf1d8a3a8ca4458473feaf19875b2b8d;hpb=b68022ca3782d5eb5a1a7ef6f8cf7abe1dc15bd6;p=roundcube.git diff --git a/program/include/rcube_html_page.php b/program/include/rcube_html_page.php index 6a19703..77b7ff2 100644 --- a/program/include/rcube_html_page.php +++ b/program/include/rcube_html_page.php @@ -4,8 +4,8 @@ +-----------------------------------------------------------------------+ | program/include/rcube_html_page.php | | | - | This file is part of the RoundCube PHP suite | - | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland | + | This file is part of the Roundcube PHP suite | + | Copyright (C) 2005-2011 The Roundcube Dev Team | | Licensed under the GNU GPL | | | | CONTENTS: | @@ -15,7 +15,7 @@ | Author: Thomas Bruederli | +-----------------------------------------------------------------------+ - $Id: $ + $Id: rcube_html_page.php 5135 2011-08-26 09:22:53Z alec $ */ @@ -28,17 +28,20 @@ class rcube_html_page { protected $scripts_path = ''; protected $script_files = array(); + protected $css_files = array(); protected $scripts = array(); protected $charset = RCMAIL_CHARSET; protected $script_tag_file = "\n"; - protected $script_tag = ""; + protected $script_tag = "\n"; + protected $link_css_file = "\n"; protected $default_template = "\n\n\n"; protected $title = ''; protected $header = ''; protected $footer = ''; protected $body = ''; + protected $base_path = ''; /** Constructor */ @@ -55,11 +58,14 @@ class rcube_html_page static $sa_files = array(); if (!preg_match('|^https?://|i', $file) && $file[0] != '/') - $file = $this->scripts_path . $file . (($fs = @filemtime($this->scripts_path . $file)) ? '?s='.$fs : ''); + $file = $this->scripts_path . $file . (($fs = @filemtime($this->scripts_path . $file)) ? '?s='.$fs : ''); if (in_array($file, $sa_files)) { return; } + + $sa_files[] = $file; + if (!is_array($this->script_files[$position])) { $this->script_files[$position] = array(); } @@ -81,8 +87,20 @@ class rcube_html_page } } + /** + * Link an external css file + * + * @param string File URL + */ + public function include_css($file) + { + $this->css_files[] = $file; + } + /** * Add HTML code to the page header + * + * @param string $str HTML code */ public function add_header($str) { @@ -92,6 +110,8 @@ class rcube_html_page /** * Add HTML code to the page footer * To be added right befor + * + * @param string $str HTML code */ public function add_footer($str) { @@ -100,6 +120,8 @@ class rcube_html_page /** * Setter for page title + * + * @param string $t Page title */ public function set_title($t) { @@ -109,6 +131,8 @@ class rcube_html_page /** * Setter for output charset. * To be specified in a meta tag and sent as http-header + * + * @param string $charset Charset */ public function set_charset($charset) { @@ -117,6 +141,8 @@ class rcube_html_page /** * Getter for output charset + * + * @return string Output charset */ public function get_charset() { @@ -129,11 +155,11 @@ class rcube_html_page public function reset() { $this->script_files = array(); - $this->scripts = array(); - $this->title = ''; - $this->header = ''; - $this->footer = ''; - $this->body = ''; + $this->scripts = array(); + $this->title = ''; + $this->header = ''; + $this->footer = ''; + $this->body = ''; } /** @@ -148,123 +174,140 @@ class rcube_html_page // set default page title if (empty($this->title)) { - $this->title = 'RoundCube Mail'; + $this->title = 'Roundcube Mail'; } // replace specialchars in content - $__page_title = Q($this->title, 'show', FALSE); - $__page_header = $__page_body = $__page_footer = ''; + $page_title = Q($this->title, 'show', FALSE); + $page_header = ''; + $page_footer = ''; // include meta tag with charset if (!empty($this->charset)) { if (!headers_sent()) { header('Content-Type: text/html; charset=' . $this->charset); } - $__page_header = 'charset . '" />'."\n"; + $page_header = 'charset . '" />'."\n"; } // definition of the code to be placed in the document header and footer if (is_array($this->script_files['head'])) { foreach ($this->script_files['head'] as $file) { - $__page_header .= sprintf($this->script_tag_file, $file); + $page_header .= sprintf($this->script_tag_file, $file); } } $head_script = $this->scripts['head_top'] . $this->scripts['head']; if (!empty($head_script)) { - $__page_header .= sprintf($this->script_tag, $head_script); + $page_header .= sprintf($this->script_tag, $head_script); } if (!empty($this->header)) { - $__page_header .= $this->header; + $page_header .= $this->header; + } + + // put docready commands into page footer + if (!empty($this->scripts['docready'])) { + $this->add_script('$(document).ready(function(){ ' . $this->scripts['docready'] . "\n});", 'foot'); } if (is_array($this->script_files['foot'])) { foreach ($this->script_files['foot'] as $file) { - $__page_footer .= sprintf($this->script_tag_file, $file); + $page_footer .= sprintf($this->script_tag_file, $file); } } - if (!empty($this->scripts['foot'])) { - $__page_footer .= sprintf($this->script_tag, $this->scripts['foot']); + if (!empty($this->footer)) { + $page_footer .= $this->footer . "\n"; } - if (!empty($this->footer)) { - $__page_footer .= $this->footer; + if (!empty($this->scripts['foot'])) { + $page_footer .= sprintf($this->script_tag, $this->scripts['foot']); } // find page header - if ($hpos = strpos(strtolower($output), '')) { - $__page_header .= "\n"; + if ($hpos = stripos($output, '')) { + $page_header .= "\n"; } else { if (!is_numeric($hpos)) { - $hpos = strpos(strtolower($output), '')) || ($fpos = strripos($output, ''))) { + $output = substr_replace($output, $page_footer."\n", $fpos, 0); } else { - $bpos = strpos(strtolower($output), '')+7; - } - - // add page body - if ($bpos && $__page_body) { - $output = substr($output,0,$bpos) . "\n$__page_body\n" . substr($output,$bpos,strlen($output)); + $output .= "\n".$page_footer; } - // find and add page footer - $output_lc = strtolower($output); - if (($fpos = strrpos($output_lc, '')) || ($fpos = strrpos($output_lc, ''))) { - $output = substr($output, 0, $fpos) . "$__page_footer\n" . substr($output, $fpos); - } - else { - $output .= "\n".$__page_footer; + // add css files in head, before scripts, for speed up with parallel downloads + if (!empty($this->css_files) && + (($pos = stripos($output, '