GC.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. * @package chamilo.exercise
  6. * @author Istvan Mandak
  7. * @version $Id: GC.php 20451 2009-05-10 12:02:22Z ivantcholakov $
  8. */
  9. /**
  10. * Code
  11. */
  12. // usage: HotPotGC($_configuration['root_sys'],$flag);
  13. // working recursively, flag[0,1] print or delete the HotPotatoes temp files (.t.html)
  14. echo "Garbage Collector<BR>";
  15. HotPotGC(api_get_path(SYS_PATH), 1, 1);
  16. /**
  17. * Garbage collector caller function
  18. */
  19. function HotPotGC($root_sys, $flag, $userID)
  20. {
  21. // flag[0,1] - print or delete the HotPotatoes temp files (.t.html)
  22. $documentPath = $root_sys."courses";
  23. HotPotGCt($documentPath, $flag, $userID);
  24. }
  25. /**
  26. * Garbage collector
  27. */
  28. function HotPotGCt($folder, $flag, $userID)
  29. { // Garbage Collector
  30. $filelist = array();
  31. if ($dir = @opendir($folder)) {
  32. while (($file = readdir($dir)) !== false) {
  33. if ($file != ".") {
  34. if ($file != "..") {
  35. $full_name = $folder."/".$file;
  36. if (is_dir($full_name)) {
  37. HotPotGCt($folder."/".$file, $flag);
  38. } else {
  39. $filelist[] = $file;
  40. }
  41. }
  42. }
  43. }
  44. closedir($dir);
  45. }
  46. while (list ($key, $val) = each($filelist)) {
  47. if (stristr($val, $userID.".t.html")) {
  48. if ($flag == 1) {
  49. FileManager::my_delete($folder."/".$val);
  50. } else {
  51. echo $folder."/".$val."<br />";
  52. }
  53. }
  54. }
  55. }