Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
a68b704d
Commit
a68b704d
authored
9 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
FIX Must not return error when vars does not exists
parent
80e10158
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/includes/odtphp/Segment.php
+51
-4
51 additions, 4 deletions
htdocs/includes/odtphp/Segment.php
with
51 additions
and
4 deletions
htdocs/includes/odtphp/Segment.php
+
51
−
4
View file @
a68b704d
...
...
@@ -82,9 +82,55 @@ class Segment implements IteratorAggregate, Countable
*/
public
function
merge
()
{
$this
->
xmlParsed
.
=
str_replace
(
array_keys
(
$this
->
vars
),
array_values
(
$this
->
vars
),
$this
->
xml
);
// We concat all file, later we will
// Note: To change style of table-row, we should make a replace here to add attribute
// table:style-name="Table4.A2"
// To provide debug information on line number processed
global
$count
;
if
(
empty
(
$count
))
$count
=
1
;
else
$count
++
;
if
(
empty
(
$this
->
savxml
))
$this
->
savxml
=
$this
->
xml
;
// Sav content of line at first line merged, so we will reuse original for next steps
$this
->
xml
=
$this
->
savxml
;
$tmpvars
=
$this
->
vars
;
// Store into $tmpvars so we won't modify this->vars when completing data with empty values
// Search all tags fou into condition to complete $tmpvars, so we will proceed all tests even if not defined
$reg
=
'@\[!--\sIF\s([{}a-zA-Z0-9\.\,_]+)\s--\]@smU'
;
preg_match_all
(
$reg
,
$this
->
xml
,
$matches
,
PREG_SET_ORDER
);
//var_dump($tmpvars);exit;
foreach
(
$matches
as
$match
)
// For each match, if there is no entry into this->vars, we add it
{
if
(
!
empty
(
$match
[
1
])
&&
!
isset
(
$tmpvars
[
$match
[
1
]]))
{
$tmpvars
[
$match
[
1
]]
=
''
;
// Not defined, so we set it to '', we just need entry into this->vars for next loop
}
}
// Conditionals substitution
// Note: must be done before static substitution, else the variable will be replaced by its value and the conditional won't work anymore
foreach
(
$tmpvars
as
$key
=>
$value
)
{
// If value is true (not 0 nor false nor null nor empty string)
if
(
$value
)
{
// Remove the IF tag
$this
->
xml
=
str_replace
(
'[!-- IF '
.
$key
.
' --]'
,
''
,
$this
->
xml
);
// Remove everything between the ELSE tag (if it exists) and the ENDIF tag
$reg
=
'@(\[!--\sELSE\s'
.
$key
.
'\s--\](.*))?\[!--\sENDIF\s'
.
$key
.
'\s--\]@smU'
;
// U modifier = all quantifiers are non-greedy
$this
->
xml
=
preg_replace
(
$reg
,
''
,
$this
->
xml
);
}
// Else the value is false, then two cases: no ELSE and we're done, or there is at least one place where there is an ELSE clause, then we replace it
else
{
// Find all conditional blocks for this variable: from IF to ELSE and to ENDIF
$reg
=
'@\[!--\sIF\s'
.
$key
.
'\s--\](.*)(\[!--\sELSE\s'
.
$key
.
'\s--\](.*))?\[!--\sENDIF\s'
.
$key
.
'\s--\]@smU'
;
// U modifier = all quantifiers are non-greedy
preg_match_all
(
$reg
,
$this
->
xml
,
$matches
,
PREG_SET_ORDER
);
foreach
(
$matches
as
$match
)
{
// For each match, if there is an ELSE clause, we replace the whole block by the value in the ELSE clause
if
(
!
empty
(
$match
[
3
]))
$this
->
xml
=
str_replace
(
$match
[
0
],
$match
[
3
],
$this
->
xml
);
}
// Cleanup the other conditional blocks (all the others where there were no ELSE clause, we can just remove them altogether)
$this
->
xml
=
preg_replace
(
$reg
,
''
,
$this
->
xml
);
}
}
$this
->
xmlParsed
.
=
str_replace
(
array_keys
(
$tmpvars
),
array_values
(
$tmpvars
),
$this
->
xml
);
if
(
$this
->
hasChildren
())
{
foreach
(
$this
->
children
as
$child
)
{
$this
->
xmlParsed
=
str_replace
(
$child
->
xml
,
(
$child
->
xmlParsed
==
""
)
?
$child
->
merge
()
:
$child
->
xmlParsed
,
$this
->
xmlParsed
);
...
...
@@ -103,6 +149,7 @@ class Segment implements IteratorAggregate, Countable
}
}
$this
->
file
->
close
();
return
$this
->
xmlParsed
;
}
/**
...
...
@@ -136,7 +183,7 @@ class Segment implements IteratorAggregate, Countable
public
function
setVars
(
$key
,
$value
,
$encode
=
true
,
$charset
=
'ISO-8859'
)
{
if
(
strpos
(
$this
->
xml
,
$this
->
odf
->
getConfig
(
'DELIMITER_LEFT'
)
.
$key
.
$this
->
odf
->
getConfig
(
'DELIMITER_RIGHT'
))
===
false
)
{
throw
new
SegmentException
(
"var
$key
not found in
{
$this
->
getName
()
}
"
);
//
throw new SegmentException("var $key not found in {$this->getName()}");
}
$value
=
$this
->
odf
->
htmlToUTFAndPreOdf
(
$value
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment