10 defined(
'JPATH_PLATFORM') or die;
35 public $description =
'';
59 public $language =
'en-gb';
67 public $direction =
'ltr';
74 public $_generator =
'Joomla! - Open Source Content Management';
98 public $_lineEnd =
"\12";
106 public $_charset =
'utf-8';
122 public $_namespace =
'';
130 public $_profile =
'';
138 public $_scripts = array();
146 public $_script = array();
154 public $_styleSheets = array();
162 public $_style = array();
170 public $_metaTags = array();
178 public $_engine = null;
186 public $_type = null;
194 public static $_buffer = null;
202 protected static $instances = array();
210 protected $mediaVersion = null;
219 public function __construct($options = array())
221 if (array_key_exists(
'lineend', $options))
223 $this->setLineEnd($options[
'lineend']);
226 if (array_key_exists(
'charset', $options))
228 $this->setCharset($options[
'charset']);
231 if (array_key_exists(
'language', $options))
233 $this->setLanguage($options[
'language']);
236 if (array_key_exists(
'direction', $options))
238 $this->setDirection($options[
'direction']);
241 if (array_key_exists(
'tab', $options))
243 $this->setTab($options[
'tab']);
246 if (array_key_exists(
'link', $options))
248 $this->setLink($options[
'link']);
251 if (array_key_exists(
'base', $options))
253 $this->setBase($options[
'base']);
256 if (array_key_exists(
'mediaversion', $options))
258 $this->setMediaVersion($options[
'mediaversion']);
274 public static function getInstance($type =
'html', $attributes = array())
276 $signature = serialize(array($type, $attributes));
278 if (empty(self::$instances[$signature]))
280 $type = preg_replace(
'/[^A-Z0-9_\.-]/i',
'', $type);
281 $path = __DIR__ .
'/' . $type .
'/' . $type .
'.php';
285 if (!file_exists($path))
293 $class =
'JDocument' . $type;
295 if (!class_exists($class))
297 $path = __DIR__ .
'/' . $type .
'/' . $type .
'.php';
299 if (file_exists($path))
305 throw new RuntimeException(
'Invalid JDocument Class', 500);
309 $instance =
new $class($attributes);
310 self::$instances[$signature] = $instance;
312 if (!is_null($ntype))
315 $instance->setType($ntype);
319 return self::$instances[$signature];
331 public function setType($type)
333 $this->_type = $type;
345 public function getType()
357 public function getBuffer()
359 return self::$_buffer;
372 public function setBuffer($content, $options = array())
374 self::$_buffer = $content;
389 public function getMetaData($name, $httpEquiv =
false)
391 $name = strtolower($name);
393 if ($name ==
'generator')
395 $result = $this->getGenerator();
397 elseif ($name ==
'description')
399 $result = $this->getDescription();
403 if ($httpEquiv ==
true)
405 $result = @$this->_metaTags[
'http-equiv'][$name];
409 $result = @$this->_metaTags[
'standard'][$name];
427 public function setMetaData($name, $content, $http_equiv =
false)
429 $name = strtolower($name);
431 if ($name ==
'generator')
433 $this->setGenerator($content);
435 elseif ($name ==
'description')
437 $this->setDescription($content);
441 if ($http_equiv ==
true)
443 $this->_metaTags[
'http-equiv'][$name] = $content;
447 $this->_metaTags[
'standard'][$name] = $content;
466 public function addScript($url, $type =
"text/javascript", $defer =
false, $async =
false)
468 $this->_scripts[$url][
'mime'] = $type;
469 $this->_scripts[$url][
'defer'] = $defer;
470 $this->_scripts[$url][
'async'] = $async;
489 public function addScriptVersion($url, $version = null, $type =
"text/javascript", $defer =
false, $async =
false)
492 if ($version === null)
494 $version = $this->getMediaVersion();
497 if (!empty($version) && strpos($url,
'?') ===
false)
499 $url .=
'?' . $version;
502 return $this->addScript($url, $type, $defer, $async);
515 public function addScriptDeclaration($content, $type =
'text/javascript')
517 if (!isset($this->_script[strtolower($type)]))
519 $this->_script[strtolower($type)] = $content;
523 $this->_script[strtolower($type)] .= chr(13) . $content;
541 public function addStyleSheet($url, $type =
'text/css', $media = null, $attribs = array())
543 $this->_styleSheets[$url][
'mime'] = $type;
544 $this->_styleSheets[$url][
'media'] = $media;
545 $this->_styleSheets[$url][
'attribs'] = $attribs;
564 public function addStyleSheetVersion($url, $version = null, $type =
"text/css", $media = null, $attribs = array())
567 if ($version === null)
569 $version = $this->getMediaVersion();
572 if (!empty($version) && strpos($url,
'?') ===
false)
574 $url .=
'?' . $version;
577 return $this->addStyleSheet($url, $type, $media, $attribs);
590 public function addStyleDeclaration($content, $type =
'text/css')
592 if (!isset($this->_style[strtolower($type)]))
594 $this->_style[strtolower($type)] = $content;
598 $this->_style[strtolower($type)] .= chr(13) . $content;
613 public function setCharset($type =
'utf-8')
615 $this->_charset = $type;
627 public function getCharset()
629 return $this->_charset;
641 public function setLanguage($lang =
"en-gb")
643 $this->language = strtolower($lang);
655 public function getLanguage()
657 return $this->language;
669 public function setDirection($dir =
"ltr")
671 $this->direction = strtolower($dir);
683 public function getDirection()
685 return $this->direction;
697 public function setTitle($title)
699 $this->title = $title;
711 public function getTitle()
725 public function setMediaVersion($mediaVersion)
727 $this->mediaVersion = strtolower($mediaVersion);
739 public function getMediaVersion()
741 return $this->mediaVersion;
753 public function setBase($base)
767 public function getBase()
781 public function setDescription($description)
783 $this->description = $description;
795 public function getDescription()
797 return $this->description;
809 public function setLink($url)
823 public function getLink()
837 public function setGenerator($generator)
839 $this->_generator = $generator;
851 public function getGenerator()
853 return $this->_generator;
865 public function setModifiedDate($date)
867 $this->_mdate = $date;
879 public function getModifiedDate()
881 return $this->_mdate;
902 public function setMimeEncoding($type =
'text/html', $sync =
true)
904 $this->_mime = strtolower($type);
909 $this->setMetaData(
'content-type', $type .
'; charset=' . $this->_charset,
true);
922 public function getMimeEncoding()
936 public function setLineEnd($style)
941 $this->_lineEnd =
"\15\12";
944 $this->_lineEnd =
"\12";
947 $this->_lineEnd =
"\15";
950 $this->_lineEnd = $style;
963 public function _getLineEnd()
965 return $this->_lineEnd;
977 public function setTab($string)
979 $this->_tab = $string;
991 public function _getTab()
1006 public function loadRenderer($type)
1008 $class =
'JDocumentRenderer' . $type;
1010 if (!class_exists($class))
1012 $path = __DIR__ .
'/' . $this->_type .
'/renderer/' . $type .
'.php';
1014 if (file_exists($path))
1020 throw new RuntimeException(
'Unable to load renderer class', 500);
1024 if (!class_exists($class))
1029 $instance =
new $class($this);
1043 public function parse($params = array())
1058 public function render($cache =
false, $params = array())
1062 if ($mdate = $this->getModifiedDate())
1064 $app->modifiedDate = $mdate;
1067 $app->mimeType = $this->_mime;
1068 $app->charSet = $this->_charset;