myFunctions

The XML Google Maps myFunctions class.

Defined (1)

The class is defined in the following location(s).

/xmlgooglemaps_helper.php  
  1. class myFunctions { 
  2.  
  3. function seconds2Text($seconds) { 
  4. $hours = floor($seconds / (60*60)); 
  5. $seconds -= $hours *(60*60); 
  6. $minutes = floor($seconds / 60); 
  7. $seconds -= $minutes*60; 
  8. $seconds = floor($seconds); 
  9. if ($hours != 0) { 
  10. return $hours."h ".str_pad($minutes, 2, "0", STR_PAD_LEFT)."m ".str_pad($seconds, 2, "0", STR_PAD_LEFT)."s"; 
  11. } else { 
  12. if ($minutes != 0) { 
  13. return $minutes."m ".str_pad($seconds, 2, "0", STR_PAD_LEFT)."s"; 
  14. } else { 
  15. return $seconds."s"; 
  16.  
  17. function getSpeedString($measurement, $scale, $distancekm, $timesec) { 
  18. if ($timesec==0) { 
  19. return "-"; 
  20. } else { 
  21. return sprintf("%01.2f", myFunctions::getSpeed($measurement, $scale, $distancekm, $timesec))." ".myFunctions::getSpeedMeasurementString($measurement, $scale); 
  22.  
  23. function getSpeedString2($measurement, $scale, $speed) { 
  24. if (intval($speed)==0) { 
  25. return "-"; 
  26. } else { 
  27. return sprintf("%01.2f", $speed)." ".myFunctions::getSpeedMeasurementString($measurement, $scale); 
  28.  
  29. function getSpeedMeasurementString($measurement, $scale) { 
  30. switch (strtolower($measurement.$scale)) { 
  31. case "imperiallevel2": 
  32. return "mph"; 
  33. break; 
  34. case "imperiallevel1": 
  35. return "fph"; 
  36. break; 
  37. case "metriclevel1": 
  38. return "m/s"; 
  39. break; 
  40. case "nautic_metriclevel1": 
  41. case "nautic_metriclevel2": 
  42. case "nautic_imperiallevel1": 
  43. case "nautic_imperiallevel2": 
  44. return "kn"; 
  45. break; 
  46. default: 
  47. return "km/h"; 
  48. break; 
  49.  
  50. function getSpeed($measurement, $scale, $distancekm, $timesec) 
  51. if ($timesec==0) { 
  52. return 0; 
  53. } else { 
  54. switch (strtolower($measurement.$scale)) { 
  55. case "imperiallevel2": 
  56. return ($distancekm/1.609344) / ($timesec/3600); 
  57. break; 
  58. case "imperiallevel1": 
  59. return ($distancekm/0.3048) / ($timesec); 
  60. break; 
  61. case "metriclevel1": 
  62. return ($distancekm*1000) / ($timesec); 
  63. break; 
  64. case "nautic_metriclevel1": 
  65. case "nautic_metriclevel2": 
  66. case "nautic_imperiallevel1": 
  67. case "nautic_imperiallevel2": 
  68. return ($distancekm/1.852216) / ($timesec/3600); 
  69. break;  
  70. default: 
  71. return ($distancekm) / ($timesec/3600); 
  72. break; 
  73. }  
  74.  
  75. function distBetween2PointsKM($lat1, $lon1, $lat2, $lon2) { 
  76. $lat1 = deg2rad($lat1); 
  77. $lon1 = deg2rad($lon1); 
  78. $lat2 = deg2rad($lat2); 
  79. $lon2 = deg2rad($lon2); 
  80. $ret = rad2deg(acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($lon2 - $lon1))) * 111.1206; 
  81. if (is_nan($ret)) { 
  82. $ret=0; 
  83. return $ret; 
  84.  
  85. function xmlDate2DateTime($value) { 
  86. $value = str_replace("Z", "", $value); 
  87. return strtotime($value); 
  88.  
  89. function colorName2Hex($name) { 
  90. switch (strtolower($name)) { 
  91. case "aliceblue": return "#F0F8FF"; break; 
  92. case "antiquewhite": return "#FAEBD7"; break; 
  93. case "aqua": return "#00FFFF"; break; 
  94. case "aquamarine": return "#7FFFD4"; break; 
  95. case "azure": return "#F0FFFF"; break; 
  96. case "beige": return "#F5F5DC"; break; 
  97. case "bisque": return "#FFE4C4"; break; 
  98. case "black": return "#000000"; break; 
  99. case "blanchedalmond": return "#FFEBCD"; break; 
  100. case "blue": return "#0000FF"; break; 
  101. case "blueviolet": return "#8A2BE2"; break; 
  102. case "brown": return "#A52A2A"; break; 
  103. case "burlywood": return "#DEB887"; break; 
  104. case "cadetblue": return "#5F9EA0"; break; 
  105. case "chartreuse": return "#7FFF00"; break; 
  106. case "chocolate": return "#D2691E"; break; 
  107. case "coral": return "#FF7F50"; break; 
  108. case "cornflowerblue": return "#6495ED"; break; 
  109. case "cornsilk": return "#FFF8DC"; break; 
  110. case "crimson": return "#DC143C"; break; 
  111. case "cyan": return "#00FFFF"; break; 
  112. case "darkblue": return "#00008B"; break; 
  113. case "darkcyan": return "#008B8B"; break; 
  114. case "darkgoldenrod": return "#B8860B"; break; 
  115. case "darkgray": return "#A9A9A9"; break; 
  116. case "darkgrey": return "#A9A9A9"; break; 
  117. case "darkgreen": return "#006400"; break; 
  118. case "darkkhaki": return "#BDB76B"; break; 
  119. case "darkmagenta": return "#8B008B"; break; 
  120. case "darkolivegreen": return "#556B2F"; break; 
  121. case "darkorange": return "#FF8C00"; break; 
  122. case "darkorchid": return "#9932CC"; break; 
  123. case "darkred": return "#8B0000"; break; 
  124. case "darksalmon": return "#E9967A"; break; 
  125. case "darkseagreen": return "#8FBC8F"; break; 
  126. case "darkslateblue": return "#483D8B"; break; 
  127. case "darkslategray": return "#2F4F4F"; break; 
  128. case "darkslategrey": return "#2F4F4F"; break; 
  129. case "darkturquoise": return "#00CED1"; break; 
  130. case "darkviolet": return "#9400D3"; break; 
  131. case "deeppink": return "#FF1493"; break; 
  132. case "deepskyblue": return "#00BFFF"; break; 
  133. case "dimgray": return "#696969"; break; 
  134. case "dimgrey": return "#696969"; break; 
  135. case "dodgerblue": return "#1E90FF"; break; 
  136. case "firebrick": return "#B22222"; break; 
  137. case "floralwhite": return "#FFFAF0"; break; 
  138. case "forestgreen": return "#228B22"; break; 
  139. case "fuchsia": return "#FF00FF"; break; 
  140. case "gainsboro": return "#DCDCDC"; break; 
  141. case "ghostwhite": return "#F8F8FF"; break; 
  142. case "gold": return "#FFD700"; break; 
  143. case "goldenrod": return "#DAA520"; break; 
  144. case "gray": return "#808080"; break; 
  145. case "grey": return "#808080"; break; 
  146. case "green": return "#008000"; break; 
  147. case "greenyellow": return "#ADFF2F"; break; 
  148. case "honeydew": return "#F0FFF0"; break; 
  149. case "hotpink": return "#FF69B4"; break; 
  150. case "indianred ": return "#CD5C5C"; break; 
  151. case "indigo ": return "#4B0082"; break; 
  152. case "ivory": return "#FFFFF0"; break; 
  153. case "khaki": return "#F0E68C"; break; 
  154. case "lavender": return "#E6E6FA"; break; 
  155. case "lavenderblush": return "#FFF0F5"; break; 
  156. case "lawngreen": return "#7CFC00"; break; 
  157. case "lemonchiffon": return "#FFFACD"; break; 
  158. case "lightblue": return "#ADD8E6"; break; 
  159. case "lightcoral": return "#F08080"; break; 
  160. case "lightcyan": return "#E0FFFF"; break; 
  161. case "lightgoldenrodyellow": return "#FAFAD2"; break; 
  162. case "lightgray": return "#D3D3D3"; break; 
  163. case "lightgrey": return "#D3D3D3"; break; 
  164. case "lightgreen": return "#90EE90"; break; 
  165. case "lightpink": return "#FFB6C1"; break; 
  166. case "lightsalmon": return "#FFA07A"; break; 
  167. case "lightseagreen": return "#20B2AA"; break; 
  168. case "lightskyblue": return "#87CEFA"; break; 
  169. case "lightslategray": return "#778899"; break; 
  170. case "lightslategrey": return "#778899"; break; 
  171. case "lightsteelblue": return "#B0C4DE"; break; 
  172. case "lightyellow": return "#FFFFE0"; break; 
  173. case "lime": return "#00FF00"; break; 
  174. case "limegreen": return "#32CD32"; break; 
  175. case "linen": return "#FAF0E6"; break; 
  176. case "magenta": return "#FF00FF"; break; 
  177. case "maroon": return "#800000"; break; 
  178. case "mediumaquamarine": return "#66CDAA"; break; 
  179. case "mediumblue": return "#0000CD"; break; 
  180. case "mediumorchid": return "#BA55D3"; break; 
  181. case "mediumpurple": return "#9370D8"; break; 
  182. case "mediumseagreen": return "#3CB371"; break; 
  183. case "mediumslateblue": return "#7B68EE"; break; 
  184. case "mediumspringgreen": return "#00FA9A"; break; 
  185. case "mediumturquoise": return "#48D1CC"; break; 
  186. case "mediumvioletred": return "#C71585"; break; 
  187. case "midnightblue": return "#191970"; break; 
  188. case "mintcream": return "#F5FFFA"; break; 
  189. case "mistyrose": return "#FFE4E1"; break; 
  190. case "moccasin": return "#FFE4B5"; break; 
  191. case "navajowhite": return "#FFDEAD"; break; 
  192. case "navy": return "#000080"; break; 
  193. case "oldlace": return "#FDF5E6"; break; 
  194. case "olive": return "#808000"; break; 
  195. case "olivedrab": return "#6B8E23"; break; 
  196. case "orange": return "#FFA500"; break; 
  197. case "orangered": return "#FF4500"; break; 
  198. case "orchid": return "#DA70D6"; break; 
  199. case "palegoldenrod": return "#EEE8AA"; break; 
  200. case "palegreen": return "#98FB98"; break; 
  201. case "paleturquoise": return "#AFEEEE"; break; 
  202. case "palevioletred": return "#D87093"; break; 
  203. case "papayawhip": return "#FFEFD5"; break; 
  204. case "peachpuff": return "#FFDAB9"; break; 
  205. case "peru": return "#CD853F"; break; 
  206. case "pink": return "#FFC0CB"; break; 
  207. case "plum": return "#DDA0DD"; break; 
  208. case "powderblue": return "#B0E0E6"; break; 
  209. case "purple": return "#800080"; break; 
  210. case "red": return "#FF0000"; break; 
  211. case "rosybrown": return "#BC8F8F"; break; 
  212. case "royalblue": return "#4169E1"; break; 
  213. case "saddlebrown": return "#8B4513"; break; 
  214. case "salmon": return "#FA8072"; break; 
  215. case "sandybrown": return "#F4A460"; break; 
  216. case "seagreen": return "#2E8B57"; break; 
  217. case "seashell": return "#FFF5EE"; break; 
  218. case "sienna": return "#A0522D"; break; 
  219. case "silver": return "#C0C0C0"; break; 
  220. case "skyblue": return "#87CEEB"; break; 
  221. case "slateblue": return "#6A5ACD"; break; 
  222. case "slategray": return "#708090"; break; 
  223. case "slategrey": return "#708090"; break; 
  224. case "snow": return "#FFFAFA"; break; 
  225. case "springgreen": return "#00FF7F"; break; 
  226. case "steelblue": return "#4682B4"; break; 
  227. case "tan": return "#D2B48C"; break; 
  228. case "teal": return "#008080"; break; 
  229. case "thistle": return "#D8BFD8"; break; 
  230. case "tomato": return "#FF6347"; break; 
  231. case "turquoise": return "#40E0D0"; break; 
  232. case "violet": return "#EE82EE"; break; 
  233. case "wheat": return "#F5DEB3"; break; 
  234. case "white": return "#FFFFFF"; break; 
  235. case "whitesmoke": return "#F5F5F5"; break; 
  236. case "yellow": return "#FFFF00"; break; 
  237. case "yellowgreen": return "#9ACD32"; break; 
  238. default: return $name; break; 
  239.  
  240. function xml2array($contents, $get_attributes=1) { 
  241. if(!$contents) return array(); 
  242.  
  243. if(!function_exists('xml_parser_create')) { 
  244. return array(); 
  245. //Get the XML parser of PHP - PHP must have this module for the parser to work 
  246. $parser = xml_parser_create(); 
  247. xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); 
  248. xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 ); 
  249. xml_parse_into_struct( $parser, $contents, $xml_values ); 
  250. xml_parser_free( $parser ); 
  251.  
  252. if(!$xml_values) return;//Hmm... 
  253.  
  254. //Initializations 
  255. $xml_array = array(); 
  256. $parents = array(); 
  257. $opened_tags = array(); 
  258. $arr = array(); 
  259.  
  260. $current = &$xml_array; 
  261.  
  262. //Go through the tags. 
  263. foreach($xml_values as $data) { 
  264. unset($attributes, $value);//Remove existing values, or there will be trouble 
  265.  
  266. //This command will extract these variables into the foreach scope 
  267. // tag(string), type(string), level(int), attributes(array). 
  268. extract($data);//We could use the array by itself, but this cooler. 
  269. $tag = strtolower($tag); 
  270.  
  271. $result = ''; 
  272. if($get_attributes) {//The second argument of the function decides this. 
  273. $result = array(); 
  274. if(isset($value)) $result['value'] = $value; 
  275.  
  276. //Set the attributes too. 
  277. if(isset($attributes)) { 
  278. foreach($attributes as $attr => $val) { 
  279. if($get_attributes == 1) $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' 
  280. /** :TODO: should we change the key name to '_attr'? Someone may use the tagname 'attr'. Same goes for 'value' too */ 
  281. } elseif(isset($value)) { 
  282. $result = $value; 
  283.  
  284. //See tag status and do the needed. 
  285. if($type == "open") {//The starting of the tag '<tag>' 
  286. $parent[$level-1] = &$current; 
  287.  
  288. if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag 
  289. $current[$tag] = $result; 
  290. $current = &$current[$tag]; 
  291.  
  292. } else { //There was another element with the same tag name 
  293. if(isset($current[$tag][0])) { 
  294. array_push($current[$tag], $result); 
  295. } else { 
  296. $current[$tag] = array($current[$tag], $result); 
  297. $last = count($current[$tag]) - 1; 
  298. $current = &$current[$tag][$last]; 
  299.  
  300. } elseif($type == "complete") { //Tags that ends in 1 line '<tag />' 
  301. //See if the key is already taken. 
  302. if(!isset($current[$tag])) { //New Key 
  303. $current[$tag] = $result; 
  304.  
  305. } else { //If taken, put all things inside a list(array) 
  306. if((is_array($current[$tag]) and $get_attributes == 0)//If it is already an array... 
  307. or (isset($current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)) { 
  308. array_push($current[$tag], $result); // ...push the new element into that array. 
  309. } else { //If it is not an array... 
  310. $current[$tag] = array($current[$tag], $result); //...Make it an array using using the existing value and the new value 
  311.  
  312. } elseif($type == 'close') { //End of tag '</tag>' 
  313. $current = &$parent[$level-1]; 
  314.  
  315. return($xml_array); 
  316.