function forum_delete($fid) { // 把板块下所有的帖子都查找出来,此处数据量大可能会超时,所以不要删除帖子特别多的板块 $threadlist = db_find("SELECT tid, uid FROM `bbs_thread` WHERE fid='{$fid}'"); foreach ($threadlist as $thread) { thread_delete($thread['tid']); } $r = forum__delete($fid); forum_list_cache_delete(); return $r; }
function user_delete($uid) { global $conf; // 清理用户资源 $threadlist = mythread_find_by_uid($uid, 1, 1000); foreach ($threadlist as $thread) { thread_delete($thread['tid']); } $r = user__delete($uid); $conf['cache']['type'] != 'mysql' and cache_delete("user-{$uid}"); // 全站统计 runtime_set('users-', 1); return $r; }
} $post = post_read($pid); empty($post) and message(-1, '帖子不存在:' . $pid); $tid = $post['tid']; $thread = thread_read($tid); empty($thread) and message(-1, '主题不存在:' . $tid); $fid = $thread['fid']; $forum = forum_read($fid); empty($forum) and message(-1, '板块不存在:' . $fid); $isfirst = $post['isfirst']; !forum_access_user($fid, $gid, 'allowpost') and message(-1, '您(' . $user['groupname'] . ')无权限在此版块回帖'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); !$allowdelete and !$post['allowdelete'] and message(-1, '无权删除该帖'); if ($isfirst) { // 清除所有的回复。喜欢。还有相关资源 thread_delete($tid); } else { post_delete($pid); post_list_cache_delete($tid); } message(0, '删除成功'); // 接受 base64 文件上传 } elseif ($action == 'upload') { // 允许的文件后缀名 $types = (include './conf/attach.conf.php'); $allowtypes = $types['all']; empty($uid) and message(-1, '游客不允许上传文件'); empty($group['allowattach']) and $gid != 1 and message(-1, '您无权上传'); $conf['ipaccess_on'] and !ipaccess_check($longip, 'attachs') and message(-1, '您的 IP 今日上传附件数达到上限,请明天再来。'); $conf['ipaccess_on'] and !ipaccess_check($longip, 'attachsizes') and message(-1, '您的 IP 今日上传附件尺寸达到上限,请明天再来。'); $isimage = param(2, 0);
/** * Used to load the requested page from POST or GET * @global type $input */ function load_page() { global $input; $action = $input['action']; $redraw = false; // // Actions // // Controller goes here switch ($action) { // The user clicked on an album, we display its content to them // Display the help page case 'view_help': view_help(); break; case 'view_settings': view_settings(); break; // In case we want to log out // In case we want to log out case 'logout': user_logout(); break; // The only case when we could possibly arrive here with a session created // and a "login" action is when the user refreshed the page. In that case, // we redraw the page with the last information saved in the session variables. // The only case when we could possibly arrive here with a session created // and a "login" action is when the user refreshed the page. In that case, // we redraw the page with the last information saved in the session variables. case 'login': redraw_page(); break; case 'anonymous_login': anonymous_login(); break; case 'admin_mode_update': admin_mode_update(); break; case 'view_album_assets': view_album_assets(); break; case 'view_asset_details': view_asset_details(); break; case 'view_asset_bookmark': view_asset_bookmark(); break; case 'search_bookmark': bookmarks_search(); break; case 'sort_asset_bookmark': bookmarks_sort(); break; case 'add_asset_bookmark': bookmark_add(); break; case 'add_asset_thread': thread_add(); break; case 'add_thread_comment': comment_add(); break; case 'add_thread_comment_answer': comment_add_reply(); break; case 'update_thread_comment': comment_edit(); break; case 'update_asset_thread': thread_edit(); break; case 'thread_details_view': thread_details_update(); break; case 'delete_asset_thread': thread_delete(); break; case 'delete_thread_comment': comment_delete(); break; case 'edit_settings': preferences_update(); break; case 'edit_asset_meta': asset_edit_meta(); break; case 'vote': vote_add(); break; case 'approve': comment_edit_approval(); break; case 'threads_list_view': threads_list_update(); break; case 'copy_bookmark': bookmark_copy(); break; case 'share_popup': share_popup(); break; case 'bookmark_popup': bookmark_popup(); break; case 'bookmarks_popup': bookmarks_popup(); break; case 'remove_asset_bookmark': bookmark_delete(); break; case 'remove_asset_bookmarks': bookmarks_delete_all(); break; case 'view_import': view_import(); break; case 'upload_bookmarks': bookmarks_upload(); break; case 'import_bookmarks': bookmarks_import(); break; case 'export_bookmarks': bookmarks_export(); break; case 'export_album_bookmarks': bookmarks_export_all(); break; case 'export_asset_bookmarks': bookmarks_export_all(true); break; case 'delete_bookmarks': bookmarks_delete(); break; case 'move_album_token': album_token_move(); break; case 'delete_album_token': album_token_delete(); break; case 'client_trace': client_trace(); break; // No action selected: we choose to display the homepage again // No action selected: we choose to display the homepage again default: // TODO: check session var here view_main(); } }
if (isset($_POST['t_to_uid_in_thread']) && is_numeric($_POST['t_to_uid_in_thread']) && isset($_POST['deluser_con']) && $_POST['deluser_con'] == "Y") { $del_user_uid = $_POST['t_to_uid_in_thread']; if ($user_logon = user_get_logon($del_user_uid)) { if (thread_delete_by_user($tid, $del_user_uid)) { post_add_edit_text($tid, 1); admin_add_log_entry(DELETE_USER_THREAD_POSTS, array($tid, $thread_data['TITLE'], $user_logon)); } else { $error_msg_array[] = sprintf(gettext("Failed to delete posts by selected user"), $user_logon); $valid = false; } } } if (isset($_POST['delete_thread']) && in_array($_POST['delete_thread'], $thread_delete_valid_types)) { if (isset($_POST['delete_thread_confirm']) && $_POST['delete_thread_confirm'] == "Y") { $delete_thread = $_POST['delete_thread']; if (thread_delete($tid, $delete_thread)) { post_add_edit_text($tid, 1); admin_add_log_entry(DELETE_THREAD, array($tid, $thread_data['TITLE'])); html_draw_top(sprintf('title=%s', gettext("Delete Thread")), 'class=window_title'); html_display_msg(gettext("Delete Thread"), gettext("Thread was successfully deleted"), 'discussion.php', 'get', array('continue' => gettext("Continue")), false, html_get_frame_name('main'), 'center'); html_draw_bottom(); exit; } else { $error_msg_array[] = gettext("Failed to delete thread."); $valid = false; } } } if (isset($_POST['undelete_thread']) && $_POST['undelete_thread'] == "Y") { if (isset($_POST['undelete_thread_confirm']) && $_POST['undelete_thread_confirm'] == "Y") { if (thread_undelete($tid)) {
extract($r); // node_id node_number $another_node_name = 'anothertestnode'; $another_node_title = 'Another test node'; $r = thread_create_node($lang, $user_id, $thread_id, $another_node_name, $another_node_title, 1); dump($r); $another_node_id = $r['node_id']; $node_name = 'testnode'; $node_title = 'Test node'; $node_abstract = 'The test node.'; $node_cloud = 'test node'; $node_image = '/files/images/testnode.png'; $r = thread_set_node($lang, $thread_id, $node_id, $node_name, $node_title, $node_abstract, $node_cloud, $node_image, false, false, false, false, true, true, true, true, true); dump($r); $r = thread_get_node($lang, $thread_id, $node_id); dump($r); $r = thread_node_id($thread_id, false); dump($r); $r = thread_node_id($thread_id, $node_id); dump($r); $r = thread_node_id($thread_id, $node_name, $lang); dump($r); $r = thread_node_next($lang, $thread_id, $another_node_id); dump($r); $r = thread_node_prev($lang, $thread_id, $node_id); dump($r); $r = thread_delete_node($thread_id, $another_node_id); dump($r); $r = thread_delete($thread_id); dump($r); echo sprintf('%.4f', microtime(true) - $msecs), PHP_EOL;
function threadeditall($lang, $clang) { global $supported_threads, $with_toolbar; if (!user_has_role('writer')) { return run('error/unauthorized', $lang); } $confirmed = false; $action = 'init'; if (isset($_POST['thread_create'])) { $action = 'create'; } else { if (isset($_POST['thread_delete'])) { $action = 'delete'; } else { if (isset($_POST['thread_confirmdelete'])) { $action = 'delete'; $confirmed = true; } else { if (isset($_POST['threadlist_reorder'])) { $action = 'reorder'; } } } } $new_thread_name = $new_thread_title = $new_thread_type = $new_thread_number = false; $old_thread_number = false; $p = false; switch ($action) { case 'init': case 'reset': break; case 'create': case 'delete': case 'reorder': if (isset($_POST['new_thread_title'])) { $new_thread_title = readarg($_POST['new_thread_title']); } if ($new_thread_title) { $new_thread_name = strtofname($new_thread_title); } if (isset($_POST['new_thread_number'])) { $new_thread_number = readarg($_POST['new_thread_number']); } if (isset($_POST['new_thread_type'])) { $new_thread_type = readarg($_POST['new_thread_type']); } if (isset($_POST['old_thread_number'])) { $old_thread_number = readarg($_POST['old_thread_number']); } if (isset($_POST['p'])) { $p = $_POST['p']; // DON'T readarg! } default: break; } $thread_list = array(); $r = thread_list($clang, false, false); if (!$r or count($r) != count($p)) { $p = false; } if ($r) { $pos = 1; $thread_url = url('threadedit', $lang); foreach ($r as $b) { $b['thread_url'] = $thread_url . '/' . $b['thread_id']; $b['pos'] = $p ? $p[$pos] : $pos; $thread_list[$pos] = $b; $pos++; } } $missing_new_thread_title = false; $missing_new_thread_name = false; $bad_new_thread_name = false; $missing_new_thread_type = false; $bad_new_thread_type = false; $bad_new_thread_number = false; $missing_old_thread_number = false; $bad_old_thread_number = false; switch ($action) { case 'create': if (!$new_thread_title) { $missing_new_thread_title = true; } if (!$new_thread_name) { $missing_new_thread_name = true; } else { if (!preg_match('#^[\\w-]{2,}$#', $new_thread_name)) { $bad_new_thread_name = true; } } if (!$new_thread_number) { $bad_new_thread_number = false; } else { if (!is_numeric($new_thread_number)) { $bad_new_thread_number = true; } else { if ($new_thread_number < 1 or $new_thread_number > count($thread_list) + 1) { $bad_new_thread_number = true; } } } if (!$new_thread_type) { $missing_new_thread_type = true; } else { if (!in_array($new_thread_type, $supported_threads)) { $bad_new_thread_type = true; } } break; case 'delete': if (!$old_thread_number) { $missing_old_thread_number = true; } else { if (!is_numeric($old_thread_number)) { $bad_old_thread_number = true; } else { if ($old_thread_number < 1 or $old_thread_number > count($thread_list)) { $bad_old_thread_number = true; } } } break; default: break; } $confirm_delete_thread = false; switch ($action) { case 'create': if ($missing_new_thread_title or $missing_new_thread_name or $bad_new_thread_name or $bad_new_thread_number or $missing_new_thread_type or $bad_new_thread_type) { break; } $user_id = user_profile('id'); $np = thread_create($clang, $user_id, $new_thread_name, $new_thread_title, $new_thread_type, $new_thread_number); if (!$np) { break; } extract($np); /* thread_id thread_number */ $thread_title = $new_thread_title; $thread_url = url('threadedit', $lang) . '/' . $thread_id; $pos = $thread_number; if ($thread_list) { foreach ($thread_list as &$tr) { if ($tr['thread_number'] >= $pos) { $tr['thread_number']++; } if ($tr['pos'] >= $pos) { $tr['pos']++; } } array_splice($thread_list, $pos - 1, 0, array(compact('thread_id', 'thread_title', 'thread_number', 'thread_url', 'pos'))); array_multisort(range(1, count($thread_list)), $thread_list); } else { $pos = 1; $thread_list = array($pos => compact('thread_id', 'thread_title', 'thread_number', 'thread_url', 'pos')); } break; case 'delete': if ($missing_old_thread_number or $bad_old_thread_number) { break; } if (!$confirmed) { $confirm_delete_thread = true; break; } $thread_id = $thread_list[$old_thread_number]['thread_id']; $r = thread_delete($thread_id); if (!$r) { break; } unset($thread_list[$old_thread_number]); foreach ($thread_list as &$b) { if ($b['pos'] >= $old_thread_number) { $b['pos']--; } } $old_thread_number = false; break; case 'reorder': if (!$p) { break; } $neworder = range(1, count($p)); array_multisort($p, SORT_NUMERIC, $neworder); $number = 1; $nl = array(); foreach ($neworder as $i) { $tr =& $thread_list[$i]; if ($tr['thread_number'] != $number) { thread_set_number($tr['thread_id'], $number); $tr['thread_number'] = $number; } $tr['pos'] = $number; $nl[$number++] = $tr; } $thread_list = $nl; break; default: break; } head('title', translate('threadall:title', $lang)); head('description', false); head('keywords', false); head('robots', 'noindex, nofollow'); $site_title = translate('title', $lang); $view = url('thread', $clang) . '?' . 'slang=' . $lang; $banner = build('banner', $lang, $with_toolbar ? compact('headline') : compact('headline', 'view')); $scroll = true; $toolbar = $with_toolbar ? build('toolbar', $lang, compact('view', 'scroll')) : false; $inlanguages = view('inlanguages', false, compact('clang')); $errors = compact('missing_new_thread_title', 'bad_new_thread_title', 'missing_new_thread_name', 'missing_new_thread_type', 'bad_new_thread_name', 'bad_new_thread_type', 'bad_new_thread_number', 'missing_old_thread_number', 'bad_old_thread_number'); $content = view('editing/threadeditall', $lang, compact('clang', 'site_title', 'inlanguages', 'supported_threads', 'thread_list', 'new_thread_title', 'new_thread_type', 'new_thread_number', 'old_thread_number', 'confirm_delete_thread', 'errors')); $output = layout('editing', compact('toolbar', 'banner', 'content')); return $output; }