EU Cookie

Started by nikan, May 19, 2013, 02:07:30 AM

Previous topic - Next topic

Arantor

The easiest way is to add a template layer at that point.

See how the system adds the maintenance warning, specifically the references to maint_warning where it's added to context and where this can then call template_maint_warning_above and template_maint_warning_below.
Perhaps it would have been better if I'd simply never bothered. Y'all clearly would be less unhappy that way.

@rjen

Quote from: Arantor on February 28, 2022, 05:21:13 AMThe easiest way is to add a template layer at that point.

See how the system adds the maintenance warning, specifically the references to maint_warning where it's added to context and where this can then call template_maint_warning_above and template_maint_warning_below.

Thanks,

got that working  :)

Happy with the progress so far: before this weekend I had never worked with hooks. Starting to understand better how it works. Now I only have one piece left and that is to add a little css using a hook...
Hunting for the correct procedure to do that now...

Challenge is that there is a long list of hooks (https://live627.github.io/smf-api-docs-test/hookdocs/themes.html) but not too many additional documentation / sample use cases...
 
Running SMF 2.1 with latest Tinyportal at www.fjr-club.nl
Testing SMF 2.1 with next version Tinyportal at test.fjr-club.nl

@rjen

Not sure if it is the recommended approach, but by simply adding the css in the code before the template_above is built using AddInlinnCss did the trick..

Is this 'recommended'?

AddInlineCss('.cookie_wrap
{
position: fixed;
width: 100%;
bottom: 20px;
text-align: center;
z-index: 9999;
visibility: hidden;
}
.cookie_wrap a:link, .cookie_wrap a:visited
{
text-decoration: none;
}
.cookie_wrap a:hover
{
text-decoration: underline;
cursor: pointer;
}
.cookie_notice
{
display: inline-block;
margin: 0 auto;
padding: 10px;
border-radius: 5px;
font-size: 12px;
}
#cookie_button
{
background: #346;
color: #fff;
font: bold 11px arial;
padding: 3px 12px;
border-radius: 3px;
}');
Running SMF 2.1 with latest Tinyportal at www.fjr-club.nl
Testing SMF 2.1 with next version Tinyportal at test.fjr-club.nl

Arantor

I think it's an acceptable approach. A better one would be if there were a way to push CSS into the minify pipeline at compile time but there isn't an option for that.

Your other choice is to add a new CSS file and use addCssFile to load that, perhaps slightly earlier in the process.
Perhaps it would have been better if I'd simply never bothered. Y'all clearly would be less unhappy that way.

@rjen

Quote from: Arantor on February 28, 2022, 06:44:50 AMYour other choice is to add a new CSS file and use addCssFile to load that, perhaps slightly earlier in the process.

That was indeed what I was thinking, but since it is only a few elements it feels that creating a completely new css file is a bit 'too much'

Apart from that looking at the result: I started with a separate sources file (eu_cookie.php) and subs file (subs-eu_cookie.php) for the admin functions. But also here this seems a bit 'much'  so I ended up combining all functions in the eu_cookie.php file.

This is more of a coding-standards question: what is the main reason(s) to create a separate 'subs-' file?
Would like to know that, but it is not as such related to this mod specifically...

As for this one: @nikan , I have a completely functioning SMF2.1 package with all hooks available...
Running SMF 2.1 with latest Tinyportal at www.fjr-club.nl
Testing SMF 2.1 with next version Tinyportal at test.fjr-club.nl

Arantor

Separate Subs- file is more logical separation between what we would in architectural terms call MVC, Model View Controller. View is the view of the thing you're working on (the template) while the ideal is a complete separation of "what you're doing" from "how you're doing it".

e.g. in the post flow, Post.php sets up the post form, gets all the bits needed for it, and deals with the "business logic" over things like permissions, deciding what the user should be able to see and do. But the real work of "creating a post in the database", "creating a topic in the database", that's all in Subs-Post - createPost or modifyPost is called and all the real complexity moves over there.

If you look at all the Subs files, it's all supporting functions, never the front loaded stuff.

Fun fact, there is (was) a function naming convention: PascalCase for functions directly called by index.php as "this is the user wants to do something" like Post, camelCase for functions that directly support that like createPost, lowercase or snake_case for really internal/generic support functions like preparse_code.
Perhaps it would have been better if I'd simply never bothered. Y'all clearly would be less unhappy that way.

@rjen

That's what I thought.

For a mod as simple as this (4 functions including the admin stuff) it seems most suited to not have a subs file.

Perhaps it would be best suited to create a user file and an admin file but tbh I cannot be bothered for this mod.

Just have a small layout issue left because the cookie wrapper Div is now IN the main wrapper, and is was outside before...
Running SMF 2.1 with latest Tinyportal at www.fjr-club.nl
Testing SMF 2.1 with next version Tinyportal at test.fjr-club.nl

Arantor

For a mod this small maybe not. The only guideline is "when it feels like there's too much in one file split it up".

As for the banner, position absolute might be your friend to pull it out of the wrapper?
Perhaps it would have been better if I'd simply never bothered. Y'all clearly would be less unhappy that way.

@rjen

It has an absolute position, but it starts from the left border of the wrapper ...

It's a bit funny, need to check
Running SMF 2.1 with latest Tinyportal at www.fjr-club.nl
Testing SMF 2.1 with next version Tinyportal at test.fjr-club.nl

Arantor

Sounds like you then need to set left: 0 on. Hard to tell without seeing - and I'm on mobile ;)
Perhaps it would have been better if I'd simply never bothered. Y'all clearly would be less unhappy that way.

@rjen

no probs, I will figure it out... thanks for the help...

QuoteSounds like you then need to set left: 0 on

and yep, that was it
Running SMF 2.1 with latest Tinyportal at www.fjr-club.nl
Testing SMF 2.1 with next version Tinyportal at test.fjr-club.nl

Shades.

#111
I just installed this on my SMF 2.1.1 and it works great. Anyone else that want to use it as is can follow these directions:

I make no promises or guarantees (use this at your own risk) but it worked for me! ;)

Make Backups of all your files first including database!

First install the mod via package manager and emulate it for 2.0.

Don't worry about the warning.

Just click ok or install anyways.

Once installed open (default and whatever theme you're using) index.template.php and

Find:
</div><!-- #footer -->';
Add after:
// EU Cookie mod
global $user_info;
if (!$user_info['is_admin'] && !empty($modSettings['enable_eucookie']))
echo '
<div class="cookie_wrap">
<div class="cookie_notice" style="' . ($modSettings['eucookie_color'] == 'black' ? 'background: #000; background-color: rgba(0,0,0,0.80); color: #fff;' : 'background: #fff; background-color: rgba(255,255,255,0.80); color: #000;') . '">
', !empty($modSettings['eucookie_notice']) ? $modSettings['eucookie_notice'] : $txt['eucookie_text'], '
<button id="cookie_button" type="button">OK</button>
' . (!empty($modSettings['eucookie_policy']) ?  '<a style="' . ($modSettings['eucookie_color'] == 'black' ? 'color: #fff;' : 'color: #000;') . '" href="' . $modSettings['eucookie_policy'] . '">' . $txt['eucookie_more'] . '</a>' : '') . '
</div>
</div>';

All done! 8)
ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

Advertisement: