Annotation of /mambo/branches/4.5.4/includes/mambofunc.php
Parent Directory
|
Revision Log
Revision 83 - (view) (download)
| 1 : | counterpoi | 82 | t <?php |
| 2 : | t | ||
| 3 : | t /** | ||
| 4 : | t * Sorts an Array of objects | ||
| 5 : | t */ | ||
| 6 : | t function SortArrayObjects_cmp( &$a, &$b ) { | ||
| 7 : | t global $csort_cmp; | ||
| 8 : | t | ||
| 9 : | t if ( $a->$csort_cmp['key'] > $b->$csort_cmp['key'] ) { | ||
| 10 : | t return $csort_cmp['direction']; | ||
| 11 : | t } | ||
| 12 : | t | ||
| 13 : | t if ( $a->$csort_cmp['key'] < $b->$csort_cmp['key'] ) { | ||
| 14 : | t return -1 * $csort_cmp['direction']; | ||
| 15 : | t } | ||
| 16 : | t | ||
| 17 : | t return 0; | ||
| 18 : | t } | ||
| 19 : | t | ||
| 20 : | t /** | ||
| 21 : | t * Sorts an Array of objects | ||
| 22 : | t * sort_direction [1 = Ascending] [-1 = Descending] | ||
| 23 : | t */ | ||
| 24 : | t function SortArrayObjects( &$a, $k, $sort_direction=1 ) { | ||
| 25 : | t global $csort_cmp; | ||
| 26 : | t | ||
| 27 : | t $csort_cmp = array( | ||
| 28 : | t 'key' => $k, | ||
| 29 : | t 'direction' => $sort_direction | ||
| 30 : | t ); | ||
| 31 : | t | ||
| 32 : | t usort( $a, 'SortArrayObjects_cmp' ); | ||
| 33 : | t | ||
| 34 : | t unset( $csort_cmp ); | ||
| 35 : | t } | ||
| 36 : | t | ||
| 37 : | t /** | ||
| 38 : | t * Sends mail to admin | ||
| 39 : | t */ | ||
| 40 : | t function mosSendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author ) { | ||
| 41 : | t global $mosConfig_live_site; | ||
| 42 : | t | ||
| 43 : | t $subject = _MAIL_SUB." '$type'"; | ||
| 44 : | t $message = _MAIL_MSG; | ||
| 45 : | t eval ("\$message = \"$message\";"); | ||
| 46 : | t mosMail($mosConfig_mailfrom, $mosConfig_fromname, $adminEmail, $subject, $message); | ||
| 47 : | t } | ||
| 48 : | t | ||
| 49 : | t /* | ||
| 50 : | t * Includes pathway file | ||
| 51 : | t */ | ||
| 52 : | t function mosPathWay() { | ||
| 53 : | t require mamboCore::get('mosConfig_absolute_path').'/includes/pathway.php'; | ||
| 54 : | t } | ||
| 55 : | t | ||
| 56 : | t /** | ||
| 57 : | t * Displays a not authorised message | ||
| 58 : | t * | ||
| 59 : | t * If the user is not logged in then an addition message is displayed. | ||
| 60 : | t */ | ||
| 61 : | t function mosNotAuth() { | ||
| 62 : | t global $my; | ||
| 63 : | t | ||
| 64 : | t echo _NOT_AUTH; | ||
| 65 : | t if ($my->id < 1) { | ||
| 66 : | t echo "<br />" . _DO_LOGIN; | ||
| 67 : | t } | ||
| 68 : | t } | ||
| 69 : | t | ||
| 70 : | t /** | ||
| 71 : | t * Replaces & with & for xhtml compliance | ||
| 72 : | t * | ||
| 73 : | t * Needed to handle unicode conflicts due to unicode conflicts | ||
| 74 : | t */ | ||
| 75 : | t function ampReplace( $text ) { | ||
| 76 : | t $text = str_replace( '&#', '*-*', $text ); | ||
| 77 : | t $text = str_replace( '&', '&', $text ); | ||
| 78 : | t $text = str_replace( '*-*', '&#', $text ); | ||
| 79 : | t | ||
| 80 : | t return $text; | ||
| 81 : | t } | ||
| 82 : | t | ||
| 83 : | t /** | ||
| 84 : | t * Prepares results from search for display | ||
| 85 : | t * @param string The source string | ||
| 86 : | t * @param int Number of chars to trim | ||
| 87 : | t * @param string The searchword to select around | ||
| 88 : | t * @return string | ||
| 89 : | t */ | ||
| 90 : | t function mosPrepareSearchContent( $text, $length=200, $searchword ) { | ||
| 91 : | t // strips tags won't remove the actual jscript | ||
| 92 : | t $text = preg_replace( "'<script[^>]*>.*?</script>'si", "", $text ); | ||
| 93 : | t $text = preg_replace( '/{.+?}/', '', $text); | ||
| 94 : | t //$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text ); | ||
| 95 : | t return mosSmartSubstr( strip_tags( $text ), $length, $searchword ); | ||
| 96 : | t } | ||
| 97 : | t | ||
| 98 : | t /** | ||
| 99 : | t * returns substring of characters around a searchword | ||
| 100 : | t * @param string The source string | ||
| 101 : | t * @param int Number of chars to return | ||
| 102 : | t * @param string The searchword to select around | ||
| 103 : | t * @return string | ||
| 104 : | t */ | ||
| 105 : | t function mosSmartSubstr($text, $length=200, $searchword) { | ||
| 106 : | t $wordpos = strpos(strtolower($text), strtolower($searchword)); | ||
| 107 : | t $halfside = intval($wordpos - $length/2 - strlen($searchword)); | ||
| 108 : | t if ($wordpos && $halfside > 0) { | ||
| 109 : | t return '...' . substr($text, $halfside, $length); | ||
| 110 : | t } else { | ||
| 111 : | t return substr( $text, 0, $length); | ||
| 112 : | t } | ||
| 113 : | t } | ||
| 114 : | t | ||
| 115 : | t /** | ||
| 116 : | t * Chmods files and directories recursively to given permissions. Available from 4.5.2 up. | ||
| 117 : | t * @param path The starting file or directory (no trailing slash) | ||
| 118 : | t * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 119 : | t * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 120 : | t * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 121 : | t */ | ||
| 122 : | t function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL) | ||
| 123 : | t { | ||
| 124 : | t $ret = TRUE; | ||
| 125 : | t if (is_dir($path)) { | ||
| 126 : | t $dh = opendir($path); | ||
| 127 : | t while ($file = readdir($dh)) { | ||
| 128 : | t if ($file != '.' && $file != '..') { | ||
| 129 : | t $fullpath = $path.'/'.$file; | ||
| 130 : | t if (is_dir($fullpath)) { | ||
| 131 : | t if (!mosChmodRecursive($fullpath, $filemode, $dirmode)) | ||
| 132 : | t $ret = FALSE; | ||
| 133 : | t } else { | ||
| 134 : | t if (isset($filemode)) | ||
| 135 : | t if (!@chmod($fullpath, $filemode)) | ||
| 136 : | t $ret = FALSE; | ||
| 137 : | t } // if | ||
| 138 : | t } // if | ||
| 139 : | t } // while | ||
| 140 : | t closedir($dh); | ||
| 141 : | t if (isset($dirmode)) | ||
| 142 : | t if (!@chmod($path, $dirmode)) | ||
| 143 : | t $ret = FALSE; | ||
| 144 : | t } else { | ||
| 145 : | t if (isset($filemode)) | ||
| 146 : | t $ret = @chmod($path, $filemode); | ||
| 147 : | t } // if | ||
| 148 : | t return $ret; | ||
| 149 : | t } // mosChmodRecursive | ||
| 150 : | t | ||
| 151 : | t /** | ||
| 152 : | t * Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up. | ||
| 153 : | t * @param path The starting file or directory (no trailing slash) | ||
| 154 : | t * @param filemode Integer value to chmod files. NULL = dont chmod files. | ||
| 155 : | t * @param dirmode Integer value to chmod directories. NULL = dont chmod directories. | ||
| 156 : | t * @return TRUE=all succeeded FALSE=one or more chmods failed | ||
| 157 : | t */ | ||
| 158 : | t function mosChmod($path) | ||
| 159 : | t { | ||
| 160 : | t global $mosConfig_fileperms, $mosConfig_dirperms; | ||
| 161 : | t $filemode = NULL; | ||
| 162 : | t if ($mosConfig_fileperms != '') | ||
| 163 : | t $filemode = octdec($mosConfig_fileperms); | ||
| 164 : | t $dirmode = NULL; | ||
| 165 : | t if ($mosConfig_dirperms != '') | ||
| 166 : | t $dirmode = octdec($mosConfig_dirperms); | ||
| 167 : | t if (isset($filemode) || isset($dirmode)) | ||
| 168 : | t return mosChmodRecursive($path, $filemode, $dirmode); | ||
| 169 : | t return TRUE; | ||
| 170 : | t } // mosChmod | ||
| 171 : | t | ||
| 172 : | t /** | ||
| 173 : | t * Function to convert array to integer values | ||
| 174 : | t */ | ||
| 175 : | t function mosArrayToInts( &$array, $default=null ) { | ||
| 176 : | t if (is_array( $array )) { | ||
| 177 : | t $n = count( $array ); | ||
| 178 : | t for ($i = 0; $i < $n; $i++) { | ||
| 179 : | t $array[$i] = intval( $array[$i] ); | ||
| 180 : | t } | ||
| 181 : | t } else { | ||
| 182 : | t if (is_null( $default )) { | ||
| 183 : | t return array(); | ||
| 184 : | t } else { | ||
| 185 : | t return array( $default ); | ||
| 186 : | t } | ||
| 187 : | t } | ||
| 188 : | t } | ||
| 189 : | t | ||
| 190 : | t /** | ||
| 191 : | t * Strip slashes from strings or arrays of strings | ||
| 192 : | t * @param value the input string or array | ||
| 193 : | t */ | ||
| 194 : | t function mosStripslashes(&$value) | ||
| 195 : | t { | ||
| 196 : | t $ret = ''; | ||
| 197 : | t if (is_string($value)) { | ||
| 198 : | t $ret = stripslashes($value); | ||
| 199 : | t } else { | ||
| 200 : | t if (is_array($value)) { | ||
| 201 : | t $ret = array(); | ||
| 202 : | t while (list($key,$val) = each($value)) { | ||
| 203 : | t $ret[$key] = mosStripslashes($val); | ||
| 204 : | t } // while | ||
| 205 : | t } else { | ||
| 206 : | t $ret = $value; | ||
| 207 : | t } // if | ||
| 208 : | t } // if | ||
| 209 : | t return $ret; | ||
| 210 : | t } // mosStripSlashes | ||
| 211 : | t | ||
| 212 : | t /** | ||
| 213 : | t * Copy the named array content into the object as properties | ||
| 214 : | t * only existing properties of object are filled. when undefined in hash, properties wont be deleted | ||
| 215 : | t * @param array the input array | ||
| 216 : | t * @param obj byref the object to fill of any class | ||
| 217 : | t * @param string | ||
| 218 : | t * @param boolean | ||
| 219 : | t */ | ||
| 220 : | t function mosBindArrayToObject( $array, &$obj, $ignore='', $prefix=NULL, $checkSlashes=true ) { | ||
| 221 : | t $database = mamboDatabase::getInstance(); | ||
| 222 : | t return $database->mosBindArrayToOBject($array, $obj, $ignore='', $prefix=NULL, $checkSlashes=true); | ||
| 223 : | t } | ||
| 224 : | t | ||
| 225 : | t /** | ||
| 226 : | t * Utility function to read the files in a directory | ||
| 227 : | t * @param string The file system path | ||
| 228 : | t * @param string A filter for the names | ||
| 229 : | t * @param boolean Recurse search into sub-directories | ||
| 230 : | t * @param boolean True if to prepend the full path to the file name | ||
| 231 : | t */ | ||
| 232 : | t function mosReadDirectory( $path, $filter='.', $recurse=false, $fullpath=false ) { | ||
| 233 : | t $arr = array(); | ||
| 234 : | t if (!@is_dir( $path )) { | ||
| 235 : | t return $arr; | ||
| 236 : | t } | ||
| 237 : | t $handle = opendir( $path ); | ||
| 238 : | t | ||
| 239 : | t while ($file = readdir($handle)) { | ||
| 240 : | t $dir = mosPathName( $path.'/'.$file, false ); | ||
| 241 : | t $isDir = is_dir( $dir ); | ||
| 242 : | t if (($file <> ".") && ($file <> "..")) { | ||
| 243 : | t if (preg_match( "/$filter/", $file )) { | ||
| 244 : | t if ($fullpath) { | ||
| 245 : | t $arr[] = trim( mosPathName( $path.'/'.$file, false ) ); | ||
| 246 : | t } else { | ||
| 247 : | t $arr[] = trim( $file ); | ||
| 248 : | t } | ||
| 249 : | t } | ||
| 250 : | t if ($recurse && $isDir) { | ||
| 251 : | t $arr2 = mosReadDirectory( $dir, $filter, $recurse, $fullpath ); | ||
| 252 : | t $arr = array_merge( $arr, $arr2 ); | ||
| 253 : | t } | ||
| 254 : | t } | ||
| 255 : | t } | ||
| 256 : | t closedir($handle); | ||
| 257 : | t asort($arr); | ||
| 258 : | t return $arr; | ||
| 259 : | t } | ||
| 260 : | t | ||
| 261 : | t /** | ||
| 262 : | t * Utility function redirect the browser location to another url | ||
| 263 : | t * | ||
| 264 : | t * Can optionally provide a message. | ||
| 265 : | t * @param string The file system path | ||
| 266 : | t * @param string A filter for the names | ||
| 267 : | t */ | ||
| 268 : | t function mosRedirect( $url, $msg='' ) { | ||
| 269 : | t mamboCore::redirect($url, $msg); | ||
| 270 : | t } | ||
| 271 : | t | ||
| 272 : | t /** | ||
| 273 : | t * Function to strip additional / or \ in a path name | ||
| 274 : | t * @param string The path | ||
| 275 : | t * @param boolean Add trailing slash | ||
| 276 : | t */ | ||
| 277 : | t function mosPathName($p_path,$p_addtrailingslash = true) { | ||
| 278 : | t $retval = ""; | ||
| 279 : | t | ||
| 280 : | t $isWin = (substr(PHP_OS, 0, 3) == 'WIN'); | ||
| 281 : | t | ||
| 282 : | t if ($isWin) { | ||
| 283 : | t $retval = str_replace( '/', '\\', $p_path ); | ||
| 284 : | t if ($p_addtrailingslash) { | ||
| 285 : | t if (substr( $retval, -1 ) != '\\') { | ||
| 286 : | t $retval .= '\\'; | ||
| 287 : | t } | ||
| 288 : | t } | ||
| 289 : | t // Remove double \\ | ||
| 290 : | t $retval = str_replace( '\\\\', '\\', $retval ); | ||
| 291 : | t } else { | ||
| 292 : | t $retval = str_replace( '\\', '/', $p_path ); | ||
| 293 : | t if ($p_addtrailingslash) { | ||
| 294 : | t if (substr( $retval, -1 ) != '/') { | ||
| 295 : | t $retval .= '/'; | ||
| 296 : | t } | ||
| 297 : | t } | ||
| 298 : | t // Remove double // | ||
| 299 : | t $retval = str_replace('//','/',$retval); | ||
| 300 : | t } | ||
| 301 : | t | ||
| 302 : | t return $retval; | ||
| 303 : | t } | ||
| 304 : | t | ||
| 305 : | t /** | ||
| 306 : | t * Checks the user agent string against known browsers | ||
| 307 : | t */ | ||
| 308 : | t function mosGetBrowser( $agent ) { | ||
| 309 : | t require( "includes/agent_browser.php" ); | ||
| 310 : | t | ||
| 311 : | t if (preg_match( "/msie[\/\sa-z]*([\d\.]*)/i", $agent, $m ) | ||
| 312 : | t && !preg_match( "/webtv/i", $agent ) | ||
| 313 : | t && !preg_match( "/omniweb/i", $agent ) | ||
| 314 : | t && !preg_match( "/opera/i", $agent )) { | ||
| 315 : | t // IE | ||
| 316 : | t return "MS Internet Explorer $m[1]"; | ||
| 317 : | t } else if (preg_match( "/netscape.?\/([\d\.]*)/i", $agent, $m )) { | ||
| 318 : | t // Netscape 6.x, 7.x ... | ||
| 319 : | t return "Netscape $m[1]"; | ||
| 320 : | t } else if ( preg_match( "/mozilla[\/\sa-z]*([\d\.]*)/i", $agent, $m ) | ||
| 321 : | t && !preg_match( "/gecko/i", $agent ) | ||
| 322 : | t && !preg_match( "/compatible/i", $agent ) | ||
| 323 : | t && !preg_match( "/opera/i", $agent ) | ||
| 324 : | t && !preg_match( "/galeon/i", $agent ) | ||
| 325 : | t && !preg_match( "/safari/i", $agent )) { | ||
| 326 : | t // Netscape 3.x, 4.x ... | ||
| 327 : | t return "Netscape $m[2]"; | ||
| 328 : | t } else { | ||
| 329 : | t // Other | ||
| 330 : | t $found = false; | ||
| 331 : | t foreach ($browserSearchOrder as $key) { | ||
| 332 : | t if (preg_match( "/$key.?\/([\d\.]*)/i", $agent, $m )) { | ||
| 333 : | t $name = "$browsersAlias[$key] $m[1]"; | ||
| 334 : | t return $name; | ||
| 335 : | t break; | ||
| 336 : | t } | ||
| 337 : | t } | ||
| 338 : | t } | ||
| 339 : | t | ||
| 340 : | t return 'Unknown'; | ||
| 341 : | t } | ||
| 342 : | t | ||
| 343 : | t /** | ||
| 344 : | t * Checks the user agent string against known operating systems | ||
| 345 : | t */ | ||
| 346 : | t function mosGetOS( $agent ) { | ||
| 347 : | t require( "includes/agent_os.php" ); | ||
| 348 : | t | ||
| 349 : | t foreach ($osSearchOrder as $key) { | ||
| 350 : | t if (preg_match( "/$key/i", $agent )) { | ||
| 351 : | t return $osAlias[$key]; | ||
| 352 : | t break; | ||
| 353 : | t } | ||
| 354 : | t } | ||
| 355 : | t | ||
| 356 : | t return 'Unknown'; | ||
| 357 : | t } | ||
| 358 : | t | ||
| 359 : | t /** | ||
| 360 : | t * Makes a variable safe to display in forms | ||
| 361 : | t * | ||
| 362 : | t * Object parameters that are non-string, array, object or start with underscore | ||
| 363 : | t * will be converted | ||
| 364 : | t * @param object An object to be parsed | ||
| 365 : | t * @param int The optional quote style for the htmlspecialchars function | ||
| 366 : | t * @param string|array An optional single field name or array of field names not | ||
| 367 : | t * to be parsed (eg, for a textarea) | ||
| 368 : | t */ | ||
| 369 : | t function mosMakeHtmlSafe( &$mixed, $quote_style=ENT_QUOTES, $exclude_keys='' ) { | ||
| 370 : | t if (is_object( $mixed )) { | ||
| 371 : | t foreach (get_object_vars( $mixed ) as $k => $v) { | ||
| 372 : | t if (is_array( $v ) || is_object( $v ) || $v == NULL || substr( $k, 1, 1 ) == '_' ) { | ||
| 373 : | t continue; | ||
| 374 : | t } | ||
| 375 : | t if (is_string( $exclude_keys ) && $k == $exclude_keys) { | ||
| 376 : | t continue; | ||
| 377 : | t } else if (is_array( $exclude_keys ) && in_array( $k, $exclude_keys )) { | ||
| 378 : | t continue; | ||
| 379 : | t } | ||
| 380 : | t $mixed->$k = htmlspecialchars( $v, $quote_style ); | ||
| 381 : | t } | ||
| 382 : | t } | ||
| 383 : | t } | ||
| 384 : | t | ||
| 385 : | t /** | ||
| 386 : | t * Checks whether a menu option is within the users access level | ||
| 387 : | t * @param int Item id number | ||
| 388 : | t * @param string The menu option | ||
| 389 : | t * @param int The users group ID number | ||
| 390 : | t * @param database A database connector object | ||
| 391 : | t * @return boolean True if the visitor's group at least equal to the menu access | ||
| 392 : | t */ | ||
| 393 : | t function mosMenuCheck( $Itemid, $menu_option, $task, $gid ) { | ||
| 394 : | t $menuhandler = mosMenuHandler::getInstance(); | ||
| 395 : | t return $menuhandler->menuCheck($Itemid, $menu_option, $task, $gid); | ||
| 396 : | t } | ||
| 397 : | t | ||
| 398 : | t /** | ||
| 399 : | t * Returns formated date according to current local and adds time offset | ||
| 400 : | t * @param string date in datetime format | ||
| 401 : | t * @param string format optional format for strftime | ||
| 402 : | t * @param offset time offset if different than global one | ||
| 403 : | t * @returns formated date | ||
| 404 : | t */ | ||
| 405 : | t function mosFormatDate( $date, $format="", $offset="" ){ | ||
| 406 : | t global $mosConfig_offset; | ||
| 407 : | t if ( $format == '' ) { | ||
| 408 : | t // %Y-%m-%d %H:%M:%S | ||
| 409 : | t $format = _DATE_FORMAT_LC; | ||
| 410 : | t } | ||
| 411 : | t if ( $offset == '' ) { | ||
| 412 : | t $offset = $mosConfig_offset; | ||
| 413 : | t } | ||
| 414 : | t if ( $date && ereg( "([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $date, $regs ) ) { | ||
| 415 : | t $date = mktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] ); | ||
| 416 : | t $date = $date > -1 ? strftime( $format, $date + ($offset*60*60) ) : '-'; | ||
| 417 : | t } | ||
| 418 : | t return $date; | ||
| 419 : | t } | ||
| 420 : | t | ||
| 421 : | t /** | ||
| 422 : | t * Returns current date according to current local and time offset | ||
| 423 : | t * @param string format optional format for strftime | ||
| 424 : | t * @returns current date | ||
| 425 : | t */ | ||
| 426 : | t function mosCurrentDate( $format="" ) { | ||
| 427 : | t global $mosConfig_offset; | ||
| 428 : | t if ($format=="") { | ||
| 429 : | t $format = _DATE_FORMAT_LC; | ||
| 430 : | t } | ||
| 431 : | t $date = strftime( $format, time() + ($mosConfig_offset*60*60) ); | ||
| 432 : | t return $date; | ||
| 433 : | t } | ||
| 434 : | t | ||
| 435 : | t /** | ||
| 436 : | t * Utility function to provide ToolTips | ||
| 437 : | t * @param string ToolTip text | ||
| 438 : | t * @param string Box title | ||
| 439 : | t * @returns HTML code for ToolTip | ||
| 440 : | t */ | ||
| 441 : | t function mosToolTip( $tooltip, $title='', $width='', $image='tooltip.png', $text='', $href='#' ) { | ||
| 442 : | t global $mosConfig_live_site; | ||
| 443 : | t | ||
| 444 : | t if ( $width ) { | ||
| 445 : | t $width = ', WIDTH, \''.$width .'\''; | ||
| 446 : | t } | ||
| 447 : | t if ( $title ) { | ||
| 448 : | t $title = ', CAPTION, \''.$title .'\''; | ||
| 449 : | t } | ||
| 450 : | t if ( !$text ) { | ||
| 451 : | t $image = $mosConfig_live_site . '/includes/js/ThemeOffice/'. $image; | ||
| 452 : | t $text = '<img src="'. $image .'" border="0" />'; | ||
| 453 : | t } | ||
| 454 : | t $style = 'style="text-decoration: none; color: #333;"'; | ||
| 455 : | t if ( $href ) { | ||
| 456 : | t $style = ''; | ||
| 457 : | t } | ||
| 458 : | t $tip = "<a href=\"". $href ."\" onMouseOver=\"return overlib('" . $tooltip . "'". $title .", BELOW, RIGHT". $width .");\" onmouseout=\"return nd();\" ". $style .">". $text ."</a>"; | ||
| 459 : | t return $tip; | ||
| 460 : | t } | ||
| 461 : | t | ||
| 462 : | t /** | ||
| 463 : | t * Utility function to provide Warning Icons | ||
| 464 : | t * @param string Warning text | ||
| 465 : | t * @param string Box title | ||
| 466 : | t * @returns HTML code for Warning | ||
| 467 : | t */ | ||
| 468 : | t function mosWarning($warning, $title='Mambo Warning') { | ||
| 469 : | t global $mosConfig_live_site; | ||
| 470 : | t $tip = "<a href=\"#\" onMouseOver=\"return overlib('" . $warning . "', CAPTION, '$title', BELOW, RIGHT);\" onmouseout=\"return nd();\"><img src=\"" . $mosConfig_live_site . "/includes/js/ThemeOffice/warning.png\" border=\"0\" /></a>"; | ||
| 471 : | t return $tip; | ||
| 472 : | t } | ||
| 473 : | t | ||
| 474 : | t function mosCreateGUID(){ | ||
| 475 : | t srand((double)microtime()*1000000); | ||
| 476 : | t $r = rand ; | ||
| 477 : | t $u = uniqid(getmypid() . $r . (double)microtime()*1000000,1); | ||
| 478 : | t $m = md5 ($u); | ||
| 479 : | t return($m); | ||
| 480 : | t } | ||
| 481 : | t | ||
| 482 : | t function mosCompressID( $ID ){ | ||
| 483 : | t return(Base64_encode(pack("H*",$ID))); | ||
| 484 : | t } | ||
| 485 : | t | ||
| 486 : | t function mosExpandID( $ID ) { | ||
| 487 : | t return ( implode(unpack("H*",Base64_decode($ID)), '') ); | ||
| 488 : | t } | ||
| 489 : | t | ||
| 490 : | t /** | ||
| 491 : | t * Mail function (uses phpMailer) | ||
| 492 : | t * @param string From e-mail address | ||
| 493 : | t * @param string From name | ||
| 494 : | t * @param string/array Recipient e-mail address(es) | ||
| 495 : | t * @param string E-mail subject | ||
| 496 : | t * @param string Message body | ||
| 497 : | t * @param boolean false = plain text, true = HTML | ||
| 498 : | t * @param string/array CC e-mail address(es) | ||
| 499 : | t * @param string/array BCC e-mail address(es) | ||
| 500 : | t * @param string/array Attachment file name(s) | ||
| 501 : | t * @param string/array Reply-to e-mail address | ||
| 502 : | t * @param string/array Reply-to name | ||
| 503 : | t */ | ||
| 504 : | t function mosMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=NULL, $bcc=NULL, $attachment=NULL, $replyto=NULL, $replytoname=NULL ) { | ||
| 505 : | counterpoi | 83 | t require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpmailer/class.phpmailer.php'); |
| 506 : | t $mail =& new mosMailer ($from, $fromname, $subject, $body); | ||
| 507 : | t $result = $mail->mosMail($recipient, $mode, $cc, $bcc, $attachment, $replyto, $replytoname); | ||
| 508 : | t return $result; | ||
| 509 : | counterpoi | 82 | t } // mosMail |
| 510 : | t | ||
| 511 : | t /** | ||
| 512 : | t * Random password generator | ||
| 513 : | t * @return password | ||
| 514 : | t */ | ||
| 515 : | t function mosMakePassword() { | ||
| 516 : | t $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
| 517 : | t $len = strlen($salt); | ||
| 518 : | t $makepass=""; | ||
| 519 : | t mt_srand(10000000*(double)microtime()); | ||
| 520 : | t for ($i = 0; $i < 8; $i++) | ||
| 521 : | t $makepass .= $salt[mt_rand(0,$len - 1)]; | ||
| 522 : | t return $makepass; | ||
| 523 : | t } | ||
| 524 : | t | ||
| 525 : | t if (!function_exists('html_entity_decode')) { | ||
| 526 : | t /** | ||
| 527 : | t * html_entity_decode function for backward compatability in PHP | ||
| 528 : | t * @param string | ||
| 529 : | t * @param string | ||
| 530 : | t */ | ||
| 531 : | t function html_entity_decode ($string, $opt = ENT_COMPAT) { | ||
| 532 : | t | ||
| 533 : | t $trans_tbl = get_html_translation_table (HTML_ENTITIES); | ||
| 534 : | t $trans_tbl = array_flip ($trans_tbl); | ||
| 535 : | t | ||
| 536 : | t if ($opt & 1) { // Translating single quotes | ||
| 537 : | t // Add single quote to translation table; | ||
| 538 : | t // doesn't appear to be there by default | ||
| 539 : | t $trans_tbl["'"] = "'"; | ||
| 540 : | t } | ||
| 541 : | t | ||
| 542 : | t if (!($opt & 2)) { // Not translating double quotes | ||
| 543 : | t // Remove double quote from translation table | ||
| 544 : | t unset($trans_tbl["""]); | ||
| 545 : | t } | ||
| 546 : | t | ||
| 547 : | t return strtr ($string, $trans_tbl); | ||
| 548 : | t } | ||
| 549 : | t } | ||
| 550 : | t | ||
| 551 : | t ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

