Home Help Search Register
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Become a Bigace 3.0 beta tester
Pages: [1]
  Print  
Author Topic: Import postings from Wordpress  (Read 1871 times)
0 Members and 1 Guest are viewing this topic.
Kevin
Global Moderator
BIGACE Guru
*****
Posts: 2601



WWW
« on: July 24, 2009, 10:30:27 PM »

Hi there,

I have written a short script which imports postings from Wordpress and adds them as BIGACE news entries.
It requires the News and Comment extension to be installed.
 
It is a quick and ugly hack so it has no error handling or anything else a good script should have Grin
But it works quite well, my last wordpress import had about 50 blog postings and 200 comments.

To use it, copy the code below and save it as wp_import.php in your BIGACE root folder!

Code:
<?php

// +------------------------------------------------------------------------+
// | BIGACE - a PHP based Web CMS for MySQL                             |
// +------------------------------------------------------------------------+
// | Copyright (c) Kevin Papst                                                     |
// | Web           http://www.bigace.de                                         |
// | Sourceforge   http://sourceforge.net/projects/bigace/               |
// +------------------------------------------------------------------------+
// | This source file is subject to version 2 or (at your option) any    |
// | later version, of the GNU General Public License as published     |
// | by the FreeSoftware Foundation, available at:                          |
// | http://www.gnu.org/licenses/gpl.html                                     |
// +------------------------------------------------------------------------+
// | This program is distributed in the hope that it will be useful,      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty|
// | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  |
// | See the GNU General Public License for more details.               |
// +------------------------------------------------------------------------+

/*
  This script (is a dirty hack and beside that) imports postings from wordpress and adds them as bigace news entries.
  It requires the News and Comment extension to be installed.
  
  It is a quick and ugly hack so I has no error handling or anything else a good script should have ;D
  But it works quite well, my last wordpress import had about 50 blog postings and 200 comments.
  
  Some facts:
  ===========
  It ...
  - will only import published posts
  - will NOT import images or any other uploads
      - will not clear up content, so linked images might be be broken
  - will not map usernames. Postings will be assigned to the current user - so make sure to login before!
  - will use the BIGACE DB encoding. If wordpress does not run with utf-8, you might have to add encoding.
  - will NOT only import categories, tags or any other meta tags
  - will create new unique urls. If you need proper redirects, create your own script...
  
  How to use:
  ===========
  - adjust connection values to your wordpress database
  - put script into BIGACE root directory
  - open it in your browser ... 
  - ... and enjoy the new created postings and comments!
  
*/

// wordpress connection settings
$wp_host "localhost";
$wp_database "wordpress";
$wp_username "root";
$wp_password "root";
$wp_prefix "wp_";

// stop here, if PHP is just a bunch of weird characters to you ;)
// -----------------------------------------------------------------------------


// setup bigace environment
include_once(dirname(__FILE__).'/system/libs/init_session.inc.php');

import('classes.sql.MySQLConnection');
import('classes.news.NewsAdminService');
import('classes.news.NewsAdminService');
import('classes.comments.CommentAdminService');

$news_id ConfigurationReader::getConfigurationValue("news""root.id"null);
$news_lang ConfigurationReader::getConfigurationValue("news""default.language",null);

if(
is_null($news_id) || is_null($news_lang))
    die(
"BIGACE News extension is not configured properly!");

// create connection to wordprss database
$myqslConn = new MySQLConnection($wp_host$wp_database$wp_username$wp_passwordtrue);

$allPostings $myqslConn->sql('SELECT * FROM '.$wp_prefix.'posts WHERE post_type = "post" and post_status = "publish"');

echo 
"<p>Found " $allPostings->count() . " postings to import!</p>";

$cas = new CommentAdminService(_BIGACE_ITEM_MENU);
$nas = new NewsAdminService();

for(
$i=0$i $allPostings->count(); $i++) 
{
    
$entry $allPostings->next();
    
$resultID $nas->createNews($news_lang$entry['post_title'], $entry['post_excerpt'], ''$entry['post_content'], array(), strtotime($entry['post_date']), nulltrue);
    
    if(
$resultID !== false
    {
        
$allComments $myqslConn->sql('SELECT * FROM '.$wp_prefix.'comments WHERE comment_post_ID = "'.$entry['ID'].'"');
        echo 
"<p>Found " $allComments->count() . " comments for posting: ".$entry['ID']."</p>";
        for(
$a=0$a $allComments->count(); $a++) 
        {
            
$tc $allComments->next();
            
$type = (isset($tc['comment_type']) && strlen($tc['comment_type']) > ) ? 'trackback' 'comment';
            
$cas->createComment($resultID$news_lang$tc['comment_author'], $tc['comment_content'], $tc['comment_author_email'], $tc['comment_author_url'], $type);
        }
    }
}

?>

 
  Some facts:
  ===========
  It ...
  - will only import published posts
  - will NOT import images or any other uploads
      - will not clear up content, so linked images might be be broken
  - will not map usernames. Postings will be assigned to the current user - so make sure to login before!
  - will use the BIGACE DB encoding. If wordpress does not run with utf-8, you might have to add encoding.
  - will NOT only import categories, tags or any other meta tags
  - will create new unique urls. If you need proper redirects, create your own script...
 
  How to use:
  ===========
  - adjust connection values to your wordpress database
  - put script into BIGACE root directory
  - open it in your browser ...
  - ... and enjoy the new created postings and comments!


And don't say I didn't warn you if something fails, its really just a dirty hack  Grin Grin Grin

Cheers
Kevin
Logged

BIGACE needs you. Join the Team! | BIGACE Plugins | Using BIGACE for your business? Like the support? Think about a donation!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF | Simple Machines LLC