[Linpha-cvs] SF.net SVN: linpha: [4645] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2006-11-12 23:15:15
|
Revision: 4645 http://svn.sourceforge.net/linpha/?rev=4645&view=rev Author: fangehrn Date: 2006-11-12 15:14:49 -0800 (Sun, 12 Nov 2006) Log Message: ----------- * improved MetaData class a lot Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/admin/maintenance_import.php trunk/linpha2/admin/metadata_define.php trunk/linpha2/admin/metadata_define_post.php trunk/linpha2/admin/metadata_select.php trunk/linpha2/index.php trunk/linpha2/install/sql/sql.data.php trunk/linpha2/lib/classes/linpha.imgview.class.php trunk/linpha2/lib/classes/linpha.import.class.php trunk/linpha2/lib/classes/linpha.metadata.class.php trunk/linpha2/lib/classes/linpha.sql.class.php trunk/linpha2/templates/default/home.html.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/ChangeLog 2006-11-12 23:14:49 UTC (rev 4645) @@ -3,6 +3,7 @@ if you have a public upload folder, its dangerous if the user may upload own php files! but: we will need to make an option which file types are allowed, its also dangerous to upload videos because there are security holes in the video players! + * improved MetaData class a lot 2006-11-11 flo * renamed: Modified: trunk/linpha2/admin/maintenance_import.php =================================================================== --- trunk/linpha2/admin/maintenance_import.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/admin/maintenance_import.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -200,8 +200,7 @@ * * if "Delete First" and "All albums" was selected, the whole table will be deleted */ - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); - $MetaData = new MetaData(); + $MetaData = new MetaDataIndex(); foreach($array_meta AS $meta_value) { @@ -267,8 +266,6 @@ */ if( isset($array_meta_ids) && $_REQUEST['index_'.$meta_value] == 'index' ) { - $MetaData->setFields($meta_value); - echo i18n("Index Image"); foreach($array_meta_ids AS $id=>$md5sum) @@ -283,14 +280,10 @@ switch($meta_value) { case 'exif': - include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); // used for jpeg comment - include_once(LINPHA_DIR.'/lib/classes/phpmeta/EXIF.php'); - $MetaData->saveExifData( $full_filename,$md5sum ); + $MetaData->saveData( 'exif', $full_filename,$md5sum ); break; case 'iptc': - include_once(LINPHA_DIR.'/lib/classes/phpmeta/Photoshop_IRB.php'); - include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); - $MetaData->saveIptcData( $full_filename,$md5sum ); + $MetaData->saveData( 'iptc', $full_filename,$md5sum ); break; case 'xmp': break; Modified: trunk/linpha2/admin/metadata_define.php =================================================================== --- trunk/linpha2/admin/metadata_define.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/admin/metadata_define.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -261,8 +261,7 @@ function show_exif_iptc() { - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); - $MetaData = new MetaData(); + $MetaData = new LinMetaDataAdmin(); $MetaData->setFields( $GLOBALS['cat3'] ); /** Modified: trunk/linpha2/admin/metadata_define_post.php =================================================================== --- trunk/linpha2/admin/metadata_define_post.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/admin/metadata_define_post.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -88,17 +88,16 @@ $linpha->sql->config->reloadConfig(); break; case 'create_exifiptc': - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); if( ! isset($_POST['selected_fields'])) { $_POST['selected_fields'] = Array(); } if($cat3 == 'exif') { $linpha->db->Execute("DROP TABLE IF EXISTS ".LIN_PREFIX."meta_exif"); - $linpha->db->Execute( Metadata::createExifTable( $_POST['selected_fields'] ) ); + $linpha->db->Execute( LinMetadataAdmin::createExifTable( $_POST['selected_fields'] ) ); } elseif($cat3 == 'iptc') { $linpha->db->Execute("DROP TABLE IF EXISTS ".LIN_PREFIX."meta_iptc"); - $linpha->db->Execute( Metadata::createIptcTable( $_POST['selected_fields'] ) ); + $linpha->db->Execute( LinMetadataAdmin::createIptcTable( $_POST['selected_fields'] ) ); } break; } Modified: trunk/linpha2/admin/metadata_select.php =================================================================== --- trunk/linpha2/admin/metadata_select.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/admin/metadata_select.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -74,8 +74,7 @@ /** * set exif/iptc fields */ - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); - $MetaData = new MetaData(); + $MetaData = new LinMetaDataAdmin(); $MetaData->setFields('exif'); $MetaData->setFields('iptc'); ?> Modified: trunk/linpha2/index.php =================================================================== --- trunk/linpha2/index.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/index.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -13,7 +13,7 @@ /** * some init stuff */ - include_once(LINPHA_DIR.'/lib/classes/linpha.class.php'); + require_once(LINPHA_DIR.'/lib/classes/linpha.class.php'); global $linpha; $linpha = new Linpha(); $linpha->sql->startSession(); @@ -25,38 +25,38 @@ { $_GET['linCat'] = 'alb'; } - + /** * open modules */ switch($_GET['linCat']) { case 'alb': - include_once(LINPHA_DIR.'/lib/modules/module.albums.php'); + require_once(LINPHA_DIR.'/lib/modules/module.albums.php'); break; case 'search': - include_once(LINPHA_DIR.'/lib/modules/module.search.php'); + require_once(LINPHA_DIR.'/lib/modules/module.search.php'); break; case 'basket': - include_once(LINPHA_DIR.'/lib/modules/module.basket.php'); + require_once(LINPHA_DIR.'/lib/modules/module.basket.php'); break; case 'browse': - include_once(LINPHA_DIR.'/lib/modules/module.browse.php'); + require_once(LINPHA_DIR.'/lib/modules/module.browse.php'); break; case 'filemanager': - include_once(LINPHA_DIR.'/lib/modules/module.filemanager.php'); + require_once(LINPHA_DIR.'/lib/modules/module.filemanager.php'); break; case 'settings': - include_once(LINPHA_DIR.'/lib/modules/module.settings.php'); + require_once(LINPHA_DIR.'/lib/modules/module.settings.php'); break; case 'ajax': - include_once(LINPHA_DIR.'/lib/modules/module.ajax.php'); + require_once(LINPHA_DIR.'/lib/modules/module.ajax.php'); break; case 'newimg': - include_once(LINPHA_DIR.'/lib/modules/module.newimg.php'); + require_once(LINPHA_DIR.'/lib/modules/module.newimg.php'); break; case 'empty': - include_once(LINPHA_DIR.'/lib/modules/module.empty.php'); + require_once(LINPHA_DIR.'/lib/modules/module.empty.php'); break; } Modified: trunk/linpha2/install/sql/sql.data.php =================================================================== --- trunk/linpha2/install/sql/sql.data.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/install/sql/sql.data.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -260,8 +260,6 @@ * flag_nr 12 */ $sql_queries[] = "INSERT INTO ".LIN_PREFIX."meta_fields " . - "(name, field_type, flags) VALUES ('builtin_filename', 0, 12)"; - $sql_queries[] = "INSERT INTO ".LIN_PREFIX."meta_fields " . "(name, field_type, flags) VALUES ('builtin_description', 0, 12)"; $sql_queries[] = "INSERT INTO ".LIN_PREFIX."meta_fields " . "(name, field_type, flags) VALUES ('builtin_time_add', 0, 12)"; Modified: trunk/linpha2/lib/classes/linpha.imgview.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.imgview.class.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/lib/classes/linpha.imgview.class.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -24,11 +24,14 @@ */ if(!defined('LINPHA_DIR')) { exit(1); } -define('LIN_SELECT_FIELDS',LIN_PREFIX."photos.id AS id, ".LIN_PREFIX."photos.name AS name, " . +define('LIN_SELECT_FIELDS', + "".LIN_PREFIX."photos.id AS id, ".LIN_PREFIX."photos.name AS name, " . "".LIN_PREFIX."photos.img_type AS img_type, ".LIN_PREFIX."photos.md5sum AS md5sum, " . "".LIN_PREFIX."photos.width AS width, ".LIN_PREFIX."photos.height AS height, " . - "".LIN_PREFIX."photos.stats_numbers AS stats_numbers, " . - "".LIN_PREFIX."photos.time_add AS time_add"); + "".LIN_PREFIX."photos.time_add AS time_add, ".LIN_PREFIX."photos.time_mod AS time_mod, " . + "".LIN_PREFIX."photos.time_exif AS time_exif, ".LIN_PREFIX."photos.stats_numbers AS stats_numbers, " . + "".LIN_PREFIX."photos.stats_views AS stats_views, ".LIN_PREFIX."photos.stats_downloads AS stats_downloads" +); class LinImgview { @@ -613,17 +616,13 @@ } else { $flag_nr = 13; // flag nr of thumb } - $array_image_infos = MetaData::readInformations( - array( - 'filename' => $photo_value['name'], - 'full_filename' => LinSql::getFullImagePath( $photo_value['id'] ), - 'md5sum' => $photo_value['md5sum'], - 'width' => $photo_value['width'], - 'height' => $photo_value['height'] - ), - $flag_nr - ); + $array_image_infos = LinMetaDataRead::readInformations( + $photo_value, + LinSql::getFullImagePath( $photo_value['id'] ), + $flag_nr + ); + $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['before'] = ''; $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['after'] = ''; $index = 'before'; @@ -914,13 +913,49 @@ } } - $days = $GLOBALS['linpha']->sql->config->value['sys_style_home_newimagesage']; - $days_in_sec = $days*60*60*24; - $lower_date = time()-$days_in_sec; - $this->viewHomeSetImages('new_images','sys_style_home_newimagesnr',' AND time_add > '.LinSql::linAddslashes($lower_date)); - $this->viewHomeSetImages('random_images','sys_style_home_nrrandomimages',''); + /** + * new images + */ + $days = $GLOBALS['linpha']->sql->config->value['sys_style_home_newimagesage']; + $days_in_sec = $days*60*60*24; + $lower_date = time()-$days_in_sec; + $this->viewHomeSetImages('new_images','sys_style_home_newimagesnr',' AND time_add > '.LinSql::linAddslashes($lower_date)); + + /** + * random images + */ + $this->viewHomeSetImages('random_images','sys_style_home_nrrandomimages',''); - $this->viewHomeSetBrowseByDate(); + /** + * browse by date + */ + $this->viewHomeSetBrowseByDate(); + + /** + * album informations + */ + + foreach($this->photos_filtered AS $photo_key=>$photo_value) + { + $array_image_infos = LinMetaDataRead::readInformations( + $photo_value, + LinSql::getFullImagePath( $photo_value['id'] ), + $flag_nr=12 + ); + + $this->photos_filtered[$photo_key]['album_infos'] = ''; + foreach($array_image_infos AS $key=>$value) + { + if($key == 'builtin_stats_numbers') + { + $this->photos_filtered[$photo_key]['album_infos'] .= $value['value'].' '.i18n("Photos").'<br />'; + } + else + { + $this->photos_filtered[$photo_key]['album_infos'] .= $value['value'].'<br />'; + } + } + } } /** @@ -1190,17 +1225,11 @@ $this->viewImgStoreImageInformation(); - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); - $GLOBALS['linpha']->template->output['image_infos'] = MetaData::readInformations( - array( - 'filename' => $this->filename, - 'full_filename' => $this->full_filename, - 'md5sum' => $this->md5sum, - 'width' => $this->org_width, - 'height' => $this->org_height - ), - $flag_nr=10 - ); + $GLOBALS['linpha']->template->output['image_infos'] = LinMetaDataRead::readInformations( + $this->photos_filtered[ $this->current_key ], + $this->src_file, + $flag_nr=10 + ); if(isset($_GET['force_update'])) { LinImport::updateEntry( $GLOBALS['linpha']->template->idCurrent , dirname($this->full_filename) , $this->filename ); @@ -1255,51 +1284,22 @@ { $this->full_filename = LinSql::getFullImagePath( $GLOBALS['linpha']->template->idCurrent ); - /** - * set image informations - */ - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); - $MetaData = new MetaData(); - $MetaData->setFields('exif'); - $MetaData->setFields('iptc'); + $array_meta = array('exif','iptc'); + foreach($array_meta AS $value) + { + if( !isset($MetaData) ) + { + $MetaData = new LinMetaDataIndex(); + } - /** - * read exif and iptc from file if no entry - */ - if($GLOBALS['linpha']->sql->config->value['sys_image_exif']) - { - /** - * check if exif information are already in db - * if not, read exif information from file and store it in the db - * - */ - $query = $GLOBALS['linpha']->db->Execute("SELECT md5sum ". - "FROM ".LIN_PREFIX."meta_exif WHERE md5sum = '".$this->md5sum."'"); - - if( $query->EOF) // not a single value returned - { - include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); // used for jpeg comment - include_once(LINPHA_DIR.'/lib/classes/phpmeta/EXIF.php'); - $MetaData->saveExifData( $this->full_filename,$this->md5sum); - } - } - - if($GLOBALS['linpha']->sql->config->value['sys_image_iptc']) - { - /** - * check if there is already IPTC info in db if not, get IPTC - * information from file and store it in the db - */ - $query = $GLOBALS['linpha']->db->Execute("SELECT md5sum ". - "FROM ".LIN_PREFIX."meta_iptc WHERE md5sum = '".$this->md5sum."'"); - - if( $query->EOF) // not a single value returned - { - include_once(LINPHA_DIR.'/lib/classes/phpmeta/Photoshop_IRB.php'); - include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); - $MetaData->saveIptcData( $this->full_filename,$this->md5sum); - } - } + /** + * read exif/iptc from file if no entry + */ + if($GLOBALS['linpha']->sql->config->value['sys_image_'.$value]) + { + $MetaData->saveData( $value, $this->full_filename,$this->md5sum); + } + } } /** Modified: trunk/linpha2/lib/classes/linpha.import.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.import.class.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/lib/classes/linpha.import.class.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -456,13 +456,12 @@ { include_once( LINPHA_DIR.'/lib/classes/phpmeta/EXIF.php' ); $meta = get_EXIF_JPEG($dirname.'/'.$filename); - include_once(LINPHA_DIR.'/lib/classes/linpha.metadata.class.php'); /** * get date */ if( isset($meta[0][34665]['Data'][0][36867]['Data'][0]) ) { - $time_exif = MetaData::convertExifDateToUnix( $meta[0][34665]['Data'][0][36867]['Data'][0] ); + $time_exif = LinMetaDataIndex::convertExifDateToUnix( $meta[0][34665]['Data'][0][36867]['Data'][0] ); } /** @@ -471,7 +470,7 @@ */ if( $GLOBALS['linpha']->sql->config->value['sys_import_exif_autorot'] && isset($meta[0][274]['Data'][0]) ) { - $rotate = MetaData::getRotationByExifTag( $meta[0][274]['Data'][0] ); + $rotate = LinMetaDataIndex::getRotationByExifTag( $meta[0][274]['Data'][0] ); } } } Modified: trunk/linpha2/lib/classes/linpha.metadata.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.metadata.class.php 2006-11-12 18:26:04 UTC (rev 4644) +++ trunk/linpha2/lib/classes/linpha.metadata.class.php 2006-11-12 23:14:49 UTC (rev 4645) @@ -26,561 +26,144 @@ if(!defined('LINPHA_DIR')) { exit(1); } -class MetaData { - -public $available_fields, $defined_fields; - - -function __construct() -{ -} - /** - * show nice name for exif, iptc, builtin and own fields, for example: convert "exif_datetimeoriginal" to "DateTime Original" + * Functions to read MetaData from the database */ -function getNameOfField( $key , $show_exifiptc_in_brackets) +class LinMetaDataRead extends LinMetaData { - $pos = strpos($key,'_'); - $first_part = substr($key,0,$pos); - $last_part = substr($key,$pos+1); - switch($first_part) + /** + * read image information from database + * and escape data with htmlspecialchars() if necessary + * + * @param array array_src_infos array containing needed source file informations, same as LIN_SELECT_FIELDS + * + */ + function readInformations($array_src_infos, $full_filename, $flag_nr) { - case 'builtin': // builtin and special fields like filename, imagesize and dimension - $value = i18n( ucfirst( $last_part ) ); - break; - - case 'id': // own fields - $data2 = $GLOBALS['linpha']->db->GetRow("SELECT name FROM ".LIN_PREFIX."meta_fields WHERE id = '".$last_part."'"); - $value = i18n( ucfirst( $data2['name'] ) ); - break; - case 'exif': - $value = $GLOBALS['Tags_Exif'][$last_part]; - if($show_exifiptc_in_brackets) { - $value .= ' (exif)'; - } - break; - case 'iptc': - $value = $GLOBALS['Tags_Iptc'][$last_part]; - if($show_exifiptc_in_brackets) { - $value .= ' (iptc)'; - } - break; - } - - return $value; -} - -/** - * read image information from database - */ -function readInformations($full_filename,$filename,$md5sum,$width,$height,$flag_nr) -{ - $query = $GLOBALS['linpha']->db->Execute("SELECT name " . - "FROM ".LIN_PREFIX."meta_fields " . - "WHERE flags = '".$flag_nr."' ORDER by id"); - - while($fields_data = $query->FetchRow(ADODB_FETCH_NUM)) - { - $name = MetaData::getNameOfField( $fields_data['0'], false ); - $value = ''; - - $pos = strpos($fields_data['0'],'_'); - $first_part = substr($fields_data['0'],0,$pos); - $last_part = substr($fields_data['0'],$pos+1); - /** - * get field id - */ - $data = $GLOBALS['linpha']->db->GetRow("SELECT id " . - "FROM ".LIN_PREFIX."meta_fields WHERE name = '".$last_part."'"); + $query = $GLOBALS['linpha']->db->Execute("SELECT name " . + "FROM ".LIN_PREFIX."meta_fields " . + "WHERE flags = '".$flag_nr."' ORDER by id"); - switch($first_part) + while($fields_data = $query->FetchRow(ADODB_FETCH_NUM)) { - case 'builtin': + $name = LinMetaData::getNameOfField( $fields_data['0'], false ); + $value = ''; + + $pos = strpos($fields_data['0'],'_'); + $first_part = substr($fields_data['0'],0,$pos); + $last_part = substr($fields_data['0'],$pos+1); /** - * @todo maybe we could save this values in the db for - * speed improvements + * get field id */ - switch($last_part) + $data = $GLOBALS['linpha']->db->GetRow("SELECT id " . + "FROM ".LIN_PREFIX."meta_fields WHERE name = '".$last_part."'"); + + switch($first_part) { - case 'filename': - $value = '<span title="'.$filename.'">'.$filename.'</span>'; // is already escaped - break; - case 'imagesize': - $value = LinFilesys::niceFilesize( filesize( $full_filename ), 2 ); - break; - case 'dimension': - $value = $width.'x'.$height; - break; - case 'thumbnail': - $value = 'thumbnail'; - break; - default: // field entries which are stored in linpha_meta_data + case 'builtin': + + switch($last_part) + { + case 'filename': + $value = $array_src_infos['name']; // is already escaped + break; + case 'imagesize': + $value = LinFilesys::niceFilesize( filesize( $full_filename ), 2 ); + break; + case 'dimension': + $value = $array_src_infos['width'].'x'.$array_src_infos['height']; + break; + case 'thumbnail': + $value = 'thumbnail'; + break; + case 'time_add': + $name = i18n("Date Added"); + $value = linStrftime($array_src_infos['time_add']); + break; + case 'time_mod': + $name = i18n("Date Modified"); + $value = linStrftime($array_src_infos['time_mod']); + break; + case 'time_exif': + $name = i18n("Date Taken"); + $value = linStrftime($array_src_infos['time_exif']); + break; + case 'stats_numbers': + $name = i18n("Photos"); + $value = $array_src_infos['stats_numbers']; + break; + case 'stats_views': + $name = i18n("Nr Of Views"); + $value = $array_src_infos['stats_views']; + break; + case 'stats_downloads': + $name = i18n("Nr Of Downloads"); + $value = $array_src_infos['stats_downloads']; + break; + default: + + /** + * description, category, persons, date (field entries which are stored in linpha_meta_data) + */ + $meta_data = $GLOBALS['linpha']->db->GetRow("SELECT meta_data " . + "FROM ".LIN_PREFIX."meta_data ". + "WHERE field_id = '".$data['id']."' " . + "AND md5sum = '".$array_src_infos['md5sum']."'"); + + if(isset($meta_data['meta_data'])) { + $value = htmlspecialchars($meta_data['meta_data'],ENT_QUOTES); + } + } + case 'id': // own fields $meta_data = $GLOBALS['linpha']->db->GetRow("SELECT meta_data " . - "FROM ".LIN_PREFIX."meta_data ". + "FROM ".LIN_PREFIX."meta_data " . "WHERE field_id = '".$data['id']."' " . - "AND md5sum = '".$md5sum."'"); - + "AND md5sum = '".$array_src_infos['md5sum']."'"); + if(isset($meta_data['meta_data'])) { $value = htmlspecialchars($meta_data['meta_data'],ENT_QUOTES); } - } - case 'id': // own fields - $meta_data = $GLOBALS['linpha']->db->GetRow("SELECT meta_data " . - "FROM ".LIN_PREFIX."meta_data " . - "WHERE field_id = '".$data['id']."' " . - "AND md5sum = '".$md5sum."'"); - - if(isset($meta_data['meta_data'])) { - $value = htmlspecialchars($meta_data['meta_data'],ENT_QUOTES); - } - break; - case 'exif': - if($GLOBALS['linpha']->sql->config->value['sys_image_exif']) { - $exif_data = $GLOBALS['linpha']->db->GetRow("SELECT ".$last_part." " . - "FROM ".LIN_PREFIX."meta_exif WHERE md5sum = '".$md5sum."'"); - - if(isset($exif_data[$last_part])) { - $value = htmlspecialchars($exif_data[$last_part],ENT_QUOTES); + break; + case 'exif': + if($GLOBALS['linpha']->sql->config->value['sys_image_exif']) { + $exif_data = $GLOBALS['linpha']->db->GetRow("SELECT ".$last_part." " . + "FROM ".LIN_PREFIX."meta_exif WHERE md5sum = '".$array_src_infos['md5sum']."'"); + + if(isset($exif_data[$last_part])) { + $value = htmlspecialchars($exif_data[$last_part],ENT_QUOTES); + } } - } - break; - case 'iptc': - if($GLOBALS['linpha']->sql->config->value['sys_image_iptc']) { - $iptc_data = $GLOBALS['linpha']->db->GetRow("SELECT ".$last_part." " . - "FROM ".LIN_PREFIX."meta_iptc WHERE md5sum = '".$md5sum."'"); - - if(isset($iptc_data[$last_part])) { - $value = htmlspecialchars($iptc_data[$last_part],ENT_QUOTES); + break; + case 'iptc': + if($GLOBALS['linpha']->sql->config->value['sys_image_iptc']) { + $iptc_data = $GLOBALS['linpha']->db->GetRow("SELECT ".$last_part." " . + "FROM ".LIN_PREFIX."meta_iptc WHERE md5sum = '".$array_src_infos['md5sum']."'"); + + if(isset($iptc_data[$last_part])) { + $value = htmlspecialchars($iptc_data[$last_part],ENT_QUOTES); + } } + break; } - break; - } - - if($value != '') - { - $output_array[$fields_data['name']] = Array('name' => $name, 'value' => $value); - } - } - - return $output_array; -} - -/** - * set available and defined fields - * @param string $what [exif,iptc] - */ -function setFields($what) -{ - /** - * create definedfields[] - */ - $this->defined_fields[$what] = $GLOBALS['linpha']->db->MetaColumns(LIN_PREFIX."meta_".$what); - - /** - * remove md5sum entry - */ - unset($this->defined_fields[$what]['MD5SUM']); - /** - * change keys to lowercase - */ - foreach($this->defined_fields[$what] AS $key=>$value) - { - $new_key = strtolower($key); - unset($this->defined_fields[$what][$key]); - $this->defined_fields[$what][$new_key] = $GLOBALS['Tags_'.ucfirst($what)][$new_key]; - } - - /** - * create available_fields - */ - foreach($GLOBALS['Tags_'.ucfirst($what)] AS $key=>$value) - { - if( ! isset( $this->defined_fields[$what][$key] )) + if($value != '') { - $this->available_fields[$what][$key] = $value; + $output_array[$fields_data['name']] = Array('name' => $name, 'value' => $value); } } -} - - -/** - * save data in DB functions - */ - /** - * store EXIF data in DB - * - * create an entry in the db even if we haven't found anything - * to prevent img_view.class.php to call this function every time - * the image is viewed - */ - function saveExifData($filename,$md5sum) - { - /** - * get exif info from file - */ - $exif_data = get_EXIF_JPEG( $filename ); - - /** - * get exif tags - */ - $exif_tags = $this->getExifTranslationArray(); - /** - * special tags - */ - // Canon Owner Name append to Artist - if(isset($exif_data['Makernote_Tag']['Decoded Data']) - && is_array($exif_data['Makernote_Tag']['Decoded Data']) // sometimes 'Decoded Data' is an empty string - && isset($exif_data['Makernote_Tag']['Decoded Data'][0][9]['Text Value'])) - { - $owner = $exif_data['Makernote_Tag']['Decoded Data'][0][9]['Text Value']; - if(isset($exif_data[0][315]['Text Value'])) - { - $exif_data[0][315]['Text Value'] .= $owner; - } - else - { - $exif_data[0][315]['Text Value'] = $owner; - } - - } - - /** - * search for valid tags - */ - $str_columns = "md5sum, "; - $str_values = "'".$md5sum."', "; - foreach($exif_tags AS $key=>$value) - { - $key = strtolower($key); - - if($value != "" && isset($this->defined_fields['exif'][$key])) - { - /** - * there are currently only entries at level deep 2 and 5 in the - * array - */ - $array_pieces = explode('/',$value); - switch(count($array_pieces)) - { - case 2: - if(isset($exif_data[ $array_pieces[0] ][ $array_pieces[1] ]['Text Value'])) - { - $str_columns .= $key.', '; - - $exif_value = $exif_data[ $array_pieces[0] ][ $array_pieces[1] ]['Text Value']; - $str_values .= "'".linSql::linAddslashes(trim( $exif_value ))."', "; - } - break; - case 5: - if(isset($exif_data[ $array_pieces[0] ][ $array_pieces[1] ][ $array_pieces[2] ][ $array_pieces[3] ][ $array_pieces[4] ]['Text Value'])) - { - $str_columns .= $key.', '; - - $exif_value = $exif_data[ $array_pieces[0] ][ $array_pieces[1] ][ $array_pieces[2] ][ $array_pieces[3] ][ $array_pieces[4] ]['Text Value']; - $str_values .= "'".linSql::linAddslashes(trim( $exif_value ))."', "; - } - break; - default: - echo "Error no valid path for key: ".$key." value: ".$value; - break; - } - } - } - - /** - * add jpegcomment - */ - if(in_array('jpegcomment',$this->defined_fields['exif'])) - { - $jpeg_header_data = get_jpeg_header_data( $filename ); - $comment = get_jpeg_Comment( $jpeg_header_data ); - if(!empty($comment)) - { - $str_columns .= 'jpegcomment, '; - $str_values .= "'".linSql::linAddslashes(trim( $comment ))."', "; - } - } - - /** - * remove last two signs - */ - $str_columns = substr($str_columns,0,strlen($str_columns)-2); - $str_values = substr($str_values,0,strlen($str_values)-2); - - - /** - * no double entries - */ - $query = $GLOBALS['linpha']->db->Execute("SELECT md5sum FROM ".LIN_PREFIX."meta_exif ". - "WHERE md5sum = '".$md5sum."'"); - - if( $query->EOF) // not a sigle value returned - { - $GLOBALS['linpha']->db->Execute("INSERT into ".LIN_PREFIX."meta_exif (".$str_columns.") ". - "VALUES (".$str_values.")"); - } + return $output_array; } - /** - * esacape sql strings a clean way - - function cleansql($text) - { - $return=""; - $chars = preg_split('//', $text, -1, PREG_SPLIT_NO_EMPTY); - $count = count($chars); - for ($c=0; $c<$count; $c++) - { - $letter=$chars[$c]; - if (!preg_match("/[a-zA-Z0-9]/", $letter)) - { - $return .= "\\$letter"; - } - else - { - $return .= "$letter"; - } - } - return $return; - } - */ - /** - * store IPTC data in DB - */ - function saveIptcData($filename, $md5sum) - { - // Retrieve the header information - $jpeg_header_data = get_jpeg_header_data($filename); - - if($jpeg_header_data) - { - // get array with all available IPTC data - $IPTC_Info = get_Photoshop_IPTC(get_Photoshop_IRB($jpeg_header_data)); - - // init values (prevent php notice msg if not set) - $caption = ""; - $object_name = ""; - $edit_status = ""; - $priority = ""; - $category = ""; - $supplemental_categorie = ""; - $job_id = ""; - $keywords = ""; - $date_released = ""; - $time_released = ""; - $instructions = ""; - $date_created = ""; - $time_created = ""; - $program = ""; - $object_cycle = ""; - $byline = ""; - $byline_title = ""; - $city = ""; - $sublocation = ""; - $state = ""; - $country_code = ""; - $country = ""; - $trans_reference = ""; - $headline = ""; - $credit = ""; - $source = ""; - $copyright = ""; - $caption_writer = ""; - - $IPTC_Meta = array(); +} // end class LinMetaData - $query = $GLOBALS['linpha']->db->Execute("SELECT md5sum " . - "FROM ".LIN_PREFIX."meta_iptc " . - "WHERE md5sum = '".$md5sum."' "); - if( $query->EOF) // not a sigle value returned - { - if(is_array($IPTC_Info)) - { - // Cycle through each of the IPTC-NAA IIM records - foreach($IPTC_Info as $IPTC_Record) - { - switch ( $IPTC_Record['IPTC_Type'] ) - { - case "2:05": // object name - $object_name = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:07": // edit_status - $edit_status = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:10": // priority - $priority = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:15": // category - $category = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:20": // supplemental_categorie - $supplemental_categorie .= " ".linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:22": // job_id - $job_id = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:25": // keywords - $keywords .= " ".linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:30": // date_released - $date_released = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:35": // time_released - $time_released = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:40": // instructions - $instructions = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:55": // date_created - $date_created = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:60": // time_created - $time_created = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:65": // program - $program = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:75": // object_cycle - $object_cycle = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:80": // byline - $byline = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:85": // byline_title - $byline_title = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:90": // city - $city = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:92": // sublocation - $sublocation = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:95": // state - $state = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:100": // country_code - $country_code = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:101": // country - $country = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:103": // trans_reference - $trans_reference = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:105": // headline - $headline = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:110": // credit - $credit = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:115": // source - $source = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:116": // copyright - $copyright = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:120": // caption - $caption = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - - case "2:122": // caption_writer - $caption_writer = linSql::linAddslashes(rtrim($IPTC_Record['RecData'])); - break; - } - } - - $GLOBALS['linpha']->db->Execute("INSERT INTO ".LIN_PREFIX."meta_iptc ( " . - "md5sum, caption, caption_writer, headline, " . - "instructions, keywords, category, supplemental_categorie, " . - "copyright, byline, byline_title, credit, source, " . - "edit_status, priority, object_cycle, job_id, program, " . - "object_name, date_created, date_released, time_created, " . - "time_released, city, sublocation, state, country, " . - "country_code, trans_reference) " . - "VALUES('".$md5sum."', '".$caption."', '".$caption_writer."', '".$headline."', " . - "'".$instructions."', '".$keywords."', '".$category."', '".$supplemental_categorie."', " . - "'".$copyright."', '".$byline."', '".$byline_title."', '".$credit."', '".$source."', " . - "'".$edit_status."', '".$priority."', '".$object_cycle."', '".$job_id."', '".$program."', " . - "'".$object_name."', '".$date_created."', '".$date_released."', '".$time_created."', " . - "'".$time_released."', '".$city."', '".$sublocation."', '".$state."', '".$country."', " . - "'".$country_code."', '".$trans_reference."')"); - - return true; - } - else - { - /** - * save empty entry to prevent re-read on every page visit - */ - $GLOBALS['linpha']->db->Execute("INSERT INTO ".LIN_PREFIX."meta_iptc " . - "(md5sum) VALUES('".$md5sum."')"); - - return false; - } - } - } - else - { - return false; - } - } - - - /** - * edit iptc functions + * Admin functions to select the tags which should be indexed */ - /** - * edit IPTC Data in HTML popup - */ - function editIptcData() - { - - } - - /** - * save modified IPTC data to DB - */ - function saveModIptcData() - { - - } - - - -/** - * createTable functions - */ +class LinMetaDataAdmin extends LinMetaData +{ function createExifTable($array='') { if(empty($array)) @@ -594,7 +177,7 @@ "md5sum VARCHAR(32) NOT NULL, "; foreach($array AS $key=>$value) { - $str .= linSql::linAddslashes(strtolower($value))." VARCHAR(255), "; + $str .= LinSql::linAddslashes(strtolower($value))." VARCHAR(255), "; } $str .= "PRIMARY KEY (md5sum), "; $str .= "KEY (md5sum) )"; @@ -648,189 +231,7 @@ 'fnumber' ); } - - /** - * get array with exiftags and path where they are - * keys are used to create the database table - * - * warning: if making changes in the keys of the array, we will need to - * update the db!! - */ - function getExifTranslationArray() - { - return Array( - // TIFF Rev. 6.0 Attribute Information - // A. Tags relating to image data structure - 'ImageWidth' => '', - 'ImageLength' => '', - 'BitsPerSample' => '', - 'Compression' => '', - 'PhotometricInterpretation' => '', - 'Orientation' => '0/274', - 'SamplesPerPixel' => '', - 'PlanarConfiguration' => '', - 'YCbCrSubSampling' => '', - 'YCbCrPositioning' => '0/531', - 'XResolution' => '0/282', - 'YResolution' => '0/283', - 'ResolutionUnit' => '0/296', - - // B. Tags relating to recording offset - 'StripOffsets' => '', - 'RowsPerStrip' => '', - 'StripByteCounts' => '', - 'JPEGInterchangeFormat' => '', - 'JPEGInterchangeFormatLength' => '', - - // C. Tags relating to image data characteristics - 'TransferFunction' => '', - 'WhitePoint' => '', - 'PrimaryChromaticities' => '', - 'YCbCrCoefficients' => '', - 'ReferenceBlackWhite' => '', - - // D. Other tags - 'DateTime' => '0/306', - 'ImageDescription' => '0/270', - 'Make' => '0/271', - 'Model' => '0/272', - 'Software' => '0/305', - 'Artist' => '0/315', - 'Copyright' => '0/33432', - - // Exif IFD Attribute Information - // A. Tags Relating to Version - 'ExifVersion' => '0/34665/Data/0/36864', - 'FlashpixVersion' => '0/34665/Data/0/40960', - - // B. Tag Relating to Image Data Characteristics - 'ColorSpace' => '0/34665/Data/0/40961', - - // C. Tags Relating to Image Configuration - 'ComponentsConfiguration' => '0/34665/Data/0/37121', - 'CompressedBitsPerPixel' => '0/34665/Data/0/37122', - 'PixelXDimension' => '0/34665/Data/0/40962', - 'PixelYDimension' => '0/34665/Data/0/40963', - - // D. Tags Relating to User Information - //'MakerNote' => '', too big to store!! - 'UserComment' => '0/34665/Data/0/37510', - - // E. Tag Relating to Related File Information - 'RelatedSoundFile' => '', - - // F. Tags Relating to Date and Time - 'DateTimeOriginal' => '0/34665/Data/0/36867', - 'DateTimeDigitized' => '0/34665/Data/0/36868', - 'SubSecTime' => '', - 'SubSecTimeOriginal' => '', - 'SubSecTimeDigitized' => '', - - // G. Tags Relating to Picture-Taking Conditions - 'ExposureTime' => '0/34665/Data/0/33434', - 'FNumber' => '0/34665/Data/0/33437', - 'ExposureProgram' => '0/34665/Data/0/34850', - 'SpectralSensitivity' => '', - 'ISOSpeedRatings' => '0/34665/Data/0/34855', - 'OECF' => '', - 'ShutterSpeedValue' => '0/34665/Data/0/37377', - 'ApertureValue' => '0/34665/Data/0/37378', - 'BrightnessValue' => '0/34665/Data/0/37379', - 'ExposureBiasValue' => '0/34665/Data/0/37380', - 'MaxApertureValue' => '0/34665/Data/0/37381', - 'SubjectDistance' => '0/34665/Data/0/37382', - 'MeteringMode' => '0/34665/Data/0/37383', - 'LightSource' => '0/34665/Data/0/37384', - 'Flash' => '0/34665/Data/0/37385', - 'FocalLength' => '0/34665/Data/0/37386', - 'SubjectArea' => '', - 'FlashEnergy' => '', - 'SpatialFrequencyResponse' => '', - 'FocalPlaneXResolution' => '0/34665/Data/0/41486', - 'FocalPlaneYResolution' => '0/34665/Data/0/41487', - 'FocalPlaneResolutionUnit' => '0/34665/Data/0/41488', - 'SubjectLocation' => '', - 'ExposureIndex' => '', - 'SensingMethod' => '0/34665/Data/0/41495', - 'FileSource' => '0/34665/Data/0/41728', - 'SceneType' => '0/34665/Data/0/41729', - 'CFAPattern' => '', - 'CustomRendered' => '0/34665/Data/0/41985', - 'ExposureMode' => '0/34665/Data/0/41986', - 'WhiteBalance' => '0/34665/Data/0/41987', - 'DigitalZoomRatio' => '0/34665/Data/0/41988', - 'FocalLengthIn35mmFilm' => '', - 'SceneCaptureType' => '0/34665/Data/0/41990', - 'GainControl' => '0/34665/Data/0/41991', - 'Contrast' => '0/34665/Data/0/41992', - 'Saturation' => '0/34665/Data/0/41993', - 'Sharpness' => '0/34665/Data/0/41994', - 'DeviceSettingDescription' => '', - 'SubjectDistanceRange' => '', - - // H. Other Tags - 'ImageUniqueID' => '', - - // GPS Attribute Information - // A. Tags Relating to GPS - 'GPSVersionID' => '0/34853/Data/0/0', - 'GPSLatitudeRef' => '0/34853/Data/0/1', - 'GPSLatitude' => '0/34853/Data/0/2', - 'GPSLongitudeRef' => '0/34853/Data/0/3', - 'GPSLongitude' => '0/34853/Data/0/4', - 'GPSAltitudeRef' => '0/34853/Data/0/5', - 'GPSAltitude' => '0/34853/Data/0/6', - 'GPSTimeStamp' => '0/34853/Data/0/7', - 'GPSSatellites' => '0/34853/Data/0/8', - 'GPSStatus' => '0/34853/Data/0/9', - 'GPSMeasureMode' => '0/34853/Data/0/10', - 'GPSDOP' => '0/34853/Data/0/11', - 'GPSSpeedRef' => '0/34853/Data/0/12', - 'GPSSpeed' => '0/34853/Data/0/13', - 'GPSTrackRef' => '0/34853/Data/0/14', - 'GPSTrack' => '0/34853/Data/0/15', - 'GPSImgDirectionRef' => '0/34853/Data/0/16', - 'GPSImgDirection' => '0/34853/Data/0/17', - 'GPSMapDatum' => '0/34853/Data/0/18', - 'GPSDestLatitudeRef' => '0/34853/Data/0/19', - 'GPSDestLatitude' => '0/34853/Data/0/20', - 'GPSDestLongitudeRef' => '0/34853/Data/0/21', - 'GPSDestLongitude' => '0/34853/Data/0/22', - 'GPSDestBearingRef' => '0/34853/Data/0/23', - 'GPSDestBearing' => '0/34853/Data/0/24', - 'GPSDestDistanceRef' => '0/34853/Data/0/25', - 'GPSDestDistance' => '0/34853/Data/0/26', - 'GPSProcessingMethod' => '0/34853/Data/0/27', - 'GPSAreaInformation' => '0/34853/Data/0/28', - 'GPSDateStamp' => '0/34853/Data/0/29', - 'GPSDifferential' => '0/34853/Data/0/30', - - // Custom Makernotes http://www.ozhiker.com/electronics/pjmt/jpeg_info/makernotes.html - // there are several tags: camera settings etc. might be usefull - - // Canon - // overwrite Artist => 0/315 - //'OwnerName' => 'Makernote_Tag/Decoded Data/0/9' - - // Casio - - // Fujifilm - - // Konica/Minolta - - // Nikon - - // Olympus - - // Panasonic - - // Ricoh - - 'JpegComment' => '' - ); - } - - + function createIptcTable($array='') { if(empty($array)) @@ -845,7 +246,7 @@ foreach($array AS $key=>$value) { - $str .= linSql::linAddslashes(strtolower($value))." VARCHAR(255), "; + $str .= LinSql::linAddslashes(strtolower($value))." VARCHAR(255), "; } $str .= "PRIMARY KEY (md5sum), "; $str .= "KEY (md5sum) )"; @@ -879,9 +280,215 @@ $str = substr($str,0,strlen($str)-2).")"; } return $str; + } + +} // end class LinMetaDataAdmin + + +/** + * Index functions (save data in DB) + */ +class LinMetaDataIndex extends LinMetaData +{ + /** + * wrapper function for saveExifData and saveIptcDate for easier access + */ + function saveData($what,$filename,$md5sum) + { + /** + * no double entries + * do this check at very first position to improve performance! + * also do not setFields in the __contruct() because they may never be used + */ + $query = $GLOBALS['linpha']->db->Execute("SELECT md5sum FROM ".LIN_PREFIX."meta_".$what." ". + "WHERE md5sum = '".$md5sum."'"); + + if( $query->EOF) // not a single value returned + { + /** + * define tags to index if not already done + */ + if( !isset($this->defined_fields[$what])) + { + $this->setFields($what); + } + + switch($what) + { + case 'exif': + $this->saveExifData($filename,$md5sum); + break; + case 'iptc': + $this->saveIptcData($filename,$md5sum); + break; + } + } } + + /** + * store EXIF data in DB + * + * create an entry in the db even if we haven't found anything + * to prevent img_view.class.php to call this function every time + * the image is viewed + */ + function saveExifData($filename,$md5sum) + { + include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); // used for jpeg comment + include_once(LINPHA_DIR.'/lib/classes/phpmeta/EXIF.php'); + $str_columns = "md5sum, "; + $str_values = "'".$md5sum."', "; + + /** + * get exif info from file + */ + $exif_data = get_EXIF_JPEG( $filename ); + if( $exif_data) + { + /** + * special tags + */ + // Canon Owner Name append to Artist + if(isset($exif_data['Makernote_Tag']['Decoded Data']) + && is_array($exif_data['Makernote_Tag']['Decoded Data']) // sometimes 'Decoded Data' is an empty string + && isset($exif_data['Makernote_Tag']['Decoded Data'][0][9]['Text Value'])) + { + $owner = $exif_data['Makernote_Tag']['Decoded Data'][0][9]['Text Value']; + if(isset($exif_data[0][315]['Text Value'])) + { + $exif_data[0][315]['Text Value'] .= $owner; + } + else + { + $exif_data[0][315]['Text Value'] = $owner; + } + + } + + /** + * search for valid tags + */ + foreach($this->defined_fields['exif'] AS $key=>$value) + //foreach(LinMetaData::$Tags['exif'] AS $key=>$value) + { + if( !empty(LinMetaData::$Tags['exif'][$key]['pathvalue']) ) + { + /** + * there are currently only entries at level deep 2 and 5 in the array + */ + $array_pieces = explode('/',$value['pathvalue']); + switch(count($array_pieces)) + { + case 2: + if(isset($exif_data[ $array_pieces[0] ][ $array_pieces[1] ]['Text Value'])) + { + $str_columns .= $key.', '; + + $exif_value = $exif_data[ $array_pieces[0] ][ $array_pieces[1] ]['Text Value']; + $str_values .= "'".LinSql::linAddslashes(trim( $exif_value ))."', "; + } + break; + case 5: + if(isset($exif_data[ $array_pieces[0] ][ $array_pieces[1] ][ $array_pieces[2] ][ $array_pieces[3] ][ $array_pieces[4] ]['Text Value'])) + { + $str_columns .= $key.', '; + + $exif_value = $exif_data[ $array_pieces[0] ][ $array_pieces[1] ][ $array_pieces[2] ][ $array_pieces[3] ][ $array_pieces[4] ]['Text Value']; + $str_values .= "'".LinSql::linAddslashes(trim( $exif_value ))."', "; + } + break; + default: + echo "Error no valid path for key: ".$key." value: ".$value['pathvalue']."<br />"; + break; + } + } + } + + /** + * add jpegcomment + */ + if(isset($this->defined_fields['exif']['jpegcomment'])) + { + $jpeg_header_data = get_jpeg_header_data( $filename ); + $comment = get_jpeg_Comment( $jpeg_header_data ); + if(!empty($comment)) + { + $str_columns .= 'jpegcomment, '; + $str_values .= "'".LinSql::linAddslashes(trim( $comment ))."', "; + } + } + } + + /** + * remove last two signs (the comma and the space) which we added to much + */ + $str_columns = substr($str_columns,0,strlen($str_columns)-2); + $str_values = substr($str_values,0,strlen($str_values)-2); + + + $GLOBALS['linpha']->db->Execute("INSERT into ".LIN_PREFIX."meta_exif (".$str_columns.") ". + "VALUES (".$str_values.")"); + } + /** + * store IPTC data in DB + */ + function saveIptcData($filename, $md5sum) + { + include_once(LINPHA_DIR.'/lib/classes/phpmeta/Photoshop_IRB.php'); + include_once(LINPHA_DIR.'/lib/classes/phpmeta/JPEG.php'); + + $str_columns = "md5sum, "; + $str_values = "'".$md5sum."', "; + + // Retrieve the header information + $jpeg_header_data = get_jpeg_header_data($filename); + + if( $jpeg_header_data ) + { + // get array with all available IPTC data + $IPTC_Info = get_Photoshop_IPTC(get_Photoshop_IRB($jpeg_header_data)); + + if(is_array($IPTC_Info)) + { + /** + * search for valid tags + */ + foreach($this->defined_fields['iptc'] AS $key=>$value) + { + if( !empty(LinMetaData::$Tags['iptc'][$key]['path']) ) + { + $str_columns .= $key.', '; + $str_values .= "'"; + + foreach($IPTC_Info as $IPTC_Record) + { + if( $IPTC_Record['IPTC_Type'] == LinMetaData::$Tags['iptc'][$key]['path'] ) + { + $str_values .= "".LinSql::linAddslashes(trim( $IPTC_Record['RecData'] ))." "; + + } + } + + $str_values .= "', "; + } + } + } + } + + /** + * remove last two signs (the comma and the space) which we added to much + */ + $str_columns = substr($str_columns,0,strlen($str_columns)-2); + $str_values = substr($str_values,0,strlen($str_values)-2); + + + $GLOBALS['linpha']->db->Execute("INSERT into ".LIN_PREFIX."meta_iptc (".$str_columns.") ". + "VALUES (".$str_values.")"); + } + + /** * Autorotate Images via EXIF tag * Most Images contain an orientation tag which shows if and how to rotate * the images @@ -889,8 +496,8 @@ * @return degrees to rotate * @author bzrudi */ - function getRotationByExifTag($rotation) - { + function getRotationByExifTag($rotation) + { if(is_numeric($rotation)) { switch($rotation) @@ -970,188 +577,318 @@ return mktime($hour,$min,$sec,$month,$day,$year); } -} // end class metadata +} // end class LinMetaDataIndex -$GLOBALS['Tags_Exif'] = Array( - // TIFF Rev. 6.0 Attribute Information - // A. Tags relating to image data structure - 'imagewidth' => 'Image Width', - 'imagelength' => 'Image Length', - 'bitspersample' => 'Bits Per Sample', - 'compression' => 'Compression', - 'photometricinterpretation' => 'Photometric Interpretation', - 'orientation' => 'Orientation', - 'samplesperpixel' => 'Samples Per Pixel', - 'planarconfiguration' => 'Planar Configuration', - 'ycbcrsubsampling' => 'YCbCr Sub Sampling', - 'ycbcrpositioning' => 'YCbCr Positioning', - 'xresolution' => 'X Resolution', - 'yresolution' => 'Y Resolution', - 'resolutionunit' => 'Resolution Unit', - - // B. Tags relating to recording offset - 'stripoffsets' => 'Strip Offsets', - 'rowsperstrip' => 'Rows Per Strip', - 'stripbytecounts' => 'Strip Byte Counts', - 'jpeginterchangeformat' => 'JPEG Interchange Format', - 'jpeginterchangeformatlength' => 'JPEG Interchange Format Length', - - // C. Tags relating to image data characteristics - 'transferfunction' => 'Transfer Function', - 'whitepoint' => 'White Point', - 'primarychromaticities' => 'Primary Chromaticities', - 'ycbcrcoefficients' => 'YCbCr Coefficients', - 'referenceblackwhite' => 'Reference Black White', - - // D. Other tags - 'datetime' => 'Date Time', - 'imagedescription' => 'Image Description', - 'make' => 'Make', - 'model' => 'Model', - 'software' => 'Software', - 'artist' => 'Artist', - 'copyright' => 'Copyright', - -// Exif IFD Attribute Information - // A. Tags Relating to Version - 'exifversion' => 'Exif Version', - 'flashpixversion' => 'FlashPix Version', - - // B. Tag Relating to Image Data Characteristics - 'colorspace' => 'Color Space', - - // C. Tags Relating to Image Configuration - 'componentsconfiguration' => 'Components Configuration', - 'compressedbitsperpixel' => 'Compressed Bits Per Pixel', - 'pixelxdimension' => 'Pixel X Dimension', - 'pixelydimension' => 'Pixel Y Dimension', - - // D. Tags Relating to User Information - //'makernote' => 'MakerNote', too big to store!! - 'usercomment' => 'User Comment', - - // E. Tag Relating to Related File Information - 'relatedsoundfile' => 'Related Sound File', - - // F. Tags Relating to Date and Time - 'datetimeoriginal' => 'Date Time Original', - 'datetimedigitized' => 'Date Time Digitized', - 'subsectime' => 'Sub Sec Time', - 'subsectimeoriginal' => 'Sub Sec Time Original', - 'subsectimedigitized' => 'Sub Sec Time Digitized', - - // G. Tags Relating to Picture-Taking Conditions - 'exposuretime' => 'Exposure Time', - 'fnumber' => 'F Number', - 'exposureprogram' => 'Exposure Program', - 'spectralsensitivity' => 'Spectral Sensitivity', - 'isospeedratings' => 'ISO Speed Ratings', - 'oecf' => 'OECF', - 'shutterspeedvalue' => 'Shutter Speed Value', - 'aperturevalue' => 'Aperture Value', - 'brightnessvalue' => 'Brightness Value', - 'exposurebiasvalue' => 'Exposure Bias Value', - 'maxaperturevalue' => 'MaxAperture Value', - 'subjectdistance' => 'Subject Distance', - 'meteringmode' => 'Metering Mode', - 'lightsource' => 'Light Source', - 'flash' => 'Flash', - 'focallength' => 'Focal Length', - 'subjectarea' => 'Subject Area', - 'flashenergy' => 'Flash Energy', - 'spatialfrequencyresponse' => 'Spatial Frequency Response', - 'focalplanexresolution' => 'Focal Plane X Resolution', - 'focalplaneyresolution' => 'Foca Plane Y Resolution', - 'focalplaneresolutionunit' => 'Focal Plane Resolution Unit', - 'subjectlocation' => 'Subject Location', - 'exposureindex' => 'Exposure Index', - 'sensingmethod' => 'Sensing Method', - 'filesource' => 'File Source', - 'scenetype' => 'Scene Type', - 'cfapattern' => 'CFA Pattern', - 'customrendered' => 'Custom Rendered', - 'exposuremode' => 'Exposure Mode', - 'whitebalance' => 'White Balance', - 'digitalzoomratio' => 'Digital Zoom Ratio', - 'focallengthin35mmfilm' => 'Focal Length In 35mm Film', - 'scenecapturetype' => 'Scene Capture Type', - 'gaincontrol' => 'Gain Control', - 'contrast' => 'Contrast', - 'saturation' => 'Saturation', - 'sharpness' => 'Sharpness', - 'devicesettingdescription' => 'Device Setting Description', - 'subjectdistancerange' => 'Subject Distance Range', - - // H. Other Tags - 'imageuniqueid' => 'Image Unique ID', - -// GPS Attribute Information - // A. Tags Relating to GPS - 'gpsversionid' => 'GPS Version ID', - 'gpslatituderef' => 'GPS Latitude Ref', - 'gpslatitude' => 'GPS Latitude', - 'gpslongituderef' => 'GPS Longitude Ref', - 'gpslongitude' => 'GPS Longitude', - 'gpsaltituderef' => 'GPS Altitude Ref', - 'gpsaltitude' => 'GPS Altitude', - 'gpstimestamp' => 'GPS Timestamp', - 'gpssatellites' => 'GPS Satellites', - 'gpsstatus' => 'GPS Status', - 'gpsmeasuremode' => 'GPS Measure Mode', - 'gpsdop' => 'GPS DOP', - 'gpsspeedref' => 'GPS Speed Ref', - 'gpsspeed' => 'GPS Speed', - 'gpstrackref' => 'GPS Track Ref', - 'gpstrack' => 'GPS Track', - 'gpsimgdirectionref' => 'GPS Img Direction Ref', - 'gpsimgdirection' => 'GPS Img Direction', - 'gpsmapdatum' => 'GPS Map Datum', - 'gpsdestlatituderef' => 'GPS Dest Latitude Ref', - 'gpsdestlatitude' => 'GPS Dest Latitude', - 'gpsdestlongituderef' => 'GPS Dest Longitude Ref', - 'gpsdestlongitude' => 'GPS Dest Longitude', - 'gpsdestbearingref' => 'GPS Dest Bearing Ref', - 'gpsdestbearing' => 'GPS Dest Bearing', - 'gpsdestdistanceref' => 'GPS Dest Distance Ref', - 'gpsdestdistance' => 'GPS Dest Distance', - 'gpsprocessingmethod' => 'GPS Processing Method', - 'gpsareainformation' => 'GPS Area Information', - 'gpsdatestamp' => 'GPS DateStamp', - 'gpsdifferential' => 'GPS Differential', - -// Custom Makernotes - 'jpegcomment' => 'JPEG Comment' -); +/** + * Modificate metadata and save the information back to the file (iptc and xmp) + */ +class LinMetaDataModificate extends LinMetaData +{ -$GLOBALS['Tags_Iptc'] = Array( - 'caption' => 'Caption', - 'caption_writer' => 'Caption Writer', - 'headline' => 'Headline', - 'instructions' => 'Special Instructions', - 'keywords' => 'Keywords', - 'category' => 'Category', - 'supplemental_categorie' => 'Supplemental Category', - 'copyright' => 'Copyright Notice', - 'byline' => 'By-Line (Author)', - 'byline_title' => 'By-Line Title', - 'credit' => 'Credit', - 'source' => 'Source', - 'edit_status' => 'Edit Status', - 'priority' => 'Priority', - 'object_cycle' => 'Object Cycle', - 'job_id' => 'Fixture Identifier', - 'program' => 'Originating Program', - 'object_name' => 'Object Name (Title)', - 'date_created' => 'Date Created', - 'date_released' => 'Release Date', - 'time_created' => 'Time Created', - 'time_released' => 'Release Time', - 'city' => 'City', - 'sublocation' => 'Sub-Location', - 'state' => 'Province/State', - 'country' => 'Country Name', - 'country_code' => 'Country Code', - 'trans_reference' => 'Transmission Reference' -); +/** + * edit iptc functions + */ + /** + * edit IPTC Data in HTML popup + */ + function editIptcData() + { + + } + + /** + * save modified IPTC data to DB + */ + function saveModIptcData() + { + + } + +} // end class LinMetaDataModificate + + +/** + * class LinMetaData + * + * some common definitions which are used in more than one child class of LinMetaData + */ +class LinMetaData +{ + public $available_fields, $defined_fields; + + static $Tags = array( + + 'exif' => array( + // TIFF Rev. 6.0 Attribute Information + // A. Tags relating to image data structure + 'imagewidth' => array('name' => 'Image Width', 'pathkey' => 'ImageWidth', 'pathvalue' => ''), + 'imagelength' => array('name' => 'Image Length', 'pathkey' => 'ImageLength', 'pathvalue' => ''), + 'bitspersample' => arra... [truncated message content] |