function delete_category($id, $delete_children) { $cids = array(); if ($delete_children === 'yes') { $category = new CODOF\Forum\Category(\DB::getPDO()); $cats_tree = $category->generate_tree($category->get_categories()); $children = $category->get_sub_categories($cats_tree, $id); $cids = get_cids($children); if ($cids !== NULL) { DB::table(PREFIX . 'codo_categories')->whereIn('cat_id', $cids)->delete(); } else { $cids = array(); } } else { DB::table(PREFIX . 'codo_categories')->where('cat_pid', '=', $id)->update(array('cat_pid' => 0)); } DB::table(PREFIX . 'codo_categories')->where('cat_id', $id)->delete(); //delete all topics if ($delete_children !== 'yes') { $ids = array($id); } else { $ids = array_merge(array($id), $cids); } DB::table(PREFIX . 'codo_topics')->whereIn('cat_id', $ids)->delete(); DB::table(PREFIX . 'codo_unread_topics')->whereIn('cat_id', $ids)->delete(); DB::table(PREFIX . 'codo_unread_categories')->whereIn('cat_id', $ids)->delete(); //DB::table(PREFIX . 'codo_tags AS g') // ->join(PREFIX . 'codo_topics AS t', 't.topic_id', '=', 'g.topic_id') // ->whereIn('t.cat_id', $ids)->delete(); $q = 'DELETE codo_tags FROM ' . PREFIX . 'codo_tags ' . ' LEFT JOIN ' . PREFIX . 'codo_topics ON ' . PREFIX . 'codo_tags.topic_id=' . PREFIX . 'codo_topics.topic_id ' . ' WHERE ' . PREFIX . 'codo_topics.cat_id IN (' . implode(',', $ids) . ')'; \DB::delete($q); DB::table(PREFIX . 'codo_notify_subscribers')->whereIn('cid', $ids)->delete(); DB::table(PREFIX . 'codo_permissions')->whereIn('cid', $ids)->delete(); $qry = 'UPDATE ' . PREFIX . 'codo_users AS u,' . PREFIX . 'codo_posts As p SET no_posts=no_posts-' . '(SELECT COUNT(post_id) FROM codo_posts WHERE cat_id=' . $id . ' AND post_status <> 0 AND uid=u.id) WHERE p.cat_id=' . $id . ' AND u.id=p.uid'; DB::getPDO()->query($qry); DB::table(PREFIX . 'codo_posts')->whereIn('cat_id', $ids)->delete(); }
public function category($catid, $page) { $cat = new \CODOF\Forum\Category($this->db); $cat_info = $cat->get_cat_info($catid); $cid = $cat_info['cat_id']; $user = \CODOF\User\User::get(); if (!$cat_info) { $this->view = 'not_found'; return; } if (!$user->can('view category', $cid)) { $this->view = 'access_denied'; return; } $cats = $cat->get_categories(); $cats_tree = $cat->generate_tree($cats); $sub_cats = $cat->get_sub_categories($cats_tree, $cid); $this->smarty->assign('parents', $cat->find_parents($cats, $cid)); $this->smarty->assign('cats', $cats_tree); $this->smarty->assign('sub_cats', $sub_cats); //$num_results = \CODOF\Util::get_opt("num_posts_cat_topics"); $subscriber = new \CODOF\Forum\Notification\Subscriber(); $this->smarty->assign('no_followers', $subscriber->followersOfCategory($cid)); if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) { $this->smarty->assign('my_subscription_type', $subscriber->levelForCategory($cid)); } $api = new Ajax\forum\category(); $num_topics_page = \CODOF\Util::get_opt('num_posts_cat_topics'); $data = $api->get_topics($cid, $page); $this->smarty->assign('load_more_hidden', false); if ($page * $num_topics_page >= $cat_info['no_topics']) { $this->smarty->assign('load_more_hidden', true); } if (isset($_GET['search']) && $_GET['search'] != null) { //$search_conds = json_decode($_GET['search']); $search_data = $_GET['search']; } else { $search_data = '{}'; } $user = \CODOF\User\User::get(); $this->smarty->assign('new_topics', $data['new_topics']); $this->smarty->assign('can_create_topic', $cat->canCreateTopicIn($cid)); $this->smarty->assign('can_search', $user->can('use search')); $this->smarty->assign('search_data', $search_data); $this->smarty->assign('topics', \CODOF\HB\Render::tpl('forum/category', $data)); $this->smarty->assign('cat_info', $cat_info); $this->smarty->assign('cat_alias', $catid); $this->smarty->assign('curr_page', $page); $this->smarty->assign('num_posts_per_page', $num_topics_page); $this->assign_editor_vars(); $no_topics = $no_posts = ' -- '; if ($user->can('view all topics', $cid)) { $no_topics = \CODOF\Util::abbrev_no($cat_info['no_topics'], 2); $no_posts = \CODOF\Util::abbrev_no($cat_info['no_posts'], 2); } $this->smarty->assign('no_topics', $no_topics); $this->smarty->assign('no_posts', $no_posts); $this->css_files = array('category', 'editor', 'jquery.textcomplete'); $this->js_files = array(array('category/category.js', array('type' => 'defer')), array('category/jquery.easing.1.3.js', array('type' => 'defer')), array('bootstrap-tagsinput.js', array('type' => 'defer')), array('bootstrap-slider.js', array('type' => 'defer'))); $this->js_files = array_merge($this->js_files, $cat->get_js_editor_files()); $this->smarty->assign('can_make_sticky', $user->can('make sticky')); $this->view = 'forum/category'; $this->smarty->assign('can_make_sticky', $user->can('make sticky')); $this->smarty->assign('can_add_tags', $user->can('add tags')); \CODOF\Hook::call('on_category_view', array($cat_info)); \CODOF\Store::set('rel:canonical_page', '/'); \CODOF\Store::set('sub_title', $cat_info['cat_name']); \CODOF\Store::set('og:url', RURI . 'category/' . $catid); \CODOF\Store::set('og:desc', $cat_info['cat_description']); \CODOF\Store::set('og:image', DURI . CAT_IMGS . $cat_info['cat_img']); }