|
@@ -8,35 +8,39 @@ class controller_main extends Controller
|
|
|
header('Location: /user/login');
|
|
header('Location: /user/login');
|
|
|
}
|
|
}
|
|
|
$this->model = new Model_main();
|
|
$this->model = new Model_main();
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function index()
|
|
function index()
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
$data['users'] = $this->get_users();
|
|
$data['users'] = $this->get_users();
|
|
|
-
|
|
|
|
|
$data['posts'] = $this->model->get_posts();
|
|
$data['posts'] = $this->model->get_posts();
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
$this->view->generate('main_view.php', $data);
|
|
$this->view->generate('main_view.php', $data);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function createpost(){
|
|
public function createpost(){
|
|
|
if(isset($_POST['caption'], $_POST['post'])){
|
|
if(isset($_POST['caption'], $_POST['post'])){
|
|
|
- $this->model->create_post($_POST['caption'], $_POST['post']);
|
|
|
|
|
|
|
+ $this->model->create_post(htmlentities($_POST['caption']), htmlentities($_POST['post']));
|
|
|
}
|
|
}
|
|
|
header('Location: /');
|
|
header('Location: /');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function post($id){
|
|
|
|
|
|
|
+ public function post($id)
|
|
|
|
|
+ {
|
|
|
if(!$id) Route::ErrorPage404();
|
|
if(!$id) Route::ErrorPage404();
|
|
|
$data['post'] = $this->model->get_post($id);
|
|
$data['post'] = $this->model->get_post($id);
|
|
|
|
|
+ if(!$data['post']) Route::ErrorPage404();
|
|
|
$data['users'] = $this->get_users();
|
|
$data['users'] = $this->get_users();
|
|
|
- var_dump($data);
|
|
|
|
|
|
|
+ $data['comments'] = $this->model->get_comments($id);
|
|
|
|
|
+ $this->view->generate('post.php', $data);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ public function add_comment($post_id)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(isset($_POST['comment'])){
|
|
|
|
|
+ $user_id = $_SESSION['user']['id'];
|
|
|
|
|
+ $this->model->add_comment($post_id, $user_id, htmlentities($_POST['comment']));
|
|
|
|
|
+ }
|
|
|
|
|
+ header('Location: /main/post/' . $post_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function get_users(): array
|
|
private function get_users(): array
|