3 require_once "../inc/common.php";
4 require_once "../inc/header.php";
5 require_once "../Classes/class-plugin-git.php";
7 if (!current_user_can(PERMISSION_MANAGE_PLUGINS
))
10 $p = new PluginRepo();
13 <h2
>Add
New Plugin
</h2
>
19 Welcome to our lively plugins hub, where creativity takes center stage.<br>
20 We've got two fantastic plugins to kick things off (one practical, one for a playful twist).<br>
21 Join us on this exciting journey and unlock new possibilities for your website!<br><br>";
24 echo "Oops! Could not find plugins list. This is an upstream error, which means there is nothing wrong<br>
25 on your panel, it just means we can't check the plugins information webpage for some reason.<br>
26 Nothing to worry about! Try again later!";
28 require_once "../inc/footer.php";
34 const ibtns
= document
.querySelectorAll(".btn-install-plugin");
35 ibtns
.forEach((ib
) => {
36 ib
.addEventListener('click', (e
) => {
37 console
.log("Button clicked! " +ib
.innerHTML
);
38 if (ib
.innerHTML
!== "Install" && ib
.innerHTML
!== "Uninstall") // some point between, don't do anything
40 else if (ib
.innerHTML
== "Install") // install button pressed!
42 let req
= requestInstall(ib
.id
.slice(0,-7))
45 ib
.classList
.replace("btn-primary", "btn-secondary");
46 ib
.innerHTML
= "Installing...";
50 let uhoh
= new bsModal("Error", "Could not install: "+req
, "", null, false, true);
53 else if (ib
.innerHTML
== "Uninstall")
55 let req
= requestInstall(ib
.id
.slice(0,-7), true); // true = uninstall
58 ib
.classList
.replace("btn-outline-danger", "btn-secondary");
59 ib
.innerHTML
= "Uninstalling...";
63 let uhoh
= new bsModal("Error", "Could not uninstall: "+req
, "", null, false, true);
68 const installed
= document
.querySelectorAll(".installed");
69 installed
.forEach((el
) => {
70 let btn
= document
.getElementById(el
.id +
'install');
71 btn
.classList
.replace("btn-primary", "btn-outline-danger");
72 btn
.innerHTML
= "Uninstall";
75 function requestInstall(name
, uninstall
= false)
77 let inst
= (uninstall
) ? "uninstall" : "install";
78 var xhr
= new XMLHttpRequest();
80 xhr
.onload
= function() {
81 if (xhr
.status
=== 200) {
82 var response
= JSON
.parse(xhr
.responseText
);
83 console
.log(response
.success
);
84 let install_button
= document
.getElementById(name+
'install');
85 if (response
.success
!== undefined
)
89 install_button
.innerHTML
= (inst
== "uninstall") ? "Install" : "Uninstall";
90 install_button
.classList
.replace('btn-secondary', (inst
== "uninstall") ? 'btn-primary' : 'btn-outline-danger');
91 let icomplete
= bsModal(((inst
== "uninstall") ? "Uninstall" : "Install") +
" Plugin", response
.success
,"<div id=\""+name+
"closebtn\" class=\"btn btn-danger\">Close</div>", null, true, true, false);
92 let closebtn
= document
.getElementById(name+
"closebtn");
93 closebtn
.addEventListener('click', e
=> {
102 install_button
.innerHTML
= (inst
== "uninstall") ? "Uninstall" : "Install";
103 install_button
.classList
.replace('btn-secondary', (inst
== "uninstall") ? 'btn-outline-danger' : 'btn-primary');
104 let icomplete
= bsModal(((inst
== "uninstall") ? "Uninstall" : "Install") +
" Plugin", response
.error
,"", null, false, true);
105 let closebtn
= document
.getElementById(name+
"closebtn");
106 closebtn
.addEventListener('click', e
=> {
114 xhr
.open('GET', BASE_URL +
'api/plugin.php?'+inst+
'=' + name
, true);
119 function create_info_modal(modname
)
121 fetch('https://api.dalek.services/plugins.list')
122 .then(response
=> response
.json()) // Parse the response as JSON
124 for (let i
= 0; data
[i
]; i++
)
126 if (data
[i
].name
== modname
)
128 const modal
= bsModal(
129 "<i>Information about " + data
[i
].title +
"</i>", // title
130 "<div class=\"" + data
[i
].name +
"_screenshots\"><i class=\"fa fa-spinner\" aria-hidden=\"true\"></i></div><div class=\"" + data
[i
].name +
"_description\"><i class=\"fa fa-spinner\" aria-hidden=\"true\"></i></div>",
131 "<div id=\""+modname+
"closebtn\" class=\"btn btn-danger\">Close</div>", null, true, true, false
133 let modalclose
= document
.getElementById(modal
);
134 modalclose
.addEventListener('click', (e
) => {
135 $
("#"+modal
).modal('hide');
137 console
.log(modal +
'-body');
138 boobs
= document
.getElementById(modal +
'-body');
139 boobs
.innerHTML
= data
[i
].description
;
144 // Handle any errors that occur during the request
145 console
.error('Error:', error
);
149 const infoButtons
= document
.querySelectorAll('.more-info');
150 infoButtons
.forEach((el
) => {
151 el
.addEventListener('click', (event
) => {
152 create_info_modal(el
.id
);