本文整理汇总了PHP中Pimcore\Tool::isFrontentRequestByAdmin方法的典型用法代码示例。如果您正苦于以下问题:PHP Tool::isFrontentRequestByAdmin方法的具体用法?PHP Tool::isFrontentRequestByAdmin怎么用?PHP Tool::isFrontentRequestByAdmin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Tool
的用法示例。
在下文中一共展示了Tool::isFrontentRequestByAdmin方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
/**
* @return bool
*/
public function start()
{
if (\Pimcore\Tool::isFrontentRequestByAdmin() && !$this->force) {
return false;
}
if ($content = CacheManager::load($this->key)) {
echo $content;
return true;
}
$this->captureEnabled = true;
ob_start();
return false;
}
示例2: init
public function init()
{
parent::init();
$pimUser = false;
if (\Pimcore\Tool::isFrontentRequestByAdmin()) {
$pimUser = \Pimcore\Tool\Admin::getCurrentUser();
if ($pimUser) {
//echo "IS ADMIN";
}
}
$identity = \Zend_Auth::getInstance()->getIdentity();
if (!$identity && !$pimUser or $this->getParam('oid') != $identity['oid']) {
$this->redirect("/");
} else {
// login ok
}
}
示例3: process
/**
* @param $asset
* @param Config $config
* @param null $fileSystemPath
* @param bool $deferred deferred means that the image will be generated on-the-fly (details see below)
* @return mixed|string
*/
public static function process($asset, Config $config, $fileSystemPath = null, $deferred = false)
{
$format = strtolower($config->getFormat());
$contentOptimizedFormat = false;
if (!$fileSystemPath && $asset instanceof Asset) {
$fileSystemPath = $asset->getFileSystemPath();
}
if ($asset instanceof Asset) {
$id = $asset->getId();
} else {
$id = "dyn~" . crc32($fileSystemPath);
}
if (!file_exists($fileSystemPath)) {
return "/pimcore/static/img/filetype-not-supported.png";
}
$modificationDate = filemtime($fileSystemPath);
$fileExt = File::getFileExtension(basename($fileSystemPath));
// simple detection for source type if SOURCE is selected
if ($format == "source" || empty($format)) {
$format = self::getAllowedFormat($fileExt, array("jpeg", "gif", "png"), "png");
$contentOptimizedFormat = true;
// format can change depending of the content (alpha-channel, ...)
}
if ($format == "print") {
$format = self::getAllowedFormat($fileExt, array("svg", "jpeg", "png", "tiff"), "png");
if (($format == "tiff" || $format == "svg") && \Pimcore\Tool::isFrontentRequestByAdmin()) {
// return a webformat in admin -> tiff cannot be displayed in browser
$format = "png";
} else {
if ($format == "tiff") {
$transformations = $config->getItems();
if (is_array($transformations) && count($transformations) > 0) {
foreach ($transformations as $transformation) {
if (!empty($transformation)) {
if ($transformation["method"] == "tifforiginal") {
return str_replace(PIMCORE_DOCUMENT_ROOT, "", $fileSystemPath);
}
}
}
}
} else {
if ($format == "svg") {
return str_replace(PIMCORE_DOCUMENT_ROOT, "", $fileSystemPath);
}
}
}
}
$thumbDir = $asset->getImageThumbnailSavePath() . "/thumb__" . $config->getName();
$filename = preg_replace("/\\." . preg_quote(File::getFileExtension($asset->getFilename())) . "/", "", $asset->getFilename());
// add custom suffix if available
if ($config->getFilenameSuffix()) {
$filename .= "~-~" . $config->getFilenameSuffix();
}
// add high-resolution modifier suffix to the filename
if ($config->getHighResolution() > 1) {
$filename .= "@" . $config->getHighResolution() . "x";
}
$filename .= "." . $format;
$fsPath = $thumbDir . "/" . $filename;
if (!is_dir(dirname($fsPath))) {
File::mkdir(dirname($fsPath));
}
$path = str_replace(PIMCORE_DOCUMENT_ROOT, "", $fsPath);
// check for existing and still valid thumbnail
if (is_file($fsPath) and filemtime($fsPath) >= $modificationDate) {
return $path;
}
// deferred means that the image will be generated on-the-fly (when requested by the browser)
// the configuration is saved for later use in Pimcore\Controller\Plugin\Thumbnail::routeStartup()
// so that it can be used also with dynamic configurations
if ($deferred) {
$configId = "thumb_" . $id . "__" . md5($path);
TmpStore::add($configId, $config, "thumbnail_deferred");
return $path;
}
// transform image
$image = Asset\Image::getImageTransformInstance();
if (!$image->load($fileSystemPath)) {
return "/pimcore/static/img/filetype-not-supported.png";
}
$image->setUseContentOptimizedFormat($contentOptimizedFormat);
$startTime = StopWatch::microtime_float();
$transformations = $config->getItems();
// check if the original image has an orientation exif flag
// if so add a transformation at the beginning that rotates and/or mirrors the image
if (function_exists("exif_read_data")) {
$exif = @exif_read_data($fileSystemPath);
if (is_array($exif)) {
if (array_key_exists("Orientation", $exif)) {
$orientation = intval($exif["Orientation"]);
if ($orientation > 1) {
$angleMappings = [2 => 180, 3 => 180, 4 => 180, 5 => 90, 6 => 90, 7 => 90, 8 => 270];
if (array_key_exists($orientation, $angleMappings)) {
//.........这里部分代码省略.........
示例4: init
/**
* @throws \Zend_Controller_Router_Exception
*/
public function init()
{
// this is only executed once per request (first request)
if (self::$isInitial) {
\Pimcore::getEventManager()->trigger("frontend.controller.preInit", $this);
}
parent::init();
// log exceptions if handled by error_handler
$this->checkForErrors();
// general definitions
if (self::$isInitial) {
\Pimcore::unsetAdminMode();
Document::setHideUnpublished(true);
Object\AbstractObject::setHideUnpublished(true);
Object\AbstractObject::setGetInheritedValues(true);
Object\Localizedfield::setGetFallbackValues(true);
}
// assign variables
$this->view->controller = $this;
// init website config
$config = Config::getWebsiteConfig();
$this->config = $config;
$this->view->config = $config;
$document = $this->getParam("document");
if (!$document instanceof Document) {
\Zend_Registry::set("pimcore_editmode", false);
$this->editmode = false;
$this->view->editmode = false;
self::$isInitial = false;
// check for a locale first, and set it if available
if ($this->getParam("pimcore_parentDocument")) {
// this is a special exception for renderlets in editmode (ajax request), because they depend on the locale of the parent document
// otherwise there'll be notices like: Notice: 'No translation for the language 'XX' available.'
if ($parentDocument = Document::getById($this->getParam("pimcore_parentDocument"))) {
if ($parentDocument->getProperty("language")) {
$this->setLocaleFromDocument($parentDocument->getProperty("language"));
}
}
}
// no document available, continue, ...
return;
} else {
$this->setDocument($document);
// register global locale if the document has the system property "language"
if ($this->getDocument()->getProperty("language")) {
$this->setLocaleFromDocument($this->getDocument()->getProperty("language"));
}
if (self::$isInitial) {
// append meta-data to the headMeta() view helper, if it is a document-request
if (!Model\Staticroute::getCurrentRoute() && $this->getDocument() instanceof Document\Page) {
if (is_array($this->getDocument()->getMetaData())) {
foreach ($this->getDocument()->getMetaData() as $meta) {
// only name
if (!empty($meta["idName"]) && !empty($meta["idValue"]) && !empty($meta["contentValue"])) {
$method = "append" . ucfirst($meta["idName"]);
$this->view->headMeta()->{$method}($meta["idValue"], $meta["contentValue"]);
}
}
}
}
}
}
// this is only executed once per request (first request)
if (self::$isInitial) {
// contains the logged in user if necessary
$user = null;
// default is to set the editmode to false, is enabled later if necessary
\Zend_Registry::set("pimcore_editmode", false);
if (Tool::isFrontentRequestByAdmin()) {
$this->disableBrowserCache();
// start admin session & get logged in user
$user = Authentication::authenticateSession();
}
if (\Pimcore::inDebugMode()) {
$this->disableBrowserCache();
}
if (!$this->document->isPublished()) {
if (Tool::isFrontentRequestByAdmin()) {
if (!$user) {
throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
}
} else {
throw new \Zend_Controller_Router_Exception("access denied for " . $this->document->getFullPath());
}
}
// logged in users only
if ($user) {
// set the user to registry so that it is available via \Pimcore\Tool\Admin::getCurrentUser();
\Zend_Registry::set("pimcore_admin_user", $user);
// document editmode
if ($this->getParam("pimcore_editmode")) {
\Zend_Registry::set("pimcore_editmode", true);
// check if there is the document in the session
$docKey = "document_" . $this->getDocument()->getId();
$docSession = Session::getReadOnly("pimcore_documents");
if ($docSession->{$docKey}) {
// if there is a document in the session use it
//.........这里部分代码省略.........
示例5: checkForRedirect
/**
* Checks for a suitable redirect
* @throws Exception
* @param bool $override
* @return void
*/
protected function checkForRedirect($override = false)
{
// not for admin requests
if (Tool::isFrontentRequestByAdmin()) {
return;
}
try {
$front = \Zend_Controller_Front::getInstance();
$config = Config::getSystemConfig();
// get current site if available
$sourceSite = null;
if (Site::isSiteRequest()) {
$sourceSite = Site::getCurrentSite();
}
$cacheKey = "system_route_redirect";
if (empty($this->redirects) && !($this->redirects = Cache::load($cacheKey))) {
$list = new Redirect\Listing();
$list->setOrder("DESC");
$list->setOrderKey("priority");
$this->redirects = $list->load();
Cache::save($this->redirects, $cacheKey, array("system", "redirect", "route"), null, 998);
}
$requestScheme = $_SERVER['HTTPS'] == 'on' ? \Zend_Controller_Request_Http::SCHEME_HTTPS : \Zend_Controller_Request_Http::SCHEME_HTTP;
$matchRequestUri = $_SERVER["REQUEST_URI"];
$matchUrl = $requestScheme . "://" . $_SERVER["HTTP_HOST"] . $matchRequestUri;
foreach ($this->redirects as $redirect) {
$matchAgainst = $matchRequestUri;
if ($redirect->getSourceEntireUrl()) {
$matchAgainst = $matchUrl;
}
// if override is true the priority has to be 99 which means that overriding is ok
if (!$override || $override && $redirect->getPriority() == 99) {
if (@preg_match($redirect->getSource(), $matchAgainst, $matches)) {
// check for a site
if ($sourceSite) {
if ($sourceSite->getId() != $redirect->getSourceSite()) {
continue;
}
}
array_shift($matches);
$target = $redirect->getTarget();
if (is_numeric($target)) {
$d = Document::getById($target);
if ($d instanceof Document\Page || $d instanceof Document\Link || $d instanceof Document\Hardlink) {
$target = $d->getFullPath();
} else {
\Logger::error("Target of redirect no found (Document-ID: " . $target . ")!");
continue;
}
}
// replace escaped % signs so that they didn't have effects to vsprintf (PIMCORE-1215)
$target = str_replace("\\%", "###URLENCODE_PLACEHOLDER###", $target);
$url = vsprintf($target, $matches);
$url = str_replace("###URLENCODE_PLACEHOLDER###", "%", $url);
// support for pcre backreferences
$url = replace_pcre_backreferences($url, $matches);
if ($redirect->getTargetSite() && !preg_match("@http(s)?://@i", $url)) {
try {
$targetSite = Site::getById($redirect->getTargetSite());
// if the target site is specified and and the target-path is starting at root (not absolute to site)
// the root-path will be replaced so that the page can be shown
$url = preg_replace("@^" . $targetSite->getRootPath() . "/@", "/", $url);
$url = $requestScheme . "://" . $targetSite->getMainDomain() . $url;
} catch (\Exception $e) {
\Logger::error("Site with ID " . $redirect->getTargetSite() . " not found.");
continue;
}
} else {
if (!preg_match("@http(s)?://@i", $url) && $config->general->domain && $redirect->getSourceEntireUrl()) {
// prepend the host and scheme to avoid infinite loops when using "domain" redirects
$url = ($front->getRequest()->isSecure() ? "https" : "http") . "://" . $config->general->domain . $url;
}
}
// pass-through parameters if specified
$queryString = $_SERVER["QUERY_STRING"];
if ($redirect->getPassThroughParameters() && !empty($queryString)) {
$glue = "?";
if (strpos($url, "?")) {
$glue = "&";
}
$url .= $glue;
$url .= $queryString;
}
header($redirect->getHttpStatus());
header("Location: " . $url, true, $redirect->getStatusCode());
// log all redirects to the redirect log
\Pimcore\Log\Simple::log("redirect", Tool::getAnonymizedClientIp() . " \t Custom-Redirect ID: " . $redirect->getId() . " , Source: " . $_SERVER["REQUEST_URI"] . " -> " . $url);
exit;
}
}
}
} catch (\Exception $e) {
// no suitable route found
}
//.........这里部分代码省略.........
示例6: run
//.........这里部分代码省略.........
if (Tool::useFrontendOutputFilters(new \Zend_Controller_Request_Http())) {
$front->registerPlugin(new Controller\Plugin\HybridAuth(), 792);
$front->registerPlugin(new Controller\Plugin\QrCode(), 793);
$front->registerPlugin(new Controller\Plugin\CommonFilesFilter(), 794);
$front->registerPlugin(new Controller\Plugin\WysiwygAttributes(), 796);
$front->registerPlugin(new Controller\Plugin\Webmastertools(), 797);
$front->registerPlugin(new Controller\Plugin\Analytics(), 798);
$front->registerPlugin(new Controller\Plugin\TagManagement(), 804);
$front->registerPlugin(new Controller\Plugin\Targeting(), 805);
$front->registerPlugin(new Controller\Plugin\EuCookieLawNotice(), 807);
$front->registerPlugin(new Controller\Plugin\HttpErrorLog(), 850);
$front->registerPlugin(new Controller\Plugin\Cache(), 901);
// for caching
}
self::initControllerFront($front);
// set router
$router = $front->getRouter();
$routeAdmin = new \Zend_Controller_Router_Route('admin/:controller/:action/*', array('module' => 'admin', "controller" => "index", "action" => "index"));
$routeInstall = new \Zend_Controller_Router_Route('install/:controller/:action/*', array('module' => 'install', "controller" => "index", "action" => "index"));
$routeUpdate = new \Zend_Controller_Router_Route('admin/update/:controller/:action/*', array('module' => 'update', "controller" => "index", "action" => "index"));
$routePlugins = new \Zend_Controller_Router_Route('admin/plugin/:controller/:action/*', array('module' => 'pluginadmin', "controller" => "index", "action" => "index"));
$routeExtensions = new \Zend_Controller_Router_Route('admin/extensionmanager/:controller/:action/*', array('module' => 'extensionmanager', "controller" => "index", "action" => "index"));
$routeReports = new \Zend_Controller_Router_Route('admin/reports/:controller/:action/*', array('module' => 'reports', "controller" => "index", "action" => "index"));
$routePlugin = new \Zend_Controller_Router_Route('plugin/:module/:controller/:action/*', array("controller" => "index", "action" => "index"));
$routeWebservice = new \Zend_Controller_Router_Route('webservice/:controller/:action/*', array("module" => "webservice", "controller" => "index", "action" => "index"));
$routeSearchAdmin = new \Zend_Controller_Router_Route('admin/search/:controller/:action/*', array("module" => "searchadmin", "controller" => "index", "action" => "index"));
// website route => custom router which check for a suitable document
$routeFrontend = new Controller\Router\Route\Frontend();
$router->addRoute('default', $routeFrontend);
// only do this if not frontend => performance issue
if (!$frontend) {
$router->addRoute("install", $routeInstall);
$router->addRoute('plugin', $routePlugin);
$router->addRoute('admin', $routeAdmin);
$router->addRoute('update', $routeUpdate);
$router->addRoute('plugins', $routePlugins);
$router->addRoute('extensionmanager', $routeExtensions);
$router->addRoute('reports', $routeReports);
$router->addRoute('searchadmin', $routeSearchAdmin);
if ($conf instanceof \Zend_Config and $conf->webservice and $conf->webservice->enabled) {
$router->addRoute('webservice', $routeWebservice);
}
// check if this request routes into a plugin, if so check if the plugin is enabled
if (preg_match("@^/plugin/([^/]+)/.*@", $_SERVER["REQUEST_URI"], $matches)) {
$pluginName = $matches[1];
if (!Pimcore\ExtensionManager::isEnabled("plugin", $pluginName)) {
\Pimcore\Tool::exitWithError("Plugin is disabled. To use this plugin please enable it in the extension manager!");
}
}
// force the main (default) domain for "admin" requests
if ($conf->general->domain && $conf->general->domain != Tool::getHostname()) {
$url = ($_SERVER['HTTPS'] == "on" ? "https" : "http") . "://" . $conf->general->domain . $_SERVER["REQUEST_URI"];
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $url, true, 301);
exit;
}
}
// check if webdav is configured and add router
if ($conf instanceof \Zend_Config) {
if ($conf->assets->webdav->hostname) {
$routeWebdav = new \Zend_Controller_Router_Route_Hostname($conf->assets->webdav->hostname, array("module" => "admin", 'controller' => 'asset', 'action' => 'webdav'));
$router->addRoute('webdav', $routeWebdav);
}
}
$front->setRouter($router);
self::getEventManager()->trigger("system.startup", $front);
// throw exceptions also when in preview or in editmode (documents) to see it immediately when there's a problem with this page
$throwExceptions = false;
if (Tool::isFrontentRequestByAdmin()) {
$user = \Pimcore\Tool\Authentication::authenticateSession();
if ($user instanceof User) {
$throwExceptions = true;
}
}
// run dispatcher
// this is also standard for /admin/ requests -> error handling is done in Pimcore_Controller_Action_Admin
if (!PIMCORE_DEBUG && !$throwExceptions && !PIMCORE_DEVMODE) {
@ini_set("display_errors", "Off");
@ini_set("display_startup_errors", "Off");
$front->dispatch();
} else {
@ini_set("display_errors", "On");
@ini_set("display_startup_errors", "On");
$front->throwExceptions(true);
try {
$front->dispatch();
} catch (\Zend_Controller_Router_Exception $e) {
if (!headers_sent()) {
header("HTTP/1.0 404 Not Found");
}
\Logger::err($e);
throw new \Zend_Controller_Router_Exception("No route, document, custom route or redirect is matching the request: " . $_SERVER["REQUEST_URI"] . " | \n" . "Specific ERROR: " . $e->getMessage());
} catch (\Exception $e) {
if (!headers_sent()) {
header("HTTP/1.0 500 Internal Server Error");
}
throw $e;
}
}
}
示例7: url
/**
* @param array $urlOptions
* @param null $name
* @param bool $reset
* @param bool $encode
* @return string|void
* @throws \Exception
*/
public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
{
if (!$urlOptions) {
$urlOptions = array();
}
// when using $name = false we don't use the default route (happens when $name = null / ZF default behavior)
// but just the query string generation using the given parameters
// eg. $this->url(["foo" => "bar"], false) => /?foo=bar
if ($name === null) {
if (Staticroute::getCurrentRoute() instanceof Staticroute) {
$name = Staticroute::getCurrentRoute()->getName();
}
}
$siteId = null;
if (Site::isSiteRequest()) {
$siteId = Site::getCurrentSite()->getId();
}
// check for a site in the options, if valid remove it from the options
$hostname = null;
if (isset($urlOptions["site"])) {
$config = Config::getSystemConfig();
$site = $urlOptions["site"];
if (!empty($site)) {
try {
$site = Site::getBy($site);
unset($urlOptions["site"]);
$hostname = $site->getMainDomain();
$siteId = $site->getId();
} catch (\Exception $e) {
\Logger::warn("passed site doesn't exists");
\Logger::warn($e);
}
} else {
if ($config->general->domain) {
$hostname = $config->general->domain;
}
}
}
if ($name && ($route = Staticroute::getByName($name, $siteId))) {
// assemble the route / url in Staticroute::assemble()
$url = $route->assemble($urlOptions, $reset, $encode);
// if there's a site, prepend the host to the generated URL
if ($hostname && !preg_match("/^http/i", $url)) {
$url = "//" . $hostname . $url;
}
if (Config::getSystemConfig()->documents->allowcapitals == 'no') {
$urlParts = parse_url($url);
$url = str_replace($urlParts["path"], strtolower($urlParts["path"]), $url);
}
return $url;
}
// this is to add support for arrays as values for the default \Zend_View_Helper_Url
$unset = array();
foreach ($urlOptions as $optionName => $optionValues) {
if (is_array($optionValues)) {
foreach ($optionValues as $key => $value) {
$urlOptions[$optionName . "[" . $key . "]"] = $value;
}
$unset[] = $optionName;
}
}
foreach ($unset as $optionName) {
unset($urlOptions[$optionName]);
}
try {
return parent::url($urlOptions, $name, $reset, $encode);
} catch (\Exception $e) {
if (Tool::isFrontentRequestByAdmin()) {
// routes can be site specific, so in editmode it's possible that we don't get
// the right route (sites are not registered in editmode), so we cannot throw exceptions there
return "ERROR_IN_YOUR_URL_CONFIGURATION:~ROUTE--" . $name . "--DOES_NOT_EXIST";
}
throw new \Exception("Route '" . $name . "' for building the URL not found");
}
}
示例8: getWebsiteConfig
/**
* @static
* @return mixed|\Zend_Config
*/
public static function getWebsiteConfig()
{
if (\Zend_Registry::isRegistered("pimcore_config_website")) {
$config = \Zend_Registry::get("pimcore_config_website");
} else {
$cacheKey = "website_config";
$siteId = null;
if (Model\Site::isSiteRequest()) {
$siteId = Model\Site::getCurrentSite()->getId();
} elseif (Tool::isFrontentRequestByAdmin()) {
// this is necessary to set the correct settings in editmode/preview (using the main domain)
$front = \Zend_Controller_Front::getInstance();
$originDocument = $front->getRequest()->getParam("document");
if ($originDocument) {
$site = Tool\Frontend::getSiteForDocument($originDocument);
if ($site) {
$siteId = $site->getId();
}
}
}
if ($siteId) {
$cacheKey = $cacheKey . "_site_" . $siteId;
}
if (!($config = Cache::load($cacheKey))) {
$settingsArray = [];
$cacheTags = ["website_config", "system", "config", "output"];
$list = new Model\WebsiteSetting\Listing();
$list = $list->load();
foreach ($list as $item) {
$key = $item->getName();
$itemSiteId = $item->getSiteId();
if ($itemSiteId != 0 && $itemSiteId != $siteId) {
continue;
}
$s = null;
switch ($item->getType()) {
case "document":
case "asset":
case "object":
$s = Model\Element\Service::getElementById($item->getType(), $item->getData());
break;
case "bool":
$s = (bool) $item->getData();
break;
case "text":
$s = (string) $item->getData();
break;
}
if ($s instanceof Model\Element\ElementInterface) {
$cacheTags = $s->getCacheTags($cacheTags);
}
if (isset($s)) {
$settingsArray[$key] = $s;
}
}
$config = new \Zend_Config($settingsArray, true);
Cache::save($config, $cacheKey, $cacheTags, null, 998);
}
self::setWebsiteConfig($config);
}
return $config;
}
示例9: getMimeType
/**
* Get the height of the generated thumbnail image in pixels.
* @return string HTTP Mime Type of the generated thumbnail image.
*/
public function getMimeType()
{
if (!$this->mimetype) {
// get target mime type without actually generating the thumbnail (deferred)
$mapping = ["png" => "image/png", "jpg" => "image/jpeg", "jpeg" => "image/jpeg", "pjpeg" => "image/jpeg", "gif" => "image/gif", "tiff" => "image/tiff", "svg" => "image/svg+xml"];
$targetFormat = strtolower($this->getConfig()->getFormat());
$format = $targetFormat;
$fileExt = \Pimcore\File::getFileExtension($this->getAsset()->getFilename());
if ($targetFormat == "source" || empty($targetFormat)) {
$format = Thumbnail\Processor::getAllowedFormat($fileExt, ["jpeg", "gif", "png"], "png");
} elseif ($targetFormat == "print") {
$format = Thumbnail\Processor::getAllowedFormat($fileExt, ["svg", "jpeg", "png", "tiff"], "png");
if (($format == "tiff" || $format == "svg") && \Pimcore\Tool::isFrontentRequestByAdmin()) {
// return a webformat in admin -> tiff cannot be displayed in browser
$format = "png";
}
}
if (array_key_exists($format, $mapping)) {
$this->mimetype = $mapping[$format];
} else {
// unknown
$this->mimetype = "application/octet-stream";
}
}
return $this->mimetype;
}
示例10: process
/**
* @param $asset
* @param Config $config
* @param null $fileSystemPath
* @param bool $deferred deferred means that the image will be generated on-the-fly (details see below)
* @param bool $returnAbsolutePath
* @param bool $generated
* @return mixed|string
*/
public static function process($asset, Config $config, $fileSystemPath = null, $deferred = false, $returnAbsolutePath = false, &$generated = false)
{
$generated = false;
$errorImage = PIMCORE_PATH . "/static6/img/filetype-not-supported.png";
$format = strtolower($config->getFormat());
$contentOptimizedFormat = false;
if (!$fileSystemPath && $asset instanceof Asset) {
$fileSystemPath = $asset->getFileSystemPath();
}
if ($asset instanceof Asset) {
$id = $asset->getId();
} else {
$id = "dyn~" . crc32($fileSystemPath);
}
$fileExt = File::getFileExtension(basename($fileSystemPath));
// simple detection for source type if SOURCE is selected
if ($format == "source" || empty($format)) {
$format = self::getAllowedFormat($fileExt, ["jpeg", "gif", "png"], "png");
$contentOptimizedFormat = true;
// format can change depending of the content (alpha-channel, ...)
}
if ($format == "print") {
$format = self::getAllowedFormat($fileExt, ["svg", "jpeg", "png", "tiff"], "png");
if (($format == "tiff" || $format == "svg") && \Pimcore\Tool::isFrontentRequestByAdmin()) {
// return a webformat in admin -> tiff cannot be displayed in browser
$format = "png";
$deferred = false;
// deferred is default, but it's not possible when using isFrontentRequestByAdmin()
} elseif ($format == "tiff") {
$transformations = $config->getItems();
if (is_array($transformations) && count($transformations) > 0) {
foreach ($transformations as $transformation) {
if (!empty($transformation)) {
if ($transformation["method"] == "tifforiginal") {
return self::returnPath($fileSystemPath, $returnAbsolutePath);
}
}
}
}
} elseif ($format == "svg") {
return self::returnPath($fileSystemPath, $returnAbsolutePath);
}
} elseif ($format == "tiff") {
if (\Pimcore\Tool::isFrontentRequestByAdmin()) {
// return a webformat in admin -> tiff cannot be displayed in browser
$format = "png";
$deferred = false;
// deferred is default, but it's not possible when using isFrontentRequestByAdmin()
}
}
$thumbDir = $asset->getImageThumbnailSavePath() . "/thumb__" . $config->getName();
$filename = preg_replace("/\\." . preg_quote(File::getFileExtension($asset->getFilename())) . "/", "", $asset->getFilename());
// add custom suffix if available
if ($config->getFilenameSuffix()) {
$filename .= "~-~" . $config->getFilenameSuffix();
}
// add high-resolution modifier suffix to the filename
if ($config->getHighResolution() > 1) {
$filename .= "@" . $config->getHighResolution() . "x";
}
$fileExtension = $format;
if ($format == "original") {
$fileExtension = \Pimcore\File::getFileExtension($fileSystemPath);
}
$filename .= "." . $fileExtension;
$fsPath = $thumbDir . "/" . $filename;
// deferred means that the image will be generated on-the-fly (when requested by the browser)
// the configuration is saved for later use in Pimcore\Controller\Plugin\Thumbnail::routeStartup()
// so that it can be used also with dynamic configurations
if ($deferred) {
// only add the config to the TmpStore if necessary (the config is auto-generated)
if (!Config::getByName($config->getName())) {
$configId = "thumb_" . $id . "__" . md5(str_replace(PIMCORE_TEMPORARY_DIRECTORY, "", $fsPath));
TmpStore::add($configId, $config, "thumbnail_deferred");
}
return self::returnPath($fsPath, $returnAbsolutePath);
}
// all checks on the file system should be below the deferred part for performance reasons (remote file systems)
if (!file_exists($fileSystemPath)) {
return self::returnPath($errorImage, $returnAbsolutePath);
}
if (!is_dir(dirname($fsPath))) {
File::mkdir(dirname($fsPath));
}
$path = self::returnPath($fsPath, false);
// check for existing and still valid thumbnail
if (is_file($fsPath) and filemtime($fsPath) >= filemtime($fileSystemPath)) {
return self::returnPath($fsPath, $returnAbsolutePath);
}
// transform image
$image = Asset\Image::getImageTransformInstance();
//.........这里部分代码省略.........