Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 276 lines (243 sloc) 7.966 kb
<?php /*
ocPortal
Copyright (c) ocProducts, 2004-2012
See text/EN/licence.txt for full licencing information.
NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package core
*/
/**
* Get a list of languages files for the given language. ONLY those that are overridden.
*
* @param ?LANGUAGE_NAME The language (NULL: uses the current language)
* @return array The language files
*/
function get_lang_files($lang=NULL)
{
if (is_null($lang)) $lang=get_site_default_lang();
$_dir=@opendir(get_file_base().'/lang/'.$lang);
$_lang_files=array();
if ($_dir!==false)
{
while (false!==($file=readdir($_dir)))
{
if (($file!='.') && ($file!='..') && ((substr($file,-4)=='.ini') || (substr($file,-3)=='.po')))
{
if (substr($file,-3)=='.po')
{
$file=preg_replace('#\-'.str_replace('#','\#',preg_quote(strtolower($lang))).'$#','',substr($file,0,strlen($file)-3));
} else
{
$file=substr($file,0,strlen($file)-4);
}
$_lang_files[$file]='lang';
}
}
closedir($_dir);
}
$_dir=@opendir(get_custom_file_base().'/lang_custom/'.$lang);
if ($_dir!==false)
{
while (false!==($file=readdir($_dir)))
{
if (($file!='.') && ($file!='..') && ((substr($file,-4)=='.ini') || (substr($file,-3)=='.po')))
{
if (substr($file,-3)=='.po')
{
$file=preg_replace('#\-'.str_replace('#','\#',preg_quote(strtolower($lang))).'$#','',substr($file,0,strlen($file)-3));
} else
{
$file=substr($file,0,strlen($file)-4);
}
$_lang_files[$file]='lang_custom';
}
}
closedir($_dir);
}
if (get_file_base()!=get_custom_file_base())
{
$_dir=@opendir(get_file_base().'/lang_custom/'.$lang);
if ($_dir!==false)
{
while (false!==($file=readdir($_dir)))
{
if (($file!='.') && ($file!='..') && ((substr($file,-4)=='.ini') || (substr($file,-3)=='.po')))
{
if (substr($file,-3)=='.po')
{
$file=preg_replace('#\-'.str_replace('#','\#',preg_quote($lang)).'$#','',substr($file,0,strlen($file)-3));
} else
{
$file=substr($file,0,strlen($file)-4);
}
$_lang_files[$file]='lang_custom';
}
}
closedir($_dir);
}
}
return $_lang_files;
}
/**
* Search the database to find human-readable names for language IDs.
*
* @param array The language IDs (array of AUTO_LINK)
* @return array Human readable names (List of string against same IDs in input array or null for orphan strings)
*/
function find_lang_content_names($ids)
{
static $langidfields=NULL;
if (is_null($langidfields))
{
$query='SELECT m_name,m_table,m_type FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'db_meta';
$all_fields=$GLOBALS['SITE_DB']->query($query);
$langidfields=array();
foreach ($all_fields as $f)
{
if (substr($f['m_type'],-6)=='_TRANS')
$langidfields[]=array('m_name'=>$f['m_name'],'m_table'=>$f['m_table'],'key'=>'');
}
foreach ($langidfields as $i=>$l)
{
foreach ($all_fields as $f)
{
if (($l['m_table']==$f['m_table']) && (substr($f['m_type'],0,1)=='*') && ($l['key']==''))
$langidfields[$i]['key']=$f['m_name'];
}
}
$langidfields[]=array('m_name'=>'config_value','m_table'=>'config','key'=>'the_name');
}
$ret=array();
foreach ($langidfields as $field)
{
$db=$GLOBALS[((substr($field['m_table'],0,2)=='f_')?'FORUM_DB':'SITE_DB')];
if (is_null($db)) continue; // None forum driver
$or_list='';
foreach ($ids as $id)
{
if (!isset($ret[$id])) // Try and lookup anything not found yet
{
if ($or_list!='') $or_list.=' OR ';
$or_list.=($field['m_table']=='config')?db_string_equal_to($field['m_name'],strval($id)):($field['m_name'].'='.strval($id));
}
}
if ($or_list!='')
{
$test=list_to_map($field['m_name'],$db->query('SELECT * FROM '.$db->get_table_prefix().$field['m_table'].' WHERE '.$or_list));
foreach ($ids as $id)
{
if (array_key_exists($id,$test))
{
$cma_hooks=find_all_hooks('systems','content_meta_aware');
foreach (array_keys($cma_hooks) as $hook)
{
require_code('hooks/systems/content_meta_aware/'.$hook);
$ob=object_factory('Hook_content_meta_aware_'.$hook);
$info=$ob->info();
if ($info['table']==$field['m_table'])
{
if ($info['title_field_dereference'])
{
$ret[$id]=$field['m_table'].' \ '.get_translated_text($test[$id][$info['title_field']]).' \ '.$field['m_name'];
} else
{
$ret[$id]=$field['m_table'].' \ '.(is_integer($test[$id][$info['title_field']])?strval($test[$id][$info['title_field']]):$test[$id][$info['title_field']]).' \ '.$field['m_name'];
}
continue 2;
}
}
$ret[$id]=$field['m_table'].' \ '.(is_integer($test[$id][$field['key']])?strval($test[$id][$field['key']]):$test[$id][$field['key']]).' \ '.$field['m_name'];
} else
{
if (!array_key_exists($id,$ret)) $ret[$id]=NULL;
}
}
}
}
return $ret;
}
/**
* Get a nice formatted XHTML listed language file selector for the given language.
*
* @param ?LANGUAGE_NAME The language (NULL: uses the current language)
* @return tempcode The language file selector
*/
function nice_get_lang_files($lang=NULL)
{
$_lang_files=get_lang_files(is_null($lang)?get_site_default_lang():$lang);
ksort($_lang_files);
require_lang('lang');
$lang_files=new ocp_tempcode();
foreach (array_keys($_lang_files) as $lang_file)
{
if (!is_null($lang))
{
$base_map=get_lang_file_map(fallback_lang(),$lang_file,true);
$criticise_map=get_lang_file_map($lang,$lang_file);
$num_translated=0;
$num_english=count($base_map);
foreach ($base_map as $key=>$val)
{
if (array_key_exists($key,$criticise_map)) $num_translated++;
}
$lang_files->attach(form_input_list_entry($lang_file,false,do_lang_tempcode('TRANSLATION_PROGRESS',escape_html($lang_file),escape_html(integer_format($num_translated)),escape_html(integer_format($num_english)))));
} else
{
$lang_files->attach(form_input_list_entry($lang_file,false,$lang_file));
}
}
return $lang_files;
}
/**
* Get the full name of a language. e.g. 'EN' would become 'English'
*
* @param LANGUAGE_NAME The language
* @return string The full name of the language
*/
function lookup_language_full_name($code)
{
global $LANGS_MAP;
if ($LANGS_MAP===NULL)
{
$map_file_a=get_file_base().'/lang/langs.ini';
$map_file_b=get_custom_file_base().'/lang_custom/langs.ini';
if (!is_file($map_file_b)) $map_file_b=$map_file_a;
$LANGS_MAP=better_parse_ini_file($map_file_b);
}
return isset($LANGS_MAP[$code])?$LANGS_MAP[$code]:$code;
}
/**
* Get an array of all the INI description entries in the specified language.
*
* @param LANGUAGE_NAME The language
* @param ?ID_TEXT The language file (NULL: all non-custom language files)
* @return array The language descriptions
*/
function get_lang_file_descriptions($lang,$file=NULL)
{
if (is_null($file))
{
$dh=opendir(get_file_base().'/lang/'.$lang);
$descriptions=array();
while (($f=readdir($dh))!==false)
{
if (substr($f,-4)=='.ini')
$descriptions=array_merge($descriptions,get_lang_file_descriptions($lang,basename($f,'.ini')));
}
return $descriptions;
}
$a=get_custom_file_base().'/lang_custom/'.$lang.'/'.$file.'.ini';
if ((get_custom_file_base()!=get_file_base()) && (!is_file($a)))
$a=get_file_base().'/lang_custom/'.$lang.'/'.$file.'.ini';
$b=(is_file($a))?$a:get_file_base().'/lang/'.$lang.'/'.$file.'.ini';
if (!is_file($b)) $b=get_file_base().'/lang/'.fallback_lang().'/'.$file.'.ini';
$target=array();
require_code('lang_compile');
_get_lang_file_map($b,$target,true);
return $target;
}
Jump to Line
Something went wrong with that request. Please try again.