forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.php
82 lines (69 loc) · 2.11 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
<?php
class Ukagaka_Action extends Typecho_Widget implements Widget_Interface_Do
{
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
}
private function info($t)
{
$database = Typecho_Db::get();
$options = Typecho_Widget::widget('Widget_Options');
$Ukagaka = $options->plugin('Ukagaka');
$select = $database->select()->from('table.options')
->where('name = ?', 'Ukagaka_starttime');
$lifetime = $database->fetchAll($select);
$ki = array();
$ki['notice'] = stripslashes($Ukagaka->notice);
$ki['nickname'] = stripcslashes($Ukagaka->nickname);
$ki['born'] = stripslashes($lifetime[0]['value']);
$foods = explode("\r\n", $Ukagaka->foods);
foreach ($foods as $key => $value) {
$xx = explode("//", $value);
$ki['foods'][] = $xx[0];
$ki['eatsay'][] = $xx[1];
}
if ($Ukagaka->contact) {
$contact = explode("\r\n", $Ukagaka->contact);
foreach ($contact as $key => $value) {
$xx = explode("//", $value);
$ki['question'][] = $xx[0];
$ki['answer'][] = $xx[1];
}
}
if ($Ukagaka->selftalk) {
$selftalk = explode("\r\n", $Ukagaka->selftalk);
foreach ($selftalk as $key => $value) {
$ki['talk'][] = explode("//", $value);
}
} else {
$ki['talk'] = '';
}
$ki = json_encode($ki);
echo $ki;
}
private function get_ki_lifetime($starttime)
{
$endtime = time();
$lifetime = $endtime-$starttime;
$day = intval($lifetime / 86400);
$lifetime = $lifetime % 86400;
$hours = intval($lifetime / 3600);
$lifetime = $lifetime % 3600;
$minutes = intval($lifetime / 60);
$lifetime = $lifetime % 60;
return array('day'=>$day, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$lifetime);
}
/**
* 绑定动作
*
* @access public
* @return void
*/
public function action()
{
header('Content-type: application/json');
$this->on($this->request);
$this->info((isset($_GET['type']) ? htmlspecialchars($_GET['type']) : ''));
}
}