News Manager blog

GS Blog -> News Manager migration script

Stevenjaycohen has posted a script to migrate GS Blog posts to News Manager:

http://get-simple.info/forums/showthread.php?tid=3972&pid=31496#pid31496

<?php

if ($handle = opendir('/path/to/data/blog')) {
      echo "Directory handle: $handle\n";
          echo "Entries:<br/>";
$entries=array();
          /* This is the correct way to loop over the directory. */
          while (false !== ($entry = readdir($handle))) {
            echo $entry."<br/>";
            if (strpos($entry, ".") != 0){
$entries [] = $entry;
            }
          }

      closedir($handle);
      echo "<br/><br/><b>".count($entries)." Entries</b>";

      date_default_timezone_set('America/New_York');
      foreach ($entries as $filename){
        if ($file = file_get_contents("/full/path/to/data/blog/".$filename)){
          echo "<br/>Got ".$filename."!<br/>";
          $newfile='<?xml version="1.0" encoding="UTF-8"?><item>';
          $titleStart = strpos($file,"<title>");
          $titleEnd = strpos($file,"</title>");
          $titleEnd = $titleEnd - $titleStart + 8;
          $title = substr($file, $titleStart, $titleEnd);
          $newfile .= $title;
          $dateStart = strpos($file,"<date>");
          $dateStart = $dateStart + 15;
          $dateEnd = strpos($file,"</date>");
          $dateEnd = $dateEnd - $dateStart - 3;
          $oldDate = substr($file, $dateStart, $dateEnd);
          echo "<br/>".$oldDate."<br/>";
          $oDate = new DateTime($oldDate);
          $date = "<date><![CDATA[".date_format($oDate, 'D, d M Y G:i:s O')."]]></date>";
          $newfile .= $date;
          $tagsStart = strpos($file,"<tags>");
          $tagsEnd = strpos($file,"</tags>");
          $tagsEnd = $tagsEnd - $tagsStart + 7;
          $tags = substr($file, $tagsStart, $tagsEnd);
          $newfile .= $tags;
          $privateStart = strpos($file,"<private");
          $privateEnd = strpos($file,"</private>");
          $privateEnd = $privateEnd - $privateStart + 10;
          $private = substr($file, $privateStart, $privateEnd);
          $newfile .= $private;
          $contentStart = strpos($file, "<content>");
          $contentEnd = strpos($file, "</content>");
          $contentEnd = $contentEnd - $contentStart + 10;
          $content = substr($file, $contentStart, $contentEnd);
          $newfile .= $content;
          $newfile .= "</item>";
          file_put_contents("/full/path/to/data/posts/".$filename, $newfile);
        }
      }
}

?>

 

« Back to News Manager blog

blog comments powered by Disqus