Ejemplo n.º 1
0
 function get($url, &$pipeline)
 {
     global $g_config;
     if (!$g_config['renderimages']) {
         return null;
     }
     global $g_image_cache;
     // Check if this URL have been cached
     //
     if (isset($g_image_cache[$url])) {
         //      return do_image_open($g_image_cache[$url]);
         return $g_image_cache[$url]['handle'];
     }
     // Download image; we should do it before we call do_image_open,
     // as it tries to open image file twice: first to determine image type
     // and second to actually create the image - PHP url wrappers do no caching
     // at all
     //
     // only do this for remote files that are prefixed with a protocol
     if (substr($url, 0, 8) == 'file:///') {
         // we have a local file, just remember the file in the cache
         $filename = substr($url, 8);
         $cached = 0;
     } else {
         $filename = Image::make_cache_filename($url);
         // REQUIRES: PHP 4.3.0+
         // we suppress warning messages, as missing image files will cause 'copy' to print
         // several warnings
         //
         // @TODO: change to fetcher class call
         //
         $data = $pipeline->fetch($url);
         if (is_null($data)) {
             error_log("Cannot fetch image: " . $url);
             return null;
         }
         $file = fopen($filename, 'wb');
         fwrite($file, $data->content);
         fclose($file);
         $pipeline->pop_base_url();
         $cached = 1;
         //     if (!@copy($url, $filename)) {
         //       error_log("Cannot fetch image: ".$url);
         //       return null;
         //     };
     }
     // register it in the cached objects array
     //
     // $g_image_cache[$url] = $filename;
     $g_image_cache[$url] = array('filename' => $filename, 'handle' => do_image_open($filename), 'cached' => $cached);
     // return image
     //
     // return do_image_open($filename);
     return $g_image_cache[$url]['handle'];
 }
 function get($url, &$pipeline)
 {
     global $g_config;
     if (!$g_config['renderimages']) {
         return null;
     }
     global $g_image_cache;
     // Check if this URL have been cached
     //
     if (isset($g_image_cache[$url])) {
         //      return do_image_open($g_image_cache[$url]);
         return $g_image_cache[$url];
     }
     // Download image; we should do it before we call do_image_open,
     // as it tries to open image file twice: first to determine image type
     // and second to actually create the image - PHP url wrappers do no caching
     // at all
     //
     $filename = ImageFactory::make_cache_filename($url);
     // REQUIRES: PHP 4.3.0+
     // we suppress warning messages, as missing image files will cause 'copy' to print
     // several warnings
     //
     // @TODO: change to fetcher class call
     //
     $data = $pipeline->fetch($url);
     if (is_null($data)) {
         error_log("Cannot fetch image: " . $url);
         return null;
     }
     $file = @fopen($filename, 'wb');
     @fwrite($file, $data->content);
     @fclose($file);
     $pipeline->pop_base_url();
     // register it in the cached objects array
     //
     $handle = do_image_open($filename, $type);
     $g_image_cache[$url] =& new Image($handle, $filename, $type);
     // return image
     //
     // return do_image_open($filename);
     return $g_image_cache[$url];
 }