Example #1
0
 /**
  * Class constructor
  *
  * @param	object	&$db	Database object
  * @return	void
  */
 public function __construct(&$db)
 {
     $this->db =& $db;
     Logger::log('Database Forge Class Initialized');
 }
Example #2
0
 /**
  * Load a helper.
  * 
  * Supply the name and the helper will be loaded from the supplied directory,
  * or from one of the helperPaths (which you can add).
  * 
  * @param string        $helperName Name of the helper
  * @param string|null   $directory  Directory to load the helper from, will ignore $helperPaths
  * @return bool                     Whether the helper was succesfully loaded (true if yes)
  */
 public function load($helperName, $directory = null)
 {
     // First determine the name of the helper
     $helperName = strtolower(str_replace(array('_helper', '.php'), '', $helperName) . '_helper');
     // Determine what directories should be checked
     $directories = is_null($directory) ? $this->helperPaths : array($directory);
     // Check it is already loaded
     if (isset($this->helpers[$helperName])) {
         Logger::log("Helper '" . $helperName . "' is already loaded. Skipping");
         return false;
     }
     // First check if there is an 'extension' class
     $extendedHelper = Config::get('main')->application_prefix . $helperName;
     $extendedHelperLoaded = false;
     foreach ($directories as $helperPath) {
         $file = $helperPath . DS . $extendedHelper . '.php';
         if (file_exists($file)) {
             $extendedHelperLoaded = true;
             $extendedHelperFile = $file;
         }
     }
     // If an extension is loaded there needs to be a base helper
     if ($extendedHelperLoaded) {
         $baseHelper = Core::$coreDir . DS . 'Helpers' . DS . $helperName . '.php';
         if (!file_exists($baseHelper)) {
             throw new HelperException("Could not load helper. Base Helper not found while Extension loaded", 1);
         }
         // Fire the associated event
         $event = Events::fireEvent('helperLoadEvent', $helperName, $baseHelper, $extendedHelper, $extendedHelperFile);
         if ($event->isCancelled()) {
             Logger::log("Not loading helper. Aborted by event");
             return false;
         }
         include_once $event->extendedHelperFile;
         include_once $event->helperFile;
         $this->helpers[$event->helperName] = true;
         Logger::log("Loading base helper '" . $event->helperName . "' and extended helper '" . $event->extendedHelperName . "'");
         return true;
     }
     // If no extension exists, try loading a regular helper
     foreach ($directories as $helperPath) {
         $file = $helperPath . DS . $helperName . '.php';
         if (file_exists($file)) {
             // Fire the associated event
             $event = Events::fireEvent('helperLoadEvent', $helperName, $file);
             if ($event->isCancelled()) {
                 Logger::log("Not loading helper. Aborted by event");
                 return false;
             }
             include_once $event->helperFile;
             $this->helpers[$event->helperName] = true;
             Logger::log("Loading helper '" . $event->helperName . "'");
             return true;
         }
     }
     throw new HelperException("Could not load helper. Helper not found.", 1);
 }
Example #3
0
 /**
  * Retrieve a language file and return the language array
  * 
  * @param string $langfile
  * @param string $idiom
  * @param boolean $add_suffix
  * @param string $alt_path
  * @return type
  * @throws LanguageException
  */
 public static function get($langfile, $idiom = '', $add_suffix = TRUE, $alt_path = '')
 {
     // First we determine the file that should be loaded
     $langfile = str_replace('.php', '', $langfile);
     if ($add_suffix === TRUE) {
         $langfile = preg_replace('/_lang$/', '', $langfile) . '_lang';
     }
     $langfile .= '.php';
     // Then we determine the idiom
     if (empty($idiom) or !preg_match('/^[a-z_-]+$/i', $idiom)) {
         $config = Config::get('main');
         $idiom = empty($config->language) ? 'english' : $config->language;
     }
     // Is it already loaded? Return the entire language array
     if (isset(self::$is_loaded[$langfile]) && self::$is_loaded[$langfile] === $idiom) {
         return self::$language;
     }
     // Prepare the language variable
     $lang = array();
     // Load the base file, so any others found can override it
     $basepath = Core::$coreDir . DS . 'Language' . DS . $idiom . DS . $langfile;
     if (($found = file_exists($basepath)) === TRUE) {
         $lang = array_merge($lang, (array) (include $basepath));
     }
     // Do we have an alternative path to look in?
     if ($alt_path !== '') {
         $alt_path .= 'Language' . DS . $idiom . DS . $langfile;
         if (file_exists($alt_path)) {
             $lang = array_merge($lang, (array) (include $alt_path));
             $found = TRUE;
         }
     } else {
         foreach (self::$languagePaths as $languagePath) {
             $languagePath .= DS . $idiom . DS . $langfile;
             if ($basepath !== $languagePath && file_exists($languagePath)) {
                 $lang = array_merge($lang, (array) (include $languagePath));
                 $found = TRUE;
                 break;
             }
         }
     }
     // If nothing is found, kill it
     if ($found !== TRUE) {
         throw new LanguageException('Unable to load the requested language file: language/' . $idiom . '/' . $langfile, 1);
     }
     // If only empty content is found, return the language array
     if (empty($lang)) {
         Logger::logError('Language file contains no data: language/' . $idiom . '/' . $langfile);
         return self::$language;
     }
     // Save the data and return it
     self::$is_loaded[$langfile] = $idiom;
     self::$language = array_merge(self::$language, $lang);
     Logger::log('Language file loaded: language/' . $idiom . '/' . $langfile);
     return self::$language;
 }
Example #4
0
 /**
  * Disables the event system.
  */
 public static function disable()
 {
     Logger::log('Disabled the Event system');
     self::$enabled = false;
 }
Example #5
0
 /**
  * Class constructor
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     if (is_array($params)) {
         foreach ($params as $key => $val) {
             $this->{$key} = $val;
         }
     }
     $this->factory = Factory::getInstance();
     Logger::log('Database Driver ' . get_class($this) . ' Initialized');
 }
Example #6
0
 /**
  * Class constructor
  *
  * @param	object	&$db	Database object
  * @return	void
  */
 public function __construct(&$db)
 {
     $this->db =& $db;
     $this->factory = Factory::getInstance();
     Logger::log('Database Utility Class Initialized');
 }
Example #7
0
 /**
  * Resets the layout manager to its default state.
  */
 public static function reset()
 {
     if (!is_null(self::$current_engine)) {
         self::$current_engine->reset();
     }
     // Unload the engines
     self::$engines = array();
     self::$engines_loaded = false;
     self::$file_extensions = array();
     self::$current_engine = null;
     self::$assigned_variables = array();
     self::$directory = Core::$appDir . DS . 'Views';
     Logger::log('Reset the layout manager to its default state');
 }
Example #8
0
 /**
  * The Module Callable.
  *
  * When a module listens for a specific routing path, this callable get's called.
  * After this the module can handle the request with the route() function in the module's root directory
  *
  * @param array   Regex matches
  */
 public static function moduleCallable($matches = array())
 {
     // First detect what module is attached to this route
     Logger::newLevel('Module callable called!');
     // Get the route
     $route = !empty($matches['route']) ? $matches['route'] : null;
     // See if the route exists
     if (isset(self::$module_routes[$route])) {
         Logger::log("Module '" . self::$module_routes[$route] . "' matched given route");
         // Load the module
         $mod = self::get(self::$module_routes[$route]);
         unset($matches['route']);
         $mod->route($matches);
     } else {
         Logger::logError('Route did not match known module. Fatal error');
         return Logger::http_error(500);
     }
     Logger::stopLevel();
 }
Example #9
0
 /**
  * CSRF Set Cookie
  *
  * @codeCoverageIgnore
  * @return	Security
  */
 public function csrf_set_cookie()
 {
     $expire = time() + $this->_csrf_expire;
     $cfg = Config::get('main');
     $secure_cookie = (bool) $cfg->cookie_secure;
     if ($secure_cookie && !is_https()) {
         return $this;
     }
     setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, $cfg->cookie_path, $cfg->cookie_domain, $secure_cookie, $cfg->cookie_httponly);
     Logger::log('CSRF cookie sent');
     return $this;
 }
Example #10
0
 /**
  * Constructor - Sets Email Preferences
  *
  * The constructor can be passed an array of config values
  *
  * @param	array	$config = array()
  * @return	void
  */
 public function __construct(array $config = array())
 {
     $this->charset = Config::get('main')->charset;
     if (count($config) > 0) {
         $this->initialize($config);
     } else {
         $this->_smtp_auth = !($this->smtp_user === '' && $this->smtp_pass === '');
     }
     $this->_safe_mode = !Core::isPHP('5.4') && ini_get('safe_mode');
     $this->charset = strtoupper($this->charset);
     Logger::log('Email Class Initialized');
 }
Example #11
0
 /**
  * Initialize OpenSSL
  *
  * @param	array	$params	Configuration parameters
  * @return	void
  */
 protected function _openssl_initialize($params)
 {
     if (!empty($params['cipher'])) {
         $params['cipher'] = strtolower($params['cipher']);
         $this->_cipher_alias($params['cipher']);
         $this->_cipher = $params['cipher'];
     }
     if (!empty($params['mode'])) {
         $params['mode'] = strtolower($params['mode']);
         if (!isset($this->_modes['openssl'][$params['mode']])) {
             Logger::logError('Encryption: OpenSSL mode ' . strtoupper($params['mode']) . ' is not available.');
         } else {
             $this->_mode = $this->_modes['openssl'][$params['mode']];
         }
     }
     if (isset($this->_cipher, $this->_mode)) {
         // This is mostly for the stream mode, which doesn't get suffixed in OpenSSL
         $handle = empty($this->_mode) ? $this->_cipher : $this->_cipher . '-' . $this->_mode;
         if (!in_array($handle, openssl_get_cipher_methods(), TRUE)) {
             $this->_handle = NULL;
             Logger::logError('Encryption: Unable to initialize OpenSSL with method ' . strtoupper($handle) . '.');
         } else {
             $this->_handle = $handle;
             Logger::log('Encryption: OpenSSL initialized with method ' . strtoupper($handle) . '.');
         }
     }
 }