Forums | Mahara Community

Developers /
get_all_theme_objects and directory with dot


Yaju Mahida's profile picture
Posts: 131

05 October 2011, 0:41

We use subversion and under each sub-directory of Mahara a directory called .svn is created by it.

The logic in the function get_all_theme_objects and $subdir != "." && $subdir != ".." doesn't skip .svn directory which generates [WAR] 09 (lib/mahara.php:639) The name of the theme '.svn' contains invalid characters.

I have modified the logic as  if (substr($subdir, 0, 1) != "." && is_dir($themebase . $subdir))  which solves the issue - ignores all directories with dot and double dots.

Want feedback on this and also if useful please include this in Mahara.

I have provided patch with this patch.

function get_all_theme_objects() {
    static $themes = null;

    if (is_null($themes)) {
        $themes = array();
        $themebase = get_config('docroot') . 'theme/';
        if (!$themedir = opendir($themebase)) {
            throw new SystemException('Unable to read theme directory '.$themebase);
        }
        while (false !== ($subdir = readdir($themedir))) {
            /*Fails to ignore .svn directory. Modified to avoid unnecessary warning message.*/
            if (substr($subdir, 0, 1) != "." && is_dir($themebase . $subdir)) {
                // is the theme directory name valid?
                if (!Theme::name_is_valid($subdir)) {
                    log_warn(get_string('themenameinvalid', 'error', $subdir));
                } else {
                    $config_path = $themebase . $subdir . '/themeconfig.php';
                    if (is_readable($config_path)) {
                        require($config_path);
                        if (empty($theme->disabled) || !$theme->disabled) {
                            $themes[$subdir] = $theme;
                        }
                    }
                }
            }
        }
        closedir($themedir);
        asort($themes);
    }

    return $themes;
}

anonymous profile picture
Account deleted
Posts: 214

05 October 2011, 9:47

Hi Yaju,

The content of the patch looks fine. In Mahara, we use git rather than subversion so haven't hit this issue before.

If you want to have this included in mahara, there are two ways you can do so:

  • submit the patch to our review system - https://reviews.mahara.org; or
  • raise a bug and attach your patch in the bug tracker (I can do this if you prefer).

Just a few points to note:

  • the comment is probably not required in this case; and
  • please don't use hard tabs :)

You might want to read the coding guidelines (https://wiki.mahara.org/index.php/Developer_Area/Coding_guidelines) and the contributing code page (https://wiki.mahara.org/index.php/Developer_Area/Contributing_Code) for more information.

Thanks for the patch,

Andrew

Yaju Mahida's profile picture
Posts: 131
3 results