Guest User

Untitled

a guest
Jan 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $jsFile = $_GET["jsFile"];
  2. $jsBaseUrl = "js/";
  3.  
  4. $imports = array($jsFile)
  5.  
  6. function importJsFile($package)
  7. {
  8.     global $jsBaseUrl, $imports;
  9.     $newJS = "";
  10.    
  11.     // package is in the form of stuff.stuff.stuff
  12.     $fileURL = $jsBaseUrl.str_replace(".", "/", $package).".js";
  13.    
  14.     // Open the file and begin reading
  15.     $h = fopen($fileURL, "r");
  16.     while(($line = fgets($h)) !== false)
  17.     {
  18.         if(strstr($line, "@import") !== false
  19.         && !in_array(($pac = substr($line, strlen("@import "))), $imports)) {
  20.             $imports[] = $pac;
  21.             $newJS .= importJsFile($pac);
  22.         } else {
  23.             $newJS .= $line;
  24.         }
  25.     }
  26.    
  27.     // If there was a problem reading the file, we will not be at the end
  28.     if(!feof($h))
  29.     {
  30.         throw new Exception("Problem reading JS file: ".$package);
  31.     }
  32.    
  33.     fclose($h);
  34.    
  35.     return newJS;
  36. }
Add Comment
Please, Sign In to add comment