From d79a8ea78fa673eb5983e67e5c70225f57d2d8d4 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Wed, 2 Aug 2023 21:31:45 -0400 Subject: [PATCH] Twig 3: Use verbatim instead of raw tag in templates - also ensure we don't pass a null in one of the functions in functions.php --- inc/functions.php | 6 ++- templates/generic_page.html | 4 +- templates/index.html | 4 +- templates/main.js | 54 +++++++++---------- templates/post_form.html | 4 +- templates/post_reply.html | 6 +-- templates/themes/basic/index.html | 4 +- templates/themes/calendar/calendar.html | 4 +- templates/themes/catalog/catalog.html | 4 +- templates/themes/donate/donate.html | 4 +- templates/themes/faq/index.html | 4 +- templates/themes/irc/irc.html | 4 +- templates/themes/radio/radio.html | 4 +- templates/themes/rules/rules.html | 4 +- .../staffapplication/staffapplication.html | 4 +- templates/themes/stream/stream.html | 4 +- templates/thread.html | 4 +- 17 files changed, 63 insertions(+), 59 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index c82a4c93..991729ef 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2231,7 +2231,11 @@ function escape_markup_modifiers($string) { } function utf8tohtml($utf8) { - return htmlspecialchars($utf8, ENT_NOQUOTES, 'UTF-8'); + if ($utf8 == null) { + return ''; + } else { + return htmlspecialchars($utf8, ENT_NOQUOTES, 'UTF-8'); + } } function ordutf8($string, &$offset) { diff --git a/templates/generic_page.html b/templates/generic_page.html index 830d1f43..775da16e 100644 --- a/templates/generic_page.html +++ b/templates/generic_page.html @@ -49,8 +49,8 @@ {% for footer in config.footer %}

{{ footer }}

{% endfor %} - + {% endverbatim %} diff --git a/templates/index.html b/templates/index.html index 259e99f8..97c7c53a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -112,9 +112,9 @@ - + {% endverbatim %} diff --git a/templates/main.js b/templates/main.js index af62bb1a..270d409e 100644 --- a/templates/main.js +++ b/templates/main.js @@ -1,4 +1,4 @@ -{% raw %} +{% verbatim %} /* gettext-compatible _ function, example of usage: * @@ -109,16 +109,16 @@ function alert(a, do_confirm, confirm_ok_action, confirm_cancel_action) { var saved = {}; -var selectedstyle = '{% endraw %}{{ config.default_stylesheet.0|addslashes }}{% raw %}'; +var selectedstyle = '{% endverbatim %}{{ config.default_stylesheet.0|addslashes }}{% verbatim %}'; var styles = [ - {% endraw %} - {% for stylesheet in stylesheets %}{% raw %}['{% endraw %}{{ stylesheet.name|addslashes }}{% raw %}', '{% endraw %}{{ stylesheet.uri|addslashes }}{% raw %}'], - {% endraw %}{% endfor %}{% raw %} + {% endverbatim %} + {% for stylesheet in stylesheets %}{% verbatim %}['{% endverbatim %}{{ stylesheet.name|addslashes }}{% verbatim %}', '{% endverbatim %}{{ stylesheet.uri|addslashes }}{% verbatim %}'], + {% endverbatim %}{% endfor %}{% verbatim %} ]; var codestyles = { - {% endraw %} - {% for stylesheet in code_stylesheets %}{% raw %}'{% endraw %}{{ stylesheet.name|addslashes }}{% raw %}' : '{% endraw %}{{ stylesheet.uri|addslashes }}{% raw %}', - {% endraw %}{% endfor %}{% raw %} + {% endverbatim %} + {% for stylesheet in code_stylesheets %}{% verbatim %}'{% endverbatim %}{{ stylesheet.name|addslashes }}{% verbatim %}' : '{% endverbatim %}{{ stylesheet.uri|addslashes }}{% verbatim %}', + {% endverbatim %}{% endfor %}{% verbatim %} }; if (typeof board_name === 'undefined') { @@ -126,16 +126,16 @@ if (typeof board_name === 'undefined') { } function changeStyle(styleName) { - {% endraw %} - {% if config.stylesheets_board %}{% raw %} + {% endverbatim %} + {% if config.stylesheets_board %}{% verbatim %} if (board_name) { stylesheet_choices[board_name] = styleName; localStorage.board_stylesheets = JSON.stringify(stylesheet_choices); } - {% endraw %}{% else %} + {% endverbatim %}{% else %} localStorage.stylesheet = styleName; {% endif %} - {% raw %} + {% verbatim %} var styleUrl; @@ -178,9 +178,9 @@ function changeStyle(styleName) { } -{% endraw %} +{% endverbatim %} {% if config.stylesheets_board %} - {% raw %} + {% verbatim %} if (!localStorage.board_stylesheets) { localStorage.board_stylesheets = '{}'; @@ -195,15 +195,15 @@ function changeStyle(styleName) { } } } - {% endraw%} + {% endverbatim%} {% else %} - {% raw %} + {% verbatim %} if (localStorage.stylesheet) { changeStyle(localStorage.stylesheet); } - {% endraw %} + {% endverbatim %} {% endif %} -{% raw %} +{% verbatim %} function get_cookie(cookie_name) { var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); @@ -236,7 +236,7 @@ function highlightReply(id) { function generatePassword() { var pass = ''; - var chars = '{% endraw %}{{ config.genpassword_chars }}{% raw %}'; + var chars = '{% endverbatim %}{{ config.genpassword_chars }}{% verbatim %}'; for (var i = 0; i < 8; i++) { var rnd = Math.floor(Math.random() * chars.length); pass += chars.substring(rnd, rnd + 1); @@ -327,15 +327,15 @@ function rememberStuff() { if (sessionStorage.body) { var saved = JSON.parse(sessionStorage.body); - if (get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')) { + if (get_cookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}')) { // Remove successful posts - var successful = JSON.parse(get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')); + var successful = JSON.parse(get_cookie('{% endverbatim %}{{ config.cookies.js }}{% verbatim %}')); for (var url in successful) { saved[url] = null; } sessionStorage.body = JSON.stringify(saved); - document.cookie = '{% endraw %}{{ config.cookies.js }}{% raw %}={};expires=0;path=/;'; + document.cookie = '{% endverbatim %}{{ config.cookies.js }}{% verbatim %}={};expires=0;path=/;'; } if (saved[document.location]) { document.forms.post.body.value = saved[document.location]; @@ -361,13 +361,13 @@ var script_settings = function(script_name) { }; function init() { - {% endraw %} + {% endverbatim %} {% if config.allow_delete %} if (document.forms.postcontrols) { document.forms.postcontrols.password.value = localStorage.password; } {% endif %} - {% raw %} + {% verbatim %} if (window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1)) highlightReply(window.location.hash.substring(1)); @@ -388,16 +388,16 @@ function ready() { } } -{% endraw %} +{% endverbatim %} var post_date = "{{ config.post_date }}"; var max_images = {{ config.max_images }}; onready(init); -{% if config.google_analytics %}{% raw %} +{% if config.google_analytics %}{% verbatim %} -var _gaq = _gaq || [];_gaq.push(['_setAccount', '{% endraw %}{{ config.google_analytics }}{% raw %}']);{% endraw %}{% if config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', '{% endraw %}{{ config.google_analytics_domain }}{% raw %}']){% endraw %}{% endif %}{% if not config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', 'none']){% endraw %}{% endif %}{% raw %};_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();{% endraw %}{% endif %} +var _gaq = _gaq || [];_gaq.push(['_setAccount', '{% endverbatim %}{{ config.google_analytics }}{% verbatim %}']);{% endverbatim %}{% if config.google_analytics_domain %}{% verbatim %}_gaq.push(['_setDomainName', '{% endverbatim %}{{ config.google_analytics_domain }}{% verbatim %}']){% endverbatim %}{% endif %}{% if not config.google_analytics_domain %}{% verbatim %}_gaq.push(['_setDomainName', 'none']){% endverbatim %}{% endif %}{% verbatim %};_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();{% endverbatim %}{% endif %} {% if config.statcounter_project and config.statcounter_security %} var sc = document.createElement('script'); diff --git a/templates/post_form.html b/templates/post_form.html index bf02ad1a..5d9d3a2b 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -208,6 +208,6 @@ - +{% endverbatim %} diff --git a/templates/post_reply.html b/templates/post_reply.html index 936d19c3..d5f6313f 100644 --- a/templates/post_reply.html +++ b/templates/post_reply.html @@ -1,4 +1,4 @@ -{% filter remove_whitespace %} +{% apply remove_whitespace %} {# tabs and new lines will be ignored #}
>>
@@ -20,7 +20,7 @@ {% include 'post/fileinfo.html' %} {% include 'post/post_controls.html' %}
1 %}style="clear:both"{% endif %}> - {% endfilter %}{% if index %}{{ post.body|truncate_body(post.link) }}{% else %}{{ post.body }}{% endif %}{% filter remove_whitespace %} + {% endapply %}{% if index %}{{ post.body|truncate_body(post.link) }}{% else %}{{ post.body }}{% endif %}{% apply remove_whitespace %} {% if post.modifiers['ban message'] %} {{ config.mod.ban_message|sprintf(post.modifiers['ban message']) }} {% endif %} @@ -30,4 +30,4 @@
-{% endfilter %} +{% endapply %} diff --git a/templates/themes/basic/index.html b/templates/themes/basic/index.html index 94bc79d0..d5d1c820 100644 --- a/templates/themes/basic/index.html +++ b/templates/themes/basic/index.html @@ -49,9 +49,9 @@
vichan Copyright © 2012-2016 vichan-devel

- + {% endverbatim %} {% endfilter %} diff --git a/templates/themes/calendar/calendar.html b/templates/themes/calendar/calendar.html index eeb08f1c..22bc0303 100644 --- a/templates/themes/calendar/calendar.html +++ b/templates/themes/calendar/calendar.html @@ -185,8 +185,8 @@ }); - + {% endverbatim %} diff --git a/templates/themes/catalog/catalog.html b/templates/themes/catalog/catalog.html index a72e503f..12542a70 100644 --- a/templates/themes/catalog/catalog.html +++ b/templates/themes/catalog/catalog.html @@ -100,9 +100,9 @@
- + {% endverbatim %} {% endfilter %} diff --git a/templates/themes/donate/donate.html b/templates/themes/donate/donate.html index 4cacc030..b64f16f5 100644 --- a/templates/themes/donate/donate.html +++ b/templates/themes/donate/donate.html @@ -52,9 +52,9 @@
- + {% endverbatim %} diff --git a/templates/themes/faq/index.html b/templates/themes/faq/index.html index cd4526eb..26b690f2 100644 --- a/templates/themes/faq/index.html +++ b/templates/themes/faq/index.html @@ -152,9 +152,9 @@
vichan Copyright © 2012-2016 vichan-devel

- +{% endverbatim %} {% endfilter %} diff --git a/templates/themes/irc/irc.html b/templates/themes/irc/irc.html index 6d1ffb18..0b21aae5 100644 --- a/templates/themes/irc/irc.html +++ b/templates/themes/irc/irc.html @@ -27,9 +27,9 @@
- + {% endverbatim %} {% endfilter %} diff --git a/templates/themes/radio/radio.html b/templates/themes/radio/radio.html index ed73b47e..fa3c3a2a 100644 --- a/templates/themes/radio/radio.html +++ b/templates/themes/radio/radio.html @@ -127,8 +127,8 @@ $(document).ready(function(){

To upload a voice-over / bump to radio click here

- + {% endverbatim %} diff --git a/templates/themes/rules/rules.html b/templates/themes/rules/rules.html index a1a33e5d..7c09f3f4 100644 --- a/templates/themes/rules/rules.html +++ b/templates/themes/rules/rules.html @@ -26,9 +26,9 @@ {% include 'rules.html' %}
- + {% endverbatim %} {% endfilter %} diff --git a/templates/themes/staffapplication/staffapplication.html b/templates/themes/staffapplication/staffapplication.html index 4d4e425b..132081fd 100644 --- a/templates/themes/staffapplication/staffapplication.html +++ b/templates/themes/staffapplication/staffapplication.html @@ -72,9 +72,9 @@
lainchan Copyright © 2014-2017 lainchan Administration

- + {% endverbatim %} {% endfilter %} diff --git a/templates/themes/stream/stream.html b/templates/themes/stream/stream.html index dadb0dba..e30df1a9 100644 --- a/templates/themes/stream/stream.html +++ b/templates/themes/stream/stream.html @@ -174,8 +174,8 @@ function change_format(e) {
lainchan Copyright © 2014-2017 lainchan Administration

- + {% endverbatim %} diff --git a/templates/thread.html b/templates/thread.html index fe09ddab..65f87f07 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -111,9 +111,9 @@
- + {% endverbatim %}