- <?php
- /**
- * <b>Utility Class : Bible</b><br />
- * A collection of utility functions for working with Bible References.
- * Some of the functions get a specific verse, others parse verses, and others create links to verses.
- * Includes database and BibleGateway accessor functions.
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @link http://www.biblegateway.com Bible Gateway
- * @package paristemi
- * @subpackage paristemi_util
- * @since Build 0.7
- * @version Build 0.7
- * @filesource
- */
- /**
- * Include the constants file and all of the files in the include list
- */
- if(ltrim(dirname($_SERVER['SCRIPT_FILENAME'])) == "" || !file_exists($_SERVER['DOCUMENT_ROOT']."/constants.php")) {
- if(!file_exists("../constants.php")) { require_once("../public_html/constants.php"); }
- else { require_once("../constants.php"); }
- }
- else { require_once($_SERVER['DOCUMENT_ROOT']."/constants.php"); }
-
- /**
- * Utility Class : Bible
- * A collection of utility functions for working with Bible References.
- * Some of the functions get a specific verse, others parse verses, and others create links to verses.
- * Includes database and BibleGateway accessor functions.
- * @author Kristen O'Brien <kristen_paristemi-com>
- * @copyright Copyright © 2004, Kristen O'Brien
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @link http://www.paristemi.com Paristemi Main Site
- * @link http://www.biblegateway.com Bible Gateway
- * @package paristemi
- * @subpackage paristemi_util
- * @since Build 0.7
- * @version Build 0.7
- * @filesource
- */
- class UtilBible {
- function GetDBBibleVerses($ref)
- {
- $ref = explode(" ",$ref);
- if(count($ref) == 3) { $book = $ref[0]." ".$ref[1]; $ch = $ref[2]; }
- else { $book = $ref[0]; $ch = $ref[1]; }
- $ref2 = explode(":",$ch);
- $chapter = $ref2[0];
- $versestart = "";
- $versestop = "";
- if(isset($ref2[1])) {
- $ref3 = explode("-",$ref2[1]);
- $versestart = $ref3[0];
- if(isset($ref3[1])) {
- $versestop = $ref3[1];
- }
- }
- $versearr = array();
- if($versestop != "") {
- for($i=$versestart; $i<=$versestop; $i++) { $versearr[] = $i; }
- }
- else { $versearr[] = $versestart; }
-
- $result = mysql_query("select b.number
- from biblebooks b
- where b.book LIKE '$book%'
- limit 1;");
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- $booknum = $row['number'];
-
- $verses = array();
- foreach($versearr as $verse) {
- $result = mysql_query("select b.text
- from bible b
- where b.book = $booknum
- AND b.chapter = $chapter
- AND b.verse = $verse
- limit 1;");
- $row = mysql_fetch_array($result, MYSQL_ASSOC);
- $verses[] = $row['text'];
- }
- return implode(' ',$verses);
- }
-
- function &GetVerses($ref,$version=null,$implodeverses=1,$lang=null) {
- if(!$GLOBALS['USE_INTERNET_BIBLE_DB'] &&
- ($version == null || $version == $GLOBALS['DB_BIBLE_VERSION'])) {
- return UtilBible::GetDBBibleVerses($ref);
- $version = $GLOBALS['DB_BIBLE_VERSION'];
- }
- else {
- if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
- if($lang == null) { $lang = $GLOBALS['BIBLE_LANGUAGE']; }
- $ref = str_replace(":","%3A",str_replace(" ","+",$ref));
- $file =& file("http://www.biblegateway.com/cgi-bin/bible?passage=".
- $ref."&x=22&y=12&version=".$version.
- "&showfn=no&showxref=no&language=".$lang, "r");
- $file_content = trim(implode('',$file));
-
- $file_content = substr($file_content,0,strpos($file_content,'</CONTENT>'));
- $file_content = substr(strstr($file_content,'<DIV CLASS="PassageResults"><BR>
- <BR>'),37);
- $file_content = substr($file_content,0,strrpos($file_content,"<BR>"));
- $file_content = substr(strstr($file_content,"</B>"),4);
- $file_content = str_replace("<BR>"," ",$file_content);
- $file_content = preg_replace("/(\r\n|\n|\r)/", " ", $file_content);
- $file_content = str_replace(' quot;','"',$file_content);
- $file_content = str_replace(' ','',$file_content);
- $file_content = str_replace("<I>","#",$file_content);
- $file_content = str_replace("</I>","^",$file_content);
- while (strpos($file_content,"#") != 0) {
- $file_content = substr($file_content,0,strrpos($file_content,"#")).
- substr($file_content,strrpos($file_content,"^")+1,strlen($file_content));
- }
-
- $begin = strpos($file_content,"<SUP>");
- $verses = array();
- while($begin != 0) {
- $file_content = substr($file_content,strpos($file_content,"</SUP>")+6,
- strlen($file_content));
- if(strpos($file_content,"<SUP>") != 0) {
- $verses[] = trim(str_replace(' ','',substr($file_content,0,strpos($file_content,"<SUP>"))));
- }
- else { $verses[] = trim(str_replace(' ','',$file_content)); }
- $begin = strpos($file_content,"<SUP>");
- }
- if($implodeverses) { return implode(" ",$verses); }
- else { return $verses; }
- }
- }
-
- function &DisplayVerse($ref,$verse,$version=null,$bldref=0,$printspace=1,$endspace=1) {
- if(!$GLOBALS['USE_INTERNET_BIBLE_DB'] && $version == null) {
- $version = $GLOBALS['DB_BIBLE_VERSION']; }
- if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
- $verse = "<em>\"".$verse."\" "."</em>";
- if($printspace) { $verse .= "<br /> - "; }
- else { $verse .= "["; }
- if($bldref) { $verse .= "<b>"; }
- $verse .= $ref." (".$version.")";
- if($bldref) { $verse .= "</b>"; }
- if($printspace && $endspace) { $verse .= "<br />"; }
- else if(!$printspace){ $verse .= "]"; }
- return $verse;
- }
-
- function &DisplayVerseEmail($ref,$verse,$version=null) {
- if(!$GLOBALS['USE_INTERNET_BIBLE_DB'] && $version == null) {
- $version = $GLOBALS['DB_BIBLE_VERSION']; }
- if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
- $verse = '"'.trim(trim(trim($verse)," ")).'"'."\r\n\r\n- "
- .$ref." (".$version.")";
- $verse = str_replace('"','"',$verse);
- return $verse;
- }
-
- function &DisplayVerseLink($ref,$version=null,$lang=null,$href=1)
- {
- if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
- if($lang == null) { $lang = $GLOBALS['BIBLE_LANGUAGE']; }
- $displayref = $ref;
- $ref = str_replace(":","%3A",str_replace(" ","+",$ref));
- $linktext = "";
- if($href) { $linktext .= "<a href=\""; }
- $linktext .= "http://www.biblegateway.com/cgi-bin/bible?passage=".$ref;
- $linktext .= "&x=22&y=12&version=".$version;
- $linktext .= "&showfn=".$GLOBALS['BIBLE_SHOW_FOOTNOTE']."&showxref=".$GLOBALS['BIBLE_SHOW_CROSS_REFERENCE'];
- $linktext .= "language=".$lang."&orientation=linebyline";
- if($href) { $linktext .= "\">".$displayref."</a>"; }
- return $linktext;
- }
-
- function &DisplayChapterLink($ref,$version=null,$lang=null,$href=1,$linktitle=null)
- {
- if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
- if($lang == null) { $lang = $GLOBALS['BIBLE_LANGUAGE']; }
- if($linktitle == null) { $linktitle = $ref; }
- $refarr = explode(" ",$ref);
- if(count($refarr) == 3) { $book = $refarr[0]."+".$refarr[1]; $ch = $refarr[2]; }
- else { $book = $refarr[0]; $ch = $refarr[1]; }
- $ref2 = explode(":",$ch);
- $chapter = $ref2[0];
- $chapterlink = "";
- if($book != null && $chapter != null) {
- if($href) { $chapterlink .= "<a href=\""; }
- $chapterlink .= "http://www.biblegateway.com/bible?language=".$lang;
- $chapterlink .= "&version=".$version."&showfn=".$GLOBALS['BIBLE_SHOW_FOOTNOTE'];
- $chapterlink .= "&showxref=".$GLOBALS['BIBLE_SHOW_CROSS_REFERENCE'];
- $chapterlink .= "&passage=".$book."+".$chapter;
- if($href) { $chapterlink .= "\">".$linktitle."</a>"; }
- }
- return $chapterlink;
- }
-
- function &ParseVerses(&$full_text) {
- $text = $full_text;
- $begin = strpos($text,'</VERSE>');
- while($begin != 0) {
- $verseref = substr($text,0,strpos($text,'</VERSE>'));
- if(substr(strstr($verseref,'<VERSE'),6,1) == ">") {
- $verseref = substr(strstr($verseref,'<VERSE>'),7);
- $version = $GLOBALS['BIBLE_VERSION'];
- $btext = substr($text,0,strpos($text,'<VERSE>'));
- }
- else {
- $verseref = substr(strstr($verseref,'<VERSE ver='),15);
- $version = substr($text,strpos($text,'<VERSE ver=')+11,3);
- $btext = substr($text,0,strpos($text,'<VERSE'));
- }
- $etext = substr($text,strpos($text,'</VERSE>')+8,strlen($text));
- $text = $btext." ".
- UtilBible::DisplayVerse($verseref,UtilBible::GetVerses($verseref,$version),$version,0,0).
- " ".$etext;
- $begin = strpos($text,'</VERSE>');
- }
-
- $begin = strpos($text,'</LINK>');
- while($begin != 0) {
- $verseref = substr($text,0,strpos($text,'</LINK>'));
- if(substr(strstr($verseref,'<LINK'),5,1) == ">") {
- $verseref = substr(strstr($verseref,'<LINK>'),6);
- $version = $GLOBALS['BIBLE_VERSION'];
- $btext = substr($text,0,strpos($text,'<LINK>'));
- }
- else {
- $verseref = substr(strstr($verseref,'<LINK ver='),14);
- $version = substr($text,strpos($text,'<LINK ver=')+10,3);
- $btext = substr($text,0,strpos($text,'<LINK'));
- }
- $etext = substr($text,strpos($text,'</LINK>')+7,strlen($text));
- $text = $btext.UtilBible::DisplayVerseLink($verseref,$version).$etext;
- $begin = strpos($text,'</LINK>');
- }
- return $text;
- }
- }
-
- ?>