예제 #1
0
 /**
  * Formats the message to be published on Twitter
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return	
  */
 public function formatMessage(EasyBlogPost &$post, EasyBlogTableOAuth &$oauth)
 {
     // Get the message template to use to push to Twitter
     $content = !empty($oauth->message) ? $oauth->message : $this->config->get('main_twitter_message');
     // Default vars to search / replace
     $search = array();
     $replace = array();
     // Replace the {title} tag
     if (JString::stristr($content, '{title}') !== false) {
         $search[] = '{title}';
         $replace[] = $post->title;
     }
     // Replace the {introtext} tag
     if (JString::stristr($content, '{introtext}') !== false) {
         $search[] = '{introtext}';
         $replace[] = $post->getIntro(EASYBLOG_STRIP_TAGS);
     }
     // Replace the {category} tag
     if (JString::stristr($content, '{category}') !== false) {
         // Get the primary category of the blog post
         $category = $post->getPrimaryCategory();
         $search[] = '{category}';
         $replace[] = $category->title;
     }
     // Get the final content
     $content = JString::str_ireplace($search, $replace, $content);
     // Replace the {link} tag
     if (JString::stristr($content, '{link}') !== false) {
         // Twitter will automatically shorten urls and a link will have a maximum of 22 chars
         // which leaves us with an offset of 118 characters
         $length = 22;
         $link = 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) {
             $link = rtrim(JURI::root(), '/') . '/index.php?option=com_easyblog&view=entry&id=' . $post->id;
         }
         // Get the remaining length that we can use.
         $remaining = 140 - $length;
         // Split the message
         $parts = explode('{link}', $content);
         for ($i = 0; $i < count($parts); $i++) {
             $tmp =& $parts[$i];
             $tmpLength = JString::strlen($tmp);
             if ($tmpLength > $remaining) {
                 if ($remaining <= 0) {
                     $tmp = JString::substr($tmp, 0, 0);
                 } else {
                     if ($remaining < 6) {
                         $tmp = JString::substr($tmp, 0, $remaining);
                     } else {
                         $tmp = JString::substr($tmp, 0, $remaining - 3) . JText::_('COM_EASYBLOG_ELLIPSES');
                     }
                     $remaining = 0;
                 }
             } else {
                 $remaining -= $tmpLength;
             }
         }
         $content = implode($link, $parts);
     } else {
         $content = JString::substr($content, 0, 136) . JText::_('COM_EASYBLOG_ELLIPSES');
     }
     return $content;
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * 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;
 }
예제 #4
0
 /**
  * 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;
 }