Skip to content

Commit d3c6e9c

Browse files
committed
fix: restore Smiley Helper removed in 3.2.0-dev.
1 parent 53115e6 commit d3c6e9c

2 files changed

Lines changed: 319 additions & 0 deletions

File tree

application/config/smileys.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
$smileys = array(
17+
18+
// smiley image name width height alt
19+
20+
':-)' => array('grin.gif', '19', '19', 'grin'),
21+
':lol:' => array('lol.gif', '19', '19', 'LOL'),
22+
':cheese:' => array('cheese.gif', '19', '19', 'cheese'),
23+
':)' => array('smile.gif', '19', '19', 'smile'),
24+
';-)' => array('wink.gif', '19', '19', 'wink'),
25+
';)' => array('wink.gif', '19', '19', 'wink'),
26+
':smirk:' => array('smirk.gif', '19', '19', 'smirk'),
27+
':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'),
28+
':-S' => array('confused.gif', '19', '19', 'confused'),
29+
':wow:' => array('surprise.gif', '19', '19', 'surprised'),
30+
':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'),
31+
':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'),
32+
'%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'),
33+
';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'),
34+
':P' => array('raspberry.gif', '19', '19', 'raspberry'),
35+
':blank:' => array('blank.gif', '19', '19', 'blank stare'),
36+
':long:' => array('longface.gif', '19', '19', 'long face'),
37+
':ohh:' => array('ohh.gif', '19', '19', 'ohh'),
38+
':grrr:' => array('grrr.gif', '19', '19', 'grrr'),
39+
':gulp:' => array('gulp.gif', '19', '19', 'gulp'),
40+
'8-/' => array('ohoh.gif', '19', '19', 'oh oh'),
41+
':down:' => array('downer.gif', '19', '19', 'downer'),
42+
':red:' => array('embarrassed.gif', '19', '19', 'red face'),
43+
':sick:' => array('sick.gif', '19', '19', 'sick'),
44+
':shut:' => array('shuteye.gif', '19', '19', 'shut eye'),
45+
':-/' => array('hmm.gif', '19', '19', 'hmmm'),
46+
'>:(' => array('mad.gif', '19', '19', 'mad'),
47+
':mad:' => array('mad.gif', '19', '19', 'mad'),
48+
'>:-(' => array('angry.gif', '19', '19', 'angry'),
49+
':angry:' => array('angry.gif', '19', '19', 'angry'),
50+
':zip:' => array('zip.gif', '19', '19', 'zipper'),
51+
':kiss:' => array('kiss.gif', '19', '19', 'kiss'),
52+
':ahhh:' => array('shock.gif', '19', '19', 'shock'),
53+
':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'),
54+
':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'),
55+
':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'),
56+
':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'),
57+
':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'),
58+
':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'),
59+
':vampire:' => array('vampire.gif', '19', '19', 'vampire'),
60+
':snake:' => array('snake.gif', '19', '19', 'snake'),
61+
':exclaim:' => array('exclaim.gif', '19', '19', 'exclaim'),
62+
':question:' => array('question.gif', '19', '19', 'question')
63+
64+
);

system/helpers/smiley_helper.php

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
<?php
2+
/**
3+
* CodeIgniter
4+
*
5+
* An open source application development framework for PHP
6+
*
7+
* This content is released under the MIT License (MIT)
8+
*
9+
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining a copy
12+
* of this software and associated documentation files (the "Software"), to deal
13+
* in the Software without restriction, including without limitation the rights
14+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
* copies of the Software, and to permit persons to whom the Software is
16+
* furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in
19+
* all copies or substantial portions of the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
* THE SOFTWARE.
28+
*
29+
* @package CodeIgniter
30+
* @author EllisLab Dev Team
31+
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32+
* @copyright Copyright (c) 2014 - 2016, 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
36+
* @filesource
37+
*/
38+
defined('BASEPATH') OR exit('No direct script access allowed');
39+
40+
/**
41+
* CodeIgniter Smiley Helpers
42+
*
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.
49+
*/
50+
51+
// ------------------------------------------------------------------------
52+
53+
if ( ! function_exists('smiley_js'))
54+
{
55+
/**
56+
* Smiley Javascript
57+
*
58+
* Returns the javascript required for the smiley insertion. Optionally takes
59+
* an array of aliases to loosely couple the smiley array to the view.
60+
*
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
65+
*/
66+
function smiley_js($alias = '', $field_id = '', $inline = TRUE)
67+
{
68+
static $do_setup = TRUE;
69+
$r = '';
70+
71+
if ($alias !== '' && ! is_array($alias))
72+
{
73+
$alias = array($alias => $field_id);
74+
}
75+
76+
if ($do_setup === TRUE)
77+
{
78+
$do_setup = FALSE;
79+
$m = array();
80+
81+
if (is_array($alias))
82+
{
83+
foreach ($alias as $name => $id)
84+
{
85+
$m[] = '"'.$name.'" : "'.$id.'"';
86+
}
87+
}
88+
89+
$m = '{'.implode(',', $m).'}';
90+
91+
$r .= <<<EOF
92+
var smiley_map = {$m};
93+
94+
function insert_smiley(smiley, field_id) {
95+
var el = document.getElementById(field_id), newStart;
96+
97+
if ( ! el && smiley_map[field_id]) {
98+
el = document.getElementById(smiley_map[field_id]);
99+
100+
if ( ! el)
101+
return false;
102+
}
103+
104+
el.focus();
105+
smiley = " " + smiley;
106+
107+
if ('selectionStart' in el) {
108+
newStart = el.selectionStart + smiley.length;
109+
110+
el.value = el.value.substr(0, el.selectionStart) +
111+
smiley +
112+
el.value.substr(el.selectionEnd, el.value.length);
113+
el.setSelectionRange(newStart, newStart);
114+
}
115+
else if (document.selection) {
116+
document.selection.createRange().text = smiley;
117+
}
118+
}
119+
EOF;
120+
}
121+
elseif (is_array($alias))
122+
{
123+
foreach ($alias as $name => $id)
124+
{
125+
$r .= 'smiley_map["'.$name.'"] = "'.$id."\";\n";
126+
}
127+
}
128+
129+
return ($inline)
130+
? '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'
131+
: $r;
132+
}
133+
}
134+
135+
// ------------------------------------------------------------------------
136+
137+
if ( ! function_exists('get_clickable_smileys'))
138+
{
139+
/**
140+
* Get Clickable Smileys
141+
*
142+
* Returns an array of image tag links that can be clicked to be inserted
143+
* into a form field.
144+
*
145+
* @param string the URL to the folder containing the smiley images
146+
* @param array
147+
* @return array
148+
*/
149+
function get_clickable_smileys($image_url, $alias = '')
150+
{
151+
// For backward compatibility with js_insert_smiley
152+
if (is_array($alias))
153+
{
154+
$smileys = $alias;
155+
}
156+
elseif (FALSE === ($smileys = _get_smiley_array()))
157+
{
158+
return FALSE;
159+
}
160+
161+
// Add a trailing slash to the file path if needed
162+
$image_url = rtrim($image_url, '/').'/';
163+
164+
$used = array();
165+
foreach ($smileys as $key => $val)
166+
{
167+
// Keep duplicates from being used, which can happen if the
168+
// mapping array contains multiple identical replacements. For example:
169+
// :-) and :) might be replaced with the same image so both smileys
170+
// will be in the array.
171+
if (isset($used[$smileys[$key][0]]))
172+
{
173+
continue;
174+
}
175+
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;
178+
}
179+
180+
return $link;
181+
}
182+
}
183+
184+
// ------------------------------------------------------------------------
185+
186+
if ( ! function_exists('parse_smileys'))
187+
{
188+
/**
189+
* Parse Smileys
190+
*
191+
* Takes a string as input and swaps any contained smileys for the actual image
192+
*
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
197+
*/
198+
function parse_smileys($str = '', $image_url = '', $smileys = NULL)
199+
{
200+
if ($image_url === '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())))
201+
{
202+
return $str;
203+
}
204+
205+
// Add a trailing slash to the file path if needed
206+
$image_url = rtrim($image_url, '/').'/';
207+
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);
211+
}
212+
213+
return $str;
214+
}
215+
}
216+
217+
// ------------------------------------------------------------------------
218+
219+
if ( ! function_exists('_get_smiley_array'))
220+
{
221+
/**
222+
* Get Smiley Array
223+
*
224+
* Fetches the config/smiley.php file
225+
*
226+
* @return mixed
227+
*/
228+
function _get_smiley_array()
229+
{
230+
static $_smileys;
231+
232+
if ( ! is_array($_smileys))
233+
{
234+
if (file_exists(APPPATH.'config/smileys.php'))
235+
{
236+
include(APPPATH.'config/smileys.php');
237+
}
238+
239+
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
240+
{
241+
include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
242+
}
243+
244+
if (empty($smileys) OR ! is_array($smileys))
245+
{
246+
$_smileys = array();
247+
return FALSE;
248+
}
249+
250+
$_smileys = $smileys;
251+
}
252+
253+
return $_smileys;
254+
}
255+
}

0 commit comments

Comments
 (0)