Source for file html.php
Documentation is available at html.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
jimport('joomla.utilities.utility');
* DocumentHTML class, provides an easy interface to parse and display a HTML document
* @package Joomla.Platform
* Array of Header <link> tags
* Array of template parameters
* String holding parsed template
* Array of parsed template JDoc tags
* Integer with caching setting
* Set to true when the document should be output as HTML%
* @param array $options Associative array of options
// Set default mime type and document metadata (meta data syncs with mime type by default)
* Get the HTML document head data
* @return array The document head data in array form
$data['title'] =
$this->title;
$data['link'] =
$this->link;
$data['links'] =
$this->_links;
$data['style'] =
$this->_style;
* Set the HTML document head data
* @param array $data The document head data in array form
* @return JDocumentHTML instance of $this to allow chaining
$this->title =
(isset
($data['title']) &&
!empty($data['title'])) ?
$data['title'] :
$this->title;
$this->description =
(isset
($data['description']) &&
!empty($data['description'])) ?
$data['description'] :
$this->description;
$this->link =
(isset
($data['link']) &&
!empty($data['link'])) ?
$data['link'] :
$this->link;
$this->_metaTags =
(isset
($data['metaTags']) &&
!empty($data['metaTags'])) ?
$data['metaTags'] :
$this->_metaTags;
$this->_links =
(isset
($data['links']) &&
!empty($data['links'])) ?
$data['links'] :
$this->_links;
$this->_styleSheets =
(isset
($data['styleSheets']) &&
!empty($data['styleSheets'])) ?
$data['styleSheets'] :
$this->_styleSheets;
$this->_style =
(isset
($data['style']) &&
!empty($data['style'])) ?
$data['style'] :
$this->_style;
$this->_scripts =
(isset
($data['scripts']) &&
!empty($data['scripts'])) ?
$data['scripts'] :
$this->_scripts;
$this->_script =
(isset
($data['script']) &&
!empty($data['script'])) ?
$data['script'] :
$this->_script;
$this->_custom =
(isset
($data['custom']) &&
!empty($data['custom'])) ?
$data['custom'] :
$this->_custom;
if (isset
($data['scriptText']) &&
!empty($data['scriptText']))
foreach ($data['scriptText'] as $key =>
$string)
* Merge the HTML document head data
* @param array $data The document head data in array form
* @return JDocumentHTML instance of $this to allow chaining
$this->title =
(isset
($data['title']) &&
!empty($data['title']) &&
!stristr($this->title, $data['title']))
?
$this->title .
$data['title']
$this->link =
(isset
($data['link'])) ?
$data['link'] :
$this->link;
if (isset
($data['metaTags']))
foreach ($data['metaTags'] as $type1 =>
$data1)
$booldog =
$type1 ==
'http-equiv' ?
true :
false;
foreach ($data1 as $name2 =>
$data2)
$this->_links =
(isset
($data['links']) &&
!empty($data['links']) &&
is_array($data['links']))
$this->_styleSheets =
(isset
($data['styleSheets']) &&
!empty($data['styleSheets']) &&
is_array($data['styleSheets']))
if (isset
($data['style']))
foreach ($data['style'] as $type =>
$stdata)
$this->_scripts =
(isset
($data['scripts']) &&
!empty($data['scripts']) &&
is_array($data['scripts']))
if (isset
($data['script']))
foreach ($data['script'] as $type =>
$sdata)
$this->_custom =
(isset
($data['custom']) &&
!empty($data['custom']) &&
is_array($data['custom']))
* Adds <link> tags to the head of the document
* $relType defaults to 'rel' as it is the most common relation type used.
* ('rev' refers to reverse relation, 'rel' indicates normal, forward relation.)
* Typical tag: <link href="index.php" rel="Start">
* @param string $href The link that is being related.
* @param string $relation Relation of link.
* @param string $relType Relation type attribute. Either rel or rev (default: 'rel').
* @param array $attribs Associative array of remaining attributes.
* @return JDocumentHTML instance of $this to allow chaining
public function addHeadLink($href, $relation, $relType =
'rel', $attribs =
array())
$this->_links[$href]['relation'] =
$relation;
$this->_links[$href]['relType'] =
$relType;
$this->_links[$href]['attribs'] =
$attribs;
* Adds a shortcut icon (favicon)
* This adds a link to the icon shown in the favorites list or on
* the left of the url in the address bar. Some browsers display
* it on the tab, as well.
* @param string $href The link that is being related.
* @param string $type File type
* @param string $relation Relation of link
* @return JDocumentHTML instance of $this to allow chaining
public function addFavicon($href, $type =
'image/vnd.microsoft.icon', $relation =
'shortcut icon')
$this->addHeadLink($href, $relation, 'rel', array('type' =>
$type));
* Adds a custom HTML string to the head block
* @param string $html The HTML to add to the head
* @return JDocumentHTML instance of $this to allow chaining
* Returns whether the document is set up to be output as HTML5
* @return Boolean true when HTML5 is used
* Sets whether the document should be output as HTML5
* @param bool $state True when HTML5 should be output
* Get the contents of a document include
* @param string $type The type of renderer
* @param string $name The name of the element to render
* @param array $attribs Associative array of remaining attributes.
* @return The output of the renderer
public function getBuffer($type =
null, $name =
null, $attribs =
array())
// If no type is specified, return the whole buffer
$title =
(isset
($attribs['title'])) ?
$attribs['title'] :
null;
if (isset
(parent::$_buffer[$type][$name][$title]))
return parent::$_buffer[$type][$name][$title];
if ($this->_caching ==
true &&
$type ==
'modules')
$hash =
md5(serialize(array($name, $attribs, null, $renderer)));
$cbuffer =
$cache->get('cbuffer_' .
$type);
if (isset
($cbuffer[$hash]))
$options['nopathway'] =
1;
$options['nomodules'] =
1;
$options['modulemode'] =
1;
$this->setBuffer($renderer->render($name, $attribs, null), $type, $name);
$data =
parent::$_buffer[$type][$name][$title];
$tmpdata =
JCache::setWorkarounds($data, $options);
$cbuffer[$hash] =
$tmpdata;
$cache->store($cbuffer, 'cbuffer_' .
$type);
$this->setBuffer($renderer->render($name, $attribs, null), $type, $name, $title);
return parent::$_buffer[$type][$name][$title];
* Set the contents a document includes
* @param string $content The content to be set in the buffer.
* @param array $options Array of optional elements.
* @return JDocumentHTML instance of $this to allow chaining
public function setBuffer($content, $options =
array())
// The following code is just for backward compatibility.
if (func_num_args() >
1 &&
!is_array($options))
$options['type'] =
$args[1];
$options['name'] =
(isset
($args[2])) ?
$args[2] :
null;
$options['title'] =
(isset
($args[3])) ?
$args[3] :
null;
parent::$_buffer[$options['type']][$options['name']][$options['title']] =
$content;
* Parses the template and populates the buffer
* @param array $params Parameters for fetching the template
* @return JDocumentHTML instance of $this to allow chaining
public function parse($params =
array())
* Outputs the template to the browser.
* @param boolean $caching If true, cache the output
* @param array $params Associative array of attributes
* @return The rendered data
public function render($caching =
false, $params =
array())
* Count the modules based on the given condition
* @param string $condition The condition to use
* @return integer Number of modules found
$operators =
'(\+|\-|\*|\/|==|\!=|\<\>|\<|\>|\<=|\>=|and|or|xor)';
$words =
preg_split('# ' .
$operators .
' #', $condition, null, PREG_SPLIT_DELIM_CAPTURE);
for ($i =
0, $n =
count($words); $i <
$n; $i +=
2)
$words[$i] =
((isset
(parent::$_buffer['modules'][$name])) &&
(parent::$_buffer['modules'][$name] ===
false))
$str =
'return ' .
implode(' ', $words) .
';';
* Count the number of child menu items
* @return integer Number of child menu items
$active =
$menu->getActive();
$query =
$db->getQuery(true)
->where('parent_id = ' .
$active->id)
->where('published = 1');
$children =
$db->loadResult();
* @param string $directory The name of the template
* @param string $filename The actual filename
* @return string The contents of the template
// @todo remove code: $component = JApplicationHelper::getComponentName();
// Check to see if we have a valid template file
$this->_file =
$directory .
'/' .
$filename;
require
$directory .
'/' .
$filename;
// Try to find a favicon by checking the template and root folder
$path =
$directory .
'/';
$icon =
$dir .
'favicon.ico';
* Fetch the template, and initialise the params
* @param array $params Parameters to determine the template
* @return JDocumentHTML instance of $this to allow chaining
$directory = isset
($params['directory']) ?
$params['directory'] :
'templates';
$template =
$filter->clean($params['template'], 'cmd');
$file =
$filter->clean($params['file'], 'cmd');
if (!file_exists($directory .
'/' .
$template .
'/' .
$file))
// Load the language file for the template
$lang->load('tpl_' .
$template, JPATH_BASE, null, false, true)
||
$lang->load('tpl_' .
$template, $directory .
'/' .
$template, null, false, true);
$this->params = isset
($params['params']) ?
$params['params'] :
new JRegistry;
* Parse a document template
* @return JDocumentHTML instance of $this to allow chaining
$template_tags_first =
array();
$template_tags_last =
array();
// Step through the jdocs in reverse order.
for ($i =
count($matches[0]) -
1; $i >=
0; $i--
)
$name = isset
($attribs['name']) ?
$attribs['name'] :
null;
// Separate buffers to be executed first and last
if ($type ==
'module' ||
$type ==
'modules')
$template_tags_first[$matches[0][$i]] =
array('type' =>
$type, 'name' =>
$name, 'attribs' =>
$attribs);
$template_tags_last[$matches[0][$i]] =
array('type' =>
$type, 'name' =>
$name, 'attribs' =>
$attribs);
// Reverse the last array so the jdocs are in forward order.
* Render pre-parsed template
* @return string rendered template
$with[] =
$this->getBuffer($args['type'], $args['name'], $args['attribs']);
Documentation generated on Tue, 19 Nov 2013 15:04:54 +0100 by phpDocumentor 1.4.3