/** * Helper to create an img tag * @param string $uri image uri * @param array $attrs attribute key value pairs * @param boolean $return if set to true a string is returned * @return string */ function img($uri, $attrs = array(), $return = false) { static $mode = false; static $version = false; static $web_root = false; if ($mode === false) { $config = getZombieConfig(); $mode = $config['env']; $web_root = $config['web_root']; if ($web_root == '/') { $web_root = ''; } if ($mode == 'prod') { require_once $config['zombie_root'] . "/config/version.php"; $version = version(); $version = $version['images']; } } $html_attrs = attrsToString($attrs); $uri = imgUri($uri, $mode, $version, $web_root); $tag = "<img src=\"{$uri}\" {$html_attrs} />"; if ($return) { return $tag; } else { echo $tag; } }
function __construct($template, $app, $base_dir, $options = array()) { $this->config = getZombieConfig(); $this->template = $template; $this->app = strtolower($app); $this->options = $options; $this->base_dir = $base_dir; }
function compile($options) { $config = getZombieConfig(); $root = $config['zombie_root']; if (@(include __DIR__ . "/../../../config/version.php")) { $old_version = version(); } else { $old_version = array('css' => 'css', 'js' => 'js', 'images' => 'images'); } $version = uniqid(); $compile_css = false; $compile_js = false; $compile_images = false; $compile_templates = false; if (isset($options['css'])) { $compile_css = true; $compile_js = true; $compile_templates = true; } if (isset($options['js'])) { $compile_js = true; $compile_css = true; $compile_templates = true; } if (isset($options['images'])) { $compile_images = true; $compile_css = true; $compile_templates = true; } if (isset($options['templates'])) { $compile_templates = true; } if (isset($options['all']) || !$compile_css && !$compile_js && !$compile_images && !$compile_templates) { $compile_css = true; $compile_js = true; $compile_images = true; $compile_templates = true; } $css_version = $compile_css ? $version : $old_version['css']; $js_version = $compile_js ? $version : $old_version['js']; $images_version = $compile_images ? $version : $old_version['images']; writeVersion($css_version, $js_version, $images_version); if ($compile_css) { compileCss($css_version, $old_version['css'], $images_version); } if ($compile_templates) { compileTemplates(); } if ($compile_js) { compileJs($js_version, $old_version['js'], $css_version, $images_version); } if ($compile_images) { copyImages($images_version, $old_version['images']); } }
public function __construct() { $this->config = getZombieConfig(); $this->json = array(); $this->view_base = classToUnderscore(get_class($this)); $sess_class = underscoreToClass($this->config['session']['type'] . '_' . 'session'); $this->session = $sess_class::getSession(); $this->mobileInit(); $this->bouncer = "Basic"; $this->allowed_formats = array("Html", "FourOhFour"); }
/** * Construct a new query. * * @param string $query the query to be executed. * @param string $connector the connector from the config file. */ public function __construct($query = '', $connector = 'mysql') { if (MysqlQuery::$db == null) { $config = getZombieConfig(); MysqlQuery::$db = mysql_connect($config[$connector]['host'], $config[$connector]['user'], $config[$connector]['pass']); mysql_select_db($config[$connector]['database'], MysqlQuery::$db); } if (get_magic_quotes_gpc()) { $this->magic_quotes_on = true; } $this->query = $query; }
/** * decrypt data with default cipher and password * @param string $data encrypted data * @param string $pass optional password * @param string $type optional algorithm * @return string */ function decrypt($data, $pass = null, $type = null) { if (is_null($type)) { $config = getZombieConfig(); $type = $config['crypt']['type']; if (is_null($pass)) { $pass = $config['crypt']['pass']; } } $iv = substr($data, 0, 16); $data = substr($data, 16); $decrypted = openssl_decrypt($data, $type, $pass, false, $iv); return $decrypted; }
/** * @package Util * @ignore */ function deploy() { $config = getZombieConfig(); $zombie_root = $config['zombie_root']; $deploy_root = $config['deploy_root']; if (!isset($config['deploy_root'])) { die("deploy_root must be set in config before deploying.\n"); } if (!file_exists($zombie_root . "/config/version.php")) { die("It appears you haven't compiled your javascript.\n" . "Don't forget to do this before deploying.\n"); } if (!file_exists($deploy_root . "/config/config.php")) { die("Deploy directory has no config/config.php\n" . "Create it before deploying.\n"); } if (file_get_contents($zombie_root . "/config/version.php") == file_get_contents($deploy_root . "/config/version.php")) { echo "NOTICE: You have not compiled since last deploy.\n"; } echo "Deleting old.\n"; exec("rm -rf {$deploy_root}/web"); exec("rm -rf {$deploy_root}/apps"); exec("rm -rf {$deploy_root}/model"); exec("rm -rf {$deploy_root}/zombie-core"); exec("rm -rf {$deploy_root}/zombie.php"); echo "Copying config files.\n"; exec("cp {$zombie_root}/config/version.php {$deploy_root}/config/version.php"); exec("cp {$zombie_root}/config/javascript.xml {$deploy_root}/config/javascript.xml"); exec("cp {$zombie_root}/config/images.xml {$deploy_root}/config/images.xml"); exec("cp {$zombie_root}/config/stylesheets.xml {$deploy_root}/config/stylesheets.xml"); echo "Copying apps.\n"; exec("cp -r {$zombie_root}/apps {$deploy_root}/apps"); echo "Copying model.\n"; exec("cp -r {$zombie_root}/model {$deploy_root}/model"); echo "Copying web.\n"; exec("cp -r {$zombie_root}/web {$deploy_root}/web"); echo "Copying core.\n"; exec("cp -r {$zombie_root}/zombie-core {$deploy_root}/zombie-core"); symlink($deploy_root . "/zombie-core/zombie.php", $deploy_root . "/zombie.php"); echo "Migrating database.\n"; echo passthru("php {$deploy_root}/zombie.php migrate action=run"); $other_config = file_get_contents("{$deploy_root}/config/config.php"); $other_config = str_replace("getZombieConfig", "getDeployConfig", $other_config); eval("?>" . $other_config); $other_config = getDeployConfig(); if ($config['web_root'] != $other_config['web_root']) { echo "Compiling.\n"; echo passthru("php {$deploy_root}/zombie.php compile"); } echo "\nDone.\n"; }
function compileCss($version, $old_version, $images_version) { echo "COMPILING CSS\n"; $config = getZombieConfig(); $root = $config['zombie_root']; exec("rm -rf {$root}/web/build/css/" . $old_version); exec("mkdir -p {$root}/web/build/css/" . $version); $files = getCssFileLists(); foreach ($files as $file => $list) { $css = compileCssList($list, true, $version, $images_version); $out_file = $root . "/web/build/css/{$version}/{$file}.css"; echo "writing {$out_file}\n"; file_put_contents($out_file, $css); } echo "\n"; }
function getJSTemplate($app, $view, $compress = true) { $config = getZombieConfig(); $root = $config['zombie_root']; $input_file = "{$root}/apps/{$app}/views/{$view}.html"; $js_file = "{$root}/apps/{$app}/views/{$view}.js"; if (file_exists($input_file)) { $function_declare = "zs.template.templates['{$app}/{$view}'] = function"; $js_code = getTemplateOutput($input_file, 'JS', $compress, $function_declare); return $js_code; } else { if (file_exists($js_file)) { $js_code = file_get_contents($js_file); $js_code = "zs.template.templates['{$app}/{$view}'] = function() { " . "return (" . trim($js_code) . ")();}\n"; return $js_code; } } }
function doInstall($package_name) { echo "\nINSTALLING PACKAGE: {$package_name}\n"; $config = getZombieConfig(); $zroot = $config['zombie_root']; $files_to_copy = array(); $package_dir = __DIR__ . "/" . $package_name; if (!file_exists($package_dir)) { die("Package '{$package_name}' does not exist.\n"); } $find_cmd = "find " . $package_dir; $list = shell_exec($find_cmd); $files_to_copy = explode("\n", trim($list)); $pdir_len = strlen($package_dir) + 1; foreach ($files_to_copy as $key => $file) { $files_to_copy[$key] = substr($file, $pdir_len); } foreach ($files_to_copy as $file) { $src_file = $package_dir . "/" . $file; $dest_file = $zroot . "/" . $file; if ($file == "package.json" || $file == "install.php") { continue; } if (file_exists($dest_file)) { if (!is_dir($dest_file)) { echo "skipping {$dest_file}\n"; } continue; } if (is_dir($src_file)) { echo "mkdir {$dest_file}\n"; mkdir($dest_file); } else { echo "writing {$dest_file}\n"; copy($src_file, $dest_file); } } $install_file = $package_dir . "/install.php"; if (file_exists($install_file)) { echo shell_exec("php {$install_file}"); } }
function compileJs($version, $old_version, $css_version, $images_version) { $config = getZombieConfig(); $root = $config['zombie_root']; $js_config = getJsCompileConfig(); $base_dir = "{$root}/web/build/js/{$version}"; exec("rm -rf {$root}/web/build/js/" . $old_version); exec("mkdir -p {$base_dir}"); if (!file_exists(__DIR__ . "/tmp")) { mkdir(__DIR__ . "/tmp"); } $apps_dir = __DIR__ . "/../../../apps/"; $apps = getDirContents($apps_dir, array('dir')); foreach ($apps as $app) { $create_dir = false; foreach ($js_config['standalone'] as $arr) { if ($arr["app"] == $app) { $create_dir = true; } } foreach ($js_config['nocompile'] as $arr) { if ($arr["app"] == $app) { $create_dir = true; } } $templates = getDirContents($apps_dir . $app . "/views/.compiled/", array("file")); foreach ($templates as $template) { if (substr($template, -3) == '.js') { $create_dir = true; if (!isset($js_config['module'][$app])) { $js_config['module'][$app] = array(); } break; } } if ($create_dir || !empty($js_config['module'][$app])) { echo "creating dir {$base_dir}/{$app}\n"; mkdir("{$base_dir}/{$app}"); } } $main_files = array(); $loaded_js = "var zs = zs || {};\n" . "zs.settings = zs.settings || {};\n" . "zs.settings.mode = \"prod\";\n" . "zs.settings.version = \"{$version}\";\n" . "zs.settings.cssVersion = \"{$css_version}\";\n" . "zs.settings.imagesVersion = \"{$images_version}\";\n" . "zs.util = zs.util || {};\n" . "zs.util.scripts = zs.util.scripts || {};\n"; foreach ($js_config['main'] as $main) { $dir = realpath(__DIR__ . "/../../../apps/" . $main["app"] . "/views/scripts"); $file = $dir . '/' . $main["file"]; array_push($main_files, $file); $loaded_js .= "zs.util.scripts[\"/build/js/{$version}/{$main["app"]}/{$main["file"]}\"] = \"loaded\";\n"; } echo "\nCOMPILING MAIN JS:\n "; echo implode("\n ", $main_files) . "\n"; $tmp_file = __DIR__ . "/tmp/tmp.js"; file_put_contents($tmp_file, $loaded_js); array_unshift($main_files, $tmp_file); $main_js = getCompiledJs($main_files); $write_file = $base_dir . "/main.js"; echo "WRITING MAIN JS: {$write_file}\n"; file_put_contents($write_file, $main_js); echo "\nCOMPILING STANDALONE JS\n\n"; foreach ($js_config['standalone'] as $standalone) { $dir = realpath(__DIR__ . "/../../../apps/" . $standalone["app"] . "/views/scripts"); $file = $dir . '/' . $standalone["file"]; echo "compiling {$file}\n"; $standalone_compiled = getCompiledJs(array($file)); $write_file = $base_dir . "/" . $standalone["app"] . "/" . $standalone["file"]; echo "writing {$write_file}\n\n"; file_put_contents($write_file, $standalone_compiled); } echo "\nCOPYING NOCOMPILE JS\n\n"; foreach ($js_config['nocompile'] as $nocompile) { $dir = realpath(__DIR__ . "/../../../apps/" . $nocompile["app"] . "/views/scripts"); $file = $dir . '/' . $nocompile["file"]; echo "copying {$file}\n"; $write_file = $base_dir . "/" . $nocompile["app"] . "/" . $nocompile["file"]; echo "to {$write_file}\n\n"; file_put_contents($write_file, file_get_contents($file)); } echo "\nCOMPILING MODULE JS\n\n"; foreach ($js_config['module'] as $app => $js_files) { $templates = getDirContents($apps_dir . $app . "/views/.compiled/", array("file")); foreach ($templates as $key => $template) { if (substr($template, -3) !== '.js') { unset($templates[$key]); } } if (count($js_files) > 0 || count($templates) > 0) { echo "compiling module {$app}\n "; $dir = realpath(__DIR__ . "/../../../apps/" . $app . "/views/scripts"); $tdir = realpath(__DIR__ . "/../../../apps/" . $app . "/views/.compiled"); $read_files = array(); $loaded_js = ''; foreach ($templates as $template) { array_push($read_files, $tdir . '/' . $template); $loaded_js .= "zs.util.scripts[\"/build/js/{$version}/{$app}/template/{$template}\"] = \"loaded\";\n"; } foreach ($js_files as $js_file) { array_push($read_files, $dir . '/' . $js_file); $loaded_js .= "zs.util.scripts[\"/build/js/{$version}/{$app}/{$js_file}\"] = \"loaded\";\n"; } echo implode("\n ", $read_files); echo "\n"; $compiled = $loaded_js . getCompiledJs($read_files); $write_file = $base_dir . "/" . $app . "/main.js"; echo "writing {$write_file}\n\n"; file_put_contents($write_file, $compiled); } else { echo "skipping module {$app} (no javascript)\n\n"; } } exec("rm -rf " . __DIR__ . "/tmp"); }
public function templatePrepare() { if (!isset($this->options['table'])) { die("table option required:\nzombie.php generate-app app=<app> template=mysql_crud table=<table>\n"); } $config = getZombieConfig(); $this->addView('index'); $this->addView('edit'); $this->addScript('main'); $this->addModel(); $this->replace['AJAX_COMMA_SEP_FIELDS'] = ''; $this->replace['AJAX_COMMA_SEP_FIELDS_WID'] = ''; $this->replace['ENUM_OPTIONS'] = ''; $this->replace['FIELD_NAME'] = ''; $this->replace['FIELD_NAME_NICE'] = ''; $this->replace['HTML_EDIT_FIELDS'] = ''; $this->replace['HTML_EDIT_FIELDS'] = ''; $this->replace['HTML_FIELDS_TD'] = ''; $this->replace['HTML_FIELDS_TH'] = ''; $this->replace['INSERT_FIELDS_COMMA_SEP'] = ''; $this->replace['INSERT_DOLLAR_PARAMS'] = ''; $this->replace['INSERT_FUNC_PARAMS_APP'] = ''; $this->replace['INSERT_FUNC_PARAMS_MODEL'] = ''; $this->replace['INSERT_REQUEST_PARAMS'] = ''; $this->replace['INSERT_REQUEST_PARAMS'] = ''; $this->replace['JOIN_FIELD'] = ''; $this->replace['MODEL_GET_ALL'] = ''; $this->replace['MYSQL_JOINS'] = ''; $this->replace['MYSQL_ADD_PARAMS'] = ''; $this->replace['QUERY_INSERT_ADD_PARAMS'] = ''; $this->replace['REQUIRED_CLASS'] = ''; $this->replace['SET_FIELDS_COMMA_SEP'] = ''; $this->replace['SQL_FIELDS_COMMA_SEP'] = ''; $this->replace['SQL_JOINS'] = ''; $this->replace['TABLE_NAME'] = $this->options['table']; $this->replace['UPDATE_REQUEST_PARAMS'] = ''; $query = new MysqlQuery(); $table_desc = $query->describe($this->options['table']); $i = 0; $field_templates = array(); foreach ($table_desc as $sql_field) { ++$i; $validators = array(); $field_name = $sql_field['Field']; $field_name_nice = ucwords(str_replace("_", " ", $field_name)); $field_type = $sql_field['Type']; $is_join = false; if ($sql_field['Null'] == 'NO') { array_push($validators, "required"); } if ($field_type == "text") { $html_type = "textarea"; $field_template = $this->getField("textarea"); } else { if (preg_match('/_id$/', $field_name)) { $html_type = "select"; $is_join = true; $field_template = $this->getField("table_select"); } else { if (strpos($field_type, 'enum') === 0) { $html_type = "select"; $field_template = $this->getField("enum_select"); } else { $html_type = "input"; $field_template = $this->getField("textbox"); $matches = array(); if (preg_match('/char\\((\\d+)\\)$/', $field_type, $matches)) { $len = $matches[1]; $v = "maxlen=" . $len; array_push($validators, $v); } else { if (preg_match('/^int/', $field_type, $matches)) { array_push($validators, "int"); } else { if (preg_match('/^decimal|^float|^double/', $field_type, $matches)) { array_push($validators, "number"); } } } } } } if (count($validators) > 0) { $this->replace['VALIDATE'] = "validate=\"" . implode(",", $validators) . "\" "; } else { $this->replace['VALIDATE'] = ""; } $this->replace['INSERT_FIELDS_COMMA_SEP'] .= $sql_field['Field'] . "\n , "; $this->replace['UPDATE_REQUEST_PARAMS'] .= "\$request['{$field_name}'],\n "; $this->replace['SQL_FIELDS_COMMA_SEP'] .= $this->options['table'] . "." . $sql_field['Field'] . "\n , "; $this->replace['AJAX_COMMA_SEP_FIELDS_WID'] .= ' "' . $field_name . '":form.find("' . $html_type . '[name=' . $field_name . "]\").val(),\n"; if ($field_name != 'id') { $this->replace['AJAX_COMMA_SEP_FIELDS'] .= ' "' . $field_name . '":form.find("' . $html_type . '[name=' . $field_name . "]\").val(),\n"; if (!$is_join) { $this->replace['HTML_FIELDS_TD'] .= " <td><?= \$row['{$field_name}'] ?></td>\n"; $this->replace['HTML_FIELDS_TH'] .= " <th>{$field_name_nice}</th>\n"; } $this->replace['INSERT_FUNC_PARAMS_APP'] .= '$request[\'' . $field_name . "'],\n" . str_repeat(" ", 32 + strlen($this->replace['TABLE_NAME'])); $this->replace['INSERT_FUNC_PARAMS_MODEL'] .= '$' . $field_name . ",\n "; $this->replace['MYSQL_ADD_PARAMS'] .= "\n ->addParam(\$" . $field_name . ")"; $this->replace['QUERY_INSERT_ADD_PARAMS'] .= ' $query->addParam($' . $field_name . ');' . "\n"; $this->replace['QUERY_INSERT_ADD_PARAMS'] .= ' $query->addParam($' . $field_name . ');' . "\n"; $this->replace['SET_FIELDS_COMMA_SEP'] .= $sql_field['Field'] . " = \${$i} \n , "; $this->replace['INSERT_REQUEST_PARAMS'] .= "\$request['{$field_name}'],\n "; $this->replace['INSERT_DOLLAR_PARAMS'] .= "\$" . ($i - 1) . ", "; $this->replace['FIELD_NAME'] = $field_name; $this->replace['FIELD_NAME_NICE'] = $field_name_nice; if ($field_type == "text") { $field_template->replace($this->replace); $this->replace['HTML_EDIT_FIELDS'] .= $field_template->getContents(); } else { if ($is_join) { $other_table = substr($field_name, 0, strlen($field_name) - 3); $other_table_model_class = underscoreToClass($other_table . '_' . 'model'); $this->replace['MODEL_GET_ALL'] .= " \${$other_table}_model = new {$other_table_model_class}();\n" . " \$this->data['{$other_table}'] = \${$other_table}_model->getAll();\n"; $join_field = $this->getTableJoinField($other_table); $this->replace['JOIN_FIELD'] = $join_field; if (strlen($join_field) > 0) { $this->replace['OTHER_TABLE_NAME'] = $other_table; $this->replace['MYSQL_JOINS'] .= "\n ->leftJoin('{$other_table} ON {$other_table}.id = {$other_table}_id')"; $this->replace['SQL_JOINS'] .= " LEFT JOIN {$other_table} ON {$other_table}.id = {$other_table}_id\n"; $this->replace['SQL_FIELDS_COMMA_SEP'] .= "{$other_table}.{$join_field} {$other_table}_{$join_field}\n , "; $this->replace['HTML_FIELDS_TD'] .= " <td><?= \$row['{$other_table}_{$join_field}'] ?></td>\n"; $field_name_nice = ucwords(str_replace("_", " ", $other_table . " " . $join_field)); $this->replace['FIELD_NAME_NICE'] = $field_name_nice; $this->replace['HTML_FIELDS_TH'] .= " <th>{$field_name_nice}</th>\n"; $field_template->replace($this->replace); $this->replace['HTML_EDIT_FIELDS'] .= $field_template->getContents(); } } else { if (strpos($field_type, 'enum') === 0) { $enums = explode(",", str_replace("'", "", substr(substr($field_type, 5), 0, -1))); $this->replace['ENUM_OPTIONS'] = ""; foreach ($enums as $enum) { $this->replace['ENUM_OPTIONS'] .= " <option value=\"{$enum}\">{$enum}</option>\n"; } $field_template->replace($this->replace); $this->replace['HTML_EDIT_FIELDS'] .= $field_template->getContents(); } else { $field_template->replace($this->replace); $this->replace['HTML_EDIT_FIELDS'] .= $field_template->getContents(); } } } } } $this->replace['AJAX_COMMA_SEP_FIELDS'] = rtrim($this->replace['AJAX_COMMA_SEP_FIELDS'], "\n"); $this->replace['AJAX_COMMA_SEP_FIELDS_WID'] = rtrim($this->replace['AJAX_COMMA_SEP_FIELDS_WID'], "\n"); $this->replace['HTML_EDIT_FIELDS'] = rtrim($this->replace['HTML_EDIT_FIELDS'], "\n"); $this->replace['MYSQL_JOINS'] = rtrim($this->replace['MYSQL_JOINS'], " \n"); $this->replace['MYSQL_ADD_PARAMS'] = rtrim($this->replace['MYSQL_ADD_PARAMS'], " \n"); $this->replace['SQL_JOINS'] = rtrim($this->replace['SQL_JOINS'], "\n"); $this->replace['HTML_FIELDS_TH'] = rtrim($this->replace['HTML_FIELDS_TH'], "\n"); $this->replace['HTML_FIELDS_TD'] = rtrim($this->replace['HTML_FIELDS_TD'], "\n"); $this->replace['SQL_FIELDS_COMMA_SEP'] = rtrim($this->replace['SQL_FIELDS_COMMA_SEP'], " ,\n"); $this->replace['SET_FIELDS_COMMA_SEP'] = rtrim($this->replace['SET_FIELDS_COMMA_SEP'], " ,\n"); $this->replace['INSERT_DOLLAR_PARAMS'] = rtrim($this->replace['INSERT_DOLLAR_PARAMS'], " ,"); $this->replace['INSERT_FIELDS_COMMA_SEP'] = rtrim($this->replace['INSERT_FIELDS_COMMA_SEP'], " ,\n"); $this->replace['INSERT_REQUEST_PARAMS'] = rtrim($this->replace['INSERT_REQUEST_PARAMS'], " ,\n"); $this->replace['UPDATE_REQUEST_PARAMS'] = rtrim($this->replace['UPDATE_REQUEST_PARAMS'], " ,\n"); $this->replace['INSERT_FUNC_PARAMS_APP'] = rtrim($this->replace['INSERT_FUNC_PARAMS_APP'], " ,\n"); $this->replace['INSERT_FUNC_PARAMS_MODEL'] = rtrim($this->replace['INSERT_FUNC_PARAMS_MODEL'], " ,\n"); }
function addToMigration($name, $php) { $config = getZombieConfig(); $migrate_file = $config['zombie_root'] . "/model/migrate/" . $name . ".php"; if (!file_exists($migrate_file)) { die("Migration '" . $name . "' does not exist.\n"); } $contents = file_get_contents($migrate_file) . $php; file_put_contents($migrate_file, $contents); }
function copyImages($version, $old_version) { echo "COPYING IMAGES\n\n"; $config = getZombieConfig(); $root = $config['zombie_root']; exec("rm -rf {$root}/web/build/images/" . $old_version); exec("mkdir -p {$root}/web/build/images/" . $version); $apps_dir = __DIR__ . "/../../../apps/"; $apps = getDirContents($apps_dir, array('dir')); $resize = array(); foreach ($apps as $app) { $config_file = "{$root}/apps/{$app}/config/compile.json"; if (file_exists($config_file)) { $contents = file_get_contents($config_file); $config_arr = json_decode($contents, true); if (!$config_arr) { echo "ERROR: Possible problem with compile config for `{$app}`\n"; } if (isset($config_arr['images']) && is_array($config_arr['images'])) { $images = $config_arr['images']; foreach ($images as $image) { if (isset($image['resize'])) { array_push($resize, array('app' => $app, 'name' => $image['name'], 'size' => $image['resize'])); } } } } } foreach ($apps as $app) { $images_src = realpath($apps_dir . $app . "/views/images"); if (!$images_src) { continue; } $images = getDirContents($images_src . "/", array("file")); if (count($images) > 0) { $image_dest = realpath("{$root}/web/build/images/" . $version) . "/" . $app; echo "creating dir " . $image_dest . "\n"; mkdir($image_dest); } foreach ($images as $image) { $path_parts = pathinfo($images_src . "/" . $image); $ext = $path_parts['extension']; $img_source = $images_src . "/" . $image; $img_dest = $image_dest . "/" . $image; if (`which convert`) { foreach ($resize as $resize_info) { if ($app == $resize_info['app'] && $resize_info['name'] == $image) { $size = $resize_info['size']; echo "resizing {$img_source}\n"; exec("convert -resize {$size} {$img_source} {$img_dest}"); $img_source = $img_dest; } } } else { if (count($resize) > 0) { echo "error: could not find convert command\n"; } } if ($ext == 'png' && `which pngcrush`) { echo "optimizing png\n"; exec("pngcrush -rem alla -rem gAMA -rem cHRM -rem iCCP -rem sRGB -brute -reduce {$img_source} {$img_dest}"); } else { if ($ext == 'jpg' || $ext == 'jpeg') { echo "optimizing jpeg\n"; exec("jpegtran -copy none -optimize -outfile {$img_dest} {$img_source}"); } else { copy($img_source, $img_dest); } } echo "copying {$images_src}/{$image}\n" . "to {$image_dest}/{$image}\n\n"; } } }
function buildUrls() { if ($this->images_version !== false) { $build = "/build/images/" . $this->images_version; preg_match_all("/url\\(['\"]?\\/images(\\/[a-z0-9_]+\\/[a-z0-9_\\-]+\\.[a-z]+)['\"]?\\)/i", $this->css, $matches); for ($i = 0; $i < count($matches[0]); ++$i) { $new_url = "url('" . $build . $matches[1][$i] . "')"; $this->css = str_replace($matches[0][$i], $new_url, $this->css); } } $config = getZombieConfig(); $web_root = $config['web_root']; if ($web_root != '/' && !empty($web_root)) { preg_match_all("/url\\(['\"]?(\\/.*?)['\"]?\\)/i", $this->css, $matches); for ($i = 0; $i < count($matches[0]); ++$i) { $new_url = "url('" . $web_root . $matches[1][$i] . "')"; $this->css = str_replace($matches[0][$i], $new_url, $this->css); } } }
/** * @ignore */ protected function __construct() { $this->config = getZombieConfig(); }
public function __construct() { $this->config = getZombieConfig(); }
<?php # Copyright (c) 2011, Regaltic LLC. This file is # licensed under the General Public License version 3. # See the LICENSE file. /** * @package Util * @ignore */ require_once 'util.php'; require_once __DIR__ . '/../../config/config.php'; $config = getZombieConfig(); $GLOBALS['zombie_root'] = $config['zombie_root']; function autoloadApp($class) { $slug = classToUnderscore($class); @(include $GLOBALS['zombie_root'] . '/apps/' . $slug . '/' . $slug . '.php'); } function autoloadModel($class) { if (substr($class, -5) == 'Model') { $slug = classToUnderscore(substr($class, 0, strlen($class) - 5)); include $GLOBALS['zombie_root'] . '/model/' . $slug . '.php'; } } function autoloadSession($class) { if (substr($class, -7) == 'Session') { include $GLOBALS['zombie_root'] . '/zombie-core/session/' . $class . '.php'; } }