/** * Generates a new manifest file and saves it to {@link MANIFEST_FILE} */ static function compileManifest() { // Config manifest $baseDir = dirname($_SERVER['SCRIPT_FILENAME']) . "/.."; $baseDir = ereg_replace("/[^/]+/\\.\\.", "", $baseDir); $baseDir = preg_replace("/\\\\/", "/", $baseDir); // locate and include the exclude files $topLevel = scandir($baseDir); foreach ($topLevel as $file) { if ($file[0] == '.') { continue $fullPath = $baseDir . '/' . $file; } if (@is_dir($fullPath . '/') && file_exists($fullPath . '/_exclude.php')) { require_once $fullPath . '/_exclude.php'; } } // Class manifest $classManifest = array(); if (is_array(self::$restrict_to_modules) && count(self::$restrict_to_modules)) { // $restrict_to_modules is set, so we include only those specified // modules foreach (self::$restrict_to_modules as $module) { ManifestBuilder::getClassManifest($baseDir . '/' . $module, $classManifest); } } else { // Include all directories which have an _config.php file but don't // have an _manifest_exclude file $topLevel = scandir($baseDir); foreach ($topLevel as $filename) { if ($filename[0] == '.') { continue; } if (@is_dir("{$baseDir}/{$filename}") && file_exists("{$baseDir}/{$filename}/_config.php") && !file_exists("{$baseDir}/{$filename}/_manifest_exclude")) { ManifestBuilder::getClassManifest("{$baseDir}/{$filename}", $classManifest); } } } $manifest = "\$_CLASS_MANIFEST = " . var_export($classManifest, true) . ";\n"; // Load the manifest in, so that the autoloader works global $_CLASS_MANIFEST; $_CLASS_MANIFEST = $classManifest; // _config.php manifest global $databaseConfig; $topLevel = scandir($baseDir); foreach ($topLevel as $filename) { if ($filename[0] == '.') { continue; } if (@is_dir("{$baseDir}/{$filename}/") && file_exists("{$baseDir}/{$filename}/_config.php") && !file_exists("{$baseDir}/{$filename}/_manifest_exclude")) { $manifest .= "require_once(\"{$baseDir}/{$filename}/_config.php\");\n"; // Include this so that we're set up for connecting to the database // in the rest of the manifest builder require_once "{$baseDir}/{$filename}/_config.php"; } } if (!project()) { user_error("\$project isn't set", E_USER_WARNING); } // Template & CSS manifest $templateManifest = array(); $cssManifest = array(); // Only include directories if they have an _config.php file $topLevel = scandir($baseDir); foreach ($topLevel as $filename) { if ($filename[0] == '.') { continue; } if ($filename != 'themes' && @is_dir("{$baseDir}/{$filename}") && file_exists("{$baseDir}/{$filename}/_config.php")) { ManifestBuilder::getTemplateManifest($baseDir, $filename, $templateManifest, $cssManifest); } } // Get themes if (file_exists("{$baseDir}/themes")) { $themeDirs = scandir("{$baseDir}/themes"); foreach ($themeDirs as $themeDir) { if (substr($themeDir, 0, 1) == '.') { continue; } // The theme something_forum is understood as being a part of the theme something $themeName = strtok($themeDir, '_'); ManifestBuilder::getTemplateManifest($baseDir, "themes/{$themeDir}", $templateManifest, $cssManifest, $themeName); } } // Ensure that any custom templates get favoured ManifestBuilder::getTemplateManifest($baseDir, project(), $templateManifest, $cssManifest); $manifest .= "\$_TEMPLATE_MANIFEST = " . var_export($templateManifest, true) . ";\n"; $manifest .= "\$_CSS_MANIFEST = " . var_export($cssManifest, true) . ";\n"; DB::connect($databaseConfig); // Database manifest $allClasses = ManifestBuilder::allClasses($classManifest); $manifest .= "\$_ALL_CLASSES = " . var_export($allClasses, true) . ";\n"; global $_ALL_CLASSES; $_ALL_CLASSES = $allClasses; // Write manifest to disk $manifest = "<?php\n{$manifest}\n?>"; if ($fh = fopen(MANIFEST_FILE, "w")) { fwrite($fh, $manifest); fclose($fh); } else { die("Cannot write manifest file! Check permissions of " . MANIFEST_FILE); } }
/** * Return an array containing information for the manifest * @param $baseDir The root directory to analyse * @param $excludedFolders An array folder names to exclude. These don't care about where the * folder appears in the hierarchy, so be careful */ static function get_manifest_info($baseDir, $excludedFolders = array()) { // locate and include the exclude files $topLevel = scandir($baseDir); foreach ($topLevel as $file) { if ($file[0] == '.') { continue $fullPath = ''; } $fullPath = $baseDir . '/' . $file; if (@is_dir($fullPath . '/') && file_exists($fullPath . '/_exclude.php')) { require_once $fullPath . '/_exclude.php'; } } // Project - used to give precedence to template files $project = null; // Class, CSS, template manifest $classManifest = array(); $templateManifest = array(); $cssManifest = array(); if (is_array(self::$restrict_to_modules) && count(self::$restrict_to_modules)) { // $restrict_to_modules is set, so we include only those specified // modules foreach (self::$restrict_to_modules as $module) { ManifestBuilder::getClassManifest($baseDir . '/' . $module, $excludedFolders, $classManifest); } } else { // Include all directories which have an _config.php file but don't // have an _manifest_exclude file $topLevel = scandir($baseDir); foreach ($topLevel as $filename) { if ($filename[0] == '.') { continue; } if ($filename == 'themes') { continue; } if (in_array($filename, $excludedFolders)) { continue; } if (@is_dir("{$baseDir}/{$filename}") && file_exists("{$baseDir}/{$filename}/_config.php") && !file_exists("{$baseDir}/{$filename}/_manifest_exclude")) { // Get classes, templates, and CSS files ManifestBuilder::getClassManifest("{$baseDir}/{$filename}", $excludedFolders, $classManifest); ManifestBuilder::getTemplateManifest($baseDir, $filename, $excludedFolders, $templateManifest, $cssManifest); // List the _config.php files $manifestInfo["require_once"][] = "{$baseDir}/{$filename}/_config.php"; // Find the $project variable in the relevant config file without having to execute the config file if (preg_match("/\\\$project\\s*=\\s*[^\n\r]+[\n\r]/", file_get_contents("{$baseDir}/{$filename}/_config.php"), $parts)) { eval($parts[0]); } } } } // Get themes if (file_exists("{$baseDir}/themes")) { $themeDirs = scandir("{$baseDir}/themes"); foreach ($themeDirs as $themeDir) { if (substr($themeDir, 0, 1) == '.') { continue; } // The theme something_forum is understood as being a part of the theme something $themeName = strtok($themeDir, '_'); ManifestBuilder::getTemplateManifest($baseDir, "themes/{$themeDir}", $excludedFolders, $templateManifest, $cssManifest, $themeName); } } // Build class-info array from class manifest $allClasses = ManifestBuilder::allClasses($classManifest); // Ensure that any custom templates get favoured if (!$project) { user_error("\$project isn't set", E_USER_WARNING); } ManifestBuilder::getTemplateManifest($baseDir, $project, $excludedFolders, $templateManifest, $cssManifest); $manifestInfo["globals"]["_CLASS_MANIFEST"] = $classManifest; $manifestInfo["globals"]["_ALL_CLASSES"] = $allClasses; $manifestInfo["globals"]["_TEMPLATE_MANIFEST"] = $templateManifest; $manifestInfo["globals"]["_CSS_MANIFEST"] = $cssManifest; return $manifestInfo; }