• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: [fixed] plugin prefilter
PostPosted: Sat Jul 21, 2012 8:50 pm 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
I made a plugin who obfuscate email adresses.
It work with 1.10.3 (name : prefilter.protect_email.php)
\$1:
<?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&lt;jeanlechauve@gmail.com&gt;</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)
\$1:
<?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.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Sun Jul 22, 2012 4:06 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 8167
Location: Fernie British Columbia, Canada
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.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Sun Jul 22, 2012 6:05 pm 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
Thank's for your interest.

The plugin prefilter.protect_email.php is not loaded. I tested it with :
\$1:
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
\$1:
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.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Sun Jul 22, 2012 6:06 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 8167
Location: Fernie British Columbia, Canada
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.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Sun Jul 22, 2012 6:16 pm 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
I clear cache and put : die('not loaded');
Nothing happend


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Sun Jul 22, 2012 6:27 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 8167
Location: Fernie British Columbia, Canada
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.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Sun Jul 22, 2012 6:44 pm 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
Thank you :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Mon Jul 23, 2012 3:33 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 8167
Location: Fernie British Columbia, Canada
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.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin prefilter
PostPosted: Mon Jul 23, 2012 7:06 pm 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
Thank you very much :)
Here is the version for svn 8193 :
name : prefilter.protect_email.php
\$1:
<?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 :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Hosting Nation - Managed CMSMS Hosting