[fixed] plugin prefilter

Post Reply
Jean le Chauve

[fixed] plugin prefilter

Post by Jean le Chauve »

I made a plugin who obfuscate email adresses.
It work with 1.10.3 (name : prefilter.protect_email.php)

Code: Select all

<?php
function smarty_cms_prefilter_protect_email($tpl_output, &$smarty)
{
    $result = explode(':', $smarty->_current_file);
	if (count($result) > 0)
	{
		if ($result[0] == 'content' || $result[0] == 'evaluated template' || $result[0] == 'globalcontent')
		{
		$patterns = array ('#(<a).+(href="mailto:)([a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4})"(.+)(</a>)#iU',
                   '#[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}#i');
		$replace = array ('$3', '{mailto address="$0" encode="javascript"}');
		$tpl_output = preg_replace($patterns, $replace, $tpl_output);
		}
	}
    return $tpl_output;
}

function smarty_cms_about_prefilter_protect_email() {
	?>
	<p>Author: Jean le Chauve<jeanlechauve@gmail.com></p>
	<p>Version: 1.0</p>
	<p>
	Change History:<br/>
	None
	</p>
	<?php
}
?>
So, I modified it for 1.11-beta4 (name : prefilter.protect_email.php)

Code: Select all

<?php
function smarty_prefilter_protect_email($tpl_output, &$template)
{
    $smarty = $template->smarty;
	$result = explode(':', $smarty->_current_file);
	if (count($result) > 0)
	{
		if( startswith($result[0],'tmp_') ) $result[0] = 'template';
		if ($result[0] == 'content' || $result[0] == 'template' || $result[0] == 'globalcontent')
		{
		$patterns = array ('#(<a).+(href="mailto:)([a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4})"(.+)(</a>)#iU',
                   '#[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}#i');
		$replace = array ('$3', '{mailto address="$0" encode="javascript"}');
		$tpl_output = preg_replace($patterns, $replace, $tpl_output);
		}
	}
    return $tpl_output;
}
?>
It does'nt work >:(
Can you help me ? What'is wrong ?
Last edited by Jean le Chauve on Tue Jul 24, 2012 4:54 pm, edited 3 times in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: plugin prefilter

Post by calguy1000 »

What's not working. Not enough information to be able to help here.

Is your plugin being called, and just the 'private member' of the smarty class that you're accessing isn't available any more.

1.11 is due to be released TODAY so please provide information as soon as possible.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Jean le Chauve

Re: plugin prefilter

Post by Jean le Chauve »

Thank's for your interest.

The plugin prefilter.protect_email.php is not loaded. I tested it with :

Code: Select all

function smarty_prefilter_protect_email($tpl_output, &$template)
{
    $smarty = $template->smarty;
	$result = explode(':', $smarty->_current_file);
	print_r($result);
	return $tpl_output;
}
For test, I added the replacement code in the end of file prefilter.precompilefunc.php

Code: Select all

function smarty_prefilter_precompilefunc($tpl_output, &$template)
{
  $smarty = $template->smarty;
	$result = explode(':', $smarty->_current_file);
	if (count($result) > 1)
	{
	  if( startswith($result[0],'tmp_') ) $result[0] = 'template';

		switch ($result[0])
		{
		case 'stylesheet':
		  Events::SendEvent('Core','StylesheetPreCompile',array('stylesheet'=>&$tpl_output));
		  break;

			case "content":
			
				Events::SendEvent('Core', 'ContentPreCompile', array('content' => &$tpl_output));
				break;

		case 'tpl_top':
		case 'tpl_body':
		case 'tpl_head':
		case "template":
		  Events::SendEvent('Core', 'TemplatePreCompile', array('template' => &$tpl_output,'type'=>$result[0]));
		  break;

			case "globalcontent":
				Events::SendEvent('Core', 'GlobalContentPreCompile', array('global_content' => &$tpl_output));
				break;
			default:
				break;
		}

	}
	$patterns = array ('#(<a).+(href="mailto:)([a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4})"(.+)(</a>)#iU',
                   '#[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}#i');
	$replace = array ('$3', '{mailto address="$0" encode="javascript"}');
	$tpl_output = preg_replace($patterns, $replace, $tpl_output);
	Events::SendEvent('Core', 'SmartyPreCompile', array('content' => &$tpl_output));
	
	return $tpl_output;
}
?>
and the email replacement work.
How can I make the application loading my prefilter plugin ?
Last edited by Jean le Chauve on Sun Jul 22, 2012 6:10 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: plugin prefilter

Post by calguy1000 »

put a die() statement in at the top of the function... clear the cache, and see if it actually gets called. If it does not, then I'll take a quick look.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Jean le Chauve

Re: plugin prefilter

Post by Jean le Chauve »

I clear cache and put : die('not loaded');
Nothing happend
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: plugin prefilter

Post by calguy1000 »

Okay, I'll dig in.

Release has been put off by a week now anyways.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Jean le Chauve

Re: plugin prefilter

Post by Jean le Chauve »

Thank you :)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: plugin prefilter

Post by calguy1000 »

Fixed in SVN.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Jean le Chauve

Re: plugin prefilter

Post by Jean le Chauve »

Thank you very much :)
Here is the version for svn 8193 :
name : prefilter.protect_email.php

Code: Select all

<?php
function smarty_prefilter_protect_email($tpl_output, &$template)
{
	$smarty = $template->smarty;
        $result = explode(':', $smarty->_current_file);
	$patterns = array ('#(<a).+(href="mailto:)([a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4})"(.+)(</a>)#iU',
                   '#[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}#i');
        $replace = array ('$3', '{mailto address="$0" text="email" encode="javascript"}');
	if (count($result) > 1)
	{
	  if (startswith($result[0],'tmp_')) $result[0] = 'template';
		switch ($result[0])
		{
		case 'stylesheet':
			break;
		case "content":
			$tpl_output = preg_replace($patterns, $replace, $tpl_output);
			break;
		case 'tpl_top':
		case 'tpl_body':
		case 'tpl_head':
		case "template":
			$tpl_output = preg_replace($patterns, $replace, $tpl_output);
			break;
		case "globalcontent":
			$tpl_output = preg_replace($patterns, $replace, $tpl_output);
			break;
		default:
			break;
		}
	}
	
    $tpl_output = preg_replace($patterns, $replace, $tpl_output);
    return $tpl_output;
}
?>
enjoy :)
Post Reply

Return to “Closed Issues”