1
+ <?php
2
+ if (!defined ('__TYPECHO_ROOT_DIR__ ' )) exit ;
3
+
4
+ class Smilies_Action extends Typecho_Widget implements Widget_Interface_Do
5
+ {
6
+
7
+ /**
8
+ * 扫描表情文件夹
9
+ *
10
+ * @access public
11
+ * @return void
12
+ */
13
+ public function scanfolders ()
14
+ {
15
+ $ plugindir = __TYPECHO_ROOT_DIR__ .__TYPECHO_PLUGIN_DIR__ .'/Smilies/ ' ;
16
+ $ lists = array ();
17
+ $ rests =array ();
18
+ $ set = $ this ->request ->set ;
19
+ $ option = Helper::options ();
20
+ $ settings = $ option ->plugin ('Smilies ' );
21
+ $ curset = $ settings ->smiliesset ;
22
+
23
+ $ routes = glob ($ plugindir .'* ' ,GLOB_ONLYDIR );
24
+ if ($ routes ) {
25
+ $ folder = '' ;
26
+ $ locations = array ();
27
+
28
+ foreach ($ routes as $ route ) {
29
+ $ folder = str_replace ($ plugindir ,'' ,$ route );
30
+ //检索图片后缀
31
+ $ locations = glob ($ plugindir .$ folder .'/*.{gif,jpg,jpeg,png,tiff,bmp,svg,GIF,JPG,JPEG,PNG,TIFF,BMP,SVG} ' ,GLOB_BRACE |GLOB_NOSORT );
32
+
33
+ array_walk ($ locations ,array (__CLASS__ ,'cname ' ),'' );
34
+ $ folder = self ::cname ($ folder );
35
+
36
+ //分割标准组
37
+ $ lists [$ folder ] = array_splice ($ locations ,-22 );
38
+ $ rests [$ folder ] = $ locations ;
39
+ if (in_array ($ folder ,array ('tieba ' ,'weibo ' ,'wordpress ' ))) {
40
+ //预设默认排序
41
+ $ 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 ' );
42
+ }
43
+ }
44
+ }
45
+
46
+ //菜单项目显示
47
+ $ opts = '<option value="none"> ' ._t ('没有表情包 ' ).'</option> ' ;
48
+ if ($ lists ) {
49
+ $ opts = '' ;
50
+ $ keys = array_keys ($ lists );
51
+ foreach ($ keys as $ key ) {
52
+ $ opts .= '<option value=" ' .$ key .'" ' .($ key ==$ curset ? ' selected="true" ' : '' ).'> ' .$ key .'</option> ' ;
53
+ }
54
+ }
55
+
56
+ $ set = $ set ? $ set : $ curset ;
57
+ $ grids = _t ('没有在文件夹%s下找到表情图片 ' ,'<span style="color:#467B96;"> ' .$ set .'</span> ' );
58
+ $ extras = '' ;
59
+ //排序表情显示
60
+ if (isset ($ lists [$ set ])) {
61
+ $ list = $ lists ['' .$ set .'' ];
62
+ $ grids = '<div class="gridly ' .$ set .'"> ' ;
63
+ $ names = $ set ==$ curset ? explode ('| ' ,$ settings ->smsort ) : $ list ;
64
+ foreach ($ names as $ name ) {
65
+ $ grids .= '<div class="td" id=" ' .$ name .'" title=" ' ._t ('拖动对应 ' ).'" style="cursor:move;"><img src=" ' .$ option ->pluginUrl .'/Smilies/ ' .$ set .'/ ' .$ name .'" alt=""/></div> ' ;
66
+ }
67
+ $ grids .= '</div> ' ;
68
+ }
69
+
70
+ //更多表情显示
71
+ if (isset ($ rests [$ set ])) {
72
+ $ rest = $ rests ['' .$ set .'' ];
73
+ $ extras = '<div class=" ' .$ set .'"> ' ;
74
+ if ($ rest ) {
75
+ $ extras .= '<div class="caption">------ ⇓ ' ._t ('该表情包下的更多图片 ' ).' ------</div> ' ;
76
+ }
77
+ foreach ($ rest as $ rname ) {
78
+ $ extras .= '<div class="fix" title=" ' ._t ('右击复制图片地址 ' ).'"><img src=" ' .$ option ->pluginUrl .'/Smilies/ ' .$ set .'/ ' .$ rname .'" alt=""/></div> ' ;
79
+ }
80
+ $ extras .= '</div> ' ;
81
+ }
82
+
83
+ $ parse = Json::encode (array ($ lists ,$ opts ,$ grids ,$ extras ));
84
+ $ this ->response ->throwJson ($ parse );
85
+ }
86
+
87
+ /**
88
+ * 转码中文名称
89
+ *
90
+ * @access private
91
+ * @return string
92
+ */
93
+ private static function cname (&$ value ) {
94
+ $ pagecode = 'utf-8 ' ;
95
+ $ code = function_exists ('mb_detect_encoding ' ) ? strtolower (mb_detect_encoding ($ value , array ('ASCII ' ,'GB2312 ' ,'GBK ' ,'UTF-8 ' ))) : $ pagecode ;
96
+
97
+ if ($ code =='gb2312 ' || $ code =='euc-cn ' ) {
98
+ if (function_exists ('iconv ' )) {
99
+ $ value = iconv ($ code ,$ pagecode ,$ value );
100
+ } else if (function_exists ('mb_convert_encoding ' )) {
101
+ $ value = mb_convert_encoding ($ value ,$ pagecode ,$ code );
102
+ }
103
+ }
104
+ $ value = preg_replace ('/^.+[ \\\\\\/]/ ' ,'' ,$ value );
105
+
106
+ return $ value ;
107
+ }
108
+
109
+ /**
110
+ * 绑定动作
111
+ *
112
+ * @access public
113
+ * @return void
114
+ */
115
+ public function action ()
116
+ {
117
+ Helper::security ()->protect ();
118
+ $ this ->on ($ this ->request ->isPost ())->scanfolders ();
119
+ $ this ->response ->goBack ();
120
+ }
121
+
122
+ }
0 commit comments