/** * DOCUMENT ME */ public function configure() { // This call was missing, preventing easy extension of all media item edit forms at the project level parent::configure(); unset($this['id']); unset($this['type']); unset($this['service_url']); unset($this['slug']); unset($this['width']); unset($this['height']); unset($this['format']); unset($this['embed']); $this->setWidget('file', new aWidgetFormInputFilePersistent(array())); $item = $this->getObject(); // A safe assumption because we always go through the separate upload form on the first pass. // This label is a hint that changing the file is not mandatory // The 'Replace File' label is safer than superimposing a file button // on something that may or may not be a preview or generally a good thing // to try to read a button on top of $this->getWidget('file')->setLabel('Select a new file'); if (!$item->isNew()) { $this->getWidget('file')->setOption('default-preview', $item->getOriginalPath()); } $mimeTypes = aMediaTools::getOption('mime_types'); // It comes back as a mapping of extensions to types, get the types $extensions = array_keys($mimeTypes); $mimeTypes = array_values($mimeTypes); $type = false; if (!$this->getObject()->isNew()) { // You can't change the major type of an existing media object as // this would break slots (a .doc where a .gif should be...) $type = $this->getObject()->type; } // What we are selecting to add to a page if (!$type) { $type = aMediaTools::getType(); } if (!$type) { // What we are filtering for $type = aMediaTools::getSearchParameter('type'); } if ($type) { // This supports composite types like _downloadable $infos = aMediaTools::getTypeInfos($type); $extensions = array(); foreach ($infos as $info) { if ($info['embeddable']) { // This widget is actually supplying a thumbnail - allow gif, jpg and png $info['extensions'] = array('gif', 'jpg', 'png'); } foreach ($info['extensions'] as $extension) { $extensions[] = $extension; } } $mimeTypes = array(); $mimeTypesByExtension = aMediaTools::getOption('mime_types'); foreach ($extensions as $extension) { // Careful, if we are filtering for a particular type then not everything // will be on the list if (isset($mimeTypesByExtension[$extension])) { $mimeTypes[] = $mimeTypesByExtension[$extension]; } } } // The file is mandatory if it's new. Otherwise // we have a problem when they get the file type wrong // for one of two and we have to reject that one, // then they resubmit - we can add an affirmative way // to remove one item from the annotation form later $this->setValidator("file", new aValidatorFilePersistent(array("mime_types" => $mimeTypes, 'validated_file_class' => 'aValidatedFile', "required" => $this->getObject()->isNew() ? true : false), array("mime_types" => "The following file types are accepted: " . implode(', ', $extensions)))); // Necessary to work around FCK's "id and name cannot differ" problem // ... But we do it in the action which knows when that matters // $this->widgetSchema->setNameFormat('a_media_item_'.$this->getObject()->getId().'_%s'); // $this->widgetSchema->setFormFormatterName('aAdmin'); }
public function executeIndex(sfRequest $request) { $params = array(); $tag = $request->getParameter('tag'); $type = $request->getParameter('type'); $category = $request->getParameter('category'); if (aMediaTools::getType()) { $type = aMediaTools::getType(); } $search = $request->getParameter('search'); if ($request->isMethod('post')) { // Give the routing engine a shot at making the URL pretty. // We use addParams because it automatically deletes any // params with empty values. (To be fair, http_build_query can't // do that because some crappy web application might actually // use checkboxes with empty values, and that's not // technically wrong. We have the luxury of saying "reasonable // people who work here don't do that.") return $this->redirect(aUrl::addParams("aMedia/index", array("tag" => $tag, "search" => $search, "type" => $type))); } if (!empty($tag)) { $params['tag'] = $tag; } if (!empty($search)) { $params['search'] = $search; } if (!empty($type)) { $params['type'] = $type; } if (!empty($category)) { $params['category'] = $category; } $user = $this->getUser(); if ($user->isAuthenticated() && method_exists($user, "getGuardUser")) { $params['user'] = $user->getGuardUser()->getUsername(); } // Cheap insurance that these are integers $aspectWidth = floor(aMediaTools::getAttribute('aspect-width')); $aspectHeight = floor(aMediaTools::getAttribute('aspect-height')); // TODO: performance of these is not awesome (it's a linear search). // It would be more awesome with the right kind of indexing. For the // aspect ratio test to be more efficient we'd have to store the lowest // common denominator aspect ratio and index that. if ($aspectWidth && $aspectHeight) { $params['aspect-width'] = $aspectWidth; $params['aspect-height'] = $aspectHeight; } $minimumWidth = floor(aMediaTools::getAttribute('minimum-width')); if ($minimumWidth) { $params['minimum-width'] = $minimumWidth; } $minimumHeight = floor(aMediaTools::getAttribute('minimum-height')); if ($minimumHeight) { $params['minimum-height'] = $minimumHeight; } $width = floor(aMediaTools::getAttribute('width')); if ($width) { $params['width'] = $width; } $height = floor(aMediaTools::getAttribute('height')); if ($height) { $params['height'] = $height; } // The media module is now an engine module. There is always a page, and that // page might have a restricted set of categories associated with it $mediaCategories = aTools::getCurrentPage()->MediaCategories; if (count($mediaCategories)) { $params['allowed_categories'] = $mediaCategories; } $query = aMediaItemTable::getBrowseQuery($params); $this->pager = new sfDoctrinePager('aMediaItem', aMediaTools::getOption('per_page')); $this->pager->setQuery($query); $page = $request->getParameter('page', 1); $this->pager->setPage($page); $this->pager->init(); $this->results = $this->pager->getResults(); aMediaTools::setSearchParameters(array("tag" => $tag, "type" => $type, "search" => $search, "page" => $page, 'category' => $category)); $this->pagerUrl = "aMedia/index?" . http_build_query($params); if (aMediaTools::isSelecting()) { $this->selecting = true; if (aMediaTools::getAttribute("label")) { $this->label = aMediaTools::getAttribute("label"); } $this->limitSizes = false; if ($aspectWidth || $aspectHeight || $minimumWidth || $minimumHeight || $width || $height) { $this->limitSizes = true; } } }
} else { ?> <input type="image" src="<?php echo image_path('/apostrophePlugin/images/a-special-blank.gif'); ?> " class="submit a-search-submit" value="Search Pages" alt="Search" title="Search"/> <?php } ?> </div> </form> </div> </div> <?php if (!aMediaTools::getType() || substr(aMediaTools::getType(), 0, 1) === '_') { ?> <hr class="a-hr" /> <div class='a-subnav-section types'> <h4><?php echo a_('Browse by'); ?> </h4> <div class="a-filter-options type clearfix"> <?php $type = isset($type) ? $type : ''; ?> <?php $typesInfo = aMediaTools::getOption('types'); ?> <?php
<?php // This linkHref is duplicate code from mediaItem // This was the quickest / easiest way to ensure $linkHref was defined when mediaItemMeta is returned with Ajax ?> <?php if (aMediaTools::isSelecting()) { ?> <?php // When we are selecting downloadables *in general*, we don't want cropping etc., just simple selection ?> <?php // When we are selecting single images *specifically*, we do force the cropping UI. ?> <?php if (aMediaTools::isMultiple() || $mediaItem->getType() === 'image' && aMediaTools::getType() !== '_downloadable') { ?> <?php $linkHref = "#select-media-item"; ?> <?php } else { ?> <?php // Non-image single select. The multiple add action is a bit of a misnomer here ?> <?php // and redirects to aMedia/selected after adding the media item ?> <?php $linkHref = url_for('aMedia/multipleAdd?id=' . $mediaItem->getId());
/** * DOCUMENT ME * @return mixed */ public static function getUploadAllowed() { foreach (aMediaTools::getTypeInfos(aMediaTools::getType()) as $typeInfo) { if (count($typeInfo['extensions'])) { return true; } } return false; }
/** * DOCUMENT ME * @param sfWebRequest $request * @return mixed */ public function executeIndex(sfWebRequest $request) { $params = array(); $tag = $request->getParameter('tag'); $type = aMediaTools::getType(); $type = $type ? $type : $request->getParameter('type'); // It is permissible to filter more narrowly if the overall type is a metatype (_downloadable) if (substr($type, 0, 1) === '_') { if ($request->getParameter('type')) { $type = $request->getParameter('type'); } } $this->embedAllowed = aMediaTools::getEmbedAllowed(); $this->uploadAllowed = aMediaTools::getUploadAllowed(); $category = $request->getParameter('category'); $search = $request->getParameter('search'); if ($request->isMethod('post')) { // Give the routing engine a shot at making the URL pretty. // We use addParams because it automatically deletes any // params with empty values. (To be fair, http_build_query can't // do that because some crappy web application might actually // use checkboxes with empty values, and that's not // technically wrong. We have the luxury of saying "reasonable // people who work here don't do that.") return $this->redirect(aUrl::addParams("aMedia/index", array("tag" => $tag, "search" => $search, "type" => $type))); } if (!empty($tag)) { $params['tag'] = $tag; } if (!empty($search)) { $params['search'] = $search; } if (!empty($type)) { $params['type'] = $type; } if (!empty($category)) { $params['category'] = $category; } // Cheap insurance that these are integers $aspectWidth = floor(aMediaTools::getAttribute('aspect-width')); $aspectHeight = floor(aMediaTools::getAttribute('aspect-height')); if ($type === 'image') { // Now that we provide cropping tools, width and height should only exclude images // that are too small to ever be cropped to that size $minimumWidth = floor(aMediaTools::getAttribute('minimum-width')); $width = floor(aMediaTools::getAttribute('width')); $minimumWidth = max($minimumWidth, $width); $minimumHeight = floor(aMediaTools::getAttribute('minimum-height')); $height = floor(aMediaTools::getAttribute('height')); $minimumHeight = max($minimumHeight, $height); // Careful, aspect ratio can impose a bound on the other dimension if ($minimumWidth && $aspectWidth) { $minimumHeight = max($minimumHeight, $minimumWidth * $aspectHeight / $aspectWidth); } if ($minimumHeight && $aspectHeight) { $minimumWidth = max($minimumWidth, $minimumHeight * $aspectWidth / $aspectHeight); } // We've updated these with implicit constraints from the aspect ratio, the width and height params, etc. aMediaTools::setAttribute('minimum-width', $minimumWidth); aMediaTools::setAttribute('minimum-height', $minimumHeight); $params['minimum-width'] = $minimumWidth; $params['minimum-height'] = $minimumHeight; } else { // TODO: performance of these is not awesome (it's a linear search). // It would be more awesome with the right kind of indexing. For the // aspect ratio test to be more efficient we'd have to store the lowest // common denominator aspect ratio and index that. if ($aspectWidth && $aspectHeight) { $params['aspect-width'] = $aspectWidth; $params['aspect-height'] = $aspectHeight; } $minimumWidth = floor(aMediaTools::getAttribute('minimum-width')); if ($minimumWidth) { $params['minimum-width'] = $minimumWidth; } $minimumHeight = floor(aMediaTools::getAttribute('minimum-height')); if ($minimumHeight) { $params['minimum-height'] = $minimumHeight; } $width = floor(aMediaTools::getAttribute('width')); if ($width) { $params['width'] = $width; } $height = floor(aMediaTools::getAttribute('height')); if ($height) { $params['height'] = $height; } } // The media module is now an engine module. There is always a page, and that // page might have a restricted set of categories associated with it $mediaCategories = aTools::getCurrentPage()->Categories; if (count($mediaCategories)) { $params['allowed_categories'] = $mediaCategories; } $query = aMediaItemTable::getBrowseQuery($params); $this->pager = new sfDoctrinePager('aMediaItem', aMediaTools::getOption('per_page')); $page = $request->getParameter('page', 1); $this->pager->setQuery($query); if ($request->hasParameter('max_per_page')) { $this->getUser()->setAttribute('max_per_page', $request->getParameter('max_per_page'), 'apostrophe_media_prefs'); } $this->max_per_page = $this->getUser()->getAttribute('max_per_page', 20, 'apostrophe_media_prefs'); $this->pager->setMaxPerPage($this->max_per_page); $this->pager->setPage($page); $this->pager->init(); $this->results = $this->pager->getResults(); Taggable::preloadTags($this->results); // Go to the last page if we are beyond it if ($page > 1 && $page > $this->pager->getLastPage()) { $page--; $params['page'] = $page; return $this->redirect('aMedia/index?' . http_build_query($params)); } aMediaTools::setSearchParameters(array("tag" => $tag, "type" => $type, "search" => $search, "page" => $page, 'category' => $category)); $this->pagerUrl = "aMedia/index?" . http_build_query($params); if (aMediaTools::isSelecting()) { $this->selecting = true; if (aMediaTools::getAttribute("label")) { $this->label = aMediaTools::getAttribute("label"); } $this->limitSizes = $minimumWidth || $minimumHeight; } if ($request->hasParameter('layout')) { $this->getUser()->setAttribute('layout', $request->getParameter('layout'), 'apostrophe_media_prefs'); } $this->layout = aMediaTools::getLayout($this->getUser()->getAttribute('layout', 'two-up', 'apostrophe_media_prefs')); $this->enabled_layouts = aMediaTools::getEnabledLayouts(); return $this->pageTemplate; }