Compare commits

..

No commits in common. "823006937af2e19feb6a09e7893194189b28815e" and "fa60f54b150ead6440c53dbd174621f22a5cb55d" have entirely different histories.

4 changed files with 106 additions and 131 deletions

View file

@ -377,15 +377,6 @@ function _cli_add_str_to_translate($msg, $context=null) {
if (!is_null($lang) && _($msg) != "$msg")
return;
// It is a LSformat string with a simple substitution (for instance: "%{test}")?
if (preg_match("/^%[{(][^{(]+[})]$/", $msg)) {
$LSlang_cli_logger -> trace(
"_cli_add_str_to_translate($msg, $context): LSformat string with a simple substitution, ".
"ignore it"
);
return;
}
// Message already exists ?
if (array_key_exists($msg, $data)) {
if ($context && !in_array($context, $data[$msg]['contexts']))
@ -938,9 +929,6 @@ function cli_generate_lang_file($command_args) {
_cli_add_str_to_translate_from_LSconfig("LSobjects.$obj.LSform.layout.*.label");
_cli_add_str_to_translate_from_LSconfig("LSobjects.$obj.LSform.dataEntryForm.*.label");
// LSioFormat
_cli_add_str_to_translate_from_LSconfig("LSobjects.$obj.ioFormat.*.label");
// LSsearch
_cli_add_str_to_translate_from_LSconfig("LSobjects.$obj.LSsearch.predefinedFilters.*");
_cli_add_str_to_translate_from_LSconfig("LSobjects.$obj.LSsearch.extraDisplayedColumns.*.label");

View file

@ -2032,7 +2032,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
$ioFormats = $this -> getConfig('ioFormat');
if (is_array($ioFormats)) {
foreach($ioFormats as $name => $conf) {
$ret[$name] = __((isset($conf['label'])?$conf['label']:$name));
$ret[$name] = _((isset($conf['label'])?$conf['label']:$name));
}
}
return $ret;

View file

@ -20,65 +20,63 @@
******************************************************************************/
/*
* LSFormat : %{[key name][:A][:B][-][! ou _][~][%}}
*
* Extracted fields
* - 0 : full string '%{...}'
* - 1/key : key name
* - 2 : :A
* - 3/substr_a : A
* - 4 : :B
* - 5/substr_b : B
* - 6/modifiers : "!" / "_" / "~" / "%"
*/
define(
'GETFDATA_REGEX',
"/%[{(](?P<key>[A-Za-z0-9]+)(\:(?P<substr_a>-?[0-9])+)?(\:(?P<substr_b>[0-9]+))?(?P<modifiers>[\!\_~%]*)[})]/"
);
/**
* Build LSformat string
* Construction d'une chaine formatée
*
* This function build and return a LSformat string from specified format and provided data.
* Cette fonction retourne la valeur d'une chaine formatée selon le format
* et les données passés en paramètre.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param string $format The LSformat string
* @param string|object|array<string|object> $data Data to build the string
* This parameter could be a string, an object or an array of string or object.
* @param string $meth The name to the method of objet(s) to call to get the replacement value for a
* specified key
* @param string $format Format de la chaine
* @param string $format Les données pour composés la chaine
* Ce paramètre peut être un tableau de string, une string,
* une tableau d'objet ou un objet.
* @param string $format Le nom de la methode de/des objet(s) à appeler pour
* obtenir la valeur de remplacement dans la chaine formatée.
*
* @return string The builded LSformat string
* @return string La chaine formatée
*/
function getFData($format,$data,$meth=NULL) {
$unique=false;
/*
* Format : %{[key name][:A][:B][! ou _][~][%}}
*
* Extracted fields
* - 0 : full string '%{...}'
* - 1 : key name
* - 2 : :A
* - 3 : A
* - 4 : :B
* - 5 : B
* - 6 : "!" / "_" / "~" / "%"
*/
$expr="/%[{(]([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9]+))?([\!\_~%]*)[})]/";
if(!is_array($format)) {
$format=array($format);
$unique=true;
}
for($i=0;$i<count($format);$i++) {
if(is_array($data)) {
if (is_null($meth)) {
while (preg_match(GETFDATA_REGEX, $format[$i], $ch)) {
if (!isset($data[$ch['key']])) {
if ($meth==NULL) {
while (preg_match($expr,$format[$i],$ch)) {
if (!isset($data[$ch[1]])) {
$val = '';
}
elseif (is_array($data[$ch['key']])) {
$val = $data[$ch['key']][0];
elseif (is_array($data[$ch[1]])) {
$val = $data[$ch[1]][0];
}
else {
$val = $data[$ch['key']];
$val = $data[$ch[1]];
}
$val=_getFData_extractAndModify($val,$ch);
$format[$i]=str_replace($ch[0],$val,$format[$i]);
}
}
else {
while (preg_match(GETFDATA_REGEX, $format[$i], $ch)) {
if (method_exists($data[$ch['key']], $meth)) {
$value = $data[$ch['key']] -> $meth();
while (preg_match($expr,$format[$i],$ch)) {
if (method_exists($data[$ch[1]],$meth)) {
$value = $data[$ch[1]] -> $meth();
if (is_array($value)) {
$value = $value[0];
}
@ -86,19 +84,16 @@ function getFData($format, $data, $meth=NULL) {
$format[$i]=str_replace($ch[0],$value,$format[$i]);
}
else {
LSerror :: addErrorCode(
'fct_getFData_01',
array('meth' => $meth, 'obj' => $ch['key'])
);
LSerror :: addErrorCode('fct_getFData_01',array('meth' => $meth,'obj' => $ch[1]));
break;
}
}
}
}
elseif (is_object($data)) {
if (is_null($meth)) {
while (preg_match(GETFDATA_REGEX, $format[$i], $ch)) {
$value = $data -> $ch['key'];
if ($meth==NULL) {
while (preg_match($expr,$format[$i],$ch)) {
$value = $data -> $ch[1];
if (is_array($value)) {
$value = $value[0];
}
@ -107,9 +102,9 @@ function getFData($format, $data, $meth=NULL) {
}
}
else {
while (preg_match(GETFDATA_REGEX, $format[$i], $ch)) {
while (preg_match($expr,$format[$i],$ch)) {
if (method_exists($data,$meth)) {
$value = $data -> $meth($ch['key']);
$value = $data -> $meth($ch[1]);
if (is_array($value)) {
$value = $value[0];
}
@ -117,20 +112,14 @@ function getFData($format, $data, $meth=NULL) {
$format[$i]=str_replace($ch[0],$value,$format[$i]);
}
else {
LSerror :: addErrorCode(
0,
getFData(
_("Function 'getFData' : The method %{meth} of the object %{obj} doesn't exist."),
array('meth' => $meth, 'obj' => get_class($data))
)
);
LSerror :: addErrorCode(0,getFData(_("Function 'getFData' : The method %{meth} of the object %{obj} doesn't exist."),array('meth' => $meth,'obj' => get_class($data))));
break;
}
}
}
}
else {
while (preg_match(GETFDATA_REGEX, $format[$i], $ch)) {
while (preg_match($expr,$format[$i],$ch)) {
$val=_getFData_extractAndModify($data,$ch);
$format[$i]=str_replace($ch[0],$val,$format[$i]);
}
@ -144,63 +133,71 @@ function getFData($format, $data, $meth=NULL) {
function _getFData_extractAndModify($data,$ch) {
/*
* Handle substring parameters (substr_a & substr_b)
* Format : %{[key name][:A][:B][-][! ou _][~][%}}
*
* Extracted fields
* - 0 : full string '%{...}'
* - 1 : key name
* - 2 : :A
* - 3 : A
* - 4 : :B
* - 5 : B
* - 6 : "!" / "_" / "~" / "%"
*/
// If A
if($ch['substr_a']) {
if($ch[3]!="") {
// If A and B
if ($ch['substr_b']) {
if ($ch[5]!="") {
// If A and B=0
if ($ch['substr_b'] == 0) {
if ($ch[5]==0) {
// If A<0 and B=0
if ($ch['substr_a'] < 0) {
$s = mb_strlen(strval($data)) - (-1 * $ch['substr_a']);
$l = mb_strlen(strval($data));
if ($ch[3]<0) {
$s=strlen((string)$data)-(-1*$ch[3]);
$l=strlen((string)$data);
}
// If A >= 0 and B
else {
$s = $ch['substr_a'];
$l = mb_strlen(strval($data));
$s=$ch[3];
$l=strlen((string)$data);
}
}
// If A and B > 0
elseif ($ch['substr_b'] > 0) {
elseif ($ch[5]>0) {
// If A < 0 and B > 0 or A >= 0 and B > 0
$s = $ch['substr_a'];
$l = $ch['substr_b'];
$s=$ch[3];
$l=$ch[5];
}
// If A and B < 0
else {
// If A < 0 and B < 0
if ($ch['substr_a'] < 0) {
$s = $ch['substr_b'];
if ($ch[3]<0) {
$s=$ch[5];
$l=false;
}
// If A >= 0 and B < 0
else {
$s = $ch['substr_a'] + $ch['substr_b'];
$l = abs($ch['substr_b']);
$s=$ch[3]+$ch[5];
$l=abs($ch[5]);
}
}
}
// If only A
else {
if ($ch['substr_a'] < 0) {
$s = $ch['substr_a'];
if ($ch[3]<0) {
$s=$ch[3];
$l=false;
}
else {
$s=0;
$l = $ch['substr_a'];
$l=$ch[3];
}
}
if ($l==false) {
$val = mb_substr(strval($data), $s);
$val=mb_substr((string)$data,$s);
}
else {
$val = mb_substr(strval($data), $s, abs($l));
$val=mb_substr((string)$data,$s, abs($l));
}
}
else {
@ -212,25 +209,22 @@ function _getFData_extractAndModify($data, $ch) {
}
}
/*
* Handle modifiers
*/
if ($ch['modifiers']) {
if ($ch[6]) {
# Without Accent
if (strpos($ch['modifiers'], '~') !== false) {
if (strpos($ch[6], '~')!==false) {
$val = withoutAccents($val);
}
# Upper / Lower case
if (strpos($ch['modifiers'], '!') !== false) {
if (strpos($ch[6], '!')!==false) {
$val=mb_strtoupper($val);
}
elseif (strpos($ch['modifiers'], '_') !== false) {
elseif (strpos($ch[6], '_')!==false) {
$val=mb_strtolower($val);
}
# Escape HTML entities
if (strpos($ch['modifiers'], '%') !== false) {
if (strpos($ch[6], '%')!==false) {
$val = htmlentities($val);
}
}
@ -240,8 +234,9 @@ function _getFData_extractAndModify($data, $ch) {
function getFieldInFormat($format) {
$fields=array();
while (preg_match(GETFDATA_REGEX, $format, $ch)) {
$fields[] = $ch['key'];
$expr='/%[{(]([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9]+))?(-)?(\!|\_)?(~)?(%)?[})]/';
while (preg_match($expr,$format,$ch)) {
$fields[]=$ch[1];
$format=str_replace($ch[0],'',$format);
}
return $fields;

View file

@ -109,10 +109,6 @@ $GLOBALS['LSlang'] = array (
"Company" =>
"Société",
# LSobjects.LSpeople.ioFormat.myfullcsv.label
"Complete CSV" =>
"CSV Complet",
# LSobjects.LSpeople.attrs.pwdHistory.html_options.components.time.label
# LSobjects.LSsysaccount.attrs.pwdHistory.html_options.components.time.label
"Date added to history" =>
@ -697,10 +693,6 @@ $GLOBALS['LSlang'] = array (
"Simple" =>
"Simple",
# LSobjects.LSpeople.ioFormat.mycsv.label
"Simple CSV" =>
"CSV Simple",
# LSobjects.LSpeople.attrs.sambaKickoffTime.help_info
"Specifies the time when the user will be locked down and cannot login any longer." =>
"Détermine la date à partir de laquelle l'utilisateur sera bloqué et ne pourra plus se connecter.",