/** * Truncate's blog post with the respective settings. * * @access public */ public static function truncateContent(&$row, $loadVideo = false, $frontpage = false, $loadGallery = true) { $config = EasyBlogHelper::getConfig(); $truncate = true; $maxCharacter = $config->get('layout_maxlengthasintrotext', 150); // @task: Maximum characters should not be lesser than 0 $maxCharacter = $maxCharacter <= 0 ? 150 : $maxCharacter; // Check if truncation is really necessary because if introtext is already present, just use it. if (!empty($row->intro) && !empty($row->content)) { // We do not want the script to truncate anything since we'll just be using the intro part. $truncate = false; } // @task: If truncation is not necessary or the intro text is empty, let's just use the content. if (!$config->get('layout_blogasintrotext') || !$truncate) { //here we process the video and get the links. if ($loadVideo) { $row->intro = EB::videos()->processVideos($row->intro); $row->content = EB::videos()->processVideos($row->content); } // @rule: Process audio files. $row->intro = EasyBlogHelper::getHelper('Audio')->process($row->intro); $row->content = EasyBlogHelper::getHelper('Audio')->process($row->content); if (($config->get('main_image_gallery_frontpage') && $frontpage || !$frontpage) && $loadGallery) { $row->intro = EasyBlogHelper::getHelper('Gallery')->process($row->intro, $row->created_by); $row->content = EasyBlogHelper::getHelper('Gallery')->process($row->content, $row->created_by); // Process jomsocial albums $row->intro = EasyBlogHelper::getHelper('Album')->process($row->intro, $row->created_by); $row->content = EasyBlogHelper::getHelper('Album')->process($row->content, $row->created_by); } // @task: Strip out video tags $row->intro = EB::videos()->strip($row->intro); $row->content = EB::videos()->strip($row->content); // @task: Strip out audio tags $row->intro = EasyBlogHelper::getHelper('Audio')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Audio')->strip($row->content); // @task: Strip out gallery tags $row->intro = EasyBlogHelper::getHelper('Gallery')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Gallery')->strip($row->content); // @task: Strip out album tags $row->intro = EasyBlogHelper::getHelper('Album')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Album')->strip($row->content); // @rule: Once the gallery is already processed above, we will need to strip out the gallery contents since it may contain some unwanted codes // @2.0: <input class="easyblog-gallery" // @3.5: {ebgallery:'name'} $row->intro = EasyBlogHelper::removeGallery($row->intro); $row->content = EasyBlogHelper::removeGallery($row->content); if ($frontpage && $config->get('main_truncate_image_position') == 'hidden') { // Need to remove images, and videos. $row->intro = self::strip_only($row->intro, '<img>'); $row->content = self::strip_only($row->content, '<img>'); } $row->text = empty($row->intro) ? $row->content : $row->intro; return $row; } // @rule: If this is a normal blog post, we match them manually if (isset($row->posttype) && (!$row->posttype || empty($row->posttype))) { // @rule: Try to match all videos from the blog post first. $row->videos = EB::videos()->getHTMLArray($row->intro . $row->content); // @rule: $row->galleries = EasyBlogHelper::getHelper('Gallery')->getHTMLArray($row->intro . $row->content); // @rule: $row->audios = EasyBlogHelper::getHelper('Audio')->getHTMLArray($row->intro . $row->content); // @rule: $row->albums = EasyBlogHelper::getHelper('Album')->getHTMLArray($row->intro . $row->content); } // @task: Here we need to strip out all items that are embedded since they are now not required because they'll be truncated. // @task: Strip out video tags $row->intro = EB::videos()->strip($row->intro); $row->content = EB::videos()->strip($row->content); // @task: Strip out audio tags $row->intro = EasyBlogHelper::getHelper('Audio')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Audio')->strip($row->content); // @task: Strip out gallery tags $row->intro = EasyBlogHelper::getHelper('Gallery')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Gallery')->strip($row->content); // @task: Strip out album tags $row->intro = EasyBlogHelper::getHelper('Album')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Album')->strip($row->content); // This is the combined content of the intro and the fulltext $content = $row->intro . $row->content; switch ($config->get('main_truncate_type')) { case 'chars': // Remove uneccessary html tags to avoid unclosed html tags $content = strip_tags($content); // Remove blank spaces since the word calculation should not include new lines or blanks. $content = trim($content); // @task: Let's truncate the content now. $row->text = JString::substr($content, 0, $maxCharacter); break; case 'words': $tag = false; $count = 0; $output = ''; // Remove uneccessary html tags to avoid unclosed html tags $content = strip_tags($content); $chunks = preg_split("/([\\s]+)/", $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); foreach ($chunks as $piece) { if (!$tag || stripos($piece, '>') !== false) { $tag = (bool) (strripos($piece, '>') < strripos($piece, '<')); } if (!$tag && trim($piece) == '') { $count++; } if ($count > $maxCharacter && !$tag) { break; } $output .= $piece; } unset($chunks); $row->text = $output; break; case 'break': $position = 0; $matches = array(); $tag = '<br'; $matches = array(); do { $position = @JString::strpos(strtolower($content), $tag, $position + 1); if ($position !== false) { $matches[] = $position; } } while ($position !== false); $maxTag = (int) $config->get('main_truncate_maxtag'); if (count($matches) > $maxTag) { $row->text = JString::substr($content, 0, $matches[$maxTag - 1] + 6); $row->readmore = true; } else { $row->text = $content; $row->readmore = false; } break; default: $position = 0; $matches = array(); $tag = '</p>'; // @task: If configured to not display any media items on frontpage, we need to remove it here. if ($frontpage && $config->get('main_truncate_image_position') == 'hidden') { // Need to remove images, and videos. $content = self::strip_only($content, '<img>'); } do { $position = @JString::strpos(strtolower($content), $tag, $position + 1); if ($position !== false) { $matches[] = $position; } } while ($position !== false); // @TODO: Configurable $maxTag = (int) $config->get('main_truncate_maxtag'); if (count($matches) > $maxTag) { $row->text = JString::substr($content, 0, $matches[$maxTag - 1] + 4); $htmlTagPattern = array('/\\<div/i', '/\\<table/i'); $htmlCloseTagPattern = array('/\\<\\/div\\>/is', '/\\<\\/table\\>/is'); $htmlCloseTag = array('</div>', '</table>'); for ($i = 0; $i < count($htmlTagPattern); $i++) { $htmlItem = $htmlTagPattern[$i]; $htmlItemClosePattern = $htmlCloseTagPattern[$i]; $htmlItemCloseTag = $htmlCloseTag[$i]; preg_match_all($htmlItem, strtolower($row->text), $totalOpenItem); if (isset($totalOpenItem[0]) && !empty($totalOpenItem[0])) { $totalOpenItem = count($totalOpenItem[0]); preg_match_all($htmlItemClosePattern, strtolower($row->text), $totalClosedItem); $totalClosedItem = count($totalClosedItem[0]); $totalItemToAdd = $totalOpenItem - $totalClosedItem; if ($totalItemToAdd > 0) { for ($y = 1; $y <= $totalItemToAdd; $y++) { $row->text .= $htmlItemCloseTag; } } } } $row->readmore = true; } else { $row->text = $content; $row->readmore = false; } break; } //var_dump($row );exit; if ($config->get('main_truncate_ellipses') && isset($row->readmore) && $row->readmore) { $row->text .= JText::_('COM_EASYBLOG_ELLIPSES'); } if (isset($row->posttype) && (!$row->posttype || empty($row->posttype))) { // @task: Determine the position of media items that should be included in the content. $embedHTML = ''; $embedVideoHTML = ''; $imgHTML = ''; if (!empty($row->galleries)) { $embedHTML .= implode('', $row->galleries); } if (!empty($row->audios)) { $embedHTML .= implode('', $row->audios); } if (!empty($row->videos)) { $embedVideoHTML = implode('', $row->videos); } if (!empty($row->albums)) { $embedHTML .= implode('', $row->albums); } // @legacy fix: For users prior to 3.5 if (($config->get('main_truncate_type') == 'chars' || $config->get('main_truncate_type') == 'words') && !$row->getImage()) { // Append image in the post if truncation is done by characters if ($config->get('main_teaser_image') && !$frontpage || $frontpage && $config->get('main_truncate_image_position') != 'hidden') { // Match images that has preview. $pattern = '/<a class="easyblog-thumb-preview"(.*?)<\\/a>/is'; preg_match($pattern, $row->intro . $row->content, $matches); // Legacy images that doesn't have previews. if (empty($matches)) { $pattern = '#<img[^>]*>#i'; preg_match($pattern, $row->intro . $row->content, $matches); } if (!empty($matches)) { if ($config->get('main_teaser_image_align') == 'float-l' || $config->get('main_teaser_image_align') == 'float-r') { $imgHTML = '<div class="teaser-image clearfix ' . $config->get('main_teaser_image_align') . '" style="margin:8px;max-width:98%;">' . $matches[0] . '</div>'; } else { $imgHTML = '<div class="teaser-image clearfix" style="margin:8px;max-width:98%;text-align: ' . $config->get('main_teaser_image_align') . ' !important;">' . $matches[0] . '</div>'; } } } } // images if ($config->get('main_truncate_image_position') == 'top' && !empty($imgHTML)) { $row->text = $imgHTML . $row->text; } else { if ($config->get('main_truncate_image_position') == 'bottom' && !empty($imgHTML)) { $row->text = $row->text . $imgHTML; } } // videos if ($config->get('main_truncate_video_position') == 'top' && !empty($embedVideoHTML)) { $row->text = $embedVideoHTML . '<br />' . $row->text; } else { if ($config->get('main_truncate_video_position') == 'bottom' && !empty($embedVideoHTML)) { $row->text = $row->text . '<br />' . $embedVideoHTML; } } // @task: Prepend the other media items in the start of the blog posts. if ($config->get('main_truncate_media_position') == 'top' && !empty($embedHTML)) { $row->text = $embedHTML . $row->text; } else { if ($config->get('main_truncate_media_position') == 'bottom' && !empty($embedHTML)) { $row->text .= $embedHTML; } } } return $row; }
/** * Creates a new stream for new comments in EasyBlog * * @since 1.0 * @access public * @param string * @return */ public function addIndexerNewBlog($blog) { if (!class_exists('Foundry')) { return; } $config = EasyBlogHelper::getConfig(); $indexer = Foundry::get('Indexer', 'com_easyblog'); $template = $indexer->getTemplate(); // getting the blog content $content = $blog->intro . $blog->content; $image = ''; // @rule: Try to get the blog image. if ($blog->getImage()) { $image = $blog->getImage()->getSource('small'); } if (empty($image)) { // @rule: Match images from blog post $pattern = '/<\\s*img [^\\>]*src\\s*=\\s*[\\""\']?([^\\""\'\\s>]*)/i'; preg_match($pattern, $content, $matches); $image = ''; if ($matches) { $image = isset($matches[1]) ? $matches[1] : ''; if (JString::stristr($matches[1], 'https://') === false && JString::stristr($matches[1], 'http://') === false && !empty($image)) { $image = rtrim(JURI::root(), '/') . '/' . ltrim($image, '/'); } } } if (!$image) { $image = rtrim(JURI::root(), '/') . '/components/com_easyblog/assets/images/default_facebook.png'; } // @task: Strip out video tags $content = EasyBlogHelper::getHelper('Videos')->strip($content); // @task: Strip out audio tags $content = EasyBlogHelper::getHelper('Audio')->strip($content); // @task: Strip out gallery tags $content = EasyBlogHelper::getHelper('Gallery')->strip($content); // @task: Strip out album tags $content = EasyBlogHelper::getHelper('Album')->strip($content); // @rule: Once the gallery is already processed above, we will need to strip out the gallery contents since it may contain some unwanted codes // @2.0: <input class="easyblog-gallery" // @3.5: {ebgallery:'name'} $content = EasyBlogHelper::removeGallery($content); $content = strip_tags($content); if (JString::strlen($content) > $config->get('integrations_easysocial_indexer_newpost_length', 250)) { $content = JString::substr($content, 0, $config->get('integrations_easysocial_indexer_newpost_length', 250)); } // lets include the title as the search snapshot. $content = $blog->title . ' ' . $content; $template->setContent($blog->title, $content); $url = EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id); // Remove /administrator/ from the url. $url = JString::str_ireplace('administrator/', '', $url); $template->setSource($blog->id, 'blog', $blog->created_by, $url); $template->setThumbnail($image); $template->setLastUpdate($blog->modified); $state = $indexer->index($template); return $state; }
/** * Truncate's blog post with the respective settings. * * @access public */ public static function truncateContent(&$row, $loadVideo = false, $frontpage = false, $loadGallery = true) { $config = EasyBlogHelper::getConfig(); $truncate = true; $maxCharacter = $config->get('layout_maxlengthasintrotext', 150); // @task: Maximum characters should not be lesser than 0 $maxCharacter = $maxCharacter <= 0 ? 150 : $maxCharacter; // Check if truncation is really necessary because if introtext is already present, just use it. if (!empty($row->intro) && !empty($row->content)) { // We do not want the script to truncate anything since we'll just be using the intro part. $truncate = false; } // @task: If truncation is not necessary or the intro text is empty, let's just use the content. if (!$config->get('layout_blogasintrotext') || !$truncate) { //here we process the video and get the links. if ($loadVideo) { $row->intro = EB::videos()->processVideos($row->intro); $row->content = EB::videos()->processVideos($row->content); } // @rule: Process audio files. $row->intro = EasyBlogHelper::getHelper('Audio')->process($row->intro); $row->content = EasyBlogHelper::getHelper('Audio')->process($row->content); if (($config->get('main_image_gallery_frontpage') && $frontpage || !$frontpage) && $loadGallery) { $row->intro = EasyBlogHelper::getHelper('Gallery')->process($row->intro, $row->created_by); $row->content = EasyBlogHelper::getHelper('Gallery')->process($row->content, $row->created_by); // Process jomsocial albums $row->intro = EasyBlogHelper::getHelper('Album')->process($row->intro, $row->created_by); $row->content = EasyBlogHelper::getHelper('Album')->process($row->content, $row->created_by); } // @task: Strip out video tags $row->intro = EB::videos()->strip($row->intro); $row->content = EB::videos()->strip($row->content); // @task: Strip out audio tags $row->intro = EasyBlogHelper::getHelper('Audio')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Audio')->strip($row->content); // @task: Strip out gallery tags $row->intro = EasyBlogHelper::getHelper('Gallery')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Gallery')->strip($row->content); // @task: Strip out album tags $row->intro = EasyBlogHelper::getHelper('Album')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Album')->strip($row->content); // @rule: Once the gallery is already processed above, we will need to strip out the gallery contents since it may contain some unwanted codes // @2.0: <input class="easyblog-gallery" // @3.5: {ebgallery:'name'} $row->intro = EasyBlogHelper::removeGallery($row->intro); $row->content = EasyBlogHelper::removeGallery($row->content); if ($frontpage && $config->get('main_truncate_image_position') == 'hidden') { // Need to remove images, and videos. $row->intro = self::strip_only($row->intro, '<img>'); $row->content = self::strip_only($row->content, '<img>'); } $row->text = empty($row->intro) ? $row->content : $row->intro; return $row; } // @rule: If this is a normal blog post, we match them manually if (isset($row->posttype) && (!$row->posttype || empty($row->posttype))) { // @rule: Try to match all videos from the blog post first. $row->videos = EB::videos()->getHTMLArray($row->intro . $row->content); // @rule: $row->galleries = EasyBlogHelper::getHelper('Gallery')->getHTMLArray($row->intro . $row->content); // @rule: $row->audios = EasyBlogHelper::getHelper('Audio')->getHTMLArray($row->intro . $row->content); // @rule: $row->albums = EasyBlogHelper::getHelper('Album')->getHTMLArray($row->intro . $row->content); } // @task: Here we need to strip out all items that are embedded since they are now not required because they'll be truncated. // @task: Strip out video tags $row->intro = EB::videos()->strip($row->intro); $row->content = EB::videos()->strip($row->content); // @task: Strip out audio tags $row->intro = EasyBlogHelper::getHelper('Audio')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Audio')->strip($row->content); // @task: Strip out gallery tags $row->intro = EasyBlogHelper::getHelper('Gallery')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Gallery')->strip($row->content); // @task: Strip out album tags $row->intro = EasyBlogHelper::getHelper('Album')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Album')->strip($row->content); // This is the combined content of the intro and the fulltext $content = $row->intro . $row->content; //var_dump($row );exit; if ($config->get('main_truncate_ellipses') && isset($row->readmore) && $row->readmore) { $row->text .= JText::_('COM_EASYBLOG_ELLIPSES'); } if (isset($row->posttype) && (!$row->posttype || empty($row->posttype))) { // @task: Determine the position of media items that should be included in the content. $embedHTML = ''; $embedVideoHTML = ''; $imgHTML = ''; if (!empty($row->galleries)) { $embedHTML .= implode('', $row->galleries); } if (!empty($row->audios)) { $embedHTML .= implode('', $row->audios); } if (!empty($row->videos)) { $embedVideoHTML = implode('', $row->videos); } if (!empty($row->albums)) { $embedHTML .= implode('', $row->albums); } // images if ($config->get('main_truncate_image_position') == 'top' && !empty($imgHTML)) { $row->text = $imgHTML . $row->text; } else { if ($config->get('main_truncate_image_position') == 'bottom' && !empty($imgHTML)) { $row->text = $row->text . $imgHTML; } } // videos if ($config->get('main_truncate_video_position') == 'top' && !empty($embedVideoHTML)) { $row->text = $embedVideoHTML . '<br />' . $row->text; } else { if ($config->get('main_truncate_video_position') == 'bottom' && !empty($embedVideoHTML)) { $row->text = $row->text . '<br />' . $embedVideoHTML; } } // @task: Prepend the other media items in the start of the blog posts. if ($config->get('main_truncate_media_position') == 'top' && !empty($embedHTML)) { $row->text = $embedHTML . $row->text; } else { if ($config->get('main_truncate_media_position') == 'bottom' && !empty($embedHTML)) { $row->text .= $embedHTML; } } } return $row; }