Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $jsFile = $_GET["jsFile"];
- $jsBaseUrl = "js/";
- $imports = array($jsFile)
- class FailedToFindJSException extends Exception { };
- function importJsFile($package)
- {
- global $jsBaseUrl, $imports;
- $newJS = "";
- // package is in the form of stuff.stuff.stuff
- $fileURL = $jsBaseUrl.str_replace(".", "/", $package).".js";
- // Open the file and begin reading
- $h = fopen($fileURL, "r");
- if(!$h) {
- throw new FailedToFindJSException("Failed to find ".$package);
- }
- while(($line = fgets($h)) !== false)
- {
- if(strstr($line, "@import") !== false
- && !in_array(($pac = substr($line, strlen("@import "))), $imports)) {
- $imports[] = $pac;
- try {
- $newJS .= importJsFile($pac);
- } catch (FailedToFindJSException $e) {
- echo $e->getMessage();
- // Zend_Registry::get('logger')->log(Level::WARNING, $e->getMessage());
- }
- } else {
- $newJS .= $line;
- }
- }
- // If there was a problem reading the file, we will not be at the end
- if(!feof($h))
- {
- throw new Exception("Problem reading JS file: ".$package);
- }
- fclose($h);
- return newJS;
- }
Add Comment
Please, Sign In to add comment