[TYPO3-ect] div functions
Steve Ryan
stever at syntithenai.com
Fri Jan 12 16:15:54 CET 2007
Hi Elmar, any of these useful for the div class ?
Could be some of it is already there in the core ?
cheers
Steve Ryan
class mydiv {
/***************************************************************
* Merge two arrays, correctly recursing down through arbitrary depth
of sub arrays
* @param array base array
* @param array array to merge
* @return array merged array
***************************************************************/
function recursiveArrayMerge($basearray,$overridearray) {
//debug(array('override ',$basearray,'with ',$overridearray));
if (!is_array($overridearray)) $overridearray=array();
foreach ($overridearray as $key => $value) {
if (is_array($value)) {
$basearray[$key]=
tx_admininterface_misc::recursiveArrayMerge($basearray[$key], $value);
}
else {
$basearray[$key]= $value;
}
}
//debug(array('result ',$basearray));
return $basearray;
}
/***************************************************************
* Merge two arrays, correctly recursing down through arbitrary depth
of sub arrays
* @param array base array
* @param array array to merge
* @return array merged array
***************************************************************/
function recursiveArrayToLowerCase($source) {
$basearray=array();
foreach ($source as $key => $value) {
if (is_array($value)) {
$basearray[strtolower($key)]=
tx_admininterface_misc::recursiveArrayToLowerCase($value);
}
else {
$basearray[strtolower($key)]= $value;
}
}
return $basearray;
}
/**
* Remove full stops on keys from a typoscript configuration array
* @param array Incoming
* @return array Fixed array
*/
function removeDotsFromTS($in) {
if (!is_array($in)) $in=array();
foreach ($in as $key => $value) {
if (is_array($value)) {
$out[preg_replace('/(.*)\./', '$1', $key)]=
tx_admininterface_misc::removeDotsFromTS($value);
}
else {
$out[$key]= $value;
}
}
return $out;
}
/**
* Detects if content is HTML (looking for <html> tag as first and last
in string)
*
* @param string Content string to test
* @return boolean Returns true if the content begins and ends with
<html></html>-tags
*/
function isHTMLContent($c) {
$c = trim($c);
$first = strtolower(substr($c,0,6));
$last = strtolower(substr($c,-7));
if ($first.$last=='<html></html>') return 1;
}
/**
* Determine if a bit is turned on in a given value.
* @param int bit to test
* @param int value to do bitwise testing on
* @return boolean true if requested bit is enabled in the integer value
*/
function isBitwiseOptionEnabled($option,$value) {
$pos=($option-1);
$pwer=pow(2,$pos);
$res=(boolean)($value & $pwer);
return $res;
}
/**
* Generate a random password with upper and lower case letters and up
to one number
* @return text containing random password
*/
function getRandomPassword() {
$pass='';
$j=3;
for ($i=0; $i < 6; $i++) {
$type=rand(1,$i);
switch ($type) {
// lowercase
case 1:
$pass.= chr(rand(97,122));
break;
// uppercase
case 2:
$pass.= chr(rand(65,90));
break;
// number
case 3:
$pass.= chr(rand(48,57));
// just one number in password
$j=2;
break;
}
}
return $pass;
}
/**
* Get a relative url from a string in the form EXT:trade/???
* @param string file reference string in the form EXT:trade/???
* @return string relative url to requested resource
*/
function getFileName($val) {
$parts=explode('/',$val);
foreach ($parts as $pK => $pV) {
if (substr($pV,0,4)=='EXT:') {
$parts[$pK]=substr(t3lib_extMgm::extPath(substr($pV,4)),strlen(PATH_site));
$parts[$pK]=substr($parts[$pK],0,strlen($parts[$pK])-1);
}
}
$val2=implode('/',$parts);
return $val2;
}
}
More information about the TYPO3-team-extension-coordination
mailing list