-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathtxplib_html.php
More file actions
1975 lines (1708 loc) · 55.6 KB
/
txplib_html.php
File metadata and controls
1975 lines (1708 loc) · 55.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* Textpattern Content Management System
* https://textpattern.com/
*
* Copyright (C) 2026 The Textpattern Development Team
*
* This file is part of Textpattern.
*
* Textpattern is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* Textpattern is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Textpattern. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Collection of HTML widgets.
*
* @package HTML
*/
/**
* Renders the admin-side footer.
*
* The footer's default markup is provided by a theme. It can be further
* customised via the "admin_side > footer" pluggable UI callback event.
*
* In addition to the pluggable UI, this function also calls callback events
* "admin_side > main_content_end" and "admin_side > body_end".
*/
function end_page()
{
global $event, $app_mode, $theme, $textarray_script;
if ($app_mode != 'async' && $event != 'tag') {
callback_event('admin_side', 'main_content_end');
echo n.'</main><!-- /txp-body -->'.n.'<footer class="txp-footer">';
echo pluggable_ui('admin_side', 'footer', $theme->footer());
callback_event('admin_side', 'body_end');
echo script_js('vendors/PrismJS/prism/prism.js', TEXTPATTERN_SCRIPT_URL, array('article', 'edit')).
script_js('vendors/PrismJS/prism/prism-txp.js', TEXTPATTERN_SCRIPT_URL, array('article', 'edit')).
script_js('textpattern.textarray = '.json_encode($textarray_script, TEXTPATTERN_JSON), true).
n.'</footer><!-- /txp-footer -->'.n.'</body>'.n.'</html>';
}
}
/**
* Renders the user interface for one head cell of columnar data.
*
* @param string $value Element text
* @param string $sort Sort criterion
* @param string $event Event name
* @param bool $is_link Include link to admin action in user interface according to the other params
* @param string $dir Sort direction, either "asc" or "desc"
* @param string $crit Search criterion
* @param string $method Search method
* @param string $class HTML "class" attribute applied to the resulting element
* @param string $step Step name
* @return string HTML
*/
function column_head($value, $sort = '', $event = '', $is_link = '', $dir = '', $crit = '', $method = '', $class = '', $step = 'list')
{
if (is_array($value)) {
extract($value);
}
$options = (isset($options) ? (array) $options : array()) + array(
'class' => $class,
'data-col' => $sort,
);
if (preg_match('/\b(asc|desc)\b/i', $options['class'], $matches)) {
$options += array('aria-sort' => strtolower($matches[1]).'ending');
}
$head_items = array(
'value' => $value,
'sort' => $sort,
'event' => $event,
'step' => $step,
'is_link' => $is_link,
'dir' => $dir,
'crit' => $crit,
'method' => $method,
);
return column_multi_head(array($head_items), $options);
}
/**
* Renders the user interface for multiple head cells of columnar data.
*
* @param array $head_items An array of hashed elements. Valid keys: 'value', 'sort', 'event', 'is_link', 'dir', 'crit', 'method'
* @param string $class HTML "class" attribute applied to the resulting element
* @return string HTML
*/
function column_multi_head($head_items, $class = '')
{
$o = '';
$first_item = true;
foreach ($head_items as $item) {
if (empty($item)) {
continue;
}
extract(lAtts(array(
'value' => '',
'sort' => '',
'event' => '',
'step' => 'list',
'is_link' => '',
'dir' => '',
'crit' => '',
'method' => '',
), $item));
$o .= ($first_item) ? '' : ', ';
$first_item = false;
if ($is_link) {
$o .= href(gTxt($value), array(
'event' => $event,
'step' => $step,
'sort' => $sort,
'dir' => $dir,
'crit' => $crit,
'search_method' => $method,
), array());
} else {
$o .= gTxt($value);
}
}
$extra_atts = is_array($class) ? $class : array('class' => $class);
return hCell($o, '', $extra_atts + array('scope' => 'col'));
}
/**
* Renders a <th> element.
*
* @param string $text Cell text
* @param string $caption Is not used
* @param string|array $atts HTML attributes
* @return string HTML
*/
function hCell($text = '', $caption = '', $atts = '')
{
$text = ('' === $text) ? sp : $text;
return n.tag($text, 'th', $atts);
}
/**
* Renders a link invoking an admin-side action.
*
* @param string $event Event
* @param string $step Step
* @param string $linktext Link text
* @param string $class HTML class attribute for link
* @return string HTML
*/
function sLink($event, $step, $linktext, $class = '')
{
if ($linktext === '') {
$linktext = null;
}
return href($linktext, array(
'event' => $event,
'step' => $step,
), array('class' => $class));
}
/**
* Renders a link with two additional URL parameters.
*
* Renders a link invoking an admin-side action while taking up to two
* additional URL parameters.
*
* @param string $event Event
* @param string $step Step
* @param string $thing URL parameter key #1
* @param string $value URL parameter value #1
* @param string $linktext Link text
* @param string $thing2 URL parameter key #2
* @param string $val2 URL parameter value #2
* @param string $title Anchor title
* @param string $class HTML class attribute
* @return string HTML
*/
function eLink($event, $step, $thing, $value, $linktext, $thing2 = '', $val2 = '', $title = '', $class = '')
{
if ($title) {
$title = gTxt($title);
}
if ($linktext === '') {
$linktext = null;
} else {
$linktext = escape_title($linktext);
}
if (is_array($thing)) {
$atts = $thing + ($thing2 ? array($thing2 => $val2) : array());
} else {
$atts = array(
$thing => $value,
$thing2 => $val2,
'_txp_token' => form_token()
);
}
return href($linktext, array(
'event' => $event,
'step' => $step,
) + $atts, array(
'class' => $class,
'title' => $title,
));
}
/**
* Renders a link with one additional URL parameter.
*
* Renders an link invoking an admin-side action while taking up to one
* additional URL parameter.
*
* @param string $event Event
* @param string $step Step
* @param string $thing URL parameter key
* @param string $value URL parameter value
* @param string $class HTML class attribute
* @return string HTML
*/
function wLink($event, $step = '', $thing = '', $value = '', $class = '')
{
return href(sp.'!'.sp, array(
'event' => $event,
'step' => $step,
$thing => $value,
'_txp_token' => form_token(),
), array('class' => $class));
}
/**
* Renders a delete link.
*
* Renders a link invoking an admin-side "delete" action while taking up to two
* additional URL parameters.
*
* @param string $event Event
* @param string $step Step
* @param string $thing URL parameter key #1
* @param string $value URL parameter value #1
* @param string $verify Show an "Are you sure?" dialogue with this text
* @param string $thing2 URL parameter key #2
* @param string $thing2val URL parameter value #2
* @param bool $get If TRUE, uses GET request
* @param array $remember Convey URL parameters for page state. Member sequence is $page, $sort, $dir, $crit, $search_method
* @return string HTML
*/
function dLink($event, $step, $thing, $value, $verify = '', $thing2 = '', $thing2val = '', $get = '', $remember = null)
{
if ($remember) {
list($page, $sort, $dir, $crit, $search_method) = $remember;
}
if ($get) {
if ($verify) {
$verify = gTxt($verify);
} else {
$verify = gTxt('confirm_delete_popup');
}
if ($remember) {
return href(gTxt('delete'), array(
'event' => $event,
'step' => $step,
$thing => $value,
$thing2 => $thing2val,
'_txp_token' => form_token(),
'page' => $page,
'sort' => $sort,
'dir' => $dir,
'crit' => $crit,
'search_method' => $search_method,
), array(
'class' => 'destroy ui-icon ui-icon-close',
'title' => gTxt('delete'),
'data-verify' => $verify,
));
}
return href(gTxt('delete'), array(
'event' => $event,
'step' => $step,
$thing => $value,
$thing2 => $thing2val,
'_txp_token' => form_token(),
), array(
'class' => 'destroy ui-icon ui-icon-close',
'title' => gTxt('delete'),
'data-verify' => $verify,
));
}
return join('', array(
n.'<form method="post" action="index.php" data-verify="'.gTxt('confirm_delete_popup').'">',
tag(
span(gTxt('delete'), array('class' => 'ui-icon ui-icon-close')),
'button',
array(
'class' => 'destroy',
'type' => 'submit',
'title' => gTxt('delete'),
)
),
eInput($event).
sInput($step),
hInput($thing, $value),
($thing2) ? hInput($thing2, $thing2val) : '',
($remember) ? hInput(compact('page', 'sort', 'dir', 'crit', 'search_method')) : '',
tInput(),
n.'</form>',
));
}
/**
* Renders an add link.
*
* This function can be used for invoking an admin-side "add" action while
* taking up to two additional URL parameters.
*
* @param string $event Event
* @param string $step Step
* @param string $thing URL parameter key #1
* @param string $value URL parameter value #1
* @param string $thing2 URL parameter key #2
* @param string $value2 URL parameter value #2
* @return string HTML
*/
function aLink($event, $step, $thing = '', $value = '', $thing2 = '', $value2 = '')
{
return href('+', array(
'event' => $event,
'step' => $step,
$thing => $value,
$thing2 => $value2,
'_txp_token' => form_token(),
), array('class' => 'alink'));
}
/**
* Renders a link invoking an admin-side "previous/next article" action.
*
* @param string $name Link text
* @param string $event Event
* @param string $step Step
* @param int $id ID of target Textpattern object (article,...)
* @param string $title HTML title attribute
* @param string $rel HTML rel attribute
* @return string HTML
*/
function prevnext_link($name, $event, $step, $id, $title = '', $rel = '')
{
return href($name, array(
'event' => $event,
'step' => $step,
'ID' => $id,
), array(
'class' => 'navlink',
'title' => $title,
'rel' => $rel,
));
}
/**
* Renders a link invoking an admin-side "previous/next page" action.
*
* @param string $event Event
* @param int $page Target page number
* @param string $label Link text
* @param string $type Direction, either "prev" or "next"
* @param string $sort Sort field
* @param string $dir Sort direction, either "asc" or "desc"
* @param string $crit Search criterion
* @param string $search_method Search method
* @param string $step Step
* @return string HTML
*/
function PrevNextLink($event, $page, $label, $type, $sort = '', $dir = '', $crit = '', $search_method = '', $step = 'list')
{
$theClass = ($type === 'next') ? 'ui-icon-arrowthick-1-e' : 'ui-icon-arrowthick-1-w';
return href(
span(
$label,
array('class' => 'ui-icon '.$theClass)
),
array(
'event' => $event,
'step' => $step,
'page' => (int) $page,
'dir' => $dir,
'crit' => $crit,
'search_method' => $search_method,
),
array(
'rel' => $type,
'title' => $label,
)
);
}
/**
* Renders a page navigation form.
*
* @param string $event Event
* @param int $page Current page number
* @param int $numPages Total pages
* @param string $sort Sort criterion
* @param string $dir Sort direction, either "asc" or "desc"
* @param string $crit Search criterion
* @param string $search_method Search method
* @param int $total Total search term hit count [0]
* @param int $limit First visible search term hit number [0]
* @param string $step Step
* @param int $list Number of displayed page links discounting jump links, previous and next
* @return string HTML
*/
function nav_form($event, $page, $numPages, $sort = '', $dir = '', $crit = '', $search_method = '', $total = 0, $limit = 0, $step = 'list', $list = 5)
{
$out = array();
if ($numPages > 1 && $crit !== '') {
$out[] = announce(
gTxt('showing_search_results', array(
'{from}' => (($page - 1) * $limit) + 1,
'{to}' => min($total, $page * $limit),
'{total}' => $total,
)),
TEXTPATTERN_ANNOUNCE_REGULAR
);
}
$nav = array();
$list--;
$page = max(min($page, $numPages), 1);
$parameters = array(
'event' => $event,
'step' => $step,
'dir' => $dir,
'crit' => $crit,
'search_method' => $search_method,
);
// Previous page.
if ($page > 1) {
$nav[] = n.PrevNextLink($event, $page - 1, gTxt('prev'), 'prev', $sort, $dir, $crit, $search_method, $step);
} else {
$nav[] = n.span(
span(gTxt('prev'), array('class' => 'ui-icon ui-icon-arrowthick-1-w')),
array(
'class' => 'disabled',
'aria-disabled' => 'true',
'aria-label' => gTxt('prev'),
)
);
}
$nav[] = form(
n.tag(gTxt('page'), 'label', array('for' => 'current-page')).
n.tag_void('input', array(
'class' => 'current-page',
'id' => 'current-page',
'name' => 'page',
'type' => 'number',
// 'size' => INPUT_XSMALL,
'inputmode' => 'numeric',
// 'pattern' => '[1-9]\d*',
'min' => 1,
'max' => $numPages,
'value' => $page,
)).
n.gTxt('of').
n.span($numPages, array('class' => 'total-pages')).
eInput($event).
hInput(compact('sort', 'dir', 'crit', 'search_method')),
'',
'',
'get'
);
// Next page.
if ($page < $numPages) {
$nav[] = n.PrevNextLink($event, $page + 1, gTxt('next'), 'next', $sort, $dir, $crit, $search_method, $step);
} else {
$nav[] = n.span(
span(gTxt('next'), array('class' => 'ui-icon ui-icon-arrowthick-1-e')),
array(
'class' => 'disabled',
'aria-disabled' => 'true',
'aria-label' => gTxt('next'),
)
);
}
$out[] = n.tag(join($nav).n, 'nav', array(
'class' => ($numPages > 1 ? 'prev-next' : 'prev-next hidden'),
'aria-label' => gTxt('page_nav'),
));
return join('', $out);
}
/**
* Wraps a collapsible region and group structure around content.
*
* @param string $id HTML id attribute for the region wrapper and ARIA label
* @param string $content Content to wrap. If empty, only the outer wrapper will be rendered
* @param string $anchor_id HTML id attribute for the collapsible wrapper
* @param string $label L10n label name
* @param string $pane Pane reference for maintaining toggle state in prefs. Prefixed with 'pane_', suffixed with '_visible'
* @param string $class CSS class name to apply to wrapper
* @param string $help Help text item
* @return string HTML
* @since 4.6.0
*/
function wrapRegion($id, $content = '', $anchor_id = '', $label = '', $pane = '', $class = '', $help = '', $visible = null)
{
global $event;
$label = $label ? gTxt($label) : null;
if ($anchor_id && $pane) {
$heading_class = 'txp-summary'.($visible ? ' expanded' : '');
$display_state = array(
'class' => $visible ? 'toggle' : 'toggle hidden',
'id' => $anchor_id,
'role' => 'group',
);
$label = href($label, '#'.$anchor_id, array(
'role' => 'button',
'data-txp-token' => md5($pane.$event.form_token().get_pref('blog_uid')),
'data-txp-pane' => $pane,
));
$help = '';
} else {
$heading_class = '';
$display_state = array('role' => 'group');
}
if ($content) {
$content = ($label ?
hed($label.popHelp($help), 3, array(
'class' => $heading_class,
'id' => $id.'-label',
)) : '').
n.tag($content.n, 'div', $display_state).n;
}
return n.tag($content, 'section', array(
'class' => trim($label ? 'txp-details '.$class : $class),
'id' => $id,
'aria-labelledby' => $content && $label ? $id.'-label' : false,
));
}
/**
* Wraps a region and group structure around content.
*
* @param string $name HTML id attribute for the group wrapper and ARIA label
* @param string $content Content to wrap
* @param string $label L10n label name
* @param string $class CSS class name to apply to wrapper
* @param string $help Help text item
* @return string HTML
* @see wrapRegion()
* @since 4.6.0
*/
function wrapGroup($id, $content, $label, $class = '', $help = '')
{
return wrapRegion($id, $content, '', $label, '', $class, $help);
}
/**
* Renders start of a layout <table> element.
*
* @param string $id HTML id attribute
* @param string $align HTML align attribute
* @param string $class HTML class attribute
* @param int $p HTML cellpadding attribute
* @param int $w HTML width attribute
* @return string HTML
* @example
* startTable().
* tr(td('column') . td('column')).
* tr(td('column') . td('column')).
* endTable();
*/
function startTable($id = '', $align = '', $class = '', $p = 0, $w = 0)
{
$atts = join_atts(array(
'class' => $class,
'id' => $id,
'cellpadding' => (int) $p,
'width' => (int) $w,
'align' => $align,
), TEXTPATTERN_STRIP_EMPTY);
return n.'<table'.$atts.'>';
}
/**
* Renders closing </table> tag.
*
* @return string HTML
*/
function endTable()
{
return n.'</table>';
}
/**
* Renders <tr> elements from input parameters.
*
* Takes a list of arguments containing each making a row.
*
* @return string HTML
* @example
* stackRows(
* td('cell') . td('cell'),
* td('cell') . td('cell')
* );
*/
function stackRows()
{
foreach (func_get_args() as $a) {
$o[] = tr($a);
}
return join('', $o);
}
/**
* Renders a <td> element.
*
* @param string $content Cell content
* @param int $width HTML width attribute
* @param string $class HTML class attribute
* @param string $id HTML id attribute
* @return string HTML
*/
function td($content = '', $width = null, $class = '', $id = '')
{
$opts = array(
'class' => $class,
'id' => $id,
);
if (is_numeric($width)) {
$opts['width'] = (int) $width;
} elseif (is_array($width)) {
$opts = array_merge($opts, $width);
}
return tda($content, $opts);
}
/**
* Renders a <td> element with attributes.
*
* @param string $content Cell content
* @param string|array $atts Cell attributes
* @return string HTML
*/
function tda($content, $atts = '')
{
$content = ($content === '') ? sp : $content;
return n.tag($content, 'td', $atts);
}
/**
* Renders a <td> element with attributes.
*
* This function is identical to tda().
*
* @param string $content Cell content
* @param string|array $atts Cell attributes
* @return string HTML
* @access private
* @see tda()
*/
function tdtl($content, $atts = '')
{
return tda($content, $atts);
}
/**
* Renders a <tr> element with attributes.
*
* @param string $content Row content
* @param string|array $atts Row attributes
* @return string HTML
*/
function tr($content, $atts = '')
{
return n.tag($content, 'tr', $atts);
}
/**
* Renders a <td> element with top/left text orientation, colspan and
* other attributes.
*
* @param string $content Cell content
* @param int $span Cell colspan attribute
* @param int $width Cell width attribute
* @param string $class Cell class attribute
* @return string HTML
*/
function tdcs($content, $span, $width = null, $class = '')
{
$opts = array(
'class' => $class,
'colspan' => (int) $span,
);
if (is_numeric($width)) {
$opts['width'] = (int) $width;
}
return tda($content, $opts);
}
/**
* Renders a <td> element with a rowspan attribute.
*
* @param string $content Cell content
* @param int $span Cell rowspan attribute
* @param int $width Cell width attribute
* @param string $class Cell class attribute
* @return string HTML
*/
function tdrs($content, $span, $width = null, $class = '')
{
$opts = array(
'class' => $class,
'rowspan' => (int) $span,
);
if (is_numeric($width)) {
$opts['width'] = (int) $width;
}
return tda($content, $opts);
}
/**
* Renders a form label inside a table cell.
*
* @param string $text Label text
* @param string $help Help text
* @param string $label_id HTML "for" attribute, i.e. id of corresponding form element
* @return string HTML
*/
function fLabelCell($text, $help = '', $label_id = '')
{
$cell = gTxt($text).' '.popHelp($help);
if ($label_id) {
$cell = tag($cell, 'label', array('for' => $label_id));
}
return tda($cell, array('class' => 'cell-label'));
}
/**
* Renders a form input inside a table cell.
*
* @param string $name HTML name attribute
* @param string $var Input value
* @param int $tabindex HTML tabindex attribute
* @param int $size HTML size attribute
* @param bool $help TRUE to display help link
* @param string $id HTML id attribute
* @return string HTML
*/
function fInputCell($name, $var = '', $tabindex = 0, $size = 0, $help = false, $id = '')
{
$pop = ($help) ? popHelp($name) : '';
return tda(fInput('text', $name, $var, '', '', '', $size, $tabindex, $id).$pop);
}
/**
* Renders a name-value input control with label.
*
* The rendered input can be customised via the
* '{$event}_ui > inputlabel.{$name}' pluggable UI callback event.
*
* @param string $name Input name
* @param string $input Complete input control widget
* @param string|array $label Label text | array (label text, HTML block to append to label)
* @param string|array $help Help text item | array(help text item, inline help text)
* @param string|array $atts Class name | attribute pairs to assign to container div
* @param string|array $wraptag_val Tag to wrap the value / label in, or empty to omit
* @return string HTML
* @example
* echo inputLabel('active', yesnoRadio('active'), 'Keep active?');
*/
function inputLabel($name, $input, $label = '', $help = array(), $atts = array(), $wraptag_val = array('div', 'div'))
{
global $event;
$arguments = compact('name', 'input', 'label', 'help', 'atts', 'wraptag_val');
$fallback_class = 'txp-form-field edit-'.str_replace('_', '-', $name);
$tools = '';
if ($atts && is_string($atts)) {
$atts = array('class' => $atts);
} elseif (!$atts) {
$atts = array('class' => $fallback_class);
} elseif (is_array($atts) && !array_key_exists('class', $atts)) {
$atts['class'] = $fallback_class;
}
if (!is_array($help)) {
$help = array($help);
}
if (is_array($label)) {
if (isset($label[1])) {
$tools = (string) $label[1];
}
$label = (string) $label[0];
}
if (empty($help)) {
$help = array(
0 => '',
1 => '',
);
}
$inlineHelp = (isset($help[1])) ? $help[1] : '';
if ($label !== '') {
$labelContent = tag(gTxt($label).popHelp($help[0]), 'label', array('for' => $name)).$tools;
} else {
$labelContent = gTxt($name).popHelp($help[0]).$tools;
}
if (!is_array($wraptag_val)) {
$wraptag_val = array($wraptag_val, $wraptag_val);
}
if ($wraptag_val[0]) {
$input = n.tag($input, $wraptag_val[0], array('class' => 'txp-form-field-value'));
}
if (isset($wraptag_val[1]) && $wraptag_val[1]) {
$labeltag = n.tag($labelContent, $wraptag_val[1], array('class' => 'txp-form-field-label'));
} else {
$labeltag = $labelContent;
}
$out = n.tag(
$labeltag.
fieldHelp($inlineHelp).
$input.n,
'div',
$atts
);
return pluggable_ui($event.'_ui', 'inputlabel.'.$name, $out, $arguments);
}
/**
* Renders anything as an XML element.
*
* @param string $content Enclosed content
* @param string $tag The tag without brackets
* @param string|array $atts The element's HTML attributes
* @return string HTML
* @example
* echo tag('Link text', 'a', array('href' => '#', 'class' => 'warning'));
*/
function tag($content, $tag, $atts = '')
{
static $tags = array();
if (empty($tag) || $content === '') {
return $content;
}
if (!isset($tags[$tag])) {
$tags[$tag] = preg_match('/^\w[\w\-\.\:]*$/', $tag) ? 1 :
(strpos($tag, '<+>') === false ? 2 : 3);
}
switch ($tags[$tag]) {
case 1:
$atts = $atts ? join_atts($atts) : '';
return '<'.$tag.$atts.'>'.$content.'</'.$tag.'>';
case 2:
return $tag.$content.$tag;
default:
return str_replace('<+>', $content, $tag);
}
}
/**
* Renders anything as a HTML void element.
*
* @param string $tag The tag without brackets
* @param string|array $atts HTML attributes
* @return string HTML
* @since 4.6.0
* @example
* echo tag_void('input', array('name' => 'name', 'type' => 'text'));
*/
function tag_void($tag, $atts = '')
{
$tag_close = (in_array($tag, HTML5_VOID_TAGS) && get_pref('doctype') === 'html5') ? '>' : ' />';
return '<'.$tag.join_atts($atts).$tag_close;
}
/**
* Renders anything as a HTML start tag.
*
* @param string $tag The tag without brackets
* @param string|array $atts HTML attributes
* @return string A HTML start tag
* @since 4.6.0
* @example
* echo tag_start('section', array('class' => 'myClass'));
*/
function tag_start($tag, $atts = '')
{
return '<'.$tag.join_atts($atts).'>';
}
/**
* Renders anything as a HTML end tag.
*
* @param string $tag The tag without brackets
* @return string A HTML end tag
* @since 4.6.0
* @example
* echo tag_end('section');
*/
function tag_end($tag)
{
return '</'.$tag.'>';