|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @author Erwan NADER (ErnadoO) [email protected] |
|
5
|
|
|
* @package acp |
|
6
|
|
|
* @version $Id$ |
|
7
|
|
|
* @copyright (c) 2008 http://www.phpbb-services.com |
|
8
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @ignore |
|
14
|
|
|
*/ |
|
15
|
|
|
if (!defined('IN_PHPBB')) |
|
16
|
|
|
{ |
|
17
|
|
|
exit; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @package acp |
|
22
|
|
|
*/ |
|
23
|
|
|
class acp_directory |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
var $u_action; |
|
26
|
|
|
var $new_config; |
|
27
|
|
|
var $parent_id = 0; |
|
28
|
|
|
|
|
29
|
|
|
function main($id, $mode) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
global $db, $user, $auth, $template, $cache, $phpbb_seo; |
|
32
|
|
|
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; |
|
33
|
|
|
|
|
34
|
|
|
$action = request_var('action', ''); |
|
35
|
|
|
$start = request_var('start', 0); |
|
|
|
|
|
|
36
|
|
|
$submit = (isset($_POST['submit'])) ? true : false; |
|
37
|
|
|
$update = (isset($_POST['update'])) ? true : false; |
|
38
|
|
|
$cat_id = request_var('c', 0); |
|
39
|
|
|
$link_id = request_var('u', 0); |
|
40
|
|
|
|
|
41
|
|
|
$form_key = 'acp_dir_cat'; |
|
42
|
|
|
add_form_key($form_key); |
|
43
|
|
|
|
|
44
|
|
|
$this->parent_id = request_var('parent_id', 0); |
|
45
|
|
|
$cat_data = $errors = array(); |
|
46
|
|
|
if ($update && !check_form_key($form_key)) |
|
47
|
|
|
{ |
|
48
|
|
|
$update = false; |
|
49
|
|
|
$errors[] = $user->lang['FORM_INVALID']; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
switch($mode) |
|
53
|
|
|
{ |
|
54
|
|
|
case 'main': |
|
55
|
|
|
$this->page_title = 'ACP_DIRECTORY'; |
|
|
|
|
|
|
56
|
|
|
$this->tpl_name = 'acp_dir_main'; |
|
|
|
|
|
|
57
|
|
|
$user->add_lang('install'); |
|
58
|
|
|
|
|
59
|
|
|
if ($action) |
|
60
|
|
|
{ |
|
61
|
|
|
if (!confirm_box(true)) |
|
62
|
|
|
{ |
|
63
|
|
|
switch ($action) |
|
64
|
|
|
{ |
|
65
|
|
|
case 'votes': |
|
66
|
|
|
$confirm = true; |
|
67
|
|
|
$confirm_lang = 'DIR_RESET_VOTES_CONFIRM'; |
|
68
|
|
|
break; |
|
69
|
|
|
|
|
70
|
|
|
case 'comments': |
|
71
|
|
|
$confirm = true; |
|
72
|
|
|
$confirm_lang = 'DIR_RESET_COMMENTS_CONFIRM'; |
|
73
|
|
|
break; |
|
74
|
|
|
|
|
75
|
|
|
case 'clicks': |
|
76
|
|
|
$confirm = true; |
|
77
|
|
|
$confirm_lang = 'DIR_RESET_CLICKS_CONFIRM'; |
|
78
|
|
|
break; |
|
79
|
|
|
|
|
80
|
|
|
case 'orphans': |
|
81
|
|
|
$confirm = true; |
|
82
|
|
|
$confirm_lang = 'DIR_DELETE_ORPHANS'; |
|
83
|
|
|
break; |
|
84
|
|
|
|
|
85
|
|
|
default: |
|
86
|
|
|
$confirm = true; |
|
87
|
|
|
$confirm_lang = 'CONFIRM_OPERATION'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if ($confirm) |
|
91
|
|
|
{ |
|
92
|
|
|
confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array( |
|
93
|
|
|
'i' => $id, |
|
94
|
|
|
'mode' => $mode, |
|
95
|
|
|
'action' => $action, |
|
96
|
|
|
))); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
else |
|
100
|
|
|
{ |
|
101
|
|
|
switch ($action) |
|
102
|
|
|
{ |
|
103
|
|
View Code Duplication |
case 'votes': |
|
|
|
|
|
|
104
|
|
|
switch ($db->sql_layer) |
|
105
|
|
|
{ |
|
106
|
|
|
case 'sqlite': |
|
107
|
|
|
case 'firebird': |
|
108
|
|
|
$db->sql_query('DELETE FROM ' . DIR_VOTE_TABLE); |
|
109
|
|
|
break; |
|
110
|
|
|
|
|
111
|
|
|
default: |
|
112
|
|
|
$db->sql_query('TRUNCATE TABLE ' . DIR_VOTE_TABLE); |
|
113
|
|
|
break; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET |
|
117
|
|
|
link_vote = 0, |
|
118
|
|
|
link_note = 0'; |
|
119
|
|
|
$db->sql_query($sql); |
|
120
|
|
|
break; |
|
121
|
|
|
|
|
122
|
|
View Code Duplication |
case 'comments': |
|
|
|
|
|
|
123
|
|
|
switch ($db->sql_layer) |
|
124
|
|
|
{ |
|
125
|
|
|
case 'sqlite': |
|
126
|
|
|
case 'firebird': |
|
127
|
|
|
$db->sql_query('DELETE FROM ' . DIR_COMMENT_TABLE); |
|
128
|
|
|
break; |
|
129
|
|
|
|
|
130
|
|
|
default: |
|
131
|
|
|
$db->sql_query('TRUNCATE TABLE ' . DIR_COMMENT_TABLE); |
|
132
|
|
|
break; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET |
|
136
|
|
|
link_comment = 0'; |
|
137
|
|
|
$db->sql_query($sql); |
|
138
|
|
|
break; |
|
139
|
|
|
|
|
140
|
|
|
case 'clicks': |
|
141
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET |
|
142
|
|
|
link_view = 0'; |
|
143
|
|
|
$db->sql_query($sql); |
|
144
|
|
|
break; |
|
145
|
|
|
|
|
146
|
|
|
case 'orphans': |
|
147
|
|
|
orphan_files(true); |
|
148
|
|
|
break; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
// Get current and latest version |
|
154
|
|
|
$errstr = ''; |
|
155
|
|
|
$errno = 0; |
|
156
|
|
|
|
|
157
|
|
|
$info = get_remote_file('www.phpbb-services.com', '/updatecheck', 'annuaire.txt', $errstr, $errno); |
|
158
|
|
|
|
|
159
|
|
|
if ($info === false) |
|
160
|
|
|
{ |
|
161
|
|
|
trigger_error('VERSIONCHECK_FAIL', E_USER_WARNING); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
$info = explode("\n", $info); |
|
165
|
|
|
$latest_version = trim($info[0]); |
|
166
|
|
|
$announce = trim($info[1]); |
|
167
|
|
|
$announce = (strpos($announce, '&') === false) ? str_replace('&', '&', $announce) : $announce; |
|
168
|
|
|
$download_link = trim($info[2]); |
|
169
|
|
|
$download_link = (strpos($download_link, '&') === false) ? str_replace('&', '&', $download_link) : $download_link; |
|
170
|
|
|
|
|
171
|
|
|
$up_to_date = (version_compare(str_replace('rc', 'RC', strtolower($config['dir_version'])), str_replace('rc', 'RC', strtolower($latest_version)), '<')) ? false : true; |
|
172
|
|
|
|
|
173
|
|
|
// Count number of categories |
|
174
|
|
|
$sql = 'SELECT COUNT(cat_id) AS nb_cats |
|
175
|
|
|
FROM ' . DIR_CAT_TABLE; |
|
176
|
|
|
$result = $db->sql_query($sql); |
|
177
|
|
|
$total_cats = (int) $db->sql_fetchfield('nb_cats'); |
|
178
|
|
|
$db->sql_freeresult($result); |
|
179
|
|
|
|
|
180
|
|
|
// Cont number of links |
|
181
|
|
|
$sql = 'SELECT link_id, link_active |
|
182
|
|
|
FROM ' . DIR_LINK_TABLE; |
|
183
|
|
|
$result = $db->sql_query($sql); |
|
184
|
|
|
$total_links = $waiting_links = 0; |
|
185
|
|
|
while($row = $db->sql_fetchrow($result)) |
|
186
|
|
|
{ |
|
187
|
|
|
$total_links++; |
|
188
|
|
|
if (!$row['link_active']) |
|
189
|
|
|
{ |
|
190
|
|
|
$waiting_links++; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
$db->sql_freeresult($result); |
|
194
|
|
|
|
|
195
|
|
|
// Comments number calculating |
|
196
|
|
|
$sql = 'SELECT COUNT(comment_id) AS nb_comments |
|
197
|
|
|
FROM ' . DIR_COMMENT_TABLE; |
|
198
|
|
|
$result = $db->sql_query($sql); |
|
199
|
|
|
$total_comments = (int) $db->sql_fetchfield('nb_comments'); |
|
200
|
|
|
$db->sql_freeresult($result); |
|
201
|
|
|
|
|
202
|
|
|
// Votes number calculating |
|
203
|
|
|
$sql = 'SELECT COUNT(vote_id) AS nb_votes |
|
204
|
|
|
FROM ' . DIR_VOTE_TABLE; |
|
205
|
|
|
$result = $db->sql_query($sql); |
|
206
|
|
|
$total_votes = (int) $db->sql_fetchfield('nb_votes'); |
|
207
|
|
|
$db->sql_freeresult($result); |
|
208
|
|
|
|
|
209
|
|
|
// Click number calculating |
|
210
|
|
|
$sql = 'SELECT SUM(link_view) AS nb_clicks |
|
211
|
|
|
FROM ' . DIR_LINK_TABLE; |
|
212
|
|
|
$result = $db->sql_query($sql); |
|
213
|
|
|
$total_clicks = (int) $db->sql_fetchfield('nb_clicks'); |
|
214
|
|
|
$db->sql_freeresult($result); |
|
215
|
|
|
|
|
216
|
|
|
$banners_dir_size = 0; |
|
217
|
|
|
|
|
218
|
|
|
if ($banners_dir = @opendir($phpbb_root_path . 'images/directory/banners/')) |
|
219
|
|
|
{ |
|
220
|
|
|
while (($file = readdir($banners_dir)) !== false) |
|
221
|
|
|
{ |
|
222
|
|
|
if ($file[0] != '.' && $file[0] != '..' && strpos($file, 'index.') === false && strpos($file, '.db') === false) |
|
223
|
|
|
{ |
|
224
|
|
|
$banners_dir_size += filesize($phpbb_root_path . 'images/directory/banners/' . $file); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
closedir($banners_dir); |
|
228
|
|
|
|
|
229
|
|
|
$banners_dir_size = get_formatted_filesize($banners_dir_size); |
|
230
|
|
|
} |
|
231
|
|
|
else |
|
232
|
|
|
{ |
|
233
|
|
|
// Couldn't open banners dir. |
|
234
|
|
|
$banners_dir_size = $user->lang['NOT_AVAILABLE']; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
$total_orphan = orphan_files(); |
|
238
|
|
|
|
|
239
|
|
|
$template->assign_vars(array( |
|
240
|
|
|
'S_UP_TO_DATE' => $up_to_date, |
|
241
|
|
|
'S_VERSION_CHECK' => true, |
|
242
|
|
|
'U_ACTION' => $this->u_action, |
|
243
|
|
|
|
|
244
|
|
|
'LATEST_VERSION' => $latest_version, |
|
245
|
|
|
'CURRENT_VERSION' => $config['dir_version'], |
|
246
|
|
|
'U_ANNOUNCE' => $announce, |
|
247
|
|
|
'U_DOWNLOAD' => $download_link, |
|
248
|
|
|
|
|
249
|
|
|
'TOTAL_CATS' => $total_cats, |
|
250
|
|
|
'TOTAL_LINKS' => $total_links-$waiting_links, |
|
251
|
|
|
'WAITING_LINKS' => $waiting_links, |
|
252
|
|
|
'TOTAL_COMMENTS' => $total_comments, |
|
253
|
|
|
'TOTAL_VOTES' => $total_votes, |
|
254
|
|
|
'TOTAL_CLICKS' => $total_clicks, |
|
255
|
|
|
'TOTAL_ORPHANS' => $total_orphan, |
|
256
|
|
|
'BANNERS_DIR_SIZE' => $banners_dir_size, |
|
257
|
|
|
)); |
|
258
|
|
|
break; |
|
259
|
|
|
|
|
260
|
|
|
case 'settings': |
|
261
|
|
|
$display_vars = array( |
|
262
|
|
|
'title' => 'ACP_DIRECTORY_SETTINGS', |
|
263
|
|
|
'vars' => array( |
|
264
|
|
|
'legend1' => 'DIR_PARAM', |
|
265
|
|
|
|
|
266
|
|
|
'dir_banner_width' => '', |
|
267
|
|
|
'dir_banner_height' => '', |
|
268
|
|
|
|
|
269
|
|
|
'dir_mail' => array('lang' => 'DIR_MAIL_VALIDATION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), |
|
270
|
|
|
'dir_activ_checkurl' => array('lang' => 'DIR_ACTIVE_CHECK', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
271
|
|
|
'dir_activ_flag' => array('lang' => 'DIR_ACTIV_FLAG', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), |
|
272
|
|
|
'dir_activ_rss' => array('lang' => 'DIR_ACTIV_RSS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
273
|
|
|
'dir_activ_pagerank' => array('lang' => 'DIR_ACTIV_PAGERANK', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
274
|
|
|
'dir_show' => array('lang' => 'DIR_SHOW', 'validate' => 'int:1', 'type' => 'text:3:3', 'explain' => false), |
|
275
|
|
|
'dir_length_describe' => array('lang' => 'DIR_MAX_DESC', 'validate' => 'int:1', 'type' => 'text:3:3', 'explain' => false), |
|
276
|
|
|
'dir_new_time' => array('lang' => 'DIR_NEW_TIME', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), |
|
277
|
|
|
'dir_default_order' => array('lang' => 'DIR_DEFAULT_ORDER', 'validate' => 'string', 'type' => 'select', 'explain' => true, 'method' => 'get_order_list', 'params' => array('{CONFIG_VALUE}')), |
|
278
|
|
|
|
|
279
|
|
|
'legend2' => 'DIR_RECENT_GUEST', |
|
280
|
|
|
'dir_recent_block' => array('lang' => 'DIR_RECENT_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
281
|
|
|
'dir_recent_rows' => array('lang' => 'DIR_RECENT_ROWS', 'validate' => 'int:1', 'type' => 'text:3:3', 'explain' => false), |
|
282
|
|
|
'dir_recent_columns' => array('lang' => 'DIR_RECENT_COLUMNS', 'validate' => 'int:1', 'type' => 'text:3:3', 'explain' => false), |
|
283
|
|
|
'dir_recent_exclude' => array('lang' => 'DIR_RECENT_EXCLUDE', 'validate' => 'string', 'type' => 'text:6:99', 'explain' => true), |
|
284
|
|
|
|
|
285
|
|
|
'legend3' => 'DIR_ADD_GUEST', |
|
286
|
|
|
'dir_visual_confirm' => array('lang' => 'DIR_VISUAL_CONFIRM', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
287
|
|
|
'dir_visual_confirm_max_attempts' => array('lang' => 'DIR_MAX_ADD_ATTEMPTS', 'validate' => 'int:1:10', 'type' => 'text:3:3', 'explain' => true), |
|
288
|
|
|
|
|
289
|
|
|
'legend4' => 'DIR_THUMB_PARAM', |
|
290
|
|
|
'dir_activ_thumb' => array('lang' => 'DIR_ACTIVE_THUMB', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), |
|
291
|
|
|
'dir_activ_thumb_remote' => array('lang' => 'DIR_ACTIVE_THUMB_REMOTE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
292
|
|
|
'dir_thumb_service' => array('lang' => 'DIR_THUMB_SERVICE', 'validate' => 'string', 'type' => 'select', 'explain' => true, 'method' => 'get_thumb_service_list', 'params' => array('{CONFIG_VALUE}')), |
|
293
|
|
|
'dir_thumb_service_reverse' => array('lang' => 'DIR_THUMB_SERVICE_REVERSE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
294
|
|
|
|
|
295
|
|
|
'legend5' => 'DIR_COMM_PARAM', |
|
296
|
|
|
'dir_allow_bbcode' => array('lang' => 'DIR_ALLOW_BBCODE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), |
|
297
|
|
|
'dir_allow_links' => array('lang' => 'DIR_ALLOW_LINKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), |
|
298
|
|
|
'dir_allow_smilies' => array('lang' => 'DIR_ALLOW_SMILIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), |
|
299
|
|
|
'dir_length_comments' => array('lang' => 'DIR_LENGTH_COMMENTS', 'validate' => 'int:2', 'type' => 'text:3:3', 'explain' => true), |
|
300
|
|
|
'dir_comments_per_page' => array('lang' => 'DIR_COMM_PER_PAGE', 'validate' => 'int:1', 'type' => 'text:3:3', 'explain' => false), |
|
301
|
|
|
|
|
302
|
|
|
'legend6' => 'DIR_BANN_PARAM', |
|
303
|
|
|
'dir_activ_banner' => array('lang' => 'DIR_ACTIV_BANNER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), |
|
304
|
|
|
'dir_banner' => array('lang' => 'DIR_MAX_BANN', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), |
|
305
|
|
|
'dir_banner_filesize' => array('lang' => 'DIR_MAX_SIZE', 'validate' => 'int:0', 'type' => 'text:5:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), |
|
306
|
|
|
'dir_storage_banner' => array('lang' => 'DIR_STORAGE_BANNER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
307
|
|
|
) |
|
308
|
|
|
); |
|
309
|
|
|
|
|
310
|
|
|
// phpbb_seo installed |
|
311
|
|
|
if (!empty($phpbb_seo)) |
|
312
|
|
|
{ |
|
313
|
|
|
// Rewrite enable, and patch installed |
|
314
|
|
|
if($phpbb_seo->cache_config['settings']['url_rewrite'] && method_exists($phpbb_seo,'directory')) |
|
315
|
|
|
{ |
|
316
|
|
|
$display_vars['vars'] += array( |
|
317
|
|
|
'legend7' => 'DIR_REWRITE_PARAM', |
|
318
|
|
|
'dir_activ_rewrite' => array('lang' => 'DIR_ACTIV_REWRITE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
|
319
|
|
|
//'dir_urlR' => array('lang' => 'DIR_RELATIVE_PATH', 'validate' => 'string', 'type' => 'text:10:99', 'explain' => true, 'append' => '/'), |
|
|
|
|
|
|
320
|
|
|
); |
|
321
|
|
|
} |
|
322
|
|
|
} |
|
323
|
|
|
$display_vars['vars'] += array( |
|
324
|
|
|
'legend8' => 'ACP_SUBMIT_CHANGES', |
|
325
|
|
|
); |
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
|
|
if (isset($display_vars['lang'])) |
|
329
|
|
|
{ |
|
330
|
|
|
$user->add_lang($display_vars['lang']); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
$this->new_config = $config; |
|
334
|
|
|
$cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; |
|
335
|
|
|
$error = array(); |
|
336
|
|
|
|
|
337
|
|
|
// We validate the complete config if whished |
|
338
|
|
|
validate_config_vars($display_vars['vars'], $cfg_array, $error); |
|
339
|
|
|
|
|
340
|
|
|
// Do not write values if there is an error |
|
341
|
|
|
if (sizeof($error)) |
|
342
|
|
|
{ |
|
343
|
|
|
$submit = false; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... |
|
347
|
|
|
foreach ($display_vars['vars'] as $config_name => $null) |
|
348
|
|
|
{ |
|
349
|
|
|
|
|
350
|
|
|
if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) |
|
351
|
|
|
{ |
|
352
|
|
|
continue; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
$this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; |
|
356
|
|
|
|
|
357
|
|
|
if ($submit) |
|
358
|
|
|
{ |
|
359
|
|
|
set_config($config_name, $config_value); |
|
360
|
|
|
} |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
View Code Duplication |
if ($submit) |
|
|
|
|
|
|
364
|
|
|
{ |
|
365
|
|
|
add_log('admin', 'DIR_CONFIG_' . strtoupper($mode)); |
|
366
|
|
|
|
|
367
|
|
|
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
$this->tpl_name = 'acp_board'; |
|
371
|
|
|
$this->page_title = $display_vars['title']; |
|
372
|
|
|
|
|
373
|
|
|
$template->assign_vars(array( |
|
374
|
|
|
'L_TITLE' => $user->lang[$display_vars['title']], |
|
375
|
|
|
'L_TITLE_EXPLAIN' => $user->lang[$display_vars['title'] . '_EXPLAIN'], |
|
376
|
|
|
|
|
377
|
|
|
'S_ERROR' => (sizeof($error)) ? true : false, |
|
378
|
|
|
'ERROR_MSG' => implode('<br />', $error), |
|
379
|
|
|
|
|
380
|
|
|
'U_ACTION' => $this->u_action) |
|
381
|
|
|
); |
|
382
|
|
|
|
|
383
|
|
|
// Output relevant page |
|
384
|
|
|
foreach ($display_vars['vars'] as $config_key => $vars) |
|
385
|
|
|
{ |
|
386
|
|
|
if (!is_array($vars) && strpos($config_key, 'legend') === false) |
|
387
|
|
|
{ |
|
388
|
|
|
continue; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
if (strpos($config_key, 'legend') !== false) |
|
392
|
|
|
{ |
|
393
|
|
|
$template->assign_block_vars('options', array( |
|
394
|
|
|
'S_LEGEND' => true, |
|
395
|
|
|
'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars) |
|
396
|
|
|
); |
|
397
|
|
|
|
|
398
|
|
|
continue; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
$type = explode(':', $vars['type']); |
|
402
|
|
|
|
|
403
|
|
|
$l_explain = ''; |
|
404
|
|
|
if ($vars['explain'] && isset($vars['lang_explain'])) |
|
405
|
|
|
{ |
|
406
|
|
|
$l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain']; |
|
407
|
|
|
} |
|
408
|
|
|
else if ($vars['explain']) |
|
409
|
|
|
{ |
|
410
|
|
|
$l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
$template->assign_block_vars('options', array( |
|
414
|
|
|
'KEY' => $config_key, |
|
415
|
|
|
'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'], |
|
416
|
|
|
'S_EXPLAIN' => $vars['explain'], |
|
417
|
|
|
'TITLE_EXPLAIN' => $l_explain, |
|
418
|
|
|
'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars), |
|
419
|
|
|
)); |
|
420
|
|
|
|
|
421
|
|
|
unset($display_vars['vars'][$config_key]); |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
break; |
|
425
|
|
|
|
|
426
|
|
|
case 'cat': |
|
|
|
|
|
|
427
|
|
|
|
|
428
|
|
|
// Major routines |
|
429
|
|
|
if ($update) |
|
430
|
|
|
{ |
|
431
|
|
|
switch ($action) |
|
432
|
|
|
{ |
|
433
|
|
|
case 'delete': |
|
434
|
|
|
$action_subcats = request_var('action_subcats', ''); |
|
435
|
|
|
$subcats_to_id = request_var('subcats_to_id', 0); |
|
436
|
|
|
$action_links = request_var('action_links', ''); |
|
437
|
|
|
$links_to_id = request_var('links_to_id', 0); |
|
438
|
|
|
|
|
439
|
|
|
$errors = $this->delete_cat($cat_id, $action_links, $action_subcats, $links_to_id, $subcats_to_id); |
|
440
|
|
|
|
|
441
|
|
|
if (sizeof($errors)) |
|
442
|
|
|
{ |
|
443
|
|
|
break; |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
$cache->destroy('sql', DIR_CAT_TABLE); |
|
447
|
|
|
|
|
448
|
|
|
trigger_error($user->lang['DIR_CAT_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); |
|
449
|
|
|
|
|
450
|
|
|
break; |
|
451
|
|
|
|
|
452
|
|
|
case 'edit': |
|
453
|
|
|
$cat_data = array( |
|
454
|
|
|
'cat_id' => $cat_id |
|
455
|
|
|
); |
|
456
|
|
|
// No break here |
|
457
|
|
|
case 'add': |
|
|
|
|
|
|
458
|
|
|
|
|
459
|
|
|
$cat_data += array( |
|
460
|
|
|
'parent_id' => request_var('cat_parent_id', (int)$this->parent_id), |
|
461
|
|
|
'cat_parents' => '', |
|
462
|
|
|
'cat_name' => utf8_normalize_nfc(request_var('cat_name', '', true)), |
|
463
|
|
|
'cat_desc' => utf8_normalize_nfc(request_var('cat_desc', '', true)), |
|
464
|
|
|
'cat_desc_uid' => '', |
|
465
|
|
|
'cat_desc_options' => 7, |
|
466
|
|
|
'cat_desc_bitfield' => '', |
|
467
|
|
|
'cat_icon' => request_var('cat_icon', ''), |
|
468
|
|
|
'display_subcat_list' => request_var('display_on_index', false), |
|
469
|
|
|
'cat_allow_comments' => request_var('allow_comments', 1), |
|
470
|
|
|
'cat_allow_votes' => request_var('allow_votes', 1), |
|
471
|
|
|
'cat_must_describe' => request_var('must_describe', 1), |
|
472
|
|
|
'cat_count_all' => request_var('count_all', 0), |
|
473
|
|
|
'cat_validate' => request_var('validate', 0), |
|
474
|
|
|
'cat_link_back' => request_var('link_back', 0), |
|
475
|
|
|
'cat_cron_enable' => request_var('cron_enable', 0), |
|
476
|
|
|
'cat_cron_freq' => request_var('cron_every', 7), |
|
477
|
|
|
//'cat_cron_next' => request_var('cat_cron_next', time()+604800), |
|
|
|
|
|
|
478
|
|
|
'cat_cron_nb_check' => request_var('nb_check', 1), |
|
479
|
|
|
); |
|
480
|
|
|
|
|
481
|
|
|
// Get data for cat description if specified |
|
482
|
|
|
if ($cat_data['cat_desc']) |
|
483
|
|
|
{ |
|
484
|
|
|
generate_text_for_storage($cat_data['cat_desc'], $cat_data['cat_desc_uid'], $cat_data['cat_desc_bitfield'], $cat_data['cat_desc_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false)); |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
$errors = $this->update_cat_data($cat_data); |
|
488
|
|
|
|
|
489
|
|
|
if (!sizeof($errors)) |
|
490
|
|
|
{ |
|
491
|
|
|
$cache->destroy('sql', DIR_CAT_TABLE); |
|
492
|
|
|
|
|
493
|
|
|
$message = ($action == 'add') ? $user->lang['DIR_CAT_CREATED'] : $user->lang['DIR_CAT_UPDATED']; |
|
494
|
|
|
|
|
495
|
|
|
trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); |
|
496
|
|
|
} |
|
497
|
|
|
break; |
|
498
|
|
|
} |
|
499
|
|
|
} |
|
500
|
|
|
$this->page_title = 'ACP_DIRECTORY'; |
|
501
|
|
|
$this->tpl_name = 'acp_dir_cat'; |
|
502
|
|
|
|
|
503
|
|
|
switch ($action) |
|
504
|
|
|
{ |
|
505
|
|
|
case 'progress_bar': |
|
506
|
|
|
$start = request_var('start', 0); |
|
507
|
|
|
$total = request_var('total', 0); |
|
508
|
|
|
|
|
509
|
|
|
$this->display_progress_bar($start, $total); |
|
510
|
|
|
break; |
|
511
|
|
|
|
|
512
|
|
|
case 'sync': |
|
|
|
|
|
|
513
|
|
|
|
|
514
|
|
View Code Duplication |
if (!$cat_id) |
|
|
|
|
|
|
515
|
|
|
{ |
|
516
|
|
|
trigger_error($user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
@set_time_limit(0); |
|
520
|
|
|
|
|
521
|
|
|
$sql = 'SELECT cat_name, cat_links |
|
522
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
523
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
524
|
|
|
$result = $db->sql_query($sql); |
|
525
|
|
|
$row = $db->sql_fetchrow($result); |
|
526
|
|
|
$db->sql_freeresult($result); |
|
527
|
|
|
|
|
528
|
|
View Code Duplication |
if (!$row) |
|
|
|
|
|
|
529
|
|
|
{ |
|
530
|
|
|
trigger_error($user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
|
if ($row['cat_links']) |
|
534
|
|
|
{ |
|
535
|
|
|
$sql = 'SELECT MIN(link_id) as min_link_id, MAX(link_id) as max_link_id |
|
536
|
|
|
FROM ' . DIR_LINK_TABLE . ' |
|
537
|
|
|
WHERE link_cat = ' . (int)$cat_id . ' |
|
538
|
|
|
AND link_active = 1'; |
|
539
|
|
|
$result = $db->sql_query($sql); |
|
540
|
|
|
$row2 = $db->sql_fetchrow($result); |
|
541
|
|
|
$db->sql_freeresult($result); |
|
542
|
|
|
|
|
543
|
|
|
// Typecast to int if there is no data available |
|
544
|
|
|
$row2['min_link_id'] = (int) $row2['min_link_id']; |
|
545
|
|
|
$row2['max_link_id'] = (int) $row2['max_link_id']; |
|
546
|
|
|
|
|
547
|
|
|
$start = request_var('start', $row2['min_link_id']); |
|
548
|
|
|
|
|
549
|
|
|
$batch_size = 200; |
|
550
|
|
|
$end = $start + $batch_size; |
|
551
|
|
|
|
|
552
|
|
|
// Sync all topics in batch mode... |
|
553
|
|
|
sync_dir_links($start, $end); |
|
554
|
|
|
|
|
555
|
|
|
if ($end < $row2['max_link_id']) |
|
556
|
|
|
{ |
|
557
|
|
|
// We really need to find a way of showing statistics... no progress here |
|
558
|
|
|
$sql = 'SELECT COUNT(link_id) as num_links |
|
559
|
|
|
FROM ' . DIR_LINK_TABLE . ' |
|
560
|
|
|
WHERE link_cat = ' . (int)$cat_id . ' |
|
561
|
|
|
AND link_active = 1 |
|
562
|
|
|
AND link_id BETWEEN ' . $start . ' AND ' . $end; |
|
563
|
|
|
$result = $db->sql_query($sql); |
|
564
|
|
|
$links_done = request_var('links_done', 0) + (int) $db->sql_fetchfield('num_links'); |
|
565
|
|
|
$db->sql_freeresult($result); |
|
566
|
|
|
|
|
567
|
|
|
$start += $batch_size; |
|
568
|
|
|
|
|
569
|
|
|
$url = $this->u_action . "&parent_id={$this->parent_id}&c=$cat_id&action=sync&start=$start&links_done=$links_done&total={$row['cat_links']}"; |
|
|
|
|
|
|
570
|
|
|
|
|
571
|
|
|
meta_refresh(0, $url); |
|
572
|
|
|
|
|
573
|
|
|
$template->assign_vars(array( |
|
574
|
|
|
'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$links_done&total={$row['cat_links']}", |
|
|
|
|
|
|
575
|
|
|
'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$links_done&total={$row['cat_links']}"), |
|
|
|
|
|
|
576
|
|
|
'S_CONTINUE_SYNC' => true, |
|
577
|
|
|
'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $links_done, $row['cat_links'])) |
|
578
|
|
|
); |
|
579
|
|
|
|
|
580
|
|
|
return; |
|
581
|
|
|
} |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
$url = $this->u_action . "&parent_id={$this->parent_id}&c=$cat_id&action=sync_cat"; |
|
|
|
|
|
|
585
|
|
|
meta_refresh(0, $url); |
|
586
|
|
|
|
|
587
|
|
|
$template->assign_vars(array( |
|
588
|
|
|
'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar', |
|
589
|
|
|
'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), |
|
590
|
|
|
'S_CONTINUE_SYNC' => true, |
|
591
|
|
|
'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['cat_links'])) |
|
592
|
|
|
); |
|
593
|
|
|
|
|
594
|
|
|
return; |
|
595
|
|
|
break; |
|
|
|
|
|
|
596
|
|
|
|
|
597
|
|
|
case 'sync_cat': |
|
|
|
|
|
|
598
|
|
|
|
|
599
|
|
|
$sql = 'SELECT cat_name |
|
600
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
601
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
602
|
|
|
$result = $db->sql_query($sql); |
|
603
|
|
|
$row = $db->sql_fetchrow($result); |
|
604
|
|
|
$db->sql_freeresult($result); |
|
605
|
|
|
|
|
606
|
|
View Code Duplication |
if (!$row) |
|
|
|
|
|
|
607
|
|
|
{ |
|
608
|
|
|
trigger_error($user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
sync_dir_cat($cat_id); |
|
612
|
|
|
|
|
613
|
|
|
add_log('admin', 'LOG_DIR_CAT_SYNC', $row['cat_name']); |
|
614
|
|
|
$cache->destroy('sql', DIR_CAT_TABLE); |
|
615
|
|
|
|
|
616
|
|
|
$template->assign_var('L_DIR_CAT_RESYNCED', sprintf($user->lang['DIR_CAT_RESYNCED'], $row['cat_name'])); |
|
617
|
|
|
|
|
618
|
|
|
break; |
|
619
|
|
|
|
|
620
|
|
|
case 'move_up': |
|
621
|
|
|
case 'move_down': |
|
|
|
|
|
|
622
|
|
|
|
|
623
|
|
View Code Duplication |
if (!$cat_id) |
|
|
|
|
|
|
624
|
|
|
{ |
|
625
|
|
|
trigger_error($user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
|
626
|
|
|
} |
|
627
|
|
|
|
|
628
|
|
|
$sql = 'SELECT cat_id, cat_name, parent_id, left_id, right_id |
|
629
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
630
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
631
|
|
|
$result = $db->sql_query($sql); |
|
632
|
|
|
$row = $db->sql_fetchrow($result); |
|
633
|
|
|
$db->sql_freeresult($result); |
|
634
|
|
|
|
|
635
|
|
View Code Duplication |
if (!$row) |
|
|
|
|
|
|
636
|
|
|
{ |
|
637
|
|
|
trigger_error($user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
$move_cat_name = $this->move_cat_by($row, $action, 1); |
|
641
|
|
|
|
|
642
|
|
|
if ($move_cat_name !== false) |
|
643
|
|
|
{ |
|
644
|
|
|
add_log('admin', 'LOG_DIR_CAT_' . strtoupper($action), $row['cat_name'], $move_cat_name); |
|
645
|
|
|
$cache->destroy('sql', DIR_CAT_TABLE); |
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
|
|
break; |
|
649
|
|
|
|
|
650
|
|
|
case 'add': |
|
651
|
|
|
case 'edit': |
|
|
|
|
|
|
652
|
|
|
|
|
653
|
|
|
// Show form to create/modify a categorie |
|
654
|
|
|
if ($action == 'edit') |
|
655
|
|
|
{ |
|
656
|
|
|
$this->page_title = 'DIR_EDIT_CAT'; |
|
657
|
|
|
$row = $this->get_cat_info($cat_id); |
|
658
|
|
|
|
|
659
|
|
|
if (!$update) |
|
660
|
|
|
{ |
|
661
|
|
|
$cat_data = $row; |
|
662
|
|
|
} |
|
663
|
|
|
else |
|
664
|
|
|
{ |
|
665
|
|
|
$cat_data['left_id'] = $row['left_id']; |
|
666
|
|
|
$cat_data['right_id'] = $row['right_id']; |
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
// Make sure no direct child categories are able to be selected as parents. |
|
670
|
|
|
$exclude_cats = array(); |
|
671
|
|
|
foreach (get_dir_cat_branch($cat_id, 'children') as $row2) |
|
672
|
|
|
{ |
|
673
|
|
|
$exclude_cats[] = $row2['cat_id']; |
|
674
|
|
|
} |
|
675
|
|
|
$parents_list = make_cat_select($cat_data['parent_id'], $exclude_cats); |
|
|
|
|
|
|
676
|
|
|
} |
|
677
|
|
|
else |
|
678
|
|
|
{ |
|
679
|
|
|
$this->page_title = 'DIR_CREATE_CAT'; |
|
680
|
|
|
|
|
681
|
|
|
$cat_id = $this->parent_id; |
|
682
|
|
|
$parents_list = make_cat_select($this->parent_id); |
|
683
|
|
|
|
|
684
|
|
|
// Fill categorie data with default values |
|
685
|
|
|
if (!$update) |
|
686
|
|
|
{ |
|
687
|
|
|
$cat_data = array( |
|
688
|
|
|
'parent_id' => $this->parent_id, |
|
689
|
|
|
'cat_name' => utf8_normalize_nfc(request_var('cat_name', '', true)), |
|
690
|
|
|
'cat_desc' => '', |
|
691
|
|
|
'cat_icon' => '', |
|
692
|
|
|
'cat_allow_comments' => true, |
|
693
|
|
|
'cat_allow_votes' => true, |
|
694
|
|
|
'cat_must_describe' => true, |
|
695
|
|
|
'cat_count_all' => false, |
|
696
|
|
|
'cat_validate' => false, |
|
697
|
|
|
'enable_icons' => false, |
|
698
|
|
|
|
|
699
|
|
|
'display_subcat_list' => true, |
|
700
|
|
|
|
|
701
|
|
|
'cat_link_back' => false, |
|
702
|
|
|
'cat_cron_enable' => false, |
|
703
|
|
|
'cat_cron_freq' => 7, |
|
704
|
|
|
'cat_cron_nb_check' => 1, |
|
705
|
|
|
); |
|
706
|
|
|
} |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
$dir_cat_desc_data = array( |
|
710
|
|
|
'text' => $cat_data['cat_desc'], |
|
711
|
|
|
'allow_bbcode' => true, |
|
712
|
|
|
'allow_smilies' => true, |
|
713
|
|
|
'allow_urls' => true |
|
714
|
|
|
); |
|
715
|
|
|
|
|
716
|
|
|
// Parse desciption if specified |
|
717
|
|
|
if ($cat_data['cat_desc']) |
|
718
|
|
|
{ |
|
719
|
|
|
if (!isset($cat_data['cat_desc_uid'])) |
|
720
|
|
|
{ |
|
721
|
|
|
// Before we are able to display the preview and plane text, we need to parse our request_var()'d value... |
|
722
|
|
|
$cat_data['cat_desc_uid'] = ''; |
|
723
|
|
|
$cat_data['cat_desc_bitfield'] = ''; |
|
724
|
|
|
$cat_data['cat_desc_options'] = 0; |
|
725
|
|
|
|
|
726
|
|
|
generate_text_for_storage($cat_data['cat_desc'], $cat_data['cat_desc_uid'], $cat_data['cat_desc_bitfield'], $cat_data['cat_desc_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false)); |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
// decode... |
|
730
|
|
|
$dir_cat_desc_data = generate_text_for_edit($cat_data['cat_desc'], $cat_data['cat_desc_uid'], $cat_data['cat_desc_options']); |
|
731
|
|
|
} |
|
732
|
|
|
|
|
733
|
|
|
$sql = 'SELECT cat_id |
|
734
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
735
|
|
|
WHERE cat_id <> ' . (int)$cat_id; |
|
736
|
|
|
$result = $db->sql_query_limit($sql, 1); |
|
737
|
|
|
|
|
738
|
|
|
if ($db->sql_fetchrow($result)) |
|
739
|
|
|
{ |
|
740
|
|
|
$template->assign_vars(array( |
|
741
|
|
|
'S_MOVE_DIR_CAT_OPTIONS' => make_cat_select($cat_data['parent_id'], $cat_id)) |
|
742
|
|
|
); |
|
743
|
|
|
} |
|
744
|
|
|
$db->sql_freeresult($result); |
|
745
|
|
|
|
|
746
|
|
|
$template->assign_vars(array( |
|
747
|
|
|
'S_EDIT_CAT' => true, |
|
748
|
|
|
'S_ERROR' => (sizeof($errors)) ? true : false, |
|
749
|
|
|
'S_CAT_PARENT_ID' => $cat_data['parent_id'], |
|
750
|
|
|
'S_ADD_ACTION' => ($action == 'add') ? true : false, |
|
751
|
|
|
|
|
752
|
|
|
'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id, |
|
753
|
|
|
'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action=$action&c=$cat_id", |
|
|
|
|
|
|
754
|
|
|
|
|
755
|
|
|
'L_TITLE' => $user->lang[$this->page_title], |
|
756
|
|
|
'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '', |
|
757
|
|
|
'ICON_IMAGE' => ($cat_data['cat_icon']) ? $phpbb_root_path . 'images/directory/icons/' . $cat_data['cat_icon'] : $phpbb_admin_path . 'images/spacer.gif', |
|
758
|
|
|
|
|
759
|
|
|
'DIR_ICON_PATH' => $phpbb_root_path . 'images/directory/icons', |
|
760
|
|
|
'DIR_CAT_NAME' => $cat_data['cat_name'], |
|
761
|
|
|
'DIR_CAT_DESC' => $dir_cat_desc_data['text'], |
|
762
|
|
|
|
|
763
|
|
|
'S_DESC_BBCODE_CHECKED' => ($dir_cat_desc_data['allow_bbcode']) ? true : false, |
|
764
|
|
|
'S_DESC_SMILIES_CHECKED' => ($dir_cat_desc_data['allow_smilies']) ? true : false, |
|
765
|
|
|
'S_DESC_URLS_CHECKED' => ($dir_cat_desc_data['allow_urls']) ? true : false, |
|
766
|
|
|
'S_DISPLAY_SUBCAT_LIST' => ($cat_data['display_subcat_list']) ? true : false, |
|
767
|
|
|
'S_PARENT_OPTIONS' => $parents_list, |
|
768
|
|
|
'S_ICON_OPTIONS' => get_dir_icon_list($cat_data['cat_icon']), |
|
769
|
|
|
'S_ALLOW_COMMENTS' => ($cat_data['cat_allow_comments']) ? true : false, |
|
770
|
|
|
'S_ALLOW_VOTES' => ($cat_data['cat_allow_votes']) ? true : false, |
|
771
|
|
|
'S_MUST_DESCRIBE' => ($cat_data['cat_must_describe']) ? true : false, |
|
772
|
|
|
'S_COUNT_ALL' => ($cat_data['cat_count_all']) ? true : false, |
|
773
|
|
|
'S_VALIDATE' => ($cat_data['cat_validate']) ? true : false, |
|
774
|
|
|
|
|
775
|
|
|
'DIR_CRON_EVERY' => $cat_data['cat_cron_freq'], |
|
776
|
|
|
'DIR_NEXT_CRON_ACTION' => !empty($cat_data['cat_cron_next']) ? $user->format_date($cat_data['cat_cron_next']) : '-', |
|
777
|
|
|
'DIR_CRON_NB_CHECK' => $cat_data['cat_cron_nb_check'], |
|
778
|
|
|
|
|
779
|
|
|
'S_LINK_BACK' => ($cat_data['cat_link_back']) ? true : false, |
|
780
|
|
|
'S_CRON_ENABLE' => ($cat_data['cat_cron_enable']) ? true : false, |
|
781
|
|
|
|
|
782
|
|
|
// In acp, append_sid() always adds SID in url, so we can use "&" delimiter in the javascript function in template for timestamp parametre |
|
783
|
|
|
'U_DATE' => append_sid($phpbb_root_path.'directory.'.$phpEx) |
|
784
|
|
|
)); |
|
785
|
|
|
|
|
786
|
|
|
return; |
|
787
|
|
|
|
|
788
|
|
|
case 'delete': |
|
|
|
|
|
|
789
|
|
|
|
|
790
|
|
View Code Duplication |
if (!$cat_id) |
|
|
|
|
|
|
791
|
|
|
{ |
|
792
|
|
|
trigger_error($user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
|
793
|
|
|
} |
|
794
|
|
|
|
|
795
|
|
|
$cat_data = $this->get_cat_info($cat_id); |
|
796
|
|
|
|
|
797
|
|
|
$subcats_id = array(); |
|
798
|
|
|
$subcats = get_dir_cat_branch($cat_id, 'children'); |
|
799
|
|
|
|
|
800
|
|
|
foreach ($subcats as $row) |
|
801
|
|
|
{ |
|
802
|
|
|
$subcats_id[] = $row['cat_id']; |
|
803
|
|
|
} |
|
804
|
|
|
|
|
805
|
|
|
$cat_list = make_cat_select($cat_data['parent_id'], $subcats_id); |
|
|
|
|
|
|
806
|
|
|
|
|
807
|
|
|
$sql = 'SELECT cat_id |
|
808
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
809
|
|
|
WHERE cat_id <> ' . (int)$cat_id; |
|
810
|
|
|
$result = $db->sql_query_limit($sql, 1); |
|
811
|
|
|
|
|
812
|
|
|
if ($db->sql_fetchrow($result)) |
|
813
|
|
|
{ |
|
814
|
|
|
$template->assign_vars(array( |
|
815
|
|
|
'S_MOVE_DIR_CAT_OPTIONS' => make_cat_select($cat_data['parent_id'], $subcats_id)) // , false, true, false??? |
|
|
|
|
|
|
816
|
|
|
); |
|
817
|
|
|
} |
|
818
|
|
|
$db->sql_freeresult($result); |
|
819
|
|
|
|
|
820
|
|
|
$parent_id = ($this->parent_id == $cat_id) ? 0 : $this->parent_id; |
|
821
|
|
|
|
|
822
|
|
|
$template->assign_vars(array( |
|
823
|
|
|
'S_DELETE_DIR_CAT' => true, |
|
824
|
|
|
'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&c=$cat_id", |
|
|
|
|
|
|
825
|
|
|
'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id, |
|
826
|
|
|
|
|
827
|
|
|
'DIR_CAT_NAME' => $cat_data['cat_name'], |
|
828
|
|
|
'S_HAS_SUBCATS' => ($cat_data['right_id'] - $cat_data['left_id'] > 1) ? true : false, |
|
829
|
|
|
'S_CATS_LIST' => $cat_list, |
|
830
|
|
|
'S_ERROR' => (sizeof($errors)) ? true : false, |
|
831
|
|
|
'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '') |
|
832
|
|
|
); |
|
833
|
|
|
|
|
834
|
|
|
return; |
|
835
|
|
|
break; |
|
|
|
|
|
|
836
|
|
|
} |
|
837
|
|
|
|
|
838
|
|
|
// Default management page |
|
839
|
|
|
if (!$this->parent_id) |
|
840
|
|
|
{ |
|
841
|
|
|
$navigation = $user->lang['DIR_INDEX']; |
|
842
|
|
|
} |
|
843
|
|
|
else |
|
844
|
|
|
{ |
|
845
|
|
|
$navigation = '<a href="' . $this->u_action . '">' . $user->lang['DIR_INDEX'] . '</a>'; |
|
846
|
|
|
|
|
847
|
|
|
$cats_nav = get_dir_cat_branch($this->parent_id, 'parents', 'descending'); |
|
848
|
|
|
|
|
849
|
|
|
foreach ($cats_nav as $row) |
|
850
|
|
|
{ |
|
851
|
|
|
if ($row['cat_id'] == $this->parent_id) |
|
852
|
|
|
{ |
|
853
|
|
|
$navigation .= ' -> ' . $row['cat_name']; |
|
854
|
|
|
} |
|
855
|
|
|
else |
|
856
|
|
|
{ |
|
857
|
|
|
$navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a>'; |
|
858
|
|
|
} |
|
859
|
|
|
} |
|
860
|
|
|
} |
|
861
|
|
|
|
|
862
|
|
|
// Jumpbox |
|
863
|
|
|
$cat_box = make_cat_select($this->parent_id); |
|
864
|
|
|
|
|
865
|
|
|
if ($action == 'sync' || $action == 'sync_cat') |
|
866
|
|
|
{ |
|
867
|
|
|
$template->assign_var('S_RESYNCED', true); |
|
868
|
|
|
} |
|
869
|
|
|
|
|
870
|
|
|
$sql = 'SELECT cat_id, parent_id, right_id, left_id, cat_name, cat_icon, cat_desc_uid, cat_desc_bitfield, cat_desc, cat_desc_options, cat_links |
|
871
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
872
|
|
|
WHERE parent_id = ' . (int)$this->parent_id . ' |
|
873
|
|
|
ORDER BY left_id'; |
|
874
|
|
|
$result = $db->sql_query($sql); |
|
875
|
|
|
|
|
876
|
|
|
if ($row = $db->sql_fetchrow($result)) |
|
877
|
|
|
{ |
|
878
|
|
|
do |
|
879
|
|
|
{ |
|
880
|
|
|
$folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['DIR_SUBCAT'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />'; |
|
881
|
|
|
|
|
882
|
|
|
$url = $this->u_action . "&parent_id=$this->parent_id&c={$row['cat_id']}"; |
|
|
|
|
|
|
883
|
|
|
|
|
884
|
|
|
$template->assign_block_vars('cats', array( |
|
885
|
|
|
'FOLDER_IMAGE' => $folder_image, |
|
886
|
|
|
'CAT_IMAGE' => ($row['cat_icon']) ? '<img src="' . $phpbb_root_path . 'images/directory/icons/' . $row['cat_icon'] . '" alt="" />' : '', |
|
887
|
|
|
'CAT_NAME' => $row['cat_name'], |
|
888
|
|
|
'CAT_DESCRIPTION' => generate_text_for_display($row['cat_desc'], $row['cat_desc_uid'], $row['cat_desc_bitfield'], $row['cat_desc_options']), |
|
889
|
|
|
'CAT_LINKS' => $row['cat_links'], |
|
890
|
|
|
|
|
891
|
|
|
'U_CAT' => $this->u_action . '&parent_id=' . $row['cat_id'], |
|
892
|
|
|
'U_MOVE_UP' => $url . '&action=move_up', |
|
893
|
|
|
'U_MOVE_DOWN' => $url . '&action=move_down', |
|
894
|
|
|
'U_EDIT' => $url . '&action=edit', |
|
895
|
|
|
'U_DELETE' => $url . '&action=delete', |
|
896
|
|
|
'U_SYNC' => $url . '&action=sync') |
|
897
|
|
|
); |
|
898
|
|
|
} |
|
899
|
|
|
while ($row = $db->sql_fetchrow($result)); |
|
900
|
|
|
} |
|
901
|
|
|
else if ($this->parent_id) |
|
902
|
|
|
{ |
|
903
|
|
|
$row = $this->get_cat_info($this->parent_id); |
|
904
|
|
|
|
|
905
|
|
|
$url = $this->u_action . '&parent_id=' . $this->parent_id . '&c=' . $row['cat_id']; |
|
906
|
|
|
|
|
907
|
|
|
$template->assign_vars(array( |
|
908
|
|
|
'S_NO_CATS' => true, |
|
909
|
|
|
|
|
910
|
|
|
'U_EDIT' => $url . '&action=edit', |
|
911
|
|
|
'U_DELETE' => $url . '&action=delete', |
|
912
|
|
|
'U_SYNC' => $url . '&action=sync') |
|
913
|
|
|
); |
|
914
|
|
|
} |
|
915
|
|
|
$db->sql_freeresult($result); |
|
916
|
|
|
|
|
917
|
|
|
$template->assign_vars(array( |
|
918
|
|
|
'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '', |
|
919
|
|
|
'NAVIGATION' => $navigation, |
|
920
|
|
|
'CAT_BOX' => $cat_box, |
|
921
|
|
|
'U_SEL_ACTION' => $this->u_action, |
|
922
|
|
|
'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id, |
|
923
|
|
|
|
|
924
|
|
|
'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar', |
|
925
|
|
|
'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), |
|
926
|
|
|
)); |
|
927
|
|
|
|
|
928
|
|
|
break; |
|
929
|
|
|
|
|
930
|
|
|
case 'val': |
|
931
|
|
|
$this->page_title = 'ACP_DIRECTORY'; |
|
932
|
|
|
$this->tpl_name = 'acp_dir_val'; |
|
933
|
|
|
|
|
934
|
|
|
$mark = (isset($_POST['link_id'])) ? request_var('link_id', array(0)) : array(); |
|
935
|
|
|
$start = request_var('start', 0); |
|
936
|
|
|
$submit = isset($_POST['submit']); |
|
937
|
|
|
|
|
938
|
|
|
$form_key = 'acp_dir_val'; |
|
939
|
|
|
add_form_key($form_key); |
|
940
|
|
|
$subscibed_cat = $loop = $affected_link = array(); |
|
941
|
|
|
|
|
942
|
|
|
if (!class_exists('messenger')) |
|
943
|
|
|
{ |
|
944
|
|
|
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); |
|
945
|
|
|
} |
|
946
|
|
|
$messenger = new messenger(false); |
|
947
|
|
|
|
|
948
|
|
|
if ($submit && sizeof($mark)) |
|
949
|
|
|
{ |
|
950
|
|
View Code Duplication |
if ($action !== 'delete' && !check_form_key($form_key)) |
|
|
|
|
|
|
951
|
|
|
{ |
|
952
|
|
|
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); |
|
953
|
|
|
} |
|
954
|
|
|
|
|
955
|
|
|
$sql_array = array( |
|
956
|
|
|
'SELECT' => 'a.link_id, a.link_name, a.link_url, a.link_description, a.link_banner, a.link_user_id, a.link_guest_email, u.username, u.user_email, u.user_lang, u.user_notify_type, c.cat_name', |
|
957
|
|
|
'FROM' => array( |
|
958
|
|
|
DIR_LINK_TABLE => 'a'), |
|
959
|
|
|
'LEFT_JOIN' => array( |
|
960
|
|
|
array( |
|
961
|
|
|
'FROM' => array(USERS_TABLE => 'u'), |
|
962
|
|
|
'ON' => 'u.user_id = a.link_user_id' |
|
963
|
|
|
), |
|
964
|
|
|
array( |
|
965
|
|
|
'FROM' => array(DIR_CAT_TABLE => 'c'), |
|
966
|
|
|
'ON' => 'a.link_cat = c.cat_id' |
|
967
|
|
|
) |
|
968
|
|
|
), |
|
969
|
|
|
'WHERE' => $db->sql_in_set('a.link_id', $mark)); |
|
970
|
|
|
|
|
971
|
|
|
$sql = $db->sql_build_query('SELECT', $sql_array); |
|
972
|
|
|
$result = $db->sql_query($sql); |
|
973
|
|
|
|
|
974
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
975
|
|
|
{ |
|
976
|
|
|
$link_data[$row['link_id']] = $row; |
|
|
|
|
|
|
977
|
|
|
$affected_link[] = $row['link_name']; |
|
978
|
|
|
$row['link_cat'] = request_var('c'.$row['link_id'], 0); |
|
979
|
|
|
|
|
980
|
|
|
$cat_data[$row['link_cat']] = isset($cat_data[$row['link_cat']]) ? $cat_data[$row['link_cat']] + 1 : 1; |
|
981
|
|
|
|
|
982
|
|
|
if ($action == 'activate') |
|
983
|
|
|
{ |
|
984
|
|
|
// We need to get back the suscribers |
|
985
|
|
|
if (!isset($subscibed_cat[$row['link_cat']])) |
|
986
|
|
|
{ |
|
987
|
|
|
$sql_array = array( |
|
988
|
|
|
'SELECT' => 'u.user_id, u.username, u.user_email, u.user_lang, u.user_jabber, u.user_notify_type', |
|
989
|
|
|
'FROM' => array( |
|
990
|
|
|
DIR_NOTIFICATION_TABLE => 'an'), |
|
991
|
|
|
'LEFT_JOIN' => array( |
|
992
|
|
|
array( |
|
993
|
|
|
'FROM' => array(USERS_TABLE => 'u'), |
|
994
|
|
|
'ON' => 'an.n_user_id = u.user_id' |
|
995
|
|
|
) |
|
996
|
|
|
), |
|
997
|
|
|
'WHERE' => 'an.n_cat_id = ' . (int)$row['link_cat']); |
|
998
|
|
|
$sql = $db->sql_build_query('SELECT', $sql_array); |
|
999
|
|
|
$result2 = $db->sql_query($sql); |
|
1000
|
|
|
|
|
1001
|
|
|
while ($row2 = $db->sql_fetchrow($result2)) |
|
1002
|
|
|
{ |
|
1003
|
|
|
$subscibed_cat[$row['link_cat']][$row2['user_id']] = array( |
|
1004
|
|
|
'username' => $row2['username'], |
|
1005
|
|
|
'user_email' => $row2['user_email'], |
|
1006
|
|
|
'user_lang' => $row2['user_lang'], |
|
1007
|
|
|
'user_jabber' => $row2['user_jabber'] |
|
1008
|
|
|
); |
|
1009
|
|
|
} |
|
1010
|
|
|
$db->sql_freeresult($result2); |
|
1011
|
|
|
} |
|
1012
|
|
|
|
|
1013
|
|
|
if(isset($subscibed_cat[$row['link_cat']])) |
|
1014
|
|
|
{ |
|
1015
|
|
|
$messenger->replyto($config['board_email']); |
|
1016
|
|
|
|
|
1017
|
|
|
$cat_data2 = $subscibed_cat[$row['link_cat']]; |
|
1018
|
|
|
|
|
1019
|
|
|
$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); |
|
1020
|
|
|
$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); |
|
1021
|
|
|
$messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']); |
|
1022
|
|
|
|
|
1023
|
|
|
foreach ($cat_data2 as $user_id => $user_data) |
|
1024
|
|
|
{ |
|
1025
|
|
|
$messenger->template('mods/directory/notification', $user_data['user_lang']); |
|
1026
|
|
|
$messenger->to($user_data['user_email'], $user_data['username']); |
|
1027
|
|
|
$messenger->im($user_data['user_jabber'], $user_data['username']); |
|
1028
|
|
|
|
|
1029
|
|
|
$messenger->assign_vars(array( |
|
1030
|
|
|
'USERNAME' => $user_data['username'], |
|
1031
|
|
|
'CAT_NAME' => strip_tags($row['cat_name']), |
|
1032
|
|
|
'LINK_NAME' => $row['link_name'], |
|
1033
|
|
|
'LINK_URL' => $row['link_url'], |
|
1034
|
|
|
'LINK_DESCRIPTION' => preg_replace('/(\[.*?\])(.*?)(\[\/.*?\])/si', '\\1', $row['link_description']), |
|
1035
|
|
|
)); |
|
1036
|
|
|
|
|
1037
|
|
|
$messenger->send($user_data['user_notify_type']); |
|
1038
|
|
|
} |
|
1039
|
|
|
|
|
1040
|
|
|
} |
|
1041
|
|
|
|
|
1042
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET link_active = 1, link_time = '. time() .', link_cat = '.request_var('c'.$row['link_id'], 0).' |
|
1043
|
|
|
WHERE link_id = ' . (int)$row['link_id']; |
|
1044
|
|
|
$db->sql_query($sql); |
|
1045
|
|
|
} |
|
1046
|
|
View Code Duplication |
elseif($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) |
|
|
|
|
|
|
1047
|
|
|
{ |
|
1048
|
|
|
if (file_exists($phpbb_root_path . 'images/directory/banners' .'/'. basename($row['link_banner']))) |
|
1049
|
|
|
{ |
|
1050
|
|
|
@unlink($phpbb_root_path . 'images/directory/banners' .'/'. basename($row['link_banner'])); |
|
1051
|
|
|
} |
|
1052
|
|
|
} |
|
1053
|
|
|
} |
|
1054
|
|
|
$db->sql_freeresult($result); |
|
1055
|
|
|
|
|
1056
|
|
|
switch ($action) |
|
1057
|
|
|
{ |
|
1058
|
|
|
case 'activate': |
|
|
|
|
|
|
1059
|
|
|
|
|
1060
|
|
|
foreach ($cat_data as $cat_id => $count) |
|
1061
|
|
|
{ |
|
1062
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . ' SET cat_links = cat_links + '.$count.' |
|
1063
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
1064
|
|
|
$db->sql_query($sql); |
|
1065
|
|
|
} |
|
1066
|
|
|
|
|
1067
|
|
|
add_log('admin', 'LOG_LINK_ACTIVE', implode(', ', $affected_link)); |
|
1068
|
|
|
|
|
1069
|
|
|
break; |
|
1070
|
|
|
|
|
1071
|
|
|
case 'delete': |
|
|
|
|
|
|
1072
|
|
|
|
|
1073
|
|
|
if (confirm_box(true)) |
|
1074
|
|
|
{ |
|
1075
|
|
|
foreach ($mark as $link_id) |
|
1076
|
|
|
{ |
|
1077
|
|
|
$sql = 'DELETE FROM ' . DIR_LINK_TABLE . ' WHERE link_id = ' . (int)$link_id; |
|
1078
|
|
|
$db->sql_query($sql); |
|
1079
|
|
|
} |
|
1080
|
|
|
|
|
1081
|
|
|
add_log('admin', 'LOG_LINK_DELETE', implode(', ', $affected_link)); |
|
1082
|
|
|
} |
|
1083
|
|
|
else |
|
1084
|
|
|
{ |
|
1085
|
|
|
$s_hidden_fields = array( |
|
1086
|
|
|
'mode' => $mode, |
|
1087
|
|
|
'action' => $action, |
|
1088
|
|
|
'link_id' => $mark, |
|
1089
|
|
|
'submit' => 1, |
|
1090
|
|
|
'start' => $start, |
|
1091
|
|
|
); |
|
1092
|
|
|
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); |
|
1093
|
|
|
} |
|
1094
|
|
|
break; |
|
1095
|
|
|
} |
|
1096
|
|
|
|
|
1097
|
|
|
$messenger->reset(); |
|
1098
|
|
|
|
|
1099
|
|
|
$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); |
|
1100
|
|
|
$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); |
|
1101
|
|
|
$messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']); |
|
1102
|
|
|
|
|
1103
|
|
|
foreach ($link_data as $id => $row) |
|
|
|
|
|
|
1104
|
|
|
{ |
|
1105
|
|
|
$username = ($row['link_user_id'] == ANONYMOUS) ? $row['link_guest_email'] : $row['username']; |
|
1106
|
|
|
$email = ($row['link_user_id'] == ANONYMOUS) ? $row['link_guest_email'] : $row['user_email']; |
|
1107
|
|
|
|
|
1108
|
|
|
$messenger->template('mods/directory/user_validation', $row['user_lang']); |
|
1109
|
|
|
$messenger->subject($user->lang['EMAIL_SUBJECT_' . strtoupper($action)]); |
|
1110
|
|
|
$messenger->to($email, $username); |
|
1111
|
|
|
|
|
1112
|
|
|
$messenger->assign_vars(array( |
|
1113
|
|
|
'USERNAME' => htmlspecialchars_decode($username), |
|
1114
|
|
|
'TEXT' => sprintf($user->lang['EMAIL_TEXT_' . strtoupper($action)], $row['link_name'], htmlspecialchars_decode($config['sitename']), generate_board_url()) |
|
1115
|
|
|
)); |
|
1116
|
|
|
|
|
1117
|
|
|
$messenger->send($row['user_notify_type']); |
|
1118
|
|
|
} |
|
1119
|
|
|
} |
|
1120
|
|
|
|
|
1121
|
|
|
$sql = 'SELECT COUNT(1) AS total_links |
|
1122
|
|
|
FROM ' . DIR_LINK_TABLE . ' |
|
1123
|
|
|
WHERE link_active = 0'; |
|
1124
|
|
|
$result = $db->sql_query($sql); |
|
|
|
|
|
|
1125
|
|
|
$total_links = (int) $db->sql_fetchfield('total_links'); |
|
1126
|
|
|
|
|
1127
|
|
|
if ($start >= $total_links) |
|
1128
|
|
|
{ |
|
1129
|
|
|
$start = ($start - 10 < 0) ? 0 : $start - 10; |
|
1130
|
|
|
} |
|
1131
|
|
|
|
|
1132
|
|
|
$sql_array = array( |
|
1133
|
|
|
'SELECT' => 'a.link_id, a.link_name, a.link_url, a.link_description, a.link_cat, a.link_user_id, a.link_uid, a.link_bitfield, a.link_flags, a.link_banner, a.link_time, c.cat_name, u.user_id, u.username, u.user_colour', |
|
1134
|
|
|
'FROM' => array( |
|
1135
|
|
|
DIR_LINK_TABLE => 'a'), |
|
1136
|
|
|
'LEFT_JOIN' => array( |
|
1137
|
|
|
array( |
|
1138
|
|
|
'FROM' => array(DIR_CAT_TABLE => 'c'), |
|
1139
|
|
|
'ON' => 'c.cat_id = a.link_cat' |
|
1140
|
|
|
), |
|
1141
|
|
|
array( |
|
1142
|
|
|
'FROM' => array(USERS_TABLE => 'u'), |
|
1143
|
|
|
'ON' => 'u.user_id = a.link_user_id' |
|
1144
|
|
|
) |
|
1145
|
|
|
), |
|
1146
|
|
|
'WHERE' => 'a.link_active = 0', |
|
1147
|
|
|
'ORDER_BY' => 'link_id ASC'); |
|
1148
|
|
|
|
|
1149
|
|
|
$sql = $db->sql_build_query('SELECT', $sql_array); |
|
1150
|
|
|
$result = $db->sql_query_limit($sql, 10, $start); |
|
1151
|
|
|
|
|
1152
|
|
|
$row = array(); |
|
|
|
|
|
|
1153
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
1154
|
|
|
{ |
|
1155
|
|
|
$s_banner = ''; |
|
1156
|
|
|
if (!empty($row['link_banner'])) |
|
1157
|
|
|
{ |
|
1158
|
|
|
if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) |
|
1159
|
|
|
{ |
|
1160
|
|
|
$u_banner = $phpbb_root_path.'images/directory/banners/' . basename($row['link_banner']); |
|
1161
|
|
|
} |
|
1162
|
|
|
else |
|
1163
|
|
|
{ |
|
1164
|
|
|
$u_banner = $row['link_banner']; |
|
1165
|
|
|
} |
|
1166
|
|
|
|
|
1167
|
|
|
list($width, $height) = @getimagesize($u_banner); |
|
1168
|
|
|
|
|
1169
|
|
View Code Duplication |
if (($width > $config['dir_banner_width'] || $height > $config['dir_banner_height']) && $config['dir_banner_width'] > 0 && $config['dir_banner_height'] > 0) |
|
|
|
|
|
|
1170
|
|
|
{ |
|
1171
|
|
|
$coef_w = $width / $config['dir_banner_width']; |
|
1172
|
|
|
$coef_h = $height / $config['dir_banner_height']; |
|
1173
|
|
|
$coef_max = max($coef_w, $coef_h); |
|
1174
|
|
|
$width /= $coef_max; |
|
1175
|
|
|
$height /= $coef_max; |
|
1176
|
|
|
} |
|
1177
|
|
|
|
|
1178
|
|
|
$s_banner = '<img src="' . $u_banner . '" width="' . $width . '" height="' . $height . '" border="0" alt="" />'; |
|
1179
|
|
|
} |
|
1180
|
|
|
|
|
1181
|
|
|
$username = ($row['link_user_id'] == ANONYMOUS) ? $row['link_guest_email'] : $row['username']; |
|
1182
|
|
|
|
|
1183
|
|
|
$link_row = array( |
|
1184
|
|
|
'LINK_URL' => $row['link_url'], |
|
1185
|
|
|
'LINK_NAME' => $row['link_name'], |
|
1186
|
|
|
'LINK_DESC' => generate_text_for_display($row['link_description'], $row['link_uid'], $row['link_bitfield'], $row['link_flags']), |
|
1187
|
|
|
'L_DIR_USER_PROP' => sprintf($user->lang['DIR_USER_PROP'], get_username_string('full', $row['link_user_id'], $username, $row['user_colour']), '<select name=c'.$row['link_id'].'>'.make_cat_select($row['link_cat']).'</select>', $user->format_date($row['link_time'])), |
|
1188
|
|
|
'BANNER' => $s_banner, |
|
1189
|
|
|
'LINK_ID' => $row['link_id'], |
|
1190
|
|
|
|
|
1191
|
|
|
); |
|
1192
|
|
|
$template->assign_block_vars('linkrow', $link_row); |
|
1193
|
|
|
} |
|
1194
|
|
|
$db->sql_freeresult($result); |
|
1195
|
|
|
|
|
1196
|
|
|
$option_ary = array('activate' => 'DIR_LINK_ACTIVATE', 'delete' => 'DIR_LINK_DELETE'); |
|
1197
|
|
|
|
|
1198
|
|
|
$template->assign_vars(array( |
|
1199
|
|
|
'PAGINATION' => generate_pagination($this->u_action . "&i=$id&action=$action&mode=$mode", $total_links, 10, $start), |
|
|
|
|
|
|
1200
|
|
|
'PAGE_NUMBER' => on_page($total_links, 10, $start), |
|
1201
|
|
|
'U_ACTION' => $this->u_action . '&start=' . $start, |
|
1202
|
|
|
'S_LINKS_OPTIONS' => build_select($option_ary), |
|
1203
|
|
|
)); |
|
1204
|
|
|
|
|
1205
|
|
|
break; |
|
1206
|
|
|
} |
|
1207
|
|
|
} |
|
1208
|
|
|
|
|
1209
|
|
|
function get_thumb_service_list($value) |
|
|
|
|
|
|
1210
|
|
|
{ |
|
1211
|
|
|
$thumbshot = array( |
|
1212
|
|
|
'apercite.fr' => 'http://www.apercite.fr/apercite/120x90/oui/oui/', |
|
1213
|
|
|
'thumbshots.org' => 'http://open.thumbshots.org/image.pxf?url=', |
|
1214
|
|
|
'easy-thumb.net' => 'http://www.easy-thumb.net/min.html?url=', |
|
1215
|
|
|
); |
|
1216
|
|
|
|
|
1217
|
|
|
$tpl = ''; |
|
1218
|
|
|
foreach ($thumbshot as $service => $url) |
|
1219
|
|
|
{ |
|
1220
|
|
|
$selected = ($url == $value) ? 'selected="selected"' : ''; |
|
1221
|
|
|
|
|
1222
|
|
|
$tpl .= '<option value="' . $url . '" ' . $selected . '>' . $service . '</option>'; |
|
1223
|
|
|
} |
|
1224
|
|
|
$tpl .= '</select>'; |
|
1225
|
|
|
|
|
1226
|
|
|
return ($tpl); |
|
1227
|
|
|
} |
|
1228
|
|
|
|
|
1229
|
|
|
function get_order_list($value) |
|
|
|
|
|
|
1230
|
|
|
{ |
|
1231
|
|
|
global $user; |
|
1232
|
|
|
|
|
1233
|
|
|
$order_array = array( |
|
1234
|
|
|
'a a', |
|
1235
|
|
|
'a d', |
|
1236
|
|
|
't a', |
|
1237
|
|
|
't d', |
|
1238
|
|
|
'r a', |
|
1239
|
|
|
'r d', |
|
1240
|
|
|
's a', |
|
1241
|
|
|
's d', |
|
1242
|
|
|
'v a', |
|
1243
|
|
|
'v d' |
|
1244
|
|
|
); |
|
1245
|
|
|
$tpl = ''; |
|
1246
|
|
|
foreach ($order_array as $i) |
|
1247
|
|
|
{ |
|
1248
|
|
|
$selected = ($i == $value) ? 'selected="selected"' : ''; |
|
1249
|
|
|
$order_substr = trim(str_replace(' ', '_', $i)); |
|
1250
|
|
|
$tpl .= '<option value="' . $i . '" ' . $selected . '>' . $user->lang['DIR_ORDER_' . strtoupper($order_substr)] . '</option>'; |
|
1251
|
|
|
} |
|
1252
|
|
|
$tpl .= '</select>'; |
|
1253
|
|
|
|
|
1254
|
|
|
return ($tpl); |
|
1255
|
|
|
} |
|
1256
|
|
|
|
|
1257
|
|
|
function get_cat_info($dir_cat_id) |
|
|
|
|
|
|
1258
|
|
|
{ |
|
1259
|
|
|
global $db; |
|
1260
|
|
|
|
|
1261
|
|
|
$sql = 'SELECT cat_id, parent_id, right_id, left_id, cat_desc, cat_desc_uid, cat_desc_options, cat_icon, cat_name, display_subcat_list, cat_allow_comments, cat_allow_votes, cat_must_describe, cat_count_all, cat_validate, cat_cron_freq, cat_cron_nb_check, cat_link_back, cat_cron_enable, cat_cron_next |
|
1262
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1263
|
|
|
WHERE cat_id = ' . (int)$dir_cat_id; |
|
1264
|
|
|
$result = $db->sql_query($sql); |
|
1265
|
|
|
$row = $db->sql_fetchrow($result); |
|
1266
|
|
|
$db->sql_freeresult($result); |
|
1267
|
|
|
|
|
1268
|
|
|
if (!$row) |
|
1269
|
|
|
{ |
|
1270
|
|
|
trigger_error('DIR_ERROR_NO_CATS', E_USER_ERROR); |
|
1271
|
|
|
} |
|
1272
|
|
|
|
|
1273
|
|
|
return $row; |
|
1274
|
|
|
} |
|
1275
|
|
|
|
|
1276
|
|
|
function update_cat_data(&$cat_data) |
|
|
|
|
|
|
1277
|
|
|
{ |
|
1278
|
|
|
global $db, $user, $cache; |
|
1279
|
|
|
|
|
1280
|
|
|
$errors = array(); |
|
1281
|
|
|
|
|
1282
|
|
|
if (!$cat_data['cat_name']) |
|
1283
|
|
|
{ |
|
1284
|
|
|
$errors[] = $user->lang['DIR_CAT_NAME_EMPTY']; |
|
1285
|
|
|
} |
|
1286
|
|
|
|
|
1287
|
|
|
if (utf8_strlen($cat_data['cat_desc']) > 4000) |
|
1288
|
|
|
{ |
|
1289
|
|
|
$errors[] = $user->lang['DIR_CAT_DESC_TOO_LONG']; |
|
1290
|
|
|
} |
|
1291
|
|
|
|
|
1292
|
|
|
if (($cat_data['cat_cron_enable'] && $cat_data['cat_cron_freq'] <= 0) || $cat_data['cat_cron_nb_check'] < 0) |
|
1293
|
|
|
{ |
|
1294
|
|
|
$errors[] = $user->lang['DIR_CAT_DATA_NEGATIVE']; |
|
1295
|
|
|
} |
|
1296
|
|
|
|
|
1297
|
|
|
// Unset data that are not database fields |
|
1298
|
|
|
$cat_data_sql = $cat_data; |
|
1299
|
|
|
|
|
1300
|
|
|
// What are we going to do tonight Brain? The same thing we do everynight, |
|
1301
|
|
|
// try to take over the world ... or decide whether to continue update |
|
1302
|
|
|
// and if so, whether it's a new cat/link or an existing one |
|
1303
|
|
|
if (sizeof($errors)) |
|
1304
|
|
|
{ |
|
1305
|
|
|
return $errors; |
|
1306
|
|
|
} |
|
1307
|
|
|
|
|
1308
|
|
|
if (!$cat_data_sql['cat_link_back']) |
|
1309
|
|
|
{ |
|
1310
|
|
|
$cat_data_sql['cat_cron_enable'] = 0; |
|
1311
|
|
|
} |
|
1312
|
|
|
|
|
1313
|
|
|
if(!$cat_data_sql['cat_cron_enable']) |
|
1314
|
|
|
{ |
|
1315
|
|
|
$cat_data_sql['cat_cron_next'] = 0; |
|
1316
|
|
|
} |
|
1317
|
|
|
|
|
1318
|
|
|
if (!$cat_data_sql['parent_id']) |
|
1319
|
|
|
{ |
|
1320
|
|
|
$cat_data_sql['display_subcat_list'] = 0; |
|
1321
|
|
|
} |
|
1322
|
|
|
|
|
1323
|
|
|
if (!isset($cat_data_sql['cat_id'])) |
|
1324
|
|
|
{ |
|
1325
|
|
|
// no cat_id means we're creating a new categorie |
|
1326
|
|
|
if ($cat_data_sql['parent_id']) |
|
1327
|
|
|
{ |
|
1328
|
|
|
$sql = 'SELECT left_id, right_id |
|
1329
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1330
|
|
|
WHERE cat_id = ' . (int)$cat_data_sql['parent_id']; |
|
1331
|
|
|
$result = $db->sql_query($sql); |
|
1332
|
|
|
$row = $db->sql_fetchrow($result); |
|
1333
|
|
|
$db->sql_freeresult($result); |
|
1334
|
|
|
|
|
1335
|
|
View Code Duplication |
if (!$row) |
|
|
|
|
|
|
1336
|
|
|
{ |
|
1337
|
|
|
trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&' . $this->parent_id), E_USER_WARNING); |
|
1338
|
|
|
} |
|
1339
|
|
|
|
|
1340
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . ' |
|
1341
|
|
|
SET left_id = left_id + 2, right_id = right_id + 2 |
|
1342
|
|
|
WHERE left_id > ' . (int)$row['right_id']; |
|
1343
|
|
|
$db->sql_query($sql); |
|
1344
|
|
|
|
|
1345
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . ' |
|
1346
|
|
|
SET right_id = right_id + 2 |
|
1347
|
|
|
WHERE ' . (int)$row['left_id'] . ' BETWEEN left_id AND right_id'; |
|
1348
|
|
|
$db->sql_query($sql); |
|
1349
|
|
|
|
|
1350
|
|
|
$cat_data_sql['left_id'] = $row['right_id']; |
|
1351
|
|
|
$cat_data_sql['right_id'] = $row['right_id'] + 1; |
|
1352
|
|
|
} |
|
1353
|
|
|
else |
|
1354
|
|
|
{ |
|
1355
|
|
|
$sql = 'SELECT MAX(right_id) AS right_id |
|
1356
|
|
|
FROM ' . DIR_CAT_TABLE; |
|
1357
|
|
|
$result = $db->sql_query($sql); |
|
1358
|
|
|
$row = $db->sql_fetchrow($result); |
|
1359
|
|
|
$db->sql_freeresult($result); |
|
1360
|
|
|
|
|
1361
|
|
|
$cat_data_sql['left_id'] = $row['right_id'] + 1; |
|
1362
|
|
|
$cat_data_sql['right_id'] = $row['right_id'] + 2; |
|
1363
|
|
|
} |
|
1364
|
|
|
|
|
1365
|
|
|
if ($cat_data_sql['cat_cron_enable']) |
|
1366
|
|
|
{ |
|
1367
|
|
|
$cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq']*86400; |
|
1368
|
|
|
} |
|
1369
|
|
|
|
|
1370
|
|
|
$sql = 'INSERT INTO ' . DIR_CAT_TABLE . ' ' . $db->sql_build_array('INSERT', $cat_data_sql); |
|
1371
|
|
|
$db->sql_query($sql); |
|
1372
|
|
|
|
|
1373
|
|
|
$cat_data['cat_id'] = $db->sql_nextid(); |
|
1374
|
|
|
|
|
1375
|
|
|
add_log('admin', 'LOG_DIR_CAT_ADD', $cat_data['cat_name']); |
|
1376
|
|
|
} |
|
1377
|
|
|
else |
|
1378
|
|
|
{ |
|
1379
|
|
|
|
|
1380
|
|
|
$row = $this->get_cat_info($cat_data_sql['cat_id']); |
|
1381
|
|
|
|
|
1382
|
|
|
if ($row['parent_id'] != $cat_data_sql['parent_id']) |
|
1383
|
|
|
{ |
|
1384
|
|
|
$errors = $this->move_cat($cat_data_sql['cat_id'], $cat_data_sql['parent_id']); |
|
1385
|
|
|
} |
|
1386
|
|
|
|
|
1387
|
|
|
if (sizeof($errors)) |
|
1388
|
|
|
{ |
|
1389
|
|
|
return $errors; |
|
1390
|
|
|
} |
|
1391
|
|
|
|
|
1392
|
|
|
if($cat_data_sql['cat_cron_enable']) |
|
1393
|
|
|
{ |
|
1394
|
|
|
if($row['cat_cron_freq'] != $cat_data_sql['cat_cron_freq'] || !$row['cat_cron_enable']) |
|
1395
|
|
|
{ |
|
1396
|
|
|
$cat_data_sql['cat_cron_next'] = time() + $cat_data_sql['cat_cron_freq']*86400; |
|
1397
|
|
|
} |
|
1398
|
|
|
} |
|
1399
|
|
|
|
|
1400
|
|
|
if ($row['cat_name'] != $cat_data_sql['cat_name']) |
|
1401
|
|
|
{ |
|
1402
|
|
|
// the cat name has changed, clear the parents list of all categories (for safety) |
|
1403
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
1404
|
|
|
SET cat_parents = ''"; |
|
1405
|
|
|
$db->sql_query($sql); |
|
1406
|
|
|
} |
|
1407
|
|
|
|
|
1408
|
|
|
// Setting the cat id to the categorie id is not really received well by some dbs. ;) |
|
1409
|
|
|
$cat_id = $cat_data_sql['cat_id']; |
|
1410
|
|
|
unset($cat_data_sql['cat_id']); |
|
1411
|
|
|
|
|
1412
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . ' |
|
1413
|
|
|
SET ' . $db->sql_build_array('UPDATE', $cat_data_sql) . ' |
|
1414
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
1415
|
|
|
$db->sql_query($sql); |
|
1416
|
|
|
|
|
1417
|
|
|
// Add it back |
|
1418
|
|
|
$cat_data['cat_id'] = $cat_id; |
|
1419
|
|
|
|
|
1420
|
|
|
add_log('admin', 'LOG_DIR_CAT_EDIT', $cat_data['cat_name']); |
|
1421
|
|
|
} |
|
1422
|
|
|
|
|
1423
|
|
|
return $errors; |
|
1424
|
|
|
} |
|
1425
|
|
|
|
|
1426
|
|
|
function move_cat($from_id, $to_id) |
|
|
|
|
|
|
1427
|
|
|
{ |
|
1428
|
|
|
global $db, $user; |
|
1429
|
|
|
|
|
1430
|
|
|
$to_data = $moved_ids = $errors = array(); |
|
|
|
|
|
|
1431
|
|
|
|
|
1432
|
|
|
$moved_cats = get_dir_cat_branch($from_id, 'children', 'descending'); |
|
1433
|
|
|
$from_data = $moved_cats[0]; |
|
1434
|
|
|
$diff = sizeof($moved_cats) * 2; |
|
1435
|
|
|
|
|
1436
|
|
|
$moved_ids = array(); |
|
1437
|
|
|
for ($i = 0; $i < sizeof($moved_cats); ++$i) |
|
|
|
|
|
|
1438
|
|
|
{ |
|
1439
|
|
|
$moved_ids[] = $moved_cats[$i]['cat_id']; |
|
1440
|
|
|
} |
|
1441
|
|
|
|
|
1442
|
|
|
// Resync parents |
|
1443
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1444
|
|
|
SET right_id = right_id - $diff, cat_parents = '' |
|
1445
|
|
|
WHERE left_id < " . (int)$from_data['right_id'] . " |
|
|
|
|
|
|
1446
|
|
|
AND right_id > " . (int)$from_data['right_id']; |
|
1447
|
|
|
$db->sql_query($sql); |
|
1448
|
|
|
|
|
1449
|
|
|
// Resync righthand side of tree |
|
1450
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1451
|
|
|
SET left_id = left_id - $diff, right_id = right_id - $diff, cat_parents = '' |
|
1452
|
|
|
WHERE left_id > " . (int)$from_data['right_id']; |
|
1453
|
|
|
$db->sql_query($sql); |
|
1454
|
|
|
|
|
1455
|
|
|
if ($to_id > 0) |
|
1456
|
|
|
{ |
|
1457
|
|
|
// Retrieve $to_data again, it may have been changed... |
|
1458
|
|
|
$to_data = $this->get_cat_info($to_id); |
|
1459
|
|
|
|
|
1460
|
|
|
// Resync new parents |
|
1461
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1462
|
|
|
SET right_id = right_id + $diff, cat_parents = '' |
|
1463
|
|
|
WHERE " . (int)$to_data['right_id'] . ' BETWEEN left_id AND right_id |
|
1464
|
|
|
AND ' . $db->sql_in_set('cat_id', $moved_ids, true); |
|
1465
|
|
|
$db->sql_query($sql); |
|
1466
|
|
|
|
|
1467
|
|
|
// Resync the righthand side of the tree |
|
1468
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1469
|
|
|
SET left_id = left_id + $diff, right_id = right_id + $diff, cat_parents = '' |
|
1470
|
|
|
WHERE left_id > " . (int)$to_data['right_id'] . ' |
|
1471
|
|
|
AND ' . $db->sql_in_set('cat_id', $moved_ids, true); |
|
1472
|
|
|
$db->sql_query($sql); |
|
1473
|
|
|
|
|
1474
|
|
|
// Resync moved branch |
|
1475
|
|
|
$to_data['right_id'] += $diff; |
|
1476
|
|
|
|
|
1477
|
|
|
if ($to_data['right_id'] > $from_data['right_id']) |
|
1478
|
|
|
{ |
|
1479
|
|
|
$diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1); |
|
1480
|
|
|
} |
|
1481
|
|
|
else |
|
1482
|
|
|
{ |
|
1483
|
|
|
$diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1); |
|
1484
|
|
|
} |
|
1485
|
|
|
} |
|
1486
|
|
|
else |
|
1487
|
|
|
{ |
|
1488
|
|
|
$sql = 'SELECT MAX(right_id) AS right_id |
|
1489
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1490
|
|
|
WHERE ' . $db->sql_in_set('cat_id', $moved_ids, true); |
|
1491
|
|
|
$result = $db->sql_query($sql); |
|
1492
|
|
|
$row = $db->sql_fetchrow($result); |
|
1493
|
|
|
$db->sql_freeresult($result); |
|
1494
|
|
|
|
|
1495
|
|
|
$diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1); |
|
1496
|
|
|
} |
|
1497
|
|
|
|
|
1498
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1499
|
|
|
SET left_id = left_id $diff, right_id = right_id $diff, cat_parents = '' |
|
1500
|
|
|
WHERE " . $db->sql_in_set('cat_id', $moved_ids); |
|
1501
|
|
|
$db->sql_query($sql); |
|
1502
|
|
|
|
|
1503
|
|
|
return $errors; |
|
1504
|
|
|
} |
|
1505
|
|
|
|
|
1506
|
|
|
function display_progress_bar($start, $total) |
|
|
|
|
|
|
1507
|
|
|
{ |
|
1508
|
|
|
global $template, $user; |
|
1509
|
|
|
|
|
1510
|
|
|
adm_page_header($user->lang['SYNC_IN_PROGRESS']); |
|
1511
|
|
|
|
|
1512
|
|
|
$template->set_filenames(array( |
|
1513
|
|
|
'body' => 'progress_bar.html') |
|
1514
|
|
|
); |
|
1515
|
|
|
|
|
1516
|
|
|
$template->assign_vars(array( |
|
1517
|
|
|
'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'], |
|
1518
|
|
|
'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS']) |
|
1519
|
|
|
); |
|
1520
|
|
|
|
|
1521
|
|
|
adm_page_footer(); |
|
1522
|
|
|
} |
|
1523
|
|
|
|
|
1524
|
|
|
function move_cat_by($dir_cat_row, $action = 'move_up', $steps = 1) |
|
|
|
|
|
|
1525
|
|
|
{ |
|
1526
|
|
|
global $db; |
|
1527
|
|
|
|
|
1528
|
|
|
/** |
|
1529
|
|
|
* Fetch all the siblings between the module's current spot |
|
1530
|
|
|
* and where we want to move it to. If there are less than $steps |
|
1531
|
|
|
* siblings between the current spot and the target then the |
|
1532
|
|
|
* module will move as far as possible |
|
1533
|
|
|
*/ |
|
1534
|
|
|
$sql = 'SELECT cat_id, cat_name, left_id, right_id |
|
1535
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1536
|
|
|
WHERE parent_id = ' . (int)$dir_cat_row['parent_id'] . ' |
|
1537
|
|
|
AND ' . (($action == 'move_up') ? 'right_id < ' . (int)$dir_cat_row['right_id'] . ' ORDER BY right_id DESC' : 'left_id > ' . (int)$dir_cat_row['left_id'] . ' ORDER BY left_id ASC'); |
|
1538
|
|
|
$result = $db->sql_query_limit($sql, $steps); |
|
1539
|
|
|
|
|
1540
|
|
|
$target = array(); |
|
1541
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
1542
|
|
|
{ |
|
1543
|
|
|
$target = $row; |
|
1544
|
|
|
} |
|
1545
|
|
|
$db->sql_freeresult($result); |
|
1546
|
|
|
|
|
1547
|
|
|
if (!sizeof($target)) |
|
1548
|
|
|
{ |
|
1549
|
|
|
// The cat is already on top or bottom |
|
1550
|
|
|
return false; |
|
1551
|
|
|
} |
|
1552
|
|
|
|
|
1553
|
|
|
/** |
|
1554
|
|
|
* $left_id and $right_id define the scope of the nodes that are affected by the move. |
|
1555
|
|
|
* $diff_up and $diff_down are the values to substract or add to each node's left_id |
|
1556
|
|
|
* and right_id in order to move them up or down. |
|
1557
|
|
|
* $move_up_left and $move_up_right define the scope of the nodes that are moving |
|
1558
|
|
|
* up. Other nodes in the scope of ($left_id, $right_id) are considered to move down. |
|
1559
|
|
|
*/ |
|
1560
|
|
|
if ($action == 'move_up') |
|
1561
|
|
|
{ |
|
1562
|
|
|
$left_id = $target['left_id']; |
|
1563
|
|
|
$right_id = $dir_cat_row['right_id']; |
|
1564
|
|
|
|
|
1565
|
|
|
$diff_up = $dir_cat_row['left_id'] - $target['left_id']; |
|
1566
|
|
|
$diff_down = $dir_cat_row['right_id'] + 1 - $dir_cat_row['left_id']; |
|
1567
|
|
|
|
|
1568
|
|
|
$move_up_left = $dir_cat_row['left_id']; |
|
1569
|
|
|
$move_up_right = $dir_cat_row['right_id']; |
|
1570
|
|
|
} |
|
1571
|
|
|
else |
|
1572
|
|
|
{ |
|
1573
|
|
|
$left_id = $dir_cat_row['left_id']; |
|
1574
|
|
|
$right_id = $target['right_id']; |
|
1575
|
|
|
|
|
1576
|
|
|
$diff_up = $dir_cat_row['right_id'] + 1 - $dir_cat_row['left_id']; |
|
1577
|
|
|
$diff_down = $target['right_id'] - $dir_cat_row['right_id']; |
|
1578
|
|
|
|
|
1579
|
|
|
$move_up_left = $dir_cat_row['right_id'] + 1; |
|
1580
|
|
|
$move_up_right = $target['right_id']; |
|
1581
|
|
|
} |
|
1582
|
|
|
|
|
1583
|
|
|
// Now do the dirty job |
|
1584
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1585
|
|
|
SET left_id = left_id + CASE |
|
1586
|
|
|
WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} |
|
1587
|
|
|
ELSE {$diff_down} |
|
1588
|
|
|
END, |
|
1589
|
|
|
right_id = right_id + CASE |
|
1590
|
|
|
WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up} |
|
1591
|
|
|
ELSE {$diff_down} |
|
1592
|
|
|
END, |
|
1593
|
|
|
cat_parents = '' |
|
1594
|
|
|
WHERE |
|
1595
|
|
|
left_id BETWEEN {$left_id} AND {$right_id} |
|
1596
|
|
|
AND right_id BETWEEN {$left_id} AND {$right_id}"; |
|
1597
|
|
|
$db->sql_query($sql); |
|
1598
|
|
|
|
|
1599
|
|
|
return $target['cat_name']; |
|
1600
|
|
|
} |
|
1601
|
|
|
|
|
1602
|
|
|
function delete_cat($cat_id, $action_links = 'delete', $action_subcats = 'delete', $links_to_id = 0, $subcats_to_id = 0) |
|
|
|
|
|
|
1603
|
|
|
{ |
|
1604
|
|
|
global $db, $user, $cache; |
|
1605
|
|
|
|
|
1606
|
|
|
$cat_data = $this->get_cat_info($cat_id); |
|
1607
|
|
|
|
|
1608
|
|
|
$errors = array(); |
|
1609
|
|
|
$log_action_posts = $log_action_cats = $posts_to_name = $subcats_to_name = ''; |
|
1610
|
|
|
$cat_ids = array($cat_id); |
|
1611
|
|
|
|
|
1612
|
|
|
if ($action_links == 'delete') |
|
1613
|
|
|
{ |
|
1614
|
|
|
$log_action_posts = 'LINKS'; |
|
1615
|
|
|
$errors = array_merge($errors, $this->delete_cat_content($cat_id)); |
|
1616
|
|
|
} |
|
1617
|
|
|
else if ($action_links == 'move') |
|
1618
|
|
|
{ |
|
1619
|
|
|
if (!$links_to_id) |
|
1620
|
|
|
{ |
|
1621
|
|
|
$errors[] = $user->lang['DIR_NO_DESTINATION_CAT']; |
|
1622
|
|
|
} |
|
1623
|
|
|
else |
|
1624
|
|
|
{ |
|
1625
|
|
|
$log_action_posts = 'MOVE_LINKS'; |
|
1626
|
|
|
|
|
1627
|
|
|
$sql = 'SELECT cat_name |
|
1628
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1629
|
|
|
WHERE cat_id = ' . (int)$links_to_id; |
|
1630
|
|
|
$result = $db->sql_query($sql); |
|
1631
|
|
|
$row = $db->sql_fetchrow($result); |
|
1632
|
|
|
$db->sql_freeresult($result); |
|
1633
|
|
|
|
|
1634
|
|
|
if (!$row) |
|
1635
|
|
|
{ |
|
1636
|
|
|
$errors[] = $user->lang['DIR_NO_CAT']; |
|
1637
|
|
|
} |
|
1638
|
|
|
else |
|
1639
|
|
|
{ |
|
1640
|
|
|
$posts_to_name = $row['cat_name']; |
|
1641
|
|
|
$errors = array_merge($errors, $this->move_cat_content($cat_id, $links_to_id)); |
|
1642
|
|
|
} |
|
1643
|
|
|
} |
|
1644
|
|
|
} |
|
1645
|
|
|
|
|
1646
|
|
|
if (sizeof($errors)) |
|
1647
|
|
|
{ |
|
1648
|
|
|
return $errors; |
|
1649
|
|
|
} |
|
1650
|
|
|
|
|
1651
|
|
|
if ($action_subcats == 'delete') |
|
1652
|
|
|
{ |
|
1653
|
|
|
$log_action_cats = 'CATS'; |
|
1654
|
|
|
$rows = get_dir_cat_branch($cat_id, 'children', 'descending', false); |
|
1655
|
|
|
|
|
1656
|
|
|
foreach ($rows as $row) |
|
1657
|
|
|
{ |
|
1658
|
|
|
$cat_ids[] = $row['cat_id']; |
|
1659
|
|
|
$errors = array_merge($errors, $this->delete_cat_content($row['cat_id'])); |
|
1660
|
|
|
} |
|
1661
|
|
|
|
|
1662
|
|
|
if (sizeof($errors)) |
|
1663
|
|
|
{ |
|
1664
|
|
|
return $errors; |
|
1665
|
|
|
} |
|
1666
|
|
|
|
|
1667
|
|
|
$diff = sizeof($cat_ids) * 2; |
|
1668
|
|
|
|
|
1669
|
|
|
$sql = 'DELETE FROM ' . DIR_CAT_TABLE . ' |
|
1670
|
|
|
WHERE ' . $db->sql_in_set('cat_id', $cat_ids); |
|
1671
|
|
|
$db->sql_query($sql); |
|
1672
|
|
|
|
|
1673
|
|
|
} |
|
1674
|
|
|
else if ($action_subcats == 'move') |
|
1675
|
|
|
{ |
|
1676
|
|
|
if (!$subcats_to_id) |
|
1677
|
|
|
{ |
|
1678
|
|
|
$errors[] = $user->lang['DIR_NO_DESTINATION_CAT']; |
|
1679
|
|
|
} |
|
1680
|
|
|
else |
|
1681
|
|
|
{ |
|
1682
|
|
|
$log_action_cats = 'MOVE_CATS'; |
|
1683
|
|
|
|
|
1684
|
|
|
$sql = 'SELECT cat_name |
|
1685
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1686
|
|
|
WHERE cat_id = ' . (int)$subcats_to_id; |
|
1687
|
|
|
$result = $db->sql_query($sql); |
|
1688
|
|
|
$row = $db->sql_fetchrow($result); |
|
1689
|
|
|
$db->sql_freeresult($result); |
|
1690
|
|
|
|
|
1691
|
|
|
if (!$row) |
|
1692
|
|
|
{ |
|
1693
|
|
|
$errors[] = $user->lang['DIR_NO_CAT']; |
|
1694
|
|
|
} |
|
1695
|
|
|
else |
|
1696
|
|
|
{ |
|
1697
|
|
|
$subcats_to_name = $row['cat_name']; |
|
1698
|
|
|
|
|
1699
|
|
|
$sql = 'SELECT cat_id |
|
1700
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1701
|
|
|
WHERE parent_id = ' . (int)$cat_id; |
|
1702
|
|
|
$result = $db->sql_query($sql); |
|
1703
|
|
|
|
|
1704
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
1705
|
|
|
{ |
|
1706
|
|
|
$this->move_cat($row['cat_id'], $subcats_to_id); |
|
1707
|
|
|
} |
|
1708
|
|
|
$db->sql_freeresult($result); |
|
1709
|
|
|
|
|
1710
|
|
|
// Grab new cat data for correct tree updating later |
|
1711
|
|
|
$cat_data = $this->get_cat_info($cat_id); |
|
1712
|
|
|
|
|
1713
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . ' |
|
1714
|
|
|
SET parent_id = ' . (int)$subcats_to_id . ' |
|
1715
|
|
|
WHERE parent_id = ' . (int)$cat_id; |
|
1716
|
|
|
$db->sql_query($sql); |
|
1717
|
|
|
|
|
1718
|
|
|
$diff = 2; |
|
1719
|
|
|
$sql = 'DELETE FROM ' . DIR_CAT_TABLE . ' |
|
1720
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
1721
|
|
|
$db->sql_query($sql); |
|
1722
|
|
|
} |
|
1723
|
|
|
} |
|
1724
|
|
|
|
|
1725
|
|
|
if (sizeof($errors)) |
|
1726
|
|
|
{ |
|
1727
|
|
|
return $errors; |
|
1728
|
|
|
} |
|
1729
|
|
|
} |
|
1730
|
|
|
else |
|
1731
|
|
|
{ |
|
1732
|
|
|
$diff = 2; |
|
1733
|
|
|
$sql = 'DELETE FROM ' . DIR_CAT_TABLE . ' |
|
1734
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
1735
|
|
|
$db->sql_query($sql); |
|
1736
|
|
|
} |
|
1737
|
|
|
|
|
1738
|
|
|
// Resync tree |
|
1739
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1740
|
|
|
SET right_id = right_id - $diff |
|
|
|
|
|
|
1741
|
|
|
WHERE left_id < {$cat_data['right_id']} AND right_id > {$cat_data['right_id']}"; |
|
1742
|
|
|
$db->sql_query($sql); |
|
1743
|
|
|
|
|
1744
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . " |
|
|
|
|
|
|
1745
|
|
|
SET left_id = left_id - $diff, right_id = right_id - $diff |
|
1746
|
|
|
WHERE left_id > {$cat_data['right_id']}"; |
|
1747
|
|
|
$db->sql_query($sql); |
|
1748
|
|
|
|
|
1749
|
|
|
$log_action = implode('_', array($log_action_posts, $log_action_cats)); |
|
1750
|
|
|
|
|
1751
|
|
|
switch ($log_action) |
|
1752
|
|
|
{ |
|
1753
|
|
|
case 'MOVE_LINKS_MOVE_CATS': |
|
1754
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_MOVE_LINKS_MOVE_CATS', $posts_to_name, $subcats_to_name, $cat_data['cat_name']); |
|
1755
|
|
|
break; |
|
1756
|
|
|
|
|
1757
|
|
|
case 'MOVE_LINKS_CATS': |
|
1758
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_MOVE_LINKS_CATS', $posts_to_name, $cat_data['cat_name']); |
|
1759
|
|
|
break; |
|
1760
|
|
|
|
|
1761
|
|
|
case 'LINKS_MOVE_CATS': |
|
1762
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_LINKS_MOVE_CATS', $subcats_to_name, $cat_data['cat_name']); |
|
1763
|
|
|
break; |
|
1764
|
|
|
|
|
1765
|
|
|
case '_MOVE_CATS': |
|
1766
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_MOVE_CATS', $subcats_to_name, $cat_data['cat_name']); |
|
1767
|
|
|
break; |
|
1768
|
|
|
|
|
1769
|
|
|
case 'MOVE_LINKS_': |
|
1770
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_MOVE_LINKS', $posts_to_name, $cat_data['cat_name']); |
|
1771
|
|
|
break; |
|
1772
|
|
|
|
|
1773
|
|
|
case 'LINKS_CATS': |
|
1774
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_LINKS_CATS', $cat_data['cat_name']); |
|
1775
|
|
|
break; |
|
1776
|
|
|
|
|
1777
|
|
|
case '_CATS': |
|
1778
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_CATS', $cat_data['cat_name']); |
|
1779
|
|
|
break; |
|
1780
|
|
|
|
|
1781
|
|
|
case 'LINKS_': |
|
1782
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_LINKS', $cat_data['cat_name']); |
|
1783
|
|
|
break; |
|
1784
|
|
|
|
|
1785
|
|
|
default: |
|
1786
|
|
|
add_log('admin', 'LOG_DIR_CAT_DEL_CAT', $cat_data['cat_name']); |
|
1787
|
|
|
break; |
|
1788
|
|
|
} |
|
1789
|
|
|
|
|
1790
|
|
|
return $errors; |
|
1791
|
|
|
} |
|
1792
|
|
|
|
|
1793
|
|
|
function move_cat_content($from_id, $to_id) |
|
|
|
|
|
|
1794
|
|
|
{ |
|
1795
|
|
|
global $db; |
|
1796
|
|
|
|
|
1797
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' |
|
1798
|
|
|
SET link_cat = ' . (int)$to_id . ' |
|
1799
|
|
|
WHERE link_cat = ' . (int)$from_id; |
|
1800
|
|
|
$db->sql_query($sql); |
|
1801
|
|
|
|
|
1802
|
|
|
$sql = 'DELETE FROM ' . DIR_NOTIFICATION_TABLE . ' |
|
1803
|
|
|
WHERE n_cat_id = ' . (int)$from_id; |
|
1804
|
|
|
$db->sql_query($sql); |
|
1805
|
|
|
|
|
1806
|
|
|
sync_dir_cat($to_id); |
|
1807
|
|
|
|
|
1808
|
|
|
return array(); |
|
1809
|
|
|
} |
|
1810
|
|
|
|
|
1811
|
|
|
function delete_cat_content($cat_id) |
|
|
|
|
|
|
1812
|
|
|
{ |
|
1813
|
|
|
global $db, $phpbb_root_path; |
|
1814
|
|
|
|
|
1815
|
|
|
$db->sql_transaction('begin'); |
|
1816
|
|
|
|
|
1817
|
|
|
// Before we remove anything we make sure we are able to adjust the post counts later. ;) |
|
1818
|
|
|
$sql = 'SELECT link_id, link_banner |
|
1819
|
|
|
FROM ' . DIR_LINK_TABLE . ' |
|
1820
|
|
|
WHERE link_cat = ' . (int)$cat_id; |
|
1821
|
|
|
$result = $db->sql_query($sql); |
|
1822
|
|
|
|
|
1823
|
|
|
$link_ids = array(); |
|
1824
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
1825
|
|
|
{ |
|
1826
|
|
|
$link_ids[] = $row['link_id']; |
|
1827
|
|
|
|
|
1828
|
|
View Code Duplication |
if($row['link_banner'] && !preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) |
|
|
|
|
|
|
1829
|
|
|
{ |
|
1830
|
|
|
if (file_exists($phpbb_root_path . 'images/directory/banners' .'/'. basename($row['link_banner']))) |
|
1831
|
|
|
{ |
|
1832
|
|
|
@unlink($phpbb_root_path . 'images/directory/banners' .'/'. basename($row['link_banner'])); |
|
1833
|
|
|
} |
|
1834
|
|
|
} |
|
1835
|
|
|
} |
|
1836
|
|
|
$db->sql_freeresult($result); |
|
1837
|
|
|
|
|
1838
|
|
|
if (sizeof($link_ids)) |
|
1839
|
|
|
{ |
|
1840
|
|
|
// Delete links datas |
|
1841
|
|
|
$link_datas_ary = array( |
|
1842
|
|
|
DIR_COMMENT_TABLE => 'comment_link_id', |
|
1843
|
|
|
DIR_VOTE_TABLE => 'vote_link_id', |
|
1844
|
|
|
); |
|
1845
|
|
|
|
|
1846
|
|
|
foreach ($link_datas_ary as $table => $field) |
|
1847
|
|
|
{ |
|
1848
|
|
|
$db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $link_ids)); |
|
|
|
|
|
|
1849
|
|
|
} |
|
1850
|
|
|
} |
|
1851
|
|
|
|
|
1852
|
|
|
// Delete cats datas |
|
1853
|
|
|
$cat_datas_ary = array( |
|
1854
|
|
|
DIR_LINK_TABLE => 'link_cat', |
|
1855
|
|
|
DIR_NOTIFICATION_TABLE => 'n_cat_id', |
|
1856
|
|
|
); |
|
1857
|
|
|
|
|
1858
|
|
|
foreach ($cat_datas_ary as $table => $field) |
|
1859
|
|
|
{ |
|
1860
|
|
|
$db->sql_query("DELETE FROM $table WHERE $field = " . (int)$cat_id); |
|
|
|
|
|
|
1861
|
|
|
} |
|
1862
|
|
|
|
|
1863
|
|
|
$db->sql_transaction('commit'); |
|
1864
|
|
|
|
|
1865
|
|
|
return array(); |
|
1866
|
|
|
} |
|
1867
|
|
|
} |
|
1868
|
|
|
|
|
1869
|
|
|
function get_dir_cat_branch($dir_cat_id, $type = 'all', $order = 'descending', $include_cat = true) |
|
1870
|
|
|
{ |
|
1871
|
|
|
global $db; |
|
1872
|
|
|
|
|
1873
|
|
|
switch ($type) |
|
1874
|
|
|
{ |
|
1875
|
|
|
case 'parents': |
|
1876
|
|
|
$condition = 'f1.left_id BETWEEN f2.left_id AND f2.right_id'; |
|
1877
|
|
|
break; |
|
1878
|
|
|
|
|
1879
|
|
|
case 'children': |
|
1880
|
|
|
$condition = 'f2.left_id BETWEEN f1.left_id AND f1.right_id'; |
|
1881
|
|
|
break; |
|
1882
|
|
|
|
|
1883
|
|
|
default: |
|
1884
|
|
|
$condition = 'f2.left_id BETWEEN f1.left_id AND f1.right_id OR f1.left_id BETWEEN f2.left_id AND f2.right_id'; |
|
1885
|
|
|
break; |
|
1886
|
|
|
} |
|
1887
|
|
|
|
|
1888
|
|
|
$rows = array(); |
|
1889
|
|
|
|
|
1890
|
|
|
$sql = 'SELECT f2.cat_id, f2.cat_name, f2.left_id, f2.right_id |
|
1891
|
|
|
FROM ' . DIR_CAT_TABLE . ' f1 |
|
1892
|
|
|
LEFT JOIN ' . DIR_CAT_TABLE . " f2 ON ($condition) |
|
|
|
|
|
|
1893
|
|
|
WHERE f1.cat_id = " . (int)$dir_cat_id . " |
|
|
|
|
|
|
1894
|
|
|
ORDER BY f2.left_id " . (($order == 'descending') ? 'ASC' : 'DESC'); |
|
1895
|
|
|
$result = $db->sql_query($sql); |
|
1896
|
|
|
|
|
1897
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
1898
|
|
|
{ |
|
1899
|
|
|
if (!$include_cat && $row['cat_id'] == $dir_cat_id) |
|
1900
|
|
|
{ |
|
1901
|
|
|
continue; |
|
1902
|
|
|
} |
|
1903
|
|
|
|
|
1904
|
|
|
$rows[] = $row; |
|
1905
|
|
|
} |
|
1906
|
|
|
$db->sql_freeresult($result); |
|
1907
|
|
|
|
|
1908
|
|
|
return $rows; |
|
1909
|
|
|
} |
|
1910
|
|
|
|
|
1911
|
|
|
function make_cat_select($select_id = false, $ignore_id = false) |
|
1912
|
|
|
{ |
|
1913
|
|
|
global $db; |
|
1914
|
|
|
|
|
1915
|
|
|
// This query is identical to the jumpbox one |
|
1916
|
|
|
$sql = 'SELECT cat_id, cat_name, parent_id, left_id, right_id |
|
1917
|
|
|
FROM ' . DIR_CAT_TABLE . ' |
|
1918
|
|
|
ORDER BY left_id ASC'; |
|
1919
|
|
|
$result = $db->sql_query($sql); |
|
1920
|
|
|
|
|
1921
|
|
|
$right = 0; |
|
1922
|
|
|
$padding_store = array('0' => ''); |
|
1923
|
|
|
$padding = ''; |
|
1924
|
|
|
$cat_list = ''; |
|
1925
|
|
|
|
|
1926
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
1927
|
|
|
{ |
|
1928
|
|
View Code Duplication |
if ($row['left_id'] < $right) |
|
|
|
|
|
|
1929
|
|
|
{ |
|
1930
|
|
|
$padding .= ' '; |
|
1931
|
|
|
$padding_store[$row['parent_id']] = $padding; |
|
1932
|
|
|
} |
|
1933
|
|
|
else if ($row['left_id'] > $right + 1) |
|
1934
|
|
|
{ |
|
1935
|
|
|
$padding = (isset($padding_store[$row['parent_id']])) ? $padding_store[$row['parent_id']] : ''; |
|
1936
|
|
|
} |
|
1937
|
|
|
|
|
1938
|
|
|
$right = $row['right_id']; |
|
1939
|
|
|
$disabled = false; |
|
1940
|
|
|
|
|
1941
|
|
|
if (((is_array($ignore_id) && in_array($row['cat_id'], $ignore_id)) || $row['cat_id'] == $ignore_id)) |
|
1942
|
|
|
{ |
|
1943
|
|
|
$disabled = true; |
|
1944
|
|
|
} |
|
1945
|
|
|
|
|
1946
|
|
|
$selected = (($row['cat_id'] == $select_id) ? ' selected="selected"' : ''); |
|
1947
|
|
|
$cat_list .= '<option value="' . $row['cat_id'] . '"' . (($disabled) ? ' disabled="disabled" class="disabled-option"' : $selected) . '>' . $padding . $row['cat_name'] . '</option>'; |
|
1948
|
|
|
} |
|
1949
|
|
|
$db->sql_freeresult($result); |
|
1950
|
|
|
unset($padding_store); |
|
1951
|
|
|
|
|
1952
|
|
|
return $cat_list; |
|
1953
|
|
|
} |
|
1954
|
|
|
|
|
1955
|
|
|
function sync_dir_cat($cat_id) |
|
1956
|
|
|
{ |
|
1957
|
|
|
global $db; |
|
1958
|
|
|
|
|
1959
|
|
|
$sql = 'SELECT COUNT(link_id) AS num_links |
|
1960
|
|
|
FROM ' . DIR_LINK_TABLE . ' |
|
1961
|
|
|
WHERE link_cat = ' . (int)$cat_id . ' |
|
1962
|
|
|
AND link_active = 1'; |
|
1963
|
|
|
$result = $db->sql_query($sql); |
|
1964
|
|
|
$total_links = (int) $db->sql_fetchfield('num_links'); |
|
1965
|
|
|
$db->sql_freeresult($result); |
|
1966
|
|
|
|
|
1967
|
|
|
$sql = 'UPDATE ' . DIR_CAT_TABLE . ' |
|
1968
|
|
|
SET cat_links = ' . $total_links . ' |
|
1969
|
|
|
WHERE cat_id = ' . (int)$cat_id; |
|
1970
|
|
|
$db->sql_query($sql); |
|
1971
|
|
|
|
|
1972
|
|
|
return; |
|
1973
|
|
|
} |
|
1974
|
|
|
|
|
1975
|
|
|
function sync_dir_links($start, $stop) |
|
1976
|
|
|
{ |
|
1977
|
|
|
global $db; |
|
1978
|
|
|
|
|
1979
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' |
|
1980
|
|
|
SET link_comment = 0, |
|
1981
|
|
|
link_note = 0, |
|
1982
|
|
|
link_vote = 0 |
|
1983
|
|
|
WHERE link_id BETWEEN ' . (int)$start . ' AND ' . (int)$stop; |
|
1984
|
|
|
$db->sql_query($sql); |
|
1985
|
|
|
|
|
1986
|
|
|
$sql = 'SELECT vote_link_id, COUNT(vote_note) AS nb_vote, SUM(vote_note) AS total FROM ' . DIR_VOTE_TABLE . ' |
|
1987
|
|
|
WHERE vote_link_id BETWEEN ' . (int)$start . ' AND ' . (int)$stop . ' |
|
1988
|
|
|
GROUP BY vote_link_id'; |
|
1989
|
|
|
$result = $db->sql_query($sql); |
|
1990
|
|
|
while ($tmp = $db->sql_fetchrow($result)) |
|
1991
|
|
|
{ |
|
1992
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET |
|
1993
|
|
|
link_note = ' . (int)$tmp['total'] . ', |
|
1994
|
|
|
link_vote = ' . (int)$tmp['nb_vote'] . ' |
|
1995
|
|
|
WHERE link_id = ' . (int)$tmp['vote_link_id']; |
|
1996
|
|
|
$db->sql_query($sql); |
|
1997
|
|
|
} |
|
1998
|
|
|
$db->sql_freeresult($result); |
|
1999
|
|
|
|
|
2000
|
|
|
$sql = 'SELECT comment_link_id, COUNT(comment_id) AS nb_comment FROM ' . DIR_COMMENT_TABLE . ' |
|
2001
|
|
|
WHERE comment_link_id BETWEEN ' . (int)$start . ' AND ' . (int)$stop . ' |
|
2002
|
|
|
GROUP BY comment_link_id'; |
|
2003
|
|
|
$result = $db->sql_query($sql); |
|
2004
|
|
|
while ($tmp = $db->sql_fetchrow($result)) |
|
2005
|
|
|
{ |
|
2006
|
|
|
$sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET |
|
2007
|
|
|
link_comment = ' . (int)$tmp['nb_comment'] . ' |
|
2008
|
|
|
WHERE link_id = ' . (int)$tmp['comment_link_id']; |
|
2009
|
|
|
$db->sql_query($sql); |
|
2010
|
|
|
} |
|
2011
|
|
|
$db->sql_freeresult($result); |
|
2012
|
|
|
|
|
2013
|
|
|
return; |
|
2014
|
|
|
} |
|
2015
|
|
|
|
|
2016
|
|
|
function get_dir_icon_list($value) |
|
2017
|
|
|
{ |
|
2018
|
|
|
global $phpbb_root_path; |
|
2019
|
|
|
|
|
2020
|
|
|
$imglist = filelist($phpbb_root_path . 'images/directory/icons', ''); |
|
2021
|
|
|
$edit_img = $filename_list = ''; |
|
2022
|
|
|
$ranks = $existing_imgs = array(); |
|
|
|
|
|
|
2023
|
|
|
|
|
2024
|
|
|
foreach ($imglist as $path => $img_ary) |
|
2025
|
|
|
{ |
|
2026
|
|
|
sort($img_ary); |
|
2027
|
|
|
|
|
2028
|
|
|
foreach ($img_ary as $img) |
|
2029
|
|
|
{ |
|
2030
|
|
|
$img = $path . $img; |
|
2031
|
|
|
|
|
2032
|
|
|
if (!in_array($img, $existing_imgs) || $action == 'edit') |
|
|
|
|
|
|
2033
|
|
|
{ |
|
2034
|
|
|
if ($img == $value) |
|
2035
|
|
|
{ |
|
2036
|
|
|
$selected = ' selected="selected"'; |
|
2037
|
|
|
$edit_img = $img; |
|
2038
|
|
|
} |
|
2039
|
|
|
else |
|
2040
|
|
|
{ |
|
2041
|
|
|
$selected = ''; |
|
2042
|
|
|
} |
|
2043
|
|
|
|
|
2044
|
|
|
if (strlen($img) > 255) |
|
2045
|
|
|
{ |
|
2046
|
|
|
continue; |
|
2047
|
|
|
} |
|
2048
|
|
|
|
|
2049
|
|
|
$filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>'; |
|
2050
|
|
|
} |
|
2051
|
|
|
} |
|
2052
|
|
|
} |
|
2053
|
|
|
$filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list; |
|
2054
|
|
|
return ($filename_list); |
|
2055
|
|
|
} |
|
2056
|
|
|
|
|
2057
|
|
|
function orphan_files($delete = false) |
|
2058
|
|
|
{ |
|
2059
|
|
|
global $db, $phpbb_root_path; |
|
2060
|
|
|
|
|
2061
|
|
|
$banner_path = 'images/directory/banners/'; |
|
2062
|
|
|
$imglist = filelist($phpbb_root_path . $banner_path); |
|
2063
|
|
|
$physical_files = $logical_files = $orphan_files = array(); |
|
2064
|
|
|
|
|
2065
|
|
|
if (!empty($imglist[''])) |
|
2066
|
|
|
{ |
|
2067
|
|
|
$imglist = array_values($imglist); |
|
2068
|
|
|
$imglist = $imglist[0]; |
|
2069
|
|
|
|
|
2070
|
|
|
foreach($imglist as $key => $img) |
|
2071
|
|
|
{ |
|
2072
|
|
|
$physical_files[] = $img; |
|
2073
|
|
|
} |
|
2074
|
|
|
$sql = 'SELECT link_banner FROM ' . DIR_LINK_TABLE . ' |
|
2075
|
|
|
WHERE link_banner <> \'\''; |
|
2076
|
|
|
$result = $db->sql_query($sql); |
|
2077
|
|
|
|
|
2078
|
|
|
while($row = $db->sql_fetchrow($result)) |
|
2079
|
|
|
{ |
|
2080
|
|
|
if (!preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $row['link_banner'])) |
|
2081
|
|
|
{ |
|
2082
|
|
|
$logical_files[] = basename($row['link_banner']); |
|
2083
|
|
|
} |
|
2084
|
|
|
} |
|
2085
|
|
|
$db->sql_freeresult($result); |
|
2086
|
|
|
|
|
2087
|
|
|
$orphan_files = array_diff($physical_files, $logical_files); |
|
2088
|
|
|
} |
|
2089
|
|
|
|
|
2090
|
|
|
if(!$delete) |
|
2091
|
|
|
{ |
|
2092
|
|
|
return sizeof($orphan_files); |
|
2093
|
|
|
} |
|
2094
|
|
|
|
|
2095
|
|
|
$directory = $phpbb_root_path.'images/directory/banners'; |
|
2096
|
|
|
|
|
2097
|
|
|
$dh = @opendir($directory); |
|
2098
|
|
|
while (($file = readdir($dh)) !== false) |
|
2099
|
|
|
{ |
|
2100
|
|
|
if (in_array($file, $orphan_files)) |
|
2101
|
|
|
{ |
|
2102
|
|
|
@unlink($directory .'/'.$file); |
|
2103
|
|
|
} |
|
2104
|
|
|
} |
|
2105
|
|
|
} |
|
2106
|
|
|
|
|
2107
|
|
|
?> |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.