UBB.Dev
I appreciate Gizmo for helping me find this development forum. I had asked this question over at the UBB.threads forum, and we decided to move the discussion to a more appropriate location.

Originally Posted by AsiaWired
I would like to know how I can be of assistance in adding a feature that would be well-loved in Christian and/or religious forums. The feature would be for automatic detection of scripture references, and auto-linking them to an online scripture database such as BlueLetterBible.org, or BibleGateway.com.

I have made a Perl script with the full regex necessary to recognize Bible references by full title, or by abbreviation, including the apocryphal books and Roman numeral notations. The script was designed for the conversion of text or html documents to ThML (Theological Markup Language). It would not be difficult to convert the regex to use for autolinking the scriptural citations within a user's post. This would greatly simplify things by placing the text just a click away from the reader.

This feature could be implemented such that it was either enabled or disabled, and if enabled, the admin should be able to select which of the online databases to link to, and which version of the Bible to use by default. Just this much would satisfy me for now. In the future, we could go a step further and enable user choice of Bible version for his/her own posts, and/or Bible DB.

I'm not fluent with PHP, but would willingly cooperate with the developers to translate the Perl into functionality with the forum code.

Can this go in Version 8? Please?! smile


Now, I would be willing to help code this addon in PHP as best I can, if someone here would be willing to help me test it (as I do not administer a server with UBB.threads, only participate in a Christian forum which does).

I saw while signing up that I should not ask for any of UBB.threads' copyrighted files. Would it be possible to show me just enough of one file which I could modify to create this addon? If this were to go into an entirely new file, what mechanism would be used to link it in with the rest of the software?

On the other hand, I would be happy to post the relevant Perl code here which would need translation to PHP, if someone here would like to help incorporate this.

I know a number of Christian forums which would appreciate this feature. Thank you!
Posted By: Gizmo Re: Auto-link generation for Scripture references - 11/29/2009 12:48 AM
Well, I guess I should start with some basic probing questions...
1. How does your perl script detect verses and link to the database (3rd party) site?
2. Do you have any experience at all in PHP? (I ask as any addon for a php script really should be in php)

As for licensed files; it's because if sharing said files we violate our license; as most of us here are gold license holders, that's like $800+ down the drain (Depending on when we renewed and the rates at the time).

I'd think that the site you're a member of would be somewat interested to have this done, is the owner not interested in providing you access?

Well, to link to a new page (like in the breadcrumbs bar above that links to the forum, portal, etc) a user would simply just add a link to the header.tpl file; so linking around isn't the issue, it's more how everything would work...

a good start would be to post your perl script and perhaps link us to a working version of the script; if someone is interested in taking it over I'm sure they'll comment.
Gizmo,

1. The perl script excels at the detecting verses part, via a regex. However, it was not a database-driven script in the least, and currently has no database-related code.

It does use an external file which is basically a tab-delimited list of Bible books and their potential representations (e.g. abbreviations, alternate names/spellings, etc.).

2. I have zero experience in PHP when it comes to writing it myself from scratch--I would just rather use Perl. I have some (a couple eight-hour days' worth) PHP experience in terms of editing existing PHP to perform some modifications of my own (such as adding some Qmail functions to Webmin).

The admin of the UBB forum where I participate has not opened it up for me to access--and perhaps he cannot share any of the files with me for the same reasons you have stated above. I understand the need to protect your software with a license, but this does make development difficult.

This script could work in more than one way. It could be applied to new posts as they are being received into the DB, such that scripture references were converted to links before insertion into the DB. In that case, the actual posts would be altered, however, and the feature would not be able to be switched off from old posts later. I would rather not change actual posts.

The way I would recommend this working is to simply parse the server output before going to the browser, and adding the links on the fly. This would not require any special arrangement with the DB, it would merely act as a filter on output.

Maybe you need to attack this item with a different viewpoint to gain support from others.

The way you requested this mod will only apply to a specific few users. Possibly you need to revisit the feature request with the viewpoint of how it can be utilized with a broader use of users other than christian sites utilizing a bible database.

FYI,
I for one would have no use for such a feature as suggested. Just my 2 cents.
Here's the subroutine for reading the data for the book names:
Code
sub assemblebooks {
my @data = (); # To hold file source data
my @books = (); # To hold book tokens for entire file
my @temp = (); # To hold single book's tokens (one line in file)
my $line = ""; # For each line of the file
my $piece = ""; # For each record in line
open (DATA, '<:encoding(utf8)', $booksfile) or die "Cannot open the Bible book names file! $!\n";
@data = <DATA>;
close DATA;

my $bk = ''; #Full book name to be cached here
foreach $line (@data) {
chomp $line;
@temp = split/\s*\t|,\s*/, $line;
$bk=$temp[0];
foreach $piece (@temp) {
push @books, "$piece\n";
$abbrev{$piece}=$bk;
}
}

$book = Regexp::Assemble->new;
foreach $line (@books) {
chomp $line;
$book->add( "$line" );
}
} # END SUB

And here's the subroutine for parsing ThML texts (will require slight modifications for the desired links output):
Code
sub parsetext {
my $num = qr/\d+/;
my $roman_numeral = qr/\b(?=[IVXLCDM])(?>M{0,4}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|V?I{0,3}))\b/i;
my $chapter = qr/$num|$roman_numeral/;

my $replace = sub {

my $REFERENCE = $1;
my $BOOK = $2||$7;
my $three = $3;
my $VERSION = "";
#NEED TO INCORPORATE SOME VERSION CHECKING ON $6
$VERSION = $VERSION || $DEFAULT_VER;
if ($abbrev{$BOOK}) { $BOOK = $abbrev{$BOOK} };
my $ThML = qq'$Lbracket\scripRef version="$VERSION" passage="$REFERENCE" parsed="$VERSION|$BOOK';
chomp $three;
$three=~s/^\.//;
$three=~s/;\s*$//;

my ($chapverse,$chap,$verses,$verse_start,$verse_end,$segment,$i) = '';
while ($three) {
($chapverse,$three) = split(/;/, $three, 2);
($chap, $verses) = split(/:|\./, $chapverse);
$chap =~ s/\s//g;
$chap = arabic($chap) if isroman($chap);
while ($verses) {
($segment,$verses) = split(/,|\s(?:and|\&)\s/i, $verses, 2);
$segment=~s/\s//g;
($verse_start,$verse_end) = split(/\-/, $segment);
unless ($verse_end) { $verse_end=$verse_start };
for ($i=$verse_start; $i<=$verse_end; $i++) {
$ThML .= "|$chap|$i";
}
}
if ($three) { $ThML .= ";$VERSION|$BOOK" } else { $ThML .= "|" };
}
$ThML .= qq|"$Rbracket$REFERENCE$Lbracket/scripRef$Rbracket|;
return $ThML;
};
###

$text =~ s%
( # BEGIN CAPTURE OF $1 ***
(?: # *LOOK FOR USUAL GRAMMAR FIRST (CAPTURED SEPARATELY)
($book) # MATCH BIBLE BOOK NAMES FROM ASSEMBLED REGEX $2
( # BEGIN CAPTURE OF $3
\.?\s # MATCH A SPACE FOLLOWING BOOK NAME
( (?:$chapter)+ # MATCH A CHAPTER
(?:[:\-,. ]* # MATCH A DELIMITER BETWEEN CHAPTERS AND VERSES
(?: (?:and|\&) \s+)? # MATCH AN OPTIONAL "AND" OR "&" BETWEEN VERSES
\d+)* # MATCH VERSE DIGITS
) # MATCH A NUMBER (USUALLY A CHAPT.)=$4
# OPTIONALLY FOLLOWED BY VERSE NUMBERS
# WHICH MAY BE DELIMITED BY THE [:-, ]
(\; # .MATCH A SEMI-COLON...ETC. (BELOW)=$5
(?:\s*(?:$chapter) # .MATCH AN OPTIONAL SPACE, THEN A NUMBER
(?:[:\-,. ]* # .MATCH A DELIMITER BETWEEN CHAPTERS AND VERSES
(?:(?:and|\&)\s+)* # .MATCH AN OPTIONAL "AND" OR "&" BETWEEN VERSES
\d+)* ) # .MATCH ZERO+ VERSE DELIMITERS/NUMBERS
)* # .MAKE CLAUSE OPTIONAL & REPEATABLE

) # CLOSE CAPTURE OF $3
) | (Book\sof\s($book)) # *OR CAPTURE WHOLE BOOK IN ABSENCE OF CHAP/VERSE
# ABOVE LINE CAPTURES TO $7 & $8
) # CLOSE CAPTURE OF $1 ***


####
( # >LOOK FOR OPTIONAL VERSION NOTATION=$6
(?:\(\w+\)*) # >MATCH WORD IN PARENTHESES
| # > -OR-
(?:[, ]+(?!$book)\w+){0,6} # >MATCH COMMA OR SPACE FOLLOWED BY WORD
)* # >CLOSE CAPTURE FOR $6
####
%$replace->()%egx;

=item Example
<scripRef version="NIV" passage="Rom. viii. 27,28; x. 8-13"
parsed="NIV|Romans|8|27|8|28;NIV|Romans|10|8|10|13">
Romans viii. 27,28; x. 8-13
</scripRef>
=cut

} #END SUB parsetext
Originally Posted by Ruben Rocha

Maybe you need to attack this item with a different viewpoint to gain support from others.

The way you requested this mod will only apply to a specific few users. Possibly you need to revisit the feature request with the viewpoint of how it can be utilized with a broader use of users other than christian sites utilizing a bible database.

FYI,
I for one would have no use for such a feature as suggested. Just my 2 cents.

Ruben,

This particular addon may only apply to Christian sites, but there are quite a few Christian forums using UBB.threads. However, this addon could be adapted for other uses.

The scripture references require some heavy regex to read/parse them properly. If you simply desire to create links out of keywords, it would likely require a fraction of the challenge that these Bible texts will require. In other words, if you develop this addon, adapting it to other uses might be an easy drop in complexity.
© UBB.Developers