function sp_save_edited_topic() { global $spThisUser; $topicid = sp_esc_int($_POST['tid']); $topicname = sp_filter_title_save($_POST['topicname'], SFTOPICS, 'topic_name'); if (empty($topicname)) { sp_notify(SPFAILURE, sp_text('Update failed')); return; } # grab topic to check $topicrecord = spdb_table(SFTOPICS, "topic_id={$topicid}", 'row'); if (empty($_POST['topicslug']) && $topicname == $topicrecord->topic_name) { $topicslug = $topicrecord->topic_slug; } else { $topicslug = sp_esc_str($_POST['topicslug']); } if (empty($_POST['topicslug'])) { $topicslug = sp_create_slug($topicname, true, SFTOPICS, 'topic_slug'); } if (empty($topicslug)) { $topicslug = 'topic-' . $topicid; } $sql = 'UPDATE ' . SFTOPICS . ' SET topic_name="' . $topicname . '", topic_slug="' . $topicslug . '" WHERE topic_id=' . sp_esc_int($topicid); if (spdb_query($sql) == false) { sp_notify(SPFAILURE, sp_text('Update failed')); } else { do_action('sph_topic_title_edited', $topicid, $topicname, $spThisUser->ID); sp_notify(SPSUCCESS, sp_text('Updated topic title saved')); # set up some data for notifications $forumslug = spdb_table(SFFORUMS, "forum_id={$topicrecord->forum_id}", 'forum_slug'); $link = sp_build_url($forumslug, $topicslug, 1); # notify admins/mods of edit $users = spdb_select('set', 'SELECT user_id, admin_options FROM ' . SFMEMBERS . " WHERE admin=1 OR moderator=1"); if ($users) { $time = time() + 7 * 24 * 60 * 60; $text = sp_text('A user has edit the topic title of'); foreach ($users as $user) { $options = unserialize($user->admin_options); if ($options['notify-edited'] && $spThisUser->ID != $user->user_id) { # dont notify self $nData = array(); $nData['user_id'] = $user->user_id; $nData['guest_email'] = ''; $nData['post_id'] = 0; $nData['link'] = $link; $nData['link_text'] = $topicname; $nData['message'] = $text; $nData['expires'] = $time; # 7 days; 24 hours; 60 mins; 60secs sp_add_notice($nData); } } } # notify author of change $sfadminsettings = sp_get_option('sfadminsettings'); if ($sfadminsettings['editnotice'] && $spThisUser->ID != $topicrecord->user_id) { $nData = array(); $nData['user_id'] = $topicrecord->user_id; $nData['guest_email'] = ''; $nData['post_id'] = 0; $nData['link'] = $link; $nData['link_text'] = $topicname; $nData['message'] = sp_text('The topic title was edited for your topic'); $nData['expires'] = time() + 30 * 24 * 60 * 60; # 30 days; 24 hours; 60 mins; 60secs sp_add_notice($nData); } } # try and update unternal links in posts with new slug if ($topicrecord->topic_slug != $topicslug) { sp_update_post_urls($topicrecord->topic_slug, $topicslug); } }
function spa_save_forums_merge() { check_admin_referer('forum-adminform_mergeforums', 'forum-adminform_mergeforums'); $source = $target = 0; if (isset($_POST['source'])) { $source = (int) $_POST['source']; } if (isset($_POST['target'])) { $target = (int) $_POST['target']; } if (empty($source) || empty($target) || $source == $target) { return spa_text('Selections invalid'); } $sourceForum = spdb_table(SFFORUMS, "forum_id={$source}", 'row'); $targetForum = spdb_table(SFFORUMS, "forum_id={$target}", 'row'); # 1 - Move sub-forums if (!empty($sourceForum->children)) { spdb_query("UPDATE " . SFFORUMS . " SET parent={$target} WHERE parent={$source}"); } # 2 - Change forum ids in requirted tables spdb_query("UPDATE " . SFTOPICS . " SET forum_id={$target} WHERE forum_id={$source}"); spdb_query("UPDATE " . SFPOSTS . " SET forum_id={$target} WHERE forum_id={$source}"); spdb_query("UPDATE " . SFTRACK . " SET forum_id={$target} WHERE forum_id={$source}"); spdb_query("UPDATE " . SFWAITING . " SET forum_id={$target} WHERE forum_id={$source}"); # 3 - Delete forum id rows in following tables spdb_query("DELETE FROM " . SFPERMISSIONS . " WHERE forum_id={$source}"); # 4 - Run clean up operations sp_reset_memberships(); sp_reset_auths(); sp_update_post_urls($sourceForum->forum_slug, $targetForum->forum_slug); sp_build_forum_index($target); # 5 - Delete the old forum record spdb_query("DELETE FROM " . SFFORUMS . " WHERE forum_id={$source}"); spa_clean_forum_children(); spa_resequence_forums($targetForum->group_id, 0); # 6 - Update Sitemap do_action('sm_rebuild'); # 7 - Update Stats do_action('sph_stats_cron'); # 8 - Let plugins in on the secret do_action('sph_merge_forums', $source, $target); # clear out group cache tpo enable change_user sp_flush_cache('group'); $mess = spa_text('Forum Merge Completed'); return $mess; }