Ignore:
Timestamp:
2011/09/09 15:29:59 (13 years ago)
Author:
Seasoft
Message:

#1475 (PEAR::HTTP_Request の配置が誤っている)
#1476 (インクルードしているライブラリをバージョンアップする)

  • PEAR::Net_URL
  • PEAR::HTTP_Request
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_11-dev/data/module/Net/URL.php

    r20116 r21237  
    3737// Net_URL Class 
    3838 
     39 
    3940class Net_URL 
    4041{ 
     42    var $options = array('encode_query_keys' => false); 
    4143    /** 
    4244    * Full url 
     
    122124    function __construct($url = null, $useBrackets = true) 
    123125    { 
     126        $this->url = $url; 
     127        $this->useBrackets = $useBrackets; 
     128 
     129        $this->initialize(); 
     130    } 
     131 
     132    function initialize() 
     133    { 
    124134        $HTTP_SERVER_VARS  = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; 
    125135 
    126         $this->useBrackets = $useBrackets; 
    127         $this->url         = $url; 
    128136        $this->user        = ''; 
    129137        $this->pass        = ''; 
     
    135143 
    136144        // Only use defaults if not an absolute URL given 
    137         if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) { 
    138  
    139             $this->protocol    = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http'); 
     145        if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) { 
     146            $this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'); 
    140147 
    141148            /** 
    142149            * Figure out host/port 
    143150            */ 
    144             if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) { 
     151            if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) &&  
     152                preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches))  
     153            { 
    145154                $host = $matches[1]; 
    146155                if (!empty($matches[3])) { 
     
    161170 
    162171        // Parse the url and store the various parts 
    163         if (!empty($url)) { 
    164             $urlinfo = parse_url($url); 
     172        if (!empty($this->url)) { 
     173            $urlinfo = parse_url($this->url); 
    165174 
    166175            // Default querystring 
     
    201210        } 
    202211    } 
    203  
    204212    /** 
    205213    * Returns full url 
     
    224232 
    225233    /** 
    226     * Adds a querystring item 
     234    * Adds or updates a querystring item (URL parameter). 
     235    * Automatically encodes parameters with rawurlencode() if $preencoded 
     236    *  is false. 
     237    * You can pass an array to $value, it gets mapped via [] in the URL if 
     238    * $this->useBrackets is activated. 
    227239    * 
    228240    * @param  string $name       Name of item 
     
    233245    function addQueryString($name, $value, $preencoded = false) 
    234246    { 
     247        if ($this->getOption('encode_query_keys')) { 
     248            $name = rawurlencode($name); 
     249        } 
     250 
    235251        if ($preencoded) { 
    236252            $this->querystring[$name] = $value; 
     
    248264    function removeQueryString($name) 
    249265    { 
     266        if ($this->getOption('encode_query_keys')) { 
     267            $name = rawurlencode($name); 
     268        } 
     269 
    250270        if (isset($this->querystring[$name])) { 
    251271            unset($this->querystring[$name]); 
     
    274294        if (!empty($this->querystring)) { 
    275295            foreach ($this->querystring as $name => $value) { 
     296                // Encode var name 
     297                $name = rawurlencode($name); 
     298 
    276299                if (is_array($value)) { 
    277300                    foreach ($value as $k => $v) { 
     
    312335                $key   = $part; 
    313336            } 
    314             if (substr($key, -2) == '[]') { 
    315                 $key = substr($key, 0, -2); 
    316                 if (@!is_array($return[$key])) { 
    317                     $return[$key]   = array(); 
     337 
     338            if (!$this->getOption('encode_query_keys')) { 
     339                $key = rawurldecode($key); 
     340            } 
     341 
     342            if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { 
     343                $key = $matches[1]; 
     344                $idx = $matches[2]; 
     345 
     346                // Ensure is an array 
     347                if (empty($return[$key]) || !is_array($return[$key])) { 
     348                    $return[$key] = array(); 
     349                } 
     350 
     351                // Add data 
     352                if ($idx === '') { 
    318353                    $return[$key][] = $value; 
    319354                } else { 
    320                     $return[$key][] = $value; 
     355                    $return[$key][$idx] = $value; 
    321356                } 
    322357            } elseif (!$this->useBrackets AND !empty($return[$key])) { 
     
    341376    * This method can also be called statically. 
    342377    * 
    343     * @param  string $url URL path to resolve 
     378    * @param  string $path URL path to resolve 
    344379    * @return string      The result 
    345380    */ 
     
    404439    { 
    405440        $this->protocol = $protocol; 
    406         $this->port = is_null($port) ? $this->getStandardPort() : $port; 
     441        $this->port     = is_null($port) ? $this->getStandardPort($protocol) : $port; 
     442    } 
     443 
     444    /** 
     445     * Set an option 
     446     * 
     447     * This function set an option 
     448     * to be used thorough the script. 
     449     * 
     450     * @access public 
     451     * @param  string $optionName  The optionname to set 
     452     * @param  string $value       The value of this option. 
     453     */ 
     454    function setOption($optionName, $value) 
     455    { 
     456        if (!array_key_exists($optionName, $this->options)) { 
     457            return false; 
     458        } 
     459 
     460        $this->options[$optionName] = $value; 
     461        $this->initialize(); 
     462    } 
     463 
     464    /** 
     465     * Get an option 
     466     * 
     467     * This function gets an option 
     468     * from the $this->options array 
     469     * and return it's value. 
     470     * 
     471     * @access public 
     472     * @param  string $opionName  The name of the option to retrieve 
     473     * @see    $this->options 
     474     */ 
     475    function getOption($optionName) 
     476    { 
     477        if (!isset($this->options[$optionName])) { 
     478            return false; 
     479        } 
     480 
     481        return $this->options[$optionName]; 
    407482    } 
    408483 
Note: See TracChangeset for help on using the changeset viewer.