Script for moving GetSimple sites

Here's a simple script (not a plugin, so no backend, sorry) to search/replace old->new site URLs in all files in a folder.

Set it up by editing the values in the first lines in the script (create the destination folder if it doesn't exist), save it as convertsiteurl.php (or what you wish) and open it in your browser like YOURSITE/convertsiteurl.php

The destination folder can be the same as the source, but just in case make a backup of all your date (well, better make a backup anyway).

<?php
# setup values:
###############
$OLDSITEURL = 'http://localhost/devsite/';
$NEWSITEURL = 'http://www.example.com/';
$SOURCE = 'data/pages/';
$DEST = 'data/convertedfiles/';
$WRITEALL = false; // if true, write all files, not only updated ones
###############
# end setup

# process files
$SOURCE = rtrim($SOURCE,'/').'/';
$DEST = rtrim($DEST,'/').'/';
$OLDSITEURL = rtrim($OLDSITEURL,'/').'/';
$NEWSITEURL = rtrim($NEWSITEURL,'/').'/';
if ($handle = opendir($SOURCE)) {
  $files = array();
  while (false !== ($file = readdir($handle))) {
    if (strpos($file, ".") != 0){
      $files[] = $file;
    }
  }
  closedir($handle);
  echo count($files),' files:<br />';
  foreach ($files as $filename){
    if ($text = file_get_contents($SOURCE.$filename)) {
      echo $filename,' <b>';
      $found = (strpos($text, $OLDSITEURL) !== false);
      if ($found) {
        $text = str_replace($OLDSITEURL, $NEWSITEURL, $text);
        echo ' - found';
      }
      if ($WRITEALL or $found) {
        file_put_contents($DEST.$filename, $text);
        echo ' - written';
      }
      echo '</b><br />';
    }
  }
}

?>

It can be used with the data/pages folder, but also with News Manager's data/posts, GS Blog's data/blog, etc.

http://get-simple.info/forums/showthread.php?tid=2816&pid=38917#pid38917

blog comments powered by Disqus