diff options
author | Christian A. Weber | 2018-04-12 17:54:23 +0200 |
---|---|---|
committer | Christian A. Weber | 2018-04-12 17:54:23 +0200 |
commit | 31bb4ba99f6572acfe08c3daf78dc043dc924903 (patch) | |
tree | 0d543471d4c5b76cef420b9fb9c592d9b9b34ba7 | |
parent | 1bf1f64969a6270d655e8819258e574b4dcb33e0 (diff) | |
download | itools-31bb4ba99f6572acfe08c3daf78dc043dc924903.tar.gz itools-31bb4ba99f6572acfe08c3daf78dc043dc924903.tar.bz2 itools-31bb4ba99f6572acfe08c3daf78dc043dc924903.zip |
remove custom img() implementation with ie_png_fix, allow using it_html::tagname() for all tags+moretags
-rw-r--r-- | it_html.class | 48 | ||||
-rwxr-xr-x | tests/it_html.t | 26 |
2 files changed, 36 insertions, 38 deletions
diff --git a/it_html.class b/it_html.class index 1f705fb..7437aed 100644 --- a/it_html.class +++ b/it_html.class @@ -65,7 +65,7 @@ class it_html * @param $p Configuration settings. Can be set/overridden in constructor, configure(), html() or head(). * See source code for a list of supported values */ -function it_html($p = array()) +function __construct($p = array()) { # Default configuration of html class $this->p = $p + array( @@ -74,7 +74,6 @@ function it_html($p = array()) 'head' => '', # Code to put into head() section 'htmltype' => 'html5', # 'html5', 'html' (=old-style), 'xhtml' or 'xhtml-mobile' 'lang' => 'de', # Language code to use in <html lang="..."> tag - 'ie_png_fix' => false, # To enable, supply URL of a transparent gif (like /images/0.gif) 'moretags' => '', # Comma-separated list of tag-functions to generate additionally to 'tags' 'name' => 'it_html', # Name of global variable $this is assigned to (string), XXX Copy and paste in configure() to keep PHP4 compatibility 'nonewlinetags' => 'a,b,em,img,input,label,span,noscript', # tags that do not like newlines after them @@ -85,7 +84,7 @@ function it_html($p = array()) 'show_favicon' => true, # If true, add <link> tag to /favicon.ico if it exists 'favicon' => '', # If set, add favicon <link> tag to this url 'staticallycallable' => 'Q,U,select', # Those methods are statically callable (have same arguments as global stubs) but are a bit slower - 'tags' => "a,b,br,button,div,em,fieldset,form,h1,h2,h3,h4,h5,h6,hr,input,label,legend,li,meta,noscript,p,pre,span,style,table,tbody,td,textarea,tfoot,th,thead,tr,ul,ol,article,section", + 'tags' => "a,b,br,button,div,em,fieldset,form,h1,h2,h3,h4,h5,h6,hr,img,input,label,legend,li,meta,noscript,p,pre,span,style,table,tbody,td,textarea,tfoot,th,thead,tr,ul,ol,article,section", 'title' => '', # HTML title (default: no title added) 'use_it_state' => false, # If true, generate code needed by state.js (aka 'history iframe') 'srclines' => $GLOBALS['debug_srclines'], # append stackdump to each tag @@ -107,7 +106,7 @@ function it_html($p = array()) $notexported = array_flip(explode(',', "dummy," . $this->p['notexported'])); # dummy keeps values > 0 # Create global functions for _tags - foreach (array_merge(explode(',', $this->p['tags']), explode(',', $this->p['moretags'])) as $func) + foreach (array_keys($this->alltags) as $func) { if (!function_exists($func) && $func) $code[$func] = "function $func() { \$args = func_get_args(); return \$GLOBALS['{$this->p['name']}']->_tag('$func', \$args); }"; @@ -140,6 +139,7 @@ static function configure($p) { $ithtml = $GLOBALS[$p['name'] ? $p['name'] : "it_html"]; $ithtml->p = $p + (array)$ithtml->p; + $ithtml->alltags = array_flip(explode(',', trim($ithtml->p['tags'] . ',' . $ithtml->p['moretags'], ','))); $ithtml->hasnonewline = array_flip(explode(',', $ithtml->p['nonewlinetags'])); $ithtml->alwaysclose = array_flip(explode(',', $ithtml->p['alwaysclosetags'])); } @@ -344,33 +344,6 @@ function tag($args) } /** - * Special img() function patches png transparency for IE 5.5-6 if ie_png_fix is set - * @param ... any number optional data or array of key => value arguments - * @return <img ... /> - */ -function img($args) -{ - if ($this->p['ie_png_fix'] && preg_match('/MSIE [56]/', $_SERVER['HTTP_USER_AGENT'])) - { - foreach($args as $id => $arg) - if (preg_match('/\.png(\?.*)?$/', $arg['src'])) - { - $args[$id]['style'] = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='{$arg['src']}',sizingMethod='crop');" . $arg['style']; - $args[$id]['src'] = $this->p['ie_png_fix']; - } - } - - foreach ($args as $arg) - $havealt += isset($arg['alt']); - - if (!$havealt) - it::error('img() needs alt'); - - return $this->_tag("img", $args); -} - - -/** * Create a dropdown menu object. Warning: encodes html code within options! * @param $tags key => value pairs of <select> tag * @param $options array (value => text) of available options or @@ -628,5 +601,16 @@ function _itjs($files, $mode) return $result; } + +/** + * Permit calling it_html::div() or parent::div() in a derived class. + */ +function __call($name, $args) +{ + if (isset($this->alltags[$name])) + return $this->_tag($name, $args[0]); + else + it::error("unknown method '$name' called."); +} + } -?> diff --git a/tests/it_html.t b/tests/it_html.t index dc039f7..e863339 100755 --- a/tests/it_html.t +++ b/tests/it_html.t @@ -124,22 +124,27 @@ class myhtml extends it_html function myhtml($p = array()) { - parent::it_html($p + array('nonewlinetags' => 'a,b,em,img,input,span,div')); + parent::__construct($p + ['moretags' => 'overriddentag,defaulttag', 'nonewlinetags' => 'a,b,defaulttag,em,img,input,overriddentag,span,div']); } function myimg($args) { array_unshift($args, array('alt' => "ALT", 'bar' => "BAR")); - return parent::img(array_filter(it_parse_args($args))); } + +function overriddentag($args) +{ + return parent::overriddentag($args); +} + } unset($GLOBALS['it_html']); new myhtml(array('htmltype' => "html")); is( - myimg(array('src' => "foo.gif", 'alt' => "foo")), + myimg(['src' => "foo.gif", 'alt' => "foo"]), '<img alt="foo" bar="BAR" src="foo.gif">', "it_html inheritance" ); @@ -151,6 +156,18 @@ is( ); is( + overriddentag("one ", ['src' => "evil", 'alt' => ""], "two ", ['foo' => "bar"], "three"), + '<overriddentag src="evil" alt="" foo="bar">one two three</overriddentag>', + "moretags override" +); + +is( + defaulttag("one ", ['src' => "evil", 'alt' => ""], "two ", ['foo' => "bar"], "three"), + '<defaulttag src="evil" alt="" foo="bar">one two three</defaulttag>', + "moretags default" +); + +is( it_html::sanitize(" \r \n " . ' <p><a href="http://www.flickr.com/people/swisspics%/">swisspics</a> posted < < ä & yesterday <b>a <i>photo</i></b> <b><i>tag missmatch</b></i>:</p><br><BR /> <P><a href="javascript:window.close()" title="Wolken"><img src="http://farm1.static.flickr.com/177/377214376_bcba167a7d_m.jpg" width="240" height="180" alt="Wolken" style="border: 1px solid #ddd;" /></a></p> @@ -219,6 +236,3 @@ is(it_html::entity_decode("’"), "'", "it_html::entity_decode numeric decim is(it_html::entity_decode("࿿"), " ", "it_html::entity_decode invalid numeric hex entity"); is(it_html::entity_decode("ϧ"), " ", "it_html::entity_decode invalid numeric decimal entity"); is(it_html::entity_decode("‹"), " ", "it_html::entity_decode entity von 0x80-0x9f"); - - -?> |