Source for file Utils.class.php

Documentation is available at Utils.class.php

  1. <?php
  2. class Utils {
  3.  
  4. /**
  5. * Make from an XML file an array.
  6. * @return array
  7. */
  8. static public function xml2array($text) {
  9. $reg_exp = '/<(\w+)[^>]*>(.*?)<\/\\1>/s';
  10. preg_match_all($reg_exp, $text, $match);
  11. foreach ($match[1] as $key=>$val) {
  12. if ( preg_match($reg_exp, $match[2][$key]) ) {
  13. $array[$val][] = Utils::xml2array($match[2][$key]);
  14. } else {
  15. $array[$val] = $match[2][$key];
  16. }
  17. }
  18. return $array;
  19. }
  20.  
  21. /**
  22. * Make a pulldown. You can add some onchange (javascript) action with the param $pAction
  23. * @param string $pName
  24. * @param array $pData
  25. * @param string $pSelected
  26. * @param string $pAction
  27. * @return string
  28. */
  29. static public function makePulldown($pName,$pData,$pSelected,$pAction = "") {
  30. if (!$pData) $pData = array(); // Create empty pulldown
  31. $lReturnValue = "<select name=\"" . $pName . "\" id=\"" . $pName . "\" $pAction>\n";
  32. foreach($pData as $KeyValue) {
  33. if (is_array($KeyValue)) {
  34. $lKey = $KeyValue[0];
  35. $lValue = $KeyValue[1];
  36. } else {
  37. $lKey = $lValue = $KeyValue;
  38. }
  39. if (!Settings::getWowzaEnabled() && $lKey == "rtmp") continue;
  40. $lReturnValue .= "<option value=\"" . $lKey . "\" " . ($pSelected == $lKey ? "selected" : "") . ">" . $lValue . "</option>\n";
  41. }
  42. $lReturnValue .= "</select>";
  43. return $lReturnValue;
  44. }
  45.  
  46. /**
  47. * Make some text javascript save. This means escaping the single quote and removing new lines.
  48. * @param string $pText
  49. * @return string
  50. */
  51. static public function JSSave($pText) {
  52. $lSearchArray = array("'","\n");
  53. $lReplaceArray = array("\'"," ");
  54.  
  55. return str_replace($lSearchArray,$lReplaceArray,$pText);
  56. }
  57.  
  58. /**
  59. * Chechk if the user is using Internet Explorer browser
  60. * @return boolean
  61. */
  62. static public function isIE() {
  63. return stripos($_SERVER['HTTP_USER_AGENT'],"MSIE") !== false;
  64. }
  65.  
  66. /**
  67. * Chechk if the user is using Firefox browser
  68. * @return boolean
  69. */
  70. static public function isFF() {
  71. return stripos($_SERVER['HTTP_USER_AGENT'],"firefox") !== false;
  72. }
  73.  
  74. /**
  75. * Check if the user is using a mobile device.
  76. * @return boolean
  77. */
  78. static public function isMobileDevice(){
  79. //Copied from the original source....
  80.  
  81. // check if the user agent value claims to be windows but not windows mobile
  82. if(stristr($_SERVER['HTTP_USER_AGENT'],'windows')&&!stristr($_SERVER['HTTP_USER_AGENT'],'windows ce')){
  83. return false;
  84. }
  85. // check if the user agent gives away any tell tale signs it's a mobile browser
  86. if(eregi('up.browser|up.link|windows ce|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp',$_SERVER['HTTP_USER_AGENT'])){
  87. return true;
  88. }
  89. // check the http accept header to see if wap.wml or wap.xhtml support is claimed
  90. if(stristr($_SERVER['HTTP_ACCEPT'],'text/vnd.wap.wml')||stristr($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml')){
  91. return true;
  92. }
  93. // check if there are any tell tales signs it's a mobile device from the _server headers
  94. if(isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])||isset($_SERVER['X-OperaMini-Features'])||isset($_SERVER['UA-pixels'])){
  95. return true;
  96. }
  97. // build an array with the first four characters from the most common mobile user agents
  98. $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-');
  99. // check if the first four characters of the current user agent are set as a key in the array
  100. if(isset($a[substr($_SERVER['HTTP_USER_AGENT'],0,4)])){
  101. return true;
  102. }
  103. }
  104. }
  105. ?>

Documentation generated on Tue, 24 Jun 2008 18:59:39 +0200 by phpDocumentor 1.3.0RC3