forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Action.php
44 lines (39 loc) · 1.17 KB
/
Action.php
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
<?php
/**
* Like Plugin
*
* @copyright Copyright (c) 2014 skylzl (http://www.woyoudian.com)
* @license GNU General Public License 2.0
*
*/
class Like_Action extends Typecho_Widget implements Widget_Interface_Do
{
private $db;
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
$this->db = Typecho_Db::get();
}
/**
* 点赞Like
*/
public function up(){
$cid=$this->request->filter('int')->cid;
if($cid){
try {
$row = $this->db->fetchRow($this->db->select('likes')->from('table.contents')->where('cid = ?', $cid));
$this->db->query($this->db->update('table.contents')->rows(array('likes' => (int)$row['likes']+1))->where('cid = ?', $cid));
$this->response->throwJson("success");
} catch (Exception $ex) {
echo $ex->getCode();
}
} else {
echo "error";
}
}
public function action(){
$this->on($this->request->is('up'))->up();
$this->response->goBack();
}
}
?>