1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Document
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Document class, provides an easy interface to parse and display a document
14 *
15 * @since 11.1
16 */
17 class JDocument
18 {
19 /**
20 * Document title
21 *
22 * @var string
23 * @since 11.1
24 */
25 public $title = '';
26
27 /**
28 * Document description
29 *
30 * @var string
31 * @since 11.1
32 */
33 public $description = '';
34
35 /**
36 * Document full URL
37 *
38 * @var string
39 * @since 11.1
40 */
41 public $link = '';
42
43 /**
44 * Document base URL
45 *
46 * @var string
47 * @since 11.1
48 */
49 public $base = '';
50
51 /**
52 * Contains the document language setting
53 *
54 * @var string
55 * @since 11.1
56 */
57 public $language = 'en-gb';
58
59 /**
60 * Contains the document direction setting
61 *
62 * @var string
63 * @since 11.1
64 */
65 public $direction = 'ltr';
66
67 /**
68 * Document generator
69 *
70 * @var string
71 */
72 public $_generator = 'Joomla! - Open Source Content Management';
73
74 /**
75 * Document modified date
76 *
77 * @var string
78 * @since 11.1
79 */
80 public $_mdate = '';
81
82 /**
83 * Tab string
84 *
85 * @var string
86 * @since 11.1
87 */
88 public $_tab = "\11";
89
90 /**
91 * Contains the line end string
92 *
93 * @var string
94 * @since 11.1
95 */
96 public $_lineEnd = "\12";
97
98 /**
99 * Contains the character encoding string
100 *
101 * @var string
102 * @since 11.1
103 */
104 public $_charset = 'utf-8';
105
106 /**
107 * Document mime type
108 *
109 * @var string
110 * @since 11.1
111 */
112 public $_mime = '';
113
114 /**
115 * Document namespace
116 *
117 * @var string
118 * @since 11.1
119 */
120 public $_namespace = '';
121
122 /**
123 * Document profile
124 *
125 * @var string
126 * @since 11.1
127 */
128 public $_profile = '';
129
130 /**
131 * Array of linked scripts
132 *
133 * @var array
134 * @since 11.1
135 */
136 public $_scripts = array();
137
138 /**
139 * Array of scripts placed in the header
140 *
141 * @var array
142 * @since 11.1
143 */
144 public $_script = array();
145
146 /**
147 * Array of scripts options
148 *
149 * @var array
150 */
151 protected $scriptOptions = array();
152
153 /**
154 * Array of linked style sheets
155 *
156 * @var array
157 * @since 11.1
158 */
159 public $_styleSheets = array();
160
161 /**
162 * Array of included style declarations
163 *
164 * @var array
165 * @since 11.1
166 */
167 public $_style = array();
168
169 /**
170 * Array of meta tags
171 *
172 * @var array
173 * @since 11.1
174 */
175 public $_metaTags = array();
176
177 /**
178 * The rendering engine
179 *
180 * @var object
181 * @since 11.1
182 */
183 public $_engine = null;
184
185 /**
186 * The document type
187 *
188 * @var string
189 * @since 11.1
190 */
191 public $_type = null;
192
193 /**
194 * Array of buffered output
195 *
196 * @var mixed (depends on the renderer)
197 * @since 11.1
198 */
199 public static $_buffer = null;
200
201 /**
202 * JDocument instances container.
203 *
204 * @var array
205 * @since 11.3
206 */
207 protected static $instances = array();
208
209 /**
210 * Media version added to assets
211 *
212 * @var string
213 * @since 3.2
214 */
215 protected $mediaVersion = null;
216
217 /**
218 * Class constructor.
219 *
220 * @param array $options Associative array of options
221 *
222 * @since 11.1
223 */
224 public function __construct($options = array())
225 {
226 if (array_key_exists('lineend', $options))
227 {
228 $this->setLineEnd($options['lineend']);
229 }
230
231 if (array_key_exists('charset', $options))
232 {
233 $this->setCharset($options['charset']);
234 }
235
236 if (array_key_exists('language', $options))
237 {
238 $this->setLanguage($options['language']);
239 }
240
241 if (array_key_exists('direction', $options))
242 {
243 $this->setDirection($options['direction']);
244 }
245
246 if (array_key_exists('tab', $options))
247 {
248 $this->setTab($options['tab']);
249 }
250
251 if (array_key_exists('link', $options))
252 {
253 $this->setLink($options['link']);
254 }
255
256 if (array_key_exists('base', $options))
257 {
258 $this->setBase($options['base']);
259 }
260
261 if (array_key_exists('mediaversion', $options))
262 {
263 $this->setMediaVersion($options['mediaversion']);
264 }
265 }
266
267 /**
268 * Returns the global JDocument object, only creating it
269 * if it doesn't already exist.
270 *
271 * @param string $type The document type to instantiate
272 * @param array $attributes Array of attributes
273 *
274 * @return object The document object.
275 *
276 * @since 11.1
277 */
278 public static function getInstance($type = 'html', $attributes = array())
279 {
280 $signature = serialize(array($type, $attributes));
281
282 if (empty(self::$instances[$signature]))
283 {
284 $type = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
285 $ntype = null;
286
287 // Determine the path and class
288 $class = 'JDocument' . ucfirst($type);
289
290 if (!class_exists($class))
291 {
292 // @deprecated 4.0 - JDocument objects should be autoloaded instead
293 $path = __DIR__ . '/' . $type . '/' . $type . '.php';
294
295 JLoader::register($class, $path);
296
297 if (class_exists($class))
298 {
299 JLog::add('Non-autoloadable JDocument subclasses are deprecated, support will be removed in 4.0.', JLog::WARNING, 'deprecated');
300 }
301 // Default to the raw format
302 else
303 {
304 $ntype = $type;
305 $class = 'JDocumentRaw';
306 }
307 }
308
309 $instance = new $class($attributes);
310 self::$instances[$signature] = $instance;
311
312 if (!is_null($ntype))
313 {
314 // Set the type to the Document type originally requested
315 $instance->setType($ntype);
316 }
317 }
318
319 return self::$instances[$signature];
320 }
321
322 /**
323 * Set the document type
324 *
325 * @param string $type Type document is to set to
326 *
327 * @return JDocument instance of $this to allow chaining
328 *
329 * @since 11.1
330 */
331 public function setType($type)
332 {
333 $this->_type = $type;
334
335 return $this;
336 }
337
338 /**
339 * Returns the document type
340 *
341 * @return string
342 *
343 * @since 11.1
344 */
345 public function getType()
346 {
347 return $this->_type;
348 }
349
350 /**
351 * Get the contents of the document buffer
352 *
353 * @return mixed
354 *
355 * @since 11.1
356 */
357 public function getBuffer()
358 {
359 return self::$_buffer;
360 }
361
362 /**
363 * Set the contents of the document buffer
364 *
365 * @param string $content The content to be set in the buffer.
366 * @param array $options Array of optional elements.
367 *
368 * @return JDocument instance of $this to allow chaining
369 *
370 * @since 11.1
371 */
372 public function setBuffer($content, $options = array())
373 {
374 self::$_buffer = $content;
375
376 return $this;
377 }
378
379 /**
380 * Gets a meta tag.
381 *
382 * @param string $name Name of the meta HTML tag
383 * @param string $attribute Attribute to use in the meta HTML tag
384 *
385 * @return string
386 *
387 * @since 11.1
388 */
389 public function getMetaData($name, $attribute = 'name')
390 {
391 // B/C old http_equiv parameter.
392 if (!is_string($attribute))
393 {
394 $attribute = $attribute == true ? 'http-equiv' : 'name';
395 }
396
397 if ($name == 'generator')
398 {
399 $result = $this->getGenerator();
400 }
401 elseif ($name == 'description')
402 {
403 $result = $this->getDescription();
404 }
405 else
406 {
407 $result = isset($this->_metaTags[$attribute]) && isset($this->_metaTags[$attribute][$name]) ? $this->_metaTags[$attribute][$name] : '';
408 }
409
410 return $result;
411 }
412
413 /**
414 * Sets or alters a meta tag.
415 *
416 * @param string $name Name of the meta HTML tag
417 * @param string $content Value of the meta HTML tag
418 * @param string $attribute Attribute to use in the meta HTML tag
419 *
420 * @return JDocument instance of $this to allow chaining
421 *
422 * @since 11.1
423 */
424 public function setMetaData($name, $content, $attribute = 'name')
425 {
426 // B/C old http_equiv parameter.
427 if (!is_string($attribute))
428 {
429 $attribute = $attribute == true ? 'http-equiv' : 'name';
430 }
431
432 if ($name == 'generator')
433 {
434 $this->setGenerator($content);
435 }
436 elseif ($name == 'description')
437 {
438 $this->setDescription($content);
439 }
440 else
441 {
442 $this->_metaTags[$attribute][$name] = $content;
443 }
444
445 return $this;
446 }
447
448 /**
449 * Adds a linked script to the page
450 *
451 * @param string $url URL to the linked script.
452 * @param array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
453 * @param array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)
454 *
455 * @return JDocument instance of $this to allow chaining
456 *
457 * @since 11.1
458 * @deprecated 4.0 The (url, mime, defer, async) method signature is deprecated, use (url, options, attributes) instead.
459 */
460 public function addScript($url, $options = array(), $attribs = array())
461 {
462 // B/C before 3.7.0
463 if (!is_array($options) && (!is_array($attribs) || $attribs === array()))
464 {
465 JLog::add('The addScript method signature used has changed, use (url, options, attributes) instead.', JLog::WARNING, 'deprecated');
466
467 $argList = func_get_args();
468 $options = array();
469 $attribs = array();
470
471 // Old mime type parameter.
472 if (!empty($argList[1]))
473 {
474 $attribs['mime'] = $argList[1];
475 }
476
477 // Old defer parameter.
478 if (isset($argList[2]) && $argList[2])
479 {
480 $attribs['defer'] = true;
481 }
482
483 // Old async parameter.
484 if (isset($argList[3]) && $argList[3])
485 {
486 $attribs['async'] = true;
487 }
488 }
489
490 // Default value for type.
491 if (!isset($attribs['type']) && !isset($attribs['mime']))
492 {
493 $attribs['type'] = 'text/javascript';
494 }
495
496 $this->_scripts[$url] = isset($this->_scripts[$url]) ? array_replace($this->_scripts[$url], $attribs) : $attribs;
497 $this->_scripts[$url]['options'] = isset($this->_scripts[$url]['options']) ? array_replace($this->_scripts[$url]['options'], $options) : $options;
498
499 return $this;
500 }
501
502 /**
503 * Adds a linked script to the page with a version to allow to flush it. Ex: myscript.js?54771616b5bceae9df03c6173babf11d
504 * If not specified Joomla! automatically handles versioning
505 *
506 * @param string $url URL to the linked script.
507 * @param array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
508 * @param array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)
509 *
510 * @return JDocument instance of $this to allow chaining
511 *
512 * @since 3.2
513 * @deprecated 4.0 This method is deprecated, use addScript(url, options, attributes) instead.
514 */
515 public function addScriptVersion($url, $options = array(), $attribs = array())
516 {
517 JLog::add('The method is deprecated, use addScript(url, attributes, options) instead.', JLog::WARNING, 'deprecated');
518
519 // B/C before 3.7.0
520 if (!is_array($options) && (!is_array($attribs) || $attribs === array()))
521 {
522 $argList = func_get_args();
523 $options = array();
524 $attribs = array();
525
526 // Old version parameter.
527 $options['version'] = isset($argList[1]) && !is_null($argList[1]) ? $argList[1] : 'auto';
528
529 // Old mime type parameter.
530 if (!empty($argList[2]))
531 {
532 $attribs['mime'] = $argList[2];
533 }
534
535 // Old defer parameter.
536 if (isset($argList[3]) && $argList[3])
537 {
538 $attribs['defer'] = true;
539 }
540
541 // Old async parameter.
542 if (isset($argList[4]) && $argList[4])
543 {
544 $attribs['async'] = true;
545 }
546 }
547 // Default value for version.
548 else
549 {
550 $options['version'] = 'auto';
551 }
552
553 return $this->addScript($url, $options, $attribs);
554 }
555
556 /**
557 * Adds a script to the page
558 *
559 * @param string $content Script
560 * @param string $type Scripting mime (defaults to 'text/javascript')
561 *
562 * @return JDocument instance of $this to allow chaining
563 *
564 * @since 11.1
565 */
566 public function addScriptDeclaration($content, $type = 'text/javascript')
567 {
568 if (!isset($this->_script[strtolower($type)]))
569 {
570 $this->_script[strtolower($type)] = $content;
571 }
572 else
573 {
574 $this->_script[strtolower($type)] .= chr(13) . $content;
575 }
576
577 return $this;
578 }
579
580 /**
581 * Add option for script
582 *
583 * @param string $key Name in Storage
584 * @param mixed $options Scrip options as array or string
585 * @param bool $merge Whether merge with existing (true) or replace (false)
586 *
587 * @return JDocument instance of $this to allow chaining
588 *
589 * @since 3.5
590 */
591 public function addScriptOptions($key, $options, $merge = true)
592 {
593 if (empty($this->scriptOptions[$key]))
594 {
595 $this->scriptOptions[$key] = array();
596 }
597
598 if ($merge && is_array($options))
599 {
600 $this->scriptOptions[$key] = array_merge($this->scriptOptions[$key], $options);
601 }
602 else
603 {
604 $this->scriptOptions[$key] = $options;
605 }
606
607 return $this;
608 }
609
610 /**
611 * Get script(s) options
612 *
613 * @param string $key Name in Storage
614 *
615 * @return array Options for given $key, or all script options
616 *
617 * @since 3.5
618 */
619 public function getScriptOptions($key = null)
620 {
621 if ($key)
622 {
623 return (empty($this->scriptOptions[$key])) ? array() : $this->scriptOptions[$key];
624 }
625 else
626 {
627 return $this->scriptOptions;
628 }
629 }
630
631 /**
632 * Adds a linked stylesheet to the page
633 *
634 * @param string $url URL to the linked style sheet
635 * @param array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
636 * @param array $attribs Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1)
637 *
638 * @return JDocument instance of $this to allow chaining
639 *
640 * @since 11.1
641 * @deprecated 4.0 The (url, mime, media, attribs) method signature is deprecated, use (url, options, attributes) instead.
642 */
643 public function addStyleSheet($url, $options = array(), $attribs = array())
644 {
645 // B/C before 3.7.0
646 if (is_string($options))
647 {
648 JLog::add('The addStyleSheet method signature used has changed, use (url, options, attributes) instead.', JLog::WARNING, 'deprecated');
649
650 $argList = func_get_args();
651 $options = array();
652 $attribs = array();
653
654 // Old mime type parameter.
655 if (!empty($argList[1]))
656 {
657 $attribs['type'] = $argList[1];
658 }
659
660 // Old media parameter.
661 if (isset($argList[2]) && $argList[2])
662 {
663 $attribs['media'] = $argList[2];
664 }
665
666 // Old attribs parameter.
667 if (isset($argList[3]) && $argList[3])
668 {
669 $attribs = array_replace($attribs, $argList[3]);
670 }
671 }
672
673 // Default value for type.
674 if (!isset($attribs['type']) && !isset($attribs['mime']))
675 {
676 $attribs['type'] = 'text/css';
677 }
678
679 $this->_styleSheets[$url] = isset($this->_styleSheets[$url]) ? array_replace($this->_styleSheets[$url], $attribs) : $attribs;
680
681 if (isset($this->_styleSheets[$url]['options']))
682 {
683 $this->_styleSheets[$url]['options'] = array_replace($this->_styleSheets[$url]['options'], $options);
684 }
685 else
686 {
687 $this->_styleSheets[$url]['options'] = $options;
688 }
689
690 return $this;
691 }
692
693 /**
694 * Adds a linked stylesheet version to the page. Ex: template.css?54771616b5bceae9df03c6173babf11d
695 * If not specified Joomla! automatically handles versioning
696 *
697 * @param string $url URL to the linked style sheet
698 * @param array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9')
699 * @param array $attribs Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1)
700 *
701 * @return JDocument instance of $this to allow chaining
702 *
703 * @since 3.2
704 * @deprecated 4.0 This method is deprecated, use addStyleSheet(url, options, attributes) instead.
705 */
706 public function addStyleSheetVersion($url, $options = array(), $attribs = array())
707 {
708 JLog::add('The method is deprecated, use addStyleSheet(url, attributes, options) instead.', JLog::WARNING, 'deprecated');
709
710 // B/C before 3.7.0
711 if (!is_array($options) && (!is_array($attribs) || $attribs === array()))
712 {
713 $argList = func_get_args();
714 $options = array();
715 $attribs = array();
716
717 // Old version parameter.
718 $options['version'] = isset($argList[1]) && !is_null($argList[1]) ? $argList[1] : 'auto';
719
720 // Old mime type parameter.
721 if (!empty($argList[2]))
722 {
723 $attribs['mime'] = $argList[2];
724 }
725
726 // Old media parameter.
727 if (isset($argList[3]) && $argList[3])
728 {
729 $attribs['media'] = $argList[3];
730 }
731
732 // Old attribs parameter.
733 if (isset($argList[4]) && $argList[4])
734 {
735 $attribs = array_replace($attribs, $argList[4]);
736 }
737 }
738 // Default value for version.
739 else
740 {
741 $options['version'] = 'auto';
742 }
743
744 return $this->addStyleSheet($url, $options, $attribs);
745 }
746
747 /**
748 * Adds a stylesheet declaration to the page
749 *
750 * @param string $content Style declarations
751 * @param string $type Type of stylesheet (defaults to 'text/css')
752 *
753 * @return JDocument instance of $this to allow chaining
754 *
755 * @since 11.1
756 */
757 public function addStyleDeclaration($content, $type = 'text/css')
758 {
759 if (!isset($this->_style[strtolower($type)]))
760 {
761 $this->_style[strtolower($type)] = $content;
762 }
763 else
764 {
765 $this->_style[strtolower($type)] .= chr(13) . $content;
766 }
767
768 return $this;
769 }
770
771 /**
772 * Sets the document charset
773 *
774 * @param string $type Charset encoding string
775 *
776 * @return JDocument instance of $this to allow chaining
777 *
778 * @since 11.1
779 */
780 public function setCharset($type = 'utf-8')
781 {
782 $this->_charset = $type;
783
784 return $this;
785 }
786
787 /**
788 * Returns the document charset encoding.
789 *
790 * @return string
791 *
792 * @since 11.1
793 */
794 public function getCharset()
795 {
796 return $this->_charset;
797 }
798
799 /**
800 * Sets the global document language declaration. Default is English (en-gb).
801 *
802 * @param string $lang The language to be set
803 *
804 * @return JDocument instance of $this to allow chaining
805 *
806 * @since 11.1
807 */
808 public function setLanguage($lang = 'en-gb')
809 {
810 $this->language = strtolower($lang);
811
812 return $this;
813 }
814
815 /**
816 * Returns the document language.
817 *
818 * @return string
819 *
820 * @since 11.1
821 */
822 public function getLanguage()
823 {
824 return $this->language;
825 }
826
827 /**
828 * Sets the global document direction declaration. Default is left-to-right (ltr).
829 *
830 * @param string $dir The language direction to be set
831 *
832 * @return JDocument instance of $this to allow chaining
833 *
834 * @since 11.1
835 */
836 public function setDirection($dir = 'ltr')
837 {
838 $this->direction = strtolower($dir);
839
840 return $this;
841 }
842
843 /**
844 * Returns the document direction declaration.
845 *
846 * @return string
847 *
848 * @since 11.1
849 */
850 public function getDirection()
851 {
852 return $this->direction;
853 }
854
855 /**
856 * Sets the title of the document
857 *
858 * @param string $title The title to be set
859 *
860 * @return JDocument instance of $this to allow chaining
861 *
862 * @since 11.1
863 */
864 public function setTitle($title)
865 {
866 $this->title = $title;
867
868 return $this;
869 }
870
871 /**
872 * Return the title of the document.
873 *
874 * @return string
875 *
876 * @since 11.1
877 */
878 public function getTitle()
879 {
880 return $this->title;
881 }
882
883 /**
884 * Set the assets version
885 *
886 * @param string $mediaVersion Media version to use
887 *
888 * @return JDocument instance of $this to allow chaining
889 *
890 * @since 3.2
891 */
892 public function setMediaVersion($mediaVersion)
893 {
894 $this->mediaVersion = strtolower($mediaVersion);
895
896 return $this;
897 }
898
899 /**
900 * Return the media version
901 *
902 * @return string
903 *
904 * @since 3.2
905 */
906 public function getMediaVersion()
907 {
908 return $this->mediaVersion;
909 }
910
911 /**
912 * Sets the base URI of the document
913 *
914 * @param string $base The base URI to be set
915 *
916 * @return JDocument instance of $this to allow chaining
917 *
918 * @since 11.1
919 */
920 public function setBase($base)
921 {
922 $this->base = $base;
923
924 return $this;
925 }
926
927 /**
928 * Return the base URI of the document.
929 *
930 * @return string
931 *
932 * @since 11.1
933 */
934 public function getBase()
935 {
936 return $this->base;
937 }
938
939 /**
940 * Sets the description of the document
941 *
942 * @param string $description The description to set
943 *
944 * @return JDocument instance of $this to allow chaining
945 *
946 * @since 11.1
947 */
948 public function setDescription($description)
949 {
950 $this->description = $description;
951
952 return $this;
953 }
954
955 /**
956 * Return the title of the page.
957 *
958 * @return string
959 *
960 * @since 11.1
961 */
962 public function getDescription()
963 {
964 return $this->description;
965 }
966
967 /**
968 * Sets the document link
969 *
970 * @param string $url A url
971 *
972 * @return JDocument instance of $this to allow chaining
973 *
974 * @since 11.1
975 */
976 public function setLink($url)
977 {
978 $this->link = $url;
979
980 return $this;
981 }
982
983 /**
984 * Returns the document base url
985 *
986 * @return string
987 *
988 * @since 11.1
989 */
990 public function getLink()
991 {
992 return $this->link;
993 }
994
995 /**
996 * Sets the document generator
997 *
998 * @param string $generator The generator to be set
999 *
1000 * @return JDocument instance of $this to allow chaining
1001 *
1002 * @since 11.1
1003 */
1004 public function setGenerator($generator)
1005 {
1006 $this->_generator = $generator;
1007
1008 return $this;
1009 }
1010
1011 /**
1012 * Returns the document generator
1013 *
1014 * @return string
1015 *
1016 * @since 11.1
1017 */
1018 public function getGenerator()
1019 {
1020 return $this->_generator;
1021 }
1022
1023 /**
1024 * Sets the document modified date
1025 *
1026 * @param string $date The date to be set
1027 *
1028 * @return JDocument instance of $this to allow chaining
1029 *
1030 * @since 11.1
1031 */
1032 public function setModifiedDate($date)
1033 {
1034 $this->_mdate = $date;
1035
1036 return $this;
1037 }
1038
1039 /**
1040 * Returns the document modified date
1041 *
1042 * @return string
1043 *
1044 * @since 11.1
1045 */
1046 public function getModifiedDate()
1047 {
1048 return $this->_mdate;
1049 }
1050
1051 /**
1052 * Sets the document MIME encoding that is sent to the browser.
1053 *
1054 * This usually will be text/html because most browsers cannot yet
1055 * accept the proper mime settings for XHTML: application/xhtml+xml
1056 * and to a lesser extent application/xml and text/xml. See the W3C note
1057 * ({@link http://www.w3.org/TR/xhtml-media-types/
1058 * http://www.w3.org/TR/xhtml-media-types/}) for more details.
1059 *
1060 * @param string $type The document type to be sent
1061 * @param boolean $sync Should the type be synced with HTML?
1062 *
1063 * @return JDocument instance of $this to allow chaining
1064 *
1065 * @since 11.1
1066 *
1067 * @link http://www.w3.org/TR/xhtml-media-types
1068 */
1069 public function setMimeEncoding($type = 'text/html', $sync = true)
1070 {
1071 $this->_mime = strtolower($type);
1072
1073 // Syncing with metadata
1074 if ($sync)
1075 {
1076 $this->setMetaData('content-type', $type . '; charset=' . $this->_charset, true);
1077 }
1078
1079 return $this;
1080 }
1081
1082 /**
1083 * Return the document MIME encoding that is sent to the browser.
1084 *
1085 * @return string
1086 *
1087 * @since 11.1
1088 */
1089 public function getMimeEncoding()
1090 {
1091 return $this->_mime;
1092 }
1093
1094 /**
1095 * Sets the line end style to Windows, Mac, Unix or a custom string.
1096 *
1097 * @param string $style "win", "mac", "unix" or custom string.
1098 *
1099 * @return JDocument instance of $this to allow chaining
1100 *
1101 * @since 11.1
1102 */
1103 public function setLineEnd($style)
1104 {
1105 switch ($style)
1106 {
1107 case 'win':
1108 $this->_lineEnd = "\15\12";
1109 break;
1110 case 'unix':
1111 $this->_lineEnd = "\12";
1112 break;
1113 case 'mac':
1114 $this->_lineEnd = "\15";
1115 break;
1116 default:
1117 $this->_lineEnd = $style;
1118 }
1119
1120 return $this;
1121 }
1122
1123 /**
1124 * Returns the lineEnd
1125 *
1126 * @return string
1127 *
1128 * @since 11.1
1129 */
1130 public function _getLineEnd()
1131 {
1132 return $this->_lineEnd;
1133 }
1134
1135 /**
1136 * Sets the string used to indent HTML
1137 *
1138 * @param string $string String used to indent ("\11", "\t", ' ', etc.).
1139 *
1140 * @return JDocument instance of $this to allow chaining
1141 *
1142 * @since 11.1
1143 */
1144 public function setTab($string)
1145 {
1146 $this->_tab = $string;
1147
1148 return $this;
1149 }
1150
1151 /**
1152 * Returns a string containing the unit for indenting HTML
1153 *
1154 * @return string
1155 *
1156 * @since 11.1
1157 */
1158 public function _getTab()
1159 {
1160 return $this->_tab;
1161 }
1162
1163 /**
1164 * Load a renderer
1165 *
1166 * @param string $type The renderer type
1167 *
1168 * @return JDocumentRenderer
1169 *
1170 * @since 11.1
1171 * @throws RuntimeException
1172 */
1173 public function loadRenderer($type)
1174 {
1175 // New class name format adds the format type to the class name
1176 $class = 'JDocumentRenderer' . ucfirst($this->getType()) . ucfirst($type);
1177
1178 if (!class_exists($class))
1179 {
1180 // "Legacy" class name structure
1181 $class = 'JDocumentRenderer' . $type;
1182
1183 if (!class_exists($class))
1184 {
1185 // @deprecated 4.0 - Non-autoloadable class support is deprecated, only log a message though if a file is found
1186 $path = __DIR__ . '/' . $this->getType() . '/renderer/' . $type . '.php';
1187
1188 if (!file_exists($path))
1189 {
1190 throw new RuntimeException('Unable to load renderer class', 500);
1191 }
1192
1193 JLoader::register($class, $path);
1194
1195 JLog::add('Non-autoloadable JDocumentRenderer subclasses are deprecated, support will be removed in 4.0.', JLog::WARNING, 'deprecated');
1196
1197 // If the class still doesn't exist after including the path, we've got issues
1198 if (!class_exists($class))
1199 {
1200 throw new RuntimeException('Unable to load renderer class', 500);
1201 }
1202 }
1203 }
1204
1205 return new $class($this);
1206 }
1207
1208 /**
1209 * Parses the document and prepares the buffers
1210 *
1211 * @param array $params The array of parameters
1212 *
1213 * @return JDocument instance of $this to allow chaining
1214 *
1215 * @since 11.1
1216 */
1217 public function parse($params = array())
1218 {
1219 return $this;
1220 }
1221
1222 /**
1223 * Outputs the document
1224 *
1225 * @param boolean $cache If true, cache the output
1226 * @param array $params Associative array of attributes
1227 *
1228 * @return The rendered data
1229 *
1230 * @since 11.1
1231 */
1232 public function render($cache = false, $params = array())
1233 {
1234 $app = JFactory::getApplication();
1235
1236 if ($mdate = $this->getModifiedDate())
1237 {
1238 $app->modifiedDate = $mdate;
1239 }
1240
1241 $app->mimeType = $this->_mime;
1242 $app->charSet = $this->_charset;
1243 }
1244 }
1245