.
if (!defined('EG')) die('Direct access not allowed!');
function encodeUrl($url)
{
$url = str_replace(' ','-',$url);
$url = urlencode($url);
// $url = html_entity_decode($url, ENT_QUOTES);
// $url = xml_encode($url);
return $url;
}
function smartDate($uglyDate = null, $lang = 'en')
{
switch ($lang)
{
case 'en':
$smDate = date('H:i, d F Y',strtotime($uglyDate));
break;
default:
$smDate = date('H:i, d F Y',strtotime($uglyDate));
}
return $smDate;
}
function sanitizeString($string)
{
$string = preg_match('/^[a-zA-Z0-9\-\_\.\+\s]+$/',$string) ? sanitizeAll($string) : 'undef';
return $string;
}
function sanitizeAlphanum($string)
{
$string = ctype_alnum($string) ? sanitizeAll($string) : 'undef';
return $string;
}
function getOrderByClause($string)
{
switch ($string)
{
case 'last-inserted':
$orderBy = 'hardware.id_hard desc';
break;
case 'alphabetically':
$orderBy = 'model';
break;
case 'alphabetically-desc':
$orderBy = 'model desc';
break;
case 'compatibility':
$orderBy = 'compatibility';
break;
case 'undef':
$orderBy = 'hardware.id_hard desc';
break;
default:
$orderBy = 'hardware.id_hard desc';
}
return $orderBy;
}
// function isEqual($str1, $str2)
// {
// // $str1 = str_replace("\n",'',$str1);
// // $str1 = str_replace("\r",null,$str1);
// // $str2 = str_replace("\n",'',$str1);
// // $str2 = str_replace("\r",null,$str1);
//
// return (strcmp($str1,$str2) === 0) ? true : false;
// }
//
// function getNewKeys($array,$ovalue)
// {
// $res = array();
// for ($i = 0; $i < count($array); $i++)
// {
// if (isEqual($array[$i],$ovalue)) $res[] = $i;
// // if (strcmp($keys[$i],$ovalue) === 0) $res[] = $i;
// }
// return $res;
// }
function diff($old, $new){
$maxlen = 0;
foreach($old as $oindex => $ovalue){
// $nkeys = getNewKeys($new,$ovalue);
$nkeys = array_keys($new, $ovalue);
foreach($nkeys as $nindex){
$matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ?
$matrix[$oindex - 1][$nindex - 1] + 1 : 1;
if($matrix[$oindex][$nindex] > $maxlen){
$maxlen = $matrix[$oindex][$nindex];
$omax = $oindex + 1 - $maxlen;
$nmax = $nindex + 1 - $maxlen;
}
}
}
if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
return array_merge(
diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
array_slice($new, $nmax, $maxlen),
diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}
function htmlDiff($old, $new){
$old = str_replace("\r\n"," \r\n ",$old);
$new = str_replace("\r\n"," \r\n ",$new);
$ret = null;
$diff = diff(explode(' ', $old), explode(' ', $new));
foreach($diff as $k){
if(is_array($k))
$ret .= (!empty($k['d'])?"".implode(' ',$k['d'])." ":'').
(!empty($k['i'])?"".implode(' ',$k['i'])." ":'');
else $ret .= $k . ' ';
}
return $ret;
}
//a cosa serve?
function applyBreaks($values,$fields)
{
$fieldsArray = explode(',',$fields);
foreach ($fieldsArray as $field)
{
if (array_key_exists($field,$values))
{
$values[$field] = nl2br($values[$field]);
}
}
return $values;
}
function getLinkToUser($user)
{
if (strstr($user,'__'))
{
return str_replace('__',null,$user);
}
else
{
return "$user";
}
}
//decode the text of the wiki
function decodeWikiText($string)
{
$string = preg_replace('/(\[hr\])/', '
${2}',$string); $string = preg_replace('/(\[p\])(.*?)(\[\/p\])/s', '
${2}
',$string); $string = preg_replace('/(\[h1\])(.*?)(\[\/h1\])/s', '