Hi, here is the modified code for importing IPTC data:
<?php
/**
* @version $Id$
* @copyright Center for History and New Media, 2007-2008
* @license
http://www.gnu.org/licenses/gpl-3.0.txt
* @package Omeka
**/
/**
* @todo Testing.
* @package Omeka
* @subpackage Models
* @author CHNM
* @copyright Center for History and New Media, 2007-2008
**/
class FilesImages
{
public $iptc_string;
public $iptc_array;
public function initialize($id3, $pathToFile)
{
$this->id3 = $id3;
$this->pathToFile = $pathToFile;
// Extract EXIF data if possible.
if (function_exists('exif_read_data') and ($exif =
@exif_read_data($this->pathToFile))) {
$this->exif = $exif;
} else {
$this->exif = array();
}
//add iptc image metadata extract customized content
$imageinfo = null;
if(function_exists('getimagesize'))
$imagesize = getimagesize($this->pathToFile, $imageinfo);
//
// Extract IPTC data also if possible.
if ($iptc = $this->get_iptc_info($imageinfo["APP13"])) {
$this->iptc = $iptc;
} else {
$this->iptc = array();
}
}
private function get_iptc_info($info) {
$iptc_match = array();
$iptc_match['2#120'] = "caption";
$iptc_match['2#122'] = "caption_writer";
$iptc_match['2#105'] = "headline";
$iptc_match['2#040'] = "special_instructions";
$iptc_match['2#080'] = "byline";
$iptc_match['2#085'] = "byline_title";
$iptc_match['2#110'] = "credit";
$iptc_match['2#115'] = "source";
$iptc_match['2#005'] = "object_name";
$iptc_match['2#055'] = "date_created";
$iptc_match['2#090'] = "city";
$iptc_match['2#095'] = "state";
$iptc_match['2#101'] = "country";
$iptc_match['2#103'] = "original_transmission_reference";
$iptc_match['2#015'] = "category";
$iptc_match['2#020'] = "supplemental_category";
$iptc_match['2#025'] = "keyword";
$iptc_match['2#116'] = "copyright_notice";
$iptc = iptcparse($info);
$iptc_array = array();
if (is_array($iptc)) {
foreach ($iptc as $key => $val) {
if (isset($iptc_match[$key])) {
$iptc_info = "";
foreach ($val as $val2) {
$iptc_info .= (($iptc_info != "" ) ? ", " : "").$val2;
}
if ($key == "2#055") {
$iptc_array[$iptc_match[$key]] = preg_replace("/([0-9]{4})
([0-9]{2})([0-9]{2})/", "\\3.\\2.\\1", $iptc_info);
}
else {
$iptc_array[$iptc_match[$key]] = $this->replace_url
($iptc_info);
}
}
}
}
return $iptc_array;
}
private function replace_url($text) {
$text = " ".$text." ";
$url_search_array = array(
"#([^]_a-z0-9-=\"'\/])([a-z]+?)://([^, \(\)<>\n\r]+)#si",
"#([^]_a-z0-9-=\"'\/])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/
[^, \(\)<>\n\r]*)?)#si"
);
$url_replace_array = array(
"\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>",
"\\1<a href=\"
http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\
\3\\4</a>"
);
$text = preg_replace($url_search_array, $url_replace_array, $text);
if (strpos($text, "@")) {
$text = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]
+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text);
}
return trim($text);
}
public function getWidth()
{
return $this->size[0];
}
public function getHeight()
{
return $this->size[1];
}
public function getBitDepth()
{
return $this->size['bits'];
}
public function getChannels()
{
return $this->size['channels'];
}
public function getExifArray()
{
if (!empty($this->exif)) {
return serialize($this->exif);
}
}
public function getExifString()
{
//Convert the exif to a string as for to store it
$exif_string = '';
foreach ($this->exif as $k => $v) {
$exif_string .= $k . ':';
if (is_array($v)) {
$exif_string .= "\n";
foreach ($v as $key => $value) {
$exif_string .= "\t" . $key . ':' . $value .
"\n";
}
} else {
$exif_string .= $v;
}
$exif_string .= "\n";
}
return $exif_string;
}
public function getIPTCArray()
{
return $this->iptc;
}
public function getIPTCString()
{
return print_r($this->iptc, true);