Ejemplo n.º 1
1
 /**
  * @throws \rmrevin\yii\minify\Exception
  */
 public function init()
 {
     parent::init();
     $minify_path = $this->minify_path = (string) \Yii::getAlias($this->minify_path);
     if (!file_exists($minify_path)) {
         helpers\FileHelper::createDirectory($minify_path);
     }
     if (!is_readable($minify_path)) {
         throw new Exception('Directory for compressed assets is not readable.');
     }
     if (!is_writable($minify_path)) {
         throw new Exception('Directory for compressed assets is not writable.');
     }
     if (true === $this->compress_output) {
         \Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function (\yii\base\Event $Event) {
             /** @var \yii\web\Response $Response */
             $Response = $Event->sender;
             if ($Response->format === \yii\web\Response::FORMAT_HTML) {
                 if (!empty($Response->data)) {
                     $Response->data = HtmlCompressor::compress($Response->data, $this->compress_options);
                 }
                 if (!empty($Response->content)) {
                     $Response->content = HtmlCompressor::compress($Response->content, $this->compress_options);
                 }
             }
         });
     }
 }
Ejemplo n.º 2
0
 public function bootstrap($app)
 {
     $time = time();
     $js = 'var autoTimer, autoInterval;
         window.onload       = resetTimer;
         window.onmousemove  = resetTimer;
         window.onmousedown  = resetTimer;
         window.onclick      = resetTimer;
         window.onscroll     = resetTimer;
         window.onkeypress   = resetTimer;
 
         function lockScreen() {
             setInterval(function () {
                 clearInterval(autoInterval);
                 if(typeof $.cookie(\'LockScreenSession\') == "undefined") {
                     window.location.href = \'' . Url::to(['/admin/user/user/lock-screen']) . '\'
                 }
             }, 3000);
         }
 
         function resetTimer() {
             clearTimeout(autoTimer);
             autoTimer = setTimeout(lockScreen, 1000 * 60 * 15);
 
         }';
     if (!\Yii::$app->user->isGuest) {
         \Yii::$app->getView()->registerJs(HtmlCompressor::compress($js, ['extra' => true]), View::POS_HEAD);
         \Yii::$app->getView()->registerJsFile(\Yii::getAlias('@web/application/media/js/jquery.cookie.js'), ['depends' => 'yii\\web\\JqueryAsset'], 'jquery.cookie.js');
         unset($_COOKIE["LockScreenSession"]);
         setcookie("LockScreenSession", $time, $time + 60 * 15, '/');
     }
 }
Ejemplo n.º 3
0
 /**
  * @throws \rmrevin\yii\minify\Exception
  */
 public function init()
 {
     parent::init();
     if (php_sapi_name() !== 'cli') {
         $urlDetails = \Yii::$app->urlManager->parseRequest(\Yii::$app->request);
         if (in_array($urlDetails[0], $this->exclude_routes)) {
             $this->enableMinify = false;
         }
     }
     $minify_path = $this->minify_path = (string) \Yii::getAlias($this->minify_path);
     if (!file_exists($minify_path)) {
         helpers\FileHelper::createDirectory($minify_path);
     }
     if (!is_readable($minify_path)) {
         throw new Exception('Directory for compressed assets is not readable.');
     }
     if (!is_writable($minify_path)) {
         throw new Exception('Directory for compressed assets is not writable.');
     }
     if (true === $this->compress_output) {
         \Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function (\yii\base\Event $Event) {
             /** @var \yii\web\Response $Response */
             $Response = $Event->sender;
             if ($Response->format === \yii\web\Response::FORMAT_HTML) {
                 if (!empty($Response->data)) {
                     $Response->data = HtmlCompressor::compress($Response->data, ['extra' => true]);
                 }
                 if (!empty($Response->content)) {
                     $Response->content = HtmlCompressor::compress($Response->content, ['extra' => true]);
                 }
             }
         });
     }
 }
    public function testMain()
    {
        $str = "<div class=\"                   test\"                  data>\n            <p>Inside text</p>\n            <!-- comment -->\n            <pre>    Inside pre\n    <span>test</span></pre>\n        </div>";
        $this->assertEquals("<div class=\" test\" data>\n<p>Inside text</p>\n<!-- comment -->\n<pre>    Inside pre\n    <span>test</span></pre>\n</div>", HtmlCompressor::compress($str));
        $this->assertEquals("<div class=\" test\" data>\n<p>Inside text</p>\n\n<pre>    Inside pre\n    <span>test</span></pre>\n</div>", HtmlCompressor::compress($str, ['no-comments' => true]));
        $this->assertEquals("<div class=\" test\" data><p>Inside text</p><!-- comment --><pre>    Inside pre\n    <span>test</span></pre></div>", HtmlCompressor::compress($str, ['extra' => true]));
        $this->assertEquals("<div class=\" test\" data><p>Inside text</p><pre>    Inside pre\n    <span>test</span></pre></div>", HtmlCompressor::compress($str, ['no-comments' => true, 'extra' => true]));
        $this->expectOutputString('Original Size: 195
Compressed Size: 115
Savings: 41.03%
');
        HtmlCompressor::compress($str, ['stats' => true]);
    }
Ejemplo n.º 5
0
            </div>
        </div>
    </td>
    <td>
        <input {{checked}} class="make-switch" data-size="small" type="radio" name="ContentArticles[main_image]" value="{{photo_id}}">
    </td>
    <td class="control vtop">
        <div class="btn-group" role="group">
            <a href="' . Url::to(['/admin/media/image/{{photo_id}}']) . '" class="change-image-button btn green" style="margin-right:0" title="' . Yii::t('admin', 'Change image') . '"><span class="fa fa-edit"></span></a>
            <a href="' . Url::to(['/admin/media/delete/{{photo_id}}?type=article']) . '" class="btn red" title="' . Yii::t('admin', 'Delete item') . '"><span class="fa fa-trash-o"></span></a>
            <input type="file" name="Medias[image]" class="change-image-input hidden">
        </div>
    </td>
</tr>
';
$photoTemplate = \rmrevin\yii\minify\HtmlCompressor::compress($photoTemplate, ['extra' => true]);
$this->registerJs("var photoTemplate = '{$photoTemplate}'", \yii\web\View::POS_HEAD);
/* @var $this yii\web\View */
/* @var $model app\modules\content\models\ContentArticles */
/* @var $form ActiveForm */
/* @var $lang \app\modules\system\models\Language */
// Language
if ($model->isNewRecord) {
    $langueBtn = ['label' => '<img src="' . $asset->baseUrl . '/images/flags/' . $lang->url . '.png" alt="' . $lang->url . '"/> ' . Yii::t('backend', 'Language'), 'options' => ['form' => 'portfolio-id', 'type' => 'submit'], 'encodeLabel' => false, 'icon' => false, 'size' => Button::SIZE_SMALL, 'disabled' => false, 'block' => false, 'type' => Button::TYPE_CIRCLE, 'color' => 'btn-default'];
} else {
    $allLang = Language::getLanguages();
    $langueBtnItems = [];
    foreach ($allLang as $item) {
        if ($lang->language_id != $item->language_id) {
            $langueBtnItems[] = ['label' => '<img src="' . $asset->baseUrl . '/images/flags/' . $item->url . '.png" alt="' . $item->url . '"/> ' . $item->name, 'url' => ['update', 'id' => $model->id, 'language' => $item->url]];
        }