Odyssey
hcuAppCommon.i
1 <?php
2 /**
3  * GetAppConfig reads appconfig.xml for client
4  *
5  * @param string $Cu HomeCU client code
6  * @param string $filename base filename of appconfig file
7  * @return string contents of appconfig.xml
8  */
9 function GetAppConfig($Cu, $filename) {
10  try {
11  if (empty($Cu) || empty($filename)) {
12  throw new Exception("Missing Parameters");
13  }
14 
15  $appfile = "/home/" . strtolower($Cu) . "/public_html/{$filename}";
16  if (!file_exists($appfile) || !is_readable($appfile)) {
17  throw new Exception("Appconfig $appfile not found");
18  }
19 
20  $appconfig = file_get_contents($appfile);
21  # parse as xml
22  # file needs to be stored as valid XML, including HTMLEntity encoding of
23  # special characters
24 // $apparray = unserialize_xml($appconfig, 'xmlclean');
25 // return (array)$apparray;
26  } catch (Exception $e) {
27  $appconfig = '';
28  }
29 
30  return $appconfig;
31 }
32 
33 /**
34  * GetAppMenu reads appconfig.xml for client
35  * returns <menu> block. Assumes updated Odyssey format
36  * with mobilepay, estatements, alerts, messages, rating, rdc, sso pushed down
37  * into the <menu> block.
38  * Also, occurances of '...check' tags become 'filter' and
39  * 'locatorCode' tags become 'mbracct'
40  *
41  * @param string $Cu HomeCU client code
42  * @param string $filename base filename of appconfig file
43  * @return array representation of <menu> block from appconfig.xml
44  */
45 function GetAppMenu($Cu, $filename) {
46 
47  $appconfig = GetAppConfig($Cu, $filename);
48  $apparray = unserialize_xml($appconfig, 'xmlclean');
49  $appmenu = HCU_array_key_value('menu',$apparray);
50 
51  $rawmenu = substr($appconfig,0,stripos($appconfig,'</menu>'));
52  $rawmenu = substr($rawmenu,stripos($appconfig,'<menu>')+6);
53 
54  return $rawmenu;
55 // return htmlentities($rawmenu, ENT_NOQUOTES | ENT_XML1, 'UTF-8', TRUE);
56 // return $appmenu;
57 }
58 
59 function unserialize_xml($input, $callback = null, $recurse = false)
60 /* bool/array unserialize_xml ( string $input [ , callback $callback ] )
61 * Unserializes an XML string, returning a multi-dimensional associative array, optionally runs a callback on all non-array data
62 * Returns false on all failure
63 * Notes:
64  * Root XML tags are stripped
65  * Due to its recursive nature, unserialize_xml() will also support SimpleXMLElement objects and arrays as input
66  * Uses simplexml_load_string() for XML parsing, see SimpleXML documentation for more info
67 */
68 {
69  // Get input, loading an xml string with simplexml if its the top level of recursion
70  $data = ((!$recurse) && is_string($input))? simplexml_load_string($input): $input;
71  // Convert SimpleXMLElements to array
72  if ($data instanceof SimpleXMLElement) $data = (array) $data;
73  // Recurse into arrays
74  if (is_array($data)) foreach ($data as &$item) $item = unserialize_xml($item, $callback, true);
75  // Run callback and return
76  return (!is_array($data) && is_callable($callback))? call_user_func($callback, $data): $data;
77 }
78 
79 function xmlclean($data) {
80  return htmlentities($data, ENT_NOQUOTES | ENT_XML1, 'UTF-8', FALSE);
81 }
82 ?>