public function onAfterRenderPage(RenderEvent $event)
 {
     $id = $event->getId();
     if (in_array($id, $this->html_compress_exclude) || preg_match('/(.*)?\\.(jpe?g|png|gif|ico|svg|psd|tiff|webm|mov|avi|mkv|mp4)$/i', $id)) {
         return;
     }
     $this->io->write('Minify/Compress html: ' . $event->getId());
     $event->setContent(\WyriHaximus\HtmlCompress\Factory::construct()->compress($event->getContent()));
 }
예제 #2
0
    /**
     * General Error Page
     *
     * Takes an error message as input
     * and displays it using the specified template.
     *
     * @param string $message Error Message
     * @param int $code HTTP Header code
     *
     * @return void
     */
    public static function halt($message, $code = 404)
    {
        Response::getSoul()->setStatus($code);
        if (Config::getSoul()->APP_DEBUG == false) {
            $message = '404 Not Found.';
        }
        $tplPath = Config::getSoul()->ERROR_TPL;
        if ($tplPath == null || !Helper::isFile(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html')) {
            $tpl = '<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>Kotori.php 500 Internal Error</title>
  <meta name="robots" content="NONE,NOARCHIVE">
  <style type="text/css">
    html * { padding:0; margin:0; }
    body * { padding:10px 20px; }
    body * * { padding:0; }
    body { font:small sans-serif; background:#eee; }
    body>div { border-bottom:1px solid #ddd; }
    h1 { font-weight:normal; margin-bottom:.4em; }
    h1 span { font-size:60%; color:#666; font-weight:normal; }
    table { border:none; border-collapse: collapse; width:100%; }
    td, th { vertical-align:top; padding:2px 3px; }
    th { width:12em; text-align:right; color:#666; padding-right:.5em; }
    #info { background:#f6f6f6; }
    #info p {font-size: 16px}
    #summary { background: #ffc; }
    #explanation { background:#eee; border-bottom: 0px none; }
  </style>
</head>
<body>
  <div id="summary">
    <h1>Kotori.php Internal Error <span>(500)</span></h1>
    <table class="meta">
      <tr>
        <th>Request Method:</th>
        <td>' . strtoupper($_SERVER['REQUEST_METHOD']) . '</td>
      </tr>
      <tr>
        <th>Request URL:</th>
        <td>' . Request::getSoul()->getBaseUrl() . ltrim($_SERVER['REQUEST_URI'], '/') . '</td>
      </tr>

    </table>
  </div>
  <div id="info">
      ' . $message . '
  </div>

  <div id="explanation">
    <p>
      You\'re seeing this error because you have <code>APP_DEBUG = True</code> in
      your index.php file. Change that to <code>False</code>, and Kotori.php
      will display a standard 404 page.
    </p>
  </div>
</body>
</html>';
        } else {
            $tpl = file_get_contents(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html');
        }
        $tpl = str_replace('{$message}', $message, $tpl);
        $htmlParser = htmlParserFactory::construct();
        $tpl = $htmlParser->compress($tpl);
        exit($tpl);
    }
예제 #3
0
 public function afterFilter()
 {
     parent::afterFilter();
     // Output compression on all requests
     $parser = \WyriHaximus\HtmlCompress\Factory::construct();
     $compressedHtml = $parser->compress($this->response->body());
     //$this->response->compress();
     $this->response->body($compressedHtml);
 }
예제 #4
0
 /**
  * @param bool $forceCompression Default: false. Forces compression regardless of Twig's debug setting.
  */
 public function __construct($forceCompression = false)
 {
     $this->forceCompression = $forceCompression;
     $this->parser = Factory::constructSmallest();
     $this->callable = array($this, 'compress');
 }
 /**
  * CompressionHelper constructor.
  */
 public function __construct()
 {
     $this->parser = Factory::construct();
 }
 /**
  * @param SourceSetEvent $event
  */
 public function onAfterFormatSmallest(SourceSetEvent $event)
 {
     $parser = Factory::constructSmallest();
     $this->compress($parser, $event);
 }
예제 #7
0
<?php

use infrajs\event\Event;
use infrajs\view\View;
use infrajs\access\Access;
use WyriHaximus\HtmlCompress;
Event::one('Controller.onshow', function () {
    if (Access::debug()) {
        return;
    }
    $html = View::html();
    $parser = HtmlCompress\Factory::construct();
    $html = $parser->compress($html);
    View::html($html, true);
});