Skip to content

Commit

Permalink
Merge branch '4.0-dev' into fix#23850
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Mar 18, 2019
2 parents b9c0065 + a7a1b62 commit 2cf1a9f
Show file tree
Hide file tree
Showing 19 changed files with 548 additions and 139 deletions.
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Layout\LayoutHelper;

$published = $this->state->get('filter.published');
$noUser = true;
?>
<div class="modal hide fade" id="collapseModal">
<div class="modal-header">
Expand Down Expand Up @@ -49,7 +50,7 @@
<div class="row">
<div class="control-group">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.user', []); ?>
<?php echo LayoutHelper::render('joomla.html.batch.user', ['noUser' => $noUser]); ?>
</div>
</div>
</div>
Expand Down
Expand Up @@ -11,6 +11,7 @@
use Joomla\CMS\Layout\LayoutHelper;

$published = $this->state->get('filter.published');
$noUser = true;
?>

<div class="container">
Expand Down Expand Up @@ -41,7 +42,7 @@
</div>
<div class="form-group col-md-6">
<div class="controls">
<?php echo LayoutHelper::render('joomla.html.batch.user', []); ?>
<?php echo LayoutHelper::render('joomla.html.batch.user', ['noUser' => $noUser]); ?>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions build.js
Expand Up @@ -23,7 +23,7 @@ const init = require('./build/build-modules-js/init.es6.js');
const compileCSS = require('./build/build-modules-js/compilecss.es6.js');
const compileJS = require('./build/build-modules-js/compilejs.es6.js');
const minifyVendor = require('./build/build-modules-js/javascript/minify-vendor.es6.js');
const watch = require('./build/build-modules-js/watch.es6.js')
const watch = require('./build/build-modules-js/watch.es6.js');

// The settings
const options = require('./package.json');
Expand Down Expand Up @@ -101,4 +101,4 @@ if (Program.compileJs) {
// Compress/transpile the javascript files
if (Program.watch) {
watch.run();
}
}
117 changes: 117 additions & 0 deletions build/build-modules-js/gzip-assets.es6.js
@@ -0,0 +1,117 @@
/**
* For creating Brotli files you need to install iltorb
* and import it like:
* const { compressStream } = require('iltorb');
*/
const Fs = require('fs');
const { gzip } = require('@gfx/zopfli');
const RootPath = require('./utils/rootpath.es6.js')._();
const WalkSync = require('./utils/walk-sync.es6.js');

const compressStream = '';
const options = {
verbose: false,
verbose_more: false,
numiterations: 15,
blocksplitting: true,
blocksplittingmax: 15,
};

/**
* Method that will create a gzipped vestion of the given file
*
* @param { string } file The path of the file
*
* @returns { void }
*/
const handleFile = (file, enableBrotli) => {
if (file.match('/images') || file.match('\\images')) {
return;
}


if (file.match(/\.min\.js/) && !file.match(/\.min\.js\.gz/) && !file.match(/\.min\.js\.br/) && !file.toLowerCase().match(/json/) && !file.toLowerCase().match(/license/)) {
// eslint-disable-next-line no-console
console.log(`Processing: ${file}`);

if (enableBrotli && compressStream) {
// Brotli file
Fs.createReadStream(file)
.pipe(compressStream())
.pipe(Fs.createWriteStream(file.replace(/\.js$/, '.js.br')));
} else {
// Gzip the file
Fs.readFile(file, (err, data) => {
if (err) throw err;
gzip(data, options, (error, output) => {
if (error) throw err;
// Save the gzipped file
Fs.writeFileSync(
file.replace(/\.js$/, '.js.gz'),
output,
{ encoding: 'utf8' },
);
});
});
}
}

if (file.match(/\.min\.css/) && !file.match(/\.min\.css\.gz/) && !file.match(/\.min\.css\.br/) && !file.match(/\.css\.map/) && !file.toLowerCase().match(/license/)) {
// eslint-disable-next-line no-console
console.log(`Processing: ${file}`);

if (enableBrotli && compressStream) {
// Brotli file
Fs.createReadStream(file)
.pipe(compressStream())
.pipe(Fs.createWriteStream(file.replace(/\.css$/, '.css.br')));
} else {
// Gzip the file
Fs.readFile(file, (err, data) => {
if (err) throw err;
gzip(data, options, (error, output) => {
if (error) throw err;
// Save the gzipped file
Fs.writeFileSync(
file.replace(/\.css$/, '.css.gz'),
output,
{ encoding: 'utf8' },
);
});
});
}
}
};

/**
* Method to gzip the script and stylesheet files
*
* @param brotliParam {string} The CLI argument
*
* @returns { void }
*/
const gzipFiles = (brotliParam) => {
let enableBrotli = false;
if (brotliParam === 'brotli') {
enableBrotli = true;
}
// Minify the legacy files
// eslint-disable-next-line no-console
console.log('Gziping stylesheets and scripts...');

const templatesFiles = WalkSync.run(`${RootPath}/templates`, []);
const adminTemplatesFiles = WalkSync.run(`${RootPath}/administrator/templates`, []);
const mediaFiles = WalkSync.run(`${RootPath}/media`, []);

if (templatesFiles.length) {
templatesFiles.forEach(file => handleFile(file, enableBrotli));
}
if (adminTemplatesFiles.length) {
adminTemplatesFiles.forEach(file => handleFile(file, enableBrotli));
}
if (mediaFiles.length) {
mediaFiles.forEach(file => handleFile(file, enableBrotli));
}
};

module.exports.gzipFiles = gzipFiles;
9 changes: 9 additions & 0 deletions build/build.php
Expand Up @@ -212,6 +212,15 @@ function clean_composer(string $dir)
exit(1);
}

// Create gzipped version of the static assets
system('npm run gzip', $gzipReturnCode);

if ($gzipReturnCode !== 0)
{
echo "`npm run gzip` did not complete as expected.\n";
exit(1);
}

// Clean the checkout of extra resources
clean_checkout($fullpath);

Expand Down
Expand Up @@ -130,7 +130,7 @@ joomla-field-switcher {
span {
position: absolute;
top: 0;
color: $gray-600;
color: var(--dark);
visibility: hidden;
opacity: 0;
transition: all .2s ease-in-out;
Expand Down
32 changes: 32 additions & 0 deletions htaccess.txt
Expand Up @@ -90,3 +90,35 @@ Options -Indexes
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>

## These directives are only enabled if the mod_headers module is enabled
## This section will check if a .gz file exists and if so will stream it
## directly or fallback to gzip any asset on the fly
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist
# and the client accepts gzip.
RewriteCond "%{HTTP:Accept-encoding}" "gzip"
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.*)\.css" "$1\.css\.gz" [QSA]

# Serve gzip compressed JS files if they exist
# and the client accepts gzip.
RewriteCond "%{HTTP:Accept-encoding}" "gzip"
RewriteCond "%{REQUEST_FILENAME}\.gz" -s
RewriteRule "^(.*)\.js" "$1\.js\.gz" [QSA]


# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]


<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header append Content-Encoding gzip

# Force proxies to cache gzipped &
# non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
103 changes: 0 additions & 103 deletions installation/template/css/template.css.map

This file was deleted.

23 changes: 13 additions & 10 deletions libraries/src/Access/Access.php
Expand Up @@ -12,8 +12,11 @@

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\UserGroupsHelper;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Profiler\Profiler;
use Joomla\CMS\Table\Asset;
use Joomla\CMS\User\User;
use Joomla\Utilities\ArrayHelper;

/**
Expand Down Expand Up @@ -281,7 +284,7 @@ protected static function preloadPermissions($assetType, $reload = false)
return;
}

!JDEBUG ?: \JProfiler::getInstance('Application')->mark('Before Access::preloadPermissions (' . $extensionName . ')');
!JDEBUG ?: Profiler::getInstance('Application')->mark('Before Access::preloadPermissions (' . $extensionName . ')');

// Get the database connection object.
$db = Factory::getDbo();
Expand All @@ -308,7 +311,7 @@ protected static function preloadPermissions($assetType, $reload = false)
self::$preloadedAssetTypes[$assetType] = true;
self::$preloadedAssetTypes[$extensionName] = true;

!JDEBUG ?: \JProfiler::getInstance('Application')->mark('After Access::preloadPermissions (' . $extensionName . ')');
!JDEBUG ?: Profiler::getInstance('Application')->mark('After Access::preloadPermissions (' . $extensionName . ')');
}

/**
Expand All @@ -330,7 +333,7 @@ protected static function preloadComponents()
return array();
}

!JDEBUG ?: \JProfiler::getInstance('Application')->mark('Before Access::preloadComponents (all components)');
!JDEBUG ?: Profiler::getInstance('Application')->mark('Before Access::preloadComponents (all components)');

// Add root to asset names list.
$components = array('root.1');
Expand Down Expand Up @@ -387,7 +390,7 @@ protected static function preloadComponents()
// Mark all components asset type as preloaded.
self::$preloadedAssetTypes['components'] = true;

!JDEBUG ?: \JProfiler::getInstance('Application')->mark('After Access::preloadComponents (all components)');
!JDEBUG ?: Profiler::getInstance('Application')->mark('After Access::preloadComponents (all components)');

return $components;
}
Expand Down Expand Up @@ -426,7 +429,7 @@ public static function checkGroup($groupId, $action, $assetKey = null, $preload
protected static function getGroupPath($groupId)
{
// Load all the groups to improve performance on intensive groups checks
$groups = \JHelperUsergroups::getInstance()->getAll();
$groups = UserGroupsHelper::getInstance()->getAll();

if (!isset($groups[$groupId]))
{
Expand Down Expand Up @@ -502,7 +505,7 @@ public static function getAssetRules($assetKey, $recursive = false, $recursivePa
// Almost all calls can take advantage of preloading.
if ($assetId && isset(self::$preloadedAssets[$assetId]))
{
!JDEBUG ?: \JProfiler::getInstance('Application')->mark('Before Access::getAssetRules (id:' . $assetId . ' name:' . $assetName . ')');
!JDEBUG ?: Profiler::getInstance('Application')->mark('Before Access::getAssetRules (id:' . $assetId . ' name:' . $assetName . ')');

// Collects permissions for each asset
$collected = array();
Expand Down Expand Up @@ -564,15 +567,15 @@ public static function getAssetRules($assetKey, $recursive = false, $recursivePa
self::$assetRules[$assetId] = self::$assetRulesIdentities[$hash];
}

!JDEBUG ?: \JProfiler::getInstance('Application')->mark('After Access::getAssetRules (id:' . $assetId . ' name:' . $assetName . ')');
!JDEBUG ?: Profiler::getInstance('Application')->mark('After Access::getAssetRules (id:' . $assetId . ' name:' . $assetName . ')');

return self::$assetRulesIdentities[$hash];
}

// Non preloading code. Use old slower method, slower. Only used in rare cases (if any) or without preloading chosen.
Log::add('Asset ' . $assetKey . ' permissions fetch without preloading (slower method).', Log::INFO, 'assets');

!JDEBUG ?: \JProfiler::getInstance('Application')->mark('Before Access::getAssetRules (assetKey:' . $assetKey . ')');
!JDEBUG ?: Profiler::getInstance('Application')->mark('Before Access::getAssetRules (assetKey:' . $assetKey . ')');

// There's no need to process it with the recursive method for the Root Asset ID.
if ((int) $assetKey === 1)
Expand Down Expand Up @@ -636,7 +639,7 @@ public static function getAssetRules($assetKey, $recursive = false, $recursivePa
$rules = new Rules;
$rules->mergeCollection($collected);

!JDEBUG ?: \JProfiler::getInstance('Application')->mark('Before Access::getAssetRules <strong>Slower</strong> (assetKey:' . $assetKey . ')');
!JDEBUG ?: Profiler::getInstance('Application')->mark('Before Access::getAssetRules <strong>Slower</strong> (assetKey:' . $assetKey . ')');

return $rules;
}
Expand Down Expand Up @@ -991,7 +994,7 @@ public static function getAuthorisedViewLevels($userId)
$authorised = array(1);

// Check for the recovery mode setting and return early.
$user = \JUser::getInstance($userId);
$user = User::getInstance($userId);
$root_user = Factory::getApplication()->get('root_user');

if (($user->username && $user->username == $root_user) || (is_numeric($root_user) && $user->id > 0 && $user->id == $root_user))
Expand Down

0 comments on commit 2cf1a9f

Please sign in to comment.