Skip to content

Commit 5f31ac8

Browse files
committed
Fix Ukagaka deactivate bug typecho-fans#34
1 parent eb950be commit 5f31ac8

File tree

6 files changed

+707
-643
lines changed

6 files changed

+707
-643
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Ukagaka/Action.php

+74-55
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,82 @@
11
<?php
22
class Ukagaka_Action extends Typecho_Widget implements Widget_Interface_Do
33
{
4-
public function __construct($request, $response, $params = NULL)
5-
{
6-
parent::__construct($request, $response, $params);
7-
}
4+
public function __construct($request, $response, $params = NULL)
5+
{
6+
parent::__construct($request, $response, $params);
7+
}
8+
9+
private function info($t)
10+
{
11+
$database = Typecho_Db::get();
12+
$options = Typecho_Widget::widget('Widget_Options');
13+
$Ukagaka = $options->plugin('Ukagaka');
14+
15+
$select = $database->select()->from('table.options')
16+
->where('name = ?', 'Ukagaka_starttime');
17+
$lifetime = $database->fetchAll($select);
18+
19+
$ki = array();
20+
21+
$ki['notice'] = stripslashes($Ukagaka->notice);
22+
$ki['nickname'] = stripcslashes($Ukagaka->nickname);
23+
$ki['born'] = stripslashes($lifetime[0]['value']);
24+
25+
$foods = explode("\r\n", $Ukagaka->foods);
826

9-
public static function info(){
10-
$options = Typecho_Widget::widget('Widget_Options');
11-
$Ukagaka = $options->plugin('Ukagaka');
12-
$wcc['notice'] = stripslashes($Ukagaka->notice);
13-
14-
$db = Typecho_Db::get();
15-
$select = $db->select()->from('table.options')
16-
->where('name = ?', 'Ukagaka_starttime');
17-
$lifetime = $db->fetchAll($select);
18-
$lifetime = self::get_wcc_lifetime($lifetime[0]['value']);
19-
$name = Typecho_Widget::widget('Widget_Options')->title;
20-
$wcc['showlifetime'] = '我已经与主人 '.$name.' 一起生存了 <font color="red">'.$lifetime["day"].'</font> 天 <font color="red">'.$lifetime["hours"].'</font> 小时 <font color="red">'.$lifetime["minutes"].'</font> 分钟 <font color="red">'.$lifetime["seconds"].'</font> 秒的快乐时光啦~*^_^*';
21-
$foods = explode("\r\n", $Ukagaka->foods);
22-
foreach ($foods as $key => $value) {
23-
$xx = explode("//", $value);
24-
$wcc['foods'][] = $xx[0];
25-
$wcc['eatsay'][] = $xx[1];
26-
}
27-
if($Ukagaka->contact){
28-
$contact = explode("\r\n", $Ukagaka->contact);
29-
foreach ($contact as $key => $value) {
30-
$xx = explode("//", $value);
31-
$wcc['ques'][] = $xx[0];
32-
$wcc['ans'][] = $xx[1];
33-
}
34-
} else {
35-
$wcc['contactapi'] = '1';
36-
}
37-
$wcc = json_encode($wcc);
38-
echo $wcc;
27+
foreach ($foods as $key => $value) {
28+
$xx = explode("//", $value);
29+
$ki['foods'][] = $xx[0];
30+
$ki['eatsay'][] = $xx[1];
3931
}
4032

41-
public static function get_wcc_lifetime($starttime){
42-
$endtime = time();
43-
$lifetime = $endtime-$starttime;
44-
$day = intval($lifetime / 86400);
45-
$lifetime = $lifetime % 86400;
46-
$hours = intval($lifetime / 3600);
47-
$lifetime = $lifetime % 3600;
48-
$minutes = intval($lifetime / 60);
49-
$lifetime = $lifetime % 60;
50-
return array('day'=>$day, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$lifetime);
33+
if ($Ukagaka->contact) {
34+
$contact = explode("\r\n", $Ukagaka->contact);
35+
36+
foreach ($contact as $key => $value) {
37+
$xx = explode("//", $value);
38+
$ki['question'][] = $xx[0];
39+
$ki['answer'][] = $xx[1];
40+
}
5141
}
52-
/**
53-
* 绑定动作
54-
*
55-
* @access public
56-
* @return void
57-
*/
58-
public function action(){
59-
$this->on($this->request);
60-
$this->info();
42+
43+
if ($Ukagaka->selftalk) {
44+
$selftalk = explode("\r\n", $Ukagaka->selftalk);
45+
foreach ($selftalk as $key => $value) {
46+
$ki['talk'][] = explode("//", $value);
47+
}
48+
} else {
49+
$ki['talk'] = '';
6150
}
62-
}
63-
?>
51+
52+
$ki = json_encode($ki);
53+
echo $ki;
54+
}
55+
56+
private function get_ki_lifetime($starttime)
57+
{
58+
$endtime = time();
59+
$lifetime = $endtime-$starttime;
60+
$day = intval($lifetime / 86400);
61+
$lifetime = $lifetime % 86400;
62+
$hours = intval($lifetime / 3600);
63+
$lifetime = $lifetime % 3600;
64+
$minutes = intval($lifetime / 60);
65+
$lifetime = $lifetime % 60;
66+
return array('day'=>$day, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$lifetime);
67+
}
68+
69+
/**
70+
* 绑定动作
71+
*
72+
* @access public
73+
* @return void
74+
*/
75+
public function action()
76+
{
77+
header('Content-type: application/json');
78+
79+
$this->on($this->request);
80+
$this->info((isset($_GET['type']) ? htmlspecialchars($_GET['type']) : ''));
81+
}
82+
}

Ukagaka/Plugin.php

+110-113
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,121 @@
11
<?php
22
/**
33
* 一只萌萌的春菜
4-
*
5-
* @category effect
6-
* @package 伪春菜
4+
*
5+
* @package 伪春菜
76
* @author Kunr
87
* @version 1.0.0
98
* @link http://kunr.me
109
*/
1110
class Ukagaka_Plugin implements Typecho_Plugin_Interface
1211
{
13-
/**
14-
* 激活插件方法,如果激活失败,直接抛出异常
15-
*
16-
* @access public
17-
* @return void
18-
* @throws Typecho_Plugin_Exception
19-
*/
20-
public static function activate()
21-
{
22-
Typecho_Plugin::factory('Widget_Archive')->header = array('Ukagaka_Plugin', 'header');
23-
Typecho_Plugin::factory('Widget_Archive')->footer = array('Ukagaka_Plugin', 'footer');
24-
$db = Typecho_Db::get();
25-
$db->query($db->insert('table.options')
26-
->rows(array(
27-
'name' => 'Ukagaka_starttime',
28-
'value' => time(),
29-
'user' => 0
30-
)));
31-
Helper::addAction('Ukagaka', 'Ukagaka_Action');
32-
}
33-
34-
/**
35-
* 禁用插件方法,如果禁用失败,直接抛出异常
36-
*
37-
* @static
38-
* @access public
39-
* @return void
40-
* @throws Typecho_Plugin_Exception
41-
*/
42-
public static function deactivate(){
43-
$db = Typecho_Db::get();
44-
$db->delete('table.options')
45-
->where('name = ?', 'Ukagaka_starttime');
46-
Helper::removeAction('Ukagaka');
47-
}
48-
49-
/**
50-
* 获取插件配置面板
51-
*
52-
* @access public
53-
* @param Typecho_Widget_Helper_Form $form 配置面板
54-
* @return void
55-
*/
56-
public static function config(Typecho_Widget_Helper_Form $form)
57-
{
58-
/** 称呼 */
59-
$nickname = new Typecho_Widget_Helper_Form_Element_Text('nickname', NULL, '主人桑', _t('春菜如何称呼主人呢..'));
60-
$form->addInput($nickname);
61-
/** 公告 */
62-
$notice = new Typecho_Widget_Helper_Form_Element_Textarea('notice', NULL, '主人暂时还没有写公告呢,这是主人第一次使用伪春菜吧', _t('博客有什么公告呢..'));
63-
$form->addInput($notice);
64-
/** 聊天 */
65-
$contact = new Typecho_Widget_Helper_Form_Element_Textarea('contact', NULL, '早上好//早上好主人sama!', _t('聊天对话'), '一行一个对话,问和答用\'//\'分割 比如: 问//答,留空使用api.');
66-
$form->addInput($contact);
67-
/** 自言自语 */
68-
$selftalk = new Typecho_Widget_Helper_Form_Element_Textarea('selftalk', NULL, '', _t('自言自语'), '一行一个自言自语设置,话和表情id(1~3)用\'//\'分割 比如: 你好//1,留空采用hitokoto');
69-
$form->addInput($selftalk);
70-
/** 零食 */
71-
$foods = new Typecho_Widget_Helper_Form_Element_Textarea('foods', NULL, '金坷垃//吃了金坷垃,一刀能秒一万八~!'."\r\n".'咸梅干//吃咸梅干,变超人!哦耶~~~', _t('零食'), '一行一个零食,零食//答语用\'//\'分割 比如: 零食//答语');
72-
$form->addInput($foods);
73-
}
74-
75-
/**
76-
* 个人用户的配置面板
77-
*
78-
* @access public
79-
* @param Typecho_Widget_Helper_Form $form
80-
* @return void
81-
*/
82-
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
83-
84-
/**
85-
* 插件实现方法
86-
*
87-
* @access public
88-
* @return void
89-
*/
90-
public static function header()
91-
{
92-
echo '<link rel="stylesheet" type="text/css" href="'.Helper::options()->pluginUrl.'/Ukagaka/assets/Ukagaka.css" />' . "\n";
93-
}
12+
/**
13+
* 激活插件方法,如果激活失败,直接抛出异常
14+
*
15+
* @access public
16+
* @return void
17+
* @throws Typecho_Plugin_Exception
18+
*/
19+
public static function activate()
20+
{
21+
Typecho_Plugin::factory('Widget_Archive')->header = array('Ukagaka_Plugin', 'header');
22+
Typecho_Plugin::factory('Widget_Archive')->footer = array('Ukagaka_Plugin', 'footer');
23+
$db = Typecho_Db::get();
24+
$db->query($db->insert('table.options')
25+
->rows(array(
26+
'name' => 'Ukagaka_starttime',
27+
'value' => time(),
28+
'user' => 0
29+
)));
30+
Helper::addAction('Ukagaka', 'Ukagaka_Action');
31+
}
9432

95-
/**
96-
* 插件实现方法
97-
*
98-
* @access public
99-
* @return void
100-
*/
101-
public static function footer()
102-
{
103-
$options = Typecho_Widget::widget('Widget_Options');
104-
$Ukagaka = $options->plugin('Ukagaka');
105-
if($Ukagaka->selftalk){
106-
$selftalk = explode("\r\n", $Ukagaka->selftalk);
107-
$vv = '[';
108-
foreach ($selftalk as $key => $value) {
109-
$vx = explode("//", $value);
110-
$vv .= '["'.$vx[0].'", "'.$vx[1].'"],';
111-
}
112-
$vv .= ']';
113-
} else {
114-
$vv = '\'\'';
115-
}
116-
$path = Helper::options()->pluginUrl.'/Ukagaka/assets';
117-
?><script type="text/javascript">!window.jQuery && document.write('<script src="//upcdn.b0.upaiyun.com/libs/jquery/jquery-1.9.1.min.js"><\/script>');</script>
118-
<script src="<?php echo $path;?>/Ukagaka.js"></script>
119-
<script type="text/javascript">var actionurl = '<?php Helper::options()->index('action/Ukagaka');?>'; var imagewidth = '85';var imageheight = '152';</script>
120-
<script type="text/javascript">createFace("<?php echo $path; ?>/skin/default/face1.gif", "<?php echo $path; ?>/skin/default/face2.gif", "<?php echo $path; ?>/skin/default/face3.gif");</script>
121-
<script type="text/javascript">var talkself_arr = <?php echo $vv;?>;</script>
122-
<?php
123-
}
33+
/**
34+
* 禁用插件方法,如果禁用失败,直接抛出异常
35+
*
36+
* @static
37+
* @access public
38+
* @return void
39+
* @throws Typecho_Plugin_Exception
40+
*/
41+
public static function deactivate(){
42+
$db = Typecho_Db::get();
43+
$db->query($db->delete('table.options')->where('name = ?', 'Ukagaka_starttime'));
44+
Helper::removeAction('Ukagaka');
45+
}
46+
47+
/**
48+
* 获取插件配置面板
49+
*
50+
* @access public
51+
* @param Typecho_Widget_Helper_Form $form 配置面板
52+
* @return void
53+
*/
54+
public static function config(Typecho_Widget_Helper_Form $form)
55+
{
56+
/** 称呼 */
57+
$nickname = new Typecho_Widget_Helper_Form_Element_Text('nickname', NULL, '主人桑', _t('春菜如何称呼主人呢..'));
58+
$form->addInput($nickname);
59+
/** 公告 */
60+
$notice = new Typecho_Widget_Helper_Form_Element_Textarea('notice', NULL, '主人暂时还没有写公告呢,这是主人第一次使用伪春菜吧', _t('博客有什么公告呢..'));
61+
$form->addInput($notice);
62+
/** 聊天 */
63+
$contact = new Typecho_Widget_Helper_Form_Element_Textarea('contact', NULL, '早上好//早上好主人sama!', _t('聊天对话'), '一行一个对话,问和答用\'//\'分割 比如: 问//答,留空使用api.');
64+
$form->addInput($contact);
65+
/** 自言自语 */
66+
$selftalk = new Typecho_Widget_Helper_Form_Element_Textarea('selftalk', NULL, '', _t('自言自语'), '一行一个自言自语设置,话和表情id(1~3)用\'//\'分割 比如: 你好//1,留空采用hitokoto');
67+
$form->addInput($selftalk);
68+
/** 零食 */
69+
$foods = new Typecho_Widget_Helper_Form_Element_Textarea('foods', NULL, '金坷垃//吃了金坷垃,一刀能秒一万八~!'."\r\n".'咸梅干//吃咸梅干,变超人!哦耶~~~', _t('零食'), '一行一个零食,零食//答语用\'//\'分割 比如: 零食//答语');
70+
$form->addInput($foods);
71+
}
72+
73+
/**
74+
* 个人用户的配置面板
75+
*
76+
* @access public
77+
* @param Typecho_Widget_Helper_Form $form
78+
* @return void
79+
*/
80+
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
81+
82+
/**
83+
* 插件实现方法
84+
*
85+
* @access public
86+
* @return void
87+
*/
88+
public static function header()
89+
{
90+
echo '<link rel="stylesheet" type="text/css" href="' . Helper::options()->pluginUrl . '/Ukagaka/assets/ukagaka.css" />' . "\n";
91+
}
92+
93+
/**
94+
* 插件实现方法
95+
*
96+
* @access public
97+
* @return void
98+
*/
99+
public static function footer()
100+
{
101+
$options = Typecho_Widget::widget('Widget_Options');
102+
$Ukagaka = $options->plugin('Ukagaka');
103+
104+
$path = Helper::options()->pluginUrl.'/Ukagaka/assets';
105+
?> <script src="<?php echo $path;?>/ukagaka.js"></script>
106+
<script type="text/javascript">
107+
var ukagaka = new Ukagaka({
108+
width: '85',
109+
height: '152',
110+
111+
api: '<?php Helper::options()->index('action/Ukagaka'); ?>',
112+
character: [
113+
'<?php echo $path; ?>/skin/default/face1.gif',
114+
'<?php echo $path; ?>/skin/default/face2.gif',
115+
'<?php echo $path; ?>/skin/default/face3.gif'
116+
],
117+
});
118+
</script>
119+
<?php
120+
}
124121
}

0 commit comments

Comments
 (0)