Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
4 changes: 2 additions & 2 deletions application/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array();
$autoload['libraries'] = array('session', 'database');

/*
| -------------------------------------------------------------------
Expand Down Expand Up @@ -89,7 +89,7 @@
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array();
$autoload['helper'] = array('url', 'file', 'form');

/*
| -------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = '';
$config['base_url'] = 'http://localhost/vietgram/';

/*
|--------------------------------------------------------------------------
Expand All @@ -35,7 +35,7 @@
| variable so that it is blank.
|
*/
$config['index_page'] = 'index.php';
$config['index_page'] = '';

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions application/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => '',
'username' => 'root',
'password' => '',
'database' => '',
'database' => 'vietgram',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
Expand Down
2 changes: 1 addition & 1 deletion application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'welcome';
$route['default_controller'] = 'C_Login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
88 changes: 88 additions & 0 deletions application/controllers/C_EditProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class C_EditProfile extends CI_Controller {


public function __construct() {
parent::__construct();
$this->load->model("M_User");

}

public function index() {
$data['profile'] = $this->M_User->loadProfile($this->session->userdata("username"));
$this->load->view("edit-profile", $data);

}

public function login() {

$username = $this->input->post("username");
$password = $this->input->post("password");

$check = $this->M_User->login($username, $password);
if ($check) {
$this->session->set_userdata("username", $username);
redirect('C_Feed');
}else {

$message = "username or password is wrong";
$this->session->set_flashdata('message', $message);
$this->load->view("index");
}
}

public function editProfpic() {
$config['upload_path'] = './assets/images/';
$config['allowed_types'] = 'gif|jpg|png';


$this->load->library('upload', $config);

if ($this->upload->do_upload('image')) {
$profpic = base_url().'/assets/images/'.$this->upload->data('file_name');

$this->M_User->editProfpic($profpic, $this->session->userdata("username"));
redirect("C_EditProfile", 'refresh');
}else {
$error['error'] = $this->upload->display_errors();
echo $error['error'];
}


}

public function editProfile() {

$name = $this->input->post("name");
$username = $this->input->post("username");
$website = $this->input->post("website");
$bio = $this->input->post("bio");
$email = $this->input->post("email");
$phonenumber = $this->input->post("phonenumber");
$gender = $this->input->post("gender");


$data = array (
'name' => $name,
'website' => $website,
'bio' => $bio,
'email' => $email,
'phonenumber' => $phonenumber,
'gender' => $gender,

);

$this->M_User->updateProfile((object) $data, $this->session->userdata("username"));

if ($this->session->userdata("username") != $username) {
$this->M_User->updateUsername($username, $this->session->userdata("username"));
$this->session->set_userdata("username", $username);

}

redirect('C_Profile');

}

}
57 changes: 57 additions & 0 deletions application/controllers/C_Feed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class C_Feed extends CI_Controller {


public function __construct() {
parent::__construct();
$this->load->model("M_User");
$this->load->model("M_Photos");
}

public function index() {
$data['photos'] = $this->M_Photos->getFeedData();
$this->load->view("feed", $data);

}

public function searchCaption() {
$data['photos'] = $this->M_Photos->search($this->input->get('searchkey'));
$this->load->view("feed", $data);


}


public function upload() {
$config['upload_path'] = './assets/images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$config['max_width'] = 1920;
$config['max_height'] = 1080;

$this->load->library('upload', $config);

if ($this->upload->do_upload('image')) {

$data = array(
'idUser' => $this->session->userdata('userID'),
'url' => base_url().'assets/images/'.$this->upload->data('file_name'),
'caption' => $this->input->post('caption'),
'likes' => 0
);

$this->M_Photos->upload($data);


redirect('C_Feed');
}else {
$error = $this->upload->display_errors();
$this->session->set_flashdata('message', $error);
redirect('C_Feed');

}
}


}
37 changes: 37 additions & 0 deletions application/controllers/C_Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class C_Login extends CI_Controller {


public function __construct() {
parent::__construct();
$this->load->model("M_User");
}

public function index() {
$this->load->view("index");

}

public function login() {

$username = $this->input->post("username");
$password = $this->input->post("password");

$check = $this->M_User->login($username, $password);
if ($check) {
$id = $this->M_User->getUserID($username);
$this->session->set_userdata("userID", $id->idUser);
$this->session->set_userdata("username", $username);
redirect('C_Feed');
}else {

$message = "username or password is wrong";
$this->session->set_flashdata('message', $message);
$this->load->view("index");
}


}

}
18 changes: 18 additions & 0 deletions application/controllers/C_Navigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class C_Navigation extends CI_Controller {


public function __construct() {
parent::__construct();
$this->load->model("M_User");
}

public function index() {
$this->load->view("explore");

}



}
23 changes: 23 additions & 0 deletions application/controllers/C_Profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class C_Profile extends CI_Controller {


public function __construct() {
parent::__construct();
$this->load->model("M_User");
$this->load->model("M_Photos");
}

public function index() {
$data['uploads'] = $this->M_User->userUploads($this->session->userdata('username'));
$data['profile'] = $this->M_User->loadProfile($this->session->userdata('username'));
$this->load->view("profile", $data);

}





}
25 changes: 25 additions & 0 deletions application/models/M_Photos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class M_Photos extends CI_Model {

public function getFeedData() {
$query = $this->db->query('SELECT user.username, photos.likes, url, caption, profpic FROM photos join profile JOIN user;');
return $query->result();
}

public function upload($data){
$this->db->insert("photos", $data);
}

public function search($searchkey) {
$qr = 'SELECT user.username, photos.likes, url, caption, profpic FROM photos join profile JOIN user WHERE caption LIKE "%'.$searchkey.'%"';
$query = $this->db->query($qr);
return $query->result();
}



}


?>
60 changes: 60 additions & 0 deletions application/models/M_User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

class M_User extends CI_Model {



public function login($username, $password) {
$this->db->like('username', $username);
$this->db->like('password', $password);
$query = $this->db->get('user');
if ($query->row() != NULL) {
return true;
}else {
return false;
}
}

public function getUserID($username) {
$query = $this->db->query("SELECT idUser FROM user where username LIKE '$username'");
return $query->row();
}

public function loadProfile($username) {
$query = $this->db->query("SELECT * FROM profile WHERE username LIKE '$username'");
return $query->row();
}

public function userUploads($idUser) {
$query = $this->db->query("SELECT * FROM photos WHERE idUser LIKE '$idUser'");
return $query->result();
}

public function updateProfile($data, $username) {
$query = $this->db->query("
UPDATE profile
SET
name = '$data->name',
website = '$data->website',
bio = '$data->bio',
email = '$data->email',
phonenumber = '$data->phonenumber',
gender = '$data->gender'
WHERE username = '$username'

");
}

public function updateUsername($username, $us) {
$query = $this->db->query("UPDATE user SET username = '$username' WHERE username = '$us'");
}

public function editProfpic($profpic, $username) {
$query = $this->db->query("UPDATE profile SET profpic = '$profpic' WHERE username = '$username'");
}


}


?>
Loading