12
12
defined ('_JEXEC ' ) or die;
13
13
14
14
use Joomla \CMS \Factory ;
15
- use Joomla \CMS \Language \Text ;
15
+ use Joomla \CMS \Filesystem \File ;
16
+ use Joomla \CMS \Filesystem \Folder ;
16
17
17
18
/**
18
19
* Installation class to perform additional changes during install/uninstall/update
@@ -50,18 +51,20 @@ class Pkg_JUNewsUltraInstallerScript
50
51
*/
51
52
public function preflight ($ type , $ parent )
52
53
{
54
+ $ app = Factory::getApplication ();
55
+
53
56
if (version_compare (JVERSION , '3.8.0 ' , 'lt ' ))
54
57
{
55
- Factory:: getApplication () ->enqueueMessage ('Update for Joomla! 3.8+ ' , 'error ' );
58
+ $ app ->enqueueMessage ('Update for Joomla! 3.8+ ' , 'error ' );
56
59
57
60
return false ;
58
61
}
59
62
60
- $ this -> MakeDirectory (JPATH_SITE . '/img ' );
63
+ Folder:: create (JPATH_SITE . '/img ' , 0777 );
61
64
62
65
if (!is_dir (JPATH_SITE . '/img/ ' ))
63
66
{
64
- Factory:: getApplication () ->enqueueMessage ('Error creating folder \'img \'. Please manually create the folder \'img \' in the root of the site where you installed Joomla! ' );
67
+ $ app ->enqueueMessage ('Error creating folder \'img \'. Please manually create the folder \'img \' in the root of the site where you installed Joomla! ' );
65
68
}
66
69
67
70
$ cache = Factory::getCache ('mod_junewsultra ' );
@@ -70,51 +73,16 @@ public function preflight($type, $parent)
70
73
return true ;
71
74
}
72
75
73
- /**
74
- * @param $parent
75
- *
76
- *
77
- * @return bool
78
- * @since 6.0
79
- */
80
- public function uninstall ($ parent )
81
- {
82
- return true ;
83
- }
84
-
85
- /**
86
- * @param $parent
87
- *
88
- *
89
- * @return bool
90
- * @since 6.0
91
- */
92
- public function update ($ parent )
93
- {
94
- return true ;
95
- }
96
-
97
76
/**
98
77
* @param $type
99
78
* @param $parent
100
- * @param $results
101
79
*
102
80
* @return bool
103
81
*
104
- * @throws \Exception
105
82
* @since 6.0
106
83
*/
107
- public function postflight ($ type , $ parent, $ results )
84
+ public function postflight ($ type , $ parent )
108
85
{
109
- $ enabled = [];
110
-
111
- $ db = Factory::getDbo ();
112
- $ query = $ db ->getQuery (true );
113
- $ app = Factory::getApplication ();
114
-
115
- $ lang = Factory::getLanguage ();
116
- $ lang ->load ('mod_junewsultra ' , JPATH_SITE );
117
-
118
86
if (version_compare (JVERSION , '4.0.0 ' , '>= ' ))
119
87
{
120
88
$ xml = file_get_contents (JPATH_SITE . '/modules/mod_junewsultra/mod_junewsultra.xml ' );
@@ -129,109 +97,6 @@ public function postflight($type, $parent, $results)
129
97
file_put_contents (JPATH_SITE . '/modules/mod_junewsultra/mod_junewsultra.xml ' , $ xml );
130
98
}
131
99
132
- foreach ($ results as $ result )
133
- {
134
- $ extension = (string ) $ result [ 'name ' ];
135
-
136
- $ query ->clear ();
137
-
138
- $ query ->select ($ db ->quoteName ([ 'enabled ' ]));
139
- $ query ->from ($ db ->quoteName ('#__extensions ' ));
140
- $ query ->where ($ db ->quoteName ('name ' ) . ' = ' . $ db ->quote ($ extension ));
141
- $ db ->setQuery ($ query );
142
-
143
- $ enabled [ $ extension ] = $ db ->loadResult ();
144
- }
145
-
146
- $ html = '<style type="text/css">
147
- .juinstall {
148
- color: #333!important;
149
- font-weight: normal;
150
- margin: 0!important;
151
- padding: 0;
152
- overflow: hidden;
153
- background: #fff!important;
154
- }
155
- .juinstall-content {
156
- margin: 5% auto!important;
157
- padding: 35px 0 18px 0;
158
- width: 50%;
159
- }
160
- .juinstall .newalert {
161
- clear: both;
162
- margin: 5px 10%!important;
163
- }
164
- .juinstall p {
165
- margin-left: 0;
166
- text-align: left;
167
- }
168
- .juinstall table td .label {
169
- margin: 0 auto;
170
- }
171
- .juinstall hr {
172
- margin-top:6px;
173
- margin-bottom:6px;
174
- border:0;
175
- border-top:1px solid #eee
176
- }
177
- </style> ' ;
178
-
179
- $ html .= '<div class="juinstall">
180
- <div class="juinstall-content">
181
- <h2 style="padding: 0 0 8px 0; margin: 0;"> ' . Text::_ ('MOD_JUNEWS_TITLE ' ) . '</h2>
182
- <h2 style="padding: 0 0 8px 0; margin: 0;"><small> ' . Text::_ ('MOD_JUNEWS_DESCRIPTION ' ) . '</small></h2>
183
- <table class="table table-striped">
184
- <thead>
185
- <tr>
186
- <th> ' . Text::_ ('MOD_JUNEWS_EXTENSION ' ) . '</th>
187
- <th> ' . Text::_ ('JSTATUS ' ) . '</th>
188
- <th> ' . Text::_ ('JENABLED ' ) . '</th>
189
- </tr>
190
- </thead>
191
- <tbody> ' ;
192
-
193
- foreach ($ results as $ result )
194
- {
195
- $ extension = (string ) $ result [ 'name ' ];
196
-
197
- $ html .= '<tr><td> ' ;
198
-
199
- if ($ extension === 'MOD_JUNEWSULTRA ' )
200
- {
201
- $ html .= Text::_ ($ extension );
202
- }
203
- else
204
- {
205
- $ html .= $ extension ;
206
- }
207
-
208
- $ html .= '</td><td><strong> ' ;
209
-
210
- if ($ result [ 'result ' ] === true )
211
- {
212
- $ html .= '<span class="label label-success"> ' . Text::_ ('MOD_JUNEWS_INSTALLED ' ) . '</span> ' ;
213
- }
214
- else
215
- {
216
- $ html .= '<span class="label label-important"> ' . Text::_ ('MOD_JUNEWS_NOT_INSTALLED ' ) . '</span> ' ;
217
- }
218
-
219
- $ html .= '</strong></td><td> ' ;
220
-
221
- if ($ enabled [ $ extension ] == 1 )
222
- {
223
- $ html .= '<span class="label label-success"> ' . Text::_ ('JYES ' ) . '</span> ' ;
224
- }
225
- else
226
- {
227
- $ html .= '<span class="label label-important"> ' . Text::_ ('JNO ' ) . '</span> ' ;
228
- }
229
-
230
- $ html .= '</td></tr> ' ;
231
- }
232
-
233
- $ html .= '</tbody></table> ' ;
234
-
235
100
$ path = JPATH_SITE . '/modules/mod_junewsultra/ ' ;
236
101
$ files = [
237
102
$ path . 'assets/donate2.gif ' ,
@@ -258,7 +123,6 @@ public function postflight($type, $parent, $results)
258
123
$ path . 'assets/css/default.css ' ,
259
124
$ path . 'assets/css/elegant.css ' ,
260
125
$ path . 'assets/css/docs.css ' ,
261
-
262
126
$ path . 'fields/jumultithumbradio.php ' ,
263
127
$ path . 'fields/colorpicker.php ' ,
264
128
$ path . 'fields/imagesetting.php ' ,
@@ -268,11 +132,9 @@ public function postflight($type, $parent, $results)
268
132
$ path . 'fields/toggler30.php ' ,
269
133
$ path . 'fields/donate.php ' ,
270
134
$ path . 'fields/article.php ' ,
271
-
272
135
$ path . 'tmpl/default/images/bg.jpg ' ,
273
136
$ path . 'tmpl/default/images/rating_star.png_ ' ,
274
137
$ path . 'tmpl/default/images/rating_star_blank.png_ ' ,
275
-
276
138
$ path . 'img/.htaccess ' ,
277
139
$ path . 'img/config.php ' ,
278
140
$ path . 'img/img.php ' ,
@@ -287,91 +149,33 @@ public function postflight($type, $parent, $results)
287
149
$ path . 'assets/js/minicolors '
288
150
];
289
151
290
- $ i = 0 ;
291
152
foreach ($ files as $ file )
292
153
{
293
154
if (file_exists ($ file ))
294
155
{
295
- $ i ++ ;
156
+ File:: delete ( $ file ) ;
296
157
}
297
158
}
298
159
299
- $ j = 0 ;
300
160
foreach ($ folders as $ folder )
301
161
{
302
162
if (is_dir ($ folder ))
303
163
{
304
- $ j ++ ;
164
+ $ this -> unlinkRecursive ( $ folder ) ;
305
165
}
306
166
}
307
167
308
- if (($ i + $ j ) > 0 )
309
- {
310
- $ html .= '<h2> ' . Text::_ ('MOD_JUNEWS_REMOVE_OLD_FILES ' ) . '</h2><table class="table table-striped"><tbody> ' ;
311
-
312
- foreach ($ files as $ file )
313
- {
314
- if (file_exists ($ file ))
315
- {
316
- $ filepath = str_replace ($ path , '' , $ file );
317
- unlink ($ file );
318
-
319
- $ html .= '<tr><td><span class="label">File:</span> <code> ' . $ filepath . '</code></td><td><span class="label label-inverse">Delete</span></td></tr> ' ;
320
- }
321
- }
322
-
323
- foreach ($ folders as $ folder )
324
- {
325
- if (is_dir ($ folder ))
326
- {
327
- $ folderpath = str_replace ($ path , '' , $ folder );
328
- $ this ->unlinkRecursive ($ folder , 1 );
329
-
330
- $ html .= '<tr><td><span class="label">Folder:</span> <code> ' . $ folderpath . '</code></td><td><span class="label label-inverse">Delete</span></td></tr> ' ;
331
- }
332
- }
333
-
334
- $ html .= '</tbody></table> ' ;
335
- }
336
-
337
- $ html .= '</div></div> ' ;
338
-
339
- //$app->enqueueMessage($html);
340
- echo $ html ;
341
-
342
168
return true ;
343
169
}
344
170
345
- /**
346
- * @param $dir
347
- *
348
- * @return bool
349
- *
350
- * @since version
351
- */
352
- private function MakeDirectory ($ dir )
353
- {
354
- if (mkdir ($ dir , 0777 , true ) || is_dir ($ dir ))
355
- {
356
- return true ;
357
- }
358
-
359
- if (!$ this ->MakeDirectory (dirname ($ dir )))
360
- {
361
- return false ;
362
- }
363
-
364
- return mkdir ($ dir , 0777 , true );
365
- }
366
-
367
171
/**
368
172
* @param $dir
369
173
* @param $deleteRootToo
370
174
*
371
175
*
372
176
* @since version
373
177
*/
374
- private function unlinkRecursive ($ dir , $ deleteRootToo )
178
+ private function unlinkRecursive ($ dir , $ deleteRootToo = 1 )
375
179
{
376
180
if (!$ dh = opendir ($ dir ))
377
181
{
0 commit comments