News:

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

Main Menu

Need help to correct error: Invalid argument supplied for foreach()

Started by axa2, December 01, 2013, 12:07:49 AM

Previous topic - Next topic

axa2

My error log for SMF 2.0.6 forum is filling up with this error:  Invalid argument supplied for foreach()

referencing file: /Themes/default/index.template.php

this is the line referenced for the error: foreach ($button_strip as $key => $value) in the following block:

// Create the buttons...
   
$buttons = array();
foreach ($button_strip as $key => $value)
{
    if (!isset($value['test']) || !empty($context[$value['test']]))
        $buttons[] = '
   <li><a' . (isset($value['id']) ? ' id="button_strip_' . $value['id'] . '"' : '') . ' class="button_strip_' . $key . (isset($value['active']) ? ' active' : '') . '" href="' . $value['url'] . '"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '><span>' . $txt[$value['text']] . '</span></a></li>';
}

// No buttons? No button strip either.

Any help would be appreciated as to what is causing the error and suggestions to fix.

Thanks!

Arantor

Well, that's a generic routine called in a bunch of places, so unless you're seeing that issue pretty much every single page, it's probably OK.

What URL(s) is it showing up on?

axa2

Every visitor to any topic is throwing that error. I cannot post a link, the forum is Merchants Accepting Bitcoin.

Arantor

I don't actually want a link, I just wanted to establish whether it was every page or not - since other pages, like the list of topics in board, aren't throwing the error, that means it's just the display code.

What mods have you installed?

axa2

List of mods installed:

Enotify 2.0.2
SMFPacks Shoutbox 1.0.4
More Spiders 1.2
Forum Firewall 1.1.6
Pretty URLs 1.0
Hide ip stuff for users 1.0.4
Register at Post View 1.1
Quick Ban on Account Delete 1.0.1
Optimus Brve 1.8.6.2
Separate the sticky topics 1.0.0
H1 Tags in link tree    1.1
RSS Feed Icon    1.1
Related Topics    1.401
Google +1 Topics    1.0
Simple Audio Video Embedder    2.1.1
Add Social Media Icons To Profiles    1.1.0
Custom Copyright    1.0.3
Most Recent Posts    1.0
Contact Page    3.2
PM to New Members    1.2
H1 BBCode    1.1
Add Twitter Tweet Button to Posts    1.1

Arantor

Well, the H1 tag mods are a bad idea, they will damage your SEO - but they're unrelated to this problem.

Please can you attach the Display.template.php file from your theme (or failing that, Themes/default/Display.template.php)?

axa2


Arantor

Your file is damaged and the damage is unlikely to have been made by a mod.

At the bottom of the topic are moderation buttons - move topic, remove topic, lock topic etc.

The definition for them has been removed, as though it had been cut down - and unsurprisingly it's going to break things if you do that.

Your file has:
// Show the page index... "Pages: [1]".
echo '
<div class="pagesection">
', template_button_strip($normal_buttons, 'right'), '
<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], !empty($modSettings['topbottomEnable']) ? $context['menu_separator'] . ' &nbsp;&nbsp;<a href="#top"><strong>' . $txt['go_up'] . '</strong></a>' : '', '</div>
<div class="nextlinks_bottom">', $context['previous_next'], '</div>
</div>';



// Restore topic. eh?  No monkey business.
if ($context['can_restore_topic'])
$mod_buttons[] = array('text' => 'restore_topic', 'image' => '', 'lang' => true, 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);

// Allow adding new mod buttons easily.
call_integration_hook('integrate_mod_buttons', array(&$mod_buttons));

echo '
<div id="moderationbuttons">', template_button_strip($mod_buttons, 'bottom', array('id' => 'moderationbuttons_strip')), '</div>';


The stock file has:
// Show the page index... "Pages: [1]".
echo '
<div class="pagesection">
', template_button_strip($normal_buttons, 'right'), '
<div class="pagelinks floatleft">', $txt['pages'], ': ', $context['page_index'], !empty($modSettings['topbottomEnable']) ? $context['menu_separator'] . ' &nbsp;&nbsp;<a href="#top"><strong>' . $txt['go_up'] . '</strong></a>' : '', '</div>
<div class="nextlinks_bottom">', $context['previous_next'], '</div>
</div>';

// Show the lower breadcrumbs.
theme_linktree();

$mod_buttons = array(
'move' => array('test' => 'can_move', 'text' => 'move_topic', 'image' => 'admin_move.gif', 'lang' => true, 'url' => $scripturl . '?action=movetopic;topic=' . $context['current_topic'] . '.0'),
'delete' => array('test' => 'can_delete', 'text' => 'remove_topic', 'image' => 'admin_rem.gif', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['are_sure_remove_topic'] . '\');"', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']),
'lock' => array('test' => 'can_lock', 'text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.gif', 'lang' => true, 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
'sticky' => array('test' => 'can_sticky', 'text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.gif', 'lang' => true, 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
'merge' => array('test' => 'can_merge', 'text' => 'merge', 'image' => 'merge.gif', 'lang' => true, 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']),
'calendar' => array('test' => 'calendar_post', 'text' => 'calendar_link', 'image' => 'linktocal.gif', 'lang' => true, 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'),
);

// Restore topic. eh?  No monkey business.
if ($context['can_restore_topic'])
$mod_buttons[] = array('text' => 'restore_topic', 'image' => '', 'lang' => true, 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);

// Allow adding new mod buttons easily.
call_integration_hook('integrate_mod_buttons', array(&$mod_buttons));

echo '
<div id="moderationbuttons">', template_button_strip($mod_buttons, 'bottom', array('id' => 'moderationbuttons_strip')), '</div>';


So you've removed the link tree and in the process removed the definition of $mod_buttons which is what causes template_button_strip to complain that $mod_buttons isn't defined.

axa2

I have no clue, since I never edited the file at all. Had to have happened while adding or removing a mod. I put the missing code back in and no longer getting errors, thanks very much for your help!

Arantor

Except no mod would actually do that, because if a mod did that, it would not be able to be uninstalled after.

Advertisement: