Beispiel #1
0
 /**
  * Truncates the content of the blog post
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function truncate(EasyBlogPost &$post)
 {
     if (!$post->isLegacy()) {
         return;
     }
     // Get the maximum allowed characters in the content
     $max = $this->config->get('layout_maxlengthasintrotext', 200);
     $max = $max <= 0 ? 200 : $max;
     // Default to truncate the post's content
     $truncate = true;
     // If introtext and content is already present, we don't need to truncate anything since it should respect the user's settings
     if ($post->intro && $post->content) {
         $truncate = false;
         $post->text = $post->intro;
     }
     // If we do not need to run any truncation, just run a simple formatting
     if (!$truncate || !$this->config->get('layout_blogasintrotext')) {
         // Process videos
         EB::videos()->format($post);
         // Process audio files
         EB::audio()->format($post);
         // Format gallery items
         EB::gallery()->format($post);
         // Format albums
         EB::album()->format($post);
         // Remove known codes
         $this->stripCodes($post);
         // Need to remove images, and videos.
         if ($this->config->get('main_truncate_image_position') == 'hidden') {
             $post->intro = $this->strip_only($post->intro, '<img>');
             $post->content = $this->strip_only($post->content, '<img>');
         }
         // Determine the correct content to display
         $contents = empty($post->intro) ? $post->content : $post->intro;
         return $contents;
     }
     // For normal posts, we will need to get a list of items included in the post
     if (isset($post->posttype) && $post->posttype == 'standard' || !$post->posttype) {
         $post->videos = EB::videos()->getItems($post->text);
         $post->galleries = EB::gallery()->getItems($post->text);
         $post->audios = EB::audio()->getItems($post->text);
         $post->albums = EB::album()->getItems($post->text);
     }
     // Strip out known codes
     $this->stripCodes($post);
     // Truncation by characters
     if ($this->config->get('main_truncate_type') == 'chars') {
         $this->truncateByChars($post);
     }
     // Truncation by break tags
     if ($this->config->get('main_truncate_type') == 'break') {
         $this->truncateByParagraph($post);
     }
     // Truncation by words
     if ($this->config->get('main_truncate_type') == 'words') {
         $this->truncateByWords($post);
     }
     // Truncation by paragraph
     if ($this->config->get('main_truncate_type') == 'paragraph') {
         $this->truncateByParagraph($post);
     }
     // Append ellipses to the content if necessary
     if ($this->config->get('main_truncate_ellipses') && isset($post->readmore) && $post->readmore) {
         $post->text .= JText::_('COM_EASYBLOG_ELLIPSES');
     }
     // Only process standard posts
     if ($post->posttype == 'standard') {
         // Determine the position of media items that should be included in the content.
         $embedHTML = '';
         $embedVideoHTML = '';
         $imgHTML = '';
         if (!empty($post->galleries)) {
             $embedHTML .= $post->galleries;
         }
         if (!empty($post->audios)) {
             $embedHTML .= implode('', $post->audios);
         }
         if (!empty($post->videos)) {
             $embedVideoHTML = implode('', $post->videos);
         }
         if (!empty($post->albums)) {
             $embedHTML .= implode('', $post->albums);
         }
         // images
         if ($this->config->get('main_truncate_image_position') == 'top' && !empty($imgHTML)) {
             $post->text = $imgHTML . $post->text;
         }
         if ($this->config->get('main_truncate_image_position') == 'bottom' && !empty($imgHTML)) {
             $post->text = $post->text . $imgHTML;
         }
         // Videos
         if ($this->config->get('main_truncate_video_position') == 'top' && !empty($embedVideoHTML)) {
             $post->text = $embedVideoHTML . '<br />' . $post->text;
         }
         if ($this->config->get('main_truncate_video_position') == 'bottom' && !empty($embedVideoHTML)) {
             $post->text = $post->text . '<br />' . $embedVideoHTML;
         }
         // Prepend the other media items in the start of the blog posts.
         if ($this->config->get('main_truncate_media_position') == 'top' && !empty($embedHTML)) {
             $contents = $embedHTML . $post->text;
         }
         if ($this->config->get('main_truncate_media_position') == 'bottom' && !empty($embedHTML)) {
             $post->text = $post->text . $embedHTML;
         }
     }
 }