public static function replaceIgnore($search, $replace, $subject, $pos = 0) { if ($pos == 0) { $pos = strpos($subject, $search); } else { $pos = strpos($subject, $search, $pos); } $canReplace = true; $ignoredArr = array('href="', 'href=\'', 'src="', 'src=\'', 'alt="', 'alt=\'', 'data-mce-src="', 'data-mce-src=\''); foreach ($ignoredArr AS $value) { $valueLength = strlen($value); $subStr = substr($subject, $pos - $valueLength, $valueLength); if ($subStr == $value) { $canReplace = false; break; } } if ($pos !== false && $pos < strlen($subject)) { if ($canReplace == true) { $subject = substr_replace($subject, $replace, $pos, strlen($search)); $pos = $pos + strlen($replace); } else { $pos = $pos + strlen($search); } $subject = JUDownloadFrontHelperString::replaceIgnore($search, $replace, $subject, $pos); } return $subject; }
public static function parseCommentText($str, $docId = null) { $params = JUDownloadHelper::getParams(null, $docId); $auto_link_url_in_comment = $params->get('auto_link_url_in_comment', 1); $trim_long_url_in_comment = $params->get('trim_long_url_in_comment', 0); $front_portion_url_in_comment = $params->get('front_portion_url_in_comment', 0); $back_portion_url_in_comment = $params->get('back_portion_url_in_comment', 0); $str = JUDownloadFrontHelperComment::autoLinkVideo($str, $docId); if ($auto_link_url_in_comment) { if ($params->get('nofollow_link_in_comment', 1)) { $noFollow = 'rel="nofollow"'; } else { $noFollow = ''; } $regex = "#http(?:s)?:\/\/(?:www\.)?[\.0-9a-z]{1,255}(\.[a-z]{2,4}){1,2}([\/\?][^\s]{1,}){0,}[\/]?#i"; preg_match_all($regex, $str, $matches); $matches = array_unique($matches[0]); if (count($matches) > 0) { foreach ($matches AS $url) { $shortenUrl = urldecode($url); if ($trim_long_url_in_comment > 0 && strlen($shortenUrl) > $trim_long_url_in_comment) { if ($front_portion_url_in_comment > 0 || $back_portion_url_in_comment > 0) { $frontStr = $front_portion_url_in_comment > 0 ? substr($shortenUrl, 0, $front_portion_url_in_comment) : ""; $backStr = $back_portion_url_in_comment > 0 ? substr($shortenUrl, (int) (0 - $back_portion_url_in_comment)) : ""; $shortenUrl = $frontStr . '...' . $backStr; } $shortenUrl = '<a ' . $noFollow . ' href="' . $url . '">' . $shortenUrl . '</a> '; $str = str_replace(trim($url), $shortenUrl, $str); $str = JUDownloadFrontHelperString::replaceIgnore(trim($url), $shortenUrl, $str); } else { $str = JUDownloadFrontHelperString::replaceIgnore($url, '<a ' . $noFollow . ' href="' . $url . '">' . trim($shortenUrl) . '</a> ', $str); } } } } $forbidden_words = array_map('trim', explode(",", strtolower(str_replace("\n", ",", $params->get('forbidden_words', ''))))); if (trim($params->get('forbidden_words', '')) && count($forbidden_words)) { $forbidden_words_replaced_by = $params->get('forbidden_words_replaced_by', '***'); foreach ($forbidden_words AS $val) { $str = preg_replace('#' . $val . '#ism', $forbidden_words_replaced_by, $str); } } return $str; }
public function getOutput($options = array()) { if (!$this->isPublished()) { return ""; } if (!$this->value) { return ""; } $value = $this->value; if ($this->isDetailsView($options)) { if ($this->params->get("strip_tags_details_view", 0)) { $allowable_tags = $this->params->get("allowable_tags", "u,b,i,a,ul,li,pre,blockquote,strong,em"); $allowable_tags = str_replace(' ', '', $allowable_tags); $allowable_tags = "<" . str_replace(',', '><', $allowable_tags) . ">"; $value = strip_tags($value, $allowable_tags); } if ($this->params->get("parse_plugin", 0)) { $value = JHtml::_('content.prepare', $value); } if ($this->params->get("nl2br_details_view", 0)) { $value = nl2br($value); } if ($this->params->get("auto_link", 1)) { $trim_long_url = $this->params->get('trim_long_url', 0); $front_portion_url = $this->params->get('front_portion_url', 0); $back_portion_url = $this->params->get('back_portion_url', 0); $regex = "#http(?:s)?:\/\/(?:www\.)?[\.0-9a-z]{1,255}(\.[a-z]{2,4}){1,2}([\/\?][^\s]{1,}){0,}[\/]?#i"; preg_match_all($regex, $value, $matches); $matches = array_unique($matches[0]); if (count($matches) > 0) { if ($this->params->get('nofollow_link', 1)) { $noFollow = 'rel="nofollow"'; } else { $noFollow = ''; } foreach ($matches AS $url) { $shortenUrl = urldecode($url); if ($trim_long_url > 0 && strlen($shortenUrl) > $trim_long_url) { if ($front_portion_url > 0 || $back_portion_url > 0) { $frontStr = $front_portion_url > 0 ? substr($shortenUrl, 0, $front_portion_url) : ""; $backStr = $back_portion_url > 0 ? substr($shortenUrl, (int) (0 - $back_portion_url)) : ""; $shortenUrl = $frontStr . '...' . $backStr; } $shortenUrl = '<a ' . $noFollow . ' href="' . $url . '">' . $shortenUrl . '</a> '; $value = str_replace(trim($url), $shortenUrl, $value); $value = JUDownloadFrontHelperString::replaceIgnore(trim($url), $shortenUrl, $value); } else { $value = JUDownloadFrontHelperString::replaceIgnore($url, '<a ' . $noFollow . ' href="' . $url . '">' . trim($shortenUrl) . '</a> ', $value); } } } } } else { if ($this->params->get("strip_tags_list_view", 1)) { $allowable_tags = $this->params->get("allowable_tags", "u,b,i,a,ul,li,pre,blockquote,strong,em"); $allowable_tags = str_replace(' ', '', $allowable_tags); $allowable_tags = "<" . str_replace(',', '><', $allowable_tags) . ">"; $value = strip_tags($value, $allowable_tags); } if ($this->params->get("use_html_entities", 0)) { $value = htmlentities($value); } if ($this->params->get("truncate", 1)) { $value = JUDownloadFrontHelperString::truncateHtml($value, $this->params->get("limit_char_in_list_view", 200)); } if ($this->params->get("parse_plugin", 0)) { $value = JHtml::_('content.prepare', $value); } } $this->setVariable('value', $value); return $this->fetch('output.php', __CLASS__); }
public function display($tpl = null) { $model = $this->getModel(); $this->model = $model; $this->state = $this->get('State'); $params = $this->state->params; $this->params = $params; $this->token = JSession::getFormToken(); $this->root_category = JUDownloadFrontHelperCategory::getRootCategory(); $categoryId = $this->state->get('category.id', $this->root_category->id); if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } $error = array(); if (!JUDownloadFrontHelperPermission::canDoCategory($categoryId, true, $error)) { $user = JFactory::getUser(); if ($user->id) { return JError::raiseError($error['code'], $error['message']); } else { $uri = JUri::getInstance(); $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false); $app = JFactory::getApplication(); $app->redirect($loginUrl, JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning'); return false; } } $topLevelCats = JUDownloadHelper::getCatsByLevel(1, $categoryId); if (is_array($topLevelCats) && count($topLevelCats) > 0) { $this->tl_catid = $topLevelCats[0]->id; } $this->category = JUDownloadFrontHelperCategory::getCategory($categoryId); $this->show_feed = JUDLPROVERSION ? $this->params->get('rss_display_icon', 1) : 0; $this->rss_link = JRoute::_(JUDownloadHelperRoute::getCategoryRoute($this->category->id, null, true)); if (isset($this->category->images) && !empty($this->category->images) && !empty($this->category->images->detail_image)) { $this->category->images->detail_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judownload/images/category/detail/', true) . $this->category->images->detail_image; } $this->category->images->detail_image_width = (int) $this->params->get('category_image_width', 200); $this->category->images->detail_image_height = (int) $this->params->get('category_image_height', 200); if ($this->params->get('category_show_description', 1)) { $this->category->description = $this->category->introtext . $this->category->fulltext; } else { $this->category->description = $this->category->fulltext; } $categoryDescLimit = (int) $this->params->get('category_desc_limit', 0); if ($categoryDescLimit > 0) { $this->category->description = JUDownloadFrontHelperString::truncateHtml($this->category->description, $categoryDescLimit); } if ($this->params->get('plugin_support', 0)) { $this->category->description = JHtml::_('content.prepare', $this->category->description, '', 'com_judownload.category'); } $this->category->class_sfx = htmlspecialchars($this->category->class_sfx); $relatedCatOrdering = $this->params->get('related_category_ordering', 'crel.ordering'); $relatedCatDirection = $this->params->get('related_category_direction', 'ASC'); $this->related_cats = $model->getRelatedCategories($this->category->id, $relatedCatOrdering, $relatedCatDirection); if (is_array($this->related_cats) && count($this->related_cats) > 0) { foreach ($this->related_cats AS $relatedCategory) { if (isset($relatedCategory->images->intro_image) && !empty($relatedCategory->images->intro_image)) { $relatedCategory->images->intro_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/', true) . $relatedCategory->images->intro_image; } $relatedCategory->images->intro_image_width = (int) $this->params->get('related_category_intro_image_width', 200); $relatedCategory->images->intro_image_height = (int) $this->params->get('related_category_intro_image_height', 200); if ($this->params->get('related_category_show_introtext', 1)) { $relatedCategoryDescLimit = (int) $this->params->get('related_category_introtext_character_limit', 500); if ($relatedCategoryDescLimit > 0) { $relatedCategory->introtext = JUDownloadFrontHelperString::truncateHtml($relatedCategory->introtext, $relatedCategoryDescLimit); } if ($params->get('plugin_support', 0)) { $relatedCategory->introtext = JHtml::_('content.prepare', $relatedCategory->introtext, '', 'com_judownload.category'); } } else { $relatedCategory->introtext = ''; } } } $subCatOrdering = $this->params->get('subcategory_ordering', 'title'); $subCatDirection = $this->params->get('subcategory_direction', 'ASC'); $this->subcategories = $model->getSubCategories($this->category->id, $subCatOrdering, $subCatDirection); if (is_array($this->subcategories) && count($this->subcategories) > 0) { foreach ($this->subcategories AS $subCategory) { if (isset($subCategory->images->intro_image) && !empty($subCategory->images->intro_image)) { $subCategory->images->intro_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/', true) . $subCategory->images->intro_image; } $subCategory->images->intro_image_width = (int) $this->params->get('subcategory_intro_image_width', 200); $subCategory->images->intro_image_height = (int) $this->params->get('subcategory_intro_image_height', 200); if ($this->params->get('subcategory_show_introtext', 1)) { $subCategoryDescLimit = (int) $this->params->get('subcategory_introtext_character_limit', 500); if ($subCategoryDescLimit > 0) { $subCategory->introtext = JUDownloadFrontHelperString::truncateHtml($subCategory->introtext, $subCategoryDescLimit); } if ($this->params->get('plugin_support', 0)) { $subCategory->introtext = JHtml::_('content.prepare', $subCategory->introtext, '', 'com_judownload.category'); } } else { $subCategory->introtext = ''; } } } $this->category->can_submit_doc = JUDownloadFrontHelperPermission::canSubmitDocument($this->category->id); if ($this->category->can_submit_doc && $this->params->get('show_submit_document_btn_in_category', 1)) { $this->category->submit_doc_link = JUDownloadFrontHelperDocument::getAddDocumentLink($this->category->id); } $this->items = array(); if ($this->category->show_item) { $user = JFactory::getUser(); $uri = JUri::getInstance(); $this->items = $this->get('Items'); foreach ($this->items as $item) { $documentItemid = JUDownloadHelperRoute::findItemIdOfDocument($item->id); $item->report_link = JRoute::_(JUDownloadHelperRoute::getReportDocumentRoute($item->id)); if ($item->checked_out > 0 && $item->checked_out != $user->get('id')) { if (JUDownloadFrontHelperPermission::canCheckInDocument($item->id)) { $item->checkin_link = JRoute::_('index.php?option=com_judownload&task=forms.checkin&id=' . $item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri))); } } else { $item->edit_link = JRoute::_('index.php?option=com_judownload&task=form.edit&id=' . $item->id . '&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); if ($item->published == 1) { $item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.unpublish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); } else { $item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.publish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); } } $item->delete_link = JRoute::_('index.php?option=com_judownload&task=forms.delete&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $item->event = new stdClass(); $context = 'com_judownload.document_list'; $results = $dispatcher->trigger('onContentAfterTitle', array($context, &$item, &$item->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array($context, &$item, &$item->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array($context, &$item, &$item->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); } $this->pagination = $this->get('Pagination'); } $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareData(); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
<a href="<?php echo JRoute::_(JUDownloadHelperRoute::getCategoryRoute($subcategory->id)); ?>"><?php echo $subcategory->title; ?></a> <?php $totalSubCats = JUDownloadFrontHelper::getTotalInsideCategories($subcategory->id); $totalDocs = JUDownloadFrontHelper::getTotalDocumentInCategory($subcategory->id); ?> <span><?php echo "(" . $totalSubCats . " Subcategory /" . $totalDocs . " Document)"; ?></span> </div> <?php if ($this->params->get('show_subcategories_introtext', 1)) { $cat_introtext_limit = (int) $this->params->get('categories_introtext_limit', 1); if ($cat_introtext_limit == 1) { $cat_introtext_limit_char = (int) $this->params->get('categories_introtext_limit_character', 1500); $cat_introtext = JUDownloadFrontHelperString::truncateHtml($subcategory->introtext, $cat_introtext_limit_char); } else { $cat_introtext = $subcategory->introtext; } ?> <div class="subcat-desc"> <?php if ($this->params->get('plugin_support', 0)) { echo JHtml::_('content.prepare', $cat_introtext); } else { echo $cat_introtext;
public function getOutput($options = array()) { if (!$this->isPublished()) { return ""; } if (!$this->value) { return ""; } $options = (array) $options; if ($this->isDetailsView($options)) { if ($this->params->get("show_introtext_in_details_view", 1)) { $description = $this->value; } else { $description = $this->doc->fulltext; } if ($this->params->get("strip_tags_details_view", 0)) { $allowable_tags = $this->params->get("allowable_tags", "u,b,i,a,ul,li,pre,blockquote,strong,em"); $allowable_tags = str_replace(' ', '', $allowable_tags); $allowable_tags = "<" . str_replace(',', '><', $allowable_tags) . ">"; $description = strip_tags($description, $allowable_tags); } if ($this->params->get("parse_plugin", 0)) { $description = JHtml::_('content.prepare', $description); } if ($this->params->get("auto_link", 1)) { $trim_long_url = $this->params->get('trim_long_url', 0); $front_portion_url = $this->params->get('front_portion_url', 0); $back_portion_url = $this->params->get('back_portion_url', 0); $regex = "#http(?:s)?:\/\/(?:www\.)?[\.0-9a-z]{1,255}(\.[a-z]{2,4}){1,2}([\/\?][^\s]{1,}){0,}[\/]?#i"; preg_match_all($regex, $description, $matches); $matches = array_unique($matches[0]); if (count($matches) > 0) { foreach ($matches AS $url) { $shortenUrl = urldecode($url); if ($trim_long_url > 0 && strlen($shortenUrl) > $trim_long_url) { if ($front_portion_url > 0 || $back_portion_url > 0) { $frontStr = $front_portion_url > 0 ? substr($shortenUrl, 0, $front_portion_url) : ""; $backStr = $back_portion_url > 0 ? substr($shortenUrl, (int) (0 - $back_portion_url)) : ""; $shortenUrl = $frontStr . '...' . $backStr; } $shortenUrl = '<a href="' . $url . '">' . $shortenUrl . '</a> '; $description = str_replace(trim($url), $shortenUrl, $description); $description = JUDownloadFrontHelperString::replaceIgnore(trim($url), $shortenUrl, $description); } else { $description = JUDownloadFrontHelperString::replaceIgnore($url, '<a href="' . $url . '">' . trim($shortenUrl) . '</a> ', $description); } } } } if ($this->params->get("nl2br_details_view", 0)) { $description = nl2br($description); } } else { $description = $this->doc->introtext; if ($this->params->get("strip_tags_list_view", 1)) { $allowable_tags = $this->params->get("allowable_tags", "u,b,i,a,ul,li,pre,blockquote,strong,em"); $allowable_tags = str_replace(' ', '', $allowable_tags); $allowable_tags = "<" . str_replace(',', '><', $allowable_tags) . ">"; $description = strip_tags($description, $allowable_tags); } if ($this->params->get("use_html_entities", 0)) { $description = htmlentities($description); } $isTruncated = false; if ($this->params->get("truncate", 1)) { if ($this->params->get("limit_char_in_list_view", 200) < strlen($description)) { $isTruncated = true; } $description = JUDownloadFrontHelperString::truncateHtml($description, $this->params->get("limit_char_in_list_view", 200)); } if ($this->params->get("parse_plugin", 0)) { $description = JHtml::_('content.prepare', $description); } if ($this->params->get("show_readmore", 0)) { if ($this->params->get("show_readmore_when", 1) == 2 || ($this->params->get("show_readmore_when", 1) == 1 && $isTruncated)) { $description .= ' <a class="readmore" href="' . JRoute::_(JUDownloadHelperRoute::getDocumentRoute($this->doc_id)) . '">' . $this->params->get("readmore_text", 'Read more...') . '</a>'; } } } $this->setVariable('value', $description); return $this->fetch('output.php', __CLASS__); }