Пример #1
0
 /**
  * @param IrcDataObject $message
  * @return void
  */
 public function sniffLinks(IrcDataObject $message)
 {
     $string = $message->getParams()['text'];
     $target = $message->getTargets()[0];
     try {
         $uri = SnifferHelper::extractUriFromString($string);
     } catch (NoUriFoundException $e) {
         return;
     }
     $cacheItem = $this->uriCache->getCacheItem($uri);
     if (!$cacheItem) {
         try {
             $shortUri = $this->createShortUri($uri);
             # We prefer is.gd for content type queries. This significantly reduces errors.
             $contentTypeUri = $shortUri;
             if ($contentTypeUri == 'No short url') {
                 $contentTypeUri = $uri;
             }
             $content_type = SnifferHelper::getContentTypeFromUri($contentTypeUri);
             $title = '(not a web page, content type: ' . $content_type . ')';
             if ($content_type == 'text/html') {
                 $title = SnifferHelper::getTitleFromUri($uri);
             }
         } catch (PageTitleDoesNotExistException $e) {
             $title = '(Page title not found or empty. Put that in your pipe and smoke it.)';
         } catch (ContentTypeNotFoundException $e) {
             return;
         } catch (GuzzleException $e) {
             $title = '(link was unresponsive: ' . $uri . ')';
         }
         if (!empty($title) && !empty($shortUri)) {
             $this->uriCache->addCacheItem($uri, $title, $shortUri);
         }
     } else {
         $title = $cacheItem->getTitle();
         $shortUri = $cacheItem->getShortUri();
     }
     if (empty($shortUri) || empty($title)) {
         return;
     }
     $connection = $this->getModule('Connection');
     $connection->write($connection->getGenerator()->ircNotice($target, '[' . $shortUri . '] ' . $title));
 }
Пример #2
0
 public function testGetContentType()
 {
     $expected = 'text/html';
     $result = SnifferHelper::getContentTypeFromUri('http://google.com/');
     $this->assertSame($expected, $result);
 }