Example #1
0
 /**
  * Get the settings from config.
  */
 public function __construct()
 {
     parent::__construct();
     $this->before_create[] = 'created_at';
     $this->before_create[] = 'updated_at';
     $this->before_update[] = 'updated_at';
     $enabled = $this->config->item('autologin_enabled');
     $this->enabled = !empty($enabled) && !is_cli();
     $database_table_name = $this->config->item('autologin_database_table_name');
     if ($database_table_name != '') {
         $this->_table = $database_table_name;
     }
     $cookie_name = $this->config->item('autologin_cookie_name');
     if ($cookie_name != '') {
         $this->cookie_name = $cookie_name;
     }
     $expiration_time = (int) $this->config->item('autologin_expiration_time');
     if ($expiration_time > 0) {
         $this->expiration_time = $expiration_time;
     }
     $hash_algorithm = $this->config->item('autologin_hash_algorithm');
     if ($hash_algorithm != '') {
         $this->hash_algorithm = $hash_algorithm;
     }
     // Make sure that $this->encryption_key is not empty!
     // Set in your configuration the corresponding encryption keys!
     $this->encryption_key = $this->config->item('encryption_key_for_autologin');
     if ($this->encryption_key == '') {
         $this->encryption_key = $this->config->item('encryption_key');
     }
     $automatic_purge = $this->config->item('autologin_automatic_purge');
     $this->automatic_purge = !empty($automatic_purge);
 }
 public function settingAction()
 {
     $settingModel = Core_Model::factory('System_Model_Setting');
     $options = array();
     $settings = $settingModel->find_many();
     foreach ($settings as $setting) {
         $options[$setting->name] = trim($setting->value);
     }
     if ($this->isPost()) {
         $sql = array();
         $params = array();
         $options = array_merge($options, $this->_request['params']);
         // Update settings
         $sql[] = 'UPDATE ' . $settingModel->getTableName() . ' SET value = CASE';
         foreach (array_keys($options) as $key) {
             $sql[] = " WHEN name='{$key}' THEN :{$key}";
             $params["{$key}"] = trim($this->_request['params'][$key]);
         }
         $sql[] = ' END';
         $settingModel->raw_execute(implode('', $sql), $params);
         // Write cache
         $this->_cache['db']->save($options, 'db_settings');
         $this->view->success = 'Change settings successfully';
     }
     $this->view->options = $options;
 }
Example #3
0
 public function __construct()
 {
     parent::__construct();
     $this->before_create[] = 'created_at';
     $this->before_create[] = 'updated_at';
     $this->before_update[] = 'updated_at';
 }
 public function init()
 {
     parent::init();
     $this->postModel = Core_Model::factory('Post_Model_Post');
     // Get all categories
     $categoryModel = Core_Model::factory('Category_Model_Category');
     $this->view->subcategories = array_filter($categoryModel->find_many(), create_function('$obj', 'return $obj->id_parent != 0;'));
 }
Example #5
0
 public static function checkAuth($username, $password)
 {
     $userModel = Core_Model::factory('User_Model_User');
     $user = $userModel->where_equal('username', $username)->find_one();
     if ($user) {
         return $user->password == sha1($user->salt . $password) ? $user : false;
     }
     return false;
 }
Example #6
0
 public static function connectDb()
 {
     if (!self::$_mysql) {
         $db_config = C('db');
         self::$_mysql = new PdoMysql();
         self::$_mysql->setAuth($db_config['username'], $db_config['password']);
         // [ read / write ] host
         self::$_mysql->setHost($db_config['r_host'], $db_config['w_host']);
         self::$_mysql->setPort($db_config['port']);
         self::$_mysql->setAppname($db_config['dbname']);
         self::$_mysql->setCharset($db_config['charset']);
     }
 }
Example #7
0
 public function __construct()
 {
     parent::__construct();
     $this->load->config('users');
     $this->load->helper('current_user');
     $this->user_id_getter = 'user_id_getter_for_models';
     $this->before_create[] = 'created_at';
     $this->before_create[] = 'created_by';
     $this->before_create[] = 'updated_at';
     $this->before_create[] = 'updated_by';
     $this->before_update[] = 'updated_at';
     $this->before_update[] = 'updated_by';
     $this->before_delete[] = 'deleted_at';
     $this->before_delete[] = 'deleted_by';
     $this->before_create[] = 'store_password';
     $this->before_update[] = 'store_password';
 }
 public static function run()
 {
     error_reporting(C('error_reporting'));
     session_start();
     date_default_timezone_set(C('date_timezone'));
     register_shutdown_function(array('Core_Exception', 'handleFatalError'));
     set_error_handler(array('Core_Exception', 'handleError'));
     set_exception_handler(array('Core_Exception', 'handleException'));
     // If already slashed, strip it
     if (get_magic_quotes_gpc()) {
         $_GET = stripslashes_deep($_GET);
         $_POST = stripslashes_deep($_POST);
         $_COOKIE = stripslashes_deep($_COOKIE);
     }
     // 链接数据库
     Core_Model::connectDb();
     $controller_class_name = 'Controller_' . str_replace('/', '_', CONTROLLER_NAME);
     $method_name = ACTION_NAME . 'Action';
     $controller = new $controller_class_name();
     // 禁止直接调用基类Core_Controller的方法
     if (in_array($method_name, get_class_methods('Core_Controller'))) {
         throw new Core_Exception("Method '{$method_name}' access denied");
     }
     // Controller 不存在
     if (!$controller) {
         throw new Core_Exception("Fail to new {$controller_class_name} object");
     }
     // 给cli 模式下来个起始换行 = =!
     IS_CLI && (print "\n");
     // 页面缓存 [ CLI 模式不缓存 ]
     IS_CLI || ob_start();
     // 执行操作
     call_user_func(array($controller, $method_name));
     // 页面输出 [ CLI 模式没缓存 ]
     IS_CLI || ob_end_flush();
     // 断开数据库
     Core_Model::closeDb();
     // 打印错误信息
     IS_DEBUG && Core_Exception::showErrors();
     // 给cli 模式下来个结束换行 = =!
     IS_CLI && (print "\n");
 }
 public function deleteAction()
 {
     if ($this->isAjax() && $this->isPost()) {
         $this->_noRender = true;
         $params = $this->_request['params'];
         $postModel = Core_Model::factory('Post_Model_Post');
         if ($postModel->where_raw('(`id_category` = ? OR `id_subcategory` = ?)', array($params['id'], $params['id']))->find_one()) {
             echo json_encode(array('success' => true, 'redirect' => false, 'msg' => 'This category is associated with some posts'));
         } else {
             $subCategories = array_filter($this->view->categories, create_function('$obj', 'return $obj->id_parent == ' . (int) $params['id'] . ';'));
             // Update parent of subcategories
             if ($subCategories) {
                 foreach ($subCategories as $category) {
                     $category->id_parent = 0;
                     $category->save();
                 }
             }
             $this->categoryModel->find_one($params['id'])->delete();
             echo json_encode(array('success' => true, 'redirect' => true, 'href' => $this->_router->generate('route_admin_category')));
         }
     }
 }
Example #10
0
 public function __construct()
 {
     parent::__construct();
     $this->_tableGenre = new Application_Model_DbTable_Genre();
 }
Example #11
0
 public function __construct()
 {
     parent::__construct();
     $this->_tableSubsidiary = new Application_Model_DbTable_Subsidiary();
 }
Example #12
0
 public function add(array $data, $table = false)
 {
     $data['bit_flag'] = $this->getNextFlag() * 2 > 0 ? $this->getNextFlag() * 2 : 1;
     $data['name'] = ucfirst($data['controller']) . self::$name_separator . ucfirst($data['action']);
     parent::add($data);
 }
Example #13
0
 /**
  * Set up class properties etc.
  */
 private function Setup()
 {
     // place for additional sets
     // e.g. $this->aConfig[ section_key ][ value_key ] = value
     $sAppConfigIni = DOCROOT . $this->oConfig->getValue(sprintf('applications.%s.config_file', $this->oRouter->getApplicationName()));
     $this->oConfig->loadIniFile($sAppConfigIni);
     $this->sLogsDirectory = $this->getConfig('General.Logs_directory', DOCROOT . 'logs/');
     $this->sLogsDirectory .= date('Y-m-d') . '/';
     // set main framework path
     $this->addPath('Lithium');
     // set application path received from config file
     if ($sAppPath = $this->getConfig('General.App_path')) {
         $this->addPath($sAppPath);
         Loader::addPath(DOCROOT . $sAppPath);
     }
     // add path for external classes
     Loader::addPath(DOCROOT);
     // set language
     if ($sLanguage = $this->getConfig('Locale.Language')) {
         $this->sLanguage = $sLanguage;
     }
     Core_Model::setLithium($this);
     Core_Module::setLithium($this);
     Database_Driver::setLithium($this);
     // initialize router
     $this->oRouter->init();
     View::setRouter($this->oRouter);
     Module_Sorter::setRouter($this->oRouter);
     Module_Pagination::setRouter($this->oRouter);
 }
Example #14
0
 public function __construct()
 {
     parent::__construct();
     $this->_tableCompany = new Application_Model_DbTable_Company();
 }
Example #15
0
 /**
  * @param $user_id
  * @param $user_data
  *
  * When you're accessing $_SESSION, you're not just changing the current script's copy of the data read from
  * the session, you're writing SafeString objects back into the active session.
  * But putting custom objects in the session is dodgy and something I would generally try to avoid.
  * To be able to do it you have to have defined the class in question before calling session_start;
  * if you don't, PHP's session handler won't know how to deserialise the instances of that class, and you'll
  * end up with the __PHP_Incomplete_Class Object.
  * @http://stackoverflow.com/questions/2010427/php-php-incomplete-class-object-with-my-session-data
  */
 protected static function loadNotifications($user_id, &$user_data)
 {
     if (isset($user_data['notifications'])) {
         unset($user_data['notifications']);
     }
     // Notifications
     // new notifications
     $all_notifications = Default_NotificationsModel::getAll(array('status' => Const_Notifications::STATUS_NEW, 'user_id' => $user_id));
     $user_data['notifications'] = array();
     // Prevent notice
     $user_data['notifications']['records'] = array();
     // Prevent notice
     $processed_notifications_count = 0;
     $new_notifications_item_ids = array();
     $new_notifications_count = 0;
     foreach ($all_notifications as $notification_rs) {
         if ($notification_rs['has_expire'] && strtotime($notification_rs['expire_timestamp']) < strtotime(Core_Model::getCurrentTime())) {
             continue;
         }
         $new_notifications_count++;
         $new_notifications_item_ids[$notification_rs->item_id][$notification_rs->type] = $notification_rs->item_id;
         $notification_obj = Cms_Notifications_Factory::getObj($notification_rs->type, $user_id, $notification_rs->item_id);
         if ($processed_notifications_count >= 3) {
             continue;
         }
         /* @var $notification_obj Cms_Notifications_Abstract */
         // not assiging the dibi row directly to the session ... read comment of method
         $user_data['notifications']['records'][] = array('id' => $notification_rs->id, 'user_id' => $notification_rs->user_id, 'author_id' => $notification_rs->author_id, 'item_id' => $notification_rs->item_id, 'type' => $notification_rs->type, 'status' => $notification_rs->status, 'timestamp' => $notification_rs->timestamp, 'json_data' => $notification_rs->json_data, 'text' => $notification_obj->getText());
         $processed_notifications_count++;
     }
     $user_data['notifications']['new'] = $new_notifications_count;
     // old (if any)
     $old_notifications = Default_NotificationsModel::getAll(array('status' => Const_Notifications::STATUS_READ, 'user_id' => $user_id));
     foreach ($old_notifications as $notification_rs) {
         if ($processed_notifications_count >= 3) {
             continue;
         }
         if (isset($new_notifications_item_ids[$notification_rs->item_id][$notification_rs->type])) {
             continue;
         }
         $new_notifications_item_ids[$notification_rs->item_id][$notification_rs->type] = $notification_rs->item_id;
         $notification_obj = Cms_Notifications_Factory::getObj($notification_rs->type, $user_id, $notification_rs->item_id);
         // not assiging the dibi row directly to the session ... read comment of method
         $user_data['notifications']['records'][] = array('id' => $notification_rs->id, 'user_id' => $notification_rs->user_id, 'author_id' => $notification_rs->author_id, 'item_id' => $notification_rs->item_id, 'type' => $notification_rs->type, 'status' => $notification_rs->status, 'timestamp' => $notification_rs->timestamp, 'json_data' => $notification_rs->json_data, 'text' => $notification_obj->getText());
         $processed_notifications_count++;
     }
 }
Example #16
0
 public function __construct()
 {
     parent::__construct();
 }
Example #17
0
 public function __construct()
 {
     parent::__construct();
     $this->_tableChain = new Application_Model_DbTable_Chain();
 }
Example #18
0
 public static function setDefaultAdapter($adapter)
 {
     switch ($adapter) {
         case 'sqlite':
             $options = self::$_options['sqlite'];
             Core_Resource_Db::configure("sqlite:{$options['dbfile']}", null, 'mysql');
             Core_Model::$auto_prefix_models = $options['prefix'];
             break;
         case 'mysql':
             $options = self::$_options['mysql'];
             Core_Resource_Db::configure("mysql:host={$options['host']};dbname={$options['dbname']}");
             Core_Resource_Db::configure('username', $options['username']);
             Core_Resource_Db::configure('password', $options['password']);
             Core_Resource_Db::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
             Core_Model::$auto_prefix_models = $options['prefix'];
             break;
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->clear_cache();
 }
Example #20
0
 public function __construct()
 {
     parent::__construct();
     $this->_tableBillboard = new Application_Model_DbTable_Billboard();
 }
Example #21
0
 /**
  * Constructor.
  * Establishes connection to database.
  */
 public function __construct()
 {
     parent::__construct();
     $this->db = new Mysqli_Component();
 }
Example #22
0
 public function __construct()
 {
     parent::__construct();
     $this->_tableUbigeo = new Application_Model_DbTable_Ubigeo();
 }
 public function __construct()
 {
     parent::__construct();
     if (empty($this->translations)) {
         // Autodetect fields containing translations.
         $this->translations = array_keys(array_except(array_flip($this->fields()), array($this->primary_key, $this->external_key_field, $this->lang_field)));
     }
 }
Example #24
0
 /**
  * Setter for Lithium instance
  * 
  * @param Lithium $oLithium
  */
 public static function setLithium(Lithium $oLithium)
 {
     self::$oLithium = $oLithium;
 }
Example #25
0
 /**
  *
  */
 public function __construct()
 {
     if (!isset(self::$db)) {
         self::$db = new Core_Db(cfg()->db_data['host'], cfg()->db_data['user'], cfg()->db_data['pass'], cfg()->db_data['db'], cfg()->db_data['driver']);
     }
 }