Exemplo n.º 1
0
 public static function getImage(&$blog, $rawIntroText = '')
 {
     $cfg = EasyBlogHelper::getConfig();
     // @task: First, we try to search to see if there's a blog image. If there is already, just ignore the rest.
     if ($blog->getImage()) {
         return $blog->getImage()->getSource('thumbnail');
     }
     // @legacy: If there's no image for this blog post, then we do this the legacy way.
     // First let's try to find for an image.
     $img = '';
     $pattern = '#<img[^>]*>#i';
     preg_match($pattern, $blog->content, $matches);
     if ($matches) {
         $img = $matches[0];
     } else {
         $text = $cfg->get('main_hideintro_entryview') ? $rawIntroText : $blog->intro;
         preg_match($pattern, $text, $matches);
         if ($matches) {
             $img = $matches[0];
         }
     }
     // Default image
     $source = '';
     //image found. now we process further to get the absolute image path.
     if ($img) {
         //get the img source
         $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i';
         preg_match($pattern, $img, $matches);
         if ($matches) {
             $imgPath = $matches[1];
             $source = EasyImageHelper::rel2abs($imgPath, JURI::root());
         }
     }
     return $source;
 }
Exemplo n.º 2
0
 public static function getFirstImage($content)
 {
     //try to search for the 1st img in the blog
     $img = '';
     $pattern = '#<img[^>]*>#i';
     preg_match($pattern, $content, $matches);
     if ($matches) {
         $img = $matches[0];
     }
     //image found. now we process further to get the absolute image path.
     if (!empty($img)) {
         //get the img src
         $pattern = '/src\\s*=\\s*"(.+?)"/i';
         preg_match($pattern, $img, $matches);
         if ($matches) {
             $imgPath = $matches[1];
             $imgSrc = EasyImageHelper::rel2abs($imgPath, JURI::root());
             return $imgSrc;
         }
     }
     return false;
 }
Exemplo n.º 3
0
 public static function getAndRemoveImages($content)
 {
     //try to search for the 1st img in the blog
     $img = '';
     $pattern = '#<img[^>]*>#i';
     $result = array();
     preg_match($pattern, $content, $matches);
     if (isset($matches[0]) && !empty($matches[0])) {
         $images = $matches[0];
         if (!is_array($images)) {
             $images = array($images);
         }
         foreach ($images as $image) {
             $content = str_ireplace($image, '', $content);
             // Get the URL to the image
             $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i';
             preg_match($pattern, $image, $matches);
             if ($matches) {
                 $imgPath = $matches[1];
                 $source = EasyImageHelper::rel2abs($imgPath, JURI::root());
                 $result[] = $source;
             }
         }
     }
     $obj = new stdClass();
     $obj->content = $content;
     $obj->images = $result;
     return $obj;
 }