Beispiel #1
0
 /**
  * autoThumb
  *
  * @param string     $context
  * @param object     $article
  * @param \JRegistry $params
  *
  * @return  void
  */
 public static function autoThumb($context, $article, $params = null)
 {
     \JHtmlBehavior::modal();
     $minimal = 30;
     $es = \Ezset::getInstance();
     include_once EZSET_ROOT . '/lib/dom/simple_html_dom.php';
     $html = str_get_html($article->text);
     $imgs = $html->find('img');
     foreach ($imgs as $img) {
         $classes = explode(' ', $img->class);
         $imgUrl = UriHelper::pathAddHost($img->src);
         // Has class nothumb, skip to next.
         if (in_array('nothumb', $classes)) {
             continue;
         }
         // If is anchor already, skip to next.
         if ($img->parent->tag == 'a') {
             continue;
         }
         // If img tag has no width and height attrs, skip.
         if (!$img->width && !$img->height) {
             continue;
         }
         // If not localhost image, skip.
         if (!strpos('-' . $imgUrl, \JURI::root()) && $es->params->get('onlyLocalhostThumb', 1)) {
             continue;
         }
         // Get img path and size
         $imgPath = \JPath::clean(str_replace(\JURI::root(), JPATH_ROOT . '/', $imgUrl));
         $size = getimagesize($imgPath);
         // Manul size
         $imgW = $img->width;
         $imgH = $img->height;
         // Original size
         $oriW = $size[0];
         $oriH = $size[1];
         // If too small, skip.
         if ($oriW <= $minimal || $oriH <= $minimal) {
             continue;
         }
         // If large ten origin, skip.
         if ($oriW <= $imgW || $oriW <= $imgW) {
             continue;
         }
         // Get thumb url
         $thumb = new \Windwalker\Image\Thumb();
         $img->src = $thumb->resize($imgUrl, $imgW, $imgH);
         $imgtext = $img->outertext;
         $imgtext = \JHtml::link($imgUrl, $imgtext, array('class' => 'modal'));
         $img->outertext = $imgtext;
         $classes = null;
     }
     $article->text = $html->save();
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * getThumbPath
  *
  * @param string $value
  *
  * @return  string
  */
 public static function getThumbPath($value)
 {
     $thumb = new \Windwalker\Image\Thumb(null, 'com_userxtd');
     return $thumb->resize($value, 300, 300, \JImage::CROP_RESIZE);
 }