|
+-----------------------------------------------------------------------+
$Id$
*/
// ********* round cube schared classes *********
class rcube_html_page
{
var $css;
var $scripts_path = '';
var $script_files = array();
var $scripts = array();
var $charset = 'ISO-8859-1';
var $script_tag_file = "\n";
var $script_tag = "\n";
var $default_template = "\n
\n\n";
var $title = '';
var $header = '';
var $footer = '';
var $body = '';
var $body_attrib = array();
var $meta_tags = array();
// PHP 5 constructor
function __construct()
{
$this->css = new rcube_css();
}
// PHP 4 compatibility
function rcube_html_page()
{
$this->__construct();
}
function include_script($file, $position='head')
{
static $sa_files = array();
if (in_array($file, $sa_files))
return;
if (!is_array($this->script_files[$position]))
$this->script_files[$position] = array();
$this->script_files[$position][] = $file;
}
function add_script($script, $position='head')
{
if (!isset($this->scripts[$position]))
$this->scripts[$position] = '';
$this->scripts[$position] .= "\n$script";
}
function set_title($t)
{
$this->title = $t;
}
function set_charset($charset)
{
global $MBSTRING;
$this->charset = $charset;
if ($MBSTRING && function_exists("mb_internal_encoding"))
{
if(!@mb_internal_encoding($charset))
$MBSTRING = FALSE;
}
}
function get_charset()
{
return $this->charset;
}
function reset()
{
$this->css = new rcube_css();
$this->script_files = array();
$this->scripts = array();
$this->title = '';
}
function write($templ='', $base_path='')
{
$output = empty($templ) ? $this->default_template : trim($templ);
// set default page title
if (!strlen($this->title))
$this->title = 'RoundCube Mail';
// replace specialchars in content
$__page_title = rep_specialchars_output($this->title, 'html', 'show', FALSE);
$__page_header = $__page_body = $__page_footer = '';
// include meta tag with charset
if (!empty($this->charset))
{
header('Content-Type: text/html; charset='.$this->charset);
$__page_header = ''."\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, $this->scripts_path, $file);
if (strlen($this->scripts['head']))
$__page_header .= sprintf($this->script_tag, $this->scripts['head']);
if (is_array($this->script_files['foot']))
foreach ($this->script_files['foot'] as $file)
$__page_footer .= sprintf($this->script_tag_file, $this->scripts_path, $file);
if (strlen($this->scripts['foot']))
$__page_footer .= sprintf($this->script_tag, $this->scripts['foot']);
$__page_header .= $this->css->show();
// find page header
if($hpos = strpos(strtolower($output), ''))
$__page_header .= "\n";
else
{
if (!is_numeric($hpos))
$hpos = strpos(strtolower($output), '')
$hpos++;
$hpos++;
}
$__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));
else
$output = $__page_header . $output;
// find page body
if($bpos = strpos(strtolower($output), '') $bpos++;
$bpos++;
}
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));
// find and add page footer
if(($fpos = strpos(strtolower($output), '')) || ($fpos = strpos(strtolower($output), '