From dc40d6bb8897ed60935347a3876145f124ef019c Mon Sep 17 00:00:00 2001 From: Eriksen Costa Paixão Date: Tue, 8 Sep 2009 02:51:46 +0000 Subject: [PATCH] by Eriksen: Corrigido bug na geração de arquivos PDF para Windows e Mac. Caminhos para funções da biblioteca PDFLib --- ieducar/includes/bootstrap.php | 6 ++++++ ieducar/intranet/include/clsPDF.inc.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/ieducar/includes/bootstrap.php b/ieducar/includes/bootstrap.php index 8328f29..f88f560 100644 --- a/ieducar/includes/bootstrap.php +++ b/ieducar/includes/bootstrap.php @@ -37,6 +37,12 @@ if (! version_compare('5.2.0', PHP_VERSION, '<=')) { die('O i-Educar requer o PHP na versão 5.2. A versão instalada de seu PHP (' . PHP_VERSION . ') não é suportada.'); } +define('DS', DIRECTORY_SEPARATOR); + +/** + * Diretório raiz da aplicação (intranet/). + */ +define('APP_ROOT', realpath(dirname(__FILE__) . '/../intranet/')); /* * Altera o include_path, adicionando o caminho a CoreExt, tornando mais diff --git a/ieducar/intranet/include/clsPDF.inc.php b/ieducar/intranet/include/clsPDF.inc.php index 7384eb5..ac41768 100755 --- a/ieducar/intranet/include/clsPDF.inc.php +++ b/ieducar/intranet/include/clsPDF.inc.php @@ -1,7 +1,43 @@ + * + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) + * qualquer versão posterior. + * + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral + * do GNU para mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto + * com este programa; se não, escreva para a Free Software Foundation, Inc., no + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. + * + * @author Eriksen Costa Paixão + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL + * @package Core + * @since Arquivo disponível desde a versão 1.0.0 + * @version $Id$ + */ + +/** + * clsPDF class. + * + * @author Eriksen Costa Paixão + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL + * @package Core + * @since Classe disponível desde a versão 1.0.0 + * @todo Verificar o método PagAgenda() pois este insere a imagem 'imagens/brasao.gif', + * inutilizando a customização do arquivo ieducar.ini + * @version $Id$ + */ class clsPDF { @@ -49,38 +85,37 @@ class clsPDF function OpenFile() { - $caminho = "tmp/"; - $lim_dir = opendir("tmp/"); - while ($lim_file = readdir($lim_dir)) - { - if ($lim_file != '.' && $lim_file != '..') - { - if (!(substr_count($lim_file, date('Y-m-d')))) - { - @unlink("tmp/".$lim_file); + $caminho = 'tmp/'; + $lim_dir = opendir('tmp/'); + $fonte = APP_ROOT . DS . 'arquivos/fontes/FreeMonoBold.ttf'; + + while ($lim_file = readdir($lim_dir)) { + if ($lim_file != '.' && $lim_file != '..') { + if (! (substr_count($lim_file, date('Y-m-d')))) { + @unlink('tmp/' . $lim_file); } } } - $caminho .= date("Y-m-d")."-"; - list($usec, $sec) = explode(" ", microtime()); - $caminho .= substr(md5("{$usec}{$sec}"), 0, 8); - $caminho .= ".pdf"; - $this->caminho = $caminho; + $caminho .= date('Y-m-d') . '-'; + list($usec, $sec) = explode(' ', microtime()); + $caminho .= substr(md5($usec . $sec), 0, 8); + $caminho .= '.pdf'; + + $this->caminho = APP_ROOT . DS . $caminho; $this->LinkArquivo = $caminho; $this->pdf = PDF_new(); - pdf_set_parameter($this->pdf, "FontOutline", "monospaced=arquivos/fontes/FreeMonoBold.ttf"); + pdf_set_parameter($this->pdf, 'FontOutline', 'monospaced=' . $fonte); PDF_open_file($this->pdf, $this->caminho); - PDF_set_info ($this->pdf, "Creator", $this->owner); - PDF_set_info ($this->pdf, "Author", $this->owner); - PDF_set_info ($this->pdf, "Title", $this->titulo); + PDF_set_info($this->pdf, 'Creator', $this->owner); + PDF_set_info($this->pdf, 'Author', $this->owner); + PDF_set_info($this->pdf, 'Title', $this->titulo); - if ($this->depurar) - { - echo "PDF: Objeto criado!
"; - echo "PDF: O objeto foi criado no seguinte local -> ".$this->LinkArquivo."
"; + if ($this->depurar) { + echo 'PDF: Objeto criado!
'; + echo 'PDF: O objeto foi criado no seguinte local -> ' . $this->LinkArquivo . '
'; } $this->OpenPage(); @@ -337,6 +372,11 @@ class clsPDF */ public function insertImageScaled($tipo, $image, $x, $y, $maxWidth) { + $image = realpath($image); + if (! is_readable($image)) { + throw new Exception('Caminho para arquivo de imagem inválido: "' . $image . '"'); + } + $y = $this->altura - $y; $im = pdf_open_image_file($this->pdf, $tipo, $image, '', 0); -- libgit2 0.21.2