remove directory checking, no longer required
[openemr.git] / library / translation.inc.php
blob46f4662dbc6f3c3212b810e421d946d199e950b7
1 <?php
2 // include_once($GLOBALS['srcdir'] . '/sql.inc');
3 include_once(dirname(__FILE__) . '/sql.inc'); // fixes vulnerability with register_globals
5 // this function is related to the interface/language module.
7 function xl($constant,$mode='r',$prepend='',$append='') {
8 $lang_id=LANGUAGE;
10 // utf8 compliant
11 if ($GLOBALS['use_set_names_utf8']) sqlQuery("SET NAMES utf8");
13 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
14 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
15 "lang_id='$lang_id' AND constant_name = '" .
16 addslashes($constant) . "' LIMIT 1";
17 $res=SqlStatement($sql);
18 $row=SqlFetchArray($res);
19 $string=$row['definition'];
20 if ($string=='') { $string="$constant"; }
21 $string="$prepend"."$string"."$append";
22 if ($mode=='e'){
23 echo $string;
24 } else {
25 return $string;
30 // ----------------------------------------------------------------------------
31 /**
32 HEADER HTML
34 shows some informations for pages html header
36 @param none
37 @return void
39 function html_header_show() {
40 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
44 // ----------------------------------------------------------------------------
45 /**
46 * Returns a string padded to a certain length with another string.
48 * This method behaves exactly like str_pad but is multibyte safe.
50 * @param string $input The string to be padded.
51 * @param int $length The length of the resulting string.
52 * @param string $pad The string to pad the input string with. Must
53 * be in the same charset like the input string.
54 * @param const $type The padding type. One of STR_PAD_LEFT,
55 * STR_PAD_RIGHT, or STR_PAD_BOTH.
56 * @param string $charset The charset of the input and the padding
57 * strings.
59 * @return string The padded string.
61 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT, $charset = 'UTF-8') {
62 mb_internal_encoding($charset);
63 $mb_length = mb_strlen($input, $charset);
64 $sb_length = strlen($input);
65 $pad_length = mb_strlen($pad, $charset);
67 /* Return if we already have the length. */
68 if ($mb_length >= $length) {
69 return $input;
72 /* Shortcut for single byte strings. */
73 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
74 return str_pad($input, $length, $pad, $type);
77 switch ($type) {
78 case STR_PAD_LEFT:
79 $left = $length - $mb_length;
80 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
81 break;
82 case STR_PAD_BOTH:
83 $left = floor(($length - $mb_length) / 2);
84 $right = ceil(($length - $mb_length) / 2);
85 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
86 $input .
87 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
88 break;
89 case STR_PAD_RIGHT:
90 $right = $length - $mb_length;
91 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
92 break;
95 return $output;