-
Notifications
You must be signed in to change notification settings - Fork 23
/
Action.php
52 lines (48 loc) · 1.29 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
<?php
/**
* Action.php
*
* 处理请求
*
* @author 熊猫小A
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
?>
<?php
class ExSearch_Action extends Widget_Abstract_Contents implements Widget_Interface_Do
{
/**
* 返回请求的 JSON
*
* @access public
*/
public function action(){
// 要求先登录
Typecho_Widget::widget('Widget_User')->to($user);
if (!$user->have() || !$user->hasLogin()) {
echo 'Invalid Request';
exit;
}
switch ($_GET['action']) {
case 'rebuild':
ExSearch_Plugin::save();
?>
重建索引完成,<a href="<?php Helper::options()->siteUrl(); ?>" target="_self">回到首页</a>。
<?php
break;
case 'api':
header('Content-Type: application/json');
$key = $_GET['key'];
if(empty($key)){
echo json_encode(array());
return;
}
$db = Typecho_Db::get();
$row = $db->fetchRow($db->select()->from('table.exsearch')
->where('table.exsearch.key = ?', $key));
$content = $row['data'];
echo $content;
break;
}
}
}