public static function ImagesUpdateSaveHandler(Form $form) { try { /** @var $image GalleryImageModel */ $image = $form->getModel('image'); } catch (Exception $e) { Core::SetMessage($e->getMessage(), 'error'); return false; } $metas = new \Core\Filestore\FileMetaHelper($image->getOriginalFile()); // Set the meta information from the form. foreach ($form->getElements() as $el) { /** @var $el FormElement */ $name = $el->get('name'); if (strpos($name, 'metas[') !== 0) { continue; } $name = substr($name, 6, -1); $metas->setMeta($name, $el->get('value')); } // If no title was set, I need to pick one by default. if (!$metas->getMetaTitle('title')) { // Generate a moderately meaningful title from the filename. $title = $image->getOriginalFile()->getBasename(true); $title = preg_replace('/[^a-zA-Z0-9 ]/', ' ', $title); $title = trim(preg_replace('/[ ]+/', ' ', $title)); $title = ucwords($title); $metas->setMeta('title', $title); } if (!$image->exists()) { // Figure out the largest weight of this album. // Note, this is NOT the size of the images, as one or more may have been deleted after uploading. $last = GalleryImageModel::Find(array('albumid' => $image->get('albumid')), 1, 'weight DESC'); $weight = $last ? $last->get('weight') : 0; $image->set('weight', $weight); } // Don't forget to keep the metatags in sync! $image->set('title', $metas->getMetaTitle('title')); $action = $image->exists() ? 'Updated' : 'Added'; $image->save(); Core::SetMessage($action . ' image successfully!', 'success'); return true; }