Exemple #1
0
 }
 $filesystem = new FileSystemTree(G_THEMESPATH, true);
 foreach (new EfrontDirectoryOnlyFilterIterator(new ArrayIterator($filesystem->tree)) as $key => $value) {
     //Automatically import themes that don't have an equivalent database representation
     if (!in_array($value['name'], $themeNames)) {
         try {
             $file = new EfrontFile($value['path'] . "/theme.xml");
             $xmlValues = themes::parseFile($file);
             $newTheme = themes::create($xmlValues);
             //$themes[$newTheme -> themes['id']] = $newTheme -> themes;
         } catch (Exception $e) {
             /*Don't halt for themes that can't be processed*/
         }
     }
 }
 $themes = themes::getAll("themes");
 foreach ($themes as $value) {
     $themeNames[] = $value->themes['name'];
     //$browserThemes[$value['id']] = $value['options']['browsers'];
     foreach ($allBrowsers as $browser => $foo) {
         if (isset($value->options['browsers'][$browser])) {
             $usedBrowsers[$browser] = $value->themes['id'];
             unset($allBrowsers[$browser]);
         }
     }
 }
 foreach ($allBrowsers as $key => $foo) {
     $currentSetTheme->options['browsers'][$key] = 1;
     $themes[$currentSetTheme->themes['id']]->options['browsers'][$key] = 1;
 }
 $legalValues = array_merge(array_keys($themes), $themeNames);
/**
 * Setup themes
 *
 * This function sets up all the required constants and initiates objects
 * accordingly, to initialize the current theme
 *
 * @since 3.6.0
 */
function setupThemes()
{
    /** The default theme path*/
    define("G_DEFAULTTHEMEPATH", G_THEMESPATH . "default/");
    /** The default theme url*/
    define("G_DEFAULTTHEMEURL", "themes/default/");
    try {
        $allThemes = themes::getAll();
        if (isset($_GET['preview_theme'])) {
            try {
                $currentTheme = new themes($_GET['preview_theme']);
            } catch (Exception $e) {
            }
        } elseif (isset($_SESSION['s_theme'])) {
            if (!empty($allThemes[$_SESSION['s_theme']])) {
                $currentTheme = $allThemes[$_SESSION['s_theme']];
            } else {
                $currentTheme = new themes($_SESSION['s_theme']);
            }
        } else {
            if (!empty($allThemes[$GLOBALS['configuration']['theme']])) {
                $currentTheme = $allThemes[$GLOBALS['configuration']['theme']];
            } else {
                $currentTheme = new themes($GLOBALS['configuration']['theme']);
            }
            $browser = detectBrowser();
            foreach ($allThemes as $value) {
                if (isset($value->options['browsers'][$browser])) {
                    try {
                        $browserTheme = $allThemes[$value->themes['id']];
                        $currentTheme = $browserTheme;
                    } catch (Exception $e) {
                    }
                }
            }
            foreach (eF_loadAllModules(true, true) as $module) {
                try {
                    if ($moduleTheme = $module->onSetTheme($currentTheme)) {
                        if (!$moduleTheme instanceof themes) {
                            $currentTheme = new themes($moduleTheme);
                        } else {
                            $currentTheme = $moduleTheme;
                        }
                    }
                } catch (Exception $e) {
                }
            }
            $_SESSION['s_theme'] = $currentTheme->{$currentTheme->entity}['id'];
        }
    } catch (Exception $e) {
        try {
            $result = eF_getTableData("themes", "*", "name = 'default'");
            if (sizeof($result) == 0) {
                throw new Exception();
                //To be caught right below. This way, the catch() code gets executed either if the result is empty or if there is a db error
            }
        } catch (Exception $e) {
            $file = new EfrontFile(G_DEFAULTTHEMEPATH . "theme.xml");
            themes::create(themes::parseFile($file));
        }
        $currentTheme = new themes('default');
    }
    $currentThemeName = $currentTheme->{$currentTheme->entity}['name'];
    /**The current theme*/
    define("G_CURRENTTHEME", $currentThemeName);
    /** The current theme path*/
    define("G_CURRENTTHEMEPATH", !isset($currentTheme->remote) || !$currentTheme->remote ? G_THEMESPATH . $currentTheme->{$currentTheme->entity}['path'] : $currentTheme->{$currentTheme->entity}['path']);
    /** The current theme url*/
    define("G_CURRENTTHEMEURL", !isset($currentTheme->remote) || !$currentTheme->remote ? "themes/" . $currentTheme->themes['path'] : $currentTheme->{$currentTheme->entity}['path']);
    /** The external pages path*/
    define("G_EXTERNALPATH", rtrim(G_CURRENTTHEMEPATH, '/') . "/external/");
    is_dir(G_EXTERNALPATH) or mkdir(G_EXTERNALPATH, 0755);
    /** The external pages link*/
    define("G_EXTERNALURL", rtrim(G_CURRENTTHEMEURL, '/') . "/external/");
    if ($fp = fopen(G_CURRENTTHEMEPATH . "css/css_global.css", 'r')) {
        /** The current theme's css*/
        define("G_CURRENTTHEMECSS", G_CURRENTTHEMEURL . "css/css_global.css?build=" . G_BUILD);
        fclose($fp);
    } else {
        /** The current theme's css*/
        define("G_CURRENTTHEMECSS", G_DEFAULTTHEMEURL . "css/css_global.css?build=" . G_BUILD);
    }
    /** The folder where the template compiled and cached files are kept*/
    define("G_THEMECACHE", G_ROOTPATH . "libraries/smarty/themes_cache/");
    /** The folder of the current theme's compiled files*/
    define("G_CURRENTTHEMECACHE", G_THEMECACHE . $currentThemeName . "/");
    /** The full filesystem path of the images directory*/
    define("G_IMAGESPATH", G_CURRENTTHEMEPATH . "images/");
    /** The full filesystem path of the images directory, in the default theme*/
    define("G_DEFAULTIMAGESPATH", G_DEFAULTTHEMEPATH . "images/");
    /** The users' avatars directory*/
    define("G_AVATARSPATH", G_IMAGESPATH . "avatars/");
    if (is_dir(G_AVATARSPATH . "system_avatars/")) {
        /*system avatars path*/
        define("G_SYSTEMAVATARSPATH", G_AVATARSPATH . "system_avatars/");
        /*system avatars URL*/
        define("G_SYSTEMAVATARSURL", G_CURRENTTHEMEURL . "images/avatars/system_avatars/");
    } else {
        /*system avatars path*/
        define("G_SYSTEMAVATARSPATH", G_DEFAULTTHEMEPATH . "images/avatars/system_avatars/");
        /*system avatars URL*/
        define("G_SYSTEMAVATARSURL", G_DEFAULTTHEMEURL . "images/avatars/system_avatars/");
    }
    /** The logo path*/
    define("G_LOGOPATH", G_DEFAULTIMAGESPATH . "logo/");
    return $currentTheme;
}