php class Post extends ESK_Controller function action_view id if _SESS

 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
<?php
class Post extends ESK_Controller
{
function action_view($id)
{
if (!$_SESSION['view_blog_'.$id])
{
$this->db->query("UPDATE `post` SET `view`=`view`+'1' WHERE `id`=?",
array($id));
$_SESSION['view_blog_'.$id] = md5(rand(10000000000,2929929299));
}
$this->model->loadModel('model_post');
$post = new model_post();
$h = array ('title'=>$post->data($id)['title']);
$this->view->generate('header',$h);
$postViev =$post->data($id);
$this->view->generate('post_view',$postViev);
}
function action_like($id)
{
if (isset($_SESSION['like_'.$id]))
{
$this->db->query("UPDATE `post` SET `like`=`like`-'1'
WHERE `id`=?",
array($id));
unset($_SESSION['like_'.$id]);
} elseif (!$_SESSION['like_'.$id]) {
$this->db->query("UPDATE `post` SET `like`=`like`+'1'
WHERE `id`=?",
array($id));
//setcookie('like_'.$id,1,time()+(84600+365));
$_SESSION['like_'.$id] = 1;
}
header("Location:/post/view/".$id);
exit;
}
function action_index ()
{
return $this->action_view(1);
}
function action_all()
{
self::load('pagination');
$pagination = new pagination();
$h = array ('title'=>'Все записи');
$this->view->generate('header',$h);
$pagination->set('pages','5');
$pagination->show();
}
}