/** * Encrypt content using Javascript so that it's hidden when JS is disabled. * * This is mostly used to hide email addresses from scraper bots. * * @param string $content Content to encrypt * @param string $message Message shown if Javascript is disabled * * @see https://github.com/jnicol/standalone-phpenkoder StandalonePHPEnkoder on Github * * @since 1.7 * * @return string Content, encrypted */ public static function js_encrypt($content, $message = '') { $output = $content; if (!class_exists('StandalonePHPEnkoder')) { include_once GRAVITYVIEW_DIR . 'includes/lib/standalone-phpenkoder/StandalonePHPEnkoder.php'; } if (class_exists('StandalonePHPEnkoder')) { $enkoder = new StandalonePHPEnkoder(); $message = empty($message) ? __('Email hidden; Javascript is required.', 'gravityview') : $message; /** * @filter `gravityview/phpenkoder/msg` Modify the message shown when Javascript is disabled and an encrypted email field is displayed * @since 1.7 * @param string $message Existing message * @param string $content Content to encrypt */ $enkoder->enkode_msg = apply_filters('gravityview/phpenkoder/msg', $message, $content); $output = $enkoder->enkode($content); } return $output; }
<?php require_once 'StandalonePHPEnkoder.php'; $enkoder = new StandalonePHPEnkoder(); // Enkode all plaintext and mailto: links in a string. $html = '<p>Why not <a href="mailto:test@test.com?subject=Hello" tile="Email me">email me</a>. Your email will be sent to test@test.com. Here is another mailto, with an email address as the anchor text: <a href="mailto:test@test.com">test@test.com</a>. If you view source you shouldn\'t see any email addresses.</p>'; echo $enkoder->enkodeAllEmails($html);