View Single Post
  #14  
Old 08-06-2005, 06:54 AM
Marris Marris is offline
 
Join Date: Jul 2005
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know how much further I'll go with these. They're still very sloppy, but the output is "good enough" for my needs (and considering my lack of skills). Anyway, I'm posting these in the hope that maybe this will inspire someone to write a proper conversion script someday.

I have made a second script copied from the first that fixes the the "p=" post links. The main difference is an additional check for '#' in the link.

Running on a local test server, I have used these to update my full database (several thousand links updated within a few hundred thousand posts).

imported post link converter (viewtopic.php?=p):

PHP Code:
<?php
$username
="";
$password="";
$database="";

// post link convertor for imported phpBB posts in vBulletin
// use at your own risk 

// post replace script converted from topic replace

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM vb3_post WHERE pagetext LIKE ('%www.domain.com/forum/viewtopic.php?p=%')";
$result=mysql_query($query) or die (mysql_error ());

$num=mysql_numrows($result);

$searchstring "www.domain.com/forum/viewtopic.php?p=";

// echo "<b><center>Database Output</center></b><br><br>";
$nonexistcount=0;
$changedcount=0;
$i=0// 10 should be $num below
while ($i $num) {
$postid=mysql_result($result,$i,"postid");
$pagetext=mysql_result($result,$i,"pagetext");

   
$count=substr_count($pagetext,$searchstring);
   
$replacecount=0;
 
//echo "<b>ROW:$i, POSTID:$postid, NUMBER OF LINKS:$count<br>ORIGINAL POST:<BR>$pagetext<br>";
$pagetext addslashes($pagetext);
//echo "<br>SLASHIFIED POST:<br>$pagetext<br>";


while ($count 0) {
   
   
$begPos strpos($pagetext,$searchstring);
   
// echo "<br>beginning position: $begPos</br>";
   
$step 0;
    
$checknum 0;
    
$dbsize 10// number of digits in total number of posts in database + 1

    
while (($step $dbsize) && ($checknum !== 1))
    {
        
$step=$step+1;
        
$checkstring substr($pagetext,$begPos+strlen($searchstring),$step);
        
$checknum preg_match ('/[^0-9]/'$checkstring);
    }
    
$endPos = ($begPos+strlen($searchstring)+$step-1);
    
//echo "<br>ending position: $endPos</br>";
//    $topicid = substr($pagetext,$begPos+strlen($searchstring),$endPos-$begPos-1);  
// old below
  
  
$psum =($endPos-$begPos);
   
$psumneg=$psum;
   if (
$psum 0){
       
       
$ic=0;
$psegs=explode("http:\/\/",$pagetext);
//echo "<br>number of segments:$psegs[$ic]<br>";
$begPos strpos($psegs[$ic],$searchstring);

//echo "<br>beginning position segment $ic: $begPos</br>";

while (( $begPos ) and ($ic 100))

{
$ic++;
$begPos strpos($psegs[$ic],$searchstring); 

}
   
//echo "<br>segment $ic : $psegs[$ic]<br>$endPos : before<br>";
   
   
$step 0;
    
$checknum 0;
    
$dbsize 10// number of digits in total number of posts in database + 1

    
while (($step $dbsize) && ($checknum !== 1))
    {
        
$step=$step+1;
        
$checkstring substr($psegs[$ic],$begPos+strlen($searchstring),$step);
        
$checknum preg_match ('/[^0-9]/'$checkstring);
    }
    
$endPos = ($begPos+strlen($searchstring)+$step-1);  
   
    
     
     
//echo "$endPos : after<br>";
   
$psumneg=($endPos-$begPos); 
   
$tmp substr($psegs[$ic],$begPos+strlen($searchstring),$endPos-$begPos-strlen($searchstring));
   
//echo "<br>COUNT:$ic<br>POST ID:$postid<br><br>NEGSUM:$psumneg<br>";
      //echo "<Br>START:$begPos<br>END:$endPos<br>new post ID:$tmp<br>";
  
} else {
   
$tmp substr($pagetext,$begPos+strlen($searchstring),$endPos-$begPos-strlen($searchstring));
  }
   if (
ereg("&"$tmp)) { 
        
$tmpsplit=explode("&",$tmp);
        
$tmp=$tmpsplit[0];
        
$tmpsid=$tmpsplit[1];
        } else {
        
$tmpsid='';
       }
   
$oldpostid $tmp;
   
 
$sql "SELECT * FROM vb3_post WHERE importpostid = '$oldpostid'";
if( !(
$result2 mysql_query($sql)) )
{
    
message_die(GENERAL_ERROR'Could not query post information'''__LINE____FILE__$sql);
}
$result2=mysql_query($sql);
@
$newpost=mysql_result($result2,0,"postid");


if (empty(
$newpost))
{
$filename[$replacecount]="post_deleted";
    
$nonexistcount=$nonexistcount+1;
}  else {
    
$filename[$replacecount] = $newpost;
}
   

$filename[$replacecount]=("testvb/showthread.php?p=" $filename[$replacecount] . "#post" $filename[$replacecount]);

if (!empty(
$tmpsid)) {
$oldpostid=( "$oldpostid"&" "$tmpsid);
//echo "$oldpostid<br>";
}

$replace[$replacecount]=("forum/viewtopic.php?p=" $oldpostid "#" $oldpostid); 

if (
substr_count($pagetext,$replace[$replacecount]) == 0){
    
$replace[$replacecount]=("forum/viewtopic.php?p=" $oldpostid);    
}    

$placeholder[$replacecount]=("place" $replacecount);

$pagetext str_replace($replace[$replacecount],$placeholder[$replacecount],$pagetext);
   
//echo "PASS:$replacecount<BR>Old post ID:$oldpostid<br>TEXT TO BE REPLACED: $replace[$replacecount]<br>";
//echo "REPLACEMENT TEXT: $filename[$replacecount]<br>";
        
   
$count=$count-1;
$replacecount=$replacecount+1;
$changedcount=$changedcount+1;
}   

$pagetext str_replace($placeholder,$filename,$pagetext);  


mysql_query("UPDATE vb3_post SET pagetext='$pagetext' WHERE postid=$postid") or die (mysql_error ());

//echo "<b>EDITED POST:<br>$pagetext<hr><br>";


$i++;
}
mysql_close();
echo 
"...DONE<br>";
echo 
"$nonexistcount missing posts replaced with placeholder link<br>";
echo 
"$changedcount links updated<br>";
echo 
"$i rows modified";
?>
imported thread link converter (viewtopic.php?=t):

PHP Code:
<?php
$username
="";
$password="";
$database="";

// thread link convertor for imported phpBB posts in vBulletin
// use at your own risk 

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM vb3_post WHERE pagetext LIKE ('%www.domain.com/forum/viewtopic.php?t=%')";
$result=mysql_query($query) or die (mysql_error ());

$num=mysql_numrows($result);

$searchstring "www.domain.com/forum/viewtopic.php?t=";

// echo "<b><center>Database Output</center></b><br><br>";
$nonexistcount=0;
$changedcount=0;
$i=0// 10 should be $num below
while ($i $num) {
$postid=mysql_result($result,$i,"postid");
$pagetext=mysql_result($result,$i,"pagetext");

   
$count=substr_count($pagetext,$searchstring);
   
$replacecount=0;
 
//echo "<b>ROW:$i, POSTID:$postid, NUMBER OF LINKS:$count<br>ORIGINAL POST:<BR>$pagetext<br>";
$pagetext addslashes($pagetext);
//echo "<br>SLASHIFIED POST:<br>$pagetext<br>";


while ($count 0) {
   
   
$begPos strpos($pagetext,$searchstring);
   
//echo "<br>beginning position: $begPos</br>";
   
$step 0;
    
$checknum 0;
    
$dbsize 10// number of digits in total number of posts in database + 1

    
while (($step $dbsize) && ($checknum !== 1))
    {
        
$step=$step+1;
        
$checkstring substr($pagetext,$begPos+strlen($searchstring),$step);
        
$checknum preg_match ('/[^0-9]/'$checkstring);
    }
    
$endPos = ($begPos+strlen($searchstring)+$step-1);
    
//echo "<br>ending position: $endPos</br>";
//    $topicid = substr($pagetext,$begPos+strlen($searchstring),$endPos-$begPos-1);  
// old below
  
  
$psum =($endPos-$begPos);
   
$psumneg=$psum;
   if (
$psum 0){
       
       
$ic=0;
$psegs=explode("http:\/\/",$pagetext);
//echo "<br>number of segments:$psegs[$ic]<br>";
$begPos strpos($psegs[$ic],$searchstring);

//echo "<br>beginning position segment $ic: $begPos</br>";

while (( $begPos ) and ($ic 100))

{
$ic++;
$begPos strpos($psegs[$ic],$searchstring); 

}
   
//echo "<br>segment $ic : $psegs[$ic]<br>$endPos : before<br>";
   
   
$step 0;
    
$checknum 0;
    
$dbsize 10// number of digits in total number of posts in database + 1

    
while (($step $dbsize) && ($checknum !== 1))
    {
        
$step=$step+1;
        
$checkstring substr($psegs[$ic],$begPos+strlen($searchstring),$step);
        
$checknum preg_match ('/[^0-9]/'$checkstring);
    }
    
$endPos = ($begPos+strlen($searchstring)+$step-1);  
   
    
     
     
//echo "$endPos : after<br>";
   
$psumneg=($endPos-$begPos); 
   
$tmp substr($psegs[$ic],$begPos+strlen($searchstring),$endPos-$begPos-strlen($searchstring));
   
//echo "<br>COUNT:$ic<br>POST ID:$postid<br><br>NEGSUM:$psumneg<br>";
      //echo "<Br>START:$begPos<br>END:$endPos<br>thread ID:$tmp<br>";
  
} else {
   
$tmp substr($pagetext,$begPos+strlen($searchstring),$endPos-$begPos-strlen($searchstring));
  }
   if (
ereg("&"$tmp)) { 
        
$tmpsplit=explode("&",$tmp);
        
$tmp=$tmpsplit[0];
        
$tmpsid=$tmpsplit[1];
        } else {
        
$tmpsid='';
       }
   
$oldthreadid $tmp;
   
 
$sql "SELECT * FROM vb3_post WHERE importthreadid = '$oldthreadid'";
if( !(
$result2 mysql_query($sql)) )
{
    
message_die(GENERAL_ERROR'Could not query thread information'''__LINE____FILE__$sql);
}
$result2=mysql_query($sql);
@
$newthread=mysql_result($result2,0,"threadid");


if (empty(
$newthread))
{
$filename[$replacecount]="thread_deleted";
    
$nonexistcount=$nonexistcount+1;
}  else {
    
$filename[$replacecount] = $newthread;
}
   

$filename[$replacecount]=("testvb/showthread.php?t=" $filename[$replacecount]);

if (!empty(
$tmpsid)) {
$oldthreadid=( "$oldthreadid"&" "$tmpsid);
//echo "$oldthreadid<br>";
}

$replace[$replacecount]=("forum/viewtopic.php?t=" $oldthreadid); 


$placeholder[$replacecount]=("place" $replacecount);

$pagetext str_replace($replace[$replacecount],$placeholder[$replacecount],$pagetext);
   
//echo "PASS:$replacecount<BR>Old thread ID:$oldthreadid<br>TEXT TO BE REPLACED: $replace[$replacecount]<br>";
//echo "REPLACEMENT TEXT: $filename[$replacecount]<br>";
        
   
$count=$count-1;
$replacecount=$replacecount+1;
$changedcount=$changedcount+1;
}   

$pagetext str_replace($placeholder,$filename,$pagetext);  


mysql_query("UPDATE vb3_post SET pagetext='$pagetext' WHERE postid=$postid") or die (mysql_error ());

//echo "<b>EDITED POST:<br>$pagetext<hr><br>";


$i++;
}
mysql_close();
echo 
"...DONE<br>";
echo 
"$nonexistcount missing threads replaced with placeholder link<br>";
echo 
"$changedcount links updated<br>";
echo 
"$i rows modified";
?>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01430 seconds
  • Memory Usage 1,972KB
  • 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
  • (2)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