MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mutil.class
Ir para a documentação deste ficheiro.
1
<?php
2
// +-----------------------------------------------------------------+
3
// | MIOLO - Miolo Development Team - UNIVATES Centro Universitário |
4
// +-----------------------------------------------------------------+
5
// | Copyleft (l) 2001 UNIVATES, Lajeado/RS - Brasil |
6
// +-----------------------------------------------------------------+
7
// | Licensed under GPL: see COPYING.TXT or FSF at www.fsf.org for |
8
// | further details |
9
// | |
10
// | Site: http://miolo.codigoaberto.org.br |
11
// | E-mail: vgartner@univates.br |
12
// | ts@interact2000.com.br |
13
// +-----------------------------------------------------------------+
14
// | Abstract: This file contains utils functions |
15
// | |
16
// | Created: 2001/08/14 Thomas Spriestersbach |
17
// | Vilson Cristiano Gärtner, |
18
// | |
19
// | History: Initial Revision |
20
// +-----------------------------------------------------------------+
21
26
class
MUtil
27
{
38
public
static
function
NVL
($value1, $value2)
39
{
40
return
($value1 != NULL) ? $value1 : $value2;
41
}
42
54
public
static
function
IfNull
($value1, $value2, $value3)
55
{
56
return
($value1 == NULL) ? $value2 : $value3;
57
}
58
69
public
static
function
SetIfNull
(&$value1, $value2)
70
{
71
if
($value1 == NULL) $value1 = $value2;
72
}
73
84
public
static
function
SetIfNotNull
(&$value1, $value2)
85
{
86
if
($value2 != NULL) $value1 = $value2;
87
}
88
100
public
static
function
getBooleanValue
($value)
101
{
102
$valueString = strtoupper((
string
)$value);
103
104
return
in_array($valueString, array(
'1'
,
'TRUE'
,
'T'
,
'SIM'
,
'YES'
,
'S'
,
'Y'
));
105
}
106
117
public
static
function
removeSpaceChars
($value)
118
{
119
$blanks = array(
"\r"
=>
''
,
"\t"
=>
''
,
"\n"
=>
''
,
' '
=>
''
,
' '
=>
''
);
120
121
return
strtr($value, $blanks);
122
}
123
134
public
static
function
copyDirectory
($sourceDir, $destinDir)
135
{
136
if
( file_exists($sourceDir) && file_exists($destinDir) )
137
{
138
$open_dir = opendir($sourceDir);
139
140
while
(
false
!== ( $file = readdir($open_dir) ) )
141
{
142
if
( $file !=
"."
&& $file !=
".."
)
143
{
144
$aux = explode (
'.'
,$file);
145
146
if
( $aux[0] !=
""
)
147
{
148
if
( file_exists($destinDir.
"/"
.$file) &&
149
filetype($destinDir.
"/"
.$file) !=
"dir"
)
150
{
151
unlink($destinDir.
"/"
.$file);
152
}
153
if
( filetype($sourceDir.
"/"
.$file) ==
"dir"
)
154
{
155
if
( ! file_exists($destinDir.
"/"
.$file) )
156
{
157
mkdir($destinDir.
"/"
.$file.
"/"
);
158
self::copyDirectory
($sourceDir.
"/"
.$file, $destinDir.
"/"
.$file);
159
}
160
}
161
else
162
{
163
copy($sourceDir.
"/"
.$file, $destinDir.
"/"
.$file);
164
}
165
}
166
}
167
}
168
}
169
}
170
171
182
public
static
function
removeDirectory
($directory, $empty=FALSE)
183
{
184
if
(substr($directory,-1) ==
'/'
)
185
{
186
$directory = substr($directory,0,-1);
187
}
188
189
if
(!file_exists($directory) || !is_dir($directory))
190
{
191
return
FALSE;
192
}
193
elseif( is_readable($directory) )
194
{
195
$handle = opendir($directory);
196
197
while
( FALSE !== ( $item = readdir($handle) ) )
198
{
199
if
( $item !=
'.'
&& $item !=
'..'
)
200
{
201
$path = $directory.
'/'
.$item;
202
203
if
( is_dir($path) )
204
{
205
self::removeDirectory
($path);
206
}
207
else
208
{
209
unlink($path);
210
}
211
}
212
}
213
214
closedir($handle);
215
216
if
( $empty == FALSE )
217
{
218
if
( ! rmdir($directory) )
219
{
220
return
FALSE;
221
}
222
}
223
}
224
225
return
TRUE;
226
}
227
235
public
static
function
getSystemTempDir
()
236
{
237
$tempFile = tempnam( md5(uniqid(rand(), TRUE)),
''
);
238
if
( $tempFile )
239
{
240
$tempDir = realpath( dirname($tempFile) );
241
unlink( $tempFile );
242
243
return
$tempDir;
244
}
245
else
246
{
247
return
'/tmp'
;
248
}
249
250
}
251
252
public
static
function
getArrayAsCSV
($data, $separator =
';'
)
253
{
254
$csv =
''
;
255
256
foreach
( $data as $line )
257
{
258
$csv .= implode($separator, $line) .
"\n"
;
259
}
260
261
return
$csv;
262
}
263
271
public
static
function
getArrayAsHTML
($data)
272
{
273
global $navbar;
274
275
$currentOption = end($navbar->getOptions());
276
$title
= $currentOption->control->label;
277
278
$header = $data[0];
279
array_shift($data);
280
281
$html =
'<div style="font-family:arial;color:#333;font-weight:400;">'
;
282
$html .=
"<h4>$title</h4>"
;
283
$html .=
'<table style="font-size:12px;"><tr>'
;
284
285
foreach
( $header as $col )
286
{
287
$html .=
"<th style=\"background:#1F72BF;color:#fff;padding:2px 4px;\">$col</th>"
;
288
}
289
290
$html .=
'</tr>'
;
291
292
$zebra =
true
;
293
294
foreach
( $data as $line )
295
{
296
if
( $zebra )
297
{
298
$html .=
'<tr>'
;
299
$zebra =
false
;
300
}
301
else
302
{
303
$html .=
'<tr style="background:#DFEFFF;">'
;
304
$zebra =
true
;
305
}
306
307
foreach
( $line as $cell )
308
{
309
$html .=
"<td style=\"padding:2px 4px;\">$cell</td>"
;
310
}
311
$html .=
'</tr>'
;
312
}
313
314
return
$html;
315
}
316
322
public
static
function
debugBacktrace
($limit=100)
323
{
324
$backtrace = debug_backtrace(
false
);
325
326
// Removes MUtil::vdBacktrace line.
327
unset($backtrace[0]);
328
329
$i = 0;
330
$traces = array();
331
332
foreach
( $backtrace as $trace )
333
{
334
if
( $i == $limit )
break
;
335
336
$traces[] = array(
337
_M(
'File'
) => $trace[
'file'
] .
':'
. $trace[
'line'
],
338
_M(
'Method'
) => $trace[
'class'
] .
'::'
. $trace[
'function'
],
339
);
340
341
$i++;
342
}
343
344
MIOLO::vd
($traces);
345
}
346
352
public
static
function
addJsCode
($jsCode)
353
{
354
$MIOLO
=
MIOLO::getInstance
();
355
356
if
(
$MIOLO
->page->request(
'cpaint_function'
) !=
''
)
357
{
358
$MIOLO
->page->addAJAXJsCode($jsCode);
359
}
360
else
361
{
362
$MIOLO
->page->onload($jsCode);
363
}
364
}
365
366
public
static
function
dumpString
($var)
367
{
368
echo
'<pre>'
. $var .
'<pre>'
;
369
}
370
}
371
372
377
class
MVarDump
378
{
382
var
$var
;
383
384
394
public
function
VarDump
(&
$var
)
395
{
396
$this->var =&
$var
;
397
}
398
406
public
function
Generate
()
407
{
408
echo
"<b>Variable Dump:</b><br><br>\n"
;
409
echo
"<blockquote>\n"
;
410
echo
"<pre>\n"
;
411
var_dump($this->var);
412
echo
"</pre>\n"
;
413
echo
"</blockquote>\n"
;
414
}
415
}
416
421
class
MInvertDate
422
{
426
var
$separator
=
'/'
;
427
431
var
$date
;
432
433
443
function
__construct
(
$date
=
null
)
444
{
445
$date
= strstr(
$date
,
'-'
) ? str_replace(
'-'
, $this->separator,
$date
) : str_replace(
'.'
, $this->separator,
$date
);
446
$this->date =
$date
;
447
$this->FormatDate();
448
}
449
450
Function FormatDate()
451
{
452
list($obj1, $obj2, $obj3) = preg_split(
'/'
.$this->separator.
'/'
, $this->date, 3);
453
$this->date = $obj3 . $this->separator . $obj2 . $this->separator . $obj1;
454
if
( ( $this->date == ($this->separator . $this->separator) ) )
455
$this->date =
'Invalid Date!'
;
456
return
$this->date
;
457
}
458
}
459
460
// formata o valor conforme n casas decimais
465
class
MFormatValue
466
{
470
var
$value
;
471
472
483
function
__construct
(
$value
,$precision=2)
484
{
485
//$this->value = sprintf("%." . $precision . "f",$value);
486
$this->value = number_format(
$value
,$precision,
','
,
'.'
);
487
return
$this->value
;
488
}
489
}
490
495
class
MQuotedPrintable
496
{
506
public
function
encode
($str)
507
{
508
define(
'CRLF'
,
"\r\n"
);
509
$lines = preg_split(
"/\r?\n/"
, $str);
510
$out =
''
;
511
512
foreach
($lines as $line)
513
{
514
515
$newpara =
''
;
516
517
for
($j = 0; $j <= strlen($line) - 1; $j++)
518
{
519
$char = substr ( $line, $j, 1 );
520
$ascii = ord ( $char );
521
522
if
( $ascii < 32 || $ascii == 61 || $ascii > 126 )
523
{
524
$char =
'='
. strtoupper ( dechex( $ascii ) );
525
}
526
527
if
( ( strlen ( $newpara ) + strlen ( $char ) ) >= 76 )
528
{
529
$out .= $newpara .
'='
. CRLF; $newpara =
''
;
530
}
531
$newpara .= $char;
532
}
533
$out .= $newpara . $char;
534
}
535
return
trim ( $out );
536
}
537
547
public
function
decode
( $str )
548
{
549
$out = preg_replace(
'/=\r?\n/'
,
''
, $str);
550
$out = preg_replace(
'/=([A-F0-9]{2})/'
, chr( hexdec (
'\\1'
) ), $out);
551
552
return
trim($out);
553
}
554
555
}
556
561
class
MTreeArray
562
{
566
var
$tree
;
567
568
580
public
function
__construct
($array, $group, $node)
581
{
582
$this->tree = array();
583
if
($rs = $array)
584
{
585
$node = explode(
','
,$node);
586
$group = explode(
','
,$group);
587
foreach
($rs as $row)
588
{
589
$aNode = array();
590
foreach
($node as $n) $aNode[] = $row[$n];
591
$s =
''
;
592
foreach
($group as $g) $s .=
'[$row['
. $g .
']]'
;
593
eval(
"\$this->tree$s"
.
"[] = \$aNode;"
);
594
}
595
}
596
}
597
}
598
599
class
MDummy
600
{
601
}
602
?>
MDummy
Definição
mutil.class:600
MFormatValue
Definição
mutil.class:466
MFormatValue\$value
$value
Definição
mutil.class:470
MFormatValue\__construct
__construct($value, $precision=2)
Definição
mutil.class:483
MIOLO\vd
static vd($variable, $forceType=null)
Definição
miolo.class:1771
MIOLO\getInstance
static getInstance()
Definição
miolo.class:134
MInvertDate
Definição
mutil.class:422
MInvertDate\$date
$date
Definição
mutil.class:431
MInvertDate\__construct
__construct($date=null)
Definição
mutil.class:443
MInvertDate\$separator
$separator
Definição
mutil.class:426
MQuotedPrintable
Definição
mutil.class:496
MQuotedPrintable\encode
encode($str)
Definição
mutil.class:506
MQuotedPrintable\decode
decode( $str)
Definição
mutil.class:547
MTreeArray
Definição
mutil.class:562
MTreeArray\$tree
$tree
Definição
mutil.class:566
MTreeArray\__construct
__construct($array, $group, $node)
Definição
mutil.class:580
MUtil
Definição
mutil.class:27
MUtil\NVL
static NVL($value1, $value2)
Definição
mutil.class:38
MUtil\IfNull
static IfNull($value1, $value2, $value3)
Definição
mutil.class:54
MUtil\getArrayAsHTML
static getArrayAsHTML($data)
Definição
mutil.class:271
MUtil\addJsCode
static addJsCode($jsCode)
Definição
mutil.class:352
MUtil\dumpString
static dumpString($var)
Definição
mutil.class:366
MUtil\removeSpaceChars
static removeSpaceChars($value)
Definição
mutil.class:117
MUtil\SetIfNull
static SetIfNull(&$value1, $value2)
Definição
mutil.class:69
MUtil\debugBacktrace
static debugBacktrace($limit=100)
Definição
mutil.class:322
MUtil\removeDirectory
static removeDirectory($directory, $empty=FALSE)
Definição
mutil.class:182
MUtil\getSystemTempDir
static getSystemTempDir()
Definição
mutil.class:235
MUtil\getBooleanValue
static getBooleanValue($value)
Definição
mutil.class:100
MUtil\getArrayAsCSV
static getArrayAsCSV($data, $separator=';')
Definição
mutil.class:252
MUtil\SetIfNotNull
static SetIfNotNull(&$value1, $value2)
Definição
mutil.class:84
MUtil\copyDirectory
static copyDirectory($sourceDir, $destinDir)
Definição
mutil.class:134
MVarDump
Definição
mutil.class:378
MVarDump\Generate
Generate()
Definição
mutil.class:406
MVarDump\$var
$var
Definição
mutil.class:382
MVarDump\VarDump
VarDump(&$var)
Definição
mutil.class:394
$MIOLO
$MIOLO
Definição
mdatetimefield.class:25
$title
$title
Definição
base.php:3
classes
utils
mutil.class
Gerado por
1.10.0