Has anyone improved /main_block.png to have transparent rounded edges?

Started by Biology Forums, August 30, 2019, 11:35:58 AM

Previous topic - Next topic

Antechinus

Ok. Looks alright. I assume the text is showing up on the current theme page too. Should be:

$txt['header_logo_width'] = 'Maximum width of logo image';
$txt['header_logo_width_desc'] = 'As % of theme width. Use any number up to 100. Defaults to 100% if left blank.';

lurkalot

Thanks for checking. 

Strange thing is since I reported that error I can't reproduce it.  I'll keep an eye on it and see if it reoccurs.  ???

Antechinus


Diego Andrés

If the error pointed the index.template.php is possibly because the setting wasn't being checked with !empty which will led to an error if the value is actually not available (usually on a first installation) but won't come back to the error log once it's saved even as an empty field because it will exist in the db after that.

SMF Tricks - Free & Premium Responsive Themes for SMF.

lurkalot

Quote from: Diego Andrés on October 11, 2019, 11:55:23 PM
If the error pointed the index.template.php is possibly because the setting wasn't being checked with !empty which will led to an error if the value is actually not available (usually on a first installation) but won't come back to the error log once it's saved even as an empty field because it will exist in the db after that.

Thanks.  I think that was indeed the problem, because I was playing with that setting after I reported the error, which is why I can no longer reproduce it.

Antechinus

This is the relevant code from index.template.php:

<h1 id="forum_title" class="image_banner">
<a href="'. $scripturl. '">
<img id="forum_banner" style="max-width:',!empty(($settings['header_logo_width']) && ($settings['header_logo_width'] < 100)) ? $settings['header_logo_width']. '%;"' : '100%;"', ' src="', $context['header_logo_url_html_safe'], '" alt="', $context['forum_name'], '" />
</a>
</h1>';

Arantor

Yeah, that's not going to work for you.


<h1 id="forum_title" class="image_banner">
<a href="'. $scripturl. '">
<img id="forum_banner" style="max-width:',!empty($settings['header_logo_width']) && $settings['header_logo_width'] < 100 ? $settings['header_logo_width']. '%;"' : '100%;"', ' src="', $context['header_logo_url_html_safe'], '" alt="', $context['forum_name'], '" />
</a>
</h1>';


You had the variable not being set check plus the size check rolled into the empty() check which meant it would always look at the size regardless.

lurkalot

Although the reported error above seems to have stopped I just visited the log again and now see two different ones.

8: Undefined index: menu_data_ 
https://cctestsite.info/forums/index.php?action=admin
File: /home/c-------/public_html/cctestsite.info/forums/Themes/Ant_Curve_CSS3_RC3/index.template.php - Line: 181

8: Undefined index: max_menu_id 
https://cctestsite.info/forums/index.php?action=admin
File: /home/c-------/public_html/cctestsite.info/forums/Themes/Ant_Curve_CSS3_RC3/index.template.php - Line: 181

Antechinus

Quote from: Arantor on October 12, 2019, 07:24:29 AM
Yeah, that's not going to work for you.


<h1 id="forum_title" class="image_banner">
<a href="'. $scripturl. '">
<img id="forum_banner" style="max-width:',!empty($settings['header_logo_width']) && $settings['header_logo_width'] < 100 ? $settings['header_logo_width']. '%;"' : '100%;"', ' src="', $context['header_logo_url_html_safe'], '" alt="', $context['forum_name'], '" />
</a>
</h1>';


You had the variable not being set check plus the size check rolled into the empty() check which meant it would always look at the size regardless.

Well it seems to be working perfectly on local. No errors at all, as far as I can tell. I've tested it with no banner, partial width banner, and full width banner. Set to one of those, go jumping all over the forum interface, check error log. All clear. Set to another option, repeat process. All clear. So if there's a problem I'm not sure how to track it down. What would you recommend?

It should look at the size. I can't see why you wouldn't want it to. If empty then default to 100%. If not empty and less then 100 then use given width.

Antechinus

Quote from: lurkalot on October 12, 2019, 08:04:05 AMAlthough the reported error above seems to have stopped I just visited the log again and now see two different ones.

8: Undefined index: menu_data_ 
https://cctestsite.info/forums/index.php?action=admin
File: /home/c-------/public_html/cctestsite.info/forums/Themes/Ant_Curve_CSS3_RC3/index.template.php - Line: 181

8: Undefined index: max_menu_id 
https://cctestsite.info/forums/index.php?action=admin
File: /home/c-------/public_html/cctestsite.info/forums/Themes/Ant_Curve_CSS3_RC3/index.template.php - Line: 181

Those are only called if you are in an area which has the sidebar menu anyway.

// Allow setting body tag class by action or board.
$body_class = array();
if (!empty($context['current_action']))
$body_class[] = 'action_'. $context['current_action'];
foreach (array('admin', 'moderate', 'profile', 'pm') as $css_trix)
if (!empty($context['current_action']) && (($context['current_action']) === $css_trix))
$body_class[] = 'area_' . $context['menu_data_' . $context['max_menu_id']]['current_area'];
if (!empty($context['current_subaction']))
$body_class[] = 'subaction_' . $context['current_subaction'];
if (empty($body_class))
$body_class[] = 'action_index';

echo '
</head>
<body class="', implode(' ',$body_class), '">';


The errors you are getting did exist in an earlier version, but as far as I know the code above fixed it. I've never seen those errors since I changed the code to only call those actions in the body class when they are relevant. Again, it's something I'm not seeing on local, so I'm not sure what to do about it.

Arantor

Well, it would sort of work the way you were using it - empty() is a wrapper for 'does the result of all of the things inside the brackets end up false'. Except it's not really meant for expressions like that, and won't shield you against undefined errors when they're used that way.

As evidenced by the fact there were errors, even if you didn't get them.

As for the errors relating to undefined $context['menu_data_'] you need to check that $context['max_menu_id'] isn't empty before trying to use it in any context. Also, you *really* should be using {} around things in foreach - what exactly is your foreach (... as $css_trix) meant to be iterating over, exactly? It may not be what you think it is.

Antechinus

Quote from: Arantor on October 12, 2019, 03:39:38 PM
Well, it would sort of work the way you were using it - empty() is a wrapper for 'does the result of all of the things inside the brackets end up false'. Except it's not really meant for expressions like that, and won't shield you against undefined errors when they're used that way.

Ok, so needs to be more verbose. The catch is that I wanted to idiot-proof the result, so that if someone entered a value higher than 100 it would still default to 100% max-width. Without that, if someone happened to enter 372 (I know, why would you, but humans...) then the banner would break out of the header.

So IMO it needs a limit of 100 set somehow. And I am not doing it with bloody nested ternaries (coz I hate them) so will do it with nicely defined brackets and a few extra lines if necessary. Simple, one-step if/then ternaries are fine, but IMO once they get past that they're more trouble than they're worth and the more spacious formatting is better for maintainability.


QuoteAs for the errors relating to undefined $context['menu_data_'] you need to check that $context['max_menu_id'] isn't empty before trying to use it in any context. Also, you *really* should be using {} around things in foreach - what exactly is your foreach (... as $css_trix) meant to be iterating over, exactly? It may not be what you think it is.

Ok, well you know me and php acrana. :D I was just copying that from someone else's recommendation.

The $context['menu_data_'] and $context['max_menu_id'] are variables that are only called when the sidebar or drop menus are present and accounted for, so that means base action has to be one of admin, moderate, profile, or pm. Those are what I am intending to check for, because if you try to call those variables outside those actions you get the errors that Lurkalot has been getting.

In those actions $context['menu_data_'] and $context['max_menu_id'] should never be empty, because in those actions there is always menu content if you have access to those actions in the first place.

The only thing that did occur to me is that perhaps this is a problem with TP admin, if Lurkalot's test site has TP installed. But offhand I can't see how that would be a problem, since if TP admin isn't called in the array of possible actions then it should be ignored and the body just wouldn't get a class for it.

Arantor

Quoteso will do it with nicely defined brackets

You just had the brackets in slightly the wrong place. Don't try to jam everything inside empty() and you're good - I posted the correct code.

QuoteThe $context['menu_data_'] and $context['max_menu_id'] are variables that are only called when the sidebar or drop menus are present

Other than the small fact that it isn't the case based on the available evidence of having errors. Don't test based on the action being right, simply test if $context['max_menu_id'] is !empty and you'll be good to go.

Antechinus

Ah I see it now. Early Sunday morning over here. Need more coffee and food. I was doubling up on my empties and stuffing it up that way. Dunno why I didn't see that before.

Re the other one: so instead of the current code block, which is this:

// Allow setting body tag class by action or board.
$body_class = array();
if (!empty($context['current_action']))
$body_class[] = 'action_'. $context['current_action'];
foreach (array('admin', 'moderate', 'profile', 'pm') as $css_trix)
if (!empty($context['current_action']) && (($context['current_action']) === $css_trix))
$body_class[] = 'area_' . $context['menu_data_' . $context['max_menu_id']]['current_area'];
if (!empty($context['current_subaction']))
$body_class[] = 'subaction_' . $context['current_subaction'];
if (empty($body_class))
$body_class[] = 'action_index';


I should just use this:

// Allow setting body tag class by action or board.
$body_class = array();
if (!empty($context['current_action']))
$body_class[] = 'action_'. $context['current_action'];
if (!empty($context['max_menu_id']))
$body_class[] = 'area_' . $context['menu_data_' . $context['max_menu_id']]['current_area'];
if (!empty($context['current_subaction']))
$body_class[] = 'subaction_' . $context['current_subaction'];
if (empty($body_class))
$body_class[] = 'action_index';

Arantor

Yes, exactly. Better to rely on whether a menu exists, rather than on whether you happen to be on one of the pages 'it should exist on'.

Antechinus

Cool. Will throw that in the next one then. I'm thinking I'll call the next one RC3.14159, just as a memorial to the 2.0.x dev process. :D

Antechinus

Ok, for anyone who wants it, a corrected index.template.php for Mutant RC3. :)

Removed attached file as requested.

lurkalot

Quote from: Antechinus on October 12, 2019, 04:42:38 PM
Ok, for anyone who wants it, a corrected index.template.php for Mutant RC3. :)

Mutant RC3 ?

I'm assuming this file is the fix for those errors I reported above.  Just installed it and now when logged in I have a rogue checkbox upper left of page.  Looks kind of strange with TP as well, excessive padding between the blocks etc.  Didn't get this with the previous index.template.php file.  https://cctestsite.info/forums/index.php

Mick.

Quote from: lurkalot on October 12, 2019, 05:42:41 PM
Quote from: Antechinus on October 12, 2019, 04:42:38 PM
Ok, for anyone who wants it, a corrected index.template.php for Mutant RC3. :)

Mutant RC3 ?

I'm assuming this file is the fix for those errors I reported above.  Just installed it and now when logged in I have a rogue checkbox upper left of page.  Looks kind of strange with TP as well, excessive padding between the blocks etc.  Didn't get this with the previous index.template.php file.  https://cctestsite.info/forums/index.php
looks like the hamburger

Antechinus

Oh yeah, I forgot I made some other changes on local too. :D Sunday morning, y'know.

Hang on and I'll edit the corrected code into an actual RC3 template, and post that.

Do me a favour and delete the other one. Bloody edit time in this board is way too short.

Advertisement: