本文整理汇总了PHP中Minify::setDocRoot方法的典型用法代码示例。如果您正苦于以下问题:PHP Minify::setDocRoot方法的具体用法?PHP Minify::setDocRoot怎么用?PHP Minify::setDocRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Minify
的用法示例。
在下文中一共展示了Minify::setDocRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLastModified
/**
* Get last modified
*
* @return string
*/
public function getLastModified()
{
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// we may be on IIS
}
return $this->lastModified;
}
示例2: action_minify
public function action_minify()
{
// load config
$config = Kohana::config('minify');
//require MINIFY_MIN_DIR.'/Minify.php';
Minify::$uploaderHoursBehind = $config['uploaderHoursBehind'];
Minify::setCache(isset($config['cachePath']) ? $config['cachePath'] : '', $config['cacheFileLocking']);
if ($config['documentRoot']) {
$_SERVER['DOCUMENT_ROOT'] = $config['documentRoot'];
} elseif (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
$config['serveOptions']['minifierOptions']['text/css']['symlinks'] = $config['symlinks'];
// auto-add targets to allowDirs
foreach ($config['symlinks'] as $uri => $target) {
$config['serveOptions']['minApp']['allowDirs'][] = $target;
}
if ($config['allowDebugFlag']) {
if (!empty($_COOKIE['minDebug'])) {
foreach (preg_split('/\\s+/', $_COOKIE['minDebug']) as $debugUri) {
if (false !== strpos($_SERVER['REQUEST_URI'], $debugUri)) {
$config['serveOptions']['debug'] = true;
break;
}
}
}
// allow GET to override
if (isset($_GET['debug'])) {
$config['serveOptions']['debug'] = true;
}
}
if ($config['errorLogger']) {
//require _once MINIFY_MIN_DIR . '/Minify/Logger.php';
if (true === $config['errorLogger']) {
//require _once MINIFY_MIN_DIR . '/FirePHP.php';
Minify_Logger::setLogger(FirePHP::getInstance(true));
} else {
Minify_Logger::setLogger($config['errorLogger']);
}
}
// check for URI versioning
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
$config['serveOptions']['maxAge'] = 31536000;
}
if (isset($_GET['g'])) {
// well need groups config
$config['serveOptions']['minApp']['groups'] = $config['groupsConfig'];
}
if (isset($_GET['f']) || isset($_GET['g'])) {
// serve!
Minify::serve('MinApp', $config['serveOptions']);
exit;
}
}
示例3: process
/**
* Runs minify
*/
function process()
{
require_once W3TC_LIB_MINIFY_DIR . '/Minify.php';
require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
HTTP_Encoder::$encodeToIe6 = $this->_config->get_boolean('minify.comprss.ie6');
Minify::$uploaderHoursBehind = $this->_config->get_integer('minify.fixtime');
Minify::setCache($this->_get_cache());
$serve_options = $this->_config->get_array('minify.options');
$serve_options['maxAge'] = $this->_config->get_integer('minify.maxage');
$serve_options['encodeOutput'] = $this->_config->get_boolean('minify.compress');
$serve_options['postprocessor'] = array(&$this, 'postprocessor');
if (stripos(PHP_OS, 'win') === 0) {
Minify::setDocRoot();
}
foreach ($this->_config->get_array('minify.symlinks') as $link => $target) {
$link = str_replace('//', realpath($_SERVER['DOCUMENT_ROOT']), $link);
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
$serve_options['minifierOptions']['text/css']['symlinks'][$link] = realpath($target);
}
if ($this->_config->get_boolean('minify.debug')) {
$serve_options['debug'] = true;
}
if ($this->_config->get('minify.debug')) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/Logger.php';
Minify_Logger::setLogger($this);
}
if (isset($_GET['f']) || isset($_GET['gg']) && isset($_GET['g']) && isset($_GET['t'])) {
if (isset($_GET['gg']) && isset($_GET['g']) && isset($_GET['t'])) {
$serve_options['minApp']['groups'] = $this->get_groups($_GET['gg'], $_GET['t']);
if ($_GET['t'] == 'js' && (in_array($_GET['g'], array('include', 'include-nb')) && $this->_config->get_boolean('minify.js.combine.header') || in_array($_GET['g'], array('include-footer', 'include-footer-nb')) && $this->_config->get_boolean('minify.js.combine.footer'))) {
$serve_options['minifiers']['application/x-javascript'] = array($this, 'minify_stub');
}
/**
* Setup user-friendly cache ID for disk cache
*/
if ($this->_config->get_string('minify.engine') == 'file') {
$cacheId = sprintf('%s.%s.%s', $_GET['gg'], $_GET['g'], $_GET['t']);
Minify::setCacheId($cacheId);
}
}
@header('Pragma: public');
try {
Minify::serve('MinApp', $serve_options);
} catch (Exception $exception) {
printf('<strong>W3 Total Cache Error:</strong> Minify error: %s', $exception->getMessage());
}
} else {
die('This file cannot be accessed directly');
}
}
示例4: minify
function minify($files)
{
global $CFG;
$cachedir = $CFG->cachedir . '/js';
// make sure the cache dir exist
if (!file_exists($cachedir)) {
@mkdir($cachedir, $CFG->directorypermissions, true);
}
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
Minify::setCache($cachedir, true);
$options = array('maxAge' => 60 * 60 * 24 * 20, 'files' => $files);
Minify::serve('Files', $options);
die;
}
示例5: minify
function minify($files)
{
global $CFG;
$cachedir = $CFG->cachedir . '/js';
// make sure the cache dir exist
if (!file_exists($cachedir)) {
@mkdir($cachedir, $CFG->directorypermissions, true);
}
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
Minify::setCache($cachedir, true);
$options = array('maxAge' => 60 * 60 * 24 * 20, 'files' => $files);
try {
Minify::serve('Files', $options);
die;
} catch (Exception $e) {
$error = $e->getMessage();
$error = str_replace("\r", ' ', $error);
$error = str_replace("\n", ' ', $error);
}
// minification failed - try to inform the developer and include the non-minified version
$js = <<<EOD
try {console.log('Error: Minimisation of javascript failed!');} catch (e) {}
// Error: {$error}
// Problem detected during javascript minimisation, please review the following code
// =================================================================================
EOD;
echo $js;
foreach ($files as $jsfile) {
echo file_get_contents($jsfile) . "\n";
}
}
示例6: css_minify_css
/**
* Uses the minify library to compress CSS.
*
* This is used if $CFG->enablecssoptimiser has been turned off. This was
* the original CSS optimisation library.
* It removes whitespace and shrinks things but does no apparent optimisation.
* Note the minify library is still being used for JavaScript.
*
* @param array $files An array of files to minify
* @return string The minified CSS
*/
function css_minify_css($files)
{
global $CFG;
if (empty($files)) {
return '';
}
set_include_path($CFG->libdir . '/minify/lib' . PATH_SEPARATOR . get_include_path());
require_once 'Minify.php';
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
// disable all caching, we do it in moodle
Minify::setCache(null, false);
$options = array('bubbleCssImports' => false, 'encodeOutput' => false, 'maxAge' => 60 * 60 * 24 * 20, 'files' => $files, 'rewriteCssUris' => false, 'quiet' => true);
$error = 'unknown';
try {
$result = Minify::serve('Files', $options);
if ($result['success']) {
return $result['content'];
}
} catch (Exception $e) {
$error = $e->getMessage();
$error = str_replace("\r", ' ', $error);
$error = str_replace("\n", ' ', $error);
}
// minification failed - try to inform the theme developer and include the non-minified version
$css = <<<EOD
/* Error: {$error} */
/* Problem detected during theme CSS minimisation, please review the following code */
/* ================================================================================ */
EOD;
foreach ($files as $cssfile) {
$css .= file_get_contents($cssfile) . "\n";
}
return $css;
}
示例7: minify
function minify($files)
{
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
// disable all caching, we do it in moodle
Minify::setCache(null, false);
$options = array('bubbleCssImports' => false, 'encodeOutput' => false, 'maxAge' => 60 * 60 * 24 * 20, 'files' => $files, 'rewriteCssUris' => false, 'quiet' => true);
$result = Minify::serve('Files', $options);
return $result['content'];
}
示例8: css_minify_css
/**
* Uses the minify library to compress CSS.
*
* This is used if $CFG->enablecssoptimiser has been turned off. This was
* the original CSS optimisation library.
* It removes whitespace and shrinks things but does no apparent optimisation.
* Note the minify library is still being used for JavaScript.
*
* @param array $files An array of files to minify
* @return string The minified CSS
*/
function css_minify_css($files)
{
global $CFG;
if (empty($files)) {
return '';
}
// We do not really want any 304 here!
// There does not seem to be any better way to prevent them here.
unset($_SERVER['HTTP_IF_NONE_MATCH']);
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
set_include_path($CFG->libdir . '/minify/lib' . PATH_SEPARATOR . get_include_path());
require_once 'Minify.php';
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
// disable all caching, we do it in moodle
Minify::setCache(null, false);
$options = array('minifiers' => array(Minify::TYPE_JS => array('JSMinPlus', 'minify')), 'bubbleCssImports' => false, 'encodeOutput' => false, 'maxAge' => 60 * 60 * 24 * 20, 'files' => $files, 'rewriteCssUris' => false, 'quiet' => true);
$error = 'unknown';
try {
$result = Minify::serve('Files', $options);
if ($result['success'] and $result['statusCode'] == 200) {
return $result['content'];
}
} catch (Exception $e) {
$error = $e->getMessage();
$error = str_replace("\r", ' ', $error);
$error = str_replace("\n", ' ', $error);
}
// minification failed - try to inform the theme developer and include the non-minified version
$css = <<<EOD
/* Error: {$error} */
/* Problem detected during theme CSS minimisation, please review the following code */
/* ================================================================================ */
EOD;
foreach ($files as $cssfile) {
$css .= file_get_contents($cssfile) . "\n";
}
return $css;
}
示例9: action_template_header
public function action_template_header()
{
//Cache::expire( self::$cache_name . '_js' );
//Cache::expire( self::$cache_name . '_css' );
// try to disable output_compression (may not have an effect)
ini_set('zlib.output_compression', '0');
$modified_js = Stack::get_sorted_stack('template_header_javascript');
foreach ($modified_js as $key => $value) {
Stack::remove('template_header_javascript', $key);
}
Stack::add('template_header_javascript', Site::get_url('user') . '/files/minified.js', 'Minified');
$modified_css = Stack::get_sorted_stack('template_stylesheet');
$css = array();
foreach ($modified_css as $key => $value) {
$css[] = $value[0];
Stack::remove('template_stylesheet', $key);
}
Stack::add('template_stylesheet', array(Site::get_url('user') . "/files/minified.css", 'screen'), 'style');
/*
* If we have the files or the cache havent expired don't create new files.
*/
if (!file_exists(site::get_dir('user') . '/files/minified.css') || !file_exists(site::get_dir('user') . '/files/minified.js') || (!Cache::has(self::$cache_name . '_js') || !Cache::has(self::$cache_name . '_css'))) {
/* Taken from min/index.php */
define('MINIFY_MIN_DIR', dirname(__FILE__) . '/min/');
// load config
require MINIFY_MIN_DIR . '/config.php';
// setup include path
set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());
require 'Minify.php';
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
Minify::setCache(isset($min_cachePath) ? $min_cachePath : '', $min_cacheFileLocking);
if ($min_documentRoot) {
$_SERVER['DOCUMENT_ROOT'] = $min_documentRoot;
} elseif (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
// Using jsmin+ 1.3
$min_serveOptions['minifiers']['application/x-javascript'] = array('JSMinPlus', 'minify');
/* Javascript */
if (!Cache::has(self::$cache_name . '_js') || !file_exists(site::get_dir('user') . '/files/minified.js')) {
$js_stack = array();
foreach ($modified_js as $js) {
$js_stack[] = Site::get_path('base') . str_replace(Site::get_url('habari') . '/', '', $js);
}
$options = array('files' => $js_stack, 'encodeOutput' => false, 'quiet' => true);
$result = Minify::serve('Files', $options);
file_put_contents(site::get_dir('user') . '/files/minified.js', $result['content']);
Cache::set(self::$cache_name . '_js', 'true', Options::get('minification__expire'));
}
/* CSS */
if (!Cache::has(self::$cache_name . '_css') || !file_exists(site::get_dir('user') . '/files/minified.css')) {
$css_stack = array();
foreach ($css as $file) {
$css_stack[] = Site::get_path('base') . str_replace(Site::get_url('habari') . '/', '', $file);
}
$options = array('files' => $css_stack, 'encodeOutput' => false, 'quiet' => true);
// handle request
$result = Minify::serve('Files', $options);
file_put_contents(site::get_dir('user') . '/files/minified.css', $result['content']);
Cache::set(self::$cache_name . '_css', 'true', Options::get('minification__expire'));
}
}
}
示例10: set_include_path
// setup include path
set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());
require 'Minify.php';
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
Minify::setCache(
isset($min_cachePath) ? $min_cachePath : ''
,$min_cacheFileLocking
);
if ($min_documentRoot) {
$_SERVER['DOCUMENT_ROOT'] = $min_documentRoot;
} elseif (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot(); // IIS may need help
}
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
if ($min_allowDebugFlag && isset($_GET['debug'])) {
$min_serveOptions['debug'] = true;
}
if ($min_errorLogger) {
require_once 'Minify/Logger.php';
if (true === $min_errorLogger) {
require_once 'FirePHP.php';
Minify_Logger::setLogger(FirePHP::getInstance(true));
} else {
Minify_Logger::setLogger($min_errorLogger);
示例11: minify
function minify($files)
{
global $CFG;
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
Minify::setCache('', true);
$options = array('bubbleCssImports' => false, 'encodeOutput' => false, 'maxAge' => 1800, 'files' => $files, 'rewriteCssUris' => false, 'quiet' => true);
$result = Minify::serve('Files', $options);
return $result['content'];
}
示例12: ob_get_clean
var src = location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
src = "../?f=" + src;
document.write('<\script type="text/javascript" src="' + src + '"><\/script>');
$(function () {
$('#builderScriptSrc')[0].href = src;
});
</script>
</body>
</html>
<?php
$content = ob_get_clean();
// setup Minify
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot(); // we may be on IIS
}
Minify::setCache(
isset($min_cachePath) ? $min_cachePath : ''
,$min_cacheFileLocking
);
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
Minify::serve('Page', array(
'content' => $content
,'id' => __FILE__
,'lastModifiedTime' => max(
// regenerate cache if any of these change
filemtime(__FILE__)
,filemtime(dirname(__FILE__) . '/../config.php')
,filemtime(dirname(__FILE__) . '/../lib/Minify.php')
示例13: runServe
public function runServe(TBGRequest $request)
{
if (!TBGContext::isMinifyEnabled()) {
$itemarray = array($request['g'] => explode(',', base64_decode($request['files'])));
if (array_key_exists('js', $itemarray)) {
header('Content-type: text/javascript');
foreach ($itemarray['js'] as $file) {
$ext = substr($file, -2);
if ($ext == 'js' && file_exists($file) && strpos(realpath($file), THEBUGGENIE_PATH) !== false) {
echo file_get_contents($file);
}
}
} else {
header('Content-type: text/css');
foreach ($itemarray['css'] as $file) {
$ext = substr($file, -3);
if ($ext == 'css' && file_exists($file) && strpos(realpath($file), THEBUGGENIE_PATH) !== false) {
echo file_get_contents($file);
}
}
}
exit;
}
$this->getResponse()->setDecoration(TBGResponse::DECORATE_NONE);
define('MINIFY_MIN_DIR', dirname(__FILE__) . '/../../../core/min');
// load config
require MINIFY_MIN_DIR . '/config.php';
// setup include path
set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());
require 'Minify.php';
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
Minify::setCache(isset($min_cachePath) ? $min_cachePath : '', $min_cacheFileLocking);
if ($min_documentRoot) {
$_SERVER['DOCUMENT_ROOT'] = $min_documentRoot;
} elseif (0 === mb_stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
if ($min_allowDebugFlag && isset($_GET['debug'])) {
$min_serveOptions['debug'] = true;
}
if ($min_errorLogger) {
require_once 'Minify/Logger.php';
if (true === $min_errorLogger) {
require_once 'FirePHP.php';
Minify_Logger::setLogger(FirePHP::getInstance(true));
} else {
Minify_Logger::setLogger($min_errorLogger);
}
}
// check for URI versioning
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
$min_serveOptions['maxAge'] = 31536000;
}
$itemarray = array($request['g'] => explode(',', base64_decode($request['files'])));
$min_serveOptions['minApp']['groups'] = $itemarray;
ob_end_clean();
$data = Minify::serve('MinApp', $min_serveOptions);
header_remove('Pragma');
foreach ($data['headers'] as $name => $val) {
header($name . ': ' . $val);
}
header('HTTP/1.1 ' . $data['statusCode']);
if ($data['statusCode'] != 304) {
echo $data['content'];
}
exit;
}
示例14: js_minify
/**
* Minify javascript files
* @param array $files
* @return string
*/
function js_minify($files)
{
// setup include path
set_include_path(__DIR__ . '/minify/lib' . PATH_SEPARATOR . get_include_path());
require_once 'Minify.php';
if (empty($files)) {
return '';
}
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
// disable all caching, we do it in moodle
Minify::setCache(null, false);
$options = array('minifiers' => array(Minify::TYPE_JS => array('JSMinPlus', 'minify')), 'bubbleCssImports' => false, 'encodeOutput' => false, 'maxAge' => 1800, 'files' => $files, 'rewriteCssUris' => false, 'quiet' => true);
$error = 'unknown';
try {
$result = Minify::serve('Files', $options);
if ($result['success']) {
return $result['content'];
}
} catch (Exception $e) {
$error = $e->getMessage();
$error = str_replace("\r", ' ', $error);
$error = str_replace("\n", ' ', $error);
}
// minification failed - try to inform the theme developer and include the non-minified version
$js = <<<EOD
try {console.log('Error: Minimisation of javascript failed!');} catch (e) {}
// Error: {$error}
// Problem detected during javascript minimisation, please review the following code
// =================================================================================
EOD;
foreach ($files as $jsfile) {
$js .= file_get_contents($jsfile) . "\n";
}
return $js;
}
示例15: if
msg += 'The option "zlib.output_compression" is disabled in your PHP configuration '
+ 'so this behavior is likely due to a server option.';
$(document.body).prepend(msg + '<\/p>');
} else if (ocStatus == '1')
$(document.body).prepend('<\p class=topNote><\strong>Note:</\strong> The option '
+ '"zlib.output_compression" is enabled in your PHP configuration, but has been '
+ 'successfully disabled via ini_set(). If you experience mangled output you '
+ 'may want to consider disabling this option in your PHP configuration.<\/p>'
);
});
});
});
</script>
<script type="text/javascript">
// workaround required to test when /min isn't child of web root
var src = location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
document.write('<\script type="text/javascript" src="../?f=' + src + '"><\/script>');
</script>
<?php
$serveOpts = array('content' => ob_get_contents(), 'id' => __FILE__, 'lastModifiedTime' => max(filemtime(__FILE__), filemtime(dirname(__FILE__) . '/../config.php')), 'minifyAll' => true, 'encodeOutput' => $encodeOutput);
ob_end_clean();
set_include_path(dirname(__FILE__) . '/../lib' . PATH_SEPARATOR . get_include_path());
require 'Minify.php';
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// we may be on IIS
}
Minify::setCache(isset($min_cachePath) ? $min_cachePath : null);
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
Minify::serve('Page', $serveOpts);