[2000] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * DOMPDF - PHP5 HTML to PDF renderer |
---|
| 4 | * |
---|
| 5 | * File: $RCSfile: image_frame_decorator.cls.php,v $ |
---|
| 6 | * Created on: 2004-08-08 |
---|
| 7 | * |
---|
| 8 | * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca> |
---|
| 9 | * |
---|
| 10 | * This library is free software; you can redistribute it and/or |
---|
| 11 | * modify it under the terms of the GNU Lesser General Public |
---|
| 12 | * License as published by the Free Software Foundation; either |
---|
| 13 | * version 2.1 of the License, or (at your option) any later version. |
---|
| 14 | * |
---|
| 15 | * This library is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * Lesser General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU Lesser General Public License |
---|
| 21 | * along with this library in the file LICENSE.LGPL; if not, write to the |
---|
| 22 | * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
---|
| 23 | * 02111-1307 USA |
---|
| 24 | * |
---|
| 25 | * Alternatively, you may distribute this software under the terms of the |
---|
| 26 | * PHP License, version 3.0 or later. A copy of this license should have |
---|
| 27 | * been distributed with this file in the file LICENSE.PHP . If this is not |
---|
| 28 | * the case, you can obtain a copy at http://www.php.net/license/3_0.txt. |
---|
| 29 | * |
---|
| 30 | * The latest version of DOMPDF might be available at: |
---|
| 31 | * http://www.digitaljunkies.ca/dompdf |
---|
| 32 | * |
---|
| 33 | * @link http://www.digitaljunkies.ca/dompdf |
---|
| 34 | * @copyright 2004 Benj Carson |
---|
| 35 | * @author Benj Carson <benjcarson@digitaljunkies.ca> |
---|
| 36 | * @contributor Helmut Tischer <htischer@weihenstephan.org> |
---|
| 37 | * @package dompdf |
---|
| 38 | * @version 0.5.1 |
---|
| 39 | * |
---|
| 40 | * Changes |
---|
| 41 | * @contributor Helmut Tischer <htischer@weihenstephan.org> |
---|
| 42 | * @version 0.5.1.htischer.20090507 |
---|
| 43 | * - add optional debug output |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | /* $Id: image_frame_decorator.cls.php 186 2009-10-19 22:42:06Z eclecticgeek@gmail.com $ */ |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Decorates frames for image layout and rendering |
---|
| 50 | * |
---|
| 51 | * @access private |
---|
| 52 | * @package dompdf |
---|
| 53 | */ |
---|
| 54 | class Image_Frame_Decorator extends Frame_Decorator { |
---|
| 55 | |
---|
| 56 | /** |
---|
| 57 | * Array of downloaded images. Cached so that identical images are |
---|
| 58 | * not needlessly downloaded. |
---|
| 59 | * |
---|
| 60 | * @var array |
---|
| 61 | */ |
---|
| 62 | static protected $_cache = array(); |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * The path to the image file (note that remote images are |
---|
| 66 | * downloaded locally to DOMPDF_TEMP_DIR). |
---|
| 67 | * |
---|
| 68 | * @var string |
---|
| 69 | */ |
---|
| 70 | protected $_image_url; |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | * The image's file extension (i.e. png, jpeg, gif) |
---|
| 74 | * |
---|
| 75 | * @var string |
---|
| 76 | */ |
---|
| 77 | protected $_image_ext; |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * Class constructor |
---|
| 81 | * |
---|
| 82 | * @param Frame $frame the frame to decorate |
---|
| 83 | * @param DOMPDF $dompdf the document's dompdf object (required to resolve relative & remote urls) |
---|
| 84 | */ |
---|
| 85 | function __construct(Frame $frame, DOMPDF $dompdf) { |
---|
| 86 | global $_dompdf_warnings; |
---|
| 87 | |
---|
| 88 | parent::__construct($frame, $dompdf); |
---|
| 89 | $url = $frame->get_node()->getAttribute("src"); |
---|
| 90 | |
---|
| 91 | //debugpng |
---|
| 92 | if (DEBUGPNG) print '[__construct '.$url.']'; |
---|
| 93 | |
---|
| 94 | list($this->_image_url, $this->_image_ext) = Image_Cache::resolve_url($url, |
---|
| 95 | $dompdf->get_protocol(), |
---|
| 96 | $dompdf->get_host(), |
---|
| 97 | $dompdf->get_base_path()); |
---|
| 98 | |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * Return the image's url |
---|
| 103 | * |
---|
| 104 | * @return string The url of this image |
---|
| 105 | */ |
---|
| 106 | function get_image_url() { |
---|
| 107 | return $this->_image_url; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | * Return the image's file extension |
---|
| 112 | * |
---|
| 113 | * @return string The image's file extension |
---|
| 114 | */ |
---|
| 115 | function get_image_ext() { |
---|
| 116 | return $this->_image_ext; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * Unlink all cached images (i.e. temporary images either downloaded |
---|
| 121 | * or converted) |
---|
| 122 | */ |
---|
| 123 | static function clear_image_cache() { |
---|
| 124 | if ( count(self::$_cache) ) { |
---|
| 125 | foreach (self::$_cache as $file) |
---|
| 126 | //debugpng |
---|
| 127 | if (DEBUGPNG) print '[clear_image_cache unlink '.$file.']'; |
---|
| 128 | if (!DEBUGKEEPTEMP) |
---|
| 129 | unlink($file); |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | ?> |
---|