Example #1
0
 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 = JUDirectoryFrontHelperString::replaceIgnore($search, $replace, $subject, $pos);
     }
     return $subject;
 }
Example #2
0
 public static function parseCommentText($str, $listingId = null)
 {
     $params = JUDirectoryHelper::getParams(null, $listingId);
     $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 = JUDirectoryFrontHelperComment::autoLinkVideo($str, $listingId);
     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 = JUDirectoryFrontHelperString::replaceIgnore(trim($url), $shortenUrl, $str);
                 } else {
                     $str = JUDirectoryFrontHelperString::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 "";
     }
     $options = (array) $options;
     if ($this->isDetailsView($options)) {
         if ($this->params->get("show_introtext_in_details_view", 1)) {
             $description = $this->value;
         } else {
             $description = $this->listing->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 = JUDirectoryFrontHelperString::replaceIgnore(trim($url), $shortenUrl, $description);
                     } else {
                         $description = JUDirectoryFrontHelperString::replaceIgnore($url, '<a href="' . $url . '">' . trim($shortenUrl) . '</a> ', $description);
                     }
                 }
             }
         }
         if ($this->params->get("nl2br_details_view", 0)) {
             $description = nl2br($description);
         }
     } else {
         $description = $this->listing->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 = JUDirectoryFrontHelperString::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::_(JUDirectoryHelperRoute::getListingRoute($this->listing_id)) . '">' . $this->params->get("readmore_text", 'Read more...') . '</a>';
             }
         }
     }
     $this->setVariable('value', $description);
     return $this->fetch('output.php', __CLASS__);
 }
Example #4
0
 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 = JUDirectoryFrontHelperString::replaceIgnore(trim($url), $shortenUrl, $value);
                     } else {
                         $value = JUDirectoryFrontHelperString::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 = JUDirectoryFrontHelperString::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__);
 }