root/scripturizer/trunk/scripturizer.php

Revision 4593, 30.1 kB (checked in by xaglen, 3 years ago)

moved translations to global array, polished translation selection on options page

Line 
1<?php
2/*
3Plugin Name: Scripturizer
4Version: 1.55
5Plugin URI: http://dev.wp-plugins.org/wiki/Scripturizer
6Description: Changes Bible references to hyperlinks for Wordpress 1.5 and above. If you have a higher version of Wordpress you might want to upgrade the plugin.
7Author: Dean Peters, ported by Glen Davis, updates by LaurenceO.com
8Author URI: http://www.healyourchurchwebsite.com/
9*/
10
11// you can pick any translation supported by the Bible Gateway, as well as the NRSV, the NET, and the ESV
12// should we add Blue Letter Bible and http://www.zhubert.com/greek as original language options somehow? ....
13// http://www.blueletterbible.org/cgi-bin/tools/printer-friendly.pl?book=Gen&chapter=1&version=heb
14// http://www.blueletterbible.org/cgi-bin/tools/printer-friendly.pl?book=Mat&chapter=1&version=grk
15// the interface on zhubert.com is weird - the NT books are numbered instead of named
16// we should also take a look at the New American Bible - http://www.nccbuscc.com/nab/bible/index.htm
17
18$scripturizer_translations=array(
19        'NIV'=>'New International Version',
20        'KJV'=>'King James Version',
21        'ESV'=>'English Standard Version',
22        'NASB'=>'New American Standard Bible',
23        'HCSB'=>'Holman Christian Standard Bible',
24        'AMP'=>'Amplified Bible',
25        'NLV'=>'New Life Version',
26        'NLT'=>'New Living Translation',
27        'CEV'=>'Contemporary English Version',
28        'NKJV'=>'New King James Version',
29        'KJ21'=>'21st Century King James Version',
30        'ASV'=>'Authorized Standard Version',
31        'YLT'=>"Young's Literal Translation",
32        'Darby'=>'Darby Translation',
33        'WYC'=>'Wycliffe New Testament',
34        'NIV-UK'=>'New International Version (British Edition)',
35        'MSG'=>'The Message',
36        'NIRV'=>"New International Readers' Version",
37        'NET'=>'New English Translation',
38        'NRSV'=>'New Revised Standard Version',
39        'NA26'=>'Nestle-Aland Greek Text 26th edition',
40        'LXX'=>'Septaugint'
41        );
42
43##### ADMIN CONSOLE #
44
45if (! function_exists('scripturizer_add_options')) {
46  function scripturizer_add_options() {
47    if (function_exists('add_options_page')) {
48      add_options_page('Options', 'Scripturizer', 9, basename(__FILE__), 'scripturizer_options_subpanel');
49    }
50  }
51}
52
53// Show the admin page content
54function scripturizer_options_subpanel() {
55global $scripturizer_translations;
56// to do -- add libronix link
57// see http://www.logos.com/support/lbs/weblinking
58    if (isset($_POST['info_update'])) {
59        update_option('scripturizer_default_translation', $_POST['scripturizer_default_translation']);
60        update_option('scripturizer_dynamic_substitution', $_POST['scripturizer_dynamic_substitution']);
61        update_option('scripturizer_xml_show_hide', $_POST['scripturizer_xml_show_hide']);
62        update_option('scripturizer_esv_key', $_POST['scripturizer_esv_key']);
63        update_option('scripturizer_xml_css', $_POST['scripturizer_xml_css']);
64        update_option('scripturizer_esv_query_options', $_POST['scripturizer_esv_query_options']);
65    ?>
66        <div class="updated"><p><strong>
67            <?php _e('Updates saved!', 'Scripturizer');?>
68        </strong></p></div>
69    <?php
70    } ?>
71    <div class="wrap">
72        <h2><?php _e('Scripturizer 1.55', 'Scripturizer'); ?></h2>
73        <form method="post">
74        <fieldset class="options">
75            <legend><b><?php _e('General Options', 'Scripturizer'); ?></b></legend>
76
77            <p><b><?php _e('IMPORTANT NOTES', 'Scripturizer'); ?></b></p>
78
79            <ol>
80                <li><?php _e('You must press the UPDATE OPTIONS button at least once to install the default settings.', 'Scripturizer'); ?></li>
81                <li><?php _e('If you mess up one of the following inputs, then clear the field (make it blank), hit "update options," and then the default values will reappear. Then, you <b>must hit "update options" again</b> in order to save the new value.', 'Scripturizer'); ?></li>
82            </ol>
83
84
85            <p>
86            <label for="scripturizer_default_translation">
87           <b><?php _e('Default Bible Translation', 'Scripturizer'); ?></b>
88           <br /><?php _e('The Scripturizer supports any version from the <a href="http://www.biblegateway.com" title="Go to Bible Gateway">Bible Gateway</a> plus ESV, NET, NRSV, and LXX. However, this option must be ESV if you want to use the ESV show/hide verse text option.', 'Scripturizer'); ?>
89                   
90                   
91           <br /><select name="scripturizer_default_translation">
92                   <?php 
93                        if (get_option('scripturizer_default_translation') == ''){
94                    $scripturizer_default_translation='ESV';
95                }else {
96                 $scripturizer_default_translation=get_option('scripturizer_default_translation');// this is now defunct -- mess with it
97            } 
98                        ksort($scripturizer_translations);
99                        $translations=array_keys($scripturizer_translations);
100                        foreach ($translations as $translation) {
101                                if (strcmp($translation,$scripturizer_default_translation)) {
102                                        echo "<option value='$translation'>".$translation.' ('.$scripturizer_translations[$translation].')</option>';
103                                } else {
104                                        echo "<option value='$translation' selected>".$translation.' ('.$scripturizer_translations[$translation].')</option>';
105                                }
106                        }
107                        ?>
108                        </select>
109                       
110           </label>
111           </p>
112
113
114
115            <p>
116            <label for="scripturizer_dynamic_substitution">
117           <b><?php _e('Scripturizer Mode. Set to 1 for dynamic substitutions. Set to 0 for permament changes.', 'Scripturizer'); ?></b>
118           <br /><input type="text" name="scripturizer_dynamic_substitution" value="<?php
119                if (get_option('scripturizer_dynamic_substitution') == ''){
120                    echo '1';
121                }else {
122                 echo get_option('scripturizer_dynamic_substitution');
123                } ?>" size="3" />
124           </label>
125
126           <br /><?php _e('You can use this plugin two ways; it can either scripturize your posts every time someone views them (dynamic), or it can permanently scripturize the posts whenever you create or edit them (static). If (1) you have a medium to high traffic site and (2) you use lots of verse references in your posts, then you probably want to use static mode. Otherwise, most low traffic blog sites should be OK in dynamic mode.', 'Scripturizer'); ?>
127            </p>
128            <p>
129            <?php _e('Considerations for Static Mode', 'Scripturizer'); ?>
130            </p>
131
132                <ol>
133                <li><?php _e('If Bible Gateway or any of the other Bible sites change their interface, then your old posts won\'t work right even if you update this plugin (whereas if you use dynamic substitution updating the plugin fixes all old and future posts transparently). This is not a theoretical consideration--the Bible sites have changed their interfaces since this plugin was first developed and they are likely to do so again.', 'Scripturizer'); ?></li>
134                <li><?php _e('If you change your default Bible translation then old posts will not be updated to reflect your new preference.', 'Scripturizer'); ?></li>
135                <li><?php _e('Since it only changes posts when you edit them, you need to go back through all your old posts with Bible', 'Scripturizer'); ?></li>
136                <li><?php _e('References and edit them to cause the plugin to take effect', 'Scripturizer'); ?></li>
137                </ol>
138
139        </fieldset>
140<p>&nbsp;</p>
141        <fieldset class="options">
142            <legend><b><?php _e('ESV Show/Hide Verse Text Options', 'Scripturizer'); ?></b></legend>
143            <p>
144            <label for="scripturizer_xml_show_hide">
145           <b><?php _e('Show/hide the text (in addition to the reference) of the ESV in your page? If yes, set to 1. If no, set to 0.', 'Scripturizer'); ?></b>
146           <br /><?php _e('Do not set to 1 unless you have an ESV Web Services Key.', 'Scripturizer'); ?>
147           <br /><input type="text" name="scripturizer_xml_show_hide" value="<?php
148                if (get_option('scripturizer_xml_show_hide') == ''){
149                    echo '0';
150                }else {
151                 echo get_option('scripturizer_xml_show_hide');
152                } ?>" size="3" />
153           </label>
154           </p>
155
156            <p>
157            <label for="scripturizer_esv_key">
158            <b><?php _e('ESV Web Service Key', 'Scripturizer'); ?></b><br />
159            <?php _e('The ESV Web Service now has a <a href="http://www.esv.org/blog/2005/10/web.service.keyless">keyless option</a>. Therefore, you no longer need your key to use the show/hide ESV text option. Instead, use <b><code>IP</code></b> as your key. However, if you are using shared-IP hosting (i.e. more than one site is hosted on your IP address) you will likely need your own key. To get your free key, follow the simple instructions at <a href="http://www.gnpcb.org/esv/share/services/">http://www.gnpcb.org/esv/share/services/</a>', 'Scripturizer' ); ?><br />
160            <input type="text" name="scripturizer_esv_key" value="<?php
161            if (!get_option('scripturizer_esv_key')){
162                echo 'IP';
163            }else {
164             echo get_option('scripturizer_esv_key');
165            } ?>" size="30" />
166            </label>
167            </p>
168            <p>
169            <label for="scripturizer_xml_css">
170            <b><?php _e('CSS for ESV inline verse display', 'Scripturizer'); ?></b><br />
171            <?php _e('This CSS modifies the SPAN tag in which the ESV verse text will be displayed on your page. Do not use any line breaks--that means don\'t push your ENTER key in this box--since the styles are added straight to the span tag.', 'Scripturizer'); ?>
172            <br />
173            <?php
174                if (get_option('scripturizer_xml_css') == ''){
175                    $LO_esv_form_css = 'white-space: pre; display: none; padding: 10px; border: dotted blue 1px; border-left: solid blue 5px; color: black;';
176                } else {
177                    $LO_esv_form_css = get_option('scripturizer_xml_css');
178                } ?>
179
180            <textarea name="scripturizer_xml_css" cols="50" rows="10" wrap="VIRTUAL"><?php echo $LO_esv_form_css; ?></textarea>
181            </label>
182            </p>
183
184            <p>
185            <label for="scripturizer_esv_query_options">
186            <b><?php _e('ESV Web Service <a href="http://www.gnpcb.org/esv/share/services/api/">Query Options</a>', 'Scripturizer'); ?></b><br />
187                <?php
188                    if (get_option('scripturizer_esv_query_options') == ''){
189                        $LO_esv_form_qo = 'action=doPassageQuery&include-passage-references=true&include-short-copyright=true&include-audio-link=false&output-format=plain-text&include-passage-horizontal-lines=false&include-heading-horizontal-lines=false&line-length=60&include-headings=false&include-subheadings=false&include-footnotes=false';
190                } else {
191                    $LO_esv_form_qo = get_option('scripturizer_esv_query_options');
192                } ?>
193
194            <textarea name="scripturizer_esv_query_options" cols="50" rows="6" wrap="VIRTUAL"><?php echo $LO_esv_form_qo; ?></textarea>
195            </label>
196            </p>
197        </fieldset>
198
199    <p class="submit">
200    <input type="submit" name="info_update" value="<?php _e('Update Options', 'Scripturizer') ?>" />
201    </p>
202    </form>
203
204    <fieldset class="options">
205        <legend><b><?php _e('Credits: "Give honor to whom honor is due"', 'Scripturizer'); ?></b></legend>
206
207        <p><?php _e('The story is too complicated to tell here. The main props go to <a href="http://www.healyourchurchwebsite.com/">Dean Peters</a> and you can learn more at the <a href="http://dev.wp-plugins.org/wiki/Scripturizer">Scripturizer central page</a>.', 'Scripturizer'); ?></p>
208    </fieldset>
209   
210
211    <fieldset class="options">
212        <legend><b><?php _e('Updates and Bug Tracking', 'Scripturizer'); ?></b></legend>
213
214        <p><?php _e('Report bugs, request new features, download the latest updates, and contact the authors at <a href="http://dev.wp-plugins.org/wiki/Scripturizer">the Scripturizer Page</a>.', 'Scripturizer'); ?></p>
215    </fieldset>
216
217    </div>
218
219<?php
220} // close scripturizer_options_subpanel()
221# END ADMIN CONSOLE #####
222
223function scripturize($text = '',$bible = NULL) {
224
225        if (!isset($bible)) {
226                $bible = get_option('scripturizer_default_translation');
227        }
228    // skip everything within a hyperlink, a <pre> block, a <code> block, or a tag
229    // we skip inside tags because something like <img src="nicodemus.jpg" alt="John 3:16"> should not be messed with
230        $anchor_regex = '<a\s+href.*?<\/a>';
231        $pre_regex = '<pre>.*<\/pre>';
232        $code_regex = '<code>.*<\/code>';
233        $other_plugin_regex= '\[bible\].*\[\/bible\]'; // for the ESV Wordpress plugin (out of courtesy)
234        $other_plugin_block_regex='\[bibleblock\].*\[\/bibleblock\]'; // ditto
235        $tag_regex = '<(?:[^<>\s]*)(?:\s[^<>]*){0,1}>'; // $tag_regex='<[^>]+>';
236        $split_regex = "/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$other_plugin_regex)|(?:$other_plugin_block_regex)|(?:$tag_regex))/i";
237// $split_regex = "/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$tag_regex))/i";       
238        $parsed_text = preg_split($split_regex,$text,-1,PREG_SPLIT_DELIM_CAPTURE);
239        $linked_text = '';
240
241  while (list($key,$value) = each($parsed_text)) {
242      if (preg_match($split_regex,$value)) {
243         $linked_text .= $value; // if it is an HTML element or within a link, just leave it as is
244      } else {
245        $linked_text .= scripturizeAddLinks($value,$bible); // if it's text, parse it for Bible references
246      }
247  }
248
249  return $linked_text;
250}
251
252
253function getEsvText($volume, $book, $verse) {
254    //Get passage text from ESV web site
255    $esvPassage = htmlentities(urlencode(trim("$volume $book $verse")));
256    $esvUrl = "http://www.gnpcb.org/esv/share/get/?key=". get_option('scripturizer_esv_key') ."&passage=$esvPassage&". get_option('scripturizer_esv_query_options');
257    $esvCh = curl_init($esvUrl);
258    curl_setopt($esvCh, CURLOPT_RETURNTRANSFER, 1);
259    $esvResponse = curl_exec($esvCh);
260    curl_close($esvCh);
261
262// Get rid of triple and double line breaks since WP turns them into <p>'s and thereby kills our <span>
263//    $esvResponse = str_replace("\n\n\n", "\n", $esvResponse);
264    $esvResponse = str_replace("\n\n", "\n", $esvResponse);
265
266    // Build the show/hide link
267    $esvSpanId = 'scripturizer' .mt_rand(); //prefix the rand number with "id" to pass XHTML validation
268    $output_dynamic = " <a href=\"javascript://\" onclick=\"showhide('"
269        . $esvSpanId
270        . "');\">[+/-]</a><span id=\""
271        . $esvSpanId
272        . "\" style=\""
273        . get_option('scripturizer_xml_css')
274        . "\">"
275        . $esvResponse
276        . "<br /><a href=\"http://www.esv.org/\"><img src=\"http://www.esv.org/assets/buttons/small.7.png\" alt=\"This text is from the ESV Bible. Visit www.esv.org to learn about the ESV.\" title=\"Visit www.esv.org to learn about the ESV Bible\" width=\"80\" height=\"21\" /></a>"
277        . "</span>";
278       
279
280    // I don't know why, but I ran into bugs when switching between dynamic and static modes based on how WP parsed the '' in the onclick action.
281    // So, for now, I decided to have two different outputs. The static mode escapes the ' by using a double ''.
282    // The dynamic output does not need to escape the ' -- (go figure!)
283    $output_static = " <a href=\"javascript://\" onclick=\"showhide(''"
284        . $esvSpanId
285        . "'');\">[+/-]</a><span id=\""
286        . $esvSpanId
287        . "\" style=\""
288        . get_option('scripturizer_xml_css')
289        . "\">"
290        . $esvResponse
291        . "<br /><a href=\"http://www.esv.org/\"><img src=\"http://www.esv.org/assets/buttons/small.7.png\" alt=\"This text is from the ESV Bible. Visit www.esv.org to learn about the ESV.\" title=\"Visit www.esv.org to learn about the ESV Bible\" width=\"80\" height=\"21\" /></a>"
292        . "</span>";
293
294    if (get_option('scripturizer_dynamic_substitution')) {
295        return $output_dynamic;
296    } else {
297        return $output_static;
298    }
299}
300function scripturizeAddLinks($text = '',$bible = NULL) {
301global $scripturizer_translations;
302
303        if (!isset($bible)) {
304                $bible=get_option('scripturizer_default_translation');
305        }
306       
307    $volume_regex = '1|2|3|I|II|III|1st|2nd|3rd|First|Second|Third';
308
309    $book_regex  = 'Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther';
310    $book_regex .= '|Job|Psalms?|Proverbs?|Ecclesiastes|Songs? of Solomon|Song of Songs|Isaiah|Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|Zechariah|Malachi';
311    $book_regex .= '|Mat+hew|Mark|Luke|John|Acts?|Acts of the Apostles|Romans|Corinthians|Galatians|Ephesians|Phil+ippians|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|Jude|Revelations?';
312
313        // I split these into two different variables from Dean's original Perl code because I want to be able to have an optional period at the end of just the abbreviations
314
315    $abbrev_regex  = 'Gen|Ex|Exo|Lev|Num|Nmb|Deut?|Josh?|Judg?|Jdg|Rut|Sam|Ki?n|Chr(?:on?)?|Ezr|Neh|Est';
316    $abbrev_regex .= '|Jb|Psa?|Pr(?:ov?)?|Eccl?|Song?|Isa|Jer|Lam|Eze|Dan|Hos|Joe|Amo|Oba|Jon|Mic|Nah|Hab|Zeph?|Hag|Zech?|Mal';
317    $abbrev_regex .= '|Mat+|Mr?k|Lu?k|Jh?n|Jo|Act|Rom|Cor|Gal|Eph|Col|Phil?|The?|Thess?|Tim|Tit|Phile|Heb|Ja?m|Pe?t|Ju?d|Rev';
318
319    $book_regex='(?:'.$book_regex.')|(?:'.$abbrev_regex.')\.?';
320
321    $verse_regex="\d{1,3}(?::\d{1,3})?(?:\s?(?:[-&,]\s?\d+))*";
322
323        // non Bible Gateway translations are all together at the end to make it easier to maintain the list
324        $translation_regex = implode('|',array_keys($scripturizer_translations)); // makes it look like 'NIV|KJV|ESV' etc
325
326        // note that this will be executed as PHP code after substitution thanks to the /e at the end!
327    $passage_regex = '/(?:('.$volume_regex.')\s)?('.$book_regex.')\s('.$verse_regex.')(?:\s?[,-]?\s?((?:'.$translation_regex.')|\s?\((?:'.$translation_regex.')\)))?/e';
328
329    $replacement_regex = "scripturizeLinkReference('\\0','\\1','\\2','\\3','\\4','$bible')";
330
331    $text=preg_replace($passage_regex,$replacement_regex,$text);
332
333    return $text;
334}
335
336function scripturizeLinkReference($reference='',$volume='',$book='',$verse='',$translation='',$user_translation='') {
337    if ($volume) {
338       $volume = str_replace('III','3',$volume);
339           $volume = str_replace('Third','3',$volume);   
340       $volume = str_replace('II','2',$volume);
341           $volume = str_replace('Second','2',$volume);     
342       $volume = str_replace('I','1',$volume);
343           $volume = str_replace('First','1',$volume);     
344       $volume = $volume{0}; // will remove st,nd,and rd (presupposes regex is correct)
345    }
346       
347        //catch an obscure bug where a sentence like "The 3 of us went downtown" triggers a link to 1 Thess 3
348        if (!strcmp(strtolower($book),"the") && $volume=='' ) {
349                return $reference;
350        }
351
352   if(!$translation) {
353         if (!$user_translation) {
354             $translation = get_option('scripturizer_default_translation');
355         } else {
356             $translation = $user_translation;
357         }
358   } else {
359       $translation = trim($translation,' ()'); // strip out any parentheses that might have made it this far
360   }
361
362   // if necessary, just choose part of the verse reference to pass to the web interfaces
363   // they wouldn't know what to do with John 5:1-2, 5, 10-13 so I just give them John 5:1-2
364   // this doesn't work quite right with something like 1:5,6 - it gets chopped to 1:5 instead of converted to 1:5-6
365   if ($verse) {
366       $verse = strtok($verse,',& ');
367   }
368
369        if (get_option('scripturizer_libronix')) {
370                $libronix=sprintf('<a title="View %s in Logos Bible Software Series X" href="libronixdls:keylink|ref=[en]bible:%s"><img border="0" src="%s/wp-content/LibronixLink.gif"></a>',trim("$volume $book $verse"),htmlentities(trim("$volume $book $verse")),get_settings('siteurl'));
371        }
372
373   switch ($translation) {
374        case 'ESV':
375        // note: the ESV could actually support a mouseover reference
376        // we could pull it directly from their site and include it in the $title text
377        // http://www.gnpcb.org/esv/share/services/api/ for more info
378             $link = 'http://www.gnpcb.org/esv/search/?go=Go&amp;q=';
379             $title = 'English Standard Version Bible';
380             $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
381        # Insert Show/Hide link and include ESV verse text
382        if (get_option('scripturizer_xml_show_hide')) {
383            $link .= getEsvText($volume, $book, $verse);
384        }
385             break;
386        case 'NET':
387                // example URL http://www.bible.org/netbible2/index.php?book=gen&chapter=1&verse=1&submit=Lookup+Verse
388             $link = 'http://www.bible.org/netbible2/index.php';
389             $title = 'New English Translation';
390             $chapter = trim(strtok($verse,':'));
391             $verses = trim(strtok('-,'));
392             $book = scripturizeNETBook($volume.' '.$book);
393             $link = sprintf('<a href="%s?book=%s&amp;chapter=%s&amp;verse=%s&amp;submit=Lookup+Verse" title="%s">%s</a>',$link,htmlentities(urlencode($book)),$chapter,$verses,$title,trim($reference));
394             break;
395        case 'NRSV':
396        // example URL http://bible.oremus.org/?passage=John+1%3A1&vnum=yes&version=nrsv
397        // there is a new interface being developed at http://bible.oremus.org/bible.cgi
398             $link = 'http://bible.oremus.org/';
399             $title = 'New Revised Standard Version';
400                         $options ='&amp;vnum=yes&amp;version=nrsv';
401             $link = sprintf('<a href="%s?passage=%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$options,$title,trim($reference));
402             break;
403        case 'NA26':
404        case 'LXX':
405        // example URL http://www.zhubert.com/bible?book=Matthew&chapter=2&verse=3
406        // there's also an XML interface to this content - could do a trick like I propose with the ESV
407             $link = 'http://www.zhubert.com/bible';
408             $title = 'original language at zhubert.com';
409                        $chapter=zhubertize_chapter($verse);
410                        $verse=zhubertize_verse($verse);
411                        $book=zhubertize_book($volume.' '.$book); 
412             $link = sprintf('<a href="%s?book=%s&amp;chapter=%d&amp;verse=%d" title="%s">%s</a>',$link,htmlentities(urlencode(trim($book))),$chapter,$verse,$title,trim($reference));
413             break;
414        default:
415                // Bible Gateway has a ton of translations, so just make it the default instead of checking for each one
416                // $translation_regex takes care of ensuring that only valid translations make it this far, anyway
417                // api at http://biblegateway.com/usage/linking/
418             $link = "http://biblegateway.com/bible?version=$translation&amp;passage=";
419             $title = 'Bible Gateway';
420             $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
421             break;
422    }
423       
424        if (get_option('scripturizer_libronix')) {
425                $link.=$libronix;
426        }
427       
428return $link;
429}
430
431function scripturizeNETBook($book='') {
432// need this function because NET Bible needs rigid input
433// it's not perfect, so someone who intends to link to the NET Bible must be cautious with their syntax
434// Jn 5:1 won't work, for example (must be 'joh' or 'john').
435    $book = strtolower(trim($book));
436    if (!$book) return '';
437
438    $book = preg_replace('/\s+/', '', $book); //strip whitespace
439
440    switch ($book) {
441           case 'judges':
442                $book = 'jdg';
443                break;
444           case 'songofsongs':
445           case 'songofsolomon':
446           case 'song':
447                $book = 'sos';
448                break;
449           case 'philemon':
450                 $book = 'phm';
451                 break;
452           default:
453                   $book = substr($book,0,3);
454    }
455    return $book;
456}
457
458function zhubertize_chapter($reference="") {
459        $chapter=strtok($reference,':');
460        return $chapter;
461}
462
463function zhubertize_verse($reference="") {
464        $chapter=strtok($reference,':');
465        $verse=strtok(' ,-;');
466        if (!$verse) {
467                $verse=1;
468        }
469        return $verse;
470}
471
472function zhubertize_book($rawbook) {
473        // ultimately I need to restore all abbreviations to the full book.
474        // perhaps take the first three letters and expand?
475        $book = strtolower(trim($rawbook));
476    $book = preg_replace('/\s+/', '', $book); //strip whitespace
477        $book= substr($book,0,3);
478        switch ($book) {
479                case 'gen':
480                        $book='Genesis';
481                        break;
482                case 'exo':
483                case 'ex':
484                        $book='Exodus';
485                        break;
486                case 'lev':
487                case 'lv':
488                        $book='Leviticus';
489                        break;
490                case 'num':
491                        $book='Numbers';
492                        break;
493                case 'deu':
494                case 'dt':
495                        $book='Deuteronomy';
496                        break;
497                case 'jos':
498                        $book='Joshua';
499                        break;
500                case 'jud':
501                case 'jd': 
502                        // could be either Judges or Jude
503                        // abbreviations for Judges should always have a g in them
504                        $judges=strpos($rawbook,'g');
505                        if ($judges===FALSE) {
506                                $book='Jude';
507                        } else {
508                                $book='Judges';
509                        }
510                        break;
511                case 'rut':
512                case 'rth':
513                        $book='Ruth';
514                        break;
515                case '1sa':
516                        $book='1 Samuel';
517                        break;
518                case '2sa':
519                        $book='2 Samuel';
520                        break;
521                case '1ki':
522                        $book='1 Kings';
523                        break;
524                case '2ki':
525                        $book='2 Kings';
526                        break;
527                case '1ch':
528                        $book='1 Chronicles';
529                        break;
530                case '2ch':
531                        $book='2 Chronicles';
532                        break;
533                case 'ezr':
534                case 'ez':
535                        $book='Ezra';
536                        break;
537                case 'neh':
538                case 'nh':
539                        $book='Nehemiah';
540                        break;
541                case 'est':
542                        $book='Esther';
543                        break;
544                case 'job':
545                case 'jb':
546                        $book='Job';
547                        break;
548                case 'psa':
549                case 'ps':
550                        $book='Psalms';
551                        break;
552                case 'pro':
553                case 'pr':
554                        $book='Proverbs';
555                        break;
556                case 'ecc':
557                        $book='Qoheleth';
558                        break;
559                case 'son':
560                case 'sos':
561                        $book='Canticle of Canticles';
562                        break;
563                case 'isa':
564                case 'is':
565                        $book='Isaiah';
566                        break;
567                case 'jer':
568                        $book='Jeremiah';
569                        break;
570                case 'eze':
571                case 'ez':
572                        $book='Ezekiel';
573                        break;
574                case 'dan':
575                case 'dn':
576                        $book='Daniel';
577                        break;
578                case 'hos':
579                        $book='Hosea';
580                        break;
581                case 'joe':
582                        $book='Joel';
583                        break;
584                case 'amo':
585                case 'am':
586                        $book='Amos';
587                        break