function __construct($callback = FALSE) { $this->cache_dir = configItem('site')['appdir'] . 'cache/'; if (!is_dir($this->cache_dir)) { mkdir($this->cache_dir, 0755); } if ($callback) { $this->callback = $callback; } }
/** * Set the logger. */ private function _setLogger() { $loggerConfig = configItem('logger'); if ($this->hookActive('logger')) { $ns = "\\application\\" . self::$hooks['logger']['namespace']; $class = self::$hooks['logger']['class']; $class_ns = "{$ns}\\{$class}"; } else { $class_ns = __NAMESPACE__ . "\\Logger"; } $this->logger = new $class_ns($loggerConfig['file'], $loggerConfig['level']); }
function __construct() { $config = configItem('mail'); $this->SMTPDebug = $config['smtp_debug']; $this->SMTPAuth = $config['smtp_auth']; $this->SMTPSecure = $config['ssl']; $this->Host = $config['host']; $this->Port = $config['port']; $this->Username = $config['uname']; $this->Password = $config['pwd']; $this->Mailer = $config['mailer']; }
/** * Initiating the model base class * * @internal param string $dbname * @internal param string $host * @internal param string $user * @internal param string $passwd * @param array $config * @internal param Logger|string $logger */ public function __construct($config = array()) { $this->_errorCallbackFunction = '_errorCallbackFunction'; $options = array(\PDO::ATTR_PERSISTENT => false, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION); try { $config = count($config) > 0 ? $config : configItem('mysql'); parent::__construct("mysql:dbname=" . $config['db'] . ";host=" . $config['host'], $config['user'], $config['password'], $options); } catch (PDOException $e) { exit("Couldn't connect to database server"); } $loggerConfig = configItem('logger'); $this->logger = new Logger($loggerConfig['file'], $loggerConfig['level']); }
/** * Default constructor * * @param string|array [optional] $config * @return \Cache */ public function __construct($config = null) { $this->_cachepath = configItem('cache')['dir']; if (true === isset($config)) { if (is_string($config)) { $this->setCache($config); } else { if (is_array($config)) { $this->setCache($config['name']); $this->setCachePath($config['path']); $this->setExtension($config['extension']); } } } }
public static function captureException($exception) { $message = $exception->getMessage(); $code = $exception->getCode(); $file = $exception->getFile(); $line = $exception->getLine(); $trace = $exception->getTraceAsString(); $date = date('M d, Y h:iA'); $log_message = "<code><h1>Exception information:</h1>\n <p>\n <strong>Date:</strong> {$date}\n </p>\n \n <p>\n <strong>Message:</strong> {$message}\n </p>\n \n <p>\n <strong>Code:</strong> {$code}\n </p>\n \n <p>\n <strong>File:</strong> {$file}\n </p>\n \n <p>\n <strong>Line:</strong> {$line}\n </p>"; if (configItem('logger')['stack']) { $log_message .= "<h3>Stack trace:</h3>\n <pre>{$trace}\n </pre>\n <br />"; } $log_message .= "</code>"; include_once 'error_template.php'; }
/** * Sets the callback as an array containing Controller, Method & Parameters * * @param string $destination */ private static function _set_callback($destination) { if (is_callable($destination)) { self::$callback = array($destination, self::$_attr); } else { $result = explode('/', trim($destination, '/')); //fix the controller now $controller = $result[0] == "" ? configItem('site')['default_controller'] : str_replace('-', '/', $result[0]); //if no method, set it to index $method = isset($result[1]) ? $result[1] : 'index'; //if controller is valid file if (self::fileExists($file = ucfirst(configItem('site')['cust_controller_dir']) . $controller . '.php', false)) { self::$callback = array(ucFirst($controller), $method, self::$_attr); } else { die("<b>Exception: </b>Incorrect routing"); } } }
/** * Redirects to a different link * * @param string $path controller/method */ function redirect($path, $addhost = true) { !$addhost ? header("Location: " . $path) : header("Location: " . configItem('site')['url'] . $path); die; }
static function show($view, $parameters = array()) { extract($parameters); $viewdir = configItem('site')['viewdir']; include_once $viewdir . $view; }
/** * @description Initializes the session handler. * @access public * @throws Exception * @internal param $array - configuration options */ public function __construct($config = array(), $db = array()) { // Sets user configuration $this->config['session'] = count($config) > 0 ? $config : configItem('session'); $this->config['db'] = count($db) > 0 ? $db : configItem('mysql'); $this->_setConfig(); // Runs the session mechanism if ($this->_read()) { $this->_update(); } else { $this->_create(); } // Cleans expired sessions if necessary and writes cookie $this->_cleanExpired(); $this->_setCookie(); }
/** * Sets the Error Handlers */ public function setHandlers() { $error = configItem('error'); if ($error == 0) { ini_set('display_errors', 0); error_reporting(0); } else { if ($error == 2) { error_reporting(0); set_error_handler(array($this, 'captureNormal')); set_exception_handler(array($this, 'captureException')); register_shutdown_function(array($this, 'captureShutdown')); } else { if ($error == 1) { error_reporting(E_ALL); ini_set('display_errors', 1); } } } }
function __construct($db = array(), $config = array()) { $config = count($config) > 0 ? $config : configItem('session'); $db_config = count($db) > 0 ? $db : configItem('mysql'); // the table to be used by the class $this->table_name = $config['table_name']; try { $this->link = mysqli_connect($db_config['host'], $db_config['user'], $db_config['password'], $db_config['db']); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } if (!$this->_tableExists()) { $this->_createTable(); } // continue if there is an active MySQL connection if ($this->_mysql_ping()) { // make sure session cookies never expire so that session lifetime // will depend only on the value of $session_lifetime ini_set('session.cookie_lifetime', 0); // if $session_lifetime is specified and is an integer number if ($config['session_lifetime'] != '' && is_integer($config['session_lifetime'])) { // set the new value ini_set('session.gc_maxlifetime', (int) $config['session_lifetime']); } // if $gc_probability is specified and is an integer number if ($config['gc_probability'] != '' && is_integer($config['gc_probability'])) { // set the new value ini_set('session.gc_probability', $config['gc_probability']); } // if $gc_divisor is specified and is an integer number if ($config['gc_divisor'] != '' && is_integer($config['gc_divisor'])) { // set the new value ini_set('session.gc_divisor', $config['gc_divisor']); } // get session lifetime $this->session_lifetime = ini_get('session.gc_maxlifetime'); // we'll use this later on in order to try to prevent HTTP_USER_AGENT spoofing $this->security_code = $config['security_code']; // some other defaults $this->lock_to_user_agent = $config['lock_to_user_agent']; $this->lock_to_ip = $config['lock_to_ip']; // the maximum amount of time (in seconds) for which a process can lock the session $this->lock_timeout = $config['lock_timeout']; // register the new handler session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc')); // start the session session_start(); // the name for the session variable that will be created upon script execution // and destroyed when instantiating this library, and which will hold information // about flashdata session variables $this->flashdata_varname = '_eaglehorn_session_flashdata_ec3asbuiad'; // assume no flashdata $this->flashdata = array(); // if there are any flashdata variables that need to be handled if (isset($_SESSION[$this->flashdata_varname])) { // store them $this->flashdata = unserialize($_SESSION[$this->flashdata_varname]); // and destroy the temporary session variable unset($_SESSION[$this->flashdata_varname]); } // handle flashdata after script execution register_shutdown_function(array($this, '_manage_flashdata')); // if no MySQL connections could be found // trigger a fatal error message and stop execution } else { trigger_error('Session Worker: No MySQL connection!', E_USER_ERROR); } }
/** * Render the template */ public function render() { $template_name = $this->base->load->template[0]; $template_file = configItem('site')['templatedir'] . $template_name . '.tpl'; if (file_exists($template_file)) { $template = $this->twig->loadTemplate($template_name . '.tpl'); $template_data = array(); if (isset($this->base->load->template[1]) && is_array($this->base->load->template[1])) { $template_data = $this->base->load->template[1]; foreach ($template_data as $key => $value) { $file = configItem('site')['viewdir'] . $value; if (file_exists($file) && is_file($file)) { $template_data[$key] = $this->base->getFileOutput($file); $this->base->logger->info("View parsed - {$file}"); } } } $this->template_markup = $template->render($template_data); if (sizeof($this->injections) > 0) { $this->_applyInjections(); } echo $this->template_markup; } else { //log error } }
/** * Writes a line to the log without prepending a status or timestamp * * @param $message * @throws RuntimeException * @internal param string $line Line to write to the log * @return void */ public function write($message) { $loggerConfig = configItem('logger'); if (!is_null($this->fileHandle) && $loggerConfig['activate']) { if (fwrite($this->fileHandle, $message) === false) { throw new \RuntimeException('The file could not be written to. Check that appropriate permissions have been set.'); } } }
/** * Triggers a hook * @param $instance * @param $hook_name * @param string $class * @param string $method_name * @param array $data */ protected function loaderHooks($instance, $hook_name, $class = '', $method_name = '', $data = array()) { $hooks = configItem('hooks'); if (isset($hooks[$hook_name]) && $hooks[$hook_name]['active']) { $ns = "\\application\\" . $hooks[$hook_name]['namespace']; $hook_class = $hooks[$hook_name]['class']; $class_ns = "{$ns}\\{$hook_class}"; $hook_instance = new $class_ns(); call_user_func_array(array($hook_instance, $hooks[$hook_name]['method']), array($instance, $class, $method_name, $data)); } }
/** * Sets the callback as an array containing Controller, Method & Parameters * * @param string $destination */ private static function _set_callback($destination) { if (is_callable($destination)) { self::$callback = array($destination, self::$_attr); } else { $result = explode('/', trim($destination, '/')); //fix the controller now $controller = $result[0] == "" ? configItem('site')['default_controller'] : str_replace('-', '/', $result[0]); //if no method, set it to index $method = isset($result[1]) ? $result[1] : 'index'; //if controller is valid file if (self::fileExists($file = ucfirst(configItem('site')['cust_controller_dir']) . $controller . '.php', false)) { self::$callback = array(ucFirst($controller), $method, self::$_attr); } else { header("HTTP/1.0 404 Not Found"); self::$_base->hook('404', array('file' => $file, 'controller' => $controller, 'method' => $method, 'message' => '404')); die; } } }
public function hook($hook_name, $data) { $hooks = configItem('hooks'); if (isset($hooks[$hook_name]) && $hooks[$hook_name]['active']) { $ns = "\\application\\" . $hooks[$hook_name]['namespace']; $hook_class = $hooks[$hook_name]['class']; $class_ns = "{$ns}\\{$hook_class}"; $hook_instance = new $class_ns(); call_user_func_array(array($hook_instance, $hooks[$hook_name]['method']), array($data)); } }