From ba3377fb4aaad4ab77967920275fb78b3516d35e Mon Sep 17 00:00:00 2001 From: alecpl Date: Wed, 12 Jan 2011 20:56:31 +0000 Subject: - include css files before scripts for speedup (with parallel downloads) + some code cleanups --- program/include/rcube_html_page.php | 86 ++++++++++++++++++++---------------- program/include/rcube_plugin_api.php | 3 +- 2 files changed, 49 insertions(+), 40 deletions(-) (limited to 'program') diff --git a/program/include/rcube_html_page.php b/program/include/rcube_html_page.php index ce35088c0..ab226bc32 100644 --- a/program/include/rcube_html_page.php +++ b/program/include/rcube_html_page.php @@ -28,11 +28,13 @@ 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 $link_css_file = "\n"; protected $default_template = "\n\n\n"; protected $title = ''; @@ -61,6 +63,9 @@ class rcube_html_page if (in_array($file, $sa_files)) { return; } + + $sa_files[] = $file; + if (!is_array($this->script_files[$position])) { $this->script_files[$position] = array(); } @@ -82,6 +87,16 @@ 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 * @@ -163,52 +178,53 @@ class rcube_html_page } // 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; } 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']); + $page_footer .= sprintf($this->script_tag, $this->scripts['foot']); } if (!empty($this->footer)) { - $__page_footer .= $this->footer; + $page_footer .= $this->footer; } // find page header if ($hpos = stripos($output, '')) { - $__page_header .= "\n"; + $page_header .= "\n"; } else { if (!is_numeric($hpos)) { @@ -220,49 +236,43 @@ class rcube_html_page } $hpos++; } - $__page_header = "\n$__page_title\n$__page_header\n\n"; + $page_header = "\n$page_title\n$page_header\n\n"; } // add page hader if ($hpos) { - $output = substr($output,0,$hpos) . $__page_header . substr($output,$hpos,strlen($output)); + $output = substr($output,0,$hpos) . $page_header . substr($output,$hpos,strlen($output)); } else { - $output = $__page_header . $output; + $output = $page_header . $output; } - // find page body - if ($bpos = stripos($output, '')+7; - } - - // add page body - if ($bpos && $__page_body) { - $output = substr($output,0,$bpos) . "\n$__page_body\n" . substr($output,$bpos,strlen($output)); - } - - // find and add page footer + // add page footer if (($fpos = strripos($output, '')) || ($fpos = strripos($output, ''))) { - $output = substr($output, 0, $fpos) . "$__page_footer\n" . substr($output, $fpos); + $output = substr($output, 0, $fpos) . "$page_footer\n" . substr($output, $fpos); } else { - $output .= "\n".$__page_footer; + $output .= "\n".$page_footer; } - // reset those global vars - $__page_header = $__page_footer = ''; + // add css files in head, before scripts, for speed up with parallel downloads + if (!empty($this->css_files) && + (($pos = stripos($output, '