/** * Retrieves the blog image to be used as the twitter image * * @since 4.0 * @access public * @param string * @return */ public static function getImage(EasyBlogPost &$blog) { $config = EB::config(); // First, we try to search to see if there's a blog image. If there is already, just ignore the rest. if ($blog->getImage('thumbnail')) { return $blog->getImage('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 = $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 = EB::image()->rel2abs($imgPath, JURI::root()); } } return $source; }
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->getImage('thumbnail', true, true)) { return $blog->getImage('thumbnail', 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 { $text = $blog->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 // Check for overrides $override = JPATH_ROOT . '/templates/' . $this->app->getTemplate() . '/html/com_easyblog/images/placeholder-facebook.png'; if (JFile::exists($override)) { $source = rtrim(JURI::root(), '/') . '/templates/' . $this->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; }
/** * Retrieve the extracted content of a blog post that can be formatted to Facebook * * @since 4.0 * @access public * @param string * @return */ public function extractPostData(EasyBlogPost &$post) { // Prepare the result data $data = new stdClass(); // Get the content's source $source = $this->config->get('integrations_facebook_source'); // Get the blog content $data->content = $post->getIntro(true); // Get the blog's image to be pushed to Facebook $data->image = $post->getImage('thumbnail', true, true); // var_dump($data->image);exit; // If there's no blog image, try to get the image from the content if (!$data->image) { // lets get full content. $fullcontent = $post->getContent('entry'); $data->image = EB::string()->getImage($fullcontent); } // If there's still no image, use author's avatar if (!$data->image) { $author = $post->getAuthor(); $data->image = $author->getAvatar(); } // if still no image. lets try to get from placeholder. if (!$data->image) { $data->image = EB::getPlaceholderImage(); } // Format the content so that it respects the length $max = $this->config->get('integrations_facebook_blogs_length'); // Remove adsense codes $data->content = EB::adsense()->strip($data->content); if ($max && JString::strlen($data->content) > $max) { $data->content = JString::substr($data->content, 0, $max) . JText::_('COM_EASYBLOG_ELLIPSES'); } // Get the url to the blog $data->url = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $post->id, false, true); // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls. $sh404exists = EBR::isSh404Enabled(); if ($this->app->isAdmin() && $sh404exists) { $data->url = EB::getExternalLink('index.php?option=com_easyblog&view=entry&id=' . $post->id); } return $data; }
/** * @param array $attributes * * @return array */ public static function getArticles($attributes) { $articles = array(); switch ($attributes['articlelist_source']) { case self::PB_ARTICLE_SOURCE_K2: // Check Com K2 Enabled if (!JSNPagebuilderHelpersPagebuilder::checkComponentEnabled("com_k2")) { return array(); } $k2ArticleModel = new JSNPbK2ArticlesModel(); $result = $k2ArticleModel->jsnGetData($attributes); foreach ($result as $_key => $_value) { $articles[$_key] = $_value; $articles[$_key]['direct_url'] = JRoute::_(K2HelperRoute::getItemRoute($_value['id'], $_value['catid'])); $articles[$_key]['category_direct_url'] = JRoute::_(K2HelperRoute::getCategoryRoute($_value['catid'])); $articles[$_key]['category_title'] = $_value['category']; $imageName = md5("Image" . $_value['id']); if (JFile::exists(JPATH_ROOT . '/media/k2/items/src/' . $imageName . '.jpg')) { $images = array('image_intro' => JRoute::_(JUri::root() . 'media/k2/items/cache/' . $imageName . '_XL.jpg'), 'image_intro_alt' => $_value['title']); $articles[$_key]['images'] = json_encode($images); } } break; case self::PB_ARTICLE_SOURCE_EASY: // Check EasyBlog Enabled if (!JSNPagebuilderHelpersPagebuilder::checkComponentEnabled("com_easyblog")) { return array(); } // Get version EasyBlog $attributes['is_old_version'] = self::checkOldVersionEasyBlog(); if (!$attributes['is_old_version']) { include_once JPATH_ROOT . '/administrator/components/com_easyblog/includes/post/post.php'; } $easyArticleModel = new JSNPbEasyblogArticlesModel(); $result = $easyArticleModel->jsnGetData($attributes); foreach ($result as $_key => $_value) { $articles[$_key] = $_value; $articles[$_key]['direct_url'] = JRoute::_(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $_value['id'])); $articles[$_key]['category_direct_url'] = JRoute::_(EasyBlogRouter::_('index.php?option=com_easyblog&view=categories&layout=listings&id=' . $_value['category_id'])); if ($attributes['is_old_version']) { $articles[$_key]['introtext'] = $_value['intro']; $imageData = json_decode($_value['image'], true); if (!is_null($imageData) && isset($imageData['title']) && isset($imageData['url'])) { $images = array('image_intro' => JRoute::_($imageData['url']), 'image_intro_alt' => $imageData['title']); $articles[$_key]['images'] = json_encode($images); } } else { $_blog = new EasyBlogPost((int) $_value['id']); $articles[$_key]['introtext'] = $_blog->getIntro(); $images = array('image_intro' => JRoute::_($_blog->getImage('original', true, true)), 'image_intro_alt' => $_value['title']); $articles[$_key]['images'] = json_encode($images); } } break; default: $articlesModel = new JSNPbArticlesModel(); $result = $articlesModel->getArticlesByAttributes($attributes); foreach ($result as $_key => $_value) { $articles[$_key] = $_value; $articles[$_key]['direct_url'] = JRoute::_(ContentHelperRoute::getArticleRoute($_value['id'], $_value['catid'])); $articles[$_key]['category_direct_url'] = JRoute::_(ContentHelperRoute::getCategoryRoute($_value['catid'])); } break; } return $articles; }
/** * 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; }
/** * Posts a message on linkedin * * @since 5.0 * @access public * @param string * @return */ public function share(EasyBlogPost &$post, EasyBlogTableOAuth &$oauth) { // Get the content $content = $post->getIntro(EASYBLOG_STRIP_TAGS); // Get the blog image $image = $post->getImage('thumbnail', true, true); // If there's no blog image, try to get the image from the content if (!$image) { $fullcontent = $post->getContent('entry'); $image = EB::string()->getImage($fullcontent); } // If there's still no image, just use the author's avatar if (!$image) { $image = $post->getAuthor()->getAvatar(); } $options = array('title' => $post->title, 'comment' => $oauth->message, 'submitted-url' => $post->getExternalPermalink(), 'submitted-image-url' => $image, 'description' => $content, 'visibility' => 'anyone'); // Satisfy linkedin's criteria $options['description'] = trim(htmlspecialchars(strip_tags(stripslashes($options['description'])))); $options['comment'] = htmlspecialchars(trim(strip_tags(stripslashes($options['comment'])))); // Linkedin now restricts the message and text size. // To be safe, we'll use 380 characters instead of 400. $options['description'] = trim(JString::substr($options['description'], 0, 395)); $options['comment'] = JString::substr($options['comment'], 0, 256); // Share to their account now $status = parent::sharePost('new', $options, true, false); // Determines if we should auto post to the company pages. if ($oauth->system && $this->config->get('integrations_linkedin_company')) { $companies = trim($this->config->get('integrations_linkedin_company')); if (!empty($companies)) { $companies = explode(',', $companies); foreach ($companies as $company) { $status = parent::sharePost('new', $options, true, false, array($company)); } } } return true; }
/** * Notify site subscribers whenever a new blog post is created * * @since 1.0 * @access public * @param string * @return */ public function notifySubscribers(EasyBlogPost $blog, $action, $comment = null) { if (!$this->exists()) { return false; } // We don't want to notify via e-mail $emailOptions = false; $recipients = array(); $rule = ''; // Get the permalink of the post $permalink = $blog->getPermalink(); // Get the blog image $image = $blog->getImage() ? $blog->getImage('frontpage') : ''; // New post created on the site if ($action == 'new.post') { $rule = 'blog.create'; $recipients = $blog->getRegisteredSubscribers('new', array($blog->created_by)); $options = array('uid' => $blog->id, 'actor_id' => $blog->created_by, 'title' => JText::sprintf('COM_EASYBLOG_EASYSOCIAL_NOTIFICATION_NEW_BLOG_POST', $blog->title), 'type' => 'blog', 'url' => $permalink, 'image' => $image); } // New comment posted on the site if ($action == 'new.comment') { if (!$this->config->get('integrations_easysocial_notifications_newcomment')) { return false; } $rule = 'blog.comment'; // Get a list of recipients that we should notify $recipients = $comment->getSubscribers($blog, array($comment->created_by)); $recipients = array_merge($recipients, array($blog->created_by)); // Format the comment's content $content = $comment->getContent(true); $options = array('uid' => $blog->id, 'actor_id' => $comment->created_by, 'title' => JText::sprintf('COM_EASYBLOG_EASYSOCIAL_NOTIFICATION_NEW_COMMENT_ON_THE_BLOG_POST', $content, $blog->title), 'type' => 'blog', 'url' => $permalink, 'image' => $image); } // New ratings added on the post if ($action == 'ratings.add' && $this->config->get('integrations_easysocial_notifications_ratings')) { $rule = 'blog.ratings'; // @TODO: Perhaps notify everyone else that subscribed to this post? // Notify the blog author $recipients = array($blog->created_by); $options = array('uid' => $blog->id, 'actor_id' => $this->my->id, 'title' => JText::sprintf('COM_EASYBLOG_EASYSOCIAL_NOTIFICATION_NEW_RATINGS_FOR_YOUR_BLOG_POST', $blog->title), 'type' => 'blog', 'url' => $permalink, 'image' => $image); } if (!$rule) { return false; } // Send notifications to the receivers when they unlock the badge FD::notify($rule, $recipients, $emailOptions, $options); }
/** * 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 = $post->getImage(); // If there's no post image, search for the first image if (!$image) { $image = EB::string()->searchImage($content); } // 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; }