/** * Prints the entire page */ public static function printPage() { // If we are building a page, create the static HTML file with static links if (self::$buildMode == SHOW_EXPORT) { // the file to write if (PATH_PAGES_COMPILED != "") { $writeFile = self::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . PATH_PAGES_COMPILED . DIRECTORY_SEPARATOR . self::$pages[self::$currentPageId]->pageTitle . ".html"; } else { $writeFile = self::$DIR_DOCUMENT_ROOT . PATH_PAGES_COMPILED . DIRECTORY_SEPARATOR . self::$pages[self::$currentPageId]->pageTitle . ".html"; } // capture output start $captureOutput = new ModulaiseCaptureOutput(); $captureOutput->start(); // render the page include self::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . PATH_TEMPLATES . DIRECTORY_SEPARATOR . self::$pages[self::$currentPageId]->templateId; // capture output end $output = $captureOutput->end(); // write the output to file ModulaiseUtils::writeFile($writeFile, $output); } else { // unless specifically requested the intermediate static html file will not be written $writeCached = isset($_REQUEST["writeCachedHtml"]) ? $_REQUEST["writeCachedHtml"] : "false"; if ($writeCached == "true") { // the file to write $writeFile = self::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . PATH_PAGES_CACHED . DIRECTORY_SEPARATOR . self::$pages[self::$currentPageId]->pageTitle . ".html"; // capture output start $captureOutput = new ModulaiseCaptureOutput(); $captureOutput->start(); // render the page include self::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . PATH_TEMPLATES . DIRECTORY_SEPARATOR . self::$pages[self::$currentPageId]->templateId; // capture output end $output = $captureOutput->end(); // write the output to file ModulaiseUtils::writeFile($writeFile, $output); // redirect to the static page header("Location: http://" . $_SERVER["SERVER_NAME"] . "/" . PATH_PAGES_CACHED . "/" . self::$pages[self::$currentPageId]->pageTitle . ".html"); } else { // render the page include self::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . PATH_TEMPLATES . DIRECTORY_SEPARATOR . self::$pages[self::$currentPageId]->templateId; } } }
/** * Concatinates CSS and JavaScript */ public static function buildCompiled() { echo "\nConcatinating CSS and JavaScript\n--------------------------------------------------------------------------------\n"; // set the PageController buildMode value to BUILD_EXPORT ModulaiseController::$buildMode = BUILD_EXPORT; // Reset global modules ModulaiseController::initialize(); // Create a page containing all modules and then in turn print js_head, js_foot and css ModulaiseController::createPage("EXPORT", "EXPORT"); // add all global modules to global modules array $allModuleNames = ModulaiseUtils::getDirectoryAsArray(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ModulaiseController::$PATH_MODULES, ONLY_DIRECTORIES); // build a list with all non-global modules foreach ($allModuleNames as $moduleId) { echo "Compiling module : " . $moduleId . "\n"; if (substr($moduleId, 0, 1) != "0") { ModulaiseController::addModule("EXPORT", $moduleId); } } $buildTagComment = "/*\n\nBuildtag: " . ModulaiseController::$buildTag . "\n\n*/\n\n"; // Write PANE_JS_HEAD // the file to write $writeFile = ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ModulaiseController::$PATH_MODULES . DIRECTORY_SEPARATOR . FOLDER_COMPILED . DIRECTORY_SEPARATOR . "js" . DIRECTORY_SEPARATOR . "js_head.concatinated.js"; echo "Writing file : " . $writeFile . "\n"; // capture output start $captureOutput = new ModulaiseCaptureOutput(); $captureOutput->start(); echo $buildTagComment; if (ModulaiseController::paneHasContent(PANE_JS_HEAD)) { // render the pane ModulaiseController::printPane(PANE_JS_HEAD); } // capture output end $output = $captureOutput->end(); // write the output to file ModulaiseUtils::writeFile($writeFile, $output); // Write PANE_JS_FOOT // the file to write $writeFile = ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ModulaiseController::$PATH_MODULES . DIRECTORY_SEPARATOR . FOLDER_COMPILED . DIRECTORY_SEPARATOR . "js" . DIRECTORY_SEPARATOR . "js_foot.concatinated.js"; echo "Writing file : " . $writeFile . "\n"; // capture output start $captureOutput = new ModulaiseCaptureOutput(); $captureOutput->start(); echo $buildTagComment; if (ModulaiseController::paneHasContent(PANE_JS_FOOT)) { // render the pane ModulaiseController::printPane(PANE_JS_FOOT); } // capture output end $output = $captureOutput->end(); // write the output to file ModulaiseUtils::writeFile($writeFile, $output); // Write each and every PANE_CSS // Prepare an empty array to hold the css $concatinated_css = array(); $debug = false; // get the pane names $paneNames = ModulaiseController::getPaneNames(); foreach ($paneNames as $name) { if ($debug === true) { echo "paneName=" . $name . "\n"; } $pos = strpos($name, PANE_CSS); if (!($pos === false)) { $nameArrays = explode("--", $name); // leading zero $nameArrays[1] = $nameArrays[1] < 10 ? "0" . $nameArrays[1] : $nameArrays[1]; // the file to write $writeFile = ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ModulaiseController::$PATH_MODULES . DIRECTORY_SEPARATOR . FOLDER_COMPILED . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . $nameArrays[1] . DELIMITER . $nameArrays[2] . ".concatinated.css"; echo "Writing file : " . $writeFile . "\n"; // capture output start $captureOutput = new ModulaiseCaptureOutput(); $captureOutput->start(); echo $buildTagComment; if (ModulaiseController::paneHasContent($name)) { // render the pane ModulaiseController::printPane($name); } // capture output end $output = $captureOutput->end(); // write the output to file ModulaiseUtils::writeFile($writeFile, $output); // Remove comments and blank lines from output $output = preg_replace('!/\\*.*?\\*/!s', '', $output); //$output = preg_replace('/\n\s*\n/', '', $output); //$output = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", $output); $output = trim($output); if ($debug === true) { echo "output=\"" . $output . "\"\n"; } // if there is something to add if ($output != "") { // also add the snippet to the concatinated array $concatinated_css[$nameArrays[1] . "--" . $nameArrays[2]][] = $output; } } } // Write everything as one big pane // the file to write $writeFile = ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ModulaiseController::$PATH_MODULES . DIRECTORY_SEPARATOR . FOLDER_COMPILED . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . "css.concatinated.css"; echo "Writing file : " . $writeFile . "\n"; // capture output start $captureOutput = new ModulaiseCaptureOutput(); $captureOutput->start(); echo $buildTagComment; // now use the concatinated_css array to concatinate everything into its right place foreach ($concatinated_css as $css_name => $contentsArray) { $nameArrays = explode("--", $css_name); $mediaType = ModulaiseUtils::getMediaType($nameArrays[1]); if ($mediaType != "@media all") { echo "/*!NEWLINE*/" . $mediaType . " {"; } else { echo "/*!NEWLINE*/"; } foreach ($contentsArray as $key => $content) { echo $content . "\n"; } if ($mediaType != "@media all") { echo "}"; } echo "/*!NEWLINE*/"; } // render the pane //print_r($concatinated_css); // capture output end $output = $captureOutput->end(); // write the output to file ModulaiseUtils::writeFile($writeFile, $output); if ($debug) { // write an extra output file ModulaiseUtils::writeFile($writeFile . ".text", $output); } }