-
Notifications
You must be signed in to change notification settings - Fork 1
/
linkprotect.php
66 lines (57 loc) · 1.67 KB
/
linkprotect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.joomla
*
* @copyright Copyright (C) 2013 David Hurley. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Link Protect Content Plugin
*
* @package Joomla.Plugin
* @subpackage Content.joomla
* @since 3.0
*/
class PlgContentLinkprotect extends JPlugin
{
private $callbackFunction;
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config);
require_once __DIR__ . '/helper/helper.php';
$helper = new LinkProtectHelper($this->params);
$this->callbackFunction = array($helper, 'replaceLinks');
}
/**
* Initiate the plugin
* @param string $context The context of the content passes to the plugin
* @param object $article The article object
* @param object $params The article params
*
* @return boolean True if the function is bypassed. Else True/False based on the replacement action
*/
public function onContentBeforeDisplay($context, $article, $params)
{
$parts = explode(".", $context);
if ($parts[0] != "com_content")
{
return;
}
if (stripos($article->text, '{linkprotect=off}') === true)
{
$article->text = str_ireplace('{linkprotect=off}', '', $article->text);
}
$app = JFactory::getApplication();
$external = $app->input->get('external', NULL);
if ($external)
{
LinkProtectHelper::leaveSite($article, $external);
} else
{
$pattern = '@href=("|\')(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)("|\')@';
$article->text = preg_replace_callback($pattern, $this->callbackFunction, $article->text);
}
}
}