Permalink
Browse files

MDL-22913 - adding basic settings to theme

  • Loading branch information...
1 parent b5d45a0 commit 5cdcedfb82df6e0e9bb1c8551fc74960f57cd197 Patrick Malley committed Jul 5, 2010
View
@@ -172,7 +172,7 @@
// specific page.
///////////////////////////////////////////////////////////////
-// $THEME->csspostprocess
+$THEME->csspostprocess = 'nonzero_process_css';
////////////////////////////////////////////////////
// Allows the user to provide the name of a function
@@ -252,4 +252,4 @@
////////////////////////////////////////////////////
// Controls the colours for the MP3 player
-////////////////////////////////////////////////////
+////////////////////////////////////////////////////
@@ -26,4 +26,14 @@
$string['pluginname'] = 'Nonzero';
$string['region-side-post'] = 'Right';
$string['region-side-pre'] = 'Left';
-$string['choosereadme'] = '<div class="clearfix"><div class="theme_screenshot"><h2>Nonzero</h2><img src="nonzero/pix/screenshot.jpg" /><h3>Theme Discussion Forum:</h3><p><a href="http://moodle.org/mod/forum/view.php?id=46">http://moodle.org/mod/forum/view.php?id=46</a></p><h3>Theme Credits</h3><p><a href="http://docs.moodle.org/en/Theme_credits">http://docs.moodle.org/en/Theme_credits</a></p><h3>Theme Documentation:</h3><p><a href="http://docs.moodle.org/en/Themes">http://docs.moodle.org/en/Themes</a></p><h3>Report a bug:</h3><p><a href="http://tracker.moodle.org">http://tracker.moodle.org</a></p></div><div class="theme_description"><h2>About</h2><p>Nonzero is a nontraditional, three-column, fluid-width theme for Moodle. It\'s nontraditional in the sense that it uses a fresh three-column layout that displays the content to the left of both block columns.<h2>Tweaks</h2><p>This theme is built upon both Base and Canvas, two parent themes included in the Moodle core. If you want to modify this theme, we recommend that you first duplicate it, then rename it before making your changes. This will prevent your customized theme from being overwritten by future Moodle upgrades, and you\'ll still have the original files if you make a mess. More information on modifying themes can be found in the <a href="http://docs.moodle.org/en/Theme">MoodleDocs</a>.</p>h3>License</h3><p>This, and all other themes included in the Moodle core, are licensed under the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>.</div></div>';
+$string['choosereadme'] = '<div class="clearfix"><div class="theme_screenshot"><h2>Nonzero</h2><img src="nonzero/pix/screenshot.jpg" /><h3>Theme Discussion Forum:</h3><p><a href="http://moodle.org/mod/forum/view.php?id=46">http://moodle.org/mod/forum/view.php?id=46</a></p><h3>Theme Credits</h3><p><a href="http://docs.moodle.org/en/Theme_credits">http://docs.moodle.org/en/Theme_credits</a></p><h3>Theme Documentation:</h3><p><a href="http://docs.moodle.org/en/Themes">http://docs.moodle.org/en/Themes</a></p><h3>Report a bug:</h3><p><a href="http://tracker.moodle.org">http://tracker.moodle.org</a></p></div><div class="theme_description"><h2>About</h2><p>Nonzero is a nontraditional, three-column, fluid-width theme for Moodle. It\'s nontraditional in the sense that it uses a fresh three-column layout that displays the content to the left of both block columns.<h2>Tweaks</h2><p>This theme is built upon both Base and Canvas, two parent themes included in the Moodle core. If you want to modify this theme, we recommend that you first duplicate it, then rename it before making your changes. This will prevent your customized theme from being overwritten by future Moodle upgrades, and you\'ll still have the original files if you make a mess. More information on modifying themes can be found in the <a href="http://docs.moodle.org/en/Theme">MoodleDocs</a>.</p>h3>License</h3><p>This, and all other themes included in the Moodle core, are licensed under the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>.</div></div>';
+
+// Config
+
+$string['configtitle'] = 'Nonzero Settings';
+$string['customcss'] = 'Custom CSS';
+$string['customcssdesc'] = 'Any CSS you enter here will be added to every page allowing your to easily customise this theme.';
+$string['regionprewidth'] = 'Left column width';
+$string['regionprewidthdesc'] = 'This sets the width of the block region that forms the left column. This column is displayed in the middle of the page while using blog layout';
+$string['regionpostwidth'] = 'Right column width';
+$string['regionpostwidthdesc'] = 'This sets the width of the block region that forms the right column.';
View
@@ -0,0 +1,100 @@
+<?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/>.
+
+/**
+ * This file contains the settings for the Nonzero theme.
+ *
+ * Currently you can set the following settings:
+ * - Region pre width
+ * - Region post width
+ * - Some custom CSS
+ *
+ * @package moodlecore
+ * @copyright 2010 Dietmar Wagner
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+function nonzero_process_css($css, $theme) {
+
+
+ // Set the region-pre and region-post widths
+ if (!empty($theme->settings->regionprewidth) && !empty($theme->settings->regionpostwidth)) {
+ $regionprewidth = $theme->settings->regionprewidth;
+ $regionpostwidth = $theme->settings->regionpostwidth;
+ } else {
+ $regionprewidth = null;
+ $regionpostwidth = null;
+ }
+ $css = nonzero_set_regionwidths($css, $regionprewidth, $regionpostwidth);
+
+
+ // Set the custom CSS
+ if (!empty($theme->settings->customcss)) {
+ $customcss = $theme->settings->customcss;
+ } else {
+ $customcss = null;
+ }
+ $css = nonzero_set_customcss($css, $customcss);
+
+ // Return the CSS
+ return $css;
+}
+
+/**
+ * Sets the region width variable in CSS
+ *
+ * @param string $css
+ * @param mixed $regionwidth
+ * @return string
+ */
+
+function nonzero_set_regionwidths($css, $regionprewidth, $regionpostwidth) {
+ $tag1 = '[[setting:regionprewidth]]';
+ $tag2 = '[[setting:regionpostwidth]]';
+ $tag3 = '[[setting:regionsumwidth]]';
+ $tag4 = '[[setting:regiondoublepresumwidth]]';
+ $replacement1 = $regionprewidth;
+ $replacement2 = $regionpostwidth;
+ if (is_null($replacement1) or is_null($replacement2)) {
+ $replacement1 = 200;
+ $replacement2 = 200;
+ }
+ $css = str_replace($tag1, $replacement1.'px', $css);
+ $css = str_replace($tag2, $replacement2.'px', $css);
+ $css = str_replace($tag3, ($replacement1+$replacement2).'px', $css);
+ $css = str_replace($tag4, (2*$replacement1+$replacement2).'px', $css);
+ return $css;
+}
+
+
+/**
+ * Sets the custom css variable in CSS
+ *
+ * @param string $css
+ * @param mixed $customcss
+ * @return string
+ */
+
+function nonzero_set_customcss($css, $customcss) {
+ $tag = '[[setting:customcss]]';
+ $replacement = $customcss;
+ if (is_null($replacement)) {
+ $replacement = '';
+ }
+ $css = str_replace($tag, $replacement, $css);
+ return $css;
+}
View
@@ -0,0 +1,60 @@
+<?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/>.
+
+/**
+ * This file contains the settings for the Nonzero theme.
+ *
+ * Currently you can set the following settings:
+ * - Region pre width
+ * - Region post width
+ * - Some custom CSS
+ *
+ * @package moodlecore
+ * @copyright 2010 Dietmar Wagner
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+// Create our admin page
+$temp = new admin_settingpage('theme_nonzero', get_string('configtitle','theme_nonzero'));
+
+// Block region-pre width
+$name = 'theme_nonzero/regionprewidth';
+$title = get_string('regionprewidth','theme_nonzero');
+$description = get_string('regionprewidthdesc', 'theme_nonzero');
+$default = 200;
+$choices = array(180=>'180px', 190=>'190px', 200=>'200px', 210=>'210px', 220=>'220px', 230=>'230px', 240=>'240px', 250=>'250px', 260=>'260px');
+$setting = new admin_setting_configselect($name, $title, $description, $default, $choices);
+$temp->add($setting);
+
+// Block region-post width
+$name = 'theme_nonzero/regionpostwidth';
+$title = get_string('regionpostwidth','theme_nonzero');
+$description = get_string('regionpostwidthdesc', 'theme_nonzero');
+$default = 200;
+$choices = array(180=>'180px', 190=>'190px', 200=>'200px', 210=>'210px', 220=>'220px', 230=>'230px', 240=>'240px', 250=>'250px', 260=>'260px');
+$setting = new admin_setting_configselect($name, $title, $description, $default, $choices);
+$temp->add($setting);
+
+// Custom CSS file
+$name = 'theme_nonzero/customcss';
+$title = get_string('customcss','theme_nonzero');
+$description = get_string('customcssdesc', 'theme_nonzero');
+$setting = new admin_setting_configtextarea($name, $title, $description, '');
+$temp->add($setting);
+
+// Add our page to the structure of the admin tree
+$ADMIN->add('themes', $temp);
Oops, something went wrong.

0 comments on commit 5cdcedf

Please sign in to comment.