parsing status_noauth works generally
authorChristian Weiske <cweiske@cweiske.de>
Wed, 15 Dec 2010 07:08:14 +0000 (08:08 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 15 Dec 2010 07:08:14 +0000 (08:08 +0100)
Wrt3g/HtmlParser.php

index d887671fb3e931b6a9a933391b5fd18a6af93364..c40f117a9d77eedd3a94677100d54d2b0cccae9f 100644 (file)
@@ -21,6 +21,12 @@ class Wrt3g_HtmlParser
         'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
         'GPRS_MSG.GOOD'        => 'good',
         'GPRS_MSG.EXCELLENT'   => 'excellent',
+        'GPRS_MSG.CTIME'       => 'connection time',
+        'GPRS_MSG.CFW'         => 'card firmware',
+        'GPRS_MSG.CMOD'        => 'card model',
+        'GPRS_MSG.CREV'        => 'card revision',
+        'GPRS_MSG.IMSI'        => 'IMSI',
+        'GPRS_MSG.SESSIONUSAGE' => 'session usage',
     );
 
 
@@ -118,30 +124,56 @@ class Wrt3g_HtmlParser
             array('&nbsp;', '</font>', '<script>', '</script>'),
             '', $body
         );
-        //var_dump($body);die();
+
         $doc = new DomDocument();
         libxml_use_internal_errors(true);//html is broken
         $doc->loadHtml($body);
                $xpath = new DOMXPath($doc);
-               $trs = $xpath->query('//table//table/tbody/tr');
+               $trs   = $xpath->query('//table//table/tbody/tr');
+        $arRaw = array();
         foreach ($trs as $tr) {
-            /*
-            var_dump(
-                '--------',$doc->saveXML($tr),
-                $xpath->query('td', $tr)->length);
-            */
             $titleItems = $xpath->query('td[@width=125]/text()', $tr);
             $valueItems = $xpath->query('td[@width=296]/*[1]', $tr);
             if ($titleItems->length && $valueItems->length) {
                 $title = substr($doc->saveXML($titleItems->item(0)), 8, -2);
                 $value = $doc->saveXML($valueItems->item(0));
-            
-                var_dump(
-                    $title, $value
-                );
+                $arRaw[self::$arTranslations[$title]] = $value;
             }
         }
 
-        $arMatches = array();
+        foreach ($arRaw as $key => &$value) {
+            $value = trim(strip_tags($value));
+            if (substr($value, 0, 8) == 'Capture(') {
+                $value = self::$arTranslations[substr($value, 8, -1)];
+            }
+        }
+        unset($value);
+
+        if (isset($arRaw['connection time'])) {
+            $arRaw['connection time'] = str_replace(
+                array(
+                    ' Capture(GPRS_MSG.HOURS)',
+                    ' Capture(GPRS_MSG.MINUTE)',
+                    ' Capture(GPRS_MSG.SECOND)',
+                ),
+                array(
+                    'h', 'm', 's'
+                ),
+                $arRaw['connection time']
+            );
+        }
+
+        if (isset($arRaw['session usage'])) {
+            $arS = explode(
+                'TX = ',
+                str_replace('RX = ', '', $arRaw['session usage'])
+            );
+            $arRaw['session usage'] = array(
+                'received' => $arS[0],
+                'sent'     => $arS[1]
+            );
+        }
+
+        return $arRaw;
     }
 }
\ No newline at end of file