<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Alternative languages helper
*
* Returns a string with links to the content in alternative languages
*
* version 0.2
* @author Luis <luis@piezas.org.es>
*/

function alt_site_url($uri = ''){
    $CI =& get_instance();
    $actual_lang=$CI->uri->segment(1);
    $languages=$CI->config->item('lang_desc');
    $ignore_lang=$CI->config->item('lang_ignore');
    if (empty($actual_lang)){
        $uri=$ignore_lang.$CI->uri->uri_string();
        $actual_lang=$ignore_lang;
    }else{
        if (!array_key_exists($actual_lang,$languages)){
            $uri=$ignore_lang.$CI->uri->uri_string();
            $actual_lang=$ignore_lang;
        }else{
            $uri=$CI->uri->uri_string();
            $uri=substr_replace($uri,'',0,1);
        }
    }
    $alt_url='';
    foreach ($languages as $lang=>$lang_desc){
		$alt_url.='<a href="'.$CI->config->slash_item('base_url');
		$new_uri=ereg_replace('^'.$actual_lang,$lang,$uri);
		$alt_url.=$new_uri;
		$alt_url.='">'.$lang_desc.'</a> | ';
    }
    return $alt_url;
}
