| 56 | | if (preg_match('#(https?://(?:[a-z0-9_-]+\.)+[a-z0-9]{1,6}[^\s]*)#is', $this->event->getArgument(1), $m)) { |
| 57 | | $url = rtrim($m[1], '), ]'); |
| 58 | | // Spam check on base URL |
| 59 | | if(array_search($url, $this->lastUrls) !== false) |
| 60 | | return; |
| 61 | | // Convert url |
| 62 | | $tinyUrl = $this->tinyUrl($url); |
| 63 | | // Spam check on tinyURL |
| 64 | | if(array_search($tinyUrl, $this->lastUrls) !== false) |
| 65 | | return; |
| | 47 | if (preg_match_all('#(https?://(?:[a-z0-9_-]+\.)+[a-z0-9]{1,6}[^\s]*)#is', $this->event->getArgument(1), $matches, PREG_SET_ORDER)) { |
| | 48 | $titleLength = $this->getPluginIni('title_length'); |
| | 49 | foreach ($matches as $m) { |
| | 50 | $url = rtrim($m[1], '), ]'); |
| | 51 | // Convert url |
| | 52 | $tinyUrl = $this->tinyUrl($url); |
| 69 | | $opts = array('http' => |
| 70 | | array( |
| 71 | | 'timeout' => 5, |
| 72 | | 'method' => 'GET', |
| 73 | | 'header' => 'Content-type: application/x-www-form-urlencoded', |
| 74 | | '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' |
| 75 | | ) |
| 76 | | ); |
| 77 | | $context = stream_context_create($opts); |
| 78 | | |
| 79 | | if ($page = @fopen($url, 'r', false, $context)) { |
| 80 | | $data = stream_get_meta_data($page); |
| 81 | | foreach ($data['wrapper_data'] as $header) { |
| 82 | | if (preg_match('/^Content-Type: ([^;]+)/', $header, $match) |
| 83 | | && ! preg_match('/^text\\/x?html$/', $match[1])) { |
| 84 | | $title = $match[1]; |
| 85 | | } |
| 86 | | } |
| 87 | | if (!isset ($title)) { |
| 88 | | $content = ''; |
| 89 | | while ($chunk = fread($page, 512)) { |
| 90 | | $content .= $chunk; |
| 91 | | if (preg_match('#<title[^>]*>([^<]*)#is', $content, $m)) { |
| 92 | | $content .= fread($page, 256); |
| 93 | | preg_match('#<title[^>]*>([^<]*)#is', $content, $m); |
| 94 | | $title = preg_replace('#\s+#', ' ', $m[1]); |
| 95 | | $title = $this->decode($title, $titleLength); |
| 96 | | break; |
| 97 | | } |
| 98 | | if (preg_match('#</head>|<body#i', $content)) { |
| 99 | | break; |
| | 64 | if ($page = @fopen($url, 'r', false, $context)) { |
| | 65 | $data = stream_get_meta_data($page); |
| | 66 | foreach ($data['wrapper_data'] as $header) { |
| | 67 | if (preg_match('/^Content-Type: ([^;]+)/', $header, $match) |
| | 68 | && ! preg_match('/^text\\/x?html$/', $match[1])) { |
| | 69 | $title = $match[1]; |
| | 72 | if (!isset ($title)) { |
| | 73 | $content = ''; |
| | 74 | while ($chunk = fread($page, 512)) { |
| | 75 | $content .= $chunk; |
| | 76 | if (preg_match('#<title[^>]*>([^<]*)#is', $content, $m)) { |
| | 77 | $content .= fread($page, 256); |
| | 78 | preg_match('#<title[^>]*>([^<]*)#is', $content, $m); |
| | 79 | $title = preg_replace('#\s+#', ' ', $m[1]); |
| | 80 | $title = $this->decode($title, $titleLength); |
| | 81 | break; |
| | 82 | } |
| | 83 | if (preg_match('#</head>|<body#i', $content)) { |
| | 84 | break; |
| | 85 | } |
| | 86 | } |
| | 87 | } |
| | 88 | fclose($page); |
| 105 | | |
| 106 | | if (!isset($title)) { |
| 107 | | $title = '[ No Title ]'; |
| 108 | | } |
| 109 | | |
| 110 | | $this->doPrivmsg( |
| 111 | | $this->event->getSource(), |
| 112 | | str_replace( |
| 113 | | array('%title%', '%link%'), |
| 114 | | array($title, $tinyUrl), |
| 115 | | $this->format |
| 116 | | ) |
| 117 | | ); |
| 118 | | |
| 119 | | // Remove one url couple if it exceeds 5 couples |
| 120 | | if (count($this->lastUrls) > 10) { |
| 121 | | array_shift($this->lastUrls); |
| 122 | | array_shift($this->lastUrls); |
| 123 | | } |
| 124 | | |
| 125 | | // Add the latest couple |
| 126 | | $this->lastUrls[] = $url; |
| 127 | | $this->lastUrls[] = $tinyUrl; |