On Fri, Oct 8, 2010 at 4:39 AM, hoss7 <[email protected]> wrote:
> i need some helper for convert email to image,
> i am new in cakephp.
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

I wouldn't bother with doing all that.

app/config/bootstrap.php:

/**
 * Wrap an email address in a formatted span tag in such a way
 * as to allow for easy javascript translation to a normal mailto: link.
 *
 * this:
 * [email protected], 'email foo!', 'some title text'
 * becomes:
 * <span class="Obfuscated" title="some title text">email foo! [ foo
AT bar DOT net ]</span>
 *
 * @param       string  address email address
 * @param       string  text    link text
 * @param       string  title   link title
 * @return      string                  obfuscated address, wrapped in i span 
tag
 **/
function obfuscateEmail($address, $text= null, $title = null, $subject = null)
{
        if (empty($address)) return null;
        
        $regexp = 
'^[_a-z0-9-]+(\.[_a-z0-9-]+)*...@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$';
        $search = Array('@', '.');
        $replace = Array(' AT ', ' DOT ');
        $class = 'Obfuscated';
        
        if (is_string($address) && eregi($regexp, $address))
        {
                $obfuscated = str_replace($search, $replace, $address);

                if (!is_null($subject))
                {
                        $title .= "|${subject}";
                }
                
                return '<span class="'.$class.'" 
title="'.$title.'">'.trim("${text}
[ ${obfuscated} ]").'</span>';
        }
        return $address;
}

app/webroot/js/global.js (jquery):

$(function()
{
        ...

        /* Obfuscated email addresses. See bootstrap.php
         */
        $('.Obfuscated').each(deObfuscateEmail);

        ...
});

/**
 * De-obfuscate printed email addresses which are of the type:
 *
 * <span class="Obfuscated" title="some title">
 * some link text [ someone AT gmail DOT com ]
 * <span>
 *
 * The braces around the address part are hard-wired here; probably shouldn't be
 **/
function deObfuscateEmail(i)
{       
        var content = $(this).text();
        
        /* grab the part inside the braces, swap out placeholders, and trim
         */
        var obfuscated = content.match(/\[(.*)\]/);
        
        var address = obfuscated[1]
                .replace(' AT ', '@')
                .replace(new RegExp(' DOT ', 'g'), '.')
                .replace(/^\s+|\s+$/g, '');
                
        /* get everything before the braces and trim
         */
        var text = content.match(/.?[^[]+/);

        text = (text[0] != content)
                ? text[0].replace(/^\s+|\s+$/g, '')
                : address;      // if there's no text part, use the address
        
        var title = $(this).attr('title') || '';
        
        /* subject may be concatenated with title
         */
        if (title.indexOf('|') >= 0)
        {
                var parts = title.split('|');
                title = parts[0];
                address += '?subject=' + parts[1];
        }
        
        $(this).replaceWith($('<a href="mailto:' + address + '" title="' +
title + '">' + text + '</a>'));
}

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to