Welcome Guest, Not a member yet? Register   Sign In
helper - advice needed
#1

[eluser]LuckyFella73[/eluser]
Hi codeigniters,

I want to set up a helper that will encode email addresses in ascii.
Where would be the best place to implement it? Would you extend
the text- or email helper or would you just set up a new helper?
#2

[eluser]johnwbaxter[/eluser]
Entirely up to you to be honest, helpers are such small things that the overhead is minimal to say the least. If it was me, i would make my own helper. But if you think it relates to another helper that you're using / loading anyway then you may as well extend that helper.
#3

[eluser]LuckyFella73[/eluser]
I'll set it up as new helper then because I can't find a place
in the existing helpers which makes me think that it should be placed there.

Thanks for your comment!
#4

[eluser]johnwbaxter[/eluser]
No problemo.
#5

[eluser]LuckyFella73[/eluser]
I just finished my helper and an other question popped up ...

How has the comment block to look like to be correct?

Do I just paste this:
Code:
/** CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package        CodeIgniter
* @author        ExpressionEngine Dev Team
* @copyright    Copyright (c) 2008 - 2009, EllisLab, Inc.
* @license        http://ellislab.com/codeigniter/user-guide/license.html
* @link        http://codeigniter.com
* @since        Version 1.0
* @filesource
*/

and then something like that:
Code:
/**
* E-Mail encoder -  ASCII
*
* encodes e-mail addresses
*
* @access    public
* @param    string - e-mail address
* @param    string
* @param    bool - 'true' adds 'mailto'
* @param    string - name of css class
* @return    string
*/

// followed by the function ..

Seems to be a stupid question but I'm not familiar with this kind of stuff ..
#6

[eluser]LuckyFella73[/eluser]
In case someone else needs this ..

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Encodes (ASCII) email addresses for basic spam protection
*
* @access    public
* @param    string - email address
* @param    string
* @param    bool
* @param    string - name of css class
* @return    string
*
* @author    Luckyfella73
*/

// ------------------------------------------------------------------------

/**
* Usage Exaples:
*
* returns pure email address ASCII encoded:
* echo (encode_email('[email protected]'));
*
* returns email address ASCII encoded with "mailto: link" and defined anchor text:
* echo (encode_email('[email protected]','John Doe','TRUE'));
*
* returns email address ASCII encoded with mailto: link, defined anchor text and css class for <a> tag:
* echo (encode_email('[email protected]','John Doe','TRUE','my-link-style'));
*/
if ( ! function_exists('encode_email'))
{
    function encode_email($email, $anchor_text = '', $mailto = FALSE, $css = '')
    {
        $email = trim($email);
        $anchor_text = trim($anchor_text);
        $css = trim($css);

        if ($email === '')
        {
            return '';
        }

        $email_encoded = '';
        for ($i=0; $i < strlen($email); $i++)
        {
            $email_encoded .= '&#'.ord(substr($email,$i)).';';
        }

        if ($anchor_text === '')
        {
            $anchor_text = $email_encoded;
        }

        if ($mailto === TRUE)
        {
            if (strlen($css) > 1)
            {
                $css = ' class="'.$css.'" ';
            }
            return '<a href="milto'.$email_encoded.'">'.$anchor_text.'</a>'. "\n";
        }
        else
        {
            return $email_encoded;
        }
    }
}

/* End of file email_encode_helper.php */
/* Location: ./system/application/helpers/email_encode_helper.php */




Theme © iAndrew 2016 - Forum software by © MyBB