<?php
/**
 * Non Secure Site URL
 *
 * Create a local URL based on your basepath. Segments can be passed via the
 * first parameter either as a string or an array.
 *
 * @author Jilani Jidni
 * @access    public
 * @param    string
 * @return    string
 */
function non_secure_site_url($uri = '')
{
    $CI =& get_instance();
    return $CI->config->non_secure_site_url($uri);
}

/**
 *
 * Non Secure Base URL
 *
 * Returns the "non_secure_base_url" item from your config file
 *
 * @author Jilani Jidni
 * @access    public
 * @return    string
 */
function non_secure_base_url()
{
    $CI =& get_instance();
    return $CI->config->slash_item('non_secure_base_url');
}

/**
 * Non Secure Header Redirect
 *
 * Non Secure Header redirect in two flavors
 *
 * @author Jilani Jidni
 * @access    public
 * @param    string    the URL
 * @param    string    the method: location or redirect
 * @return    string
 */
function non_secure_redirect($uri = '', $method = 'location')
{
    switch($method)
    {
        case 'refresh'    : header("Refresh:0;url=".non_secure_site_url($uri));
            break;
        default            : header("Location: ".non_secure_site_url($uri));
            break;
    }
    exit;
}

if(!function_exists('external_redirect'))
{
    function external_redirect($url = '', $method = 'location', $from_app = null)
    {
        $url = html_entity_decode(trim($url));

        if($from_app)
        {
            echo "<script language='javascript'> window.top.location.href='{$url}'; </script>";
            exit;
        }
        
        if(strpos($url, 'http://') != 0 && strpos($url, 'https://') != 0)
        {
            $url = 'http://' .$url;
        }

        switch($method)
        {
            case 'refresh'    : header("Refresh:0;url=" . $url);
                break;
            default            : header("Location: " . $url);
                break;
        }
        exit;
    }
}
?>