Merge pull request #822 from FHenry/develop

Qual : PHP Code_Sniffer
This commit is contained in:
Laurent Destailleur 2013-04-11 10:14:03 -07:00
commit 616219c99c
11 changed files with 692 additions and 649 deletions

View File

@ -191,7 +191,9 @@ class doc_generic_order_odt extends ModelePDFCommandes
{ {
$tmpdir=trim($tmpdir); $tmpdir=trim($tmpdir);
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
if (! $tmpdir) { unset($listofdir[$key]); continue; } if (! $tmpdir) {
unset($listofdir[$key]); continue;
}
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
else else
{ {

View File

@ -214,7 +214,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures
{ {
$tmpdir=trim($tmpdir); $tmpdir=trim($tmpdir);
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
if (! $tmpdir) { unset($listofdir[$key]); continue; } if (! $tmpdir) {
unset($listofdir[$key]); continue;
}
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
else else
{ {

View File

@ -125,7 +125,7 @@ class doc_generic_project_odt extends ModelePDFProjects
'object_note_private'=>$object->note_private, 'object_note_private'=>$object->note_private,
'object_note_public'=>$object->note_public, 'object_note_public'=>$object->note_public,
'object_public'=>$object->public, 'object_public'=>$object->public,
'object_statut'=>html_entity_decode($object->getLibStatut()) 'object_statut'=>$object->getLibStatut()
); );
} }
@ -384,6 +384,14 @@ class doc_generic_project_odt extends ModelePDFProjects
return -1; return -1;
} }
// Add odtgeneration hook
if (! is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($this->db);
}
$hookmanager->initHooks(array('odtgeneration'));
global $action;
if (! is_object($outputlangs)) $outputlangs=$langs; if (! is_object($outputlangs)) $outputlangs=$langs;
$sav_charset_output=$outputlangs->charset_output; $sav_charset_output=$outputlangs->charset_output;
$outputlangs->charset_output='UTF-8'; $outputlangs->charset_output='UTF-8';
@ -470,7 +478,6 @@ class doc_generic_project_odt extends ModelePDFProjects
// Make substitutions into odt of user info // Make substitutions into odt of user info
$tmparray=$this->get_substitutionarray_user($user,$outputlangs); $tmparray=$this->get_substitutionarray_user($user,$outputlangs);
//var_dump($tmparray); exit;
foreach($tmparray as $key=>$value) foreach($tmparray as $key=>$value)
{ {
try { try {
@ -504,6 +511,7 @@ class doc_generic_project_odt extends ModelePDFProjects
else // Text else // Text
{ {
$odfHandler->setVars($key, $value, true, 'UTF-8'); $odfHandler->setVars($key, $value, true, 'UTF-8');
$odfHandler->setVarsHeadFooter($key, $value, true, 'UTF-8');
} }
} }
catch(OdfException $e) catch(OdfException $e)
@ -534,6 +542,9 @@ class doc_generic_project_odt extends ModelePDFProjects
// Replace tags of object + external modules // Replace tags of object + external modules
$tmparray=$this->get_substitutionarray_object($object,$outputlangs); $tmparray=$this->get_substitutionarray_object($object,$outputlangs);
complete_substitutions_array($tmparray, $outputlangs, $object); complete_substitutions_array($tmparray, $outputlangs, $object);
// Call the ODTSubstitution hook
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
foreach($tmparray as $key=>$value) foreach($tmparray as $key=>$value)
{ {
try { try {
@ -794,7 +805,6 @@ class doc_generic_project_odt extends ModelePDFProjects
$contact['fullname']=$objectdetail->getFullName($outputlangs,1); $contact['fullname']=$objectdetail->getFullName($outputlangs,1);
$tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs); $tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs);
complete_substitutions_array($tmparray, $outputlangs, $contact, $contact, "completesubstitutionarray_lines");
foreach($tmparray as $key => $val) foreach($tmparray as $key => $val)
{ {
try try
@ -926,7 +936,7 @@ class doc_generic_project_odt extends ModelePDFProjects
$ref_array['amountttc']=''; $ref_array['amountttc']='';
} }
$ref_array['status']=html_entity_decode($element->getLibStatut(0)); $ref_array['status']=$element->getLibStatut(0);
$tmparray=$this->get_substitutionarray_project_reference($ref_array,$outputlangs); $tmparray=$this->get_substitutionarray_project_reference($ref_array,$outputlangs);
@ -958,8 +968,14 @@ class doc_generic_project_odt extends ModelePDFProjects
return -1; return -1;
} }
// Call the beforeODTSave hook
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
// Write new file // Write new file
$odfHandler->saveToDisk($file); $odfHandler->saveToDisk($file);
//$odfHandler->exportAsAttachedPDF($file);
if (! empty($conf->global->MAIN_UMASK)) if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK)); @chmod($file, octdec($conf->global->MAIN_UMASK));

View File

@ -123,7 +123,9 @@ class doc_generic_proposal_odt extends ModelePDFPropales
{ {
$tmpdir=trim($tmpdir); $tmpdir=trim($tmpdir);
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
if (! $tmpdir) { unset($listofdir[$key]); continue; } if (! $tmpdir) {
unset($listofdir[$key]); continue;
}
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
else else
{ {

View File

@ -1,6 +1,4 @@
<?php <?php
require_once 'zip/PclZipProxy.php';
require_once 'zip/PhpZipProxy.php';
require 'Segment.php'; require 'Segment.php';
class OdfException extends Exception class OdfException extends Exception
{} {}
@ -130,6 +128,33 @@ class Odf
return $this; return $this;
} }
/**
* Assing a template variable
*
* @param string $key name of the variable within the template
* @param string $value replacement value
* @param bool $encode if true, special XML characters are encoded
* @throws OdfException
* @return odf
*/
public function setVarsHeadFooter($key, $value, $encode = true, $charset = 'ISO-8859')
{
$tag = $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT'];
// TODO Warning string may be:
// <text:span text:style-name="T13">{</text:span><text:span text:style-name="T12">aaa</text:span><text:span text:style-name="T13">}</text:span>
// instead of {aaa} so we should enhance this function.
//print $key.'-'.$value.'-'.strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']).'<br>';
if (strpos($this->stylesXml, $tag) === false && strpos($this->stylesXml , $tag) === false) {
//if (strpos($this->contentXml, '">'. $key . '</text;span>') === false) {
throw new OdfException("var $key not found in the document");
//}
}
$value = $encode ? htmlspecialchars($value) : $value;
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
$this->vars[$tag] = str_replace("\n", "<text:line-break/>", $value);
return $this;
}
/** /**
* Evaluating php codes inside the ODT and output the buffer (print, echo) inplace of the code * Evaluating php codes inside the ODT and output the buffer (print, echo) inplace of the code
* *

View File

@ -120,7 +120,7 @@ function get_server_name()
/** /**
* is_error * is_error
* *
* @param string $cerr Error value * @param unknown_type $cerr error number
* @return boolean Error key found or not * @return boolean Error key found or not
*/ */
function is_error($cerr) function is_error($cerr)

View File

@ -73,8 +73,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
'New subscription payed', 'New subscription payed',
$sendto, $sendto,
$from, $from,
'New subscription payed '.$fulltag 'New subscription payed '.$fulltag);
);
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
if ($result) if ($result)

View File

@ -103,8 +103,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
'New subscription payed', 'New subscription payed',
$sendto, $sendto,
$from, $from,
'New subscription payed '.$fulltag 'New subscription payed '.$fulltag);
);
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
if ($result) if ($result)

View File

@ -81,8 +81,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
'New subscription payed', 'New subscription payed',
$sendto, $sendto,
$from, $from,
'New subscription payed '.$fulltag 'New subscription payed '.$fulltag);
);
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
if ($result) if ($result)

View File

@ -140,8 +140,7 @@ if ($PAYPALTOKEN)
'New subscription payed', 'New subscription payed',
$sendto, $sendto,
$from, $from,
'New subscription payed '.$fulltag 'New subscription payed '.$fulltag);
);
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
if ($result) if ($result)