|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: TDMCreateHtmlCode.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class TDMCreateHtmlCode. |
|
27
|
|
|
*/ |
|
28
|
|
|
class TDMCreateHtmlCode |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @static function getInstance |
|
32
|
|
|
* |
|
33
|
|
|
* @param null |
|
34
|
|
|
* |
|
35
|
|
|
* @return TDMCreateHtmlCode |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function getInstance() |
|
38
|
|
|
{ |
|
39
|
|
|
static $instance = false; |
|
40
|
|
|
if (!$instance) { |
|
41
|
|
|
$instance = new self(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $instance; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @public function getHtmlTag |
|
49
|
|
|
* @param string $tag |
|
50
|
|
|
* @param array $attributes |
|
51
|
|
|
* @param string $content |
|
52
|
|
|
* @param bool $noClosed |
|
53
|
|
|
* @param bool $noBreak |
|
54
|
|
|
* @param string $t |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getHtmlTag($tag = '', $attributes = [], $content = '', $noClosed = false, $noBreak = false, $t = '') |
|
58
|
|
|
{ |
|
59
|
|
|
if (empty($attributes)) { |
|
60
|
|
|
$attributes = []; |
|
61
|
|
|
} |
|
62
|
|
|
$attr = $this->getAttributes($attributes); |
|
63
|
|
|
if ('br' === $tag) { |
|
64
|
|
|
$ret = "{$t}<{$tag}{$attr}>\n"; |
|
65
|
|
|
} elseif ($noClosed) { |
|
66
|
|
|
$ret = "{$t}<{$tag}{$attr} />\n"; |
|
67
|
|
|
} elseif ($noBreak) { |
|
68
|
|
|
$ret = "{$t}<{$tag}{$attr}>{$content}</{$tag}>\n"; |
|
69
|
|
|
} else { |
|
70
|
|
|
$ret = "{$t}<{$tag}{$attr}>\n"; |
|
71
|
|
|
$ret .= "{$t}{$content}"; |
|
72
|
|
|
$ret .= "{$t}</{$tag}>\n"; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $ret; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @private function setAttributes |
|
80
|
|
|
* @param array $attributes |
|
81
|
|
|
* |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
private function getAttributes($attributes) |
|
85
|
|
|
{ |
|
86
|
|
|
$str = ''; |
|
87
|
|
|
foreach ($attributes as $name => $value) { |
|
88
|
|
|
if ('_' !== $name) { |
|
89
|
|
|
$str .= ' '.$name.'="'.$value.'"'; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $str; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @public function getHtmlEmpty |
|
98
|
|
|
* @param string $empty |
|
99
|
|
|
* |
|
100
|
|
|
* @return string |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getHtmlEmpty($empty = '') |
|
103
|
|
|
{ |
|
104
|
|
|
return "{$empty}"; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @public function getHtmlComment |
|
109
|
|
|
* @param string $htmlComment |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getHtmlComment($htmlComment = '') |
|
113
|
|
|
{ |
|
114
|
|
|
return "<!-- {$htmlComment} -->"; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @public function getHtmlBr |
|
119
|
|
|
* @param int $brNumb |
|
120
|
|
|
* @param string $htmlClass |
|
121
|
|
|
* @param string $t |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getHtmlBr($brNumb = 1, $htmlClass = '', $t = '') |
|
125
|
|
|
{ |
|
126
|
|
|
$brClass = ('' != $htmlClass) ? " class='{$htmlClass}'" : ''; |
|
127
|
|
|
$ret = ''; |
|
128
|
|
|
for ($i = 0; $i < $brNumb; ++$i) { |
|
129
|
|
|
$ret .= "{$t}<br{$brClass} />\n"; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return $ret; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @public function getHtmlHNumb |
|
137
|
|
|
* @param string $content |
|
138
|
|
|
* @param string $n |
|
139
|
|
|
* @param string $htmlHClass |
|
140
|
|
|
* @param string $t |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getHtmlHNumb($content = '', $n = '1', $htmlHClass = '', $t = '') |
|
144
|
|
|
{ |
|
145
|
|
|
$hClass = ('' != $htmlHClass) ? " class='{$htmlHClass}'" : ''; |
|
146
|
|
|
$ret = "{$t}<h{$n}{$hClass}>{$content}</h{$n}>\n"; |
|
147
|
|
|
|
|
148
|
|
|
return $ret; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @public function getHtmlDiv |
|
153
|
|
|
* @param string $content |
|
154
|
|
|
* @param string $divClass |
|
155
|
|
|
* @param string $t |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getHtmlDiv($content = '', $divClass = '', $t = '') |
|
159
|
|
|
{ |
|
160
|
|
|
$rDivClass = ('' != $divClass) ? " class='{$divClass}'" : ''; |
|
161
|
|
|
$ret = "{$t}<div{$rDivClass}>\n"; |
|
162
|
|
|
$ret .= "{$t}{$content}"; |
|
163
|
|
|
$ret .= "{$t}</div>\n"; |
|
164
|
|
|
|
|
165
|
|
|
return $ret; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @public function getHtmlPre |
|
170
|
|
|
* @param string $content |
|
171
|
|
|
* @param string $preClass |
|
172
|
|
|
* @param string $t |
|
173
|
|
|
* @return string |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getHtmlPre($content = '', $preClass = '', $t = '') |
|
176
|
|
|
{ |
|
177
|
|
|
$rPreClass = ('' != $preClass) ? " class='{$preClass}'" : ''; |
|
178
|
|
|
$ret = "{$t}<pre{$rPreClass}>\n"; |
|
179
|
|
|
$ret .= "{$t}{$content}"; |
|
180
|
|
|
$ret .= "{$t}</pre>\n"; |
|
181
|
|
|
|
|
182
|
|
|
return $ret; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @public function getHtmlSpan |
|
187
|
|
|
* @param string $content |
|
188
|
|
|
* @param string $spanClass |
|
189
|
|
|
* @param string $t |
|
190
|
|
|
* @return string |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getHtmlSpan($content = '', $spanClass = '', $t = '') |
|
193
|
|
|
{ |
|
194
|
|
|
$rSpanClass = ('' != $spanClass) ? " class='{$spanClass}'" : ''; |
|
195
|
|
|
$ret = "{$t}<span{$rSpanClass}>{$content}</span>\n"; |
|
196
|
|
|
|
|
197
|
|
|
return $ret; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @public function getHtmlParagraph |
|
202
|
|
|
* @param string $content |
|
203
|
|
|
* @param string $pClass |
|
204
|
|
|
* @param string $t |
|
205
|
|
|
* @return string |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getHtmlParagraph($content = '', $pClass = '', $t = '') |
|
208
|
|
|
{ |
|
209
|
|
|
$rPClass = ('' != $pClass) ? " class='{$pClass}'" : ''; |
|
210
|
|
|
$ret = "{$t}<p{$rPClass}>\n"; |
|
211
|
|
|
$ret .= "{$t}{$content}"; |
|
212
|
|
|
$ret .= "{$t}</p>\n"; |
|
213
|
|
|
|
|
214
|
|
|
return $ret; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @public function getHtmlI |
|
219
|
|
|
* @param string $content |
|
220
|
|
|
* @param string $iClass |
|
221
|
|
|
* @param string $t |
|
222
|
|
|
* @return string |
|
223
|
|
|
*/ |
|
224
|
|
|
public function getHtmlI($content = '', $iClass = '', $t = '') |
|
225
|
|
|
{ |
|
226
|
|
|
$rIClass = ('' != $iClass) ? " class='{$iClass}'" : ''; |
|
227
|
|
|
$ret = "{$t}<i{$rIClass}>{$content}</i>"; |
|
228
|
|
|
|
|
229
|
|
|
return $ret; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @public function getHtmlUl |
|
234
|
|
|
* @param string $content |
|
235
|
|
|
* @param string $ulClass |
|
236
|
|
|
* @param string $t |
|
237
|
|
|
* @return string |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getHtmlUl($content = '', $ulClass = '', $t = '') |
|
240
|
|
|
{ |
|
241
|
|
|
$rUlClass = ('' != $ulClass) ? " class='{$ulClass}'" : ''; |
|
242
|
|
|
$ret = "{$t}<ul{$rUlClass}>\n"; |
|
243
|
|
|
$ret .= "{$t}{$content}"; |
|
244
|
|
|
$ret .= "{$t}</ul>\n"; |
|
245
|
|
|
|
|
246
|
|
|
return $ret; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @public function getHtmlOl |
|
251
|
|
|
* @param string $content |
|
252
|
|
|
* @param string $olClass |
|
253
|
|
|
* @param string $t |
|
254
|
|
|
* @return string |
|
255
|
|
|
*/ |
|
256
|
|
|
public function getHtmlOl($content = '', $olClass = '', $t = '') |
|
257
|
|
|
{ |
|
258
|
|
|
$rOlClass = ('' != $olClass) ? " class='{$olClass}'" : ''; |
|
259
|
|
|
$ret = "{$t}<ol{$rOlClass}>\n"; |
|
260
|
|
|
$ret .= "{$t}{$content}"; |
|
261
|
|
|
$ret .= "{$t}</ol>\n"; |
|
262
|
|
|
|
|
263
|
|
|
return $ret; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @public function getHtmlLi |
|
268
|
|
|
* @param string $content |
|
269
|
|
|
* @param string $liClass |
|
270
|
|
|
* @param string $t |
|
271
|
|
|
* @return string |
|
272
|
|
|
*/ |
|
273
|
|
|
public function getHtmlLi($content = '', $liClass = '', $t = '') |
|
274
|
|
|
{ |
|
275
|
|
|
$rLiClass = ('' != $liClass) ? " class='{$liClass}'" : ''; |
|
276
|
|
|
|
|
277
|
|
|
return "{$t}<li{$rLiClass}>{$content}</li>\n"; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @public function getHtmlStrong |
|
282
|
|
|
* @param string $content |
|
283
|
|
|
* @param string $strongClass |
|
284
|
|
|
* @param string $t |
|
285
|
|
|
* @return string |
|
286
|
|
|
*/ |
|
287
|
|
|
public function getHtmlStrong($content = '', $strongClass = '', $t = '') |
|
288
|
|
|
{ |
|
289
|
|
|
$rStrongClass = ('' != $strongClass) ? " class='{$strongClass}'" : ''; |
|
290
|
|
|
|
|
291
|
|
|
return "{$t}<strong{$rStrongClass}>{$content}</strong>\n"; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* @public function getHtmlAnchor |
|
296
|
|
|
* @param string $url |
|
297
|
|
|
* @param string $content |
|
298
|
|
|
* @param string $title |
|
299
|
|
|
* @param string $target |
|
300
|
|
|
* @param string $aClass |
|
301
|
|
|
* @param string $rel |
|
302
|
|
|
* @param string $t |
|
303
|
|
|
* @return string |
|
304
|
|
|
*/ |
|
305
|
|
|
public function getHtmlAnchor($url = '#', $content = ' ', $title = '', $target = '', $aClass = '', $rel = '', $t = '') |
|
306
|
|
|
{ |
|
307
|
|
|
$target = ('' != $target) ? " target='{$target}'" : ''; |
|
308
|
|
|
$rAClass = ('' != $aClass) ? " class='{$aClass}'" : ''; |
|
309
|
|
|
$rel = ('' != $rel) ? " rel='{$rel}'" : ''; |
|
310
|
|
|
|
|
311
|
|
|
return "{$t}<a{$rAClass} href='{$url}' title='{$title}'{$target}{$rel}>{$content}</a>\n"; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @public function getHtmlImage |
|
316
|
|
|
* @param string $src |
|
317
|
|
|
* @param string $alt |
|
318
|
|
|
* @param string $imgClass |
|
319
|
|
|
* @param string $t |
|
320
|
|
|
* @return string |
|
321
|
|
|
*/ |
|
322
|
|
|
public function getHtmlImage($src = 'blank.gif', $alt = 'blank.gif', $imgClass = '', $t = '') |
|
323
|
|
|
{ |
|
324
|
|
|
$rImgClass = ('' != $imgClass) ? " class='{$imgClass}'" : ''; |
|
325
|
|
|
$ret = "{$t}<img{$rImgClass} src='{$src}' alt='{$alt}' />\n"; |
|
326
|
|
|
|
|
327
|
|
|
return $ret; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @public function getHtmlTable |
|
332
|
|
|
* @param string $content |
|
333
|
|
|
* @param string $tableClass |
|
334
|
|
|
* @param string $t |
|
335
|
|
|
* @return string |
|
336
|
|
|
*/ |
|
337
|
|
|
public function getHtmlTable($content = '', $tableClass = '', $t = '') |
|
338
|
|
|
{ |
|
339
|
|
|
$rTableClass = ('' != $tableClass) ? " class='{$tableClass}'" : ''; |
|
340
|
|
|
$ret = "{$t}<table{$rTableClass}>\n"; |
|
341
|
|
|
$ret .= "{$t}{$content}"; |
|
342
|
|
|
$ret .= "{$t}</table>\n"; |
|
343
|
|
|
|
|
344
|
|
|
return $ret; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* @public function getHtmlTableThead |
|
349
|
|
|
* @param string $content |
|
350
|
|
|
* @param string $theadClass |
|
351
|
|
|
* @param string $t |
|
352
|
|
|
* @return string |
|
353
|
|
|
*/ |
|
354
|
|
|
public function getHtmlTableThead($content = '', $theadClass = '', $t = '') |
|
355
|
|
|
{ |
|
356
|
|
|
$rTheadClass = ('' != $theadClass) ? " class='{$theadClass}'" : ''; |
|
357
|
|
|
$ret = "{$t}\t<thead{$rTheadClass}>\n"; |
|
358
|
|
|
$ret .= "{$t}\t{$content}"; |
|
359
|
|
|
$ret .= "{$t}\t</thead>\n"; |
|
360
|
|
|
|
|
361
|
|
|
return $ret; |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
/** |
|
365
|
|
|
* @public function getHtmlTableTbody |
|
366
|
|
|
* @param string $content |
|
367
|
|
|
* @param string $tbodyClass |
|
368
|
|
|
* @param string $t |
|
369
|
|
|
* @return string |
|
370
|
|
|
*/ |
|
371
|
|
|
public function getHtmlTableTbody($content = '', $tbodyClass = '', $t = '') |
|
372
|
|
|
{ |
|
373
|
|
|
$rTbodyClass = ('' != $tbodyClass) ? " class='{$tbodyClass}'" : ''; |
|
374
|
|
|
$ret = "{$t}\t<tbody{$rTbodyClass}>\n"; |
|
375
|
|
|
$ret .= "{$t}\t{$content}"; |
|
376
|
|
|
$ret .= "{$t}\t</tbody>\n"; |
|
377
|
|
|
|
|
378
|
|
|
return $ret; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* @public function getHtmlTableTfoot |
|
383
|
|
|
* @param string $content |
|
384
|
|
|
* @param string $tfootClass |
|
385
|
|
|
* @param string $t |
|
386
|
|
|
* @return string |
|
387
|
|
|
*/ |
|
388
|
|
|
public function getHtmlTableTfoot($content = '', $tfootClass = '', $t = '') |
|
389
|
|
|
{ |
|
390
|
|
|
$rTfootClass = ('' != $tfootClass) ? " class='{$tfootClass}'" : ''; |
|
391
|
|
|
$ret = "{$t}\t<tfoot{$rTfootClass}>\n"; |
|
392
|
|
|
$ret .= "{$t}\t{$content}"; |
|
393
|
|
|
$ret .= "{$t}\t</tfoot>\n"; |
|
394
|
|
|
|
|
395
|
|
|
return $ret; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* @public function getHtmlTableRow |
|
400
|
|
|
* @param string $content |
|
401
|
|
|
* @param string $trClass |
|
402
|
|
|
* @param string $t |
|
403
|
|
|
* @return string |
|
404
|
|
|
*/ |
|
405
|
|
|
public function getHtmlTableRow($content = '', $trClass = '', $t = '') |
|
406
|
|
|
{ |
|
407
|
|
|
$rTrClass = ('' != $trClass) ? " class='{$trClass}'" : ''; |
|
408
|
|
|
$ret = "{$t}\t<tr{$rTrClass}>\n"; |
|
409
|
|
|
$ret .= "{$t}\t{$content}"; |
|
410
|
|
|
$ret .= "{$t}\t</tr>\n"; |
|
411
|
|
|
|
|
412
|
|
|
return $ret; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
/** |
|
416
|
|
|
* @public function getHtmlTableHead |
|
417
|
|
|
* @param string $content |
|
418
|
|
|
* @param string $thClass |
|
419
|
|
|
* @param string $colspan |
|
420
|
|
|
* @param string $t |
|
421
|
|
|
* @return string |
|
422
|
|
|
*/ |
|
423
|
|
|
public function getHtmlTableHead($content = '', $thClass = '', $colspan = '', $t = '') |
|
424
|
|
|
{ |
|
425
|
|
|
$rThClass = ('' != $thClass) ? " class='{$thClass}'" : ''; |
|
426
|
|
|
$colspan = ('' != $colspan) ? " colspan='{$colspan}'" : ''; |
|
427
|
|
|
|
|
428
|
|
|
return "{$t}<th{$colspan}{$rThClass}>{$content}</th>\n"; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* @public function getHtmlTableData |
|
433
|
|
|
* @param string $content |
|
434
|
|
|
* @param string $tdClass |
|
435
|
|
|
* @param string $colspan |
|
436
|
|
|
* @param string $t |
|
437
|
|
|
* @return string |
|
438
|
|
|
*/ |
|
439
|
|
|
public function getHtmlTableData($content = '', $tdClass = '', $colspan = '', $t = '') |
|
440
|
|
|
{ |
|
441
|
|
|
$rTdClass = ('' != $tdClass) ? " class='{$tdClass}'" : ''; |
|
442
|
|
|
$colspan = ('' != $colspan) ? " colspan='{$colspan}'" : ''; |
|
443
|
|
|
|
|
444
|
|
|
return "{$t}<td{$colspan}{$rTdClass}>{$content}</td>\n"; |
|
445
|
|
|
} |
|
446
|
|
|
} |
|
447
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.