forked from JoomGallery/JoomGallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.php
403 lines (361 loc) · 14.2 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
<?php
// $HeadURL: https://joomgallery.org/svn/joomgallery/JG-3/JG/trunk/administrator/components/com_joomgallery/script.php $
// $Id: script.php 4408 2014-07-12 08:24:56Z erftralle $
/****************************************************************************************\
** JoomGallery 3 **
** By: JoomGallery::ProjectTeam **
** Copyright (C) 2008 - 2013 JoomGallery::ProjectTeam **
** Based on: JoomGallery 1.0.0 by JoomGallery::ProjectTeam **
** Released under GNU GPL Public License **
** License: http://www.gnu.org/copyleft/gpl.html or have a look **
** at administrator/components/com_joomgallery/LICENSE.TXT **
\****************************************************************************************/
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
/**
* Install method
* is called by the installer of Joomla!
*
* @access protected
* @return void
* @since 2.0
*/
class Com_JoomGalleryInstallerScript
{
/**
* Version string of the current version
*
* @var string
*/
private $version = '3.2.0';
/**
* Preflight method
*
* Is called afore installation and update processes
*
* @param $type string 'install', 'discover_install', or 'update'
* @return boolean False if installation or update shall be prevented, true otherwise
* @since 2.1
*/
public function preflight($type = 'install')
{
if(version_compare(JVERSION, '4.0', 'ge') || version_compare(JVERSION, '3.0', 'lt'))
{
JError::raiseWarning(500, 'JoomGallery 3.x is only compatible to Joomla! 3.x');
return false;
}
return true;
}
/**
* Install method
*
* @return boolean True on success, false otherwise
* @since 2.0
*/
public function install()
{
$app = JFactory::getApplication();
jimport('joomla.filesystem.file');
// Create image directories
require_once JPATH_ADMINISTRATOR.'/components/com_joomgallery/helpers/file.php';
$thumbpath = JPATH_ROOT.'/images/joomgallery/thumbnails';
$imgpath = JPATH_ROOT.'/images/joomgallery/details';
$origpath = JPATH_ROOT.'/images/joomgallery/originals';
$result = array();
$result[] = JFolder::create($thumbpath);
$result[] = JoomFile::copyIndexHtml($thumbpath);
$result[] = JFolder::create($imgpath);
$result[] = JoomFile::copyIndexHtml($imgpath);
$result[] = JFolder::create($origpath);
$result[] = JoomFile::copyIndexHtml($origpath);
$result[] = JoomFile::copyIndexHtml(JPATH_ROOT.'/images/joomgallery');
if(in_array(false, $result))
{
$app->enqueueMessage(JText::_('Unable to create image directories!'), 'error');
return false;
}
// Create news feed module
$subdomain = '';
$language = JFactory::getLanguage();
if(strpos($language->getTag(), 'de-') === false)
{
$subdomain = 'en.';
}
$row = JTable::getInstance('module');
$row->title = 'JoomGallery News';
$row->ordering = 1;
$row->position = 'joom_cpanel';
$row->published = 1;
$row->module = 'mod_feed';
$row->access = $app->getCfg('access');
$row->showtitle = 1;
$row->params = 'cache=1
cache_time=15
moduleclass_sfx=
rssurl=http://www.'.$subdomain.'joomgallery.net/feed/rss.html
rssrtl=0
rsstitle=1
rssdesc=0
rssimage=1
rssitems=3
rssitemdesc=1
word_count=200';
$row->client_id = 1;
$row->language = '*';
if(!$row->store())
{
$app->enqueueMessage(JText::_('Unable to insert feed module data!'), 'error');
}
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert('#__modules_menu');
$query->set('moduleid = '.$row->id);
$query->set('menuid = 0');
$db->setQuery($query);
if(!$db->query())
{
$app->enqueueMessage(JText::_('Unable to assign feed module!'), 'error');
}
// joom_settings.css
$temp = JPATH_ROOT.'/media/joomgallery/css/joom_settings.temp.css';
$dest = JPATH_ROOT.'/media/joomgallery/css/joom_settings.css';
if(!JFile::move($temp, $dest))
{
$app->enqueueMessage(JText::_('Unable to copy joom_settings.css!'), 'error');
return false;
}
?>
<div class="hero-unit">
<img src="../media/joomgallery/images/joom_logo.png" alt="JoomGallery Logo" />
<div class="alert alert-success">
<h3>JoomGallery <?php echo $this->version; ?> was installed successfully.</h3>
</div>
<p>You may now start using JoomGallery or download specific language files afore:</p>
<p>
<a title="Start" class="btn" onclick="location.href='index.php?option=com_joomgallery'; return false;" href="#">Start now!</a>
<a title="Languages" class="btn btn-primary" onclick="location.href='index.php?option=com_joomgallery&controller=help'; return false;" href="#">Languages</a>
</p>
</div>
<?php
}
/**
* Update method
*
* @return boolean True on success, false otherwise
* @since 2.0
*/
public function update()
{
jimport('joomla.filesystem.file'); ?>
<div class="hero-unit">
<img src="../media/joomgallery/images/joom_logo.png" alt="JoomGallery Logo" />
<div class="alert alert-info">
<h3>Update JoomGallery to version: <?php echo $this->version; ?></h3>
</div>
</div>
<?php
$error = false;
// Delete temporary joom_settings.temp.css
if(JFile::exists(JPATH_ROOT.'/media/joomgallery/css/joom_settings.temp.css'))
{
if(!JFile::delete(JPATH_ROOT.'/media/joomgallery/css/joom_settings.temp.css'))
{
JError::raiseWarning(500, JText::_('Unable to delete temporary joom_settings.temp.css!'));
$error = true;
}
}
//******************* Delete folders/files ************************************
echo '<div class="alert alert-info">';
echo '<h3>File system</h3>';
$delete_folders = array();
// MooRainbow assets
$delete_folders[] = JPATH_ROOT.'/media/joomgallery/js/moorainbow';
echo '<p>';
echo 'Looking for orphaned files and folders from the old installation ';
// Unzipped folder of latest auto update with cURL
$temp_dir = false;
$database = JFactory::getDbo();
$query = $database->getQuery(true)
->select('jg_pathtemp')
->from('#__joomgallery_config');
$database->setQuery($query);
$temp_dir = $database->loadResult();
if($temp_dir)
{
//$delete_folders[] = JPATH_SITE.'/'.$temp_dir.'update';
for($i = 0; $i <= 100; $i++)
{
$update_folder = JPATH_SITE.'/'.$temp_dir.'update'.$i;
if(JFolder::exists($update_folder))
{
$delete_folders[] = $update_folder;
}
}
}
$deleted = false;
$jg_delete_error = false;
foreach($delete_folders as $delete_folder)
{
if(JFolder::exists($delete_folder))
{
echo 'delete folder: '.$delete_folder.' : ';
$result = JFolder::delete($delete_folder);
if($result == true)
{
$deleted = true;
echo '<span class="label label-success">ok</span>';
}
else
{
$jg_delete_error = true;
echo '<span class="label label-important">not ok</span>';
}
echo '<br />';
}
}
// Files
$delete_files = array();
// Cache file of the newsfeed for the update checker
$delete_files[] = JPATH_ADMINISTRATOR.'/cache/'.md5('http://www.joomgallery.net/components/com_newversion/rss/extensions2.rss').'.spc';
$delete_files[] = JPATH_ADMINISTRATOR.'/cache/'.md5('http://www.en.joomgallery.net/components/com_newversion/rss/extensions2.rss').'.spc';
$delete_files[] = JPATH_ADMINISTRATOR.'/cache/'.md5('http://www.joomgallery.net/components/com_newversion/rss/extensions3.rss').'.spc';
$delete_files[] = JPATH_ADMINISTRATOR.'/cache/'.md5('http://www.en.joomgallery.net/components/com_newversion/rss/extensions3.rss').'.spc';
// Zip file of latest auto update with cURL
$delete_files[] = JPATH_ADMINISTRATOR.'/components/com_joomgallery/temp/update.zip';
// Old category form field
$delete_files[] = JPATH_ADMINISTRATOR.'/components/com_joomgallery/models/fields/category.php';
// JHtml file that is not used anymore
$delete_files[] = JPATH_ROOT.'/components/com_joomgallery/helpers/html/joompopup.php';
// JFormFields that aren't used anymore
$delete_files[] = JPATH_ADMINISTRATOR.'/components/com_joomgallery/models/fields/cbowner.php';
$delete_files[] = JPATH_ADMINISTRATOR.'/components/com_joomgallery/models/fields/owner.php';
$delete_files[] = JPATH_ADMINISTRATOR.'/components/com_joomgallery/models/fields/color.php';
// Template files that aren't used anymore
$delete_files[] = JPATH_ROOT.'/components/com_joomgallery/views/category/tmpl/default_catpagination.php';
$delete_files[] = JPATH_ROOT.'/components/com_joomgallery/views/category/tmpl/default_imgpagination.php';
$delete_files[] = JPATH_ROOT.'/components/com_joomgallery/views/gallery/tmpl/default_pagination.php';
// Old changelog.php
$delete_files[] = JPATH_ROOT.'/administrator/components/com_joomgallery/changelog.php';
// Old ordering form field
$delete_files[] = JPATH_ADMINISTRATOR.'/components/com_joomgallery/models/fields/ordering.php';
foreach($delete_files as $delete_file)
{
if(JFile::exists($delete_file))
{
echo 'delete file: '.$delete_file.' : ';
$result = JFile::delete($delete_file);
if($result == true)
{
$deleted = true;
echo '<span class="label label-success">ok</span>';
}
else
{
$jg_delete_error = true;
echo '<span class="label label-important">not ok</span>';
}
echo '<br />';
}
}
//******************* END delete folders/files ************************************
if($deleted)
{
if($jg_delete_error)
{
echo '<span class="label label-important">problems in deletion of files/folders</span>';
$error = true;
}
else
{
echo '<span class="label label-success">files/folders sucessfully deleted</span>';
}
}
else
{
echo '<span class="label label-success">nothing to delete</span>';
}
echo '</p>';
echo '</div>';
//******************* Write joom_settings.css ************************************
/*echo '<div class="alert alert-info">';
echo '<h3>CSS</h3>';
echo '<p>';
echo 'Update configuration dependent CSS settings: ';
require_once JPATH_ADMINISTRATOR.'/components/com_joomgallery/includes/defines.php';
JLoader::register('JoomConfig', JPATH_ADMINISTRATOR.'/components/com_joomgallery/helpers/config.php');
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_joomgallery/tables');
$config = JoomConfig::getInstance('admin');
if(!$config->save())
{
$error = true;
echo '<span class="label label-important">not ok</span>';
}
else
{
echo '<span class="label label-success">ok</span>';
}
echo '</p>';
echo '</div>';*/
//******************* End write joom_settings.css ************************************
if($error)
{
echo '<div class="alert alert-error">
<h3>Problem with the update to JoomGallery version '.$this->version.'<br />Please read the update infos above</h3>
</div>';
JFactory::getApplication()->enqueueMessage(JText::_('Problem with the update to JoomGallery version '.$this->version.'. Please read the update infos below'), 'error');
}
else
{ ?>
<div class="hero-unit">
<img src="../media/joomgallery/images/joom_logo.png" alt="JoomGallery Logo" />
<div class="alert alert-success">
<h3>JoomGallery was updated to version <?php echo $this->version; ?> successfully.</h3>
<button class="btn btn-small btn-info" data-toggle="modal" data-target="#jg-changelog-popup"><i class="icon-list"></i> Changelog</button>
</div>
<p>You may now start using JoomGallery or download specific language files afore:</p>
<p>
<a title="Start" class="btn" onclick="location.href='index.php?option=com_joomgallery'; return false;" href="#">Go on!</a>
<a title="Languages" class="btn btn-primary" onclick="location.href='index.php?option=com_joomgallery&controller=help'; return false;" href="#">Languages</a>
</p>
</div>
<?php JHtml::_('bootstrap.modal', 'jg-changelog-popup'); ?>
<div class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="PopupChangelogModalLabel" aria-hidden="true" id="jg-changelog-popup">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="PopupChangelogModalLabel">Changelog</h3>
</div>
<div id="jg-changelog-popup-container">
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo JText::_('JTOOLBAR_CLOSE'); ?></button>
</div>
</div>
<script type="text/javascript">
jQuery('#jg-changelog-popup').modal({backdrop: true, keyboard: true, show: false});
jQuery('#jg-changelog-popup').on('show', function ()
{
document.getElementById('jg-changelog-popup-container').innerHTML = '<div class="modal-body"><iframe class="iframe" frameborder="0" src="<?php echo JRoute::_('index.php?option=com_joomgallery&controller=changelog&tmpl=component'); ?>" height="400px" width="100%"></iframe></div>';
});
</script>
<?php
}
return !$error;
}
/**
* Uninstall method
*
* @return boolean True on success, false otherwise
* @since 2.0
*/
public function uninstall()
{
$path = JPATH_ROOT.'/images/joomgallery';
if(JFolder::exists($path))
{
JFolder::delete($path);
}
echo '<div class="alert alert-info">JoomGallery was uninstalled successfully!<br />
Please remember to remove your images folders manually
if you didn\'t use JoomGallery\'s default directories.</div>';
return true;
}
}