TinyPortal

Development => Block Codes => Topic started by: sangham.net on April 24, 2013, 07:03:18 PM

Title: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on April 24, 2013, 07:03:18 PM
Dear TPortal fans and friends,

I hope I posted it in the right section, if not please apologize.

I had a lot of errors and could now find out that it was caused or caused to came up by a TP standard block called "recent topic"

Code ("don't use code not sure if ok or not!") Select
global $context, $modSettings, $txt;
$context['TPortal']['recentboxnum'] = '15';

if(isset($modSettings['recycle_board']))
$bb = $modSettings['recycle_board'];

$what = ssi_recentTopics($context['TPortal']['recentboxnum'], NULL, NULL, 'array');
$counter=1;
$cmax = count($what);

echo '
<div style="width: 100%; overflow: auto; height: 30ex;">';

foreach($what as $w)
{
echo '
<div class="smalltext"><a href="'.$w['href'].'">' . $w['short_subject'] . '</a></div>
<div class="smalltext">', $txt['by'], ' <b>', $w['poster']['link'], '</b></div>
<div class="smalltext">';
if(!$w['new'])
echo '<a href="'.$w['href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '['.$w['time'].']
</div>';

if($counter != $cmax)
echo '<hr />';
$counter++;
}
echo '
</div>';


The error I got in the error log was:
"8: Undefined variable: settings"
21 File: .../Themes/default/languages/TPortal.german-utf8.php (tp_above sub template - eval?)


May questions - beside the intention to inform and share - are:

Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: Freddy on April 24, 2013, 07:20:07 PM
Is the block working as it should ?


To try to get rid of the error in the log change :

global $context, $modSettings, $txt;

to

global $context, $modSettings, $txt, $settings;
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on April 25, 2013, 03:54:40 AM
Thanks for your answer Freddy.

I have already deactivated it. Before, it seemed to work well. It showed topics where presently are new posts.

Thanks for your hint, in regard of the change. Since I am not very familiar with programming, I assume its meant in a kind of log.php file or another php file. Is that right?

Another thing is, that I previously had tried to raise the question on SMF-support forum (http://www.simplemachines.org/community/index.php?topic=502364.0), as I thought that it is a SMF issue. There I got the hint, that it could be a block that could cause the "problem". So I proved it, by turning on and of all blocks, one after the other and found out that it has troubles with this block.

So now it just seems that two things do not work well together. I hope that does not cause any "We are right and you are wrong" discussions between specialists, as such easy could happen. Maybe there are smooth alternatives.

Thanks a lot for your advices.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: IchBin on April 25, 2013, 06:09:03 AM
$settings is a global variable used by SMF and TP. Since it seems to be referencing your German language file, I'd suggest checking that file to see if the $settings variable is inside of it. If it is, add the $settings variable to the global line at the top of the file. If there is no global line, just add this then.

global $settings;
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on April 25, 2013, 06:43:36 AM
Thanks a lot for your suggestion. No, it is not exclusively referring to the German language file:

"8: Undefined variable: settings"
File: .../Themes/default/languages/TPortal.english-utf8.php (tp_above sub template - eval?)
line:: 21


I will look at the files anyway, thanks for the hint.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on April 25, 2013, 07:07:31 AM
I looked at the file (english), TPortal.english-utf8.php and as you assumed, there is no $settings within it.

*/

global $txt, $context, $scripturl;

// Navigation... //
// Rev 89


A German file does not exist in the default folder, since the defalt language is English, I guess. So you think it is caused by the "invalide" text php. Maybe I have an old version or would that need to be fixed in all language php's?

Correction, I looked into the folder ../forum/Themes/default/languages/... instead of ...Themes/default/languages/... (although I don't understand its function, of this two different folders)
A file german language file exists here as well as all other language files.

here the english in the theme default folder
<?php
/**
 * @package TinyPortal
 * @version 1.0
 * @author IchBin - http://www.tinyportal.net
 * @founder Bloc
 * @license MPL 2.0
 *
 * The contents of this file are subject to the Mozilla Public License Version 2.0
 * (the "License"); you may not use this package except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Copyright (C) 2012 - The TinyPortal Team
 *
 */

global $txt$context$scripturl;


here the german

<?php
// Version: 1.0 beta4
// German Translation V. 1.0 by The_Gentleman
// TPortal

// Navigation... //
// Rev 89
$txt['tp-admin9'] = 'TP Downloads';


it seems to miss the global setting total

The Swedish does not seem to have it either:

<?php
// Version: 1Beta4; TPortal

// Navigation... //
// Rev 89
$txt['tp-admin9'] = 'Filer';


Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on April 25, 2013, 10:24:14 AM
I have add the $setting in both English files, once in /forum/Themes/default/languages/... and in ...Themes/default/languages/

Still the error arises as soon as I enable this block. ".../Themes/default/languages/TPortal.english-utf8.php"

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)

Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: IchBin on April 27, 2013, 05:20:44 AM
Turn off the template eval option in SMF Admin > Server settings. This will hopefully show you a different error with a more specific place to find the error.
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on April 27, 2013, 05:30:15 AM
Thanks for your advice, IchBin.

Somebody told me that already, still I am a "chicken" in regard of this as there is a heavy warning sentence to change settings there. That's why I tried to figure it out in any other way first. To turn it on again will be no problem, will it? Sorry for being such a scary chicken.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on April 27, 2013, 11:56:00 AM
Ok, the chicken did it at least. I got this now in the error log, as soon as I enable the block with every page view event (link).

8: Undefined variable: settings
File: .../Themes/default/TPsubs.template.php(127) : eval()'d code
Line: 21


Here also code areas in relation to Line 21 und (127):


Code ("TPsubs.template.php - line 18 - 30") Select
// TPortal searchblock
function TPortal_searchbox()
{
global $context, $txt, $scripturl;

echo '
<form accept-charset="', $context['character_set'], '" action="', $scripturl, '?action=search2" method="post" style="padding: 0; text-align: center; margin: 0; ">
<input type="text" name="search" value="" class="block_search" />
<input type="submit" name="submit" value="', $txt['search'], '" class="block_search_submit" /><br />
<br /><span class="smalltext"><a href="', $scripturl, '?action=search;advanced">', $txt['search_advanced'], '</a></span>
<input type="hidden" name="advanced" value="0" />
</form>';
}


Code ("TPsubs.template.php - line 120 - 128") Select
// php blocktype
function TPortal_phpbox()
{
global $context;

// execute what is in the block, no echoing
if(!empty($context['TPortal']['phpboxbody']));
eval(tp_convertphp($context['TPortal']['phpboxbody'],true));
}


(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: IchBin on April 29, 2013, 08:41:55 PM
This part eval()'d code in your error means that you have some code in a custom php block that has this error in it. You need to find out which block it is, and then post the code of that block here if you don't know how to fix it.
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on May 03, 2013, 06:28:41 AM
Dear IchBin,

It must be in the standard "recent Topic" Block (here:), since it only happens if this block is activated.

Code ("recent Topic") Select
global $context, $modSettings, $txt;
$context['TPortal']['recentboxnum'] = '15';

if(isset($modSettings['recycle_board']))
$bb = $modSettings['recycle_board'];

$what = ssi_recentTopics($context['TPortal']['recentboxnum'], NULL, NULL, 'array');
$counter=1;
$cmax = count($what);

echo '
<div style="width: 100%; overflow: auto; height: 30ex;">';

foreach($what as $w)
{
echo '
<div class="smalltext"><a href="'.$w['href'].'">' . $w['short_subject'] . '</a></div>
<div class="smalltext">', $txt['by'], ' <b>', $w['poster']['link'], '</b></div>
<div class="smalltext">';
if(!$w['new'])
echo '<a href="'.$w['href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '['.$w['time'].']
</div>';

if($counter != $cmax)
echo '<hr />';
$counter++;
}
echo '
</div>';


Thanks for your care.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: IchBin on May 03, 2013, 04:01:37 PM
Change
global $context, $modSettings, $txt;

to this:
global $context, $modSettings, $txt, $settings;
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on May 03, 2013, 04:13:16 PM
Everything perfect with this block and error now!

Thank you very much!

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: Freddy on May 03, 2013, 04:15:42 PM
I did say that originally ;)
Title: Re: "recent Topic" Block "problem" - 8: Undefined variable: settings
Post by: sangham.net on May 03, 2013, 04:24:17 PM
Freddy, No doubt... somehow I thought I had to change anywhere anything special... Right in front of the eye unseen.
Thanks and sorry for not understanding the first answer rightly and causing so much other directions of thought and investigations.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fsangham.net%2FSmileys%2Fsadhu_sangham_sw.gif&hash=e3299fe21483bdca6cf59bd25a8c6109b379e840)