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 108 lines (94 sloc) 2.822 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
*/
/**
* Helper function for *_text_file
*
* @param string The file name (without .txt)
* @param ?LANGUAGE_NAME The language to load from (NULL: none) (blank: search)
* @return string The path to the file
*/
function _find_text_file_path($codename,$lang)
{
if (is_null($lang))
{
$langs=array('');
}
elseif ($lang!='')
{
$langs=array($lang);
} else
{
$langs=array(user_lang());
if (get_site_default_lang()!=user_lang()) $langs[]=get_site_default_lang();
if (fallback_lang()!=get_site_default_lang()) $langs[]=fallback_lang();
}
$i=0;
$path='';
do
{
$lang=$langs[$i];
$path=get_custom_file_base().'/text_custom/'.$lang.'/'.$codename.'.txt';
if (!file_exists($path))
{
$path=get_file_base().'/text/'.$lang.'/'.$codename.'.txt';
}
$i++;
}
while ((!file_exists($path)) && (array_key_exists($i,$langs)));
if (!file_exists($path)) $path='';
return $path;
}
/**
* Read a text file, using the _custom system
*
* @param string The file name (without .txt)
* @param ?LANGUAGE_NAME The language to load from (NULL: none) (blank: search)
* @param boolean Whether to tolerate missing files
* @return string The file contents
*/
function read_text_file($codename,$lang=NULL,$missing_blank=false)
{
$path=_find_text_file_path($codename,$lang);
$in=@file_get_contents($path,FILE_TEXT);
if ($in===false)
{
if ($missing_blank) return '';
warn_exit(do_lang_tempcode('MISSING_TEXT_FILE',escape_html($codename)));
}
$in=unixify_line_format($in);
return $in;
}
/**
* Write a text file, using the _custom system
*
* @param string The file name (without .txt)
* @param ?LANGUAGE_NAME The language to write for (NULL: none) (blank: search)
* @param string The data to write
*/
function write_text_file($codename,$lang,$out)
{
$xpath=_find_text_file_path($codename,$lang);
if ($xpath=='')
{
$xpath=get_file_base().'/text/'.user_lang().'/'.$codename.'.txt';
}
$path=str_replace(get_file_base().'/text/',get_custom_file_base().'/text_custom/',$xpath);
$myfile=@fopen($path,'wt');
if ($myfile===false) intelligent_write_error($path);
$out=unixify_line_format($out);
if (fwrite($myfile,$out)<strlen($out)) warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
fclose($myfile);
fix_permissions($path);
sync_file($path);
}
Jump to Line
Something went wrong with that request. Please try again.