-
Notifications
You must be signed in to change notification settings - Fork 2
/
dd_disable_mailto.php
147 lines (127 loc) · 3.11 KB
/
dd_disable_mailto.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* @package DD_Disable_MailTo
*
* @author HR IT-Solutions Florian Häusler <[email protected]>
* @copyright Copyright (C) 2011 - 2017 Didldu e.K. | HR IT-Solutions
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
**/
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
jimport('joomla.access.access');
/**
* Joomla! system plugin to disable mailto extension
*/
class plgSystemDD_Disable_MailTo extends JPlugin
{
protected $app;
// Plugin info constants
const TYPE = 'system';
const NAME = 'dd_disable_mailto';
/**
* Construct Events
*
* @since Version 1.2.2.1
*/
function __construct( $subject )
{
parent::__construct($subject);
// Load plugin parameters
$this->plugin = JPluginHelper::getPlugin(self::TYPE, self::NAME);
$this->params = new JRegistry($this->plugin->params);
if ($this->app->isAdmin()) // Trigger Events only in Backend
{
$option = $this->app->input->get->get("option", 0, "STR");
if ($option === "com_plugins" ) // And only on plugin page, to save performance
{
$disable_mailTo = $this->params->get('disable_mailto', 0);
if (!$disable_mailTo)
{
$this->set_mailTo(false);
}
else
{
$this->set_mailTo();
}
}
}
}
/**
* onAfterRoute Event
* - redirectOldMailtoLinks
*
* @since Version 1.2.2.1
*/
public function onAfterRoute(){
// Redirect old mailTo otion
if ($this->params->get('redirect_mailto', 0))
{
$this->redirectOldMailtoLinks();
}
}
/**
* onAfterRender Event
* remveMailtoLink
*
* @since Version 1.2.2.1
*/
public function onAfterRender()
{
// Front end
if ($this->app instanceof JApplicationSite)
{
if ($this->params->get('remove_mailto_link', 0)) // Remove mailTo link Option
{
$html = $this->app->getBody();
$html = $this->remveMailtoLink($html);
$this->app->setBody($html);
}
}
}
/**
* Remove bootstrap mailto list link (like protostar, etc...) method
*
* @param string $content the content to replace
*
* @return string without list elemenent email-icon
*
* @since Version 1.2.2.1
*/
private function remveMailtoLink($content)
{
return preg_replace('/<li class=\"email-icon\">(.*?)<\/li>/s', ' ', $content);
}
/**
* Redirect old mailto links to home by HTTP STATUS 301 method
*
* @since Version 1.2.0.0
*/
private function redirectOldMailtoLinks()
{
if (strpos(JUri::current(), 'component/mailto') !== false)
{
$alternativeURL = $this->params->get('redirect_mailto_url');
$this->app->redirect(JURI::base() . $alternativeURL, 301);
}
return true;
}
/**
* Enable / Disable com_mailto extension method
*
* @param boolean $enable true = enabled
*
* @since Version 1.0.0.0
*/
private function set_mailTo($enable = true)
{
$enable = intval($enable);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update('#__extensions')
->set($db->qn('enabled') . ' = ' . $enable)
->where($db->qn('element') . ' = ' . $db->q('com_mailto'))
->where($db->qn('type') . ' = ' . $db->q('component'));
$db->setQuery($query);
$db->execute();
}
}