Documentation is available at Utils.class.php
- <?php
- class Utils {
- /**
- * Make from an XML file an array.
- * @return array
- */
- static public function xml2array($text) {
- $reg_exp = '/<(\w+)[^>]*>(.*?)<\/\\1>/s';
- preg_match_all($reg_exp, $text, $match);
- foreach ($match[1] as $key=>$val) {
- if ( preg_match($reg_exp, $match[2][$key]) ) {
- $array[$val][] = Utils::xml2array($match[2][$key]);
- } else {
- $array[$val] = $match[2][$key];
- }
- }
- return $array;
- }
- /**
- * Make a pulldown. You can add some onchange (javascript) action with the param $pAction
- * @param string $pName
- * @param array $pData
- * @param string $pSelected
- * @param string $pAction
- * @return string
- */
- static public function makePulldown($pName,$pData,$pSelected,$pAction = "") {
- if (!$pData) $pData = array(); // Create empty pulldown
- $lReturnValue = "<select name=\"" . $pName . "\" id=\"" . $pName . "\" $pAction>\n";
- foreach($pData as $KeyValue) {
- if (is_array($KeyValue)) {
- $lKey = $KeyValue[0];
- $lValue = $KeyValue[1];
- } else {
- $lKey = $lValue = $KeyValue;
- }
- $lReturnValue .= "<option value=\"" . $lKey . "\" " . ($pSelected == $lKey ? "selected" : "") . ">" . $lValue . "</option>\n";
- }
- $lReturnValue .= "</select>";
- return $lReturnValue;
- }
- /**
- * Make some text javascript save. This means escaping the single quote and removing new lines.
- * @param string $pText
- * @return string
- */
- static public function JSSave($pText) {
- $lSearchArray = array("'","\n");
- $lReplaceArray = array("\'"," ");
- return str_replace($lSearchArray,$lReplaceArray,$pText);
- }
- /**
- * Chechk if the user is using Internet Explorer browser
- * @return boolean
- */
- static public function isIE() {
- return stripos($_SERVER['HTTP_USER_AGENT'],"MSIE") !== false;
- }
- /**
- * Chechk if the user is using Firefox browser
- * @return boolean
- */
- static public function isFF() {
- return stripos($_SERVER['HTTP_USER_AGENT'],"firefox") !== false;
- }
- /**
- * Check if the user is using a mobile device.
- * @return boolean
- */
- static public function isMobileDevice(){
- //Copied from the original source....
- // check if the user agent value claims to be windows but not windows mobile
- if(stristr($_SERVER['HTTP_USER_AGENT'],'windows')&&!stristr($_SERVER['HTTP_USER_AGENT'],'windows ce')){
- return false;
- }
- // check if the user agent gives away any tell tale signs it's a mobile browser
- if(eregi('up.browser|up.link|windows ce|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp',$_SERVER['HTTP_USER_AGENT'])){
- return true;
- }
- // check the http accept header to see if wap.wml or wap.xhtml support is claimed
- if(stristr($_SERVER['HTTP_ACCEPT'],'text/vnd.wap.wml')||stristr($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml')){
- return true;
- }
- // check if there are any tell tales signs it's a mobile device from the _server headers
- if(isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])||isset($_SERVER['X-OperaMini-Features'])||isset($_SERVER['UA-pixels'])){
- return true;
- }
- // build an array with the first four characters from the most common mobile user agents
- $a = array('acs-','alav','alca','amoi','audi','aste','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','opwv','palm','pana','pant','pdxg','phil','play','pluc','port','prox','qtek','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','w3c ','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-');
- // check if the first four characters of the current user agent are set as a key in the array
- if(isset($a[substr($_SERVER['HTTP_USER_AGENT'],0,4)])){
- return true;
- }
- }
- }
- ?>
Documentation generated on Sat, 19 Jan 2008 12:56:20 +0100 by phpDocumentor 1.3.0RC3