Changeset 163
- Timestamp:
- 03/11/08 14:29:06 (5 years ago)
- Files:
-
- 1 modified
-
trunk/Phergie/Plugin/Url.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Phergie/Plugin/Url.php
r161 r163 21 21 */ 22 22 protected $format = '%nick%: %title% [ %link% ]'; 23 protected $titleOnlyFormat = '%title%'; 23 24 24 25 /** … … 50 51 if ($format) { 51 52 $this->format = $format; 53 } 54 $titleOnlyFormat = $this->getPluginIni('title_only_format'); 55 if ($titleOnlyFormat) { 56 $this->titleOnlyFormat = $titleOnlyFormat; 52 57 } 53 58 } … … 76 81 $opts = array('http' => 77 82 array( 78 'timeout' => 4,83 'timeout' => 3.5, 79 84 'method' => 'GET', 80 85 'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12' … … 93 98 if (!isset ($title)) { 94 99 $content = ''; 95 while ($chunk = fread($page, 512)) { 100 $tstamp = time()+4; 101 while ($chunk = fread($page, 1)) { 96 102 $content .= $chunk; 103 // Check for timeout 104 if(time() > $tstamp) 105 break; 106 // Skip checks unless we read 100 bytes, no need to kill the cpu 107 if (!(strlen($content) % 100)) { 108 continue; 109 } 110 // Try to read title 97 111 if (preg_match('#<title[^>]*>([^<]*)#is', $content, $m)) { 98 $content .= fread($page, 256); 112 // Start another loop to grab some more data in order to be sure we have the complete title 113 $loop = 120; 114 while (($chunk = fread($page, 1)) && $loop--) { 115 $content .= $chunk; 116 // Check for timeout 117 if(time() > $tstamp) 118 break; 119 } 99 120 preg_match('#<title[^>]*>([^<]*)#is', $content, $m); 100 121 $title = preg_replace('#\s+#', ' ', $m[1]); 101 $title = $this->decode($title, $titleLength);122 $title = trim($this->decode($title, $titleLength)); 102 123 break; 103 124 } 125 // Title won't appear beyond that point so stop parsing 104 126 if (preg_match('#</head>|<body#i', $content)) { 105 127 break; … … 110 132 } 111 133 112 if (!isset($title) ) {134 if (!isset($title) || empty($title)) { 113 135 if ($tinyUrl === $url) { 114 136 unset($tinyUrl, $url); … … 118 140 } 119 141 142 143 // Send url and title 120 144 $this->doPrivmsg( 121 145 $this->event->getSource(), … … 148 172 // and minimize the size of the cache for less cache bloat. 149 173 $url = dechex(crc32($url)); $tiny = dechex(crc32($tiny)); 150 $cache = array('url' => $this->urlCache[$source][$url], 'tiny' => $this->tinyCache[$source][$tiny]); 174 $cache = array 175 ( 176 'url' => isset($this->urlCache[$source][$url]) ? $this->urlCache[$source][$url] : null, 177 'tiny' => isset($this->tinyCache[$source][$tiny]) ? $this->tinyCache[$source][$tiny] : null 178 ); 151 179 152 180 $expire = $this->expire;