-
Notifications
You must be signed in to change notification settings - Fork 1
/
keywordmgr.php
266 lines (194 loc) · 8.75 KB
/
keywordmgr.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2016 Coppermine Dev Team
v1.0 originally written by Gregory Demar
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3
as published by the Free Software Foundation.
********************************************
Coppermine version: 1.6.03
$HeadURL$
**********************************************/
define('IN_COPPERMINE', true);
define('KEYWORDMGR_PHP', true);
define('SEARCH_PHP', true);
require('include/init.inc.php');
//Die if not admin_mode
if (!GALLERY_ADMIN_MODE) {
cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
}
$icon_array['ok'] = cpg_fetch_icon('ok', 1);
list($timestamp, $form_token) = getFormToken();
pageheader($lang_keywordmgr_php['title']);
echo '<form name="keywordForm" id="cpgform" action="keywordmgr.php?page=changeword" method="post">';
starttable("100%", cpg_fetch_icon('keyword_mgr', 2) . $lang_keywordmgr_php['title'], 3);
echo <<<EOT
<tr>
<td class="tablef"><strong>{$lang_common['edit']}</strong></td>
<td class="tablef"><strong>{$lang_common['delete']}</strong></td>
<td class="tablef"><strong>{$lang_keywordmgr_php['search']}</strong></td>
</tr>
EOT;
$page = ''; // initialize
if ($superCage->get->keyExists('page')) {
$page = $superCage->get->getAlpha('page');
} elseif ($superCage->post->keyExists('page')) {
$page = $superCage->post->getAlpha('page');
}
$keysep = $CONFIG['keyword_separator'];
switch ($page) {
default:
case 'display':
$result = cpg_db_query("SELECT keywords FROM {$CONFIG['TABLE_PICTURES']}");
if (!$result->numRows()) {
cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
}
$edit_icon = cpg_fetch_icon('edit', 2);
$delete_icon = cpg_fetch_icon('delete', 2);
$search_icon = cpg_fetch_icon('search', 2);
// Find unique keywords
$total_array = array();
$lowercase_word_array = array();
$i = 0;
while (list($keywords) = $result->fetchRow()) {
$array = explode($keysep, html_entity_decode($keywords));
foreach ($array as $word) {
if ($word == '.' || $word == '' || $word == ' ' || $word == $keysep ) {
continue;
}
$word_escaped = htmlspecialchars($word);
$word_param = urlencode($word);
$word_label = addslashes($word_escaped);
$lowercase_word = addslashes(utf_strtolower($word_escaped));
$confirm_delete = sprintf($lang_keywordmgr_php['confirm_delete'], '"' . $word_label . '"');
$title = sprintf($lang_keywordmgr_php['keyword_del'], '"' . $word_escaped . '"');
$search_link = sprintf($lang_keywordmgr_php['keyword_test_search'], '"' . $word_escaped . '"');
$word = <<<EOT
<tr>
<td class="tableb">
<input type="radio" class="radio" name="keywordEdit" value="$lowercase_word" onclick="document.keywordForm.newword.value='$word_label'" id="keyword{$i}" />
<label for="keyword{$i}" class="clickable_option" title="{$lang_common['edit']} "{$word_escaped}"">
$edit_icon $word_escaped
</label>
</td>
<td class="tableb">
<a href="keywordmgr.php?page=delete&remove=$word_param&form_token={$form_token}&timestamp={$timestamp}" onclick="return confirm('$confirm_delete')" title="$title">
$delete_icon $word_escaped
</a>
</td>
<td class="tableb">
<a href="thumbnails.php?album=search&keywords=on&search=$word_param" target="_blank">
$search_icon $search_link
</a>
</td>
</tr>
EOT;
if (!in_array($lowercase_word, $lowercase_word_array)) {
$total_array[] = $word;
$lowercase_word_array[] = $lowercase_word;
}
$i++;
}
}
$result->free();
sort($total_array);
echo implode("\n", $total_array);
unset($total_array);
echo <<< EOT
<tr>
<td colspan="5" class="tablef" align="center">
<input type="text" name="newword" />
<button type="submit" class="button" name="keyword_submit" value="{$lang_keywordmgr_php['change_keyword']}">{$icon_array['ok']}{$lang_keywordmgr_php['change_keyword']}</button>
</td>
</tr>
EOT;
break;
case 'changeword':
//Check if the form token is valid
if(!checkFormToken()){
cpg_die(ERROR, $lang_errors['invalid_form_token'], __FILE__, __LINE__);
}
if ($superCage->get->keyExists('keywordEdit')) {
$request_keywordEdit = $superCage->get->getEscaped('keywordEdit');
} elseif ($superCage->post->keyExists('keywordEdit')) {
$request_keywordEdit = $superCage->post->getEscaped('keywordEdit');
}
if ($superCage->get->keyExists('newword')) {
$request_newword = $superCage->get->getEscaped('newword');
} elseif ($superCage->post->keyExists('newword')) {
$request_newword = $superCage->post->getEscaped('newword');
}
if ($request_keywordEdit && $request_newword) {
$keywordEdit = $request_keywordEdit;
$query = "SELECT pid, keywords FROM {$CONFIG['TABLE_PICTURES']} WHERE CONCAT('$keysep', `keywords`, '$keysep') LIKE '%{$keysep}{$keywordEdit}{$keysep}%'";
$result = cpg_db_query($query);
while (list($id, $keywords) = $result->fetchRow()) {
$array_new = array();
$array_old = explode($keysep, trim(html_entity_decode($keywords)));
foreach ($array_old as $word) {
// convert old to new if it's the same word
if (utf_strtolower(Inspekt::getEscaped($word)) == utf_strtolower($keywordEdit)) {
$word = html_entity_decode($request_newword);
} elseif (utf_strtolower(addslashes(Inspekt::getEscaped($word))) == utf_strtolower($keywordEdit)) { // needed to detect previously added keywords with spare slashes
$word = html_entity_decode($request_newword);
}
// rebuild array to reprocess it
$array_new[] = Inspekt::getEscaped(trim($word));
}
$keywords = implode($keysep, $array_new);
$newquerys[] = "UPDATE {$CONFIG['TABLE_PICTURES']} SET keywords = '$keywords' WHERE pid = $id";
}
$result->free();
}
$newquerys[] = "UPDATE {$CONFIG['TABLE_PICTURES']} SET keywords = TRIM(REPLACE(keywords, '{$keysep}{$keysep}', '{$keysep}'))";
$newquerys[] = "UPDATE {$CONFIG['TABLE_PICTURES']} SET keywords = '' WHERE keywords = '{$keysep}'";
foreach ($newquerys as $query) {
$result = cpg_db_query($query);
}
header("Location: keywordmgr.php?page=display");
break;
case 'delete':
//Check if the form token is valid
if(!checkFormToken()){
cpg_die(ERROR, $lang_errors['invalid_form_token'], __FILE__, __LINE__);
}
if ($superCage->get->keyExists('remove')) {
$remove = $superCage->get->getEscaped('remove');
} elseif ($superCage->post->keyExists('remove')) {
$remove = $superCage->post->getEscaped('remove');
}
$query = "SELECT pid, keywords FROM {$CONFIG['TABLE_PICTURES']} WHERE CONCAT('$keysep', keywords, '$keysep') LIKE '%{$keysep}{$remove}{$keysep}%'";
$result = cpg_db_query($query);
while (list($id, $keywords) = $result->fetchRow()) {
$array_new = array();
$array_old = explode($keysep, trim(html_entity_decode($keywords)));
foreach ($array_old as $word) {
// convert old to new if it's the same word
if (utf_strtolower(Inspekt::getEscaped($word)) == utf_strtolower($remove)) {
$word = '';
}
// rebuild array to reprocess it
$array_new[] = Inspekt::getEscaped(trim($word));
}
$keywords = implode($keysep, $array_new);
$newquerys[] = "UPDATE {$CONFIG['TABLE_PICTURES']} SET keywords = '$keywords' WHERE pid = $id";
}
$result->free();
$newquerys[] = "UPDATE {$CONFIG['TABLE_PICTURES']} SET keywords = TRIM(REPLACE(keywords, '{$keysep}{$keysep}', '{$keysep}'))";
$newquerys[] = "UPDATE {$CONFIG['TABLE_PICTURES']} SET keywords = '' WHERE keywords = '{$keysep}'";
foreach ($newquerys as $query) {
$result = cpg_db_query($query);
}
header("Location: keywordmgr.php?page=display");
break;
}
endtable();
echo "<input type=\"hidden\" name=\"form_token\" value=\"{$form_token}\" />
<input type=\"hidden\" name=\"timestamp\" value=\"{$timestamp}\" /></form>";
if ($CONFIG['clickable_keyword_search'] != 0) {
include('include/keyword.inc.php');
}
pagefooter();
//EOF