Array Unshift warning

Started by tjbalon, January 19, 2017, 12:28:09 AM

Previous topic - Next topic

tjbalon

Awhile back I made this thread in Coding Discussion: http://www.simplemachines.org/community/index.php?topic=551130.0

We're still seeing this issue, and I'm quite lost how to fix it so I've turned to support now. Basically, any custom page on the website does not have a link tree at the top that says like "Forum Name >>". Because of this, it creates massive warnings in our PHP logs.

[error] 559#559: *5294 FastCGI sent in stderr: "PHP message: PHP Warning:  array_unshift() expects parameter 1 to be array, null given in public_html/Sources/Load.php on line 1798"

Anyone know how we can fix this? I've yet to figure it out and it seems like it's an issue somewhere in the code that displays the link trees in general. If we can either fix the issue in Load.php or re-enable link tree, either would be awesome.

Arantor

No, it's complaining because custom pages aren't done correctly.

The underlying menu code including the link tree handler expects that the array is defined, even if you don't display it and at a minimum it expects there to be an array for it to put something on the start of. Seems like custom pages aren't doing that.

So as a minimum, before the theme loads, declare $context['linktree'] as an array.

If you wanted to provide link tree items for your page -which you probably should for consistency - you can do so by adding items to the array yourself.

You don't need to have the 'Forum Name >' item, SMF does that. But you can add each item from left to right with code similar to the following:


$context['linktree'][] = array(
'name' => 'Page Title',
'url' => $scripturl . '?action=mycustomaction',
);

tjbalon

Quote from: Arantor on January 19, 2017, 03:03:36 AM
No, it's complaining because custom pages aren't done correctly.

The underlying menu code including the link tree handler expects that the array is defined, even if you don't display it and at a minimum it expects there to be an array for it to put something on the start of. Seems like custom pages aren't doing that.

So as a minimum, before the theme loads, declare $context['linktree'] as an array.

If you wanted to provide link tree items for your page -which you probably should for consistency - you can do so by adding items to the array yourself.

You don't need to have the 'Forum Name >' item, SMF does that. But you can add each item from left to right with code similar to the following:


$context['linktree'][] = array(
'name' => 'Page Title',
'url' => $scripturl . '?action=mycustomaction',
);


I cannot seem to find where we disabled linktrees on custom pages originally... any clue where this might be? Right now our custom pages don't show link trees.

ex: https://i.gyazo.com/07cedba084da0c8f08791f16ccc14678.png

Arantor

It's not a case of you disabling it, you didn't set it up in the first place.

tjbalon

Quote from: Arantor on January 19, 2017, 01:52:42 PM
It's not a case of you disabling it, you didn't set it up in the first place.

But originally when we had custom pages, it would show Forum Name >> at the top by default. Makes me think I screwed something up.

So after including header.php, call that context linktree? Or where does that go.

Thanks as always for the help, really appreciate it Arantor.

Arantor

I don't know how your code is set up, but you need to have that line before the theme is loaded.

tjbalon

#6
So, if I use

$context['linktree'][] = array(
);


before I call header.php, We get the Forum Name >> at the top of the page, due to us declaring the array at all. Anyway to get this to go away? Forum pages like this we don't want as integrated into the main website (aka no link trees, that way we can have a more clean white page.


Arantor

I would assume so, though since I have no idea what header.php contains I can't tell you for sure.

Chen Zhen

Prior to calling your header.php file just put:
$context['linktree'] = array();

.. in the default template this is checked if empty and then skips the linktree if it is.
Atm I am assuming your custom template does the same but can't be sure.

Btw am I correct that this is regarding Tango Worldwide using Dream Portal?
If so.. the theme "looks" decent and the user base seems fairly good but what should be declared as XHTML is a mess.
Your template needs a serious makeover.. my validator doesn't even bother listing all errors because there are too many.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

tjbalon

#9
Quote from: Chen Zhen on January 20, 2017, 05:50:50 PM
Prior to calling your header.php file just put:
$context['linktree'] = array();

.. in the default template this is checked if empty and then skips the linktree if it is.
Atm I am assuming your custom template does the same but can't be sure.

Btw am I correct that this is regarding Tango Worldwide using Dream Portal?
If so.. the theme "looks" decent and the user base seems fairly good but what should be declared as XHTML is a mess.
Your template needs a serious makeover.. my validator doesn't even bother listing all errors because there are too many.

New theme is inbound for SMF 2.1 addressing a lot of issues, but we're working on things slowly but surely. Issue is we host 40ish gameservers so, things get piled up on the developer side of things..

$context['linktree'] = array();

Causes it to show the name of the forum at the top of the custom pages.

As for the header.php


<?php


// Which Theme are we using?
$ssi_theme 4;
// Layers to be utilized
$ssi_layers = array('html','body');
// Change "true" to "false" to disable Gzip if not supported on your server
$ssi_gzip true;
//This is the SSI.php file in the Board dir.
require('SSI.php');
//Let's set custom titles
$output '<html><title>%TITLE%</title><body>';

?>



Thanks again for the help guys. Chen are you a dev for simple-portal?

Chen Zhen


Edit the theme's index template and find where it displays the $context['linktree'].
You may need to edit the file so that it checks if the array is empty prior to attempting to display its contents.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Advertisement: