1: <?php
2: /**
3: * Document for class GeoTag, a basic html tag object
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 list (ul or ol) 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:
26: class GeoTag
27: {
28: private $tag;
29: public $text;
30: protected $atts;
31: private $addons;
32: private $isinline;
33:
34: /**
35: * Constructor
36: *
37: * @param string $tag HTML tag
38: * @param array||string $text Content of tag(s). Use an array to create multiple instances of the same tag
39: * @param string $class Class
40: * @param string $id Id
41: * @param string $style Style
42: * @param string $atts Any other attribute
43: */
44: public function __construct($tag, $text = null, $class = null, $id = null, $style = null, $atts = null)
45: {
46: $this->init($tag, $text, $class, $id, $style, $atts);
47: }
48:
49: /**
50: * Set tag attribute
51: *
52: * @param string $att Name of attribute
53: * @param string $value Value of attribute
54: *
55: * @return void
56: */
57: public function setAtt($att, $value = null)
58: {
59: // Checking for the value insures that individually set atts do not override
60: // atts which have already been set by $atts
61:
62: if (isset($value)) {
63: $this->atts[$att] = $value;
64: }
65: }
66:
67: /**
68: * Set tag content
69: *
70: * @param string $text conteht value
71: *
72: * @return void
73: */
74: public function setText($text)
75: {
76: if (isset($text)) {
77: $this->text = $text;
78: }
79: }
80:
81: /**
82: * Initialize tag content and attributes Set number of rows to span
83: Also determines whether tag is inline, meaning it has no content or separate end tag.
84: *
85: * @param string $tag HTML tag
86: * @param string $text Tag content
87: * @param string $class Class attribute
88: * @param string $id Id attribute
89: * @param string $style Style attribute
90: * @param string|array $atts Any other attributes
91: *
92: * @return void
93: */
94: protected function init($tag, $text = null, $class = null, $id = null, $style = null, $atts = null)
95: {
96: $inlines = array(
97: 'img',
98: 'link',
99: 'meta',
100: 'input',
101: 'base'
102: );
103: if (in_array($tag, $inlines)) {
104: $this->isinline = true;
105: }
106:
107: if ($atts) {
108: //$atts = Geo::arr($atts);// atts should always be an array, so this is probably not neccesary
109: foreach ($atts as $att => $value) {
110: $this->setAtt($att, $value);
111: }
112: }
113: $this->tag = $tag;
114: $this->setText($text);
115: $this->setAtt("class", $class);
116: $this->setAtt("id", $id);
117: $this->setAtt("style", $style);
118: }
119:
120: /**
121: * Creates tag for output
122: *
123: * @param bool $start Indicates that this tag is only the first part of an inline tag, plus the content.
124: * @param bool $end Indicates that this tag is only an end tag.
125: Start and end indicators can be used when tags are out put directly to web page without being stored in buffer.
126: *
127: * @return void
128: */
129: public function baseTag($start = null, $end = null)
130: {
131:
132: $tags = $attsline = '';
133: if ($end) {
134: return "</" . $this->tag . ">";
135: }
136:
137: $this->text = Geo::arr($this->text);
138:
139: foreach ($this->text as $key => $value) {
140: $attsarr = array();
141: $tags .= "<" . $this->tag;
142: $idline = '';
143:
144: if ($this->atts) {
145: foreach ($this->atts as $key2 => $value2) {
146:
147: if (isset($value2)) {
148: $value3=Geo::ifArr($value2, $key);
149:
150: if(isset($value3)){
151: $attsarr[] = $key2 . '="' . $value3.
152: geoIf($key2 == 'id' && $key && is_numeric($key), "_" . $key) . '"';
153: }
154:
155: }
156:
157: }
158: }
159:
160: if ($attsarr) {
161: $tags .= " ".implode(' ', $attsarr);
162: }
163:
164: if ($this->isinline) {
165: if (defined("GEO_IS_XHTML") && GEO_IS_XHTML) {
166: $tags .= ' /';
167: }
168:
169: $tags .= ">";
170: } else {
171: $tags .= ">" . $value . geoIf(!$start, "</" . $this->tag . ">");
172: }
173:
174: }
175:
176: return $tags;
177: }
178: }
179: