1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
19
* CodeIgniter Smiley Helpers
21
* @package CodeIgniter
24
* @author ExpressionEngine Dev Team
25
* @link http://codeigniter.com/user_guide/helpers/smiley_helper.html
28
// ------------------------------------------------------------------------
33
* Returns the javascript required for the smiley insertion. Optionally takes
34
* an array of aliases to loosely couple the smiley array to the view.
37
* @param mixed alias name or array of alias->field_id pairs
38
* @param string field_id if alias name was passed in
41
if ( ! function_exists('smiley_js'))
43
function smiley_js($alias = '', $field_id = '', $inline = TRUE)
45
static $do_setup = TRUE;
49
if ($alias != '' && ! is_array($alias))
51
$alias = array($alias => $field_id);
54
if ($do_setup === TRUE)
62
foreach ($alias as $name => $id)
64
$m[] = '"'.$name.'" : "'.$id.'"';
68
$m = '{'.implode(',', $m).'}';
71
var smiley_map = {$m};
73
function insert_smiley(smiley, field_id) {
74
var el = document.getElementById(field_id), newStart;
76
if ( ! el && smiley_map[field_id]) {
77
el = document.getElementById(smiley_map[field_id]);
84
smiley = " " + smiley;
86
if ('selectionStart' in el) {
87
newStart = el.selectionStart + smiley.length;
89
el.value = el.value.substr(0, el.selectionStart) +
91
el.value.substr(el.selectionEnd, el.value.length);
92
el.setSelectionRange(newStart, newStart);
94
else if (document.selection) {
95
document.selection.createRange().text = smiley;
102
if (is_array($alias))
104
foreach ($alias as $name => $id)
106
$r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n";
113
return '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>';
122
// ------------------------------------------------------------------------
125
* Get Clickable Smileys
127
* Returns an array of image tag links that can be clicked to be inserted
131
* @param string the URL to the folder containing the smiley images
134
if ( ! function_exists('get_clickable_smileys'))
136
function get_clickable_smileys($image_url, $alias = '', $smileys = NULL)
138
// For backward compatibility with js_insert_smiley
140
if (is_array($alias))
145
if ( ! is_array($smileys))
147
if (FALSE === ($smileys = _get_smiley_array()))
153
// Add a trailing slash to the file path if needed
154
$image_url = rtrim($image_url, '/').'/';
157
foreach ($smileys as $key => $val)
159
// Keep duplicates from being used, which can happen if the
160
// mapping array contains multiple identical replacements. For example:
161
// :-) and :) might be replaced with the same image so both smileys
162
// will be in the array.
163
if (isset($used[$smileys[$key][0]]))
168
$link[] = "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('".$key."', '".$alias."')\"><img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" /></a>";
170
$used[$smileys[$key][0]] = TRUE;
177
// ------------------------------------------------------------------------
182
* Takes a string as input and swaps any contained smileys for the actual image
185
* @param string the text to be parsed
186
* @param string the URL to the folder containing the smiley images
189
if ( ! function_exists('parse_smileys'))
191
function parse_smileys($str = '', $image_url = '', $smileys = NULL)
193
if ($image_url == '')
198
if ( ! is_array($smileys))
200
if (FALSE === ($smileys = _get_smiley_array()))
206
// Add a trailing slash to the file path if needed
207
$image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
209
foreach ($smileys as $key => $val)
211
$str = str_replace($key, "<img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" />", $str);
218
// ------------------------------------------------------------------------
223
* Fetches the config/smiley.php file
228
if ( ! function_exists('_get_smiley_array'))
230
function _get_smiley_array()
232
if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'))
234
include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php');
236
elseif (file_exists(APPPATH.'config/smileys.php'))
238
include(APPPATH.'config/smileys.php');
241
if (isset($smileys) AND is_array($smileys))
250
// ------------------------------------------------------------------------
255
* Generates the javascript function needed to insert smileys into a form field
257
* DEPRECATED as of version 1.7.2, use smiley_js instead
260
* @param string form name
261
* @param string field name
264
if ( ! function_exists('js_insert_smiley'))
266
function js_insert_smiley($form_name = '', $form_field = '')
269
<script type="text/javascript">
270
function insert_smiley(smiley)
272
document.{$form_name}.{$form_field}.value += " " + smiley;
280
/* End of file smiley_helper.php */
281
/* Location: ./system/helpers/smiley_helper.php */
b'\\ No newline at end of file'