First Commit

This commit is contained in:
PMKuipers 2023-05-26 15:21:13 +02:00
commit 5fe3baeb96
5 changed files with 322 additions and 0 deletions

216
classes/bible.php Normal file
View File

@ -0,0 +1,216 @@
<?php
namespace filter_bibleversesnwt;
class bible {
protected $books = null;
protected $lang = "en";
static function languages(){
$langcodes = ["nl","en"];
$languages = [];
foreach($langcodes as $l){
$languages[$l] = get_string("l_".$l,'filter_bibleversesnwt');
}
return $languages;
}
private function wolhref($book,$chapter,$verse,$verse_end=0){
$book = ($book > 0)?$book:1;
$chapter = ($chapter >0)?$chapter:1;
$verse = ($verse > 0)?$verse:1;
$verse_end = ($verse_end > $verse)?$verse_end:$verse;
if($this->lang == "nl"){
return "https://wol.jw.org/nl/wol/b/r18/lp-o/nwtsty/${book}/${chapter}#v=${book}:${chapter}:${verse}-${book}:${chapter}:${verse_end}";
}
else { // if $this->lang == 'en'
return "https://wol.jw.org/nl/wol/b/r1/lp-e/nwtsty/${book}/${chapter}#v=${book}:${chapter}:${verse}-${book}:${chapter}:${verse_end}";
}
}
static function booknames($lang){
$books = [
"nl" => [
[], // Intentionally left blank
["genesis","ge","gen"],
["exodus","ex"],
["leviticus","le","lev"],
["numeri","nu","num"],
["deuteronomium","de","deut"],
["jozua","joz"],
["rechters","re"],
["ruth","ru"],
["1 samuël","1 samuel","1sa","1sam","1 sam"],
["2 samuël","2 samuel","2sa","2sam","1 sam"],
["1 koningen","1kon","1 kon"],
["2 koningen","2kon","2 kon"],
["1 kronieken","1kr","1kron","1 kron"],
["2 kronieken","2kr","2kron","2 kron"],
["ezra","ezr"],
["nehemia","ne","neh"],
["esther","es"],
["job"],
["psalm","ps"],
["spreuken","sp", "spr"],
["prediker","pr","pred"],
["hooglied","hgl","hoogl"],
["jesaja","jes"],
["jeremia","jer"],
["klaagliederen","klg"],
["ezechiël","ezechiel","ez","eze","ezech"],
["daniël","daniel","da","dan"],
["hosea","ho","hos"],
["joël","joel","joë","joe"],
["amos","am"],
["obadja","ob"],
["jona","jon"],
["micha","mi","mic"],
["nahum","na", "nah"],
["habakuk","hab"],
["zefanja","ze"],
["haggai","haggaï","hag"],
["zacharia","za","zach"],
["maleachi","mal"],
["mattheus","mt", "mat","matt"],
["markus","mr"],
["lukas","lk"],
["johannes","jo", "joh"],
["handelingen","han"],
["romeinen","ro", "rom"],
["1 korinthiërs","1 korinthiers","1kor","1 kor"],
["2 korinthiërs","2 korinthiers","2kor","2 kor"],
["galaten","ga"],
["efziërs","efeziers","ef"],
["filippenzen","fil"],
["kolossenzen","kol"],
["1 thessalonicenzen","1th","1 thess", "1thess"],
["2 thessalonicenzen","2th","2 thess", "2thess"],
["1 timotheüs","1 timotheus","1ti", "1tim", "1 tim"],
["2 timotheüs","2 timotheus","2ti", "2tim", "2 tim"],
["titus","tit"],
["filemon","flm"],
["hebreeën","hebreeen","heb"],
["jakobus","jak"],
["1 petrus","1pe","1pet", "1 pet"],
["2 petrus","2pe","2pet", "2 pet"],
["1 johannes","1jo", "1joh","1 joh", "1 jo"],
["2 johannes","2jo", "2joh","2 joh", "2 jo"],
["3 johannes","3jo", "3joh","3 joh", "3 jo"],
["judas","ju", "jud"],
["openbaring","opb", "openb"],
],
"en" => [
[], // Intentionally left blank
["genesis","ge","gen"],
["exodus","ex"],
["leviticus","le","lev"],
["numbers","nu","num"],
["deuteronomium","de","deut"],
["joshua","jos"],
["rechters","jg"],
["ruth","ru"],
["1 samuel","1sa",],
["2 samuel","2sa",],
["1 kings","1ki",],
["2 kings","2ki",],
["1 chronicles","1ch",],
["2 chronicles","2ch",],
["ezra","ezr"],
["nehemia","ne","neh"],
["esther","es"],
["job"],
["psalm","ps"],
["proverbs","pr"],
["ecclesiastics","ec"],
["song of solomon","ca"],
["isaiah","isa"],
["jeremiah","jer"],
["lamentations","la"],
["ezekiel","eze"],
["daniel","da"],
["hosea","ho"],
["joel","joe"],
["amos","am"],
["obadiah","ob"],
["jonah","jon"],
["micah","mic"],
["nahum","na"],
["habakkuk","hab"],
["zephaniah","zep"],
["haggai","haggaï","hag"],
["zechariah","zec"],
["malachi","mal"],
["matthew","mt"],
["mark","mr"],
["luke","lk"],
["john","joh"],
["acts","ac"],
["romans","ro"],
["1 corinthians","1co"],
["2 corinthians","2co"],
["galatians","ga"],
["ephesians","eph"],
["philippians","php"],
["colossians","col"],
["1 thessalonians","1th"],
["2 thessalonians","2th"],
["1 timothy","1ti"],
["2 timothy","2ti"],
["titus","tit"],
["philemon","phm"],
["hebrews","heb"],
["james","jas"],
["1 peter","1pe"],
["2 peter","2pe"],
["1 john","1jo"],
["2 john","2jo"],
["3 john","3jo"],
["jude","ju"],
["revelation","re"],
]
];
return (array_key_exists($lang,$books))?$books[$lang]:$books["en"];
}
function __construct($lang="en"){
$this->books = static::booknames($lang);
$this->lang = $lang;
}
function parse($content){
for($booknum=1;$booknum<count($this->books);$booknum++){
$names = $this->books[$booknum];
foreach($names as $bookname){
$re = "/([1-3]?\s?\b{$bookname})\s*?(\d*):(\d+)(?:\s*?[-,]\s*?(\d+))?/i";
// First check the presence of the bookname before
if( ($ix = stripos($content,$bookname)) !== false){
$matches = [];
$content = preg_replace_callback($re,function ($m) use ($booknum, $bookname){
$book = strtolower(trim($m[1]));
$ch = $m[2];
$verse = $m[3];
$verse_to = (count($m)>4)?$m[4]:0;
if($book == $bookname){ // Check if name matches
$href = $this->wolhref($booknum,$ch,$verse,$verse_to);
return "<a href='{$href}' onclick='window.open(\"{$href}\",\"_bible_\",\"width=500,height=800\"); return false;' target='_bible_' class='bible-link'>".$m[0]."</a>";
} else {
return $m[0];
}
},$content);
}
}
}
return $content;
}
}

35
filter.php Normal file
View File

@ -0,0 +1,35 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Filter main class for the filter_pluginname plugin.
*
* @package filter_pluginname
* @copyright Year, You Name <your@email.address>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use filter_bibleversesnwt\bible;
class filter_bibleversesnwt extends moodle_text_filter {
function filter($text, array $options = []) {
// Return the modified text.
// return print_r($options,true).$text; // Debug to check content of options
$bible = new bible("nl");
return $bible->parse($text);
}
}

11
filterlocalsettings.php Normal file
View File

@ -0,0 +1,11 @@
<?php
use filter_bibleversesnwt\bible;
class bibleversesnwt_filter_local_settings_form extends filter_local_settings_form {
protected function definition_inner($mform) {
$mform->addElement('select', 'biblelang', get_string('biblelang', 'filter_bibleversesnwt'), bible::languages());
$mform->setType('biblelang', PARAM_NOTAGS);
}
}

View File

@ -0,0 +1,28 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Languages configuration for the filter_pluginname plugin.
*
* @package filter_pluginname
* @copyright Year, You Name <your@email.address>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['filtername'] = 'Bible verses auto-linking';
$string['biblelang'] = 'Language used for bible verse recognition';
$string['l_en'] = "English";
$string['l_nl'] = "Dutch";

32
version.php Normal file
View File

@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version metadata for the filter_pluginname plugin.
*
* @package filter_pluginname
* @copyright Year, You Name <your@email.address>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 20230525;
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11)
$plugin->component = 'filter_bibleversesnwt';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '1.0';