-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin_config.php
More file actions
215 lines (163 loc) · 6.16 KB
/
Copy pathadmin_config.php
File metadata and controls
215 lines (163 loc) · 6.16 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
require_once('../../class2.php');
if (!getperms('P')) {
e107::redirect('admin');
exit;
}
require_once(e_ADMIN . 'auth.php');
if (!function_exists('jsonplug_lower')) {
function jsonplug_lower($str) {
$str = trim((string)$str);
return function_exists('mb_strtolower') ? mb_strtolower($str) : strtolower($str);
}
}
// =====================================
// Caricamento lingua admin
// =====================================
$candidates = array();
if (defined('e_LANGUAGE')) {
$candidates[] = e_LANGUAGE;
$candidates[] = ucfirst(strtolower(e_LANGUAGE));
}
$candidates[] = 'English';
$candidates = array_unique($candidates);
foreach ($candidates as $candidate) {
$langFile = e_PLUGIN . 'jsonplug/languages/' . $candidate . '.php';
if (is_readable($langFile)) {
$lan = include($langFile);
if (is_array($lan)) {
foreach ($lan as $key => $value) {
if (!defined($key)) {
define($key, $value);
}
}
}
break;
}
}
// =====================================
// Oggetti e107
// =====================================
$ns = e107::getRender();
$frm = e107::getForm();
$mes = e107::getMessage();
$db = e107::getDb();
$lanTitle = defined('LAN_JSONLD_TITLE') ? LAN_JSONLD_TITLE : 'JSON-LD Schema Manager';
$lanLabel = defined('LAN_JSONLD_LABEL') ? LAN_JSONLD_LABEL : 'Codice Schema JSON-LD';
$lanHelp = defined('LAN_JSONLD_HELP') ? LAN_JSONLD_HELP : 'Inserisci solo il codice JSON-LD, senza tag <script>.';
$lanSave = defined('LAN_JSONLD_SAVE') ? LAN_JSONLD_SAVE : 'Salva';
$lanSuccess = defined('LAN_JSONLD_SUCCESS') ? LAN_JSONLD_SUCCESS : 'Impostazioni salvate con successo.';
// =====================================
// Recupero lingue installate
// =====================================
$languages = array();
if (method_exists(e107::getLanguage(), 'installed')) {
$tmp = e107::getLanguage()->installed();
if (is_array($tmp)) {
foreach ($tmp as $lng) {
if (is_string($lng) && trim($lng) !== '') {
$languages[] = trim($lng);
}
}
}
}
if (empty($languages)) {
$languages = array('English');
}
// =====================================
// Salvataggio dati
// =====================================
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_jsonld'])) {
$posted = isset($_POST['jsonld_data']) && is_array($_POST['jsonld_data']) ? $_POST['jsonld_data'] : array();
$saved = 0;
foreach ($languages as $lng) {
if (!array_key_exists($lng, $posted)) {
continue;
}
$content = (string)$posted[$lng];
$lngEscaped = $db->escape($lng);
$contentEscaped = $db->escape($content);
$exists = $db->retrieve('jsonplug', 'jsonld_id', "jsonld_lang = '{$lngEscaped}'");
if ($exists) {
$result = $db->update(
'jsonplug',
"jsonld_data = '{$contentEscaped}' WHERE jsonld_lang = '{$lngEscaped}'"
);
} else {
$result = $db->insert('jsonplug', array(
'jsonld_lang' => $lng,
'jsonld_data' => $content
));
}
if ($result !== false) {
$saved++;
}
}
if ($saved > 0) {
$mes->addSuccess($lanSuccess);
} else {
$mes->addInfo('Nessuna lingua salvata.');
}
}
// =====================================
// Recupero dati esistenti
// =====================================
$currentData = array();
$lowerData = array();
$rows = $db->retrieve('jsonplug', '*', '', true);
if (!empty($rows) && is_array($rows)) {
foreach ($rows as $row) {
if (isset($row['jsonld_lang'])) {
$currentData[$row['jsonld_lang']] = $row['jsonld_data'];
$lowerData[jsonplug_lower($row['jsonld_lang'])] = $row['jsonld_data'];
}
}
}
// =====================================
// Interfaccia admin
// =====================================
$formAction = defined('e_REQUEST_URI') ? e_REQUEST_URI : $_SERVER['REQUEST_URI'];
$text = $mes->render();
$text .= $frm->open('jsonld_form', 'post', $formAction);
$text .= '<ul class="nav nav-tabs" style="margin-bottom: 20px;">';
foreach ($languages as $index => $lng) {
$activeClass = ($index === 0) ? ' class="active"' : '';
$tabId = 'lang-' . md5($lng);
$text .= '<li' . $activeClass . '>';
$text .= '<a href="#' . $tabId . '" data-toggle="tab">' . htmlspecialchars($lng, ENT_QUOTES, 'UTF-8') . '</a>';
$text .= '</li>';
}
$text .= '</ul>';
$text .= '<div class="tab-content">';
foreach ($languages as $index => $lng) {
$activePane = ($index === 0) ? ' active in' : '';
$tabId = 'lang-' . md5($lng);
$textareaId = 'jsonld_data_' . md5($lng);
$fieldName = 'jsonld_data[' . htmlspecialchars($lng, ENT_QUOTES, 'UTF-8') . ']';
$val = '';
if (isset($currentData[$lng])) {
$val = $currentData[$lng];
} elseif (isset($lowerData[jsonplug_lower($lng)])) {
$val = $lowerData[jsonplug_lower($lng)];
}
$text .= '<div class="tab-pane fade' . $activePane . '" id="' . $tabId . '" style="padding: 15px; border: 1px solid #ddd; border-top: none; background: #f9f9f9;">';
$text .= '<div class="form-group">';
$text .= '<label for="' . $textareaId . '" style="font-weight:bold; margin-bottom: 10px; display:block;">';
$text .= htmlspecialchars($lanLabel . ' - ' . $lng, ENT_QUOTES, 'UTF-8');
$text .= '</label>';
$text .= '<textarea id="' . $textareaId . '" name="' . $fieldName . '" rows="12" cols="80" style="width: 100%; max-height: 300px; font-family: monospace; resize: vertical;" class="form-control">';
$text .= htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
$text .= '</textarea>';
$text .= '<small class="help-block" style="margin-top:5px; display:block;">';
$text .= htmlspecialchars($lanHelp, ENT_QUOTES, 'UTF-8');
$text .= '</small>';
$text .= '</div>';
$text .= '</div>';
}
$text .= '</div>';
$text .= '<br>';
$text .= $frm->button('save_jsonld', $lanSave, 'submit', array('class' => 'btn btn-primary'));
$text .= $frm->close();
$ns->tablerender($lanTitle, $text);
require_once(e_ADMIN . 'footer.php');
exit;