Changeset 5653 in subversion


Ignore:
Timestamp:
Dec 26, 2011 10:40:37 AM (17 months ago)
Author:
thomasb
Message:

Get rid of sprintf() calls for html output generation

Location:
trunk/roundcubemail/program/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/html.php

    r5532 r5653  
    66 |                                                                       | 
    77 | This file is part of the Roundcube Webmail client                     | 
    8  | Copyright (C) 2005-2010, The Roundcube Dev Team                       | 
     8 | Copyright (C) 2005-2011, The Roundcube Dev Team                       | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    8181        $tagname = self::$lc_tags ? strtolower($tagname) : $tagname; 
    8282        if (isset($content) || in_array($tagname, self::$containers)) { 
    83             $templ = $attrib['noclose'] ? "<%s%s>%s" : "<%s%s>%s</%s>%s"; 
    84             unset($attrib['noclose']); 
    85             return sprintf($templ, $tagname, self::attrib_string($attrib, $allowed_attrib), $content, $tagname, $suffix); 
     83            $suffix = $attrib['noclose'] ? $suffix : '</' . $tagname . '>' . $suffix; 
     84            unset($attrib['noclose'], $attrib['nl']); 
     85            return '<' . $tagname  . self::attrib_string($attrib, $allowed_attrib) . '>' . $content . $suffix; 
    8686        } 
    8787        else { 
    88             return sprintf("<%s%s />%s", $tagname, self::attrib_string($attrib, $allowed_attrib), $suffix); 
     88            return '<' . $tagname  . self::attrib_string($attrib, $allowed_attrib) . '>' . $suffix; 
    8989        } 
    9090    } 
     
    220220        } 
    221221        return self::tag('iframe', $attr, $cont, array_merge(self::$common_attrib, 
    222             array('src','name','width','height','border','frameborder'))); 
     222            array('src','name','width','height','border','frameborder'))); 
     223    } 
     224 
     225    /** 
     226     * Derrived method to create <script> tags 
     227     * 
     228     * @param mixed $attr Hash array with tag attributes or string with script source (src) 
     229     * @return string HTML code 
     230     * @see html::tag() 
     231     */ 
     232    public static function script($attr, $cont = null) 
     233    { 
     234        if (is_string($attr)) { 
     235            $attr = array('src' => $attr); 
     236        } 
     237        if ($cont) { 
     238            if (self::$doctype == 'xhtml') 
     239                $cont = "\n/* <![CDATA[ */\n" . $cont . "\n/* ]]> */\n"; 
     240            else 
     241                $cont = "\n" . $cont . "\n"; 
     242        } 
     243 
     244        return self::tag('script', $attr + array('type' => 'text/javascript', 'nl' => true), 
     245            $cont, array_merge(self::$common_attrib, array('src','type','charset'))); 
    223246    } 
    224247 
     
    268291            if (in_array($key, array('checked', 'multiple', 'disabled', 'selected'))) { 
    269292                if ($value) { 
    270                     $attrib_arr[] = sprintf('%s="%s"', $key, $key); 
     293                    $attrib_arr[] = $key . '="' . $key . '"'; 
    271294                } 
    272295            } 
    273296            else if ($key=='value') { 
    274                 $attrib_arr[] = sprintf('%s="%s"', $key, Q($value, 'strict', false)); 
     297                $attrib_arr[] = $key . '="' . Q($value, 'strict', false) . '"'; 
    275298            } 
    276299            else { 
    277                 $attrib_arr[] = sprintf('%s="%s"', $key, Q($value)); 
     300                $attrib_arr[] = $key . '="' . Q($value) . '"'; 
    278301            } 
    279302        } 
  • trunk/roundcubemail/program/include/rcube_html_page.php

    r5135 r5653  
    3232    protected $scripts = array(); 
    3333    protected $charset = RCMAIL_CHARSET; 
    34  
    35     protected $script_tag_file = "<script type=\"text/javascript\" src=\"%s\"></script>\n"; 
    36     protected $script_tag  =  "<script type=\"text/javascript\">\n/* <![CDATA[ */\n%s\n/* ]]> */\n</script>\n"; 
    37     protected $link_css_file = "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n"; 
    3834    protected $default_template = "<html>\n<head><title></title></head>\n<body></body>\n</html>"; 
    3935 
     
    196192        if (is_array($this->script_files['head'])) { 
    197193            foreach ($this->script_files['head'] as $file) { 
    198                 $page_header .= sprintf($this->script_tag_file, $file); 
     194                $page_header .= html::script($file); 
    199195            } 
    200196        } 
     
    202198        $head_script = $this->scripts['head_top'] . $this->scripts['head']; 
    203199        if (!empty($head_script)) { 
    204             $page_header .= sprintf($this->script_tag, $head_script); 
     200            $page_header .= html::script(array(), $head_script); 
    205201        } 
    206202 
     
    216212        if (is_array($this->script_files['foot'])) { 
    217213            foreach ($this->script_files['foot'] as $file) { 
    218                 $page_footer .= sprintf($this->script_tag_file, $file); 
     214                $page_footer .= html::script($file); 
    219215            } 
    220216        } 
     
    225221 
    226222        if (!empty($this->scripts['foot'])) { 
    227             $page_footer .= sprintf($this->script_tag, $this->scripts['foot']); 
     223            $page_footer .= html::script(array(), $this->scripts['foot']); 
    228224        } 
    229225 
     
    267263            $css = ''; 
    268264            foreach ($this->css_files as $file) { 
    269                 $css .= sprintf($this->link_css_file, $file); 
     265                $css .= html::tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $file, 'nl' => true)); 
    270266            } 
    271267            $output = substr_replace($output, $css, $pos, 0); 
Note: See TracChangeset for help on using the changeset viewer.