Changeset 239
- Timestamp:
- 04/14/08 23:14:26 (7 months ago)
- Files:
-
- trunk/Phergie/Plugin/Php.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Plugin/Php.php
r238 r239 17 17 */ 18 18 protected $cache; 19 20 /** 21 * Set to true by the custom error handler if an HTTP error code has been received 22 * 23 * @var boolean 24 */ 25 protected $errorStatus = false; 19 26 20 27 /** … … 54 61 $name = str_replace(array('_', ' '), '-', $function); 55 62 $tmp = file_get_contents('http://php.net/manual/en/function.' . rtrim($name, '();') . '.php'); 56 if( strpos( $tmp, '<p class="refpurpose dc-title">' ) !== false) {63 if(!$this->errorStatus && strpos($tmp, '<p class="refpurpose dc-title">') !== false) { 57 64 $contents = '[ '.$this->tinyUrl('http://php.net/'.$name).' ] '; 58 65 if (preg_match( '/<div class="methodsynopsis dc-description">(.*?)<\/div>/mis', $tmp, $m)) { 59 $contents .= $this-> _clean($m[1]);66 $contents .= $this->decode($m[1]); 60 67 } 61 68 if (preg_match( '/<p class="refpurpose dc-title">(.*?)<\/p>/mis', $tmp, $m)) { 62 $m = explode( '-', $this-> _clean($m[1]), 2);69 $m = explode( '-', $this->decode($m[1]), 2); 63 70 $contents .= ' - '.$m[1]; 64 71 } 65 72 $contents = trim(str_replace(' ,', ',', $contents)); 66 } 67 else {68 $contents = 'Nothing found';73 } else { 74 $this->errorStatus = false; 75 $contents = 'Nothing found'; 69 76 } 70 77 $this->cache[$function] = $contents; … … 72 79 $this->doPrivmsg($this->event->getSource(), $this->cache[$function]); 73 80 } 81 82 /** 83 * Custom error handler meant to handle 404 errors and such 84 */ 85 public function onPhpError($errno, $errstr, $errfile, $errline) 86 { 87 if ($errno === E_WARNING) { 88 // Check to see if there was HTTP warning while connecting to the site 89 if (preg_match('{HTTP/1\.[01] ([0-9]{3})}i', $errstr, $m)) { 90 $this->errorStatus = true; 91 $this->debug('PHP Warning: ' . $errstr . 'in ' . $errfile . ' on line ' . $errline); 92 return true; 93 // Safely ignore these SSL warnings so they don't appear in the log 94 } else if (stripos($errstr, 'SSL: fatal protocol error in') !== false || 95 stripos($errstr, 'failed to open stream') !== false || 96 stripos($errstr, 'HTTP request failed') !== false || 97 stripos($errstr, 'SSL: An existing connection was forcibly closed by the remote host') !== false || 98 stripos($errstr, 'Failed to enable crypto in') !== false || 99 stripos($errstr, 'SSL: An established connection was aborted by the software in your host machine') !== false || 100 stripos($errstr, 'SSL operation failed with code') !== false || 101 stripos($errstr, 'unable to connect to') !== false) { 102 $this->errorStatus = true; 103 $this->debug('PHP Warning: ' . $errstr . 'in ' . $errfile . ' on line ' . $errline); 104 return true; 105 } 106 } 107 return false; 108 } 74 109 }