blob: 5de1d83bbd2f73f9bddcce058bd37bbc2c6ce022 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001#############
2Smiley Helper
3#############
4
5The Smiley Helper file contains functions that let you manage smileys
6(emoticons).
7
Andrey Andreev21c3c222014-12-04 12:10:00 +02008.. important:: The Smiley helper is DEPRECATED and should not be used.
9 It is currently only kept for backwards compatibility.
10
Derek Jonesf33091f2013-07-19 16:44:19 -070011.. contents::
12 :local:
13
14.. raw:: html
15
16 <div class="custom-index container"></div>
Derek Jones8ede1a22011-10-05 13:34:52 -050017
18Loading this Helper
19===================
20
Andrey Andreev53b8ef52012-11-08 21:38:53 +020021This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050022
23 $this->load->helper('smiley');
24
25Overview
26========
27
vlakoff2efd1f22013-08-06 17:31:48 +020028The Smiley helper has a renderer that takes plain text smileys, like
Derek Jones8ede1a22011-10-05 13:34:52 -050029:-) and turns them into a image representation, like |smile!|
30
31It also lets you display a set of smiley images that when clicked will
32be inserted into a form field. For example, if you have a blog that
33allows user commenting you can show the smileys next to the comment
34form. Your users can click a desired smiley and with the help of some
35JavaScript it will be placed into the form field.
36
37Clickable Smileys Tutorial
38==========================
39
40Here is an example demonstrating how you might create a set of clickable
41smileys next to a form field. This example requires that you first
42download and install the smiley images, then create a controller and the
43View as described.
44
Andrey Andreev53b8ef52012-11-08 21:38:53 +020045.. important:: Before you begin, please `download the smiley images
Steven Crothersd2001232013-07-03 02:18:00 -070046 <http://ellislab.com/asset/ci_download_files/smileys.zip>`_
Andrey Andreev53b8ef52012-11-08 21:38:53 +020047 and put them in a publicly accessible place on your server.
48 This helper also assumes you have the smiley replacement array
49 located at `application/config/smileys.php`
Derek Jones8ede1a22011-10-05 13:34:52 -050050
51The Controller
52--------------
53
vlakoff1c757802013-08-06 20:25:14 +020054In your **application/controllers/** directory, create a file called
vlakoff2efd1f22013-08-06 17:31:48 +020055Smileys.php and place the code below in it.
Derek Jones8ede1a22011-10-05 13:34:52 -050056
Derek Jones123bb202013-07-19 16:37:51 -070057.. important:: Change the URL in the :func:`get_clickable_smileys()`
Derek Jones8ede1a22011-10-05 13:34:52 -050058 function below so that it points to your smiley folder.
59
Andrey Andreev53b8ef52012-11-08 21:38:53 +020060You'll notice that in addition to the smiley helper, we are also using
61the :doc:`Table Class <../libraries/table>`::
Derek Jones8ede1a22011-10-05 13:34:52 -050062
63 <?php
64
65 class Smileys extends CI_Controller {
66
Andrey Andreev53b8ef52012-11-08 21:38:53 +020067 public function index()
Derek Jones8ede1a22011-10-05 13:34:52 -050068 {
69 $this->load->helper('smiley');
70 $this->load->library('table');
71
72 $image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comments');
73 $col_array = $this->table->make_columns($image_array, 8);
74
75 $data['smiley_table'] = $this->table->generate($col_array);
76 $this->load->view('smiley_view', $data);
77 }
Andrey Andreev53b8ef52012-11-08 21:38:53 +020078
Derek Jones8ede1a22011-10-05 13:34:52 -050079 }
80
vlakoff787fe132014-04-14 14:45:36 +020081In your **application/views/** directory, create a file called **smiley_view.php**
Andrey Andreev53b8ef52012-11-08 21:38:53 +020082and place this code in it::
Derek Jones8ede1a22011-10-05 13:34:52 -050083
84 <html>
85 <head>
86 <title>Smileys</title>
87 <?php echo smiley_js(); ?>
88 </head>
89 <body>
90 <form name="blog">
91 <textarea name="comments" id="comments" cols="40" rows="4"></textarea>
92 </form>
93 <p>Click to insert a smiley!</p>
94 <?php echo $smiley_table; ?> </body> </html>
95 When you have created the above controller and view, load it by visiting http://www.example.com/index.php/smileys/
96 </body>
97 </html>
98
99Field Aliases
100-------------
101
102When making changes to a view it can be inconvenient to have the field
103id in the controller. To work around this, you can give your smiley
104links a generic name that will be tied to a specific id in your view.
105
106::
107
108 $image_array = get_smiley_links("http://example.com/images/smileys/", "comment_textarea_alias");
109
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200110To map the alias to the field id, pass them both into the
Derek Jones123bb202013-07-19 16:37:51 -0700111:func:`smiley_js()` function::
Derek Jones8ede1a22011-10-05 13:34:52 -0500112
113 $image_array = smiley_js("comment_textarea_alias", "comments");
114
Derek Jonesf33091f2013-07-19 16:44:19 -0700115Available Functions
116===================
Derek Jones8ede1a22011-10-05 13:34:52 -0500117
Derek Jonesf33091f2013-07-19 16:44:19 -0700118.. function:: get_clickable_smileys($image_url[, $alias = ''[, $smileys = NULL]])
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200119
120 :param string $image_url: URL path to the smileys directory
121 :param string $alias: Field alias
Andrey Andreev3de130c2014-02-07 23:31:49 +0200122 :returns: An array of ready to use smileys
123 :rtype: array
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200124
Derek Jonesf33091f2013-07-19 16:44:19 -0700125 Returns an array containing your smiley images wrapped in a clickable
126 link. You must supply the URL to your smiley folder and a field id or
127 field alias.
Derek Jones8ede1a22011-10-05 13:34:52 -0500128
Derek Jonesf33091f2013-07-19 16:44:19 -0700129 Example::
Derek Jones8ede1a22011-10-05 13:34:52 -0500130
Andrey Andreev3de130c2014-02-07 23:31:49 +0200131 $image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comment');
Derek Jones8ede1a22011-10-05 13:34:52 -0500132
Derek Jonesf33091f2013-07-19 16:44:19 -0700133.. function:: smiley_js([$alias = ''[, $field_id = ''[, $inline = TRUE]]])
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200134
135 :param string $alias: Field alias
136 :param string $field_id: Field ID
137 :param bool $inline: Whether we're inserting an inline smiley
Andrey Andreev3de130c2014-02-07 23:31:49 +0200138 :returns: Smiley-enabling JavaScript code
139 :rtype: string
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200140
Derek Jonesf33091f2013-07-19 16:44:19 -0700141 Generates the JavaScript that allows the images to be clicked and
142 inserted into a form field. If you supplied an alias instead of an id
143 when generating your smiley links, you need to pass the alias and
144 corresponding form id into the function. This function is designed to be
145 placed into the <head> area of your web page.
Derek Jones8ede1a22011-10-05 13:34:52 -0500146
Derek Jonesf33091f2013-07-19 16:44:19 -0700147 Example::
Derek Jones8ede1a22011-10-05 13:34:52 -0500148
Derek Jonesf33091f2013-07-19 16:44:19 -0700149 <?php echo smiley_js(); ?>
Derek Jones8ede1a22011-10-05 13:34:52 -0500150
Derek Jonesf33091f2013-07-19 16:44:19 -0700151.. function:: parse_smileys([$str = ''[, $image_url = ''[, $smileys = NULL]]])
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200152
153 :param string $str: Text containing smiley codes
154 :param string $image_url: URL path to the smileys directory
155 :param array $smileys: An array of smileys
Andrey Andreev3de130c2014-02-07 23:31:49 +0200156 :returns: Parsed smileys
157 :rtype: string
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200158
Derek Jonesf33091f2013-07-19 16:44:19 -0700159 Takes a string of text as input and replaces any contained plain text
160 smileys into the image equivalent. The first parameter must contain your
161 string, the second must contain the URL to your smiley folder
Derek Jones8ede1a22011-10-05 13:34:52 -0500162
Derek Jonesf33091f2013-07-19 16:44:19 -0700163 Example::
Derek Jones8ede1a22011-10-05 13:34:52 -0500164
vlakoff2efd1f22013-08-06 17:31:48 +0200165 $str = 'Here are some smileys: :-) ;-)';
Andrey Andreevea801ab2014-01-20 15:03:43 +0200166 $str = parse_smileys($str, 'http://example.com/images/smileys/');
Derek Jonesf33091f2013-07-19 16:44:19 -0700167 echo $str;
Derek Jones8ede1a22011-10-05 13:34:52 -0500168
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200169.. |smile!| image:: ../images/smile.gif