function wppa_copy_iptc($fromphoto, $tophoto) { global $wpdb; $iptclines = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_IPTC . "` WHERE `photo` = %s", $fromphoto), ARRAY_A); if ($iptclines) { foreach ($iptclines as $line) { $id = wppa_create_iptc_entry(array('photo' => $tophoto, 'tag' => $line['tag'], 'description' => $line['description'], 'status' => $line['status'])); } } }
function wppa_import_iptc($id, $info, $nodelete = false) { global $wpdb; static $labels; $doit = false; // Do we need this? if (wppa_switch('wppa_save_iptc')) { $doit = true; } if (substr(wppa_opt('wppa_newphoto_name_method'), 0, 2) == '2#') { $doit = true; } if (!$doit) { return; } wppa_dbg_msg('wppa_import_iptc called for id=' . $id); wppa_dbg_msg('array is' . (is_array($info) ? ' ' : ' NOT ') . 'available'); wppa_dbg_msg('APP13 is ' . (isset($info['APP13']) ? 'set' : 'NOT set')); // Is iptc data present? if (!isset($info['APP13'])) { return false; } // No iptc data avail //var_dump( $info ); // Parse $iptc = iptcparse($info['APP13']); if (!is_array($iptc)) { return false; } // No data avail // There is iptc data for this image. // First delete any existing ipts data for this image if (!$nodelete) { $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_IPTC . "` WHERE `photo` = %s", $id)); wppa_dbg_q('Q214'); } // Find defined labels if (!is_array($labels)) { $result = $wpdb->get_results("SELECT `tag` FROM `" . WPPA_IPTC . "` WHERE `photo` = '0' ORDER BY `tag`", ARRAY_N); wppa_dbg_q('Q215'); if (!is_array($result)) { $result = array(); } $labels = array(); foreach ($result as $res) { $labels[] = $res['0']; } } foreach (array_keys($iptc) as $s) { // Check for valid item if ($s == '2#000') { continue; } // Skip this one if (is_array($iptc[$s])) { $c = count($iptc[$s]); for ($i = 0; $i < $c; $i++) { // Process item wppa_dbg_msg('IPTC ' . $s . ' = ' . $iptc[$s][$i]); // Check labels first if (!in_array($s, $labels)) { // Add to labels $labels[] = $s; // Add to db $photo = '0'; $tag = $s; $desc = $s . ':'; if ($s == '2#005') { $desc = 'Graphic name:'; } if ($s == '2#010') { $desc = 'Urgency:'; } if ($s == '2#015') { $desc = 'Category:'; } if ($s == '2#020') { $desc = 'Supp categories:'; } if ($s == '2#040') { $desc = 'Spec instr:'; } if ($s == '2#055') { $desc = 'Creation date:'; } if ($s == '2#080') { $desc = 'Photographer:'; } if ($s == '2#085') { $desc = 'Credit byline title:'; } if ($s == '2#090') { $desc = 'City:'; } if ($s == '2#095') { $desc = 'State:'; } if ($s == '2#101') { $desc = 'Country:'; } if ($s == '2#103') { $desc = 'Otr:'; } if ($s == '2#105') { $desc = 'Headline:'; } if ($s == '2#110') { $desc = 'Source:'; } if ($s == '2#115') { $desc = 'Photo source:'; } if ($s == '2#120') { $desc = 'Caption:'; } $status = 'display'; if ($s == '1#090') { $status = 'hide'; } if ($desc == $s . ':') { $status = 'hide'; } // if ( $s == '2#000' ) $status = 'hide'; $iret = wppa_create_iptc_entry(array('photo' => $photo, 'tag' => $tag, 'description' => $desc, 'status' => $status)); if (!$iret) { wppa_log('Warning', 'Could not add IPTC tag ' . $tag . ' for photo ' . $photo); } } // Now add poto specific data item $photo = $id; $tag = $s; $desc = $iptc[$s][$i]; $status = 'default'; $iret = wppa_create_iptc_entry(array('photo' => $photo, 'tag' => $tag, 'description' => $desc, 'status' => $status)); if (!$iret) { wppa_log('Warning', 'Could not add IPTC tag ' . $tag . ' for photo ' . $photo); } } } } wppa_iptc_clean_garbage($id); }