From 5fe3baeb962f776e795459c22420d0ca57c08970 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Fri, 26 May 2023 15:21:13 +0200 Subject: [PATCH] First Commit --- classes/bible.php | 216 ++++++++++++++++++++++++++++++ filter.php | 35 +++++ filterlocalsettings.php | 11 ++ lang/en/filter_bibleversesnwt.php | 28 ++++ version.php | 32 +++++ 5 files changed, 322 insertions(+) create mode 100644 classes/bible.php create mode 100644 filter.php create mode 100644 filterlocalsettings.php create mode 100644 lang/en/filter_bibleversesnwt.php create mode 100644 version.php diff --git a/classes/bible.php b/classes/bible.php new file mode 100644 index 0000000..5e2c456 --- /dev/null +++ b/classes/bible.php @@ -0,0 +1,216 @@ + 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;$booknumbooks);$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 "".$m[0].""; + } else { + return $m[0]; + } + },$content); + } + + } + } + return $content; + + + } + + +} \ No newline at end of file diff --git a/filter.php b/filter.php new file mode 100644 index 0000000..cbee00d --- /dev/null +++ b/filter.php @@ -0,0 +1,35 @@ +. + +/** + * Filter main class for the filter_pluginname plugin. + * + * @package filter_pluginname + * @copyright Year, You Name + * @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); + + } +} \ No newline at end of file diff --git a/filterlocalsettings.php b/filterlocalsettings.php new file mode 100644 index 0000000..cc1c54a --- /dev/null +++ b/filterlocalsettings.php @@ -0,0 +1,11 @@ +addElement('select', 'biblelang', get_string('biblelang', 'filter_bibleversesnwt'), bible::languages()); + $mform->setType('biblelang', PARAM_NOTAGS); + } + + +} \ No newline at end of file diff --git a/lang/en/filter_bibleversesnwt.php b/lang/en/filter_bibleversesnwt.php new file mode 100644 index 0000000..e4cd109 --- /dev/null +++ b/lang/en/filter_bibleversesnwt.php @@ -0,0 +1,28 @@ +. + +/** + * Languages configuration for the filter_pluginname plugin. + * + * @package filter_pluginname + * @copyright Year, You Name + * @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"; diff --git a/version.php b/version.php new file mode 100644 index 0000000..da8ef1a --- /dev/null +++ b/version.php @@ -0,0 +1,32 @@ +. + +/** + * Version metadata for the filter_pluginname plugin. + * + * @package filter_pluginname + * @copyright Year, You Name + * @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'; +