/** * Loads the configured driver and validates it. * * @param array|string custom configuration or config group name * @return void */ public function __construct($config = NO) { if (is_string($config)) { $name = $config; // Test the config group name if (($config = Eight::config('cache.' . $config)) === NULL) { throw new Cache_Exception('The :group: group is not defined in your configuration.', array(':group:' => $name)); } } if (is_array($config)) { // Append the default configuration options $config += Eight::config('cache.default'); } else { // Load the default group $config = Eight::config('cache.default'); } // Cache the config in the object $this->config = $config; // Set driver name $driver = 'Cache_Driver_' . ucfirst($this->config['driver']); // Load the driver if (!Eight::auto_load($driver)) { throw new Cache_Exception('The :driver: driver for the :class: library could not be found', array(':driver:' => $this->config['driver'], ':class:' => get_class($this))); } // Initialize the driver $this->driver = new $driver($this->config['params']); // Validate the driver if (!$this->driver instanceof Cache_Driver) { throw new Cache_Exception('The :driver: driver for the :library: library must implement the :interface: interface', array(':driver:' => $this->config['driver'], ':library:' => get_class($this), ':interface:' => 'Cache_Driver')); } Eight::log('debug', 'Cache Library initialized'); }
/** * Loads encryption configuration and validates the data. * * @param array|string custom configuration or config group name * @throws Eight_Exception */ public function __construct($config = NO) { if (!defined('MCRYPT_ENCRYPT')) { throw new Eight_Exception('encrypt.requires_mcrypt'); } if (is_string($config)) { $name = $config; // Test the config group name if (($config = Eight::config('encryption.' . $config)) === nil) { throw new Eight_Exception('encrypt.undefined_group', $name); } } if (is_array($config)) { // Append the default configuration options $config += Eight::config('encryption.default'); } else { // Load the default group $config = Eight::config('encryption.default'); } if (empty($config['key'])) { throw new Eight_Exception('encrypt.no_encryption_key'); } // Find the max length of the key, based on cipher and mode $size = mcrypt_get_key_size($config['cipher'], $config['mode']); if (strlen($config['key']) > $size) { // Shorten the key to the maximum size $config['key'] = substr($config['key'], 0, $size); } // Find the initialization vector size $config['iv_size'] = mcrypt_get_iv_size($config['cipher'], $config['mode']); // Cache the config in the object $this->config = $config; Eight::log('debug', 'Encrypt Library initialized'); }
/** * Sets the config for the class. * * @param : array - config passed from the payment library constructor */ public function __construct($config) { $this->test_mode = $config['test_mode']; if ($this->test_mode) { $this->fields['USER'] = $config['SANDBOX_USER']; $this->fields['PWD'] = $config['SANDBOX_PWD']; $this->fields['SIGNATURE'] = $config['SANDBOX_SIGNATURE']; $this->fields['ENDPOINT'] = $config['SANDBOX_ENDPOINT']; } else { $this->fields['USER'] = $config['USER']; $this->fields['PWD'] = $config['PWD']; $this->fields['SIGNATURE'] = $config['SIGNATURE']; $this->fields['ENDPOINT'] = $config['ENDPOINT']; } $this->fields['VERSION'] = $config['VERSION']; $this->fields['CURRENCYCODE'] = $config['CURRENCYCODE']; $this->required_fields['USER'] = !empty($config['USER']); $this->required_fields['PWD'] = !empty($config['PWD']); $this->required_fields['SIGNATURE'] = !empty($config['SIGNATURE']); $this->required_fields['ENDPOINT'] = !empty($config['ENDPOINT']); $this->required_fields['VERSION'] = !empty($config['VERSION']); $this->required_fields['CURRENCYCODE'] = !empty($config['CURRENCYCODE']); $this->curl_config = $config['curl_config']; Eight::log('debug', 'Paypalpro Payment Driver Initialized'); }
/** * Loads Session and configuration options. * * @return void */ public function __construct($config = array()) { // Load Session $this->session = Session::instance(); // Append default auth configuration $config += Eight::config('auth'); // Save the config in the object $this->config = $config; // Init Bcrypt if we're using it if ($this->config['hash_method'] == 'bcrypt') { $this->bcrypt = new Bcrypt(12); } // Set the driver class name $driver = 'Auth_Driver_' . $config['driver']; if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $config['driver'], get_class($this)); } // Load the driver $driver = new $driver($config); if (!$driver instanceof Auth_Driver) { throw new Eight_Exception('core.driver_implements', $config['driver'], get_class($this), 'Auth_Driver'); } // Load the driver for access $this->driver = $driver; Eight::log('debug', 'Auth Library loaded'); }
public function __construct() { // Load Encrypt library if (Eight::config('session.encryption')) { $this->encrypt = new Encrypt(); } Eight::log('debug', 'Session Cache Driver Initialized'); }
public function write($id, $data) { $data = empty($this->encrypt) ? base64_encode($data) : $this->encrypt->encode($data); if (strlen($data) > 4048) { Eight::log('error', 'Session (' . $id . ') data exceeds the 4KB limit, ignoring write.'); return NO; } return cookie::set($this->cookie_name, $data, Eight::config('session.expiration')); }
/** * Constructs a new Pagination object. * * @param array configuration settings * @return void */ public function __construct($config = array()) { // No custom group name given if (!isset($config['group'])) { $config['group'] = 'default'; } // Pagination setup $this->initialize($config); Eight::log('debug', 'Pagination Library initialized'); }
/** * Sets the config for the class. * * @param array config passed from the library */ public function __construct($config) { $this->authnet_values['x_login'] = $config['auth_net_login_id']; $this->authnet_values['x_tran_key'] = $config['auth_net_tran_key']; $this->required_fields['x_login'] = !empty($config['auth_net_login_id']); $this->required_fields['x_tran_key'] = !empty($config['auth_net_tran_key']); $this->curl_config = $config['curl_config']; $this->test_mode = $config['test_mode']; Eight::log('debug', 'Authorize.net Payment Driver Initialized'); }
/** * Sets the config for the class. * * @param array config passed from the library */ public function __construct($config) { // Check to make sure the certificate is valid $this->certificate = is_file($config['certificate']) ? $config['certificate'] : FALSE; if (!$this->certificate) { throw new Eight_Exception('payment.invalid_certificate', $config['certificate']); } $this->curl_config = $config['curl_config']; $this->test_mode = $config['test_mode']; Eight::log('debug', 'YourPay.net Payment Driver Initialized'); }
/** * Sets the config for the class. * * @param array config passed from the library */ public function __construct($config) { $this->fields['profile_id'] = $config['profile_id']; $this->fields['profile_key'] = $config['profile_key']; $this->fields['transaction_type'] = $config['transaction_type']; $this->required_fields['profile_id'] = !empty($config['profile_id']); $this->required_fields['profile_key'] = !empty($config['profile_key']); $this->required_fields['transaction_type'] = !empty($config['transaction_type']); $this->curl_config = $config['curl_config']; $this->test_mode = $config['test_mode']; Eight::log('debug', 'Trident Payment Driver Initialized'); }
/** * Constructor. * * @return void */ public function __construct() { // Only run the constructor once if (self::$instance !== nil) { return; } // Create segment array from the URI self::$segments = explode('/', Router::$current_uri); // Create a singleton self::$instance = $this; Eight::log('debug', 'URI Library initialized'); }
public function __construct() { // Add all built in profiles to event Event::add('profiler.run', array($this, 'benchmarks')); Event::add('profiler.run', array($this, 'database')); Event::add('profiler.run', array($this, 'session')); Event::add('profiler.run', array($this, 'post')); Event::add('profiler.run', array($this, 'cookies')); Event::add('profiler.run', array($this, 'environment')); Event::add('profiler.run', array($this, 'logs')); // Add profiler to page output automatically Event::add('system.display', array($this, 'render')); Eight::log('debug', 'Profiler Library initialized'); }
/** * Sets the config for the class. * * @param array config passed from the library */ public function __construct($config) { $this->test_mode = $config['test_mode']; $this->tclink_library = $config['tclink_library']; $this->fields['ip'] = $_SERVER['REMOTE_ADDR']; $this->fields['custid'] = $config['custid']; $this->fields['password'] = $config['password']; $this->fields['action'] = 'sale'; $this->fields['media'] = $config['media']; if (!extension_loaded('tclink')) { if (!dl($this->tclink_library)) { throw new Eight_Exception('payment.no_dlib', $this->tclink_library); } } Eight::log('debug', 'TrustCommerce Payment Driver Initialized'); }
/** * Loads the archive driver. * * @throws Eight_Exception * @param string type of archive to create * @return void */ public function __construct($type = nil) { $type = empty($type) ? 'zip' : $type; // Set driver name $driver = 'Archive_Driver_' . ucfirst($type); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $type, get_class($this)); } // Initialize the driver $this->driver = new $driver(); // Validate the driver if (!$this->driver instanceof Archive_Driver) { throw new Eight_Exception('core.driver_implements', $type, get_class($this), 'Archive_Driver'); } Eight::log('debug', 'Archive Library initialized'); }
/** * Constructor: __construct * On first session instance creation, sets up the driver and creates session. */ public function __construct() { $this->input = new Input(); // This part only needs to be run once if (self::$instance === NULL) { // Load config self::$config = Eight::config('session'); // Makes a mirrored array, eg: foo=foo self::$protect = array_combine(self::$protect, self::$protect); if (self::$config['driver'] != 'native') { // Set driver name $driver = 'Session_Driver_' . ucfirst(self::$config['driver']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('session.driver_not_supported', self::$config['driver']); } // Initialize the driver self::$driver = new $driver(); // Validate the driver if (!self::$driver instanceof Session_Driver) { throw new Eight_Exception('session.driver_must_implement_interface'); } } // Create a new session $this->create(); // Regenerate session id if (self::$config['regenerate'] > 0 and $_SESSION['total_hits'] % self::$config['regenerate'] === 0) { $this->regenerate(); } // Close the session just before sending the headers, so that // the session cookie can be written Event::add('system.post_controller', 'session_write_close'); // Singleton instance self::$instance = $this; } Eight::log('debug', 'Session Library initialized'); }
/** * Loads Session and configuration options. * * @return void */ public function __construct($config = array()) { // Load Session $this->session = Session::instance(); // Append default auth configuration $config += Eight::config('auth'); // Clean up the salt pattern and split it into an array $config['salt_pattern'] = preg_split('/,\\s*/', Eight::config('auth.salt_pattern')); // Save the config in the object $this->config = $config; // Set the driver class name $driver = 'Auth_Driver_' . $config['driver']; if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $config['driver'], get_class($this)); } // Load the driver $driver = new $driver($config); if (!$driver instanceof Auth_Driver) { throw new Eight_Exception('core.driver_implements', $config['driver'], get_class($this), 'Auth_Driver'); } // Load the driver for access $this->driver = $driver; Eight::log('debug', 'Auth Library loaded'); }
/** * Method: join * Generates the JOIN portion of the query. * * Parameters: * table - table name * cond - join condition * type - type of join (optional) * * Returns: * The <Database> object */ public function join($table, $cond, $type = '') { if ($type != '') { $type = strtoupper(trim($type)); if (!in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { $type = ''; } else { $type .= ' '; } } if (preg_match_all('/\\s+(AND|OR)\\s+/', $cond, $matches)) { $arr = preg_split('/\\s+(AND|OR)\\s+/', $cond); $cond = "("; foreach ($arr as $k => $v) { if (preg_match('/([^\\s]+)([\\s+]?=[\\s+]?)(.+)/i', $v, $where)) { $cond .= $this->driver->escape_column($this->config['table_prefix'] . $where[1]) . ' = ' . (is_numeric($where[3]) ? $where[3] : $this->driver->escape_column($this->config['table_prefix'] . $where[3])) . $matches[0][$k]; } else { Eight::log('debug', 'Failed to add join: ' . $v); } } $cond .= ")"; } else { if (preg_match('/([^\\s]+)([\\s+]?=[\\s+]?)(.+)/i', $cond, $where)) { $cond = $this->driver->escape_column($this->config['table_prefix'] . $where[1]) . ' = ' . (is_numeric($where[3]) ? $where[3] : $this->driver->escape_column($this->config['table_prefix'] . $where[3])); } else { Eight::log('debug', 'Failed to add join: ' . $cond); } } $this->join[] = $type . 'JOIN ' . $this->driver->escape_column($this->config['table_prefix'] . $table) . ' ON ' . $cond; return $this; }
/** * Delete cache items by tag */ public function delete_tag($tags) { Eight::log('debug', __('Cache: XCache driver does not support tags')); return NULL; }
/** * Constructs a new Captcha object. * * @throws Eight_Exception * @param string config group name * @return void */ public function __construct($group = nil) { // Create a singleton instance once empty(self::$instances[$group]) and self::$instances[$group] = $this; // No config group name given if (!is_string($group)) { $group = 'default'; } // Load and validate config group if (!is_array($config = Eight::config('captcha.' . $group))) { throw new Eight_Exception('captcha.undefined_group', $group); } // All captcha config groups inherit default config group if ($group !== 'default') { // Load and validate default config group if (!is_array($default = Eight::config('captcha.default'))) { throw new Eight_Exception('captcha.undefined_group', 'default'); } // Merge config group with default config group $config += $default; } // Assign config values to the object foreach ($config as $key => $value) { if (array_key_exists($key, self::$config)) { self::$config[$key] = $value; } } // Store the config group name as well, so the drivers can access it self::$config['group'] = $group; // If using a background image, check if it exists if (!empty($config['background'])) { self::$config['background'] = str_replace('\\', '/', realpath($config['background'])); if (!is_file(self::$config['background'])) { throw new Eight_Exception('captcha.file_not_found', self::$config['background']); } } // If using any fonts, check if they exist if (!empty($config['fonts'])) { self::$config['fontpath'] = str_replace('\\', '/', realpath($config['fontpath'])) . '/'; foreach ($config['fonts'] as $font) { if (!is_file(self::$config['fontpath'] . $font)) { throw new Eight_Exception('captcha.file_not_found', self::$config['fontpath'] . $font); } } } // Set driver name $driver = 'Captcha_Driver_' . ucfirst($config['style']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $config['style'], get_class($this)); } // Initialize the driver $this->driver = new $driver(); // Validate the driver if (!$this->driver instanceof Captcha_Driver) { throw new Eight_Exception('core.driver_implements', $config['style'], get_class($this), 'Captcha_Driver'); } Eight::log('debug', 'Captcha Library initialized'); }
/** * Clears the internal query cache * * @param string $sql */ public function clear_cache($sql = NULL) { if (empty($sql)) { self::$query_cache = array(); } else { unset(self::$query_cache[$this->query_hash($sql)]); } Eight::log('debug', 'Database cache cleared: ' . get_class($this)); }
/** * Constructor: __construct * Sets up the config for the class. * * Parameters: * config - database configuration */ public function __construct($config) { $this->db_config = $config; Eight::log('debug', 'MySQLi Database Driver Initialized'); }
/** * Runs the CURL methods to communicate with paypal. * * @param string paypal API method to run * @param string any additional name-value-pair query string data to send to paypal * @return mixed */ protected function make_paypal_api_request($nvp_str) { $postdata = http_build_query($this->api_authroization_fields) . '&' . $nvp_str; parse_str(urldecode($postdata), $nvpstr); Eight::log('debug', 'Connecting to ' . $this->api_connection_fields['ENDPOINT']); $ch = curl_init($this->api_connection_fields['ENDPOINT']); // Set custom curl options curl_setopt_array($ch, $this->curl_config); // Setting the nvpreq as POST FIELD to curl curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); // Getting response from server $response = curl_exec($ch); if (curl_errno($ch)) { throw new Eight_User_Exception('CURL ERROR', Eight::debug(array('curl_error_no' => curl_errno($ch), 'curl_error_msg' => curl_error($ch)))); // Moving to error page to display curl errors $this->session->set_flash(array('curl_error_no' => curl_errno($ch), 'curl_error_msg' => curl_error($ch))); url::redirect($this->api_connection_fields['ERRORURL']); } else { curl_close($ch); } return $response; }
/** * Method: insert_id * Returns last insert id * * @deprecated */ public function insert_id() { if (is_object(Database_Mysql_Result::$last_result)) { return Database_Mysql_Result::$last_result->insert_id(); } else { Eight::log("error", "Could not find last result"); return false; } }
public function gc($maxlifetime) { // Delete all expired sessions $this->db->use_master(YES); $query = $this->db->delete($this->table, array('session_last_activity <' => time() - $maxlifetime)); Eight::log('debug', 'Session garbage collected: ' . $query->count() . ' row(s) deleted.'); return TRUE; }
public function _memcache_failure_callback($host, $port) { $this->backend->setServerParams($host, $port, 1, -1, NO); Eight::log('error', __('Cache: Memcache server down: :host:::port:', array(':host:' => $host, ':port:' => $port))); }
/** * Delete cache items by keys or tags */ public function delete($keys, $tag = NO) { $success = YES; $paths = $this->exists($keys, $tag); // Disable all error reporting while deleting $ER = error_reporting(0); foreach ($paths as $path) { // Remove the cache file if (!unlink($path)) { Eight::log('error', 'Cache: Unable to delete cache file: ' . $path); $success = NO; } } // Turn on error reporting again error_reporting($ER); return $success; }
/** * Method: insert_id * Returns last insert id * * @deprecated */ public function insert_id() { if (is_object(Database_Mssql_Result::$last_result)) { return Database_Mssql_Result::$last_result->insert_id(); } else { Eight::log('error', "Could not find last result."); return FALSE; } }
/** * exception handler, displays the error message, source of the * exception, and the stack trace of the error. * * @uses Eight::lang() * @uses Eight_Exception::text() * @param object exception object * @return void */ public static function handle(Exception $e) { try { // Get the exception information $type = get_class($e); $code = $e->getCode(); $message = $e->getMessage(); // Create a text version of the exception $error = Eight_Exception::text($e); // Add this exception to the log Eight::log('error', $error); // Manually save logs after exceptions Eight::log_save(); if (Eight::config('core.display_errors') === FALSE && Eight::$force_show_errors !== YES) { // Do not show the details $file = $line = NULL; $trace = array(); $template = '_disabled'; } else { $file = $e->getFile(); $line = $e->getLine(); $trace = $e->getTrace(); $template = Eight::$server_api == 'cli' ? '_cli' : ''; } if (Eight::$server_api != 'cli') { header("Content-Type: text/html;charset=utf-8"); } if ($e instanceof Eight_Exception) { $template = $e->getTemplate() . $template; if (!headers_sent()) { $e->sendHeaders(); } // Use the human-readable error name $code = Eight::lang('4' . $code); } else { $template = Eight_Exception::$template . $template; if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } if ($e instanceof ErrorException) { // Use the human-readable error name $code = Eight::lang('4' . $e->getSeverity()); if (version_compare(PHP_VERSION, '5.3', '<')) { // Workaround for a bug in ErrorException::getTrace() that exists in // all PHP 5.2 versions. @see http://bugs.php.net/45895 for ($i = count($trace) - 1; $i > 0; --$i) { if (isset($trace[$i - 1]['args'])) { // Re-position the arguments $trace[$i]['args'] = $trace[$i - 1]['args']; unset($trace[$i - 1]['args']); } } } } } // Clean the output buffer if one exists ob_get_level() and ob_clean(); if ($template = Eight::find_file('views', $template)) { include $template; } } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo Eight_Exception::text($e), "\n"; // Exit with an error code exit(1); } }
/** * Sanitizes global GET, POST and COOKIE data. Also takes care of * magic_quotes and register_globals, if they have been enabled. * * @return void */ public function __construct() { // Use XSS clean? $this->use_xss_clean = (bool) Eight::config('core.global_xss_filtering'); if (self::$instance === nil) { // Convert all global variables to UTF-8. $_GET = Input::clean($_GET); $_POST = Input::clean($_POST); $_COOKIE = Input::clean($_COOKIE); $_SERVER = Input::clean($_SERVER); if (PHP_SAPI == 'cli') { // Convert command line arguments $_SERVER['argv'] = Input::clean($_SERVER['argv']); } // magic_quotes_runtime is enabled if (get_magic_quotes_runtime()) { exit('Disable magic_quotes_runtime! It is evil and deprecated: http://php.net/magic_quotes'); } // magic_quotes_gpc is enabled if (get_magic_quotes_gpc()) { exit('Disable magic_quotes_gpc! It is evil and deprecated: http://php.net/magic_quotes'); } // register_globals is enabled if (ini_get('register_globals')) { exit('Disable register_globals! It is evil and deprecated: http://php.net/register_globals'); } if (is_array($_GET)) { foreach ($_GET as $key => $val) { // Sanitize $_GET $_GET[$this->clean_input_keys($key)] = $this->clean_input_data($val); } } else { $_GET = array(); } if (is_array($_POST)) { foreach ($_POST as $key => $val) { // Sanitize $_POST $_POST[$this->clean_input_keys($key)] = $this->clean_input_data($val); } } else { $_POST = array(); } if (is_array($_COOKIE)) { foreach ($_COOKIE as $key => $val) { // Sanitize $_COOKIE $_COOKIE[$this->clean_input_keys($key)] = $this->clean_input_data($val); } } else { $_COOKIE = array(); } // Create a singleton self::$instance = $this; Eight::log('debug', 'Global GET, POST and COOKIE data sanitized'); } // Assign global vars to request helper vars request::$get = $_GET; request::$post = $_POST; request::$input = array_merge(URI::instance()->segments(2, YES), $_REQUEST); }
/** * Fetch an i18n language item. * * @param string language key to fetch * @param array additional information to insert into the line * @return string i18n language string, or the requested key if the i18n item is not found */ public static function lang($key, $args = array()) { // Extract the main group from the key $group = explode('.', $key, 2); $group = $group[0]; // Get locale name $locale = Eight::config('locale.language.0'); if (!isset(self::$internal_cache['language'][$locale][$group])) { // Messages for this group $messages = array(); if ($files = self::find_file('i18n', $locale . '/' . $group)) { foreach ($files as $file) { include $file; // Merge in configuration if (!empty($lang) and is_array($lang)) { foreach ($lang as $k => $v) { $messages[$k] = $v; } } } } if (!isset(self::$write_cache['language'])) { // Write language cache self::$write_cache['language'] = YES; } self::$internal_cache['language'][$locale][$group] = $messages; } // Get the line from cache $line = self::key_string(self::$internal_cache['language'][$locale], $key); if ($line === NULL or empty($line)) { Eight::log('debug', 'Missing i18n entry ' . $key . ' for language ' . $locale); // Return the key string as fallback return $key; } if (is_string($line) && func_num_args() > 1) { $args = array_slice(func_get_args(), 1); // Add the arguments into the line $line = vsprintf($line, is_array($args[0]) ? $args[0] : $args); } return $line; }