protected function validateAPIKey() { // Media API is no longer used internally and defaults to off in apostrophePlugin $this->forward404Unless(sfConfig::get('app_a_media_apienabled', false)); if (!$this->hasRequestParameter('apikey')) { if (!aMediaTools::getOption("apipublic")) { $this->logMessage('info', 'flunking because no apikey'); $this->unauthorized(); } return; } $apikey = $this->getRequestParameter('apikey'); $apikeys = array_flip(aMediaTools::getOption('apikeys')); if (!isset($apikeys[$apikey])) { $this->logMessage('info', 'ZZ flunking because bad apikey'); } $this->forward404Unless(isset($apikeys[$apikey])); $this->validAPIKey = true; $this->user = false; if ($this->validAPIKey) { // With a valid API key you can request media info on behalf of any user $this->user = $this->getRequestParameter('user'); } if (!$this->user) { // Use of the API from javascript as an already authenticated user // is permitted if ($this->getUser()->isAuthenticated()) { $guardUser = $this->getUser()->getGuardUser(); if ($guardUser) { $this->user = $guardUser->getUsername(); } } } }
public static function listenToRoutingLoadConfigurationEvent(sfEvent $event) { $r = $event->getSubject(); if (aMediaTools::getOption("routes_register") && in_array('aMedia', sfConfig::get('sf_enabled_modules'))) { // Since the media plugin is now an engine, we need our own // catch-all rule for administrative URLs in the media area. // Prepending it first means it matches last $r->prependRoute('a_media_other', new aRoute('/:action', array('module' => 'aMedia'))); $r->prependRoute('a_media_image_show', new aRoute('/view/:slug', array('module' => 'aMedia', 'action' => 'show'), array('slug' => '^[\\w\\-]+$'))); // Allow permalinks for PDF originals $r->prependRoute('a_media_image_original', new sfRoute('/uploads/media_items/:slug.original.:format', array('module' => 'aMediaBackend', 'action' => 'original'), array('slug' => '^[\\w\\-]+$', 'format' => '^(jpg|png|gif|pdf)$'))); $r->prependRoute('a_media_image', new sfRoute('/uploads/media_items/:slug.:width.:height.:resizeType.:format', array('module' => 'aMediaBackend', 'action' => 'image'), array('slug' => '^[\\w\\-]+$', 'width' => '^\\d+$', 'height' => '^\\d+$', 'resizeType' => '^\\w$', 'format' => '^(jpg|png|gif)$'))); // What we want: // /media <-- everything // /image <-- media of type image // /video <-- media of type video // /tag/tagname <-- media with this tag // /image/tag/tagname <-- images with this tag // /video/tag/tagname <-- video with this tag // /media?search=blah blah blah <-- searches are full of // dirty URL-unfriendly characters and // are traditionally query strings. $r->prependRoute('a_media_index', new aRoute('/', array('module' => 'aMedia', 'action' => 'index'))); $r->prependRoute('a_media_index_type', new aRoute('/:type', array('module' => 'aMedia', 'action' => 'index'), array('type' => '(image|video)'))); $r->prependRoute('a_media_index_category', new aRoute('/category/:category', array('module' => 'aMedia', 'action' => 'index'), array('category' => '.*'))); $r->prependRoute('a_media_index_tag', new aRoute('/tag/:tag', array('module' => 'aMedia', 'action' => 'index'), array('tag' => '.*'))); $r->prependRoute('a_media_select', new aRoute('/select', array('class' => 'aRoute', 'module' => 'aMedia', 'action' => 'select'))); $r->prependRoute('a_media_info', new sfRoute('/info', array('module' => 'aMediaBackend', 'action' => 'info'))); $r->prependRoute('a_media_tags', new sfRoute('/tags', array('module' => 'aMediaBackend', 'action' => 'tags'))); $r->prependRoute('a_media_upload_images', new aRoute('/uploadImages', array('module' => 'aMedia', 'action' => 'uploadImages'))); $r->prependRoute('a_media_edit_images', new aRoute('/editImages', array('module' => 'aMedia', 'action' => 'editImages'))); $r->prependRoute('a_media_new_video', new aRoute('/newVideo', array('module' => 'aMedia', 'action' => 'newVideo'))); $r->prependRoute('a_media_edit_video', new aRoute('/editVideo', array('module' => 'aMedia', 'action' => 'editVideo'))); } }
/** * DOCUMENT ME * @param mixed $type * @param mixed $default * @return mixed */ protected function getExtensionFromType($type, $default = '') { $extensionsByMimeType = array_flip(aMediaTools::getOption('mime_types')); if (isset($extensionsByMimeType[$type])) { return '.' . $extensionsByMimeType[$type]; } return $default; }
/** * Thanks yet again to http:thatsquality.com/articles/can-the-symfony-forms-framework-be-domesticated-a-simple-todo-list * @param mixed $validator * @param mixed $values * @param mixed $args * @return mixed */ public function atLeastOne($validator, $values, $args) { for ($i = 0; $i < aMediaTools::getOption('batch_max'); $i++) { if (!is_null($values["item-{$i}"]['file'])) { return $values; } } throw new sfValidatorError($validator, 'at_least_one'); }
public function configure() { for ($i = 0; $i < aMediaTools::getOption('batch_max'); $i++) { if (isset($this->active[$i])) { $this->embedForm("item-{$i}", new aMediaImageForm()); } } $this->widgetSchema->setNameFormat('a_media_items[%s]'); // $this->widgetSchema->setFormFormatterName('aAdmin'); $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe'); }
public function configure() { for ($i = 0; $i < aMediaTools::getOption('batch_max'); $i++) { $uploadImageForm = new aMediaUploadImageForm(); $this->embedForm("item-{$i}", $uploadImageForm); $this->widgetSchema->setNameFormat('a_media_items[%s]'); $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'atLeastOne')))); } $this->widgetSchema->setFormFormatterName('aAdmin'); $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe'); }
/** * DOCUMENT ME */ public function postConfigure() { if ($this->getObject()->isNew()) { $permissionIds = array(); $permissionNames = array(sfConfig::get('app_a_group_editor_permission', 'editor'), aMediaTools::getOption('upload_credential'), 'blog_author', 'view_locked'); foreach ($permissionNames as $permissionName) { $permission = Doctrine::getTable('sfGuardPermission')->findOneByName($permissionName); if ($permission) { $permissionIds[] = $permission->id; } } $this->setDefault('permissions_list', $permissionIds); } }
public function executeBrowser($request) { // We don't use a single integrated form for this anymore. What we wanted was // individual-link behavior, and yet we overlaid a form on that, // which had some interesting aspects but was ultimately confusing // and a problem for search engine indexing etc // ... But we do now use a simple form for the search form $this->current = "aMedia/index"; $params = array(); $type = aMediaTools::getSearchParameter('type'); if (strlen($type)) { $this->type = $type; $params['type'] = $type; } $tag = aMediaTools::getSearchParameter('tag'); if (strlen($tag)) { $this->selectedTag = $tag; $params['tag'] = $tag; } $categorySlug = aMediaTools::getSearchParameter('category'); if (strlen($categorySlug)) { $this->selectedCategory = Doctrine::getTable('aMediaCategory')->findOneBySlug($categorySlug); $params['category'] = $categorySlug; } $search = aMediaTools::getSearchParameter('search'); if (strlen($search)) { $this->search = $search; $params['search'] = $search; } $this->searchForm = new aMediaSearchForm(); $this->searchForm->bind(array('search' => $request->getParameter('search'))); $this->current .= "?" . http_build_query($params); $this->allTags = aMediaItemTable::getAllTagNameForUserWithCount(); $tagsByPopularity = $this->allTags; arsort($tagsByPopularity); $this->popularTags = array(); $n = 0; $max = aMediaTools::getOption('popular_tags'); foreach ($tagsByPopularity as $tag => $count) { if ($n == $max) { break; } $this->popularTags[$tag] = $count; $n++; } }
/** * DOCUMENT ME */ public function configure() { $this->setWidget("file", new aWidgetFormInputFilePersistent(array("image-preview" => array("width" => 50, "height" => 50, "resizeType" => "c")))); $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); $this->setValidator("file", new aValidatorFilePersistent(array("mime_types" => $mimeTypes, 'validated_file_class' => 'aValidatedFile', "required" => false), array("mime_types" => "The following file types are accepted: " . implode(', ', $extensions)))); // Without this, the radio buttons on the edit form will not have a default $this->setWidget("view_is_secure", new sfWidgetFormInputHidden(array('default' => '0'))); $this->setValidator("view_is_secure", new sfValidatorPass(array('required' => false))); $this->setDefault('view_is_secure', 0); // The same as the edit form by design $this->widgetSchema->setNameFormat('a_media_item[%s]'); $this->widgetSchema->setFormFormatterName('aAdmin'); $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe'); }
public static function listenToRoutingLoadConfigurationEvent(sfEvent $event) { $r = $event->getSubject(); if (aMediaTools::getOption("routes_register") && in_array('aMedia', sfConfig::get('sf_enabled_modules'))) { // Since the media plugin is now an engine, we need our own // catch-all rule for administrative URLs in the media area. // Prepending it first means it matches last $r->prependRoute('a_media_other', new aRoute('/:action', array('module' => 'aMedia'))); $r->prependRoute('a_media_image_show', new aRoute('/view/:slug', array('module' => 'aMedia', 'action' => 'show'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$'))); // Allow permalinks for PDF originals $r->prependRoute('a_media_image_original', new sfRoute(sfConfig::get('app_a_routes_media_image_original', '/uploads/media_items/:slug.original.:format'), array('module' => 'aMediaBackend', 'action' => 'original'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'format' => '^(\\w+)$'))); $route = new sfRoute(sfConfig::get('app_a_routes_media_image', '/uploads/media_items/:slug.:width.:height.:resizeType.:format'), array('module' => 'aMediaBackend', 'action' => 'image'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'width' => '^\\d+$', 'height' => '^\\d+$', 'resizeType' => '^\\w$', 'format' => '^(jpg|png|gif)$')); $r->prependRoute('a_media_image', $route); $route = new sfRoute(sfConfig::get('app_a_routes_media_image_cropped', '/uploads/media_items/:slug.:cropLeft.:cropTop.:cropWidth.:cropHeight.:width.:height.:resizeType.:format'), array('module' => 'aMediaBackend', 'action' => 'image'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'width' => '^\\d+$', 'height' => '^\\d+$', 'cropLeft' => '^\\d+$', 'cropTop' => '^\\d+$', 'cropWidth' => '^\\d+$', 'cropHeight' => '^\\d+$', 'resizeType' => '^\\w$', 'format' => '^(jpg|png|gif)$')); $r->prependRoute('a_media_image_cropped', $route); // What we want: // /media <-- everything // /image <-- media of type image // /video <-- media of type video // /tag/tagname <-- media with this tag // /image/tag/tagname <-- images with this tag // /video/tag/tagname <-- video with this tag // /media?search=blah blah blah <-- searches are full of // dirty URL-unfriendly characters and // are traditionally query strings. $r->prependRoute('a_media_index', new aRoute('/', array('module' => 'aMedia', 'action' => 'index'))); $r->prependRoute('a_media_index_type', new aRoute('/:type', array('module' => 'aMedia', 'action' => 'index'), array('type' => '(image|video)'))); $r->prependRoute('a_media_index_category', new aRoute('/category/:category', array('module' => 'aMedia', 'action' => 'index'), array('category' => '.*'))); // Support for existing pretty-URL tag links so they don't 404. We don't recommend // this for the generation of new links because it doesn't handle various // punctuation well with a wide variety of webserver configurations $r->prependRoute('a_media_index_deprecated_tag', new aRoute('/tag/:tag', array('module' => 'aMedia', 'action' => 'index'), array('tag' => '.*'))); // We removed :tag because we allow tags with dots and such and pretty URLs // work great until your rewrite rules decide they are supposed to be static files $r->prependRoute('a_media_index_tag', new aRoute('/tag', array('module' => 'aMedia', 'action' => 'index'), array('tag' => '.*'))); $r->prependRoute('a_media_select', new aRoute('/select', array('class' => 'aRoute', 'module' => 'aMedia', 'action' => 'select'))); $r->prependRoute('a_media_info', new sfRoute('/info', array('module' => 'aMediaBackend', 'action' => 'info'))); $r->prependRoute('a_media_tags', new sfRoute('/tags', array('module' => 'aMediaBackend', 'action' => 'tags'))); $r->prependRoute('a_media_upload', new aRoute('/upload', array('module' => 'aMedia', 'action' => 'upload'))); $r->prependRoute('a_media_edit_multiple', new aRoute('/editMultiple', array('module' => 'aMedia', 'action' => 'editMultiple'))); $r->prependRoute('a_media_edit', new aRoute('/edit', array('module' => 'aMedia', 'action' => 'edit'))); $r->prependRoute('a_media_new_video', new aRoute('/newVideo', array('module' => 'aMedia', 'action' => 'newVideo'))); $r->prependRoute('a_media_edit_video', new aRoute('/editVideo', array('module' => 'aMedia', 'action' => 'editVideo'))); } }
public function configure() { unset($this['type']); unset($this['service_url']); unset($this['slug']); unset($this['width']); unset($this['height']); unset($this['format']); $this->setWidget('file', new aWidgetFormInputFilePersistent(array('image-preview' => aMediaTools::getOption('gallery_constraints')))); $item = $this->getObject(); if (!$item->isNew()) { $this->getWidget('file')->setOption('default-preview', $item->getOriginalPath()); } $this->setValidator('file', new aValidatorFilePersistent(array('mime_types' => array('image/jpeg', 'image/png', 'image/gif'), 'required' => !$this->getObject()->getId()), array('mime_types' => 'JPEG, PNG and GIF only.', 'required' => 'Select a JPEG, PNG or GIF file'))); $this->setValidator('title', new sfValidatorString(array('min_length' => 3, 'max_length' => 200, 'required' => true), array('min_length' => 'Title must be at least 3 characters.', 'max_length' => 'Title must be <200 characters.', 'required' => 'You must provide a title.'))); $this->setWidget('view_is_secure', new sfWidgetFormSelectRadio(array('choices' => array(0 => 'Public', 1 => 'Hidden'), 'default' => 0))); $this->setValidator('view_is_secure', new sfValidatorBoolean()); $this->widgetSchema->setLabel('view_is_secure', 'Permissions'); $this->widgetSchema->setNameFormat('a_media_item[%s]'); // $this->widgetSchema->setFormFormatterName('aAdmin'); $this->widgetSchema->setLabel('media_categories_list', 'Categories'); $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe'); }
<?php echo $form->renderHiddenFields(); ?> <input type="hidden" name="active" value="<?php echo implode(",", $active); ?> " /> <?php $n = 0; ?> <ul> <?php for ($i = 0; $i < aMediaTools::getOption('batch_max'); $i++) { ?> <?php if (isset($form["item-{$i}"])) { ?> <?php // What we're passing here is actually a widget schema ?> <?php // (they get nested when embedded forms are present), but ?> <?php // it supports the same methods as a form for rendering purposes ?> <?php include_partial('aMedia/editImage', array("item" => false, "firstPass" => $firstPass, "form" => $form["item-{$i}"], "n" => $n, 'i' => $i, 'itemFormScripts' => 'false'));
echo a_('Add ' . $typeLabel); ?> </a></li> <li><a href="<?php echo url_for("aMedia/searchServices"); ?> " class="a-btn icon big a-search"><span class="icon"></span><?php echo a_('Search Services'); ?> </a></li> <?php } ?> </ul> <?php if (aMediaTools::getOption('linked_accounts') && aMediaTools::userHasAdminPrivilege()) { ?> <a href="<?php echo url_for("aMedia/link"); ?> " class="a-btn icon a-users lite mini a-align-right a-media-link-accounts alt"><span class="icon"></span><?php echo a_('Linked Accounts'); ?> </a> <?php } ?> </div> <?php a_js_call('apostrophe.clickOnce(?)', '#a-save-media-selection,.a-media-select-video,.a-select-cancel');
/** * * The input value must be an array potentially containing two * keys, newfile and persistid. newfile must contain an array of * the following subkeys, if it is present: * * tmp_name: The absolute temporary path to the newly uploaded file * name: The browser-submitted file name (optional, but necessary to distinguish amongst Microsoft Office formats) * type: The browser-submitted file content type (required although our guessers never trust it) * error: The error code (optional) * size: The file size in bytes (optional) * The persistid key allows lookup of a previously uploaded file * when no new file has been submitted. * A RARE BUT USEFUL CASE: if you need to prefill this cache before * invoking the form for the first time, you can instantiate this * validator yourself: * $vfp = new aValidatorFilePersistent(); * $guid = aGuid::generate(); * $vfp->clean( * array( * 'newfile' => * array('tmp_name' => $myexistingfile), * 'persistid' => $guid)); * Then set array('persistid' => $guid) as the default value * for the file widget. This logic is most easily encapsulated in * the configure() method of your form class. * @see sfValidatorFile * @see sfValidatorBase * @param mixed $value * @return mixed */ public function clean($value) { $persistid = false; if (isset($value['persistid'])) { $persistid = $value['persistid']; } $newFile = false; $persistentDir = $this->getPersistentDir(); if (!self::validPersistId($persistid)) { $persistid = false; } $cvalue = false; // Why do we tolerate the newfile fork being entirely absent? // Because with persistent file upload widgets, it's safe to // redirect a form submission to another action via the GET method // after validation... which is extremely useful if you want to // split something into an iframed initial upload action and // a non-iframed annotation action and you need to be able to // stuff the state of the form into a URL and do window.parent.location =. // As long as we tolerate the absence of the newfile button, we can // rebuild the submission from what's in // getRequest()->getParameterHolder()->getAll(), and that is useful. if (!isset($value['newfile']) || $this->isEmpty($value['newfile'])) { if ($persistid !== false) { $filePath = "{$persistentDir}/{$persistid}.file"; $data = false; if (file_exists($filePath)) { $dataPath = "{$persistentDir}/{$persistid}.data"; // Don't let them expire touch($filePath); touch($dataPath); $data = file_get_contents($dataPath); if (strlen($data)) { $data = unserialize($data); } } if ($data) { $cvalue = $data; } } } else { $newFile = true; $cvalue = $value['newfile']; } if (isset($cvalue['name'])) { $this->originalName = $cvalue['name']; } else { $this->originalName = ''; } try { $result = parent::clean($cvalue); } catch (Exception $e) { // If there is a validation error stop keeping this // file around and don't display the reassuring // "you don't have to upload again" message side by side // with the validation error. if ($persistid !== false) { $infoPath = "{$persistentDir}/{$persistid}.data"; $filePath = "{$persistentDir}/{$persistid}.file"; @unlink($infoPath); @unlink($filePath); } throw $e; } if ($newFile) { // Expiration of abandoned stuff has to happen somewhere self::removeOldFiles($persistentDir); if ($persistid !== false) { $filePath = "{$persistentDir}/{$persistid}.file"; copy($cvalue['tmp_name'], $filePath); $data = $cvalue; $data['newfile'] = true; $data['tmp_name'] = $filePath; // It's useful to know the mime type and true extension for // supplying previews and icons $extensionsByMimeType = array_flip(aMediaTools::getOption('mime_types')); if (!isset($cvalue['type'])) { // It's not sensible to trust a browser-submitted mime type anyway, // so don't force non-web invocations of this code to supply one $cvalue['type'] = 'unknown/unknown'; } $data['mime_type'] = $this->getMimeType($filePath, $cvalue['type']); if (isset($extensionsByMimeType[$data['mime_type']])) { $data['extension'] = $extensionsByMimeType[$data['mime_type']]; } self::putFileInfo($persistid, $data); } } elseif ($persistid !== false) { $data = self::getFileInfo($persistid); if ($data !== false) { $data['newfile'] = false; self::putFileInfo($persistid, $data); } } return $result; }
<?php use_helper('jQuery'); ?> <div id="a-media-plugin"> <?php include_component('aMedia', 'browser'); ?> <div class="a-media-library"> <?php $id = $mediaItem->getId(); $options = aDimensions::constrain($mediaItem->getWidth(), $mediaItem->getHeight(), $mediaItem->getFormat(), aMediaTools::getOption('show_constraints')); $embedCode = $mediaItem->getEmbedCode($options['width'], $options['height'], $options['resizeType'], $options['format']); ?> <?php // This was inside a ul which doesn't make sense ?> <?php echo link_to(__('Media Library', null, 'apostrophe'), '@a_media_index', array('class' => 'a-btn big icon a-arrow-left thin', 'id' => 'media-library-back-button')); ?> <ul class="a-media-item-content" id="a-media-item-content-<?php echo $mediaItem->getId(); ?>
<hr class="a-hr"/> <h4 class="a-account-preview-name">Account: <span><?php echo a_entities($name); ?> </span></h4> <h5 class="a-account-preview-description"><?php echo $description; ?> </h5> <ul class="a-account-preview-recent"> <?php foreach ($results['results'] as $result) { ?> <li><?php echo $service->embed($result['id'], aMediaTools::getOption('video_account_preview_width'), aMediaTools::getOption('video_account_preview_height')); ?> </li> <?php } ?> </ul> <div class="a-account-preview-confirm"> <p class="a-help">Add this account so that all new media associated with it will automatically be added to the media repository on an ongoing basis.</p> <ul class="a-ui a-controls"> <li><?php echo a_js_button(a_('Add This Account'), array('big', 'icon', 'a-add'), 'a-account-preview-ok'); ?> </li> <li><?php
?> class="a-media-thumb-link"> <?php if ($type == 'video') { ?> <span class="a-media-play-btn"></span><?php } ?> <?php if ($type == 'pdf') { ?> <span class="a-media-pdf-btn"></span><?php } ?> <img src="<?php echo url_for($mediaItem->getScaledUrl(aMediaTools::getOption('gallery_constraints'))); ?> " /> </a> </li> <?php // Stored as HTML ?> <li class="a-media-item-title"> <h3> <a <?php echo $linkAttributes; ?> ><?php echo htmlspecialchars($mediaItem->getTitle());
/** * DOCUMENT ME * @return mixed */ public function isAdmin() { return sfContext::getInstance()->getUser()->hasCredential(aMediaTools::getOption('admin_credential')); }
<?php // Make sure we're compatible with sf_escaping_strategy: true $items = isset($items) ? $sf_data->getRaw('items') : array(); foreach ($items as $item) { ?> <li id="a-media-selection-preview-<?php echo $item->getId(); ?> " class="a-media-selection-preview-item"> <h4 class="a-media-selection-title">You are cropping "<?php echo $item->getTitle(); ?> "</h4> <img src="<?php echo url_for($item->getScaledUrl(aMediaTools::getOption('crop_constraints'))); ?> " /> </li> <?php } a_js_call('apostrophe.mediaEnableMultiplePreview()');
/** * Default is to return only services that are ready to be used. * If you pass boolean false, you'll get services that are NOT ready to be used. * If you pass null, you'll get all services * @param mixed $configured * @return mixed */ public static function getEmbedServices($configured = true) { if (!isset(aMediaTools::$embedServices[$configured])) { aMediaTools::$embedServices[$configured] = array(); $serviceInfos = aMediaTools::getOption('embed_services'); foreach ($serviceInfos as $serviceInfo) { $class = $serviceInfo['class']; $service = new $class(); $service->setType($serviceInfo['media_type']); if ($configured) { if (!$service->configured()) { continue; } } elseif ($configured === false) { if ($service->configured()) { continue; } } else { // null = all } aMediaTools::$embedServices[$configured][] = $service; } } return aMediaTools::$embedServices[$configured]; }
/** * 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'); }
/** * DOCUMENT ME * @return mixed */ public function isAdmin() { $isAdmin = $this->getUser()->hasCredential(aMediaTools::getOption('admin_credential')); return $isAdmin; }
<?php use_helper('a'); use_javascript('/sfDoctrineActAsTaggablePlugin/js/pkTagahead.js'); $options = array('choose-one' => a_('Choose Categories')); if (sfContext::getInstance()->getUser()->hasCredential(aMediaTools::getOption('admin_credential'))) { ?> <?php $options['add'] = a_('+ New Category'); } a_js_call('aMultipleSelectAll(?)', $options);
<?php // Compatible with sf_escaping_strategy: true $mediaItem = isset($mediaItem) ? $sf_data->getRaw('mediaItem') : null; $layout = isset($layout) ? $sf_data->getRaw('layout') : null; ?> <?php use_helper('a'); $domId = 'a-media-thumb-link-' . $mediaItem->getId(); $galleryConstraints = aMediaTools::getOption('gallery_constraints'); isset($layout['showSuccess']) ? $embedConstraints = aMediaTools::getOption('show_constraints') : ($embedConstraints = $galleryConstraints); $showUrl = url_for("aMedia/show?" . http_build_query(array("slug" => $mediaItem->getSlug()))); $embeddable = $mediaItem->getEmbeddable(); isset($autoplay) ? $autoplay : ($autoplay = false); if ($selecting) { ?> <?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 $multipleStyleSelect = true;
public function executeUploadImages(sfRequest $request) { // Belongs at the beginning, not the end $this->forward404Unless(aMediaTools::userHasUploadPrivilege()); $this->form = new aMediaUploadImagesForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('a_media_items'), $request->getFiles('a_media_items')); if ($this->form->isValid()) { $request->setParameter('first_pass', true); $active = array(); // Saving embedded forms is weird. We can get the form objects // via getEmbeddedForms(), but those objects were never really // bound, so getValue will fail on them. We have to look at the // values array of the parent form instead. The widgets and // validators of the embedded forms are rolled into it. // See: // http://thatsquality.com/articles/can-the-symfony-forms-framework-be-domesticated-a-simple-todo-list for ($i = 0; $i < aMediaTools::getOption('batch_max'); $i++) { $values = $this->form->getValues(); if ($values["item-{$i}"]['file']) { $active[] = $i; } else { // So the editImagesForm validator won't complain about these $items = $request->getParameter("a_media_items"); unset($items["item-{$i}"]); $request->setParameter("a_media_items", $items); } } $request->setParameter('active', implode(",", $active)); // We'd like to just do this... // $this->forward('aMedia', 'editImages'); // But we need to break out of the iframe, and // modern browsers ignore Window-target: _top which // would otherwise be perfect for this. // Fortunately, the persistent file upload widget can tolerate // a GET-method redirect very nicely as long as we pass the // persistids. So we make the current parameters available // to a template that breaks out of the iframe via // JavaScript and passes the prameters on. $this->parameters = $request->getParameterHolder('a_media_items')->getAll(); // If I don't do this I just get redirected back to myself unset($this->parameters['module']); unset($this->parameters['action']); return 'Redirect'; } } }
<?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 foreach ($typesInfo as $typeName => $typeInfo) { ?> <?php // If a metatype such as _downloadable or _embeddable is in force show only types that support it ?> <?php $metatype = aMediaTools::getMetatype(); ?> <?php if ($metatype) { ?> <?php if (!a_get_option($typeInfo, substr($metatype, 1), false)) {
/** * DOCUMENT ME */ public function go() { $dir_iterator = new RecursiveDirectoryIterator($this->dir); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); $count = 0; $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); foreach ($iterator as $sfile) { if ($sfile->isFile()) { $file = $sfile->getPathname(); if (preg_match('/(^|\\/)\\./', $file)) { # Silently ignore all dot folders to avoid trouble with svn and friends $this->giveFeedback("info", "Ignoring dotfile", $file); continue; } $pathinfo = pathinfo($file); // basename and filename seem backwards to me, but that's how it is in the PHP docs and // sure enough that's how it behaves if ($pathinfo['basename'] === 'Thumbs.db') { continue; } $vfp = new aValidatorFilePersistent(array('mime_types' => $mimeTypes, 'validated_file_class' => 'aValidatedFile', 'required' => false), array('mime_types' => 'The following file types are accepted: ' . implode(', ', $extensions))); $guid = aGuid::generate(); try { $vf = $vfp->clean(array('newfile' => array('tmp_name' => $file, 'name' => $pathinfo['basename']), 'persistid' => $guid)); } catch (Exception $e) { $this->giveFeedback("warning", "Not supported or corrupt", $file); continue; } $item = new aMediaItem(); // Split it up to make tags out of the portion of the path that isn't dir (i.e. the folder structure they used) $dir = $this->dir; $dir = preg_replace('/\\/$/', '', $dir) . '/'; $relevant = preg_replace('/^' . preg_quote($dir, '/') . '/', '', $file); // TODO: not Microsoft-friendly, might matter in some setting $components = preg_split('/\\//', $relevant); $tags = array_slice($components, 0, count($components) - 1); foreach ($tags as &$tag) { // We don't strictly need to be this harsh, but it's safe and definitely // takes care of some things we definitely can't allow, like periods // (which cause mod_rewrite problems with pretty Symfony URLs). // TODO: clean it up in a nicer way without being UTF8-clueless // (aTools::slugify is UTF8-safe) $tag = aTools::slugify($tag); } $item->title = aMediaTools::filenameToTitle($pathinfo['basename']); $item->setTags($tags); if (!strlen($item->title)) { $this->giveFeedback("error", "Files must have a basename", $file); continue; } // The preSaveImage / save / saveImage dance is necessary because // the sluggable behavior doesn't kick in until save and the image file // needs a slug based filename. if (!$item->preSaveFile($vf)) { $this->giveFeedback("error", "Save failed", $file); continue; } $item->save(); if (!$item->saveFile($vf)) { $this->giveFeedback("error", "Save failed", $file); $item->delete(); continue; } unlink($file); $count++; $this->giveFeedback("completed", $count, $file); } } $this->giveFeedback("total", $count); }
?> <label class="full">Embed Preview</label> <div class="a-form-field"> <?php echo $embedCode; ?> </div> <label class="full">Embed Thumbnail</label> <?php } ?> <?php $widget = $form['file']->getWidget(); ?> <?php $previewUrl = $widget->getPreviewUrl($form['file']->getValue(), aMediaTools::getOption('gallery_constraints')); ?> <div class="a-form-field"> <?php if ($previewUrl) { ?> <?php echo image_tag($previewUrl); ?> <?php } else { ?> <?php $format = $widget->getFormat($form['file']->getValue()); ?> <?php
<ul class="a-controls a-media-upload-form-footer" id="a-media-video-add-by-url-form-submit"> <li><input type="submit" value="<?php echo __('Go', null, 'apostrophe'); ?> " class="a-submit" /></li> <li><?php echo link_to_function(__("Cancel", null, 'apostrophe'), "\$('#a-media-video-add-by-url-form').hide(); \$('#a-media-video-add-by-url-heading').hide(); \$('#a-media-video-buttons').show();", array("class" => "a-cancel a-btn icon event-default")); ?> </li> </ul> </form> <?php if (aMediaTools::getOption('embed_codes')) { ?> <h4 id="a-media-video-add-by-embed-heading" class="a-media-video-heading"><?php echo __('Add by Embed Code', null, 'apostrophe'); ?> </h4> <form id="a-media-video-add-by-embed-form" class="a-media-search-form" method="POST" action="<?php echo url_for("aMedia/editVideo"); ?> "> <div class="a-form-row a-search-field" style="position:relative"> <label for="a-media-video-embed"></label> <?php $form = new aMediaVideoEmbedForm();
?> <script type="text/javascript"> function aMediaVideoSearchRenderResults() { if (!aMediaVideoSearchResults) { return; } var perPage = <?php echo aMediaTools::getOption('video_search_per_page'); ?> ; var start = (aMediaVideoSearchPage - 1) * perPage; var template = <?php echo json_encode(aYoutube::embed('_ID_', aMediaTools::getOption('video_search_preview_width'), aMediaTools::getOption('video_search_preview_height'))); ?> ; var i; var limit = start + perPage; var total = aMediaVideoSearchResults.length; var pages = Math.ceil(total / perPage); if (limit > total) { limit = total; } $('#a-media-video-search-results').html(''); for (i = start; (i < limit); i++) { li_class = "normal";