ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: ahrasis on February 03, 2015, 10:50:47 am

Title: How these are defined?
Post by: ahrasis on February 03, 2015, 10:50:47 am
I am getting undefined error(s) for $context['latest_post']['link'] and $context['latest_post']['time'].

Code: [Select]
<p class="inline">
', $context['common_stats']['boardindex_total_posts'], '', !empty($settings['show_latest_member']) ? ' - ' . $txt['latest_member'] . ': <strong> ' . $context['common_stats']['latest_member']['link'] . '</strong>' : '', ' - ', $txt['most_online_today'], ': ', comma_format($modSettings['mostOnlineToday']), '<br />
', (!empty($context['latest_post']) ? $txt['latest_post'] . ': <strong>"' . $context['latest_post']['link'] . '"</strong>  ( ' . $context['latest_post']['time'] . ' )' : ''), ' - <a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>
</p>

I can find $context['latest_post'] but how $context['latest_post']['link'] and $context['latest_post']['time'] are defined?

$context['latest_post'] is defined:
Code: [Select]
		// Retrieve the categories and boards.
require_once(SUBSDIR . '/BoardsList.class.php');
$boardIndexOptions = array(
'include_categories' => true,
'base_level' => 0,
'parent_id' => 0,
'set_latest_post' => true,
'countChildPosts' => !empty($modSettings['countChildPosts']),
);
$boardlist = new Boards_List($boardIndexOptions);
$context['categories'] = $boardlist->getBoards();
$context['latest_post'] = $boardlist->getLatestPost();

Any heads up?

My temporary solution is checking whether those $context['latest_post']['link'] and $context['latest_post']['time'] are empty instead.

Code: [Select]
					', (!empty($context['latest_post']['link']) && !empty($context['latest_post']['time']) ? $txt['latest_post'] . ': <strong>"' . $context['latest_post']['link'] . '"</strong>  ( ' . $context['latest_post']['time'] . ' )' : ''), ' - <a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>

Should this be fine?
Title: Re: How these are defined?
Post by: emanuele on February 03, 2015, 11:54:19 am
Where are you getting these errors?
I seem to remember something similar already reported, but that I was unable to pinpoint.

Yes, here it is: http://www.elkarte.net/community/index.php?topic=2027.0
http://www.elkarte.net/community/index.php?topic=1857.0

Looking at the code, it looks like it is related to a...
AHA!
Got it.
When all the categories are collapsed, the array is not set to the board, but just to a piece of it and hence the error.
Try with this change
In BoardIndex.class.php search:
Code: [Select]
		if (empty($this->_latest_post))
and replace it with:
Code: [Select]
		if (empty($this->_latest_post) || empty($this->_latest_post['link']))
Title: Re: How these are defined?
Post by: emanuele on February 03, 2015, 05:41:34 pm
https://github.com/emanuele45/Dialogo/commit/1aa09b5b7ed0cca4855dac66de78fa83c7e2786d
Title: Re: How these are defined?
Post by: ahrasis on February 04, 2015, 12:25:16 am
I think you mean BoardsList.class.php. But I haven't try your solution as it doesn't mention about $context['latest_post']['time'] which is also undefined. Will your solution covers that too or just the $context['latest_post']['link'] undefined error?

Edited - Attempted the suggested fix. So far there is no undefined error for both $context. Will update if there is any.
Title: Re: How these are defined?
Post by: emanuele on February 04, 2015, 03:36:27 am
Yep, sorry!
I mixed BoardIndex.template.php with BoardsList.class.php... :-[