Skip to content

Commit 6ad06a7

Browse files
mainly compatibility fixes and cosmetics
1 parent e4170c1 commit 6ad06a7

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed

CHANGELOG

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
1.4.1.661
2+
3+
- JS fix: fix for possible errorneous leading zero before year number in custom header
4+
- JS fix: Some browser compatibility fixes in ttxweb.js
5+
- Some more browser compatibility improvements
6+
- Added seqn0 URL parameter to control display of subpage sequence number (debug use)
7+
- Clearer comments in code and documentation regarding turn rates
8+
19
1.4.0.660
210

311
- New: file name pattern for EP1 files is now configurable via ttxweb_config.php

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ The following URL parameters are supported (if provided, they override the value
110110
- **refresh** - seconds for auto refresh via XHR, 0 = disabled (default: set by TTXWEB_REFRESH in ttxweb_config.php)
111111
- **template** - override configured template name (default: set by TTXWEB_TEMPLATE in ttxweb_config.php)
112112
- **turn** - 0 (do not automatically turn subpages) | 1 (turn subpage on every XHR refresh) | *not set* (turn according to TTXWEB_TURN_RATES in ttxweb_config.php, **default**)
113-
114-
The **xhr** GET parameter is used internally to implement the XMLHttpRequest refresh function. By setting it to 1 you can get only the ttxContainer part of the page if you want to embed it in your own XMLHttpRequest applications.
113+
- **seqn0** - 0 (display actual subpage number in header) | 1 (display subpage number in header as *00*; useful for "animated" pages that otherwise have no multi-page content and would be transmitted with 0000 instead of SEQN in linear transmission) | *not set* (show subpage number as 00 only for pages defined in TTXWEB_TURN_RATES)
114+
- **xhr** - this parameter is used internally to implement the XMLHttpRequest refresh function. By setting it to 1 you can get only the ttxStage part of the page if you want to embed it in your own XMLHttpRequest applications.
115115

116116
# Contact the author
117117

includes/ttxweb_decoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
// ttxweb.php EP1 teletext document renderer
4-
// version: 1.4.0.660 (2023-08-10)
4+
// version: 1.4.1.661 (2023-08-11)
55
// (c) 2023 Fabian Schneider - @fabianswebworld
66

77
const EP1_HEADER_LENGTH = 6;
@@ -552,20 +552,20 @@ function g0ToHtml($ttxString, $ttxLanguage) {
552552
case 'de-DE':
553553
return str_replace(
554554
['&', chr(0x24), '@', '[', '\\', ']', '`', '{', '|', '}', '~', chr(0x7f), '<', '>', '"', '\''],
555-
['&amp;', '$', '&sect;', '&Auml;', '&Ouml;', '&Uuml;', '&deg;', '&auml;', '&ouml;', '&uuml;', '&szlig;', '&#9632;', '&lt;', '&gt;', '&quot;', '&apos;'],
555+
['&amp;', '$', '&sect;', '&Auml;', '&Ouml;', '&Uuml;', '&deg;', '&auml;', '&ouml;', '&uuml;', '&szlig;', '&#9632;', '&lt;', '&gt;', '&quot;', '&#39;'],
556556
$ttxString
557557
);
558558
break;
559559
case 'en-GB':
560560
return str_replace(
561561
['&', chr(0x23), chr(0x24), '@', '[', '\\', ']', chr(0x5e), chr(0x5f), '`', '{', '|', '}', '~', chr(0x7f), '<', '>', '"', '\''],
562-
['&amp;', '&pound;', '$', '@', '&#8592;', '&frac12;', '&#8594;', '&#8593;', '#', '&#8212;', '&frac14;', '&#9553;', '&frac34;', '&divide;', '&#9632;', '&lt;', '&gt;', '&quot;', '&apos;', '&amp;'],
562+
['&amp;', '&pound;', '$', '@', '&#8592;', '&frac12;', '&#8594;', '&#8593;', '#', '&#8212;', '&frac14;', '&#9553;', '&frac34;', '&divide;', '&#9632;', '&lt;', '&gt;', '&quot;', '&#39;', '&amp;'],
563563
$ttxString
564564
);
565565
default:
566566
return str_replace(
567567
['&', chr(0x7f), '<', '>', '"', '\''],
568-
['&amp;', '&#9632;', '&lt;', '&gt;', '&quot;', '&apos;'],
568+
['&amp;', '&#9632;', '&lt;', '&gt;', '&quot;', '&#39;'],
569569
$ttxString
570570
);
571571
}

includes/ttxweb_main.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

33
// ttxweb.php EP1 teletext document renderer
4-
// version: 1.4.0.660 (2023-08-10)
4+
// version: 1.4.1.661 (2023-08-11)
55
// (c) 2023 Fabian Schneider - @fabianswebworld
66

77
// GLOBAL DEFINITIONS
88

9-
const TTXWEB_VERSION = '1.4.0.660 (2023-08-10)'; // version string
9+
const TTXWEB_VERSION = '1.4.1.661 (2023-08-11)'; // version string
1010

1111
// for user and template configuration see ttxweb_config.php
1212

@@ -18,7 +18,9 @@
1818
// reveal - 0 (hide concealed text, default) | 1 (reveal concealed text on load)
1919
// refresh - seconds for auto refresh via XHR, 0 = disabled (default: set by TTXWEB_REFRESH in ttxweb_config.php)
2020
// template - temporary template name (default: set by TTXWEB_TEMPLATE in ttxweb_config.php)
21-
// turn - turn subpage on XHR refresh (default: turn according to TTXWEB_TURN_RATES in ttxweb_config.php)
21+
// turn - 1 = turn subpage on XHR refresh (default: turn according to TTXWEB_TURN_RATES in ttxweb_config.php)
22+
// seqn0 - 1 = always display subpage 00 in custom header (default: only if page is in TTXWEB_TURN_RATES)
23+
// xhr - 1 = output ttxStage only (only used internally for XMLHttpRefresh via ttxweb.js)
2224

2325

2426
// FUNCTION DEFINITONS
@@ -174,10 +176,12 @@ function pageExists($pageNum, $subpageNum) {
174176
if (empty($templateName)) { $templateName = 'default'; }
175177

176178
// build query string to pass to the next query
179+
// with some more sanitizations
177180
$queryArray = $_GET;
178181
unset($queryArray['page']);
179182
unset($queryArray['sub']);
180183
unset($queryArray['xhr']);
184+
unset($queryArray['seqn0']);
181185
if (isset($queryArray['level15'])) {
182186
if ($queryArray['level15'] == '1') {
183187
unset($queryArray['level15']);
@@ -193,6 +197,14 @@ function pageExists($pageNum, $subpageNum) {
193197
unset($queryArray['reveal']);
194198
}
195199
}
200+
if (isset($queryArray['refresh'])) {
201+
$queryArray['refresh'] = abs(filter_var($queryArray['refresh'], FILTER_SANITIZE_NUMBER_INT));
202+
}
203+
if (isset($queryArray['turn'])) {
204+
if (!(($queryArray['turn'] == '1') || ($queryArray['turn'] == '0'))) {
205+
unset($queryArray['turn']);
206+
}
207+
}
196208
$queryString = htmlspecialchars(http_build_query($queryArray));
197209
if (!empty($queryString)) {
198210
$queryString = '&amp;' . $queryString;
@@ -229,6 +241,8 @@ function pageExists($pageNum, $subpageNum) {
229241
$origRefresh = $refresh;
230242
$origNextSubpageNum = $nextSubpageNum;
231243
if (isset($ttxTurnRates[$pageNum]) && !isset($_GET['sub'])) {
244+
// page has a turnrate set in TTXWEB_TURN_RATES, so always
245+
// display 00 as subpage number by default
232246
$refresh = $ttxTurnRates[$pageNum];
233247
$turn = true;
234248
$seqn0 = true;
@@ -246,6 +260,20 @@ function pageExists($pageNum, $subpageNum) {
246260
$nextSubpageNum = $origNextSubpageNum;
247261
}
248262
}
263+
if (isset($_GET['refresh'])) {
264+
$refresh = $origRefresh;
265+
}
266+
267+
// overwrite pages with turnrate if seqn0 URL parameter is set
268+
// 1 = always show subpage number 00
269+
if (isset($_GET['seqn0'])) {
270+
if ($_GET['seqn0'] == '1') {
271+
$seqn0 = true;
272+
}
273+
if ($_GET['seqn0'] == '0') {
274+
$seqn0 = false;
275+
}
276+
}
249277

250278
// include header template if not requested from XMLHttpRequest
251279
if (!($xhr)) include($templateFolder . '/header.php');

js/ttxweb.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function xhrRefresh() {
1717
else {
1818
var nextSubpage = subpageNum + 1;
1919
if (nextSubpage > numSubpages) nextSubpage = 1;
20-
var myXhrUrl = window.location.pathname + '?xhr=1&' + window.location.search.substring(1).replace('&sub=([0-9]{1,2})','') + '&sub=' + nextSubpage;
20+
var myXhrUrl = window.location.pathname + ('?xhr=1&' + window.location.search.substring(1).replace('&sub=([0-9]{1,2})', '') + '&sub=' + nextSubpage).replace('&&', '&');
2121
}
2222

2323
var myCurrentContents = document.createElement('div');
@@ -70,10 +70,10 @@ function xhrRefresh() {
7070
function renderRow0() {
7171
var myDate = new Date();
7272

73-
var myWeekDay = myDate.toLocaleString(document.getElementById('ttxLanguage').innerHTML, {weekday: 'long'}).substr(0, 2);
73+
var myWeekDay = myDate.toLocaleString(document.getElementById('ttxLanguage').innerHTML, {weekday: 'long'}).substring(0, 2);
7474
var myMonth = zeroPad(myDate.getMonth() + 1);
7575
var myDay = zeroPad(myDate.getDate());
76-
var myYear = zeroPad(myDate.getFullYear().toString().substr(-2));
76+
var myYear = myDate.getFullYear().toString().substring(2, 4);
7777
var myHours = zeroPad(myDate.getHours());
7878
var myMinutes = zeroPad(myDate.getMinutes());
7979
var mySeconds = zeroPad(myDate.getSeconds());
@@ -209,6 +209,10 @@ function setNumPadFocus() {
209209
elem.select();
210210
}
211211

212+
String.prototype.trim = function() {
213+
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
214+
}
215+
212216
var revealState = document.getElementById('ttxReveal').innerHTML;
213217
var refreshTimer = document.getElementById('ttxRefresh').innerHTML * 1000;
214218
var refreshState = (refreshTimer != 0);

0 commit comments

Comments
 (0)