default.php
8.54 KB
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
<?php
/**
* @package Joomla.Plugin
* @subpackage Installer.packageinstaller
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JHtml::_('bootstrap.tooltip');
JHtml::_('jquery.token');
JText::script('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_ERROR_UNKNOWN');
JText::script('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_ERROR_EMPTY');
JFactory::getDocument()->addScriptDeclaration('
Joomla.submitbuttonpackage = function()
{
var form = document.getElementById("adminForm");
// do field validation
if (form.install_package.value == "")
{
alert("' . JText::_('PLG_INSTALLER_PACKAGEINSTALLER_NO_PACKAGE', true) . '");
}
else
{
JoomlaInstaller.showLoading();
form.installtype.value = "upload"
form.submit();
}
};
');
// Drag and Drop installation scripts
$token = JSession::getFormToken();
$return = JFactory::getApplication()->input->getBase64('return');
// Drag-drop installation
JFactory::getDocument()->addScriptDeclaration(
<<<JS
jQuery(document).ready(function($) {
if (typeof FormData === 'undefined') {
$('#legacy-uploader').show();
$('#uploader-wrapper').hide();
return;
}
var uploading = false;
var dragZone = $('#dragarea');
var fileInput = $('#install_package');
var button = $('#select-file-button');
var url = 'index.php?option=com_installer&task=install.ajax_upload';
var returnUrl = $('#installer-return').val();
var actions = $('.upload-actions');
var progress = $('.upload-progress');
var progressBar = progress.find('.bar');
var percentage = progress.find('.uploading-number');
if (returnUrl) {
url += '&return=' + returnUrl;
}
button.on('click', function(e) {
fileInput.click();
});
fileInput.on('change', function (e) {
if (uploading) {
return;
}
Joomla.submitbuttonpackage();
});
dragZone.on('dragenter', function(e) {
e.preventDefault();
e.stopPropagation();
dragZone.addClass('hover');
return false;
});
// Notify user when file is over the drop area
dragZone.on('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
dragZone.addClass('hover');
return false;
});
dragZone.on('dragleave', function(e) {
e.preventDefault();
e.stopPropagation();
dragZone.removeClass('hover');
return false;
});
dragZone.on('drop', function(e) {
e.preventDefault();
e.stopPropagation();
dragZone.removeClass('hover');
if (uploading) {
return;
}
var files = e.originalEvent.target.files || e.originalEvent.dataTransfer.files;
if (!files.length) {
return;
}
var file = files[0];
var data = new FormData;
data.append('install_package', file);
data.append('installtype', 'upload');
dragZone.attr('data-state', 'uploading');
uploading = true;
$.ajax({
url: url,
data: data,
type: 'post',
processData: false,
cache: false,
contentType: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
progressBar.css('width', 0);
progressBar.attr('aria-valuenow', 0);
percentage.text(0);
// Upload progress
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
var number = Math.round(percentComplete * 100);
progressBar.css('width', number + '%');
progressBar.attr('aria-valuenow', number);
percentage.text(number);
if (number === 100) {
dragZone.attr('data-state', 'installing');
}
}
}, false);
return xhr;
}
})
.done(function (res) {
// Handle extension fatal error
if (!res || (!res.success && !res.data)) {
showError(res);
return;
}
// Always redirect that can show message queue from session
if (res.data.redirect) {
location.href = res.data.redirect;
} else {
location.href = 'index.php?option=com_installer&view=install';
}
}).error(function (error) {
uploading = false;
if (error.status === 200) {
var res = error.responseText || error.responseJSON;
showError(res);
} else {
showError(error.statusText);
}
});
function showError(res) {
dragZone.attr('data-state', 'pending');
var message = Joomla.JText._('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_ERROR_UNKNOWN');
if (res == null) {
message = Joomla.JText._('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_ERROR_EMPTY');
} else if (typeof res === 'string') {
// Let's remove unnecessary HTML
message = res.replace(/(<([^>]+)>|\s+)/g, ' ');
} else if (res.message) {
message = res.message;
}
Joomla.renderMessages({error: [message]});
}
});
});
JS
);
JFactory::getDocument()->addStyleDeclaration(
<<<CSS
#dragarea {
background-color: #fafbfc;
border: 1px dashed #999;
box-sizing: border-box;
padding: 5% 0;
transition: all 0.2s ease 0s;
width: 100%;
}
#dragarea p.lead {
color: #999;
}
#upload-icon {
font-size: 48px;
width: auto;
height: auto;
margin: 0;
line-height: 175%;
color: #999;
transition: all .2s;
}
#dragarea.hover {
border-color: #666;
background-color: #eee;
}
#dragarea.hover #upload-icon,
#dragarea p.lead {
color: #666;
}
.upload-progress, .install-progress {
width: 50%;
margin: 5px auto;
}
/* Default transition (.3s) is too slow, progress will not run to 100% */
.upload-progress .progress .bar {
-webkit-transition: width .1s;
-moz-transition: width .1s;
-o-transition: width .1s;
transition: width .1s;
}
#dragarea[data-state=pending] .upload-progress {
display: none;
}
#dragarea[data-state=pending] .install-progress {
display: none;
}
#dragarea[data-state=uploading] .install-progress {
display: none;
}
#dragarea[data-state=uploading] .upload-actions {
display: none;
}
#dragarea[data-state=installing] .upload-progress {
display: none;
}
#dragarea[data-state=installing] .upload-actions {
display: none;
}
CSS
);
$maxSize = JFilesystemHelper::fileUploadMaxSize();
?>
<legend><?php echo JText::_('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_INSTALL_JOOMLA_EXTENSION'); ?></legend>
<div id="uploader-wrapper">
<div id="dragarea" data-state="pending">
<div id="dragarea-content" class="text-center">
<p>
<span id="upload-icon" class="icon-upload" aria-hidden="true"></span>
</p>
<div class="upload-progress">
<div class="progress progress-striped active">
<div class="bar bar-success"
style="width: 0;"
role="progressbar"
aria-valuenow="0"
aria-valuemin="0"
aria-valuemax="100"
></div>
</div>
<p class="lead">
<span class="uploading-text">
<?php echo JText::_('PLG_INSTALLER_PACKAGEINSTALLER_UPLOADING'); ?>
</span>
<span class="uploading-number">0</span><span class="uploading-symbol">%</span>
</p>
</div>
<div class="install-progress">
<div class="progress progress-striped active">
<div class="bar" style="width: 100%;"></div>
</div>
<p class="lead">
<span class="installing-text">
<?php echo JText::_('PLG_INSTALLER_PACKAGEINSTALLER_INSTALLING'); ?>
</span>
</p>
</div>
<div class="upload-actions">
<p class="lead">
<?php echo JText::_('PLG_INSTALLER_PACKAGEINSTALLER_DRAG_FILE_HERE'); ?>
</p>
<p>
<button id="select-file-button" type="button" class="btn btn-success">
<span class="icon-copy" aria-hidden="true"></span>
<?php echo JText::_('PLG_INSTALLER_PACKAGEINSTALLER_SELECT_FILE'); ?>
</button>
</p>
<p>
<?php echo JText::sprintf('JGLOBAL_MAXIMUM_UPLOAD_SIZE_LIMIT', $maxSize); ?>
</p>
</div>
</div>
</div>
</div>
<div id="legacy-uploader" style="display: none;">
<div class="control-group">
<label for="install_package" class="control-label"><?php echo JText::_('PLG_INSTALLER_PACKAGEINSTALLER_EXTENSION_PACKAGE_FILE'); ?></label>
<div class="controls">
<input class="input_box" id="install_package" name="install_package" type="file" size="57" /><br>
<?php echo JText::sprintf('JGLOBAL_MAXIMUM_UPLOAD_SIZE_LIMIT', $maxSize); ?>
</div>
</div>
<div class="form-actions">
<button class="btn btn-primary" type="button" id="installbutton_package" onclick="Joomla.submitbuttonpackage()">
<?php echo JText::_('PLG_INSTALLER_PACKAGEINSTALLER_UPLOAD_AND_INSTALL'); ?>
</button>
</div>
<input id="installer-return" name="return" type="hidden" value="<?php echo $return; ?>" />
<input id="installer-token" name="return" type="hidden" value="<?php echo $token; ?>" />
</div>