forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Action.php
122 lines (107 loc) · 3.76 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
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
class Smilies_Action extends Typecho_Widget implements Widget_Interface_Do
{
/**
* 扫描表情文件夹
*
* @access public
* @return void
*/
public function scanfolders()
{
$plugindir = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.'/Smilies/';
$lists = array();
$rests =array();
$set = $this->request->set;
$option = Helper::options();
$settings = $option->plugin('Smilies');
$curset = $settings->smiliesset;
$routes = glob($plugindir.'*',GLOB_ONLYDIR);
if ($routes) {
$folder = '';
$locations = array();
foreach ($routes as $route) {
$folder = str_replace($plugindir,'',$route);
//检索图片后缀
$locations = glob($plugindir.$folder.'/*.{gif,jpg,jpeg,png,tiff,bmp,svg,GIF,JPG,JPEG,PNG,TIFF,BMP,SVG}',GLOB_BRACE|GLOB_NOSORT);
array_walk($locations,array(__CLASS__ ,'cname'),'');
$folder = self::cname($folder);
//分割标准组
$lists[$folder] = array_splice($locations,-22);
$rests[$folder] = $locations;
if (in_array($folder,array('tieba','weibo','wordpress'))) {
//预设默认排序
$lists[$folder] = array('icon_mrgreen.png','icon_neutral.png','icon_twisted.png','icon_arrow.png','icon_eek.png','icon_smile.png','icon_confused.png','icon_cool.png','icon_evil.png','icon_biggrin.png','icon_idea.png','icon_redface.png','icon_razz.png','icon_rolleyes.png','icon_wink.png','icon_cry.png','icon_surprised.png','icon_lol.png','icon_mad.png','icon_sad.png','icon_exclaim.png','icon_question.png');
}
}
}
//菜单项目显示
$opts = '<option value="none">'._t('没有表情包').'</option>';
if ($lists) {
$opts = '';
$keys = array_keys($lists);
foreach ($keys as $key) {
$opts .= '<option value="'.$key.'"'.($key==$curset ? ' selected="true"' : '').'>'.$key.'</option>';
}
}
$set = $set ? $set : $curset;
$grids = _t('没有在文件夹%s下找到表情图片','<span style="color:#467B96;">'.$set.'</span>');
$extras = '';
//排序表情显示
if (isset($lists[$set])) {
$list = $lists[''.$set.''];
$grids = '<div class="gridly '.$set.'">';
$names = $set==$curset ? explode('|',$settings->smsort) : $list;
foreach ($names as $name) {
$grids .= '<div class="td" id="'.$name.'" title="'._t('拖动对应').'" style="cursor:move;"><img src="'.$option->pluginUrl.'/Smilies/'.$set.'/'.$name.'" alt=""/></div>';
}
$grids .= '</div>';
}
//更多表情显示
if (isset($rests[$set])) {
$rest = $rests[''.$set.''];
$extras = '<div class="'.$set.'">';
if ($rest) {
$extras .= '<div class="caption">------ ⇓ '._t('该表情包下的更多图片').' ------</div>';
}
foreach ($rest as $rname) {
$extras .= '<div class="fix" title="'._t('右击复制图片地址').'"><img src="'.$option->pluginUrl.'/Smilies/'.$set.'/'.$rname.'" alt=""/></div>';
}
$extras .= '</div>';
}
$parse = Json::encode(array($lists,$opts,$grids,$extras));
$this->response->throwJson($parse);
}
/**
* 转码中文名称
*
* @access private
* @return string
*/
private static function cname(&$value) {
$pagecode = 'utf-8';
$code = function_exists('mb_detect_encoding') ? strtolower(mb_detect_encoding($value, array('ASCII','GB2312','GBK','UTF-8'))) : $pagecode;
if ($code=='gb2312' || $code=='euc-cn') {
if (function_exists('iconv')) {
$value = iconv($code,$pagecode,$value);
} else if (function_exists('mb_convert_encoding')) {
$value = mb_convert_encoding($value,$pagecode,$code);
}
}
$value = preg_replace('/^.+[\\\\\\/]/','',$value);
return $value;
}
/**
* 绑定动作
*
* @access public
* @return void
*/
public function action()
{
Helper::security()->protect();
$this->on($this->request->isPost())->scanfolders();
$this->response->goBack();
}
}