/** * Get whether this is a production environment * * @uses get_environment() * * @return bool True if on a production environment, false on development */ function is_prod() { $env = get_environment(); if ($env && 'production' == $env) { return true; } return false; }
/** * Enqueue scripts and styles. */ function sudoers_scripts() { global $page, $numpages; wp_enqueue_style('sudoers-style', get_stylesheet_uri()); wp_enqueue_script('sudoers-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true); wp_enqueue_script('sudoers-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true); if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } wp_register_script('sudoers', get_template_directory_uri() . '/js/sudoers.js', array(), '20151215'); wp_localize_script('sudoers', 'sudoers', array('is_home' => is_home(), 'is_front_page' => is_front_page(), 'is_single' => is_single(), 'is_singular' => is_singular(), 'is_page' => is_page(), 'is_category' => is_category(), 'is_tag' => is_tag(), 'is_archive' => is_archive(), 'is_404' => is_404(), 'is_search' => is_search(), 'is_tax' => is_tax(), 'is_author' => is_author(), 'is_paged' => is_paged(), 'is_slideshow' => is_single() && $numpages > 1 ? 1 : 0, 'is_video_single' => is_single() && in_category(SUDOERS_VIDEO_CATEGORY) ? 1 : 0, 'is_video_cat' => is_category(SUDOERS_VIDEO_CATEGORY) ? 1 : 0, 'post_page' => $page, 'post_numpages' => $numpages, 'debug_js' => false, 'environment' => get_environment())); wp_enqueue_script('sudoers'); }
<?php include_once 'file.inc.php'; ?> <html> <head> <meta charset="utf-8"> <title>PHP_FILE_CMS</title> </head> <body> <table border="1"> <caption>系统信息</caption> <?php $env = get_environment(); ?> <tr><td>主机(ip)</td><td><?php echo $env['host_name'] . "(" . $env['ip'] . ")"; ?> </td></tr> <tr><td>端口</td><td><?php echo $env['port']; ?> </td></tr> <tr><td>客户端</td><td><?php echo $env['agent']; ?> </td></tr> <tr><td>WEB服务器</td><td><?php echo $env['web_server']; ?>
} function get_environment() { $env = 'development'; $envfile = realpath(dirname(__FILE__) . "/../") . "/ENVIRONMENT"; if (is_file($envfile)) { $new_env = trim(file_get_contents($envfile)); if (!empty($new_env)) { $env = $new_env; } else { die("Please specify an environment in {$envfile}"); } } else { die("Please create the ENVIRONMENT file in {$envfile}"); } header("Altlast4Web-Environment: {$env}"); return $env; } define('ROOT_DIR', get_rootdir()); define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); define('APPLICATION_ENV', get_environment()); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), get_include_path()))); require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->setFallbackAutoloader(true); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $application->bootstrap()->run();
} catch (Twig_Sandbox_SecurityError $e) { $t->pass('Sandbox throws a SecurityError exception if an unallowed tag is used in the template'); } $twig = get_environment(true, $templates, array(), array(), array('Object' => 'foo')); $t->is($twig->loadTemplate('1_basic1')->render($params), 'foo', 'Sandbox allow some methods'); $twig = get_environment(true, $templates, array(), array('upper')); $t->is($twig->loadTemplate('1_basic2')->render($params), 'FABIEN', 'Sandbox allow some filters'); $twig = get_environment(true, $templates, array('if')); $t->is($twig->loadTemplate('1_basic3')->render($params), 'foo', 'Sandbox allow some tags'); $t->diag('Sandbox locally set for an include'); $templates = array('2_basic' => '{{ obj.foo }}{% include "2_included" %}{{ obj.foo }}', '2_included' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}'); $twig = get_environment(false, $templates); $t->is($twig->loadTemplate('2_basic')->render($params), 'fooFOOfoo', 'Sandbox does nothing if disabled globally and sandboxed not used for the include'); $templates = array('3_basic' => '{{ obj.foo }}{% include "3_included" sandboxed %}{{ obj.foo }}', '3_included' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}'); $twig = get_environment(false, $templates); $twig = get_environment(true, $templates); try { $twig->loadTemplate('3_basic')->render($params); $t->fail('Sandbox throws a SecurityError exception when the included file is sandboxed'); } catch (Twig_Sandbox_SecurityError $e) { $t->pass('Sandbox throws a SecurityError exception when the included file is sandboxed'); } function get_environment($sandboxed, $templates, $tags = array(), $filters = array(), $methods = array()) { static $prefix = 0; ++$prefix; $loader = new Twig_Loader_Var($templates, $prefix); $twig = new Twig_Environment($loader, array('trim_blocks' => true, 'debug' => true)); $policy = new Twig_Sandbox_SecurityPolicy($tags, $filters, $methods); $twig->addExtension(new Twig_Extension_Sandbox($policy, $sandboxed)); return $twig;
<?php require 'config.php'; //获得当前服务器环境 function get_environment() { if (defined('SAE_ACCESSKEY')) { return "sae"; } elseif (defined('BAE')) { return "bae"; } return "php"; } require 'common_' . get_environment() . ".php";