HeadData Class Reference
[Controller]
Centralizes HTML HEAD data. More...
Public Member Functions |
|
__construct () | |
add_conditional_css_file ($browser, $file, $to_front=false) | |
add_css_file ($file, $to_front=false) | |
add_css_snippet ($snippet, $before_includes=false) | |
Add a CSS snippet. |
|
add_js_file ($file, $to_front=false) | |
Add a javascript file include. |
|
add_js_snippet ($snippet, $before_includes=false) | |
Add a javascript snippet. |
|
add_link ($href, $rel, $attrs=array()) | |
Add a <link> to head. |
|
add_meta ($name, $content, $override=false) | |
add_meta_http_equiv ($name, $content) | |
render ($policy=self::META_INFORMATION) | |
Returns html. |
|
Public Attributes |
|
$conditional_css_files = array() | |
$css_files = array() | |
$css_snippets = array('before' => array(), 'after' => array()) | |
$description = '' | |
$js_files = array() | |
$js_snippets = array('before' => array(), 'after' => array()) | |
$keywords = '' | |
$links = array() | |
$meta = array() | |
$meta_http_equiv = array() | |
$robots_index = ROBOTS_INDEX_FOLLOW | |
$title | |
const | ALL = 1792 |
const | CSS_INCLUDES = 1024 |
const | IE50 = 'IE5' |
const | IE55 = 'IE55' |
const | IE6 = 'IE6' |
const | IE7 = 'IE7' |
const | JAVASCRIPT_INCLUDES = 512 |
const | META_INFORMATION = 256 |
Protected Member Functions |
|
escape_file ($file) | |
render_conditional_css ($arr_browsers) | |
Render coditional CSS. |
|
render_css ($css_files) | |
Render CSS includes. |
|
render_css_snippets ($arr_snippets) | |
render_js ($js_files) | |
Render CSS includes. |
|
render_js_snippets ($arr_snippets) | |
render_links ($arr_links) | |
Render Links. |
|
render_meta ($arr_meta) | |
Render Meta Tags. |
|
render_meta_http_equiv ($arr_meta) | |
Render Meta Http Quiv Tags. |
|
render_robots ($robot_policy) | |
Render META robots section. |
|
render_title ($title, $description, $keywords) | |
Render title and meta description section.
|
Detailed Description
Centralizes HTML HEAD data.
Collects all stuff that is put in the HTML head section, like CSS, scripts or meta information
Definition at line 18 of file headdata.cls.php.
Constructor & Destructor Documentation
HeadData::__construct | ( | ) |
Definition at line 63 of file headdata.cls.php.
00063 { 00064 $this->title = Config::get_value(Config::TITLE); 00065 }
Member Function Documentation
HeadData::add_conditional_css_file | ( | $ | browser, | |
$ | file, | |||
$ | to_front = false |
|||
) |
Definition at line 138 of file headdata.cls.php.
00138 { 00139 if (!empty($file)) { 00140 if (!isset($this->conditional_css_files[$browser])) { 00141 $this->conditional_css_files[$browser] = array(); 00142 } 00143 if ($to_front) { 00144 array_unshift($this->conditional_css_files[$browser], $file); 00145 } else { 00146 $this->conditional_css_files[$browser][] = $file; 00147 } 00148 } 00149 }
HeadData::add_css_file | ( | $ | file, | |
$ | to_front = false |
|||
) |
Definition at line 128 of file headdata.cls.php.
HeadData::add_css_snippet | ( | $ | snippet, | |
$ | before_includes = false |
|||
) |
Add a CSS snippet.
- Parameters:
-
string $snippet bool $before_includes If true, the snippet is placed before included files
- Returns:
- void
Definition at line 158 of file headdata.cls.php.
HeadData::add_js_file | ( | $ | file, | |
$ | to_front = false |
|||
) |
Add a javascript file include.
- Parameters:
-
string $file bool $to_front If true, the javascript file is included before other
- Returns:
- void
Definition at line 101 of file headdata.cls.php.
HeadData::add_js_snippet | ( | $ | snippet, | |
$ | before_includes = false |
|||
) |
Add a javascript snippet.
- Parameters:
-
string $snippet bool $before_includes If true, the snippet is placed before include files
- Returns:
- void
Definition at line 118 of file headdata.cls.php.
HeadData::add_link | ( | $ | href, | |
$ | rel, | |||
$ | attrs = array() |
|||
) |
Add a <link> to head.
- Parameters:
-
string $href Url link points to string $rel rel attribute array $attrs More attributes, like type, rev, etc
- Returns:
- void
Definition at line 186 of file headdata.cls.php.
00186 { 00187 $attrs = Arr::force($attrs, false); 00188 $attrs['rel'] = $rel; 00189 $attrs['href'] = $href; 00190 $this->links[$rel . $href] = html::tag_selfclosing('link', $attrs); 00191 }
HeadData::add_meta | ( | $ | name, | |
$ | content, | |||
$ | override = false |
|||
) |
Definition at line 168 of file headdata.cls.php.
HeadData::add_meta_http_equiv | ( | $ | name, | |
$ | content | |||
) |
Definition at line 174 of file headdata.cls.php.
HeadData::escape_file | ( | $ | file | ) | [protected] |
Definition at line 298 of file headdata.cls.php.
00298 { 00299 if (strpos($file, '://') === false) { 00300 $file = Config::get_value(Config::URL_BASEDIR) . ltrim($file, '/'); 00301 } 00302 return $file; 00303 }
HeadData::render | ( | $ | policy =
self::META_INFORMATION |
) |
Returns html.
- Parameters:
-
int $policy Defines how to render, meaning depends on implementation
- Returns:
- string The rendered content
Implements IRenderer.
Definition at line 73 of file headdata.cls.php.
00073 { 00074 $ret = ''; 00075 if (Common::flag_is_set($policy, self::META_INFORMATION)) { 00076 $ret .= $this->render_title($this->title, $this->description, $this->keywords); 00077 $ret .= $this->render_robots($this->robots_index); 00078 $ret .= $this->render_meta($this->meta); 00079 $ret .= $this->render_links($this->links); 00080 $ret .= $this->render_meta_http_equiv($this->meta_http_equiv); 00081 } 00082 if (Common::flag_is_set($policy, self::CSS_INCLUDES)) { 00083 $ret .= $this->render_css_snippets($this->css_snippets['before']); 00084 $ret .= $this->render_css($this->css_files); 00085 $ret .= $this->render_conditional_css($this->conditional_css_files); 00086 $ret .= $this->render_css_snippets($this->css_snippets['after']); 00087 } 00088 if (Common::flag_is_set($policy, self::JAVASCRIPT_INCLUDES)) { 00089 $ret .= $this->render_js($this->js_files); 00090 } 00091 return $ret; 00092 }
HeadData::render_conditional_css | ( | $ | arr_browsers | ) | [protected] |
Render coditional CSS.
- Parameters:
-
array $arr_browsers
- Returns:
- string
Definition at line 311 of file headdata.cls.php.
00311 { 00312 $ret = ''; 00313 foreach($arr_browsers as $browser => $css_files) { 00314 $token = ''; 00315 switch ($browser) { 00316 case self::IE50: 00317 $token = 'IE 5.0'; 00318 break; 00319 case self::IE55: 00320 $token = 'IE 5.5'; 00321 break; 00322 case self::IE6: 00323 $token = 'IE 6'; 00324 break; 00325 case self::IE7: 00326 $token = 'IE 7'; 00327 break; 00328 default: 00329 continue; 00330 break; 00331 } 00332 $ret .= "<!--[if $token]>\n" . $this->render_css($css_files) . "<![endif]-->\n"; 00333 } 00334 return $ret; 00335 }
HeadData::render_css | ( | $ | css_files | ) | [protected] |
Render CSS includes.
- Parameters:
-
array CSS files
- Returns:
- string
Definition at line 288 of file headdata.cls.php.
00288 { 00289 $ret = ''; 00290 $css_files = array_unique($css_files); 00291 foreach ($css_files as $file) { 00292 $file = String::escape($this->escape_file($file)); 00293 $ret .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$file\" />\n"; 00294 } 00295 return $ret; 00296 }
HeadData::render_css_snippets | ( | $ | arr_snippets | ) | [protected] |
Definition at line 363 of file headdata.cls.php.
00363 { 00364 $ret = ''; 00365 foreach($arr_snippets as $snippet) { 00366 $ret .= html::style($snippet) . "\n"; 00367 } 00368 return $ret; 00369 }
HeadData::render_js | ( | $ | js_files | ) | [protected] |
Render CSS includes.
- Parameters:
-
array CSS files
- Returns:
- string
Definition at line 343 of file headdata.cls.php.
00343 { 00344 $js_files = array_unique($js_files); 00345 $ret = ''; 00346 $ret .= $this->render_js_snippets($this->js_snippets['before']); 00347 foreach ($js_files as $file) { 00348 $file = $this->escape_file($file); 00349 $ret .= html::include_js($file) . "\n"; 00350 } 00351 $ret .= $this->render_js_snippets($this->js_snippets['after']); 00352 return $ret; 00353 }
HeadData::render_js_snippets | ( | $ | arr_snippets | ) | [protected] |
Definition at line 355 of file headdata.cls.php.
00355 { 00356 $ret = ''; 00357 foreach($arr_snippets as $snippet) { 00358 $ret .= html::script_js($snippet) . "\n"; 00359 } 00360 return $ret; 00361 }
HeadData::render_links | ( | $ | arr_links | ) | [protected] |
HeadData::render_meta | ( | $ | arr_meta | ) | [protected] |
Render Meta Tags.
- Parameters:
-
array
- Returns:
- string
Definition at line 246 of file headdata.cls.php.
00246 { 00247 $ret = ''; 00248 foreach ($arr_meta as $name => $content) { 00249 $ret .= html::meta($name, $content) . "\n"; 00250 } 00251 return $ret; 00252 }
HeadData::render_meta_http_equiv | ( | $ | arr_meta | ) | [protected] |
Render Meta Http Quiv Tags.
- Parameters:
-
array
- Returns:
- string
Definition at line 260 of file headdata.cls.php.
00260 { 00261 $ret = ''; 00262 foreach ($arr_meta as $name => $content) { 00263 $ret .= html::meta_http_equiv($name, $content) . "\n"; 00264 } 00265 return $ret; 00266 }
HeadData::render_robots | ( | $ | robot_policy | ) | [protected] |
Render META robots section.
- Parameters:
-
int $robot_policy
- Returns:
- string
Definition at line 221 of file headdata.cls.php.
00221 { 00222 $robots_policies = array(); 00223 $robots_available_policies = array( 00224 'index' => ROBOTS_NOINDEX, 00225 'follow' => ROBOTS_NOFOLLOW, 00226 'archive' => ROBOTS_NOARCHIVE 00227 ); 00228 foreach ($robots_available_policies as $name => $flag) { 00229 if (Common::flag_is_set($robot_policy, $flag)) { 00230 $robots_policies[] = 'no' . $name; 00231 } 00232 else { 00233 $robots_policies[] = $name; 00234 } 00235 } 00236 00237 return html::meta('robots', implode(', ', $robots_policies)) . "\n"; 00238 }
HeadData::render_title | ( | $ | title, | |
$ | description, | |||
$ | keywords | |||
) | [protected] |
Render title and meta description section.
- Parameters:
-
string $title string $description string $keywords
- Returns:
- string
Definition at line 201 of file headdata.cls.php.
00201 { 00202 $ret = ''; 00203 // title 00204 $ret .= html::tag('title', String::escape($title)) . "\n"; 00205 if ($description) { 00206 $description = String::preg_replace('|\s\s+|s', ' ', $description); 00207 $ret .= html::meta('description', String::substr_word($description, 0, 200)) . "\n"; 00208 } 00209 if ($keywords) { 00210 $ret .= html::meta('keywords', $keywords) . "\n"; 00211 } 00212 return $ret; 00213 }
Member Data Documentation
HeadData::$conditional_css_files = array() |
Definition at line 48 of file headdata.cls.php.
HeadData::$css_files = array() |
Definition at line 46 of file headdata.cls.php.
HeadData::$css_snippets = array('before' => array(), 'after' => array()) |
Definition at line 47 of file headdata.cls.php.
HeadData::$description = '' |
Definition at line 30 of file headdata.cls.php.
HeadData::$js_files = array() |
Definition at line 44 of file headdata.cls.php.
HeadData::$js_snippets = array('before' => array(), 'after' => array()) |
Definition at line 45 of file headdata.cls.php.
HeadData::$keywords = '' |
Definition at line 36 of file headdata.cls.php.
HeadData::$links = array() |
Definition at line 51 of file headdata.cls.php.
HeadData::$meta = array() |
Definition at line 49 of file headdata.cls.php.
HeadData::$meta_http_equiv = array() |
Definition at line 50 of file headdata.cls.php.
HeadData::$robots_index = ROBOTS_INDEX_FOLLOW |
Definition at line 42 of file headdata.cls.php.
HeadData::$title |
Definition at line 24 of file headdata.cls.php.
const HeadData::ALL = 1792 |
Definition at line 56 of file headdata.cls.php.
const HeadData::CSS_INCLUDES = 1024 |
Definition at line 55 of file headdata.cls.php.
const HeadData::IE50 = 'IE5' |
Definition at line 58 of file headdata.cls.php.
const HeadData::IE55 = 'IE55' |
Definition at line 59 of file headdata.cls.php.
const HeadData::IE6 = 'IE6' |
Definition at line 60 of file headdata.cls.php.
const HeadData::IE7 = 'IE7' |
Definition at line 61 of file headdata.cls.php.
const HeadData::JAVASCRIPT_INCLUDES = 512 |
Definition at line 54 of file headdata.cls.php.
const HeadData::META_INFORMATION = 256 |
Definition at line 53 of file headdata.cls.php.
The documentation for this class was generated from the following file:
- gyro/core/controller/base/headdata.cls.php