The following warnings occurred:
Warning [2] Undefined array key "threadviews_countguests" - Line: 745 - File: showthread.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 745 errorHandler->error_callback
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 830 postParser->parse_message
/showthread.php 1121 build_postbit
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 46 - File: showthread.php(1650) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1650) : eval()'d code 46 errorHandler->error_callback
/showthread.php 1650 eval




Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String find/replace script - Moving/migrating sites
#1
(first posted here)

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 (e.g. *.xml in data/pages)

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 Code:
<?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.
Reply




Users browsing this thread: 1 Guest(s)