Changeset 011e805 in github for program/include/html.php


Ignore:
Timestamp:
Dec 26, 2011 10:40:37 AM (17 months ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.8
Children:
fe1bd5f
Parents:
5e8c772
Message:

Get rid of sprintf() calls for html output generation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/html.php

    rf230739 r011e805  
    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        } 
Note: See TracChangeset for help on using the changeset viewer.