Skip to content

Commit

Permalink
FIX #7420
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 18, 2017
1 parent 0c01c7c commit aba907d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions htdocs/includes/odtphp/Segment.php
Expand Up @@ -24,7 +24,7 @@ class Segment implements IteratorAggregate, Countable
protected $images = array();
protected $odf;
protected $file;

/**
* Constructor
*
Expand Down Expand Up @@ -86,15 +86,15 @@ public function getIterator()
*/
public function merge()
{
// To provide debug information on line number processed
// 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);
Expand All @@ -106,7 +106,7 @@ public function merge()
$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)
Expand All @@ -133,7 +133,7 @@ public function merge()
$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) {
Expand All @@ -143,7 +143,7 @@ public function merge()
}
$reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/sm";
$this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed);
// Miguel Erill 09704/2017 - Add macro replacement to invoice lines
// Miguel Erill 09704/2017 - Add macro replacement to invoice lines
$this->xmlParsed = $this->macroReplace($this->xmlParsed);
$this->file->open($this->odf->getTmpfile());
foreach ($this->images as $imageKey => $imageValue) {
Expand All @@ -155,28 +155,28 @@ public function merge()
}
}
$this->file->close();

return $this->xmlParsed;
}

/**
* Function to replace macros for invoice short and long month, invoice year
*
*
* Substitution occur when the invoice is generated, not considering the invoice date
* so do not (re)generate in a diferent date than the one that the invoice belongs to
* Perhaps it would be better to use the invoice issued date but I still do not know
* how to get it here
*
* Miguel Erill 09/04/2017
*
*
* @param string $value String to convert
*/
public function macroReplace($text)
{
global $langs;

$patterns=array( '__CURRENTDAY__','__CURRENTDAYTEXT__','__CURRENTMONTHSHORT__','__CURRENTMONTH__','__CURRENTYEAR__' );
$values=array( date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y') );
$patterns=array('/__CURRENTDAY__/','/__CURRENTDAYTEXT__/','/__CURRENTMONTHSHORT__/','/__CURRENTMONTH__/','/__CURRENTYEAR__/');
$values=array(date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y'));

$text=preg_replace($patterns, $values, $text);

Expand All @@ -203,7 +203,7 @@ protected function _analyseChildren($xml)
}
return $this;
}

/**
* Assign a template variable to replace
*
Expand Down

0 comments on commit aba907d

Please sign in to comment.