/** * Initializes the user, setting them up as a member or guest, and * checking for automatic logins. * * @param RPG_Model $model Instance of a user model. * @param RPG_Session $session Instance of session class. * @param RPG_Input $input Instance of input class. */ public function __construct($model = null, $session = null, $input = null) { if ($model === null) { $model = RPG::model('user'); } if ($session === null) { $session = RPG::session(); } if ($input === null) { $input = RPG::input(); } $this->_model = $model; $this->_session = $session; $this->_input = $input; // try to see if we're logged in according to the session if ($this->isLoggedIn()) { // setup registered user $this->setupMember(); } else { if (!$this->_attemptAutoLogin()) { // if auto-login failed, we're a guest $this->setupGuest(); } } }
/** * Displays the main frontend dashboard. Contains latest news entries * along with miscellaneous/important information in the sidebar. */ public function doIndex() { $t = RPG::template('home/index.php'); $t->newsEntries = RPG::model('news')->getEntries(array('where' => array('news_time <= :0', RPG_NOW))); // characters, squads, money, active battles // not finalized, some could be injected right in the template itself $t->characters = 5; $t->maxCharacters = 16; $t->squads = 3; $t->maxSquads = 8; $t->money = 17338; $t->moneyName = 'Aurum'; $t->activeBattles = 'N/A'; RPG::view()->setNavCurrent('home', 'home')->setTitle('RPG Home')->setContent($t); }
/** * 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; }
set_error_handler(array('RPG', 'handlePhpError')); // Default configuration items $defaultConfig = array('modelPath' => RPG_ROOT . '/models', 'viewPath' => RPG_ROOT . '/views', 'controllerPath' => RPG_ROOT . '/controllers', 'cachePath' => RPG_ROOT . '/cache', 'tmpPath' => RPG_ROOT . '/tmp', 'sessionPath' => RPG_ROOT . '/tmp/sessions', 'objectsPath' => RPG_ROOT . '/cache/objects'); // Override defaults if needed $config = array_merge($defaultConfig, $config); // // Start the main execution! // Top-level try/catch block for a last-ditch effort error page. // try { // Initialize the system RPG::setConfig($config); RPG_Template::setPath($config['viewPath']); RPG_Model::setPath($config['modelPath']); RPG::session(); RPG::user(RPG::model('user')); // add this now, so controllers can include CSS that overrides defaults RPG::view()->addStyleSheet('media/styles/light.css'); // Process the request RPG::router($config['controllerPath'])->processRequest(); // stop the timer - needs to be here so it can get rendered via templates RPG::debug('Execution Time (pre-render): ' . round(microtime(true) - RPG::get('__debug_time'), 4)); // Render the output - TODO: handle styles differently later RPG::view()->render(); } catch (RPG_Exception $ex) { // Basic error page echo '<html> <head> <title>Application Error</title> <style type="text/css"> body { font-family: sans-serif; }