Beispiel #1
0
 /**
  * Private constructor, can be called only from the factory method.
  * @param stdClass $config
  */
 private function __construct($config)
 {
     global $CFG;
     //needed for included lib.php files
     $this->settings = $config->settings;
     $this->name = $config->name;
     $this->dir = $config->dir;
     if ($this->name != 'base') {
         $baseconfig = theme_config::find_theme_config('base', $this->settings);
     } else {
         $baseconfig = $config;
     }
     $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts', 'javascripts_footer', 'parents_exclude_javascripts', 'layouts', 'enable_dock', 'enablecourseajax', 'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'hidefromselector');
     foreach ($config as $key => $value) {
         if (in_array($key, $configurable)) {
             $this->{$key} = $value;
         }
     }
     // verify all parents and load configs and renderers
     foreach ($this->parents as $parent) {
         if ($parent == 'base') {
             $parent_config = $baseconfig;
         } else {
             if (!($parent_config = theme_config::find_theme_config($parent, $this->settings))) {
                 // this is not good - better exclude faulty parents
                 continue;
             }
         }
         $libfile = $parent_config->dir . '/lib.php';
         if (is_readable($libfile)) {
             // theme may store various function here
             include_once $libfile;
         }
         $renderersfile = $parent_config->dir . '/renderers.php';
         if (is_readable($renderersfile)) {
             // may contain core and plugin renderers and renderer factory
             include_once $renderersfile;
         }
         $this->parent_configs[$parent] = $parent_config;
         $rendererfile = $parent_config->dir . '/renderers.php';
         if (is_readable($rendererfile)) {
             // may contain core and plugin renderers and renderer factory
             include_once $rendererfile;
         }
     }
     $libfile = $this->dir . '/lib.php';
     if (is_readable($libfile)) {
         // theme may store various function here
         include_once $libfile;
     }
     $rendererfile = $this->dir . '/renderers.php';
     if (is_readable($rendererfile)) {
         // may contain core and plugin renderers and renderer factory
         include_once $rendererfile;
     } else {
         // check if renderers.php file is missnamed renderer.php
         if (is_readable($this->dir . '/renderer.php')) {
             debugging('Developer hint: ' . $this->dir . '/renderer.php should be renamed to ' . $this->dir . "/renderers.php.\n                    See: http://docs.moodle.org/dev/Output_renderers#Theme_renderers.", DEBUG_DEVELOPER);
         }
     }
     // cascade all layouts properly
     foreach ($baseconfig->layouts as $layout => $value) {
         if (!isset($this->layouts[$layout])) {
             foreach ($this->parent_configs as $parent_config) {
                 if (isset($parent_config->layouts[$layout])) {
                     $this->layouts[$layout] = $parent_config->layouts[$layout];
                     continue 2;
                 }
             }
             $this->layouts[$layout] = $value;
         }
     }
     //fix arrows if needed
     $this->check_theme_arrows();
 }
 /**
  * Loads the theme config from config.php file.
  *
  * @param string $themename
  * @param stdClass $settings from config_plugins table
  * @param boolean $parentscheck true to also check the parents.    .
  * @return stdClass The theme configuration
  */
 private static function find_theme_config($themename, $settings, $parentscheck = true)
 {
     // We have to use the variable name $THEME (upper case) because that
     // is what is used in theme config.php files.
     if (!($dir = theme_config::find_theme_location($themename))) {
         return null;
     }
     $THEME = new stdClass();
     $THEME->name = $themename;
     $THEME->dir = $dir;
     $THEME->settings = $settings;
     global $CFG;
     // just in case somebody tries to use $CFG in theme config
     include "{$THEME->dir}/config.php";
     // verify the theme configuration is OK
     if (!is_array($THEME->parents)) {
         // parents option is mandatory now
         return null;
     } else {
         // We use $parentscheck to only check the direct parents (avoid infinite loop).
         if ($parentscheck) {
             // Find all parent theme configs.
             foreach ($THEME->parents as $parent) {
                 $parentconfig = theme_config::find_theme_config($parent, $settings, false);
                 if (empty($parentconfig)) {
                     return null;
                 }
             }
         }
     }
     return $THEME;
 }
Beispiel #3
0
 /**
  * Private constructor, can be called only from the factory method.
  * @param stdClass $config
  */
 private function __construct($config)
 {
     global $CFG;
     //needed for included lib.php files
     $this->settings = $config->settings;
     $this->name = $config->name;
     $this->dir = $config->dir;
     if ($this->name != 'base') {
         $baseconfig = theme_config::find_theme_config('base', $this->settings);
     } else {
         $baseconfig = $config;
     }
     $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts', 'javascripts_footer', 'parents_exclude_javascripts', 'layouts', 'resource_mp3player_colors', 'enable_dock', 'enablecourseajax', 'filter_mediaplugin_colors', 'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'hidefromselector');
     foreach ($config as $key => $value) {
         if (in_array($key, $configurable)) {
             $this->{$key} = $value;
         }
     }
     // verify all parents and load configs and renderers
     foreach ($this->parents as $parent) {
         if ($parent == 'base') {
             $parent_config = $baseconfig;
         } else {
             if (!($parent_config = theme_config::find_theme_config($parent, $this->settings))) {
                 // this is not good - better exclude faulty parents
                 continue;
             }
         }
         $libfile = $parent_config->dir . '/lib.php';
         if (is_readable($libfile)) {
             // theme may store various function here
             include_once $libfile;
         }
         $renderersfile = $parent_config->dir . '/renderers.php';
         if (is_readable($renderersfile)) {
             // may contain core and plugin renderers and renderer factory
             include_once $renderersfile;
         }
         $this->parent_configs[$parent] = $parent_config;
         $rendererfile = $parent_config->dir . '/renderers.php';
         if (is_readable($rendererfile)) {
             // may contain core and plugin renderers and renderer factory
             include_once $rendererfile;
         }
     }
     $libfile = $this->dir . '/lib.php';
     if (is_readable($libfile)) {
         // theme may store various function here
         include_once $libfile;
     }
     $rendererfile = $this->dir . '/renderers.php';
     if (is_readable($rendererfile)) {
         // may contain core and plugin renderers and renderer factory
         include_once $rendererfile;
     }
     // cascade all layouts properly
     foreach ($baseconfig->layouts as $layout => $value) {
         if (!isset($this->layouts[$layout])) {
             foreach ($this->parent_configs as $parent_config) {
                 if (isset($parent_config->layouts[$layout])) {
                     $this->layouts[$layout] = $parent_config->layouts[$layout];
                     continue 2;
                 }
             }
             $this->layouts[$layout] = $value;
         }
     }
     //fix arrows if needed
     $this->check_theme_arrows();
 }