Example #1
0
 function compose($o)
 {
     if ($this->debug || $this->get->src) {
         $o = parent::compose($o);
         $o->cookie_path = $CONFIG['session.cookie_path'];
         $o->cookie_domain = $CONFIG['session.cookie_domain'];
         $o->document_domain = $CONFIG['document.domain'];
         $o->maxage = $CONFIG['maxage'];
     } else {
         ++self::$recursion;
         $src = Patchwork\Superloader::class2file(substr(get_class($this), 6));
         $src = Patchwork\Serverside::returnAgent($src, (array) $this->get);
         --self::$recursion;
         $parser = new JSqueeze();
         if ('/*!' != substr(ltrim(substr($src, 0, 512)), 0, 3)) {
             $o->DATA = Patchwork::__URI__();
             $o->DATA .= (false === strpos($o->DATA, '?') ? '?' : '&') . 'src=1';
             $o->DATA = "// Copyright & source: {$o->DATA}\n";
             foreach (count_chars($o->DATA, 1) as $k => $w) {
                 $parser->charFreq[$k] += $w;
             }
             $o->DATA .= $parser->squeeze($src);
         } else {
             $o->DATA = $parser->squeeze($src);
         }
     }
     return $o;
 }
 /**
  */
 public function apply($in, $params = [])
 {
     require_php_lib('jsqueeze');
     !isset($params['single_line']) && ($params['single_line'] = true);
     !isset($params['keep_important_comments']) && ($params['keep_important_comments'] = true);
     !isset($params['special_var_rx']) && ($params['special_var_rx'] = \JSqueeze::SPECIAL_VAR_RX);
     $parser = new \JSqueeze();
     return $parser->squeeze($in, $params['single_line'], $params['keep_important_comments'], $params['special_var_rx']);
 }
Example #3
0
 public function filterDump(AssetInterface $asset)
 {
     $parser = new \JSqueeze();
     $asset->setContent($parser->squeeze($asset->getContent(), $this->singleLine, $this->keepImportantComments, $this->specialVarRx));
 }
Example #4
0
 public function handler($data)
 {
     global $post;
     $settings = get_post_meta($post->ID, '_cornerstone_settings', true);
     $update = array();
     if (isset($data['post_title'])) {
         $update['post_title'] = $data['post_title'];
     }
     if (isset($data['allow_comments'])) {
         $update['comment_status'] = $data['allow_comments'] == 'true' ? 'open' : 'closed';
     }
     if (current_user_can($this->manager->post_type_object->cap->publish_posts)) {
         $update['post_status'] = $data['post_status'];
     }
     if (post_type_supports($post->post_type, 'page-attributes')) {
         $page_templates = wp_get_theme()->get_page_templates($post);
         $update['page_template'] = 'default';
         if (isset($data['page_template']) && isset($page_templates[$data['page_template']])) {
             $update['page_template'] = $data['page_template'];
         }
         if (isset($data['post_parent'])) {
             $update['post_parent'] = (int) $data['post_parent'];
         }
     }
     if (isset($data['custom_css'])) {
         $settings['custom_css'] = $data['custom_css'];
     }
     // Update Custom JS
     if (isset($data['custom_js']) && current_user_can('unfiltered_html')) {
         $settings['custom_js'] = $data['custom_js'];
     }
     // Minify JS
     if (isset($settings['custom_js'])) {
         require CS()->path('includes/utility/jsqueeze.php');
         $jz = new JSqueeze();
         $minified = $jz->squeeze($settings['custom_js']);
         if ($minified == ';') {
             $minified = '';
         }
         $settings['custom_js_mini'] = $minified;
     }
     if (!empty($update)) {
         $update['ID'] = $post->ID;
         $result = wp_update_post($update, true);
         if (is_wp_error($result)) {
             return $result;
         }
     }
     update_post_meta($post->ID, '_cornerstone_settings', $settings);
 }
Example #5
0
 public function handler($atts)
 {
     extract($atts);
     global $post;
     $settings = get_post_meta($post->ID, '_cornerstone_settings', true);
     $post_type_object = get_post_type_object($post->post_type);
     $update = array();
     // Title
     $post_title = esc_html($post_title);
     if ($post_title != $post->post_title) {
         $update['post_title'] = $post_title;
     }
     // Comments
     $allow_comments = $allow_comments == 'true' ? 'open' : 'closed';
     if ($post->comment_status != $allow_comments) {
         $update['comment_status'] = $allow_comments;
     }
     // Publish
     if (current_user_can($post_type_object->cap->publish_posts)) {
         if ($post->post_status != $post_status) {
             $update['post_status'] = $post_status;
         }
     }
     // Page only
     if (post_type_supports($post->post_type, 'page-attributes')) {
         if (isset($page_template)) {
             $update['page_template'] = $page_template;
         }
         if (isset($post_parent)) {
             $update['post_parent'] = $post_parent;
         }
     }
     // Update Custom CSS
     if (isset($custom_css)) {
         $settings['custom_css'] = $custom_css;
     }
     // Update Custom JS
     if (isset($custom_js) && current_user_can('unfiltered_html')) {
         $settings['custom_js'] = $custom_js;
     }
     // If either are just the default message, ignore that code.
     if ($settings['custom_css'] == $this->defaultCSS) {
         $settings['custom_css'] = '';
     }
     if ($settings['custom_js'] == $this->defaultJS) {
         $settings['custom_js'] = '';
     }
     // Minify JS
     if ($settings['custom_js'] != '') {
         require CS()->path('includes/utility/jsqueeze.php');
         $jz = new JSqueeze();
         $minified = $jz->squeeze($custom_js);
         if ($minified == ';') {
             $minified = '';
         }
         $settings['custom_js_mini'] = $minified;
     }
     update_post_meta($post->ID, '_cornerstone_settings', $settings);
     if (!empty($update)) {
         $update['ID'] = $post->ID;
         wp_update_post($update);
     }
 }
Example #6
0
 /**
  * Построить сводный сжатый файл типа ext из файлов files (массив имен файлов)
  * в папке dir
  * @param $dir
  * @param $files
  * @param $ext
  */
 private function rebuild_js($dir, $files, $ext)
 {
     $compfile = $this->get_full_md5fn($dir, $files, $ext);
     if (file_exists($compfile)) {
         unlink($compfile);
     }
     $JSqueeze = new JSqueeze();
     $fout = fopen($compfile, "w+");
     foreach ($files as $file) {
         if (substr($file, -(strlen($ext) + 1)) != '.' . $ext) {
             $file .= '.' . $ext;
         }
         $ff = fopen($dir . $file, "r");
         $buf = fread($ff, filesize($dir . $file));
         /* удалить комментарии и пробелы*/
         //$buf = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buf);
         //$buf = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buf);
         $buf = $JSqueeze->squeeze($buf, true, false);
         fwrite($fout, $buf . ' ');
     }
     fclose($fout);
 }
<!DOCTYPE html>
<html>
 <head>
  <title>Minify JS code</title>
 </head>
 <body>
  <div id="content">
   <h1>Minify JavaScript</h1>
   <p>Paste your JavaScript code in the textbox and click <b>Minify</b></p>
   <form method="POST">
    <textarea name="code" style="width:400px;height:200px;"></textarea><br/>
    <button style="padding:5px 30px;font-size:20px;">Minify</button>
   </form>
   <?php 
require_once "min-js.php";
$jSqueeze = new JSqueeze();
echo "<h2>Output</h2>";
$input = "lala";
$code = $jSqueeze->squeeze($input, true, false);
if ($code != $input) {
    echo '<textarea name="code" style="width:400px;height:200px;">' . $code . '</textarea>';
} else {
    echo 'There was no need to be minified';
}
?>
  </div>
  <!-- http://subinsb.com/php-minify-js-code -->
 </body>
</html>
Example #8
0
 /**
  * Minifies and returns text.
  *
  * @return string|bool
  */
 protected function getMinifiedText()
 {
     switch ($this->type) {
         case 'css':
             return \CssMin::minify($this->text);
             break;
         case 'js':
             $jsqueeze = new \JSqueeze();
             return $jsqueeze->squeeze($this->text);
             break;
     }
     return false;
 }
Example #9
0
 /**
  * Create symlinks for site modules.
  *
  * @param string $mode Mode.
  * @param string $globPattern File selection pattern.
  * @param string $dir Directory where symlinks will be created.
  *
  * @throws Exception 'Не удалось создать символическую ссылку'
  */
 private function linkSite($mode, $globPattern, $dir)
 {
     $JSMin = new JSqueeze();
     $fileList = glob($globPattern);
     if (!empty($fileList)) {
         foreach ($fileList as $fo) {
             $fo_stripped = str_replace(SITE_DIR, '', $fo);
             list(, , $module) = explode(DIRECTORY_SEPARATOR, $fo_stripped);
             $new_dir = implode(DIRECTORY_SEPARATOR, array($dir, $module));
             if (!file_exists($new_dir)) {
                 mkdir($new_dir);
             }
             $srcFile = $fo;
             $linkPath = implode(DIRECTORY_SEPARATOR, array($dir, $module, basename($fo_stripped)));
             switch ($mode) {
                 case self::MODE_SYMLINK:
                     $this->text('Создаем симлинк ', $srcFile, ' --> ', $linkPath);
                     if (!@symlink($srcFile, $linkPath)) {
                         throw new \Exception('Не удалось создать символическую ссылку с ' . $srcFile . ' на ' . $linkPath);
                     }
                     break;
                 case self::MODE_COPY:
                     $pi = pathinfo($srcFile);
                     if (isset($pi['extension']) && $pi['extension'] == 'js') {
                         $this->text('Минифицируем и копируем ', $srcFile, ' --> ', $linkPath);
                         file_put_contents($linkPath, $JSMin->squeeze(file_get_contents($srcFile), true, false, false));
                     } else {
                         $this->text('Создаем символическую ссылку ', $srcFile, ' --> ', $linkPath);
                         if (!@symlink($srcFile, $linkPath)) {
                             throw new \Exception('Не удалось создать символическую ссылку с ' . $srcFile . ' на ' . $linkPath);
                         }
                     }
                     break;
             }
         }
     }
 }
$all_css = $css1 . $css2 . $css3 . $css4 . $css5 . $css6 . $css8;
$all_css_minified = compress($all_css);
// echo($all_css_minified);
$myfile = fopen("public/allCSS.css", "w") or die("Unable to open file!");
fwrite($myfile, $all_css_minified);
// JS
$js1 = file_get_contents("assets/jquery/jquery.min.js");
$js2 = file_get_contents("public/js/snack.js");
$js3 = file_get_contents("assets/jquery-ui/jquery-ui.min.js");
$js4 = file_get_contents("assets/bootstrap/js/bootstrap.min.js");
$js5 = file_get_contents("assets/bootstrap-material/js/ripples.min.js");
$js6 = file_get_contents("assets/bootstrap-material/js/material.min.js");
/*$js4 = " ";
$js5 = " ";
$js6 = " ";*/
$semicolon = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
$all_js = $js1 . $semicolon . $js2 . $semicolon . $js3 . $semicolon . $js4 . $semicolon . $js5 . $semicolon . $js6;
require_once "min-js.php";
$jSqueeze = new JSqueeze();
$all_js_minified = $jSqueeze->squeeze($all_js, true, false);
$myfile = fopen("public/allJS.min.js", "w") or die("Unable to open file!");
fwrite($myfile, $all_js);
?>



<script>
<?php 
echo $all_js;
?>
</script>