/** * Loads the configured driver and validates it. * * @param array|string custom configuration or config group name * @return void */ public function __construct($config = FALSE) { if (is_string($config)) { $name = $config; // Test the config group name if (($config = Ko::config('cache')->{$config}) === NULL) { throw new KoException('Cache: Undefined group :name.', array(':name' => $name)); } } if (!is_array($config)) { // Load the default group $config = Ko::config('cache')->default; } // Cache the config in the object $this->_config = $config; // Set driver name $driver = 'Cache_' . ucfirst($this->_config['driver']); // Load the driver if (!Ko::autoload($driver)) { throw new KoException('Class :name not found.', array(':name' => $driver)); } // Initialize the driver $this->_driver = new $driver($this->_config); // Validate the driver if (!$this->_driver instanceof Cache_Driver) { throw new KoException('Cache: Not valid driver ' . $this->_config['driver']); } }
/** * * @param $lang */ public function __construct($lang = 'en-US') { static $data; if (!isset($data[$lang])) { $stores = (array) Ko::config('store'); $lang = str_replace(array(' ', '_'), '-', $lang); if ($lang !== 'en-US') { $langData = Ko::lang('store', $lang); foreach ($stores as &$store) { if (isset($store->name)) { $store->name = $langData[$store->id]['name']; } // if(isset($store->desc)) if (isset($store->desc) && isset($langData[$store->id]['desc'])) { $store->desc = $langData[$store->id]['desc']; } if (isset($store->product_name) && isset($langData[$store->id]['product_name'])) { $store->product_name = $langData[$store->id]['product_name']; } } unset($stores, $langData); } $data[$lang] = (array) Ko::config('store'); } $this->data = $data[$lang]; }
/** * Save an uploaded file to a new location. * * @param mixed name of $_FILE input or array of upload data * @param string new filename * @param string new directory * @param integer chmod mask * @return string full path to new file */ public static function save($file, $filename = NULL, $directory = NULL, $chmod = 0644) { // Load file data from FILES if not passed as array $file = is_array($file) ? $file : $_FILES[$file]; if ($filename === NULL) { $filename = time() . $file['name']; } if (Ko::config('upload.remove_spaces') === TRUE) { $filename = preg_replace('/\\s+/', '_', $filename); } if ($directory === NULL) { $directory = Ko::config('upload.directory', TRUE); } // Make sure the directory ends with a slash $directory = rtrim($directory, '/') . '/'; if (!is_dir($directory) and Ko::config('upload.create_dir') === TRUE) { mkdir($directory, 0777, TRUE); } if (!is_writable($directory)) { throw new KoException('The upload destination folder, :dir:, does not appear to be writable.', array(':dir:' => $directory)); } if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory . $filename)) { if ($chmod !== FALSE) { chmod($filename, $chmod); } return $filename; } return FALSE; }
public function write($id, $data) { $data = base64_encode($data); if (strlen($data) > 4048) { return FALSE; } return cookie::set($this->cookie_name, $data, Ko::config('session.expiration')); }
public function __construct() { // Load configuration $config = Ko::config('session'); if (is_array($config['storage'])) { if (!empty($config['storage']['group'])) { // Set the group name $this->db = $config['storage']['group']; } if (!empty($config['storage']['table'])) { // Set the table name $this->table = $config['storage']['table']; } } Ko_Log::add('debug', 'Session Database Driver Initialized'); }
public function open($path, $name) { $config = Ko::config('session.storage'); if (empty($config)) { // Load the default group $config = Ko::config('cache.default'); } elseif (is_string($config)) { $name = $config; // Test the config group name if (($config = Ko::config('cache.' . $config)) === NULL) { throw new KoException('The :group: group is not defined in your configuration.', array(':group:' => $name)); } } $this->_cache = $cache = Cache::instance($config); return is_object($this->_cache); }
/** * On first session instance creation, sets up the driver and creates session. * * @param string Force a specific session_id */ protected function __construct($group = 'default') { // This part only needs to be run once if (self::$instance[$group] === NULL) { // Load config self::$config = Ko::config('session.' . $group); // Configure garbage collection ini_set('session.gc_probability', (int) self::$config['gc_probability']); ini_set('session.gc_divisor', 100); ini_set('session.gc_maxlifetime', self::$config['lifetime'] == 0 ? 86400 : self::$config['lifetime']); // Create a new session $this->create(); // Write the session at shutdown register_shutdown_function(array($this, 'write_close')); // Singleton instance self::$instance[$group] = $this; } }
/** * Sets up the database configuration, loads the Database_Driver. * * @throws KoException */ public function __construct($config = array()) { if (empty($config)) { $config = Ko::config('database.default'); } elseif (is_string($config)) { $name = $config; if (($config = Ko::config('database.' . $config)) === NULL) { throw new KoException('database.undefined_group :group', array(':group' => $name)); } } // Merge the default config with the passed config $this->_config = array_merge($this->_config, $config); $driver = 'Database_' . ucfirst($this->_config['type']); if (!Ko::autoload($driver)) { throw new KoException('core.driver_not_found :error', array(':error' => $this->_config['type'] . get_class($this))); } $this->_driver = new $driver($this->_config); if (!$this->_driver instanceof Database_Driver) { throw new KoException('core.driver_implements :error', array(':error' => $this->_config['type'] . get_class($this) . 'Database_Driver')); } }
private function _auth($reverse = FALSE) { static $backup = array(); $keys = array('auth_user', 'auth_pass'); foreach ($keys as $key) { if ($reverse) { if (isset($backup[$key])) { $_SERVER[$key] = $backup[$key]; unset($backup[$key]); } else { unset($_SERVER[$key]); } } else { $value = getenv($key); if (!empty($value)) { $backup[$key] = $value; } $_SERVER[$key] = Ko::config('cache')->xcache[$key]; } } }
/** * Constructs a new Captcha object. * * @throws KoException * @param string config group name * @return void */ public function __construct($config = NULL) { if (empty($config)) { $config = Ko::config('captcha.default'); } elseif (is_string($config)) { if (($config = Ko::config('captcha.' . $config)) === NULL) { throw new KoException('captcha.undefined_group :group', array(':group' => $config)); } } $config_default = Ko::config('captcha.default'); // Merge the default config with the passed config self::$config = array_merge($config_default, $config); // 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 KoException('captcha.file_not_found :background', array(':background' => 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 KoException('captcha.file_not_found :font', array(':font' => self::$config['fontpath'] . $font)); } } } // Set driver name $driver = 'Captcha_' . ucfirst($config['style']); // Load the driver if (!Ko::autoload($driver)) { throw new KoException('core.driver_not_found :style', array(':style' => $driver)); } $this->driver = new $driver(); // Validate the driver if (!$this->driver instanceof Captcha_Driver) { throw new KoException('core.driver_implements :driver', array(':driver' => $config['style'])); } }
/** * Captures the output that is generated when a view is included. * The view data will be extracted to make local variables. This method * is static to prevent object scope resolution. * * @param string filename * @return string */ public function capture($filename = NULL, $display = FALSE) { if ($filename !== NULL) { $this->setView($filename); } if (empty($this->_file)) { throw new Exception('You must set the file to use within your view before rendering'); } // Check && get the file's realpath $type = Ko::config('smarty.templates_ext') or $type = 'tpl'; if (($filepath = Ko::findFile('views', $this->_file, $type)) === FALSE) { throw new KoException('The requested view :file could not be found', array(':file' => $this->_file . '.' . $type)); } return $this->_smarty->fetch($filepath, NULL, NULL, $display); }
/** * 初始化用户地块信息 */ public function initUserMapData() { $initMap = array(); $initMap = (array) Ko::config('initmap'); if (empty($initMap)) { return; } $map = new MapModel(); // 使用AS脚本里生成的代码,放到initmap类里,然后判断是否有start_time, foreach ($initMap as $key => $value) { //@todo 临时加入start_time $model = new StoreModel($this->lang); if (isset($initMap[$key]['start_time'])) { // 如果有start_time的话,那么就是作物,计算一下成熟的时间即可 $item_id = $initMap[$key]['id']; $item = $model->getStoreById($item_id); if ($item && isset($item->collect_in)) { $initMap[$key]['start_time'] = $this->timestamp - $item->collect_in; } } } foreach ($initMap as $map_item) { $map->add(array('uid' => $this->uid, 'itemid' => isset($map_item['id']) ? $map_item['id'] : 0, 'map_x' => isset($map_item['x']) ? $map_item['x'] : 0, 'map_y' => isset($map_item['y']) ? $map_item['y'] : 0, 'flipped' => isset($map_item['flipped']) ? $map_item['flipped'] : 0, 'products' => isset($map_item['products']) ? $map_item['products'] : 0, 'start_time' => isset($map_item['start_time']) ? $map_item['start_time'] : 0, 'times_used' => isset($map_item['times_used']) ? $map_item['times_used'] : 0)); } //输出转对象数组 foreach ($initMap as $key => $value) { $initMap[$key] = (object) $value; } return $initMap; }
/** * Sends the response status and all set headers. * * @return Request */ public function sendHeaders() { if (!headers_sent()) { foreach ($this->headers as $name => $value) { if (is_string($name)) { $value = "{$name}: {$value}"; } header($value, TRUE, $this->status); } if ($this->status) { $errRequest = Ko::config('request'); header($errRequest[$this->status], TRUE, $this->status); unset($errRequest); } } return $this; }
/** * Return the mime type of an extension. * * @param string extension: php, pdf, txt, etc * @return string mime type on success * @return FALSE on failure */ public static function mime_by_ext($extension) { // Load all of the mime types $mimes = Ko::config('mimes'); return isset($mimes[$extension]) ? $mimes[$extension][0] : FALSE; }