--- scripturefilter.inc.orig	2008-08-13 20:33:18.000000000 +0100
+++ scripturefilter.inc	2008-08-13 21:14:39.000000000 +0100
@@ -23,6 +23,24 @@ function scripturize ($text = '',$bible 
 	}
     }
     
+	//repeat, this time to get the partial references
+	$split_regex = "/\<\!-- SCRIPTUREFILTERCONTEXT --\>/U";
+
+    $parsed_text = preg_split($split_regex,$linked_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 matches the comment, remove it!
+	} else {
+		if (substr($value, 0, 28)=="<!-- SCRIPTUREFILTERCHAPTER ") {
+			$linked_text .= scripturizeAddPartialLinks($value); // if it's text, parse it for partial Bible references
+		} else {
+			$linked_text .= $value; // othewise it's already a link, so add it
+		}
+	}
+    }
+	
     return $linked_text;
 }
 
@@ -41,10 +59,9 @@ function scripturizeAddLinks($text = '',
 
     $book_regex='(?:'.$book_regex.')|(?:'.$abbrev_regex.')\.?';
 
-    $verse_regex="\d{1,3}(?::\d{1,3})?(?:\s?(?:[-&,]\s?\d+))*";
-
-    $translation_regex = 'NIV|NASB|AMP|NLT|KJV|ESV|CEV|NET|NKJV|KJ21|ASV|WE|YLT|DARBY|WYC|NIV-UK|TNIV|MSG|NIRV';
+    $verse_regex="(?:c(?:h(?:ap(?:ter)?)?)?s?\.?\s?)?\d{1,3}(?:\s?(?::|verse|vv?)s?\.?\s?\d{1,3})?(?:\s?(?:(?:-|&amp;|and|—|–|,)\s?\d+))*";
 
+    $translation_regex='NIV|NASB|AMP|NLT|KJV|ESV|CEV|NET|NKJV|KJ21|ASV|WE|YLT|DARBY|WYC|NIV-UK|TNIV|NIRV|AKJV|ACV|BBE|WEB|Webster|Weymouth';
     // 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';
@@ -56,8 +73,29 @@ function scripturizeAddLinks($text = '',
     return $text;
 }
 
-function scripturizeLinkReference($reference='',$volume='',$book='',$verse='',$translation='',$user_translation='') {
-    if ($volume) {
+function scripturizeAddPartialLinks($text = '') {
+    $verse_regex="(?:verse|vv?)s?\.?\s?\d{1,3}(?:\s?(?:(?:-|&amp;|and|—|–|,)\s?\d+))*";
+	
+    $translation_regex='NIV|NASB|AMP|NLT|KJV|ESV|CEV|NET|NKJV|KJ21|ASV|WE|YLT|DARBY|WYC|NIV-UK|TNIV|NIRV|AKJV|ACV|BBE|WEB|Webster|Weymouth';
+    // note that this will be executed as PHP code after substitution thanks to the /e at the end!
+
+    $passage_regex = '/('.$verse_regex.')(?:\s?[,-]?\s?((?:'.$translation_regex.')|\s?\((?:'.$translation_regex.')\)))?/e';
+
+	//get context
+	$context=substr($text, 28, strpos($text, " -->",28)-28);
+	list($volume,$book,$chap,$translation) = explode("|",$context);
+	
+	//remove context comment
+	$text=substr($text, strpos($text, "-->",29)+3);
+
+    $replacement_regex = "scripturizeLinkReference('\\0','$volume','$book','$chap\\1','\\2','$translation',TRUE)";	
+    $text=preg_replace($passage_regex,$replacement_regex,$text);
+
+    return $text;
+}
+
+function scripturizeLinkReference($reference='',$volume='',$book='',$verse='',$translation='',$user_translation='',$second_pass=FALSE) {
+	if ($volume) {
        $volume = str_replace('III','3',$volume);
        $volume = str_replace('II','2',$volume);
        $volume = str_replace('I','1',$volume);
@@ -74,12 +112,14 @@ function scripturizeLinkReference($refer
        $translation = trim($translation,' ()'); // strip out any parentheses that might have made it this far
    }
 
-   // 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
-   if ($verse) {
-       $verse = strtok($verse,',& ');
-   }
+	//switch ' and ', '&' and ';' for  ',' in link  (assumes & is html encoded)
+	$verse=preg_replace("/\s?(?:and|\&amp\;|,)\s?/i",",",$verse);	
+	//switch '—' or '–' for  '-' in link
+	$verse=preg_replace("/\s?(?:—|–|-)\s?/i","-",$verse);	
+	//switch v,vv,verse,verses,vs for  ':' in link
+	$verse=preg_replace("/\s?(?::|verse|vv?)s?\.?\s?/i",":",$verse);
+	//remove 'chapter' from the link
+	$verse=preg_replace("/c(?:h(?:ap(?:ter)?)?)?s?\.?\s?/i","",$verse);
 
    switch ($translation) {
         case 'ESV':
@@ -107,6 +147,13 @@ function scripturizeLinkReference($refer
              break;
     }
 
+	if(!$second_pass) {
+	   $colonpos=strpos($verse,":");   
+	   if($colonpos) $chap= substr($verse, 0, $colonpos);
+	   else $chap= $verse;   
+	   $link="<!-- SCRIPTUREFILTERCONTEXT -->$link<!-- SCRIPTUREFILTERCONTEXT --><!-- SCRIPTUREFILTERCHAPTER $volume|$book|$chap|$translation -->";
+	}  
+
     return $link;
 }
 
