Skip to content

Commit

Permalink
Color of block icons - task #859.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jul 25, 2016
1 parent 6671f51 commit 04bdbeb
Show file tree
Hide file tree
Showing 329 changed files with 715 additions and 305 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -3,6 +3,7 @@ Version Information
25th July 2016 - Version 3.1.1.2
1. Setting coursepagepageheadinglocation/frontpagepageheadinglocation is not always applied correctly - task #863.
2. Userpicture in navbar: style improvements - task #861.
3. Color of block icons - task #859.

23rd July 2016 - Version 3.1.1.1
1. Hamburger button looks ugly in many cases - task #860.
Expand Down
28 changes: 24 additions & 4 deletions Gruntfile.js
Expand Up @@ -144,7 +144,7 @@ module.exports = function(grunt) {
decachephp += 'require(\'' + configfile + '\');';
decachephp += 'theme_reset_all_caches();';

var svgcolor = grunt.option('svgcolor') || '#7575E0';
var svgcolor = grunt.option('svgcolor') || '#999999';

grunt.initConfig({
less: {
Expand Down Expand Up @@ -204,6 +204,12 @@ module.exports = function(grunt) {
cwd: 'pix_plugins_originals/',
src: '**',
dest: 'pix_plugins/',
},
svg_fp: {
expand: true,
cwd: 'pix_fp_originals/',
src: '**',
dest: 'pix/fp/',
}
},
replace: {
Expand All @@ -222,6 +228,14 @@ module.exports = function(grunt) {
from: '#999',
to: svgcolor
}]
},
svg_colours_fp: {
src: 'pix/fp/**/*.svg',
overwrite: true,
replacements: [{
from: '#999',
to: svgcolor
}]
}
},
svgmin: { // Task
Expand Down Expand Up @@ -249,6 +263,12 @@ module.exports = function(grunt) {
src: ['**/*.svg'], // Actual pattern(s) to match.
dest: 'pix_plugins/', // Destination path prefix.
ext: '.svg' // Destination file paths will have this extension.
}, { // Dictionary of files
expand: true, // Enable dynamic expansion.
cwd: 'pix/fp', // Source matches are relative to this path.
src: ['**/*.svg'], // Actual pattern(s) to match.
dest: 'pix/fp/', // Destination path prefix.
ext: '.svg' // Destination file paths will have this extension.
}]
}
},
Expand Down Expand Up @@ -292,8 +312,8 @@ module.exports = function(grunt) {
grunt.registerTask("decache", ["exec:decache"]);

grunt.registerTask("compile", ["less:editor_"+build, "decache"]);
grunt.registerTask("copy:svg", ["copy:svg_core", "copy:svg_plugins"]);
grunt.registerTask("replace:svg_colours", ["replace:svg_colours_core", "replace:svg_colours_plugins"]);
grunt.registerTask("svg", ["copy:svg", "svgmin", "replace:svg_colours"]);
grunt.registerTask("copy:svg", ["copy:svg_core", "copy:svg_plugins", "copy:svg_fp"]);
grunt.registerTask("replace:svg_colours", ["replace:svg_colours_core", "replace:svg_colours_plugins", "replace:svg_colours_fp"]);
grunt.registerTask("svg", ["copy:svg", "replace:svg_colours", "svgmin"]);
grunt.registerTask("amd", ["jshint", "uglify"]);
};
1 change: 0 additions & 1 deletion classes/core_renderer.php
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down
163 changes: 163 additions & 0 deletions classes/toolbox.php
@@ -0,0 +1,163 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Campus theme with the underlying Bootstrap theme.
*
* @package theme
* @subpackage campus
* @copyright &copy; 2016-onwards G J Barnard in respect to modifications of the Clean theme.
* @copyright &copy; 2016-onwards Work undertaken for David Bogner of Edulabs.org.
* @author G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
* @author Based on code originally written by Mary Evans, Bas Brands, Stuart Lamour and David Scotson.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace theme_campus;

class toolbox {

protected static $theme;

/**
* Finds the given setting in the theme from the themes' configuration object.
* @param string $setting Setting name.
* @param string $format false|'format_text'|'format_html'.
* @param theme_config $theme null|theme_config object.
* @return any false|value of setting.
*/
static public function get_setting($setting, $format = false, $theme = null) {

if (empty($theme)) {
if (empty(self::$theme)) {
self::$theme = \theme_config::load('campus');
}
$theme = self::$theme;
}

global $CFG;
require_once($CFG->dirroot . '/lib/weblib.php');
if (empty($theme->settings->$setting)) {
return false;
} else if (!$format) {
return $theme->settings->$setting;
} else if ($format === 'format_text') {
return format_text($theme->settings->$setting, FORMAT_PLAIN);
} else if ($format === 'format_html') {
return format_text($theme->settings->$setting, FORMAT_HTML, array('trusted' => true, 'noclean' => true));
} else {
return format_string($theme->settings->$setting);
}
}

/**
* Finds the given setting in the theme using the get_config core function for when the theme_config object has not been created.
* @param string $setting Setting name.
* @param themename $themename null(default of 'shoelace' used)|theme name.
* @return any false|value of setting.
*/
static public function get_config_setting($setting, $themename = null) {
if (empty($themename)) {
$themename = 'campus';
}
return \get_config('theme_' . $themename, $setting);
}

static public function change_icons() {
static $lastrun = 0;
if (empty($lastrun)) {
$lastrun = time();
} else {
$thisrun = time();
if (($thisrun - $lastrun) <= 5) {
$lastrun = $thisrun;
/* Prevent muiltiple runs within a five second period.
Helps to reduce the issue of multiple calls when 'Purging all caches'. */
return;
}
$lastrun = $thisrun;
}

static $folder = null;
if (empty($folder)) {
global $CFG, $PAGE;
$themedir = $PAGE->theme->dir;
$folder = '.';

if (file_exists("$CFG->dirroot/theme/campus/$folder")) {
$folder = "$CFG->dirroot/theme/campus";
} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/campus")) {
$folder = "$CFG->themedir/campus";
} else {
$folder = dirname(__FILE__);
}
}

$iconcolour = self::get_setting('iconcolour');
if (strlen($iconcolour) > 0) {
$currenticoncolour = self::get_config_setting('currenticoncolour');
// Do we need to look at all the files and change them?
if (strcmp($currenticoncolour, $iconcolour) != 0) {
set_config('currenticoncolour', $iconcolour, 'theme_campus');
$files = array();
self::svg_files($files, $folder . '/pix/fp');
self::svg_files($files, $folder . '/pix_core');
self::svg_files($files, $folder . '/pix_plugins');
$attrset = false;

foreach ($files as $file => $filename) {
$svg = simplexml_load_file($filename);
if (isset($svg->path)) {
foreach ($svg->path as $pathidx => $path) {
foreach ($path->attributes() as $attridx => $attr) {
if ((strcmp($attridx, 'fill') == 0)) {
if ((strcmp($attr, '#fff') != 0) && (strcmp($attr, $iconcolour) != 0)) {
$path['fill'] = $iconcolour;
$attrset = true;
}
}
}
}
if ($attrset) {
$svg->asXML($filename);
$attrset = false;
}
}
}
\purge_all_caches(); // Reset cache even though setting would have done this, files not updated on system!
}
}
}

static private function svg_files(&$files, $root) {
if (file_exists($root)) {
$thefiles = scandir($root);

foreach ($thefiles as $file => $filename) {
if ((strlen($filename) == 1) && ($filename[0] == '.')) {
continue;
}
if ((strlen($filename) == 2) && ($filename[0] == '.') && ($filename[1] == '.')) {
continue;
}
if (is_dir("$root/$filename")) {
self::svg_files($files, "$root/$filename");
} else if (strpos($filename, '.svg') !== FALSE) { // TODO: See if 'finfo_file' is better.
$files[] = $root . '/' . $filename;
}
}
}
}
}
6 changes: 6 additions & 0 deletions lang/en/theme_campus.php
Expand Up @@ -142,6 +142,12 @@
$string['linkcolour'] = 'Link text colour';
$string['linkcolourdesc'] = 'Set the link text colour.';

$string['iconcoloursetting'] = 'Use icon colour setting';
$string['iconcoloursetting_desc'] = 'Use the icon colour setting for the icons. The icon colour functionality is new. If you experience problems with it, then turn it off and run \'grunt svg\' on the Node.js command prompt. Please see \'Gruntfile.js\' for full details.';

$string['iconcolour'] = 'Icon colour';
$string['iconcolour_desc'] = 'The colour for the icons.';

$string['headingcolour'] = 'Heading colour';
$string['headingcolourdesc'] = 'Set the heading colour.';

Expand Down
5 changes: 5 additions & 0 deletions lib.php
Expand Up @@ -33,6 +33,11 @@ function theme_campus_process_css($css, $theme) {
} else {
$customcss = null;
}

if (\theme_campus\toolbox::get_setting('iconcoloursetting')) {
\theme_campus\toolbox::change_icons();
}

$css = theme_campus_set_customcss($css, $customcss);

return $css;
Expand Down
3 changes: 3 additions & 0 deletions pix/fp/add_file.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/create_folder.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/download_all.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/help.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/logout.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/refresh.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/search.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/setting.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/view_icon_active.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/view_list_active.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pix/fp/view_tree_active.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pix_core/a/add_file.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pix_core/a/download_all.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04bdbeb

Please sign in to comment.