<?php
 class HelperBase { function sort($a,$b) { $al = $a['conf']['sort']; $bl = $b['conf']['sort']; if ($al == $bl) { return 0; } return ($al < $bl) ? -1 : +1; } function utf8EncodeArray($A) { if(is_array($A)) { foreach($A as $k => $v) { $A[$k] = $this->utf8EncodeArray($v); } } else if(is_string($A)) { return utf8_encode($A); } else { return $A; } return $A; } function isMobile() { $toCheck = array('iPhone','iPad','Android','webOS','BlackBerry','iPod'); foreach($toCheck as $v) { if(strpos($_SERVER['HTTP_USER_AGENT'],$v)!==false) { return $v; } } if($_GET['isMobile']) { return true; } } function print_rf($array,$n="",$title_only=0) { $a = debug_backtrace(); echo "<div style='text-align:left;font-family:Verdana;font-size:12px;background-color:white;border:1px solid #ccc;padding:10px;margin:3px;color:black'>"; if($n) echo "<b>$n</b>"; if($n AND !$title_only) echo " | "; if(!$title_only) echo "print_rf in ".basename($a[0]["file"]).":".$a[0]["line"]; echo "<pre style='font-family:Verdana'>"; print_r($array); echo "</pre>"; echo "</div>"; } function serialize($v) { $v = $this->rmSpcChars($v); return serialize($v); } function rmSpcChars($v) { if(is_array($v)) { foreach($v as $y => $z) { $v[$y] = $this->rmSpcChars($z); } } else { $v = stripslashes($v); $v = strtr($v,array('"'=>'&quot;',"'"=>'&#039;')); } return $v; } function getAfXBETA($xml) { $x = 0; $attr = $xml->attributes(); if(count($attr)) { foreach($attr as $y => $z) { $R['attr'][$y] = (string)$z; } } if($R['attr'] AND (string)$xml) { $R['data'] = (string)$xml; } else if(!count($xml) AND (string)$xml) { $R = (string)$xml; } foreach ($xml->children() as $k => $v) { $i=0;foreach($v as $x) {$i++;break;} if($i OR count((array)$v->attributes()) OR (is_array($R) AND $R[$k])) { if($R[$k]) { if(!$R[$k][0] OR !is_array($R[$k])) { $tmp = $R[$k]; $R[$k] = array(); $R[$k][] = $tmp; } $R[$k][] = $this->getAfX($v); } else { $R[$k] = $this->getAfX($v); } } else { $R[$k] = (string)$v; } $x++; } return $R; } function getAfX($xml) { $x = 0; $attr = $xml->attributes(); if(count($attr)) { foreach($attr as $y => $z) { $R['attr'][$y] = (string)$z; } } foreach ($xml->children() as $k => $v) { $i=0;foreach($v as $x) {$i++;break;} if($i OR count((array)$v->attributes()) ) { if($R[$k]) { if(!$R[$k][0]) { $tmp = $R[$k]; $R[$k] = array(); $R[$k][] = $tmp; } $R[$k][] = $this->getAfX($v); } else { $R[$k] = $this->getAfX($v); } } else { $R[$k] = (string)$v; } $x++; } return $R; } function getJsSelect($name,$A=array(),$default) { foreach($A as $k => $v) { if(is_numeric($k)) { $k = (string)$k; } $V[] = array($k,$v); } $R = array( 'xtype' => 'combo', 'hiddenName' => $name, 'displayField' => 'n', 'valueField' => 'v', 'forceSelection'=> true, 'queryMode' => 'local', 'editable' => false, 'triggerAction' => 'all', 'value' => $default, 'store' => $V, ); return $R; } function getAbyPath($A,$path=false,$sep='/') { $P = explode($sep,$path); $R = $A; foreach($P as $k) { if(!$k) continue; if(!is_array($R)) { return array(); } $R = $R[$k]; } return $R; } function writeXmlStringAsPhpArray($Xml) { if(is_string($Xml)) { $Xml = $this->getAfX(simplexml_load_string($Xml)); return var_export($Xml,true); } elseif(is_array($Xml)){ return var_export($Xml,true); } } function isValidEmail($v) { if(preg_match('#^[^\\x00-\\x1f@]+@[^\\x00-\\x1f@]{2,}\.[a-z]{2,}$#i',$v)) { return true; } else { return false; } } function removeWhiteSpaces($buffer) { $search = array( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' ); $replace = array( '>', '<', '\\1' ); $buffer = preg_replace($search, $replace, $buffer); return $buffer; } function mergeArray($tpl1,$tpl2) { $tpl = array(); if(is_array($tpl1) AND is_array($tpl2)) { $tpl = array_merge_recursive($tpl1,$tpl2); } else if(!is_array($tpl1)) { $tpl = $tpl2; } else if(!is_array($tpl2)) { $tpl = $tpl1; } return $tpl; } function getArrayAsRows($A) { if(!is_array($A)) return array($A); if(!$A[0]) { $R[0] = $A; } else { $R = $A; } return $R; } } if(floatval(phpversion())>=5) { class Helper extends HelperBase {} } ?>