Advertisement
7heSama

Builder 2

Aug 14th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?php
  2. //Builds php files on xampp localhost then outputs them to a build folder (as HTML, eventually)
  3. //Written by Kris with a K
  4.  
  5. //Recursively delete dir/contents
  6. //Thanks to holger1 at php.net for code
  7. function rrmdir($dir) {
  8. if (is_dir($dir)) {
  9. $objects = scandir($dir);
  10. foreach ($objects as $object) {
  11. if ($object != "." && $object != "..") {
  12. if (filetype($dir."/".$object) == "dir")
  13. rrmdir($dir."/".$object);
  14. else
  15. unlink ($dir."/".$object);
  16. }
  17. }
  18. reset($objects);
  19. rmdir($dir);
  20. }
  21. }
  22.  
  23. //Recursively glob dir/contents
  24. //Thanks to StackOverflow community for assistance
  25. function r2glob($dir, $ext = "*") {
  26. $files = glob($dir . "\\" . $ext);
  27. foreach($files as $subDir)
  28. {
  29. if (is_dir($subDir . "\\"))
  30. $files = array_merge($files, r2glob($subDir));
  31. }
  32.  
  33. return $files;
  34. }
  35.  
  36. //Checks to see if a filepath ends in a file-ext or dir name
  37. function is_dir_path($path) {
  38. $levels = explode("\\", $path);
  39. $last = $levels[sizeof($levels) - 1];
  40. if (sizeof(explode(".", $last)) > 1)
  41. return false;
  42. else
  43. return true;
  44. }
  45.  
  46. $localroot = "C:\\xampp\htdocs\intranet\\";
  47. $localbuild = "C:\\xampp\htdocs\intranet\build\\";
  48. $hosted = "https:\\\\localhost\intranet\\";
  49.  
  50. // test solution file_get_contents
  51. $arrContextOptions=array(
  52. "ssl"=>array(
  53. "verify_peer"=>false,
  54. "verify_peer_name"=>false,
  55. ),
  56. );
  57.  
  58. echo $localroot . "<br>";
  59. echo $localbuild . "<br>";
  60. echo $hosted . "<br>";
  61.  
  62. // sterilize build dir
  63. rrmdir($localbuild);
  64.  
  65. // get build files
  66. $paths = r2glob(dirname(__FILE__));
  67.  
  68. // output build files
  69. foreach($paths as $path)
  70. {
  71. echo "<br>";
  72. $path = str_replace($localroot, "", $path);
  73. $source = $hosted . $path;
  74. $dest = $localbuild . $path;
  75.  
  76. if (is_dir_path($dest))
  77. {
  78. mkdir($dest, 0755, true);
  79. echo "Make folder $source at $dest. <br>";
  80. }
  81. else
  82. {
  83. $content = file_get_contents($source, false, stream_context_create($arrContextOptions));
  84. file_put_contents(str_replace(".php", ".html", $dest), $content);
  85. }
  86. }
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement