Changeset 168
- Timestamp:
- 03/12/08 23:23:54 (5 years ago)
- Files:
-
- 1 modified
-
trunk/Phergie/Plugin/Url.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Phergie/Plugin/Url.php
r165 r168 78 78 foreach ($matches as $m) { 79 79 $url = rtrim($m[1], '), ].?!'); 80 $scheme = strtolower(parse_url($url, PHP_URL_SCHEME)); 81 if ($scheme == 'https' && !extension_loaded('openssl')) 82 continue; 83 80 84 // Convert url 81 85 $tinyUrl = $this->tinyUrl($url); … … 83 87 // Prevent spamfest 84 88 if($this->checkURLCache($url, $tinyUrl)) 85 return;89 continue; 86 90 87 91 $opts = array('http' => … … 94 98 $context = stream_context_create($opts); 95 99 100 $this->debug("Opening Stream for $url"); 96 101 $previousHandler = set_error_handler(array($this, 'errorHandler')); 97 102 if ($page = fopen($url, 'r', false, $context)) { 103 $this->debug("Opened Stream for $url"); 98 104 $data = stream_get_meta_data($page); 99 105 foreach ($data['wrapper_data'] as $header) { … … 181 187 $source = $this->event->getSource(); 182 188 183 // Transform the URL and TinyURL into a HEX CRC32 checksum to prevent potential problems 184 // and minimize the size of the cache for less cache bloat. 185 $url = dechex(crc32($url)); $tiny = dechex(crc32($tiny)); 189 /** 190 * Transform the URL and TinyURL into a HEX CRC32 checksum to prevent potential problems 191 * and minimize the size of the cache for less cache bloat. 192 */ 193 $url = $this->getURLChecksum($url); $tiny = $this->getURLChecksum($tiny); 186 194 $cache = array 187 195 ( … … 191 199 192 200 $expire = $this->expire; 193 // If cache expiration is enabled, check to see if the given url has expired in the cache 194 // If expire is disabled, simply check to see if the url is listed 201 /** 202 * If cache expiration is enabled, check to see if the given url has expired in the cache 203 * If expire is disabled, simply check to see if the url is listed 204 */ 195 205 if (($expire > 0 && (($cache['url'] + $expire) > time() || ($cache['tiny'] + $expire) > time())) || 196 206 ($expire <= 0 && (isset($cache['url']) || isset($cache['tiny'])))) { … … 213 223 $source = $this->event->getSource(); 214 224 215 // Transform the URL and TinyURL into a HEX CRC32 checksum to prevent potential problems 216 // and minimize the size of the cache for less cache bloat. 217 $url = dechex(crc32($url)); $tiny = dechex(crc32($tiny)); 225 /** 226 * Transform the URL and TinyURL into a HEX CRC32 checksum to prevent potential problems 227 * and minimize the size of the cache for less cache bloat. 228 */ 229 $url = $this->getURLChecksum($url); $tiny = $this->getURLChecksum($tiny); 218 230 $time = time(); 219 231 … … 252 264 253 265 /** 254 * Custom error handler meant to handle 404 errors and such255 */266 * Custom error handler meant to handle 404 errors and such 267 */ 256 268 public function errorHandler($errno, $errstr, $errfile, $errline) 257 269 { … … 263 275 return false; 264 276 } 277 278 /** 279 * Takes a url, parses and cleans the URL without of all the junk 280 * and then return the hex checksum of the url. 281 */ 282 public function getURLChecksum($url) { 283 $parsed = parse_url($url); 284 if (is_array($parsed)) { 285 $url = $parsed['host']; 286 $url .= isset($parsed['port']) ? ':'.$parsed['port'] : ''; 287 if(isset($parsed['path'])) 288 { 289 $url .= (substr($parsed['path'], 0, 1) == '/') ? $parsed['path'] : ('/'.$parsed['path']); 290 } 291 $url .= isset($parsed['query']) ? '?'.$parsed['query'] : ''; 292 } 293 return dechex(crc32($url)); 294 } 265 295 }