1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 4.3.2 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008, 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 * Generates the javascrip function needed to insert smileys into a form field
36 * @param string form name
37 * @param string field name
40 if ( ! function_exists('js_insert_smiley'))
42 function js_insert_smiley($form_name = '', $form_field = '')
45 <script type="text/javascript">
46 function insert_smiley(smiley)
48 document.{$form_name}.{$form_field}.value += " " + smiley;
54 // ------------------------------------------------------------------------
57 * Get Clickable Smileys
59 * Returns an array of image tag links that can be clicked to be inserted
63 * @param string the URL to the folder containing the smiley images
66 if ( ! function_exists('get_clickable_smileys'))
68 function get_clickable_smileys($image_url = '', $smileys = NULL)
70 if ( ! is_array($smileys))
72 if (FALSE === ($smileys = _get_smiley_array()))
78 // Add a trailing slash to the file path if needed
79 $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
82 foreach ($smileys as $key => $val)
84 // Keep duplicates from being used, which can happen if the
85 // mapping array contains multiple identical replacements. For example:
86 // :-) and :) might be replaced with the same image so both smileys
87 // will be in the array.
88 if (isset($used[$smileys[$key][0]]))
93 $link[] = "<a href=\"javascript:void(0);\" onClick=\"insert_smiley('".$key."')\"><img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" /></a>";
95 $used[$smileys[$key][0]] = TRUE;
102 // ------------------------------------------------------------------------
107 * Takes a string as input and swaps any contained smileys for the actual image
110 * @param string the text to be parsed
111 * @param string the URL to the folder containing the smiley images
114 if ( ! function_exists('parse_smileys'))
116 function parse_smileys($str = '', $image_url = '', $smileys = NULL)
118 if ($image_url == '')
123 if ( ! is_array($smileys))
125 if (FALSE === ($smileys = _get_smiley_array()))
131 // Add a trailing slash to the file path if needed
132 $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
134 foreach ($smileys as $key => $val)
136 $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);
143 // ------------------------------------------------------------------------
148 * Fetches the config/smiley.php file
153 if ( ! function_exists('_get_smiley_array'))
155 function _get_smiley_array()
157 if ( ! file_exists(APPPATH.'config/smileys'.EXT))
162 include(APPPATH.'config/smileys'.EXT);
164 if ( ! isset($smileys) OR ! is_array($smileys))
174 /* End of file smiley_helper.php */
175 /* Location: ./system/helpers/smiley_helper.php */