ignore run-tests files
[linksys-wrt3g-tools.git] / Wrt3g / HtmlParser.php
1 <?php
2 /**
3 * HTML parsing for the linksys router HTML pages
4 *
5 * PHP version 5
6 *
7 * @category Tools
8 * @package  linksys-wrt3g-tools
9 * @author   Christian Weiske <cweiske@cweiske.de>
10 * @license  AGPL v3
11 * @link     http://cweiske.de/linksys-wrt3g-tools.htm
12 */
13 class Wrt3g_HtmlParser
14 {
15     protected static $arTranslations = array(
16         'GPRS_MSG.WWBEAR'      => 'type',
17         'GPRS_MSG.NNAME'       => 'network',
18         'GPRS_MSG.STRENGTH'    => 'signal strength',
19         'GPRS_MSG.ACQUIRING'   => 'aquiring',
20         'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
21         'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
22     );
23
24
25
26     /**
27     * Parses the body of /index_wstatus1.asp and returns extracted values.
28     *
29     * @param string $body HTML document to parse
30     *
31     * @return array Array of key-value pairs
32     */
33     public function index_wstatus1($body)
34     {
35         $arRetval = array();
36         $arMatches = array();
37         preg_match_all('#>Capture\(([^)]+)\)</#', $body, $arMatches);
38         $arData = array();
39         reset($arMatches[1]);
40         while (current($arMatches[1])) {
41             $key   = current($arMatches[1]);
42             $value = next($arMatches[1]);
43             if (isset(self::$arTranslations[$key])) {
44                 $key = self::$arTranslations[$key];
45             }
46             if (isset(self::$arTranslations[$value])) {
47                 $value = self::$arTranslations[$value];
48             }
49             $arRetval[$key] = $value;
50             next($arMatches[1]);
51         }
52
53         return $arRetval;
54     }
55
56
57
58     /**
59     * Parses the body of /index_wstatus2.asp and returns extracted values.
60     *
61     * @param string $body HTML document to parse
62     *
63     * @return array Array with "connection" as key and one of "connecting",
64     *               "connected" or "disconnected" as value.
65     */
66     public function index_wstatus2($body)
67     {
68         preg_match('/var status2 = "(.+)"/', $body, $arMatches);
69
70         $strStatus = $arMatches[1];
71         //Connecting
72         //Disconnected
73         //Connected
74         return array('connection' => strtolower($strStatus));
75     }
76 }