paristemi
[ class tree: paristemi ] [ index: paristemi ] [ all elements ]

Source for file util_bible.php

Documentation is available at util_bible.php

  1. <?php
  2. /**
  3. * <b>Utility Class : Bible</b><br />
  4. * A collection of utility functions for working with Bible References.
  5. * Some of the functions get a specific verse, others parse verses, and others create links to verses.
  6. * Includes database and BibleGateway accessor functions.
  7. * @author Kristen O'Brien <kristen_paristemi-com>
  8. * @copyright Copyright 2004, Kristen O'Brien
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @link http://www.paristemi.com Paristemi Main Site
  11. * @link http://www.biblegateway.com Bible Gateway
  12. * @package paristemi
  13. * @subpackage paristemi_util
  14. * @since Build 0.7
  15. * @version Build 0.7
  16. * @filesource
  17. */
  18. /**
  19. * Include the constants file and all of the files in the include list
  20. */
  21. if(ltrim(dirname($_SERVER['SCRIPT_FILENAME'])) == "" || !file_exists($_SERVER['DOCUMENT_ROOT']."/constants.php")) {
  22. if(!file_exists("../constants.php")) { require_once("../public_html/constants.php"); }
  23. else { require_once("../constants.php"); }
  24. }
  25. else { require_once($_SERVER['DOCUMENT_ROOT']."/constants.php"); }
  26. /**
  27. * Utility Class : Bible
  28. * A collection of utility functions for working with Bible References.
  29. * Some of the functions get a specific verse, others parse verses, and others create links to verses.
  30. * Includes database and BibleGateway accessor functions.
  31. * @author Kristen O'Brien <kristen_paristemi-com>
  32. * @copyright Copyright &copy; 2004, Kristen O'Brien
  33. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  34. * @link http://www.paristemi.com Paristemi Main Site
  35. * @link http://www.biblegateway.com Bible Gateway
  36. * @package paristemi
  37. * @subpackage paristemi_util
  38. * @since Build 0.7
  39. * @version Build 0.7
  40. * @filesource
  41. */
  42. class UtilBible {
  43. function GetDBBibleVerses($ref)
  44. {
  45. $ref = explode(" ",$ref);
  46. if(count($ref) == 3) { $book = $ref[0]." ".$ref[1]; $ch = $ref[2]; }
  47. else { $book = $ref[0]; $ch = $ref[1]; }
  48. $ref2 = explode(":",$ch);
  49. $chapter = $ref2[0];
  50. $versestart = "";
  51. $versestop = "";
  52. if(isset($ref2[1])) {
  53. $ref3 = explode("-",$ref2[1]);
  54. $versestart = $ref3[0];
  55. if(isset($ref3[1])) {
  56. $versestop = $ref3[1];
  57. }
  58. }
  59. $versearr = array();
  60. if($versestop != "") {
  61. for($i=$versestart; $i<=$versestop; $i++) { $versearr[] = $i; }
  62. }
  63. else { $versearr[] = $versestart; }
  64. $result = mysql_query("select b.number
  65. from biblebooks b
  66. where b.book LIKE '$book%'
  67. limit 1;");
  68. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  69. $booknum = $row['number'];
  70. $verses = array();
  71. foreach($versearr as $verse) {
  72. $result = mysql_query("select b.text
  73. from bible b
  74. where b.book = $booknum
  75. AND b.chapter = $chapter
  76. AND b.verse = $verse
  77. limit 1;");
  78. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  79. $verses[] = $row['text'];
  80. }
  81. return implode(' ',$verses);
  82. }
  83. function &GetVerses($ref,$version=null,$implodeverses=1,$lang=null) {
  84. if(!$GLOBALS['USE_INTERNET_BIBLE_DB'] &&
  85. ($version == null || $version == $GLOBALS['DB_BIBLE_VERSION'])) {
  86. return UtilBible::GetDBBibleVerses($ref);
  87. $version = $GLOBALS['DB_BIBLE_VERSION'];
  88. }
  89. else {
  90. if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
  91. if($lang == null) { $lang = $GLOBALS['BIBLE_LANGUAGE']; }
  92. $ref = str_replace(":","%3A",str_replace(" ","+",$ref));
  93. $file =& file("http://www.biblegateway.com/cgi-bin/bible?passage=".
  94. $ref."&x=22&y=12&version=".$version.
  95. "&showfn=no&showxref=no&language=".$lang, "r");
  96. $file_content = trim(implode('',$file));
  97. $file_content = substr($file_content,0,strpos($file_content,'</CONTENT>'));
  98. $file_content = substr(strstr($file_content,'<DIV CLASS="PassageResults"><BR>
  99. <BR>'),37);
  100. $file_content = substr($file_content,0,strrpos($file_content,"<BR>"));
  101. $file_content = substr(strstr($file_content,"</B>"),4);
  102. $file_content = str_replace("<BR>"," ",$file_content);
  103. $file_content = preg_replace("/(\r\n|\n|\r)/", " ", $file_content);
  104. $file_content = str_replace(' quot;','&quot;',$file_content);
  105. $file_content = str_replace('&nbsp;','',$file_content);
  106. $file_content = str_replace("<I>","#",$file_content);
  107. $file_content = str_replace("</I>","^",$file_content);
  108. while (strpos($file_content,"#") != 0) {
  109. $file_content = substr($file_content,0,strrpos($file_content,"#")).
  110. substr($file_content,strrpos($file_content,"^")+1,strlen($file_content));
  111. }
  112.  
  113. $begin = strpos($file_content,"<SUP>");
  114. $verses = array();
  115. while($begin != 0) {
  116. $file_content = substr($file_content,strpos($file_content,"</SUP>")+6,
  117. strlen($file_content));
  118. if(strpos($file_content,"<SUP>") != 0) {
  119. $verses[] = trim(str_replace(' ','',substr($file_content,0,strpos($file_content,"<SUP>"))));
  120. }
  121. else { $verses[] = trim(str_replace(' ','',$file_content)); }
  122. $begin = strpos($file_content,"<SUP>");
  123. }
  124. if($implodeverses) { return implode(" ",$verses); }
  125. else { return $verses; }
  126. }
  127. }
  128. function &DisplayVerse($ref,$verse,$version=null,$bldref=0,$printspace=1,$endspace=1) {
  129. if(!$GLOBALS['USE_INTERNET_BIBLE_DB'] && $version == null) {
  130. $version = $GLOBALS['DB_BIBLE_VERSION']; }
  131. if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
  132. $verse = "<em>\"".$verse."\" "."</em>";
  133. if($printspace) { $verse .= "<br /> - "; }
  134. else { $verse .= "["; }
  135. if($bldref) { $verse .= "<b>"; }
  136. $verse .= $ref." (".$version.")";
  137. if($bldref) { $verse .= "</b>"; }
  138. if($printspace && $endspace) { $verse .= "<br />"; }
  139. else if(!$printspace){ $verse .= "]"; }
  140. return $verse;
  141. }
  142. function &DisplayVerseEmail($ref,$verse,$version=null) {
  143. if(!$GLOBALS['USE_INTERNET_BIBLE_DB'] && $version == null) {
  144. $version = $GLOBALS['DB_BIBLE_VERSION']; }
  145. if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
  146. $verse = '"'.trim(trim(trim($verse),"&nbsp;")).'"'."\r\n\r\n- "
  147. .$ref." (".$version.")";
  148. $verse = str_replace('&quot;','"',$verse);
  149. return $verse;
  150. }
  151.  
  152. function &DisplayVerseLink($ref,$version=null,$lang=null,$href=1)
  153. {
  154. if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
  155. if($lang == null) { $lang = $GLOBALS['BIBLE_LANGUAGE']; }
  156. $displayref = $ref;
  157. $ref = str_replace(":","%3A",str_replace(" ","+",$ref));
  158. $linktext = "";
  159. if($href) { $linktext .= "<a href=\""; }
  160. $linktext .= "http://www.biblegateway.com/cgi-bin/bible?passage=".$ref;
  161. $linktext .= "&amp;x=22&amp;y=12&amp;version=".$version;
  162. $linktext .= "&showfn=".$GLOBALS['BIBLE_SHOW_FOOTNOTE']."&showxref=".$GLOBALS['BIBLE_SHOW_CROSS_REFERENCE'];
  163. $linktext .= "language=".$lang."&amp;orientation=linebyline";
  164. if($href) { $linktext .= "\">".$displayref."</a>"; }
  165. return $linktext;
  166. }
  167. function &DisplayChapterLink($ref,$version=null,$lang=null,$href=1,$linktitle=null)
  168. {
  169. if($version == null) { $version = $GLOBALS['BIBLE_VERSION']; }
  170. if($lang == null) { $lang = $GLOBALS['BIBLE_LANGUAGE']; }
  171. if($linktitle == null) { $linktitle = $ref; }
  172. $refarr = explode(" ",$ref);
  173. if(count($refarr) == 3) { $book = $refarr[0]."+".$refarr[1]; $ch = $refarr[2]; }
  174. else { $book = $refarr[0]; $ch = $refarr[1]; }
  175. $ref2 = explode(":",$ch);
  176. $chapter = $ref2[0];
  177. $chapterlink = "";
  178. if($book != null && $chapter != null) {
  179. if($href) { $chapterlink .= "<a href=\""; }
  180. $chapterlink .= "http://www.biblegateway.com/bible?language=".$lang;
  181. $chapterlink .= "&amp;version=".$version."&amp;showfn=".$GLOBALS['BIBLE_SHOW_FOOTNOTE'];
  182. $chapterlink .= "&amp;showxref=".$GLOBALS['BIBLE_SHOW_CROSS_REFERENCE'];
  183. $chapterlink .= "&amp;passage=".$book."+".$chapter;
  184. if($href) { $chapterlink .= "\">".$linktitle."</a>"; }
  185. }
  186. return $chapterlink;
  187. }
  188. function &ParseVerses(&$full_text) {
  189. $text = $full_text;
  190. $begin = strpos($text,'</VERSE>');
  191. while($begin != 0) {
  192. $verseref = substr($text,0,strpos($text,'</VERSE>'));
  193. if(substr(strstr($verseref,'<VERSE'),6,1) == ">") {
  194. $verseref = substr(strstr($verseref,'<VERSE>'),7);
  195. $version = $GLOBALS['BIBLE_VERSION'];
  196. $btext = substr($text,0,strpos($text,'<VERSE>'));
  197. }
  198. else {
  199. $verseref = substr(strstr($verseref,'<VERSE ver='),15);
  200. $version = substr($text,strpos($text,'<VERSE ver=')+11,3);
  201. $btext = substr($text,0,strpos($text,'<VERSE'));
  202. }
  203. $etext = substr($text,strpos($text,'</VERSE>')+8,strlen($text));
  204. $text = $btext." ".
  205. UtilBible::DisplayVerse($verseref,UtilBible::GetVerses($verseref,$version),$version,0,0).
  206. " ".$etext;
  207. $begin = strpos($text,'</VERSE>');
  208. }
  209.  
  210. $begin = strpos($text,'</LINK>');
  211. while($begin != 0) {
  212. $verseref = substr($text,0,strpos($text,'</LINK>'));
  213. if(substr(strstr($verseref,'<LINK'),5,1) == ">") {
  214. $verseref = substr(strstr($verseref,'<LINK>'),6);
  215. $version = $GLOBALS['BIBLE_VERSION'];
  216. $btext = substr($text,0,strpos($text,'<LINK>'));
  217. }
  218. else {
  219. $verseref = substr(strstr($verseref,'<LINK ver='),14);
  220. $version = substr($text,strpos($text,'<LINK ver=')+10,3);
  221. $btext = substr($text,0,strpos($text,'<LINK'));
  222. }
  223. $etext = substr($text,strpos($text,'</LINK>')+7,strlen($text));
  224. $text = $btext.UtilBible::DisplayVerseLink($verseref,$version).$etext;
  225. $begin = strpos($text,'</LINK>');
  226. }
  227. return $text;
  228. }
  229. }
  230.  
  231. ?>

Documentation generated on Mon, 10 May 2004 12:11:05 -0700 by phpDocumentor 1.3.0RC3