User Tools

Site Tools


Arvid, May 2020:
The following contents are restored from the old FlatPress wiki and may be WAY outdated. I do not have any SPB instance running, nor do I know if the following description works. Please let me know if so!
See also: Considerations around SimplePhpBlog and its storing system

SPB Importer

BACKUP your original content/ before running your script.

isoconvert.php imports and converts from SPB iso-8859-1 charset to FP UTF-8; also it removes some offending keys (relatedlink) ad blank keys.

Installing and using

  1. Copy the code that follows into a file named isoconvert.php and put it in your flatpress/ installation dir.
  2. Put the file in your flatpress/ root and point your browser to http://yoursite/flatpress/isoconvert.php
  3. IMPORTANT: Don't forget to delete this file once you're done with importing.

Important additional information

isoconvert.php can import from GZ too. If you enabled GZ compression in SPB you should uncompress those files.

GZ import is disabled by default, so to issue the conversion you must point your browser to http://mysite/flatpress/isoconvert.php?ungz=true

WARNING Once you run this script, if you SKIPPED GZ files, then you should run the script once again with ungz=true, but this would mean converting twice files that were not SKIPPED. So you must delete the content/ dir and put a fresh copy before re-executing the script. Of course this mean you must always have a backup ready.

You can also try the DB Dump script, which should list most of the issues you may find. If dump lists GZ files, then you'll have to run isoconvert with ungz=true.


    header('Content-Type: text/plain');
    class utfencoder extends fs_filelister {
        var $_directory = CONTENT_DIR;
		var $foundgz = false;
        function _checkFile($d,$f) {
            if (is_dir($p)) {
                return 1;
            } else  {
				$DO_GZ = (isset($_GET['ungz']))? $_GET['ungz'] : false;
                echo "Converting $p ... ";
                $s = io_load_file($p);
				if ((strpos( $p, '.gz' ) !== false )  ) {
					if (!$DO_GZ) {
						$this->foundgz = true;
						echo "GZ: SKIPPED\n"; 
						return 2;	
					echo "[WARNING] File was GZ, moving to TXT... ";
					$s = gzinflate(substr($s, 10 ));
					if (strpos($f, 'view_counter')!== false) {
						io_write_file($d . '/view_counter.txt');
						echo "(uncompressed) ";
					$f = substr($f, 0,-3);
					$p = "$d/$f";	
                $s = mb_convert_encoding($s, 'UTF-8', 'ISO-8859-1');
				if (($f != 'view_counter.txt') && (strpos($s, 'VERSION|') === false)) {
					echo " IMPORTING $f from old versions ";
                    // compatibility with old versions -__-'
                    $cont = explode('|', $s);
                    if (strpos($f, 'entry')!==false) {
                        $s = "VERSION|0.3|SUBJECT|{$cont[0]}|CONTENT|{$cont[2]}|DATE|{$cont[1]}";
                    } elseif (strpos($f, 'comment')!==false) {
                        $s = "VERSION|0.3|NAME|{$cont[0]}|CONTENT|{$cont[2]}|DATE|{$cont[1]}";
                    } else {
                        echo "SKIPPED\n";
				// remove or replace offending keys
				$s = str_replace('relatedlink', 'RELATEDLINK', $s);
				$s = str_replace('TB_PING||', '', $s);
                $s = io_write_file($p, $s);
                echo "DONE\n";
	echo "======= FlatPress importer =======\n\n" ;
	echo "Starting process...\n";
    $o =& new utfencoder;
    echo "\n\nFINISHED";
	if ($o->foundgz) {
		echo "\nWARNING: DataBase contained GZ Files: FlatPress can't read GZipped files,\n" ;
		echo "so you should call again this script as in /isoconvert.php?ungz=true\n\n";
		echo "Please notice that you will LOSE your original GZ files, so DO A BACKUP first.";
res/tools/spbimporter.txt · Last modified: 2020/05/10 13:13 by arvid