summaryrefslogtreecommitdiffstats
path: root/system/helpers/smiley_helper.php
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-01-28 22:00:20 +0100
committerDerek Jones <derek.jones@ellislab.com>2008-01-28 22:00:20 +0100
commit269b942a2bf7b022795e591d9b0ad04526ee7e09 (patch)
treef465bb5a700d4cc5d72ca6e55e251640a46b869b /system/helpers/smiley_helper.php
parenta25530f6594c7ba45b3faa9537fda9f807069759 (diff)
added ability to "extend" helpers
* modified Loader to check for prefixed helpers in application/helpers folder * surrounded provided helper functions with if (! function_exists('foo')) conditionals so the user's helper functions take precedent.
Diffstat (limited to 'system/helpers/smiley_helper.php')
-rw-r--r--system/helpers/smiley_helper.php120
1 files changed, 64 insertions, 56 deletions
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php
index d61ea7828..f4149478c 100644
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -37,9 +37,11 @@
* @param string field name
* @return string
*/
-function js_insert_smiley($form_name = '', $form_field = '')
+if (! function_exists('js_insert_smiley'))
{
-return <<<EOF
+ function js_insert_smiley($form_name = '', $form_field = '')
+ {
+ return <<<EOF
<script type="text/javascript">
function insert_smiley(smiley)
{
@@ -47,8 +49,8 @@ return <<<EOF
}
</script>
EOF;
-}
-
+ }
+}
// ------------------------------------------------------------------------
/**
@@ -61,37 +63,40 @@ EOF;
* @param string the URL to the folder containing the smiley images
* @return array
*/
-function get_clickable_smileys($image_url = '', $smileys = NULL)
+if (! function_exists('get_clickable_smileys'))
{
- if ( ! is_array($smileys))
+ function get_clickable_smileys($image_url = '', $smileys = NULL)
{
- if (FALSE === ($smileys = _get_smiley_array()))
+ if ( ! is_array($smileys))
{
- return $str;
- }
- }
+ if (FALSE === ($smileys = _get_smiley_array()))
+ {
+ return $str;
+ }
+ }
- // Add a trailing slash to the file path if needed
- $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
+ // Add a trailing slash to the file path if needed
+ $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
- $used = array();
- foreach ($smileys as $key => $val)
- {
- // Keep duplicates from being used, which can happen if the
- // mapping array contains multiple identical replacements. For example:
- // :-) and :) might be replaced with the same image so both smileys
- // will be in the array.
- if (isset($used[$smileys[$key][0]]))
+ $used = array();
+ foreach ($smileys as $key => $val)
{
- continue;
- }
+ // Keep duplicates from being used, which can happen if the
+ // mapping array contains multiple identical replacements. For example:
+ // :-) and :) might be replaced with the same image so both smileys
+ // will be in the array.
+ if (isset($used[$smileys[$key][0]]))
+ {
+ continue;
+ }
- $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>";
+ $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>";
- $used[$smileys[$key][0]] = TRUE;
- }
+ $used[$smileys[$key][0]] = TRUE;
+ }
- return $link;
+ return $link;
+ }
}
// ------------------------------------------------------------------------
@@ -106,30 +111,33 @@ function get_clickable_smileys($image_url = '', $smileys = NULL)
* @param string the URL to the folder containing the smiley images
* @return string
*/
-function parse_smileys($str = '', $image_url = '', $smileys = NULL)
+if (! function_exists('parse_smileys'))
{
- if ($image_url == '')
+ function parse_smileys($str = '', $image_url = '', $smileys = NULL)
{
- return $str;
- }
-
- if ( ! is_array($smileys))
- {
- if (FALSE === ($smileys = _get_smiley_array()))
+ if ($image_url == '')
{
return $str;
- }
- }
+ }
+
+ if ( ! is_array($smileys))
+ {
+ if (FALSE === ($smileys = _get_smiley_array()))
+ {
+ return $str;
+ }
+ }
- // Add a trailing slash to the file path if needed
- $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
+ // Add a trailing slash to the file path if needed
+ $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
- foreach ($smileys as $key => $val)
- {
- $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);
- }
+ foreach ($smileys as $key => $val)
+ {
+ $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);
+ }
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -142,24 +150,24 @@ function parse_smileys($str = '', $image_url = '', $smileys = NULL)
* @access private
* @return mixed
*/
-function _get_smiley_array()
+if (! function_exists('_get_smiley_array'))
{
- if ( ! file_exists(APPPATH.'config/smileys'.EXT))
+ function _get_smiley_array()
{
- return FALSE;
- }
+ if ( ! file_exists(APPPATH.'config/smileys'.EXT))
+ {
+ return FALSE;
+ }
- include(APPPATH.'config/smileys'.EXT);
+ include(APPPATH.'config/smileys'.EXT);
- if ( ! isset($smileys) OR ! is_array($smileys))
- {
- return FALSE;
- }
+ if ( ! isset($smileys) OR ! is_array($smileys))
+ {
+ return FALSE;
+ }
- return $smileys;
+ return $smileys;
+ }
}
-
-
-
?> \ No newline at end of file