Skip to content

Commit f040b7f

Browse files
authored
[5.3] Apply mail cloaking in finder results (#44641)
1 parent 389ddae commit f040b7f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

components/com_finder/src/View/Search/HtmlView.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ public function display($tpl = null)
208208
if (\is_array($this->results)) {
209209
$dispatcher = $this->getDispatcher();
210210

211-
// Import Finder plugins
211+
// Import Content and Finder plugins
212212
PluginHelper::importPlugin('finder', null, true, $dispatcher);
213+
PluginHelper::importPlugin('content', null, true, $dispatcher);
213214

214215
foreach ($this->results as $result) {
215216
$dispatcher->dispatch('onFinderResult', new ResultEvent('onFinderResult', [

plugins/content/emailcloak/src/Extension/EmailCloak.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Joomla\Plugin\Content\EmailCloak\Extension;
1212

1313
use Joomla\CMS\Event\Content\ContentPrepareEvent;
14+
use Joomla\CMS\Event\Finder\ResultEvent;
1415
use Joomla\CMS\HTML\HTMLHelper;
1516
use Joomla\CMS\Plugin\CMSPlugin;
1617
use Joomla\Event\SubscriberInterface;
@@ -36,7 +37,33 @@ final class EmailCloak extends CMSPlugin implements SubscriberInterface
3637
*/
3738
public static function getSubscribedEvents(): array
3839
{
39-
return ['onContentPrepare' => 'onContentPrepare'];
40+
return [
41+
'onContentPrepare' => 'onContentPrepare',
42+
'onFinderResult' => 'onFinderResult',
43+
];
44+
}
45+
46+
/**
47+
* Plugin that cloaks all emails in com_finder from spambots via Javascript.
48+
*
49+
* @param ResultEvent $event Event instance
50+
*
51+
* @return void
52+
*/
53+
public function onFinderResult(ResultEvent $event)
54+
{
55+
$item = $event->getItem();
56+
57+
// If the item does not have a text property there is nothing to do
58+
if (!isset($item->description)) {
59+
return;
60+
}
61+
62+
$text = $this->cloak($item->description);
63+
64+
if ($text) {
65+
$item->description = $text;
66+
}
4067
}
4168

4269
/**

0 commit comments

Comments
 (0)