...

World Wide Web Server 2012-07-04 16:07:22 -07:00
parent 65a4dd55f5
commit 3f438d1be3

@ -1,197 +1,7 @@
WIKI
Lang_uri Lib
Lang_uri Library
Supplementary code for URI Language Identifier.
Lang_uri.php
[code]
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* ********** COPYRIGHT-VERSION NOTICE **********
*
* @author osci
* @copyright Copyright (c) 2011, NetID.gr.
* @license Read License Notice Below
* @link http://www.netid.gr/
* @version Version 0.9
*
* *************** CREDITS NOTICE ***************
* This code originated, although quite modified, from
* MY-Url_helper version 0.2 (supplament to wiredsignz's URI Language Identifier)
* @author Luis <luis@piezas.org.es>
* @modified by Ionut <contact@quasiperfect.eu>
*
* *************** LICENSE NOTICE ***************
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
class Lang_uri {
var $uri = ''; //Leave blank for current url
var $slug = array(); //pass array in the format ('lang_abbr'=>'slug-to-add'), ie
var $stripsegment = FALSE; //if needed to delete last segment (when using slug)
var $exclude_current = FALSE; //don't return anything for current language
var $nolink_current = FALSE; //don't return link for current language but display
var $link_open_tag = ''; //open tag for link
var $link_close_tag = ''; //close tag for link
var $nolink_open_tag = ''; //open tag for no link
var $nolink_close_tag = ''; //close tag for no link
var $divider = ''; //divider, ie '<div class="divider"></div>', leave empty for no use
var $link_extra_global = ''; //accepts a string for global link class, ie 'class="lang_links"'
var $link_extra_lang = ''; //array for specific lang details ('lang_abbr'=>'class="some" id="en_lang"'), leave empty for no use
var $lang_useimg = NULL; //Values TRUE/FALSE.if not set it reads setting from config file
var $lang_img_path = 'img/'; //path for flag imgs. needs trailing slash. path is absolute (using base_url()). empty for value from config
var $lang_img_ext = 'png'; //file extension for flag imgs. imgs must have the lang_ as filename, ie en.png, el.png, etc
/**
* Constructor
*
* @access public
* @param array initialization parameters
*/
public function __construct($params = array())
{
log_message('debug', "Lang_uri Class Construct");
if (count($params) > 0)
{
$this->initialize($params);
}
}
/**
* Initialize Preferences
*
* @access public
* @param array initialization parameters
* @return void
*/
function initialize($params = array())
{
if (count($params) > 0)
{
foreach ($params as $key => $val)
{
if (isset($this->$key))
{
$this->$key = $val;
}
}
}
log_message('debug', "Lang_uri Class Initialized");
}
// --------------------------------------------------------------------
/**
* Generate the language uri links
*
* @access public
* @return string
*/
function create_links()
{
log_message('debug', "Lang_uri Class create_links start");
$output = '';
$CI = & get_instance();
if ($this->uri == '') {
$this->uri = $CI->uri->uri_string();
$this->uri = (substr($this->uri, 0, 1) == '/' ? $this->uri : "/$this->uri");
}
$this->uri = ($this->stripsegment) ? substr($this->uri, 0, strrpos($this->uri, '/')) : $this->uri;
$languages = $CI->config->item('lang_desc');
if ($this->lang_useimg===NULL)
{
$this->lang_useimg = $CI->config->item('lang_useimg');
}
if ($this->lang_img_path=='')
{
$this->lang_img_path = $CI->config->item('lang_img_path');
}
$ignore_lang = $CI->config->item('lang_ignore_abbr');
$current_lang = $CI->config->item('language_abbr');
$i=0;
foreach ($languages as $lang => $lang_desc)
{
if (!($this->exclude_current AND $lang==$current_lang))
{
if ($i>0)
{
$output .= $this->divider;
} else {
$i++;
}
if (!($this->nolink_current AND $lang==$current_lang))
{
$output.=$this->link_open_tag.'<a > $ignore_lang) {
$slash = (substr($this->uri, 0, 1) == '/' ? '' : '/');
$new_uri = '/'.$lang.$slash.$this->uri;
} else {
$new_uri = $this->uri;
}
$new_uri = substr_replace($new_uri, '', 0, 1);
if (!empty($this->slug))
{
$slugitem = (! isset($this->slug[$lang]) OR $this->slug[$lang] == "") ? '' : $this->slug[$lang];
$new_uri .= ( $slugitem == '') ? '' : '/' . $slugitem;
}
$output.= $new_uri.'"';
$output.= $this->link_extra_global;
if ($this->link_extra_lang != NULL)
{
$alt_uri .= (! isset($this->link_extra_lang) OR $this->link_extra_lang == "") ? '' : $this->link_extra_lang[$lang];
}
$output.= '>';
if ($this->lang_useimg) {
$output.= '<img >lang_img_path.$lang.'.'.$this->lang_img_ext.'" alt="'.$lang_desc.'"></a>'.$this->link_close_tag;
} else {
$output.= $lang_desc.'</a>'.$this->link_close_tag;
}
} else {
if ($this->lang_useimg) {
$output.= $this->nolink_open_tag.'<img >lang_img_path.$lang.'.'.$this->lang_img_ext.'" alt="'.$lang_desc.'">'.$this->nolink_close_tag;
} else {
$output.=$this->nolink_open_tag.$lang_desc.$this->nolink_close_tag;
}
}
}
}
return $output;
log_message('debug', "Lang_uri Class create_links end");
}
}
// END Lang_uri Class
/* End of file Lang_uri.php */
/* Location: ./application/libraries/Lang_uri.php */
[/code]
File [[File:Lang_uri.zip]]
Installation
copy Lang_uri.php to application/libraries