Пример #1
0
	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;
	}