fixing code indenting, spacing and user of require_once
[openemr.git] / library / translation.inc.php
bloba47abde427f2ee39dae31a04de9e387d2b47f0ee
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 sqlQuery("SET NAMES utf8");
12 $sql="SELECT * FROM lang_definitions JOIN lang_constants ON " .
13 "lang_definitions.cons_id = lang_constants.cons_id WHERE " .
14 "lang_id='$lang_id' AND constant_name = '" .
15 addslashes($constant) . "' LIMIT 1";
16 $res=SqlStatement($sql);
17 $row=SqlFetchArray($res);
18 $string=$row['definition'];
19 if ($string=='') { $string="$constant"; }
20 $string="$prepend"."$string"."$append";
21 if ($mode=='e'){
22 echo $string;
23 } else {
24 return $string;
29 // ----------------------------------------------------------------------------
30 /**
31 HEADER HTML
33 shows some informations for pages html header
35 @param none
36 @return void
38 function html_header_show() {
39 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> '."\n";
43 // ----------------------------------------------------------------------------
44 /**
45 * Returns a string padded to a certain length with another string.
47 * This method behaves exactly like str_pad but is multibyte safe.
49 * @param string $input The string to be padded.
50 * @param int $length The length of the resulting string.
51 * @param string $pad The string to pad the input string with. Must
52 * be in the same charset like the input string.
53 * @param const $type The padding type. One of STR_PAD_LEFT,
54 * STR_PAD_RIGHT, or STR_PAD_BOTH.
55 * @param string $charset The charset of the input and the padding
56 * strings.
58 * @return string The padded string.
60 function mb_strpad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT, $charset = 'UTF-8') {
61 mb_internal_encoding($charset);
62 $mb_length = mb_strlen($input, $charset);
63 $sb_length = strlen($input);
64 $pad_length = mb_strlen($pad, $charset);
66 /* Return if we already have the length. */
67 if ($mb_length >= $length) {
68 return $input;
71 /* Shortcut for single byte strings. */
72 if ($mb_length == $sb_length && $pad_length == strlen($pad)) {
73 return str_pad($input, $length, $pad, $type);
76 switch ($type) {
77 case STR_PAD_LEFT:
78 $left = $length - $mb_length;
79 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input;
80 break;
81 case STR_PAD_BOTH:
82 $left = floor(($length - $mb_length) / 2);
83 $right = ceil(($length - $mb_length) / 2);
84 $output = mb_substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) .
85 $input .
86 mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
87 break;
88 case STR_PAD_RIGHT:
89 $right = $length - $mb_length;
90 $output = $input . mb_substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset);
91 break;
94 return $output;