Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit d677d45

Browse files
author
mattpass
committed
Update to plugins to use new serialized settings
1 parent 8b4436d commit d677d45

File tree

2 files changed

+34
-83
lines changed

2 files changed

+34
-83
lines changed

classes/Settings.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,12 @@ public function savelast10Files($fileName, $files): bool
248248
$ICEcoderSettingsFromFile['last10Files'] = $files;
249249
return $this->setConfigUsersSettings($fileName, $ICEcoderSettingsFromFile);
250250
}
251+
252+
public function updatePlugins($fileName, $plugins): bool
253+
{
254+
// Update users config settings file
255+
$ICEcoderSettingsFromFile = $this->getConfigUsersSettings($fileName);
256+
$ICEcoderSettingsFromFile['plugins'] = $plugins;
257+
return $this->setConfigUsersSettings($fileName, $ICEcoderSettingsFromFile);
258+
}
251259
}

lib/plugins-manager.php

Lines changed: 26 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
require_once dirname(__FILE__) . "/../classes/Settings.php";
3+
4+
$settingsClass = new \ICEcoder\Settings();
5+
26
include "headers.php";
37
include "settings.php";
48
$t = $text['plugins-manager'];
@@ -13,10 +17,6 @@
1317
// If we have an action to perform
1418
if (false === $demoMode && isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] && isset($_GET['action'])) {
1519

16-
// Get our old plugin & user settings
17-
$oldPlugins = $ICEcoder["plugins"];
18-
$settingsContents = getData("../data/" . $settingsFile);
19-
2020
// ==========
2121
// INSTALLING
2222
// ==========
@@ -61,61 +61,27 @@
6161
// Remove the tmp zip file
6262
unlink($zipFile);
6363

64-
// Start creating a new chunk for the plugins settings
65-
$settingsNew = '"plugins" => array(';
66-
67-
// Set all the old plugins
68-
for ($i = 0; $i < count($oldPlugins); $i++) {
69-
$settingsNew .=
70-
' array("' .
71-
$oldPlugins[$i][0] . '","' .
72-
$oldPlugins[$i][1] . '","' .
73-
$oldPlugins[$i][2] . '","' .
74-
$oldPlugins[$i][3] . '","' .
75-
$oldPlugins[$i][4] . '","' .
76-
$oldPlugins[$i][5] .
77-
'"),';
78-
}
79-
// Then add the new one
80-
$settingsNew .=
81-
' array("' .
82-
$pluginsData[$_GET['plugin']]['name'] . '","' .
83-
$pluginsData[$_GET['plugin']]['icon'] . '","' .
84-
$pluginsData[$_GET['plugin']]['style'] . '","' .
85-
$pluginsData[$_GET['plugin']]['URL'] . '","' .
86-
$pluginsData[$_GET['plugin']]['target'] . '","' .
87-
$pluginsData[$_GET['plugin']]['timer'] .
88-
'")';
89-
$settingsNew .= ' ),' . PHP_EOL;
64+
$ICEcoder["plugins"][] = [
65+
$pluginsData[$_GET['plugin']]['name'],
66+
$pluginsData[$_GET['plugin']]['icon'],
67+
$pluginsData[$_GET['plugin']]['style'],
68+
$pluginsData[$_GET['plugin']]['URL'],
69+
$pluginsData[$_GET['plugin']]['target'],
70+
$pluginsData[$_GET['plugin']]['timer']
71+
];
9072
}
9173

9274
// ============
9375
// UNINSTALLING
9476
// ============
9577

9678
if ("uninstall" === $_GET['action']) {
97-
98-
// Start creating a new chunk for the plugins settings
99-
$settingsNew = '"plugins" => array(';
100-
101-
// Set all the old plugins
102-
for ($i = 0; $i < count($oldPlugins); $i++) {
103-
// As long as it's not the one we want to remove
104-
if ($oldPlugins[$i][0] !== $pluginsData[$_GET['plugin']]['name']) {
105-
$settingsNew .=
106-
' array("' .
107-
$oldPlugins[$i][0] . '","' .
108-
$oldPlugins[$i][1] . '","' .
109-
$oldPlugins[$i][2] . '","' .
110-
$oldPlugins[$i][3] . '","' .
111-
$oldPlugins[$i][4] . '","' .
112-
$oldPlugins[$i][5] .
113-
'"),';
79+
// Remove the old plugin
80+
for ($i = 0; $i < count($ICEcoder["plugins"]); $i++) {
81+
if ($ICEcoder["plugins"][$i][0] === $pluginsData[$_GET['plugin']]['name']) {
82+
unset($ICEcoder["plugins"][$i]);
11483
}
11584
}
116-
// Rtrim off the last comma
117-
$settingsNew = rtrim($settingsNew, ',');
118-
$settingsNew .= ' ),' . PHP_EOL;
11985

12086
// Finally, delete the plugin itself
12187
$target = '../plugins/';
@@ -128,48 +94,25 @@
12894
// ========
12995

13096
if ("update" === $_GET['action']) {
131-
132-
// Start creating a new chunk for the plugins settings
133-
$settingsNew = '"plugins" => array(';
134-
13597
// Redo the arrays using the form data
136-
for ($i = 0; $i < count($oldPlugins); $i++) {
98+
for ($i = 0; $i < count($ICEcoder["plugins"]); $i++) {
13799
$timer = intval($_POST['timer' . $i]);
138100
if ($timer == 0) {
139101
$timer = "";
140102
}
141-
$settingsNew .=
142-
' array("' .
143-
$_POST['name' . $i] . '","' .
144-
$_POST['icon' . $i] . '","' .
145-
$_POST['style' . $i] . '","' .
146-
$_POST['URL' . $i] . '","' .
147-
$_POST['target' . $i] . '","' .
148-
$timer .
149-
'"),';
103+
$ICEcoder["plugins"][] = [
104+
$_POST['name' . $i],
105+
$_POST['icon' . $i],
106+
$_POST['style' . $i],
107+
$_POST['URL' . $i],
108+
$_POST['target' . $i],
109+
$timer
110+
];
150111
}
151-
// Rtrim off the last comma
152-
$settingsNew = rtrim($settingsNew, ',');
153-
$settingsNew .= ' ),' . PHP_EOL;
154112
}
155113

156-
// Now we have a new settingsNew string to use and files installed/uninstalled
157-
// we can update the plugin arrays in the settings file
158-
159-
// Identify the bit to replace
160-
$repPosStart = strpos($settingsContents, '"plugins"');
161-
$repPosEnd = strpos($settingsContents, '"ftpSites"');
162-
163-
// Compile our new settings
164-
$settingsContents = substr($settingsContents, 0, $repPosStart) .
165-
$settingsNew .
166-
substr($settingsContents, $repPosEnd, strlen($settingsContents));
167-
168114
// Now update the config file
169-
if (is_writeable("../data/".$settingsFile)) {
170-
$fh = fopen("../data/".$settingsFile, 'w');
171-
fwrite($fh, $settingsContents);
172-
fclose($fh);
115+
if (true === $settingsClass->updatePlugins($settingsFile, $ICEcoder['plugins'])) {
173116
// Finally, reload ICEcoder itself if plugin requires it or just the iFrame screen for the user if it doesn't
174117
if ("install" === $_GET['action'] && "true" === $pluginsData[$_GET['plugin']]['reload']) {
175118
echo "<script>if (confirm('" . $t['ICEcoder needs to...'] . "')) {parent.window.location.reload(true);} else {window.location='plugins-manager.php?updatedPlugins&csrf=' + parent.ICEcoder.csrf;}</script>";

0 commit comments

Comments
 (0)