Add option to optimise inline css.

This commit is contained in:
Starbeamrainbowlabs 2016-04-09 21:48:08 +01:00
parent 3961c4977a
commit 9b457bb5da
4 changed files with 71 additions and 2 deletions

View File

@ -103,6 +103,7 @@ Key | Value | Explanation
`show_subpages` | boolean | Whether to show a list of subpages at the bottom of the page.
`subpages_display_depth` | number | The depth to which we should display when listing subpages at the bottom of the page.
`max_recent_changes` | number | The maximum number of recent changes to display on the recent changes page.
`optimize_pages` | boolean | Whether to optimise all webpages generated. Currently this option only minifies inline css.
`users` | array of users | An array of usernames and passwords - passwords should be hashed with sha256. Put one user / password on each line, remembering the comma at the end. The last user in the list doesn't need a comma after their details though. Tip: use the `hash` action to hash passwords appropriately for Pepperminty Wiki, but remember to use an incognito window!
`require_login_view` | boolean | Whether to require that users login before they do anything else. If you combine this setting with the `data_storage_dir` option to move the storage directory outside your web root, this will completely hide your wiki from anyone who isn't logged in.
`data_storage_dir` | path | The directory in which to store all files, except this main index.php. A single dot ('.') denotes the current directory. Remember to omit the trailing slash from the directory name, as it is added automatically by Pepperminty Wiki. Combine with `require_login_view` in order to completely hide your wiki from anonymous users.

View File

@ -260,6 +260,8 @@ $settings->defaultaction = "view";
// A VIRUS INTO YOUR WIKI
$settings->updateurl = "https://raw.githubusercontent.com/sbrl/pepperminty-wiki/master/index.php";
// Whether to optimise all webpages generated.
$settings->optimize_pages = true;
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// Other Modules ////////////////////////////////
@ -785,6 +787,11 @@ function system_extension_mime_type($ext) {
return isset($types[$ext]) ? $types[$ext] : null;
}
/**
* Generates a stack trace.
* @param bool $log_trace Whether to send the stack trace to the error log.
* @return string A string prepresentation of a stack trace.
*/
function stack_trace($log_trace = true)
{
$result = "";
@ -1198,7 +1205,34 @@ class page_renderer
if(preg_match("/^[^\/]*\/\/|^\//", $settings->css))
return "<link rel='stylesheet' href='$settings->css' />";
else
return "<style>$settings->css</style>";
{
$css = $settings->css;
if(!empty($settings->optimize_pages))
{
// CSS Minification ideas by Jean from catswhocode.com
// Link: http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php
// Remove comments
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', "", $css);
// Cut down whitespace
$css = preg_replace('/\s+/', " ", $css);
// Remove whitespace after colons and semicolons
$css = str_replace([
" :",
": ",
"; ",
" { ",
" } "
], [
":",
":",
";",
"{",
"}"
], $css);
}
return "<style>$css</style>";
}
}
public static $nav_divider = "<span class='nav-divider inflexible'> | </span>";

View File

@ -375,6 +375,11 @@ function system_extension_mime_type($ext) {
return isset($types[$ext]) ? $types[$ext] : null;
}
/**
* Generates a stack trace.
* @param bool $log_trace Whether to send the stack trace to the error log.
* @return string A string prepresentation of a stack trace.
*/
function stack_trace($log_trace = true)
{
$result = "";
@ -788,7 +793,34 @@ class page_renderer
if(preg_match("/^[^\/]*\/\/|^\//", $settings->css))
return "<link rel='stylesheet' href='$settings->css' />";
else
return "<style>$settings->css</style>";
{
$css = $settings->css;
if(!empty($settings->optimize_pages))
{
// CSS Minification ideas by Jean from catswhocode.com
// Link: http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php
// Remove comments
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', "", $css);
// Cut down whitespace
$css = preg_replace('/\s+/', " ", $css);
// Remove whitespace after colons and semicolons
$css = str_replace([
" :",
": ",
"; ",
" { ",
" } "
], [
":",
":",
";",
"{",
"}"
], $css);
}
return "<style>$css</style>";
}
}
public static $nav_divider = "<span class='nav-divider inflexible'> | </span>";

View File

@ -257,6 +257,8 @@ $settings->defaultaction = "view";
// A VIRUS INTO YOUR WIKI
$settings->updateurl = "https://raw.githubusercontent.com/sbrl/pepperminty-wiki/master/index.php";
// Whether to optimise all webpages generated.
$settings->optimize_pages = true;
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// Other Modules ////////////////////////////////