Commit dc40d6bb8897ed60935347a3876145f124ef019c
1 parent
399ad60d
Exists in
master
by Eriksen: Corrigido bug na geração de arquivos PDF para Windows e Mac. Caminho…
…s para funções da biblioteca PDFLib
Showing
2 changed files
with
70 additions
and
24 deletions
Show diff stats
ieducar/includes/bootstrap.php
| ... | ... | @@ -37,6 +37,12 @@ if (! version_compare('5.2.0', PHP_VERSION, '<=')) { |
| 37 | 37 | die('O i-Educar requer o PHP na versão 5.2. A versão instalada de seu PHP (' . PHP_VERSION . ') não é suportada.'); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | +define('DS', DIRECTORY_SEPARATOR); | |
| 41 | + | |
| 42 | +/** | |
| 43 | + * Diretório raiz da aplicação (intranet/). | |
| 44 | + */ | |
| 45 | +define('APP_ROOT', realpath(dirname(__FILE__) . '/../intranet/')); | |
| 40 | 46 | |
| 41 | 47 | /* |
| 42 | 48 | * Altera o include_path, adicionando o caminho a CoreExt, tornando mais | ... | ... |
ieducar/intranet/include/clsPDF.inc.php
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - | |
| 4 | - | |
| 3 | +/** | |
| 4 | + * i-Educar - Sistema de gestão escolar | |
| 5 | + * | |
| 6 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
| 7 | + * <ctima@itajai.sc.gov.br> | |
| 8 | + * | |
| 9 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
| 10 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
| 11 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
| 12 | + * qualquer versão posterior. | |
| 13 | + * | |
| 14 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
| 15 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
| 16 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
| 17 | + * do GNU para mais detalhes. | |
| 18 | + * | |
| 19 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
| 20 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
| 21 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
| 22 | + * | |
| 23 | + * @author Eriksen Costa Paixão <eriksen.paixao_bs@cobra.com.br> | |
| 24 | + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL | |
| 25 | + * @package Core | |
| 26 | + * @since Arquivo disponível desde a versão 1.0.0 | |
| 27 | + * @version $Id$ | |
| 28 | + */ | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * clsPDF class. | |
| 32 | + * | |
| 33 | + * @author Eriksen Costa Paixão <eriksen.paixao_bs@cobra.com.br> | |
| 34 | + * @license http://creativecommons.org/licenses/GPL/2.0/legalcode.pt CC GNU GPL | |
| 35 | + * @package Core | |
| 36 | + * @since Classe disponível desde a versão 1.0.0 | |
| 37 | + * @todo Verificar o método PagAgenda() pois este insere a imagem 'imagens/brasao.gif', | |
| 38 | + * inutilizando a customização do arquivo ieducar.ini | |
| 39 | + * @version $Id$ | |
| 40 | + */ | |
| 5 | 41 | class clsPDF |
| 6 | 42 | { |
| 7 | 43 | |
| ... | ... | @@ -49,38 +85,37 @@ class clsPDF |
| 49 | 85 | |
| 50 | 86 | function OpenFile() |
| 51 | 87 | { |
| 52 | - $caminho = "tmp/"; | |
| 53 | - $lim_dir = opendir("tmp/"); | |
| 54 | - while ($lim_file = readdir($lim_dir)) | |
| 55 | - { | |
| 56 | - if ($lim_file != '.' && $lim_file != '..') | |
| 57 | - { | |
| 58 | - if (!(substr_count($lim_file, date('Y-m-d')))) | |
| 59 | - { | |
| 60 | - @unlink("tmp/".$lim_file); | |
| 88 | + $caminho = 'tmp/'; | |
| 89 | + $lim_dir = opendir('tmp/'); | |
| 90 | + $fonte = APP_ROOT . DS . 'arquivos/fontes/FreeMonoBold.ttf'; | |
| 91 | + | |
| 92 | + while ($lim_file = readdir($lim_dir)) { | |
| 93 | + if ($lim_file != '.' && $lim_file != '..') { | |
| 94 | + if (! (substr_count($lim_file, date('Y-m-d')))) { | |
| 95 | + @unlink('tmp/' . $lim_file); | |
| 61 | 96 | } |
| 62 | 97 | } |
| 63 | 98 | } |
| 64 | - $caminho .= date("Y-m-d")."-"; | |
| 65 | - list($usec, $sec) = explode(" ", microtime()); | |
| 66 | - $caminho .= substr(md5("{$usec}{$sec}"), 0, 8); | |
| 67 | - $caminho .= ".pdf"; | |
| 68 | 99 | |
| 69 | - $this->caminho = $caminho; | |
| 100 | + $caminho .= date('Y-m-d') . '-'; | |
| 101 | + list($usec, $sec) = explode(' ', microtime()); | |
| 102 | + $caminho .= substr(md5($usec . $sec), 0, 8); | |
| 103 | + $caminho .= '.pdf'; | |
| 104 | + | |
| 105 | + $this->caminho = APP_ROOT . DS . $caminho; | |
| 70 | 106 | $this->LinkArquivo = $caminho; |
| 71 | 107 | |
| 72 | 108 | $this->pdf = PDF_new(); |
| 73 | - pdf_set_parameter($this->pdf, "FontOutline", "monospaced=arquivos/fontes/FreeMonoBold.ttf"); | |
| 109 | + pdf_set_parameter($this->pdf, 'FontOutline', 'monospaced=' . $fonte); | |
| 74 | 110 | PDF_open_file($this->pdf, $this->caminho); |
| 75 | 111 | |
| 76 | - PDF_set_info ($this->pdf, "Creator", $this->owner); | |
| 77 | - PDF_set_info ($this->pdf, "Author", $this->owner); | |
| 78 | - PDF_set_info ($this->pdf, "Title", $this->titulo); | |
| 112 | + PDF_set_info($this->pdf, 'Creator', $this->owner); | |
| 113 | + PDF_set_info($this->pdf, 'Author', $this->owner); | |
| 114 | + PDF_set_info($this->pdf, 'Title', $this->titulo); | |
| 79 | 115 | |
| 80 | - if ($this->depurar) | |
| 81 | - { | |
| 82 | - echo "<b>PDF:</b> Objeto criado!<br>"; | |
| 83 | - echo "<b>PDF:</b> O objeto foi criado no seguinte local -> ".$this->LinkArquivo."<br>"; | |
| 116 | + if ($this->depurar) { | |
| 117 | + echo '<b>PDF:</b> Objeto criado!<br>'; | |
| 118 | + echo '<b>PDF:</b> O objeto foi criado no seguinte local -> ' . $this->LinkArquivo . '<br>'; | |
| 84 | 119 | } |
| 85 | 120 | |
| 86 | 121 | $this->OpenPage(); |
| ... | ... | @@ -337,6 +372,11 @@ class clsPDF |
| 337 | 372 | */ |
| 338 | 373 | public function insertImageScaled($tipo, $image, $x, $y, $maxWidth) |
| 339 | 374 | { |
| 375 | + $image = realpath($image); | |
| 376 | + if (! is_readable($image)) { | |
| 377 | + throw new Exception('Caminho para arquivo de imagem inválido: "' . $image . '"'); | |
| 378 | + } | |
| 379 | + | |
| 340 | 380 | $y = $this->altura - $y; |
| 341 | 381 | $im = pdf_open_image_file($this->pdf, $tipo, $image, '', 0); |
| 342 | 382 | ... | ... |