.
* @param $sTitle
* Value of the title
attribute of the
* a
element. Unused if not provided
* or empty. The default is 'PointedEars'.
* @param $sToName
* Name to be used in the To header of the e-mail.
* Note that @link{rawurlencode()} is used to escape
* special characters automatically.
* The default is "Thomas 'PointedEars' Lahn".
*
* @return
* The converted argument if the condition applies,
* the unconverted argument otherwise.
*/
function mailto_link(
$sAddress = 'selfhtml.de@PointedEars.de',
$sTitle = 'PointedEars',
$sToName = "Thomas 'PointedEars' Lahn",
$sSubject = 'SELFbug',
$sImgPath = '../../media/mail.gif'
)
{
//width="14" height="15" // image size detection not yet implemented
return ($sImgPath != ''
? ' '
: '')
. '' . (($sTitle != '') ? $sTitle : $sAddress) . '';
}
// map bug states to numbers so that they become comparable
function array_values_to_keys($a)
{
$aNew = array();
foreach ($a as $key => $value)
{
$aNew[$value] = count($aNew);
}
return $aNew;
}
/**
* Maps an array to another array using a callback function.
*
* Unlike array_map(), the callback is called with three parameters: the value
* to be processed, the key of that value, and the array processed. The return
* value of the callback defines the value for the same key of the returned
* array.
*
* Because of the way the callback is called, this method supports processing
* only one array at a time, unlike array_map(). Unlike array_walk(), this
* function does not modify the original array.
*
* @param string|array $callback
* The callback to be used for mapping array values. If an array, the first
* element of the array is supposed to be the class name, and the second
* element the method name of a static method to be used.
* @param array $array
* The array to process
* @return array
* @see array_map()
* @see array_walk()
*/
function array_map2($callback, $array)
{
$a = array();
if (is_array($callback))
{
list($class, $method) = $callback;
}
foreach ($array as $key => &$value)
{
if (is_array($callback))
{
$a[$key] = $class::$method($value, $key, $array);
}
else
{
$a[$key] = $callback($value, $key, $array);
}
}
return $a;
}
/**
* Converts a string or an array of strings to an associative
* bitmask array with the string(s) as key(s).
*
* Converts the argument to a bitmask array where each member's
* value is a power of 2, so that arbitrary member values can be
* added to an integer on which bitwise operations with the member
* value or a combination of member values are possible.
*
* @author (c) 2003 Thomas Lahn <SELFbug@PointedEars.de>
* @param $aArray
* String or array of strings to be converted.
*/
function getBitmaskArray($aArray)
{
$a = array();
if (is_array($aArray))
{
for ($i = 0; $i < count($aArray); $i++)
{
$a[$aArray[$i]] = pow(2, $i);
}
}
else
$a[$aArray] = 1;
return $a;
}
/**
* Returns the contents of a file as if include() was used.
*
* @param string $filename Path of the file to retrieve
* @return string File contents
*/
function get_include_content($filename)
{
if (is_file($filename))
{
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return '';
}
/**
* Replaces each group of expressions in a string with the same
* corresponding string.
*
* @param Array[Array[string] | string, string] $map
* @param string $subject
* @return string
* A copy of $subject with the provided mapping applied.
*/
function preg_replace_group($map = array(), $subject = '')
{
if ($subject)
{
for ($i = 0, $len = count($map); $i < $len; $i++)
{
$subject = preg_replace($map[$i][0], $map[$i][1], $subject);
}
}
return $subject;
}
/**
* Randomly encodes a string of characters.
*
* @param string $s
* String to be encoded
* @param string $format = 'sgml'
* Encoding format. Currently only SGML-based encoding of
* ASCII characters with character references is supported.
* @return string
*/
function randomEsc($s = '', $format = 'sgml')
{
$f = function_exists('mt_rand') ? 'mt_rand' : 'rand';
return preg_replace_callback('/[\\x00-\\x7F]/',
create_function('$m', "return $f(0, 1)" . '? $m[0] : "" . ord($m[0]) . ";";'),
$s);
}
/**
* Reduces sequences of two or more consecutive white-space characters
* in an input to a single space.
*
* @param string $s
* @return string
*/
function reduceWhitespace($s)
{
return preg_replace('/\s{2,}/', ' ', $s);
}
function debug($x)
{
echo '';
// if (is_array($x))
// {
// print_r($x);
// }
// else
// {
var_dump($x);
// }
echo '
';
}