Changeset 4925
- Timestamp:
- Jan 12, 2008, 5:12:53 AM (15 years ago)
- Location:
- OpenPNE/trunk/lib/include/Net
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE/trunk/lib/include/Net/Socket.php
r2 r4925 18 18 // +----------------------------------------------------------------------+ 19 19 // 20 // $Id: Socket.php,v 1. 24 2005/02/03 20:40:16chagenbu Exp $20 // $Id: Socket.php,v 1.31 2007/05/04 04:30:29 chagenbu Exp $ 21 21 22 22 require_once 'PEAR.php'; … … 24 24 define('NET_SOCKET_READ', 1); 25 25 define('NET_SOCKET_WRITE', 2); 26 define('NET_SOCKET_ERROR', 3);26 define('NET_SOCKET_ERROR', 4); 27 27 28 28 /** … … 217 217 218 218 /** 219 * Sets the file buffering size on the stream. 220 * See php's stream_set_write_buffer for more information. 221 * 222 * @param integer $size Write buffer size. 223 * @access public 224 * @return mixed on success or an PEAR_Error object otherwise 225 */ 226 function setWriteBuffer($size) 227 { 228 if (!is_resource($this->fp)) { 229 return $this->raiseError('not connected'); 230 } 231 232 $returned = stream_set_write_buffer($this->fp, $code); 233 if ($returned == 0) { 234 return true; 235 } 236 return $this->raiseError('Cannot set write buffer.'); 237 } 238 239 /** 219 240 * Returns information about an existing socket resource. 220 241 * Currently returns four entries in the result array: … … 330 351 * Tests for end-of-file on a socket descriptor. 331 352 * 353 * Also returns true if the socket is disconnected. 354 * 332 355 * @access public 333 356 * @return bool … … 335 358 function eof() 336 359 { 337 return ( is_resource($this->fp) &&feof($this->fp));360 return (!is_resource($this->fp) || feof($this->fp)); 338 361 } 339 362 … … 526 549 } 527 550 551 /** 552 * Turns encryption on/off on a connected socket. 553 * 554 * @param bool $enabled Set this parameter to true to enable encryption 555 * and false to disable encryption. 556 * @param integer $type Type of encryption. See 557 * http://se.php.net/manual/en/function.stream-socket-enable-crypto.php for values. 558 * 559 * @access public 560 * @return false on error, true on success and 0 if there isn't enough data and the 561 * user should try again (non-blocking sockets only). A PEAR_Error object 562 * is returned if the socket is not connected 563 */ 564 function enableCrypto($enabled, $type) 565 { 566 if (version_compare(phpversion(), "5.1.0", ">=")) { 567 if (!is_resource($this->fp)) { 568 return $this->raiseError('not connected'); 569 } 570 return @stream_socket_enable_crypto($this->fp, $enabled, $type); 571 } else { 572 return $this->raiseError('Net_Socket::enableCrypto() requires php version >= 5.1.0'); 573 } 574 } 575 528 576 } -
OpenPNE/trunk/lib/include/Net/URL.php
r2 r4925 33 33 // +-----------------------------------------------------------------------+ 34 34 // 35 // $Id: URL.php,v 1. 36 2004/06/19 18:58:50 richardExp $35 // $Id: URL.php,v 1.49 2007/06/28 14:43:07 davidc Exp $ 36 36 // 37 37 // Net_URL Class 38 38 39 39 40 class Net_URL 40 41 { 42 var $options = array('encode_query_keys' => false); 41 43 /** 42 44 * Full url … … 122 124 function __construct($url = null, $useBrackets = true) 123 125 { 126 $this->url = $url; 127 $this->useBrackets = $useBrackets; 128 129 $this->initialize(); 130 } 131 132 function initialize() 133 { 124 134 $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; 125 135 126 $this->useBrackets = $useBrackets;127 $this->url = $url;128 136 $this->user = ''; 129 137 $this->pass = ''; … … 135 143 136 144 // 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'); 140 147 141 148 /** 142 149 * Figure out host/port 143 150 */ 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 { 145 154 $host = $matches[1]; 146 155 if (!empty($matches[3])) { … … 161 170 162 171 // 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); 165 174 166 175 // Default querystring … … 201 210 } 202 211 } 203 204 212 /** 205 213 * Returns full url … … 224 232 225 233 /** 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. 227 239 * 228 240 * @param string $name Name of item … … 233 245 function addQueryString($name, $value, $preencoded = false) 234 246 { 247 if ($this->getOption('encode_query_keys')) { 248 $name = rawurlencode($name); 249 } 250 235 251 if ($preencoded) { 236 252 $this->querystring[$name] = $value; … … 248 264 function removeQueryString($name) 249 265 { 266 if ($this->getOption('encode_query_keys')) { 267 $name = rawurlencode($name); 268 } 269 250 270 if (isset($this->querystring[$name])) { 251 271 unset($this->querystring[$name]); … … 274 294 if (!empty($this->querystring)) { 275 295 foreach ($this->querystring as $name => $value) { 296 // Encode var name 297 $name = rawurlencode($name); 298 276 299 if (is_array($value)) { 277 300 foreach ($value as $k => $v) { … … 312 335 $key = $part; 313 336 } 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 === '') { 318 353 $return[$key][] = $value; 319 354 } else { 320 $return[$key][ ] = $value;355 $return[$key][$idx] = $value; 321 356 } 322 357 } elseif (!$this->useBrackets AND !empty($return[$key])) { … … 341 376 * This method can also be called statically. 342 377 * 343 * @param string $ urlURL path to resolve378 * @param string $path URL path to resolve 344 379 * @return string The result 345 380 */ … … 404 439 { 405 440 $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]; 407 482 } 408 483
Note: See TracChangeset
for help on using the changeset viewer.