getOption() public static method

public static getOption ( $name ) : mixed
$name
return mixed
Ejemplo n.º 1
0
 /**
  * if this method is called in self::shutdown() it forces the browser to close the connection an allows the
  * shutdown-function to run in the background
  * @static
  * @return string
  */
 public static function outputBufferEnd($data)
 {
     $output = null;
     $contentEncoding = null;
     if (headers_sent()) {
         return $data;
     }
     // cleanup admin session Set-Cookie headers if needed
     // a detailed description why this is necessary can be found in the doc-block of \Pimcore\Tool\Session::$sessionCookieCleanupNeeded
     if (Tool\Session::isSessionCookieCleanupNeeded()) {
         $headers = headers_list();
         $headers = array_reverse($headers);
         foreach ($headers as $header) {
             if (strpos($header, Tool\Session::getOption("name")) !== false) {
                 header($header, true);
                 // setting the header again with 2nd arg = true, overrides all duplicates
                 break;
             }
         }
     }
     // only send this headers in the shutdown-function, so that it is also possible to get the contents of this buffer earlier without sending headers
     if (self::$inShutdown) {
         // force closing the connection at the client, this enables to do certain tasks (writing the cache) in the "background"
         header("Connection: close\r\n");
         // check for supported content-encodings
         if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) {
             $contentEncoding = "gzip";
         }
         if (!empty($data) && $contentEncoding) {
             ignore_user_abort(true);
             // find the content-type of the response
             $front = \Zend_Controller_Front::getInstance();
             $a = $front->getResponse()->getHeaders();
             $b = array_merge(headers_list(), $front->getResponse()->getRawHeaders());
             $contentType = null;
             // first check headers in headers_list() because they overwrite all other headers => see SOAP controller
             foreach ($b as $header) {
                 if (stripos($header, "content-type") !== false) {
                     $parts = explode(":", $header);
                     if (strtolower(trim($parts[0])) == "content-type") {
                         $contentType = trim($parts[1]);
                         break;
                     }
                 }
             }
             if (!$contentType) {
                 foreach ($a as $header) {
                     if (strtolower(trim($header["name"])) == "content-type") {
                         $contentType = $header["value"];
                         break;
                     }
                 }
             }
             // prepare the response to be sent (gzip or not)
             // do not add text/xml or a wildcard for text/* here because this causes problems with the SOAP server
             $gzipContentTypes = array("@text/html@i", "@application/json@", "@text/javascript@", "@text/css@");
             $gzipIt = false;
             foreach ($gzipContentTypes as $type) {
                 if (@preg_match($type, $contentType)) {
                     $gzipIt = true;
                     break;
                 }
             }
             // gzip the contents and send connection close tthat the process can run in the background to finish
             // some tasks like writing the cache ...
             // using mb_strlen() because of PIMCORE-1509
             if ($gzipIt) {
                 $output = "‹" . substr(gzcompress($data, 2), 0, -4) . pack('V', crc32($data)) . pack('V', mb_strlen($data, "latin1"));
                 // (although all modern browsers don't need it anymore) to work properly with google adwords check & co.
                 header("Content-Encoding: {$contentEncoding}\r\n");
             }
         }
         // no gzip/deflate encoding
         if (!$output) {
             $output = $data;
         }
         if (strlen($output) > 0) {
             // check here if there is actually content, otherwise readfile() and similar functions are not working anymore
             header("Content-Length: " . mb_strlen($output, "latin1"));
         }
         header("X-Powered-By: pimcore", true);
     }
     // return the data unchanged
     return $output;
 }
Ejemplo n.º 2
0
 public function diffVersionsAction()
 {
     $versionFrom = Version::getById($this->getParam("from"));
     $docFrom = $versionFrom->loadData();
     $request = $this->getRequest();
     $sessionName = Tool\Session::getOption("name");
     $prefix = $request->getScheme() . "://" . $request->getHttpHost() . $docFrom->getFullPath() . "?pimcore_version=";
     $fromUrl = $prefix . $this->getParam("from") . "&" . $sessionName . "=" . $_COOKIE[$sessionName];
     $toUrl = $prefix . $this->getParam("to") . "&" . $sessionName . "=" . $_COOKIE[$sessionName];
     $fromFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/version-diff-tmp-" . uniqid() . ".png";
     $toFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/version-diff-tmp-" . uniqid() . ".png";
     $diffFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/version-diff-tmp-" . uniqid() . ".png";
     if (\Pimcore\Image\HtmlToImage::isSupported() && class_exists("Imagick")) {
         \Pimcore\Image\HtmlToImage::convert($fromUrl, $fromFile);
         \Pimcore\Image\HtmlToImage::convert($toUrl, $toFile);
         $image1 = new Imagick($fromFile);
         $image2 = new Imagick($toFile);
         if ($image1->getImageWidth() == $image2->getImageWidth() && $image1->getImageHeight() == $image2->getImageHeight()) {
             $result = $image1->compareImages($image2, Imagick::METRIC_MEANSQUAREERROR);
             $result[0]->setImageFormat("png");
             $result[0]->writeImage($diffFile);
             $result[0]->clear();
             $result[0]->destroy();
             $this->view->image = base64_encode(file_get_contents($diffFile));
             unlink($diffFile);
         } else {
             $this->view->image1 = base64_encode(file_get_contents($fromFile));
             $this->view->image2 = base64_encode(file_get_contents($toFile));
         }
         // cleanup
         $image1->clear();
         $image1->destroy();
         $image2->clear();
         $image2->destroy();
         unlink($fromFile);
         unlink($toFile);
     } else {
         $this->renderScript("document/diff-versions-unsupported.php");
     }
 }