? esv.css
? esv_tooltip.js
Index: scripturefilter.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/scripturefilter/scripturefilter.inc,v
retrieving revision 1.6
diff -u -r1.6 scripturefilter.inc
--- scripturefilter.inc	21 May 2007 16:40:51 -0000	1.6
+++ scripturefilter.inc	14 Jun 2007 21:16:55 -0000
@@ -1,58 +1,203 @@
 <?php
-/* $Id: scripturefilter.inc,v 1.6 2007/05/21 16:40:51 smsimms Exp $ */
+/* $Id: scripturefilter.inc,v 1.3.4.1 2007/05/21 16:45:34 smsimms Exp $ */
+
+//edited to pull Bible Translation from settings.
+define('DEFAULT_BIBLE_TRANSLATION',variable_get("scripturefilter_default_translation_format", 'NIV'));
+
+$scripturizer_translations = array(); ### Global arrary of Bible translations
+	//abbrv - Abbreviation of the Bible translation name, using the Bible Gateway as the standard
+	//name - Full name of Bible translation, using the Bible Gateway...
+	//gateway_id - the ID for use with the Bible Gateway
+$scripturizer_translations[0]['abbrv'] = 'ALAB';
+$scripturizer_translations[0]['name'] = 'Arabic Life Application Bible';
+$scripturizer_translations[0]['gateway_id'] = '28';
+
+$scripturizer_translations[1]['abbrv'] = 'BULG';
+$scripturizer_translations[1]['name'] = 'Bulgarian Bible';
+$scripturizer_translations[1]['gateway_id'] = '21';
+
+$scripturizer_translations[2]['abbrv'] = 'BG1940';
+$scripturizer_translations[2]['name'] = '1940 Bulgarian Bible';
+$scripturizer_translations[2]['gateway_id'] = '82';
+
+$scripturizer_translations[3]['abbrv'] = 'HCV';
+$scripturizer_translations[3]['name'] = 'Haitian Creole Version ';
+$scripturizer_translations[3]['gateway_id'] = '23';
+
+$scripturizer_translations[4]['abbrv'] = 'SNC';
+$scripturizer_translations[4]['name'] = 'Slovo na cestu';
+$scripturizer_translations[4]['gateway_id'] = '29';
+
+$scripturizer_translations[5]['abbrv'] = 'DN1933';
+$scripturizer_translations[5]['name'] = 'Dette er Biblen pÃ¥ dansk';
+$scripturizer_translations[5]['gateway_id'] = '';
+
+$scripturizer_translations[6]['abbrv'] = 'ELB';
+$scripturizer_translations[6]['name'] = 'Elberfelder';
+$scripturizer_translations[6]['gateway_id'] = '54';
+
+$scripturizer_translations[7]['abbrv'] = 'HOF';
+$scripturizer_translations[7]['name'] = 'Hoffnung für Alle';
+$scripturizer_translations[7]['gateway_id'] = '33';
+
+$scripturizer_translations[8]['abbrv'] = 'LUTH1545';
+$scripturizer_translations[8]['name'] = 'Luther Bibel 1545';
+$scripturizer_translations[8]['gateway_id'] = '10';
+
+$scripturizer_translations[9]['abbrv'] = 'AMP';
+$scripturizer_translations[9]['name'] = 'Amplified Bible';
+$scripturizer_translations[9]['gateway_id'] = '45';
+
+$scripturizer_translations[10]['abbrv'] = 'ASV';
+$scripturizer_translations[10]['name'] = 'American Standard Version';
+$scripturizer_translations[10]['gateway_id'] = '8';
+
+$scripturizer_translations[11]['abbrv'] = 'CEV';
+$scripturizer_translations[11]['name'] = 'Contemporary English Version';
+$scripturizer_translations[11]['gateway_id'] = '46';
+
+$scripturizer_translations[12]['abbrv'] = 'DARBY';
+$scripturizer_translations[12]['name'] = 'Darby Translation';
+$scripturizer_translations[12]['gateway_id'] = '16';
+
+$scripturizer_translations[13]['abbrv'] = 'DRA';
+$scripturizer_translations[13]['name'] = 'Douay-Rheims 1899 American Edition';
+$scripturizer_translations[13]['gateway_id'] = '63';
+
+$scripturizer_translations[14]['abbrv'] = 'ESV';
+$scripturizer_translations[14]['name'] = 'English Standard Version';
+$scripturizer_translations[14]['gateway_id'] = '47';
+
+$scripturizer_translations[15]['abbrv'] = 'HCSB';
+$scripturizer_translations[15]['name'] = 'Holman Christian Standard Bible';
+$scripturizer_translations[15]['gateway_id'] = '77';
+
+$scripturizer_translations[16]['abbrv'] = 'KJ21';
+$scripturizer_translations[16]['name'] = '21st Century King James Version';
+$scripturizer_translations[16]['gateway_id'] = '48';
+
+$scripturizer_translations[17]['abbrv'] = 'KJV';
+$scripturizer_translations[17]['name'] = 'King James Version';
+$scripturizer_translations[17]['gateway_id'] = '9';
+
+$scripturizer_translations[18]['abbrv'] = 'MSG';
+$scripturizer_translations[18]['name'] = 'The Message';
+$scripturizer_translations[18]['gateway_id'] = '65';
+
+$scripturizer_translations[19]['abbrv'] = 'NASB';
+$scripturizer_translations[19]['name'] = 'New American Standard Bible';
+$scripturizer_translations[19]['gateway_id'] = '49';
+
+$scripturizer_translations[20]['abbrv'] = 'NIRV';
+$scripturizer_translations[20]['name'] = 'New International Reader\'s Version';
+$scripturizer_translations[20]['gateway_id'] = '76';
+
+$scripturizer_translations[21]['abbrv'] = 'NIV';
+$scripturizer_translations[21]['name'] = 'New International Version';
+$scripturizer_translations[21]['gateway_id'] = '31';
+
+$scripturizer_translations[22]['abbrv'] = 'NIVUK';
+$scripturizer_translations[22]['name'] = 'New International Version - UK';
+$scripturizer_translations[22]['gateway_id'] = '64';
+
+$scripturizer_translations[23]['abbrv'] = 'NKJV';
+$scripturizer_translations[23]['name'] = 'New King James Version';
+$scripturizer_translations[23]['gateway_id'] = '50';
+
+$scripturizer_translations[24]['abbrv'] = 'NLT';
+$scripturizer_translations[24]['name'] = 'New Living Translation';
+$scripturizer_translations[24]['gateway_id'] = '51';
+
+$scripturizer_translations[25]['abbrv'] = 'NLV';
+$scripturizer_translations[25]['name'] = 'New Life Version';
+$scripturizer_translations[25]['gateway_id'] = '74';
+
+$scripturizer_translations[26]['abbrv'] = 'TNIV';
+$scripturizer_translations[26]['name'] = 'Today\'s New International Version';
+$scripturizer_translations[26]['gateway_id'] = '72';
+
+$scripturizer_translations[27]['abbrv'] = 'WE';
+$scripturizer_translations[27]['name'] = 'Worldwide English (New Testament)';
+$scripturizer_translations[27]['gateway_id'] = '73';
+
+$scripturizer_translations[28]['abbrv'] = 'WYC';
+$scripturizer_translations[28]['name'] = 'Wycliffe New Testament';
+$scripturizer_translations[28]['gateway_id'] = '53';
+
+$scripturizer_translations[29]['abbrv'] = 'YLT';
+$scripturizer_translations[29]['name'] = 'Young\'s Literal Translation';
+$scripturizer_translations[29]['gateway_id'] = '15';
+
+// Sort the array alphabetically by translation name
+foreach ($scripturizer_translations as $key => $row) {
+   $n[$key] = $row['name'];
+}
+array_multisort($n, SORT_ASC, $scripturizer_translations);
 
-define('DEFAULT_BIBLE_TRANSLATION','NIV');
 
 function scripturize ($text = '',$bible = DEFAULT_BIBLE_TRANSLATION){
     // skip everything within a hyperlink, a <pre> block, a <code> block, or a tag
     // we skip tags because something like <img src="blah" alt="John 3:16"> should not be messed with
-    $anchor_regex = '<a\s+href.*?<\/a>';
-    $pre_regex = '<pre>.*<\/pre>';
-    $code_regex = '<code>.*<\/code>';
-    $tag_regex = '<(?:[^<>\s]*)(?:\s[^<>]*){0,1}>'; // $tag_regex='<[^>]+>';
-    $split_regex = "/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$tag_regex))/i";
-
-    $parsed_text = preg_split($split_regex,$text,-1,PREG_SPLIT_DELIM_CAPTURE);
-    $linked_text = '';
-
-    while (list($key,$value) = each($parsed_text)) {
-        if (preg_match($split_regex,$value)) {
-	    $linked_text .= $value; // if it is an HTML element or within a link, just leave it as is
-	} else {
-            $linked_text .= scripturizeAddLinks($value,$bible); // if it's text, parse it for Bible references
+
+	if (!isset($bible)) {
+		$bible = gvariable_get("scripturefilter_default_translation_format", DEFAULT_BIBLE_TRANSLATION);
 	}
-    }
-    
-    return $linked_text;
+    // skip everything within a hyperlink, a <pre> block, a <code> block, or a tag
+    // we skip inside tags because something like <img src="nicodemus.jpg" alt="John 3:16"> should not be messed with
+	$anchor_regex = '<a\s+href.*?<\/a>';
+	$pre_regex = '<pre>.*<\/pre>';
+	$code_regex = '<code>.*<\/code>';
+	$other_plugin_regex= '\[bible\].*\[\/bible\]'; // for the ESV Wordpress plugin (out of courtesy)
+	$other_plugin_block_regex='\[bibleblock\].*\[\/bibleblock\]'; // ditto
+	$tag_regex = '<(?:[^<>\s]*)(?:\s[^<>]*){0,1}>'; // $tag_regex='<[^>]+>';
+	$split_regex = "/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$other_plugin_regex)|(?:$other_plugin_block_regex)|(?:$tag_regex))/i";
+
+	//    $split_regex = "/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$tag_regex))/i";
+	$parsed_text = preg_split($split_regex,$text,-1,PREG_SPLIT_DELIM_CAPTURE);
+	$linked_text = '';
+
+  while (list($key,$value) = each($parsed_text)) {
+      if (preg_match($split_regex,$value)) {
+         $linked_text .= $value; // if it is an HTML element or within a link, just leave it as is
+      } else {
+        $linked_text .= scripturizeAddLinks($value,$bible); // if it's text, parse it for Bible references
+      }
+  }
+
+  return $linked_text;
 }
 
 function scripturizeAddLinks($text = '',$bible = DEFAULT_BIBLE_TRANSLATION) {
-    $volume_regex = '1|2|3|I|II|III|1st|2nd|3rd|First|Second|Third';
 
-    $book_regex  = 'Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther';
-    $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';
-    $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?';
+	if (!isset($bible)) {
+	//Pull Bible translation from 
+	$bible=variable_get("scripturefilter_default_translation_format", DEFAULT_BIBLE_TRANSLATION);
+	}
 
-    // split these up from the Perl code because I want to be able to have an optional period at the end of just the abbreviations
+		$volume_regex = '1|2|3|I|II|III|1st|2nd|3rd|First|Second|Third';
 
-    $abbrev_regex  = 'Gen|Ex|Exo|Lev|Num|Nmb|Deut?|Josh?|Judg?|Jdg|Rut|Sam|Ki?n|Chr(?:on?)?|Ezr|Neh|Est';
-    $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';
-    $abbrev_regex .= '|Mat|Mr?k|Lu?k|Jh?n|Jo|Act|Rom|Cor|Gal|Eph|Col|Phi|The?|Thess?|Tim|Tit|Phile|Heb|Ja?m|Pe?t|Ju?d|Rev';
+		$book_regex  = 'Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther';
+		$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';
+		$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?';
 
-    $book_regex='(?:'.$book_regex.')|(?:'.$abbrev_regex.')\.?';
+		$abbrev_regex  = 'Gen|Ex|Exo|Lev|Num|Nmb|Deut?|Josh?|Judg?|Jdg|Rut|Sam|Ki?n|Chr(?:on?)?|Ezr|Neh|Est';
+		$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';
+		$abbrev_regex .= '|Mat|Mr?k|Lu?k|Jh?n|Jo|Act|Rom|Cor|Gal|Eph|Col|Phi(?:l?)?|The?|Thess?|Tim|Tit|Phile|Heb|Ja?m|Pe?t|Ju?d|Rev';
 
-    $verse_regex="\d{1,3}(?::\d{1,3})?(?:\s?(?:[-&,]\s?\d+))*";
+		$book_regex = '(?:'.$book_regex.')|(?:'.$abbrev_regex.')\.?';
 
-    $translation_regex = 'NIV|NASB|AMP|NLT|KJV|ESV|CEV|NET|NKJV|KJ21|ASV|WE|YLT|DARBY|WYC|NIV-UK|TNIV|MSG|NIRV';
+		$verse_substr_regex = "(?:[:.][0-9]{1,3})?(?:[-&,;]\s?[0-9]{1,3})*";
+		$verse_regex = "[0-9]{1,3}(?:". $verse_substr_regex ."){1,2}";
 
-    // note that this will be executed as PHP code after substitution thanks to the /e at the end!
+    $translation_regex = 'NIV|NASB|AMP|NLT|KJV|ESV|CEV|NET|NKJV|KJ21|ASV|WE|YLT|DARBY|WYC|NIV-UK|TNIV|MSG|NIRV';
 
+	// note that this will be executed as PHP code after substitution thanks to the /e at the end!
     $passage_regex = '/(?:('.$volume_regex.')\s)?('.$book_regex.')\s('.$verse_regex.')(?:\s?[,-]?\s?((?:'.$translation_regex.')|\s?\((?:'.$translation_regex.')\)))?/e';
 
     $replacement_regex = "scripturizeLinkReference('\\0','\\1','\\2','\\3','\\4','$bible')";
 
     $text=preg_replace($passage_regex,$replacement_regex,$text);
-
+	
     return $text;
 }
 
@@ -74,6 +219,9 @@
        $translation = trim($translation,' ()'); // strip out any parentheses that might have made it this far
    }
 
+   $passage = $volume ."+". $book."+".$verse;
+   $Verse = $volume . " " . $book . " " . $verse;
+   
    // if necessary, just choose part of the verse reference to pass to the web interfaces
    // they wouldn't know what to do with John 5:1-2, 5, 10-13 so I just give them John 5:1-2
    // 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
@@ -83,31 +231,154 @@
 
    switch ($translation) {
         case 'ESV':
-        // note: the ESV could actually support a mouseover reference
-        // we could pull it directly from their site and include it in the $title text
-        // http://www.gnpcb.org/esv/share/services/api/ for more info
-             $link = 'http://www.gnpcb.org/esv/search/?go=Go&q=';
-             $title = 'English Standard Version Bible';
-             $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
-             break;
+        	//The ESV API allows us to do much more with this translation.  Options for the ESV are set on the settings page of the plugin
+			If(variable_get("scripturefilter_default_displaystyle", 'tooltip')=='tooltip'){
+			$link = esv_tooltip($passage, $Verse);
+			}
+			elseif(variable_get("scripturefilter_default_displaystyle", 'tooltip')=='inline'){
+			$link = esv_inline($passage,$Verse);
+			}
+			break;
         case 'NET':
-             $link = 'http://net.bible.org/passage.php?passage=';
-             $title = 'New English Translation';
-             $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
+            $link = 'http://net.bible.org/passage.php?passage=';
+            $title = 'New English Translation';
+            $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
              break;
 	case 'TNIV':
-             $link = 'http://www.tniv.info/bible/passagesearch.php?passage_request=';
-             $title = 'Today\'s New International Version';
-             $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
-	     break;
+            $link = 'http://www.tniv.info/bible/passagesearch.php?passage_request=';
+            $title = 'Today\'s New International Version';
+            $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
+			break;
         default:
-             $link = "http://biblegateway.com/cgi-bin/bible?language=english&version=$translation&passage=";
-             $title = 'Bible Gateway';
-             $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
-             break;
+		//The & symbol must be replaced with &amp; throughout, including and links to be XHTML Compliant.
+            $link = "http://biblegateway.com/cgi-bin/bible?language=english&amp;version=$translation&amp;passage=";
+            $title = 'Bible Gateway';
+            $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
+            break;
     }
 
     return $link;
 }
 
+function esv_getverse($passage){
+//Set options for ESV text
+		$options =  "&include-footnotes=".variable_get("scripturefilter_esv_include-footnotes",TRUE);
+		$options .= "&include-audio-link=".variable_get("scripturefilter_esv_audio",TRUE);
+		$options .= "&audio-format=".variable_get('scripturefilter_esv_audio-format', 'flash');
+		$options .= "&audio-version=".variable_get('scripturefilter_esv_audio-version', 'mm');
+		$options .= "&include-headings=".variable_get("scripturefilter_esv_include-headings",TRUE);
+		$options .= "&include-subheadings=".variable_get("scripturefilter_esv_include-subheadings",TRUE);
+		$options .= "&include-verse-numbers=".variable_get("scripturefilter_esv_include-verse-numbers",TRUE);
+
+
+             $url = "http://www.gnpcb.org/esv/share/get/?key=" . variable_get("scripturefilter_esv_$API_key",IP). "&passage=" . $passage ."&action=doPassageQuery".$options;
+             
+			 //Pulls text from the ESV website via curl or fopen
+				if (function_exists("curl_init")) {
+					$ch = curl_init($url);
+					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+					$VerseText = curl_exec($ch);
+					curl_close($ch);
+				} else if (ini_get('allow_url_fopen') == true) {
+					if ($rvs = fopen($url, 'r')) {
+						$VerseText = "";
+
+						while (!feof($rvs)) {
+							$VerseText .= fgets($rvs);
+						}
+
+						fclose($rvs);
+					}
+				} else {
+					$readerr = 1;
+					$VerseText = "Error retrieving passage text - curl and remote fopen both seem to be disabled on your host.";
+				}
+
+				if ($readerr == 0)
+				{
+					if (strpos($VerseText, "You have exceeded your quota of 500 requests per day.") === false) {
+					} else {
+						$VerseText = "Error retrieving Bible passage. Please check again tomorrow.";
+					}
+				}
+				   				
+	Return $VerseText;
+}
+
+function esv_getcache($passage,$reset = FALSE) {
+    //This function will check if the passage requested is currently in cache, if it is it will use the cached text, if not it will request the text and add it to the cache for 24hours
+	
+	if (!$reset && ($cache = cache_get('scripture'.$passage)) && !empty($cache->data)) {
+      $VerseText = unserialize($cache->data);
+    }
+    else {
+      // Do your expensive calculations here, and populate $my_data
+      // with the correct stuff..
+	  $VerseText = esv_getverse($passage);
+	  //Cache Bible Verse for 24hours - 60*60*24 = 86400
+      cache_set('scripture'.$passage, 'cache', serialize($VerseText), time() + 86400);
+    }
+  return $VerseText;
+}
+
+function esv_inline($passage, $Verse){
+		//This function generates the link to pass back for the collapsed inline block
+
+				$VerseText = esv_getcache($passage);
+				//clean up text
+   				$VerseText = str_replace("\n", "", $VerseText);
+				$VerseText = str_replace("\r", "", $VerseText);
+				$VerseText = str_replace("'", "&#8217;", $VerseText);
+				$VerseText = str_replace("<h2", "<span style='font-size:".variable_get("scripturefilter_esv_inline-heading-fontsize",'20')."px;' class='passageheading'", $VerseText);
+				$VerseText = str_replace("</h2>", "</span>", $VerseText);
+				$VerseText = str_replace("<h3", "<span style='font-size:". variable_get("scripturefilter_esv_inline-subheading-fontsize",'16') ."px;' class='passagesubheading'", $VerseText);
+				$VerseText = str_replace("</h3>", "</span>", $VerseText);
+				$VerseText = str_replace("<p class=", "<span style='display:block;' class='passagetext'", $VerseText);
+				$VerseText = str_replace("<p>", "<span style='display:block;' class='passagetext'>", $VerseText);
+				$VerseText = str_replace("</p>", "</span>", $VerseText);
+				$VerseText = strip_tags($VerseText, "<br><span><object><param><a>");
+				
+
+				//Style the collasible block
+				$esv_div_style ="white-space: normal;";
+				$esv_div_style ="background-color: ".variable_get("scripturefilter_esv_inline-background-colour",'white').";";
+				$esv_div_style.="display: none;"; 
+				$esv_div_style.="padding: 10px;";
+				$esv_div_style.="border: ". variable_get('scripturefilter_esv_inline-border-style', 'dotted').' '.variable_get("scripturefilter_esv_inline-border-colour",'blue').' '.variable_get("scripturefilter_esv_inline-border-width",'1')."px;";
+				$esv_div_style.="border-left: solid ".variable_get("scripturefilter_esv_inline-border-colour",'blue')." ".variable_get("scripturefilter_esv_inline-left-border",'5')."px;";
+				$esv_div_style.="color: ".variable_get("scripturefilter_esv_inline-text-colour",'black').";";
+	
+		$esvSpanId = 'scripturefilter' .mt_rand(); //prefix the rand number with "id" to pass XHTML validation
+    $output_dynamic = " <a href=\"javascript://\" onclick=\"jQuery('span#".$esvSpanId . "').toggle('slow');\">".$Verse." [+/-]</a><span id=\"" . $esvSpanId . "\" style=\"" . $esv_div_style. "\">" .$VerseText . "</span>";
+
+
+	Return $output_dynamic;
+}
+
+function esv_tooltip($passage, $Verse){
+		//This function generates the link to pass back for the hover tooltip
+				$VerseText = esv_getcache($passage);
+
+				//Clean up the Text
+   				$VerseText = str_replace("\n", "", $VerseText);
+				$VerseText = str_replace("\r", "", $VerseText);
+				$VerseText = strip_tags($VerseText, "<div><br><span><p>");
+				$VerseText = str_replace("(Listen)", "", $VerseText);
+				$VerseText = str_replace("'", "&#8217;", $VerseText);
+
+				
+				preg_match('/<div class="esv">(.*?)<div class="esv-text">/i', $VerseText, $matches);
+				$VerseRef = $matches[0];
+				$VerseRef = strip_tags($VerseRef, "");
+				$VerseText = preg_replace('/<div class="esv">(.*?)<div class="esv-text">/i', '', $VerseText);
+				
+				IF (variable_get("scripturefilter_esv_show-header",TRUE) ==  TRUE){
+				$tooltipheader = trim($Verse);
+				}
+				
+				$ReturnText = '<a href="http://www.gnpcb.org/esv/search/?q='. $passage .'" onmouseover="toolText(\''. $tooltipheader .'\', \''. htmlentities($VerseText) .'\');" onmouseout="clearTip()">'. trim($Verse) .'</a>';
+
+						return $ReturnText;
+}
+
 ?>
Index: scripturefilter.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/scripturefilter/scripturefilter.module,v
retrieving revision 1.9
diff -u -r1.9 scripturefilter.module
--- scripturefilter.module	25 Feb 2007 00:13:22 -0000	1.9
+++ scripturefilter.module	17 Jun 2007 21:45:03 -0000
@@ -1,5 +1,5 @@
 <?php
-/* $Id: scripturefilter.module,v 1.9 2007/02/25 00:13:22 smsimms Exp $ */
+/* $Id: scripturefilter.module,v 1.8.4.1 2007/05/21 16:45:34 smsimms Exp $ */
 
 function scripturefilter_help($section) {
   switch ($section) {
@@ -24,45 +24,365 @@
     case 'process':
       return scripturize($text, variable_get("scripturefilter_default_translation_$format", DEFAULT_BIBLE_TRANSLATION));
      
-    case 'settings':
-      $form['filter_scripturefilter'] = array(
-        '#type' => 'fieldset',
-        '#title' => 'Scripture filter',
-        '#collapsible' => TRUE,
-        '#description' => t('This filter enables content that has a reference to Scripture to be linked to one of several online Bibles, such as BibleGateway, the ESV online Bible and the NET Bible.')
-      );
-
-      $form['filter_scripturefilter']["scripturefilter_default_translation_$format"] = array(
-        '#type' => 'select',
-        '#title' => t('Default Bible translation'),
-        '#default_value' => variable_get("scripturefilter_default_translation_$format", DEFAULT_BIBLE_TRANSLATION),
-        '#options' => array(
-          "KJ21" => t("21st Century King James Version"),
-          "ASV" => t("American Standard Version"),
-          "AMP" => t("Amplified Bible"),
-          "CEV" => t("Contemporary English Version"),
-          "DARBY" => t("Darby Translation"),
-          "ESV" => t("English Standard Version"),
-          "KJV" => t("King James Version"),
-          "MSG" => t("The Message"),
-          "NASB" => t("New American Standard Bible"),
-          "NET" => t("New English Translation"),
-          "NIRV" => t("New International Reader's Version"),
-          "NIV" => t("New International Version"),
-          "NIV-UK" => t("New International Version - UK"),
-          "NKJV" => t("New King James Version"),
-          "NLT" => t("New Living Translation"),
-          "TNIV" => t("Today's New International Version"),
-          "WE" => t("Worldwide English New Testament"),
-          "WYC" => t("Wycliffe New Testament"),
-          "YLT" => t("Young's Literal Translation"),
-        ),
-      );
-      return $form;
+//removed Code from case 'settings' down to return $form
 
     default:
       return $text;
   }
 }
 
+//Added Code Below...
+
+function scripturefilter_menu($may_cache) {
+  //This function creates the menu link for the settings page
+  global $user;
+  $items = array();
+
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/settings/scripturefilter', 
+      'title' => t('Scripture Filter'),
+      'description' => t('Configure the settings for Scripture Filter'),
+      'access' => user_access('administer scripture filter'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('scripturefilter_settings'),
+    );
+  }
+  return $items;
+} // endfunction scripturefilter_menu
+
+function scripturefilter_perm() {
+  return array('administer scripture filter');
+}
+
+function scripturefilter_footer($main = 0) {
+//Add Javascript and CSS and settings for Tooltip to page
+If(variable_get("scripturefilter_default_translation_format", DEFAULT_BIBLE_TRANSLATION)=="ESV"){
+    //If translation is ESV then add the appropirate CSS File
+	$scripture_dir = drupal_get_path('module', 'scripturefilter');
+	drupal_add_css($scripture_dir . '/esv.css');
+
+If(variable_get("scripturefilter_default_displaystyle", 'tooltip')=="tooltip"){
+	//If display style is tooltip then add js and options
+	
+	drupal_add_js($scripture_dir . '/esv_tooltip.js');
+
+	$ttoptions = array(
+		'scripture' => array(
+	'tipWidth' => variable_get("scripturefilter_esv_tooltip_width",600).'px',
+	'tipBorderSize' => variable_get("scripturefilter_esv_border-width",'1') . 'px',
+	'tipWidthHeaderSub' => (variable_get("scripturefilter_esv_tooltip_width",600)-10).'px',
+	'tipWidthBodySub' => (variable_get("scripturefilter_esv_tooltip_width",600)-4).'px',
+	'tipBorderColor' => variable_get("scripturefilter_esv_border-colour",'black'),
+	'tipHeaderOpacity' => "93",
+	'tipBodyOpacity' => "97",
+	'tipHeaderBgColor' => variable_get("scripturefilter_esv_heading-colour",'#444'),
+	'tipHeaderFontFamily' => "",
+	'tipHeaderFontSize' => variable_get("scripturefilter_esv_heading-font",16) . 'px',
+	'tipHeaderFontColor' => variable_get("scripturefilter_esv_heading-font-colour",'white'),
+	'tipHeaderAlign' => "left",
+	'tipHeaderPadding' => "5px",
+	'tipBodyBgColor' => variable_get("scripturefilter_esv_body-colour",'#E8E8FF') ,
+	'tipBodyFontFamily' => "",
+	'tipBodyFontSize' => variable_get("scripturefilter_esv_body-font",13) . 'px',
+	'tipBodyFontColor' => variable_get("scripturefilter_esv_body-font-colour",'black'),
+	'tipBodyAlign' => "left",
+	'tipBodyPadding' => "2px",
+	));
+drupal_add_js($ttoptions, 'setting');
+	}
+elseif(variable_get("scripturefilter_default_displaystyle", 'tooltip')=="inline"){
+	}
+
+	}
+}
+
+function scripturefilter_settings() {
+//This array creates the Settings Menu
+      $form['filter_scripturefilter'] = array('#type' => 'fieldset',
+					      '#title' => 'Scripture filter',
+					      '#collapsible' => TRUE,
+					      '#description' => t('This filter enables content that has a reference to Scripture to be linked to one of several online Bibles, such as BibleGateway, the ESV online Bible and the NET Bible.'));
+
+      $form['filter_scripturefilter']["scripturefilter_default_translation_format"] =
+	array('#type' => 'select',
+	      '#title' => t('Default Bible translation'),
+	      '#default_value' => variable_get("scripturefilter_default_translation_format", DEFAULT_BIBLE_TRANSLATION),
+	      '#options' => array("KJ21" => t("21st Century King James Version"),
+				  "ASV" => t("American Standard Version"),
+				  "AMP" => t("Amplified Bible"),
+				  "CEV" => t("Contemporary English Version"),
+				  "DARBY" => t("Darby Translation"),
+				  "ESV" => t("English Standard Version"),
+				  "KJV" => t("King James Version"),
+				  "MSG" => t("The Message"),
+				  "NASB" => t("New American Standard Bible"),
+				  "NET" => t("New English Translation"),
+				  "NIRV" => t("New International Reader's Version"),
+				  "NIV" => t("New International Version"),
+				  "NIV-UK" => t("New International Version - UK"),
+				  "NKJV" => t("New King James Version"),
+				  "NLT" => t("New Living Translation"),
+				  "TNIV" => t("Today's New International Version"),
+				  "WE" => t("Worldwide English New Testament"),
+				  "WYC" => t("Wycliffe New Testament"),
+				  "YLT" => t("Young's Literal Translation"),
+				  ),
+	      );
+
+		$form['filter_scripturefilter_esv'] = array('#type' => 'fieldset',
+					      '#title' => 'ESV settings',
+					      '#collapsible' => TRUE,
+						  '#collapsed' => TRUE,
+					      '#description' => t('These are the settings for the ESV bible.'));
+
+	$form['filter_scripturefilter_esv']["scripturefilter_esv_API_key"] =
+	array('#type' => 'textfield',
+	      '#title' => t('ESV API Key'),
+	      '#default_value' => variable_get("scripturefilter_esv_API_key",IP),
+		  '#description' => t("The default value for this is 'IP'.  Read more about this <a href='http://www.gnpcb.org/esv/share/services/'>here</a>"),
+	      '#size' => '30',
+				  );
+
+
+	$form['filter_scripturefilter_esv']["scripturefilter_default_displaystyle"] =
+	array('#type' => 'select',
+	      '#title' => t('Default Bible translation'),
+	      '#default_value' => variable_get("scripturefilter_default_displaystyle", 'tooltip'),
+	      '#options' => array(
+				  "tooltip" => t("Display Verse as a Tooltip   "),
+				  "inline" => t("Display Verse in collapsed Block  "),
+				  ),
+	      );		  
+
+	$form['filter_scripturefilter_esv']["scripturefilter_esv_show-header"] =
+	array('#type' => 'checkbox',
+	      '#title' => t('Display Header'),
+	      '#default_value' => variable_get("scripturefilter_esv_show-header",TRUE),
+		  	  );
+			  
+	$form['filter_scripturefilter_esv']["scripturefilter_esv_audio"] =
+	array('#type' => 'checkbox',
+	      '#title' => t('Display Audio Link'),
+	      '#default_value' => variable_get("scripturefilter_esv_audio",TRUE),
+		  '#description' => t("Audio is only available if you chose to display the text in the collapsible block"),
+		  	  );				  
+		  
+	  	$form['filter_scripturefilter_esv']["scripturefilter_esv_include-footnotes"] =
+	array('#type' => 'checkbox',
+	      '#title' => t('Include Footnotes'),
+	      '#default_value' => variable_get("scripturefilter_esv_include-footnotes",TRUE),
+	      	  );
+
+	$form['filter_scripturefilter_esv']["scripturefilter_esv_include-verse-numbers"] =
+	array('#type' => 'checkbox',
+	      '#title' => t('Include Verse Numbers'),
+	      '#default_value' => variable_get("scripturefilter_esv_include-verse-numbers",TRUE),
+	      	  );				  
+	$form['filter_scripturefilter_esv']["scripturefilter_esv_include-headings"] =
+	array('#type' => 'checkbox',
+	      '#title' => t('Include Section Headings'),
+	      '#default_value' => variable_get("scripturefilter_esv_include-headings",TRUE),
+	      	  );				  
+	
+	$form['filter_scripturefilter_esv']["scripturefilter_esv_include-subheadings"] =
+	array('#type' => 'checkbox',
+	      '#title' => t('Include Subheadings'),
+	      '#default_value' => variable_get("scripturefilter_esv_include-subheadings",TRUE),
+	      	  );
+
+		$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip'] = array('#type' => 'fieldset',
+					      '#title' => 'ESV Tooltip settings',
+					      '#collapsible' => TRUE,
+						  '#collapsed' => TRUE,
+					      '#description' => t('These are the settings for the ESV bible when displayed in Tooltip form.'));
+			  
+    $form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_tooltip_width"] =
+	array('#type' => 'textfield',
+	      '#title' => t('ESV Tooltip Width'),
+		  '#field_suffix' => t('px'),
+	      '#default_value' => variable_get("scripturefilter_esv_tooltip_width",'600'),
+	      '#size' => '6',
+				  );
+				  			  
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_border-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Border Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_border-colour",'black'),
+	      	  );
+
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_border-width"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Border Width'),
+		  '#size' => '3',
+		  '#field_suffix' => t('px'),
+	      '#default_value' => variable_get("scripturefilter_esv_border-width",'1'),
+	      	  );
+
+			  
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_heading-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Heading Background Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_heading-colour",'#444'),
+	      	  );
+
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_heading-font"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Heading Font Size'),
+		  '#size' => '3',
+		  '#field_suffix' => t('pt'),
+	      '#default_value' => variable_get("scripturefilter_esv_heading-font",'16'),
+	      	  );
+			  
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_heading-font-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Heading Font Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_heading-font-colour",'white'),
+	      	  );
+
+			  
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_body-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Body Background Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_body-colour",'#E8E8FF'),
+	      	  );
+			  
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_body-font"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Body Font Size'),
+		  '#size' => '3',
+  		  '#field_suffix' => t('pt'),
+	      '#default_value' => variable_get("scripturefilter_esv_body-font",'13'),
+	      	  );
+
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_tooltip']["scripturefilter_esv_body-font-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Body Font Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_body-font-colour",'black'),
+	      	  );
+
+	  		$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline'] = array('#type' => 'fieldset',
+			      '#title' => 'ESV settings for Collasible Block Display',
+			      '#collapsible' => TRUE,
+				  '#collapsed' => TRUE,
+			      '#description' => t('These are the settings for the ESV bible when displayed in collapsible block form.'));
+
+	$audioformat = array(
+				'flash' => t('Flash Player'),
+				'mp3' => t('MP3'),
+				'real' => t('Real Audio'),
+				'wma' => t('Windows Media Audio'),
+					);
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_audio-format"] = array(
+		  '#type' => 'select',
+		  '#title' => t('Audio Format'),
+		  '#default_value' =>  variable_get('scripturefilter_esv_audio-format', 'flash'),
+		  '#options' => $audioformat,
+		  '#description' => t('RealAudio and WMA, only have New Testament recordings'),
+		     );			  
+
+	$audiospeaker = array(
+				'mm' => t('Max McLean, complete Bible'),
+				'ml' => t('Marquis Laughlin, New Testament only'),
+				'ml-mm' => t('Max McLean for Old Testament, Marquis Laughlin for New Testament'),
+					);
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_audio-version"] = array(
+		  '#type' => 'select',
+		  '#title' => t('Audio Speaker'),
+		  '#default_value' =>  variable_get('scripturefilter_esv_audio-version', 'mm'),
+		  '#options' => $audiospeaker,
+		  '#description' => t('Only affects the output if the audio format is flash or mp3'),
+		     );			  
+
+
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-border-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Border Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_inline-border-colour",'blue'),
+		  '#description' => t("This sets the colour of the border to the collasible block and left margin"),
+	      	  );
+			  
+	$borderstyles = array(
+				'none' => t('No Border'),
+				'dotted' => t('Dotted Border'),
+				'dashed' => t('Dashed Border'),
+				'solid' => t('Solid Border'),
+				'double' => t('Dotted Border'),
+				'groove' => t('3D Groove Border'),
+					);
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-border-style"] = array(
+		  '#type' => 'select',
+		  '#title' => t('Border Style'),
+		  '#default_value' =>  variable_get('scripturefilter_esv_inline-border-style', 'dotted'),
+		  '#options' => $borderstyles,
+		     );			  
+			  
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-border-width"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Border Width'),
+		  '#size' => '3',
+		  '#field_suffix' => t('px'),
+	      '#default_value' => variable_get("scripturefilter_esv_inline-border-width",'1'),
+	      	  );
+
+
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-left-border"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Left Margin Size'),
+		  '#size' => '3',
+		  '#field_suffix' => t('px'),
+	      '#default_value' => variable_get("scripturefilter_esv_inline-left-border",'5'),
+	      	  );
+
+  	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-heading-fontsize"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Heading Fontsize'),
+		  '#size' => '3',
+		  '#field_suffix' => t('pt'),
+	      '#default_value' => variable_get("scripturefilter_esv_inline-heading-fontsize",'18'),
+		  '#description' => t("This sets the fontsize of the Headings in the passage"),
+	      	  );
+
+   	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-subheading-fontsize"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Subheading Fontsize'),
+		  '#size' => '3',
+		  '#field_suffix' => t('pt'),
+	      '#default_value' => variable_get("scripturefilter_esv_inline-subheading-fontsize",'14'),
+		  '#description' => t("This sets the fontsize of the Subheadings in the passage"),
+	      	  );
+
+	$form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-text-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Text Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_inline-text-colour",'black'),
+		  '#description' => t("This sets the colour of the text"),
+	      	  );
+
+  $form['filter_scripturefilter_esv']['filter_scripturefilter_esv_inline']["scripturefilter_esv_inline-background-colour"] =
+	array('#type' => 'textfield',
+	      '#title' => t('Background Colour'),
+		  '#size' => '8',
+	      '#default_value' => variable_get("scripturefilter_esv_inline-background-colour",'white'),
+		  '#description' => t("This sets the colour of the background to the collapsable block"),
+	      	  );
+
+	return system_settings_form($form);
+		  
+}
+
+function scripturefilter_settings_validate($form_id, $form_values) {
+ //Clears out cached verses when settings are changed
+ cache_clear_all('scripture', 'cache', TRUE); 
+ //Clears out the Input Filter Cache
+ db_query("DELETE FROM cache_filter");
+}
+
 ?>
