/**
  * Method to test getCategoryLink().
  *
  * @return void
  *
  * @covers \Windwalker\Helper\JContentHelper::getCategoryLink
  */
 public function testGetCategoryLink()
 {
     JContentHelper::$categoryRouteHandler = array($this, 'getCategoryRoute');
     $categoryId = '34';
     $this->assertSame('category/foobar', JContentHelper::getCategoryLink($categoryId));
     $this->assertSame(\JUri::root() . 'category/foobar', JContentHelper::getCategoryLink($categoryId, true));
 }
Пример #2
0
 /**
  * likeButton
  *
  * @param string $context
  * @param object $article
  *
  * @return  void
  */
 public static function likeButton($context, $article)
 {
     $context = explode('.', $context);
     if ($context[0] != 'com_content') {
         return;
     }
     $input = \JFactory::getApplication()->input;
     $uri = \JUri::getInstance();
     // Force http to make like button always use same link.
     $uri->setScheme('http');
     // Set Route
     $link = JContentHelper::getArticleLink("{$article->id}:{$article->alias}", $article->catid, false);
     $link = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')) . \JRoute::_($link);
     // Set like
     $es = \Ezset::getInstance();
     $position = $es->params->get('fbLikePosition', 1);
     $like = with(new FileLayout('ezset.article.facebook.like'))->render(array('uri' => $link));
     if ($input->get('view') == 'featured' || $input->get('layout') == 'blog') {
         if ($es->params->get('fbLikeOnBlog', 0)) {
             $article->introtext = $like . $article->introtext;
         }
     } elseif ($input->get('view') == 'article') {
         switch ($position) {
             // After Title
             case 1:
                 $article->text = $like . $article->text;
                 break;
                 // After Content
             // After Content
             case 2:
                 $article->text = $article->text . $like;
                 break;
                 // Both
             // Both
             case 3:
                 $article->text = $like . $article->text . $like;
                 break;
         }
     }
 }
Пример #3
0
 /**
  * clearView
  *
  * @param string     $context
  * @param object     $article
  * @param \JRegistry $params
  *
  * @return  void
  */
 public static function clearView($context, $article, $params = null)
 {
     $input = \JFactory::getApplication()->input;
     if ($input->get('layout') != 'blog' && $input->get('view') != 'featured') {
         return;
     }
     $es = \Ezset::getInstance();
     $html = new Dom();
     $imgW = $es->params->get('blogViewImgWidth', 150);
     $maxChar = $es->params->get('blogViewMaxChar', 250);
     $default = $es->params->get('blogViewImgDefault');
     $crop = (bool) $es->params->get('blogViewImgCrop', true);
     $allowTags = $es->params->get('blogViewTagsAllow');
     $doc = \JFactory::getDocument();
     $text = $article->introtext;
     $mainImg = null;
     if ($doc->getType() != 'html') {
         return;
     }
     $thumb = new \Windwalker\Image\Thumb();
     if ($default) {
         $thumb->setDefaultImage($default);
     }
     // Clean Tags
     if ($es->params->get('blogViewClearly', 0)) {
         // If first image = main image, delete this paragraph.
         $html = $html->load($text);
         /** @var \PHPHtmlParser\Dom\Collection|\PHPHtmlParser\Dom\HtmlNode[] $imgs */
         $imgs = $html->find('img');
         if ($imgs->count()) {
             $mainImg = $imgs[0]->src;
             // Is img in p tag?
             /** @var \PHPHtmlParser\Dom\HtmlNode $p */
             $p = $imgs[0]->getParent();
             // If image has anchor, get parent.
             if ($p->getTag() != 'p') {
                 $p = $p->getParent();
             }
             // remove first img
             $p->setInnerHtml(str_replace($p->firstChild()->outerHtml(), '', $p->innerHtml()));
             if (!trim($p->innerHtml())) {
                 $p->setOuterHtml('');
             }
             $text = (string) $html;
         }
         if ($es->params->get('blogViewCleanTags', 0)) {
             $text = strip_tags($text, $allowTags);
             if (!$allowTags) {
                 $text = StringHelper::substr($text, 0, $maxChar);
             }
         }
     }
     // Handle Image
     if ($crop) {
         $imageUrl = $thumb->resize($mainImg, $imgW, $imgW, $crop);
     } else {
         $imageUrl = $thumb->resize($mainImg, $imgW, 999);
     }
     // Article Link
     $link = JContentHelper::getArticleLink($article->id, $article->catid, 0);
     $data = array('link' => $link, 'image_width' => $imgW, 'image_url' => $imageUrl, 'article' => $article, 'text' => $text);
     // Set layout
     $layout = with(new FileLayout('ezset.article.blog.clearview'))->render($data);
     $article->introtext = $layout;
 }
Пример #4
0
 /**
  * getCategoryLink
  *
  * @param string $catid
  *
  * @return  string
  */
 public static function getCategoryLink($catid)
 {
     $uri = \JUri::getInstance();
     $link = JContentHelper::getCategoryLink($catid, false);
     return $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')) . \JRoute::_($link);
 }