示例#1
0
文件: lib.php 项目: amsibsam/moodle3
/**
 * Extra LESS code to inject.
 *
 * This will generate some LESS code from the settings used by the user. We cannot use
 * the {@link theme_more_less_variables()} here because we need to create selectors or
 * alter existing ones.
 *
 * @param theme_config $theme The theme config object.
 * @return string Raw LESS code.
 */
function theme_campus_extra_less($theme)
{
    global $CFG, $OUTPUT;
    if (file_exists("{$CFG->dirroot}/theme/campus/campus-lib.php")) {
        include_once $CFG->dirroot . '/theme/campus/campus-lib.php';
    } else {
        if (!empty($CFG->themedir) && file_exists("{$CFG->themedir}/campus/campus-lib.php")) {
            include_once $CFG->themedir . '/campus/campus-lib.php';
        }
    }
    $campuscategorytree = theme_campus_get_top_level_categories();
    $content = '@import "' . $CFG->dirroot . '/theme/bootstrapbase/less/moodle";';
    $content .= '@import "variables-campus";';
    $content .= '@import "bootstrapchanges";';
    $content .= '@import "moodlechanges";';
    $content .= '@import "campuschanges";';
    $content .= '@import "campuscustom";';
    // Front page.
    if (!empty($theme->settings->frontpagelogo) && !empty($theme->settings->frontpagebackgroundimage)) {
        if (!empty($theme->settings->frontpageresponsivelogo) && !empty($theme->settings->frontpageresponsivebackgroundimage)) {
            if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivelogo', 'frontpageresponsivelogo')) {
                if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivebackgroundimage', 'frontpageresponsivebackgroundimage')) {
                    $backgroundwidth = $backgrounddimensions['width'];
                    $backgroundheight = $backgrounddimensions['height'];
                } else {
                    $backgroundwidth = 960;
                    // Fallback, where 960 is the value of @navbarCollapseWidth.
                    $backgroundheight = $dimensions['height'];
                }
                $totalwidth = $dimensions['width'] + $backgroundwidth;
                $fplogowidth = $dimensions['width'] / $totalwidth * 100;
                $fpabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                $fpflexpaddingbottom = $dimensions['height'] / $totalwidth * 100;
                $fpbackgroundwidth = 100 - $fplogowidth;
                /* .fpresponsiveheaderlogo(@frontpageMixinLogoWidth;
                   @frontpageAbsoluteMixinPaddingBottom;
                   @frontpageFlexMixinPaddingBottom;
                   @frontpageMixinBackgroundWidth) */
                $content .= '.fpresponsiveheaderlogo(' . $fplogowidth . '%; ' . $fpabsolutepaddingbottom . '%; ' . $fpflexpaddingbottom . '%; ' . $fpbackgroundwidth . '%);';
            }
        }
    } else {
        // Theme responsive images fall back.
        if (($logoresponsivedetails = theme_campus_get_theme_responsive_logo()) && ($backgroundresponsivedetails = theme_campus_get_theme_responsive_background())) {
            if ($logoresponsivedetails['fullname'] && ($dimensions = getimagesize($logoresponsivedetails['fullname']))) {
                // http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
                if ($backgroundresponsivedetails['fullname'] && ($backgrounddimensions = getimagesize($backgroundresponsivedetails['fullname']))) {
                    $backgroundwidth = $backgrounddimensions[0];
                    $backgroundheight = $backgrounddimensions[1];
                } else {
                    $backgroundwidth = 960;
                    // Fallback, where 960 is the value of @navbarCollapseWidth.
                    $backgroundheight = $dimensions[1];
                }
                $totalwidth = $dimensions[0] + $backgroundwidth;
                $fplogowidth = $dimensions[0] / $totalwidth * 100;
                $fpabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                $fpflexpaddingbottom = $dimensions[1] / $totalwidth * 100;
                $fpbackgroundwidth = 100 - $fplogowidth;
                /* .fpresponsiveheaderlogo(@frontpageMixinLogoWidth;
                   @frontpageAbsoluteMixinPaddingBottom;
                   @frontpageFlexMixinPaddingBottom;
                   @frontpageMixinBackgroundWidth) */
                $content .= '.fpresponsiveheaderlogo(' . $fplogowidth . '%; ' . $fpabsolutepaddingbottom . '%; ' . $fpflexpaddingbottom . '%; ' . $fpbackgroundwidth . '%);';
            }
        }
    }
    // Course catetgory.
    foreach ($campuscategorytree as $key => $value) {
        $categorylogoused = false;
        $cchavecustomsetting = 'coursecategoryhavecustomheader' . $key;
        $ccsetting = 'coursecategorylogo' . $key;
        $ccbsetting = 'coursecategorybackgroundimage' . $key;
        if (!empty($theme->settings->{$cchavecustomsetting}) && !empty($theme->settings->{$ccsetting}) && !empty($theme->settings->{$ccbsetting})) {
            if ($dimensions = theme_campus_get_image_dimensions($theme, $ccsetting, $ccsetting)) {
                if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, $ccbsetting, $ccbsetting)) {
                    $backgroundwidth = $backgrounddimensions['width'];
                    $backgroundheight = $backgrounddimensions['height'];
                } else {
                    if (!empty($theme->settings->pagewidthmax)) {
                        $backgroundwidth = $theme->settings->pagewidthmax;
                        // Fallback, default max px of #page unless a percentage.
                        if ($backgroundwidth == 100) {
                            // Percentage value, cannot use in calculation!
                            $backgroundwidth = 1680;
                            // Fallback, where 1680 is the default max px of #page.
                        }
                    } else {
                        $backgroundwidth = 1680;
                        // Fallback, where 1680 is the default max px of #page.
                    }
                    $backgroundheight = $dimensions['height'];
                }
                $totalwidth = $dimensions['width'] + $backgroundwidth;
                $cclogowidth = $dimensions['width'] / $totalwidth * 100;
                $ccabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                $ccflexpaddingbottom = $dimensions['height'] / $totalwidth * 100;
                $ccbackgroundwidth = 100 - $cclogowidth;
                /* ccheaderlogo(@courseCategoryKey;
                   @courseCategoryMixinLogoWidth;
                   @courseCategoryMixinAbsolutePaddingBottom;
                   @courseCategoryMixinFlexPaddingBottom;
                   @courseCategoryMixinBackgroundWidth) */
                $content .= '.ccheaderlogo(' . $key . '; ' . $cclogowidth . '%; ' . $ccabsolutepaddingbottom . '%; ' . $ccflexpaddingbottom . '%; ' . $ccbackgroundwidth . '%);';
                $ccsetting = 'coursecategoryresponsivelogo' . $key;
                $ccbsetting = 'coursecategoryresponsivebackgroundimage' . $key;
                if (!empty($theme->settings->{$ccsetting}) && !empty($theme->settings->{$ccbsetting})) {
                    if ($dimensions = theme_campus_get_image_dimensions($theme, $ccsetting, $ccsetting)) {
                        if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, $ccbsetting, $ccbsetting)) {
                            $backgroundwidth = $backgrounddimensions['width'];
                            $backgroundheight = $backgrounddimensions['height'];
                        } else {
                            $backgroundwidth = 960;
                            // Fallback, where 960 is the value of @navbarCollapseWidth.
                            $backgroundheight = $dimensions['height'];
                        }
                        $totalwidth = $dimensions['width'] + $backgroundwidth;
                        $cclogowidth = $dimensions['width'] / $totalwidth * 100;
                        $ccabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                        $ccflexpaddingbottom = $dimensions['height'] / $totalwidth * 100;
                        $ccbackgroundwidth = 100 - $cclogowidth;
                        /* .ccresponsiveheaderlogo(@courseCategoryKey;
                           @courseCategoryMixinLogoWidth;
                           @courseCategoryMixinAbsolutePaddingBottom;
                           @courseCategoryMixinFlexPaddingBottom;
                           @courseCategoryMixinBackgroundWidth) */
                        $content .= '.ccresponsiveheaderlogo(' . $key . '; ' . $cclogowidth . '%; ' . $ccabsolutepaddingbottom . '%; ' . $ccflexpaddingbottom . '%; ' . $ccbackgroundwidth . '%);';
                    }
                }
                $categorylogoused = true;
            }
        } else {
            if (!empty($theme->settings->frontpagelogo) && !empty($theme->settings->frontpagebackgroundimage)) {
                // Front page fall back.
                if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpagelogo', 'frontpagelogo')) {
                    // Front page campus desktop images.
                    if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpagebackgroundimage', 'frontpagebackgroundimage')) {
                        $backgroundwidth = $backgrounddimensions['width'];
                        $backgroundheight = $backgrounddimensions['height'];
                    } else {
                        if (!empty($theme->settings->pagewidthmax)) {
                            $backgroundwidth = $theme->settings->pagewidthmax;
                            // Fallback, default max px of #page unless a percentage.
                            if ($backgroundwidth == 100) {
                                // Percentage value, cannot use in calculation!
                                $backgroundwidth = 1680;
                                // Fallback, where 1680 is the default max px of #page.
                            }
                        } else {
                            $backgroundwidth = 1680;
                            // Fallback, where 1680 is the default max px of #page.
                        }
                        $backgroundheight = $dimensions['height'];
                    }
                    $totalwidth = $dimensions['width'] + $backgroundwidth;
                    $cclogowidth = $dimensions['width'] / $totalwidth * 100;
                    $ccabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                    $ccflexpaddingbottom = $dimensions['height'] / $totalwidth * 100;
                    $ccbackgroundwidth = 100 - $cclogowidth;
                    /* ccheaderlogo(@courseCategoryKey;
                       @courseCategoryMixinLogoWidth;
                       @courseCategoryMixinAbsolutePaddingBottom;
                       @courseCategoryMixinFlexPaddingBottom;
                       @courseCategoryMixinBackgroundWidth) */
                    $content .= '.ccheaderlogo(' . $key . '; ' . $cclogowidth . '%; ' . $ccabsolutepaddingbottom . '%; ' . $ccflexpaddingbottom . '%; ' . $ccbackgroundwidth . '%);';
                    if (!empty($theme->settings->frontpageresponsivelogo) && !empty($theme->settings->frontpageresponsivebackgroundimage)) {
                        if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivelogo', 'frontpageresponsivelogo')) {
                            if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivebackgroundimage', 'frontpageresponsivebackgroundimage')) {
                                $backgroundwidth = $backgrounddimensions['width'];
                                $backgroundheight = $backgrounddimensions['height'];
                            } else {
                                $backgroundwidth = 960;
                                // Fallback, where 960 is the value of @navbarCollapseWidth.
                                $backgroundheight = $dimensions['height'];
                            }
                            $totalwidth = $dimensions['width'] + $backgroundwidth;
                            $cclogowidth = $dimensions['width'] / $totalwidth * 100;
                            $ccabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                            $ccflexpaddingbottom = $dimensions['height'] / $totalwidth * 100;
                            $ccbackgroundwidth = 100 - $cclogowidth;
                            /* ccheaderlogo(@courseCategoryKey;
                               @courseCategoryMixinLogoWidth;
                               @courseCategoryMixinAbsolutePaddingBottom;
                               @courseCategoryMixinFlexPaddingBottom;
                               @courseCategoryMixinBackgroundWidth) */
                            $content .= '.ccresponsiveheaderlogo(' . $key . '; ' . $cclogowidth . '%; ' . $ccabsolutepaddingbottom . '%; ' . $ccflexpaddingbottom . '%; ' . $ccbackgroundwidth . '%);';
                        }
                    }
                    // Using front page, so use those settings.
                    if (!empty($theme->settings->frontpagelogoposition)) {
                        switch ($theme->settings->frontpagelogoposition) {
                            /* .ccheaderlogoposition(@courseCategoryKey;
                               @courseCategoryMixinLogoPosition;
                               @courseCategoryMixinSitenamePositionLeft;
                               @courseCategoryMixinSitenamePositionRight) */
                            case 1:
                                $content .= '.ccheaderlogoposition(' . $key . '; left; auto; 50px);';
                                break;
                            case 2:
                                $content .= '.ccheaderlogoposition(' . $key . '; right; 50px; auto);';
                                break;
                        }
                    }
                }
            } else {
                if ($logodetails = theme_campus_get_theme_logo()) {
                    // Theme images fall back.
                    if ($logodetails['fullname'] && ($dimensions = getimagesize($logodetails['fullname']))) {
                        // http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
                        $backgrounddetails = theme_campus_get_theme_background();
                        if ($backgrounddetails['fullname'] && ($backgrounddimensions = getimagesize($backgrounddetails['fullname']))) {
                            $backgroundwidth = $backgrounddimensions[0];
                            $backgroundheight = $backgrounddimensions[1];
                        } else {
                            if (!empty($theme->settings->pagewidthmax)) {
                                $backgroundwidth = $theme->settings->pagewidthmax;
                                // Fallback, default max px of #page unless a percentage.
                                if ($backgroundwidth == 100) {
                                    // Percentage value, cannot use in calculation!
                                    $backgroundwidth = 1680;
                                    // Fallback, where 1680 is the default max px of #page.
                                }
                            } else {
                                $backgroundwidth = 1680;
                                // Fallback, where 1680 is the default max px of #page.
                            }
                            $backgroundheight = $dimensions[1];
                        }
                        $totalwidth = $dimensions[0] + $backgroundwidth;
                        $cclogowidth = $dimensions[0] / $totalwidth * 100;
                        $ccabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                        $ccflexpaddingbottom = $dimensions[1] / $totalwidth * 100;
                        $ccbackgroundwidth = 100 - $cclogowidth;
                        /* ccheaderlogo(@courseCategoryKey;
                           @courseCategoryMixinLogoWidth;
                           @courseCategoryMixinAbsolutePaddingBottom;
                           @courseCategoryMixinFlexPaddingBottom;
                           @courseCategoryMixinBackgroundWidth) */
                        $content .= '.ccheaderlogo(' . $key . '; ' . $cclogowidth . '%; ' . $ccabsolutepaddingbottom . '%; ' . $ccflexpaddingbottom . '%; ' . $ccbackgroundwidth . '%);';
                        // Theme responsive images fall back.
                        if (($logoresponsivedetails = theme_campus_get_theme_responsive_logo()) && ($backgroundresponsivedetails = theme_campus_get_theme_responsive_background())) {
                            if ($logoresponsivedetails['fullname'] && ($dimensions = getimagesize($logoresponsivedetails['fullname']))) {
                                // http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
                                if ($backgroundresponsivedetails['fullname'] && ($backgrounddimensions = getimagesize($backgroundresponsivedetails['fullname']))) {
                                    $backgroundwidth = $backgrounddimensions[0];
                                    $backgroundheight = $backgrounddimensions[1];
                                } else {
                                    $backgroundwidth = 960;
                                    // Fallback, where 960 is the value of @navbarCollapseWidth.
                                    $backgroundheight = $dimensions[1];
                                }
                                $totalwidth = $dimensions[0] + $backgroundwidth;
                                $cclogowidth = $dimensions[0] / $totalwidth * 100;
                                $ccabsolutepaddingbottom = $backgroundheight / $backgroundwidth * 100;
                                $ccflexpaddingbottom = $dimensions[1] / $totalwidth * 100;
                                $ccbackgroundwidth = 100 - $cclogowidth;
                                /* ccheaderlogo(@courseCategoryKey;
                                   @courseCategoryMixinLogoWidth;
                                   @courseCategoryMixinAbsolutePaddingBottom;
                                   @courseCategoryMixinFlexPaddingBottom;
                                   @courseCategoryMixinBackgroundWidth) */
                                $content .= '.ccresponsiveheaderlogo(' . $key . '; ' . $cclogowidth . '%; ' . $ccabsolutepaddingbottom . '%; ' . $ccflexpaddingbottom . '%; ' . $ccbackgroundwidth . '%);';
                            }
                        }
                        $content .= '.ccheaderlogoposition(' . $key . '; left; auto; 50px);';
                        // Theme layout uses logo on left.
                    }
                }
            }
        }
        if ($categorylogoused == true) {
            $ccsetting = 'coursecategorybgcolour' . $key;
            if (!empty($theme->settings->{$ccsetting})) {
                /* .ccheaderbackgroundcolour(@courseCategoryKey;
                   @courseCategoryMixinBackgroundColour) */
                $content .= '.ccheaderbackgroundcolour(' . $key . '; ' . $theme->settings->{$ccsetting} . ');';
            }
            $ccsetting = 'coursecategorylogoposition' . $key;
            if (!empty($theme->settings->{$ccsetting})) {
                switch ($theme->settings->{$ccsetting}) {
                    /* .ccheaderlogoposition(@courseCategoryKey;
                       @courseCategoryMixinLogoPosition;
                       @courseCategoryMixinSitenamePositionLeft;
                       @courseCategoryMixinSitenamePositionRight) */
                    case 1:
                        $content .= '.ccheaderlogoposition(' . $key . '; left; auto; 50px);';
                        break;
                    case 2:
                        $content .= '.ccheaderlogoposition(' . $key . '; right; 50px; auto);';
                        break;
                }
            }
        }
    }
    // Header toggle.
    if (!empty($theme->settings->showheadertoggle)) {
        // NOTE: If @navbarCollapseWidth changes in the variables-campus.less file, then change this.
        // .headertogglesetup(@screenWidth)
        $content .= '.headertogglesetup(961px);';
        // .headertogglemenuhide(@screenWidth)
        $content .= '.headertogglemenuhide(960px);';
        // .headertogglemenuhidenofancy(@screenWidth)
        $content .= '.headertogglemenuhidenofancy(960px);';
    }
    return $content;
}
        $frontpagesettings = true;
    }
}
// Fall back to theme logo and background if no frontpage logo or background and technically if the course category logo or background do not exist too.
if (!$hdlogo || !$hdbackgroundimage) {
    // Note: Please remeber to set the image dimensions in 'theme_campus_extra_less()' of lib.php.
    if ($logodetails = theme_campus_get_theme_logo()) {
        $hdlogo = $OUTPUT->pix_url($logodetails['name'], 'theme');
        // $hdlogo can still be false if 'pix_url' fails for some unknown reason.
    }
    if ($backgrounddetails = theme_campus_get_theme_background()) {
        $hdbackgroundimage = $OUTPUT->pix_url($backgrounddetails['name'], 'theme');
        // $hdbackgroundimage can still be false if 'pix_url' fails for some unknown reason.
    }
    // Use theme responsive versions.
    if ($logoresponsivedetails = theme_campus_get_theme_responsive_logo()) {
        $hdresponsivelogo = $OUTPUT->pix_url($logoresponsivedetails['name'], 'theme');
        // $hdresponsivelogo can still be false if 'pix_url' fails for some unknown reason.
    }
    if ($backgroundresponsivedetails = theme_campus_get_theme_responsive_background()) {
        $hdresponsivebackgroundimage = $OUTPUT->pix_url($backgroundresponsivedetails['name'], 'theme');
        // $hdresponsivebackgroundimage can still be false if 'pix_url' fails for some unknown reason.
    }
    // Use flex layout with the logo on the left.
    $hdlayout = 'flexlayout';
    $hdbackgroundextrapos = 1;
    $hdlogoextrapos = $hdbackgroundextrapos;
    $hdflexlayout = true;
    $themesettings = true;
    $frontpagesettings = true;
}