Beispiel #1
0
 public function replaceTags(&$string, $area = 'article')
 {
     if (!is_string($string) || $string == '') {
         return;
     }
     if (strpos($string, '{' . $this->params->article_tag) === false) {
         return;
     }
     // allow in component?
     if (($area == 'component' || $area == 'article' && JFactory::getApplication()->input->get('option') == 'com_content') && in_array(JFactory::getApplication()->input->get('option'), $this->params->disabled_components)) {
         $this->helpers->get('protect')->protect($string);
         $this->helpers->get('process')->removeAll($string, $area);
         NNProtect::unprotect($string);
         return;
     }
     $this->helpers->get('protect')->protect($string);
     $this->params->message = '';
     // COMPONENT
     if (JFactory::getDocument()->getType() == 'feed') {
         $s = '#(<item[^>]*>)#s';
         $string = preg_replace($s, '\\1<!-- START: AA_COMPONENT -->', $string);
         $string = str_replace('</item>', '<!-- END: AA_COMPONENT --></item>', $string);
     }
     if (strpos($string, '<!-- START: AA_COMPONENT -->') === false) {
         $this->helpers->get('tag')->tagArea($string, 'component');
     }
     $components = $this->helpers->get('tag')->getAreaByType($string, 'component');
     foreach ($components as $component) {
         if (strpos($string, $component['0']) === false) {
             continue;
         }
         $this->helpers->get('process')->processArticles($component['1'], 'components');
         $string = str_replace($component['0'], $component['1'], $string);
     }
     // EVERYWHERE
     $this->helpers->get('process')->processArticles($string, 'other');
     NNProtect::unprotect($string);
 }
Beispiel #2
0
 function replaceTags(&$str, $area = 'article')
 {
     if (!is_string($str) || $str == '') {
         return;
     }
     if (!preg_match('#\\{' . $this->params->tags . '#', $str)) {
         return;
     }
     // allow in component?
     if ($area == 'component' && in_array(JFactory::getApplication()->input->get('option'), $this->params->disabled_components)) {
         $this->protectTags($str);
         return;
     }
     $this->protect($str);
     // COMPONENT
     if (JFactory::getDocument()->getType() == 'feed') {
         $s = '#(<item[^>]*>)#s';
         $str = preg_replace($s, '\\1<!-- START: MODA_COMPONENT -->', $str);
         $str = str_replace('</item>', '<!-- END: MODA_COMPONENT --></item>', $str);
     }
     if (strpos($str, '<!-- START: MODA_COMPONENT -->') === false) {
         $this->tagArea($str, 'MODA', 'component');
     }
     $this->params->message = '';
     $components = $this->getTagArea($str, 'MODA', 'component');
     foreach ($components as $component) {
         $this->processModules($component['1'], 'components');
         $str = str_replace($component['0'], $component['1'], $str);
     }
     // EVERYWHERE
     $this->processModules($str, 'other');
     NNProtect::unprotect($str);
 }
Beispiel #3
0
 function onAfterRender()
 {
     // not in pdf's
     if (JFactory::getDocument()->getType() == 'pdf') {
         return;
     }
     $html = JResponse::getBody();
     if ($html == '') {
         return;
     }
     if (JFactory::getDocument()->getType() != 'html') {
         $this->replaceTags($html);
         $this->cleanLeftoverJunk($html);
     } else {
         // only do stuff in body
         list($pre, $body, $post) = nnText::getBody($html);
         $this->protect($body);
         $this->replaceTags($body);
         $html = $pre . $body . $post;
         $this->cleanLeftoverJunk($html);
         NNProtect::unprotect($html);
         // replace head with newly generated head
         // this is necessary because the plugins might have added scripts/styles to the head
         $orig_document = clone JFactory::getDocument();
         $this->updateHead($html, $orig_document);
         unset($orig_document);
     }
     JResponse::setBody($html);
 }
Beispiel #4
0
	/**
	 * replace any protected tags to original
	 */
	public static function unprotectForm(&$str, $tags = array(), $protected = array())
	{
		// Protect entire form
		if (empty($tags))
		{

			NNProtect::unprotect($str);

			return;
		}

		NNProtect::unprotectTags($str, $tags, $protected);
	}
Beispiel #5
0
 function replaceTags(&$string, $area = 'article')
 {
     if (!is_string($string) || $string == '') {
         return;
     }
     if (!NNText::stringContains($string, $this->params->start_tags)) {
         return;
     }
     // allow in component?
     if ($area == 'component' && in_array(JFactory::getApplication()->input->get('option'), $this->params->disabled_components)) {
         $this->protect($string);
         $this->removeAll($string, $area);
         NNProtect::unprotect($string);
         return;
     }
     $this->protect($string);
     // COMPONENT
     if (NNFrameworkFunctions::isFeed()) {
         $s = '#(<item[^>]*>)#s';
         $string = preg_replace($s, '\\1<!-- START: MODA_COMPONENT -->', $string);
         $string = str_replace('</item>', '<!-- END: MODA_COMPONENT --></item>', $string);
     }
     if (strpos($string, '<!-- START: MODA_COMPONENT -->') === false) {
         $this->tagArea($string, 'MODA', 'component');
     }
     $this->params->message = '';
     $components = $this->getTagArea($string, 'MODA', 'component');
     foreach ($components as $component) {
         if (strpos($string, $component['0']) === false) {
             continue;
         }
         $this->processModules($component['1'], 'components');
         $string = str_replace($component['0'], $component['1'], $string);
     }
     // EVERYWHERE
     $this->processModules($string, 'other');
     NNProtect::unprotect($string);
 }
Beispiel #6
0
	function onAfterRender()
	{
		// not in pdf's
		if (JFactory::getDocument()->getType() == 'pdf')
		{
			return;
		}

		$html = JResponse::getBody();
		if ($html == '')
		{
			return;
		}

		if (JFactory::getDocument()->getType() != 'html')
		{
			$this->replaceTags($html);
		}
		else
		{
			// only do stuff in body
			list($pre, $body, $post) = nnText::getBody($html);
			$this->protect($body);
			$this->replaceTags($body);
			$html = $pre . $body . $post;
		}

		$this->cleanLeftoverJunk($html);
		NNProtect::unprotect($html);

		JResponse::setBody($html);
	}
Beispiel #7
0
 /**
  * onAfterRender
  */
 public function onAfterRender()
 {
     // only in html and feeds
     if (JFactory::getDocument()->getType() !== 'html' && JFactory::getDocument()->getType() !== 'feed') {
         return;
     }
     // Grab the body (but be gentle)
     $html = JResponse::getBody();
     if ($html == '') {
         return;
     }
     list($pre, $body, $post) = NNText::getBody($html);
     $this->protect($body);
     $this->replaceInTheRest($body);
     NNProtect::unprotect($body);
     $this->cleanTagsFromHead($pre);
     $html = $pre . $body . $post;
     $this->cleanLeftoverJunk($html);
     // Throw the body back (less gentle)
     JResponse::setBody($html);
 }
 function protectEmails(&$str, $area = '')
 {
     if (!is_string($str) || $str == '') {
         return;
     }
     // No action needed if no @ is found
     if (strpos($str, '@') === false) {
         return;
     }
     if ($this->params->protect_in_js && strpos($str, '</script>') !== false) {
         if (preg_match_all($this->params->regex_js, $str, $matches, PREG_SET_ORDER) > 0) {
             foreach ($matches as $match) {
                 $script = $match[0];
                 while (preg_match($this->params->regex_injs, $script, $regs, PREG_OFFSET_CAPTURE)) {
                     $protected = str_replace(array('.', '@'), array($regs[1][0] . ' + ' . 'String.fromCharCode(46)' . ' + ' . $regs[1][0], $regs[1][0] . ' + ' . 'String.fromCharCode(64)' . ' + ' . $regs[1][0]), $regs[0][0]);
                     $script = substr_replace($script, $protected, $regs[0][1], strlen($regs[0][0]));
                 }
                 $str = str_replace($match[0], $script, $str);
             }
         }
     }
     $this->protect($str);
     // Do not protect if {emailprotector=off} is found in text
     if (strpos($str, '{emailprotector=off}') !== false || strpos($str, '<!-- EPOFF -->') !== false) {
         $str = str_replace(array('<p>{emailprotector=off}</p>', '{emailprotector=off}'), '<!-- EPOFF -->', $str);
         NNProtect::unprotect($str);
         return;
     }
     // Fix derivatives of link code <a href="http://mce_host/ourdirectory/email@domain.com">email@domain.com</a>
     // This happens when inserting an email in TinyMCE, cancelling its suggestion to add the mailto: prefix...
     if (strpos($str, 'mce_host') !== false) {
         $str = preg_replace('#"http://mce_host([\\x20-\\x7f][^<>]+/)#i', '"mailto:', $str);
     }
     // Search for derivatives of link code <a href="mailto:email@domain.com">anytext</a>
     while (preg_match($this->params->regex_link, $str, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = str_replace('&amp;', '&', $regs[2][0]);
         $protected = $this->protectEmail($mail, $regs[5][0], $regs[1][0], $regs[4][0]);
         $str = substr_replace($str, $protected, $regs[0][1], strlen($regs[0][0]));
     }
     NNProtect::protectHtmlTags($str);
     $pre = '';
     $post = '';
     $len = strlen($str);
     // Split the string for very long strings
     if ($len > 2000) {
         $first = strpos($str, '@');
         if ($first === false) {
             NNProtect::unprotect($str);
             return;
         }
         $last = strrpos($str, '@');
         $first = max($first - 100, 0);
         $last = min($last + 100, $len);
         $pre = substr($str, 0, $first);
         $post = substr($str, $last);
         $str = substr($str, $first, $last - $first);
     }
     // Search for plain text email@domain.com
     while (preg_match($this->params->regex, $str, $regs, PREG_OFFSET_CAPTURE)) {
         $protected = $this->protectEmail('', $regs[1][0]);
         $str = substr_replace($str, $protected, $regs[1][1], strlen($regs[1][0]));
     }
     $str = $pre . $str . $post;
     NNProtect::unprotect($str);
 }