/** * This function grabs all the CSS and JavaScript files sprinkled throughout Shimmie's folders, * concatenates them together into two large files (one for CSS and one for JS) and then stores * them in the /cache/ directory for serving to the user. * * Why do this? Two reasons: * 1. Reduces the number of files the user's browser needs to download. * 2. Allows these cached files to be compressed/minified by the admin. * * TODO: This should really be configurable somehow... */ protected function add_auto_html_headers() { global $config; $data_href = get_base_href(); $theme_name = $config->get_string('theme', 'default'); $this->add_html_header("<script type='text/javascript'>base_href = '{$data_href}';</script>", 40); # 404/static handler will map these to themes/foo/bar.ico or lib/static/bar.ico $this->add_html_header("<link rel='icon' type='image/x-icon' href='{$data_href}/favicon.ico'>", 41); $this->add_html_header("<link rel='apple-touch-icon' href='{$data_href}/apple-touch-icon.png'>", 42); $css_files = array(); $css_latest = 0; foreach (array_merge(zglob("lib/*.css"), zglob("ext/*/style.css"), zglob("themes/{$theme_name}/style.css")) as $css) { $css_files[] = $css; $css_latest = max($css_latest, filemtime($css)); } $css_cache_file = data_path("cache/style.{$theme_name}.{$css_latest}.css"); if (!file_exists($css_cache_file)) { $css_data = ""; foreach ($css_files as $file) { $file_data = file_get_contents($file); $pattern = '/url[\\s]*\\([\\s]*["\']?([^"\'\\)]+)["\']?[\\s]*\\)/'; $replace = 'url("../../' . dirname($file) . '/$1")'; $file_data = preg_replace($pattern, $replace, $file_data); $css_data .= $file_data . "\n"; } file_put_contents($css_cache_file, $css_data); } $this->add_html_header("<link rel='stylesheet' href='{$data_href}/{$css_cache_file}' type='text/css'>", 43); $js_files = array(); $js_latest = 0; foreach (array_merge(zglob("lib/*.js"), zglob("ext/*/script.js"), zglob("themes/{$theme_name}/script.js")) as $js) { $js_files[] = $js; $js_latest = max($js_latest, filemtime($js)); } $js_cache_file = data_path("cache/script.{$theme_name}.{$js_latest}.js"); if (!file_exists($js_cache_file)) { $js_data = ""; foreach ($js_files as $file) { $js_data .= file_get_contents($file) . "\n"; } file_put_contents($js_cache_file, $js_data); } $this->add_html_header("<script src='{$data_href}/{$js_cache_file}' type='text/javascript'></script>", 44); }
* * Each of these can be imported at the start of a function with eg "global $page, $user;" */ if (!file_exists("data/config/shimmie.conf.php")) { header("Location: install.php"); exit; } require_once "core/sys_config.inc.php"; require_once "core/util.inc.php"; // set up and purify the environment _version_check(); _sanitise_environment(); try { // load base files ctx_log_start("Opening files"); $files = array_merge(zglob("core/*.php"), zglob("ext/{" . ENABLED_EXTS . "}/main.php")); foreach ($files as $filename) { require_once $filename; } ctx_log_endok(); ctx_log_start("Connecting to DB"); // connect to the database $database = new Database(); $config = new DatabaseConfig($database); ctx_log_endok(); // load the theme parts ctx_log_start("Loading themelets"); foreach (_get_themelet_files(get_theme()) as $themelet) { require_once $themelet; } ctx_log_endok();
/** * @param bool $all * @return ExtensionInfo[] */ private function get_extensions($all) { $extensions = array(); if ($all) { $exts = zglob("ext/*/main.php"); } else { $exts = zglob("ext/{" . ENABLED_EXTS . "}/main.php"); } foreach ($exts as $main) { $extensions[] = new ExtensionInfo($main); } usort($extensions, "__extman_extcmp"); return $extensions; }
/** * @param string $_theme * @return array */ function _get_themelet_files($_theme) { $base_themelets = array(); if (file_exists('themes/' . $_theme . '/custompage.class.php')) { $base_themelets[] = 'themes/' . $_theme . '/custompage.class.php'; } $base_themelets[] = 'themes/' . $_theme . '/layout.class.php'; $base_themelets[] = 'themes/' . $_theme . '/themelet.class.php'; $ext_themelets = zglob("ext/{" . ENABLED_EXTS . "}/theme.php"); $custom_themelets = zglob('themes/' . $_theme . '/{' . ENABLED_EXTS . '}.theme.php'); return array_merge($base_themelets, $ext_themelets, $custom_themelets); }
function __construct($hint) { if (strpos($hint, "..") !== FALSE) { return; } // Select the test cases for "All" extensions. $dir = "{" . ENABLED_EXTS . "}"; // Unless the user specified just a specific extension. if (file_exists("ext/{$hint}/test.php")) { $dir = $hint; } $this->TestSuite('All tests'); foreach (zglob("ext/{$dir}/test.php") as $file) { $this->addFile($file); } }