-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.rantispam.php
250 lines (230 loc) · 7.09 KB
/
install.rantispam.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* @component RAntispam
* @author Ratmil Torres
* @copyright (C) Ratmil Torres
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/
defined('_JEXEC') or die;
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
class com_rantispamInstallerScript
{
/**
* Constructor
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
public function __constructor(JAdapterInstance $adapter)
{
}
/**
* Called before any type of action
*
* @param string $route Which action is happening (install|uninstall|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
public function preflight($route, JAdapterInstance $adapter)
{
return true;
}
/**
* Called after any type of action
*
* @param string $route Which action is happening (install|uninstall|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
public function postflight($route, JAdapterInstance $adapter)
{
return true;
}
/**
* Called on installation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
public function install(JAdapterInstance $adapter)
{
$this->updatePlugins();
$this->init_prob_data();
return true;
}
/**
* Called on update
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
public function update(JAdapterInstance $adapter)
{
$this->updatePlugins();
$this->init_prob_data();
return true;
}
/**
* Called on uninstallation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
public function uninstall(JAdapterInstance $adapter)
{
$this->uninstallPlugins();
return true;
}
function uninstallPlugins()
{
$this->uninstall_plugin('rantispam', 'system');
}
function install_plugin($component, $element, $folder = 'system', $extra_folders = null, $extra_files = null, $language_files = null)
{
$this->uninstall_plugin($element, $folder, $extra_folders);
$db = JFactory::getDBO();
$name = $folder . ' - ' . $element;
$e_name = $db->escape($name);
$e_element = $db->escape($element);
$e_folder = $db->escape($folder);
$version = new JVersion;
if($version->RELEASE >= "1.6")
{
$result = true;
$dest_folder = JPATH_SITE.'/'.'plugins'.'/'.$folder.'/'.$element;
$dest_file_php = JPATH_SITE.'/'.'plugins'.'/'.$folder.'/'.$element.'/'.$element.'.php';
$dest_file_xml = JPATH_SITE.'/'.'plugins'.'/'.$folder.'/'.$element.'/'.$element.'.xml';
if(!JFolder::exists($dest_folder))
{
JFolder::create($dest_folder);
}
if(is_array($extra_folders))
{
foreach($extra_folders as $extra_folder)
{
$new_folder = JPATH_ADMINISTRATOR.'/components/'.$component.'/extensions/plugins/'.$folder.'/'.$element.'/'.$extra_folder;
if(!JFolder::copy($new_folder, $dest_folder . "/" . $extra_folder))
{
echo "Error copying folder ($new_folder) to ($dest_folder) folder<br/>";
$result = false;
}
}
}
$file_php = JPATH_ADMINISTRATOR.'/components/'.$component.'/extensions/plugins/'.$folder.'/'.$element.'/'.$element.'.php';
if(!JFile::exists($file_php) || !JFile::copy($file_php, $dest_file_php))
{
echo "Error copying file ($file_php) to ($dest_file_php)<br/>";
$result = false;
}
$file_xml = JPATH_ADMINISTRATOR.'/components/'.$component.'/extensions/plugins/'.$folder.'/'.$element.'/'.$element.'.xml';
if(!JFile::exists($file_xml) || !JFile::copy($file_xml, $dest_file_xml))
{
echo "Error copying file ($file_xml) to ($dest_file_xml)<br/>";
$result = false;
}
if($extra_files)
{
foreach($extra_files as $extra_file)
{
$source_file = JPATH_ADMINISTRATOR.'/components/'.$component.'/extensions/plugins/'.$folder.'/'.$element.'/'.$extra_file;
$dest_file = JPATH_SITE.'/plugins/'.$folder.'/'.$element.'/'.$extra_file;
if(!JFile::exists($source_file) || !JFile::copy($source_file, $dest_file))
{
echo "Error copying file ($source_file) to ($dest_file)<br/>";
$result = false;
}
}
}
if($language_files)
{
foreach($language_files as $language_file)
{
$dot_pos = strpos($language_file, ".");
if($dot_pos !== false)
{
$language = substr($language_file, 0, $dot_pos);
$source_file = JPATH_ADMINISTRATOR.'/components/'.$component.'/extensions/plugins/'.$folder.'/'.$element.'/'.$language_file;
$dest_file = JPATH_ADMINISTRATOR.'/language/'.$language.'/'.$language_file;
if(JFile::exists($source_file) && JFolder::exists(JPATH_ADMINISTRATOR.'/language/'.$language))
{
JFile::copy($source_file, $dest_file);
}
}
}
}
$query = "INSERT INTO #__extensions(name, type, element, folder, enabled, access)
VALUES('$e_name', 'plugin', '$e_element', '$e_folder', 1, 1)";
$db->setQuery($query);
if(!$db->query())
{
echo "Error inserting plugin record<br/>";
$result = false;
}
if(!$result)
$this->uninstall_plugin($element, $folder );
return false;
}
}
function uninstall_plugin($element, $folder = 'system', $extra_folders = null, $extra_files = null, $language_files = null)
{
$db = JFactory::getDBO();
$e_element = $db->escape($element);
$e_folder = $db->escape($folder);
$version = new JVersion;
if($version->RELEASE >= "1.6")
{
$db = JFactory::getDBO();
$db->setQuery("DELETE FROM #__extensions WHERE element='$e_element' AND folder='$e_folder' AND type='plugin'");
$db->query();
$dest_folder = JPATH_SITE.'/plugins/'.$folder.'/'.$element;
if(JFolder::exists($dest_folder))
{
JFolder::delete($dest_folder);
}
if($language_files)
{
foreach($language_files as $language_file)
{
$dot_pos = strpos($language_file, ".");
if($dot_pos !== false)
{
$language = substr($language_file, 0, $dot_pos);
$dest_file = JPATH_ADMINISTRATOR.'/language/'.$language.'/'.$language_file;
if(JFile::exists($dest_file))
{
JFile::delete($dest_file);
}
}
}
}
}
}
function updatePlugins()
{
$this->uninstall_plugin('rantispam', 'system');
$this->install_plugin('com_rantispam', 'rantispam', 'system');
}
function init_prob_data()
{
$db = JFactory::getDBO();
$db->setQuery("SELECT COUNT(*) FROM #__rantispam_token_count");
$count = $db->loadResult();
$db->setQuery("SELECT COUNT(*) FROM #__rantispam_tokens_prob");
$prob_count = $db->loadResult();
if($count == 0 || $prob_count == 0)
{
$db->setQuery("DELETE FROM #__rantispam_token_count");
$db->query();
$db->setQuery("DELETE FROM #__rantispam_tokens_prob");
$db->query();
$data_file = JPATH_ADMINISTRATOR . "/components/com_rantispam/data/initdata.sav";
require_once(JPATH_ADMINISTRATOR . "/components/com_rantispam/classes/importprobdata.php");
$importer = new ProbData_Importer();
$importer->importFromXml($data_file);
}
}
}
?>