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
|
| 8 | * @author Rick Ellis
|
| 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
| 10 | * @license http://www.codeignitor.com/user_guide/license.html
|
| 11 | * @link http://www.codeigniter.com
|
| 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
|
| 24 | * @author Rick Ellis
|
| 25 | * @link http://www.codeigniter.com/user_guide/helpers/smiley_helper.html
|
| 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 | */
|
| 40 | function js_insert_smiley($form_name = '', $form_field = '')
|
| 41 | {
|
| 42 | return <<<EOF
|
| 43 | <script type="text/javascript">
|
| 44 | function insert_smiley(smiley)
|
| 45 | {
|
| 46 | document.{$form_name}.{$form_field}.value += " " + smiley;
|
| 47 | }
|
| 48 | </script>
|
| 49 | EOF;
|
| 50 | }
|
| 51 |
|
| 52 | // ------------------------------------------------------------------------
|
| 53 |
|
| 54 | /**
|
| 55 | * Get Clickable Smileys
|
| 56 | *
|
| 57 | * Returns an array of image tag links that can be clicked to be inserted
|
| 58 | * into a form field.
|
| 59 | *
|
| 60 | * @access public
|
| 61 | * @param string the URL to the folder containing the smiley images
|
| 62 | * @return array
|
| 63 | */
|
| 64 | function get_clickable_smileys($image_url = '', $smileys = NULL)
|
| 65 | {
|
| 66 | if ( ! is_array($smileys))
|
| 67 | {
|
| 68 | if (FALSE === ($smileys = _get_smiley_array()))
|
| 69 | {
|
| 70 | return $str;
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | // Add a trailing slash to the file path if needed
|
| 75 | $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
|
| 76 |
|
| 77 | $used = array();
|
| 78 | foreach ($smileys as $key => $val)
|
| 79 | {
|
| 80 | // Keep duplicates from being used, which can happen if the
|
| 81 | // mapping array contains multiple identical replacements. For example:
|
| 82 | // :-) and :) might be replaced with the same image so both smileys
|
| 83 | // will be in the array.
|
| 84 | if (isset($used[$smileys[$key][0]]))
|
| 85 | {
|
| 86 | continue;
|
| 87 | }
|
| 88 |
|
| 89 | $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>";
|
| 90 |
|
| 91 | $used[$smileys[$key][0]] = TRUE;
|
| 92 | }
|
| 93 |
|
| 94 | return $link;
|
| 95 | }
|
| 96 |
|
| 97 | // ------------------------------------------------------------------------
|
| 98 |
|
| 99 | /**
|
| 100 | * Parse Smileys
|
| 101 | *
|
| 102 | * Takes a string as input and swaps any contained smileys for the actual image
|
| 103 | *
|
| 104 | * @access public
|
| 105 | * @param string the text to be parsed
|
| 106 | * @param string the URL to the folder containing the smiley images
|
| 107 | * @return string
|
| 108 | */
|
| 109 | function parse_smileys($str = '', $image_url = '', $smileys = NULL)
|
| 110 | {
|
| 111 | if ($image_url == '')
|
| 112 | {
|
| 113 | return $str;
|
| 114 | }
|
| 115 |
|
| 116 | if ( ! is_array($smileys))
|
| 117 | {
|
| 118 | if (FALSE === ($smileys = _get_smiley_array()))
|
| 119 | {
|
| 120 | return $str;
|
| 121 | }
|
| 122 | }
|
| 123 |
|
| 124 | // Add a trailing slash to the file path if needed
|
| 125 | $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
|
| 126 |
|
| 127 | foreach ($smileys as $key => $val)
|
| 128 | {
|
| 129 | $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);
|
| 130 | }
|
| 131 |
|
| 132 | return $str;
|
| 133 | }
|
| 134 |
|
| 135 | // ------------------------------------------------------------------------
|
| 136 |
|
| 137 | /**
|
| 138 | * Get Smiley Array
|
| 139 | *
|
| 140 | * Fetches the config/smiley.php file
|
| 141 | *
|
| 142 | * @access private
|
| 143 | * @return mixed
|
| 144 | */
|
| 145 | function _get_smiley_array()
|
| 146 | {
|
| 147 | if ( ! file_exists(APPPATH.'config/smileys'.EXT))
|
| 148 | {
|
| 149 | return FALSE;
|
| 150 | }
|
| 151 |
|
| 152 | include(APPPATH.'config/smileys'.EXT);
|
| 153 |
|
| 154 | if ( ! isset($smileys) OR ! is_array($smileys))
|
| 155 | {
|
| 156 | return FALSE;
|
| 157 | }
|
| 158 |
|
| 159 | return $smileys;
|
| 160 | }
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
admin | c7e5999 | 2006-10-28 05:21:35 +0000 | [diff] [blame] | 165 | ?> |