Skip to content

Commit 02d3486

Browse files
committed
update smiley helper
1 parent c201e37 commit 02d3486

File tree

2 files changed

+129
-86
lines changed

2 files changed

+129
-86
lines changed

config/smileys.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
defined('BASEPATH') or exit('No direct script access allowed');
3+
4+
/*
5+
| -------------------------------------------------------------------
6+
| SMILEYS
7+
| -------------------------------------------------------------------
8+
| This file contains an array of smileys for use with the emoticon helper.
9+
| Individual images can be used to replace multiple smileys. For example:
10+
| :-) and :) use the same image replacement.
11+
|
12+
| Please see user guide for more info:
13+
| https://codeigniter.com/user_guide/helpers/smiley_helper.html
14+
|
15+
*/
16+
// smiley image name width height alt
17+
$smileys = array(
18+
':-)' => ['grin.gif', '19', '19', 'grin'],
19+
':lol:' => ['lol.gif', '19', '19', 'LOL'],
20+
':cheese:' => ['cheese.gif', '19', '19', 'cheese'],
21+
':)' => ['smile.gif', '19', '19', 'smile'],
22+
';-)' => ['wink.gif', '19', '19', 'wink'],
23+
';)' => ['wink.gif', '19', '19', 'wink'],
24+
':smirk:' => ['smirk.gif', '19', '19', 'smirk'],
25+
':roll:' => ['rolleyes.gif', '19', '19', 'rolleyes'],
26+
':-S' => ['confused.gif', '19', '19', 'confused'],
27+
':wow:' => ['surprise.gif', '19', '19', 'surprised'],
28+
':bug:' => ['bigsurprise.gif', '19', '19', 'big surprise'],
29+
':-P' => ['tongue_laugh.gif', '19', '19', 'tongue laugh'],
30+
'%-P' => ['tongue_rolleye.gif', '19', '19', 'tongue rolleye'],
31+
';-P' => ['tongue_wink.gif', '19', '19', 'tongue wink'],
32+
':P' => ['raspberry.gif', '19', '19', 'raspberry'],
33+
':blank:' => ['blank.gif', '19', '19', 'blank stare'],
34+
':long:' => ['longface.gif', '19', '19', 'long face'],
35+
':ohh:' => ['ohh.gif', '19', '19', 'ohh'],
36+
':grrr:' => ['grrr.gif', '19', '19', 'grrr'],
37+
':gulp:' => ['gulp.gif', '19', '19', 'gulp'],
38+
'8-/' => ['ohoh.gif', '19', '19', 'oh oh'],
39+
':down:' => ['downer.gif', '19', '19', 'downer'],
40+
':red:' => ['embarrassed.gif', '19', '19', 'red face'],
41+
':sick:' => ['sick.gif', '19', '19', 'sick'],
42+
':shut:' => ['shuteye.gif', '19', '19', 'shut eye'],
43+
':-/' => ['hmm.gif', '19', '19', 'hmmm'],
44+
'>:(' => ['mad.gif', '19', '19', 'mad'],
45+
':mad:' => ['mad.gif', '19', '19', 'mad'],
46+
'>:-(' => ['angry.gif', '19', '19', 'angry'],
47+
':angry:' => ['angry.gif', '19', '19', 'angry'],
48+
':zip:' => ['zip.gif', '19', '19', 'zipper'],
49+
':kiss:' => ['kiss.gif', '19', '19', 'kiss'],
50+
':ahhh:' => ['shock.gif', '19', '19', 'shock'],
51+
':coolsmile:' => ['shade_smile.gif', '19', '19', 'cool smile'],
52+
':coolsmirk:' => ['shade_smirk.gif', '19', '19', 'cool smirk'],
53+
':coolgrin:' => ['shade_grin.gif', '19', '19', 'cool grin'],
54+
':coolhmm:' => ['shade_hmm.gif', '19', '19', 'cool hmm'],
55+
':coolmad:' => ['shade_mad.gif', '19', '19', 'cool mad'],
56+
':coolcheese:' => ['shade_cheese.gif', '19', '19', 'cool cheese'],
57+
':vampire:' => ['vampire.gif', '19', '19', 'vampire'],
58+
':snake:' => ['snake.gif', '19', '19', 'snake'],
59+
':exclaim:' => ['exclaim.gif', '19', '19', 'exclaim'],
60+
':question:' => ['question.gif', '19', '19', 'question']
61+
);

system/helpers/smiley_helper.php

Lines changed: 68 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -26,67 +26,63 @@
2626
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2727
* THE SOFTWARE.
2828
*
29-
* @package CodeIgniter
30-
* @author EllisLab Dev Team
31-
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32-
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (http://bcit.ca/)
33-
* @license http://opensource.org/licenses/MIT MIT License
34-
* @link https://codeigniter.com
35-
* @since Version 1.0.0
29+
* @package CodeIgniter
30+
* @author EllisLab Dev Team
31+
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32+
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (http://bcit.ca/)
33+
* @license http://opensource.org/licenses/MIT MIT License
34+
* @link https://codeigniter.com
35+
* @since Version 1.0.0
3636
* @filesource
3737
*/
38-
defined('BASEPATH') OR exit('No direct script access allowed');
38+
defined('BASEPATH') or exit('No direct script access allowed');
3939

4040
/**
4141
* CodeIgniter Smiley Helpers
4242
*
43-
* @package CodeIgniter
44-
* @subpackage Helpers
45-
* @category Helpers
46-
* @author EllisLab Dev Team
47-
* @link https://codeigniter.com/user_guide/helpers/smiley_helper.html
48-
* @deprecated 3.0.0 This helper is too specific for CI.
43+
* @package CodeIgniter
44+
* @subpackage Helpers
45+
* @category Helpers
46+
* @author EllisLab Dev Team
47+
* @link https://codeigniter.com/user_guide/helpers/smiley_helper.html
48+
* @deprecated 3.0.0 This helper is too specific for CI.
4949
*/
5050

5151
// ------------------------------------------------------------------------
5252

53-
if ( ! function_exists('smiley_js'))
54-
{
53+
if (!function_exists('smiley_js')) {
5554
/**
5655
* Smiley Javascript
5756
*
5857
* Returns the javascript required for the smiley insertion. Optionally takes
5958
* an array of aliases to loosely couple the smiley array to the view.
6059
*
61-
* @param mixed alias name or array of alias->field_id pairs
62-
* @param string field_id if alias name was passed in
63-
* @param bool
64-
* @return array
60+
* @param mixed alias name or array of alias->field_id pairs
61+
* @param string field_id if alias name was passed in
62+
* @param bool
63+
*
64+
* @return array
6565
*/
66-
function smiley_js($alias = '', $field_id = '', $inline = TRUE)
66+
function smiley_js($alias = '', $field_id = '', $inline = true)
6767
{
68-
static $do_setup = TRUE;
68+
static $do_setup = true;
6969
$r = '';
7070

71-
if ($alias !== '' && ! is_array($alias))
72-
{
71+
if ($alias !== '' && !is_array($alias)) {
7372
$alias = array($alias => $field_id);
7473
}
7574

76-
if ($do_setup === TRUE)
77-
{
78-
$do_setup = FALSE;
79-
$m = array();
75+
if ($do_setup === true) {
76+
$do_setup = false;
77+
$m = array();
8078

81-
if (is_array($alias))
82-
{
83-
foreach ($alias as $name => $id)
84-
{
85-
$m[] = '"'.$name.'" : "'.$id.'"';
79+
if (is_array($alias)) {
80+
foreach ($alias as $name => $id) {
81+
$m[] = '"' . $name . '" : "' . $id . '"';
8682
}
8783
}
8884

89-
$m = '{'.implode(',', $m).'}';
85+
$m = '{' . implode(',', $m) . '}';
9086

9187
$r .= <<<EOF
9288
var smiley_map = {$m};
@@ -117,64 +113,56 @@ function insert_smiley(smiley, field_id) {
117113
}
118114
}
119115
EOF;
120-
}
121-
elseif (is_array($alias))
122-
{
123-
foreach ($alias as $name => $id)
124-
{
125-
$r .= 'smiley_map["'.$name.'"] = "'.$id."\";\n";
116+
} elseif (is_array($alias)) {
117+
foreach ($alias as $name => $id) {
118+
$r .= 'smiley_map["' . $name . '"] = "' . $id . "\";\n";
126119
}
127120
}
128121

129122
return ($inline)
130-
? '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'
123+
? '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */' . $r . '// ]]></script>'
131124
: $r;
132125
}
133126
}
134127

135128
// ------------------------------------------------------------------------
136129

137-
if ( ! function_exists('get_clickable_smileys'))
138-
{
130+
if (!function_exists('get_clickable_smileys')) {
139131
/**
140132
* Get Clickable Smileys
141133
*
142134
* Returns an array of image tag links that can be clicked to be inserted
143135
* into a form field.
144136
*
145-
* @param string the URL to the folder containing the smiley images
146-
* @param array
147-
* @return array
137+
* @param string the URL to the folder containing the smiley images
138+
* @param array
139+
*
140+
* @return array
148141
*/
149142
function get_clickable_smileys($image_url, $alias = '')
150143
{
151144
// For backward compatibility with js_insert_smiley
152-
if (is_array($alias))
153-
{
145+
if (is_array($alias)) {
154146
$smileys = $alias;
155-
}
156-
elseif (FALSE === ($smileys = _get_smiley_array()))
157-
{
158-
return FALSE;
147+
} elseif (false === ($smileys = _get_smiley_array())) {
148+
return false;
159149
}
160150

161151
// Add a trailing slash to the file path if needed
162-
$image_url = rtrim($image_url, '/').'/';
152+
$image_url = rtrim($image_url, '/') . '/';
163153

164154
$used = array();
165-
foreach ($smileys as $key => $val)
166-
{
155+
foreach ($smileys as $key => $val) {
167156
// Keep duplicates from being used, which can happen if the
168157
// mapping array contains multiple identical replacements. For example:
169158
// :-) and :) might be replaced with the same image so both smileys
170159
// will be in the array.
171-
if (isset($used[$smileys[$key][0]]))
172-
{
160+
if (isset($used[$smileys[$key][0]])) {
173161
continue;
174162
}
175163

176-
$link[] = '<a href="javascript:void(0);" onclick="insert_smiley(\''.$key.'\', \''.$alias.'\')"><img src="'.$image_url.$smileys[$key][0].'" alt="'.$smileys[$key][3].'" style="width: '.$smileys[$key][1].'; height: '.$smileys[$key][2].'; border: 0;" /></a>';
177-
$used[$smileys[$key][0]] = TRUE;
164+
$link[] = '<a href="javascript:void(0);" onclick="insert_smiley(\'' . $key . '\', \'' . $alias . '\')"><img src="' . $image_url . $smileys[$key][0] . '" alt="' . $smileys[$key][3] . '" style="width: ' . $smileys[$key][1] . '; height: ' . $smileys[$key][2] . '; border: 0;" /></a>';
165+
$used[$smileys[$key][0]] = true;
178166
}
179167

180168
return $link;
@@ -183,31 +171,29 @@ function get_clickable_smileys($image_url, $alias = '')
183171

184172
// ------------------------------------------------------------------------
185173

186-
if ( ! function_exists('parse_smileys'))
187-
{
174+
if (!function_exists('parse_smileys')) {
188175
/**
189176
* Parse Smileys
190177
*
191178
* Takes a string as input and swaps any contained smileys for the actual image
192179
*
193-
* @param string the text to be parsed
194-
* @param string the URL to the folder containing the smiley images
195-
* @param array
196-
* @return string
180+
* @param string the text to be parsed
181+
* @param string the URL to the folder containing the smiley images
182+
* @param array
183+
*
184+
* @return string
197185
*/
198-
function parse_smileys($str = '', $image_url = '', $smileys = NULL)
186+
function parse_smileys($str = '', $image_url = '', $smileys = null)
199187
{
200-
if ($image_url === '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())))
201-
{
188+
if ($image_url === '' or (!is_array($smileys) && false === ($smileys = _get_smiley_array()))) {
202189
return $str;
203190
}
204191

205192
// Add a trailing slash to the file path if needed
206-
$image_url = rtrim($image_url, '/').'/';
193+
$image_url = rtrim($image_url, '/') . '/';
207194

208-
foreach ($smileys as $key => $val)
209-
{
210-
$str = str_replace($key, '<img src="'.$image_url.$smileys[$key][0].'" alt="'.$smileys[$key][3].'" style="width: '.$smileys[$key][1].'; height: '.$smileys[$key][2].'; border: 0;" />', $str);
195+
foreach ($smileys as $key => $val) {
196+
$str = str_replace($key, '<img src="' . $image_url . $smileys[$key][0] . '" alt="' . $smileys[$key][3] . '" style="width: ' . $smileys[$key][1] . '; height: ' . $smileys[$key][2] . '; border: 0;" />', $str);
211197
}
212198

213199
return $str;
@@ -216,35 +202,31 @@ function parse_smileys($str = '', $image_url = '', $smileys = NULL)
216202

217203
// ------------------------------------------------------------------------
218204

219-
if ( ! function_exists('_get_smiley_array'))
220-
{
205+
if (!function_exists('_get_smiley_array')) {
221206
/**
222207
* Get Smiley Array
223208
*
224209
* Fetches the config/smiley.php file
225210
*
226-
* @return mixed
211+
* @return mixed
227212
*/
228213
function _get_smiley_array()
229214
{
230215
static $_smileys;
231216

232-
if ( ! is_array($_smileys))
233-
{
234-
if (file_exists(APPPATH.'config/smileys.php'))
235-
{
236-
include(APPPATH.'config/smileys.php');
217+
if (!is_array($_smileys)) {
218+
if (file_exists(__DIR__ . '/../../config/smileys.php')) {
219+
include(__DIR__ . '/../../config/smileys.php');
237220
}
238221

239-
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
240-
{
241-
include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
222+
if (file_exists(APPPATH . 'config/' . ENVIRONMENT . '/smileys.php')) {
223+
include(APPPATH . 'config/' . ENVIRONMENT . '/smileys.php');
242224
}
243225

244-
if (empty($smileys) OR ! is_array($smileys))
245-
{
226+
if (empty($smileys) or !is_array($smileys)) {
246227
$_smileys = array();
247-
return FALSE;
228+
229+
return false;
248230
}
249231

250232
$_smileys = $smileys;

0 commit comments

Comments
 (0)