View Single Post
  #124  
Old 12-09-2004, 05:20 PM
sv1cec sv1cec is offline
 
Join Date: May 2004
Location: Athens, Greece
Posts: 2,091
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, here is the code I came up with, it is mostly based on the postings.php code, with some mods to make it suitable for more than two threads.

PHP Code:
        case 'merge':

            if (!
can_moderate($vars['forumid'], 'canmanagethreads'))
            {
                
print_no_permission();
            }
            if (!
is_array($vars['threads']))
            {
                eval(
print_standard_error('error_invalidid'));
            }
            if (empty(
$_POST['do']))
            {
                
define('PRINT_TPL''inline_merge_thread');
            }
            else
            {
            
toss_cookies();
                    
            
$sqlthreads implode(', '$vars['threads']);
            
            
$firstpost $DB_site->query_first("SELECT * FROM " TABLE_PREFIX "post WHERE threadid IN ($sqlthreads) ORDER BY dateline ASC");
            
$notes=$firstpost['notes'];
            
$thrd_firstpost=$firstpost['postid'];
            
$oldtitle=$firstpost['title'];
            
$notes=$firstpost['notes'];
            
$title=$_POST['title'];
            
$threadid=$firstpost['threadid'];
            
$newnotes sprintf('Thread merged from other threads by %1$s on %2$s at %3$s via Moderation Tool.'$bbuserinfo['username'], vbdate($vboptions['dateformat'], TIMENOW), vbdate($vboptions['timeformat'], TIMENOW));
            
$newnotes .= $notes;

            if (
$title=='')
            {
                
$title=$oldtitle;
            }

            foreach (
$vars['threads'] AS $mergethreadid)
            {
                if (
$mergethreadid!=$threadid)
                {
                    
$mergethreadid verify_id('thread'$mergethreadid);
                    
$mergethreadinfo fetch_threadinfo($mergethreadid);
                    
$mergeforuminfo fetch_foruminfo($mergethreadinfo['forumid']);
                
                    if (!
$mergethreadinfo['visible'] OR $mergethreadinfo['isdeleted'] OR $mergethreadid == $threadid)
                    {
                        eval(
print_standard_error('error_invalidid'));
                    }
                
                    
// check forum permissions for the merge forum
                    
$mergeforumperms fetch_permissions($mergethreadinfo['forumid']);
                    if (!(
$mergeforumperms CANVIEW) OR !can_moderate($mergethreadinfo['forumid'], 'canmanagethreads'))
                    {
                        
print_no_permission();
                    }
                
                    
// check if there is a forum password and if so, ensure the user has it set
                    
verify_forum_password($mergeforuminfo['forumid'], $mergeforuminfo['password']);
                    
$mrgthrd_firstpost $DB_site->query_first("
                        SELECT postid
                        FROM " 
TABLE_PREFIX "post
                        WHERE threadid = 
$mergethreadinfo[threadid]
                        ORDER BY dateline ASC
                    "
);
                
                    
// sort out polls
                    
$pollcode '';
                    if (
$mergethreadinfo['pollid'] != 0)
                    { 
// merge thread has poll ...
                        
if ($threadinfo['pollid'] == 0)
                        { 
// ... and original thread doesn't
                            
$pollcode ',pollid = ' $mergethreadinfo['pollid'];
                        }
                        else
                        { 
// ... and original does
                            // if the poll isn't found anywhere else, delete the merge thread's poll
                            
if (!$poll $DB_site->query_first("
                                SELECT threadid
                                FROM " 
TABLE_PREFIX "thread
                                WHERE pollid = 
$mergethreadinfo[pollid] AND
                                    threadid <> 
$mergethreadinfo[threadid]
                                "
))
                            {
                                
$DB_site->query("DELETE FROM " TABLE_PREFIX "poll WHERE pollid = $mergethreadinfo[pollid]");
                                
$DB_site->query("DELETE FROM " TABLE_PREFIX "pollvote WHERE pollid = $mergethreadinfo[pollid]");
                            }
                        }
                    }
                
                    
// move posts
                    
$DB_site->query("UPDATE " TABLE_PREFIX "post SET threadid = $threadid WHERE threadid = $mergethreadid");
                    
$DB_site->query("UPDATE " TABLE_PREFIX "post SET parentid = $thrd_firstpost[postid] WHERE postid = $mrgthrd_firstpost[postid]"); // make merge thread child of first post in other thread
                    
$DB_site->query("UPDATE " TABLE_PREFIX "thread SET title = '" addslashes(htmlspecialchars_uni($title)) . "'$pollcode WHERE threadid = $threadid");
                    
$DB_site->query("DELETE FROM " TABLE_PREFIX "thread WHERE threadid = $mergethreadid");
                    
$DB_site->query("UPDATE " TABLE_PREFIX "thread SET pollid = $threadid WHERE open = 10 AND pollid = $mergethreadid"); // update redirects
                    
$DB_site->query("DELETE FROM " TABLE_PREFIX "threadrate WHERE threadid = $mergethreadid");
                    
$DB_site->query("DELETE FROM " TABLE_PREFIX "subscribethread WHERE threadid = $mergethreadid");
                
                    
// update postindex for the 2 posts who's titles may have changed (first post of each thread)
                    
delete_post_index($thrd_firstpost['postid']);
                    
delete_post_index($mrgthrd_firstpost['postid']);
                    
build_post_index($thrd_firstpost['postid'] , $foruminfo);
                    
build_post_index($mrgthrd_firstpost['postid'] , $foruminfo);
                
                    
build_thread_counters($threadid);
                    
build_forum_counters($threadinfo['forumid']);
                    if (
$mergethreadinfo['forumid'] != $threadinfo['forumid'])
                    {
                        
build_forum_counters($mergethreadinfo['forumid']);
                    }
                }
            }
            if (
$vars['forumid'])
            {
                
$url "forumdisplay.php?$session[sessionurl]f=$vars[forumid]&mod=1";
                eval(
print_standard_redirect('redirect_mergethread'));
            }
        }
        break; 
It works for me!

I just do not know what toss_cookies does!

Rgds
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01514 seconds
  • Memory Usage 1,896KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete