News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

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.

@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

@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

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.

@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

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.

@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

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?

@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

Arantor

Sounds like you then need to set left: 0 on. Hard to tell without seeing - and I'm on mobile ;)

@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

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

Mightymax44

#112
Hi,
Add archive works smf 2.1.3 with french translation and turkish transalation (thanks @uok825).



-edit by Kindred - Attachment removed.
La connaissance, c'est partager le savoir qui nous fait grandir.

Kindred

This mod has no specified license, which means that it defaults to a restrictive license and modification and re-distribution of the original files is not allowed.

You can provide the alternate language INSTRUCTION on how to add the strings, but you can not repackage and attach a complete download.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mightymax44

#114
OK sorry you can removed my previous message.
the license in the package apparently authorizes
La connaissance, c'est partager le savoir qui nous fait grandir.

Topman

I'm getting lots of e mail from Google saying the wording of my cookie consent does not comply with Google policy.

I don't have one on my forum at the moment. The EU Cookie control no longer works on my version of SMF.

As the UK is now not even in the EU, I don't know why Google is doing this.

These cookie notices are a nuisance to users. Everyone clicks accept just to do what they want and we call all delete cookies using something like CCleaner anyway.



Mightymax44

Quote from: Topman on March 17, 2023, 07:28:17 AMI'm getting lots of e mail from Google saying the wording of my cookie consent does not comply with Google policy.

I don't have one on my forum at the moment. The EU Cookie control no longer works on my version of SMF.

As the UK is now not even in the EU, I don't know why Google is doing this.

These cookie notices are a nuisance to users. Everyone clicks accept just to do what they want and we call all delete cookies using something like CCleaner anyway.




You can reinstall it
smf version 2.1.3:
-download the archive and unzip

modify the file package-info.xml
find:
<uninstall for="2.0 - 2.0.99">
        <modification reverse="true">install2.xml</modification>
        <modification reverse="true">install-utf8.xml</modification>
    </uninstall>

add after:

    <install for="2.1 - 2.1.99">
        <modification>install2.xml</modification>
        <modification>install-utf8.xml</modification>
        <redirect url="index.php?action=admin;area=modsettings;sa=euc" timeout="5000">redirect.txt</redirect>
    </install>

    <uninstall for="2.1 - 2.1.99">
        <modification reverse="true">install2.xml</modification>
        <modification reverse="true">install-utf8.xml</modification>
    </unintall>

modify this file install2.xml

find:

<![CDATA[function template_html_below()
{
    global $context, $settings, $options, $scripturl, $txt, $modSettings;]]>

replace with:
<![CDATA[function template_body_below()
{
    global $context, $txt, $scripturl, $modSettings;]]>

save the files and zip the archive.
You can install the package on your board and it's done

For french user

add to the install2.xml

find:
</modification>
add before:
<file name="$languagedir/Modifications.french.php" error="skip">
        <operation>
            <search position="end" />
            <add><![CDATA[
// EU Cookie
$txt['mods_cat_eucookie'] = 'EU Cookie';
$txt['enable_eucookie'] = 'Activer EU Cookie';
$txt['eucookie_color'] = 'Selectionner couleur';
$txt['eucookie_black'] = 'Noir';
$txt['eucookie_white'] = 'Blanc';
$txt['eucookie_notice'] = 'Texte de notification:';
$txt['eucookie_text'] = 'En utilisant notre site, vous autorisez l\'utilisation des cookies pour offir un fonctionnement optimale.';
$txt['eucookie_policy'] = 'URL de la page de politique cookie';
$txt['eucookie_more'] = 'En savoir plus';
]]></add>
        </operation>
    </file>

if necessary install-utf8.xml
find:
</modification>
add before:
<file name="$languagedir/Modifications.french-utf8.php" error="skip">
        <operation>
            <search position="end" />
            <add><![CDATA[
// EU Cookie
$txt['mods_cat_eucookie'] = 'EU Cookie';
$txt['enable_eucookie'] = 'Activer EU Cookie';
$txt['eucookie_color'] = 'Selectionner couleur';
$txt['eucookie_black'] = 'Noir';
$txt['eucookie_white'] = 'Blanc';
$txt['eucookie_notice'] = 'Texte de notification:';
$txt['eucookie_text'] = 'En utilisant notre site, vous autorisez l\'utilisation des cookies pour offir un fonctionnement optimale de notre site.';
$txt['eucookie_policy'] = 'URL de la page de politique cookie';
$txt['eucookie_more'] = 'En savoir plus';
]]></add>
        </operation>
    </file>
;)
La connaissance, c'est partager le savoir qui nous fait grandir.

Arantor

Quote from: mightymax44 on March 21, 2023, 02:27:21 PMif necessary install-utf8.xml

Yeah about that... 2.1 doesn't have the UTF-8 files, and all the stock files are themselves UTF-8. Implementing these instructions as given will likely corrupt any non-English language installation.

Advertisement: