/** * Process the page response (former $this->page()) * @todo use a better term that is applicable to all response * * @since ADD MVC 0.0 * @version 0.2 */ public function execute() { # ADD MVC 0.5 backward support if (method_exists($this, 'page')) { return $this->page(); } try { $this->mode = isset($_REQUEST['mode']) ? "{$_REQUEST['mode']}" : ''; $this->process_data(); } catch (e_user $e) { if ($e instanceof e_user_malicious) { $e->handle_exception(); die; } if ($this->mode) { $exception_label = "user_" . $this->mode; } else { $exception_label = "user"; } $this->add_exception($e, $exception_label); } $this->assign('ctrl_basename', $this->basename()); $this->assign('C', add::config()); $error_messages = $this->view()->getTemplateVars('error_messages'); if (is_array($error_messages)) { $this->assign('error_message', $error_messages[0]); } if (add::is_development()) { add::config()->root_timer->lap("Before Printing"); } $this->print_response($this->data); }
/** * Smarty construct * * @since ADD MVC 0.0 */ public function __construct() { $C = add::config(); parent::__construct(); if (is_array($C->views_dir)) { $this->setTemplateDir(array_merge($C->views_dir, array($C->add_dir . '/views/'))); } else { $this->setTemplateDir(array($C->views_dir, $C->add_dir . '/views/')); } $this->compile_dir = $C->caches_dir . '/smarty_compile/'; $this->config_dir = $C->configs_dir . '/smarty/'; $this->cache_dir = $C->caches_dir . '/smarty_cache/'; if (add::is_development()) { foreach (array($this->compile_dir, $this->cache_dir) as $dir) { if (!is_dir($dir)) { $this->_dir_perms = 0777; } else { if (!is_writable($dir)) { # Do something } } } } }
/** * Sets and return or return an environment status * * @since ADD MVC 0.8 */ public static function environment_status($new_status = null) { if ($new_status) { if (is_string($new_status)) { if ($new_status === 'development') { if (add::is_developer()) { add::$environment_status = $new_status; } else { add::$environment_status = "live"; } } else { if ($new_status === 'live') { add::$environment_status = 'live'; } else { throw new e_developer("Invalid environment_status: {$new_status}"); } } } /** * No errors if live * * @since ADD MVC 0.7.2 */ if (add::is_live()) { error_reporting(0); add::$handle_shutdown = false; } else { error_reporting(E_ALL); /** * When development, record the time spent on script execution * * @since ADD MVC 0.7.2 */ if (add::is_development()) { add::$handle_shutdown = true; if (!isset($GLOBALS['add_mvc_root_timer'])) { $GLOBALS['add_mvc_root_timer'] = add_development_timer::start("Framework Configuration"); } add::config()->root_timer = $GLOBALS['add_mvc_root_timer']; } } } return add::$environment_status; }
/** * Sets and return or return an environment status * * @since ADD MVC 0.8 */ public static function environment_status($new_status = null) { /** * * @see http://code.google.com/p/add-mvc-framework/issues/detail?id=33 */ if (!add::is_developer()) { if (add::$environment_status != 'live' || isset($new_status) && $new_status != 'live') { $new_status = 'live'; } } if ($new_status) { if (is_string($new_status)) { if ($new_status === 'development') { if (add::is_developer()) { add::$environment_status = $new_status; } else { add::$environment_status = "live"; } } else { if ($new_status === 'live') { add::$environment_status = 'live'; } else { throw new e_developer("Invalid environment_status: {$new_status}"); } } } else { if ($new_status !== true) { throw new e_developer("Invalid new environment status", $new_status); } } /** * No errors if live * * @since ADD MVC 0.7.2 */ if (add::is_live()) { error_reporting(0); ini_set('display_errors', 0); add::$handle_shutdown = false; } else { error_reporting(E_ALL); ini_set('display_errors', 1); /** * When development, record the time spent on script execution * * @since ADD MVC 0.7.2 */ if (add::is_development()) { add::$handle_shutdown = true; if (!isset($GLOBALS['add_mvc_root_timer'])) { $GLOBALS['add_mvc_root_timer'] = add_development_timer::start("Framework Configuration"); } add::config()->root_timer = $GLOBALS['add_mvc_root_timer']; } } } return add::$environment_status; }
/** * is_developer() * * Checks if the user is developer according to his/her IP * * @since ADD MVC 0.7.2 */ public static function is_developer() { # Fix for issue #6 if (current_ip_in_network()) { return true; } if (isset(add::config()->developer_ips) && is_array(add::config()->developer_ips)) { return in_array(current_user_ip(), add::config()->developer_ips); } else { return add::is_development(); } }
/** * The pre-view process * * @param array $common_gpc * * @since ADD MVC 0.0 */ public function process_data($common_gpc = array()) { header("HTTP/1.0 404 Not Found"); $this->assign('is_development', add::is_development()); }
/** * Process the page response (former $this->page()) * * @todo remove the automatic assigning of {$C} * * @since ADD MVC 0.0 * @version 0.2 */ public function execute() { # ADD MVC 0.5 backward support if (method_exists($this, 'page')) { return $this->page(); } # Set Content Type $this->content_type($this->content_type); try { $this->set_mode(); $this->process_data(isset($this->common_gpc) ? $this->recursive_compact($this->common_gpc) : array()); } catch (e_user $e) { if ($e instanceof e_user_malicious) { $e->handle_exception(); die; } if ($this->mode) { $exception_label = "user_" . $this->mode; } else { $exception_label = "user"; } /** * * * // what if $e is unrelated to $this->gpc_filter_exception * if ($this->gpc_filter_exception instanceof e_user_input) { * $e = $this->gpc_filter_exception; * } * */ $this->add_exception($e, $exception_label); } $this->assign('ctrl_basename', $this->basename()); $this->assign('C', add::config()); $error_messages = isset($this->data['error_messages']) && is_array($this->data['error_messages']) ? $this->data['error_messages'] : array(); if (is_array($error_messages) && isset($error_messages[0])) { $this->assign('error_message', $error_messages[0]); } if (add::is_development()) { add::config()->root_timer->lap("Before Printing"); } $this->print_response($this->data); }
* Set the exception emails * * @see http://code.google.com/p/add-mvc-framework/issues/detail?id=38 * * */ if (isset($C->developer_emails)) { if (is_string($C->developer_emails)) { e_add::$email_addresses = $C->developer_emails; } else { if (is_object($C->developer_emails) || is_array($C->developer_emails)) { e_add::$email_addresses = implode(", ", (array) $C->developer_emails); } } } if (add::is_development() && !is_writeable($C->caches_dir)) { $C->caches_dir = sys_get_temp_dir() . '/add_mvc_caches_' . sha1($C->root_dir); if (!file_exists($C->caches_dir)) { umask(0); mkdir($C->caches_dir); } else { if (!is_dir($C->caches_dir)) { throw new e_system("Cache directory is not a directory", $C->caches_dir); } } } if (!is_writeable($C->caches_dir)) { if (!file_exists($C->caches_dir)) { throw new e_system("Cache directory is not existing ", $C->caches_dir); } if (!is_dir($C->caches_dir)) {
/** * Exception page view filepath name * */ public static function view_filepath() { if (add::is_development()) { $tpl_filepath = "exceptions/development/" . static::view_basename() . ".tpl"; if (!static::view()->templateExists($tpl_filepath)) { $tpl_filepath = "exceptions/development/e_add.tpl"; } if (static::view()->templateExists($tpl_filepath)) { return $tpl_filepath; } else { # Throw a default exception cause we are already on a a custom exception throw new Exception("No development view file found for exception " . print_r($this, true)); } } else { $tpl_filepath = "exceptions/" . static::view_basename() . ".tpl"; if (!static::view()->templateExists($tpl_filepath)) { $parent_class = get_parent_class(get_called_class()); $tpl_filepath = $parent_class::view_filepath(); } return $tpl_filepath; } }
/** * Handling Exceptions * * @since ADD MVC 0.7 */ public function handle_sensitive_exception($user_message = "An error has occured") { if (add::is_development()) { $this->print_exception(); die; } else { $this->mail(); $this->view()->assign('exception', $this); $this->view()->assign('C', add::config()); $this->display_view(); } }
<?php require 'config.php'; #echo "ADD DIR: ".$C->add_dir; require $C->add_dir . '/init.php'; #date_default_timezone_set(add::config()->default_timezone); if (add::config()->debug_sql && add::is_development() && add::is_developer()) { locust_mule_db::singleton()->debug = true; }
*/ $C->assets_path = $C->base_url . 'assets/'; $C->css_path = $C->assets_path . 'css/'; $C->js_path = $C->assets_path . 'js/'; $C->images_path = $C->assets_path . 'images/'; $C->assets_libs_path = $C->assets_path . 'libs/'; /** * No errors if live * * @since ADD MVC 0.7.2 */ if (add::is_live()) { error_reporting(0); } else { error_reporting(E_ALL); /** * When development, record the time spent on script execution * * @since ADD MVC 0.7.2 */ if (add::is_development()) { $GLOBALS['add_mvc_root_timer'] = add_development_timer::start("Framework Configuration"); add::config()->root_timer = $GLOBALS['add_mvc_root_timer']; } } add::load_functions('common'); /** * Libraries */ add::load_lib('adodb'); add::load_lib('smarty');