Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to CodeIgniter 3.X #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

//Please change to your installation folder, with a trailing / (slash)
$config['base_url'] = 'http://localhost/';
$config['base_url'] = 'http://localhost/hunt/Treasure-Hunt/';

/*
|--------------------------------------------------------------------------
Expand All @@ -29,7 +29,7 @@
|
*/
// $config['index_page'] = 'index.php';
$config['index_page'] = '';
$config['index_page'] = 'index.php';

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -252,11 +252,12 @@
| 'sess_time_to_update' = how many seconds between CI refreshing Session Information
|
*/

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
Expand Down
10 changes: 5 additions & 5 deletions application/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@
*/

$active_group = 'default';
$active_record = TRUE;
$query_builder = TRUE;

//database details - change these to the correct values
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['username'] = 'treasure_user';
$db['default']['password'] = 'treasure_password';
$db['default']['database'] = 'treasurehunt';


//standard CI database details
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function login() {
'role' => $role
));

redirect(base_url(), 'location');
redirect(site_url('login'));
}else{
//0 was returned. could be some error with Facebook API
//return to home page, and let the user try logging in again, after logging out
Expand All @@ -110,7 +110,7 @@ public function login() {
}else{
$facebook = $this->facebook->instance->getRedirectLoginHelper();
$permissions = ['email'];
$loginUrl = $facebook->getLoginUrl(base_url().'login', $permissions);
$loginUrl = $facebook->getLoginUrl(site_url('login'), $permissions);

//redirect to Facebook to authenticate
redirect($loginUrl);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class nimda extends CI_Controller {
class Nimda extends CI_Controller {

function __construct() {
parent::__construct();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class admin_model extends CI_Model {
class Admin_model extends CI_Model {
function get_stats(){
//retrieve basic stats

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class levels_model extends CI_Model {
class Levels_model extends CI_Model {

function get_level() {
//get level for the current user
Expand Down Expand Up @@ -76,8 +76,8 @@ function check_answer($answer){
'fb_uid' => $fb_uid,
'fb_name' => $fb_name,
'level' => $current_level,
'answer' => mysql_real_escape_string($answer),
'ip' => mysql_real_escape_string($_SERVER['REMOTE_ADDR'])
'answer' => $this->db->escape($answer),
'ip' => $this->db->escape($_SERVER['REMOTE_ADDR'])
);
$this->db->insert('log_answers',$log);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class status_model extends CI_Model {
class Status_model extends CI_Model {

function get_leaderboard(){
//prepare a leaderboard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class user_model extends CI_Model {
class User_model extends CI_Model {

/*Note:
Roles are used to easily separate admins without duplicating code.
Expand Down
20 changes: 10 additions & 10 deletions application/views/includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<?php if($this->session->userdata('is_logged_in')==TRUE) { ?>
<li <?=$active['arena']?>><a href="<?=base_url();?>">Arena</a></li>
<li <?=$active['arena']?>><a href="<?=site_url();?>">Arena</a></li>
<?php } ?>
<li <?=$active['rules']?>><a href="<?=base_url();?>rules">Rules</a></li>
<li <?=$active['leaderboard']?>><a href="<?=base_url();?>leaderboard">Leaderboard</a></li>
<li <?=$active['winners']?>><a href="<?=base_url();?>winners">Winners</a></li>
<li <?=$active['rules']?>><a href="<?=site_url('rules');?>">Rules</a></li>
<li <?=$active['leaderboard']?>><a href="<?=site_url('leaderboard');?>">Leaderboard</a></li>
<li <?=$active['winners']?>><a href="<?=site_url('winners');?>">Winners</a></li>


<?php if($this->session->userdata('role')>=2) { ?>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin Panel <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="<?=base_url();?>nimda">Home</a></li>
<li><a href="<?=base_url();?>nimda/levels">Levels</a></li>
<li><a href="<?=base_url();?>nimda/users">Users</a></li>
<li><a href="<?=site_url('nimda');?>">Home</a></li>
<li><a href="<?=site_url('nimda/levels');?>">Levels</a></li>
<li><a href="<?=site_url('nimda/users');?>">Users</a></li>
</ul>
</li>
<?php } ?>
Expand All @@ -115,16 +115,16 @@
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if($this->session->userdata('is_logged_in')!=TRUE) { ?>
<li><a href="<?=base_url();?>login">Login</a></li>
<li><a href="<?=site_url('login');?>">Login</a></li>
<?php }else { ?>
<li><a href="http://www.facebook.com/clueless.tathva" target="_blank">Clues</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><?=$this->session->userdata('fb_name')?> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="<?=base_url();?>profile">Profile</a></li>
<li><a href="<?=site_url('profile');?>">Profile</a></li>
<li class="divider"></li>
<li class="dropdown-header"><?=$this->session->userdata('fb_name')?></li>
<li><a href="<?=base_url();?>logout">Log-out</a></li>
<li><a href="<?=site_url('logout');?>">Log-out</a></li>
</ul>
</li>
<?php } ?>
Expand Down
4 changes: 2 additions & 2 deletions application/views/pages/answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
if($result == true){
echo '<h1><span class="text-success">CORRECT</span></h1>';
echo '<br><img src="/levels/'.$image.'"/><br><br>';
echo '<br><p><a class="btn btn-lg btn-success" href="'.base_url().'">Next Level <i class="glyphicon glyphicon-chevron-right"></i></a></p>';
echo '<br><p><a class="btn btn-lg btn-success" href="'.site_url().'">Next Level <i class="glyphicon glyphicon-chevron-right"></i></a></p>';

}else{
echo '<h1><span class="text-danger">WRONG</span></h1>';
echo '<br><p><a class="btn btn-lg btn-danger" href="'.base_url().'">Try Again <i class="glyphicon glyphicon-chevron-left"></i></a></p>';
echo '<br><p><a class="btn btn-lg btn-danger" href="'.site_url().'">Try Again <i class="glyphicon glyphicon-chevron-left"></i></a></p>';
}
?>
</div>
Expand Down
6 changes: 3 additions & 3 deletions application/views/pages/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<br><br>
<p>An exciting online treasure hunt</p>
<h3>Start playing, and think harder!</h3>
<p><a class="btn btn-primary btn-lg" href="<?=base_url()?>login">Login with Facebook <i class="glyphicon glyphicon-log-in"></i></a></p>
<p><a class="btn btn-primary btn-lg" href="<?=site_url('login')?>">Login with Facebook <i class="glyphicon glyphicon-log-in"></i></a></p>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-4">
<h2>Leaderboard</h2>
<p>Keep track of your competitors.</p>
<p><a class="btn btn-default" href="<?=base_url()?>leaderboard">View Leaderboard »</a></p>
<p><a class="btn btn-default" href="<?=site_url('leaderboard')?>">View Leaderboard »</a></p>
</div>
<div class="col-lg-4">
<h2>Winners</h2>
<p>The determined ones.</p>
<p><a class="btn btn-default" href="<?=base_url()?>winners">Winners »</a></p>
<p><a class="btn btn-default" href="<?=site_url('winners')?>">Winners »</a></p>
</div>
<div class="col-lg-4">
<h2>Tathva</h2>
Expand Down
4 changes: 2 additions & 2 deletions application/views/pages/wait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<div class="col-lg-4">
<h2>Leaderboard</h2>
<p>Keep track of your competitors.</p>
<p><a class="btn btn-default" href="<?=base_url()?>leaderboard">View Leaderboard »</a></p>
<p><a class="btn btn-default" href="<?=site_url('leaderboard')?>">View Leaderboard »</a></p>
</div>
<div class="col-lg-4">
<h2>Winners</h2>
<p>The determined ones.</p>
<p><a class="btn btn-default" href="<?=base_url()?>winners">Winners »</a></p>
<p><a class="btn btn-default" href="<?=site_url('winners')?>">Winners »</a></p>
</div>
<div class="col-lg-4">
<h2>Tathva</h2>
Expand Down
10 changes: 5 additions & 5 deletions tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ CREATE TABLE IF NOT EXISTS `users` (


CREATE TABLE IF NOT EXISTS `ci_sessions` (
`session_id` varchar(40) NOT NULL DEFAULT '0',
`id` varchar(40) NOT NULL DEFAULT '0',
`ip_address` varchar(45) NOT NULL DEFAULT '0',
`user_agent` varchar(120) NOT NULL,
`last_activity` int(10) unsigned NOT NULL DEFAULT '0',
`user_data` text NOT NULL,
PRIMARY KEY (`session_id`),
KEY `last_activity_idx` (`last_activity`)
`timestamp` int(10) unsigned NOT NULL DEFAULT 0,
`data` blob NOT NULL,
PRIMARY KEY (`id`),
KEY `last_activity_idx` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Expand Down