public function __construct() { include Kohana::find_file('vendor', 'facebook/src/facebook'); // class setup $this->_facebook = new Facebook(array('appId' => Kohana::config('facebook')->app_id, 'secret' => Kohana::config('facebook')->secret, 'cookie' => true)); $this->canvasUrl = Kohana::config('facebook')->canvas_url; $this->scope = Kohana::config('facebook')->scope; try { $this->uid = $this->getUser(); if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('Kohana_Facebook', 'facebook->api(/me)'); } $this->_me = $this->_facebook->api('/me'); if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } } catch (FacebookApiException $e) { $log = Kohana_Log::instance(); $log->write($e); var_dump($e); $this->redirectToLogin(); exit; } }
/** * Loads Session and configuration options. * * @return void */ public function __construct($config = array()) { // Clean up the salt pattern and split it into an array $config['salt_pattern'] = preg_split('/,\\s*/', Kohana::config('auth')->get('salt_pattern')); // Save the config in the object $this->config = $config; $this->session = Session::instance(); Kohana_Log::instance()->add('debug', 'Auth Library loaded'); }
/** * Initializes the environment: * * - Disables register_globals and magic_quotes_gpc * - Determines the current environment * - Set global settings * - Sanitizes GET, POST, and COOKIE variables * - Converts GET, POST, and COOKIE variables to the global character set * * Any of the global settings can be set here: * * > boolean "errors" : use internal error and exception handling? * > boolean "profile" : do internal benchmarking? * > boolean "caching" : cache the location of files between requests? * > string "charset" : character set used for all input and output * > string "base_url" : set the base URL for the application * > string "index_file" : set the index.php file name * > string "cache_dir" : set the cache directory path * * @throws Kohana_Exception * @param array global settings * @return void */ public static function init(array $settings = NULL) { static $run; // This function can only be run once if ($run === TRUE) { return; } // The system is now ready $run = TRUE; if (isset($settings['profile'])) { // Enable profiling self::$profiling = (bool) $settings['profile']; } if (self::$profiling === TRUE) { // Start a new benchmark $benchmark = Profiler::start(__CLASS__, __FUNCTION__); } // Start an output buffer ob_start(); if (isset($settings['errors'])) { // Enable error handling Kohana::$errors = (bool) $settings['errors']; } if (Kohana::$errors === TRUE) { // Enable the Kohana shutdown handler, which catches E_FATAL errors. register_shutdown_function(array('Kohana', 'shutdown_handler')); // Enable Kohana exception handling, adds stack traces and error source. set_exception_handler(array('Kohana', 'exception_handler')); // Enable Kohana error handling, converts all PHP errors to exceptions. set_error_handler(array('Kohana', 'error_handler')); } if (ini_get('register_globals')) { if (isset($_REQUEST['GLOBALS'])) { // Prevent malicious GLOBALS overload attack echo "Global variable overload attack detected! Request aborted.\n"; // Exit with an error status exit(1); } // Get the variable names of all globals $global_variables = array_keys($GLOBALS); // Remove the standard global variables from the list $global_variables = array_diff($global_variables, array('GLOBALS', '_REQUEST', '_GET', '_POST', '_FILES', '_COOKIE', '_SERVER', '_ENV', '_SESSION')); foreach ($global_variables as $name) { // Retrieve the global variable and make it null global ${$name}; ${$name} = NULL; // Unset the global variable, effectively disabling register_globals unset($GLOBALS[$name], ${$name}); } } // Determine if we are running in a command line environment self::$is_cli = PHP_SAPI === 'cli'; // Determine if we are running in a Windows environment self::$is_windows = DIRECTORY_SEPARATOR === '\\'; if (isset($settings['cache_dir'])) { // Set the cache directory path self::$cache_dir = realpath($settings['cache_dir']); } else { // Use the default cache directory self::$cache_dir = APPPATH . 'cache'; } if (!is_writable(self::$cache_dir)) { throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Kohana::debug_path(self::$cache_dir))); } if (isset($settings['caching'])) { // Enable or disable internal caching self::$caching = (bool) $settings['caching']; } if (self::$caching === TRUE) { // Load the file path cache self::$_files = Kohana::cache('Kohana::find_file()'); } if (isset($settings['charset'])) { // Set the system character set self::$charset = strtolower($settings['charset']); } if (isset($settings['base_url'])) { // Set the base URL self::$base_url = rtrim($settings['base_url'], '/') . '/'; } if (isset($settings['index_file'])) { // Set the index file self::$index_file = trim($settings['index_file'], '/'); } // Determine if the extremely evil magic quotes are enabled self::$magic_quotes = (bool) get_magic_quotes_gpc(); // Sanitize all request variables $_GET = self::sanitize($_GET); $_POST = self::sanitize($_POST); $_COOKIE = self::sanitize($_COOKIE); // Load the logger self::$log = Kohana_Log::instance(); // Load the config self::$config = Kohana_Config::instance(); if (isset($benchmark)) { // Stop benchmarking Profiler::stop($benchmark); } }
/** * Initializes the environment: * * - Disables register_globals and magic_quotes_gpc * - Determines the current environment * - Set global settings * - Sanitizes GET, POST, and COOKIE variables * - Converts GET, POST, and COOKIE variables to the global character set * * Any of the global settings can be set here: * * Type | Setting | Description | Default Value * ----------|------------|------------------------------------------------|--------------- * `boolean` | errors | use internal error and exception handling? | `TRUE` * `boolean` | profile | do internal benchmarking? | `TRUE` * `boolean` | caching | cache the location of files between requests? | `FALSE` * `string` | charset | character set used for all input and output | `"utf-8"` * `string` | base_url | set the base URL for the application | `"/"` * `string` | index_file | set the index.php file name | `"index.php"` * `string` | cache_dir | set the cache directory path | `APPPATH."cache"` * * @throws Kohana_Exception * @param array global settings * @return void * @uses Kohana::globals * @uses Kohana::sanitize * @uses Kohana::cache * @uses Profiler */ public static function init(array $settings = NULL) { if (Kohana::$_init) { // Do not allow execution twice return; } // Kohana is now initialized Kohana::$_init = TRUE; if (isset($settings['profile'])) { // Enable profiling Kohana::$profiling = (bool) $settings['profile']; } if (Kohana::$profiling === TRUE) { // Start a new benchmark $benchmark = Profiler::start('Kohana', __FUNCTION__); } // Start an output buffer ob_start(); if (defined('E_DEPRECATED')) { // E_DEPRECATED only exists in PHP >= 5.3.0 Kohana::$php_errors[E_DEPRECATED] = 'Deprecated'; } if (isset($settings['errors'])) { // Enable error handling Kohana::$errors = (bool) $settings['errors']; } if (Kohana::$errors === TRUE) { // Enable Kohana exception handling, adds stack traces and error source. set_exception_handler(array('Kohana', 'exception_handler')); // Enable Kohana error handling, converts all PHP errors to exceptions. set_error_handler(array('Kohana', 'error_handler')); } // Enable the Kohana shutdown handler, which catches E_FATAL errors. register_shutdown_function(array('Kohana', 'shutdown_handler')); if (ini_get('register_globals')) { // Reverse the effects of register_globals Kohana::globals(); } // Determine if we are running in a command line environment Kohana::$is_cli = PHP_SAPI === 'cli'; // Determine if we are running in a Windows environment Kohana::$is_windows = DIRECTORY_SEPARATOR === '\\'; if (isset($settings['cache_dir'])) { // Set the cache directory path Kohana::$cache_dir = realpath($settings['cache_dir']); } else { // Use the default cache directory Kohana::$cache_dir = APPPATH . 'cache'; } if (!is_writable(Kohana::$cache_dir)) { throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Kohana::debug_path(Kohana::$cache_dir))); } if (isset($settings['caching'])) { // Enable or disable internal caching Kohana::$caching = (bool) $settings['caching']; } if (Kohana::$caching === TRUE) { // Load the file path cache Kohana::$_files = Kohana::cache('Kohana::find_file()'); } if (isset($settings['charset'])) { // Set the system character set Kohana::$charset = strtolower($settings['charset']); } if (function_exists('mb_internal_encoding')) { // Set the MB extension encoding to the same character set mb_internal_encoding(Kohana::$charset); } if (isset($settings['base_url'])) { // Set the base URL Kohana::$base_url = rtrim($settings['base_url'], '/') . '/'; } if (isset($settings['index_file'])) { // Set the index file Kohana::$index_file = trim($settings['index_file'], '/'); } // Determine if the extremely evil magic quotes are enabled Kohana::$magic_quotes = (bool) get_magic_quotes_gpc(); // Sanitize all request variables $_GET = Kohana::sanitize($_GET); $_POST = Kohana::sanitize($_POST); $_COOKIE = Kohana::sanitize($_COOKIE); // Load the logger Kohana::$log = Kohana_Log::instance(); // Load the config Kohana::$config = Kohana_Config::instance(); if (isset($benchmark)) { // Stop benchmarking Profiler::stop($benchmark); } }
/** * Initializes the environment: * * - Disables register_globals and magic_quotes_gpc * - Determines the current environment * - Set global settings * - Sanitizes GET, POST, and COOKIE variables * - Converts GET, POST, and COOKIE variables to the global character set * * Any of the global settings can be set here: * * > boolean "display_errors" : display errors and exceptions * > boolean "log_errors" : log errors and exceptions * > boolean "cache_paths" : cache the location of files between requests * > string "charset" : character set used for all input and output * * @param array global settings * @return void */ public static function init(array $settings = NULL) { static $_init; // This function can only be run once if ($_init === TRUE) { return; } if (isset($settings['profile'])) { // Enable profiling self::$profile = (bool) $settings['profile']; } if (self::$profile === TRUE) { // Start a new benchmark $benchmark = Profiler::start(__CLASS__, __FUNCTION__); } // The system will now be initialized $_init = TRUE; // Start an output buffer ob_start(); if (version_compare(PHP_VERSION, '6.0', '<=')) { // Disable magic quotes at runtime set_magic_quotes_runtime(0); } if (ini_get('register_globals')) { if (isset($_REQUEST['GLOBALS'])) { // Prevent malicious GLOBALS overload attack echo "Global variable overload attack detected! Request aborted.\n"; // Exit with an error status exit(1); } // Get the variable names of all globals $global_variables = array_keys($GLOBALS); // Remove the standard global variables from the list $global_variables = array_diff($global_vars, array('GLOBALS', '_REQUEST', '_GET', '_POST', '_FILES', '_COOKIE', '_SERVER', '_ENV', '_SESSION')); foreach ($global_variables as $name) { // Retrieve the global variable and make it null global ${$name}; ${$name} = NULL; // Unset the global variable, effectively disabling register_globals unset($GLOBALS[$name], ${$name}); } } // Determine if we are running in a command line environment self::$is_cli = PHP_SAPI === 'cli'; // Determine if we are running in a Windows environment self::$is_windows = DIRECTORY_SEPARATOR === '\\'; if (isset($settings['display_errors'])) { // Enable or disable the display of errors self::$display_errors = (bool) $settings['display_errors']; } if (isset($settings['cache_paths'])) { // Enable or disable the caching of paths self::$cache_paths = (bool) $settings['cache_paths']; } if (isset($settings['charset'])) { // Set the system character set self::$charset = strtolower($settings['charset']); } if (isset($settings['base_url'])) { // Set the base URL self::$base_url = rtrim($settings['base_url'], '/') . '/'; } // Determine if the extremely evil magic quotes are enabled self::$magic_quotes = (bool) get_magic_quotes_gpc(); // Sanitize all request variables $_GET = self::sanitize($_GET); $_POST = self::sanitize($_POST); $_COOKIE = self::sanitize($_COOKIE); // Load the logger self::$log = Kohana_Log::instance(); // Determine if this server supports UTF-8 natively utf8::$server_utf8 = extension_loaded('mbstring'); // Normalize all request variables to the current charset $_GET = utf8::clean($_GET, self::$charset); $_POST = utf8::clean($_POST, self::$charset); $_COOKIE = utf8::clean($_COOKIE, self::$charset); if (isset($benchmark)) { // Stop benchmarking Profiler::stop($benchmark); } }
public function incomingPayment() { if ($_POST) { $this->_incomingPaymentData = $_POST; if ($this->_checkMD5(Arr::get($_POST, 'md5')) && $this->_checkServerIP(Request::$client_ip)) { $payment = ORM::factory('payment', array('control' => $this->_incomingPaymentData['control'])); if ($payment->loaded()) { $incomingPayment = ORM::factory('payment_incoming', array('t_id' => $this->_incomingPaymentData['t_id'])); if ($incomingPayment->loaded()) { $incomingPayment->t_status = $this->_incomingPaymentData['t_status']; $incomingPayment->updated = time(); $incomingPayment->status = $this->_checkPayment($payment->id); } else { $this->_incomingSave($incomingPayment, $payment->id); } } else { $incomingPayment = ORM::factory('payment_incoming'); $this->_incomingSave($incomingPayment); } $incomingPayment->save(); return $incomingPayment->saved(); } else { $this->_incomingPaymentData = FALSE; Kohana_Log::instance()->add(Log::ERROR, 'Wrong MD5 hash for payment'); } } return FALSE; }
/** * Remove an entry from the index * * @param Searchable Model to remove * @return Search */ public function remove($item) { $hits = $this->find('uid:' . $item->get_unique_identifier()); if (sizeof($hits) == 0) { Kohana_Log::instance()->add('error', 'No index entry found for id ' . $item->get_unique_identifier())->write(); } elseif (sizeof($hits) > 1) { Kohana_Log::instance()->add('error', 'Non-unique Identifier - More than one record was returned')->write(); } elseif (sizeof($hits) == 1) { $this->open_index()->delete($hits[0]->id); } return $this; }
public function incomingPayment() { if ($_POST) { $this->_incomingPaymentData = $_POST; if ($this->_checkMD5(Arr::get($_POST, 'md5sum')) && $this->_checkServerIP(Request::$client_ip)) { $payment = ORM::factory('transferuj_payment', array('crc' => $this->_incomingPaymentData['tr_crc'])); $incomingPayment = ORM::factory('transferuj_payment_incoming'); if ($payment->loaded()) { $this->_incomingSave($incomingPayment, $payment->id); } else { $this->_incomingSave($incomingPayment); } $incomingPayment->save(); return $incomingPayment->saved(); } else { $this->_incomingPaymentData = FALSE; Kohana_Log::instance()->add(Log::ERROR, 'Wrong MD5 hash for payment'); } } return FALSE; }
public static function exception($msg, $e) { $log = Kohana_Log::instance()->add(log::ERROR, $msg . ' || Exception message: :emsg, file: :file, line: :line', array(':emsg' => $e->getMessage(), ':file' => $e->getFile(), ':line' => $e->getLine())); }