function compileTemplates() { $config = getZombieConfig(); $root = $config['zombie_root']; $apps = getDirContents($root . "/apps/", array("dir")); foreach ($apps as $app) { $view_dir = "{$root}/apps/{$app}/views/"; $views = getDirContents($view_dir, array("file")); foreach ($views as $view) { $file_in = $view_dir . $view; $parts = pathinfo($file_in); $view_name = $parts['filename']; $ext = $parts['extension']; $compile_dir = $view_dir . ".compiled/"; $file_out_php = $compile_dir . $view_name . ".php"; $file_out_js = $compile_dir . $view_name . ".js"; if (!file_exists($compile_dir)) { mkdir($compile_dir); } if ($ext == 'html') { $php_code = getPHPTemplate($app, $view_name); $js_code = getJSTemplate($app, $view_name); echo "writing {$file_out_php}\n\n"; file_put_contents($file_out_php, $php_code); echo "writing {$file_out_js}\n\n"; file_put_contents($file_out_js, $js_code); } else { if ($ext == 'js') { echo "copying {$file_in}\nto {$file_out_js}\n\n"; copy($file_in, $file_out_js); } else { if ($ext == 'php') { echo "copying {$file_in}\nto {$file_out_php}\n\n"; copy($file_in, $file_out_php); } } } } } }
<?php header("Content-type: text/javascript"); if ((isset($_GET['js']) || isset($_GET['template'])) && isset($_GET['app'])) { $app = preg_replace('/[^0-9a-zA-Z_]/', '', $_GET['app']); if (isset($_GET['js'])) { $js = preg_replace('/[^0-9a-zA-Z_\\/\\.]/', '', $_GET['js']); $js_file = __DIR__ . "/../../apps/" . $app . "/views/scripts/" . $js . ".js"; if (file_exists($js_file)) { echo file_get_contents($js_file); } else { header("HTTP/1.1 404 Not Found"); } } else { $template = preg_replace('/[^0-9a-zA-Z_\\/\\.]/', '', $_GET['template']); require __DIR__ . "/../../zombie-core/template/createTemplate.php"; $js_code = getJSTemplate($app, $template); echo $js_code; } } else { header("HTTP/1.1 404 Not Found"); }