Ejemplo n.º 1
0
 /**
  * Auto post to social network sites
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return	
  */
 public function shareSystem(EasyBlogPost &$post, $force = false)
 {
     // Determines if the primary category of this post requires auto posting or not
     $category = $post->getPrimaryCategory();
     if (!$category->autopost) {
         return;
     }
     // Get a list of system oauth clients.
     $model = EB::model('Oauth');
     $clients = $model->getSystemClients();
     foreach ($clients as $client) {
         // If this is a new post, ensure that it respects the settings before auto posting
         if ($post->isNew() && !$this->config->get('integrations_' . $client->type . '_centralized_auto_post') && !$force) {
             continue;
         }
         // If the post is updated, ensure that it respects the settings before auto posting
         if (!$post->isNew() && !$this->config->get('integrations_' . $client->type . '_centralized_send_updates') && !$force) {
             continue;
         }
         $table = EB::table('OAuth');
         $table->bind($client);
         // Push the item now
         $table->push($post);
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * Retrieves the custom permalink
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public static function getCustomPermalink(EasyBlogPost $post)
 {
     $config = EB::config();
     $custom = $config->get('main_sef_custom');
     $date = EB::date($data->created);
     $fallback = $date->toFormat('%Y') . '/' . $date->toFormat('%m') . '/' . $date->toFormat('%d') . '/' . $data->permalink;
     // If the user didn't enter any values for the custom sef, we'll just load the default one which is the 'date' based
     if (!$custom) {
         return $fallback;
     }
     // Break down parts of the url defined by the admin
     $pieces = explode('/', $custom);
     if (!$pieces) {
         return $fallback;
     }
     $result = array();
     foreach ($pieces as $piece) {
         $piece = str_ireplace('%year_num%', $date->format('Y'), $piece);
         $piece = str_ireplace('%month_num%', $date->format('m'), $piece);
         $piece = str_ireplace('%day_num%', $date->format('d'), $piece);
         $piece = str_ireplace('%day%', $date->format('A'), $piece);
         $piece = str_ireplace('%month%', $date->format('b'), $piece);
         $piece = str_ireplace('%blog_id%', $post->id, $piece);
         $piece = str_ireplace('%category%', $post->getPrimaryCategory()->getPermalink(), $piece);
         $piece = str_ireplace('%category_id%', $post->getPrimaryCategory()->id, $piece);
         $result[] = $piece;
     }
     $url = implode('/', $result);
     $url .= '/' . $post->permalink;
     return $url;
 }
Ejemplo n.º 5
0
 /**
  * Determines if the current post is protected
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function isProtected(EasyBlogPost &$blog)
 {
     // Password protection disabled
     if (!$this->config->get('main_password_protect')) {
         return false;
     }
     // Site admin should not be restricted
     if (EB::isSiteAdmin()) {
         return false;
     }
     // Blog does not contain any password protection
     if (empty($blog->blogpassword)) {
         return false;
     }
     // User already entered password
     if ($blog->verifyPassword()) {
         return false;
     }
     // Set the return url to the current url
     $return = base64_encode(JRequest::getURI());
     $category = $blog->getPrimaryCategory();
     $blog->category = $category;
     $blog->categories = $blog->getCategories();
     // Get the blogger object
     $blogger = EB::user($blog->created_by);
     // Set the author object into the table.
     $blog->author = $blogger;
     $this->set('blogger', $blog->author);
     $this->set('return', $return);
     $this->set('blog', $blog);
     $this->set('category', $category);
     parent::display('blogs/entry/default.protected');
     return;
 }