]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - settings/add-plugin.php
Add a `Plugins` overview card
[irc/unrealircd/unrealircd-webpanel.git] / settings / add-plugin.php
CommitLineData
e47cb29f
VP
1<?php
2
3require_once "../inc/common.php";
4require_once "../inc/header.php";
5require_once "../Classes/class-plugin-git.php";
6
fae5cd15
VP
7if (!current_user_can(PERMISSION_MANAGE_PLUGINS))
8 die("Access denied");
9
e47cb29f
VP
10$p = new PluginRepo();
11?>
12
13<h2>Add New Plugin</h2>
14<br>
15
16<?php
17 if ($p) {
18 echo "
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>";
22 $p->do_list();
23 } else {
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!";
27 }
28 require_once "../inc/footer.php";
29
30?>
31
e47cb29f 32<script>
fae5cd15
VP
33
34 const ibtns = document.querySelectorAll(".btn-install-plugin");
35 ibtns.forEach((ib) => {
36 ib.addEventListener('click', (e) => {
fae5cd15
VP
37 if (ib.innerHTML !== "Install" && ib.innerHTML !== "Uninstall") // some point between, don't do anything
38 {}
39 else if (ib.innerHTML == "Install") // install button pressed!
40 {
41 let req = requestInstall(ib.id.slice(0,-7))
42 if (req == true)
43 {
44 ib.classList.replace("btn-primary", "btn-secondary");
45 ib.innerHTML = "Installing...";
46 }
47 else
48 {
49 let uhoh = new bsModal("Error", "Could not install: "+req, "", null, false, true);
50 }
51 }
52 else if (ib.innerHTML == "Uninstall")
53 {
54 let req = requestInstall(ib.id.slice(0,-7), true); // true = uninstall
55 if (req == true)
56 {
57 ib.classList.replace("btn-outline-danger", "btn-secondary");
58 ib.innerHTML = "Uninstalling...";
59 }
60 else
61 {
62 let uhoh = new bsModal("Error", "Could not uninstall: "+req, "", null, false, true);
63 }
64 }
65 });
66 })
67 const installed = document.querySelectorAll(".installed");
68 installed.forEach((el) => {
69 let btn = document.getElementById(el.id + 'install');
70 btn.classList.replace("btn-primary", "btn-outline-danger");
71 btn.innerHTML = "Uninstall";
72 });
73
74 function requestInstall(name, uninstall = false)
75 {
76 let inst = (uninstall) ? "uninstall" : "install";
77 var xhr = new XMLHttpRequest();
78
79 xhr.onload = function() {
80 if (xhr.status === 200) {
81 var response = JSON.parse(xhr.responseText);
82 console.log(response.success);
83 let install_button = document.getElementById(name+'install');
84 if (response.success !== undefined)
85 {
86 if (install_button)
87 {
88 install_button.innerHTML = (inst == "uninstall") ? "Install" : "Uninstall";
89 install_button.classList.replace('btn-secondary', (inst == "uninstall") ? 'btn-primary' : 'btn-outline-danger');
f2e770d4 90 setTimeout(() => { location.reload() }, 500);
fae5cd15
VP
91 }
92 }
93 else
94 {
95 if (install_button)
96 {
97 install_button.innerHTML = (inst == "uninstall") ? "Uninstall" : "Install";
98 install_button.classList.replace('btn-secondary', (inst == "uninstall") ? 'btn-outline-danger' : 'btn-primary');
f2e770d4 99 setTimeout(() => { location.reload() }, 500);
fae5cd15
VP
100 }
101 }
102 }
103 };
104
105 xhr.open('GET', BASE_URL + 'api/plugin.php?'+inst+'=' + name, true);
106 xhr.send();
107 return true;
108 }
109
110 function create_info_modal(modname)
111 {
e6d7cf20 112 fetch(BASE_URL + 'api/plugin.php')
fae5cd15
VP
113 .then(response => response.json()) // Parse the response as JSON
114 .then(data => {
4074d0d1 115 for (let i = 0; data.list[i]; i++)
fae5cd15 116 {
4074d0d1 117 if (data.list[i].name == modname)
fae5cd15
VP
118 {
119 const modal = bsModal(
4074d0d1
VP
120 "<i>Information about " + data.list[i].title + "</i>", // title
121 "<div class=\"" + data.list[i].name + "_screenshots\"><i class=\"fa fa-spinner\" aria-hidden=\"true\"></i></div><div class=\"" + data.list[i].name + "_description\"><i class=\"fa fa-spinner\" aria-hidden=\"true\"></i></div>",
a2c0dd46 122 "<div id=\""+modname+"closebtn\" class=\"btn btn-danger\">Close</div>", null, true, true, true
fae5cd15
VP
123 );
124 let modalclose = document.getElementById(modal);
125 modalclose.addEventListener('click', (e) => {
126 $("#"+modal).modal('hide');
127 });
fae5cd15 128 boobs = document.getElementById(modal + '-body');
f2e770d4
VP
129 boobs.innerHTML = "";
130 if (data.list[i].screenshot.length)
131 {
132 boobs.innerHTML += ` <div style="padding-left: 0px; padding-right: 0px;">
133 <img src="` + (data.list[i].screenshot[0] ?? "") + `" class="screenshot img-fluid" alt="` + data.list[i].screenshot[1] + ` style="max-width: 100%; height:auto">
134 </div>`;
135 }
136 boobs.innerHTML += "<p class=\"alert alert-primary mt-2\"><i><b>Description:</i></b><br>" + atob(data.list[i].readme.replace(["\n",""],["<br>","<br>"])) + "</p>";
137 boobs.innerHTML += `<div class="alert alert-dark">
138 <table class="table">
139 <tr>
140 <th scope="row">Title</th>
141 <td>`+data.list[i].title+`</td>
142 </tr>
143 <tr>
144 <th scope="row">Description</th>
145 <td>`+data.list[i].description+`</td>
146 </tr>
147 <tr>
148 <th scope="row">Version</th>
149 <td>`+data.list[i].version+`</td>
150 </tr>
151 <tr>
152 <th scope="row">Author</th>
153 <td>`+data.list[i].author+`</td>
154 </tr>
155 <tr>
156 <th scope="row">Min Version Required</th>
157 <td>`+data.list[i].minver+`</td>
158 </tr>
159 <tr>
160 <th scope="row">Max Version</th>
161 <td>`+data.list[i].maxver+`</td>
162 </tr>
163
164 </table></small>
165 </div>`;
fae5cd15
VP
166 }
167 }
168 })
169 .catch(error => {
170 // Handle any errors that occur during the request
171 console.error('Error:', error);
172 });
173 }
174
175 const infoButtons = document.querySelectorAll('.more-info');
176 infoButtons.forEach((el) => {
177 el.addEventListener('click', (event) => {
178 create_info_modal(el.id);
179
180 });
181 });
182</script>