/** * @param null $env * @param bool|false $set * @return bool|string */ function environment($env = null, $set = false) { if ($env !== null && $set) { setEnvironment($env); } elseif ($env !== null && !$set) { if ($env == getEnvironment()) { return true; } else { return false; } } return getEnvironment(); }
/** * @param array $replace * @return array */ function &getConfig($replace = array()) { static $_config; if (isset($_config)) { // Are any values being dynamically replaced? if (count($replace) > 0) { foreach ($replace as $key => $val) { if (isset($_config[0][$key])) { if (is_array($_config[0][$key])) { $_config[0][$key] = array_merge($_config[0][$key], $val); } else { $_config[0][$key] = $val; } } } } return $_config[0]; } //include environment based configurations $env = getEnvironment(); //include default configurations foreach (glob(root . "/config/default/*.config.php") as $app_config) { if (file_exists($app_config)) { require $app_config; } } if ($env != "default") { foreach (glob(root . "/config/{$env['environment']}/*.config.php") as $app_config) { if (file_exists($app_config)) { require $app_config; } } } $core_config_file = dirname(__DIR__) . '/config/config.php'; require $core_config_file; // Does the $config array exist in the file? if (!isset($config) or !is_array($config)) { exit('Your config file does not appear to be formatted correctly.'); } $config['site']['url'] = $env['url']; $_config[0] =& $config; return $_config[0]; }
<?php /** * Created by PhpStorm. * User: ioan * Date: 18.12.2015 * Time: 11:46 AM */ global $kernel; if ($kernel === null) { $env = getEnvironment(); $debug = false; $kernel = new AppKernel($env, $debug); $kernel->boot(); }
<!doctype html> <html <?php language_attributes(); ?> class="no-js" data-environment="<?php echo getEnvironment(); ?> "> <head> <meta charset="<?php bloginfo('charset'); ?> "> <title><?php wp_title(''); if (wp_title('', false)) { echo ' :'; } ?> <?php bloginfo('name'); ?> </title> <!-- dns prefetch --> <link href="//www.google-analytics.com" rel="dns-prefetch"> <link href="//netdna.bootstrapcdn.com" rel="dns-prefetch"> <link href="use.typekit.net" rel="dns-prefetch"> <!-- meta --> <meta name="description" content="<?php
/** * 動作環境のデータベース接続URI情報リスト取得 * @param string $file 接続URI情報iniファイル指定 * @param string [$name=null] iniパラメータ名 * @param string [$env=null] 環境 * @return array */ private static function getUriList($file, $name = null, $env = null) { if (!is_readable($file)) { // ファイルが読み込み不可なら return array(); } $list = parse_ini_file($file, true); if (is_null($env)) { // 環境指定ない場合 if (function_exists('getEnvironment')) { $env = getEnvironment(); } else { $env = 'devel'; } } if (isset($list[$env])) { // 環境のURI取得できた場合 if (is_null($name)) { // パラメータ指定ない場合 return $list[$env]; } else { if (isset($list[$env][$name])) { // パラメータ指定があり、URI取得できている場合 return $list[$env][$name]; } } } return array(); }
/** * Prepares an email. * * @param string $recipient The mail recipient * @param string $subject The subject * @param string $message The message (may be HTML formatted) * @param string $plainmessage Optional plain message (may differ from $message) * @param array $attachments Array of filenames to attach * @return PHPMailer A PHPMailer object ready to be sent. */ function mail_prepare($recipient, $subject, $message, $plainmessage = "", $attachments = array()) { global $CONFIG; require_once __DIR__ . "/mail/class.smtp.php"; require_once __DIR__ . "/mail/class.phpmailer.php"; if (isDev() && isset($CONFIG['mail']['dev_whitelist'])) { $isvalidrecipient = false; // on dev server, only domains/recipients in the whitelist are allowed foreach ($CONFIG['mail']['dev_whitelist'] as $needle) { if (!isset($CONFIG['mail']['dev_recipient'])) { $CONFIG['mail']['dev_recipient'] = $needle; } if (stripos($recipient, $needle) !== false) { $isvalidrecipient = true; break; } } if (!$isvalidrecipient && isset($CONFIG['mail']['dev_recipient'])) { // if not found in whitelist, send to predefined recipient $recipient = $CONFIG['mail']['dev_recipient']; log_debug("email recipient changed to: " . var_export($recipient, true)); } } $mail = new PHPMailer(true); $mail->SetLanguage("en", __DIR__ . "/mail/language/"); $mail->CharSet = "utf-8"; $mail->IsSMTP(); $mail->Host = $CONFIG['mail']['smtp_server']; if (isset($CONFIG['mail']['smtp_auth']) && $CONFIG['mail']['smtp_auth']) { $mail->SMTPAuth = true; $mail->Username = $CONFIG['mail']['smtp_user']; $mail->Password = $CONFIG['mail']['smtp_pass']; } if (isset($CONFIG['mail']['smtp_tls']) && $CONFIG['mail']['smtp_tls'] == true) { $mail->SMTPSecure = 'tls'; } $mail->From = $CONFIG['mail']['from']; $mail->FromName = $CONFIG['mail']['from_name']; try { if (is_array($recipient)) { foreach ($recipient as $r) { $mail->AddAddress($r); } } else { $mail->AddAddress($recipient); } } catch (Exception $ex) { WdfException::Log($ex); $res = false; } $mail->AddReplyTo($CONFIG['mail']['from']); $mail->WordWrap = 80; if (starts_with($subject, "[nomark]")) { $subject = trim(str_replace("[nomark]", "", $subject)); } else { $env = getEnvironment(); if (isDev() && !starts_with($subject, "[{$env}]")) { $subject = "[{$env}] {$subject}"; } } $mail->Subject = $subject; $mail->ContentType = "text/html"; $message = str_ireplace("<br>", "<br/>", $message); $message = str_ireplace("<br >", "<br/>", $message); $message = str_ireplace("<br />", "<br/>", $message); $message = str_ireplace("{crlf}", "<br/>", $message); $message = str_ireplace("\\r", "\r", $message); $message = str_ireplace("\\'", "'", $message); $message = str_ireplace("\\\"", "\"", $message); $message = str_ireplace("\r\n", "<br/>", $message); $message = str_ireplace("\n", "<br/>", $message); $message = str_ireplace("<br/>", "<br/>\n", $message); $mail->Body = $message; $mail->AltBody = strip_tags($plainmessage == "" ? $message : str_ireplace("<br/>", "\n", $plainmessage)); $mail->AltBody = str_ireplace("\n--\n", "\n--\n", $mail->AltBody); if (!is_array($attachments)) { $attachments = array($attachments); } foreach ($attachments as $a) { if (file_exists($a)) { $mail->AddAttachment($a); } else { log_debug("email attachment not found: {$a}"); } } return $mail; }
<?php /** * TEMPLATE * Set the template for routes * * =========================================================================== */ ?> <?php /** * DOMAINS * Set domain and environment */ $domains = array('www.incipit.local' => 'LOCAL', 'incipit.local' => 'LOCAL', 'development.incipit.dom' => 'DEV', 'quality.incipit.dom' => 'QUA', 'www.incipit.dom' => 'PROD', 'incipit.dom' => 'PROD'); /** ENVIRONMENT */ defined('ENVIRONMENT') or define('ENVIRONMENT', getEnvironment($domains, $_SERVER['SERVER_NAME'])); /** * COMMON * Set commons site info */ $commons = array('name' => 'Incipit', 'description' => 'This framework is created for init a new web standard project. GRUNT and SCSS frontend based. PHP and MySQL backend base.', 'separator' => '|', 'opengraph' => array('og:title' => 'Incipit', 'og:url' => 'http' . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'og:image' => 'http' . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . IMG_PATH . 'social/incipit.png', 'og:site_name' => 'Incipit', 'og:description' => 'This framework is created for init a new web standard project. GRUNT and SCSS frontend based. PHP and MySQL backend base.'), 'webapp' => array('title' => 'Incipit App', 'description' => 'This framework is created for init a new web standard project. GRUNT and SCSS frontend based. PHP and MySQL backend base.', 'starturl' => 'http' . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST'], 'color' => '#123456', 'statusbar' => 'black')); /** * PAGES * Associated uri => infos */ $pages = array('/' => array('template' => 'blank', 'content' => 'index', 'title' => 'Homepage', 'description' => 'This framework is the homepage', 'opengraph' => array('og:title' => '', 'og:type' => '', 'og:image' => '', 'og:site_name' => '', 'og:description' => ''), 'webapp' => array('title' => 'Incipit App', 'description' => 'This framework is created for init a new web standard project. GRUNT and SCSS frontend based. PHP and MySQL backend base.', 'starturl' => 'http' . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST'], 'color' => '#123456', 'statusbar' => 'translucent')), '/parent' => array('template' => 'blank', 'content' => 'parent', 'title' => 'Parent', 'description' => 'This is the parent page'), '/parent/child' => array('template' => 'blank', 'content' => 'child', 'title' => 'Child', 'description' => 'This is the child page'), '/parent/child/depth' => array('template' => 'blank', 'content' => 'depth', 'title' => 'Depth', 'description' => 'This is the depth page'), '404' => array('template' => 'blank', 'content' => '404', 'title' => 'Errore 404', 'description' => 'This is the 404 error page'));
<?php define("ENVIRONMENT", getEnvironment()); define("SHOW_ERRORS", $config['errors'][ENVIRONMENT] == 1 ? true : false); define("ROOT_PATH", str_replace('\\', '/', __DIR__) . '/'); define("EXTS_PATH", ROOT_PATH . 'extensions/'); define("FILE_VER", date('dmy')); /** * Identify environment based on server name information * * @return string Environment name */ function getEnvironment() { switch ($_SERVER['SERVER_NAME']) { case 'danielfanica.com': case 'www.danielfanica.com': return 'production'; break; case 'alpha.danielfanica.com': return 'alpha'; break; default: return 'development'; break; } }