Moodle

Theme directory

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.9
  • Fix Version/s: None
  • Component/s: Themes
  • Labels:
    None
  • Affected Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE

Description

Link: http://docs.moodle.org/en/Theme_directory

Currently we can change theme directory by using following two variables.

$CFG->themewww
$CFG->themedir

this works well if the new directory is parallel to theme directory or in root of moodle.
e.g. /moodle/<newtheme>

but this won't work in case where new directory in not in root.
e.g. /moodle/<dir>/<newtheme>

This is because themes in Moodle calls Moodle config file from styles.php (may be in some other files too)
require_once("../../config.php");

It would be nice if Moodle theme don't require Moodle's config file.

Activity

Hide
Eloy Lafuente (stronk7) added a comment -

Hi jai,

the reason for that being included there is that the styles.php script is called from all Moodle pages, in order to include the needed css contents. And all pages that are directly invoked MUST include config.php in order to get access to all the Moodle stuff (APIs, global objects and so on).

So I really think it isn't possible to avoid that require_once().

Anyway... where is the point about not to use the "theme" directory to store themes? It's like not using the "mod" dir to store modules and so on.

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi jai, the reason for that being included there is that the styles.php script is called from all Moodle pages, in order to include the needed css contents. And all pages that are directly invoked MUST include config.php in order to get access to all the Moodle stuff (APIs, global objects and so on). So I really think it isn't possible to avoid that require_once(). Anyway... where is the point about not to use the "theme" directory to store themes? It's like not using the "mod" dir to store modules and so on. Ciao
Hide
jai gupta added a comment -

Hi Eloy,

I agree with the fact that styles.php is called from moodle to include theme css but what I don't understand is why is it not possible to include css files directly in Moodle pages.

My aim is not to change default dir e.g "theme" or "mod" but I want to remove the limitations which exists with the solution provided on http://docs.moodle.org/en/Theme_directory.

The problem is because we need to include config.php file in theme when we move/change the location of theme folder using variables $CFG->themewww and CFG->themedir we need to update all themes, all files to make this work.

Suppose someone is teaching theme designing and he wants allows users to upload theme then all users should know the path of config.php and also including config.php may be a security risk in this case.

Show
jai gupta added a comment - Hi Eloy, I agree with the fact that styles.php is called from moodle to include theme css but what I don't understand is why is it not possible to include css files directly in Moodle pages. My aim is not to change default dir e.g "theme" or "mod" but I want to remove the limitations which exists with the solution provided on http://docs.moodle.org/en/Theme_directory. The problem is because we need to include config.php file in theme when we move/change the location of theme folder using variables $CFG->themewww and CFG->themedir we need to update all themes, all files to make this work. Suppose someone is teaching theme designing and he wants allows users to upload theme then all users should know the path of config.php and also including config.php may be a security risk in this case.
Hide
Tim Hunt added a comment -

Themes have to go inside the themes folder. That is how Moodle is designed to work. Same for all plugins, as Eloy says.

Your example of teaching theme creation is a bad one. You should not allow students to edit files directly on your server. That way lies huge security risks. Instead, each student should be using their own Moodle install. For example, using the windows installer packages.

Show
Tim Hunt added a comment - Themes have to go inside the themes folder. That is how Moodle is designed to work. Same for all plugins, as Eloy says. Your example of teaching theme creation is a bad one. You should not allow students to edit files directly on your server. That way lies huge security risks. Instead, each student should be using their own Moodle install. For example, using the windows installer packages.
Hide
Federico Heinz added a comment -

I realize this is issue has been marked as "won't fix", but I'd like to ask you to reconsider this decision.

Maybe Jay' s use case of teaching theme development isn't the best example, but Tim's retort that "Themes have to go in the themes folder because that is how Moodle is designed to work" flies on the face of the information contained in the Theme directory guide.

Of course, we cannot get rid of the require_once of config.php in styles.php, but it should be done in such a fashion that it works independently of where the theme is stored. I have a good use case for this: take a Moodle hosting site that wants to keep a single copy of Moodle on the disk, to make maintainance easier.

There's a nice discussion of why and how you might want to do this over at Moodle's general development forum. The solution proposed by Martin Langhoff in that thread has a serious drawback, though: the moodle root directory ends up littered with dozens of config_foo.php files. A better solution, borrowed from Drupal, is to keep virtual host-specific configuration for site foo in a directory sites/foo. Under such a scheme, the site-specific configuration for site foo is in sites/foo/config.php, while the same information for site bar is in sites/bar/config.php

Now, in such a setup, you may not want the administrator of every virtual host to be able to use the theme of every other virtual host on that particular machine — that would be bad, you may end up with your customers impersonating one another. Also, you may want to provide your users with access to upload themes to their own theme directory, without upsetting other users' theme collection. A nice extension of the same idea expressed in the previous paragraph would be to use $CFG->themedir to have a site-specific themes directory at sites/foo/themes, sites/bar/themes, and so on. Unfortunately, this doesn't work because the require_once on themes' styles.php scripts expects config.php to be exactly two directory levels above the theme, not four as in this case.

The desired effect can be achieved my placing the site-specific theme directory directly in Moodle's root, but the result is not pretty: a profusion of theme-foo and theme-bar directories cluttering up Moodle's root, and a nuisance whenever you do an upgrade and have to copy all those folders over to the new instalation (instead of just copying the one directory sites).

So, please, I ask you to reconsider this issue as a bug worth solving, not by avoiding the inevitable require_once of config.php , but rather by putting into place some way to find config.php that doesn't rely simply on ../../config.php being the right one (and failing if no such file is there).

Show
Federico Heinz added a comment - I realize this is issue has been marked as "won't fix", but I'd like to ask you to reconsider this decision. Maybe Jay' s use case of teaching theme development isn't the best example, but Tim's retort that "Themes have to go in the themes folder because that is how Moodle is designed to work" flies on the face of the information contained in the Theme directory guide. Of course, we cannot get rid of the require_once of config.php in styles.php, but it should be done in such a fashion that it works independently of where the theme is stored. I have a good use case for this: take a Moodle hosting site that wants to keep a single copy of Moodle on the disk, to make maintainance easier. There's a nice discussion of why and how you might want to do this over at Moodle's general development forum. The solution proposed by Martin Langhoff in that thread has a serious drawback, though: the moodle root directory ends up littered with dozens of config_foo.php files. A better solution, borrowed from Drupal, is to keep virtual host-specific configuration for site foo in a directory sites/foo. Under such a scheme, the site-specific configuration for site foo is in sites/foo/config.php, while the same information for site bar is in sites/bar/config.php Now, in such a setup, you may not want the administrator of every virtual host to be able to use the theme of every other virtual host on that particular machine — that would be bad, you may end up with your customers impersonating one another. Also, you may want to provide your users with access to upload themes to their own theme directory, without upsetting other users' theme collection. A nice extension of the same idea expressed in the previous paragraph would be to use $CFG->themedir to have a site-specific themes directory at sites/foo/themes, sites/bar/themes, and so on. Unfortunately, this doesn't work because the require_once on themes' styles.php scripts expects config.php to be exactly two directory levels above the theme, not four as in this case. The desired effect can be achieved my placing the site-specific theme directory directly in Moodle's root, but the result is not pretty: a profusion of theme-foo and theme-bar directories cluttering up Moodle's root, and a nuisance whenever you do an upgrade and have to copy all those folders over to the new instalation (instead of just copying the one directory sites). So, please, I ask you to reconsider this issue as a bug worth solving, not by avoiding the inevitable require_once of config.php , but rather by putting into place some way to find config.php that doesn't rely simply on ../../config.php being the right one (and failing if no such file is there).
Hide
Tim Hunt added a comment -

Things have moved on a lot since 3rd February (as has my knowledge of Moodle's themes system). Have you been following the changes relating to themes that are being made for Moodle 2.0. I think they do everything you want. The latest batch of work is MDL-20204.

Show
Tim Hunt added a comment - Things have moved on a lot since 3rd February (as has my knowledge of Moodle's themes system). Have you been following the changes relating to themes that are being made for Moodle 2.0. I think they do everything you want. The latest batch of work is MDL-20204.
Hide
Federico Heinz added a comment -

Thanks for pointing me in that direction, Tim. Indeed, MDL-20799 would solve the problem, and in a very clean fashion.

Show
Federico Heinz added a comment - Thanks for pointing me in that direction, Tim. Indeed, MDL-20799 would solve the problem, and in a very clean fashion.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: