public function executeNormalView()
 {
     // Mostly identical to aImage, but we have the URL to contend with too
     $this->setup();
     $this->constraints = $this->getOption('constraints', array());
     $this->width = $this->getOption('width', 440);
     $this->height = $this->getOption('height', 330);
     $this->resizeType = $this->getOption('resizeType', 's');
     $this->flexHeight = $this->getOption('flexHeight');
     $this->defaultImage = $this->getOption('defaultImage');
     $this->title = $this->getOption('title');
     $this->description = $this->getOption('description');
     // Behave well if it's not set yet!
     $data = $this->slot->getArrayValue();
     $this->link = false;
     if (isset($data['url'])) {
         $this->link = $data['url'];
     }
     if (isset($data['title'])) {
         $this->img_title = $data['title'];
     }
     // Behave well if it's not set yet!
     if (!count($this->slot->MediaItems)) {
         $this->item = false;
         $this->itemId = false;
     } else {
         $this->item = $this->slot->MediaItems[0];
         $this->itemId = $this->item->id;
         $this->dimensions = aDimensions::constrain($this->item->width, $this->item->height, $this->item->format, array("width" => $this->width, "height" => $this->flexHeight ? false : $this->height, "resizeType" => $this->resizeType));
         $this->embed = $this->item->getEmbedCode('_WIDTH_', '_HEIGHT_', '_c-OR-s_', '_FORMAT_', false);
     }
 }
 /**
  * DOCUMENT ME
  */
 public function executeNormalView()
 {
     $this->setup();
     $this->constraints = $this->getOption('constraints', array());
     $this->width = $this->getOption('width', 100);
     $this->height = $this->getOption('height', 220);
     $this->resizeType = $this->getOption('resizeType', 's');
     $this->flexHeight = $this->getOption('flexHeight', true);
     $this->defaultImage = $this->getOption('defaultImage');
     $this->title = $this->getOption('title', true);
     $this->pdfPreview = $this->getOption('pdfPreview', false);
     $this->description = $this->getOption('description', true);
     // Behave well if it's not set yet!
     if (!count($this->slot->MediaItems)) {
         $this->item = false;
         $this->itemId = false;
     } else {
         $this->item = $this->slot->MediaItems[0];
         $this->itemId = $this->item->id;
         if ($this->pdfPreview) {
             $this->dimensions = aDimensions::constrain($this->item->width, $this->item->height, $this->item->format, array("width" => $this->width, "height" => $this->flexHeight ? false : $this->height, "resizeType" => $this->resizeType));
         }
         $this->embed = $this->item->getEmbedCode('_WIDTH_', '_HEIGHT_', '_c-OR-s_', '_FORMAT_', false);
     }
 }
 protected function getInsetMedia()
 {
     // We are going to return the media in both Normal and Edit View
     if (!count($this->slot->MediaItems)) {
         $this->item = false;
         $this->itemId = false;
     } else {
         $this->item = $this->slot->MediaItems[0];
         $this->itemId = $this->item->id;
         $this->dimensions = aDimensions::constrain($this->item->width, $this->item->height, $this->item->format, array("width" => $this->options['width'], "height" => $this->options['flexHeight'] ? false : $this->options['height'], "resizeType" => $this->options['resizeType']));
         $this->embed = $this->item->getEmbedCode('_WIDTH_', '_HEIGHT_', '_c-OR-s_', '_FORMAT_', false);
     }
 }
 /**
  * DOCUMENT ME
  */
 public function executeNormalView()
 {
     $this->setup();
     $this->options['constraints'] = $this->getOption('constraints', array());
     $this->options['width'] = $this->getOption('width', 320);
     $this->options['height'] = $this->getOption('height', 240);
     $this->options['resizeType'] = $this->getOption('resizeType', 's');
     $this->options['flexHeight'] = $this->getOption('flexHeight', true);
     $this->options['title'] = $this->getOption('title', false);
     $this->options['description'] = $this->getOption('description', false);
     // Behave well if it's not set yet!
     if (!count($this->slot->MediaItems)) {
         $this->item = false;
         $this->itemId = false;
     } else {
         $this->item = $this->slot->MediaItems[0];
         $this->itemId = $this->item->id;
         $this->dimensions = aDimensions::constrain($this->item->width, $this->item->height, $this->item->format, array("width" => $this->options['width'], "height" => $this->options['flexHeight'] ? false : $this->options['height'], "resizeType" => $this->options['resizeType'], 'forceScale' => true));
         $this->embed = $this->item->getEmbedCode('_WIDTH_', '_HEIGHT_', '_c-OR-s_', '_FORMAT_', false);
     }
 }
 /**
  * DOCUMENT ME
  */
 protected function getButtonMedia()
 {
     // We are going to return the media in both Normal and Edit View
     // Backwards compatibility with pkContextCMS  button slots that the data migration task missed
     if (!count($this->slot->MediaItems)) {
         $value = $this->slot->getArrayValue();
         if (isset($value['image'])) {
             $mediaItem = Doctrine::getTable('aMediaItem')->find($value['image']->id);
             if ($mediaItem) {
                 $this->slot->MediaItems[] = $mediaItem;
             }
         }
     }
     if (!count($this->slot->MediaItems)) {
         $this->item = false;
         $this->itemId = false;
     } else {
         $this->item = $this->slot->MediaItems[0];
         $this->itemId = $this->item->id;
         $this->dimensions = aDimensions::constrain($this->item->width, $this->item->height, $this->item->format, array("width" => $this->options['width'], "height" => $this->options['flexHeight'] ? false : $this->options['height'], "resizeType" => $this->options['resizeType']));
         $this->embed = $this->item->getEmbedCode('_WIDTH_', '_HEIGHT_', '_c-OR-s_', '_FORMAT_', false);
     }
 }
 public function getScaledUrl($options)
 {
     $options = aDimensions::constrain($this->getWidth(), $this->getHeight(), $this->getFormat(), $options);
     return "aMediaBackend/image?" . http_build_query(array("slug" => $this->slug, "width" => $options['width'], "height" => $options['height'], "resizeType" => $options['resizeType'], "format" => $options['format']));
 }
示例#7
0
<?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();
?>
示例#8
0
文件: _slideshow.php 项目: hashir/UoA
    foreach ($items as $item) {
        ?>
	  <?php 
        $dimensions = aDimensions::constrain($item->width, $item->height, $item->format, array("width" => $options['width'], "height" => $options['flexHeight'] ? false : $options['height'], "resizeType" => $options['resizeType']));
        ?>
		<?php 
        // Implement maximum height
        ?>
		<?php 
        if ($options['maxHeight']) {
            ?>
			<?php 
            if ($dimensions['height'] > $options['maxHeight']) {
                ?>
			  <?php 
                $dimensions = aDimensions::constrain($item->width, $item->height, $item->format, array("width" => false, "height" => $options['maxHeight'], "resizeType" => $options['resizeType']));
                ?>
			<?php 
            }
            ?>
		<?php 
        }
        ?>
		
	  <?php 
        $embed = $item->getEmbedCode($dimensions['width'], $dimensions['height'], $dimensions['resizeType'], $dimensions['format']);
        ?>
	  <li class="a-slideshow-item" id="a-slideshow-item-<?php 
        echo $id;
        ?>
-<?php 
 /**
  * DOCUMENT ME
  * @param mixed $value
  * @param mixed $imagePreview
  * @return mixed
  */
 public function getPreviewUrl($value, $imagePreview = array())
 {
     list($exists, $persistid, $extension) = $this->getExistsPersistidAndExtension($value);
     // hasOption just verifies that the option is valid, it doesn't check what,
     // if anything, was passed. Thanks to Lucjan Wilczewski
     $defaultPreview = $this->hasOption('default-preview') ? $this->getOption('default-preview') : false;
     if ($exists) {
         $defaultPreview = false;
     }
     if ($exists || $defaultPreview) {
         // Note change of key
         $urlStem = sfConfig::get('app_aPersistentFileUpload_preview_url', '/uploads/uploaded_image_preview');
         $urlStem = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . $urlStem;
         // This is the corresponding directory path. You have to override one
         // if you override the other. You override this one by setting
         // app_aToolkit_upload_uploaded_image_preview_dir
         $dir = aFiles::getUploadFolder("uploaded_image_preview");
         // While we're here age off stale previews
         aValidatorFilePersistent::removeOldFiles($dir);
         if ($exists) {
             $info = aValidatorFilePersistent::getFileInfo($persistid);
             $source = $info['tmp_name'];
         } else {
             $source = $defaultPreview;
         }
         $info = aImageConverter::getInfo($source, array('format-only' => true));
         $previewable = false;
         if ($info && in_array($info['format'], array('jpg', 'png', 'gif'))) {
             $previewable = true;
             $info = aImageConverter::getInfo($source);
         }
         if ($previewable) {
             $iwidth = $info['width'];
             $iheight = $info['height'];
             // This is safe - based on sniffed file contents and not a user supplied extension
             $format = $info['format'];
             $dimensions = aDimensions::constrain($iwidth, $iheight, $format, $imagePreview);
             // A simple filename reveals less
             $imagename = "{$persistid}.{$format}";
             $url = "{$urlStem}/{$imagename}";
             $output = "{$dir}/{$imagename}";
             if (isset($info['newfile']) && $info['newfile'] || !file_exists($output)) {
                 if ($imagePreview['resizeType'] === 'c') {
                     $method = 'cropOriginal';
                 } else {
                     $method = 'scaleToFit';
                 }
                 sfContext::getInstance()->getLogger()->info("YY calling converter method {$method} width " . $dimensions['width'] . ' height ' . $dimensions['height']);
                 aImageConverter::$method($source, $output, $dimensions['width'], $dimensions['height']);
                 sfContext::getInstance()->getLogger()->info("YY after converter");
             }
         } else {
             // Don't try to provide an icon alternative to the preview here,
             // it's better to do that at the project and/or apostrophePlugin level
             // where we can style it better... the less we fake templating inside
             // a widget the better. See getFormat
             $url = false;
         }
         return $url;
     }
     return false;
 }
示例#10
0
 /**
  * Returns a Symfony action URL. Call url_for or use sfController for final routing.
  * @param mixed $options
  * @return mixed
  */
 public function getScaledUrl($options)
 {
     $options = aDimensions::constrain($this->getWidth(), $this->getHeight(), $this->getFormat(), $options);
     $params = array("slug" => $this->slug, "width" => $options['width'], "height" => $options['height'], "resizeType" => $options['resizeType'], "format" => $options['format']);
     // check for null because 0 is valid
     if (!is_null($options['cropLeft']) && !is_null($options['cropTop']) && !is_null($options['cropWidth']) && !is_null($options['cropHeight'])) {
         $params = array_merge($params, array("cropLeft" => $options['cropLeft'], "cropTop" => $options['cropTop'], "cropWidth" => $options['cropWidth'], "cropHeight" => $options['cropHeight']));
     }
     return "aMediaBackend/image?" . http_build_query($params);
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The value displayed in this widget
  *                             (i.e. the browser-side filename submitted
  *                             on a previous partially successful
  *                             validation of this form)
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $exists = false;
     if (isset($value['persistid']) && strlen($value['persistid'])) {
         $persistid = $value['persistid'];
         $info = aValidatorFilePersistent::getFileInfo($persistid);
         if ($info) {
             $exists = true;
         }
     } else {
         // One implementation, not two (to inevitably drift apart)
         $persistid = aGuid::generate();
     }
     $result = '';
     // hasOption just verifies that the option is valid, it doesn't check what,
     // if anything, was passed. Thanks to Lucjan Wilczewski
     $preview = $this->hasOption('image-preview') ? $this->getOption('image-preview') : false;
     $defaultPreview = $this->hasOption('default-preview') ? $this->getOption('default-preview') : false;
     if ($exists) {
         $defaultPreview = false;
     }
     if ($exists || $defaultPreview) {
         if ($preview) {
             // Note change of key
             $urlStem = sfConfig::get('app_aPersistentFileUpload_preview_url', '/uploads/uploaded_image_preview');
             // This is the corresponding directory path. You have to override one
             // if you override the other. You override this one by setting
             // app_aToolkit_upload_uploaded_image_preview_dir
             $dir = aFiles::getUploadFolder("uploaded_image_preview");
             // While we're here age off stale previews
             aValidatorFilePersistent::removeOldFiles($dir);
             $imagePreview = $this->getOption('image-preview');
             if ($exists) {
                 $source = $info['tmp_name'];
             } else {
                 $source = $defaultPreview;
             }
             $info = aImageConverter::getInfo($source);
             if ($info) {
                 $iwidth = $info['width'];
                 $height = $info['height'];
                 // This is safe - based on sniffed file contents and not a user supplied extension
                 $format = $info['format'];
                 list($iwidth, $iheight) = getimagesize($source);
                 $dimensions = aDimensions::constrain($iwidth, $iheight, $format, $imagePreview);
                 // A simple filename reveals less
                 $imagename = "{$persistid}.{$format}";
                 $url = "{$urlStem}/{$imagename}";
                 $output = "{$dir}/{$imagename}";
                 if (isset($info['newfile']) && $info['newfile'] || !file_exists($output)) {
                     if ($imagePreview['resizeType'] === 'c') {
                         $method = 'cropOriginal';
                     } else {
                         $method = 'scaleToFit';
                     }
                     sfContext::getInstance()->getLogger()->info("YY calling converter method {$method} width " . $dimensions['width'] . ' height ' . $dimensions['height']);
                     aImageConverter::$method($source, $output, $dimensions['width'], $dimensions['height']);
                     sfContext::getInstance()->getLogger()->info("YY after converter");
                 }
             }
             if (isset($imagePreview['markup'])) {
                 $markup = $imagePreview['markup'];
             } else {
                 $markup = '<img src="%s" />';
             }
             $result .= sprintf($markup, $url);
         }
         $result .= $this->getOption('existing-html');
     }
     return $result . $this->renderTag('input', array_merge(array('type' => $this->getOption('type'), 'name' => $name . '[newfile]'), $attributes)) . $this->renderTag('input', array('type' => 'hidden', 'name' => $name . '[persistid]', 'value' => $persistid));
 }