From a87efca07dc603258fe2f3469302e656d162fa64 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 15 Dec 2010 08:08:14 +0100 Subject: [PATCH] parsing status_noauth works generally --- Wrt3g/HtmlParser.php | 56 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/Wrt3g/HtmlParser.php b/Wrt3g/HtmlParser.php index d887671..c40f117 100644 --- a/Wrt3g/HtmlParser.php +++ b/Wrt3g/HtmlParser.php @@ -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(' ', '', ''), '', $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 -- 2.30.2