News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

setupThemeContext in XML?

Started by live627, November 11, 2010, 01:56:43 PM

Previous topic - Next topic

live627

So today I was hammered by a huge blitz of errors in the SMF log. After some extensive debugging and tearing my hair out I fixed it (and yes, there's a whole world of difference between a fix and a quick patch).

The errors were mysterious. Came from something I built, with an error from someone else's work. A recursive XML call was generating undefined language errors for menu items. SAY WHAT!?

Then I thought, the menu was being loaded while the custom language file was not. I could've just loaded the missing file and be done with it. But no, I wanted to find the ROOT CAUSE of the issue. I knew what to do. I added a code block to setupMenuContext().

if (isset($_REQUEST['xml']))
{
trigger_error(var_export(debug_backtrace(), true));
return;
}


What I got:

1024: array (
0 =>
array (
'file' => '/public_html/Sources/Subs.php',
'line' => 3318,
'function' => 'setupMenuContext',
'args' =>
array (
),
),
1 =>
array (
'file' => '/public_html/Sources/Subs.php',
'line' => 3396,
'function' => 'setupThemeContext',
'args' =>
array (
),
),
2 =>
array (
'file' => '/public_html/Sources/Subs.php',
'line' => 2853,
'function' => 'template_header',
'args' =>
array (
),
),
3 =>
array (
'file' => '/public_html/index.php',
'line' => 166,
'function' => 'obExit',
'args' =>
array (
0 => NULL,
1 => NULL,
2 => true,
),
),
)


The answer to the problem lie right there! Now, there's not too much to be messed with, because XML output needs the bulk of the functions listed above to render templates and sub-templates. That leaves one possibility.

if (!isset($_REQUEST['xml']))
setupThemeContext();


Add that code to the beginning of template_header() and you're done.




I know I've rambled bit this bug and its devastating results are not very obvious.

[SiNaN]

Would you post a sample code that triggers the errors?
Former SMF Core Developer | My Mods | SimplePortal

live627

No. But it's very easy to trigger the error.

In your menu, put a string that is in a language file loaded in default mode but not loaded in XML.

Does XML need the extra overhead provided by the menu?

Joshua Dickerson

You have confused me with this report. It looks like you did your homework but I am not going to track it unless I understand the issue better. What errors did it cause?
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

live627

I'm now wondering if this is a symptom, rather than the cause. Is the theme loaded while strictly in XML mode? I  don't remember.

Joshua Dickerson

Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

live627

Hmm. Well, the gist of this bug report is that the menu gets loaded even iin XML mode. But it isn't used as far as I know.

Joshua Dickerson

I don't see a reason for loading the menu but I'll wait for some other devs to weigh in on it before tracking it.
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

Arantor

There are some things in the XML theme that do rely on setupThemeContext, so blocking that function is a no-go. There's also some 'making permissions clearly available in context' stuff done in the menu code, so I wouldn't be happy moving that either.

A broader scale refactoring on the other hand would make this issue trivial to clean up :( But unfortunately that's not really something we can deal with in 2.1.

What I can say is that anything adding to the menu should be either directly editing the file mod-fashion (and thus putting their language stuff in index.language.php) or using a hook whereupon they can tell it to load the language file (or not bother, as appropriate)

Advertisement: