forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.php
139 lines (97 loc) · 3.79 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
class Version_Action extends Typecho_Widget implements Widget_Interface_Do
{
public function __construct($request, $response, $params = null)
{
parent::__construct($request, $response, $params);
}
public function execute()
{
}
public function action()
{
}
public function permissionCheck()
{
$user = Typecho_Widget::widget('Widget_User');
if(!$user->pass('editor', true))
throw new Typecho_Widget_Exception(_t('没有编辑权限'), 403);
}
public function respond()
{
$this->response->setContentType('image/gif');
echo base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAQUAP8ALAAAAAABAAEAAAICRAEAOw==');
}
public function revert()
{
$this->permissionCheck();
$vid = $this->request->get('vid');
if(!isset($vid))
throw new Typecho_Widget_Exception(_t('参数不正确'), 404);
$vid = intval($vid);
$db = Typecho_Db::get();
$table = $db->getPrefix() . 'verion_plugin';
$row = $db->fetchRow($db->select()->from($table)->where('vid = ? ', $vid));
$cid = $row['cid'];
// 找出文章和文章的草稿
$raw = $db->fetchRow($db->select()->from('table.contents')->where("cid = ? ", $cid));
$raw2 = $db->fetchRow($db->select()->from('table.contents')->where("parent = ? AND (type = 'post' OR type = 'post_draft' OR type = 'page' OR type = 'page_draft')", $cid));
if(!empty($row))
{
$raw['text'] = $row['text'];
$raw2['text'] = $row['text'];
// 开始回退
$db->query($db->update('table.contents')->rows($raw)->where('cid = ? ', $cid));
$db->query($db->update('table.contents')->rows($raw2)->where("parent = ? AND (type = 'post' OR type = 'post_draft' OR type = 'page' OR type = 'page_draft')", $cid));
}else{
throw new Typecho_Widget_Exception(_t('数据为空'), 404);
}
// $this->respond();
}
public function delete()
{
$this->permissionCheck();
$vid = $this->request->get('vid');
if(!isset($vid))
throw new Typecho_Widget_Exception(_t('参数不正确'), 404);
$vid = intval($vid);
$db = Typecho_Db::get();
$table = $db->getPrefix() . 'verion_plugin';
$db->query($db->delete($table)->where('vid = ? ', $vid));
// $this->respond();
}
public function preview()
{
$this->permissionCheck();
$vid = $this->request->get('vid');
if(!isset($vid))
throw new Typecho_Widget_Exception(_t('参数不正确'), 404);
$vid = intval($vid);
$db = Typecho_Db::get();
$table = $db->getPrefix() . 'verion_plugin';
$row = $db->fetchRow($db->select()->from($table)->where('vid = ? ', $vid));
$this->response->setContentType('text/plain');
echo $row['text'];
}
public function comment()
{
$this->permissionCheck();
$vid = $this->request->get('vid');
$comment = $this->request->get('comment');
if(!isset($vid))
throw new Typecho_Widget_Exception(_t('参数不正确'), 404);
$vid = intval($vid);
$db = Typecho_Db::get();
$table = $db->getPrefix() . 'verion_plugin';
$row = $db->fetchRow($db->select()->from($table)->where('vid = ? ', $vid));
if(!empty($row))
{
$row['comment'] = $comment;
$db->query($db->update($table)->rows($row)->where('vid = ? ', $vid));
}else{
throw new Typecho_Widget_Exception(_t('数据为空'), 404);
}
// $this->respond();
}
}