/[drupal]/contributions/modules/zoomify/zoomify.inc
ViewVC logotype

Contents of /contributions/modules/zoomify/zoomify.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Wed Jan 9 20:50:11 2008 UTC (22 months, 2 weeks ago) by kratib
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.1: +109 -29 lines
File MIME type: text/x-php
Significant changes in file handling
1 <?php
2 // $Id$
3 /**
4 * @file Utility and API functions for zoomify.module
5 */
6
7 function _zoomify_images($node) {
8 $images = array();
9 foreach (module_implements('images') as $module) {
10 $these_images = module_invoke($module, 'images', $node);
11 if (!empty($these_images)) {
12 $images = $images + $these_images;
13 }
14 }
15 return $images;
16 }
17
18 function _zoomify_basepath() {
19 $basepath = file_directory_path().'/zoomify';
20 if (!file_check_directory($basepath, FILE_CREATE_DIRECTORY)) {
21 $msg = t('Could not create path %path', array('%path' => $basepath));
22 drupal_set_message($msg, 'error');
23 watchdog('zoomify', $msg, WATCHDOG_ERROR);
24 }
25 return $basepath;
26 }
27
28 function _zoomify_nodepath($node) {
29 return file_create_path(_zoomify_basepath().'/'.$node->nid);
30 }
31
32 function _zoomify_filepath($node, $fid) {
33 return file_create_path(_zoomify_nodepath($node).'/'.$fid);
34 }
35
36 function _zoomify_identical($node, $fid, $filepath) {
37 $md5 = md5_file($filepath);
38 $md5_path = _zoomify_filepath($node, $fid).'/Image.md5';
39 if (!file_exists($md5_path)) return FALSE;
40 $md5_existing = file_get_contents($md5_path);
41 return $md5_existing == $md5;
42 }
43
44 function _zoomify_insert_node($node) {
45 $images = _zoomify_images($node);
46 if (empty($images)) return;
47 foreach ($images as $fid => $filepath) {
48 _zoomify_process($node, $fid, $filepath);
49 }
50 }
51
52 function _zoomify_process($node, $fid, $filepath) {
53 // TODO: Let user adjust maximum time for scripts or provide better mechanism.
54 set_time_limit(0);
55 $info = image_get_info($filepath);
56 if ($info === FALSE) {
57 $msg = t('Could not find image info for file %path.', array('%path' => $filepath));
58 watchdog('zoomify', $msg, WATCHDOG_ERROR);
59 drupal_set_message($msg, 'error');
60 return;
61 }
62 if (($info['width'] < variable_get('zoomify_minimum_width', 1024))
63 && ($info['height'] < variable_get('zoomify_minimum_height', 768))) return;
64
65 // Call the Python tilemaker script on the input file.
66 $pathinfo = pathinfo_filename($filepath);
67 $cmd = 'python '.drupal_get_path('module', 'zoomify').'/ZoomifyImage/ZoomifyFileProcessor.py'.
68 ' "'.$filepath.'"'.
69 ' 2>&1';
70 $return = 0;
71 $output = array();
72 exec($cmd, $output, $return);
73 if ($return) {
74 $msg = t('ZoomifyFileProcessor.py returned an error:<br />!output', array('!output' => implode('<br />', $output)));
75 watchdog('zoomify', $msg, WATCHDOG_ERROR);
76 drupal_set_message($msg, 'error');
77 return;
78 }
79 else {
80 $msg = t('Tiles created for file %path.', array('%path' => $filepath));
81 watchdog('zoomify', $msg, WATCHDOG_NOTICE);
82 drupal_set_message($msg, 'status');
83 }
84
85 if (!file_check_directory(_zoomify_nodepath($node), FILE_CREATE_DIRECTORY)) {
86 $msg = t('Could not create path %path.', array('%path' => _zoomify_nodepath($node)));
87 drupal_set_message($msg, 'error');
88 watchdog('zoomify', $msg, WATCHDOG_ERROR);
89 }
90 rename($pathinfo['dirname'].'/'.$pathinfo['filename'], _zoomify_filepath($node, $fid));
91 $md5 = md5_file($filepath);
92 $md5_path = _zoomify_filepath($node, $fid).'/Image.md5';
93 file_put_contents($md5_path, $md5);
94 }
95
96 function _zoomify_delete_node($node) {
97 if (is_dir(_zoomify_nodepath($node))) {
98 rrmdir(_zoomify_nodepath($node));
99 $msg = t('Tiles deleted for node %nid.', array('%nid' => $node->nid));
100 watchdog('zoomify', $msg, WATCHDOG_NOTICE);
101 drupal_set_message($msg, 'status');
102 }
103 }
104
105 function _zoomify_update_node($node) {
106 $old_images = file_scan_directory(_zoomify_nodepath($node), '.*', array('.', '..'), 0, FALSE);
107 $images = _zoomify_images($node);
108 foreach ($images as $fid => $filepath) {
109 if (!_zoomify_identical($node, $fid, $filepath)) {
110 rrmdir(_zoomify_filepath($node, $fid));
111 _zoomify_process($node, $fid, $filepath);
112 }
113 }
114 foreach ($old_images as $old_image) {
115 if (!array_key_exists($old_image->basename, $images) && is_dir($old_image->filename)) {
116 rrmdir($old_image->filename);
117 $msg = t('Tiles deleted for obsolete file %fid.', array('%fid' => $old_image->basename));
118 watchdog('zoomify', $msg, WATCHDOG_NOTICE);
119 drupal_set_message($msg, 'status');
120 }
121 }
122 }
123

  ViewVC Help
Powered by ViewVC 1.1.2