66 *
77 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
88 * @license GNU General Public License version 2 or later; see LICENSE.txt
9-
10- * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
119 */
1210
11+ namespace Joomla \Plugin \Content \EmailCloak \Extension ;
12+
1313use Joomla \CMS \HTML \HTMLHelper ;
1414use Joomla \CMS \Plugin \CMSPlugin ;
1515use Joomla \String \StringHelper ;
2323 *
2424 * @since 1.5
2525 */
26- class PlgContentEmailcloak extends CMSPlugin
26+ final class EmailCloak extends CMSPlugin
2727{
28- /**
29- * @var \Joomla\CMS\Application\SiteApplication
30- *
31- * @since 3.9.0
32- */
33- protected $ app ;
34-
3528 /**
3629 * Plugin that cloaks all emails in content from spambots via Javascript.
3730 *
@@ -46,16 +39,16 @@ public function onContentPrepare($context, &$row, &$params, $page = 0)
4639 {
4740 // Don't run if in the API Application
4841 // Don't run this plugin when the content is being indexed
49- if ($ this ->app ->isClient ('api ' ) || $ context === 'com_finder.indexer ' ) {
42+ if ($ this ->getApplication () ->isClient ('api ' ) || $ context === 'com_finder.indexer ' ) {
5043 return ;
5144 }
5245
53- // If the row is not an object or does not have a text property there is nothign to do
46+ // If the row is not an object or does not have a text property there is nothing to do
5447 if (!is_object ($ row ) || !property_exists ($ row , 'text ' )) {
5548 return ;
5649 }
5750
58- $ this ->_cloak ($ row ->text , $ params );
51+ $ this ->cloak ($ row ->text , $ params );
5952 }
6053
6154 /**
@@ -66,7 +59,7 @@ public function onContentPrepare($context, &$row, &$params, $page = 0)
6659 *
6760 * @return string A regular expression that matches a link containing the parameters.
6861 */
69- protected function _getPattern ($ link , $ text )
62+ private function getPattern ($ link , $ text )
7063 {
7164 $ pattern = '~(?:<a ([^>]*)href\s*=\s*"mailto: ' . $ link . '"([^>]*))> ' . $ text . '</a>~i ' ;
7265
@@ -82,7 +75,7 @@ protected function _getPattern($link, $text)
8275 *
8376 * @return void
8477 */
85- protected function _cloak (&$ text , &$ params )
78+ private function cloak (&$ text , &$ params )
8679 {
8780 /*
8881 * Check for presence of {emailcloak=off} which is explicits disables this
@@ -125,7 +118,7 @@ protected function _cloak(&$text, &$params)
125118 * >[email protected] </a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add 126119 * the mailto: prefix...
127120 */
128- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchEmail );
121+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchEmail );
129122 $ pattern = str_replace ('"mailto: ' , '"([\x20-\x7f][^<>]+/) ' , $ pattern );
130123
131124 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
@@ -146,7 +139,7 @@ protected function _cloak(&$text, &$params)
146139 * >anytext</a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add
147140 * the mailto: prefix...
148141 */
149- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchText );
142+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchText );
150143 $ pattern = str_replace ('"mailto: ' , '"([\x20-\x7f][^<>]+/) ' , $ pattern );
151144
152145 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
@@ -166,7 +159,7 @@ protected function _cloak(&$text, &$params)
166159 * Search for derivatives of link code <a href="mailto:[email protected] " 167160168161 */
169- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchEmail );
162+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchEmail );
170163
171164 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
172165 $ mail = $ regs [2 ][0 ];
@@ -185,7 +178,7 @@ protected function _cloak(&$text, &$params)
185178 * Search for derivatives of link code <a href="mailto:[email protected] " 186179 * ><anyspan >[email protected] </anyspan></a> 187180 */
188- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchEmailSpan );
181+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchEmailSpan );
189182
190183 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
191184 $ mail = $ regs [2 ][0 ];
@@ -204,7 +197,7 @@ protected function _cloak(&$text, &$params)
204197 * Search for derivatives of link code <a href="mailto:[email protected] "> 205198 * <anyspan >anytext</anyspan></a>
206199 */
207- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchTextSpan );
200+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchTextSpan );
208201
209202 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
210203 $ mail = $ regs [2 ][0 ];
@@ -222,7 +215,7 @@ protected function _cloak(&$text, &$params)
222215 * Search for derivatives of link code <a href="mailto:[email protected] "> 223216 * anytext</a>
224217 */
225- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchText );
218+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchText );
226219
227220 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
228221 $ mail = $ regs [2 ][0 ];
@@ -240,7 +233,7 @@ protected function _cloak(&$text, &$params)
240233 * Search for derivatives of link code <a href="mailto:[email protected] "> 241234 * <img anything></a>
242235 */
243- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchImage );
236+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchImage );
244237
245238 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
246239 $ mail = $ regs [2 ][0 ];
@@ -258,7 +251,7 @@ protected function _cloak(&$text, &$params)
258251 * Search for derivatives of link code <a href="mailto:[email protected] "> 259252 * <img anything>[email protected] </a> 260253 */
261- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchImage . $ searchEmail );
254+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchImage . $ searchEmail );
262255
263256 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
264257 $ mail = $ regs [2 ][0 ];
@@ -276,7 +269,7 @@ protected function _cloak(&$text, &$params)
276269 * Search for derivatives of link code <a href="mailto:[email protected] "> 277270 * <img anything>any text</a>
278271 */
279- $ pattern = $ this ->_getPattern ($ searchEmail , $ searchImage . $ searchText );
272+ $ pattern = $ this ->getPattern ($ searchEmail , $ searchImage . $ searchText );
280273
281274 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
282275 $ mail = $ regs [2 ][0 ];
@@ -294,7 +287,7 @@ protected function _cloak(&$text, &$params)
294287 * Search for derivatives of link code <a href="mailto:[email protected] ? 295288 * subject=Text">[email protected] </a> 296289 */
297- $ pattern = $ this ->_getPattern ($ searchEmailLink , $ searchEmail );
290+ $ pattern = $ this ->getPattern ($ searchEmailLink , $ searchEmail );
298291
299292 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
300293 $ mail = $ regs [2 ][0 ] . $ regs [3 ][0 ];
@@ -316,7 +309,7 @@ protected function _cloak(&$text, &$params)
316309 * Search for derivatives of link code <a href="mailto:[email protected] ? 317310 * subject=Text">anytext</a>
318311 */
319- $ pattern = $ this ->_getPattern ($ searchEmailLink , $ searchText );
312+ $ pattern = $ this ->getPattern ($ searchEmailLink , $ searchText );
320313
321314 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
322315 $ mail = $ regs [2 ][0 ] . $ regs [3 ][0 ];
@@ -337,7 +330,7 @@ protected function _cloak(&$text, &$params)
337330 * Search for derivatives of link code <a href="mailto:[email protected] ?subject= Text" 338331 * ><anyspan >[email protected] </anyspan></a> 339332 */
340- $ pattern = $ this ->_getPattern ($ searchEmailLink , $ searchEmailSpan );
333+ $ pattern = $ this ->getPattern ($ searchEmailLink , $ searchEmailSpan );
341334
342335 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
343336 $ mail = $ regs [2 ][0 ] . $ regs [3 ][0 ];
@@ -356,7 +349,7 @@ protected function _cloak(&$text, &$params)
356349 * Search for derivatives of link code <a href="mailto:[email protected] ?subject= Text"> 357350 * <anyspan >anytext</anyspan></a>
358351 */
359- $ pattern = $ this ->_getPattern ($ searchEmailLink , $ searchTextSpan );
352+ $ pattern = $ this ->getPattern ($ searchEmailLink , $ searchTextSpan );
360353
361354 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
362355 $ mail = $ regs [2 ][0 ] . $ regs [3 ][0 ];
@@ -374,7 +367,7 @@ protected function _cloak(&$text, &$params)
374367 * Search for derivatives of link code
375368 * <a href="mailto:[email protected] ?subject=Text"><img anything></a> 376369 */
377- $ pattern = $ this ->_getPattern ($ searchEmailLink , $ searchImage );
370+ $ pattern = $ this ->getPattern ($ searchEmailLink , $ searchImage );
378371
379372 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
380373 $ mail = $ regs [2 ][0 ] . $ regs [3 ][0 ];
@@ -396,7 +389,7 @@ protected function _cloak(&$text, &$params)
396389 * Search for derivatives of link code
397390 * <a href="mailto:[email protected] ?subject=Text"><img anything>[email protected] </a> 398391 */
399- $ pattern = $ this ->_getPattern ($ searchEmailLink , $ searchImage . $ searchEmail );
392+ $ pattern = $ this ->getPattern ($ searchEmailLink , $ searchImage . $ searchEmail );
400393
401394 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
402395 $ mail = $ regs [2 ][0 ] . $ regs [3 ][0 ];
@@ -418,7 +411,7 @@ protected function _cloak(&$text, &$params)
418411 * Search for derivatives of link code
419412 * <a href="mailto:[email protected] ?subject=Text"><img anything>any text</a> 420413 */
421- $ pattern = $ this ->_getPattern ($ searchEmailLink , $ searchImage . $ searchText );
414+ $ pattern = $ this ->getPattern ($ searchEmailLink , $ searchImage . $ searchText );
422415
423416 while (preg_match ($ pattern , $ text , $ regs , PREG_OFFSET_CAPTURE )) {
424417 $ mail = $ regs [2 ][0 ] . $ regs [3 ][0 ];
0 commit comments