7heSama

Builder

Aug 8th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 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.     echo $localroot . "<br>";
  51.     echo $localbuild . "<br>";
  52.     echo $hosted . "<br>";
  53.    
  54.     // sterilize build dir
  55.     rrmdir($localbuild);
  56.    
  57.     // get build files
  58.     $paths = r2glob(dirname(__FILE__));
  59.    
  60.     // output build files
  61.     foreach($paths as $path)
  62.     {
  63.         echo "<br>";
  64.         $path = str_replace($localroot, "", $path);
  65.         $source = $hosted . $path;
  66.         $dest = $localbuild . $path;
  67.        
  68.         if (is_dir_path($dest))
  69.         {
  70.             mkdir($dest, 0755, true);
  71.             echo "Make folder $source at $dest. <br>";
  72.         }
  73.         else
  74.         {
  75.             copy($source, $dest);
  76.             echo "Copy $source to $dest. <br>";
  77.         }
  78.     }
  79. ?>
Add Comment
Please, Sign In to add comment