MDL-22913 - adding basic settings to theme

This commit is contained in:
Patrick Malley 2010-07-05 22:32:05 +00:00
parent b5d45a0430
commit 5cdcedfb82
5 changed files with 309 additions and 145 deletions

View file

@ -172,7 +172,7 @@ $THEME->layouts = array(
// specific page.
///////////////////////////////////////////////////////////////
// $THEME->csspostprocess
$THEME->csspostprocess = 'nonzero_process_css';
////////////////////////////////////////////////////
// Allows the user to provide the name of a function
@ -252,4 +252,4 @@ $THEME->layouts = array(
////////////////////////////////////////////////////
// Controls the colours for the MP3 player
////////////////////////////////////////////////////
////////////////////////////////////////////////////

View file

@ -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.';

100
theme/nonzero/lib.php Executable file
View file

@ -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;
}

60
theme/nonzero/settings.php Executable file
View file

@ -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);

View file

@ -1,143 +1,137 @@
/** Path: theme pagelayout **/
/*********************************************************************************************
left column: 250px
right column: 350px
padding left/right column: 10px
padding center column: 30px
**********************************************************************************************/
body {margin:auto 0px;width:auto;}
#page {width:100%;overflow:hidden;}
#page-content {
clear: both;
overflow: hidden;
position: relative;
width: 100%;
}
#page-content #region-main-box {
float: left;
margin-left: -200px;
position: relative;
width: 200%;
right: 100%;
}
#page-content #region-main-box #region-post-box {
float: left;
margin-left: -200px;
width: 100%;
}
#page-content #region-main-box #region-post-box #region-main-wrap {
float: left;
width: 50%;
}
#page-content #region-main-box #region-post-box #region-main-wrap #region-main {
overflow: hidden;
position: relative;
margin-left: 400px;
left: 100%;
}
#page-content #region-main-box #region-post-box #region-pre {
float: right;
position: relative;
left: 200px;
width: 200px;
}
#page-content #region-main-box #region-post-box #region-post {
float: right;
position: relative;
left: 600px;
width: 200px;
}
#page-content #region-main-box #region-post-box #region-main-wrap #region-main .region-content {
overflow: hidden;
padding: 20px 20px 20px 0;
}
#page-content #region-main-box #region-post-box #region-pre .region-content,
#page-content #region-main-box #region-post-box #region-post .region-content {
overflow: hidden;
padding: 20px 10px;
}
#page-footer {
clear: both;
float: left;
width: 100%;
}
/** Only side pre **/
.side-pre-only #page-content #region-main-box {
margin-left: 0px;
}
.side-pre-only #page-content #region-main-box #region-post-box {
margin-left: -200px;
}
.side-pre-only #page-content #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: 200px;
}
.side-pre-only #page-content #region-main-box #region-post-box #region-pre {
left: 200px;
width: 200px;
}
.side-pre-only #page-content #region-main-box #region-post-box #region-post {
width: 0%;
}
/** Only side post **/
.side-post-only #page-content #region-main-box {
margin-left: 0px;
}
.side-post-only #page-content #region-main-box #region-post-box {
margin-left: -200px;
}
.side-post-only #page-content #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: 200px;
}
.side-post-only #page-content #region-main-box #region-post-box #region-post {
left: 200px;
width: 200px;
}
.has_dock.side-post-only .page-middle #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: 200px;
}
/** No blocks whatsoever **/
.content-only #page-content #region-main-box {
margin-left: 0px;
}
.content-only #page-content #region-main-box #region-post-box {
margin-left: 0px;
}
.content-only #page-content #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: 0px;
}
.content-only #page-content #region-main-box #region-post-box #region-pre {
width: 0px;
}
.content-only #page-content #region-main-box #region-post-box #region-post {
width: 0px;
/** Path: theme pagelayout **/
body {margin:auto 0px;width:auto;}
#page {width:100%;overflow:hidden;}
#page-content {
clear: both;
overflow: hidden;
position: relative;
width: 100%;
}
#page-content #region-main-box {
float: left;
margin-left: -[[setting:regionpostwidth]];;
position: relative;
width: 200%;
right: 100%;
}
#page-content #region-main-box #region-post-box {
float: left;
margin-left: -[[setting:regionprewidth]];;
width: 100%;
}
#page-content #region-main-box #region-post-box #region-main-wrap {
float: left;
width: 50%;
}
#page-content #region-main-box #region-post-box #region-main-wrap #region-main {
overflow: hidden;
position: relative;
margin-left: [[setting:regionsumwidth]];
left: 100%;
}
#page-content #region-main-box #region-post-box #region-pre {
float: right;
position: relative;
width: [[setting:regionprewidth]];
left: [[setting:regionprewidth]];
}
#page-content #region-main-box #region-post-box #region-post {
float: right;
position: relative;
left: [[setting:regiondoublepresumwidth]];
width: [[setting:regionpostwidth]];
}
#page-content #region-main-box #region-post-box #region-main-wrap #region-main .region-content {
overflow: hidden;
padding: 20px 20px 20px 0;
}
#page-content #region-main-box #region-post-box #region-pre .region-content,
#page-content #region-main-box #region-post-box #region-post .region-content {
overflow: hidden;
padding: 20px 10px;
}
#page-footer {
clear: both;
float: left;
width: 100%;
}
/** Only side pre **/
.side-pre-only #page-content #region-main-box {
margin-left: 0px;
}
.side-pre-only #page-content #region-main-box #region-post-box {
margin-left: -[[setting:regionprewidth]];
}
.side-pre-only #page-content #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: [[setting:regionprewidth]];
}
.side-pre-only #page-content #region-main-box #region-post-box #region-pre {
left: [[setting:regionprewidth]];
width: [[setting:regionprewidth]];
}
.side-pre-only #page-content #region-main-box #region-post-box #region-post {
width: 0%;
}
/** Only side post **/
.side-post-only #page-content #region-main-box {
margin-left: 0px;
}
.side-post-only #page-content #region-main-box #region-post-box {
margin-left: -[[setting:regionpostwidth]];
}
.side-post-only #page-content #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: [[setting:regionpostwidth]];
}
.side-post-only #page-content #region-main-box #region-post-box #region-post {
left: [[setting:regionpostwidth]];
width: [[setting:regionpostwidth]];
}
.has_dock.side-post-only .page-middle #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: [[setting:regionprewidth]];
}
/** No blocks whatsoever **/
.content-only #page-content #region-main-box {
margin-left: 0px;
}
.content-only #page-content #region-main-box #region-post-box {
margin-left: 0px;
}
.content-only #page-content #region-main-box #region-post-box #region-main-wrap #region-main {
margin-left: 0px;
}
.content-only #page-content #region-main-box #region-post-box #region-pre {
width: 0px;
}
.content-only #page-content #region-main-box #region-post-box #region-post {
width: 0px;
}