| Conditions | 158 |
| Paths | > 20000 |
| Total Lines | 1179 |
| Code Lines | 714 |
| Lines | 84 |
| Ratio | 7.12 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | |||
| 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.