1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * The file written by Mário César Kolling <mario.kolling@serpro.gov.br> * |
---|
6 | * -------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \**************************************************************************/ |
---|
12 | |
---|
13 | class common_functions |
---|
14 | { |
---|
15 | function borkb($size, $enclosed = NULL) |
---|
16 | { |
---|
17 | if (!$size) |
---|
18 | $size = 0; |
---|
19 | |
---|
20 | if ($enclosed) |
---|
21 | { |
---|
22 | $left = '('; |
---|
23 | $right = ')'; |
---|
24 | } |
---|
25 | |
---|
26 | if ($size < 1024) |
---|
27 | $rstring = $left . $size . ' B' . $right; |
---|
28 | else if ($size < 1048576) |
---|
29 | $rstring = $left . round($size/1024) . ' KB' . $right; |
---|
30 | else if ($size < 1073741824) |
---|
31 | $rstring = $left . round($size/1024/1024) . ' MB' . $right; |
---|
32 | else |
---|
33 | $rstring = $left . round($size/1024/1024/1024) . ' GB' . $right; |
---|
34 | |
---|
35 | return $rstring; |
---|
36 | } |
---|
37 | |
---|
38 | function complete_string($str = "", $length = 10, $align = "R", $char = " ") { |
---|
39 | if( $str == null ) |
---|
40 | $str = ""; |
---|
41 | else |
---|
42 | if( strlen($str) > $length ) { |
---|
43 | return substr($str, 0, $length); |
---|
44 | } else if( strlen($str) == $length ) { |
---|
45 | return $str; |
---|
46 | } |
---|
47 | |
---|
48 | $char = substr($char, 0, 1); |
---|
49 | $complete_str = ""; |
---|
50 | |
---|
51 | while( strlen($str) + strlen($complete_str) < $length ) |
---|
52 | $complete_str .= $char; |
---|
53 | |
---|
54 | if( $align == "L" ) |
---|
55 | return $str . $complete_str; |
---|
56 | else |
---|
57 | return $complete_str . $str; |
---|
58 | } |
---|
59 | |
---|
60 | function strach_string($string,$size) { |
---|
61 | return strlen($string)>$size ? substr($string,0,$size)."...": |
---|
62 | $string; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Fixes the odd indexing of multiple file uploads from the format: |
---|
67 | * |
---|
68 | * $_FILES['field']['key']['index'] |
---|
69 | * |
---|
70 | * To the more standard and appropriate: |
---|
71 | * |
---|
72 | * $_FILES['field']['index']['key'] |
---|
73 | * |
---|
74 | * @param array $files |
---|
75 | * @author Corey Ballou |
---|
76 | * @link http://www.jqueryin.com |
---|
77 | */ |
---|
78 | function fixFilesArray(&$files) |
---|
79 | { |
---|
80 | $names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1); |
---|
81 | |
---|
82 | foreach ($files as $key => $part) { |
---|
83 | // only deal with valid keys and multiple files |
---|
84 | $key = (string) $key; |
---|
85 | if (isset($names[$key]) && is_array($part)) { |
---|
86 | foreach ($part as $position => $value) { |
---|
87 | $files[$position][$key] = $value; |
---|
88 | } |
---|
89 | // remove old key reference |
---|
90 | unset($files[$key]); |
---|
91 | } |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | } //end common class |
---|
96 | |
---|
97 | |
---|
98 | ?> |
---|