@@ -35,7 +35,7 @@ class PluginsPresenter extends PagePresenter
3535 */
3636 public function createList (): void
3737 {
38- global $ gL10n, $ gCurrentSession ;
38+ global $ gL10n ;
3939
4040 $ this ->setHtmlID ('adm_plugins ' );
4141 $ this ->setHeadline ($ gL10n ->get ('SYS_PLUGIN_MANAGER ' ));
@@ -50,6 +50,77 @@ public function createList(): void
5050 ' , true
5151 );
5252
53+ $ this ->addJavascript ('
54+ function callPluginAction(url, csrfToken, pluginName) {
55+ $.post(url, {
56+ "adm_csrf_token": csrfToken,
57+ "name": pluginName
58+ }, function(data) {
59+ const messageText = $("#adm_status_message");
60+
61+ var returnStatus = "error";
62+ var returnMessage = "";
63+
64+ try {
65+ const returnData = JSON.parse(data);
66+
67+ returnStatus = returnData.status;
68+
69+ if (typeof returnData.message !== "undefined") {
70+ returnMessage = returnData.message;
71+ }
72+ } catch (e) {
73+ // fallback for old implementation without JSON response
74+ if (data === "done") {
75+ returnStatus = "success";
76+ } else {
77+ returnMessage = data;
78+ }
79+ }
80+
81+ if (returnStatus === "success") {
82+ if (returnMessage !== "") {
83+ messageText.html(
84+ "<div class=\"alert alert-success\">" +
85+ "<i class=\"bi bi-check-lg\"></i> " +
86+ returnMessage +
87+ "</div>"
88+ );
89+ }
90+ } else {
91+ if (returnMessage.length === 0) {
92+ returnMessage = "Error: Undefined error occurred!";
93+ }
94+
95+ messageText.html(
96+ "<div class=\"alert alert-danger\">" +
97+ "<i class=\"bi bi-exclamation-circle-fill\"></i> " +
98+ returnMessage +
99+ "</div>"
100+ );
101+ }
102+
103+ setTimeout(function() {
104+ $("#adm_modal").modal("hide");
105+ $("#adm_modal_messagebox").modal("hide");
106+ location.reload();
107+ }, 2000);
108+ });
109+ }
110+
111+ function callPluginInstall(url, csrfToken, pluginName) {
112+ callPluginAction(url, csrfToken, pluginName);
113+ }
114+
115+ function callPluginUpdate(url, csrfToken, pluginName) {
116+ callPluginAction(url, csrfToken, pluginName);
117+ }
118+
119+ function callPluginUninstall(url, csrfToken, pluginName) {
120+ callPluginAction(url, csrfToken, pluginName);
121+ }
122+ ' );
123+
53124 $ this ->smarty ->assign ('list ' , $ this ->templateData );
54125 $ this ->smarty ->assign ('l10n ' , $ gL10n );
55126 try {
@@ -94,7 +165,7 @@ public function createCards(): void
94165 */
95166 public function prepareData (): void
96167 {
97- global $ gL10n ;
168+ global $ gL10n, $ gCurrentSession ;
98169 $ pluginManager = new PluginManager ();
99170 $ plugins = $ pluginManager ->getAvailablePlugins ();
100171 $ templateRowPluginParent ['overview ' ] = array ('id ' => 'overview_plugins ' , 'name ' => $ gL10n ->get ('SYS_OVERVIEW_EXTENSIONS ' ), 'entries ' => array ());
@@ -142,23 +213,26 @@ public function prepareData(): void
142213 // add update action if an update is available
143214 if ($ interface ->isUpdateAvailable ()) {
144215 $ templateRow ['actions ' ][] = array (
145- 'url ' => SecurityUtils::encodeUrl (ADMIDIO_URL . FOLDER_MODULES . '/plugins.php ' , array ('mode ' => 'update ' , 'name ' => $ pluginName )),
216+ 'dataHref ' => 'callPluginUpdate( \'' . SecurityUtils::encodeUrl (ADMIDIO_URL . FOLDER_MODULES . '/plugins.php ' , array ('mode ' => 'update ' )) . '\', \'' . $ gCurrentSession ->getCsrfToken () . '\', \'' . addslashes ($ pluginName ) . '\') ' ,
217+ 'dataMessage ' => $ gL10n ->get ('SYS_WANT_UPDATE_PLUGIN ' , array ($ pluginName )),
146218 'icon ' => 'bi bi-arrow-clockwise ' ,
147219 'tooltip ' => $ gL10n ->get ('SYS_PLUGIN_UPDATE ' )
148220 );
149221 }
150222 if (!$ interface ->isAdmidioPlugin ()) {
151223 // add uninstall action
152224 $ templateRow ['actions ' ][] = array (
153- 'url ' => SecurityUtils::encodeUrl (ADMIDIO_URL . FOLDER_MODULES . '/plugins.php ' , array ('mode ' => 'uninstall ' , 'name ' => $ pluginName )),
225+ 'dataHref ' => 'callPluginUninstall( \'' . SecurityUtils::encodeUrl (ADMIDIO_URL . FOLDER_MODULES . '/plugins.php ' , array ('mode ' => 'uninstall ' )) . '\', \'' . $ gCurrentSession ->getCsrfToken () . '\', \'' . addslashes ($ pluginName ) . '\') ' ,
226+ 'dataMessage ' => $ gL10n ->get ('SYS_WANT_UNINSTALL_PLUGIN ' , array ($ pluginName )),
154227 'icon ' => 'bi bi-trash ' ,
155228 'tooltip ' => $ gL10n ->get ('SYS_PLUGIN_UNINSTALL ' )
156229 );
157230 }
158231 } else {
159232 // add install action
160233 $ templateRow ['actions ' ][] = array (
161- 'url ' => SecurityUtils::encodeUrl (ADMIDIO_URL . FOLDER_MODULES . '/plugins.php ' , array ('mode ' => 'install ' , 'name ' => $ pluginName )),
234+ 'dataHref ' => 'callPluginInstall( \'' . SecurityUtils::encodeUrl (ADMIDIO_URL . FOLDER_MODULES . '/plugins.php ' , array ('mode ' => 'install ' )) . '\', \'' . $ gCurrentSession ->getCsrfToken () . '\', \'' . addslashes ($ pluginName ) . '\') ' ,
235+ 'dataMessage ' => $ gL10n ->get ('SYS_WANT_INSTALL_PLUGIN ' , array ($ pluginName )),
162236 'icon ' => 'bi bi-download ' ,
163237 'tooltip ' => $ gL10n ->get ('SYS_PLUGIN_INSTALL ' )
164238 );
@@ -206,4 +280,4 @@ public function prepareData(): void
206280
207281 $ this ->templateData = $ templateRowPluginParent ;
208282 }
209- }
283+ }
0 commit comments