/** * 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($config = array()) { // Set the config $this->config = $config; // Set a filename, if we don't have one if (str::e($this->config['filename'])) { $this->config['filename'] = date("Y-m-d_g-ia"); } // Build driver class $driver = "Export_Driver_" . trim(strtoupper($config['driver'])); // Load the driver if (!Eight::auto_load($driver)) { throw new Export_Exception('export.driver_not_supported', $config['driver']); } // Initialize the driver $this->driver = new $driver($this->config); // Validate the driver if (!$this->driver instanceof Export_Driver) { throw new Export_Exception('export.driver_not_supported', 'Export drivers must use the Export_Driver interface.'); } // Set the columns if (!arr::e($this->config['columns'])) { $this->driver->set_columns($this->config['columns']); } }
/** * 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'); }
/** * Sets the payment processing fields. * The driver will translate these into the specific format for the provider. * Standard fields are (Providers may have additional or different fields): * * card_num * exp_date * cvv * description * amount * tax * shipping * first_name * last_name * company * address * city * state * zip * email * phone * fax * ship_to_first_name * ship_to_last_name * ship_to_company * ship_to_address * ship_to_city * ship_to_state * ship_to_zip * * @param array the driver string */ public function __construct($config = array()) { if (empty($config)) { // Load the default group $config = Eight::config('payment.default'); } elseif (is_string($config)) { $this->config['driver'] = $config; } // Merge the default config with the passed config is_array($config) and $this->config = array_merge($this->config, $config); // Set driver name $driver = 'Payment_Driver_' . ucfirst($this->config['driver']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $this->config['driver'], get_class($this)); } // Get the driver specific settings $this->config = array_merge($this->config, Eight::config('payment.' . $this->config['driver'])); // Initialize the driver $this->driver = new $driver($this->config); // Validate the driver if (!$this->driver instanceof Payment_Driver) { throw new Eight_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Payment_Driver'); } }
/** * Loads the database instance, if the database is not already loaded. * * @return void */ public function __construct() { // Eight global instance $this->core = Eight::instance(); $this->obj = Eight::instance(); $this->db = Eight::instance()->db; }
/** * 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'); }
/** * Returns an array of the names of the days, using the current locale. * * @param integer left of day names * @return array */ public static function days($length = YES) { // strftime day format $format = $length > 3 ? '%A' : '%a'; // Days of the week $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); if (Calendar::$start_monday === YES) { // Push Sunday to the end of the days array_push($days, array_shift($days)); } if (strpos(Eight::config('locale.language.0'), 'en') !== 0) { // This is a bit awkward, but it works properly and is reliable foreach ($days as $i => $day) { // Convert the English names to i18n names $days[$i] = strftime($format, strtotime($day)); } } if (is_int($length) or ctype_digit($length)) { foreach ($days as $i => $day) { // Shorten the days to the expected length $days[$i] = mb_substr($day, 0, $length); } } return $days; }
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')); }
/** * Loads URI, and Input into this controller. * * @return void */ public function __construct() { if (Eight::$instance == nil) { // Set the instance to the first controller loaded Eight::$instance = $this; } // Input should always be available $this->input = Input::instance(); }
/** * Get styles for table. * * @return string */ public function styles() { static $styles_output; if (!$styles_output) { $styles_output = YES; return file_get_contents(Eight::find_file('views', 'profiler/table', NO, 'css')); } return ''; }
/** * Throws a new 404 exception. * * @throws Eight_Exception_404 * @return void */ public static function trigger($page = NULL) { // Silence 404 errors (as matched within the ignore array) and die quietly if (in_array(Router::$complete_uri, arr::c(Eight::config('core.ignore_page_not_found')))) { Eight::shutdown(); exit; } throw new Eight_Exception_404($page); }
/** * 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'); }
/** * Generates a new Captcha challenge. * * @return string the challenge answer */ public function generate_challenge() { // Load riddles from the current language $riddles = Eight::lang('captcha.riddles'); // Pick a random riddle $riddle = $riddles[array_rand($riddles)]; // Store the question for output $this->riddle = $riddle[0]; // Return the answer return $riddle[1]; }
/** * 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'); }
public static function logged_in() { if (str::e($_COOKIE[Eight::config('facebook.api_key') . '_user'])) { return FALSE; } else { if (intval(Eight::instance()->fb->user) > 0) { return TRUE; } else { return FALSE; } } }
public function upload() { $profiler = new Profiler(); $form = new Formation(); $form->input('hello')->label(YES); $form->upload('file', YES)->label(YES)->rules('required|size[200KB]|allow[jpg,png,gif]'); $form->submit('Upload'); if ($form->validate()) { echo Eight::debug($form->as_array()); } echo $form->render(); }
/** * 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'); }
/** * Generates a new Captcha challenge. * * @return string the challenge answer */ public function generate_challenge() { // Load words from the current language and randomize them $words = Eight::lang('captcha.words'); shuffle($words); // Loop over each word... foreach ($words as $word) { // ...until we find one of the desired length if (abs(Captcha::$config['complexity'] - strlen($word)) < 2) { return strtoupper($word); } } // Return any random word as final fallback return strtoupper($words[array_rand($words)]); }
/** * 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'); }
/** * Sets the view filename. * * @chainable * @param string view filename * @param string view file type * @return object */ public function set_filename($name, $type = nil) { if ($type === nil) { // Load the filename and set the content type $this->eight_filename = Eight::find_file('views', $name, YES); $this->eight_filetype = EXT; } else { // Load the filename and set the content type $this->eight_filename = Eight::find_file('views', $name, YES, $type); $this->eight_filetype = Eight::config('mimes.' . $type); if ($this->eight_filetype === nil) { // Use the specified type $this->eight_filetype = $type; } } return $this; }
/** * Fetches an absolute site URL based on a URI segment. * * @param string site URI to convert * @param string non-default protocol * @return string */ public static function site($uri = '', $protocol = NO) { if ($path = trim(parse_url($uri, PHP_URL_PATH), '/')) { // Add path suffix $path .= Eight::config('core.url_suffix'); } if ($query = parse_url($uri, PHP_URL_QUERY)) { // ?query=string $query = '?' . $query; } if ($fragment = parse_url($uri, PHP_URL_FRAGMENT)) { // #fragment $fragment = '#' . $fragment; } // Concat the URL return url::base(YES, $protocol) . $path . $query . $fragment; }
/** * Sets a cookie with the given parameters. * * @param string cookie name or array of config options * @param string cookie value * @param integer number of seconds before the cookie expires * @param string URL path to allow * @param string URL domain to allow * @param boolean HTTPS only * @param boolean HTTP only (requires PHP 5.2 or higher) * @return boolean */ public static function set($name, $value = nil, $expire = nil, $path = nil, $domain = nil, $secure = nil, $httponly = nil) { if (headers_sent()) { return NO; } // If the name param is an array, we import it is_array($name) and extract($name, EXTR_OVERWRITE); // Fetch default options $config = Eight::config('cookie'); foreach (array('value', 'expire', 'domain', 'path', 'secure', 'httponly') as $item) { if (${$item} === nil and isset($config[$item])) { ${$item} = $config[$item]; } } // Expiration timestamp $expire = $expire == 0 ? 0 : time() + (int) $expire; return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); }
/** * Creates a new image editor instance. * * @throws Eight_Exception * @param string filename of image * @param array non-default configurations * @return void */ public function __construct($image, $config = nil) { static $check; // Make the check exactly once $check === nil and $check = function_exists('getimagesize'); if ($check === NO) { throw new Eight_Exception('image.getimagesize_missing'); } // Check to make sure the image exists if (!is_file($image)) { throw new Eight_Exception('image.file_not_found', $image); } // Disable error reporting, to prevent PHP warnings $ER = error_reporting(0); // Fetch the image size and mime type $image_info = getimagesize($image); // Turn on error reporting again error_reporting($ER); // Make sure that the image is readable and valid if (!is_array($image_info) or count($image_info) < 3) { throw new Eight_Exception('image.file_unreadable', $image); } // Check to make sure the image type is allowed if (!isset(Image::$allowed_types[$image_info[2]])) { throw new Eight_Exception('image.type_not_allowed', $image); } // Image has been validated, load it $this->image = array('file' => str_replace('\\', '/', realpath($image)), 'width' => $image_info[0], 'height' => $image_info[1], 'type' => $image_info[2], 'ext' => Image::$allowed_types[$image_info[2]], 'mime' => $image_info['mime']); // Load configuration $this->config = (array) $config + Eight::config('image'); // Set driver class name $driver = 'Image_Driver_' . ucfirst($this->config['driver']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $this->config['driver'], get_class($this)); } // Initialize the driver $this->driver = new $driver($this->config['params']); // Validate the driver if (!$this->driver instanceof Image_Driver) { throw new Eight_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Image_Driver'); } }
public static function factory($controller) { $controller_file = strtolower($controller); // Set controller class name $controller = 'Controller_' . ucfirst($controller); if (!class_exists($controller, FALSE)) { // If the file doesn't exist, just return if (($filepath = Eight::find_file('classes/controllers', $controller_file)) === FALSE) { return FALSE; } // Include the Controller file require_once $filepath; } // Run system.pre_controller Event::run('dispatch.pre_controller'); // Initialize the controller $controller = new $controller(); // Run system.post_controller_constructor Event::run('dispatch.post_controller_constructor'); return new Dispatch($controller); }
/** * 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'); }
public function assert_not_pattern($value, $regex, $debug = nil) { if (!is_string($value) or !is_string($regex) or preg_match($regex, $value)) { throw new UnitTest_Exception(Eight::lang('unittest.assert_not_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug); } return $this; }
?> — <?php echo $code; ?> </title> <base href="http://php.net/" /> </head> <body> <div id="framework_error" style="width:900px;margin:20px auto;"> <?php // Unique error identifier $error_id = uniqid('error'); ?> <style type="text/css"> <?php include Eight::find_file('views', 'eight/errors', FALSE, 'css'); ?> </style> <script type="text/javascript"> document.write('<style type="text/css"> .collapsed { display: none; } </style>'); function eight_toggle(elem) { elem = document.getElementById(elem); if (elem.style && elem.style['display']) // Only works with the "style" attr var disp = elem.style['display']; else if (elem.currentStyle) // For MSIE, naturally var disp = elem.currentStyle['display'];
/** * Sets config values. * * @throws Eight_Exception * @param array configuration settings * @return void */ public function initialize($config = array()) { // Load config group if (isset($config['group'])) { // Load and validate config group if (!is_array($group_config = Eight::config('pagination.' . $config['group']))) { throw new Eight_Exception('pagination.undefined_group', $config['group']); } // All pagination config groups inherit default config group if ($config['group'] !== 'default') { // Load and validate default config group if (!is_array($default_config = Eight::config('pagination.default'))) { throw new Eight_Exception('pagination.undefined_group', 'default'); } // Merge config group with default config group $group_config += $default_config; } // Merge custom config items with config group $config += $group_config; } // Assign config values to the object foreach ($config as $key => $value) { if (property_exists($this, $key)) { $this->{$key} = $value; } } // Clean view directory $this->directory = trim($this->directory, '/') . '/'; // Build generic URL with page in query string if ($this->query_string !== '') { // Extract current page $this->current_page = isset($_GET[$this->query_string]) ? (int) $_GET[$this->query_string] : 1; // Insert {page} placeholder $_GET[$this->query_string] = '{page}'; // Create full URL $this->url = url::site(Router::$current_uri) . '?' . str_replace('%7Bpage%7D', '{page}', http_build_query($_GET)); // Reset page number $_GET[$this->query_string] = $this->current_page; } else { // Use current URI if no base_url set $this->url = $this->base_url === '' ? URI::instance()->segments() : explode('/', trim($this->base_url, '/')); // Convert uri 'label' to corresponding integer if needed if (is_string($this->uri_segment)) { if (($key = array_search($this->uri_segment, $this->url)) === NO) { // If uri 'label' is not found, auto add it to base_url $this->url[] = $this->uri_segment; $this->uri_segment = count($this->url) + 1; } else { $this->uri_segment = $key + 1; } } // Insert {page} placeholder if (!empty($this->base_url)) { $this->url[$this->uri_segment - 1] = '{page}'; } else { $this->url[$this->uri_segment] = '{page}'; } // Create full URL $this->url = url::site(implode('/', $this->url)) . Router::$query_string; // Extract current page $this->current_page = URI::instance()->segment($this->uri_segment); } // Core pagination values $this->total_items = (int) max(0, $this->total_items); $this->items_per_page = (int) max(1, $this->items_per_page); $this->total_pages = (int) ceil($this->total_items / $this->items_per_page); $this->current_page = (int) min(max(1, $this->current_page), max(1, $this->total_pages)); $this->current_first_item = (int) min(($this->current_page - 1) * $this->items_per_page + 1, $this->total_items); $this->current_last_item = (int) min($this->current_first_item + $this->items_per_page - 1, $this->total_items); // If there is no first/last/previous/next page, relative to the // current page, value is set to NO. Valid page number otherwise. $this->first_page = $this->current_page === 1 ? NO : 1; $this->last_page = $this->current_page >= $this->total_pages ? NO : $this->total_pages; $this->previous_page = $this->current_page > 1 ? $this->current_page - 1 : NO; $this->next_page = $this->current_page < $this->total_pages ? $this->current_page + 1 : NO; // SQL values $this->sql_offset = (int) ($this->current_page - 1) * $this->items_per_page; $this->sql_limit = sprintf(' LIMIT %d OFFSET %d ', $this->items_per_page, $this->sql_offset); }
/** * 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; }