/**
  * Prints ant properties
  */
 public static function getAntProperties()
 {
     // read all module templates
     $allModuleTemplates = ModulaiseUtils::getDirectoryAsArray(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . PATH_BOILERPLATES_MODULES);
     echo "# List all moduletemplates from boilerplates/modules folder\n";
     $firstLoop = true;
     // loop all modules files
     foreach ($allModuleTemplates as $templateName) {
         if ($firstLoop) {
             echo "ALL_MODULE_TEMPLATES_DEFAULT=" . $templateName . "\n";
             echo "ALL_MODULE_TEMPLATES=";
             $firstLoop = false;
         } else {
             echo ",";
         }
         echo $templateName;
     }
     // read all page templates
     $allPageTemplates = ModulaiseUtils::getDirectoryAsArray(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . PATH_BOILERPLATES_PAGES);
     echo "\n\n# List all pagetemplates from boilerplates/pages folder\n";
     $firstLoop = true;
     // loop all modules files
     foreach ($allPageTemplates as $templateName) {
         if ($firstLoop) {
             echo "ALL_PAGE_TEMPLATES_DEFAULT=" . $templateName . "\n";
             echo "ALL_PAGE_TEMPLATES=";
             $firstLoop = false;
         } else {
             echo ",";
         }
         echo $templateName;
     }
     // read all project templates
     $allBoilerPlates = ModulaiseUtils::getDirectoryAsArray(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . PATH_BOILERPLATES_PROJECTS);
     echo "\n\n# List all boilerplates from boilerplates/projects folder\n";
     $firstLoop = true;
     // loop all modules files
     foreach ($allBoilerPlates as $boilerPlate) {
         if ($firstLoop) {
             echo "ALL_BOILERPLATES_DEFAULT=" . $boilerPlate . "\n";
             echo "ALL_BOILERPLATES=";
             $firstLoop = false;
         } else {
             echo ",";
         }
         echo $boilerPlate;
     }
     // read all build packages
     $allBuildPackages = ModulaiseUtils::getDirectoryAsArray(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . PATH_BUILDS);
     // flip, we want latest builds first
     $allBuildPackages = array_reverse($allBuildPackages, true);
     echo "\n\n# List all buildPackages from build folder\n";
     $firstLoop = true;
     $i = 0;
     // loop all modules files
     foreach ($allBuildPackages as $buildTag) {
         $i++;
         if ($i < 20 && ModulaiseUtils::EndsWith($buildTag, ".zip")) {
             if ($firstLoop) {
                 echo "ALL_BUILDPACKAGES_DEFAULT=" . substr($buildTag, 0, -4) . "\n";
                 echo "ALL_BUILDPACKAGES=";
                 $firstLoop = false;
             } else {
                 echo ",";
             }
             echo substr($buildTag, 0, -4);
         }
     }
     // read all deploy destinations
     $allDeployDestinations = ModulaiseUtils::getDirectoryAsArray(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . PATH_TO_DEPLOY_TARGETS, ONLY_DIRECTORIES);
     echo "\n\n# List all deploy destinations from config-project folder\n";
     $firstLoop = true;
     // loop all modules files
     foreach ($allDeployDestinations as $destination) {
         if ($firstLoop) {
             echo "ALL_DEPLOY_DESTINATIONS_DEFAULT=" . $destination . "\n";
             echo "ALL_DEPLOY_DESTINATIONS=";
             $firstLoop = false;
         } else {
             echo ",";
         }
         echo $destination;
     }
 }
 /**
  * Initializes all global settings and all global modules
  */
 public static function initialize()
 {
     $debug = false;
     // set the buildtag
     if (isset($_REQUEST["buildTag"])) {
         self::$buildTag = $_REQUEST["buildTag"];
     } else {
         self::$buildTag = "no-buildtag";
     }
     // Include modulaise php scripts to the include path
     set_include_path(get_include_path() . PATH_SEPARATOR . self::$DIR_MODULAISE_ROOT);
     // Read global configuration file
     ModulaiseUtils::readConfigurationFile(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "modulaise" . DIRECTORY_SEPARATOR . "config-global" . DIRECTORY_SEPARATOR . "global.config");
     // Read configuration file
     ModulaiseUtils::readConfigurationFile(ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "modulaise" . DIRECTORY_SEPARATOR . "config-project" . DIRECTORY_SEPARATOR . "project.config");
     // set the path to modules if not already set
     if (self::$PATH_MODULES === false) {
         self::$PATH_MODULES = PATH_MODULES;
     }
     // reset cache
     self::$modulePaneContentsCache = array();
     self::$globalPaneContent = new ModulaisePaneContent();
     self::$globalModules = array();
     // set the static path to the page
     if (self::$staticContentPath === false) {
         if (self::$buildMode == SHOW_EXPORT) {
             self::$staticContentPath = PATH_MODULES_BUILD;
         } else {
             self::$staticContentPath = PATH_MODULES_DEVELOPMENT;
         }
     }
     // path to all modules
     $allModulesPath = self::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . self::$PATH_MODULES;
     if ($debug) {
         self::printComment("\n\n" . get_class() . "->initialize(): \n\nallModulesPath=" . $allModulesPath . "\n\n");
     }
     // add all global modules to global modules array
     $allModuleNames = ModulaiseUtils::getDirectoryAsArray($allModulesPath, ONLY_DIRECTORIES);
     // build a list of all global modules
     foreach ($allModuleNames as $moduleId) {
         if (substr($moduleId, 0, 1) == "0") {
             $module = new ModulaiseModule($moduleId);
             array_push(self::$globalModules, $module);
             self::$globalPaneContent->addPaneContent($module->getPaneContent());
         }
     }
     if ($debug) {
         $a = print_r(self::$globalPaneContent->getContent(), TRUE);
         self::printComment("\n\n" . get_class() . "->initialize(): \n\n" . $a . "\n\n");
     }
 }
 public static function getPages()
 {
     // Get all pages
     $returnArray = array();
     $pageDirectory = ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . PATH_PAGES;
     $allPages = ModulaiseUtils::getDirectoryAsArray($pageDirectory);
     foreach ($allPages as $file) {
         if (ModulaiseUtils::EndsWith($file, ".php")) {
             $pageName = substr($file, 0, -4);
             $currentLink = PATH_PAGES . "/" . substr($file, 0, -4) . ".php";
             $cacheLink = PATH_PAGES . "/" . substr($file, 0, -4) . ".php?writeCachedHtml=true";
             $exportLink = PATH_PAGES_COMPILED . "/" . substr($file, 0, -4) . ".html";
             array_push($returnArray, new ModulaiseIndexPageElement($pageName, $currentLink, $exportLink, $cacheLink));
         }
     }
     return $returnArray;
 }
 /**
  * Initialize
  */
 public function initialize($moduleId)
 {
     $debug = false;
     // first get the directory contents of the module
     $targetDir = ModulaiseController::$DIR_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . ModulaiseController::$PATH_MODULES . DIRECTORY_SEPARATOR . $moduleId;
     $moduleDirectory = ModulaiseUtils::getDirectoryAsArray($targetDir, ONLY_DIRECTORIES);
     foreach ($moduleDirectory as $outerDir) {
         $d = explode(DELIMITER, $outerDir);
         if ($debug) {
             ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): \nd[0]=" . $d[0] . "\nd[1]=" . $d[1] . "\nd[2]=" . $d[2] . "\n\n");
         }
         // check for html
         if ($d[0] == "html") {
             // html_head pane
             if (isset($d[1]) && $d[1] == "head") {
                 $priorityId = -1;
                 if (isset($d[2]) && ctype_digit($d[2])) {
                     $priorityId = intval($d[2]);
                 }
                 if (!isset($d[2])) {
                     $priorityId = 75;
                 }
                 if ($priorityId != -1) {
                     // Set target pane
                     if ($priorityId < 50) {
                         $targetPane = PANE_HTML_HEAD_FIRST;
                     } else {
                         $targetPane = PANE_HTML_HEAD_LAST;
                     }
                     // add all snippets from html_head directory to panecontent
                     $innerDirectory = ModulaiseUtils::getDirectoryAsArray($targetDir . DIRECTORY_SEPARATOR . $outerDir, ONLY_FILES);
                     foreach ($innerDirectory as $file) {
                         $this->addFileSnippet($moduleId, $targetPane, $priorityId, $outerDir . DIRECTORY_SEPARATOR . $file);
                     }
                 }
             }
             // html_foot pane
             if (isset($d[1]) && $d[1] == "foot") {
                 $priorityId = -1;
                 if (isset($d[2]) && ctype_digit($d[2])) {
                     $priorityId = intval($d[2]);
                 }
                 if (!isset($d[2])) {
                     $priorityId = 75;
                 }
                 if ($priorityId != -1) {
                     // Set target pane
                     if ($priorityId < 50) {
                         $targetPane = PANE_HTML_FOOT_FIRST;
                     } else {
                         $targetPane = PANE_HTML_FOOT_LAST;
                     }
                     // add all snippets from html_foot directory to panecontent
                     $innerDirectory = ModulaiseUtils::getDirectoryAsArray($targetDir . DIRECTORY_SEPARATOR . $outerDir, ONLY_FILES);
                     foreach ($innerDirectory as $file) {
                         $this->addFileSnippet($moduleId, $targetPane, $priorityId, $outerDir . DIRECTORY_SEPARATOR . $file);
                     }
                 }
             }
         }
         // check for javascript
         if ($d[0] == "js") {
             // js_head pane
             if (isset($d[1]) && $d[1] == "head") {
                 $priorityId = -1;
                 if (isset($d[2]) && ctype_digit($d[2])) {
                     $priorityId = intval($d[2]);
                 }
                 if (!isset($d[2])) {
                     $priorityId = 75;
                 }
                 if ($priorityId != -1) {
                     $targetPane = PANE_JS_HEAD;
                     // add all snippets from js_head directory to panecontent
                     $innerDirectory = ModulaiseUtils::getDirectoryAsArray($targetDir . DIRECTORY_SEPARATOR . $outerDir, ONLY_FILES);
                     if ($debug) {
                         ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): innerDirectory=" . $innerDirectory . "\n\n");
                     }
                     foreach ($innerDirectory as $file) {
                         if ($debug) {
                             ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): " . $moduleId . ", " . $targetPane . ", " . $priorityId . ", " . $outerDir . DIRECTORY_SEPARATOR . $file . "\n\n");
                         }
                         if (ModulaiseController::$buildMode == SHOW_DEVELOPMENT) {
                             $this->addStringSnippet($moduleId, $targetPane, $priorityId, ModulaiseUtils::getJsImportStatement($moduleId . "/" . $outerDir . "/" . $file));
                         }
                         if (ModulaiseController::$buildMode == SHOW_EXPORT) {
                         }
                         if (ModulaiseController::$buildMode == BUILD_EXPORT) {
                             $this->addFileSnippet($moduleId, $targetPane, $priorityId, $outerDir . DIRECTORY_SEPARATOR . $file);
                         }
                     }
                 }
             }
             // js_foot pane
             if (isset($d[1]) && $d[1] == "foot") {
                 $priorityId = -1;
                 if (isset($d[2]) && ctype_digit($d[2])) {
                     $priorityId = $d[2];
                 }
                 if (!isset($d[2])) {
                     $priorityId = 75;
                 }
                 if ($priorityId != -1) {
                     // Set target pane
                     $targetPane = PANE_JS_FOOT;
                     // add all snippets from js_foot directory to panecontent
                     $innerDirectory = ModulaiseUtils::getDirectoryAsArray($targetDir . DIRECTORY_SEPARATOR . $outerDir, ONLY_FILES);
                     foreach ($innerDirectory as $file) {
                         if ($debug) {
                             ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): " . $moduleId . ", " . $targetPane . ", " . $priorityId . ", " . $outerDir . DIRECTORY_SEPARATOR . $file . "\n\n");
                         }
                         if (ModulaiseController::$buildMode == SHOW_DEVELOPMENT) {
                             $this->addStringSnippet($moduleId, $targetPane, $priorityId, ModulaiseUtils::getJsImportStatement($moduleId . "/" . $outerDir . "/" . $file));
                         }
                         if (ModulaiseController::$buildMode == SHOW_EXPORT) {
                             $this->addFileSnippet($moduleId, $targetPane, $priorityId, $outerDir . DIRECTORY_SEPARATOR . $file);
                         }
                         if (ModulaiseController::$buildMode == BUILD_EXPORT) {
                             $this->addFileSnippet($moduleId, $targetPane, $priorityId, $outerDir . DIRECTORY_SEPARATOR . $file);
                         }
                     }
                 }
             }
         }
         // check for css
         if ($d[0] == "css") {
             if ($debug) {
                 ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): d[0]==\"css\"\n\n");
             }
             $priorityId = -1;
             if (isset($d[1])) {
                 if (ctype_digit($d[1]) || is_int($d[1])) {
                     $priorityId = intval($d[1]);
                 }
             }
             if (!isset($d[1])) {
                 $priorityId = 75;
             }
             if ($debug) {
                 ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): priorityId=" . $priorityId . "\n\n");
             }
             if ($priorityId != -1) {
                 if ($debug) {
                     ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): priorityId != NULL\n\n");
                 }
                 // add all CSS snippets from css directory to panecontent
                 $innerDirectory = ModulaiseUtils::getDirectoryAsArray($targetDir . DIRECTORY_SEPARATOR . $outerDir, ONLY_FILES);
                 if ($debug) {
                     ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): innerDirectory=" . $innerDirectory . "\n\n");
                 }
                 foreach ($innerDirectory as $file) {
                     // set the target pane name to this complicated formula
                     $targetPane = PANE_CSS . "--" . $priorityId . "--" . $file;
                     if ($debug) {
                         ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): " . $moduleId . ", " . $targetPane . ", " . $priorityId . ", " . $outerDir . DIRECTORY_SEPARATOR . $file . "\n\n");
                     }
                     if ($debug) {
                         ModulaiseController::printComment("\n\n" . get_class() . "->initializePaneContent(): " . $moduleId . ", " . $targetPane . ", " . $priorityId . ", " . $outerDir . DIRECTORY_SEPARATOR . $file . "\n\n");
                     }
                     if (ModulaiseController::$buildMode == SHOW_DEVELOPMENT) {
                         $this->addStringSnippet($moduleId, $targetPane, $priorityId, ModulaiseUtils::getCssImportStatement($moduleId . "/" . $outerDir . "/" . $file, $file));
                     }
                     if (ModulaiseController::$buildMode == SHOW_EXPORT) {
                     }
                     if (ModulaiseController::$buildMode == BUILD_EXPORT) {
                         $this->addExportCssSnippet($moduleId, $targetPane, $priorityId, $outerDir . DIRECTORY_SEPARATOR . $file);
                     }
                 }
             }
         }
     }
     $this->sortPanes();
     return true;
 }
 /**
  * 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);
     }
 }