public function editImageDataAction()
{
if ($this->getRequest()->isPost()) {
$data = $this->_getParam('data');
if (is_array($data)) {
foreach ($data as $id => $values) {
if (!empty($values['description']) || !empty($values['place']) || !empty($values['photographer'])) {
$image = $this->_helper->service('image')->find($id);
$image->setDescription($values['description']);
$image->setPlace($values['place']);
$image->setPhotographer($values['photographer']);
if ($values['date'] && $values['date'] != '0000-00-00') {
$image->setDate($values['date']);
} else {
$image->setDate(date('Y-m-d'));
}
}
}
$this->_helper->entity->flushManager();
}
$parameters = $this->getRequest()->getParams();
$next = $parameters['next'];
if ($next == 1) {
$this->_helper->redirector('article', 'image', 'admin', array('article_number' => $this->_getParam('article_number')));
}
}
$this->view->article = $this->_getParam('article_number');
$this->view->languageId = $this->_getParam('language_id');
$this->_helper->layout->setLayout('iframe');
$images = array();
$articleImages = $this->_helper->service('image')->findByArticle($this->_getParam('article_number'));
foreach ($articleImages as $k => $articleImage) {
unset($exifDate);
unset($iptcDate);
unset($iptcPlace);
unset($iptcPhotographer);
unset($iptcDescription);
$image = $articleImage->getImage();
$allowedExtensions = array('jpg', 'jpeg', 'tiff', 'tif');
$imagePathParts = explode('.', $image->getPath());
$imageExtension = strtolower($imagePathParts[count($imagePathParts) - 1]);
if (in_array($imageExtension, $allowedExtensions)) {
$exif = @exif_read_data($image->getPath());
if (isset($exif['DateTime'])) {
$exifDate = date('Y-m-d', strtotime($exif['DateTime']));
}
$size = getimagesize($image->getPath(), $info);
$iptc = array();
foreach ($info as $key => $value) {
$iptc[$key] = iptcparse($value);
}
if (isset($iptc['APP13'])) {
$iptc = $iptc['APP13'];
}
if (isset($iptc['2#055'])) {
$iptcDate = $iptc['2#055'][0];
$iptcDate = date('Y-m-d', strtotime($iptcDate));
}
if (isset($iptc['2#080'])) {
$iptcPhotographer = $iptc['2#080'][0];
}
if (isset($iptc['2#120'])) {
$iptcDescription = $iptc['2#120'][0];
}
if (isset($iptc['2#090']) || isset($iptc['2#092']) || isset($iptc['2#101'])) {
$iptcPlace = array();
if (isset($iptc['2#101'])) {
$iptcPlace[] = $iptc['2#101'][0];
}
if (isset($iptc['2#090'])) {
$iptcPlace[] = $iptc['2#090'][0];
}
if (isset($iptc['2#092'])) {
$iptcPlace[] = $iptc['2#092'][0];
}
$iptcPlace = implode(', ', $iptcPlace);
}
}
if ($image->getDescription() == '') {
if (isset($iptcPhotographer)) {
$image->setPhotographer($iptcPhotographer);
}
if (isset($iptcDescription)) {
$image->setDescription($iptcDescription);
}
if (isset($iptcPlace)) {
$image->setPlace($iptcPlace);
}
if (isset($exifDate)) {
$image->setDate($exifDate);
}
if (isset($iptcDate)) {
$image->setDate($iptcDate);
}
$images[] = $image;
} elseif ($this->_getParam('force_edit')) {
$images[] = $image;
}
}
$this->view->images = $images;
}