TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,021
  • Total Topics: 21,332
  • Online today: 582
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 239
  • Total: 239

move wordpress posts to TP

Started by alvinleephd, May 17, 2008, 02:21:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

alvinleephd


IchBin

Yes, if you manually cut and paste the text. There are no converters for TP and Wordpress.

PeterLawrence

#2
This shouldn't be too difficult to write.
Here some code where I done it the other way around.

Remember to backup your databases before using this script.
P.S. I only wrote this script to see if is was possible. I kind of like to keep my options open  ;).


<?php
   
// Converts tinyportal pages into wordpress pages
   // Place this code in the wordpress folder 
   // REMOVE this script after use since it is a big SECURITY RISK
   
   
$PathToSMF = '../smf/'; //  SET TO SMF LOCATION

   
require_once('wp-load.php'); // Wordpress

   
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Database access</title>
</head> 
<body>'
;

// Look for Settings.php....
$PathToSMF = $PathToSMF.'Settings.php';
if (file_exists($PathToSMF)) 
{
// Found it!
require($PathToSMF);
}
else // Can't find it...
{
echo ' <p> Can\'t find SMF settings file:,',$PathToSMF,'</p><p></body></html>';
exit;
}
// Attempt a connection.
$attempt = @mysql_connect($db_server, $db_user, $db_passwd);
if ($attempt != false)
{
$attempt = @mysql_select_db($db_name);
}
else
{
echo ' <p> Can\'t connect to SMF database</p> ';
}
if ($attempt)
{
$attempt2 = @mysql_select_db(DB_NAME);
if ($attempt2 == false)
{
echo ' <p> Can\'t connect to wordpress database</p></p><p></body></html>';
exit;
}
// Insert a marker page. This also finds page id starting point
$now = date('Y-m-d H:i:s');
$now_gmt = gmdate('Y-m-d H:i:s');
$post_guid = get_option('home') . '/?page_id=TinyPortal';
echo 'new id :',$post_guid,'<br>';
$user_id = 2;

$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__(htmlspecialchars_decode($row[0])))."', '', 'Start of TinyPortal Pages', '0', '".$wpdb->escape(_c('tppage|wordpresspage'))."', '$now', '$now_gmt','$post_guid', 'publish', 'page', '', '', '')");

$NewPageID=$wpdb->insert_id;
$pagelist=array();
$pagename=array();
$subpage=array();

$attempt = @mysql_select_db($db_name);
if ($attempt == false)
{
echo ' <p> Can\'t connect to SMF database</p> ';
}
$request = @mysql_query("SELECT category, shortname FROM ${db_prefix}tp_articles");

               
// find data about pages so links can be converted...
       $pagecount=0;
while ($row = @mysql_fetch_row($request))
{
$subpage[$pagecount] = $row[0];
$pagelist[$pagecount] = $NewPageID+$pagecount;
$pagename[$pagecount] = $row[1];
$pagecount++;
}
@mysql_free_result($request);

$request = @mysql_query("SELECT body, subject, category, shortname FROM ${db_prefix}tp_articles");
$oldIds=1;
$attempt2 = @mysql_select_db(DB_NAME);
while ($row = @mysql_fetch_row($request))
{
$oldIds++;
$NewPageID = $NewPageID+1; 
echo ' - old ID -',$oldIds, ' - subject - ',$row[1],' - short name -',$row[3],' - new ID - ',$NewPageID,'</br>';
$pattern = '/\?page=.*&quot/';
$acount=preg_match_all($pattern, $row[0], $matches);
$acount=0;
foreach ($matches[0] as $thelink)
{
$linkstrlength=strlen($thelink)-1; 
$oldlink = substr($thelink,6,-5);

// now search for replacment link id
$NewLinkID=-1;

// first look for name
for ($i = 0; $i < $pagecount; $i++)
{
if (strcmp($oldlink,$pagename[$i])==0)
{
    $NewLinkID=$pagelist[$i]+1;
}
}
if ($NewLinkID==-1)
{
// else use id
for ($i = 0; $i < $pagecount; $i++)
{
if (($i+1)==intval($oldlink))
{
$NewLinkID=$pagelist[$i]+1;
}
}
}
if ($NewLinkID>-1)
{
$newlink = '?page_id=' . $NewLinkID. '"';
echo $acount,': ',$thelink,' ',$oldlink,' ',$newlink,'</br>';
$row[0] = str_replace($thelink,$newlink,$row[0]);
echo '<p>',$row[0],'</p>';
}
else
{
echo 'Link not found : ',$oldlink,'</br>';
}
$acount++;
}
$now = date('Y-m-d H:i:s');
$now_gmt = gmdate('Y-m-d H:i:s');
$post_guid = get_option('home') . '/?page_id='.$NewPageID;
echo 'new id :',$post_guid,'<br>';
$user_id = 2;
$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__(htmlspecialchars_decode($row[0])))."', '', '".$row[1]."', '0', '".$wpdb->escape(_c($row[3]))."', '$now', '$now_gmt','$post_guid', 'publish', 'page', '', '', '')");
echo 'Insert ID ',$wpdb->insert_id,'<br>';
echo '<hr>';
}
@mysql_free_result($request);
}
echo ' </body></html>';
?>


Crip

I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



IchBin

Thats a PHP file Crip. You probably run in it your browser from the root of your site.

Crip

I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



IchBin

Looking at the code a little closer it looks ok to me. But I was wrong in that, you need to place it in your wordpress folder. Then, make sure you change this line.
$PathToSMF = '../smf/'; //  SET TO SMF LOCATION

If you're looking to try it, just make sure you have a backup of your stuff before you start changing stuff.

PeterLawrence

Yes this script should be placed in the Wordpress folder.
It’s just a quick hack I did to test if it was possible to transfer pages from one system to the other. And should not be used unless you know what you’re doing.

I would not recommend running this script on a live site. I tend to copy my websites over to an emulator, for example Server2go and test things out on this. It also serves as a backup to the live system.

I’ve done a little programming for both wordpress and smf and noticed that because of the coding style of the two applications the include files can be mixed to some degree. Hence, I thought I would try out a little test application.

With a bit of work you should be able to switch it around so that you can transfer Wordpress pages to TP. But saying that it may be quicker to do a cut and paste job of the web articles between the two systems

Note this script has only been tested on Wordpress 2.6.2 and Tinypportal 1.05 beta and 0.98.

Crip

TP + Wordpress --- both I do know, but myself was just curious .. good work PL
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



phantomm

I know that is old topic, but i try to use script from PeterLawrence.
Can anyone explain to me why every time i get this error: "Can't find SMF settings file: /forum/Settings.php" ?

Patch to smf is correct.

WP is in mydomain.com
SMF is in mydomain.com/forum
so my patch to smf is: $PathToSMF = '/forum/';

or i messed up something.. ?

//
forgot to add:
WP: 3.1.2
SMF: 2.0 RC5
TP: 1.0 RC1 (old version)

This website is proudly hosted on Crocweb Cloud Website Hosting.