Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 108 lines (94 sloc) 2.822 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
<?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);
}

Something went wrong with that request. Please try again.