From 8ede1a2ecbb62577afd32996956c5feaf7ddf9b6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 5 Oct 2011 13:34:52 -0500 Subject: replacing the old HTML user guide with a Sphinx-managed user guide --- user_guide_src/source/helpers/smiley_helper.rst | 160 ++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 user_guide_src/source/helpers/smiley_helper.rst (limited to 'user_guide_src/source/helpers/smiley_helper.rst') diff --git a/user_guide_src/source/helpers/smiley_helper.rst b/user_guide_src/source/helpers/smiley_helper.rst new file mode 100644 index 000000000..941ba11e3 --- /dev/null +++ b/user_guide_src/source/helpers/smiley_helper.rst @@ -0,0 +1,160 @@ +############# +Smiley Helper +############# + +The Smiley Helper file contains functions that let you manage smileys +(emoticons). + +.. contents:: Page Contents + +Loading this Helper +=================== + +This helper is loaded using the following code + +:: + + $this->load->helper('smiley'); + +Overview +======== + +The Smiley helper has a renderer that takes plain text simileys, like +:-) and turns them into a image representation, like |smile!| + +It also lets you display a set of smiley images that when clicked will +be inserted into a form field. For example, if you have a blog that +allows user commenting you can show the smileys next to the comment +form. Your users can click a desired smiley and with the help of some +JavaScript it will be placed into the form field. + +Clickable Smileys Tutorial +========================== + +Here is an example demonstrating how you might create a set of clickable +smileys next to a form field. This example requires that you first +download and install the smiley images, then create a controller and the +View as described. + +.. important:: Before you begin, please `download the smiley images `_ + and put them in a publicly accessible place on your server. This helper + also assumes you have the smiley replacement array located at + `application/config/smileys.php` + +The Controller +-------------- + +In your `application/controllers/` folder, create a file called +smileys.php and place the code below in it. + +.. important:: Change the URL in the `get_clickable_smileys()` + function below so that it points to your smiley folder. + +You'll notice that in addition to the smiley helper we are using the :doc:`Table Class <../libraries/table>`. + +:: + + load->helper('smiley'); + $this->load->library('table'); + + $image_array = get_clickable_smileys('http://example.com/images/smileys/', 'comments'); + $col_array = $this->table->make_columns($image_array, 8); + + $data['smiley_table'] = $this->table->generate($col_array); + $this->load->view('smiley_view', $data); + } + } + +In your `application/views/` folder, create a file called `smiley_view.php` +and place this code in it: + +:: + + + + Smileys + + + +
+ +
+

Click to insert a smiley!

+ + When you have created the above controller and view, load it by visiting http://www.example.com/index.php/smileys/ + + + +Field Aliases +------------- + +When making changes to a view it can be inconvenient to have the field +id in the controller. To work around this, you can give your smiley +links a generic name that will be tied to a specific id in your view. + +:: + + $image_array = get_smiley_links("http://example.com/images/smileys/", "comment_textarea_alias"); + +To map the alias to the field id, pass them both into the `smiley_js` +function + +:: + + $image_array = smiley_js("comment_textarea_alias", "comments"); + +****************** +Function Reference +****************** + +get_clickable_smileys() +======================= + +Returns an array containing your smiley images wrapped in a clickable +link. You must supply the URL to your smiley folder and a field id or +field alias. + +:: + + $image_array = get_smiley_links("http://example.com/images/smileys/", "comment"); + +Note: Usage of this function without the second parameter, in +combination with `js_insert_smiley` has been deprecated. + +smiley_js() +=========== + +Generates the JavaScript that allows the images to be clicked and +inserted into a form field. If you supplied an alias instead of an id +when generating your smiley links, you need to pass the alias and +corresponding form id into the function. This function is designed to be +placed into the area of your web page. + +:: + + + +Note: This function replaces `js_insert_smiley`, which has been +deprecated. + +parse_smileys() +=============== + +Takes a string of text as input and replaces any contained plain text +smileys into the image equivalent. The first parameter must contain your +string, the second must contain the URL to your smiley folder + +:: + + $str = 'Here are some simileys: :-) ;-)'; + $str = parse_smileys($str, "http://example.com/images/smileys/"); + echo $str; + + +.. |smile!| image:: ../images/smile.gif -- cgit v1.2.3-24-g4f1b