1: <?php
2: /**
3: * Document for class GeoHtml
4: *
5: * PHP Version 5.6
6: *
7: * @category Class
8: * @package Geolib
9: * @author Peter Pitchford <peter@geotonics.com>
10: * @license GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
11: * @link http://geotonics.com/#geolib
12: */
13:
14: /**
15: * Geo - Class to create html html tags
16: *
17: * @category Html_Tag
18: * @package Geolib
19: * @author Peter Pitchford <peter@geotonics.com>
20: * @license GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
21: * @version Release: .1
22: * @link http://geotonics.com/#geolib
23: * @since Class available since Release .1
24: */
25: class GeoHtml extends GeoTag
26: {
27: private $sessionName;
28: private $state;
29:
30: /**
31: * Constructor for GeoHtml Class
32: *
33: * @param string|object $body Html body tag or GeoBody object
34: * @param string|object $head A GeoHead object, usually from geoHead().
35: * A string for the title can be used
36: * if no other head attributes are required.
37: * @param string $userSessionName Name of user session.
38: * @param string $doctype Document type
39: * @param bool $start If true, tag is the intial tag and the content. Leave out end tag.
40: */
41: public function __construct($body = null, $head = null, $userSessionName = null, $doctype = null, $start = null)
42: {
43: if (isset($head)) {
44: if (!is_object($head)) {
45: $head = geoHead($head);
46: }
47:
48: } else {
49: $head = geoHead('');
50: }
51:
52: if (!is_object($body)) {
53: $body = geoBody($body);
54: }
55: $this->userSessionName=$userSessionName;
56:
57: $this->start = $start;
58:
59: $body->text .= $head->scripts();
60: header("Content-Type: text/html; charset=utf-8'");
61: $this->setDoctypeTag($doctype);
62: parent::__construct("html", $head->tag() . $body->tag(null, $start));
63: }
64:
65: /**
66: * Set the Doctype, set a flag if Doctype is XHTML
67: *
68: * @param string $doctype String representing the doctype to be used
69: *
70: * @return void
71: */
72: public static function setDoctype($doctype = null)
73: {
74: if (!$doctype) {
75: $doctype="HTML 5";
76: }
77:
78: define("GEO_DOCTYPE", $doctype);
79: define("GEO_IS_XHTML", geoIf($doctype == "XHTML 1.0 Strict", true, false));
80: }
81:
82: /**
83: * Create the doctype tag based on the DOCTYPE set by setDocType()
84: * @return void
85: */
86: private function setDoctypeTag()
87: {
88: switch (GEO_DOCTYPE) {
89: case "XHTML 1.0 Strict":
90: $this->doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'."\n".
91: '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
92: $this->setatt('xmlns', "http://www.w3.org/1999/xhtml");
93: $this->setatt('xml:lang', "en");
94: $this->setatt('lang', "en");
95: break;
96: case "HTML 4.01 Transitional":
97: $this->doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n".
98: '"http://www.w3.org/TR/html4/loose.dtd">';
99: break;
100: case "HTML 4.01 Frameset":
101: $this->doctype .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
102: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
103: break;
104: case "HTML 4.01 strict":
105: $this->doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"' . "\n".
106: '"http://www.w3.org/TR/html4/strict.dtd">';
107: break;
108: case "HTML 5":
109: default:
110: $this->doctype = '<!DOCTYPE html>';
111: break;
112: }
113:
114: }
115:
116: /**
117: * Creates HTML page
118: *
119: * @param bool $tidyTag Turn tidy on, so that source code is printed with pretty indentation.
120: *
121: * @return Doctype and HTML tags
122: */
123: public function tag($tidyTag = null)
124: {
125: if (GeoDebug::isOn()) {
126: $this->text = str_replace(
127: "</body>",
128: GeoDebug::vars(null, null, null, null, $this->userSessionName)."</body>",
129: $this->text
130: );
131:
132: if (!$tidyTag && $tidyTag !== false) {
133: $this->text = "\n".Geo::tidy($this->text)."\n";
134: }
135:
136: } elseif ($tidyTag) {
137: $this->text = Geo::tidy($this->text);
138: } else {
139: $this->text = str_replace(
140: array("\n", "\r"),
141: " ",
142: $this->text
143: );
144: }
145:
146: GeoDebug::reset();
147: return $this->doctype . "\n" . parent::baseTag($this->start);
148: }
149: }
150: