Sunday, March 29, 2015

my custom application core changes for codeigniter

my custom system changes...

in application/core/Lang.php

function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{
$langfile = str_replace('.php', '', $langfile);

if ($add_suffix == TRUE)
{
$langfile = str_replace('_lang.', '', $langfile).'_lang';
}

$langfile .= '.php';

if (in_array($langfile, $this->is_loaded, TRUE))
{
return;
}

$config =& get_config();

if ($idiom == '')
{
// BOROO edited this code [start]
            //урт нэрийг богино кодоор солиж хэлний санг зохицууллаа
$deft_lang = ( ! isset($config['language'])) ? 'mn' : $config['language'];
$idiom = ($deft_lang == '') ? 'mn' : $deft_lang;
            // BOROO edited this code [end]
}

// Determine where the language file is and load it
if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile))
{
include($alt_path.'language/'.$idiom.'/'.$langfile);
}
else
{
$found = FALSE;

foreach (get_instance()->load->get_package_paths(TRUE) as $package_path)
{
if (file_exists($package_path.'language/'.$idiom.'/'.$langfile))
{
include($package_path.'language/'.$idiom.'/'.$langfile);
$found = TRUE;
break;
}
}

if ($found !== TRUE)
{
show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
}
}


if ( ! isset($lang))
{
log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
return;
}

if ($return == TRUE)
{
return $lang;
}

$this->is_loaded[] = $langfile;
$this->language = array_merge($this->language, $lang);
unset($lang);

log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
return TRUE;
}

in application/core/Router.php


function _set_routing()
{
// Are query strings enabled in the config file?  Normally CI doesn't utilize query strings
// since URI segments are more search-engine friendly, but they can optionally be used.
// If this feature is enabled, we will gather the directory/class/method a little differently
$segments = array();
if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')]))
{
if (isset($_GET[$this->config->item('directory_trigger')]))
{
$this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')])));
$segments[] = $this->fetch_directory();
}

if (isset($_GET[$this->config->item('controller_trigger')]))
{
$this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));
$segments[] = $this->fetch_class();
}

if (isset($_GET[$this->config->item('function_trigger')]))
{
$this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
$segments[] = $this->fetch_method();
}
}

// Load the routes.php file.
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
elseif (is_file(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}

$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
unset($route);

// Set the default controller so we can display it in the event
// the URI doesn't correlated to a valid controller.
$this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);

        // BOROO added this code [start]
        $this->dashboard_controller = (!isset($this->routes['dashboard_controller']) OR $this->routes['dashboard_controller'] == '') ? FALSE : strtolower($this->routes['dashboard_controller']);
        $this->seo_controller = (!isset($this->routes['seo_controller']) OR $this->routes['seo_controller'] == '') ? FALSE : strtolower($this->routes['seo_controller']);
        $this->supported_languages = (!isset($this->routes['supported_languages']) OR empty($this->routes['supported_languages'])) ? array() : $this->routes['supported_languages'];
        // BOROO added this code [end]

// Were there any query string segments?  If so, we'll validate them and bail out since we're done.
if (count($segments) > 0)
{
return $this->_validate_request($segments);
}

// Fetch the complete URI string
$this->uri->_fetch_uri_string();

// Is there a URI string? If not, the default controller specified in the "routes" file will be shown.
if ($this->uri->uri_string == '')
{
return $this->_set_default_controller();
}

// Do we need to remove the URL suffix?
$this->uri->_remove_url_suffix();

// Compile the segments into an array
$this->uri->_explode_segments();

// Parse any custom routing that may exist
$this->_parse_routes();

// Re-index the segment array so that it starts with 1 rather than 0
$this->uri->_reindex_segments();

}


function _set_default_controller()
{
// BOROO edited this code [start]
        //админ санд ондоо контроллер ажиллана
        $default_controller = $this->admin_mode ? $this->dashboard_controller : $this->default_controller;

        if ($default_controller === FALSE) {
            show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file.");
        }
// Is the method being specified?
if (strpos($default_controller, '/') !== FALSE)
{
$x = explode('/', $default_controller);

$this->set_class($x[0]);
$this->set_method($x[1]);
$this->_set_request($x);
}
else
{
$this->set_class($default_controller);
$this->set_method('index');
$this->_set_request(array($default_controller, 'index'));
}
        // BOROO edited this code [end]

// re-index the routed segments array so it starts with 1 rather than 0
$this->uri->_reindex_segments();

log_message('debug', "No URI present. Default controller set.");

}


function _validate_request($segments)
{
        // BOROO added this code [start]
        if (!empty($this->supported_languages) && count($this->supported_languages) > 0) {

            $lang_code = strtolower($segments[0]);

            if (array_key_exists($lang_code, $this->supported_languages)) {

                $this->config->set_item('language', $lang_code);
                $this->set_language($lang_code);

                $segments = array_slice($segments, 1);
            }
        }
        // BOROO added this code [end]
       
if (count($segments) == 0)
{
return $segments;
}

// Does the requested controller exist in the root folder?
if (file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
{
return $segments;
}

// Is the controller in a sub-folder?
if (is_dir(APPPATH.'controllers/'.$segments[0]))
{
            // BOROO added this code [start]
            if (!empty($this->admin_uri) && $this->admin_uri == $segments[0]) {
                $this->admin_mode = TRUE;
            } else {
                if (!empty($this->api_uri) && $this->api_uri == $segments[0]) {
                    $this->api_mode = TRUE;
                }
            }
            // BOROO added this code [end]

// Set the directory and remove it from the segment array
$this->set_directory($segments[0]);
$segments = array_slice($segments, 1);

if (count($segments) > 0)
{
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);

$this->set_directory('');
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');

return $x;
}
else
{
show_404($this->fetch_directory().$segments[0]);
}
}
}
else
{
                // BOROO edited this code [start]
                //админ санд ондоо контроллер ажиллана
                $default_controller = $this->admin_mode ? $this->dashboard_controller : $this->default_controller;

                // Is the method being specified in the route?
                if (strpos($default_controller, '/') !== FALSE) {
                    $x = explode('/', $default_controller);

                    $this->set_class($x[0]);
                    $this->set_method($x[1]);
                } else {
                    $this->set_class($default_controller);
                    $this->set_method('index');
                }
               
                // Does the default controller exist in the sub-folder?
                if (!file_exists(APPPATH . 'controllers/' . $this->fetch_directory() . $default_controller . '.php')) {
                    $this->directory = '';
                    return array();
                }
                // BOROO edited this code [end]

}

return $segments;
}

        // BOROO added this code [start]
        if (count($segments) > 0) {
            if (file_exists(APPPATH . 'controllers/' . $this->fetch_directory() . $segments[0] . '.php')) {
                return $segments;
            }
            if (file_exists(APPPATH . 'controllers/' . $this->fetch_directory() . $this->seo_controller . '.php')) {
                $this->set_class($this->seo_controller);
                array_unshift($segments, $this->seo_controller);
                return $segments;
            } else {
                show_404();
            }

            return $segments;
        }
        // BOROO added this code [end]

// If we've gotten this far it means that the URI does not correlate to a valid
// controller class.  We will now see if there is an override
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);

$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');

return $x;
}


// Nothing else to do at this point but show a 404
show_404($segments[0]);

}

// BOROO added this code [start]
    function is_api_mode() {
        return $this->api_mode;
    }
   
    function is_admin_mode() {
        return $this->admin_mode;
    }
   
    function set_language($language) {
        $this->language = trim($language, '/') . '/';
    }
   
    function fetch_language() {
        return $this->language;
    }
   
    function get_supported_languages() {
        return $this->supported_languages;
    }
    // BOROO added this code [end]

No comments: