-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscript.php
409 lines (354 loc) · 11.5 KB
/
script.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<?php
/**
* @version 3.0.1
* @package JEM
* @copyright (C) 2013-2014 joomlaeventmanager.net
* @copyright (C) 2005-2009 Christoph Lukes
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die;
$db = JFactory::getDBO();
jimport('joomla.filesystem.folder');
/**
* Script file of JEM component
*/
class com_jemInstallerScript
{
private $oldRelease = "";
private $newRelease = "";
/**
* Method to install the component
*
* @return void
*/
function install($parent)
{
$error = array(
'summary' => 0,
'folders' => 0
);
$this->getHeader();
?>
<h2><?php echo JText::_('COM_JEM_INSTALL_STATUS'); ?>:</h2>
<h3><?php echo JText::_('COM_JEM_INSTALL_CHECK_FOLDERS'); ?>:</h3> <?php
$imageDir = "/images/jem";
$createDirs = array(
$imageDir,
$imageDir.'/categories',
$imageDir.'/categories/small',
$imageDir.'/events',
$imageDir.'/events/small',
$imageDir.'/venues',
$imageDir.'/venues/small'
);
// Check for existance of /images/jem directory
if (JFolder::exists(JPATH_SITE.$createDirs[0])) {
echo "<p><span style='color:green;'>".JText::_('COM_JEM_INSTALL_SUCCESS').":</span> ".
JText::sprintf('COM_JEM_INSTALL_DIRECTORY_EXISTS_SKIP', $createDirs[0])."</p>";
} else {
echo "<p><span style='color:orange;'>".JText::_('COM_JEM_INSTALL_INFO').":</span> ".
JText::sprintf('COM_JEM_INSTALL_DIRECTORY_NOT_EXISTS', $createDirs[0])."</p>";
echo "<p>".JText::_('COM_JEM_INSTALL_DIRECTORY_TRY_CREATE').":</p>";
echo "<ul>";
// Folder creation
foreach($createDirs as $directory) {
if (JFolder::create(JPATH_SITE.$directory)) {
echo "<li><span style='color:green;'>".JText::_('COM_JEM_INSTALL_SUCCESS').":</span> ".
JText::sprintf('COM_JEM_INSTALL_DIRECTORY_CREATED', $directory)."</li>";
} else {
echo "<li><span style='color:red;'>".JText::_('COM_JEM_INSTALL_ERROR').":</span> ".
JText::sprintf('COM_JEM_INSTALL_DIRECTORY_NOT_CREATED', $directory)."</li>";
$error['folders']++;
}
}
echo "</ul>";
}
if($error['folders']) {
echo "<p>".JText::_('COM_JEM_INSTALL_DIRECTORY_CHECK_EXISTANCE')."</p>";
}
echo "<h3>".JText::_('COM_JEM_INSTALL_SETTINGS')."</h3>";
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('id')->from('#__jem_settings');
$db->setQuery($query);
$db->loadResult();
if($db->loadResult()) {
echo "<p><span style='color:green;'>".JText::_('COM_JEM_INSTALL_SUCCESS').":</span> ".
JText::_('COM_JEM_INSTALL_FOUND_SETTINGS')."</p>";
}
echo "<h3>".JText::_('COM_JEM_INSTALL_SUMMARY')."</h3>";
foreach ($error as $k => $v) {
if($k != 'summary') {
$error['summary'] += $v;
}
}
if($error['summary']) {
?>
<p style='color: red;'>
<b><?php echo JText::_('COM_JEM_INSTALL_INSTALLATION_NOT_SUCCESSFUL'); ?></b>
</p>
<?php
} else {
?>
<p style='color: green;'>
<b><?php echo JText::_('COM_JEM_INSTALL_INSTALLATION_SUCCESSFUL'); ?></b>
</p> <?php
}
$param_array = array(
"event_comunoption"=>"0",
"event_comunsolution"=>"0",
"event_show_author"=>"1",
"event_lg"=>"",
"event_link_author"=>"1",
"event_show_contact"=>"1",
"event_link_contact"=>"1",
"event_show_description"=>"1",
"event_show_detailsadress"=>"1",
"event_show_detailstitle"=>"1",
"event_show_detlinkvenue"=>"1",
"event_show_hits"=>"0",
"event_show_locdescription"=>"1",
"event_show_mapserv"=>"0",
"event_show_print_icon"=>"1",
"event_show_email_icon"=>"1",
"event_show_ical_icon"=>"1",
"event_tld"=>"",
"editevent_show_meta_option"=>"0",
"editevent_show_attachment_tab"=>"0",
"editevent_show_other_tab"=>"0",
"global_display"=>"1",
"global_regname"=>"1",
"global_show_archive_icon"=>"1",
"global_show_filter"=>"1",
"global_show_email_icon"=>"1",
"global_show_ical_icon"=>"1",
"global_show_icons"=>"1",
"global_show_locdescription"=>"1",
"global_show_print_icon"=>"1",
"global_show_timedetails"=>"1",
"global_show_detailsadress"=>"1",
"global_show_detlinkvenue"=>"1",
"global_show_mapserv"=>"0",
"global_tld"=>"",
"global_lg"=>""
);
$this->setGlobalAttribs($param_array);
}
/**
* method to uninstall the component
*
* @return void
*/
function uninstall($parent)
{
$this->getHeader(); ?>
<h2><?php echo JText::_('COM_JEM_UNINSTALL_STATUS'); ?>:</h2>
<p><?php echo JText::_('COM_JEM_UNINSTALL_TEXT'); ?></p>
<?php
}
/**
* method to update the component
*
* @return void
*/
function update($parent)
{
$this->getHeader(); ?>
<h2><?php echo JText::_('COM_JEM_UPDATE_STATUS'); ?>:</h2>
<p><?php echo JText::sprintf('COM_JEM_UPDATE_TEXT', $parent->get('manifest')->version); ?></p>;
<?php
}
/**
* method to run before an install/update/uninstall method
*
* @return void
*/
function preflight($type, $parent)
{
// Minimum required PHP version
$minPhpVersion = "5.3.10";
// Abort if PHP release is older than required version
if(version_compare(PHP_VERSION, $minPhpVersion, '<')) {
Jerror::raiseWarning(100, JText::sprintf('COM_JEM_PREFLIGHT_WRONG_PHP_VERSION', $minPhpVersion, PHP_VERSION));
return false;
}
// Abort if Magic Quotes are enabled, it was removed from phpversion 5.4
if (version_compare(phpversion(), '5.4', '<') ) {
if (function_exists('get_magic_quotes_gpc')) {
if(get_magic_quotes_gpc()) {
Jerror::raiseWarning(100, JText::_('COM_JEM_PREFLIGHT_MAGIC_QUOTES_ENABLED'));
return false;
}
}
}
// Minimum Joomla version as per Manifest file
$minJoomlaVersion = $parent->get('manifest')->attributes()->version;
// abort if the current Joomla release is older than required version
$jversion = new JVersion();
if(version_compare($jversion->getShortVersion(), $minJoomlaVersion, '<')) {
Jerror::raiseWarning(100, JText::sprintf('COM_JEM_PREFLIGHT_OLD_JOOMLA_VERSION', $minJoomlaVersion));
return false;
}
// abort if the release being installed is not newer than the currently installed version
if ($type == 'update') {
// Installed component version
$this->oldRelease = $this->getParam('version');
// Installing component version as per Manifest file
$this->newRelease = $parent->get('manifest')->version;
if (version_compare($this->newRelease, $this->oldRelease, 'lt')) {
Jerror::raiseWarning(100, JText::sprintf('COM_JEM_PREFLIGHT_INCORRECT_VERSION_SEQUENCE', $this->oldRelease, $this->newRelease));
return false;
}
// Remove obsolete files and folder
$this->deleteObsoleteFiles();
// Initialize schema table if necessary
$this->initializeSchema($this->oldRelease);
}
// $type is the type of change (install, update or discover_install)
echo '<p>' . JText::_('COM_JEM_PREFLIGHT_' . $type . '_TEXT') . '</p>';
}
/**
* Method to run after an install/update/uninstall method
*
* @return void
*/
function postflight($type, $parent)
{
// $type is the type of change (install, update or discover_install)
echo '<p>' . JText::_('COM_JEM_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
if ($type == 'update') {
}
}
/**
* Get a parameter from the manifest file (actually, from the manifest cache).
*
* @param $name The name of the parameter
*
* @return The parameter
*/
private function getParam($name) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('manifest_cache')->from('#__extensions')->where(array("type = 'component'", "element = 'com_jem'"));
$db->setQuery($query);
$manifest = json_decode($db->loadResult(), true);
return $manifest[$name];
}
/**
* Sets parameter values in the component's row of the extension table
*
* @param $param_array An array holding the params to store
*/
private function setParams($param_array) {
if (count($param_array) > 0) {
// read the existing component value(s)
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('params')->from('#__extensions')->where(array("type = 'component'", "element = 'com_jem'"));
$db->setQuery($query);
$params = json_decode($db->loadResult(), true);
// add the new variable(s) to the existing one(s)
foreach ($param_array as $name => $value) {
$params[(string) $name] = (string) $value;
}
// store the combined new and existing values back as a JSON string
$paramsString = json_encode($params);
$query = $db->getQuery(true);
$query->update('#__extensions')
->set('params = '.$db->quote($paramsString))
->where(array("type = 'component'", "element = 'com_jem'"));
$db->setQuery($query);
$db->query();
}
}
/**
* Sets globalattrib values in the settings table
*
* @param $param_array An array holding the params to store
*/
private function setGlobalAttribs($param_array) {
if (count($param_array) > 0) {
// read the existing component value(s)
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('globalattribs')->from('#__jem_settings');
$db->setQuery($query);
$params = json_decode($db->loadResult(), true);
// add the new variable(s) to the existing one(s)
foreach ($param_array as $name => $value) {
$params[(string) $name] = (string) $value;
}
// store the combined new and existing values back as a JSON string
$paramsString = json_encode($params);
$query = $db->getQuery(true);
$query->update('#__jem_settings')
->set('globalattribs = '.$db->quote($paramsString));
$db->setQuery($query);
$db->query();
}
}
/**
* Helper method that outputs a short JEM header with logo and text
*/
private function getHeader() {
?>
<img src="../media/com_jem/images/jemlogo.png" alt="" style="float:left; padding-right:20px;" />
<h1><?php echo JText::_('COM_JEM'); ?></h1>
<p class="small"><?php echo JText::_('COM_JEM_INSTALLATION_HEADER'); ?></p>
<?php
}
/**
* Checks if component is already registered in Joomlas schema table and adds an entry if
* neccessary
* @param string $versionId The JEM version to add to the schema table
*/
private function initializeSchema($versionId) {
$db = JFactory::getDbo();
// Get extension ID of JEM
$query = $db->getQuery(true);
$query->select('extension_id')->from('#__extensions')->where(array("type='component'", "element='com_jem'"));
$db->setQuery($query);
$extensionId = $db->loadResult();
if(!$extensionId) {
// This is a fresh installation, return
return;
}
// Check if an entry already exists in schemas table
$query = $db->getQuery(true);
$query->select('version_id')->from('#__schemas')->where('extension_id = '.$extensionId);
$db->setQuery($query);
if($db->loadResult()) {
// Entry exists, return
return;
}
// Insert extension ID and old release version number into schemas table
$query = $db->getQuery(true);
$query->insert('#__schemas')
->columns($db->quoteName(array('extension_id', 'version_id')))
->values(implode(',', array($extensionId, $db->quote($versionId))));
$db->setQuery($query);
$db->query();
}
/**
* Remove all obsolete files and folders of previous versions.
*
* Todo: Enhance the lists on each new version.
*
* @return void
*/
private function deleteObsoleteFiles()
{
$files = array();
$folders = array();
foreach ($files as $file) {
if (JFile::exists(JPATH_ROOT . $file) && !JFile::delete(JPATH_ROOT . $file)) {
echo JText::sprintf('FILES_JOOMLA_ERROR_FILE_FOLDER', $file).'<br />';
}
}
foreach ($folders as $folder) {
if (JFolder::exists(JPATH_ROOT . $folder) && !JFolder::delete(JPATH_ROOT . $folder)) {
echo JText::sprintf('FILES_JOOMLA_ERROR_FILE_FOLDER', $folder).'<br />';
}
}
}
}