-
Notifications
You must be signed in to change notification settings - Fork 3
/
MY_html_helper.php
454 lines (413 loc) · 14.6 KB
/
MY_html_helper.php
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
<?php
function html_message($data = '')
{
if($data)
return '<div id="status_message" style="font-family:verdana;font-size:15px;padding:15px;background:#FBE6F2;border:1px solid #D893A1;color:#333333;">'
.$data.
'</div>';
else
return '';
}
function html_makeOption( $value, $text='', $value_name='value', $text_name='text' ) {
$obj = new stdClass;
$obj->$value_name = $value;
$obj->$text_name = trim( $text ) ? $text : $value;
return $obj;
}
function html_writableCell( $folder, $relative=1, $text='', $visible=1 ) {
$writeable = '<b><font color="green">Writeable</font></b>';
$unwriteable = '<b><font color="red">Unwriteable</font></b>';
echo '<tr>';
echo '<td class="item">';
echo $text;
if ( $visible ) {
echo $folder . '/';
}
echo '</td>';
echo '<td align="left">';
if ( $relative ) {
echo is_writable( "../$folder" ) ? $writeable : $unwriteable;
} else {
echo is_writable( "$folder" ) ? $writeable : $unwriteable;
}
echo '</td>';
echo '</tr>';
}
/**
* Generates an HTML select list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @param mixed The key that is selected
* @returns string HTML for the select list
*/
function html_selectList( &$arr, $tag_name, $tag_attribs, $key, $text, $selected=NULL ) {
// check if array
if ( is_array( $arr ) ) {
reset( $arr );
}
$html = "\n<select name=\"$tag_name\" $tag_attribs>";
$count = count( $arr );
for ($i=0, $n=$count; $i < $n; $i++ ) {
$k = $arr[$i]->$key;
$t = $arr[$i]->$text;
$id = ( isset($arr[$i]->id) ? @$arr[$i]->id : null);
$extra = '';
$extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
if (is_array( $selected )) {
foreach ($selected as $obj) {
$k2 = $obj->$key;
if ($k == $k2) {
$extra .= " selected=\"selected\"";
break;
}
}
} else {
$extra .= ($k == $selected ? " selected=\"selected\"" : '');
}
$html .= "\n\t<option value=\"".$k."\"$extra>" . $t . "</option>";
}
$html .= "\n</select>\n";
return $html;
}
/**
* Writes a select list of integers
* @param int The start integer
* @param int The end integer
* @param int The increment
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @param string The printf format to be applied to the number
* @returns string HTML for the select list
*/
function html_integerSelectList( $start, $end, $inc, $tag_name, $tag_attribs, $selected, $format="" ) {
$start = intval( $start );
$end = intval( $end );
$inc = intval( $inc );
$arr = array();
for ($i=$start; $i <= $end; $i+=$inc) {
$fi = $format ? sprintf( "$format", $i ) : "$i";
$arr[] = html_makeOption( $fi, $fi );
}
return html_selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
}
/**
* Writes a select list of month names based on Language settings
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @returns string HTML for the select list values
*/
function html_monthSelectList( $tag_name, $tag_attribs, $selected ) {
$arr = array(
html_makeOption( '01', _JAN ),
html_makeOption( '02', _FEB ),
html_makeOption( '03', _MAR ),
html_makeOption( '04', _APR ),
html_makeOption( '05', _MAY ),
html_makeOption( '06', _JUN ),
html_makeOption( '07', _JUL ),
html_makeOption( '08', _AUG ),
html_makeOption( '09', _SEP ),
html_makeOption( '10', _OCT ),
html_makeOption( '11', _NOV ),
html_makeOption( '12', _DEC )
);
return html_selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
}
/**
* Generates an HTML select list from a tree based query list
* @param array Source array with id and parent fields
* @param array The id of the current list item
* @param array Target array. May be an empty array.
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @param mixed The key that is selected
* @returns string HTML for the select list
*/
function html_treeSelectList( &$src_list, $src_id, $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected ) {
// establish the hierarchy of the menu
$children = array();
// first pass - collect children
foreach ($src_list as $v ) {
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$ilist = mosTreeRecurse( 0, '', array(), $children );
// assemble menu items to the array
$this_treename = '';
foreach ($ilist as $item) {
if ($this_treename) {
if ($item->id != $src_id && strpos( $item->treename, $this_treename ) === false) {
$tgt_list[] = html_makeOption( $item->id, $item->treename );
}
} else {
if ($item->id != $src_id) {
$tgt_list[] = html_makeOption( $item->id, $item->treename );
} else {
$this_treename = "$item->treename/";
}
}
}
// build the html select list
return html_selectList( $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected );
}
/**
* Writes a yes/no select list
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @returns string HTML for the select list values
*/
function html_yesnoSelectList( $tag_name, $tag_attribs, $selected, $yes=_CMN_YES, $no=_CMN_NO ) {
$arr = array(
html_makeOption( '0', $no ),
html_makeOption( '1', $yes ),
);
return html_selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
}
/**
* Generates an HTML radio list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @returns string HTML for the select list
*/
function html_radioList( &$arr, $tag_name, $tag_attribs, $selected=null, $key='value', $text='text' ) {
reset( $arr );
$html = "";
for ($i=0, $n=count( $arr ); $i < $n; $i++ ) {
$k = $arr[$i]->$key;
$t = $arr[$i]->$text;
$id = ( isset($arr[$i]->id) ? @$arr[$i]->id : null);
$extra = '';
$extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
if (is_array( $selected )) {
foreach ($selected as $obj) {
$k2 = $obj->$key;
if ($k == $k2) {
$extra .= " selected=\"selected\"";
break;
}
}
} else {
$extra .= ($k == $selected ? " checked=\"checked\"" : '');
}
$html .= "\n\t<input type=\"radio\" name=\"$tag_name\" id=\"$tag_name$k\" value=\"".$k."\"$extra $tag_attribs />";
$html .= "\n\t<label for=\"$tag_name$k\">$t</label>";
}
$html .= "\n";
return $html;
}
/**
* Writes a yes/no radio list
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the <select> tag
* @param mixed The key that is selected
* @returns string HTML for the radio list
*/
function html_yesnoRadioList( $tag_name, $tag_attribs, $selected, $yes=_CMN_YES, $no=_CMN_NO ) {
$arr = array(
html_makeOption( '0', $no ),
html_makeOption( '1', $yes )
);
return html_radioList( $arr, $tag_name, $tag_attribs, $selected );
}
/**
* @param int The row index
* @param int The record id
* @param boolean
* @param string The name of the form element
* @return string
*/
function html_idBox( $rowNum, $recId, $checkedOut=false, $name='cid' ) {
if ( $checkedOut ) {
return '';
} else {
return '<input type="checkbox" id="cb'.$rowNum.'" name="'.$name.'[]" value="'.$recId.'" onclick="isChecked(this.checked);" />';
}
}
function html_sortIcon( $base_href, $field, $state='none' ) {
global $mosConfig_live_site;
$alts = array(
'none' => _CMN_SORT_NONE,
'asc' => _CMN_SORT_ASC,
'desc' => _CMN_SORT_DESC,
);
$next_state = 'asc';
if ($state == 'asc') {
$next_state = 'desc';
} else if ($state == 'desc') {
$next_state = 'none';
}
$html = "<a href=\"$base_href&field=$field&order=$next_state\">"
. "<img src=\"$mosConfig_live_site/images/M_images/sort_$state.png\" width=\"12\" height=\"12\" border=\"0\" alt=\"{$alts[$next_state]}\" />"
. "</a>";
return $html;
}
/**
* Writes Close Button
*/
function html_CloseButton ( &$params, $hide_js=NULL ) {
// displays close button in Pop-up window
if ( $params->get( 'popup' ) && !$hide_js ) {
?>
<script language="javascript" type="text/javascript">
<!--
document.write('<div align="center" style="margin-top: 30px; margin-bottom: 30px;">');
document.write('<a href="#" onclick="javascript:window.close();"><span class="small"><?php echo _PROMPT_CLOSE;?></span></a>');
document.write('</div>');
//-->
</script>
<?php
}
}
/**
* Writes Back Button
*/
function html_BackButton ( &$params, $hide_js=NULL ) {
// Back Button
if ( $params->get( 'back_button' ) && !$params->get( 'popup' ) && !$hide_js) {
?>
<div class="back_button">
<a href='javascript:history.go(-1)'>
<?php echo _BACK; ?></a>
</div>
<?php
}
}
/**
* Cleans text of all formating and scripting code
*/
function html_cleanText ( &$text ) {
$text = preg_replace( "'<script[^>]*>.*?</script>'si", '', $text );
$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text );
$text = preg_replace( '/<!--.+?-->/', '', $text );
$text = preg_replace( '/{.+?}/', '', $text );
$text = preg_replace( '/ /', ' ', $text );
$text = preg_replace( '/&/', ' ', $text );
$text = preg_replace( '/"/', ' ', $text );
$text = strip_tags( $text );
$text = htmlspecialchars( $text );
return $text;
}
/**
* Writes Print icon
*/
function html_PrintIcon( &$row, &$params, $hide_js, $link, $status=NULL ) {
if ( $params->get( 'print' ) && !$hide_js ) {
// use default settings if none declared
if ( !$status ) {
$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
}
// checks template image directory for image, if non found default are loaded
if ( $params->get( 'icons' ) ) {
$image = mosAdminMenus::ImageCheck( 'printButton.png', '/images/M_images/', NULL, NULL, _CMN_PRINT, _CMN_PRINT );
} else {
$image = _ICON_SEP .' '. _CMN_PRINT. ' '. _ICON_SEP;
}
if ( $params->get( 'popup' ) && !$hide_js ) {
// Print Preview button - used when viewing page
?>
<script language="javascript" type="text/javascript">
<!--
document.write('<td align="right" width="100%" class="buttonheading">');
document.write('<a href="#" onclick="javascript:window.print(); return false;" title="<?php echo _CMN_PRINT;?>">');
document.write('<?php echo $image;?>');
document.write('</a>');
document.write('</td>');
//-->
</script>
<?php
} else {
// Print Button - used in pop-up window
?>
<td align="right" width="100%" class="buttonheading">
<a href="<?php echo $link; ?>" target="_blank" onclick="window.open('<?php echo $link; ?>','win2','<?php echo $status; ?>'); return false;" title="<?php echo _CMN_PRINT;?>">
<?php echo $image;?></a>
</td>
<?php
}
}
}
/**
* simple Javascript Cloaking
* email cloacking
* by default replaces an email with a mailto link with email cloacked
*/
function html_emailCloaking( $mail, $mailto=1, $text='', $email=1 ) {
// convert text
$mail = html_encoding_converter( $mail );
// split email by @ symbol
$mail = explode( '@', $mail );
$mail_parts = explode( '.', $mail[1] );
// random number
$rand = rand( 1, 100000 );
$replacement = "\n <script language='JavaScript' type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n var prefix = 'ma' + 'il' + 'to';";
$replacement .= "\n var path = 'hr' + 'ef' + '=';";
$replacement .= "\n var addy". $rand ." = '". @$mail[0] ."' + '@';";
$replacement .= "\n addy". $rand ." = addy". $rand ." + '". implode( "' + '.' + '", $mail_parts ) ."';";
if ( $mailto ) {
// special handling when mail text is different from mail addy
if ( $text ) {
if ( $email ) {
// convert text
$text = html_encoding_converter( $text );
// split email by @ symbol
$text = explode( '@', $text );
$text_parts = explode( '.', $text[1] );
$replacement .= "\n var addy_text". $rand ." = '". @$text[0] ."' + '@' + '". implode( "' + '.' + '", @$text_parts ) ."';";
} else {
$replacement .= "\n var addy_text". $rand ." = '". $text ."';";
}
$replacement .= "\n document.write( '<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>' );";
$replacement .= "\n document.write( addy_text". $rand ." );";
$replacement .= "\n document.write( '<\/a>' );";
} else {
$replacement .= "\n document.write( '<a ' + path + '\'' + prefix + ':' + addy". $rand ." + '\'>' );";
$replacement .= "\n document.write( addy". $rand ." );";
$replacement .= "\n document.write( '<\/a>' );";
}
} else {
$replacement .= "\n document.write( addy". $rand ." );";
}
$replacement .= "\n //-->";
$replacement .= '\n </script>';
// XHTML compliance `No Javascript` text handling
$replacement .= "<script language='JavaScript' type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write( '<span style=\'display: none;\'>' );";
$replacement .= "\n //-->";
$replacement .= "\n </script>";
$replacement .= _CLOAKING;
$replacement .= "\n <script language='JavaScript' type='text/javascript'>";
$replacement .= "\n <!--";
$replacement .= "\n document.write( '</' );";
$replacement .= "\n document.write( 'span>' );";
$replacement .= "\n //-->";
$replacement .= "\n </script>";
return $replacement;
}
function html_encoding_converter( $text ) {
// replace vowels with character encoding
$text = str_replace( 'a', 'a', $text );
$text = str_replace( 'e', 'e', $text );
$text = str_replace( 'i', 'i', $text );
$text = str_replace( 'o', 'o', $text );
$text = str_replace( 'u', 'u', $text );
return $text;
}