Beispiel #1
0
 public function testSafeFilename()
 {
     $abs = '/etc/passwd';
     $this->assertEquals('etc/passwd', Library::safeFilename($abs));
     // Test urlparams get encoded
     $urlparams = '%2F..%2F..%2Fsecretfile.txt';
     $this->assertEquals('%252F..%252F..%252Fsecretfile.txt', Library::safeFilename($urlparams));
 }
Beispiel #2
0
 /**
  * Helper function to make a path to an image.
  *
  * @param string         $filename Target filename
  * @param string|integer $width    Target width
  * @param string|integer $height   Target height
  * @param string         $crop     String identifier for cropped images
  *
  * @return string Image path
  */
 public function image($filename, $width = '', $height = '', $crop = '')
 {
     if ($width != '' || $height != '') {
         // You don't want the image, you just want a thumbnail.
         return $this->thumbnail($filename, $width, $height, $crop);
     }
     // After v1.5.1 we store image data as an array
     if (is_array($filename)) {
         $filename = isset($filename['filename']) ? $filename['filename'] : $filename['file'];
     }
     $image = sprintf('%sfiles/%s', $this->app['paths']['root'], Lib::safeFilename($filename));
     return $image;
 }
Beispiel #3
0
 /**
  * Helper function to make a path to an image.
  *
  * @param string         $filename Target filename
  * @param string|integer $width    Target width
  * @param string|integer $height   Target height
  * @param string         $crop     String identifier for cropped images
  *
  * @return string Image path
  */
 public function image($filename, $width = null, $height = null, $crop = null)
 {
     if ($width || $height) {
         // You don't want the image, you just want a thumbnail.
         return $this->thumbnail($filename, $width, $height, $crop);
     }
     // After v1.5.1 we store image data as an array
     if (is_array($filename)) {
         $filename = isset($filename['filename']) ? $filename['filename'] : $filename['file'];
     }
     $image = sprintf('%s%s', $this->app['resources']->getUrl('files'), Lib::safeFilename($filename));
     return $image;
 }
Beispiel #4
0
 public function getLocalUrl($path)
 {
     $prefix = $this->app['resources']->getUrl($this->namespace);
     return $prefix . Lib::safeFilename($path);
 }
 public function htmlRespImg($html, $name, array $options = array())
 {
     $dom = $this->createDOMDocument($html);
     $elements = $dom->getElementsByTagName('img');
     if (count($elements) === 0) {
         return $html;
     }
     // Get Extension boltresponsiveimages
     $extensionName = 'boltresponsiveimages';
     if (!$this->app['extensions']->isEnabled($extensionName)) {
         return $html;
     }
     $extension = $this->app['extensions.' . $extensionName];
     if ($extension == null) {
         return $html;
     }
     // Get Twig Function respImg
     $twigFunction = $this->twig->getFunction('respImg');
     if (!$twigFunction) {
         return $html;
     }
     $respImg = $twigFunction->getCallable();
     // Not override sizes, if defined
     if (!$options['sizes']) {
         $options['sizes'] = $extension->getSizesAttrib($name);
     }
     foreach ($elements as $element) {
         if (!$element->hasAttribute('src')) {
             continue;
         }
         $file = $element->getAttribute('src');
         $filename = Lib::safeFilename($file);
         // Set options for specific image
         $optionsImg = $options;
         // Add width fallback to sizes because layout reasons
         // Example: An editor choose a specific width
         if ($element->hasAttribute('width')) {
             $width = $element->getAttribute('width');
             $optionsImg['sizes'][] = $width . 'px';
         }
         if ($element->hasAttribute('class')) {
             $attrClass = $element->getAttribute('class');
             $optionsImg['class'][] = $attrClass;
         }
         $htmlImg = (string) $respImg($filename, $name, $optionsImg);
         $domImg = $this->createDOMDocument($htmlImg);
         // Load the $domImg document fragment node into the current document
         $newnode = $dom->importNode($domImg->documentElement, true);
         // Replace current img node
         $element->parentNode->replaceChild($newnode, $element);
     }
     $result = $dom->saveHTML();
     return new \Twig_Markup($result, 'UTF-8');
 }