Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter Smiley Helpers
|
| 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Helpers
|
| 23 | * @category Helpers
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/helpers/smiley_helper.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 26 | */
|
| 27 |
|
| 28 | // ------------------------------------------------------------------------
|
| 29 |
|
| 30 | /**
|
| 31 | * JS Insert Smiley
|
| 32 | *
|
| 33 | * Generates the javascrip function needed to insert smileys into a form field
|
| 34 | *
|
| 35 | * @access public
|
| 36 | * @param string form name
|
| 37 | * @param string field name
|
| 38 | * @return string
|
| 39 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 40 | if (! function_exists('js_insert_smiley'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 41 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 42 | function js_insert_smiley($form_name = '', $form_field = '')
|
| 43 | {
|
| 44 | return <<<EOF
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 45 | <script type="text/javascript">
|
| 46 | function insert_smiley(smiley)
|
| 47 | {
|
| 48 | document.{$form_name}.{$form_field}.value += " " + smiley;
|
| 49 | }
|
| 50 | </script>
|
| 51 | EOF;
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 52 | }
|
| 53 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 54 | // ------------------------------------------------------------------------
|
| 55 |
|
| 56 | /**
|
| 57 | * Get Clickable Smileys
|
| 58 | *
|
| 59 | * Returns an array of image tag links that can be clicked to be inserted
|
| 60 | * into a form field.
|
| 61 | *
|
| 62 | * @access public
|
| 63 | * @param string the URL to the folder containing the smiley images
|
| 64 | * @return array
|
| 65 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 66 | if (! function_exists('get_clickable_smileys'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 67 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 68 | function get_clickable_smileys($image_url = '', $smileys = NULL)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 69 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 70 | if ( ! is_array($smileys))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 71 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 72 | if (FALSE === ($smileys = _get_smiley_array()))
|
| 73 | {
|
| 74 | return $str;
|
| 75 | }
|
| 76 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 77 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 78 | // Add a trailing slash to the file path if needed
|
| 79 | $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 80 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 81 | $used = array();
|
| 82 | foreach ($smileys as $key => $val)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 83 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 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]]))
|
| 89 | {
|
| 90 | continue;
|
| 91 | }
|
| 92 |
|
| 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>";
|
| 94 |
|
| 95 | $used[$smileys[$key][0]] = TRUE;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 96 | }
|
| 97 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 98 | return $link;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 99 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 100 | }
|
| 101 |
|
| 102 | // ------------------------------------------------------------------------
|
| 103 |
|
| 104 | /**
|
| 105 | * Parse Smileys
|
| 106 | *
|
| 107 | * Takes a string as input and swaps any contained smileys for the actual image
|
| 108 | *
|
| 109 | * @access public
|
| 110 | * @param string the text to be parsed
|
| 111 | * @param string the URL to the folder containing the smiley images
|
| 112 | * @return string
|
| 113 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 114 | if (! function_exists('parse_smileys'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 115 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 116 | function parse_smileys($str = '', $image_url = '', $smileys = NULL)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 117 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 118 | if ($image_url == '')
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 119 | {
|
| 120 | return $str;
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 121 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 122 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 123 | if ( ! is_array($smileys))
|
| 124 | {
|
| 125 | if (FALSE === ($smileys = _get_smiley_array()))
|
| 126 | {
|
| 127 | return $str;
|
| 128 | }
|
| 129 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 130 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 131 | // Add a trailing slash to the file path if needed
|
| 132 | $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
|
| 133 |
|
| 134 | foreach ($smileys as $key => $val)
|
| 135 | {
|
| 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);
|
| 137 | }
|
| 138 |
|
| 139 | return $str;
|
| 140 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 141 | }
|
| 142 |
|
| 143 | // ------------------------------------------------------------------------
|
| 144 |
|
| 145 | /**
|
| 146 | * Get Smiley Array
|
| 147 | *
|
| 148 | * Fetches the config/smiley.php file
|
| 149 | *
|
| 150 | * @access private
|
| 151 | * @return mixed
|
| 152 | */
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 153 | if (! function_exists('_get_smiley_array'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 154 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 155 | function _get_smiley_array()
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 156 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 157 | if ( ! file_exists(APPPATH.'config/smileys'.EXT))
|
| 158 | {
|
| 159 | return FALSE;
|
| 160 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 161 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 162 | include(APPPATH.'config/smileys'.EXT);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 163 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 164 | if ( ! isset($smileys) OR ! is_array($smileys))
|
| 165 | {
|
| 166 | return FALSE;
|
| 167 | }
|
| 168 |
|
| 169 | return $smileys;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 170 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 171 | }
|
| 172 |
|
admin | c7e5999 | 2006-10-28 05:21:35 +0000 | [diff] [blame] | 173 | ?> |