html Class Reference
[Lib]
Class that wrappes common HTML. More...
Static Public Member Functions |
|
static | a ($text, $href, $descr, $attrs=array()) |
Static. |
|
static | attr ($name, $value) |
Returns code for attribute, including
leading blank. |
|
static | attrs ($arr) |
static | b ($text, $cls="") |
A strong tag. |
|
static | br ($cls= '') |
returns a br-tag |
|
static | div ($text, $cls= '') |
A div tag. |
|
static | dl ($items, $cls= '') |
Returns HTML code for a definition list.
|
|
static | em ($text, $cls="") |
An em tag. |
|
static | error ($text) |
Static. |
|
static | flash ($file, $attrs=array(), $params=array()) |
Returns html to embed flash files. |
|
static | form ($name, $action, $content, $method= 'post', $attrs=array()) |
Return a form. |
|
static | h ($text, $level, $cls="") |
A heading. |
|
static | img ($path, $alt, $attrs=array()) |
Output image tag. |
|
static | include_css ($path, $media= 'screen') |
A CSS include. |
|
static | include_js ($path) |
A javascript include. |
|
static | info ($text) |
static | input ($type, $name, $attrs) |
Returns an input element. |
|
static | label ($title, $for, $cls= '') |
static | li ($items, $cls= '', $useOrdered=false) |
Returns HTML code for a list. |
|
static | meta ($name, $content) |
Creates META tag. |
|
static | meta_http_equiv ($equiv, $content) |
Creates META http-equiv tag. |
|
static | note ($text) |
static | p ($text, $cls= '') |
A p tag. |
|
static | script_js ($content) |
Create script tag with content. |
|
static | select ($name, $options, $value, $attrs=array()) |
Builds select box. |
|
static | span ($text, $cls= '') |
A span tag. |
|
static | style ($content) |
Create style tag with content. |
|
static | submit ($text, $name, $descr, $attrs=array()) |
Create an submit button. |
|
static | success ($text) |
static | table ($rows, $head, $summary, $attr=array()) |
Output a table. |
|
static | tag ($tag, $text, $attrs=array()) |
Tag surrounding text. |
|
static | tag_selfclosing ($tag, $attrs=array()) |
Self closing tag. |
|
static | td ($text, $attr=array(), $is_head=false) |
Build a table cell. |
|
static | title ($text, $descr="") |
Static. |
|
static | tr ($cells, $attr=array()) |
Combine table cells into a row. |
|
static | warning ($text) |
Public Attributes |
|
const | EMPTY_ATTRIBUTE = '[[[[[empty]]]]' |
Detailed Description
Class that wrappes common HTML.
Definition at line 13 of file html.cls.php.
Member Function Documentation
static html::a | ( | $ | text, | |
$ | href, | |||
$ | descr, | |||
$ | attrs = array() |
|||
) | [static] |
Static.
Returns the code for a link
Returns the follwoing: <a [class="$cls"] href="$href" $title="$descr">$text
- Parameters:
-
String The Text for the link String The HREF String A Desctiption, displayed as tool tip String Other atrributes
- Returns:
- String The code for an anchor tag
Definition at line 32 of file html.cls.php.
00032 { 00033 // We need path here, but cannot rely on URL class, since href may be 00034 // horribly broken 00035 $url = str_replace(Config::get_url(Config::URL_SERVER), "", $href); 00036 $url = str_replace(Config::get_url(Config::URL_SERVER_SAFE), "", $href); 00037 00038 if (Url::current()->is_ancestor_of($url)) { 00039 html::_appendClass($attrs, 'active'); 00040 } 00041 if (Url::current()->is_same_as($url)) { 00042 html::_appendClass($attrs, 'self'); 00043 } 00044 00045 $attrs['href'] = $href; 00046 if ($descr) { 00047 $attrs['title'] = $descr; 00048 } 00049 00050 return html::tag('a', $text, $attrs); 00051 }
static html::attr | ( | $ | name, | |
$ | value | |||
) | [static] |
Returns code for attribute, including leading blank.
- Returns:
- string Empty string if passed value is empty
Definition at line 395 of file html.cls.php.
00395 { 00396 $value = str_replace("\n", ' ', $value); 00397 if ($value === self::EMPTY_ATTRIBUTE) { 00398 $value = ''; 00399 } else if (empty($value) && strval($value) !== '0') { 00400 return ''; 00401 } 00402 00403 // remove every non-word character 00404 $clean_name = preg_replace('|[^\w:_-]|', '', $name); 00405 if ($clean_name === '') { 00406 return ''; 00407 } 00408 00409 return ' ' . $clean_name . '="' . String::escape($value) . '"'; 00410 }
static html::attrs | ( | $ | arr | ) | [static] |
Definition at line 412 of file html.cls.php.
00412 { 00413 $ret = ''; 00414 foreach($arr as $key => $value) { 00415 if ($key === 'class' && is_array($value)) { 00416 $value = implode(' ', $value); 00417 } 00418 $ret .= html::attr($key, $value); 00419 } 00420 return $ret; 00421 }
static html::b | ( | $ | text, | |
$ | cls = "" |
|||
) | [static] |
A strong tag.
- Parameters:
-
string $text Content within tag string $cls HTML class
- Returns:
- string <strong class="$cls>$text
Definition at line 163 of file html.cls.php.
00163 { 00164 return html::tag('strong', $text, array('class' => $cls)); 00165 }
static html::br | ( | $ | cls = '' |
) | [static] |
returns a br-tag
Definition at line 504 of file html.cls.php.
00504 { 00505 return '<br' . html::attr('class', $cls) . ' />'; 00506 }
static html::div | ( | $ | text, | |
$ | cls = '' |
|||
) | [static] |
A div tag.
- Parameters:
-
string $text Content within div string $cls HTML class
- Returns:
- string <div class="$cls>$text
Definition at line 126 of file html.cls.php.
00126 { 00127 return html::tag('div', $text, array('class' => $cls)); 00128 }
static html::dl | ( | $ | items, | |
$ | cls = '' |
|||
) | [static] |
Returns HTML code for a definition list.
The list topics and descriptions are provided with special classes:
- Even/uneven
- First and last
- Parameters:
-
array $items Array of list items as associative array with topic => description string $cls Possible class name. The class is assigned to topics, descriptions, and container
- Returns:
- String
Definition at line 267 of file html.cls.php.
00267 { 00268 $c = count($items); 00269 if ($c == 0) { 00270 return ''; 00271 } 00272 00273 $list = "\n"; 00274 $i = 0; 00275 foreach($items as $dt => $dd) { 00276 $arr_cls = array($cls); 00277 $arr_cls[] = (++$i % 2) ? 'uneven' : 'even'; 00278 if ($i === 1) { 00279 $arr_cls[] = 'first'; 00280 } 00281 if ($i === $c) { 00282 $arr_cls[] = 'last'; 00283 } 00284 $list .= html::tag('dt', $dt, array('class' => $arr_cls)); 00285 $list .= "\n"; 00286 $list .= html::tag('dd', $dd, array('class' => $arr_cls)); 00287 $list .= "\n"; 00288 } 00289 00290 return html::tag('dl', $list, array('class' => $cls)); 00291 }
static html::em | ( | $ | text, | |
$ | cls = "" |
|||
) | [static] |
An em tag.
- Parameters:
-
string $text Content within tag string $cls HTML class
- Returns:
- string <em class="$cls>$text
Definition at line 175 of file html.cls.php.
00175 { 00176 return html::tag('em', $text, array('class' => $cls)); 00177 }
static html::error | ( | $ | text | ) | [static] |
static html::flash | ( | $ | file, | |
$ | attrs = array() , |
|||
$ | params = array() |
|||
) | [static] |
Returns html to embed flash files.
Code is XHTML compliant!
- Parameters:
-
string $file URL of flash file array $attrs HTML attributes for object tag array $params Flahs params (rendered as param tags)
Definition at line 517 of file html.cls.php.
00517 { 00518 // See http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 00519 $alternative = tr('You need flash to be installed, to view this content', 'core'); 00520 if (!isset($params['wmode'])) { 00521 $params['wmode'] = 'transparent'; 00522 } 00523 $param_tags = ''; 00524 foreach($params as $key => $value) { 00525 $param_tags .= self::tag_selfclosing('param', array('name' => $key, 'value' => $value)) . "\n"; 00526 } 00527 00528 self::_appendClass($attrs, 'player'); 00529 $ie_attrs = array_merge($attrs, array( 00530 'classid' => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000', 00531 'codebase' => 'http://get.adobe.com/shockwave/' 00532 )); 00533 $other_attrs = array_merge($attrs, array( 00534 'type' => 'application/x-shockwave-flash', 00535 'data' => $file, 00536 )); 00537 00538 $ret = ''; 00539 // Non-IE version 00540 $ret .= "<!--[if !IE]> -->\n" . html::tag('object', $param_tags, $other_attrs) . "\n<!-- <![endif]-->\n"; 00541 // IE Version 00542 $param_tags .= self::tag_selfclosing('param', array('name' => 'movie', 'value' => $file)) . "\n"; 00543 $ret .= "<!--[if IE]> \n" . html::tag('object', $param_tags, $ie_attrs) . "\n<![endif]-->\n"; 00544 00545 return $ret; 00546 }
static html::form | ( | $ | name, | |
$ | action, | |||
$ | content, | |||
$ | method = 'post' , |
|||
$ | attrs = array() |
|||
) | [static] |
Return a form.
Definition at line 324 of file html.cls.php.
00324 { 00325 $attrs['name'] = $name; 00326 $attrs['id'] = Arr::get_item($attrs, 'id', $name); 00327 $attrs['action'] = $action; 00328 $attrs['method'] = $method; 00329 return self::tag('form', $content, $attrs); 00330 }
static html::h | ( | $ | text, | |
$ | level, | |||
$ | cls = "" |
|||
) | [static] |
A heading.
- Parameters:
-
string $text Content within tag int $level The level of heading (1 to 6). 1 creates h1, 2 creates h2 etc... string $cls HTML class
- Returns:
- string <h$level class="$cls>$text</h$level>
Definition at line 188 of file html.cls.php.
00188 { 00189 return html::tag('h' . $level, $text, array('class' => $cls)); 00190 }
static html::img | ( | $ | path, | |
$ | alt, | |||
$ | attrs = array() |
|||
) | [static] |
Output image tag.
- Parameters:
-
string $path URL of image string $alt Alt text array $attrs HTML attributes
- Returns:
- string
Definition at line 83 of file html.cls.php.
00083 { 00084 if ($alt === '') { 00085 $alt = self::EMPTY_ATTRIBUTE; 00086 } 00087 $attrs['src'] = $path; 00088 $attrs['alt'] = $alt; 00089 return self::tag_selfclosing('img', $attrs); 00090 }
static html::include_css | ( | $ | path, | |
$ | media = 'screen' |
|||
) | [static] |
A CSS include.
- Parameters:
-
string $path URL of CSS string $media Media
- Returns:
- string <style type="text/css" media="$media"> url($path);</style>
Definition at line 454 of file html.cls.php.
00454 { 00455 return '<style type="text/css" media="' . String::clear_html($media) . '">@import url(' . String::clear_html($path) . ');</style>'; 00456 }
static html::include_js | ( | $ | path | ) | [static] |
A javascript include.
- Parameters:
-
string $path URL of script
- Returns:
- string <script type="text/javascript" src="$path"></script>
Definition at line 429 of file html.cls.php.
00429 { 00430 return '<script type="text/javascript" src="' . String::clear_html($path) . '"></script>'; 00431 }
static html::info | ( | $ | text | ) | [static] |
Definition at line 114 of file html.cls.php.
00114 { 00115 return html::p($text, "info"); 00116 }
static html::input | ( | $ | type, | |
$ | name, | |||
$ | attrs | |||
) | [static] |
Returns an input element.
Definition at line 314 of file html.cls.php.
00314 { 00315 $attrs['name'] = $name; 00316 $attrs['type'] = $type; 00317 self::_appendClass($attrs, $type); 00318 return self::tag_selfclosing('input', $attrs); 00319 }
static html::label | ( | $ | title, | |
$ | for, | |||
$ | cls = '' |
|||
) | [static] |
Definition at line 303 of file html.cls.php.
00303 { 00304 $attrs = array( 00305 'for' => $for, 00306 'class' => $cls 00307 ); 00308 return self::tag('label', self::span($title), $attrs); 00309 }
static html::li | ( | $ | items, | |
$ | cls = '' , |
|||
$ | useOrdered = false |
|||
) | [static] |
Returns HTML code for a list.
The list's items are provided with special classes:
- Even/uneven
- First and last
- Parameters:
-
array $items Array of list items string $cls Possible class name. The class is assigned to both items and container (ul/ol) Boolean True if list should be ordered, that is coantiner shouldbe ol not ul
- Returns:
- String
Definition at line 231 of file html.cls.php.
00231 { 00232 $c = count($items); 00233 if ($c == 0) { 00234 return ''; 00235 } 00236 00237 $li = ''; 00238 $i = 0; 00239 foreach($items as $item) { 00240 $arr_cls = array($cls); 00241 $arr_cls[] = (++$i % 2) ? 'uneven' : 'even'; 00242 if ($i === 1) { 00243 $arr_cls[] = 'first'; 00244 } 00245 if ($i === $c) { 00246 $arr_cls[] = 'last'; 00247 } 00248 $li .= html::tag('li', $item, array('class' => $arr_cls)); 00249 } 00250 00251 $tag = ($useOrdered) ? 'ol' : 'ul'; 00252 return html::tag($tag, $li, array('class' => $cls)); 00253 }
static html::meta | ( | $ | name, | |
$ | content | |||
) | [static] |
Creates META tag.
- Parameters:
-
string $name string $content
- Returns:
- string
Definition at line 478 of file html.cls.php.
00478 { 00479 $attrs = array( 00480 'name' => $name, 00481 'content' => $content 00482 ); 00483 return self::tag_selfclosing('meta', $attrs); 00484 }
static html::meta_http_equiv | ( | $ | equiv, | |
$ | content | |||
) | [static] |
Creates META http-equiv tag.
- Parameters:
-
string $equiv string $content
- Returns:
- string
Definition at line 493 of file html.cls.php.
00493 { 00494 $attrs = array( 00495 'http-equiv' => $equiv, 00496 'content' => $content 00497 ); 00498 return self::tag_selfclosing('meta', $attrs); 00499 }
static html::note | ( | $ | text | ) | [static] |
Definition at line 106 of file html.cls.php.
00106 { 00107 return html::p($text, "note"); 00108 }
static html::p | ( | $ | text, | |
$ | cls = '' |
|||
) | [static] |
A p tag.
- Parameters:
-
string $text Content within tag string $cls HTML class
- Returns:
- string <p class="$cls>$text
Definition at line 138 of file html.cls.php.
00138 { 00139 return html::tag('p', $text, array('class' => $cls)); 00140 }
static html::script_js | ( | $ | content | ) | [static] |
Create script tag with content.
- Parameters:
-
string $content The script
- Returns:
- string
Definition at line 439 of file html.cls.php.
00439 { 00440 $content = "<!--// <![CDATA[\n" . $content . "\n// ]]> -->"; 00441 $attrs = array( 00442 'type' => 'text/javascript' 00443 ); 00444 return html::tag('script', $content, $attrs); 00445 }
static html::select | ( | $ | name, | |
$ | options, | |||
$ | value, | |||
$ | attrs = array() |
|||
) | [static] |
Builds select box.
- Parameters:
-
string $name array $options string $value array $attrs
- Returns:
- string
Definition at line 341 of file html.cls.php.
00341 { 00342 $opts = self::options(Arr::force($options), Arr::force($value, false)); 00343 $attrs['name'] = $name; 00344 return html::tag('select', $opts, $attrs); 00345 }
static html::span | ( | $ | text, | |
$ | cls = '' |
|||
) | [static] |
A span tag.
- Parameters:
-
string $text Content within tag string $cls HTML class
- Returns:
- string <span class="$cls>$text
Definition at line 150 of file html.cls.php.
00150 { 00151 return html::tag('span', $text, array('class' => $cls)); 00152 }
static html::style | ( | $ | content | ) | [static] |
Create style tag with content.
- Parameters:
-
string $content The CSS
- Returns:
- string
Definition at line 464 of file html.cls.php.
00464 { 00465 $attrs = array( 00466 'type' => 'text/css' 00467 ); 00468 return html::tag('style', $content, $attrs); 00469 }
static html::submit | ( | $ | text, | |
$ | name, | |||
$ | descr, | |||
$ | attrs = array() |
|||
) | [static] |
Create an submit button.
Definition at line 296 of file html.cls.php.
00296 { 00297 $attrs['alt'] = $descr; 00298 $attrs['title'] = $descr; 00299 $attrs['value'] = $text; 00300 return self::input('submit', $name, $attrs); 00301 }
static html::success | ( | $ | text | ) | [static] |
Definition at line 102 of file html.cls.php.
00102 { 00103 return html::p($text, "success"); 00104 }
static html::table | ( | $ | rows, | |
$ | head, | |||
$ | summary, | |||
$ | attr = array() |
|||
) | [static] |
Output a table.
The table rows are labeled with classes "first", "last" and "even"/"uneven"
If you pass an array as $rows or $head, instead an array of arrays, it is treated as one single row.
- Since:
- 0.5.1
- Parameters:
-
array $rows Array of arrays of body cells. Cells must be already formated with either
or
- Parameters:
-
array $head Array of arrays of head cells. Cells must be already formated with either
or
- Parameters:
-
string $summary Table summary array $attr Additional html attributes
- Returns:
- string
Definition at line 585 of file html.cls.php.
00585 { 00586 $ret = ''; 00587 00588 $body = self::table_build_rows($rows); 00589 $head = self::table_build_rows($head); 00590 00591 $content = ''; 00592 $content .= ($head) ? html::tag('thead', $head) . "\n" : ''; 00593 $content .= ($body) ? html::tag('tbody', $body) . "\n" : ''; 00594 00595 $attr['summary'] = $summary; 00596 $ret .= html::tag( 00597 'table', 00598 $content, 00599 $attr 00600 ); 00601 00602 return $ret; 00603 }
static html::tag | ( | $ | tag, | |
$ | text, | |||
$ | attrs = array() |
|||
) | [static] |
Tag surrounding text.
- Parameters:
-
string $tag Tag name string $text Content within tag array $attrs HTML attributes as associative array of name => value
- Returns:
- string <tag attrs>="">text</tag>
Definition at line 201 of file html.cls.php.
00201 { 00202 return '<' . $tag . html::attrs($attrs) . ">" . $text . "</" . $tag . ">"; 00203 }
static html::tag_selfclosing | ( | $ | tag, | |
$ | attrs = array() |
|||
) | [static] |
Self closing tag.
- Parameters:
-
string $tag Tag name array $attrs HTML attributes as associative array of name => value
- Returns:
- string <tag attrs="">
Definition at line 213 of file html.cls.php.
00213 { 00214 return '<' . $tag . html::attrs($attrs) . " />"; 00215 }
static html::td | ( | $ | text, | |
$ | attr = array() , |
|||
$ | is_head = false |
|||
) | [static] |
Build a table cell.
Definition at line 551 of file html.cls.php.
static html::title | ( | $ | text, | |
$ | descr = "" |
|||
) | [static] |
Static.
Returns code for title tag and related meta tags
- Returns:
- String The HTML code for title and meta tags
Definition at line 61 of file html.cls.php.
00061 { 00062 $arrFilter = array("-", ",", ".", "(", ")", ":", "'", '"', "&"); 00063 $keywords = str_replace($arrFilter, " ", $descr); 00064 $keywords = str_replace(" ", " ", $keywords); 00065 $keywords = str_replace(" ", ",", $keywords); 00066 00067 $ret = self::tag('title', String::escape($text)) . "\n"; 00068 $ret .= self::meta('title', $text) . "\n"; 00069 $ret .= self::meta('description', $descr) . "\n"; 00070 $ret .= self::meta('keywords', $keywords) . "\n"; 00071 return $ret; 00072 }
static html::tr | ( | $ | cells, | |
$ | attr = array() |
|||
) | [static] |
Combine table cells into a row.
Table cells must be enclosed in
or
already
Definition at line 563 of file html.cls.php.
00563 { 00564 $text = implode("\n", Arr::force($cells)); 00565 return self::tag('tr', $text, $attr); 00566 }
static html::warning | ( | $ | text | ) | [static] |
Definition at line 110 of file html.cls.php.
00110 { 00111 return html::p($text, "warning"); 00112 }
Member Data Documentation
const html::EMPTY_ATTRIBUTE = '[[[[[empty]]]]' |
Definition at line 19 of file html.cls.php.
The documentation for this class was generated from the following file:
- gyro/core/lib/helpers/html.cls.php