function wppa_copy_exif($fromphoto, $tophoto) { global $wpdb; $exiflines = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo` = %s", $fromphoto), ARRAY_A); if ($exiflines) { foreach ($exiflines as $line) { $id = wppa_create_exif_entry(array('photo' => $tophoto, 'tag' => $line['tag'], 'description' => $line['description'], 'status' => $line['status'])); } } }
function wppa_import_exif($id, $file, $nodelete = false) { global $wpdb; static $labels; static $names; global $wppa; // Do we need this? if (!wppa_switch('wppa_save_exif')) { return; } // Check filetype if (!function_exists('exif_imagetype')) { return false; } $image_type = exif_imagetype($file); if ($image_type != IMAGETYPE_JPEG) { return false; } // Not supported image type // Get exif data if (!function_exists('exif_read_data')) { return false; } // Not supported by the server $exif = @exif_read_data($file, 'EXIF'); if (!is_array($exif)) { return false; } // No data present // There is exif data for this image. // First delete any existing exif data for this image if (!$nodelete) { $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_EXIF . "` WHERE `photo` = %s", $id)); wppa_dbg_q('Q218'); } // Find defined labels if (!is_array($labels)) { $result = $wpdb->get_results("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo` = '0' ORDER BY `tag`", ARRAY_A); wppa_dbg_q('Q219'); if (!is_array($result)) { $result = array(); } $labels = array(); $names = array(); foreach ($result as $res) { $labels[] = $res['tag']; $names[] = $res['description']; } } foreach (array_keys($exif) as $s) { // Process item wppa_dbg_msg('EXIF ' . $s . ' = ' . serialize($exif[$s])); // Check labels first $tag = ''; if (in_array($s, $names)) { $i = 0; while ($i < count($labels)) { if ($names[$i] == $s) { $tag = $labels[$i]; } } } if ($tag == '') { $tag = wppa_exif_tag($s); } if ($tag == 'E#EA1C') { $tag = ''; } // EA1C is explixitly undefined and will fail to register if ($tag == '') { continue; } if (!in_array($tag, $labels)) { // Add to labels $labels[] = $tag; $names[] = $s . ':'; // Add to db $photo = '0'; $desc = $s . ':'; $status = 'display'; if (substr($s, 0, 12) == 'UndefinedTag') { $status = 'hide'; } $iret = wppa_create_exif_entry(array('photo' => $photo, 'tag' => $tag, 'description' => $desc, 'status' => $status)); if (!$iret) { wppa_log('Warning 1', 'Could not add EXIF tag ' . $tag . ' for photo ' . $photo); } } // Now add poto specific data item // If its an array... if (is_array($exif[$s])) { // continue; $c = count($exif[$s]); $max = wppa_opt('wppa_exif_max_array_size'); if ($max != '0' && $c > $max) { wppa_dbg_msg('Exif tag ' . $tag . ': array truncated form ' . $c . ' to ' . $max . ' elements for photo nr ' . $id . '.', 'red'); $c = $max; } for ($i = 0; $i < $c; $i++) { $photo = $id; $desc = $exif[$s][$i]; $status = 'default'; $iret = wppa_create_exif_entry(array('photo' => $photo, 'tag' => $tag, 'description' => $desc, 'status' => $status)); if (!$iret) { wppa_log('Warning 2', 'Could not add EXIF tag ' . $tag . ' for photo ' . $photo); } } } else { $photo = $id; $desc = $exif[$s]; $status = 'default'; $iret = wppa_create_exif_entry(array('photo' => $photo, 'tag' => $tag, 'description' => $desc, 'status' => $status)); if (!$iret) { } /* wppa_log( 'Warning 3', 'Could not add EXIF tag '.$tag.' for photo '.$photo.', desc = '.$desc ); */ // Is junk, dont care } } wppa_exif_clean_garbage($id); }