/
class.riceballs.plugin.php
executable file
·197 lines (180 loc) · 5.18 KB
/
class.riceballs.plugin.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php if (!defined('APPLICATION')) exit();
$PluginInfo['RiceBalls'] = array(
'Name' => 'Rice Balls',
'Description' => 'Replaces <a href="http://en.wikipedia.org/wiki/Emoticon">emoticons</a> (smilies/smileys) with David Lanham\'s Rice Balls images from AdiumXtras.',
'Version' => '1.0.1',
'MobileFriendly' => TRUE,
'Author' => "Matt Sephton",
'AuthorEmail' => 'matt@gingerbeardman.com',
'AuthorUrl' => 'http://www.gingerbeardman.com',
'License' => 'GPL v2',
'RequiredApplications' => array('Vanilla' => '>=2.0.18'),
);
/**
* Note: Added jquery events required for proper display/hiding of emoticons
* as write & preview buttons are clicked on forms in Vanilla 2.0.14. These
* are necessary in order for this plugin to work properly.
*/
class RiceBallsPlugin implements Gdn_IPlugin {
/**
* Replace emoticons in comments.
*/
public function Base_AfterCommentFormat_Handler($Sender) {
if (!C('Plugins.RiceBalls.FormatEmoticons', TRUE))
return;
$Object = $Sender->EventArguments['Object'];
$Object->FormatBody = $this->DoEmoticons($Object->FormatBody);
$Sender->EventArguments['Object'] = $Object;
}
public function DiscussionController_Render_Before($Sender) {
$this->_RiceBallsSetup($Sender);
}
/**
* Return an array of emoticons.
*/
public static function GetEmoticons() {
return array(
':-|' => 'Ambivalent',
':|' => 'Ambivalent',
'O:)' => 'Angel',
'o:)' => 'Angel',
'O:-)' => 'Angel',
'O:)' => 'Angel',
'o:-)' => 'Angel',
'o:)' => 'Angel',
'>:o' => 'Angry',
':<' => 'Angry',
':-<' => 'Angry',
':-#' => 'Blush',
':#' => 'Blush',
'8|' => 'BugEyed',
'8-|' => 'BugEyed',
':S' => 'Confused',
':-S' => 'Confused',
':s' => 'Confused',
':-s' => 'Confused',
'%)' => 'Crazy',
'%-)' => 'Crazy',
':’(' => 'Crying',
':’-(' => 'Crying',
':!' => 'FootInMouth',
':-!' => 'FootInMouth',
':(' => 'Frown',
':-(' => 'Frown',
':o' => 'Gasp',
'=-o' => 'Gasp',
'X)' => 'Grin',
'<3' => 'Heart',
'8)' => 'Hot',
'8-)' => 'Hot',
':-*' => 'Kiss',
':*' => 'Kiss',
':O' => 'LargeGasp',
'=O' => 'LargeGasp',
'=-O' => 'LargeGasp',
':-O' => 'LargeGasp',
':-D' => 'Laugh',
':D' => 'Laugh',
'xD' => 'Laugh',
'XD' => 'Laugh',
':X' => 'LipsAreSealed',
':-x' => 'LipsAreSealed',
':-X' => 'LipsAreSealed',
':x' => 'LipsAreSealed',
':$' => 'MoneyMouth',
'$)' => 'MoneyMouth',
':-$' => 'MoneyMouth',
'$-)' => 'MoneyMouth',
'>:-)' => 'Naughty',
'>:)' => 'Naughty',
'>:->' => 'Naughty',
'>:>' => 'Naughty',
':-B' => 'Nerd',
':B' => 'Nerd',
'8-B' => 'Nerd',
'8B' => 'Nerd',
'D:' => 'OhNoes',
'P-[' => 'Pirate',
'P-|' => 'Pirate',
':pirate' => 'Pirate',
':ar' => 'Pirate',
':yarr' => 'Pirate',
'(sarc)' => 'Sarcastic',
'</sarcasm>' => 'Sarcastic',
'^)' => 'Sarcastic',
':[[' => 'Sick',
':-)' => 'Smile',
':)' => 'Smile',
'^_^' => 'Smile',
':P' => 'StickingOutTongue',
':-p' => 'StickingOutTongue',
':-P' => 'StickingOutTongue',
':p' => 'StickingOutTongue',
'(N)' => 'ThumbsDown',
'(n)' => 'ThumbsDown',
'(Y)' => 'ThumbsUp',
'(y)' => 'ThumbsUp',
':\\' => 'Undecided',
':/' => 'Undecided',
':-\\' => 'Undecided',
':-/' => 'Undecided',
'>:-O' => 'VeryAngry',
':@' => 'VeryAngry',
':-@' => 'VeryAngry',
';-)' => 'Wink',
';)' => 'Wink',
':-d' => 'Yum',
':d' => 'Yum',
':agbic' => 'AGBIC',
':nes' => 'AGBIC',
':love' => 'Love',
'(L)' => 'Love',
':trophy' => 'Trophy',
':prize' => 'Trophy',
':winner' => 'Trophy'
);
}
/**
* Replace emoticons in comment preview.
*/
public function PostController_AfterCommentPreviewFormat_Handler($Sender) {
if (!C('Plugins.RiceBalls.FormatEmoticons', TRUE))
return;
$Sender->Comment->Body = $this->DoEmoticons($Sender->Comment->Body);
}
public function PostController_Render_Before($Sender) {
$this->_RiceBallsSetup($Sender);
}
/**
* Thanks to punbb 1.3.5 (GPL License) for this function - ported from their do_smilies function.
*/
public static function DoEmoticons($Text) {
$Text = ' '.$Text.' ';
// special case crying smiley to work around SmartyPants
$Text = str_replace(array(':’(', ':’-('), array(':’(', ':’-('), $Text);
$Emoticons = RiceBallsPlugin::GetEmoticons();
foreach ($Emoticons as $Key => $Replacement) {
if (strpos($Text, $Key) !== FALSE)
$Text = preg_replace(
"#(?<=[>\s])".preg_quote($Key, '#')."(?=\W)#m",
'<span class="RiceBall RiceBall' . $Replacement . '" title="' . $Replacement . '"><span>' . $Key . '</span></span>',
$Text
);
}
return substr($Text, 1, -1);
}
/**
* Prepare a page to be emotified.
*/
private function _RiceBallsSetup($Sender) {
$Sender->AddJsFile('riceballs.js', 'plugins/RiceBalls');
$Sender->AddCssFile('riceballs.css', 'plugins/RiceBalls');
// Deliver the emoticons to the page.
$Sender->AddDefinition('RiceBalls', base64_encode(json_encode($this->GetEmoticons())));
}
public function Setup() {
//SaveToConfig('Plugins.RiceBalls.FormatEmoticons', TRUE);
SaveToConfig('Garden.Format.Hashtags', FALSE); // Autohashing to search is incompatible with RiceBalls
}
}
?>