/**
  * @param string
  * @return void
  */
 public function display($url)
 {
     $this->autoRender = false;
     $fileParts = $this->MediaHandler->urlToRequestParts(urldecode($url));
     extract($fileParts, EXTR_OVERWRITE);
     if ($width || $height) {
         $MediaHandler = new MediaHandlerComponent($filename);
         if (!is_file($resizedPath = $MediaHandler->thumbnail($width, $height))) {
             throw new NotFoundException(__('404. Not found.', 'gummfw'));
             die;
         }
         header('Content-Type: ' . $MediaHandler->info('mime'));
         echo file_get_contents($resizedPath);
     } else {
         header('Content-Type: image/jpeg');
         echo file_get_contents($filename);
     }
 }
Beispiel #2
0
 /**
  * @param mixed $url
  * @param array $params
  * @param array $attributes
  * @return string
  */
 public function display($url, $params = array(), $attributes = array())
 {
     $params = array_merge(array('layoutDimensions' => false, 'width' => null, 'height' => null, 'context' => null, 'ar' => null, 'crop' => true, 'exact' => false, 'suffix' => 'gummcrop'), (array) $params);
     if (!$url) {
         return false;
     }
     $url = stripslashes(htmlspecialchars_decode($url, ENT_QUOTES));
     // If the ruequested "url" contains <object> or <iframe> tags
     if (strpos($url, '<') !== false) {
         // $width = $params['width'];
         // $height = $params['height'];
         $width = $params['exact'] === true ? $params['width'] : '100%';
         $height = $params['exact'] === true ? $params['height'] : '100%';
         if ($width) {
             $url = preg_replace("'(width=[\\'|\"])(\\d+[\\%]?)([\\'|\"])'imsU", '${1}' . $width . '${3}', $url);
         }
         if ($height && $height != 999) {
             $url = preg_replace("'(height=[\\'|\"])(\\d+[\\%]?)([\\'|\"])'imsU", '${1}' . $height . '${3}', $url);
         }
         // Some cleanup
         if (strpos($url, '<object') !== false && strpos($url, 'wmode') === false) {
             $url = preg_replace("'(<object.*)(</object>)'imsU", '${1}<param name="wmode" value="transparent" />${2}', $url);
         } elseif (strpos($url, '<iframe') !== false) {
             if (preg_match_all("'<iframe.*src=\"(.*)\".*></iframe>'imsU", $url, $srcUrl)) {
                 $srcUrl = $srcUrl[1][0];
                 if (strpos($srcUrl, 'wmode') === false) {
                     $srcUrl .= strpos($srcUrl, '?') === false ? '?wmode=transparent' : '&amp;wmode=transparent';
                     $url = preg_replace("'(<iframe.*src=\")(.*)(\".*></iframe>)'imsU", '${1}' . $srcUrl . '${3}', $url);
                 }
                 if (strpos($url, 'frameborder') === false) {
                     $url = preg_replace("'(<iframe.*)(>.*</iframe>)'imsU", '${1} frameborder="0"${2}', $url);
                 }
             }
         }
         $url = preg_replace("'<p>.*</p>'imsU", '', $url);
         $styleAttr = '';
         if (isset($params['ar'])) {
             $styleAttr = ' style="padding-bottom:' . 1 / $params['ar'] * 100 . '%"';
         }
         $url = '<div class="embeddedVideoWrapper"' . $styleAttr . '>' . $url . '</div>';
         return $url;
     } elseif (strpos($url, env('HTTP_HOST')) === false) {
         return $this->constructImgTag($url);
     } else {
         App::import('Component', 'MediaHandler');
         $MediaHandler = new MediaHandlerComponent();
         $filepath = $MediaHandler->urlToFilePath($url);
         $aspectRatio = null;
         if (extension_loaded('gd') && ($params['width'] || $params['height'] || $params['ar']) && $this->Wp->getOption('enable_image_resize') != 'false') {
             $whProps = $this->getMediaDimensions($params);
             // $whProps = $this->getMediaDimensionsForClientResolution($params['width'], $params['height'], $params['context']);
             $params = array_merge($params, $whProps);
             $clientResolution = $this->getClientResolution();
             $url = self::mediaUrlPath($url, $params);
             $filepath = $MediaHandler->urlToFilePath($url);
             $fileParts = $MediaHandler->urlToRequestParts($url);
             $MediaHandler->initialize($fileParts['filename']);
             if (!is_file($filepath)) {
                 $MediaHandler->thumbnail($fileParts['width'], $fileParts['height']);
             }
             if ($fileParts['width'] && $fileParts['height']) {
                 $aspectRatio = round($fileParts['width'] / $fileParts['height'], 4);
             }
         } else {
             $MediaHandler->initialize($filepath);
         }
         if (!$aspectRatio) {
             $aspectRatio = round($MediaHandler->info('aspectRatio'), 4);
         }
         $attributes['data-aspectratio'] = $aspectRatio;
     }
     if (!isset($attributes['id'])) {
         $attributes['id'] = 'img-' . uniqid();
     }
     if (!extension_loaded('gd')) {
         $whProps = $this->getMediaDimensions($params);
         $attributes['width'] = $whProps['width'];
     }
     $output = $this->constructImgTag($url, $attributes);
     if (!is_admin()) {
         $jsPreloadScript = "\n            (function(\$){\n                var ele = \$('#{$attributes['id']}');\n                if (ele.height() === 0) {\n                    var height = ele.width() / {$aspectRatio}; \n                    ele.css({\n                        height: height,\n                        opacity: 0\n                    }).addClass('gummModHeight').parent().addClass('imgloading');\n                    ele.load(function(){\n                        \$(this).parent().removeClass('imgloading');\n                        \$(this).animate({\n                            opacity: 1\n                        }, 350, function(){\n                            \$(this).css('opacity', '');\n                        }).css({\n                            height: ''\n                        }).removeClass('gummModHeight').next('script.imgpreloaderscript').remove();\n                    });\n                } else {\n                    ele.next('script.imgpreloaderscript').remove();\n                }\n            }) (jQuery)";
         $output .= '<script type="text/javascript" class="imgpreloaderscript">' . $jsPreloadScript . '</script>';
     }
     return $output;
 }