#0001
#0002
#0003
#0004
#0005
#0006
#0007
#0008
#0009
#0010
#0011
#0012
#0013
#0014
#0015
#0016
#0017
#0018
#0019
#0020
#0021
#0022
#0023
#0024
#0025
#0026
#0027
#0028
#0029
#0030
#0031
#0032
#0033
#0034
#0035
#0036
#0037
#0038
#0039
#0040
#0041
#0042
#0043
#0044
#0045
#0046
#0047
#0048
#0049
#0050
#0051
#0052
#0053
#0054
#0055
#0056
#0057
#0058
#0059
#0060
#0061
#0062
#0063
#0064
#0065
#0066
#0067
#0068
#0069
#0070
#0071
#0072
#0073
#0074
#0075
#0076
#0077
#0078
#0079
#0080
#0081
#0082
#0083
#0084
#0085
#0086
#0087
#0088
#0089
#0090
#0091
#0092
#0093
#0094
#0095
#0096
#0097
#0098
#0099
#0100
#0101
#0102
#0103
#0104
#0105
#0106
#0107
#0108
#0109
#0110
#0111
#0112
#0113
#0114
#0115
#0116
#0117
#0118
#0119
#0120
#0121
#0122
#0123
#0124
#0125
#0126
#0127
#0128
#0129
#0130
#0131
#0132
#0133
#0134
#0135
#0136
#0137
#0138
#0139
#0140
#0141
#0142
#0143
#0144
#0145
#0146
#0147
#0148
#0149
#0150
#0151
#0152
#0153
#0154
#0155
#0156
#0157
#0158
#0159
#0160
#0161
#0162
#0163
#0164
#0165
#0166
#0167
#0168
#0169
#0170
#0171
#0172
#0173
#0174
#0175
#0176
#0177
#0178
#0179
#0180
#0181
#0182
#0183
#0184
#0185
#0186
#0187
#0188
#0189
#0190
#0191
#0192
#0193
#0194
#0195
#0196
#0197
#0198
#0199
#0200
#0201
#0202
#0203
#0204
#0205
#0206
#0207
#0208
#0209
#0210
#0211
#0212
#0213
#0214
#0215
#0216
#0217
#0218
#0219
#0220
#0221
#0222
#0223
#0224
#0225
#0226
#0227
#0228
#0229
#0230
#0231
#0232
#0233
#0234
#0235
#0236
#0237
#0238
#0239
#0240
#0241
#0242
#0243
#0244
#0245
#0246
#0247
#0248
#0249
#0250
#0251
#0252
#0253
#0254
#0255
#0256
#0257
#0258
#0259
#0260
#0261
#0262
#0263
#0264
#0265
#0266
#0267
#0268
|
<?php /* * General top-level functions. */
/** * Prints human-readable information about a variable much prettier. * * @author John Faircloth */ function print_obj($obj, $kill = false) {
echo '<pre class="print_obj" style="text-align: left;">'."\n"; print_r($obj); echo "\n</pre>\n"; if ( $kill ) die;
}
/* * Return user definde constats * * @author Nesbert Hidalgo * @return array */ function get_user_defined_constants() { $return = get_defined_constants(true); return $return['user']; } /* * Returns a human readable size or a file or a size * http://us2.php.net/manual/hk/function.filesize.php#64387 * * @author Nesbert Hidalgo * @param mixed $file_or_size * @return string */ function get_filesize($file_or_size) { $iec = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"); $size = is_numeric($file_or_size) ? $file_or_size : filesize($file_or_size); $i = 0; while ( ($size/1024) > 1 ) { $size = $size / 1024; $i++; } return substr($size, 0, strpos($size,'.') + 4).' '.$iec[$i]; }
/* * Get the mime type of a file (http://www.duke.edu/websrv/file-extensions.html). * * @author Nesbert Hidalgo * @param string $file_name required * @return string */ function get_mime_type($filename) { echo $filename; $mime_types = array( '.ai' => 'application/postscript', '.aif' => 'audio/x-aiff', '.aifc' => 'audio/x-aiff', '.aiff' => 'audio/x-aiff', '.asc' => 'text/plain', '.au' => 'audio/basic', '.avi' => 'video/x-msvideo', '.bcpio' => 'application/x-bcpio', '.bin' => 'application/octet-stream', '.c' => 'text/plain', '.cc' => 'text/plain', '.ccad' => 'application/clariscad', '.cdf' => 'application/x-netcdf', '.class' => 'application/octet-stream', '.cpio' => 'application/x-cpio', '.cpt' => 'application/mac-compactpro', '.csh' => 'application/x-csh', '.css' => 'text/css', '.dcr' => 'application/x-director', '.dir' => 'application/x-director', '.dms' => 'application/octet-stream', '.doc' => 'application/msword', '.drw' => 'application/drafting', '.dvi' => 'application/x-dvi', '.dwg' => 'application/acad', '.dxf' => 'application/dxf', '.dxr' => 'application/x-director', '.eps' => 'application/postscript', '.etx' => 'text/x-setext', '.exe' => 'application/octet-stream', '.ez' => 'application/andrew-inset', '.f' => 'text/plain', '.f90' => 'text/plain', '.fli' => 'video/x-fli', '.gif' => 'image/gif', '.gtar' => 'application/x-gtar', '.gz' => 'application/x-gzip', '.h' => 'text/plain', '.hdf' => 'application/x-hdf', '.hh' => 'text/plain', '.hqx' => 'application/mac-binhex40', '.htm' => 'text/html', '.html' => 'text/html', '.ice' => 'x-conference/x-cooltalk', '.ief' => 'image/ief', '.iges' => 'model/iges', '.igs' => 'model/iges', '.ips' => 'application/x-ipscript', '.ipx' => 'application/x-ipix', '.jpe' => 'image/jpeg', '.jpeg' => 'image/jpeg', '.jpg' => 'image/jpeg', '.js' => 'application/x-javascript', '.kar' => 'audio/midi', '.latex' => 'application/x-latex', '.lha' => 'application/octet-stream', '.lsp' => 'application/x-lisp', '.lzh' => 'application/octet-stream', '.m' => 'text/plain', '.man' => 'application/x-troff-man', '.me' => 'application/x-troff-me', '.mesh' => 'model/mesh', '.mid' => 'audio/midi', '.midi' => 'audio/midi', '.mif' => 'application/vnd.mif', '.mime' => 'www/mime', '.mov' => 'video/quicktime', '.movie' => 'video/x-sgi-movie', '.mp2' => 'audio/mpeg', '.mp3' => 'audio/mpeg', '.mpe' => 'video/mpeg', '.mpeg' => 'video/mpeg', '.mpg' => 'video/mpeg', '.mpga' => 'audio/mpeg', '.ms' => 'application/x-troff-ms', '.msh' => 'model/mesh', '.nc' => 'application/x-netcdf', '.oda' => 'application/oda', '.pbm' => 'image/x-portable-bitmap', '.pdb' => 'chemical/x-pdb', '.pdf' => 'application/pdf', '.php' => 'text/html', '.pgm' => 'image/x-portable-graymap', '.pgn' => 'application/x-chess-pgn', '.png' => 'image/png', '.pnm' => 'image/x-portable-anymap', '.pot' => 'application/mspowerpoint', '.ppm' => 'image/x-portable-pixmap', '.pps' => 'application/mspowerpoint', '.ppt' => 'application/mspowerpoint', '.ppz' => 'application/mspowerpoint', '.pre' => 'application/x-freelance', '.prt' => 'application/pro_eng', '.ps' => 'application/postscript', '.qt' => 'video/quicktime', '.ra' => 'audio/x-realaudio', '.ram' => 'audio/x-pn-realaudio', '.ras' => 'image/cmu-raster', '.rgb' => 'image/x-rgb', '.rm' => 'audio/x-pn-realaudio', '.roff' => 'application/x-troff', '.rpm' => 'audio/x-pn-realaudio-plugin', '.rtf' => 'text/rtf', '.rtx' => 'text/richtext', '.scm' => 'application/x-lotusscreencam', '.set' => 'application/set', '.sgm' => 'text/sgml', '.sgml' => 'text/sgml', '.sh' => 'application/x-sh', '.shar' => 'application/x-shar', '.silo' => 'model/mesh', '.sit' => 'application/x-stuffit', '.skd' => 'application/x-koan', '.skm' => 'application/x-koan', '.skp' => 'application/x-koan', '.skt' => 'application/x-koan', '.smi' => 'application/smil', '.smil' => 'application/smil', '.snd' => 'audio/basic', '.sol' => 'application/solids', '.spl' => 'application/x-futuresplash', '.src' => 'application/x-wais-source', '.step' => 'application/STEP', '.stl' => 'application/SLA', '.stp' => 'application/STEP', '.sv4cpio' => 'application/x-sv4cpio', '.sv4crc' => 'application/x-sv4crc', '.swf' => 'application/x-shockwave-flash', '.t' => 'application/x-troff', '.tar' => 'application/x-tar', '.tcl' => 'application/x-tcl', '.tex' => 'application/x-tex', '.texi' => 'application/x-texinfo', '.texinfo' => 'application/x-texinfo', '.tif' => 'image/tiff', '.tiff' => 'image/tiff', '.tr' => 'application/x-troff', '.tsi' => 'audio/TSP-audio', '.tsp' => 'application/dsptype', '.tsv' => 'text/tab-separated-values', '.txt' => 'text/plain', '.unv' => 'application/i-deas', '.ustar' => 'application/x-ustar', '.vcd' => 'application/x-cdlink', '.vda' => 'application/vda', '.viv' => 'video/vnd.vivo', '.vivo' => 'video/vnd.vivo', '.vrml' => 'model/vrml', '.wav' => 'audio/x-wav', '.wrl' => 'model/vrml', '.xbm' => 'image/x-xbitmap', '.xlc' => 'application/vnd.ms-excel', '.xll' => 'application/vnd.ms-excel', '.xlm' => 'application/vnd.ms-excel', '.xls' => 'application/vnd.ms-excel', '.xlw' => 'application/vnd.ms-excel', '.xml' => 'text/xml', '.xpm' => 'image/x-xpixmap', '.xwd' => 'image/x-xwindowdump', '.xyz' => 'chemical/x-pdb', '.zip' => 'application/zip', ); $filename = basename($filename); $extension = pathinfo($filename, PATHINFO_EXTENSION); return ( in_array('.'.$extension, array_keys($mime_types)) ? $mime_types['.'.$extension] : false ); }
/* * Deep cleans arrays, objects, strings * * @author Nesbert Hidalgo * @param mixed $data * @return mixed */ function strip_slashes($data) { switch ( true ) { // clean data array case ( is_array($data) ): $clean_values = array(); foreach ($data as $name => $value) $clean_values[$name] = is_array($value) ? array_map('strip_slashes', $value) : stripslashes(trim($value)); break; // get vars from object -> clean data -> update and return object case ( is_object($data) ): $clean_values = $this->strip_slashes(get_object_vars($data)); foreach ($clean_values as $name => $value) $data->$name = is_array($value) ? array_map('strip_slashes', $value) : stripslashes(trim($value)); $clean_values = $data; break; // clean data default: $clean_values = stripslashes(trim($data)); break; } return $clean_values; }
?>
|