diff --git a/Tugas Vietgram 14 b/Tugas Vietgram 14 new file mode 100644 index 00000000000..db8d6a6c52a --- /dev/null +++ b/Tugas Vietgram 14 @@ -0,0 +1 @@ +Tugas Vietgram 14 diff --git a/application/config/autoload.php b/application/config/autoload.php index 7cdc9013c11..5d691f08c68 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database','session','upload','form_validation'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array(); +$autoload['helper'] = array('url','file'); /* | ------------------------------------------------------------------- diff --git a/application/config/config.php b/application/config/config.php index 782b19c74b6..2a747d57c39 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -23,7 +23,7 @@ | a PHP script and you can easily do that on your own. | */ -$config['base_url'] = ''; +$config['base_url'] = 'http://localhost/vietgrams/'; /* |-------------------------------------------------------------------------- @@ -35,7 +35,7 @@ | variable so that it is blank. | */ -$config['index_page'] = 'index.php'; +$config['index_page'] = ''; /* |-------------------------------------------------------------------------- @@ -63,8 +63,6 @@ | For more information please see the user guide: | | https://codeigniter.com/user_guide/general/urls.html -| -| Note: This option is ignored for CLI requests. */ $config['url_suffix'] = ''; @@ -88,7 +86,7 @@ | This determines which character set is used by default in various methods | that require a character set to be provided. | -| See https://secure.php.net/htmlspecialchars for a list of supported charsets. +| See http://php.net/htmlspecialchars for a list of supported charsets. | */ $config['charset'] = 'UTF-8'; @@ -133,7 +131,7 @@ | | $config['composer_autoload'] = '/path/to/vendor/autoload.php'; | -| For more information about Composer, please visit https://getcomposer.org/ +| For more information about Composer, please visit http://getcomposer.org/ | | Note: This will NOT disable or override the CodeIgniter-specific | autoloading (application/config/autoload.php) @@ -159,8 +157,6 @@ | | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! | -| Note: This option is ignored for CLI requests. -| */ $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; @@ -191,6 +187,20 @@ $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd'; +/* +|-------------------------------------------------------------------------- +| Allow $_GET array +|-------------------------------------------------------------------------- +| +| By default CodeIgniter enables access to the $_GET array. If for some +| reason you would like to disable it, set 'allow_get_array' to FALSE. +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['allow_get_array'] = TRUE; + /* |-------------------------------------------------------------------------- | Error Logging Threshold @@ -221,7 +231,7 @@ |-------------------------------------------------------------------------- | | Leave this BLANK unless you would like to set something other than the default -| application/logs/ directory. Use a full server path. +| application/logs/ directory. Use a full server path with trailing slash. | */ $config['log_path'] = ''; @@ -269,7 +279,7 @@ |-------------------------------------------------------------------------- | | Leave this BLANK unless you would like to set something other than the default -| application/views/errors/ directory. Use a full server path. +| application/views/errors/ directory. Use a full server path with trailing slash. | */ $config['error_views_path'] = ''; @@ -280,7 +290,7 @@ |-------------------------------------------------------------------------- | | Leave this BLANK unless you would like to set something other than the default -| application/cache/ directory. Use a full server path. +| application/cache/ directory. Use a full server path with trailing slash. | */ $config['cache_path'] = ''; @@ -396,6 +406,34 @@ $config['cookie_secure'] = FALSE; $config['cookie_httponly'] = FALSE; +/* +|-------------------------------------------------------------------------- +| Standardize newlines +|-------------------------------------------------------------------------- +| +| Determines whether to standardize newline characters in input data, +| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value. +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['standardize_newlines'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Global XSS Filtering +|-------------------------------------------------------------------------- +| +| Determines whether the XSS filter is always active when GET, POST or +| COOKIE data is encountered +| +| WARNING: This feature is DEPRECATED and currently available only +| for backwards compatibility purposes! +| +*/ +$config['global_xss_filtering'] = FALSE; + /* |-------------------------------------------------------------------------- | Cross Site Request Forgery @@ -452,6 +490,20 @@ */ $config['time_reference'] = 'local'; +/* +|-------------------------------------------------------------------------- +| Rewrite PHP Short Tags +|-------------------------------------------------------------------------- +| +| If your PHP installation does not have short tag support enabled CI +| can rewrite the tags on-the-fly, enabling you to utilize that syntax +| in your view files. Options are TRUE or FALSE (boolean) +| +| Note: You need to have eval() enabled for this to work. +| +*/ +$config['rewrite_short_tags'] = FALSE; + /* |-------------------------------------------------------------------------- | Reverse Proxy IPs diff --git a/application/config/database.php b/application/config/database.php index 77748959f9f..526c26d97cb 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -22,7 +22,7 @@ | ['dbdriver'] The database driver. e.g.: mysqli. | Currently supported: | cubrid, ibase, mssql, mysql, mysqli, oci8, -| odbc, pdo, postgre, sqlite3, sqlsrv +| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv | ['dbprefix'] You can add an optional prefix, which will be added | to the table name when using the Query Builder class | ['pconnect'] TRUE/FALSE - Whether to use a persistent connection @@ -76,9 +76,9 @@ $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', - 'username' => '', + 'username' => 'root', 'password' => '', - 'database' => '', + 'database' => 'vietgram', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, diff --git a/application/config/routes.php b/application/config/routes.php index 8ebf62bfa43..52f802e89ff 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -43,12 +43,12 @@ | This is not exactly a route, but allows you to automatically route | controller and method names that contain dashes. '-' isn't a valid | class or method name character, so it requires translation. -| When you set this option to TRUE, it will replace ALL dashes with -| underscores in the controller and method URI segments. +| When you set this option to TRUE, it will replace ALL dashes in the +| controller and method URI segments. | | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ -$route['default_controller'] = 'welcome'; +$route['default_controller'] = 'login_c'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; diff --git a/application/controllers/explore_c.php b/application/controllers/explore_c.php new file mode 100644 index 00000000000..4a5037002ec --- /dev/null +++ b/application/controllers/explore_c.php @@ -0,0 +1,20 @@ +load->model('vietgram_m'); + } + + public function index() + { + $data['title'] = 'Explore | Vietgram'; + $user = $this->session->userdata('user'); + $data['friends'] = $this->vietgram_m->getExplore($user['username']); + $this->load->view('header',$data); + $this->load->view('explore_v',$data); + $this->load->view('footer'); + } +} \ No newline at end of file diff --git a/application/controllers/feed_c.php b/application/controllers/feed_c.php new file mode 100644 index 00000000000..54bb4a13e7d --- /dev/null +++ b/application/controllers/feed_c.php @@ -0,0 +1,22 @@ +load->model('vietgram_m'); + $this->load->model('vietgram_m'); + } + + public function index() + { + $data['title'] = 'Feed | Vietgram'; + $data['feed'] = $this->vietgram_m->getAllFeed(); + $data['comments'] = $this->vietgram_m->getAllComments(); + + $this->load->view('header',$data); + $this->load->view('feed_v',$data); + $this->load->view('footer'); + } +} diff --git a/application/controllers/login_c.php b/application/controllers/login_c.php new file mode 100644 index 00000000000..09047b6c107 --- /dev/null +++ b/application/controllers/login_c.php @@ -0,0 +1,37 @@ +load->model('vietgram_m'); + $this->load->library('session'); + } + + public function index() + { + $this->load->view('login_v'); + } + + public function login() + { + $this->form_validation->set_rules('username', 'username', 'required'); + $this->form_validation->set_rules('password', 'password', 'required'); + + if ($this->form_validation->run() == false) { + redirect('login_c'); + } else { + $username = $this->input->post('username',true); + $pass = $this->input->post('password',true); + $data = $this->vietgram_m->cek_login($username,$password); + if (count($data) == 1) { + $this->session->set_userdata('user', $data[0]); + redirect('feed_c'); + } else { + redirect('login_c'); + } + } + } +} +?> \ No newline at end of file diff --git a/application/controllers/profile_c.php b/application/controllers/profile_c.php new file mode 100644 index 00000000000..a2b94a12ffa --- /dev/null +++ b/application/controllers/profile_c.php @@ -0,0 +1,52 @@ +load->model('vietgram_m'); + $this->load->model('vietgram_m'); + } + + public function index() + { + $data['title'] = 'Profile | Vietgram'; + $user = $this->session->userdata('user'); + $data['profile'] = $this->vietgram_m->getProfile($user['username']); + $data['photo'] = $this->vietgram_m->getPhoto($user['username']); + + $this->load->view('header',$data); + $this->load->view('profile_v',$data); + $this->load->view('footer'); + } + public function edit() + { + $user = $this->session->userdata('user'); + $data['title'] = 'Edit Profile | Vietgram'; + $data['profile'] = $this->vietgram_m->getProfile($user['username']); + $username = $data['profile']['username']; + $this->form_validation->set_rules('username', 'username','required'); + + if ($this->form_validation->run() == false) { + $this->load->view('header',$data); + $this->load->view('edit-profile_v',$data); + $this->load->view('footer'); + } else { + $update = array( + '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'), + 'phone' => $this->input->post('phone'), + 'gender' => $this->input->post('gender'), + 'ava' => $data['profile']['ava'], + 'follower' => $data['profile']['follower'], + 'following' => $data['profile']['following'] + ); + $this->vietgram_m->editProfile($username,$update); + redirect('profile'); + } + } +} \ No newline at end of file diff --git a/application/controllers/upload_photo_c.php b/application/controllers/upload_photo_c.php new file mode 100644 index 00000000000..02d43f5aedf --- /dev/null +++ b/application/controllers/upload_photo_c.php @@ -0,0 +1,59 @@ +load->model('vietgram_m'); + $this->load->model('vietgram_m'); + } + + public function index() + { + $data['title'] = 'Upload | Vietgram'; + $user = $this->session->userdata('user'); + $data['profile'] = $this->vietgram_m->getProfile($user['username']); + $data['photo'] = $this->vietgram_m->getPhoto($user['username']); + + $this->load->view('header',$data); + $this->load->view('upload-photo_c',$data); + $this->load->view('footer'); + } + + public function do_upload() + { + $user = $this->session->userdata('user'); + $new_name = 'feed_'.$user['username']; + + $config['upload_path'] = './assets/images/'; + $config['allowed_types'] = ['png','jpg','gif','jpeg']; + $config['max_size'] = 0; + $config['max_width'] = 0; + $config['max_height'] = 0; + $config['file_name'] = $new_name; + + $this->load->library('upload', $config); + $this->upload->initialize($config); + + if ( ! $this->upload->do_upload('userfile')) { + $this->session->set_flashdata('flash',$this->upload->display_errors()); + redirect('upload_photo_c',$data); + } else { + $upload_data = $this->upload->data(); + $file_name = $upload_data['file_name']; + $data = array( + 'photo_name' => $file_name, + 'username' => $user['username'], + 'likes' => 0, + 'comment' => 0, + 'caption' => $this->input->post('caption'), + 'location' => $this->input->post('location') + ); + + $this->vietgram_m->uploadPhoto($data); + $this->session->set_flashdata('upload_success','Photo uploaded'); + redirect('profile'); + } + } +} diff --git a/application/models/vietgram_m.php b/application/models/vietgram_m.php new file mode 100644 index 00000000000..3c625cfc80b --- /dev/null +++ b/application/models/vietgram_m.php @@ -0,0 +1,81 @@ +db->query("SELECT * FROM user WHERE username = '".$username."' AND password = '".$password."'"); + return $query->result_array(); + } + + public function signup(){ + $data = [ + "username" => $this->input->post('username', true), + "password" => $this->input->post('password', true), + "email" => $this->input->post('email', true) + ]; + $this->db->insert('user', $data); + } + + public function logout(){ + session_start(); + + $_SESSION = []; + session_unset(); + session_destroy(); + + echo " + "; + exit; + } + + public function getAllFeed() + { + $query = $this->db->query("SELECT * FROM photo NATURAL JOIN profile WHERE photo.username = profile.username"); + return $query->result_array(); + } + + public function getProfile($username) + { + $query = $this->db->query("SELECT * FROM profile WHERE username = '".$username."'"); + return $query->row_array(); + } + + public function editProfile($username,$data) + { + $query = $this->db->where('username',$username); + $this->db->update('profile',$data); + } + + public function getExplore($username) + { + $query = $this->db->query("SELECT * FROM profile WHERE username NOT LIKE '".$username."'"); + return $query->result_array(); + } + + public function getPhoto($username) + { + $query = $this->db->query("SELECT * FROM photo WHERE username = '".$username."'"); + return $query->result_array(); + } + + public function uploadPhoto($data) + { + $this->db->insert('photo', $data); + } + + public function getAllComments() + { + $query = $this->db->query("SELECT * FROM comments"); + return $query->result_array(); + } + + public function getComments($username) + { + $query = $this->db->query("SELECT * FROM profile WHERE username = '".$username."'"); + return $query->row_array(); + } + +} +?> \ No newline at end of file diff --git a/application/views/edit-profile_v.php b/application/views/edit-profile_v.php new file mode 100644 index 00000000000..31a3c806967 --- /dev/null +++ b/application/views/edit-profile_v.php @@ -0,0 +1,47 @@ + + + + + + + + = $profile['username'] ?> + + + + Username: + + + + Name: + + + + + Website: + + + + Bio: + = $profile['bio']?> + + + Email: + + + + Phone Number: + + + + Gender: + + Male + Female + Can't remember + + + + + + diff --git a/application/views/explore_v.php b/application/views/explore_v.php new file mode 100644 index 00000000000..fd863c2f712 --- /dev/null +++ b/application/views/explore_v.php @@ -0,0 +1,21 @@ + + + + $f) { ?> + + + + + + = $f['username'] ?> + = $f['name'] ?> + + + + Follow + + + + + + \ No newline at end of file diff --git a/application/views/feed_v.php b/application/views/feed_v.php new file mode 100644 index 00000000000..c1eb1ad9825 --- /dev/null +++ b/application/views/feed_v.php @@ -0,0 +1,62 @@ + + + + $f) { ?> + + + + + + =$f['username']?> + =$f['location']?> + + + + + + + + + + + + + + + + Liked by =$f['likes'] ?> + =$f['username']?> =$f['caption'] ?> + View more comments + + + $c) { + if ($c['photo_name']==$f['photo_name']) { ?> + + + = $c['person'] ?> = $c['comment'] ?> + + + + + + 2 hours ago + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/views/footer.php b/application/views/footer.php new file mode 100644 index 00000000000..bee34e62801 --- /dev/null +++ b/application/views/footer.php @@ -0,0 +1,23 @@ + +