edit_course_html_files.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Goes through all HTML files of the courses directory and replaces
  5. * the first string by the second string.
  6. * This is useful when a portal was installed under one URL and then
  7. * changed URL (or port), to ensure documents are not pointing to the
  8. * previous URL.
  9. * This script is designed to be run from the browser, so maybe you
  10. * need to move it to an executable folder and change the first require.
  11. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  12. */
  13. require __DIR__.'/../../main/inc/global.inc.php';
  14. api_protect_admin_script();
  15. // Search string
  16. $search = 'be:8181';
  17. $replace = 'be';
  18. $dir = api_get_path(SYS_COURSE_PATH);
  19. $courses = scandir($dir);
  20. $i = 0;
  21. foreach ($courses as $courseDir) {
  22. if (substr($courseDir, 0, 1) === '.') {
  23. continue;
  24. }
  25. exec('find '.$dir.$courseDir.'/document/ -type f -name "*.html" -exec sed -i '."'s/hn:8181/hn/g' {} +");
  26. //print('find '.$dir.$courseDir.'/document/ -type f -name "*.html" -exec sed -i '."'s/hn:8181/hn/g' {} +<br />");
  27. $i++;
  28. //if ($i == 2) {
  29. // exit;
  30. //}
  31. echo "Replaced all $search in ".$dir.$courseDir."<br />";
  32. }
  33. echo "Done";