예제 #1
0
 /**
  * @return mixed
  */
 public function getPath()
 {
     $fsPath = $this->getFileSystemPath();
     $path = str_replace(PIMCORE_DOCUMENT_ROOT, "", $fsPath);
     $path = urlencode_ignore_slash($path);
     $results = \Pimcore::getEventManager()->trigger("frontend.path.asset.video.image-thumbnail", $this, ["filesystemPath" => $fsPath, "frontendPath" => $path]);
     if ($results->count()) {
         $path = $results->last();
     }
     return $path;
 }
예제 #2
0
 /**
  * @param array $urlOptions
  * @param bool $reset
  * @param bool $encode
  * @return mixed|string
  */
 public function assemble(array $urlOptions = array(), $reset = false, $encode = true)
 {
     // get request parameters
     $blockedRequestParams = array("controller", "action", "module", "document");
     $front = \Zend_Controller_Front::getInstance();
     if ($reset) {
         $requestParameters = array();
     } else {
         $requestParameters = $front->getRequest()->getParams();
         // remove blocked parameters from request
         foreach ($blockedRequestParams as $key) {
             if (array_key_exists($key, $requestParameters)) {
                 unset($requestParameters[$key]);
             }
         }
     }
     $defaultValues = $this->getDefaultsArray();
     // apply values (controller,action,module, ... ) from previous match if applicable (only when )
     if ($reset) {
         if (self::$_currentRoute && self::$_currentRoute->getName() == $this->getName()) {
             $defaultValues = array_merge($defaultValues, self::$_currentRoute->_values);
         }
     }
     // merge with defaults
     $urlParams = array_merge($requestParameters, $defaultValues, $urlOptions);
     $parametersInReversePattern = array();
     $parametersGet = array();
     $parametersNotNamed = array();
     $url = $this->getReverse();
     $forbiddenCharacters = array("#", ":", "?");
     // check for named variables
     foreach ($urlParams as $key => $param) {
         if (strpos($this->getReverse(), "%" . $key) !== false) {
             $parametersInReversePattern[$key] = $param;
         } else {
             if (is_numeric($key)) {
                 $parametersNotNamed[$key] = $param;
             } else {
                 // only append the get parameters if there are defined in $urlOptions
                 // or if they are defined in $_GET an $reset is false
                 if (array_key_exists($key, $urlOptions) || !$reset && array_key_exists($key, $_GET)) {
                     $parametersGet[$key] = $param;
                 }
             }
         }
     }
     $urlEncodeEscapeCharacters = "~|urlen" . md5(microtime()) . "code|~";
     // replace named variables
     uksort($parametersInReversePattern, function ($a, $b) {
         // order by key length, longer key have priority
         // (%abcd prior %ab, so that %ab doesn't replace %ab in [%ab]cd)
         return strlen($b) - strlen($a);
     });
     foreach ($parametersInReversePattern as $key => $value) {
         $value = str_replace($forbiddenCharacters, "", $value);
         if (strlen($value) > 0) {
             $url = str_replace("%" . $key, str_replace("%", $urlEncodeEscapeCharacters, $encode ? urlencode_ignore_slash($value) : $value), $url);
         }
     }
     // not named parameters
     $o = array();
     foreach ($parametersNotNamed as $option) {
         $option = str_replace($forbiddenCharacters, "", $option);
         $o[] = str_replace("%", $urlEncodeEscapeCharacters, $encode ? urlencode_ignore_slash($option) : $option);
     }
     // remove optional parts
     $url = preg_replace("/\\{([^\\}]+)?%[^\\}]+\\}/", "", $url);
     $url = str_replace(array("{", "}"), "", $url);
     $url = @vsprintf($url, $o);
     if (empty($url)) {
         $url = "ERROR_IN_YOUR_URL_CONFIGURATION:~ONE_PARAMETER_IS_MISSING_TO_GENERATE_THE_URL";
         return $url;
     }
     // optional get parameters
     if (!empty($parametersGet)) {
         if ($encode) {
             $getParams = array_urlencode($parametersGet);
         } else {
             $getParams = array_toquerystring($parametersGet);
         }
         $url .= "?" . $getParams;
     }
     // convert tmp urlencode escape char back to real escape char
     $url = str_replace($urlEncodeEscapeCharacters, "%", $url);
     return $url;
 }
예제 #3
0
 /**
  * @param $path
  * @return mixed
  */
 protected function prepareFrontendPath($path)
 {
     if (\Pimcore\Tool::isFrontend()) {
         $path = urlencode_ignore_slash($path);
         $results = \Pimcore::getEventManager()->trigger("frontend.path.document", $this, ["frontendPath" => $path]);
         if ($results->count()) {
             $path = $results->last();
         }
     }
     return $path;
 }
예제 #4
0
 /**
  * @param array $urlOptions
  * @param bool $reset
  * @param bool $encode
  * @return mixed|string
  */
 public function assemble(array $urlOptions = [], $reset = false, $encode = true)
 {
     // get request parameters
     $blockedRequestParams = ["controller", "action", "module", "document"];
     $front = \Zend_Controller_Front::getInstance();
     if ($reset) {
         $requestParameters = [];
     } else {
         $requestParameters = $front->getRequest()->getParams();
         // remove blocked parameters from request
         foreach ($blockedRequestParams as $key) {
             if (array_key_exists($key, $requestParameters)) {
                 unset($requestParameters[$key]);
             }
         }
     }
     $defaultValues = $this->getDefaultsArray();
     // apply values (controller,action,module, ... ) from previous match if applicable (only when )
     if ($reset) {
         if (self::$_currentRoute && self::$_currentRoute->getName() == $this->getName()) {
             $defaultValues = array_merge($defaultValues, self::$_currentRoute->_values);
         }
     }
     // merge with defaults
     $urlParams = array_merge($defaultValues, $requestParameters, $urlOptions);
     $parametersInReversePattern = [];
     $parametersGet = [];
     $url = $this->getReverse();
     $forbiddenCharacters = ["#", ":", "?"];
     // check for named variables
     uksort($urlParams, function ($a, $b) {
         // order by key length, longer key have priority
         // (%abcd prior %ab, so that %ab doesn't replace %ab in [%ab]cd)
         return strlen($b) - strlen($a);
     });
     $tmpReversePattern = $this->getReverse();
     foreach ($urlParams as $key => $param) {
         if (strpos($tmpReversePattern, "%" . $key) !== false) {
             $parametersInReversePattern[$key] = $param;
             // we need to replace the found variable to that it cannot match again a placeholder
             // eg. %abcd prior %ab if %abcd matches already %ab shouldn't match again on the same placeholder
             $tmpReversePattern = str_replace("%" . $key, "---", $tmpReversePattern);
         } else {
             // only append the get parameters if there are defined in $urlOptions
             // or if they are defined in $_GET an $reset is false
             if (array_key_exists($key, $urlOptions) || !$reset && array_key_exists($key, $_GET)) {
                 $parametersGet[$key] = $param;
             }
         }
     }
     $urlEncodeEscapeCharacters = "~|urlen" . md5(microtime()) . "code|~";
     // replace named variables
     uksort($parametersInReversePattern, function ($a, $b) {
         // order by key length, longer key have priority
         // (%abcd prior %ab, so that %ab doesn't replace %ab in [%ab]cd)
         return strlen($b) - strlen($a);
     });
     foreach ($parametersInReversePattern as $key => $value) {
         $value = str_replace($forbiddenCharacters, "", $value);
         if (strlen($value) > 0) {
             if ($encode) {
                 $value = urlencode_ignore_slash($value);
             }
             $value = str_replace("%", $urlEncodeEscapeCharacters, $value);
             $url = str_replace("%" . $key, $value, $url);
         }
     }
     // remove optional parts
     $url = preg_replace("/\\{([^\\}]+)?%[^\\}]+\\}/", "", $url);
     $url = str_replace(["{", "}"], "", $url);
     // optional get parameters
     if (!empty($parametersGet)) {
         if ($encode) {
             $getParams = array_urlencode($parametersGet);
         } else {
             $getParams = array_toquerystring($parametersGet);
         }
         $url .= "?" . $getParams;
     }
     // convert tmp urlencode escape char back to real escape char
     $url = str_replace($urlEncodeEscapeCharacters, "%", $url);
     $results = \Pimcore::getEventManager()->trigger("frontend.path.staticroute", $this, ["frontendPath" => $url, "params" => $urlParams, "reset" => $reset, "encode" => $encode]);
     if ($results->count()) {
         $url = $results->last();
     }
     return $url;
 }
예제 #5
0
파일: Asset.php 프로젝트: pimcore/pimcore
 /**
  * Returns the full path of the document including the filename
  *
  * @return string
  */
 public function getFullPath()
 {
     $path = $this->getPath() . $this->getFilename();
     if (\Pimcore\Tool::isFrontend()) {
         $path = urlencode_ignore_slash($path);
         $results = \Pimcore::getEventManager()->trigger("frontend.path.asset", $this);
         if ($results->count()) {
             $path = $results->last();
         }
     }
     return $path;
 }
예제 #6
0
파일: Video.php 프로젝트: pimcore/pimcore
 /**
  * Returns a path to a given thumbnail or an thumbnail configuration
  *
  * @param mixed
  * @return string
  */
 public function getThumbnail($thumbnailName, $onlyFormats = [])
 {
     $thumbnail = $this->getThumbnailConfig($thumbnailName);
     if ($thumbnail) {
         try {
             Video\Thumbnail\Processor::process($this, $thumbnail, $onlyFormats);
             // check for existing videos
             $customSetting = $this->getCustomSetting("thumbnails");
             if (is_array($customSetting) && array_key_exists($thumbnail->getName(), $customSetting)) {
                 foreach ($customSetting[$thumbnail->getName()]["formats"] as &$path) {
                     $fullPath = $this->getVideoThumbnailSavePath() . $path;
                     $path = str_replace(PIMCORE_DOCUMENT_ROOT, "", $fullPath);
                     $path = urlencode_ignore_slash($path);
                     $results = \Pimcore::getEventManager()->trigger("frontend.path.asset.video.thumbnail", $this, ["filesystemPath" => $fullPath, "frontendPath" => $path]);
                     if ($results->count()) {
                         $path = $results->last();
                     }
                 }
                 return $customSetting[$thumbnail->getName()];
             }
         } catch (\Exception $e) {
             Logger::error("Couldn't create thumbnail of video " . $this->getRealFullPath());
             Logger::error($e);
         }
     }
     return null;
 }
예제 #7
0
 /**
  * @param array $urlOptions
  * @return string
  */
 public function assemble(array $urlOptions = array(), $reset = false, $encode = true)
 {
     // get request parameters
     $blockedRequestParams = array("controller", "action", "module", "document");
     $front = Zend_Controller_Front::getInstance();
     if ($reset) {
         $requestParameters = array();
     } else {
         $requestParameters = $front->getRequest()->getParams();
         // remove blocked parameters from request
         foreach ($blockedRequestParams as $key) {
             if (array_key_exists($key, $requestParameters)) {
                 unset($requestParameters[$key]);
             }
         }
     }
     $urlParams = array_merge($requestParameters, $urlOptions);
     $parametersInReversePattern = array();
     $parametersGet = array();
     $parametersNotNamed = array();
     $url = $this->getReverse();
     $forbiddenCharacters = array("#", ":", "?");
     // check for named variables
     foreach ($urlParams as $key => $param) {
         if (strpos($this->getReverse(), "%" . $key) !== false) {
             $parametersInReversePattern[$key] = $param;
         } else {
             if (is_numeric($key)) {
                 $parametersNotNamed[$key] = $param;
             } else {
                 // only append the get parameters if there are defined in $urlOptions
                 if (array_key_exists($key, $urlOptions)) {
                     $parametersGet[$key] = $param;
                 }
             }
         }
     }
     $urlEncodeEscapeCharacters = "~|urlen" . md5(microtime()) . "code|~";
     // replace named variables
     foreach ($parametersInReversePattern as $key => $value) {
         $value = str_replace($forbiddenCharacters, "", $value);
         if (strlen($value) > 0) {
             $url = str_replace("%" . $key, str_replace("%", $urlEncodeEscapeCharacters, $encode ? urlencode_ignore_slash($value) : $value), $url);
         }
     }
     // not named parameters
     $o = array();
     foreach ($parametersNotNamed as $option) {
         $option = str_replace($forbiddenCharacters, "", $option);
         $o[] = str_replace("%", $urlEncodeEscapeCharacters, $encode ? urlencode_ignore_slash($option) : $option);
     }
     // remove optional parts
     $url = preg_replace("/\\{[^\\}]*%[^\\{]*\\}/", "", $url);
     $url = str_replace(array("{", "}"), "", $url);
     $url = @vsprintf($url, $o);
     if (empty($url)) {
         $url = "ERROR_IN_YOUR_URL_CONFIGURATION:~ONE_PARAMETER_IS_MISSING_TO_GENERATE_THE_URL";
         return $url;
     }
     // optional get parameters
     if (!empty($parametersGet)) {
         if ($encode) {
             $getParams = array_urlencode($parametersGet);
         } else {
             $getParams = array_toquerystring($parametersGet);
         }
         $url .= "?" . $getParams;
     }
     // convert tmp urlencode escape char back to real escape char
     $url = str_replace($urlEncodeEscapeCharacters, "%", $url);
     return $url;
 }