Example #1
0
 /**
  * Returns a hash by image id of hashes containing cropping info:
  * cropLeft, cropTop, cropWidth, cropHeight. There may not be
  * cropping info for images that were never cropped. In such cases
  * you should refer to the original dimensions of the image
  * @return mixed
  */
 public function getCroppingInfo()
 {
     $croppingInfo = array();
     $imageInfo = aMediaTools::getAttribute('imageInfo', array());
     $selection = aMediaTools::getSelection();
     foreach ($selection as $item) {
         if (isset($imageInfo['cropLeft'])) {
             $info = array('cropLeft' => $imageInfo['cropLeft'], 'cropTop' => $imageInfo['cropTop'], 'cropWidth' => $imageInfo['cropWidth'], 'cropHeight' => $imageInfo['cropHeight']);
             $croppingInfo[$item->id] = $info;
         }
     }
     return $croppingInfo;
 }
Example #2
0
<?php

// Compatible with sf_escaping_strategy: true
$label = isset($label) ? $sf_data->getRaw('label') : null;
$limitSizes = isset($limitSizes) ? $sf_data->getRaw('limitSizes') : null;
$pager = isset($pager) ? $sf_data->getRaw('pager') : null;
$pagerUrl = isset($pagerUrl) ? $sf_data->getRaw('pagerUrl') : null;
$results = isset($results) ? $sf_data->getRaw('results') : null;
?>

<?php 
use_helper('a');
?>

<?php 
$type = aMediaTools::getAttribute('type');
$selecting = aMediaTools::isSelecting();
$multipleStyle = $type === 'image' || aMediaTools::isMultiple();
?>

<?php 
$body_class = 'a-media a-media-index';
$body_class .= $selecting ? ' a-media-selecting' : '';
$body_class .= ' ' . $layout['name'];
?>

<?php 
slot('body_class', $body_class);
?>

<?php 
Example #3
0
 /**
  * DOCUMENT ME
  * @return mixed
  */
 public function getCropThumbnailUrl()
 {
     $selectedConstraints = aMediaTools::getOption('selected_constraints');
     if ($aspectRatio = aMediaTools::getAspectRatio()) {
         // Allow for either the width or the height to be flex
         if (isset($selectedConstraints['height']) && $selectedConstraints['height'] !== false) {
             $selectedConstraints = array_merge($selectedConstraints, array('width' => floor($selectedConstraints['height'] * $aspectRatio)));
         } else {
             $selectedConstraints = array_merge($selectedConstraints, array('height' => floor($selectedConstraints['width'] / $aspectRatio)));
         }
     }
     $imageInfo = aMediaTools::getAttribute('imageInfo');
     if (isset($imageInfo[$this->id]['cropLeft']) && isset($imageInfo[$this->id]['cropTop']) && isset($imageInfo[$this->id]['cropWidth']) && isset($imageInfo[$this->id]['cropHeight'])) {
         $selectedConstraints = array_merge($selectedConstraints, array('cropLeft' => $imageInfo[$this->id]['cropLeft'], 'cropTop' => $imageInfo[$this->id]['cropTop'], 'cropWidth' => $imageInfo[$this->id]['cropWidth'], 'cropHeight' => $imageInfo[$this->id]['cropHeight']));
     }
     return $this->getScaledUrl($selectedConstraints);
 }
Example #4
0
 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;
         }
     }
 }
Example #5
0
				<?php 
    echo a_js_button(a_('Crop'), array('icon', 'a-crop', 'lite', 'no-label', 'alt'));
    ?>
			</li>
			<li>
				<?php 
    echo a_js_button(a_('Delete'), array('icon', 'a-delete', 'lite', 'no-label', 'alt'));
    ?>
			</li>
		</ul>

	  <div class="a-thumbnail-container" style="background-image: url('<?php 
    echo url_for($item->getCropThumbnailUrl());
    ?>
'); overflow: hidden;">
			<img src="<?php 
    echo url_for($item->getCropThumbnailUrl());
    ?>
" class="a-thumbnail" style="visibility:hidden;" />	
		</div>

	</li>
	<?php 
    a_js_call('apostrophe.setObjectId(?, ?)', $domId, $id);
    $n++;
}
?>

<?php 
a_js_call('apostrophe.mediaEnableSelect(?)', array('setCropUrl' => url_for('aMedia/crop'), 'removeUrl' => url_for('aMedia/multipleRemove'), 'updateMultiplePreviewUrl' => url_for('aMedia/updateMultiplePreview'), 'multipleAddUrl' => url_for('aMedia/multipleAdd'), 'ids' => aMediaTools::getSelection(), 'aspectRatio' => aMediaTools::getAspectRatio(), 'minimumSize' => array(aMediaTools::getAttribute('minimum-width'), aMediaTools::getAttribute('minimum-height')), 'maximumSize' => array(aMediaTools::getAttribute('maximum-width'), aMediaTools::getAttribute('maximum-height')), 'imageInfo' => aMediaTools::getAttribute('imageInfo')));
Example #6
0
        $clauses[] = __('A %w%x%h% aspect ratio', array('%w%' => aMediaTools::getAttribute('aspect-width'), '%h%' => aMediaTools::getAttribute('aspect-height')), 'apostrophe');
    }
    if (aMediaTools::getAttribute('minimum-width')) {
        $clauses[] = __('A minimum width of %mw% pixels', array('%mw%' => aMediaTools::getAttribute('minimum-width')), 'apostrophe');
    }
    if (aMediaTools::getAttribute('minimum-height')) {
        $clauses[] = __('A minimum height of %mh% pixels', array('%mh%' => aMediaTools::getAttribute('minimum-height')), 'apostrophe');
    }
    if (aMediaTools::getAttribute('width')) {
        $clauses[] = __('A width of exactly %w% pixels', array('%w%' => aMediaTools::getAttribute('width')), 'apostrophe');
    }
    if (aMediaTools::getAttribute('height')) {
        $clauses[] = __('A height of exactly %h% pixels', array('%h%' => aMediaTools::getAttribute('height')), 'apostrophe');
    }
    if (aMediaTools::getAttribute('type')) {
        // Internationalize the plural so that can be correct too
        $type = __(aMediaTools::getAttribute('type') . "s", null, 'apostrophe');
    } else {
        $type = __("items", null, 'apostrophe');
    }
    if (count($clauses)) {
        // Markup change: for I18N it's better to use a list here rather than
        // trying to create a sentence with commas and 'and'
        echo '<h4 class="a-constraints-description">' . __("Displaying only %t% with:", array('%t%' => $type), 'apostrophe') . '</h4>';
        echo '<ul class="a-constraints">';
        foreach ($clauses as $clause) {
            echo '<li>' . $clause . '</li>';
        }
        echo '</ul>';
    }
}
Example #7
0
 /**
  * DOCUMENT ME
  * @return mixed
  */
 public static function getNiceTypeName()
 {
     $type = aMediaTools::getAttribute('type', 'media item');
     // The names of types are meant to be user friendly (in English), except for
     // the metatypes like _downloadable which can't be user friendly and unique at the same time.
     // I can't think of a nicer phrase for "all embeddable things" than "media item"
     $niceNames = array('_downloadable' => 'file', '_embeddable' => 'media item');
     if (isset($niceNames[$type])) {
         return $niceNames[$type];
     }
     return $type;
 }
Example #8
0
 /**
  * DOCUMENT ME
  * @param sfWebRequest $request
  * @return mixed
  */
 public function executeSelected(sfWebRequest $request)
 {
     $this->hasPermissionsForSelect();
     $this->forward404Unless(aMediaTools::isSelecting());
     $selection = aMediaTools::getSelection();
     $imageInfo = aMediaTools::getAttribute('imageInfo');
     // Get all the items in preparation for possible cropping
     if (count($selection)) {
         $items = Doctrine::getTable('aMediaItem')->createQuery('m')->whereIn('m.id', $selection)->execute();
     } else {
         $items = array();
     }
     $items = aArray::listToHashById($items);
     $newSelection = array();
     foreach ($selection as $id) {
         $nid = $id;
         // Try not to make gratuitous crops
         if (isset($imageInfo[$id])) {
             $item = $items[$id];
             $i = $imageInfo[$id];
             if ($item->getCroppable() && isset($i['cropLeft']) && ($i['cropLeft'] > 0 || $i['cropTop'] > 0 || $i['cropWidth'] != $item->width || $i['cropHeight'] != $item->height)) {
                 // We need to make a crop
                 $item = $items[$id];
                 $crop = $item->findOrCreateCrop($imageInfo[$id]);
                 $crop->save();
                 $nid = $crop->id;
             }
             $newSelection[] = $nid;
         }
     }
     // Ooops best to get this before clearing it huh
     $after = aMediaTools::getAfter();
     // addParamsNoDelete never attempts to eliminate a field just because
     // its value is empty. This is how we distinguish between cancellation
     // and selecting zero items
     if (!aMediaTools::isMultiple()) {
         // Call this too soon and you lose isMultiple
         aMediaTools::clearSelecting();
         if (count($newSelection)) {
             $after = aUrl::addParams($after, array("aMediaId" => $newSelection[0]));
             return $this->redirect($after);
         } else {
             // Our image UI lets you trash your single selection. Which makes sense.
             // So implement a way of passing that back. It's up to the
             // receiving action to actually respect it of course
             $after = aUrl::addParams($after, array("aMediaUnset" => 1));
             return $this->redirect($after);
         }
     } else {
         aMediaTools::clearSelecting();
         $url = aUrl::addParamsNoDelete($after, array("aMediaIds" => implode(",", $newSelection)));
         return $this->redirect($url);
     }
 }