| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* Sorts an Array of objects |
* Sorts an Array of objects |
|
*/ |
|
|
function SortArrayObjects_cmp( &$a, &$b ) { |
|
|
global $csort_cmp; |
|
|
|
|
|
if ( $a->$csort_cmp['key'] > $b->$csort_cmp['key'] ) { |
|
|
return $csort_cmp['direction']; |
|
|
} |
|
|
|
|
|
if ( $a->$csort_cmp['key'] < $b->$csort_cmp['key'] ) { |
|
|
return -1 * $csort_cmp['direction']; |
|
|
} |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Sorts an Array of objects |
|
| 5 |
* sort_direction [1 = Ascending] [-1 = Descending] |
* sort_direction [1 = Ascending] [-1 = Descending] |
| 6 |
*/ |
*/ |
| 7 |
function SortArrayObjects( &$a, $k, $sort_direction=1 ) { |
function SortArrayObjects( &$a, $k, $sort_direction=1 ) { |
| 8 |
global $csort_cmp; |
$sorter =& new mosObjectSorter($a, $k, $sort_direction); |
|
|
|
|
$csort_cmp = array( |
|
|
'key' => $k, |
|
|
'direction' => $sort_direction |
|
|
); |
|
|
|
|
|
usort( $a, 'SortArrayObjects_cmp' ); |
|
|
|
|
|
unset( $csort_cmp ); |
|
| 9 |
} |
} |
| 10 |
|
|
| 11 |
/** |
/** |
| 12 |
* Sends mail to admin |
* Sends mail to admin |
| 13 |
|
* Deprecated - not used in Mambo (code copied into weblinks.php) |
| 14 |
|
* Could do with a better facility that works out who to send it to as well |
| 15 |
|
* Note the "email" parameter was not used in the earlier version |
| 16 |
*/ |
*/ |
| 17 |
function mosSendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author ) { |
function mosSendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author ) { |
| 18 |
global $mosConfig_live_site; |
$mosConfig_live_site = mamboCore::get('mosConfig_live_site'); |
| 19 |
|
$from = mamboCore::get('mosConfig_mailfrom'); |
| 20 |
|
$fromname = mamboCore::get('mosConfig_fromname'); |
| 21 |
$subject = _MAIL_SUB." '$type'"; |
$subject = _MAIL_SUB." '$type'"; |
| 22 |
$message = _MAIL_MSG; |
$message = _MAIL_MSG; |
| 23 |
eval ("\$message = \"$message\";"); |
eval ("\$message = \"$message\";"); |
| 24 |
mosMail($mosConfig_mailfrom, $mosConfig_fromname, $adminEmail, $subject, $message); |
require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpmailer/class.phpmailer.php'); |
| 25 |
|
$mail =& new mosMailer ($from, $fromname, $subject, $message); |
| 26 |
|
return $mail->mosMail($adminEmail); |
| 27 |
} |
} |
| 28 |
|
|
| 29 |
/* |
/* |
| 30 |
* Includes pathway file |
* Includes pathway file |
| 31 |
|
* Needed by templates |
| 32 |
*/ |
*/ |
| 33 |
function mosPathWay() { |
function mosPathWay() { |
| 34 |
require mamboCore::get('mosConfig_absolute_path').'/includes/pathway.php'; |
$pathway = mosPathway::getInstance(); |
| 35 |
|
echo $pathway->makePathway(); |
| 36 |
} |
} |
| 37 |
|
|
| 38 |
/** |
/** |
| 53 |
* Replaces & with & for xhtml compliance |
* Replaces & with & for xhtml compliance |
| 54 |
* |
* |
| 55 |
* Needed to handle unicode conflicts due to unicode conflicts |
* Needed to handle unicode conflicts due to unicode conflicts |
| 56 |
|
* Deprecated - simply code the line below |
| 57 |
*/ |
*/ |
| 58 |
function ampReplace( $text ) { |
function ampReplace( $text ) { |
| 59 |
$text = str_replace( '&#', '*-*', $text ); |
return preg_replace('/(&)([^#]|$)/','&$2', $text); |
|
$text = str_replace( '&', '&', $text ); |
|
|
$text = str_replace( '*-*', '&#', $text ); |
|
|
|
|
|
return $text; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Prepares results from search for display |
|
|
* @param string The source string |
|
|
* @param int Number of chars to trim |
|
|
* @param string The searchword to select around |
|
|
* @return string |
|
|
*/ |
|
|
function mosPrepareSearchContent( $text, $length=200, $searchword ) { |
|
|
// strips tags won't remove the actual jscript |
|
|
$text = preg_replace( "'<script[^>]*>.*?</script>'si", "", $text ); |
|
|
$text = preg_replace( '/{.+?}/', '', $text); |
|
|
//$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text ); |
|
|
return mosSmartSubstr( strip_tags( $text ), $length, $searchword ); |
|
|
} |
|
|
|
|
|
/** |
|
|
* returns substring of characters around a searchword |
|
|
* @param string The source string |
|
|
* @param int Number of chars to return |
|
|
* @param string The searchword to select around |
|
|
* @return string |
|
|
*/ |
|
|
function mosSmartSubstr($text, $length=200, $searchword) { |
|
|
$wordpos = strpos(strtolower($text), strtolower($searchword)); |
|
|
$halfside = intval($wordpos - $length/2 - strlen($searchword)); |
|
|
if ($wordpos && $halfside > 0) { |
|
|
return '...' . substr($text, $halfside, $length); |
|
|
} else { |
|
|
return substr( $text, 0, $length); |
|
|
} |
|
| 60 |
} |
} |
| 61 |
|
|
| 62 |
/** |
/** |
| 68 |
*/ |
*/ |
| 69 |
function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL) |
function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL) |
| 70 |
{ |
{ |
| 71 |
$ret = TRUE; |
$fileman = mosFileManager::getInstance(); |
| 72 |
if (is_dir($path)) { |
return $fileman->mosChmodRecursive($path, $filemode, $dirmode); |
| 73 |
$dh = opendir($path); |
} |
|
while ($file = readdir($dh)) { |
|
|
if ($file != '.' && $file != '..') { |
|
|
$fullpath = $path.'/'.$file; |
|
|
if (is_dir($fullpath)) { |
|
|
if (!mosChmodRecursive($fullpath, $filemode, $dirmode)) |
|
|
$ret = FALSE; |
|
|
} else { |
|
|
if (isset($filemode)) |
|
|
if (!@chmod($fullpath, $filemode)) |
|
|
$ret = FALSE; |
|
|
} // if |
|
|
} // if |
|
|
} // while |
|
|
closedir($dh); |
|
|
if (isset($dirmode)) |
|
|
if (!@chmod($path, $dirmode)) |
|
|
$ret = FALSE; |
|
|
} else { |
|
|
if (isset($filemode)) |
|
|
$ret = @chmod($path, $filemode); |
|
|
} // if |
|
|
return $ret; |
|
|
} // mosChmodRecursive |
|
| 74 |
|
|
| 75 |
/** |
/** |
| 76 |
* Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up. |
* Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up. |
| 81 |
*/ |
*/ |
| 82 |
function mosChmod($path) |
function mosChmod($path) |
| 83 |
{ |
{ |
| 84 |
global $mosConfig_fileperms, $mosConfig_dirperms; |
$fileman = mosFileManager::getInstance(); |
| 85 |
$filemode = NULL; |
return $fileman->mosChmod($path); |
|
if ($mosConfig_fileperms != '') |
|
|
$filemode = octdec($mosConfig_fileperms); |
|
|
$dirmode = NULL; |
|
|
if ($mosConfig_dirperms != '') |
|
|
$dirmode = octdec($mosConfig_dirperms); |
|
|
if (isset($filemode) || isset($dirmode)) |
|
|
return mosChmodRecursive($path, $filemode, $dirmode); |
|
|
return TRUE; |
|
| 86 |
} // mosChmod |
} // mosChmod |
| 87 |
|
|
| 88 |
/** |
/** |
| 89 |
* Function to convert array to integer values |
* Function to convert array to integer values |
| 90 |
|
* Deprecated - not used within Mambo |
| 91 |
*/ |
*/ |
| 92 |
function mosArrayToInts( &$array, $default=null ) { |
function mosArrayToInts( &$array, $default=null ) { |
| 93 |
if (is_array( $array )) { |
if (is_array( $array )) { |
| 110 |
*/ |
*/ |
| 111 |
function mosStripslashes(&$value) |
function mosStripslashes(&$value) |
| 112 |
{ |
{ |
| 113 |
$ret = ''; |
$database = mamboDatabase::getInstance(); |
| 114 |
if (is_string($value)) { |
return $database->mosStripslashes($value); |
| 115 |
$ret = stripslashes($value); |
} |
|
} else { |
|
|
if (is_array($value)) { |
|
|
$ret = array(); |
|
|
while (list($key,$val) = each($value)) { |
|
|
$ret[$key] = mosStripslashes($val); |
|
|
} // while |
|
|
} else { |
|
|
$ret = $value; |
|
|
} // if |
|
|
} // if |
|
|
return $ret; |
|
|
} // mosStripSlashes |
|
| 116 |
|
|
| 117 |
/** |
/** |
| 118 |
* Copy the named array content into the object as properties |
* Copy the named array content into the object as properties |
| 135 |
* @param boolean True if to prepend the full path to the file name |
* @param boolean True if to prepend the full path to the file name |
| 136 |
*/ |
*/ |
| 137 |
function mosReadDirectory( $path, $filter='.', $recurse=false, $fullpath=false ) { |
function mosReadDirectory( $path, $filter='.', $recurse=false, $fullpath=false ) { |
| 138 |
$arr = array(); |
if (@is_dir($path)) { |
| 139 |
if (!@is_dir( $path )) { |
$dir =& new mosDirectory($path); |
| 140 |
return $arr; |
$arr = $dir->listFiles ($filter, $type='file', $recurse, $fullpath); |
|
} |
|
|
$handle = opendir( $path ); |
|
|
|
|
|
while ($file = readdir($handle)) { |
|
|
$dir = mosPathName( $path.'/'.$file, false ); |
|
|
$isDir = is_dir( $dir ); |
|
|
if (($file <> ".") && ($file <> "..")) { |
|
|
if (preg_match( "/$filter/", $file )) { |
|
|
if ($fullpath) { |
|
|
$arr[] = trim( mosPathName( $path.'/'.$file, false ) ); |
|
|
} else { |
|
|
$arr[] = trim( $file ); |
|
|
} |
|
| 141 |
} |
} |
| 142 |
if ($recurse && $isDir) { |
else $arr = array(); |
|
$arr2 = mosReadDirectory( $dir, $filter, $recurse, $fullpath ); |
|
|
$arr = array_merge( $arr, $arr2 ); |
|
|
} |
|
|
} |
|
|
} |
|
|
closedir($handle); |
|
|
asort($arr); |
|
| 143 |
return $arr; |
return $arr; |
| 144 |
} |
} |
| 145 |
|
|
| 160 |
* @param boolean Add trailing slash |
* @param boolean Add trailing slash |
| 161 |
*/ |
*/ |
| 162 |
function mosPathName($p_path,$p_addtrailingslash = true) { |
function mosPathName($p_path,$p_addtrailingslash = true) { |
| 163 |
$retval = ""; |
$fileman = mosFileManager::getInstance(); |
| 164 |
|
return $fileman->mosPathName($p_path,$p_addtrailingslash); |
|
$isWin = (substr(PHP_OS, 0, 3) == 'WIN'); |
|
|
|
|
|
if ($isWin) { |
|
|
$retval = str_replace( '/', '\\', $p_path ); |
|
|
if ($p_addtrailingslash) { |
|
|
if (substr( $retval, -1 ) != '\\') { |
|
|
$retval .= '\\'; |
|
|
} |
|
|
} |
|
|
// Remove double \\ |
|
|
$retval = str_replace( '\\\\', '\\', $retval ); |
|
|
} else { |
|
|
$retval = str_replace( '\\', '/', $p_path ); |
|
|
if ($p_addtrailingslash) { |
|
|
if (substr( $retval, -1 ) != '/') { |
|
|
$retval .= '/'; |
|
|
} |
|
|
} |
|
|
// Remove double // |
|
|
$retval = str_replace('//','/',$retval); |
|
|
} |
|
|
|
|
|
return $retval; |
|
| 165 |
} |
} |
| 166 |
|
|
| 167 |
/** |
/** |
| 375 |
* @return password |
* @return password |
| 376 |
*/ |
*/ |
| 377 |
function mosMakePassword() { |
function mosMakePassword() { |
| 378 |
$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php'); |
| 379 |
$len = strlen($salt); |
$authenticator = mamboAuthenticator::getInstance(); |
| 380 |
$makepass=""; |
return $authenticator->mosMakePassword(); |
|
mt_srand(10000000*(double)microtime()); |
|
|
for ($i = 0; $i < 8; $i++) |
|
|
$makepass .= $salt[mt_rand(0,$len - 1)]; |
|
|
return $makepass; |
|
| 381 |
} |
} |
| 382 |
|
|
| 383 |
if (!function_exists('html_entity_decode')) { |
if (!function_exists('html_entity_decode')) { |