Get rid of sprintf() calls for html output generation

pull/1/head
thomascube 13 years ago
parent 5e8c7729fb
commit 011e8055fe

@ -5,7 +5,7 @@
| program/include/html.php | | program/include/html.php |
| | | |
| This file is part of the Roundcube Webmail client | | This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2010, The Roundcube Dev Team | | Copyright (C) 2005-2011, The Roundcube Dev Team |
| Licensed under the GNU GPL | | Licensed under the GNU GPL |
| | | |
| PURPOSE: | | PURPOSE: |
@ -80,12 +80,12 @@ class html
$tagname = self::$lc_tags ? strtolower($tagname) : $tagname; $tagname = self::$lc_tags ? strtolower($tagname) : $tagname;
if (isset($content) || in_array($tagname, self::$containers)) { if (isset($content) || in_array($tagname, self::$containers)) {
$templ = $attrib['noclose'] ? "<%s%s>%s" : "<%s%s>%s</%s>%s"; $suffix = $attrib['noclose'] ? $suffix : '</' . $tagname . '>' . $suffix;
unset($attrib['noclose']); unset($attrib['noclose'], $attrib['nl']);
return sprintf($templ, $tagname, self::attrib_string($attrib, $allowed_attrib), $content, $tagname, $suffix); return '<' . $tagname . self::attrib_string($attrib, $allowed_attrib) . '>' . $content . $suffix;
} }
else { else {
return sprintf("<%s%s />%s", $tagname, self::attrib_string($attrib, $allowed_attrib), $suffix); return '<' . $tagname . self::attrib_string($attrib, $allowed_attrib) . '>' . $suffix;
} }
} }
@ -219,7 +219,30 @@ class html
$attr = array('src' => $attr); $attr = array('src' => $attr);
} }
return self::tag('iframe', $attr, $cont, array_merge(self::$common_attrib, return self::tag('iframe', $attr, $cont, array_merge(self::$common_attrib,
array('src','name','width','height','border','frameborder'))); array('src','name','width','height','border','frameborder')));
}
/**
* Derrived method to create <script> tags
*
* @param mixed $attr Hash array with tag attributes or string with script source (src)
* @return string HTML code
* @see html::tag()
*/
public static function script($attr, $cont = null)
{
if (is_string($attr)) {
$attr = array('src' => $attr);
}
if ($cont) {
if (self::$doctype == 'xhtml')
$cont = "\n/* <![CDATA[ */\n" . $cont . "\n/* ]]> */\n";
else
$cont = "\n" . $cont . "\n";
}
return self::tag('script', $attr + array('type' => 'text/javascript', 'nl' => true),
$cont, array_merge(self::$common_attrib, array('src','type','charset')));
} }
/** /**
@ -267,14 +290,14 @@ class html
// attributes with no value // attributes with no value
if (in_array($key, array('checked', 'multiple', 'disabled', 'selected'))) { if (in_array($key, array('checked', 'multiple', 'disabled', 'selected'))) {
if ($value) { if ($value) {
$attrib_arr[] = sprintf('%s="%s"', $key, $key); $attrib_arr[] = $key . '="' . $key . '"';
} }
} }
else if ($key=='value') { else if ($key=='value') {
$attrib_arr[] = sprintf('%s="%s"', $key, Q($value, 'strict', false)); $attrib_arr[] = $key . '="' . Q($value, 'strict', false) . '"';
} }
else { else {
$attrib_arr[] = sprintf('%s="%s"', $key, Q($value)); $attrib_arr[] = $key . '="' . Q($value) . '"';
} }
} }
return count($attrib_arr) ? ' '.implode(' ', $attrib_arr) : ''; return count($attrib_arr) ? ' '.implode(' ', $attrib_arr) : '';

@ -31,10 +31,6 @@ class rcube_html_page
protected $css_files = array(); protected $css_files = array();
protected $scripts = array(); protected $scripts = array();
protected $charset = RCMAIL_CHARSET; protected $charset = RCMAIL_CHARSET;
protected $script_tag_file = "<script type=\"text/javascript\" src=\"%s\"></script>\n";
protected $script_tag = "<script type=\"text/javascript\">\n/* <![CDATA[ */\n%s\n/* ]]> */\n</script>\n";
protected $link_css_file = "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n";
protected $default_template = "<html>\n<head><title></title></head>\n<body></body>\n</html>"; protected $default_template = "<html>\n<head><title></title></head>\n<body></body>\n</html>";
protected $title = ''; protected $title = '';
@ -195,13 +191,13 @@ class rcube_html_page
// definition of the code to be placed in the document header and footer // definition of the code to be placed in the document header and footer
if (is_array($this->script_files['head'])) { if (is_array($this->script_files['head'])) {
foreach ($this->script_files['head'] as $file) { foreach ($this->script_files['head'] as $file) {
$page_header .= sprintf($this->script_tag_file, $file); $page_header .= html::script($file);
} }
} }
$head_script = $this->scripts['head_top'] . $this->scripts['head']; $head_script = $this->scripts['head_top'] . $this->scripts['head'];
if (!empty($head_script)) { if (!empty($head_script)) {
$page_header .= sprintf($this->script_tag, $head_script); $page_header .= html::script(array(), $head_script);
} }
if (!empty($this->header)) { if (!empty($this->header)) {
@ -215,7 +211,7 @@ class rcube_html_page
if (is_array($this->script_files['foot'])) { if (is_array($this->script_files['foot'])) {
foreach ($this->script_files['foot'] as $file) { foreach ($this->script_files['foot'] as $file) {
$page_footer .= sprintf($this->script_tag_file, $file); $page_footer .= html::script($file);
} }
} }
@ -224,7 +220,7 @@ class rcube_html_page
} }
if (!empty($this->scripts['foot'])) { if (!empty($this->scripts['foot'])) {
$page_footer .= sprintf($this->script_tag, $this->scripts['foot']); $page_footer .= html::script(array(), $this->scripts['foot']);
} }
// find page header // find page header
@ -266,7 +262,7 @@ class rcube_html_page
) { ) {
$css = ''; $css = '';
foreach ($this->css_files as $file) { foreach ($this->css_files as $file) {
$css .= sprintf($this->link_css_file, $file); $css .= html::tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $file, 'nl' => true));
} }
$output = substr_replace($output, $css, $pos, 0); $output = substr_replace($output, $css, $pos, 0);
} }

Loading…
Cancel
Save