Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion plugins/content/emailcloak/emailcloak.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CONTENT_EMAILCLOAK_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\EmailCloak</namespace>
<files>
<filename plugin="emailcloak">emailcloak.php</filename>
<folder plugin="emailcloak">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_content_emailcloak.ini</language>
Expand Down
48 changes: 48 additions & 0 deletions plugins/content/emailcloak/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Content.emailcloak
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Content\EmailCloak\Extension\EmailCloak;

return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new EmailCloak(
$dispatcher,
(array) PluginHelper::getPlugin('content', 'emailcloak')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt

* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

namespace Joomla\Plugin\Content\EmailCloak\Extension;

use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\String\StringHelper;
Expand All @@ -23,15 +23,8 @@
*
* @since 1.5
*/
class PlgContentEmailcloak extends CMSPlugin
final class EmailCloak extends CMSPlugin
{
/**
* @var \Joomla\CMS\Application\SiteApplication
*
* @since 3.9.0
*/
protected $app;

/**
* Plugin that cloaks all emails in content from spambots via Javascript.
*
Expand All @@ -46,16 +39,16 @@ public function onContentPrepare($context, &$row, &$params, $page = 0)
{
// Don't run if in the API Application
// Don't run this plugin when the content is being indexed
if ($this->app->isClient('api') || $context === 'com_finder.indexer') {
if ($this->getApplication()->isClient('api') || $context === 'com_finder.indexer') {
return;
}

// If the row is not an object or does not have a text property there is nothign to do
// If the row is not an object or does not have a text property there is nothing to do
if (!is_object($row) || !property_exists($row, 'text')) {
return;
}

$this->_cloak($row->text, $params);
$this->cloak($row->text, $params);
}

/**
Expand All @@ -66,7 +59,7 @@ public function onContentPrepare($context, &$row, &$params, $page = 0)
*
* @return string A regular expression that matches a link containing the parameters.
*/
protected function _getPattern($link, $text)
private function getPattern($link, $text)
{
$pattern = '~(?:<a ([^>]*)href\s*=\s*"mailto:' . $link . '"([^>]*))>' . $text . '</a>~i';

Expand All @@ -82,7 +75,7 @@ protected function _getPattern($link, $text)
*
* @return void
*/
protected function _cloak(&$text, &$params)
private function cloak(&$text, &$params)
{
/*
* Check for presence of {emailcloak=off} which is explicits disables this
Expand Down Expand Up @@ -125,7 +118,7 @@ protected function _cloak(&$text, &$params)
* >[email protected]</a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add
* the mailto: prefix...
*/
$pattern = $this->_getPattern($searchEmail, $searchEmail);
$pattern = $this->getPattern($searchEmail, $searchEmail);
$pattern = str_replace('"mailto:', '"([\x20-\x7f][^<>]+/)', $pattern);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
Expand All @@ -146,7 +139,7 @@ protected function _cloak(&$text, &$params)
* >anytext</a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add
* the mailto: prefix...
*/
$pattern = $this->_getPattern($searchEmail, $searchText);
$pattern = $this->getPattern($searchEmail, $searchText);
$pattern = str_replace('"mailto:', '"([\x20-\x7f][^<>]+/)', $pattern);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
Expand All @@ -166,7 +159,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]"
* >[email protected]</a>
*/
$pattern = $this->_getPattern($searchEmail, $searchEmail);
$pattern = $this->getPattern($searchEmail, $searchEmail);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0];
Expand All @@ -185,7 +178,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]"
* ><anyspan >[email protected]</anyspan></a>
*/
$pattern = $this->_getPattern($searchEmail, $searchEmailSpan);
$pattern = $this->getPattern($searchEmail, $searchEmailSpan);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0];
Expand All @@ -204,7 +197,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]">
* <anyspan >anytext</anyspan></a>
*/
$pattern = $this->_getPattern($searchEmail, $searchTextSpan);
$pattern = $this->getPattern($searchEmail, $searchTextSpan);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0];
Expand All @@ -222,7 +215,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]">
* anytext</a>
*/
$pattern = $this->_getPattern($searchEmail, $searchText);
$pattern = $this->getPattern($searchEmail, $searchText);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0];
Expand All @@ -240,7 +233,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]">
* <img anything></a>
*/
$pattern = $this->_getPattern($searchEmail, $searchImage);
$pattern = $this->getPattern($searchEmail, $searchImage);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0];
Expand All @@ -258,7 +251,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]">
* <img anything>[email protected]</a>
*/
$pattern = $this->_getPattern($searchEmail, $searchImage . $searchEmail);
$pattern = $this->getPattern($searchEmail, $searchImage . $searchEmail);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0];
Expand All @@ -276,7 +269,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]">
* <img anything>any text</a>
*/
$pattern = $this->_getPattern($searchEmail, $searchImage . $searchText);
$pattern = $this->getPattern($searchEmail, $searchImage . $searchText);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0];
Expand All @@ -294,7 +287,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]?
* subject=Text">[email protected]</a>
*/
$pattern = $this->_getPattern($searchEmailLink, $searchEmail);
$pattern = $this->getPattern($searchEmailLink, $searchEmail);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0] . $regs[3][0];
Expand All @@ -316,7 +309,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]?
* subject=Text">anytext</a>
*/
$pattern = $this->_getPattern($searchEmailLink, $searchText);
$pattern = $this->getPattern($searchEmailLink, $searchText);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0] . $regs[3][0];
Expand All @@ -337,7 +330,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]?subject= Text"
* ><anyspan >[email protected]</anyspan></a>
*/
$pattern = $this->_getPattern($searchEmailLink, $searchEmailSpan);
$pattern = $this->getPattern($searchEmailLink, $searchEmailSpan);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0] . $regs[3][0];
Expand All @@ -356,7 +349,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code <a href="mailto:[email protected]?subject= Text">
* <anyspan >anytext</anyspan></a>
*/
$pattern = $this->_getPattern($searchEmailLink, $searchTextSpan);
$pattern = $this->getPattern($searchEmailLink, $searchTextSpan);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0] . $regs[3][0];
Expand All @@ -374,7 +367,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code
* <a href="mailto:[email protected]?subject=Text"><img anything></a>
*/
$pattern = $this->_getPattern($searchEmailLink, $searchImage);
$pattern = $this->getPattern($searchEmailLink, $searchImage);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0] . $regs[3][0];
Expand All @@ -396,7 +389,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code
* <a href="mailto:[email protected]?subject=Text"><img anything>[email protected]</a>
*/
$pattern = $this->_getPattern($searchEmailLink, $searchImage . $searchEmail);
$pattern = $this->getPattern($searchEmailLink, $searchImage . $searchEmail);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0] . $regs[3][0];
Expand All @@ -418,7 +411,7 @@ protected function _cloak(&$text, &$params)
* Search for derivatives of link code
* <a href="mailto:[email protected]?subject=Text"><img anything>any text</a>
*/
$pattern = $this->_getPattern($searchEmailLink, $searchImage . $searchText);
$pattern = $this->getPattern($searchEmailLink, $searchImage . $searchText);

while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
$mail = $regs[2][0] . $regs[3][0];
Expand Down