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; }
<?php /** * Created by JetBrains PhpStorm. * User: powellc * Date: 1/17/13 * Time: 10:20 PM * This is the upgrade file from 1.4.3 to 1.4.4 * * Required because with the file input change in 2.6.0 returning core resolved paths, * the data in the database will contain that path now. */ $images = GalleryImageModel::Find(); foreach ($images as $i) { /** @var $i GalleryImageModel */ // Just in case if (strpos($i->get('file'), 'public/') !== 0) { $i->set('file', 'public/galleryalbum/' . $i->get('file')); $i->save(); } // Don't forget to copy over the meta data too! // This is because the gallery system will use the new version of metadata. $u = UserModel::Construct($i->get('uploaderid')); $helper = new \Core\Filestore\FileMetaHelper($i->getOriginalFile()); $helper->setMeta('title', $i->get('title')); $helper->setMeta('keywords', explode(',', $i->get('keywords'))); $helper->setMeta('description', $i->get('description')); $helper->setMeta('authorid', $i->get('uploaderid')); if ($u && $u instanceof User_Backend) { $helper->setMeta('author', $u->getDisplayName()); }