- b2evolution CMS Support Forums
- b2evolution Support
- Plugins & Extensions
- Simple PHP Blog (also know as SimplePHPBlog) importer
1 mochababy Sep 21, 2008 22:53
The below file will show in the browser window all the posts in MT format which can then be imported into B2Evo. This is how it works
1. Download the file and place it in your root directory of your simple php blog.
2. Call it via http protocol.
Eg. http://example.com/mt.php?n=10000
3. The reason why i have the n so high is because it parses the number of posts that you would like to import from the newest to oldest. I just thought that a lot of people would like that functionality and flexibility in case you have like 10,000 posts and only wanted the most recent 500.
4. This import script does not yet support comments but i'm sure I could rewrite it to. If you need that let me know and i'll dig up the code
5. HAVE FUN WITH B2EVO!!!
<?php
// Include Required Functions
require_once('scripts/sb_functions.php');
read_config();
require_once('languages/' . $blog_config[ 'blog_language' ] . '/strings.php');
sb_language( 'index' );
// Please note, you can change the number of entries that appear by
// passing the variable 'n' in the URL. You can also limit it to a certain
// category by passing 'c'. For instance, this will make it show
// 20 entries in the 'tech' category:
// http://www.mywebsite.com/rss.php?n=20&c=tech
function generate_mt ( $max_entries=0, $category='' )
{
// Read entries by month, year and/or day. Generate HTML output.
//
// Used for the main Index page.
global $lang_string, $blog_config, $user_colors, $sb_info;
$entry_file_array = blog_entry_listing();
$port = ':' . $_SERVER[ 'SERVER_PORT'];
if ($port == ':80') {
$port = '';
}
if ( ( dirname($_SERVER[ 'PHP_SELF' ]) == '\\' || dirname($_SERVER[ 'PHP_SELF' ]) == '/' ) ) {
// Hosted at root.
$base_url = 'http://' . $_SERVER[ 'HTTP_HOST' ].$port. '/';
} else {
// Hosted in sub-directory.
$base_url = 'http://' . $_SERVER[ 'HTTP_HOST' ].$port.dirname($_SERVER[ 'PHP_SELF' ]) . '/';
}
header('Content-type: text/plain');
// Read entry files
if ( $max_entries<=0 ) {
$max_entries=min( $blog_config[ 'blog_max_entries' ]<<1, count( $entry_file_array ) );
}
else {
$max_entries=min( $max_entries, count( $entry_file_array ) );
}
$entries=0;
$i=0;
while ( ( $entries<$max_entries ) && ( $i<count( $entry_file_array ) ) ) {
list( $entry_filename, $year_dir, $month_dir ) = explode( '|', $entry_file_array[ $i ] );
$contents=blog_entry_to_array( CONTENT_DIR . $year_dir . '/' . $month_dir . '/' . $entry_filename );
$cats = split( ',', $contents[ 'CATEGORIES' ] );
for ( $j = 0; $j < count( $cats ); $j++ ) {
if ( ( empty( $category ) ) || strpos( ',' . $category . ',', ',' . $cats[ $j ] . ',' )!==false ) {
$entries++;
//Required item fields
echo "AUTHOR: " . $blog_config[ 'blog_author' ] . "\n";
echo "TITLE: " . clean_rss_output( blog_to_html( $contents[ 'SUBJECT' ], false, false ) ) . "\n";
echo "DATE: " . gmdate( 'm/d/Y H:i:s', $contents[ 'DATE' ] ) . "\n";
//Optional item fields
echo "CATEGORY: ";
for ( $k = 0; $k < count( $cats ); $k++ ) {
echo get_category_by_id( $cats[ $k ] );
if ( $k < count( $cats ) - 1 ) {
echo ', ';
}
}
echo "\n";echo "-----\nBODY:\n" . clean_rss_output( replace_more_tag( blog_to_html( $contents[ 'CONTENT' ], false, false ), true, '' ) ) . $content_footer . "\n--------\n";
break;
}
}
$i++;
}
}
// Output Page
generate_mt( @$_GET[ 'n' ], @$_GET[ 'c' ] );
?>
3 mochababy Sep 28, 2008 05:14
well i'm not posting it for the recognition (I do thank you for it though), I was just in a bind to import over 900 posts from simple php blog and needed something simpler than a very complicated python script. So i did it and i hope that someone finds it useful!
Thanks mochababy. I don't need this but I hate to see someone's shared work go unrecognized is the thing. YAY for sharing extensions to open source software! YAY for mochababy!