Changeset 138
- Timestamp:
- 03/07/08 19:01:55 (9 months ago)
- Files:
-
- trunk/Phergie/Plugin/Abstract/Base.php (modified) (1 diff)
- trunk/Phergie/Plugin/FeedTicker.php (modified) (6 diffs)
- trunk/Phergie/Plugin/Url.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Plugin/Abstract/Base.php
r106 r138 214 214 215 215 /** 216 * Decodes the entities of a given string and 217 * transliterates the UTF-8 string into corresponding ASCII characters. 218 * 219 * @param string $text The text to decode. 220 * @param string $charSetFrom The charset used as the base chrset to convert from 221 * @param string $charSetTo The charset used to convert to 222 * @return string 223 */ 224 public function decodeTranslit($text, $charSetFrom = 'UTF-8', $charSetTo = 'ISO-8859-1') { 225 $text = html_entity_decode($text, ENT_QUOTES, $charSetFrom); 226 $text = preg_replace('/�*([0-9]+);/me', "$this->codeToUtf(\\1)", $text); 227 $text = preg_replace('/�*([a-f0-9]+);/mei', "$this->codeToUtf(hexdec(\\1))", $text); 228 229 // Use the translit extension if installed else fallback on to basic transliteration 230 if (extension_loaded('iconv')) { 231 $text = iconv($charSetFrom, $charSetTo.'//TRANSLIT', $text); 232 // Transliteration supprt via the translit extension is still experimental 233 } else if (false && extension_loaded('translit')) { 234 $text = transliterate($text, array('han_transliterate', 'diacritical_remove'), $charSetFrom, $charSetTo); 235 } else { 236 $text = strtr($text, '��������������������������', 237 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYPYaaaaaaaceeeeiiiidnoooooouuuuypy'); 238 $text = preg_replace('{[^a-z0-9&|"#\'\{\}()�^!�\[\]$*���%�`~=+:/;.,?><\\ _-]}i', '', $text); 239 $text = utf8_decode($text); 240 } 241 242 return $text; 243 } 244 245 /** 246 * Converts a given unicode to its UTF-8 equivalent. 247 * 248 * @param int $code The code to decode to UTF-8. 249 * @return string 250 */ 251 public function codeToUtf($code) { 252 $code = intval($code); 253 switch ($code) { 254 // 1 byte, 7 bits 255 case 0: 256 return chr(0); 257 case ($code & 0x7F): 258 return chr($code); 259 260 // 2 bytes, 11 bits 261 case ($code & 0x7FF): 262 return chr(0xC0 | (($code >> 6) & 0x1F)) . 263 chr(0x80 | ($code & 0x3F)); 264 265 // 3 bytes, 16 bits 266 case ($code & 0xFFFF): 267 return chr(0xE0 | (($code >> 12) & 0x0F)) . 268 chr(0x80 | (($code >> 6) & 0x3F)) . 269 chr(0x80 | ($code & 0x3F)); 270 271 // 4 bytes, 21 bits 272 case ($code & 0x1FFFFF): 273 return chr(0xF0 | ($code >> 18)) . 274 chr(0x80 | (($code >> 12) & 0x3F)) . 275 chr(0x80 | (($code >> 6) & 0x3F)) . 276 chr(0x80 | ($code & 0x3F)); 277 } 278 } 279 280 /** 216 281 * Returns whether or not the current environment meets the requirements 217 282 * of the plugin in order for it to be run, including the PHP version, trunk/Phergie/Plugin/FeedTicker.php
r130 r138 93 93 // Global Feed Title, Feed URL and Article Title Filters 94 94 $globalTitle = trim($this->getPluginIni('filter_title')); 95 $globalUrl = trim($this->getPluginIni('filter_url'));95 $globalUrl = trim($this->getPluginIni('filter_url')); 96 96 $globalArticle = trim($this->getPluginIni('filter_article')); 97 97 98 98 $i = 0; 99 99 $this->feeds = array(); … … 101 101 // Feed and Chan data 102 102 $feed = $this->getPluginIni('feed' . $i); 103 $chans = $this->getPluginIni('chans' . $i); 103 $chans = $this->getPluginIni('chans' . $i); 104 104 // Feed Title, Feed URL and Article Title Filter Data 105 105 $filterTitle = $this->getPluginIni('filter_title' . $i); 106 106 $filterUrl = $this->getPluginIni('filter_url' . $i); 107 107 $filterArticle = $this->getPluginIni('filter_article' . $i); 108 108 109 109 if (!empty($feed) && !empty($chans)) { 110 110 $this->feeds[] = array($feed, preg_split('#[\s\r\n,]+#', $chans)); 111 111 // Feed Title, Feed URL and Article Title Filters 112 $this->filterTitle[] = trim(trim(implode('|', array($globalTitle, $filterTitle)), '|')); 113 $this->filterUrl[] = trim(trim(implode('|', array($globalUrl, $filterUrl)), '|')); 114 $this->filterArticle[] = trim(trim(implode('|', array($globalArticle, $filterArticle)), '|')); 112 $filterTrim = "| \t\n\r\0\v\0xa0"; 113 $this->filterTitle[] = trim(implode('|', array($globalTitle, $filterTitle)), $filterTrim); 114 $this->filterUrl[] = trim(implode('|', array($globalUrl, $filterUrl)), $filterTrim); 115 $this->filterArticle[] = trim(implode('|', array($globalArticle, $filterArticle)), $filterTrim); 115 116 } 116 117 } while (++$i < 10); … … 194 195 $content = @file_get_contents($url, null, $context); 195 196 if (empty ($content)) { 196 $this->debug('Feed empty: ' . $url); 197 $this->debug('Feed empty: ' . $url); 197 198 continue; 198 199 } … … 213 214 } else { // Trouble 214 215 $this->debug('Feed format unrecognized: ' . $url); 215 continue; 216 continue; 216 217 } 217 218 } … … 248 249 // Feed Title, Feed URL and Article Title Filters 249 250 $filterTitle = $this->filterTitle[$id]; 250 $filterUrl = $this->filterUrl[$id]; 251 $filterArticle = $this->filterArticle[$id]; 252 251 $filterUrl = $this->filterUrl[$id]; 252 $filterArticle = $this->filterArticle[$id]; 253 253 254 // Check against the filters if any are set 254 if (($filterTitle && preg_match(' /'.$filterTitle.'/im', $title, $match)) ||255 ($filterUrl && preg_match(' /'.$filterUrl.'/im', $url, $match)) ||256 ($filterArticle && preg_match(' /'.$filterArticle.'/im', $article, $match))) {255 if (($filterTitle && preg_match('{'.$filterTitle.'}im', $title, $match)) || 256 ($filterUrl && preg_match('{'.$filterUrl.'}im', $url, $match)) || 257 ($filterArticle && preg_match('{'.$filterArticle.'}im', $article, $match))) { 257 258 return false; 258 259 } 259 260 return true; 260 261 } 261 262 262 263 /** 263 264 * Transliterates a UTF-8 string into corresponding ASCII characters and … … 269 270 * @return string 270 271 */ 271 protected function decode($str, $trim = null) 272 { 273 $out = utf8_decode($str); 274 $out = html_entity_decode($out, ENT_QUOTES); 275 $out = strtr($out, 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYPYaaaaaaaceeeeiiiidnoooooouuuuypy'); 276 $out = preg_replace('{[^a-z0-9&|"#\'\{\}()§^!°\[\]$*¨µ£%´`~=+:/;.,?><\\ _-]}i', '', $out); 277 $out = preg_replace('/&#([a-f0-9]+);/mi', "", $out); 272 protected function decode($str, $trim = null) { 273 $out = $this->decodeTranslit($str); 278 274 if($trim > 0) { 279 275 $out = substr($out, 0, $trim) . (strlen($out) > $trim ? '...' : ''); trunk/Phergie/Plugin/Url.php
r132 r138 117 117 $this->cache[] = $url; 118 118 $this->cache[] = $tinyUrl; 119 if (count($this->cache) > 10) {120 array_shift($this->cache);121 array_shift($this->cache);122 }119 if (count($this->cache) > 10) { 120 array_shift($this->cache); 121 array_shift($this->cache); 122 } 123 123 124 124 unset($title, $tinyUrl, $title); … … 136 136 * @return string 137 137 */ 138 protected function decode($str, $trim=null) 139 { 140 $out = utf8_decode($str); 141 $out = html_entity_decode($out, ENT_QUOTES); 142 $out = strtr($out, 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYPYaaaaaaaceeeeiiiidnoooooouuuuypy'); 143 $out = preg_replace('{[^a-z0-9&|"#\'\{\}()§^!°\[\]$*¨µ£%´`~=+:/;.,?><\\ _-]}i', '', $out); 144 $out = preg_replace('/&#([a-f0-9]+);/mi', "", $out); 145 $out = trim($out); 138 protected function decode($str, $trim = null) { 139 $out = $this->decodeTranslit($str); 146 140 if($trim > 0) { 147 141 $out = substr($out, 0, $trim) . (strlen($out) > $trim ? '...' : '');