2 // include_once($GLOBALS['srcdir'] . '/sql.inc');
3 include_once(dirname(__FILE__
) . '/sql.inc'); // fixes vulnerability with register_globals
5 // Translation function
6 // This is the translation engine
7 function xl($constant,$mode='r',$prepend='',$append='') {
9 if (isset($_SESSION['language_choice'])) {
10 $lang_id=$_SESSION['language_choice'];
17 // language id = 1, so no need to translate
24 // convert new lines to spaces and remove windows end of lines
25 $patterns = array ('/\n/','/\r/');
26 $replace = array (' ','');
27 $constant = preg_replace($patterns, $replace, $constant);
29 // second, attempt translation
30 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
31 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
32 "lang_id='$lang_id' AND constant_name = '" .
33 addslashes($constant) . "' LIMIT 1";
34 $res=SqlStatement($sql);
35 $row=SqlFetchArray($res);
36 $string=$row['definition'];
37 if ($string=='') { $string="$constant"; }
40 $string="$prepend"."$string"."$append";
49 // Added 5-09 by BM for translation of list labels (when applicable)
50 // Wrapper for the above translation function xl()
52 // Only translates if the $GLOBALS['translate_lists'] is set to true.
54 function xl_list_label($constant,$mode='r',$prepend='',$append='') {
55 if ($GLOBALS['translate_lists']) {
58 xl($constant,$mode,$prepend,$append);
61 return xl($constant,$mode,$prepend,$append);
67 echo $prepend.$constant.$append;
70 return $prepend.$constant.$append;
75 // Added 5-09 by BM for translation of layout labels (when applicable)
76 // Wrapper for the translation function xl()
78 // Only translates if the $GLOBALS['translate_layout'] is set to true.
80 function xl_layout_label($constant,$mode='r',$prepend='',$append='') {
81 if ($GLOBALS['translate_layout']) {
84 xl($constant,$mode,$prepend,$append);
87 return xl($constant,$mode,$prepend,$append);
93 echo $prepend.$constant.$append;
96 return $prepend.$constant.$append;
101 // Added 6-2009 by BM for translation of access control group labels
103 // Wrapper for the translation function xl()
105 // Only translates if the $GLOBALS['translate_gacl_groups'] is set to true.
107 function xl_gacl_group($constant,$mode='r',$prepend='',$append='') {
108 if ($GLOBALS['translate_gacl_groups']) {
111 xl($constant,$mode,$prepend,$append);
114 return xl($constant,$mode,$prepend,$append);
120 echo $prepend.$constant.$append;
123 return $prepend.$constant.$append;
128 // ----------------------------------------------------------------------------
132 shows some informations for pages html header
137 function html_header_show() {
139 // Below line was commented by the UTF-8 project on 05-2009 by BM.
140 // We commented this out since we are now standardizing encoding
141 // in the globals.php file.
142 // echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
146 // ----------------------------------------------------------------------------
148 * Returns a string padded to a certain length with another string.
150 * This method behaves exactly like str_pad but is multibyte safe.
152 * @param string $input The string to be padded.
153 * @param int $length The length of the resulting string.
154 * @param string $pad The string to pad the input string with. Must
155 * be in the same charset like the input string.
156 * @param const $type The padding type. One of STR_PAD_LEFT,
157 * STR_PAD_RIGHT, or STR_PAD_BOTH.
158 * @param string $charset The charset of the input and the padding
161 * @return string The padded string.
163 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT
, $charset = 'UTF-8') {
164 mb_internal_encoding($charset);
165 $mb_length = mb_strlen($input, $charset);
166 $sb_length = strlen($input);
167 $pad_length = mb_strlen($pad, $charset);
169 /* Return if we already have the length. */
170 if ($mb_length >= $length) {
174 /* Shortcut for single byte strings. */
175 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
176 return str_pad($input, $length, $pad, $type);
181 $left = $length - $mb_length;
182 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
185 $left = floor(($length - $mb_length) / 2);
186 $right = ceil(($length - $mb_length) / 2);
187 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
189 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
192 $right = $length - $mb_length;
193 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);