protected function featureBug()
 {
     $conf = \Pimcore\Config::getSystemConfig();
     $email = $conf->general->contactemail;
     $this->view->contactEmail = $email;
     if (!$this->getParam("submit")) {
         if (HtmlToImage::isSupported()) {
             $file = PIMCORE_TEMPORARY_DIRECTORY . "/screen-" . uniqid() . ".jpeg";
             HtmlToImage::convert($this->getParam("url"), $file, 1280, "jpeg");
             $this->view->image = str_replace(PIMCORE_DOCUMENT_ROOT, "", $file);
         }
     } else {
         // send the request
         $type = $this->view->type;
         $urlParts = parse_url($this->getParam("url"));
         $subject = "Feature Request for ";
         if ($type == "bug") {
             $subject = "Bug Report for ";
         }
         $subject .= $urlParts["host"];
         $mail = \Pimcore\Tool::getMail($email, $subject, "UTF-8");
         $mail->setIgnoreDebugMode(true);
         $bodyText = "URL: " . $this->getParam("url") . "\n\n";
         $bodyText .= "Description: \n\n" . $this->getParam("description");
         $image = null;
         if (HtmlToImage::isSupported()) {
             $markers = \Zend_Json::decode($this->getParam("markers"));
             $screenFile = PIMCORE_DOCUMENT_ROOT . $this->getParam("screenshot");
             list($width, $height) = getimagesize($screenFile);
             $im = imagecreatefromjpeg($screenFile);
             $font = PIMCORE_DOCUMENT_ROOT . "/pimcore/static6/font/vera.ttf";
             $fontSize = 10;
             if ($markers && count($markers) > 0) {
                 foreach ($markers as $marker) {
                     // set up array of points for polygon
                     $x = $marker["position"]["left"] * $width / 100;
                     $y = $marker["position"]["top"] * $height / 100;
                     $bbox = imagettfbbox($fontSize, 0, $font, $marker["text"]);
                     $textWidth = $bbox[4] + 10;
                     $values = array($x, $y, $x - 10, $y - 10, $x - 10, $y - 40, $x + $textWidth, $y - 40, $x + $textWidth, $y - 10, $x + 10, $y - 10);
                     $textcolor = imagecolorallocate($im, 255, 255, 255);
                     $bgcolor = imagecolorallocatealpha($im, 0, 0, 0, 30);
                     // draw a polygon
                     imagefilledpolygon($im, $values, 6, $bgcolor);
                     imagettftext($im, $fontSize, 0, $x, $y - 20, $textcolor, $font, $marker["text"]);
                 }
             }
             imagejpeg($im, $screenFile);
             imagedestroy($im);
             $image = file_get_contents($screenFile);
             unlink($screenFile);
         }
         if ($image) {
             $bodyText .= "\n\n\nsee attached file: screen.jpg";
             $at = $mail->createAttachment($image);
             $at->type = 'image/jpeg';
             $at->disposition = \Zend_Mime::DISPOSITION_ATTACHMENT;
             $at->encoding = \Zend_Mime::ENCODING_BASE64;
             $at->filename = 'screen.jpg';
         }
         if ($type == "bug") {
             $bodyText .= "\n\n";
             $bodyText .= "Details: \n\n";
             foreach ($_SERVER as $key => $value) {
                 $bodyText .= $key . " => " . $value . "\n";
             }
         }
         $mail->setBodyText($bodyText);
         $mail->send();
     }
     $this->renderScript("/admin-button/feature-bug.php");
 }
 public function generateScreenshotAction()
 {
     $success = false;
     if ($this->getParam("id")) {
         $doc = Document::getById($this->getParam("id"));
         $url = Tool::getHostUrl() . $doc->getRealFullPath() . "?pimcore_preview=true";
         $config = \Pimcore\Config::getSystemConfig();
         if ($config->general->http_auth) {
             $username = $config->general->http_auth->username;
             $password = $config->general->http_auth->password;
             if ($username && $password) {
                 $url = str_replace("://", "://" . $username . ":" . $password . "@", $url);
             }
         }
         $tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/screenshot_tmp_" . $doc->getId() . ".png";
         $file = PIMCORE_TEMPORARY_DIRECTORY . "/document-page-previews/document-page-screenshot-" . $doc->getId() . ".jpg";
         $dir = dirname($file);
         if (!is_dir($dir)) {
             File::mkdir($dir);
         }
         try {
             if (\Pimcore\Image\HtmlToImage::convert($url, $tmpFile)) {
                 $im = \Pimcore\Image::getInstance();
                 $im->load($tmpFile);
                 $im->scaleByWidth(400);
                 $im->save($file, "jpeg", 85);
                 unlink($tmpFile);
                 $success = true;
             }
         } catch (\Exception $e) {
             \Logger::error($e);
         }
     }
     $this->_helper->json(array("success" => $success));
 }
 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");
     }
 }