getIni('format'); if ($format) { $this->format = $format; } } /** * Checks an incoming message for the presence of a URL and, if one is * found, responds with its title if it is an HTML document and the * TinyURL equivalent of its original URL if it meets length requirements. * * @return void */ public function onPrivmsg() { // URL Match if (preg_match('#(https?://(?:[a-z0-9_-]+\.)+[a-z]{2,6}[^\s]*)#is', $event->getArgument(1), $m)) { $url = rtrim($m[1], '), ]'); // @todo if image or something, output content type $tinyUrl = $this->tinyUrl($url); $title = ''; $titleLength = $this->getIni('title_length'); if ($page = @fopen($url, 'r')) { $content = ''; while ($chunk = fread($page, 512)) { $content .= $chunk; if (preg_match('#]*>([^<]*)#is', $content, $m)) { $title = $this->decode($m[1], $titleLength); break; } if (preg_match('#|doPrivmsg( $this->getSource(), str_replace( array('%title%', '%link%'), array($title, $tinyUrl), $this->format ) ); } } /** * Transliterates a UTF-8 string into corresponding ASCII characters and * truncates and appends an ellipsis to the string if it exceeds a given * length. * * @param string $str String to decode * @param int $trim Maximum string length, optional * @return string */ protected function decode($str, $trim=null) { $out = utf8_decode($str); $out = html_entity_decode($out, ENT_QUOTES); $out = strtr($out, 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYPYaaaaaaaceeeeiiiidnoooooouuuuypy'); $out = preg_replace('{[^a-z0-9&|"#\'\{\}()§^!°\[\]$*¨µ£%´`~=+:/;.,?><\\ _-]}i', '', $out); if($trim > 0) { $out = substr($out, 0, $trim) . (strlen($out) > $trim ? '...' : ''); } return $out; } }