コード例 #1
0
ファイル: Vbulletin.php プロジェクト: laiello/crindigan
    /**
     * Creates a new user record on the local database, if it doesn't exist.
     *
     * @param  array $user
     */
    protected function _createLocalRecord(array $user)
    {
        $db = RPG::database();
        $existing = $db->query('SELECT user_id FROM {user}
								WHERE user_external_id = :0', $user['userid']);
        if ($existing->getNumRows() > 0) {
            $userId = $existing->fetchOne();
        } else {
            /* TODO: this should replace the raw insert()
            			
            			$obj = RPG::model('user')->getObject();
            			$obj->user_name = htmlspecialchars_decode($user['username'], ENT_COMPAT);
            			$obj->user_email = $user['email'];
            			$obj->user_external_id = $user['userid'];
            			RPG::model('user')->insert($obj);
            			*/
            $userId = $db->insert('user', array('user_name' => htmlspecialchars_decode($user['username'], ENT_COMPAT), 'user_password' => '', 'user_salt' => RPG::model('user')->generateSalt(5), 'user_email' => $user['email'], 'user_autologin' => '', 'user_autologin_time' => 0, 'user_money' => 0, 'user_external_id' => $user['userid'], 'user_joindate' => RPG_NOW));
        }
        return $userId;
    }
コード例 #2
0
ファイル: news.php プロジェクト: laiello/crindigan
 /**
  * Fetches a set of entries, given a series of options.
  *
  * - getBody: Will fetch the body of each entry (true)
  * - getUser: Will fetch the author name (true)
  * - limit:   Max number of entries to fetch (5)
  * - offset:  Number to start fetching entries (0)
  * - where:   Optional where clause (array())
  * - order:   How to order the result (array('news_time' => 'DESC'))
  *
  * @param  array $options List of options.
  * @return array News entries referenced by news_id.
  */
 public function getEntries(array $options = array())
 {
     $default = array('getBody' => true, 'getUser' => true, 'limit' => 5, 'offset' => 0, 'where' => array(), 'order' => array('news_time' => 'DESC'));
     $options = array_merge($default, $options);
     $select = RPG::database()->select('news')->addColumns('news_id', 'news_author', 'news_title', 'news_time');
     if ($options['getBody']) {
         $select->addColumns('news_body');
     }
     if ($options['getUser']) {
         $select->addColumns('user_name')->addLeftJoin('user', 'user_id = news_author');
     }
     if ($options['where']) {
         // first element is condition, and the rest are bind params
         $where = array_shift($options['where']);
         $select->addWhere($where);
         $select->setBind($options['where']);
     }
     $select->setOrderBy($options['order'])->setLimit($options['limit'], $options['offset']);
     return $select->execute()->fetchMapped('news_id');
 }
コード例 #3
0
ファイル: Session.php プロジェクト: laiello/crindigan
 /**
  * Cleans up sessions older than $maxLifetime seconds.
  *
  * @param  int $maxLifetime
  * @return bool
  */
 public function gc($maxLifetime)
 {
     RPG::database()->delete('session', array('session_time < :0', RPG_NOW - $maxLifetime));
     return true;
 }
コード例 #4
0
ファイル: hello.php プロジェクト: laiello/crindigan
 public function doDelete($key)
 {
     $db = RPG::database();
     $db->delete('hello', array('hello_key = :0', $key));
 }
コード例 #5
0
ファイル: user.php プロジェクト: laiello/crindigan
 public function updateAutoLogin($userId, $key = '', $time = 0)
 {
     $affected = RPG::database()->update('user', array('user_autologin' => $key, 'user_autologin_time' => $time), array('user_id = :0', $userId));
 }
コード例 #6
0
ファイル: Select.php プロジェクト: laiello/crindigan
 /**
  * Creates the SQL and executes the query.
  *
  * @return RPG_Database_Result
  */
 public function execute()
 {
     return RPG::database()->query($this->getSql(), $this->_bind);
 }
コード例 #7
0
ファイル: Hybrid.php プロジェクト: laiello/crindigan
    /**
     * Removes all expired session records from the database along with their
     * corresponding temporary files.
     *
     * @param  int $maxLifetime
     * @return bool
     */
    public function gc($maxLifetime)
    {
        $cut = RPG_NOW - $maxLifetime;
        $set = RPG::database()->queryAll('SELECT session_id FROM {session_memory}
										  WHERE session_time < :0', $cut);
        RPG::database()->delete('session_memory', array('session_time < :0', $cut));
        foreach ($set as $row) {
            $file = $this->_getFile($row['session_id']);
            if (file_exists($file)) {
                unlink($file);
            }
        }
        return true;
    }