/[drupal]/contributions/modules/scripturefilter/scripturefilter.inc
ViewVC logotype

Diff of /contributions/modules/scripturefilter/scripturefilter.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3, Tue Aug 1 20:54:56 2006 UTC revision 1.3.4.1, Mon May 21 16:45:34 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /*  /* $Id: scripturefilter.inc,v 1.6 2007/05/21 16:40:51 smsimms Exp $ */
 Modified for use in Drupal by David Blewett, August 2004  
 Contact: david@dawninglight.net  
 Site: www.dawninglight.net  
   
 Removed Wordpress-specific function calls  
 */  
   
 /*  
 Plugin Name: Scripturizer  
 Version: 1.4 fork  
 Plugin URI: http://xastanford.org/archives/scripturizer-in-php/  
 Description: Changes Bible references to hyperlinks  
 Author: Dean Peters, ported by Glen Davis  
 Author URI: http://www.healyourchurchwebsite.com/  
 */  
   
 /*  
 Copyright (c) 2002-2004  
   Dean Peters   <http://www.HealYourChurchWebSite.com>  
   
 Additional Credits:  
   Jonathan Fox  <http://vulpecula.us/~jon/>  
   Jason Rust <http://rustyparts.com/blip/>  
   Joseph Markey <http://thegreatlands.com/archives/000032.html>  
   
 MovableType Scripturizer Plug-In Tutorial  
   Rob Hulson    <http://www.robhulson.com/archives/000073.html>  
   
 Translation to PHP for Wordpress 5/28/2004  
   Glen Davis <http://www.xastanford.org/>  
   *added NET Bible, Message, NIRV  
   *now able to specify translation on fly as in Gen 1:1, CEV  
   *altered the book regex to suit my tastes (period is optional on abbrev, for example)  
   
 Permission is hereby granted, free of charge, to any person obtaining a  
 copy of this software and associated documentation files (the "Software"),  
 to deal in the Software without restriction, including without limitation  
 the rights to use, copy, modify, merge, publish, distribute, sublicense,  
 and/or sell copies of the Software, and to permit persons to whom the  
 Software is furnished to do so, subject to the following conditions:  
   
 The above copyright notice and this permission notice shall be included in  
 all copies or substantial portions of the Software.  
   
 The Software is provided "as is", without warranty of any kind, express or  
 implied, including but not limited to the warranties of merchantability,  
 fitness for a particular purpose and noninfringement. In no event shall  
 the authors or copyright holders be liable for any claim, damages or other  
 liability, whether in an action of contract, tort or otherwise, arising  
 from, out of or in connection with the Software or the use or other  
 dealings in the Software.  
 */  
3    
4  define('DEFAULT_BIBLE_TRANSLATION','NIV');  define('DEFAULT_BIBLE_TRANSLATION','NIV');
5    
# Line 64  function scripturize ($text = '',$bible Line 12  function scripturize ($text = '',$bible
12      $tag_regex = '<(?:[^<>\s]*)(?:\s[^<>]*){0,1}>'; // $tag_regex='<[^>]+>';      $tag_regex = '<(?:[^<>\s]*)(?:\s[^<>]*){0,1}>'; // $tag_regex='<[^>]+>';
13      $split_regex = "/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$tag_regex))/i";      $split_regex = "/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$tag_regex))/i";
14    
15    $parsed_text = preg_split($split_regex,$text,-1,PREG_SPLIT_DELIM_CAPTURE);      $parsed_text = preg_split($split_regex,$text,-1,PREG_SPLIT_DELIM_CAPTURE);
16    $linked_text = '';      $linked_text = '';
17    
18    while (list($key,$value) = each($parsed_text)) {      while (list($key,$value) = each($parsed_text)) {
19        if (preg_match($split_regex,$value)) {          if (preg_match($split_regex,$value)) {
20           $linked_text .= $value; // if it is an HTML element or within a link, just leave it as is              $linked_text .= $value; // if it is an HTML element or within a link, just leave it as is
21        } else {          } else {
22          $linked_text .= scripturizeAddLinks($value,$bible); // if it's text, parse it for Bible references              $linked_text .= scripturizeAddLinks($value,$bible); // if it's text, parse it for Bible references
23        }          }
24    }      }
25    
26    return $linked_text;      return $linked_text;
27  }  }
28    
29  function scripturizeAddLinks($text = '',$bible = DEFAULT_BIBLE_TRANSLATION) {  function scripturizeAddLinks($text = '',$bible = DEFAULT_BIBLE_TRANSLATION) {
# Line 85  function scripturizeAddLinks($text = '', Line 33  function scripturizeAddLinks($text = '',
33      $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 .= '|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';
34      $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 .= '|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?';
35    
36  //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      // 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
37    
38      $abbrev_regex  = 'Gen|Ex|Exo|Lev|Num|Nmb|Deut?|Josh?|Judg?|Jdg|Rut|Sam|Ki?n|Chr(?:on?)?|Ezr|Neh|Est';      $abbrev_regex  = 'Gen|Ex|Exo|Lev|Num|Nmb|Deut?|Josh?|Judg?|Jdg|Rut|Sam|Ki?n|Chr(?:on?)?|Ezr|Neh|Est';
39      $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 .= '|Jb|Psa?|Pr(?:ov?)?|Eccl?|Song?|Isa|Jer|Lam|Eze|Dan|Hos|Joe|Amo|Oba|Jon|Mic|Nah|Hab|Zeph?|Hag|Zech?|Mal';
# Line 97  function scripturizeAddLinks($text = '', Line 45  function scripturizeAddLinks($text = '',
45    
46      $translation_regex = 'NIV|NASB|AMP|NLT|KJV|ESV|CEV|NET|NKJV|KJ21|ASV|WE|YLT|DARBY|WYC|NIV-UK|TNIV|MSG|NIRV';      $translation_regex = 'NIV|NASB|AMP|NLT|KJV|ESV|CEV|NET|NKJV|KJ21|ASV|WE|YLT|DARBY|WYC|NIV-UK|TNIV|MSG|NIRV';
47    
48  // note that this will be executed as PHP code after substitution thanks to the /e at the end!      // note that this will be executed as PHP code after substitution thanks to the /e at the end!
49    
50      $passage_regex = '/(?:('.$volume_regex.')\s)?('.$book_regex.')\s('.$verse_regex.')(?:\s?[,-]?\s?((?:'.$translation_regex.')|\s?\((?:'.$translation_regex.')\)))?/e';      $passage_regex = '/(?:('.$volume_regex.')\s)?('.$book_regex.')\s('.$verse_regex.')(?:\s?[,-]?\s?((?:'.$translation_regex.')|\s?\((?:'.$translation_regex.')\)))?/e';
51    
# Line 126  function scripturizeLinkReference($refer Line 74  function scripturizeLinkReference($refer
74         $translation = trim($translation,' ()'); // strip out any parentheses that might have made it this far         $translation = trim($translation,' ()'); // strip out any parentheses that might have made it this far
75     }     }
76    
77     //if necessary, just choose part of the verse reference to pass to the web interfaces     // if necessary, just choose part of the verse reference to pass to the web interfaces
78     //they wouldn't know what to do with John 5:1-2, 5, 10-13 so I just give them John 5:1-2     // they wouldn't know what to do with John 5:1-2, 5, 10-13 so I just give them John 5:1-2
79     //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     // 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
80     if ($verse) {     if ($verse) {
81         $verse = strtok($verse,',& ');         $verse = strtok($verse,',& ');
82     }     }
# Line 143  function scripturizeLinkReference($refer Line 91  function scripturizeLinkReference($refer
91               $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));               $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
92               break;               break;
93          case 'NET':          case 'NET':
94               $link = 'http://www.bible.org/cgi-bin/netbible.pl?header=on';               $link = 'http://net.bible.org/passage.php?passage=';
95               $title = 'New English Translation';               $title = 'New English Translation';
96               $chapter = trim(strtok($verse,':'));               $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
              $verses = trim(strtok('-,'));  
              $book = scripturizeNETBook($volume.' '.$book);  
              $link = sprintf('<a href="%s&book=%s&chapter=%s&verse=%s" title="%s">%s</a>',$link,htmlentities(urlencode($book)),$chapter,$verses,$title,trim($reference));  
97               break;               break;
98     case 'TNIV':          case 'TNIV':
99               $link = 'http://www.tniv.info/bible/passagesearch.php?passage_request=';               $link = 'http://www.tniv.info/bible/passagesearch.php?passage_request=';
100               $title = 'Today\'s New International Version';               $title = 'Today\'s New International Version';
101               $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));               $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
# Line 160  function scripturizeLinkReference($refer Line 105  function scripturizeLinkReference($refer
105               $title = 'Bible Gateway';               $title = 'Bible Gateway';
106               $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));               $link = sprintf('<a href="%s%s" title="%s">%s</a>',$link,htmlentities(urlencode(trim("$volume $book $verse"))),$title,trim($reference));
107               break;               break;
         // should I add Libronix links? perhaps with define constant to enable/disable...  
         // see http://www.logos.com/support/lbs/weblinking  
         // libronixdls:keylink|ref=[en]bible:Gen%201:1|res=LLS:ESV  
108      }      }
109    
110      return $link;      return $link;
111  }  }
112    
 function scripturizeNETBook($book='') {  
 //need this function because NET Bible needs rigid input  
 //it's not perfect, so someone who intends to link to the NET Bible must be cautious with their syntax  
 //Jn 5:1 won't work, for example (must be 'joh' or 'john').  
     $book = strtolower(trim($book));  
     if (!$book) return '';  
   
     $book = preg_replace('/\s+/', '', $book); //strip whitespace  
   
     switch ($book) {  
            case 'judges':  
                 $book = 'jdg';  
                 break;  
            case 'song of songs':  
            case 'song of solomon':  
            case 'song':  
                 $book = 'sos';  
                 break;  
            case 'philemon':  
                  $book = 'phm';  
                  break;  
            default:  
                    $book = substr($book,0,3);  
     }  
     return $book;  
 }  
   
   
113  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.3.4.1

  ViewVC Help
Powered by ViewVC 1.1.2