- Timestamp:
- Jan 3, 2012, 9:21:13 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/batch_manager_global.php
r12796 r12831 383 383 if ('metadata' == $action) 384 384 { 385 $query = ' 386 SELECT id, path 387 FROM '.IMAGES_TABLE.' 388 WHERE id IN ('.implode(',', $collection).') 389 ;'; 390 $id_to_path = array(); 391 $result = pwg_query($query); 392 while ($row = pwg_db_fetch_assoc($result)) 393 { 394 $id_to_path[$row['id']] = $row['path']; 395 } 396 397 update_metadata($id_to_path); 385 sync_metadata($collection); 398 386 399 387 array_push( -
trunk/admin/include/functions_metadata.php
r11748 r12831 49 49 $day = 1; 50 50 } 51 51 52 52 $iptc[$pwg_key] = $year.'-'.$month.'-'.$day; 53 53 } … … 110 110 } 111 111 112 function update_metadata($files) 112 113 function get_sync_metadata_attributes() 114 { 115 global $conf; 116 117 $update_fields = array('filesize', 'width', 'height'); 118 119 if ($conf['use_exif']) 120 { 121 $update_fields = 122 array_merge( 123 $update_fields, 124 array_keys($conf['use_exif_mapping']) 125 ); 126 } 127 128 if ($conf['use_iptc']) 129 { 130 $update_fields = 131 array_merge( 132 $update_fields, 133 array_keys($conf['use_iptc_mapping']) 134 ); 135 } 136 137 return array_unique($update_fields); 138 } 139 140 function get_sync_metadata($infos) 141 { 142 global $conf; 143 $file = PHPWG_ROOT_PATH.$infos['path']; 144 $fs = @filesize($file); 145 146 if ($fs===false) 147 { 148 return false; 149 } 150 151 $infos['filesize'] = floor($fs/1024); 152 153 if (isset($infos['representative_ext'])) 154 { 155 $file = original_to_representative($file, $infos['representative_ext']); 156 } 157 158 if ($image_size = @getimagesize($file)) 159 { 160 $infos['width'] = $image_size[0]; 161 $infos['height'] = $image_size[1]; 162 } 163 164 if ($conf['use_exif']) 165 { 166 $exif = get_sync_exif_data($file); 167 $infos = array_merge($infos, $exif); 168 } 169 170 if ($conf['use_iptc']) 171 { 172 $iptc = get_sync_iptc_data($file); 173 $infos = array_merge($infos, $iptc); 174 } 175 176 return $infos; 177 } 178 179 180 function sync_metadata($ids) 113 181 { 114 182 global $conf; … … 121 189 $datas = array(); 122 190 $tags_of = array(); 123 $has_high_images = array();124 125 $image_ids = array();126 foreach ($files as $id => $file)127 {128 array_push($image_ids, $id);129 }130 191 131 192 $query = ' 132 SELECT id 193 SELECT id, path, representative_ext 133 194 FROM '.IMAGES_TABLE.' 134 WHERE has_high = \'true\' 135 AND id IN ( 136 '.wordwrap(implode(', ', $image_ids), 80, "\n").' 195 WHERE id IN ( 196 '.wordwrap(implode(', ', $ids), 160, "\n").' 137 197 ) 138 198 ;'; 139 199 140 $has_high_images = array_from_query($query, 'id'); 141 142 foreach ($files as $id => $file) 143 { 144 $data = array(); 145 $data['id'] = $id; 146 $data['filesize'] = floor(filesize($file)/1024); 147 148 if ($image_size = @getimagesize($file)) 149 { 150 $data['width'] = $image_size[0]; 151 $data['height'] = $image_size[1]; 152 } 153 154 if (in_array($id, $has_high_images)) 155 { 156 $high_file = dirname($file).'/pwg_high/'.basename($file); 157 158 $data['high_filesize'] = floor(filesize($high_file)/1024); 159 } 160 161 if ($conf['use_exif']) 162 { 163 $exif = get_sync_exif_data($file); 164 if (count($exif) == 0 and isset($data['high_filesize'])) 165 { 166 $exif = get_sync_exif_data($high_file); 167 } 168 $data = array_merge($data, $exif); 169 } 170 171 if ($conf['use_iptc']) 172 { 173 $iptc = get_sync_iptc_data($file); 174 if (count($iptc) == 0 and isset($data['high_filesize'])) 175 { 176 $iptc = get_sync_iptc_data($high_file); 177 } 178 $data = array_merge($data, $iptc); 179 180 if (count($iptc) > 0) 181 { 182 foreach (array_keys($iptc) as $key) 200 $result = pwg_query($query); 201 while ($data = pwg_db_fetch_assoc($result)) 202 { 203 $data = get_sync_metadata($data); 204 if ($data === false) 205 { 206 continue; 207 } 208 209 $id = $data['id']; 210 foreach (array('keywords', 'tags') as $key) 211 { 212 if (isset($data[$key])) 213 { 214 if (!isset($tags_of[$id])) 183 215 { 184 if ($key == 'keywords' or $key == 'tags') 185 { 186 if (!isset($tags_of[$id])) 187 { 188 $tags_of[$id] = array(); 189 } 190 191 foreach (explode(',', $iptc[$key]) as $tag_name) 192 { 193 array_push( 194 $tags_of[$id], 195 tag_id_from_tag_name($tag_name) 196 ); 197 } 198 } 216 $tags_of[$id] = array(); 199 217 } 218 219 foreach (explode(',', $data[$key]) as $tag_name) 220 { 221 array_push( 222 $tags_of[$id], 223 tag_id_from_tag_name($tag_name) 224 ); 225 } 200 226 } 201 227 } … … 208 234 if (count($datas) > 0) 209 235 { 210 $update_fields = 211 array( 212 'filesize', 213 'width', 214 'height', 215 'high_filesize', 216 'date_metadata_update' 217 ); 218 219 if ($conf['use_exif']) 220 { 221 $update_fields = 222 array_merge( 223 $update_fields, 224 array_keys($conf['use_exif_mapping']) 225 ); 226 } 227 228 if ($conf['use_iptc']) 229 { 230 $update_fields = 231 array_merge( 232 $update_fields, 233 array_diff( 234 array_keys($conf['use_iptc_mapping']), 235 array('tags', 'keywords') 236 ) 237 ); 238 } 236 $update_fields = get_sync_metadata_attributes(); 237 array_push($update_fields, 'date_metadata_update'); 238 239 $update_fields = array_diff( 240 $update_fields, 241 array('tags', 'keywords') 242 ); 239 243 240 244 mass_updates( … … 242 246 array( 243 247 'primary' => array('id'), 244 'update' => array_unique($update_fields)248 'update' => $update_fields 245 249 ), 246 250 $datas, … … 301 305 } 302 306 303 $files = array();304 305 307 $query = ' 306 SELECT id, path 308 SELECT id, path, representative_ext 307 309 FROM '.IMAGES_TABLE.' 308 310 WHERE storage_category_id IN ('.implode(',', $cat_ids).')'; … … 315 317 $query.= ' 316 318 ;'; 317 $result = pwg_query($query); 318 while ($row = pwg_db_fetch_assoc($result)) 319 { 320 $files[$row['id']] = $row['path']; 321 } 322 323 return $files; 319 return hash_from_query($query, 'id'); 324 320 } 325 321 ?> -
trunk/admin/include/functions_upload.inc.php
r12443 r12831 481 481 $conf['use_exif'] = false; 482 482 } 483 update_metadata(array($image_id=>$file_path));483 sync_metadata(array($image_id)); 484 484 485 485 invalidate_user_cache(); -
trunk/admin/picture_modify.php
r12796 r12831 95 95 if (isset($_GET['sync_metadata'])) 96 96 { 97 $query = ' 98 SELECT path 99 FROM '.IMAGES_TABLE.' 100 WHERE id = '.$_GET['image_id'].' 101 ;'; 102 list($path) = pwg_db_fetch_row(pwg_query($query)); 103 update_metadata(array($_GET['image_id'] => $path)); 104 97 sync_metadata(array( intval($_GET['image_id']))); 105 98 array_push($page['infos'], l10n('Metadata synchronized from file')); 106 99 } -
trunk/admin/site_reader_local.php
r12642 r12831 31 31 { 32 32 $this->site_url = $url; 33 global $conf; 34 if (!isset($conf['flip_file_ext'])) 35 { 36 $conf['flip_file_ext'] = array_flip($conf['file_ext']); 37 } 38 if (!isset($conf['flip_picture_ext'])) 39 { 40 $conf['flip_picture_ext'] = array_flip($conf['picture_ext']); 41 } 33 42 } 34 43 … … 69 78 * and $conf['picture_ext'] 70 79 * @param string $path recurse in this directory 71 * @return array like "pic.jpg"=>array(' tn_ext'=>'jpg' ... )80 * @return array like "pic.jpg"=>array('representative_ext'=>'jpg' ... ) 72 81 */ 73 82 function get_elements($path) 74 83 { 75 84 global $conf; 76 if (!isset($conf['flip_file_ext']))77 {78 $conf['flip_file_ext'] = array_flip($conf['file_ext']);79 }80 85 81 86 $subdirs = array(); … … 94 99 if ( isset($conf['flip_file_ext'][$extension]) ) 95 100 { 96 $tn_ext = $this->get_tn_ext($path, $filename_wo_ext); 101 $representative_ext = null; 102 if (! isset($conf['flip_picture_ext'][$extension]) ) 103 { 104 $representative_ext = $this->get_representative_ext($path, $filename_wo_ext); 105 } 97 106 $fs[ $path.'/'.$node ] = array( 98 ' tn_ext' => $tn_ext,107 'representative_ext' => $representative_ext, 99 108 ); 100 109 } … … 124 133 function get_update_attributes() 125 134 { 126 return array(' tn_ext', 'has_high', 'representative_ext');135 return array('representative_ext'); 127 136 } 128 137 … … 133 142 134 143 $filename = basename($file); 135 $dirname = dirname($file);136 $filename_wo_ext = get_filename_wo_extension($filename);137 144 $extension = get_extension($filename); 138 145 139 $data['tn_ext'] = $this->get_tn_ext($dirname, $filename_wo_ext); 140 $data['has_high'] = $this->get_has_high($dirname, $filename); 146 $representative_ext = null; 147 if (! isset($conf['flip_picture_ext'][$extension]) ) 148 { 149 $dirname = dirname($file); 150 $filename_wo_ext = get_filename_wo_extension($filename); 151 $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext); 152 } 141 153 142 if ( !isset($conf['flip_picture_ext'][$extension]) ) 143 { 144 $data['representative_ext'] = $this->get_representative_ext( 145 $dirname, $filename_wo_ext 146 ); 147 } 154 $data['representative_ext'] = $representative_ext; 148 155 return $data; 149 156 } … … 153 160 function get_metadata_attributes() 154 161 { 155 global $conf; 156 157 $update_fields = array('filesize', 'width', 'height', 'high_filesize', 'high_width', 'high_height'); 158 159 if ($conf['use_exif']) 160 { 161 $update_fields = 162 array_merge( 163 $update_fields, 164 array_keys($conf['use_exif_mapping']) 165 ); 166 } 167 168 if ($conf['use_iptc']) 169 { 170 $update_fields = 171 array_merge( 172 $update_fields, 173 array_keys($conf['use_iptc_mapping']) 174 ); 175 } 176 177 return $update_fields; 162 return get_sync_metadata_attributes(); 178 163 } 179 164 180 165 // returns a hash of attributes (metadata+filesize+width,...) for file 181 function get_element_metadata($ file, $has_high = false)166 function get_element_metadata($infos) 182 167 { 183 global $conf; 184 if (!is_file($file)) 185 { 186 return null; 187 } 188 189 $data = array(); 190 191 $data['filesize'] = floor(filesize($file)/1024); 192 193 if ($image_size = @getimagesize($file)) 194 { 195 $data['width'] = $image_size[0]; 196 $data['height'] = $image_size[1]; 197 } 198 199 if ($has_high) 200 { 201 $high_file = dirname($file).'/pwg_high/'.basename($file); 202 $data['high_filesize'] = floor(filesize($high_file)/1024); 203 204 if ($high_size = @getimagesize($high_file)) 205 { 206 $data['high_width'] = $high_size[0]; 207 $data['high_height'] = $high_size[1]; 208 } 209 } 210 211 if ($conf['use_exif']) 212 { 213 $exif = get_sync_exif_data($file); 214 if (count($exif) == 0 and isset($data['high_filesize'])) 215 { 216 $exif = get_sync_exif_data($high_file); 217 } 218 $data = array_merge($data, $exif); 219 } 220 221 if ($conf['use_iptc']) 222 { 223 $iptc = get_sync_iptc_data($file); 224 if (count($iptc) == 0 and isset($data['high_filesize'])) 225 { 226 $iptc = get_sync_iptc_data($high_file); 227 } 228 $data = array_merge($data, $iptc); 229 } 230 231 return $data; 168 return get_sync_metadata($infos); 232 169 } 233 170 … … 249 186 } 250 187 251 function get_tn_ext($path, $filename_wo_ext)252 {253 global $conf;254 255 $base_test =256 $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.';257 258 foreach ($conf['picture_ext'] as $ext)259 {260 $test = $base_test.$ext;261 if (is_file($test))262 {263 return $ext;264 }265 }266 267 return null;268 }269 270 function get_has_high($path, $filename)271 {272 if (is_file($path.'/pwg_high/'.$filename))273 {274 return 'true';275 }276 277 return null;278 }279 188 280 189 } -
trunk/admin/site_update.php
r12681 r12831 81 81 if ($site_is_remote) 82 82 { 83 fatal_error('remote sites not supported'); 83 84 include_once(PHPWG_ROOT_PATH.'admin/site_reader_remote.php'); 84 85 $local_listing = null; … … 99 100 if (isset($_POST['submit'])) 100 101 { 101 if (!isset($conf['flip_picture_ext']))102 {103 $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);104 }105 102 if ($site_reader->open()) 106 103 { … … 313 310 ); 314 311 mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); 315 312 316 313 // add default permissions to categories 317 314 $category_ids = array(); … … 322 319 add_permission_on_category($category_ids, get_admins()); 323 320 } 324 321 325 322 $counts['new_categories'] = count($inserts); 326 323 } … … 374 371 .wordwrap( 375 372 implode(', ', $cat_ids), 376 80,373 160, 377 374 "\n" 378 375 ).')'; … … 411 408 } 412 409 413 if ( isset( $conf['flip_picture_ext'][get_extension($filename)] ) 414 and !isset($fs[$path]['tn_ext']) ) 415 { // For a picture thumbnail is mandatory and for non picture element, 416 // thumbnail and representative are optionnal 417 array_push( 418 $errors, 419 array( 420 'path' => $path, 421 'type' => 'PWG-UPDATE-2' 422 ) 423 ); 424 } 425 else 426 { 427 $insert = array( 428 'id' => $next_element_id++, 429 'file' => $filename, 430 'date_available' => CURRENT_DATE, 431 'path' => $path, 432 'tn_ext' => isset($fs[$path]['tn_ext']) 433 ? $fs[$path]['tn_ext'] 434 : null, 435 'storage_category_id' => $db_fulldirs[$dirname], 436 'added_by' => $user['id'], 437 ); 438 439 if ( $_POST['privacy_level']!=0 ) 440 { 441 $insert['level'] = $_POST['privacy_level']; 442 } 443 444 array_push( 445 $inserts, 446 $insert 447 ); 448 449 array_push( 450 $insert_links, 451 array( 452 'image_id' => $insert['id'], 453 'category_id' => $insert['storage_category_id'], 454 ) 455 ); 456 457 array_push( 458 $infos, 459 array( 460 'path' => $insert['path'], 461 'info' => l10n('added') 462 ) 463 ); 464 465 $caddiables[] = $insert['id']; 466 } 410 $insert = array( 411 'id' => $next_element_id++, 412 'file' => $filename, 413 'date_available' => CURRENT_DATE, 414 'path' => $path, 415 'representative_ext' => $fs[$path]['representative_ext'], 416 'storage_category_id' => $db_fulldirs[$dirname], 417 'added_by' => $user['id'], 418 ); 419 420 if ( $_POST['privacy_level']!=0 ) 421 { 422 $insert['level'] = $_POST['privacy_level']; 423 } 424 425 array_push( 426 $inserts, 427 $insert 428 ); 429 430 array_push( 431 $insert_links, 432 array( 433 'image_id' => $insert['id'], 434 'category_id' => $insert['storage_category_id'], 435 ) 436 ); 437 438 array_push( 439 $infos, 440 array( 441 'path' => $insert['path'], 442 'info' => l10n('added') 443 ) 444 ); 445 446 $caddiables[] = $insert['id']; 467 447 } 468 448 … … 561 541 foreach ( $files as $id=>$file ) 562 542 { 543 $file = $file['path']; 563 544 $data = $site_reader->get_element_update_attributes($file); 564 545 if ( !is_array($data) ) 565 546 { 566 547 continue; 567 }568 $extension = get_extension($file);569 if ( isset($conf['flip_picture_ext'][$extension]) )570 {571 if ( !isset($data['tn_ext']) )572 {573 array_push(574 $errors,575 array(576 'path' => $file,577 'type' => 'PWG-UPDATE-2'578 )579 );580 continue;581 }582 548 } 583 549 … … 656 622 $tags_of = array(); 657 623 658 $has_high_images = array(); 659 660 $image_ids = array(); 661 foreach ($files as $id => $file) 662 { 663 array_push($image_ids, $id); 664 } 665 666 if (count($image_ids) > 0) 667 { 668 $query = ' 669 SELECT id 670 FROM '.IMAGES_TABLE.' 671 WHERE has_high = \'true\' 672 AND id IN ( 673 '.wordwrap(implode(', ', $image_ids), 80, "\n").' 674 )'; 675 $has_high_images = array_from_query($query, 'id' ); 676 } 677 678 foreach ( $files as $id=>$file ) 679 { 680 $data = $site_reader->get_element_metadata( 681 $file, 682 in_array($id, $has_high_images) 683 ); 624 foreach ( $files as $id => $element_infos ) 625 { 626 $data = $site_reader->get_element_metadata($element_infos); 684 627 685 628 if ( is_array($data) ) … … 710 653 else 711 654 { 712 array_push($errors, array('path' => $ file, 'type' => 'PWG-ERROR-NO-FS'));655 array_push($errors, array('path' => $element_infos['path'], 'type' => 'PWG-ERROR-NO-FS')); 713 656 } 714 657 } … … 818 761 'meta_empty_overrides' => false, 819 762 ); 820 763 821 764 $cat_selected = array(); 822 765 -
trunk/include/derivative.inc.php
r12797 r12831 43 43 elseif (!empty($infos['representative_ext'])) 44 44 { 45 $pi = pathinfo($infos['path']); 46 $file_wo_ext = get_filename_wo_extension($pi['basename']); 47 $this->rel_path = $pi['dirname'].'/pwg_representative/' 48 .$file_wo_ext.'.'.$infos['representative_ext']; 45 $this->rel_path = original_to_representative($infos['path'], $infos['representative_ext']); 49 46 } 50 47 else -
trunk/include/functions.inc.php
r12798 r12831 732 732 } 733 733 734 /** Transforms an original path to its pwg representative */ 735 function original_to_representative($path, $representative_ext) 736 { 737 $pos = strrpos($path, '/'); 738 $path = substr_replace($path, 'pwg_representative/', $pos+1, 0); 739 $pos = strrpos($path, '.'); 740 return substr_replace($path, $representative_ext, $pos+1); 741 } 742 743 734 744 /* Returns the PATH to the thumbnail to be displayed. If the element does not 735 745 * have a thumbnail, the default mime image path is returned. The PATH can be -
trunk/include/ws_functions.inc.php
r12810 r12831 1742 1742 // update metadata from the uploaded file (exif/iptc) 1743 1743 require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php'); 1744 update_metadata(array($image_id=>$file_path));1744 sync_metadata(array($image_id)); 1745 1745 } 1746 1746 … … 1926 1926 // update metadata from the uploaded file (exif/iptc), even if the sync 1927 1927 // was already performed by add_uploaded_file(). 1928 $query = '1929 SELECT1930 path1931 FROM '.IMAGES_TABLE.'1932 WHERE id = '.$image_id.'1933 ;';1934 list($file_path) = pwg_db_fetch_row(pwg_query($query));1935 1928 1936 1929 require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php'); 1937 update_metadata(array($image_id=>$file_path));1930 sync_metadata(array($image_id)); 1938 1931 1939 1932 return array( … … 3329 3322 $conf['use_exif'] = false; 3330 3323 $conf['use_iptc'] = false; 3331 update_metadata(array($image['id'] => $image['path']));3324 sync_metadata(array($image['id'])); 3332 3325 3333 3326 return $result;
Note: See TracChangeset
for help on using the changeset viewer.