|
1 | 1 | <?php
|
| 2 | +require_once dirname(__FILE__) . "/../classes/Settings.php"; |
| 3 | + |
| 4 | +$settingsClass = new \ICEcoder\Settings(); |
| 5 | + |
2 | 6 | include "headers.php";
|
3 | 7 | include "settings.php";
|
4 | 8 | $t = $text['plugins-manager'];
|
|
13 | 17 | // If we have an action to perform
|
14 | 18 | if (false === $demoMode && isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] && isset($_GET['action'])) {
|
15 | 19 |
|
16 |
| - // Get our old plugin & user settings |
17 |
| - $oldPlugins = $ICEcoder["plugins"]; |
18 |
| - $settingsContents = getData("../data/" . $settingsFile); |
19 |
| - |
20 | 20 | // ==========
|
21 | 21 | // INSTALLING
|
22 | 22 | // ==========
|
|
61 | 61 | // Remove the tmp zip file
|
62 | 62 | unlink($zipFile);
|
63 | 63 |
|
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 | + ]; |
90 | 72 | }
|
91 | 73 |
|
92 | 74 | // ============
|
93 | 75 | // UNINSTALLING
|
94 | 76 | // ============
|
95 | 77 |
|
96 | 78 | 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]); |
114 | 83 | }
|
115 | 84 | }
|
116 |
| - // Rtrim off the last comma |
117 |
| - $settingsNew = rtrim($settingsNew, ','); |
118 |
| - $settingsNew .= ' ),' . PHP_EOL; |
119 | 85 |
|
120 | 86 | // Finally, delete the plugin itself
|
121 | 87 | $target = '../plugins/';
|
|
128 | 94 | // ========
|
129 | 95 |
|
130 | 96 | if ("update" === $_GET['action']) {
|
131 |
| - |
132 |
| - // Start creating a new chunk for the plugins settings |
133 |
| - $settingsNew = '"plugins" => array('; |
134 |
| - |
135 | 97 | // Redo the arrays using the form data
|
136 |
| - for ($i = 0; $i < count($oldPlugins); $i++) { |
| 98 | + for ($i = 0; $i < count($ICEcoder["plugins"]); $i++) { |
137 | 99 | $timer = intval($_POST['timer' . $i]);
|
138 | 100 | if ($timer == 0) {
|
139 | 101 | $timer = "";
|
140 | 102 | }
|
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 | + ]; |
150 | 111 | }
|
151 |
| - // Rtrim off the last comma |
152 |
| - $settingsNew = rtrim($settingsNew, ','); |
153 |
| - $settingsNew .= ' ),' . PHP_EOL; |
154 | 112 | }
|
155 | 113 |
|
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 |
| - |
168 | 114 | // 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'])) { |
173 | 116 | // Finally, reload ICEcoder itself if plugin requires it or just the iFrame screen for the user if it doesn't
|
174 | 117 | if ("install" === $_GET['action'] && "true" === $pluginsData[$_GET['plugin']]['reload']) {
|
175 | 118 | 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