e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
319 stars 213 forks source link

USERTHEME issue, new theme way is not working #4543

Closed Jimmi08 closed 2 years ago

Jimmi08 commented 2 years ago

Bug Description

USERTHEME doesn't work with new 2.3 themes

What I am trying to do

I am using USERTHEME in e_module.php in the plugin (user select skin and sitetheme is changed) . I am aware about layout and menu issues, but this is about something else.

This should be possible because in class2.php is USERTHEME defined after loading e_module addon.

//
// P: THEME LOADING
//

if(!defined('USERTHEME') && !isset($_E107['no_theme']))
{
    $dbg->logTime('Load Theme');
    define('USERTHEME', (e107::getUser()->getPref('sitetheme') && file_exists(e_THEME.e107::getUser()->getPref('sitetheme'). '/theme.php') ? e107::getUser()->getPref('sitetheme') : false));
}

What happens?

  1. any loading files in theme suggested in many other issues fails
$sitetheme = e107::getPref('sitetheme');
require_once(e_THEME.$sitetheme."/xyzfile.php");

It can be fixed with using USERTHEME.

if(defined('USERTHEME')) $sitetheme = USERTHEME;
else $sitetheme = e107::getPref('sitetheme');
  1. header and footer are not loaded it means that with HTML themes USERTHEME is ignored somewhere...

Because if I use some old v1 theme (with theme.php), it works. F.e.: define('USERTHEME', "Rideblue");

How to Reproduce

Steps to reproduce the behavior:

  1. set site theme in theme manager to anything else than bootstrap3
  2. use this define('USERTHEME', "bootstrap3"); in class2.php before define it in class2.php : (or in e_module of any plugin)
    //
    // P: THEME LOADING
    //
    define('USERTHEME', "bootstrap3");
    if(!defined('USERTHEME') && !isset($_E107['no_theme']))

Expected Behavior

Site theme change

Note

There is already correct code how this should work in js_manager.php file:

    /**
     * Get current theme name
     *
     * @return string
     */
    public function getCurrentTheme()
    {
        // XXX - USERTHEME is defined only on user session init
        return ($this->isInAdmin() ? e107::getPref('admintheme') : deftrue('USERTHEME', e107::getPref('sitetheme')));
    }

Any direct using of e107::getPref('sitetheme') for loading something is wrong.

Thanks

CaMer0n commented 2 years ago

Marking as invalid. Tested with define('USERTHEME', 'jayya'); in e_module.php

Resulting source code contains:

<link id="stylesheet-jayya-style" rel="stylesheet" media="all" property="stylesheet" type="text/css" href="/e107v2/e107_themes/jayya/style.css?1634602182" />
Jimmi08 commented 2 years ago

@CaMer0n jayya is not html theme

CaMer0n commented 2 years ago

@Jimmi08

I tested again with your exact steps to reproduce:

defined('USERTHEME', 'bootstrap3'); in class2.php directly after e_module.php loading routine.

(Sitetheme set to "bootstrap5" and running on PHP 8.1)

Resulting source code contains:

<link id="stylesheet-bootstrap3-style" rel="stylesheet" media="all" property="stylesheet" type="text/css" href="/e107v2/e107_themes/bootstrap3/style.css?1634602182" />

THEME constant equals:

./e107_themes/bootstrap3/

You wrote:

I am aware about layout and menu issues, but this is about something else.

Then you would already know that HEADER/FOOTER wont display if the stored layout for the current theme doesn't match a layout by the same name in the "USERTHEME" folder.

header and footer are not loaded it means that with HTML themes USERTHEME is ignored somewhere

No it doesn't. See answer above.

Any direct using of e107::getPref('sitetheme') for loading something is wrong.

Solution: Use the constants provided. THEME, THEME_ABS, USERTHEME.

Jimmi08 commented 2 years ago

Thanks for your time. So USERTHEME is the solution.

Jimmi08 commented 1 year ago

USERTHEME is not defined in admin area

image

Jimmi08 commented 1 year ago

https://github.com/e107inc/e107/discussions/5003