Javascriptを使う場合のヘルパー

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   CodeIgniter Package
 * @package    Javascript Helper
 * @author     KUNIHARU Tsujioka <kunitsuji@gmail.com>
 * @copyright  Copyright (c) 2008 KUNIHARU Tsujioka <kunitsuji@gmail.com>
 * @copyright  Copyright (c) 2006-2008 Usagi Project (URL:http://usagi.mynets.jp)
 * @license    New BSD License
 */


/**
 * @param   string script
 * @param   bool   cdata this cdata = true then write CDATA block
 * @access  public
 * @return  string
 */
if (! function_exists('js_codeBlock'))
{
    function js_codeBlock($script = null, $cdata = false)
    {
        $block  = ($script !== null);
        if ($cdata)
        {
            $script = "//<![CDATA[\n" . $script;
            if ($block)
            {
                $script .= "\n//]]>";
            }
        }

        $script = '<script type="text/javascript">' . $script;
        if ($block)
        {
            $script .= '</script>';
        }
        return $script;
    }
}

/**
 * @param   bool   safe this safe = true then write CDATA END block
 * @access  public
 * @return  string
 */
if (! function_exists('js_blockEnd'))
{
    function js_blockEnd($cdata = false)
    {
        $endTag = '';
        if ($cdata)
        {
            $endTag .= "\n//]]>";
        }
        $endTag .= '</script>';
        return $endTag;
    }
}

/**
 * @param   mixd   url
 * @access  public
 * @return  string
 */
if (! function_exists('js_link'))
{
    function js_link($url)
    {
        if (is_array($url))
        {
            $tag    = '';
            foreach ($url as $row)
            {
                $tag .= js_link($row);
            }
            return $tag;
        }
        if (strpos($url, '.js') === false && strpos($url, '?') === false)
        {
            $url .= '.js';
        }
        return '<script type="text/javascript" src="' . $url . '"></script>';
    }
}

/**
 * @param   string
 * @access  public
 * @return  string
 */
if (! function_exists('js_escapeScript'))
{
    function js_escapeScript($script)
    {
        $script = str_replace(array("\r\n", "\n", "\r"), '\n', $script);
        $script = str_replace(array('"', "'"), array('\"', "\\'"), $script);
        return $script;
    }
}

/**
 * @param   string
 * @access  public
 * @return  string
 */
if (! function_exists('js_escapeString'))
{
    function js_escapeString($string)
    {
        $escape = array("\r\n" => '\n',
                        "\r"   => '\n',
                        "\n"   => '\n',
                        '"'    => '\"',
                        "'"    => "\\'"
                        );
        return str_replace(array_keys($escape), array_values($escape), $string);
    }
}

?>