コード例 #1
0
ファイル: Post.php プロジェクト: featherbb/featherbb
 public function handle_deletion($is_topic_post, $id, $tid, $fid)
 {
     Container::get('hooks')->fire('model.post.handle_deletion_start', $is_topic_post, $id, $tid, $fid);
     if ($is_topic_post) {
         Container::get('hooks')->fire('model.post.model.topic.delete', $tid, $fid);
         // Delete the topic and all of its posts
         Topic::delete($tid);
         Forum::update($fid);
         return Router::redirect(Router::pathFor('Forum', array('id' => $fid)), __('Topic del redirect'));
     } else {
         Container::get('hooks')->fire('model.post.handle_deletion', $tid, $fid, $id);
         // Delete just this one post
         $this->delete($id, $tid);
         Forum::update($fid);
         // Redirect towards the previous post
         $post = DB::for_table('posts')->select('id')->where('topic_id', $tid)->where_lt('id', $id)->order_by_desc('id');
         $post = Container::get('hooks')->fireDB('model.post.handle_deletion_query', $post);
         $post = $post->find_one();
         return Router::redirect(Router::pathFor('viewPost', ['pid' => $post['id']]) . '#p' . $post['id'], __('Post del redirect'));
     }
 }
コード例 #2
0
ファイル: Users.php プロジェクト: featherbb/featherbb
 public function delete_users()
 {
     if (Input::post('users')) {
         $user_ids = is_array(Input::post('users')) ? array_keys(Input::post('users')) : explode(',', Input::post('users'));
         $user_ids = array_map('intval', $user_ids);
         // Delete invalid IDs
         $user_ids = array_diff($user_ids, array(0, 1));
     } else {
         $user_ids = array();
     }
     $user_ids = Container::get('hooks')->fire('model.admin.model.users.delete_users.user_ids', $user_ids);
     if (empty($user_ids)) {
         throw new Error(__('No users selected'), 404);
     }
     // Are we trying to delete any admins?
     $is_admin = DB::for_table('users')->where_in('id', $user_ids)->where('group_id', ForumEnv::get('FEATHER_ADMIN'))->find_one();
     if ($is_admin) {
         throw new Error(__('No delete admins message'), 403);
     }
     if (Input::post('delete_users_comply')) {
         // Fetch user groups
         $user_groups = array();
         $result['select'] = array('id', 'group_id');
         $result = DB::for_table('users')->select_many($result['select'])->where_in('id', $user_ids);
         $result = Container::get('hooks')->fireDB('model.admin.model.admin.users.delete_users.user_groups_query', $result);
         $result = $result->find_many();
         foreach ($result as $cur_user) {
             if (!isset($user_groups[$cur_user['group_id']])) {
                 $user_groups[$cur_user['group_id']] = array();
             }
             $user_groups[$cur_user['group_id']][] = $cur_user['id'];
         }
         // Are any users moderators?
         $group_ids = array_keys($user_groups);
         $select_fetch_user_mods = array('g_id', 'g_moderator');
         $result = DB::for_table('groups')->select_many($select_fetch_user_mods)->where_in('g_id', $group_ids)->find_many();
         foreach ($result as $cur_group) {
             if ($cur_group['g_moderator'] == '0') {
                 unset($user_groups[$cur_group['g_id']]);
             }
         }
         $user_groups = Container::get('hooks')->fire('model.admin.model.users.delete_users.user_groups', $user_groups);
         // Fetch forum list and clean up their moderator list
         $select_mods = array('id', 'moderators');
         $result = DB::for_table('forums')->select_many($select_mods)->find_many();
         foreach ($result as $cur_forum) {
             $cur_moderators = $cur_forum['moderators'] != '' ? unserialize($cur_forum['moderators']) : array();
             foreach ($user_groups as $group_users) {
                 $cur_moderators = array_diff($cur_moderators, $group_users);
             }
             if (!empty($cur_moderators)) {
                 DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set('moderators', serialize($cur_moderators))->save();
             } else {
                 DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set_expr('moderators', 'NULL')->save();
             }
         }
         // Delete any subscriptions
         DB::for_table('topic_subscriptions')->where_in('user_id', $user_ids)->delete_many();
         DB::for_table('forum_subscriptions')->where_in('user_id', $user_ids)->delete_many();
         // Remove them from the online list (if they happen to be logged in)
         DB::for_table('online')->where_in('user_id', $user_ids)->delete_many();
         // Should we delete all posts made by these users?
         if (Input::post('delete_posts')) {
             @set_time_limit(0);
             // Find all posts made by this user
             $select_user_posts = array('p.id', 'p.topic_id', 't.forum_id');
             $result = DB::for_table('posts')->table_alias('p')->select_many($select_user_posts)->inner_join('topics', array('t.id', '=', 'p.topic_id'), 't')->inner_join('forums', array('f.id', '=', 't.forum_id'), 'f')->where('p.poster_id', $user_ids);
             $result = Container::get('hooks')->fireDB('model.admin.model.admin.users.delete_users.user_posts_query', $result);
             $result = $result->find_many();
             if ($result) {
                 foreach ($result as $cur_post) {
                     // Determine whether this post is the "topic post" or not
                     $result2 = DB::for_table('posts')->where('topic_id', $cur_post['topic_id'])->order_by('posted')->find_one_col('id');
                     if ($result2 == $cur_post['id']) {
                         \FeatherBB\Model\Topic::delete($cur_post['topic_id']);
                     } else {
                         \FeatherBB\Model\Post::delete($cur_post['id'], $cur_post['topic_id']);
                     }
                     \FeatherBB\Model\Forum::update($cur_post['forum_id']);
                 }
             }
         } else {
             // Set all their posts to guest
             DB::for_table('posts')->where_in('poster_id', $user_ids)->update_many('poster_id', '1');
         }
         // Delete the users
         DB::for_table('users')->where_in('id', $user_ids)->delete_many();
         // Delete user avatars
         $userProfile = new \FeatherBB\Model\Profile();
         foreach ($user_ids as $user_id) {
             $userProfile->delete_avatar($user_id);
         }
         // Regenerate the users info cache
         if (!Container::get('cache')->isCached('users_info')) {
             Container::get('cache')->store('users_info', Cache::get_users_info());
         }
         $stats = Container::get('cache')->retrieve('users_info');
         return Router::redirect(Router::pathFor('adminUsers'), __('Users delete redirect'));
     }
     return $user_ids;
 }