File: page_request.php

package info (click to toggle)
postfixadmin 2.3.5-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,200 kB
  • sloc: php: 25,767; xml: 14,485; perl: 964; sh: 664; python: 169; makefile: 84
file content (63 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
// $Id: page_request.php,v 1.1 2005/04/29 23:15:51 lastcraft Exp $

class PageRequest {
    var $_parsed;
    
    function PageRequest($raw) {
        $statements = explode('&', $raw);
        $this->_parsed = array();
        foreach ($statements as $statement) {
            if (strpos($statement, '=') === false) {
                continue;
            }
            $this->_parseStatement($statement);
        }
    }
    
    /** @access private */
    function _parseStatement($statement) {
        list($key, $value) = explode('=', $statement);
        $key = urldecode($key);
        if (preg_match('/(.*)\[\]$/', $key, $matches)) {
            $key = $matches[1];
            if (! isset($this->_parsed[$key])) {
                $this->_parsed[$key] = array();
            }
            $this->_addValue($key, $value);
        } elseif (isset($this->_parsed[$key])) {
            $this->_addValue($key, $value);
        } else {
            $this->_setValue($key, $value);
        }
    }
    
    /** @access private */
    function _addValue($key, $value) {
        if (! is_array($this->_parsed[$key])) {
            $this->_parsed[$key] = array($this->_parsed[$key]);
        }
        $this->_parsed[$key][] = urldecode($value);
    }
    
    /** @access private */
    function _setValue($key, $value) {
        $this->_parsed[$key] = urldecode($value);
    }
    
    function getAll() {
        return $this->_parsed;
    }
    
    function get() {
        $request = &new PageRequest($_SERVER['QUERY_STRING']);
        return $request->getAll();
    }
    
    function post() {
        global $HTTP_RAW_POST_DATA;
        $request = &new PageRequest($HTTP_RAW_POST_DATA);
        return $request->getAll();
    }
}
?>