{NOSPAM_EMAIL} Replacement Tag

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

{NOSPAM_EMAIL} Replacement Tag

Post by marcus@localhorst »

Holla,

I've wrote this tag to encode e-mail links to prevent for spam.

{NOSPAM_EMAIL:mail@adress.tld} will produce

Code: Select all

<a href="mailto:%6D%61%69%6C%40%61%64%72%65%73%73%2E%74%6C%64">mail<span>@</span>adress<span>.</span>tld</a>
you can replace @ and . with any combination you want to confuse the robots.

UPDATE
it's better now :-)

You can use now:
{NOSPAM_EMAIL:mail@adress.tld:linktext} this will produce

Code: Select all

<a href="mailto:%6D%61%69%6C%40%61%64%72%65%73%73%2E%74%6C%64">linktext</a>

just paste the code into a file inside the frontend_render folder and use the tag in your contentparts.

greetings marcus

Code: Select all

<?php 

/******************************************** 
titel:          {NOSPAM_EMAIL} Replacement-Tag 
description:  1.{NOSPAM_EMAIL:mail@adress.tld} 
                this tag will encode your emailadress to hexcode 
                the output looks like this: 
                <a href="mailto:%6D%61%69%6C%40%61%64%72%65%73%73%2E%74%6C%64">mail<span>@</span>adress<span>.</span>tld</a>
							2.{NOSPAM_EMAIL:mail@adress.tld:Linktext}
							  the output looks like this: 
                <a href="mailto:%6D%61%69%6C%40%61%64%72%65%73%73%2E%74%6C%64">linktext/a>
								
notice:         these two vars replace @ and . with the chars you prefer like this: mail (at) adress (dot) tdl 
                $ats = "(at)"; 
                $dots = "(dot)"; 
                          
                look at this too: 
                http://www.phpwcms.de/forum/viewtopic.php?t=4819 
                
author:         Marcus Obst 
last modified:  07.02.2006
********************************************/ 
function no_spam($mail,$alt='') { 
// these vars replace the @s and dots 
$ats = "<span>@</span>"; 
$dots = "<span>.</span>";
      $str = "";          
      $a = unpack("C*", $mail); 
      foreach ($a as $b) 
         $str .= sprintf("%%%X", $b); 
             $enc_mail = str_replace("@",$ats,$alt); 
             $enc_mail = str_replace(".",$dots,$enc_mail);
             $str = "<a href=\"mailto:" . $str . "\">" . $enc_mail . "</a>"; 
      return $str; 
   } 

if( ! ( strpos($content["all"],'{NOSPAM_EMAIL')==false ) ) {
        //$content["all"] = str_replace('{NAV_LIST_ALL}','{NAV_LIST_ALL:0:navcontainer}',$content["all"]);
				$content["all"] = preg_replace('/\{NOSPAM_EMAIL:([\w|@|.|\-|_|\+]+)\}/','{NOSPAM_EMAIL:$1:$1}',$content["all"]);
        $content["all"] = preg_replace('/\{NOSPAM_EMAIL:([\w|@|.|\-|_|\+]+):(.*?)\}/e','no_spam("$1","$2")',$content["all"]);
}	


?>
Last edited by marcus@localhorst on Tue 7. Feb 2006, 20:07, edited 5 times in total.
jscholtysik

Post by jscholtysik »

Hi Marcus,


finally a replacement tag that does not affect the core code. Great!


@ Pappnase: Hi Oliver, new stuff for your Add On section in the docu site !



Joachim
Pappnase

Post by Pappnase »

hello joachim

yes you're right if i had the time i will implement it!

atm i'm very busy!
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

jscholtysik wrote:Hi Marcus,
finally a replacement tag that does not affect the core code. Great!
Yep very nice.... Maybe it can inspire other ppl to make replacement tags... this one could be a kind of "template"
http://www.studmed.dk Portal for doctors and medical students in Denmark
jscholtysik

Post by jscholtysik »

Hi frold,


here we are again to discuss a general description for "how to create an extension or add on for phpwcms"... :-)


Joachim
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

i made this with basic php knowlege and the {TOPLEVEL} Tag as help.
Some things are unclear for me and i would like to know something more. for example about the frontend_init folder (i think it is for querys and the frontend_render folder is for display data)
well, a tutorial would be great :-)
brans

Post by brans »

hi marcus!

Thank you for your Replacement Tag! This is a very good one!

I'd love to have such people like you with us at the dev-corner.

If you are interested in developing future phpwcms add-ons, please write me a PN or email or read my threat at:
Phpwcms-Discussion => Volunteers needed
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

marcus@localhorst wrote:i made this with basic php knowlege and the {TOPLEVEL} Tag as help.
Some things are unclear for me and i would like to know something more. for example about the frontend_init folder (i think it is for querys and the frontend_render folder is for display data)
well, a tutorial would be great :-)
well I found this on the docu pages...
$phpwcms["allow_ext_init"] = 0;

This function allows you to load your own PHP scripts before phpWCMS is loaded. Your files are stored in the following directory.
/phpwcms_template/inc_script/frontend_init
Default = 0 Forbidden / 1 = Allowed.

$phpwcms["allow_ext_render"] = 0;

If you use existing functions from the INIT folder for rendering the page.
These files can be rendered from the directory
/phpwcms_template/inc_script/frontend_render
Default = 0 Forbidden / 1 = Allowed.
http://www.phpwcms-docu.de/conf.inc.php_en.phtml
http://www.studmed.dk Portal for doctors and medical students in Denmark
spirelli
Posts: 996
Joined: Tue 27. Jul 2004, 13:37
Location: London

Post by spirelli »

jscholtysik wrote: @ Pappnase: Hi Oliver, new stuff for your Add On section in the docu site
Pappnase does not equal Oliver!


----------------------


Does this work in any way with the mail form content part??
rk
Posts: 162
Joined: Sat 24. Apr 2004, 23:48
Location: Hannover, Germany
Contact:

Post by rk »

spirelli wrote: Pappnase does not equal Oliver!
Pappnase IS equal Oliver, but he is not equal OG :-).
Ralf
novallis
Posts: 121
Joined: Tue 7. Dec 2004, 11:23
Location: Hassloch, Germany

Post by novallis »

@ marcus@localhorst:

Thank you for the good work!

Is it possible to enhance the Replacement Tag to show a alternative text instead of the email adress, for example

Code: Select all

<a href="mailto:eamil@adress.com>alternative text</a>
So the replacemant tag needs a further parameter "alttext" for example like:

{NOSPAM_EMAIL:mail@adress.tld:alttext}

Best regards
novallis
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

mmm...
should be possible
{NOSPAM_EMAIL:name@domain.tld:alternative Text}
try this:

Code: Select all

function no_spam($mail='',$alt='') { 
// 1. just added a 2. parameter to the function ($alt)
      $str = "";          
      $a = unpack("C*", $mail); 
      foreach ($a as $b) 
         $str .= sprintf("%%%X", $b); 
             $str = "<a href=\"mailto:" . $str . "\">" . $alt . "</a>"; 
      return $str; 
   } 

if( ! ( strpos($content["all"],'{NOSPAM_EMAIL')===false ) ) { 
  $content["all"] = preg_replace('/\{NOSPAM_EMAIL:(.*?):(.*?)\}/e','no_spam("$1","$2");',$content["all"]);
//2. add a 2. regExpr to catch tha alternativ text ->NOSPAM_EMAIL:(.*?):(.*?)
//3. add the 2. parameter to the function "no_spam("$1","$2");" ($2 holds the catched alternative text
} 
this is a quick and dirty hack but it works like you want.
(but only in this way not in both ways)

best
m.
novallis
Posts: 121
Joined: Tue 7. Dec 2004, 11:23
Location: Hassloch, Germany

Post by novallis »

Thank you for your quick reply.

I will try it out this evening.

Regards
Novallis
spirelli
Posts: 996
Joined: Tue 27. Jul 2004, 13:37
Location: London

Post by spirelli »

rk wrote:
spirelli wrote: Pappnase does not equal Oliver!
Pappnase IS equal Oliver, but he is not equal OG :-).
Oh yeah, strange I know this normally. Hmmm, sorry to everyone.
User avatar
nekket
Posts: 613
Joined: Tue 18. Nov 2003, 15:46
Location: Baden-Baden
Contact:

Post by nekket »

I love this MOD! Thank you, I was looking for somthing like this :D
Post Reply