$remove_action = $remove_action == 'move_all' ? 'move_all' : 'remove_all'; try { $article_infos = $db_querier->select_single_row(PREFIX . "wiki_articles", array('encoded_title', 'id_cat', 'auth'), 'WHERE id = :id', array('id' => $del_to_remove)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } $general_auth = empty($article_infos['auth']) ? true : false; $article_auth = !empty($article_infos['auth']) ? unserialize($article_infos['auth']) : array(); if (!((!$general_auth || AppContext::get_current_user()->check_auth($config->get_authorizations(), WIKI_DELETE)) && ($general_auth || AppContext::get_current_user()->check_auth($article_auth, WIKI_DELETE)))) { $error_controller = PHPBoostErrors::user_not_authorized(); DispatchManager::redirect($error_controller); } $sub_cats = array(); //On fait un tableau contenant la liste des sous catégories de cette catégorie wiki_find_subcats($sub_cats, $article_infos['id_cat']); $sub_cats[] = $article_infos['id_cat']; //On rajoute la catégorie que l'on supprime if (empty($article_infos['encoded_title'])) { //si l'article n'existe pas on redirige vers l'index AppContext::get_response()->redirect('/wiki/' . url('wiki.php', '', '&')); } if ($remove_action == 'move_all') { //Si la nouvelle catégorie n'est pas une catégorie if (!array_key_exists($report_cat, $categories) && $report_cat > 0) { AppContext::get_response()->redirect('/wiki/' . url('property.php?del=' . $del_to_remove . '&error=e_not_a_cat#message_helper', '', '&')); } //Si on ne la déplace pas dans une de ses catégories filles if ($report_cat > 0 && in_array($report_cat, $sub_cats) || $report_cat == $article_infos['id_cat']) { //Si on veut reporter dans une catégorie parente AppContext::get_response()->redirect('/wiki/' . url('property.php?del=' . $del_to_remove . '&error=e_cat_contains_cat#message_helper', '', '&'));
function wiki_find_subcats(&$array, $id_cat) { global $_WIKI_CATS; foreach ($_WIKI_CATS as $key => $value) { if ($value['id_parent'] == $id_cat) { $array[] = $key; wiki_find_subcats($array, $key); } } }
function wiki_find_subcats(&$array, $id_cat) { //On parcourt les catégories et on détermine les catégories filles foreach (WikiCategoriesCache::load()->get_categories() as $key => $value) { if ($value['id_parent'] == $id_cat) { $array[] = $key; //On rappelle la fonction pour la catégorie fille wiki_find_subcats($array, $key); } } }