public static function getImage(EasyBlogPost &$blog, $rawIntroText = '') { // First, we try to search to see if there's a blog image. If there is already, just ignore the rest. if ($blog->hasImage()) { return $blog->getImage('large', true, true); } // For image posts. if (isset($blog->images[0])) { return $blog->images[0]; } // 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 { $category = $blog->getPrimaryCategory(); $text = $category->getParam('main_hideintro_entryview') ? $rawIntroText : $blog->intro; preg_match($pattern, $text, $matches); if ($matches) { $img = $matches[0]; } } // Get the image source $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i'; preg_match($pattern, $img, $matches); if ($matches) { $imgPath = $matches[1]; $source = EB::image()->rel2abs($imgPath, JURI::root()); return $source; } // Default post image if the blog post doesn't contain any image $app = JFactory::getApplication(); $override = JPATH_ROOT . '/templates/' . $app->getTemplate() . '/html/com_easyblog/images/placeholder-facebook.png'; if (JFile::exists($override)) { $source = rtrim(JURI::root(), '/') . '/templates/' . $app->getTemplate() . '/html/com_easyblog/images/placeholder-facebook.png'; } else { $source = rtrim(JURI::root(), '/') . '/components/com_easyblog/themes/wireframe/images/placeholder-facebook.png'; } return $source; }
/** * Prepares a blog content before submitting to JomSocial's stream * * @since 5.0 * @access public * @param string * @return */ private function prepareBlogContent(EasyBlogPost $post, $permalink) { $content = ''; // If the stream is configured to not display any contents at all, skip this if (!$this->config->get('integrations_jomsocial_submit_content')) { return $content; } // Check if the post requires verification if ($this->config->get('main_password_protect', true) && !empty($blog->blogpassword)) { $template = EB::template(); $template->set('id', $blog->id); $template->set('return', base64_encode($blogLink)); $content = $template->output('site/blogs/protected'); return $content; } // Get the content $content = $post->getContent(); $image = ''; // If there's no post image, search for the first image if (!$post->hasImage()) { // This will return a string of img tag if exist. $image = EB::string()->searchImage($content); if (!is_array($image)) { // We need to extract the src attribute preg_match('/src="([^"]*)"/i', $image, $matches); if ($matches) { $image = $matches[1]; } } } else { $image = $post->getImage(); } // Normalize the content of the post $content = $this->normalizeContent($content); $template = EB::template(); $template->set('permalink', $permalink); $template->set('image', $image); $template->set('content', $content); $output = $template->output('site/jomsocial/stream'); return $output; }