*/ /** * This ItemAddOption allows the user to pick a watermark to apply * to the image upon upload. * * @package Watermark * @subpackage UserInterface */ class WatermarkOption extends ItemAddOption { /** * @see ItemAddOption::loadTemplate */ function loadTemplate(&$template, &$form, $item) { GalleryCoreApi::requireOnce('modules/watermark/classes/WatermarkHelper.class'); list ($ret, $watermarks) = WatermarkHelper::fetchWatermarks(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } $currentId = null; foreach (array_keys($watermarks) as $id) { if (!isset($currentId)) { $currentId = $id; } $watermarks[$id] = (array)$watermarks[$id]; } $WatermarkOption = array(); $WatermarkOption['watermarks'] = $watermarks; $WatermarkOption['currentId'] = $currentId; $template->setVariable('WatermarkOption', $WatermarkOption); return array(null, 'modules/watermark/templates/WatermarkOption.tpl', 'modules_watermark'); } /** * @see ItemAddOption::isAppropriate */ function isAppropriate() { GalleryCoreApi::requireOnce('modules/watermark/classes/WatermarkHelper.class'); /* Only appropriate if we've got some watermarks to show */ list ($ret, $watermarks) = WatermarkHelper::fetchWatermarks(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } return array(null, !empty($watermarks)); } /** * @see ItemAddOption::handleRequestAfterAdd */ function handleRequestAfterAdd($form, $items) { $errors = array(); $warnings = array(); for ($i = 0; $i < count($items); $i++) { $warnings[$i] = array(); if (!empty($form['WatermarkOption']['watermarkId']) && GalleryUtilities::isA($items[$i], 'GalleryPhotoItem')) { list ($ret, $watermark) = GalleryCoreApi::loadEntitiesById($form['WatermarkOption']['watermarkId']); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } $watermarkArray = array(DERIVATIVE_TYPE_IMAGE_THUMBNAIL => $watermark->getApplyToThumbnail(), DERIVATIVE_TYPE_IMAGE_RESIZE => $watermark->getApplyToResizes(), DERIVATIVE_TYPE_IMAGE_PREFERRED => $watermark->getApplyToPreferred()); $ret = WatermarkHelper::watermarkItem($watermark, $items[$i], $watermark->getXPercentage(), $watermark->getYPercentage(), $watermarkArray); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } } } return array(null, $errors, $warnings); } } ?>