コード例 #1
0
ファイル: Dompdf.php プロジェクト: onyxnz/quartzpos
 /**
  * Loads an HTML file
  * Parse errors are stored in the global array _dompdf_warnings.
  *
  * @param string $file a filename or url to load
  *
  * @throws Exception
  */
 public function loadHtmlFile($file)
 {
     $this->saveLocale();
     // Store parsing warnings as messages (this is to prevent output to the
     // browser if the html is ugly and the dom extension complains,
     // preventing the pdf from being streamed.)
     if (!$this->protocol && !$this->baseHost && !$this->basePath) {
         list($this->protocol, $this->baseHost, $this->basePath) = Helpers::explode_url($file);
     }
     if (!$this->options->isRemoteEnabled() && ($this->protocol != "" && $this->protocol !== "file://")) {
         throw new Exception("Remote file requested, but remote file download is disabled.");
     }
     if ($this->protocol == "" || $this->protocol === "file://") {
         // Get the full path to $file, returns false if the file doesn't exist
         $realfile = realpath($file);
         if (!$realfile) {
             throw new Exception("File '{$file}' not found.");
         }
         $chroot = $this->options->getChroot();
         if (strpos($realfile, $chroot) !== 0) {
             throw new Exception("Permission denied on {$file}. The file could not be found under the directory specified by Options::chroot.");
         }
         // Exclude dot files (e.g. .htaccess)
         if (substr(basename($realfile), 0, 1) === ".") {
             throw new Exception("Permission denied on {$file}.");
         }
         $file = $realfile;
     }
     $contents = file_get_contents($file, null, $this->httpContext);
     $encoding = null;
     // See http://the-stickman.com/web-development/php/getting-http-response-headers-when-using-file_get_contents/
     if (isset($http_response_header)) {
         foreach ($http_response_header as $_header) {
             if (preg_match("@Content-Type:\\s*[\\w/]+;\\s*?charset=([^\\s]+)@i", $_header, $matches)) {
                 $encoding = strtoupper($matches[1]);
                 break;
             }
         }
     }
     $this->restoreLocale();
     $this->loadHtml($contents, $encoding);
 }
コード例 #2
0
ファイル: Dompdf.php プロジェクト: hieunhan1/all-website-v5
 /**
  * Loads an HTML file
  * Parse errors are stored in the global array _dompdf_warnings.
  *
  * @param string $file a filename or url to load
  *
  * @throws Exception
  */
 public function loadHtmlFile($file)
 {
     $this->saveLocale();
     if (!$this->protocol && !$this->baseHost && !$this->basePath) {
         list($this->protocol, $this->baseHost, $this->basePath) = Helpers::explode_url($file);
     }
     if (!in_array($this->protocol, $this->allowedProtocols)) {
         throw new Exception("Permission denied on {$file}. The communication protocol is not supported.");
     }
     if (!$this->options->isRemoteEnabled() && ($this->protocol != "" && $this->protocol !== "file://")) {
         throw new Exception("Remote file requested, but remote file download is disabled.");
     }
     if ($this->protocol == "" || $this->protocol === "file://") {
         // Get the full path to $file, returns false if the file doesn't exist
         $realfile = realpath($file);
         $chroot = $this->options->getChroot();
         if (strpos($realfile, $chroot) !== 0) {
             throw new Exception("Permission denied on {$file}. The file could not be found under the directory specified by Options::chroot.");
         }
         $ext = pathinfo($realfile, PATHINFO_EXTENSION);
         if (!in_array($ext, $this->allowedLocalFileExtensions)) {
             throw new Exception("Permission denied on {$file}.");
         }
         if (!$realfile) {
             throw new Exception("File '{$file}' not found.");
         }
         $file = $realfile;
     }
     $contents = file_get_contents($file, null, $this->httpContext);
     $encoding = null;
     // See http://the-stickman.com/web-development/php/getting-http-response-headers-when-using-file_get_contents/
     if (isset($http_response_header)) {
         foreach ($http_response_header as $_header) {
             if (preg_match("@Content-Type:\\s*[\\w/]+;\\s*?charset=([^\\s]+)@i", $_header, $matches)) {
                 $encoding = strtoupper($matches[1]);
                 break;
             }
         }
     }
     $this->restoreLocale();
     $this->loadHtml($contents, $encoding);
 }
コード例 #3
-1
 public function testSetters()
 {
     $option = new Options();
     $option->set(array('tempDir' => 'test1', 'fontDir' => 'test2', 'fontCache' => 'test3', 'chroot' => 'test4', 'logOutputFile' => 'test5', 'defaultMediaType' => 'test6', 'defaultPaperSize' => 'test7', 'defaultFont' => 'test8', 'dpi' => 300, 'fontHeightRatio' => 1.2, 'isPhpEnabled' => true, 'isRemoteEnabled' => true, 'isJavascriptEnabled' => false, 'isHtml5ParserEnabled' => true, 'isFontSubsettingEnabled' => true, 'debugPng' => true, 'debugKeepTemp' => true, 'debugCss' => true, 'debugLayout' => true, 'debugLayoutLines' => false, 'debugLayoutBlocks' => false, 'debugLayoutInline' => false, 'debugLayoutPaddingBox' => false, 'adminUsername' => 'test9', 'adminPassword' => 'test10'));
     $this->assertEquals('test1', $option->getTempDir());
     $this->assertEquals('test2', $option->getFontDir());
     $this->assertEquals('test3', $option->getFontCache());
     $this->assertEquals('test4', $option->getChroot());
     $this->assertEquals('test5', $option->getLogOutputFile());
     $this->assertEquals('test6', $option->getDefaultMediaType());
     $this->assertEquals('test7', $option->getDefaultPaperSize());
     $this->assertEquals('test8', $option->getDefaultFont());
     $this->assertEquals(300, $option->getDpi());
     $this->assertEquals(1.2, $option->getFontHeightRatio());
     $this->assertTrue($option->getIsPhpEnabled());
     $this->assertTrue($option->getIsRemoteEnabled());
     $this->assertFalse($option->getIsJavascriptEnabled());
     $this->assertTrue($option->getIsHtml5ParserEnabled());
     $this->assertTrue($option->getIsFontSubsettingEnabled());
     $this->assertTrue($option->getDebugPng());
     $this->assertTrue($option->getDebugKeepTemp());
     $this->assertTrue($option->getDebugCss());
     $this->assertTrue($option->getDebugLayout());
     $this->assertFalse($option->getDebugLayoutLines());
     $this->assertFalse($option->getDebugLayoutBlocks());
     $this->assertFalse($option->getDebugLayoutInline());
     $this->assertFalse($option->getDebugLayoutPaddingBox());
     $this->assertEquals('test9', $option->getAdminUsername());
     $this->assertEquals('test10', $option->getAdminPassword());
 }