home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / lib / scripts / replace.php < prev    next >
PHP Script  |  2004-03-08  |  1KB  |  60 lines

  1. <?php
  2. /*
  3. This scripts replaces strings in all Group-Office files.
  4. Enter old keywords in $string[n]['old'] and the new in $string[n]['new'].
  5. BE CAREFULL WITH THIS SCRIPT!
  6. */
  7.  
  8. require("../../Group-Office.php");
  9. //$GO_SECURITY->authenticate();
  10.  
  11. $string[0]['old'] = 'date(';
  12. $string[0]['new'] = '';
  13.  
  14. $count = count($string);
  15. require($GO_CONFIG->class_path."filesystem.class.inc");
  16. $filesystem = new filesystem;
  17.  
  18. function replace_files($path)
  19. {
  20.     global $count, $string;
  21.  
  22.     $replace_count=0;
  23.     $dir=opendir($path);
  24.     while ($file=readdir($dir))
  25.     {
  26.         if (is_dir($path.$file))
  27.         {
  28.             if ($file != "." && $file != ".." && $file != 'CVS')
  29.             {
  30.                 replace_files($path.$file.'/');
  31.             }
  32.         }else
  33.         {
  34.             if ($file != 'replace.php')
  35.             {
  36.                 $fp = fopen($path.$file, 'r');
  37.                 $data = fread($fp, filesize($path.$file));
  38.                 fclose($fp);
  39.  
  40.                 for ($i=0;$i<$count;$i++)
  41.                 {
  42.                     if($data = str_replace($string[$i]['old'],$string[$i]['new'], $data))
  43.                     {
  44.                         $replace_count++;
  45.                     }
  46.                 }
  47.  
  48.                 $fp = fopen($path.$file, 'w+');
  49.                 fwrite($fp, $data);
  50.                 fclose($fp);
  51.                 //echo $path.$file."<br />";
  52.             }
  53.  
  54.         }
  55.     }
  56.     closedir($dir);
  57.     return $replace_count;
  58. }
  59. echo replace_files($GO_CONFIG->root_path).' occurences replaced';
  60. ?>