Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like cat often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use cat, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class cat extends helper |
||
| 16 | { |
||
| 17 | /** @var \phpbb\cache\service */ |
||
| 18 | protected $cache; |
||
| 19 | |||
| 20 | /** @var \phpbb\db\driver\driver_interface */ |
||
| 21 | protected $db; |
||
| 22 | |||
| 23 | /** @var \phpbb\controller\helper */ |
||
| 24 | protected $helper; |
||
| 25 | |||
| 26 | /** @var \phpbb\language\language */ |
||
| 27 | protected $language; |
||
| 28 | |||
| 29 | /** @var \phpbb\log\log */ |
||
| 30 | protected $phpbb_log; |
||
| 31 | |||
| 32 | /** @var \phpbb\request\request */ |
||
| 33 | protected $request; |
||
| 34 | |||
| 35 | /** @var \phpbb\template\template */ |
||
| 36 | protected $template; |
||
| 37 | |||
| 38 | /** @var \phpbb\user */ |
||
| 39 | protected $user; |
||
| 40 | |||
| 41 | /** @var \ernadoo\phpbbdirectory\core\categorie */ |
||
| 42 | protected $categorie; |
||
| 43 | |||
| 44 | /** @var \ernadoo\phpbbdirectory\core\nestedset_category */ |
||
| 45 | protected $nestedset_category; |
||
| 46 | |||
| 47 | /** @var string Custom form action */ |
||
| 48 | protected $u_action; |
||
| 49 | |||
| 50 | /** @var string */ |
||
| 51 | private $action; |
||
| 52 | |||
| 53 | /** @var array */ |
||
| 54 | private $cat_data = array(); |
||
| 55 | |||
| 56 | /** @var int */ |
||
| 57 | private $cat_id; |
||
| 58 | |||
| 59 | /** @var array */ |
||
| 60 | private $errors; |
||
| 61 | |||
| 62 | /** @var string */ |
||
| 63 | private $form_key; |
||
| 64 | |||
| 65 | /** @var int */ |
||
| 66 | private $parent_id; |
||
| 67 | |||
| 68 | /** @var bool */ |
||
| 69 | private $update; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Constructor |
||
| 73 | * |
||
| 74 | * @param \phpbb\cache\service $cache Cache object |
||
| 75 | * @param \phpbb\db\driver\driver_interface $db Database object |
||
| 76 | * @param \phpbb\controller\helper $helper Helper object |
||
| 77 | * @param \phpbb\language\language $language Language object |
||
| 78 | * @param \phpbb\log\log $log Log object |
||
| 79 | * @param \phpbb\request\request $request Request object |
||
| 80 | * @param \phpbb\template\template $template Template object |
||
| 81 | * @param \phpbb\user $user User object |
||
| 82 | * @param \ernadoo\phpbbdirectory\core\categorie $categorie PhpBB Directory extension categorie object |
||
| 83 | * @param \ernadoo\phpbbdirectory\core\nestedset_category $nestedset_category PhpBB Directory extension nestedset object |
||
| 84 | */ |
||
| 85 | public function __construct(\phpbb\cache\service $cache, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\language\language $language, \phpbb\log\log $log, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\nestedset_category $nestedset_category) |
||
| 86 | { |
||
| 87 | $this->cache = $cache; |
||
| 88 | $this->db = $db; |
||
| 89 | $this->helper = $helper; |
||
| 90 | $this->language = $language; |
||
| 91 | $this->phpbb_log = $log; |
||
| 92 | $this->request = $request; |
||
| 93 | $this->template = $template; |
||
| 94 | $this->user = $user; |
||
| 95 | $this->categorie = $categorie; |
||
| 96 | $this->nestedset_category = $nestedset_category; |
||
| 97 | |||
| 98 | $this->form_key = 'acp_dir_cat'; |
||
| 99 | add_form_key($this->form_key); |
||
| 100 | |||
| 101 | $this->action = $this->request->variable('action', ''); |
||
| 102 | $this->cat_id = $request->variable('c', 0); |
||
| 103 | $this->parent_id = $request->variable('parent_id', 0); |
||
| 104 | $this->update = ($this->request->is_set_post('update')) ? true : false; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Initialize defaults data for add page |
||
| 109 | * |
||
| 110 | * @return null |
||
| 111 | */ |
||
| 112 | public function action_add() |
||
| 113 | { |
||
| 114 | $this->cat_id = $this->parent_id; |
||
| 115 | $parents_list = $this->categorie->make_cat_select($this->parent_id); |
||
| 116 | |||
| 117 | // Fill categorie data with default values |
||
| 118 | if (!$this->update) |
||
| 119 | { |
||
| 120 | $this->cat_data = array( |
||
| 121 | 'parent_id' => $this->parent_id, |
||
| 122 | 'cat_name' => $this->request->variable('cat_name', '', true), |
||
| 123 | 'cat_route' => '', |
||
| 124 | 'cat_desc' => '', |
||
| 125 | 'cat_icon' => '', |
||
| 126 | 'cat_allow_comments' => true, |
||
| 127 | 'cat_allow_votes' => true, |
||
| 128 | 'cat_must_describe' => true, |
||
| 129 | 'cat_count_all' => false, |
||
| 130 | 'cat_validate' => false, |
||
| 131 | 'enable_icons' => false, |
||
| 132 | |||
| 133 | 'display_subcat_list' => true, |
||
| 134 | |||
| 135 | 'cat_link_back' => false, |
||
| 136 | 'cat_cron_enable' => false, |
||
| 137 | 'cat_cron_freq' => 7, |
||
| 138 | 'cat_cron_nb_check' => 1, |
||
| 139 | ); |
||
| 140 | } |
||
| 141 | |||
| 142 | $this->_display_cat_form($parents_list); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Display deleting page |
||
| 147 | * |
||
| 148 | * @return null |
||
| 149 | */ |
||
| 150 | public function action_delete() |
||
| 151 | { |
||
| 152 | View Code Duplication | if (!$this->cat_id) |
|
| 153 | { |
||
| 154 | trigger_error($this->language->lang('DIR_NO_CAT') . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
||
| 155 | } |
||
| 156 | |||
| 157 | $this->cat_data = $this->_get_cat_info($this->cat_id); |
||
| 158 | |||
| 159 | $subcats_id = array(); |
||
| 160 | $subcats = $this->nestedset_category->get_subtree_data($this->cat_id); |
||
| 161 | |||
| 162 | foreach ($subcats as $row) |
||
| 163 | { |
||
| 164 | $subcats_id[] = $row['cat_id']; |
||
| 165 | } |
||
| 166 | |||
| 167 | $cat_list = $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $subcats_id); |
||
| 168 | |||
| 169 | $sql = 'SELECT cat_id |
||
| 170 | FROM ' . $this->categories_table . ' |
||
| 171 | WHERE cat_id <> ' . (int) $this->cat_id; |
||
| 172 | $result = $this->db->sql_query_limit($sql, 1); |
||
| 173 | |||
| 174 | if ($this->db->sql_fetchrow($result)) |
||
| 175 | { |
||
| 176 | $this->template->assign_vars(array( |
||
| 177 | 'S_MOVE_DIR_CAT_OPTIONS' => $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $subcats_id)) |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | $this->db->sql_freeresult($result); |
||
| 181 | |||
| 182 | $parent_id = ($this->parent_id == $this->cat_id) ? 0 : $this->parent_id; |
||
| 183 | |||
| 184 | $this->template->assign_vars(array( |
||
| 185 | 'S_DELETE_DIR_CAT' => true, |
||
| 186 | 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&c=$this->cat_id", |
||
| 187 | 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id, |
||
| 188 | |||
| 189 | 'DIR_CAT_NAME' => $this->cat_data['cat_name'], |
||
| 190 | 'S_HAS_SUBCATS' => ($this->cat_data['right_id'] - $this->cat_data['left_id'] > 1) ? true : false, |
||
| 191 | 'S_CATS_LIST' => $cat_list, |
||
| 192 | 'S_ERROR' => (sizeof($this->errors)) ? true : false, |
||
| 193 | 'ERROR_MSG' => (sizeof($this->errors)) ? implode('<br />', $this->errors) : '') |
||
| 194 | ); |
||
| 195 | |||
| 196 | return; |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Initialize data for edit page |
||
| 201 | * |
||
| 202 | * @return null |
||
| 203 | */ |
||
| 204 | public function action_edit() |
||
| 205 | { |
||
| 206 | $row = $this->_get_cat_info($this->cat_id); |
||
| 207 | |||
| 208 | if (!$this->update) |
||
| 209 | { |
||
| 210 | $this->cat_data = $row; |
||
| 211 | } |
||
| 212 | else |
||
| 213 | { |
||
| 214 | $this->cat_data['left_id'] = $row['left_id']; |
||
| 215 | $this->cat_data['right_id'] = $row['right_id']; |
||
| 216 | } |
||
| 217 | |||
| 218 | // Make sure no direct child categories are able to be selected as parents. |
||
| 219 | $exclude_cats = array(); |
||
| 220 | foreach ($this->nestedset_category->get_subtree_data($this->cat_id) as $row2) |
||
| 221 | { |
||
| 222 | $exclude_cats[] = $row2['cat_id']; |
||
| 223 | } |
||
| 224 | $parents_list = $this->categorie->make_cat_select((int) $this->cat_data['parent_id'], $exclude_cats); |
||
| 225 | |||
| 226 | $this->_display_cat_form($parents_list); |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Move order categories |
||
| 231 | * |
||
| 232 | * @return null |
||
| 233 | */ |
||
| 234 | public function action_move() |
||
| 235 | { |
||
| 236 | View Code Duplication | if (!$this->cat_id) |
|
| 237 | { |
||
| 238 | trigger_error($this->language->lang('DIR_NO_CAT') . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
||
| 239 | } |
||
| 240 | |||
| 241 | $sql = 'SELECT cat_id, cat_name, parent_id, left_id, right_id |
||
| 242 | FROM ' . $this->categories_table . ' |
||
| 243 | WHERE cat_id = ' . (int) $this->cat_id; |
||
| 244 | $result = $this->db->sql_query($sql); |
||
| 245 | $row = $this->db->sql_fetchrow($result); |
||
| 246 | $this->db->sql_freeresult($result); |
||
| 247 | |||
| 248 | View Code Duplication | if (!$row) |
|
| 249 | { |
||
| 250 | trigger_error($this->language->lang('DIR_NO_CAT') . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
||
| 251 | } |
||
| 252 | |||
| 253 | try |
||
| 254 | { |
||
| 255 | $move_cat_name = $this->nestedset_category->{$this->action}($this->cat_id); |
||
| 256 | } |
||
| 257 | catch (\Exception $e) |
||
| 258 | { |
||
| 259 | trigger_error($e->getMessage(), E_USER_WARNING); |
||
| 260 | } |
||
| 261 | |||
| 262 | if ($move_cat_name !== false) |
||
| 263 | { |
||
| 264 | $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_' . strtoupper($this->action), time(), array($row['cat_name'], $move_cat_name)); |
||
| 265 | $this->cache->destroy('sql', $this->categories_table); |
||
| 266 | } |
||
| 267 | |||
| 268 | if ($this->request->is_ajax()) |
||
| 269 | { |
||
| 270 | $json_response = new \phpbb\json_response; |
||
| 271 | $json_response->send(array('success' => ($move_cat_name !== false))); |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Display progress bar for syncinc categories |
||
| 277 | * |
||
| 278 | * @return null |
||
| 279 | */ |
||
| 280 | public function action_progress_bar() |
||
| 281 | { |
||
| 282 | $start = $this->request->variable('start', 0); |
||
| 283 | $total = $this->request->variable('total', 0); |
||
| 284 | |||
| 285 | adm_page_header($this->language->lang('SYNC_IN_PROGRESS')); |
||
| 286 | |||
| 287 | $this->template->set_filenames(array( |
||
| 288 | 'body' => 'progress_bar.html') |
||
| 289 | ); |
||
| 290 | |||
| 291 | $this->template->assign_vars(array( |
||
| 292 | 'L_PROGRESS' => $this->language->lang('SYNC_IN_PROGRESS'), |
||
| 293 | 'L_PROGRESS_EXPLAIN' => ($start && $total) ? $this->language->lang('SYNC_IN_PROGRESS_EXPLAIN', $start, $total) : $this->language->lang('SYNC_IN_PROGRESS')) |
||
| 294 | ); |
||
| 295 | |||
| 296 | adm_page_footer(); |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Get link's ID interval for _sync_dir_links() |
||
| 301 | * |
||
| 302 | * @return null |
||
| 303 | */ |
||
| 304 | public function action_sync() |
||
| 305 | { |
||
| 306 | View Code Duplication | if (!$this->cat_id) |
|
| 307 | { |
||
| 308 | trigger_error($this->language->lang('DIR_NO_CAT') . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
||
| 309 | } |
||
| 310 | |||
| 311 | @set_time_limit(0); |
||
| 312 | |||
| 313 | $sql = 'SELECT cat_name, cat_links |
||
| 314 | FROM ' . $this->categories_table . ' |
||
| 315 | WHERE cat_id = ' . (int) $this->cat_id; |
||
| 316 | $result = $this->db->sql_query($sql); |
||
| 317 | $row = $this->db->sql_fetchrow($result); |
||
| 318 | $this->db->sql_freeresult($result); |
||
| 319 | |||
| 320 | View Code Duplication | if (!$row) |
|
| 321 | { |
||
| 322 | trigger_error($this->language->lang('DIR_NO_CAT') . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
||
| 323 | } |
||
| 324 | |||
| 325 | $sql = 'SELECT MIN(link_id) as min_link_id, MAX(link_id) as max_link_id |
||
| 326 | FROM ' . $this->links_table . ' |
||
| 327 | WHERE link_cat = ' . (int) $this->cat_id . ' |
||
| 328 | AND link_active = 1'; |
||
| 329 | $result = $this->db->sql_query($sql); |
||
| 330 | $row2 = $this->db->sql_fetchrow($result); |
||
| 331 | $this->db->sql_freeresult($result); |
||
| 332 | |||
| 333 | // Typecast to int if there is no data available |
||
| 334 | $row2['min_link_id'] = (int) $row2['min_link_id']; |
||
| 335 | $row2['max_link_id'] = (int) $row2['max_link_id']; |
||
| 336 | |||
| 337 | $start = $this->request->variable('start', $row2['min_link_id']); |
||
| 338 | |||
| 339 | $batch_size = 200; |
||
| 340 | $end = $start + $batch_size; |
||
| 341 | |||
| 342 | // Sync all links in batch mode... |
||
| 343 | $this->_sync_dir_links($start, $end); |
||
| 344 | |||
| 345 | if ($end < $row2['max_link_id']) |
||
| 346 | { |
||
| 347 | // We really need to find a way of showing statistics... no progress here |
||
| 348 | $sql = 'SELECT COUNT(link_id) as num_links |
||
| 349 | FROM ' . $this->links_table . ' |
||
| 350 | WHERE link_cat = ' . (int) $this->cat_id . ' |
||
| 351 | AND link_active = 1 |
||
| 352 | AND link_id BETWEEN ' . $start . ' AND ' . $end; |
||
| 353 | $result = $this->db->sql_query($sql); |
||
| 354 | $links_done = $this->request->variable('links_done', 0) + (int) $this->db->sql_fetchfield('num_links'); |
||
| 355 | $this->db->sql_freeresult($result); |
||
| 356 | |||
| 357 | $start += $batch_size; |
||
| 358 | |||
| 359 | $url = $this->u_action . "&parent_id={$this->parent_id}&c=$this->cat_id&action=sync&start=$start&links_done=$links_done&total={$row['cat_links']}"; |
||
| 360 | |||
| 361 | meta_refresh(0, $url); |
||
| 362 | |||
| 363 | $this->template->assign_vars(array( |
||
| 364 | 'UA_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$links_done&total={$row['cat_links']}", |
||
| 365 | 'S_CONTINUE_SYNC' => true, |
||
| 366 | 'L_PROGRESS_EXPLAIN' => $this->language->lang('SYNC_IN_PROGRESS_EXPLAIN', $links_done, $row['cat_links'])) |
||
| 367 | ); |
||
| 368 | |||
| 369 | return; |
||
| 370 | } |
||
| 371 | |||
| 372 | $url = $this->u_action . "&parent_id={$this->parent_id}&c=$this->cat_id&action=sync_cat"; |
||
| 373 | meta_refresh(0, $url); |
||
| 374 | |||
| 375 | $this->template->assign_vars(array( |
||
| 376 | 'UA_PROGRESS_BAR' => $this->u_action . '&action=progress_bar', |
||
| 377 | 'S_CONTINUE_SYNC' => true, |
||
| 378 | 'L_PROGRESS_EXPLAIN' => $this->language->lang('SYNC_IN_PROGRESS_EXPLAIN', 0, $row['cat_links'])) |
||
| 379 | ); |
||
| 380 | |||
| 381 | return; |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Sync category data |
||
| 386 | * |
||
| 387 | * @return null |
||
| 388 | */ |
||
| 389 | public function action_sync_cat() |
||
| 390 | { |
||
| 391 | $sql = 'SELECT cat_name |
||
| 392 | FROM ' . $this->categories_table . ' |
||
| 393 | WHERE cat_id = ' . (int) $this->cat_id; |
||
| 394 | $result = $this->db->sql_query($sql); |
||
| 395 | $row = $this->db->sql_fetchrow($result); |
||
| 396 | $this->db->sql_freeresult($result); |
||
| 397 | |||
| 398 | View Code Duplication | if (!$row) |
|
| 399 | { |
||
| 400 | trigger_error($this->language->lang('DIR_NO_CAT') . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
||
| 401 | } |
||
| 402 | |||
| 403 | $this->_sync_dir_cat($this->cat_id); |
||
| 404 | |||
| 405 | $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_SYNC', time(), array($row['cat_name'])); |
||
| 406 | $this->cache->destroy('sql', $this->categories_table); |
||
| 407 | |||
| 408 | $this->template->assign_var('L_DIR_CAT_RESYNCED', $this->language->lang('DIR_CAT_RESYNCED', $row['cat_name'])); |
||
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Display categories page |
||
| 413 | * |
||
| 414 | * @return null |
||
| 415 | */ |
||
| 416 | public function display_cats() |
||
| 417 | { |
||
| 418 | // Default management page |
||
| 419 | if (!$this->parent_id) |
||
| 420 | { |
||
| 421 | $navigation = $this->language->lang('DIR_INDEX'); |
||
| 422 | } |
||
| 423 | else |
||
| 424 | { |
||
| 425 | $navigation = '<a href="' . $this->u_action . '">' . $this->language->lang('DIR_INDEX') . '</a>'; |
||
| 426 | |||
| 427 | $cats_nav = $this->nestedset_category->get_path_data($this->parent_id); |
||
| 428 | |||
| 429 | foreach ($cats_nav as $row) |
||
| 430 | { |
||
| 431 | if ($row['cat_id'] == $this->parent_id) |
||
| 432 | { |
||
| 433 | $navigation .= ' -> ' . $row['cat_name']; |
||
| 434 | } |
||
| 435 | else |
||
| 436 | { |
||
| 437 | $navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a>'; |
||
| 438 | } |
||
| 439 | } |
||
| 440 | } |
||
| 441 | |||
| 442 | // Jumpbox |
||
| 443 | $cat_box = $this->categorie->make_cat_select($this->parent_id); |
||
| 444 | |||
| 445 | if ($this->action == 'sync' || $this->action == 'sync_cat') |
||
| 446 | { |
||
| 447 | $this->template->assign_var('S_RESYNCED', true); |
||
| 448 | } |
||
| 449 | |||
| 450 | $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 |
||
| 451 | FROM ' . $this->categories_table . ' |
||
| 452 | WHERE parent_id = ' . (int) $this->parent_id . ' |
||
| 453 | ORDER BY left_id'; |
||
| 454 | $result = $this->db->sql_query($sql); |
||
| 455 | |||
| 456 | if ($row = $this->db->sql_fetchrow($result)) |
||
| 457 | { |
||
| 458 | do |
||
| 459 | { |
||
| 460 | $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="' . $this->language->lang('DIR_SUBCAT') . '" />' : '<img src="images/icon_folder.gif" alt="' . $this->language->lang('FOLDER') . '" />'; |
||
| 461 | |||
| 462 | $url = $this->u_action . "&parent_id=$this->parent_id&c={$row['cat_id']}"; |
||
| 463 | |||
| 464 | $this->template->assign_block_vars('cats', array( |
||
| 465 | 'FOLDER_IMAGE' => $folder_image, |
||
| 466 | 'CAT_IMAGE' => ($row['cat_icon']) ? '<img src="' . $this->get_img_path('icons', $row['cat_icon']) . '" alt="" />' : '', |
||
| 467 | 'CAT_NAME' => $row['cat_name'], |
||
| 468 | 'CAT_DESCRIPTION' => generate_text_for_display($row['cat_desc'], $row['cat_desc_uid'], $row['cat_desc_bitfield'], $row['cat_desc_options']), |
||
| 469 | 'CAT_LINKS' => $row['cat_links'], |
||
| 470 | |||
| 471 | 'U_CAT' => $this->u_action . '&parent_id=' . $row['cat_id'], |
||
| 472 | 'U_MOVE_UP' => $url . '&action=move_up', |
||
| 473 | 'U_MOVE_DOWN' => $url . '&action=move_down', |
||
| 474 | 'U_EDIT' => $url . '&action=edit', |
||
| 475 | 'U_DELETE' => $url . '&action=delete', |
||
| 476 | 'U_SYNC' => $url . '&action=sync') |
||
| 477 | ); |
||
| 478 | } |
||
| 479 | while ($row = $this->db->sql_fetchrow($result)); |
||
| 480 | } |
||
| 481 | else if ($this->parent_id) |
||
| 482 | { |
||
| 483 | $row = $this->_get_cat_info($this->parent_id); |
||
| 484 | |||
| 485 | $url = $this->u_action . '&parent_id=' . $this->parent_id . '&c=' . $row['cat_id']; |
||
| 486 | |||
| 487 | $this->template->assign_vars(array( |
||
| 488 | 'S_NO_CATS' => true, |
||
| 489 | |||
| 490 | 'U_EDIT' => $url . '&action=edit', |
||
| 491 | 'U_DELETE' => $url . '&action=delete', |
||
| 492 | 'U_SYNC' => $url . '&action=sync') |
||
| 493 | ); |
||
| 494 | } |
||
| 495 | $this->db->sql_freeresult($result); |
||
| 496 | |||
| 497 | $this->template->assign_vars(array( |
||
| 498 | 'ERROR_MSG' => (sizeof($this->errors)) ? implode('<br />', $this->errors) : '', |
||
| 499 | 'NAVIGATION' => $navigation, |
||
| 500 | 'CAT_BOX' => $cat_box, |
||
| 501 | 'U_SEL_ACTION' => $this->u_action, |
||
| 502 | 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id, |
||
| 503 | |||
| 504 | 'UA_PROGRESS_BAR' => $this->u_action . '&action=progress_bar', |
||
| 505 | )); |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Set page url |
||
| 510 | * |
||
| 511 | * @param string $u_action Custom form action |
||
| 512 | * @return null |
||
| 513 | * @access public |
||
| 514 | */ |
||
| 515 | public function set_page_url($u_action) |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Update cat table |
||
| 522 | * |
||
| 523 | * @return null |
||
| 524 | */ |
||
| 525 | public function update() |
||
| 526 | { |
||
| 527 | if (!check_form_key($this->form_key)) |
||
| 528 | { |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Check route |
||
| 623 | * |
||
| 624 | * @param string $route Route text |
||
| 625 | * @return null |
||
| 626 | * @access public |
||
| 627 | * @throws \phpbb\pages\exception\unexpected_value |
||
| 628 | */ |
||
| 629 | private function _check_route($route) |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Display form |
||
| 660 | * |
||
| 661 | * @param string $parents_list Drop-down list |
||
| 662 | * @return null |
||
| 663 | */ |
||
| 664 | private function _display_cat_form($parents_list) |
||
| 733 | |||
| 734 | /** |
||
| 735 | * Get category details |
||
| 736 | * |
||
| 737 | * @param int $cat_id The category ID |
||
| 738 | * @return array |
||
| 739 | */ |
||
| 740 | View Code Duplication | private function _get_cat_info($cat_id) |
|
| 756 | |||
| 757 | /** |
||
| 758 | * Update category data |
||
| 759 | * |
||
| 760 | * @return array |
||
| 761 | */ |
||
| 762 | private function _update_cat_data() |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Remove complete category |
||
| 858 | * |
||
| 859 | * @param string $action_links Action for categories links |
||
| 860 | * @param string $action_subcats Action for sub-categories |
||
| 861 | * @param int $links_to_id New category ID for links |
||
| 862 | * @param int $subcats_to_id New category ID for sub-categories |
||
| 863 | * @return array |
||
| 864 | */ |
||
| 865 | private function _delete_cat($action_links = 'delete', $action_subcats = 'delete', $links_to_id = 0, $subcats_to_id = 0) |
||
| 979 | |||
| 980 | /** |
||
| 981 | * Move category content from one to another forum |
||
| 982 | * |
||
| 983 | * @param int $from_id |
||
| 984 | * @param int $to_id |
||
| 985 | * @return null |
||
| 986 | */ |
||
| 987 | private function _move_cat_content($from_id, $to_id) |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Delete category content |
||
| 1003 | * |
||
| 1004 | * @return array |
||
| 1005 | */ |
||
| 1006 | private function _delete_cat_content() |
||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Update links counter |
||
| 1065 | * |
||
| 1066 | * @param int $cat_id The category ID |
||
| 1067 | * @return null |
||
| 1068 | */ |
||
| 1069 | private function _sync_dir_cat($cat_id) |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Update link data (note, vote, comment) |
||
| 1087 | * |
||
| 1088 | * @param int $start |
||
| 1089 | * @param int $stop |
||
| 1090 | * @return null |
||
| 1091 | */ |
||
| 1092 | private function _sync_dir_links($start, $stop) |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Display icons drop-down list |
||
| 1135 | * |
||
| 1136 | * @param string $icons_path |
||
| 1137 | * @param string $img_selected |
||
| 1138 | * @return string |
||
| 1139 | */ |
||
| 1140 | private function _get_dir_icon_list($icons_path, $img_selected) |
||
| 1170 | } |
||
| 1171 |