This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugins.php
184 lines (172 loc) · 5 KB
/
plugins.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
if (!defined('IN_W2W'))
{
exit;
}
// Initial var setup
$plugins = $json_a = $plugintemplates = $update_plugin = array();
$configcontents = $plugin_installed = '';
$action = (isset($_GET['action'])) ? $_GET['action'] : '';
$name = (isset($_GET['name'])) ? $_GET['name'] : '';
// get active plugins
if ($active_plugins = @file_get_contents("plugins/active.json"))
{
$json_a = $json_b = json_decode($active_plugins, true);
}
foreach( glob("plugins/*.php") as $plugins_detected)
{
require_once($plugins_detected);
$plugin = str_replace(array('plugins/', '.php'), '', $plugins_detected);
$plugin_installed = array_key_exists($plugin, $json_a) ? '<a href="?mode=plugins&name=' . $plugin . '&action=uninstall">' . $lang['PLUGIN_UNINSTALL'] . '</a>' : '<a href="?mode=plugins&name=' . $plugin . '&action=install">' . $lang['PLUGIN_INSTALL'] . '</a>';
$plugins[] .= ${$plugin . '_name'} . ' ' . ${$plugin . '_version'} . ' ( ' . $plugin_installed . ' )';
}
if ($submit)
{
foreach ($_POST as $config_key => $config_val)
{
if ($config_key == 'submit')
{
continue;
}
if ($config_key == 'name')
{
continue;
}
$update_plugin[$_POST['name']]['config'][$config_key] = $config_val;
}
$update_plugin[$_POST['name']]['config']['active'] = true;
$update_json = array_replace($json_a, $update_plugin);
$fp = fopen('plugins/active.json', 'w');
fwrite($fp, json_encode($update_json));
fclose($fp);
$redirect_url = "index.php?mode=plugins";
meta_refresh(3, $redirect_url);
msg_handler(sprintf($_POST['name'], $lang['PLUGIN_SETTINGS_UPDATED']), 'SUCCESS', 'success');
}
foreach ($json_b as $key => $value)
{
// If plugin config only has 1 value, we expect it to be the active key, therefor unset it for the settings page
if (count($json_b[$key]['config']) === 1)
{
unset($json_b[$key]);
continue;
}
if (count($json_b) === 0)
{
break;
}
foreach ($json_a[$key]['config'] as $subkey => $subvalue)
{
$list = new template();
$list->set_template();
$list->set_filename('list_plugins_row.html');
if ($subkey == 'active')
{
continue;
}
// Check for password fields
$keywords = array('pass', 'passwd', 'password');
$type = 'text';
foreach($keywords as $keyword)
{
if (strpos($subkey , $keyword) !== false)
{
$type = 'password';
}
}
$l_explain = (isset($lang[strtoupper($subkey) . '_EXPLAIN'])) ? $lang[strtoupper($subkey) . '_EXPLAIN'] : '';
$list->assign_vars(array(
'ID' => $key,
'KEY' => $subkey,
'TYPE' => $type,
'TITLE' => (isset($lang[strtoupper($subkey)])) ? $lang[strtoupper($subkey)] : ucfirst(strtolower($subkey)),
'TITLE_EXPLAIN' => $l_explain,
'CONTENT' => $subvalue,
)
);
$plugintemplates[] = $list;
}
}
$plugincontents = template::merge($plugintemplates);
foreach ($json_b as $plugin_filename => $values)
{
foreach ($plugintemplates as $cat)
{
if ($cat->values['ID'] != $plugin_filename)
{
continue 2;
}
}
$configlist = new template();
$configlist->set_template();
$configlist->set_filename('list_plugins.html');
$configlist->assign_vars(array(
'HEADER' => (isset($lang[strtoupper($plugin_filename)])) ? $lang[strtoupper($plugin_filename)] : ucfirst(strtolower($plugin_filename)),
'NAME' => $plugin_filename,
'CONTENT' => $plugincontents
));
$configtemplates[] = $configlist;
}
if (!empty($configtemplates))
{
$configcontents = template::merge($configtemplates);
}
if ($action == 'install')
{
if (array_key_exists($name, $json_a))
{
$msg_title = 'Error';
$redirect_url = "index.php?mode=plugins";
meta_refresh(3, $redirect_url);
msg_handler($lang['PLUGIN_INSTALL_EXIST'], 'ERROR', 'danger');
}
else
{
include_once ("plugins/" . $name . ".php");
$json_a[$name]['config'] = ${$name}['config'];
$fp = fopen('plugins/active.json', 'w');
fwrite($fp, json_encode($json_a));
fclose($fp);
$redirect_url = "index.php?mode=plugins";
meta_refresh(3, $redirect_url);
msg_handler(sprintf($lang['PLUGIN_INSTALL_SUCCESS'], $name), 'SUCCESS', 'success');
}
}
if ($action == 'uninstall')
{
if (!isset($json_a[$name]))
{
$redirect_url = "index.php?mode=plugins";
meta_refresh(3, $redirect_url);
msg_handler(sprintf($lang['PLUGIN_UNINSTALL_FAILED'], $name), 'ERROR', 'danger');
}
else
{
unset($json_a[$name]);
$fp = fopen('plugins/active.json', 'w');
fwrite($fp, json_encode($json_a));
fclose($fp);
$redirect_url = "index.php?mode=plugins";
meta_refresh(3, $redirect_url);
msg_handler(sprintf($lang['PLUGIN_UNINSTALL_SUCCESS'], $name), 'SUCCESS', 'success');
}
}
/**
* Loads our layout template, settings its title and content.
*/
$pluginlist = new template();
$pluginlist->set_template();
$pluginlist->set_filename('plugins_body.html');
$pluginlist->assign_vars(array(
'LIST' => (sizeof($plugins)) ? '<strong>' . implode('<br />', $plugins) . '</strong>' : '',
'CONTENT' => $configcontents
));
$template->assign_vars(array(
'CONTENT' => $pluginlist->output(),
));
/**
* Finally we can output our final page.
*/
page_header($lang['INDEX'] . ' - ' . $lang['PLUGINS']);
$template->set_filename('index_body.html');
page_footer();