Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Apply mail cloaking in finder results #44641

Open
wants to merge 5 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/com_finder/src/View/Search/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ public function display($tpl = null)
if (\is_array($this->results)) {
$dispatcher = $this->getDispatcher();

// Import Finder plugins
// Import Content and Finder plugins
PluginHelper::importPlugin('finder', null, true, $dispatcher);
PluginHelper::importPlugin('content', 'emailcloak', true, $dispatcher);
SniperSister marked this conversation as resolved.
Show resolved Hide resolved

foreach ($this->results as $result) {
$dispatcher->dispatch('onFinderResult', new ResultEvent('onFinderResult', [
Expand Down
29 changes: 28 additions & 1 deletion plugins/content/emailcloak/src/Extension/EmailCloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Joomla\Plugin\Content\EmailCloak\Extension;

use Joomla\CMS\Event\Content\ContentPrepareEvent;
use Joomla\CMS\Event\Finder\ResultEvent;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;
Expand All @@ -36,7 +37,33 @@ final class EmailCloak extends CMSPlugin implements SubscriberInterface
*/
public static function getSubscribedEvents(): array
{
return ['onContentPrepare' => 'onContentPrepare'];
return [
'onContentPrepare' => 'onContentPrepare',
'onFinderResult' => 'onFinderResult',
];
}

/**
* Plugin that cloaks all emails in com_finder from spambots via Javascript.
*
* @param ResultEvent $event Event instance
*
* @return void
*/
public function onFinderResult(ResultEvent $event)
{
$item = $event->getItem();

// If the item does not have a text property there is nothing to do
if (!isset($item->description)) {
return;
}

$text = $this->cloak($item->description);

if ($text) {
$item->description = $text;
}
}

/**
Expand Down