. /** * Renderers to align Moodle's HTML with that expected by Bootstrap * * @package theme_bootstrap * @copyright 2014 Bas Brands, www.basbrands.nl * @authors Bas Brands, David Scotson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Parses CSS before it is cached. * * This function can make alterations and replace patterns within the CSS. * * @param string $css The CSS * @param theme_config $theme The theme config object. * @return string The parsed CSS The parsed CSS. */ function theme_bootstrap_process_css($css, $theme) { $settings = get_object_vars($theme->settings); $css = theme_bootstrap_delete_css($settings, $css); $settings['brandcss'] = theme_bootstrap_brand_font_css($settings); return theme_bootstrap_replace_settings($settings, $css); } function theme_bootstrap_delete_css($settings, $css) { if ($settings['deletecss'] == true) { $find[] = '/-webkit-border-radius:[^;]*;/'; $find[] = '/-webkit-box-shadow:[^;]*;/'; $find[] = '/-moz-border-radius:[^;]*;/'; $find[] = '/-moz-box-shadow:[^;]*;/'; return preg_replace($find, '', $css); } else { return $css; } } /** * For each setting called e.g. "customcss" this looks for the string * "[[setting:customcss]]" in the CSS and replaces it with * the value held in the $settings array for the key * "customcss". * * @param array $settings containing setting names and values * @param string $css The CSS * @return string The CSS with replacements made */ function theme_bootstrap_replace_settings($settings, $css) { foreach ($settings as $name => $value) { $find[] = "[[setting:$name]]"; $replace[] = $value; } return str_replace($find, $replace, $css); } function theme_bootstrap_brand_font_css($settings) { $fontname = $settings['brandfont']; if ($fontname === '') { return ''; } $fontweight = $settings['brandfontweight']; return ".navbar-default .navbar-brand, .navbar-inverse .navbar-brand { font-family: $fontname, serif; font-weight: $fontweight; }"; } /** * This function creates the dynamic HTML needed for the * layout and then passes it back in an object so it can * be echo'd to the page. * * This keeps the logic out of the layout files. */ function theme_bootstrap_html_for_settings($PAGE) { $settings = $PAGE->theme->settings; $html = new stdClass; if ($settings->inversenavbar == true) { $html->navbarclass = 'navbar navbar-inverse'; } else { $html->navbarclass = 'navbar navbar-default'; } $fluid = (!empty($PAGE->layout_options['fluid'])); if ($fluid || $settings->fluidwidth == true) { $html->containerclass = 'container-fluid'; } else { $html->containerclass = 'container'; } $html->brandfontlink = theme_bootstrap_brand_font_link($settings); return $html; } function theme_bootstrap_brand_font_link($settings) { global $SITE; $fontname = $settings->brandfont; if ($fontname === '') { return ''; } $fontname = urlencode($fontname); $text = urlencode(str_replace(' ', '', $SITE->shortname)); $fontweight = $settings->brandfontweight; $fontitalic = ''; if ($settings->brandfontitalic == true) { $fontitalic = 'italic'; } return ''; } function bootstrap_grid($hassidepre, $hassidepost) { if ($hassidepre && $hassidepost) { $regions = array('content' => 'col-sm-4 col-sm-push-4 col-md-6 col-md-push-3'); $regions['pre'] = 'col-sm-4 col-sm-pull-4 col-md-3 col-md-pull-6'; $regions['post'] = 'col-sm-4 col-md-3'; } else if ($hassidepre && !$hassidepost) { $regions = array('content' => 'col-sm-8 col-sm-push-4 col-md-9 col-md-push-3'); $regions['pre'] = 'col-sm-4 col-sm-pull-8 col-md-3 col-md-pull-9'; $regions['post'] = 'emtpy'; } else if (!$hassidepre && $hassidepost) { $regions = array('content' => 'col-sm-8 col-md-9'); $regions['pre'] = 'empty'; $regions['post'] = 'col-sm-4 col-md-3'; } else if (!$hassidepre && !$hassidepost) { $regions = array('content' => 'col-md-12'); $regions['pre'] = 'empty'; $regions['post'] = 'empty'; } return $regions; }