moodle-filter_bibleversesnwt/classes/bible.php

216 lines
7.8 KiB
PHP
Raw Normal View History

2023-05-26 15:21:13 +02:00
<?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;
}
}