How to implement that block directly into a theme?

Permalink Browser Info Environment
I just purchased that add-on, now i'm wondering how to implement it directly into the footer.php of my theme, just to hide the email adress of my client from spam bots. Is there a way to achieve that?

Michael

Type: Discussion
Status: New
okapi
View Replies: View Best Answer
Shotster replied on at Permalink Reply
Shotster
Hi Michael,

Absolutely there's a way to do that. It's how I use it on a client's site as well. In fact, either of two approaches should work.

1) Developer API Method - This is simply a matter of loading both the Encrypted E-Mail Address (EEA) PHP class file and JavaScript file from your PHP code and then creating an instance of the EEA class. It does not make use of the block UI. I'd suggest loading the JS from your theme's header.php file like this...

$eeaJSFile = 'eea.min.js';
$pkgName = 'pmw_encrypted_email_address';
$this->addHeaderItem( $html->javascript( $eeaJSFile, $pkgName ));


That ensures that the JS will be loaded on every page of the site. Then in your theme's footer.php, do like this...

$pkgName = 'pmw_encrypted_email_address';
//Load the EEA library file
Loader::library('eea', $pkgName);
//Output the encrypted address
echo new PmwEncryptedEmailAddress( 'email.address@company.com' );

That's it. The other method is as follows...


2) Global Scrapbook Method - Create an EEA block in your global scrapbook. Give it a name. Then, in your theme's footer.php file, load that block...

$b = Block::getByName('Scrapbook EEA Block Name');  
if( is_object($b) ) $b->display();


I'd recommend the first approach. If you have any other questions or problems, let me know.

-Steve
okapi replied on at Permalink Reply
okapi
Hi Steve!
Thank you for your super-speedy repy!
Unfortunately i don't know where exactly to put the code snippets you provided. And where do the additional options go?

This should go to the header.php of my theme (where actually, between the head tags...?)
<?php
$eeaJSFile = 'eea.min.js';
$pkgName = 'pmw_encrypted_email_address';
$this->addHeaderItem( $html->javascript( $eeaJSFile, $pkgName ));
?>

This should go to the footer.php or anyplace where the email/link should appear, e.g. left_sidebar.php or another page type, right?
<?php
$pkgName = 'pmw_encrypted_email_address';
//Load the EEA library file
Loader::library('eea', $pkgName);
//Output the encrypted address
echo new PmwEncryptedEmailAddress( 'mail@email.com' );
?>


Cheers,
Michael
Shotster replied on at Permalink Reply
Shotster
> This should go to the header (where, between the head tags...?)

Yep, between the head tags will work fine. You can of course distill it down to...

$this->addHeaderItem( $html->javascript( 'eea.min.js', 'pmw_encrypted_email_address'));

...I just like using variables for clarity, but string literals work fine.


> This should go to the footer or anyplace where the email/link should appear, right?

Correct, any place you want to display an encrypted address. Of course, you need load the EEA library file only once within any given PHP file, and then you can encrypt/output as many addresses as you'd like.

// Need to load EEA class only once within a given PHP file
Loader::library('eea', 'pmw_encrypted_email_address');

The EEA constructor method takes an optional second argument which is an array of output options for the encrypted address...

$addressToEncrypt = 'email.address@company.com';
$eeaOptions = array(
 'isLink'=> 1, // 0 to display address only - i.e. no hyperlink
 'subj' => 'Web Inquiry',
 'body' => 'Details of inquiry...',
 'text' => 'contact us'
);
// Encrypt the address with supplied options
$encryptedAddress = new PmwEncryptedEmailAddress( $addressToEncrypt, $eeaOptions );
// Output the encrypted address/link
echo $encryptedAddress;


Let me know if there's anything else.

-Steve
okapi replied on at Permalink Reply
okapi
Thank you so much for your help, and sorry... as i still don't get it to work...

Let me sum up what i have tried:

I installed your add-on.
I put this code into the head section of the header.php of my theme:
<?php $this->addHeaderItem( $html->javascript( 'eea.min.js', 'pmw_encrypted_email_address')); ?>

Then i put this code into the html of the footer.php of my theme, where the enrypted email should appear:
<?php
$addressToEncrypt = 'email.address@my_clients_company.com';
$eeaOptions = array(
 'isLink'=> 1, // 0 to display address only - i.e. no hyperlink
 'subj' => 'Web Inquiry',
 'body' => 'Details of inquiry...',
 'text' => 'Email'
);
// Encrypt the address with supplied options
$encryptedAddress = new PmwEncryptedEmailAddress( $addressToEncrypt, $eeaOptions );
// Output the encrypted address/link
echo $encryptedAddress;
?>


But i still can't figure out where that code should go:
<?php
Loader::library('eea', 'pmw_encrypted_email_address');
?>


Sorry for being so stupid... at least this thread maybe help others too.

Michael
Shotster replied on at Permalink Reply
Shotster
No problem, Michael. No question is stupid.

The "Loader::library()" line also goes in the footer.php file. Somewhere near the top is just fine, although anywhere before you invoke "new PmwEncryptedEmailAddress()" will work.

That line loads the required PHP class which allows you to instantiate a new encrypted address with the "new PmwEncryptedEmailAddress()" call.

Let me know if that helps, and don't hesitate to ask any other questions.

Regards,

-Steve
okapi replied on at Permalink Reply
okapi
Thank you so much for your patience, Steve.

I did everything as you described above. Still doesn't work...

Adding this code snippet to the header of the header.php of my theme
<?php $this->addHeaderItem( $html->javascript( 'eea.min.js', 'pmw_encrypted_email_address')); ?>

results in the following error, when i try to log in as admin:

Fatal error: Call to a member function javascript() on a non-object in /***/***/elements/header.php on line 14

(Line 14 is the line of the added code).

Michael
Shotster replied on at Permalink Reply
Shotster
Change the code in header.php to...

$html = Loader::helper('html');
$this->addHeaderItem( $html->javascript( 'eea.min.js', 'pmw_encrypted_email_address'));

In other words, add the first line above. That loads the needed C5 helper file.


-Steve
jalen replied on at Permalink Reply
jalen
It would be AMAZING if you added this functionality to the standard Content block... to create an enhanced Content block. The idea would be to scan for any mailto:'s and replace the addresses with encrypted ones.
This is a standard feature of some other CMS's. Maybe the C5 team would be willing to buy your work and incorporate it themselves...
okapi replied on at Permalink Reply
okapi
Right, it's a default feature of TYPO3, for example. I would also love to see email encryption for C5 working globally!

Michael
Shotster replied on at Permalink Reply
Shotster
> It would be AMAZING if you added this functionality to the standard Content block...

Believe it or not, I've been toying with that notion. Actually, if I do it, I will create a new type of content block that uses a different editor because I'm not all that happy with Tiny MCE. I'm not saying this will happen for sure, bit it's good to know there's some interest in it. Thanks for your comments.

On a somewhat related note, I will soon be submitting a new package to the marketplace which takes advantage of the Encrypted E-Mail Address block if it's installed. I will announce it when it's available, but it takes at least a week to get through the marketplace review process.

Regards,

-Steve
jalen replied on at Permalink Reply
jalen
Shotster replied on at Permalink Reply
Shotster
> I will soon be submitting a new package to the marketplace
> which takes advantage of the Encrypted E-Mail Address block if it's installed.

Just to follow through on this, my new block is now available...

http://www.concrete5.org/marketplace/addons/enhanced-user-list/...

-Steve
okapi replied on at Permalink Best Answer Reply
okapi
After all works nicely now for me - thanks to Steve's precious help - i want to provide a brief summary of what has to be done to implement Steve's email encryption add-on into a theme:

The 1st code snippet goes in the head section of header.php of the theme:
<?php
// Load the C5 HTML helper object
$c5HtmlHelper = Loader::helper('html');
// Add the EEA JavaScript to the document head
$this->addHeaderItem( $c5HtmlHelper->javascript('eea.min.js', 'pmw_encrypted_email_address'));
?>

The 2nd code snippet goes anywhere in the html body of the theme (but always before the 3rd code snippet):
<?php
// Need to load EEA class only once within a given PHP file
Loader::library('eea', 'pmw_encrypted_email_address');
?>

The 3rd code snippet goes where the encrypted email adress should appear, anywhere in the html body of the theme (but always after the 2nd code snippet):
<?php
$addressToEncrypt = 'email@adress.com';
$eeaOptions = array(
 'isLink'=> 1, // 0 to display address only - i.e. no hyperlink
 'subj' => 'Web Inquiry',
 'body' => 'Details of inquiry...',
 'text' => 'contact us'
);
// Encrypt the address with supplied options
$encryptedAddress = new PmwEncryptedEmailAddress( $addressToEncrypt, $eeaOptions );
// Output the encrypted address/link
echo $encryptedAddress;
?>


I hope this is of interest for others who want to use this add-on directly in a theme, e.g. for email-links at the footer of a website.

Michael

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.