Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Snippets by user Damjan Malis Snippets by user Damjan Malis

Encode URL and caption like Smarty does ;)

This is very simple and effective mail helper. Original code is taken from Smarty's mailto plugin.
This helper scrambles your email addresses so those nasty web bots 'can not' harvest them.

In /lib/helper/MailEncodeHelper.php

<?php
function encode_mail($Address, $Caption=null)
{
  if ($Caption == null)
    $Caption = $Address;
 
  $string = 'document.write(\'<a href="mailto:'.$Address.'">'.$Caption.'</a>\');';
  $js_encode = '';
  for ($x=0; $x < strlen($string); $x++)
    $js_encode .= '%' . bin2hex($string[$x]);
 
  return '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>';
}
?>

In template

<?php use_helper('MailEncode') ?>
 
My email: <?php echo encode_mail('info@example.com'); ?>  
or   
My email: <?php echo encode_mail('info@example.com', 'Damjan Malis'); ?>
by Damjan Malis on 2006-07-19, tagged email  encode  helper 
(4 comments)

Compute public path

Here is how you can get public path to i.e. http://www.domain.com/flash/charts/chart.swf

Put this code into your template.

<?php
echo image_path('/flash/charts/chart.swf', true);
?>

Tnx Matt. This is the function I was looking for :)

by Damjan Malis on 2006-08-07, tagged url 
(3 comments)