public static function url($files) { $ident = self::ident($files); if (!\SYSTEM\CACHE\cache_css::get($ident)) { \LIB\lib_minify::php(); $minifier = new \MatthiasMullie\Minify\CSS(); foreach ($files as $f) { $minifier->add($f->SERVERPATH()); } \SYSTEM\CACHE\cache_css::put($ident, $minifier->minify()); } return './api.php?call=cache&id=' . self::CACHE_CSS . '&ident=' . $ident; }
require '../vendor/autoload.php'; // Initialize Slim (the router/micro framework used). $app = new \Slim\Slim(); // and define the engine used for the view @see http://twig.sensiolabs.org $app->view = new \Slim\Views\Twig(); $app->view->setTemplatesDirectory("../Mini/view"); /******************************************* THE CONFIGS *******************************************************/ // Configs for mode "development" (Slim's default), see the GitHub readme for details on setting the environment $app->configureMode('development', function () use($app) { // pre-application hook, performs stuff before real action happens @see http://docs.slimframework.com/#Hooks $app->hook('slim.before', function () use($app) { // SASS-to-CSS compiler @see https://github.com/panique/php-sass SassCompiler::run("scss/", "css/"); // CSS minifier @see https://github.com/matthiasmullie/minify $minifier = new MatthiasMullie\Minify\CSS('css/style.css'); $minifier->minify('css/style.css'); // JS minifier @see https://github.com/matthiasmullie/minify // DON'T overwrite your real .js files, always save into a different file //$minifier = new MatthiasMullie\Minify\JS('js/application.js'); //$minifier->minify('js/application.minified.js'); }); // Set the configs for development environment $app->config(array('debug' => true, 'database' => array('db_host' => 'localhost', 'db_port' => '', 'db_name' => 'scdm', 'db_user' => 'root', 'db_pass' => ''))); }); // Configs for mode "production" $app->configureMode('production', function () use($app) { // Set the configs for production environment $app->config(array('debug' => false, 'database' => array('db_host' => '', 'db_port' => '', 'db_name' => '', 'db_user' => '', 'db_pass' => ''))); }); /************************************* Load Organization Defaults ***********************************************/ $organization_defaults = array('address1' => '92 High St', 'address2' => null, 'city' => 'Winter Haven', 'state' => 'FL', 'zipcode' => '33880');
/** * Compressor libraries */ public function _compressor($language, $code = "") { $root = realpath(__DIR__); require_once $root . "/min-css.php"; require_once $root . "/jshrink.php"; require_once $root . "/html-compress.php"; if (mb_strlen($code, '8bit') > 500000) { return $code; } else { if ($language == "css") { /** * What kind of css stuff should it convert */ $minifier = new MatthiasMullie\Minify\CSS(); $minifier->add($code); return $minifier->minify(); } elseif ($language == "js") { return \JShrink\Minifier::minify($code); } elseif ($language == "html") { $html = new Tinyfier_HTML_Tool(); if ($this->curOptions['compress']["minInline"]) { return $html->process($code, array("compress_all" => true)); } else { return $html->process($code, array("compress_all" => false)); } } } }
/** * Minify CSS code. * * @param string $content * @return string minified CSS */ public static function css($content) { $error = 'unknown'; try { $minifier = new MatthiasMullie\Minify\CSS($content); return $minifier->minify(); } catch (Exception $e) { $error = $e->getMessage(); } $return = <<<EOD /* Error: {$error} */ /* Problem detected during CSS minimisation, please review the following code */ /* ========================================================================== */ EOD; return $return . $content; }
public function compress_css_action($full_path) { if (is_file($full_path)) { require_once 'Minify/Minify.php'; require_once 'Minify/CSS.php'; require_once 'Minify/Converter.php'; require_once 'Minify/Exception.php'; require_once 'Minify/JS.php'; file_put_contents($full_path . '.log', date('c') . " - COMPRESSING CSS\n", FILE_APPEND); $file_size_before = filesize($full_path); $minifier = new MatthiasMullie\Minify\CSS($full_path); $min_path = str_replace('.css', '.min.css', $full_path); $minifier->minify($min_path); $file_size_after = filesize($min_path); file_put_contents($full_path . '.log', date('c') . " - COMPRESSION COMPLETE - " . $this->human_filesize($file_size_before - $file_size_after) . " saved\n", FILE_APPEND); } }
/** * Minify and concatenate CSS * * @param string $group * * @return bool|string */ protected function pipelineCss($group = 'head') { // temporary list of assets to pipeline $temp_css = []; // clear no-pipeline assets lists $this->css_no_pipeline = []; // Compute uid based on assets and timestamp $uid = md5(json_encode($this->css) . $this->css_minify . $this->css_rewrite . $group); $file = $uid . '.css'; $inline_file = $uid . '-inline.css'; $relative_path = "{$this->base_url}{$this->assets_url}/{$file}"; // If inline files exist set them on object if (file_exists($this->assets_dir . $inline_file)) { $this->css_no_pipeline = json_decode(file_get_contents($this->assets_dir . $inline_file), true); } // If pipeline exist return it if (file_exists($this->assets_dir . $file)) { return $relative_path . $this->getTimestamp(); } // Remove any non-pipeline files foreach ($this->css as $id => $asset) { if ($asset['group'] == $group) { if (!$asset['pipeline'] || $asset['remote'] && $this->css_pipeline_include_externals === false) { $this->css_no_pipeline[$id] = $asset; } else { $temp_css[$id] = $asset; } } } //if nothing found get out of here! if (count($temp_css) == 0) { return false; } // Write non-pipeline files out if (!empty($this->css_no_pipeline)) { file_put_contents($this->assets_dir . $inline_file, json_encode($this->css_no_pipeline)); } $css_minify = $this->css_minify; // If this is a Windows server, and minify_windows is false (default value) skip the // minification process because it will cause Apache to die/crash due to insufficient // ThreadStackSize in httpd.conf - See: https://bugs.php.net/bug.php?id=47689 if (strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN' && !$this->css_minify_windows) { $css_minify = false; } // Concatenate files $buffer = $this->gatherLinks($temp_css, CSS_ASSET); if ($css_minify) { $minifier = new \MatthiasMullie\Minify\CSS(); $minifier->add($buffer); $buffer = $minifier->minify(); } // Write file if (strlen(trim($buffer)) > 0) { file_put_contents($this->assets_dir . $file, $buffer); return $relative_path . $this->getTimestamp(); } else { return false; } }
<?php require 'resources/minify/src/Minify.php'; require 'resources/minify/src/CSS.php'; require 'resources/minify/src/JS.php'; require 'resources/minify/src/Exception.php'; require 'resources/path-converter/src/Converter.php'; // var_dump(get_declared_classes()); $minifier = new MatthiasMullie\Minify\CSS('assets/css/all.css'); // we can even add another file, they'll then be // joined in 1 output file // $sourcePath2 = '/path/to/second/source/css/file.css'; $minifier->add("assets/css/team.css"); $minifier->add("assets/css/style.css"); $minifier->add("assets/css/eventsmain.css"); $minifier->add("assets/css/intro.css"); $minifier->add("assets/css/jquery-ui.structure.min.css"); $minifier->add("assets/css/jquery-ui.min.css"); $minifier->add("assets/css/jquery-ui.theme.min.css"); // or we can just add plain CSS // $css = 'body { color: #000000; }'; // $minifier->add($css); // save minified file to disk // $minifiedPath = '/path/to/minified/css/file.css'; // $minifier->minify($minifiedPath); header("Content-type: text/css"); echo $minifier->minify();
/** * Compress each languages * @param string $language The language of source code * @param string $code The source code * @return string Compressed code */ public static function _compressor($language, $code = "", $minInline) { /** * Skip if file size is > 500KB */ if (mb_strlen($code, '8bit') > 500000) { return $code; } else { if ($language == "css") { /** * What kind of css stuff should it convert */ $minifier = new MatthiasMullie\Minify\CSS(); $minifier->add($code); return $minifier->minify(); } else { if ($language == "js") { return JShrink\Minifier::minify($code); } else { if ($language == "html") { $html = new Tinyfier_HTML_Tool(); if ($minInline) { return $html->process($code, array("compress_all" => true)); } else { return $html->process($code, array("compress_all" => false)); } } } } } }