10-24-2014, 08:55 AM
These two helpers are a couple i use in my projects. Not sure if anyone will find them useful or not, but thought i would share them just in case.
the first one is an alias function for both the php functions is_null() and empty()
path/file name: application/helpers/variable_helper.php
the next one contains two files. a config file and a helper file. It converts html to bbcode and bbcode to html.
config file:
in application/config/autoload.php add the below config file to your autoload config array.
path/file name: application/config/bbcode.php
add the below file to your autoload helpers array.
path/file name: application/helpers/bbcode_helper.php
well there you go, hopefully someone finds them useful
the first one is an alias function for both the php functions is_null() and empty()
path/file name: application/helpers/variable_helper.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if (! function_exists('is_null_or_empty'))
{
/**
* this function combines the is_null() and empty() php functions into one check instead of two
*
* @access public
* @param var mixed
* @return boolean
*/
function is_null_or_empty($var)
{
if (is_null($var) OR empty($var))
{
return TRUE;
}
else
{
return FALSE;
}
}
}
the next one contains two files. a config file and a helper file. It converts html to bbcode and bbcode to html.
config file:
in application/config/autoload.php add the below config file to your autoload config array.
path/file name: application/config/bbcode.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| BBCODE
| -------------------------------------------------------------------
| $config['bbcode'] - an array containing the allowable bbcode tags.
|
| $config['htmlcode'] - an array containing the bbcode's html equivalent
|
*/
$config['bbcode'] = array(
'<',
'>',
'[list]',
'[*]',
'[/list]',
'[img]',
'[/img',
'[b]',
'[/b]',
'[u]',
'[/u]',
'[i]',
'[/i]',
'[color="',
'[/color]',
'[size="',
'[/size]',
'[url="',
'[/url]',
'[mail="',
'[/mail]',
'[code]',
'[/code]',
'[quote]',
'[/quote]',
'"]'
);
$config['htmlcode'] = array(
'<',
'>',
'<ul>',
'<li>',
'</ul>',
'<img src="',
'">',
'<b>',
'</b>',
'<u>',
'</u>',
'<i>',
'</i>',
'<span style="color:',
'</span>',
'<span style="font-size:',
'</span>',
'<a href="',
'</a>',
'<a href="mailto:',
'</a>',
'<code>',
'</code>',
'<blockquote>',
'</blockquote>',
'">'
);
add the below file to your autoload helpers array.
path/file name: application/helpers/bbcode_helper.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if (! function_exists('bb2html'))
{
function bb2html($text)
{
$CI =& get_instance();
$bbcode = $CI->config->item('bbcode');
$htmlcode = $CI->config->item('htmlcode');
$j = count($bbcode);
$newtext = $text;
for ($i = 0; $i < $j; $i++)
{
$newtext = str_replace($bbcode[$i], $htmlcode[$i], $newtext);
}
$newtext = xss_clean($newtext);
$newtext = nl2br($newtext);//second pass
return $newtext;
}
}
if (! function_exists('html2bb'))
{
function html2bb($text)
{
$CI =& get_instance();
$bbcode = $CI->config->item('bbcode');
$htmlcode = $CI->config->item('htmlcode');
$j = count($bbcode);
$newtext = $text;
for ($i = 0; $i < $j; $i++)
{
$newtext = str_replace($htmlcode[$i], $bbcode[$i], $newtext);
}
$newtext = xss_clean($newtext);
return $newtext;
}
}
well there you go, hopefully someone finds them useful