make the tests work by implementing proper html parsing :/
[linksys-wrt3g-tools.git] / Wrt3g / HtmlParser.php
index 03ac5742bd1b11090bfe9d3f5aa9945fc7143f95..970b1701013a8c55b69a05bcd02c900c89b18c80 100644 (file)
@@ -19,6 +19,8 @@ class Wrt3g_HtmlParser
         'GPRS_MSG.ACQUIRING'   => 'aquiring',
         'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
         'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
         'GPRS_MSG.ACQUIRING'   => 'aquiring',
         'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
         'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
+        'GPRS_MSG.GOOD'        => 'good',
+        'GPRS_MSG.EXCELLENT'   => 'excellent',
     );
 
 
     );
 
 
@@ -32,14 +34,39 @@ class Wrt3g_HtmlParser
     */
     public function index_wstatus1($body)
     {
     */
     public function index_wstatus1($body)
     {
-        $arRetval = array();
+        $doc = new DomDocument();
+        $doc->loadHtml($body);
+               $xpath = new DOMXPath($doc);
+               $entries = $xpath->query('//table/tr/td');
+
         $arMatches = array();
         $arMatches = array();
-        preg_match_all('#>Capture\(([^)]+)\)</#', $body, $arMatches);
+               foreach ($entries as $entry) {
+            $s = $doc->saveXML($entry);
+            $s = str_replace(
+                array('<![CDATA[', ']]>'),
+                '', $s
+            );
+            $s = strip_tags($s);
+            //some strange utf8 space char
+            $s = str_replace("\xC2\xA0", ' ', $s);
+            $s = trim($s);
+            $s = str_replace(
+                array('Capture(', ') :'),
+                '', $s
+            );
+            if (substr($s, -1) == ')') {
+                $s = substr($s, 0, -1);
+            }
+            $arMatches[] = $s;
+        }
+
+
+        $arRetval = array();
         $arData = array();
         $arData = array();
-        reset($arMatches[1]);
-        while (current($arMatches[1])) {
-            $key   = current($arMatches[1]);
-            $value = next($arMatches[1]);
+        reset($arMatches);
+        while (current($arMatches)) {
+            $key   = current($arMatches);
+            $value = next($arMatches);
             if (isset(self::$arTranslations[$key])) {
                 $key = self::$arTranslations[$key];
             }
             if (isset(self::$arTranslations[$key])) {
                 $key = self::$arTranslations[$key];
             }
@@ -47,7 +74,7 @@ class Wrt3g_HtmlParser
                 $value = self::$arTranslations[$value];
             }
             $arRetval[$key] = $value;
                 $value = self::$arTranslations[$value];
             }
             $arRetval[$key] = $value;
-            next($arMatches[1]);
+            next($arMatches);
         }
 
         return $arRetval;
         }
 
         return $arRetval;