Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-12-15 15:23:46

pexman
Member
Registered: 2016-02-27
Posts: 60

txp:php in template

Hi, I want make a cookie popup for my site. I have found some code and this php-code goes into the template, but how can I do that:

<?php if($showPopup) { ?>
  <div id="cookie-popup">
    <div class="hinweis">
      <p>Wir verwenden Cookies. Durch die weitere Nutzung der Webseite stimmen Sie der Verwendung von Cookies zu.</p>
    </div> 
    <span class="more">
      <a href="datenschutz.php">Details</a>
    </span>
    <button onclick='cookieOk()'>OK, ich bin einverstanden.</button>
  </div>
<?php  }; ?>

I know, that I have to replace <?php …function bla… ?> to <txp:php> …function bla…</txp:php> but what I can do with this?

<?php if($showPopup) { ?> 

and this

 <?php  }; ?>

Offline

#2 2020-12-15 15:49:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: txp:php in template

Since anything you set in one <txp:php> block isn’t available in another, if you want to share info you need to declare variables global in both blocks:

<txp:php>
global $showPopup;
$showPopup = gps('show_popup');
</txp:php>
...
<txp:php>
global $showPopup;

if ($showPopup) {
   echo '... doing something ...';
}
</txp:php>

Alternatively, and highly recommended is the oui_cookie plugin.

Then you can do things like this in some form that’s included on every page:

<txp:hide> Tell the plugin what values are available and the cookie validity </txp:hide>
<txp:oui_cookie name="accept_cookies" values="yes,no" duration="+1 year" />
...
<txp:hide> Display the cookie bar if consent has yet to be given </txp:hide>
<txp:oui_if_cookie name="accept_cookies">
<txp:else />
<div id="cookie-bar" class="cookies">
   <p>This website uses <a href="/terms/privacy-policy">cookies</a>. <a href="?accept_cookies=yes">Accept</a>/<a href="?accept_cookies=no">Decline</a>.</p>
</div>
</txp:oui_if_cookie>

Then anywhere you want to conditionally check something:

<txp:oui_if_cookie name="accept_cookies" value="yes">
... tracking code here...
</txp:oui_if_cookie>

Last edited by Bloke (2020-12-15 16:14:04)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2020-12-15 17:50:00

pexman
Member
Registered: 2016-02-27
Posts: 60

Re: txp:php in template

Thank you very much, its realy the problem-killer. But there is coming a warning:

Deprecated: Function get_magic_quotes_gpc() is deprecated in /textpattern/lib/constants.php on line 136

Why deprecated? i want to keep my personal magic quotes. They take everything away from us, but it makes no sense, we have to change the quotes now. Are there some mystery_quotes or similar? how you can replace that?

Offline

#4 2020-12-15 18:27:12

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: txp:php in template

pexman wrote #327531:

Why deprecated? i want to keep my personal magic quotes. They take everything away from us, but it makes no sense, we have to change the quotes now. Are there some mystery_quotes or similar? how you can replace that?

According to The Manual this feature hasn’t really done anything since 5.4 so it has finally been removed.

Offline

#5 2020-12-15 18:31:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: txp:php in template

pexman wrote #327531:

Deprecated: Function get_magic_quotes_gpc() is deprecated in /textpattern/lib/constants.php on line 136

PHP have removed this feature from the language so if you ask for magic quotes, it always returns false. They’re useless anyway. It was a ‘security’ feature that never worked very well and encouraged lazy/insecure programming habits to rely on content being escaped by the server.

There’s no situation any more you can code that will return anything of any value. Just avoid adding any code that uses it, as mentioned on StackOverflow and instead rely on better security/programming practices wholesale.

In newer version of Textpattern (v4.8+) we have removed this feature too and our internal functions will return false likewise. This is so that any plugins that call core functions or rely on this feature don’t just break, and gives plugin authors time to remove it from their code.

What issue exactly are you encountering with magic_quotes? Do you have some code you could share so we can make suggestions on how to work around it?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2020-12-16 19:58:28

pexman
Member
Registered: 2016-02-27
Posts: 60

Re: txp:php in template

Thank you, thank you, you helped me a lot. Since I wrote this, I solved a few new problems and now I stoped by a realy, i thaught fuck`n easy little problem. But first I take a full sleep night and tomorrow I continue. Thank you for the good advice to take a popupplugin.

Offline

#7 2020-12-18 22:18:12

pexman
Member
Registered: 2016-02-27
Posts: 60

Re: txp:php in template

Hallo all, hello Mr Bloke,
trying your idea doesn`t solve my popup dsvgo problem. I don`t understand the mechanik below your scripting. I have installed the oui_cookie plugin and put it in a form exactly following the plugin description. But in a few browsers the popup comes back, if you gives your okay with clicking the button, then going to another site and now with a menue-button return, and it makes “pop” and the popup ask you again. Not always, not at all, firefox and mozilla-based browsers are willing (most time)
May be you have a look on the site arteurope

I put my form called popup direct after the body-tag in all templates.

<txp:oui_cookie name="accept_cookies" values="yes" />
<txp:oui_if_cookie name="accept_cookies">


<script>
    (function() {
        // Get the link which should remove the warning.
        var accept = document.getElementById('accept_cookies');

        // If it exists, listen it…
        if (accept) {
            accept.addEventListener('click', removeWarning);
        }

        // It is clicked!
        function removeWarning(e){
            document.cookie = 'accept_cookies=yes;path=/;expires=864e2'; // Set the cookie for the whole domain for 1 day.
            var warning = document.getElementById('cookies-warning'); // Get the warning message to remove.
            warning.remove(); // Remove the message.
            e.preventDefault(); // Do not follow the link; everything's already done!
        };
    }());
</script>

<txp:else />
<div class="message-overlay">
    <div id="cookies-warning">
        <p style="text-align: center;"><a href="https://arteurope.de/arteurope/Datenschutz" title="zum Datenschutz">Diese Website verwendet Cookies. Durch die Nutzung dieser Webseite erklärst Du dich damit einverstanden, dass Cookies gesetzt werden.</a> <a id="accept_cookies" href="?accept_cookies=yes"> <p class="codrops-top">okay</p></a><a href="https://arteurope.de/arteurope/Datenschutz" title="zum Datenschutz">mehr dazu</a></p>
    </div>
</div>
</txp:oui_if_cookie>

Offline

#8 2020-12-19 00:24:38

pexman
Member
Registered: 2016-02-27
Posts: 60

Re: txp:php in template

Now I have reached a situation, where, if you have given your okay for cookies, you can surf the whole site without a new popup, but if you going back to your first site with the navigation, you see it again. On the first arriving site you get the popup always again. How to solve that, what is going wrong ?

Offline

#9 2020-12-19 02:28:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: txp:php in template

Weird. The cookie consent seems to work for me. At least, on the https://arteurope.de site in a regular browsing session. In a Private browsing session of course, the cookie isn’t stored when I leave the site.

But looking at your cookie expiration, it’s only +1 day. So it will re-request the cookie after 24 hours. Is that what you intend?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2020-12-19 06:47:50

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: txp:php in template

Try changing

<txp:oui_cookie name="accept_cookies" values="yes" />

to

<txp:oui_cookie name="accept_cookies" duration="+1 month" values="yes" />

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#11 2020-12-19 11:54:13

pexman
Member
Registered: 2016-02-27
Posts: 60

Re: txp:php in template

Solved. Thank you so much.

One time in year I make my excoursion in scripting, mostly to the end of the year. I`m a “scripting-tourist” but about 15 years. It has pressing me to implent the DSVGO. I`m very happy about your precious help.

Offline

Board footer

Powered by FluxBB