static function extract($item) { $keys = array(); // Only try to extract IPTC from photos if ($item->is_photo() && $item->mime_type == "image/jpeg") { $info = getJpegHeader($item->file_path()); if ($info !== FALSE) { $iptcBlock = getIptcBlock($info); if ($iptcBlock !== FALSE) { $iptc = iptcparse($iptcBlock); } else { $iptc = array(); } $xmp = getXmpDom($info); foreach (self::keys() as $keyword => $iptcvar) { $iptc_key = $iptcvar[0]; $xpath = $iptcvar[2]; $value = null; if ($xpath != null) { $value = getXmpValue($xmp, $xpath); } if ($value == null) { if (!empty($iptc[$iptc_key])) { $value = implode(";", $iptc[$iptc_key]); if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { $value = utf8_encode($value); } } } if ($value != null) { $keys[$keyword] = Input::clean($value); } } } } $record = ORM::factory("iptc_record")->where("item_id", "=", $item->id)->find(); if (!$record->loaded()) { $record->item_id = $item->id; } $record->data = serialize($keys); $record->key_count = count($keys); $record->dirty = 0; $record->save(); if (array_key_exists('Keywords', $keys)) { $tags = explode(';', $keys['Keywords']); foreach ($tags as $tag) { try { tag::add($item, $tag); } catch (Exception $e) { Kohana_Log::add("error", "Error adding tag: {$tag}\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); } } } }
static function extract($item) { $keys = array(); // Only try to extract IPTC from photos if ($item->is_photo() && $item->mime_type == "image/jpeg") { $info = getJpegHeader($item->file_path()); if ($info !== FALSE) { $iptcBlock = getIptcBlock($info); if ($iptcBlock !== FALSE) { $iptc = iptcparse($iptcBlock); } else { $iptc = array(); } $xmp = getXmpDom($info); foreach (self::keys() as $keyword => $iptcvar) { $iptc_key = $iptcvar[0]; $xpath = $iptcvar[2]; $value = null; if ($xpath != null) { $value = getXmpValue($xmp, $xpath); } if ($value == null) { if (!empty($iptc[$iptc_key])) { $value = implode(";", $iptc[$iptc_key]); if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { $value = utf8_encode($value); } } } if ($value != null) { $keys[$keyword] = Input::clean($value); } } } } $record = ORM::factory("iptc_record")->where("item_id", "=", $item->id)->find(); if (!$record->loaded()) { $record->item_id = $item->id; } $record->data = serialize($keys); $record->key_count = count($keys); $record->dirty = 0; $record->save(); }