From 62de4d4a14bc3da0ec2bd423d0a78e5186ee011c Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 15:06:45 +0100 Subject: [PATCH 01/40] Code clean-up with the audio controller. Remove the unitended declaration of global variables. --- js/pgm.js | 23 +++++++------- src/js/audio_controller.js | 61 +++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/js/pgm.js b/js/pgm.js index 12ae3b4d6..6a18f8838 100644 --- a/js/pgm.js +++ b/js/pgm.js @@ -4,18 +4,21 @@ * @license Unlicense */ function new_pos(p){$("#jquery_jplayer_1").jPlayer("playHead",p)} -function set_new_playerseconds(){var newval=($("#backtime :selected").val());do_ajax_save_setting('currentplayerseconds',newval)} -function set_new_playbackrate(){var newval=($("#playbackrate :selected").val());do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)} -function set_current_playbackrate(){var val=($("#playbackrate :selected").val());$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)} +function set_new_playerseconds(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)} +function set_new_playbackrate(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)} +function set_current_playbackrate(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)} function click_single(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1} -function click_repeat(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1} -function click_back(){var t=parseInt($("#playTime").text(),10);var b=parseInt($("#backtime").val(),10);var nt=t-b;var st='pause';if(nt<0)nt=0;if(!$('#jquery_jplayer_1').data().jPlayer.status.paused)st='play';$("#jquery_jplayer_1").jPlayer(st,nt)} -function click_forw(){var t=parseInt($("#playTime").text(),10);var b=parseInt($("#backtime").val(),10);var nt=t+b;var st='pause';if(!$('#jquery_jplayer_1').data().jPlayer.status.paused)st='play';$("#jquery_jplayer_1").jPlayer(st,nt)} -function click_slower(){val=parseFloat($("#pbvalue").text())-0.1;if(val>=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}} -function click_faster(){val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}} +function click_repeat(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1} +function click_back(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) +nt=0;if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) +st='play';$("#jquery_jplayer_1").jPlayer(st,nt)} +function click_forw(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);const nt=t+b;let st='pause';if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) +st='play';$("#jquery_jplayer_1").jPlayer(st,nt)} +function click_slower(){const val=parseFloat($("#pbvalue").text())-0.1;if(val>=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}} +function click_faster(){const val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}} function click_stdspeed(){$("#playbackrate").val(10);set_new_playbackrate()} -function click_slower(){var val=($("#playbackrate :selected").val());if(val>5){val--;$("#playbackrate").val(val);set_new_playbackrate()}} -function click_faster(){var val=($("#playbackrate :selected").val());if(val<15){val++;$("#playbackrate").val(val);set_new_playbackrate()}};function CountUp(server_now,server_start,id,dontrun){if(server_now5){val--;$("#playbackrate").val(val);set_new_playbackrate()}} +function click_faster(){let val=$("#playbackrate :selected").val();if(val<15){val++;$("#playbackrate").val(val);set_new_playbackrate()}};function CountUp(server_now,server_start,id,dontrun){if(server_now0){r+=hr<10?("0"+hr):hr;r+=":"} r+=min<10?("0"+min):min;r+=":";r+=sec<10?("0"+sec):sec;document.getElementById(id).innerHTML=r;if(this.dontrun)return;var self=this;setTimeout(function(){self.update(id)},1000)};/** * Control the interactions for making an automated feed wizard. diff --git a/src/js/audio_controller.js b/src/js/audio_controller.js index 67cdbd416..f21f6b6ee 100644 --- a/src/js/audio_controller.js +++ b/src/js/audio_controller.js @@ -9,28 +9,24 @@ * * @param {Number} p New player head */ - function new_pos(p) { $("#jquery_jplayer_1").jPlayer("playHead", p); } function set_new_playerseconds() { - var newval = ($("#backtime :selected").val()); - do_ajax_save_setting('currentplayerseconds',newval); - // console.log("set_new_playerseconds="+newval); + const newval = $("#backtime :selected").val(); + do_ajax_save_setting('currentplayerseconds', newval); } function set_new_playbackrate() { - var newval = ($("#playbackrate :selected").val()); - do_ajax_save_setting('currentplaybackrate',newval); - $("#jquery_jplayer_1").jPlayer("option","playbackRate", newval*0.1); - // console.log("set_new_playbackrate="+newval); + const newval = $("#playbackrate :selected").val(); + do_ajax_save_setting('currentplaybackrate', newval); + $("#jquery_jplayer_1").jPlayer("option","playbackRate", newval * 0.1); } function set_current_playbackrate() { - var val = ($("#playbackrate :selected").val()); - $("#jquery_jplayer_1").jPlayer("option","playbackRate", val*0.1); - // console.log("set_current_playbackrate="+val); + const val = $("#playbackrate :selected").val(); + $("#jquery_jplayer_1").jPlayer("option","playbackRate", val * 0.1); } function click_single() { @@ -43,7 +39,7 @@ function click_single() { function click_repeat() { $("#jquery_jplayer_1") - .on('bind', $.jPlayer.event.ended + ".jp-repeat", function(event) { + .on('bind', $.jPlayer.event.ended + ".jp-repeat", function(_event) { $(this).jPlayer("play"); }); $("#do-repeat").addClass('hide'); @@ -53,39 +49,42 @@ function click_repeat() { } function click_back() { - var t = parseInt($("#playTime").text(),10); - var b = parseInt($("#backtime").val(),10); - var nt = t - b; - var st = 'pause'; - if (nt < 0) nt = 0; - if(!$('#jquery_jplayer_1').data().jPlayer.status.paused)st = 'play'; + const t = parseInt($("#playTime").text(), 10); + const b = parseInt($("#backtime").val(), 10); + let nt = t - b; + let st = 'pause'; + if (nt < 0) + nt = 0; + if (!$('#jquery_jplayer_1').data().jPlayer.status.paused) + st = 'play'; $("#jquery_jplayer_1").jPlayer(st, nt); } function click_forw() { - var t = parseInt($("#playTime").text(),10); - var b = parseInt($("#backtime").val(),10); - var nt = t + b; - var st = 'pause'; - if(!$('#jquery_jplayer_1').data().jPlayer.status.paused)st = 'play'; + const t = parseInt($("#playTime").text(), 10); + const b = parseInt($("#backtime").val(), 10); + const nt = t + b; + let st = 'pause'; + if (!$('#jquery_jplayer_1').data().jPlayer.status.paused) + st = 'play'; $("#jquery_jplayer_1").jPlayer(st, nt); } function click_slower() { - val=parseFloat($("#pbvalue").text()) - 0.1; - if(val>=0.5){ + const val = parseFloat($("#pbvalue").text()) - 0.1; + if (val >= 0.5) { $("#pbvalue").text(val.toFixed(1)).css({'color': '#BBB'}) .animate({color: '#888'},150,function() {}); - $("#jquery_jplayer_1").jPlayer("playbackRate",val); + $("#jquery_jplayer_1").jPlayer("playbackRate", val); } } function click_faster() { - val = parseFloat($("#pbvalue").text()) + 0.1; - if (val<=4.0){ + const val = parseFloat($("#pbvalue").text()) + 0.1; + if (val <= 4.0){ $("#pbvalue").text(val.toFixed(1)).css({'color': '#BBB'}) .animate({color: '#888'},150,function() {}); - $("#jquery_jplayer_1").jPlayer("playbackRate",val); + $("#jquery_jplayer_1").jPlayer("playbackRate", val); } } @@ -95,7 +94,7 @@ function click_stdspeed() { } function click_slower() { - var val = ($("#playbackrate :selected").val()); + let val = $("#playbackrate :selected").val(); if (val > 5) { val--; $("#playbackrate").val(val); @@ -104,7 +103,7 @@ function click_slower() { } function click_faster() { - var val = ($("#playbackrate :selected").val()); + let val = $("#playbackrate :selected").val(); if (val < 15) { val++; $("#playbackrate").val(val); From ca0e8993e4f3ca7b3e3562a5480103b80bc3e46f Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 15:31:01 +0100 Subject: [PATCH 02/40] Refactor audio_controller in object namespace style. Backward compatibility is kept. --- js/pgm.js | 31 +++--- src/js/audio_controller.js | 192 +++++++++++++++++++++++++------------ 2 files changed, 145 insertions(+), 78 deletions(-) diff --git a/js/pgm.js b/js/pgm.js index 6a18f8838..dd326a599 100644 --- a/js/pgm.js +++ b/js/pgm.js @@ -3,22 +3,23 @@ * * @license Unlicense */ -function new_pos(p){$("#jquery_jplayer_1").jPlayer("playHead",p)} -function set_new_playerseconds(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)} -function set_new_playbackrate(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)} -function set_current_playbackrate(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)} -function click_single(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1} -function click_repeat(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1} -function click_back(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) +const lwt_audio_controller={newPosition:function(position){$("#jquery_jplayer_1").jPlayer("playHead",position)},setNewPlayerseconds:function(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)},setNewPlaybackrate:function(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)},setCurrentPlaybackrate:function(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)},clickSingle:function(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1},clickRepeat:function(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1},clickBack:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) nt=0;if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) -st='play';$("#jquery_jplayer_1").jPlayer(st,nt)} -function click_forw(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);const nt=t+b;let st='pause';if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) -st='play';$("#jquery_jplayer_1").jPlayer(st,nt)} -function click_slower(){const val=parseFloat($("#pbvalue").text())-0.1;if(val>=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}} -function click_faster(){const val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}} -function click_stdspeed(){$("#playbackrate").val(10);set_new_playbackrate()} -function click_slower(){let val=$("#playbackrate :selected").val();if(val>5){val--;$("#playbackrate").val(val);set_new_playbackrate()}} -function click_faster(){let val=$("#playbackrate :selected").val();if(val<15){val++;$("#playbackrate").val(val);set_new_playbackrate()}};function CountUp(server_now,server_start,id,dontrun){if(server_now=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},clickFaster:function(){const val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},clickStdSpeed:function(){$("#playbackrate").val(10);this.setNewPlaybackRate()},clickSlower:function(){let val=$("#playbackrate :selected").val();if(val>5){val--;$("#playbackrate").val(val);this.setNewPlaybackRate()}},clickFaster:function(){let val=$("#playbackrate :selected").val();if(val<15){val++;$("#playbackrate").val(val);this.setNewPlaybackRate()}},} +function new_pos(p){return lwt_audio_controller.newPosition(p)} +function set_new_playerseconds(){return lwt_audio_controller.setNewPlayerseconds()} +function set_new_playbackrate(){return lwt_audio_controller.setNewPlaybackrate()} +function set_current_playbackrate(){return lwt_audio_controller.setCurrentPlaybackrate()} +function click_single(){return lwt_audio_controller.clickSingle()} +function click_repeat(){return lwt_audio_controller.clickRepeat()} +function click_back(){return lwt_audio_controller.clickBack()} +function click_forw(){return lwt_audio_controller.clickForward()} +function click_slower(){return lwt_audio_controller.clickSlower()} +function click_faster(){return lwt_audio_controller.clickFaster()} +function click_stdspeed(){return lwt_audio_controller.clickStdSpeed()} +function click_slower(){return lwt_audio_controller.clickSlower()} +function click_faster(){return lwt_audio_controller.clickFaster()};function CountUp(server_now,server_start,id,dontrun){if(server_now0){r+=hr<10?("0"+hr):hr;r+=":"} r+=min<10?("0"+min):min;r+=":";r+=sec<10?("0"+sec):sec;document.getElementById(id).innerHTML=r;if(this.dontrun)return;var self=this;setTimeout(function(){self.update(id)},1000)};/** * Control the interactions for making an automated feed wizard. diff --git a/src/js/audio_controller.js b/src/js/audio_controller.js index f21f6b6ee..7767b66b0 100644 --- a/src/js/audio_controller.js +++ b/src/js/audio_controller.js @@ -4,109 +4,175 @@ * @license Unlicense */ + +/* + * An audio controller. + */ +const lwt_audio_controller = { + /** + * Change the position of the audio player head. + * + * @param {Number} position New player head + */ + newPosition: function (position) { + $("#jquery_jplayer_1").jPlayer("playHead", position); + }, + + setNewPlayerseconds: function () { + const newval = $("#backtime :selected").val(); + do_ajax_save_setting('currentplayerseconds', newval); + }, + + setNewPlaybackrate: function () { + const newval = $("#playbackrate :selected").val(); + do_ajax_save_setting('currentplaybackrate', newval); + $("#jquery_jplayer_1").jPlayer("option","playbackRate", newval * 0.1); + }, + + setCurrentPlaybackrate: function () { + const val = $("#playbackrate :selected").val(); + $("#jquery_jplayer_1").jPlayer("option","playbackRate", val * 0.1); + }, + + clickSingle: function () { + $("#jquery_jplayer_1").off('bind', $.jPlayer.event.ended + ".jp-repeat"); + $("#do-single").addClass('hide'); + $("#do-repeat").removeClass('hide'); + do_ajax_save_setting('currentplayerrepeatmode','0'); + return false; + }, + + clickRepeat: function () { + $("#jquery_jplayer_1") + .on('bind', $.jPlayer.event.ended + ".jp-repeat", function(_event) { + $(this).jPlayer("play"); + }); + $("#do-repeat").addClass('hide'); + $("#do-single").removeClass('hide'); + do_ajax_save_setting('currentplayerrepeatmode','1'); + return false; + }, + + clickBack: function () { + const t = parseInt($("#playTime").text(), 10); + const b = parseInt($("#backtime").val(), 10); + let nt = t - b; + let st = 'pause'; + if (nt < 0) + nt = 0; + if (!$('#jquery_jplayer_1').data().jPlayer.status.paused) + st = 'play'; + $("#jquery_jplayer_1").jPlayer(st, nt); + }, + + clickForward: function () { + const t = parseInt($("#playTime").text(), 10); + const b = parseInt($("#backtime").val(), 10); + const nt = t + b; + let st = 'pause'; + if (!$('#jquery_jplayer_1').data().jPlayer.status.paused) + st = 'play'; + $("#jquery_jplayer_1").jPlayer(st, nt); + }, + + clickSlower: function () { + const val = parseFloat($("#pbvalue").text()) - 0.1; + if (val >= 0.5) { + $("#pbvalue").text(val.toFixed(1)).css({'color': '#BBB'}) + .animate({color: '#888'},150,function() {}); + $("#jquery_jplayer_1").jPlayer("playbackRate", val); + } + }, + + clickFaster: function () { + const val = parseFloat($("#pbvalue").text()) + 0.1; + if (val <= 4.0){ + $("#pbvalue").text(val.toFixed(1)).css({'color': '#BBB'}) + .animate({color: '#888'},150,function() {}); + $("#jquery_jplayer_1").jPlayer("playbackRate", val); + } + }, + + clickStdSpeed: function () { + $("#playbackrate").val(10); + this.setNewPlaybackRate(); + }, + + clickSlower: function () { + let val = $("#playbackrate :selected").val(); + if (val > 5) { + val--; + $("#playbackrate").val(val); + this.setNewPlaybackRate(); + } + }, + + clickFaster: function () { + let val = $("#playbackrate :selected").val(); + if (val < 15) { + val++; + $("#playbackrate").val(val); + this.setNewPlaybackRate(); + } + }, + +} + /** * Change the position of the audio player head. * * @param {Number} p New player head + * + * @deprecated Since LWT 2.9.1, use lwt_audio_controller.newPosition */ function new_pos(p) { - $("#jquery_jplayer_1").jPlayer("playHead", p); + return lwt_audio_controller.newPosition(p); } function set_new_playerseconds() { - const newval = $("#backtime :selected").val(); - do_ajax_save_setting('currentplayerseconds', newval); + return lwt_audio_controller.setNewPlayerseconds(); } function set_new_playbackrate() { - const newval = $("#playbackrate :selected").val(); - do_ajax_save_setting('currentplaybackrate', newval); - $("#jquery_jplayer_1").jPlayer("option","playbackRate", newval * 0.1); + return lwt_audio_controller.setNewPlaybackrate(); } function set_current_playbackrate() { - const val = $("#playbackrate :selected").val(); - $("#jquery_jplayer_1").jPlayer("option","playbackRate", val * 0.1); + return lwt_audio_controller.setCurrentPlaybackrate(); } function click_single() { - $("#jquery_jplayer_1").off('bind', $.jPlayer.event.ended + ".jp-repeat"); - $("#do-single").addClass('hide'); - $("#do-repeat").removeClass('hide'); - do_ajax_save_setting('currentplayerrepeatmode','0'); - return false; + return lwt_audio_controller.clickSingle(); } function click_repeat() { - $("#jquery_jplayer_1") - .on('bind', $.jPlayer.event.ended + ".jp-repeat", function(_event) { - $(this).jPlayer("play"); - }); - $("#do-repeat").addClass('hide'); - $("#do-single").removeClass('hide'); - do_ajax_save_setting('currentplayerrepeatmode','1'); - return false; + return lwt_audio_controller.clickRepeat(); } function click_back() { - const t = parseInt($("#playTime").text(), 10); - const b = parseInt($("#backtime").val(), 10); - let nt = t - b; - let st = 'pause'; - if (nt < 0) - nt = 0; - if (!$('#jquery_jplayer_1').data().jPlayer.status.paused) - st = 'play'; - $("#jquery_jplayer_1").jPlayer(st, nt); + return lwt_audio_controller.clickBack(); } function click_forw() { - const t = parseInt($("#playTime").text(), 10); - const b = parseInt($("#backtime").val(), 10); - const nt = t + b; - let st = 'pause'; - if (!$('#jquery_jplayer_1').data().jPlayer.status.paused) - st = 'play'; - $("#jquery_jplayer_1").jPlayer(st, nt); + return lwt_audio_controller.clickForward(); } function click_slower() { - const val = parseFloat($("#pbvalue").text()) - 0.1; - if (val >= 0.5) { - $("#pbvalue").text(val.toFixed(1)).css({'color': '#BBB'}) - .animate({color: '#888'},150,function() {}); - $("#jquery_jplayer_1").jPlayer("playbackRate", val); - } + return lwt_audio_controller.clickSlower(); } function click_faster() { - const val = parseFloat($("#pbvalue").text()) + 0.1; - if (val <= 4.0){ - $("#pbvalue").text(val.toFixed(1)).css({'color': '#BBB'}) - .animate({color: '#888'},150,function() {}); - $("#jquery_jplayer_1").jPlayer("playbackRate", val); - } + return lwt_audio_controller.clickFaster(); } function click_stdspeed() { - $("#playbackrate").val(10); - set_new_playbackrate(); + return lwt_audio_controller.clickStdSpeed(); } function click_slower() { - let val = $("#playbackrate :selected").val(); - if (val > 5) { - val--; - $("#playbackrate").val(val); - set_new_playbackrate(); - } + return lwt_audio_controller.clickSlower(); } function click_faster() { - let val = $("#playbackrate :selected").val(); - if (val < 15) { - val++; - $("#playbackrate").val(val); - set_new_playbackrate(); - } + return lwt_audio_controller.clickFaster(); } From 6775029d132610e920f6d74b026d3c2045c0339f Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 15:52:01 +0100 Subject: [PATCH 03/40] Fixes #138: changing audio speed was partially broken. --- docs/CHANGELOG.md | 14 ++++++++++---- docs/info.html | 14 ++++++++++---- inc/session_utility.php | 17 +++++++++++------ js/pgm.js | 10 +++++----- src/js/audio_controller.js | 20 ++++++++++---------- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ccc28ebcf..1f9a97bcd 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -21,14 +21,20 @@ ones are marked like "v1.0.0-fork". ### Fixed -* Fixes [#113](https://github.com/HugoFara/lwt/issues/113): changing a language name was making text-to-speech unusable and may prompt a warning. -* Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type"). This is fixed. +* Fixes [#113](https://github.com/HugoFara/lwt/issues/113): changing a language name +was making text-to-speech unusable and may prompt a warning. +* Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type"). * Since 2.9.0, audio position was not saved properly. * On `upload_words.php`, "update only empty fields" was broken. * Translation were not set by default properly when editing terms translations table. * The field MeCab was set for japanese even when not asked for. -Signalled on PR [#155](https://github.com/HugoFara/lwt/pull/155), thanks to [@ProgramComputer](https://github.com/ProgramComputer). -* Since 2.8.1, japanese word romanization was not displayed any more. Thanks to 아르노 for signalling the bug on Discord! +Signalled on PR [#155](https://github.com/HugoFara/lwt/pull/155), thanks to +[@ProgramComputer](https://github.com/ProgramComputer). +* Since 2.8.1, japanese word romanization was not displayed any more. +Thanks to 아르노 for signalling the bug on Discord! +* The go slower/faster feature on audio was broken +([#138](https://github.com/HugoFara/lwt/issues/138)), as functions `click_slower` +and `click_faster` were declared two times in `src/js/audio_controller.js`. ### Deprecated diff --git a/docs/info.html b/docs/info.html index 075c68809..af978aaaa 100644 --- a/docs/info.html +++ b/docs/info.html @@ -2200,14 +2200,20 @@

Changed

Fixed

    -
  • Fixes #113: changing a language name was making text-to-speech unusable and may prompt a warning.
  • -
  • Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type"). This is fixed.
  • +
  • Fixes #113: changing a language name +was making text-to-speech unusable and may prompt a warning.
  • +
  • Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type").
  • Since 2.9.0, audio position was not saved properly.
  • On upload_words.php, "update only empty fields" was broken.
  • Translation were not set by default properly when editing terms translations table.
  • The field MeCab was set for japanese even when not asked for. -Signalled on PR #155, thanks to @ProgramComputer.
  • -
  • Since 2.8.1, japanese word romanization was not displayed any more. Thanks to 아르노 for signalling the bug on Discord!
  • +Signalled on PR #155, thanks to +@ProgramComputer. +
  • Since 2.8.1, japanese word romanization was not displayed any more. +Thanks to 아르노 for signalling the bug on Discord!
  • +
  • The go slower/faster feature on audio was broken +(#138), as functions click_slower +and click_faster were declared two times in src/js/audio_controller.js.

Deprecated

    diff --git a/inc/session_utility.php b/inc/session_utility.php index e69c18e39..f4bd12fde 100644 --- a/inc/session_utility.php +++ b/inc/session_utility.php @@ -5184,13 +5184,18 @@ function addjPlayerMedia () { if ($('#jquery_jplayer_1').data().jPlayer.status.playbackRateEnabled) { $("#playbackrateContainer").css("margin-top",".2em") .html( - ` + `   - +   - + 1.0 @@ -5228,9 +5233,9 @@ function prepareMediaInteractions() { set_current_playbackrate(); }); - $("#slower").on('click', click_slower); - $("#faster").on('click', click_faster); - $("#stdspeed").on('click', click_stdspeed); + $("#slower").on('click', lwt_audio_controller.setSlower); + $("#faster").on('click', lwt_audio_controller.setFaster); + $("#stdspeed").on('click', lwt_audio_controller.setStdSpeed); $("#backbutt").on('click', click_back); $("#forwbutt").on('click', click_forw); $("#do-single").on('click', click_single); diff --git a/js/pgm.js b/js/pgm.js index dd326a599..eeb7e8231 100644 --- a/js/pgm.js +++ b/js/pgm.js @@ -3,10 +3,10 @@ * * @license Unlicense */ -const lwt_audio_controller={newPosition:function(position){$("#jquery_jplayer_1").jPlayer("playHead",position)},setNewPlayerseconds:function(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)},setNewPlaybackrate:function(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)},setCurrentPlaybackrate:function(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)},clickSingle:function(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1},clickRepeat:function(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1},clickBack:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) +const lwt_audio_controller={newPosition:function(position){$("#jquery_jplayer_1").jPlayer("playHead",position)},setNewPlayerseconds:function(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)},setNewPlaybackRate:function(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)},setCurrentPlaybackrate:function(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)},clickSingle:function(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1},clickRepeat:function(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1},clickBack:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) nt=0;if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) st='play';$("#jquery_jplayer_1").jPlayer(st,nt)},clickForward:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);const nt=t+b;let st='pause';if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) -st='play';$("#jquery_jplayer_1").jPlayer(st,nt)},clickSlower:function(){const val=parseFloat($("#pbvalue").text())-0.1;if(val>=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},clickFaster:function(){const val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},clickStdSpeed:function(){$("#playbackrate").val(10);this.setNewPlaybackRate()},clickSlower:function(){let val=$("#playbackrate :selected").val();if(val>5){val--;$("#playbackrate").val(val);this.setNewPlaybackRate()}},clickFaster:function(){let val=$("#playbackrate :selected").val();if(val<15){val++;$("#playbackrate").val(val);this.setNewPlaybackRate()}},} +st='play';$("#jquery_jplayer_1").jPlayer(st,nt)},clickSlower:function(){const val=parseFloat($("#pbvalue").text())-0.1;if(val>=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},clickFaster:function(){const val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},setStdSpeed:function(){$("#playbackrate").val(10);lwt_audio_controller.setNewPlaybackRate()},setSlower:function(){let val=$("#playbackrate :selected").val();if(val>5){val--;$("#playbackrate").val(val);lwt_audio_controller.setNewPlaybackRate()}},setFaster:function(){let val=$("#playbackrate :selected").val();if(val<15){val++;$("#playbackrate").val(val);lwt_audio_controller.setNewPlaybackRate()}},} function new_pos(p){return lwt_audio_controller.newPosition(p)} function set_new_playerseconds(){return lwt_audio_controller.setNewPlayerseconds()} function set_new_playbackrate(){return lwt_audio_controller.setNewPlaybackrate()} @@ -17,9 +17,9 @@ function click_back(){return lwt_audio_controller.clickBack()} function click_forw(){return lwt_audio_controller.clickForward()} function click_slower(){return lwt_audio_controller.clickSlower()} function click_faster(){return lwt_audio_controller.clickFaster()} -function click_stdspeed(){return lwt_audio_controller.clickStdSpeed()} -function click_slower(){return lwt_audio_controller.clickSlower()} -function click_faster(){return lwt_audio_controller.clickFaster()};function CountUp(server_now,server_start,id,dontrun){if(server_now0){r+=hr<10?("0"+hr):hr;r+=":"} r+=min<10?("0"+min):min;r+=":";r+=sec<10?("0"+sec):sec;document.getElementById(id).innerHTML=r;if(this.dontrun)return;var self=this;setTimeout(function(){self.update(id)},1000)};/** * Control the interactions for making an automated feed wizard. diff --git a/src/js/audio_controller.js b/src/js/audio_controller.js index 7767b66b0..64048d1b9 100644 --- a/src/js/audio_controller.js +++ b/src/js/audio_controller.js @@ -23,7 +23,7 @@ const lwt_audio_controller = { do_ajax_save_setting('currentplayerseconds', newval); }, - setNewPlaybackrate: function () { + setNewPlaybackRate: function () { const newval = $("#playbackrate :selected").val(); do_ajax_save_setting('currentplaybackrate', newval); $("#jquery_jplayer_1").jPlayer("option","playbackRate", newval * 0.1); @@ -93,26 +93,26 @@ const lwt_audio_controller = { } }, - clickStdSpeed: function () { + setStdSpeed: function () { $("#playbackrate").val(10); - this.setNewPlaybackRate(); + lwt_audio_controller.setNewPlaybackRate(); }, - clickSlower: function () { + setSlower: function () { let val = $("#playbackrate :selected").val(); if (val > 5) { val--; $("#playbackrate").val(val); - this.setNewPlaybackRate(); + lwt_audio_controller.setNewPlaybackRate(); } }, - clickFaster: function () { + setFaster: function () { let val = $("#playbackrate :selected").val(); if (val < 15) { val++; $("#playbackrate").val(val); - this.setNewPlaybackRate(); + lwt_audio_controller.setNewPlaybackRate(); } }, @@ -166,13 +166,13 @@ function click_faster() { } function click_stdspeed() { - return lwt_audio_controller.clickStdSpeed(); + return lwt_audio_controller.setStdSpeed(); } function click_slower() { - return lwt_audio_controller.clickSlower(); + return lwt_audio_controller.setSlower(); } function click_faster() { - return lwt_audio_controller.clickFaster(); + return lwt_audio_controller.setFaster(); } From 92c48c7a9ef6bfc2d811d37f1a36e64ea282a486 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 16:07:36 +0100 Subject: [PATCH 04/40] Replaces calls to global audio functions by the new object. Removes the undocumented audio functions. --- docs/CHANGELOG.md | 1 + docs/info.html | 1 + inc/session_utility.php | 22 +++++++++------- js/pgm.js | 23 +++++----------- src/js/audio_controller.js | 54 +++----------------------------------- src/js/jq_pgm.js | 19 ++++++++------ 6 files changed, 35 insertions(+), 85 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1f9a97bcd..58caeeb70 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -40,6 +40,7 @@ and `click_faster` were declared two times in `src/js/audio_controller.js`. * PHP documentation using Doxygen (under `/docs/html`) is now deprecated and will be removed in 3.0.0. * Using `$langDefs` is deprecated in favor of `LWT_LANGUAGES_ARRAY` ([#163](https://github.com/HugoFara/lwt/issues/163)). +* Calling the global function `new_pos` to set audio position is deprecated. Please use `lwt_audio_controller.setPosition`. ## 2.9.0-fork (December 24 2023) diff --git a/docs/info.html b/docs/info.html index af978aaaa..9d119c037 100644 --- a/docs/info.html +++ b/docs/info.html @@ -2219,6 +2219,7 @@

    Deprecated

    • PHP documentation using Doxygen (under /docs/html) is now deprecated and will be removed in 3.0.0.
    • Using $langDefs is deprecated in favor of LWT_LANGUAGES_ARRAY (#163).
    • +
    • Calling the global function new_pos to set audio position is deprecated. Please use lwt_audio_controller.setPosition.

    2.9.0-fork (December 24 2023)

    Added in 2.9.0-fork

    diff --git a/inc/session_utility.php b/inc/session_utility.php index f4bd12fde..70bab7b81 100644 --- a/inc/session_utility.php +++ b/inc/session_utility.php @@ -5042,7 +5042,7 @@ function makeAudioPlayer($audio, $offset=0) return; } $audio = trim($audio); - $repeatMode = getSettingZeroOrOne('currentplayerrepeatmode', 0); + $repeatMode = (bool) getSettingZeroOrOne('currentplayerrepeatmode', 0); $currentplayerseconds = getSetting('currentplayerseconds'); if ($currentplayerseconds == '') { $currentplayerseconds = 5; @@ -5230,20 +5230,22 @@ function prepareMediaInteractions() { $("#jquery_jplayer_1") .on('bind', $.jPlayer.event.play, function(event) { - set_current_playbackrate(); + lwt_audio_controller.setCurrentPlaybackRate(); }); $("#slower").on('click', lwt_audio_controller.setSlower); $("#faster").on('click', lwt_audio_controller.setFaster); $("#stdspeed").on('click', lwt_audio_controller.setStdSpeed); - $("#backbutt").on('click', click_back); - $("#forwbutt").on('click', click_forw); - $("#do-single").on('click', click_single); - $("#do-repeat").on('click', click_repeat); - $("#playbackrate").on('change', set_new_playbackrate); - $("#backtime").on('change', set_new_playerseconds); - - + $("#backbutt").on('click', lwt_audio_controller.clickBackward); + $("#forwbutt").on('click', lwt_audio_controller.clickForward); + $("#do-single").on('click', lwt_audio_controller.clickSingle); + $("#do-repeat").on('click', lwt_audio_controller.clickRepeat); + $("#playbackrate").on('change', lwt_audio_controller.setNewPlaybackRate); + $("#backtime").on('change', lwt_audio_controller.setNewPlayerSeconds); + + if () { + lwt_audio_controller.clickRepeat(); + } } $(document).ready(prepareMediaInteractions); diff --git a/js/pgm.js b/js/pgm.js index eeb7e8231..f26ef4495 100644 --- a/js/pgm.js +++ b/js/pgm.js @@ -3,23 +3,11 @@ * * @license Unlicense */ -const lwt_audio_controller={newPosition:function(position){$("#jquery_jplayer_1").jPlayer("playHead",position)},setNewPlayerseconds:function(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)},setNewPlaybackRate:function(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)},setCurrentPlaybackrate:function(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)},clickSingle:function(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1},clickRepeat:function(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1},clickBack:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) +const lwt_audio_controller={newPosition:function(position){$("#jquery_jplayer_1").jPlayer("playHead",position)},setNewPlayerSeconds:function(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)},setNewPlaybackRate:function(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)},setCurrentPlaybackRate:function(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)},clickSingle:function(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1},clickRepeat:function(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1},clickBackward:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) nt=0;if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) st='play';$("#jquery_jplayer_1").jPlayer(st,nt)},clickForward:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);const nt=t+b;let st='pause';if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) st='play';$("#jquery_jplayer_1").jPlayer(st,nt)},clickSlower:function(){const val=parseFloat($("#pbvalue").text())-0.1;if(val>=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},clickFaster:function(){const val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},setStdSpeed:function(){$("#playbackrate").val(10);lwt_audio_controller.setNewPlaybackRate()},setSlower:function(){let val=$("#playbackrate :selected").val();if(val>5){val--;$("#playbackrate").val(val);lwt_audio_controller.setNewPlaybackRate()}},setFaster:function(){let val=$("#playbackrate :selected").val();if(val<15){val++;$("#playbackrate").val(val);lwt_audio_controller.setNewPlaybackRate()}},} -function new_pos(p){return lwt_audio_controller.newPosition(p)} -function set_new_playerseconds(){return lwt_audio_controller.setNewPlayerseconds()} -function set_new_playbackrate(){return lwt_audio_controller.setNewPlaybackrate()} -function set_current_playbackrate(){return lwt_audio_controller.setCurrentPlaybackrate()} -function click_single(){return lwt_audio_controller.clickSingle()} -function click_repeat(){return lwt_audio_controller.clickRepeat()} -function click_back(){return lwt_audio_controller.clickBack()} -function click_forw(){return lwt_audio_controller.clickForward()} -function click_slower(){return lwt_audio_controller.clickSlower()} -function click_faster(){return lwt_audio_controller.clickFaster()} -function click_stdspeed(){return lwt_audio_controller.setStdSpeed()} -function click_slower(){return lwt_audio_controller.setSlower()} -function click_faster(){return lwt_audio_controller.setFaster()};function CountUp(server_now,server_start,id,dontrun){if(server_now0){r+=hr<10?("0"+hr):hr;r+=":"} r+=min<10?("0"+min):min;r+=":";r+=sec<10?("0"+sec):sec;document.getElementById(id).innerHTML=r;if(this.dontrun)return;var self=this;setTimeout(function(){self.update(id)},1000)};/** * Control the interactions for making an automated feed wizard. @@ -117,7 +105,9 @@ if(!JQ_TOOLTIP){this.title=make_tooltip($(this).text(),$(this).attr('data_trans' function mword_each_do_text_text(_){if($(this).attr('data_status')!=''){const wid=$(this).attr('data_wid');if(wid!=''){const order=parseInt($(this).attr('data_order'));for(let j=2;j<=16;j=j+2){const index=(order+j).toString();if(index in ANN_ARRAY){if(wid==ANN_ARRAY[index][1]){const ann=ANN_ARRAY[index][2];const re=new RegExp('(['+DELIMITER+'][ ]{0,1}|^)('+ann.replace(/[-\/\\^$*+?.()|[\]{}]/g,'\\$&')+')($|[ ]{0,1}['+DELIMITER+'])','');if(!re.test($(this).attr('data_trans').replace(/ \[.*$/,''))){const trans=ann+' / '+$(this).attr('data_trans');$(this).attr('data_trans',trans.replace(' / *',''))} $(this).attr('data_ann',ann);break}}}} if(!JQ_TOOLTIP){this.title=make_tooltip($(this).attr('data_text'),$(this).attr('data_trans'),$(this).attr('data_rom'),$(this).attr('data_status'))}}} -function word_dblclick_event_do_text_text(){const t=parseInt($('#totalcharcount').text(),10);if(t==0)return;let p=100*($(this).attr('data_pos')-5)/t;if(p<0)p=0;if(typeof(window.parent.frames.h.new_pos)==='function'){window.parent.frames.h.new_pos(p)}} +function word_dblclick_event_do_text_text(){const t=parseInt($('#totalcharcount').text(),10);if(t==0) +return;let p=100*($(this).attr('data_pos')-5)/t;if(p<0) +p=0;if(typeof(window.parent.frames.h.lwt_audio_controller.newPosition)==='function'){window.parent.frames.h.lwt_audio_controller.newPosition(p)}} function word_click_event_do_text_text(){const status=$(this).attr('data_status');let ann='';if($(this).attr('data_ann')!==undefined){ann=$(this).attr('data_ann')} let hints;if(JQ_TOOLTIP){hints=make_tooltip($(this).text(),$(this).attr('data_trans'),$(this).attr('data_rom'),status)}else{hints=$(this).attr('title')} const multi_words=Array(7);for(let i=0;i<7;i++){multi_words[i]=$(this).attr('data_mw'+(i+2))} @@ -161,7 +151,8 @@ if(dict_link.startsWith('ggl.php')){dict_link="http://"+dict_link} let open_url=!0;let final_url;try{final_url=new URL(dict_link);popup|=final_url.searchParams.has("lwt_popup")}catch(err){if(err instanceof TypeError){open_url=!1}} if(popup){owin('trans.php?x=1&i='+ord+'&t='+TID)}else if(open_url){showRightFrames(undefined,'trans.php?x=1&i='+ord+'&t='+TID)} return!1} -if(e.which==65){let p=curr.attr('data_pos');const t=parseInt($('#totalcharcount').text(),10);if(t==0)return!0;p=100*(p-5)/t;if(p<0)p=0;if(typeof(window.parent.frames.h.new_pos)==='function'){window.parent.frames.h.new_pos(p)}else{return!0} +if(e.which==65){let p=curr.attr('data_pos');const t=parseInt($('#totalcharcount').text(),10);if(t==0) +return!0;p=100*(p-5)/t;if(p<0)p=0;if(typeof(window.parent.frames.h.lwt_audio_controller.newPosition)==='function'){window.parent.frames.h.lwt_audio_controller.newPosition(p)}else{return!0} return!1} if(e.which==71){dict='&nodict';setTimeout(function(){let target_url=WBLINK3;let popup=!1;popup=target_url.startsWith('*');try{const final_url=new URL(target_url);popup|=final_url.searchParams.has('lwt_popup')}catch(err){if(!(err instanceof TypeError)){throw err}} if(popup){owin(createTheDictUrl(target_url,txt))}else{showRightFrames(undefined,createTheDictUrl(target_url,txt))}},10)} diff --git a/src/js/audio_controller.js b/src/js/audio_controller.js index 64048d1b9..ff16910ee 100644 --- a/src/js/audio_controller.js +++ b/src/js/audio_controller.js @@ -18,7 +18,7 @@ const lwt_audio_controller = { $("#jquery_jplayer_1").jPlayer("playHead", position); }, - setNewPlayerseconds: function () { + setNewPlayerSeconds: function () { const newval = $("#backtime :selected").val(); do_ajax_save_setting('currentplayerseconds', newval); }, @@ -29,7 +29,7 @@ const lwt_audio_controller = { $("#jquery_jplayer_1").jPlayer("option","playbackRate", newval * 0.1); }, - setCurrentPlaybackrate: function () { + setCurrentPlaybackRate: function () { const val = $("#playbackrate :selected").val(); $("#jquery_jplayer_1").jPlayer("option","playbackRate", val * 0.1); }, @@ -53,7 +53,7 @@ const lwt_audio_controller = { return false; }, - clickBack: function () { + clickBackward: function () { const t = parseInt($("#playTime").text(), 10); const b = parseInt($("#backtime").val(), 10); let nt = t - b; @@ -128,51 +128,3 @@ const lwt_audio_controller = { function new_pos(p) { return lwt_audio_controller.newPosition(p); } - -function set_new_playerseconds() { - return lwt_audio_controller.setNewPlayerseconds(); -} - -function set_new_playbackrate() { - return lwt_audio_controller.setNewPlaybackrate(); -} - -function set_current_playbackrate() { - return lwt_audio_controller.setCurrentPlaybackrate(); -} - -function click_single() { - return lwt_audio_controller.clickSingle(); -} - -function click_repeat() { - return lwt_audio_controller.clickRepeat(); -} - -function click_back() { - return lwt_audio_controller.clickBack(); -} - -function click_forw() { - return lwt_audio_controller.clickForward(); -} - -function click_slower() { - return lwt_audio_controller.clickSlower(); -} - -function click_faster() { - return lwt_audio_controller.clickFaster(); -} - -function click_stdspeed() { - return lwt_audio_controller.setStdSpeed(); -} - -function click_slower() { - return lwt_audio_controller.setSlower(); -} - -function click_faster() { - return lwt_audio_controller.setFaster(); -} diff --git a/src/js/jq_pgm.js b/src/js/jq_pgm.js index 4b9f76930..7adc3c938 100644 --- a/src/js/jq_pgm.js +++ b/src/js/jq_pgm.js @@ -628,11 +628,13 @@ function mword_each_do_text_text(_) { function word_dblclick_event_do_text_text () { const t = parseInt($('#totalcharcount').text(), 10); - if (t == 0) return; + if (t == 0) + return; let p = 100 * ($(this).attr('data_pos') - 5) / t; - if (p < 0) p = 0; - if (typeof (window.parent.frames.h.new_pos) === 'function') { - window.parent.frames.h.new_pos(p); + if (p < 0) + p = 0; + if (typeof (window.parent.frames.h.lwt_audio_controller.newPosition) === 'function') { + window.parent.frames.h.lwt_audio_controller.newPosition(p); } } @@ -1160,12 +1162,13 @@ function keydown_event_do_text_text (e) { if (e.which == 65) { // A : set audio pos. let p = curr.attr('data_pos'); const t = parseInt($('#totalcharcount').text(), 10); - if (t == 0) return true; + if (t == 0) + return true; p = 100 * (p - 5) / t; if (p < 0) p = 0; - if (typeof (window.parent.frames.h.new_pos) === 'function') { - window.parent.frames.h.new_pos(p); - } else { + if (typeof (window.parent.frames.h.lwt_audio_controller.newPosition) === 'function') { + window.parent.frames.h.lwt_audio_controller.newPosition(p); + } else { return true; } return false; From 7aaddd4d244c0457e701917662d89c8339bc2062 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 19:09:51 +0100 Subject: [PATCH 05/40] Avoid unnecessary function return type. --- js/pgm.js | 2 +- src/js/audio_controller.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/js/pgm.js b/js/pgm.js index f26ef4495..ceaf88b77 100644 --- a/js/pgm.js +++ b/js/pgm.js @@ -3,7 +3,7 @@ * * @license Unlicense */ -const lwt_audio_controller={newPosition:function(position){$("#jquery_jplayer_1").jPlayer("playHead",position)},setNewPlayerSeconds:function(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)},setNewPlaybackRate:function(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)},setCurrentPlaybackRate:function(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)},clickSingle:function(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0');return!1},clickRepeat:function(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(_event){$(this).jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1');return!1},clickBackward:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) +const lwt_audio_controller={newPosition:function(position){$("#jquery_jplayer_1").jPlayer("playHead",position)},setNewPlayerSeconds:function(){const newval=$("#backtime :selected").val();do_ajax_save_setting('currentplayerseconds',newval)},setNewPlaybackRate:function(){const newval=$("#playbackrate :selected").val();do_ajax_save_setting('currentplaybackrate',newval);$("#jquery_jplayer_1").jPlayer("option","playbackRate",newval*0.1)},setCurrentPlaybackRate:function(){const val=$("#playbackrate :selected").val();$("#jquery_jplayer_1").jPlayer("option","playbackRate",val*0.1)},clickSingle:function(){$("#jquery_jplayer_1").off('bind',$.jPlayer.event.ended+".jp-repeat");$("#do-single").addClass('hide');$("#do-repeat").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','0')},clickRepeat:function(){$("#jquery_jplayer_1").on('bind',$.jPlayer.event.ended+".jp-repeat",function(){$("#jquery_jplayer_1").jPlayer("play")});$("#do-repeat").addClass('hide');$("#do-single").removeClass('hide');do_ajax_save_setting('currentplayerrepeatmode','1')},clickBackward:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);let nt=t-b;let st='pause';if(nt<0) nt=0;if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) st='play';$("#jquery_jplayer_1").jPlayer(st,nt)},clickForward:function(){const t=parseInt($("#playTime").text(),10);const b=parseInt($("#backtime").val(),10);const nt=t+b;let st='pause';if(!$('#jquery_jplayer_1').data().jPlayer.status.paused) st='play';$("#jquery_jplayer_1").jPlayer(st,nt)},clickSlower:function(){const val=parseFloat($("#pbvalue").text())-0.1;if(val>=0.5){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},clickFaster:function(){const val=parseFloat($("#pbvalue").text())+0.1;if(val<=4.0){$("#pbvalue").text(val.toFixed(1)).css({'color':'#BBB'}).animate({color:'#888'},150,function(){});$("#jquery_jplayer_1").jPlayer("playbackRate",val)}},setStdSpeed:function(){$("#playbackrate").val(10);lwt_audio_controller.setNewPlaybackRate()},setSlower:function(){let val=$("#playbackrate :selected").val();if(val>5){val--;$("#playbackrate").val(val);lwt_audio_controller.setNewPlaybackRate()}},setFaster:function(){let val=$("#playbackrate :selected").val();if(val<15){val++;$("#playbackrate").val(val);lwt_audio_controller.setNewPlaybackRate()}},} diff --git a/src/js/audio_controller.js b/src/js/audio_controller.js index ff16910ee..7f2971459 100644 --- a/src/js/audio_controller.js +++ b/src/js/audio_controller.js @@ -39,18 +39,16 @@ const lwt_audio_controller = { $("#do-single").addClass('hide'); $("#do-repeat").removeClass('hide'); do_ajax_save_setting('currentplayerrepeatmode','0'); - return false; }, clickRepeat: function () { $("#jquery_jplayer_1") - .on('bind', $.jPlayer.event.ended + ".jp-repeat", function(_event) { - $(this).jPlayer("play"); + .on('bind', $.jPlayer.event.ended + ".jp-repeat", function() { + $("#jquery_jplayer_1").jPlayer("play"); }); $("#do-repeat").addClass('hide'); $("#do-single").removeClass('hide'); do_ajax_save_setting('currentplayerrepeatmode','1'); - return false; }, clickBackward: function () { From cd261c9e4609378c6086ad3d271eca6a36a7fe33 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 19:23:52 +0100 Subject: [PATCH 06/40] Fixes "text_id is unkown" on text opening. --- do_text_text.php | 10 +++++----- docs/CHANGELOG.md | 1 + docs/info.html | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/do_text_text.php b/do_text_text.php index 365a9d50e..6ff8c0bef 100644 --- a/do_text_text.php +++ b/do_text_text.php @@ -633,11 +633,11 @@ function do_text_text_javascript($var_array): void //; + const new_globals = ; // Set global variables - for (const key in vars) { - window[key] = vars[key]; + for (const key in new_globals) { + window[key] = new_globals[key]; } LANG = getLangFromDict(WBLINK3); TEXTPOS = -1; @@ -668,10 +668,10 @@ function saveCurrentPosition() { $('.wsty').not('.hide').each(function() { if ($(this).offset().top >= top_pos) { pos = $(this).attr('data_pos'); - return false; + return; } }); - saveReadingPosition(text_id, pos); + saveReadingPosition(TID, pos); } $(document).ready(prepareTextInteractions); diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 58caeeb70..bd4c0f371 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -35,6 +35,7 @@ Thanks to 아르노 for signalling the bug on Discord! * The go slower/faster feature on audio was broken ([#138](https://github.com/HugoFara/lwt/issues/138)), as functions `click_slower` and `click_faster` were declared two times in `src/js/audio_controller.js`. +* When opening a text, text position was not saved and a `text_id is unknown` error was triggered. ### Deprecated diff --git a/docs/info.html b/docs/info.html index 9d119c037..b35b1d930 100644 --- a/docs/info.html +++ b/docs/info.html @@ -2214,6 +2214,7 @@

    Fixed

  • The go slower/faster feature on audio was broken (#138), as functions click_slower and click_faster were declared two times in src/js/audio_controller.js.
  • +
  • When opening a text, text position was not saved and a text_id is unknown error was triggered.

Deprecated

    From 06ae8572d6319cda3841c58804a93063b0a4bf04 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 20:35:10 +0100 Subject: [PATCH 07/40] Fixes warning on step 2 of feed wizard (related to #129) --- docs/CHANGELOG.md | 2 ++ docs/info.html | 2 ++ feed_wizard.php | 59 +++++++++++++++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bd4c0f371..86afce7ae 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -36,6 +36,8 @@ Thanks to 아르노 for signalling the bug on Discord! ([#138](https://github.com/HugoFara/lwt/issues/138)), as functions `click_slower` and `click_faster` were declared two times in `src/js/audio_controller.js`. * When opening a text, text position was not saved and a `text_id is unknown` error was triggered. +* Do not display an error on step 2 of feed wizard at first initialization +([#129](https://github.com/HugoFara/lwt/issues/129)). ### Deprecated diff --git a/docs/info.html b/docs/info.html index b35b1d930..229eb732b 100644 --- a/docs/info.html +++ b/docs/info.html @@ -2215,6 +2215,8 @@

    Fixed

    (#138), as functions click_slower and click_faster were declared two times in src/js/audio_controller.js.
  • When opening a text, text position was not saved and a text_id is unknown error was triggered.
  • +
  • Do not display an error on step 2 of feed wizard at first initialization +(#129).

Deprecated

    diff --git a/feed_wizard.php b/feed_wizard.php index 635b4995c..d937620c9 100644 --- a/feed_wizard.php +++ b/feed_wizard.php @@ -535,17 +535,23 @@ function feed_wizard_select_text(): void $_SESSION['wizard']['article_tags']=''; foreach($article_tags as $tag){ if(substr_compare(trim($tag), "redirect", 0, 8)==0) { - $_SESSION['wizard']['redirect']=trim($tag).' | '; + $_SESSION['wizard']['redirect'] = trim($tag).' | '; } else { - $_SESSION['wizard']['article_tags'].='
  • -'.$tag.'
  • '; + $_SESSION['wizard']['article_tags'] .= '
  • + -' + . $tag . + '
  • '; } } $filter_tags=explode('|', str_replace('!?!', '|', $row['NfFilterTags'])); $_SESSION['wizard']['filter_tags']=''; foreach($filter_tags as $tag){ if(trim($tag)!='') { - $_SESSION['wizard']['filter_tags'].='
  • -'.$tag.'
  • '; + $_SESSION['wizard']['filter_tags'] .= '
  • + -' + . $tag. + '
  • '; } } $_SESSION['wizard']['feed']=get_links_from_new_feed($row['NfSourceURI']); @@ -556,8 +562,8 @@ function feed_wizard_select_text(): void } $_SESSION['wizard']['feed']['feed_title']=$row['NfName']; $_SESSION['wizard']['options']=$row['NfOptions']; - if(empty($_SESSION['wizard']['feed']['feed_text'])) { - $_SESSION['wizard']['feed']['feed_text']=''; + if (empty($_SESSION['wizard']['feed']['feed_text'])) { + $_SESSION['wizard']['feed']['feed_text'] = ''; $_SESSION['wizard']['detected_feed']='Detected: «Webpage Link»'; } $_SESSION['wizard']['lang']=$row['NfLgID']; @@ -568,7 +574,7 @@ function feed_wizard_select_text(): void } if($_SESSION['wizard']['feed']['feed_text']!=get_nf_option($_SESSION['wizard']['options'], 'article_source')) { $source=get_nf_option($_SESSION['wizard']['options'], 'article_source'); - $_SESSION['wizard']['feed']['feed_text']=$source; + $_SESSION['wizard']['feed']['feed_text'] = $source; $feed_len=count($_SESSION['wizard']['feed'])-2; for ($i=0;$i<$feed_len;$i++){ $_SESSION['wizard']['feed'][$i]['text']=$_SESSION['wizard']['feed'][$i][$source]; @@ -642,16 +648,16 @@ function feed_wizard_select_text(): void $host_name=$_REQUEST['host_name']; $_SESSION['wizard']['host'][$host_name]=$_REQUEST['host_status']; } - $feed_len=count($_SESSION['wizard']['feed'])-2; - if(isset($_REQUEST['NfName'])) { + $feed_len = count($_SESSION['wizard']['feed'])-2; + if (isset($_REQUEST['NfName'])) { $_SESSION['wizard']['feed']['feed_title']=$_REQUEST['NfName']; } - if(isset($_REQUEST['NfArticleSection']) && ($_REQUEST['NfArticleSection']!=$_SESSION['wizard']['feed']['feed_text'])) { - $_SESSION['wizard']['feed']['feed_text']=$_REQUEST['NfArticleSection']; - $source=$_SESSION['wizard']['feed']['feed_text']; - for ($i=0;$i<$feed_len;$i++){ - if($_SESSION['wizard']['feed']['feed_text']!='') { - $_SESSION['wizard']['feed'][$i]['text']=$_SESSION['wizard']['feed'][$i][$source]; + if (isset($_REQUEST['NfArticleSection']) && ($_REQUEST['NfArticleSection'] != $_SESSION['wizard']['feed']['feed_text'])) { + $_SESSION['wizard']['feed']['feed_text'] = $_REQUEST['NfArticleSection']; + $source = $_SESSION['wizard']['feed']['feed_text']; + for ($i = 0; $i < $feed_len; $i++) { + if ($_SESSION['wizard']['feed']['feed_text'] != '') { + $_SESSION['wizard']['feed'][$i]['text'] = $_SESSION['wizard']['feed'][$i][$source]; } else { unset($_SESSION['wizard']['feed'][$i]['text']); } @@ -747,18 +753,24 @@ function feed_wizard_select_text(): void From cfc8513009dd0e2934682fa4d70d2a9a70055a69 Mon Sep 17 00:00:00 2001 From: HugoFara Date: Wed, 27 Dec 2023 20:39:53 +0100 Subject: [PATCH 08/40] Reorders functions to be in logical declaration order. --- feed_wizard.php | 1419 ++++++++++++++++++++++++----------------------- 1 file changed, 713 insertions(+), 706 deletions(-) diff --git a/feed_wizard.php b/feed_wizard.php index d937620c9..8647c0fa9 100644 --- a/feed_wizard.php +++ b/feed_wizard.php @@ -4,474 +4,392 @@ require_once 'inc/session_utility.php'; - -function feed_wizard_edit_options(): void +function feed_wizard_insert_uri(): void { - global $tbpref; + if(isset($_REQUEST['select_mode'])) { + $_SESSION['wizard']['select_mode'] = $_REQUEST['select_mode']; + } + if(isset($_REQUEST['hide_images'])) { + $_SESSION['wizard']['hide_images'] = $_REQUEST['hide_images']; + } pagestart('Feed Wizard', false); - if(isset($_REQUEST['filter_tags'])) { - $_SESSION['wizard']['filter_tags']=$_REQUEST['filter_tags']; + if (isset($_REQUEST['err'])) { + echo '
    +

    +++ ERROR: PLEASE CHECK YOUR NEWSFEED URI!!! +++

    +
    '; } ?> -
    + - - - - - - - - - + - - - - - - - - - - - -
    Language: - - Field must not be empty -
    Name: - - Field must not be empty -
    Newsfeed url: Feed URI: - + + /> Field must not be empty
    Article Section: - - Field must not be empty -
    Filter Tags: - -
    Options: - - - - - - - - - - - - - -
    - - /> Edit Text - - - /> Auto Update Interval: - - /> - -
    - /> Max. Links: - /> - - /> Charset: type="text" data_info="Charset" size="20" name="charset" value="" /> -
    - /> - Max. Texts: - /> - - /> - Tag: - type="text" data_info="Tag" size="20" name="tag" - value="" - /> -
    -
    - '; - }?> - - - - - - + + + + +
    - + -' + . $tag . + ''; + } + } + $filter_tags=explode('|', str_replace('!?!', '|', $row['NfFilterTags'])); + $_SESSION['wizard']['filter_tags']=''; + foreach($filter_tags as $tag){ + if(trim($tag)!='') { + $_SESSION['wizard']['filter_tags'] .= '
  • + -' + . $tag. + '
  • '; + } + } + $_SESSION['wizard']['feed']=get_links_from_new_feed($row['NfSourceURI']); + if(empty($_SESSION['wizard']['feed'])) { + unset($_SESSION['wizard']['feed']); + header("Location: feed_wizard.php?step=1&err=1"); + exit(); + } + $_SESSION['wizard']['feed']['feed_title']=$row['NfName']; + $_SESSION['wizard']['options']=$row['NfOptions']; + if (empty($_SESSION['wizard']['feed']['feed_text'])) { + $_SESSION['wizard']['feed']['feed_text'] = ''; + $_SESSION['wizard']['detected_feed']='Detected: «Webpage Link»'; + } + $_SESSION['wizard']['lang']=$row['NfLgID']; + if($_SESSION['wizard']['feed']['feed_text']!='') { + $_SESSION['wizard']['detected_feed']='Detected: «'.$_SESSION['wizard']['feed']['feed_text'] .'»'; + } else { + $_SESSION['wizard']['detected_feed']='Detected: «Webpage Link»'; + } + if($_SESSION['wizard']['feed']['feed_text']!=get_nf_option($_SESSION['wizard']['options'], 'article_source')) { + $source=get_nf_option($_SESSION['wizard']['options'], 'article_source'); + $_SESSION['wizard']['feed']['feed_text'] = $source; + $feed_len=count($_SESSION['wizard']['feed'])-2; + for ($i=0;$i<$feed_len;$i++){ + $_SESSION['wizard']['feed'][$i]['text']=$_SESSION['wizard']['feed'][$i][$source]; + } + } + } else if(isset($_REQUEST['rss_url'])) { + if(!isset($_SESSION['wizard']) || empty($_SESSION['wizard']['feed'])||$_REQUEST['rss_url']!==$_SESSION['wizard']['rss_url']) { + $_SESSION['wizard']['feed']=get_links_from_new_feed($_REQUEST['rss_url']); + $_SESSION['wizard']['rss_url']=$_REQUEST['rss_url']; + if(empty($_SESSION['wizard']['feed'])) { + unset($_SESSION['wizard']['feed']); + header("Location: feed_wizard.php?step=1&err=1"); + exit(); + } + if(!isset($_SESSION['wizard']['article_tags'])) { + $_SESSION['wizard']['article_tags']=''; + } + if(!isset($_SESSION['wizard']['filter_tags'])) { + $_SESSION['wizard']['filter_tags']=''; + } + if(!isset($_SESSION['wizard']['options'])) { + $_SESSION['wizard']['options']='edit_text=1'; + } + if(!isset($_SESSION['wizard']['lang'])) { + $_SESSION['wizard']['lang']=''; + } + if($_SESSION['wizard']['feed']['feed_text']!='') { + $_SESSION['wizard']['detected_feed']='Detected: «'.$_SESSION['wizard']['feed']['feed_text'] .'»'; + } + else { + $_SESSION['wizard']['detected_feed']='Detected: «Webpage Link»'; + } + } else { + my_die("Something went wrong with the feed wizard!"); + } } - if(isset($_REQUEST['article_selector'])) { - $_SESSION['wizard']['article_selector'] = $_REQUEST['article_selector']; + if(isset($_REQUEST['filter_tags'])) { + $_SESSION['wizard']['filter_tags']=$_REQUEST['filter_tags']; } if(isset($_REQUEST['selected_feed'])) { - $_SESSION['wizard']['selected_feed'] = $_REQUEST['selected_feed']; - } - if(isset($_REQUEST['article_tags'])) { - $_SESSION['wizard']['article_tags'] = $_REQUEST['article_tags']; - } - if(isset($_REQUEST['html'])) { - $_SESSION['wizard']['filter_tags'] = $_REQUEST['html']; - } - if(isset($_REQUEST['NfOptions'])) { - $_SESSION['wizard']['options'] = $_REQUEST['NfOptions']; - } - if(isset($_REQUEST['NfLgID'])) { - $_SESSION['wizard']['lang'] = $_REQUEST['NfLgID']; - } - if(isset($_REQUEST['NfName'])) { - $_SESSION['wizard']['feed']['feed_title']=$_REQUEST['NfName']; - } - if(!isset($_SESSION['wizard']['article_tags'])) { - $_SESSION['wizard']['article_tags']=''; + $_SESSION['wizard']['selected_feed']=$_REQUEST['selected_feed']; } if(isset($_REQUEST['maxim'])) { $_SESSION['wizard']['maxim']=$_REQUEST['maxim']; } + if(!isset($_SESSION['wizard']['maxim'])) { + $_SESSION['wizard']['maxim']=1; + } if(isset($_REQUEST['select_mode'])) { $_SESSION['wizard']['select_mode']=$_REQUEST['select_mode']; } + if(!isset($_SESSION['wizard']['select_mode'])) { + $_SESSION['wizard']['select_mode']='0'; + } if(isset($_REQUEST['hide_images'])) { $_SESSION['wizard']['hide_images']=$_REQUEST['hide_images']; } - if(!isset($_SESSION['wizard']['select_mode'])) { - $_SESSION['wizard']['select_mode']=''; + if(!isset($_SESSION['wizard']['hide_images'])) { + $_SESSION['wizard']['hide_images']='yes'; } - if(!isset($_SESSION['wizard']['maxim'])) { - $_SESSION['wizard']['maxim']=1; + if(!isset($_SESSION['wizard']['redirect'])) { + $_SESSION['wizard']['redirect']=''; } if(!isset($_SESSION['wizard']['selected_feed'])) { $_SESSION['wizard']['selected_feed']=0; } - if(!isset($_SESSION['wizard']['host2'])) { - $_SESSION['wizard']['host2']=''; + if(!isset($_SESSION['wizard']['host'])) { + $_SESSION['wizard']['host'] = array(); } - if(isset($_REQUEST['host_status']) and isset($_REQUEST['host_name'])) { + if(isset($_REQUEST['host_status']) && isset($_REQUEST['host_name'])) { $host_name=$_REQUEST['host_name']; $_SESSION['wizard']['host'][$host_name]=$_REQUEST['host_status']; } - if(isset($_REQUEST['host_status2']) and isset($_REQUEST['host_name'])) { - $host_name=$_REQUEST['host_name']; - $_SESSION['wizard']['host2'][$host_name]=$_REQUEST['host_status2']; + $feed_len = count($_SESSION['wizard']['feed'])-2; + if (isset($_REQUEST['NfName'])) { + $_SESSION['wizard']['feed']['feed_title']=$_REQUEST['NfName']; + } + if (isset($_REQUEST['NfArticleSection']) && ($_REQUEST['NfArticleSection'] != $_SESSION['wizard']['feed']['feed_text'])) { + $_SESSION['wizard']['feed']['feed_text'] = $_REQUEST['NfArticleSection']; + $source = $_SESSION['wizard']['feed']['feed_text']; + for ($i = 0; $i < $feed_len; $i++) { + if ($_SESSION['wizard']['feed']['feed_text'] != '') { + $_SESSION['wizard']['feed'][$i]['text'] = $_SESSION['wizard']['feed'][$i][$source]; + } else { + unset($_SESSION['wizard']['feed'][$i]['text']); + } + unset($_SESSION['wizard']['feed'][$i]['html']); + } + $_SESSION['wizard']['host'] = array(); } - $feed_len=count($_SESSION['wizard']['feed'])-2; - pagestart_nobody("Feed Wizard"); + pagestart_nobody('Feed Wizard'); ?> - + -
    - - - + - + - + + + + + + + +
    - - + Newsfeed url: + - -
    Article Section: + +
    Article Source: + +
    +
    + + + + - @@ -867,13 +674,13 @@ function feed_wizard_select_text(): void - + - - + + -

    '; $i=$_SESSION['wizard']['selected_feed']; $a_feed = null; @@ -888,80 +695,280 @@ function feed_wizard_select_text(): void } echo $_SESSION['wizard']['feed'][$i]['html']; ?> - + -

    +++ ERROR: PLEASE CHECK YOUR NEWSFEED URI!!! +++

    - '; + if(isset($_REQUEST['filter_tags'])) { + $_SESSION['wizard']['filter_tags']=$_REQUEST['filter_tags']; } ?> - +
    + + + + - - 1) { ?> - + + 1) { ?> + + } ?> - + - + - - +
    - + + + + + + + + + + + + + + + + + + + + +
    Feed URI: Language: - - /> + + Field must not be empty +
    Name: + + Field must not be empty +
    Newsfeed url: + Field must not be empty
    Article Section: + + Field must not be empty +
    Filter Tags: + +
    Options: + + + + + + + + + + + + + +
    + + /> Edit Text + + + /> Auto Update Interval: + + /> + +
    + /> Max. Links: + /> + + /> Charset: type="text" data_info="Charset" size="20" name="charset" value="" /> +
    + /> + Max. Texts: + /> + + /> + Tag: + type="text" data_info="Tag" size="20" name="tag" + value="" + /> +
    +
    - - - - - + '; + }?> + + + + + + - Date: Wed, 27 Dec 2023 20:51:08 +0100 Subject: [PATCH 09/40] Code cleaning. --- feed_wizard.php | 154 +++++++++++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 59 deletions(-) diff --git a/feed_wizard.php b/feed_wizard.php index 8647c0fa9..afba55cd9 100644 --- a/feed_wizard.php +++ b/feed_wizard.php @@ -6,10 +6,10 @@ function feed_wizard_insert_uri(): void { - if(isset($_REQUEST['select_mode'])) { + if (isset($_REQUEST['select_mode'])) { $_SESSION['wizard']['select_mode'] = $_REQUEST['select_mode']; } - if(isset($_REQUEST['hide_images'])) { + if (isset($_REQUEST['hide_images'])) { $_SESSION['wizard']['hide_images'] = $_REQUEST['hide_images']; } pagestart('Feed Wizard', false); @@ -24,7 +24,8 @@ function feed_wizard_insert_uri(): void Feed URI: - /> @@ -42,7 +43,9 @@ function feed_wizard_insert_uri(): void $('h1') .eq(-1) .html( - 'Feed Wizard | Step 1 - Insert Newsfeed URI Help' + 'Feed Wizard | Step 1 - Insert Newsfeed URI ' + + '' + + 'Help' ) .css('text-align','center'); @@ -53,7 +56,7 @@ function feed_wizard_insert_uri(): void function feed_wizard_select_text(): void { global $tbpref; - if(isset($_REQUEST['edit_feed']) && !isset($_SESSION['wizard'])) { + if (isset($_REQUEST['edit_feed']) && !isset($_SESSION['wizard'])) { $_SESSION['wizard']['edit_feed']=$_REQUEST['edit_feed']; $result = do_mysqli_query( "SELECT * @@ -112,7 +115,7 @@ function feed_wizard_select_text(): void $_SESSION['wizard']['feed'][$i]['text']=$_SESSION['wizard']['feed'][$i][$source]; } } - } else if(isset($_REQUEST['rss_url'])) { + } else if (isset($_REQUEST['rss_url'])) { if(!isset($_SESSION['wizard']) || empty($_SESSION['wizard']['feed'])||$_REQUEST['rss_url']!==$_SESSION['wizard']['rss_url']) { $_SESSION['wizard']['feed']=get_links_from_new_feed($_REQUEST['rss_url']); $_SESSION['wizard']['rss_url']=$_REQUEST['rss_url']; @@ -134,7 +137,8 @@ function feed_wizard_select_text(): void $_SESSION['wizard']['lang']=''; } if($_SESSION['wizard']['feed']['feed_text']!='') { - $_SESSION['wizard']['detected_feed']='Detected: «'.$_SESSION['wizard']['feed']['feed_text'] .'»'; + $_SESSION['wizard']['detected_feed'] = 'Detected: «'. + $_SESSION['wizard']['feed']['feed_text'] .'»'; } else { $_SESSION['wizard']['detected_feed']='Detected: «Webpage Link»'; @@ -143,25 +147,25 @@ function feed_wizard_select_text(): void my_die("Something went wrong with the feed wizard!"); } } - if(isset($_REQUEST['filter_tags'])) { + if (isset($_REQUEST['filter_tags'])) { $_SESSION['wizard']['filter_tags']=$_REQUEST['filter_tags']; } - if(isset($_REQUEST['selected_feed'])) { + if (isset($_REQUEST['selected_feed'])) { $_SESSION['wizard']['selected_feed']=$_REQUEST['selected_feed']; } - if(isset($_REQUEST['maxim'])) { + if (isset($_REQUEST['maxim'])) { $_SESSION['wizard']['maxim']=$_REQUEST['maxim']; } if(!isset($_SESSION['wizard']['maxim'])) { $_SESSION['wizard']['maxim']=1; } - if(isset($_REQUEST['select_mode'])) { + if (isset($_REQUEST['select_mode'])) { $_SESSION['wizard']['select_mode']=$_REQUEST['select_mode']; } if(!isset($_SESSION['wizard']['select_mode'])) { $_SESSION['wizard']['select_mode']='0'; } - if(isset($_REQUEST['hide_images'])) { + if (isset($_REQUEST['hide_images'])) { $_SESSION['wizard']['hide_images']=$_REQUEST['hide_images']; } if(!isset($_SESSION['wizard']['hide_images'])) { @@ -176,7 +180,7 @@ function feed_wizard_select_text(): void if(!isset($_SESSION['wizard']['host'])) { $_SESSION['wizard']['host'] = array(); } - if(isset($_REQUEST['host_status']) && isset($_REQUEST['host_name'])) { + if (isset($_REQUEST['host_status']) && isset($_REQUEST['host_name'])) { $host_name=$_REQUEST['host_name']; $_SESSION['wizard']['host'][$host_name]=$_REQUEST['host_status']; } @@ -184,7 +188,10 @@ function feed_wizard_select_text(): void if (isset($_REQUEST['NfName'])) { $_SESSION['wizard']['feed']['feed_title']=$_REQUEST['NfName']; } - if (isset($_REQUEST['NfArticleSection']) && ($_REQUEST['NfArticleSection'] != $_SESSION['wizard']['feed']['feed_text'])) { + if ( + isset($_REQUEST['NfArticleSection']) && + ($_REQUEST['NfArticleSection'] != $_SESSION['wizard']['feed']['feed_text']) + ) { $_SESSION['wizard']['feed']['feed_text'] = $_REQUEST['NfArticleSection']; $source = $_SESSION['wizard']['feed']['feed_text']; for ($i = 0; $i < $feed_len; $i++) { @@ -262,7 +269,7 @@ function feed_wizard_select_text(): void if (isset($_REQUEST['html'])) { echo $_REQUEST['html']; } - if(isset($_REQUEST['article_tags']) || isset($_REQUEST['edit_feed'])) { + if (isset($_REQUEST['article_tags']) || isset($_REQUEST['edit_feed'])) { echo $_SESSION['wizard']['article_tags']; } ?> @@ -270,8 +277,10 @@ function feed_wizard_select_text(): void Name: - - Field must not be empty + + Field must not be empty @@ -283,7 +292,8 @@ function feed_wizard_select_text(): void Article Source: - - - + - - + - @@ -439,43 +456,43 @@ function feed_wizard_select_text(): void function feed_wizard_filter_text(): void { - if(isset($_REQUEST['NfName'])) { + if (isset($_REQUEST['NfName'])) { $_SESSION['wizard']['feed']['feed_title'] = $_REQUEST['NfName']; } - if(isset($_REQUEST['NfArticleSection'])) { + if (isset($_REQUEST['NfArticleSection'])) { $_SESSION['wizard']['article_section'] = $_REQUEST['NfArticleSection']; } - if(isset($_REQUEST['article_selector'])) { + if (isset($_REQUEST['article_selector'])) { $_SESSION['wizard']['article_selector'] = $_REQUEST['article_selector']; } - if(isset($_REQUEST['selected_feed'])) { + if (isset($_REQUEST['selected_feed'])) { $_SESSION['wizard']['selected_feed'] = $_REQUEST['selected_feed']; } - if(isset($_REQUEST['article_tags'])) { + if (isset($_REQUEST['article_tags'])) { $_SESSION['wizard']['article_tags'] = $_REQUEST['article_tags']; } - if(isset($_REQUEST['html'])) { + if (isset($_REQUEST['html'])) { $_SESSION['wizard']['filter_tags'] = $_REQUEST['html']; } - if(isset($_REQUEST['NfOptions'])) { + if (isset($_REQUEST['NfOptions'])) { $_SESSION['wizard']['options'] = $_REQUEST['NfOptions']; } - if(isset($_REQUEST['NfLgID'])) { + if (isset($_REQUEST['NfLgID'])) { $_SESSION['wizard']['lang'] = $_REQUEST['NfLgID']; } - if(isset($_REQUEST['NfName'])) { + if (isset($_REQUEST['NfName'])) { $_SESSION['wizard']['feed']['feed_title']=$_REQUEST['NfName']; } - if(!isset($_SESSION['wizard']['article_tags'])) { - $_SESSION['wizard']['article_tags']=''; + if (!isset($_SESSION['wizard']['article_tags'])) { + $_SESSION['wizard']['article_tags'] = ''; } - if(isset($_REQUEST['maxim'])) { + if (isset($_REQUEST['maxim'])) { $_SESSION['wizard']['maxim']=$_REQUEST['maxim']; } - if(isset($_REQUEST['select_mode'])) { + if (isset($_REQUEST['select_mode'])) { $_SESSION['wizard']['select_mode']=$_REQUEST['select_mode']; } - if(isset($_REQUEST['hide_images'])) { + if (isset($_REQUEST['hide_images'])) { $_SESSION['wizard']['hide_images']=$_REQUEST['hide_images']; } if(!isset($_SESSION['wizard']['select_mode'])) { @@ -490,11 +507,11 @@ function feed_wizard_filter_text(): void if(!isset($_SESSION['wizard']['host2'])) { $_SESSION['wizard']['host2']=''; } - if(isset($_REQUEST['host_status']) and isset($_REQUEST['host_name'])) { + if (isset($_REQUEST['host_status']) and isset($_REQUEST['host_name'])) { $host_name=$_REQUEST['host_name']; $_SESSION['wizard']['host'][$host_name]=$_REQUEST['host_status']; } - if(isset($_REQUEST['host_status2']) and isset($_REQUEST['host_name'])) { + if (isset($_REQUEST['host_status2']) and isset($_REQUEST['host_name'])) { $host_name=$_REQUEST['host_name']; $_SESSION['wizard']['host2'][$host_name]=$_REQUEST['host_status2']; } @@ -534,7 +551,8 @@ function feed_wizard_filter_text(): void }); }); -
    +
    + -
    + +

    Feed Wizard | Step 3 - Filter Text @@ -660,18 +679,21 @@ function feed_wizard_filter_text(): void - - + - - + - @@ -716,7 +738,7 @@ function feed_wizard_edit_options(): void { global $tbpref; pagestart('Feed Wizard', false); - if(isset($_REQUEST['filter_tags'])) { + if (isset($_REQUEST['filter_tags'])) { $_SESSION['wizard']['filter_tags']=$_REQUEST['filter_tags']; } ?> @@ -754,34 +776,44 @@ function feed_wizard_edit_options(): void ?> - Field must not be empty + Field must not be empty Name: - - Field must not be empty + + Field must not be empty Newsfeed url: - - Field must not be empty + + Field must not be empty Article Section: - - Field must not be empty + + Field must not be empty Filter Tags: - + @@ -806,7 +838,8 @@ function feed_wizard_edit_options(): void if(get_nf_option($_SESSION['wizard']['options'], 'autoupdate')!==null) { echo ' notempty'; } - ?>" data_info="Auto Update Interval" type="number" min="0" size="4" name="autoupdate" value="" data_info="Auto Update Interval" type="number" + min="0" size="4" name="autoupdate" value="" - '; }?> - + - -