/** * 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 = EasyBlogHelper::getHelper('Videos')->processVideos($row->intro); $row->content = EasyBlogHelper::getHelper('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 = EasyBlogHelper::getHelper('Videos')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('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->source) && (!$row->source || empty($row->source))) { // @rule: Try to match all videos from the blog post first. $row->videos = EasyBlogHelper::getHelper('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 = EasyBlogHelper::getHelper('Videos')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('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': // @task: Remove Zemanta tags $content = EasyBlogHelper::removeZemantaTags($content); // 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 = ''; // @task: Remove Zemanta tags $content = EasyBlogHelper::removeZemantaTags($content); // 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->source) && (!$row->source || empty($row->source))) { // @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; }
for ($i = 0; $i < count($entries); $i++) { $row = EasyBlogHelper::getTable('Blog'); $row->bind($entries[$i]); $row->featuredImage = EasyBlogHelper::getFeaturedImage($row->intro . $row->content); // @rule: Process videos $row->intro = EasyBlogHelper::getHelper('Videos')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Videos')->strip($row->content); // @rule: Remove gallery codes $row->intro = EasyBlogHelper::getHelper('Gallery')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Gallery')->strip($row->content); // Process jomsocial albums $row->intro = EasyBlogHelper::getHelper('Album')->strip($row->intro); $row->content = EasyBlogHelper::getHelper('Album')->strip($row->content); //remove zemanta tags $row->intro = EasyBlogHelper::removeZemantaTags($row->intro); $row->content = EasyBlogHelper::removeZemantaTags($row->content); // Remove adsense codes require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php'; $row->intro = EasyBlogGoogleAdsense::stripAdsenseCode($row->intro); $row->content = EasyBlogGoogleAdsense::stripAdsenseCode($row->content); JTable::addIncludePath(EBLOG_TABLES); $author = EasyBlogHelper::getTable('Profile', 'Table'); $author->load($row->created_by); $row->author = $author; $row->date = EasyBlogDateHelper::toFormat(EasyBlogHelper::getDate($row->created), $config->get('layout_dateformat', '%A, %d %B %Y')); $items[] = $row; } // If needed, shuffle the entries if ($params->get('autoshuffle')) { shuffle($items); }