forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanagerPlugins.php
495 lines (475 loc) · 25.2 KB
/
managerPlugins.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
<?php
require_once '../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/user.php';
if (!User::isAdmin()) {
header("Location: {$global['webSiteRootURL']}?error=" . __("You can not manage plugins"));
exit;
}
require_once $global['systemRootPath'] . 'objects/plugin.php';
?>
<!DOCTYPE html>
<html lang="<?php echo $_SESSION['language']; ?>">
<head>
<title><?php echo $config->getWebSiteTitle(); ?> :: <?php echo __("Plugins"); ?></title>
<?php
include $global['systemRootPath'] . 'view/include/head.php';
?>
<script src="<?php echo $global['webSiteRootURL']; ?>view/bootstrap/bootstrap-fileinput/js/fileinput.min.js" type="text/javascript"></script>
<link href="<?php echo $global['webSiteRootURL']; ?>view/bootstrap/bootstrap-fileinput/css/fileinput.min.css" rel="stylesheet" type="text/css"/>
<script src="<?php echo $global['webSiteRootURL']; ?>view/bootstrap/bootstrap-fileinput/themes/fa/theme.min.js" type="text/javascript"></script>
<link href="<?php echo $global['webSiteRootURL']; ?>view/bootstrap/bootstrap-fileinput/themes/explorer/theme.min.css" rel="stylesheet" type="text/css"/>
<script src="<?php echo $global['webSiteRootURL']; ?>view/bootstrap/bootstrap-fileinput/themes/explorer/theme.min.js" type="text/javascript"></script>
<style>
.panel{
text-align: center;
}
.panel:hover { box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4), 0 1px 5px rgba(130, 130, 130, 0.35); }
.panel-body
{
padding: 0px;
text-align: center;
}
.the-price
{
background-color: rgba(220,220,220,.17);
box-shadow: 0 1px 0 #dcdcdc, inset 0 1px 0 #fff;
padding: 6px;
margin: 0;
}
.the-price h1
{
line-height: 1em;
padding: 0;
margin: 0;
}
.subscript
{
font-size: 25px;
}
/* CSS-only ribbon styles */
.cnrflash
{
/*Position correctly within container*/
position: absolute;
top: -9px;
right: 4px;
z-index: 1; /*Set overflow to hidden, to mask inner square*/
overflow: hidden; /*Set size and add subtle rounding to soften edges*/
width: 100px;
height: 100px;
border-radius: 3px 5px 3px 0;
}
.cnrflash-inner
{
/*Set position, make larger then container and rotate 45 degrees*/
position: absolute;
bottom: 0;
right: 0;
width: 145px;
height: 145px;
-ms-transform: rotate(45deg); /* IE 9 */
-o-transform: rotate(45deg); /* Opera */
-moz-transform: rotate(45deg); /* Firefox */
-webkit-transform: rotate(45deg); /* Safari and Chrome */
-webkit-transform-origin: 100% 100%; /*Purely decorative effects to add texture and stuff*/ /* Safari and Chrome */
-ms-transform-origin: 100% 100%; /* IE 9 */
-o-transform-origin: 100% 100%; /* Opera */
-moz-transform-origin: 100% 100%; /* Firefox */
background-image: linear-gradient(90deg, transparent 50%, rgba(255,255,255,.1) 50%), linear-gradient(0deg, transparent 0%, rgba(1,1,1,.2) 50%);
background-size: 4px,auto, auto,auto;
background-color: #aa0101;
box-shadow: 0 3px 3px 0 rgba(1,1,1,.5), 0 1px 0 0 rgba(1,1,1,.5), inset 0 -1px 8px 0 rgba(255,255,255,.3), inset 0 -1px 0 0 rgba(255,255,255,.2);
}
.cnrflash-inner:before, .cnrflash-inner:after
{
/*Use the border triangle trick to make it look like the ribbon wraps round it's container*/
content: " ";
display: block;
position: absolute;
bottom: -16px;
width: 0;
height: 0;
border: 8px solid #800000;
}
.cnrflash-inner:before
{
left: 1px;
border-bottom-color: transparent;
border-right-color: transparent;
}
.cnrflash-inner:after
{
right: 0;
border-bottom-color: transparent;
border-left-color: transparent;
}
.cnrflash-label
{
/*Make the label look nice*/
position: absolute;
bottom: 0;
left: 0;
display: block;
width: 100%;
padding-bottom: 5px;
color: #fff;
text-shadow: 0 1px 1px rgba(1,1,1,.8);
font-size: 0.95em;
font-weight: bold;
text-align: center;
}
.panel-sm{
margin-bottom: 5px;
}
.panel-sm table, .panel-sm div{
margin: 0;
}
.panel-sm .panel-heading{
height: 25px;
padding: 2px 5px;
font-size: 0.9em;
}
.panel-sm .panel-heading .panel-title{
font-size: 0.9em;
}
.panel-sm .panel-body{
padding: 0;
font-size: 0.8em;
}
</style>
</head>
<body>
<?php
include 'include/navbar.php';
?>
<div class="container-fluid">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#menu0"><i class="fa fa-plug"></i> Installed Plugins</a></li>
<li><a data-toggle="tab" href="#menu1"><i class="fa fa-cart-plus"></i> Plugins Store</a></li>
</ul>
<div class="tab-content">
<div id="menu0" class="tab-pane fade in active">
<div class="list-group-item">
<div class="btn-group" >
<button type="button" class="btn btn-default" id="upload">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <?php echo __("Upload a Plugin"); ?>
</button>
</div>
<table id="grid" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="name" data-formatter="name" data-width="300px" ><?php echo __("Name"); ?></th>
<th data-column-id="description"><?php echo __("description"); ?></th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false" data-width="150px"></th>
</tr>
</thead>
</table>
<div id="pluginsFormModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><?php echo __("Plugin Form"); ?></h4>
</div>
<div class="modal-body">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#visual">Visual</a></li>
<li><a data-toggle="tab" href="#code">Code</a></li>
</ul>
<div class="tab-content">
<div id="visual" class="tab-pane fade in active">
<div class="row" id="jsonElements" style="padding: 10px;">Some content.</div>
</div>
<div id="code" class="tab-pane fade">
<form class="form-compact" id="updatePluginForm" onsubmit="">
<input type="hidden" id="inputPluginId" >
<label for="inputData" class="sr-only">Object Data</label>
<textarea class="form-control" id="inputData" rows="5" placeholder="Object Data"></textarea>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo __("Close"); ?></button>
<button type="button" class="btn btn-primary" id="savePluginBtn"><?php echo __("Save changes"); ?></button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<div id="pluginsImportFormModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<?php
$dir = "{$global['systemRootPath']}plugin";
if (!isUnzip()) {
?>
<div class="alert alert-warning">
Make sure you have the unzip app on your server
<pre><code>sudo apt-get install unzip</code></pre>
</div>
<?php
}
if (is_writable($dir)) {
?>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><?php echo __("Upload a Plugin ZIP File"); ?></h4>
</div>
<div class="modal-body">
<input id="input-b1" name="input-b1" type="file" class="">
</div>
</div>
<?php
} else {
?>
<div class="alert alert-danger">
You need to make the plugin dir writable before upload, run this command and refresh this page
<pre><code>chown www-data:www-data <?php echo $dir; ?> && chmod 755 <?php echo $dir; ?></code></pre>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
<div id="menu1" class="tab-pane fade">
<div class="list-group-item">
<div class="panel panel-default">
<div class="panel-heading"><a href="https://easytube.club/signUp" class="btn btn-default btn-xs"><i class="fa fa-plug"></i> Easy Club Plugin Store </a></div>
<div class="panel-body">
<ul class="list-group" id="pluginStoreList">
</ul>
</div>
</div>
</div>
</div>
</div>
<li class="list-group-item hidden col-md-3" id="pluginStoreListModel">
<div class="panel panel-warning panel-sm">
<div class="panel-heading">
<h3 class="panel-title"></h3>
</div>
<div class="panel-body">
<div class="the-price">
<h1>
USD $<span class="int">0</span>.<small class="cents">00</small>
</h1>
</div>
<table class="table">
<tr >
<td>
<img src="" class="img img-responsive img-rounded img-thumbnail zoom" style="height: 70px;">
</td>
</tr>
<tr class="active">
<td class="desc" style="height: 50px;"></td>
</tr>
</table>
</div>
<div class="panel-footer">
<a href="https://easytube.club/signUp" class="btn btn-success btn-xs" role="button"><i class="fa fa-cart-plus"></i> Buy This Plugin </a>
</div>
</div>
</li>
</div><!--/.container-->
<?php
include 'include/footer.php';
?>
<script>
function jsonToForm(json) {
$('#jsonElements').empty();
$.each(json, function (i, val) {
var div;
var label;
var input;
if (typeof (val) === "object") {// checkbox
div = $('<div />', {"class": 'form-group'});
label = $('<label />', {"text": i + ": "});
if(val.type === 'textarea'){
input = $('<textarea />', {"class": 'form-control jsonElement', "name": i, "pluginType":"object"});
input.text(val.value);
}else{
input = $('<input />', {"class": 'form-control jsonElement', "type": val.type, "name": i, "value": val.value, "pluginType":"object"});
}
div.append(label);
div.append(input);
} else if (typeof (val) === "boolean") {// checkbox
div = $('<div />', {"class": 'form-group'});
label = $('<label />', {"class": "checkbox-inline"});
input = $('<input />', {"class": 'jsonElement', "type": 'checkbox', "name": i, "value": 1, "checked": val});
label.append(input);
label.append(" " + i);
div.append(label);
} else {
div = $('<div />', {"class": 'form-group'});
label = $('<label />', {"text": i + ": "});
input = $('<input />', {"class": 'form-control jsonElement', "name": i, "type": 'text', "value": val});
div.append(label);
div.append(input);
}
$('#jsonElements').append(div);
$('.jsonElement').change(function(){
var json = formToJson();
json = JSON.stringify(json);
$('#inputData').val(json);
});
})
}
function formToJson() {
var json = {};
$(".jsonElement").each(function (index) {
var name = $(this).attr("name");
var type = $(this).attr("type");
var pluginType = $(this).attr("pluginType");
if(pluginType==='object'){
if(typeof type === 'undefined'){
type = 'textarea';
}
json [name] = {type:type, value:$(this).val()};
}else if (type === 'checkbox') {
json [name] = $(this).is(":checked");
} else {
json [name] = $(this).val();
}
});
console.log(json);
return json;
}
function createPluginStoreList(src, name, price, description) {
var intPrice = Math.floor(price);
//var cents = Math.ceil((price - intPrice) * 100);
var $li = $('#pluginStoreListModel').clone();
$li.removeClass("hidden").attr("id", "");
$li.find('.panel-title').text(name);
$li.find('.int').text(intPrice);
$li.find('.cents').text("99");
$li.find('.desc').text(description);
$li.find('.img').attr("src", src);
$('#pluginStoreList').append($li);
}
$(document).ready(function () {
var myTextarea = document.getElementById("inputData");
var grid = $("#grid").bootgrid({
navigation: 0,
ajax: true,
url: "<?php echo $global['webSiteRootURL'] . "pluginsAvailable.json"; ?>",
formatters: {
"commands": function (column, row) {
var editBtn = '';
if (row.id && !$.isEmptyObject(row.data_object)) {
editBtn = '<button type="button" class="btn btn-xs btn-default command-edit" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="Edit"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Edit parameters</button>';
}
var sqlBtn = '';
if (row.databaseScript) {
sqlBtn = '<button type="button" class="btn btn-xs btn-default command-sql" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="Run Database Script"><span class="fa fa-database" aria-hidden="true"></span> Install tables</button>';
}
menu = '';
if(row.installedPlugin && row.installedPlugin.status == 'active'){
menu = row.pluginMenu;
}
return editBtn + "<br>" + sqlBtn + "<br>" + menu;
},
"name": function (column, row) {
var checked = "";
if (row.enabled) {
checked = " checked='checked' ";
}
var switchBtn = '<div class="material-switch"><input name="enable' + row.uuid + '" id="enable' + row.uuid + '" type="checkbox" value="0" class="pluginSwitch" ' + checked + ' /><label for="enable' + row.uuid + '" class="label-success"></label></div>';
var tags = '';
if (row.tags) {
for (i = 0; i < row.tags.length; i++) {
var cl = "primary";
if (row.tags[i] === 'free') {
cl = 'success';
} else if (row.tags[i] === 'firstPage') {
cl = 'danger';
} else if (row.tags[i] === 'login') {
cl = 'info';
}
tags += '<span class="label label-' + cl + '">' + row.tags[i] + '</span> ';
}
}
var txt = row.name + " (" + row.dir + ")<br><small class='text-muted'>UUID: " + row.uuid + "</small>";
txt += "<br>" + switchBtn;
txt += "<br>" + tags;
return txt;
}
}
}).on("loaded.rs.jquery.bootgrid", function () {
/* Executes after data is loaded and rendered */
grid.find(".pluginSwitch").on("change", function (e) {
var row_index = $(this).closest('tr').index();
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
modal.showPleaseWait();
$.ajax({
url: 'switchPlugin',
data: {"uuid": row.uuid, "name": row.name, "dir": row.dir, "enable": $('#enable' + row.uuid).is(":checked")},
type: 'post',
success: function (response) {
modal.hidePleaseWait();
$("#grid").bootgrid('reload');
}
});
});
grid.find(".command-edit").on("click", function (e) {
var row_index = $(this).closest('tr').index();
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
$('#inputPluginId').val(row.id);
var json = JSON.stringify(row.data_object);
jsonToForm(row.data_object);
$('#inputData').val(json);
$('#pluginsFormModal').modal();
});
grid.find(".command-sql").on("click", function (e) {
var row_index = $(this).closest('tr').index();
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
$('#inputPluginId').val(row.id);
$('#inputData').val(JSON.stringify(row.data_object));
modal.showPleaseWait();
$.ajax({
url: 'runDBScriptPlugin.json',
data: {"name": row.name},
type: 'post',
success: function (response) {
modal.hidePleaseWait();
}
});
});
});
$('#savePluginBtn').click(function (evt) {
modal.showPleaseWait();
$.ajax({
url: 'addDataObjectPlugin.json',
data: {"id": $('#inputPluginId').val(), "object_data": $('#inputData').val()},
type: 'post',
success: function (response) {
modal.hidePleaseWait();
$("#grid").bootgrid('reload');
$('#pluginsFormModal').modal('hide');
}
});
});
$('#upload').click(function (evt) {
$('#pluginsImportFormModal').modal();
});
$('#input-b1').fileinput({
uploadUrl: '<?php echo $global['webSiteRootURL']; ?>pluginImport.json',
allowedFileExtensions: ['zip']
}).on('fileuploaded', function (event, data, id, index) {
$("#grid").bootgrid('reload');
});
$.ajax({
url: 'https://easytube.club/plugins.json?jsonp=1',
dataType: 'jsonp',
success: function (response) {
for (i = 0; i < response.rows.length; i++) {
var r = response.rows[i];
createPluginStoreList(r.images[0], r.name, r.price, r.description);
}
}
});
});
</script>
</body>
</html>