|
 +-----------------------------------------------------------------------+
 $Id$
*/
/**
 * Class for HTML page creation
 *
 * @package HTML
 */
class rcube_html_page
{
    protected $scripts_path = '';
    protected $script_files = array();
    protected $scripts = array();
    protected $charset = RCMAIL_CHARSET;
    protected $script_tag_file = "\n";
    protected $script_tag  =  "";
    protected $default_template = "\n
\n\n";
    protected $title = '';
    protected $header = '';
    protected $footer = '';
    protected $body = '';
    protected $base_path = '';
    /** Constructor */
    public function __construct() {}
    /**
     * Link an external script file
     *
     * @param string File URL
     * @param string Target position [head|foot]
     */
    public function include_script($file, $position='head')
    {
        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 : '');
        if (in_array($file, $sa_files)) {
            return;
        }
        if (!is_array($this->script_files[$position])) {
            $this->script_files[$position] = array();
        }
        $this->script_files[$position][] = $file;
    }
    /**
     * Add inline javascript code
     *
     * @param string JS code snippet
     * @param string Target position [head|head_top|foot]
     */
    public function add_script($script, $position='head')
    {
        if (!isset($this->scripts[$position])) {
            $this->scripts[$position] = "\n".rtrim($script);
        } else {
            $this->scripts[$position] .= "\n".rtrim($script);
        }
    }
    /**
     * Add HTML code to the page header
     */
    public function add_header($str)
    {
        $this->header .= "\n".$str;
    }
    /**
     * Add HTML code to the page footer
     * To be added right befor ') {
                    $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 = stripos($output, '') {
                $bpos++;
            }
            $bpos++;
        }
        else {
            $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
        if (($fpos = strripos($output, '