blob: 775e43a63b9332acf90f68df23baa3670633ea8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<?php /* Copyright (c) 2024 Freya Murphy */
class HomeController extends Controller {
private $model;
function __construct($model) {
parent::__construct();
$this->model = $model;
}
public function index() {
parent::index();
$data = $this->model->get_data();
$this->view('header', $data);
$this->app_view('main', $data);
}
public function posts() {
$page = $this->main->get_num('page', 0);
$page_size = 20;
$offset = $page * $page_size;
$user = $this->main->user();
$query = $this->db;
if ($user) {
$query = $query->select('p.*, l.post_id IS NOT NULL as liked');
} else {
$query = $query->select('p.*, FALSE as liked');
}
$query = $query->from('admin.post p');
if ($user) {
$query = $query->join('admin.like l', 'p.id = l.post_id')
->where('l.user_id')->eq($user['id'])
->or()->where('l.user_id IS NULL');
}
$posts = $query->limit($page_size)
->offset($offset)
->rows();
$users = $this->main->get_users($posts);
foreach ($posts as $post) {
$data = array();
$data['user'] = $users[$post['user_id']];
$data['post'] = $post;
$this->view('template/post', $data);
}
}
public function comments() {
$page = $this->main->get_num('page', 0);
$id = $this->main->get_num('id');
$page_size = 20;
$offset = $page * $page_size;
$comments = $this->db
->select('*')
->from('admin.comment')
->limit($page_size)
->offset($offset)
->rows();
$users = $this->main->get_users($comments);
foreach ($comments as $comment) {
$data = array();
$data['user'] = $users[$comment['user_id']];
$data['comment'] = $comment;
$this->view('template/comment', $data);
}
}
public function new_post_modal() {
$this->modal(lang('new_post_modal_title'), 'new-post');
}
}
?>
|