Working on Bible Verse Tags for ASP.NET (C#)

To do:

  • build Regex to detect bible verses in tags
  • put in named back-references
  • find a way to choose different tables with LINQ
  • make it work for an entire chapter
  • add error messages
  • move it to a class file instead of in the page
  • run it from the filterText method if IndexOf(“[bible]”) !=-1
  • fix toVerse in case it goes out of range
  • fix misspelled or abbreviated bookName with value from database
  • change to Compiled Queries
  • add footnotes
  • pretty up error messages
  • clean up final code
public class bibleParts
{
	public static Func<bibleDataContext, string, IQueryable<bibleParts>>
		theVersion = CompiledQuery.Compile((bibleDataContext context, string bibleVersion) =>
			(from v in context.bibles_infos
			 where v.bibleName == bibleVersion
			 select new bibleParts
				 {
					 version = v.bibleID,
					 language = v.language,
					 copyright = v.copyright
				 }));

	public static Func<bibleDataContext, int, string, IQueryable<bibleParts>>
		theBook = CompiledQuery.Compile((bibleDataContext context, int bookLang, string book) =>
			(from b in context.book_names
			 where (b.book == book || b.abbreviation == book || b.alt == book) && b.language == bookLang
			 select new bibleParts
			 {
				 bookID = b.book_id,
				 book = b.book
			 }));
	public static Func<bibleDataContext, int, int, int, IQueryable<bibleParts>>
		theVerses = CompiledQuery.Compile((bibleDataContext context, int version, int book, int chapter) =>
			(from v in context.verses
			 where v.versionID == version && v.bookID == book && v.chapter == chapter
			 select new bibleParts
			 {
				 verseNum = v.verse1,
				 thisVerse = v.text
			 }));

	public int version {get;set;}
	public int language {get;set;}
	public string copyright {get;set;}
	public int bookID {get;set;}
	public string book {get;set;}
	public int verseNum {get;set;}
	public string thisVerse {get;set;}
}
</pre></pre>
<pre><pre>private string verseMod(string text)
{
	string textVal = text;
	string errorValue = "";
	string verseNumBegin = "<sup>";
	string verseNumEnd = "</sup>";
	string footerBegin = "<em> - ";
	string footerEnd = "</em>";
	string bibleVersion = "kjv";  //default version if none is specified
	string pat = @"\[bible[=]?(?<version>[a-zäëïöüæø]*)](?<entire>(?<book>([0-9][\s]?)?[a-zäëïöüæø]*[\s]{1}([a-zäëïöüæø]*[\s]?[a-zäëïöüæø]*[\s]{1})?)(?<chapter>[0-9]{1,3})(:{1}(?<verse>[0-9]{1,3})(-{1}(?<toVerse>[0-9]{1,3}))?)?)\[/bible]";

	Regex r = new Regex(pat, RegexOptions.IgnoreCase);

	MatchCollection m = r.Matches(textVal);
	foreach (Match match in m)
	{
		string verseVal = "";
		string errorText = "";
		if (!String.IsNullOrEmpty(match.Groups["version"].Value))
			bibleVersion = match.Groups["version"].Value;
		string thisBook = match.Groups["book"].Value;
		int fromVerse = 0;
		int toVerse;
		if (!String.IsNullOrEmpty(match.Groups["verse"].Value))
			fromVerse = Convert.ToInt32(match.Groups["verse"].Value);
		toVerse = fromVerse;
		if (!String.IsNullOrEmpty(match.Groups["toVerse"].Value))
			toVerse = Convert.ToInt32(match.Groups["toVerse"].Value);

		using (var bdc = new bibleDataContext())
		{
			var searchVersion = bibleParts.theVersion(bdc, bibleVersion).SingleOrDefault();
			if (searchVersion != null)
			{
				var searchBook = bibleParts.theBook(bdc, searchVersion.language, thisBook).SingleOrDefault();
				if (searchBook != null)
				{
					var searchVerses = bibleParts.theVerses(bdc, searchVersion.version, searchBook.bookID, Convert.ToInt32(match.Groups["chapter"].Value));
						if (fromVerse != 0)
						{
							searchVerses = from v in searchVerses
										   where v.verseNum >= fromVerse && v.verseNum <= toVerse
										   select v;
						}
							string realToVerse = "";
							verseVal += String.Format("{1}{0}{2}", match.Groups["entire"].Value.Replace(match.Groups["book"].Value.Trim(), searchBook.book), "<span class=\"bibleHead\">", "</span>");
							verseVal += "<span class=\"bibleContent\">";
							foreach (var theVerse in searchVerses)
							{
								string verseFormat = "{2}{1}{3}{0} ";
								if (String.IsNullOrEmpty(match.Groups["toVerse"].Value) && !String.IsNullOrEmpty(match.Groups["verse"].Value))
									verseFormat = "{0} ";

								verseVal += String.Format(verseFormat, theVerse.thisVerse, theVerse.verseNum, verseNumBegin, verseNumEnd);
								realToVerse = theVerse.verseNum.ToString();
							}
							verseVal += String.Format("{1}{0}{2}</span>", searchVersion.copyright, footerBegin, footerEnd);
							verseVal = verseVal.Replace(String.Format("-{0}", toVerse), String.Format("-{0}", realToVerse));
							verseVal = verseVal.Replace("-</span>", "</span>");
				}
				else
				{
					errorText = "The book \"{0}\" does not exist.  Please check the spelling and try again.";
					errorValue = match.Groups["book"].Value;
				}
			}
			else
			{
				errorText = "The version \"{0}\" is not installed on this server";
				errorValue = match.Groups["version"].Value;
			}
			if (String.IsNullOrEmpty(errorText))
			{
				textVal = textVal.Replace(match.Groups[0].Value, verseVal);
			}
			else
			{
				textVal = textVal.Replace(match.Groups[0].Value,String.Format(errorText,errorValue.Trim()));
			}
		}
	}
	return textVal;
}

Currently active at newcastlechurchofChrist.com.

Bible verse tags 2.0

See here for more information on the new version of the Bible verse tags.

I hope that this plugin can be used to spread the good news throughout the earth.

Let me know if you need any help installing it.

John 3:16For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. - King James Version
1 John 11That which was from the beginning, that which we have heard, that which we have seen with our eyes, that which we beheld, and our hands handled, concerning the Word of life   2(and the life was manifested, and we have seen, and bear witness, and declare unto you the life, the eternal [life], which was with the Father, and was manifested unto us);   3that which we have seen and heard declare we unto you also, that ye also may have fellowship with us: yea, and our fellowship is with the Father, and with his Son Jesus Christ:   4and these things we write, that our joy may be made full.   5And this is the message which we have heard from him and announce unto you, that God is light, and in him is no darkness at all.   6If we say that we have fellowship with him and walk in the darkness, we lie, and do not the truth:   7but if we walk in the light, as he is in the light, we have fellowship one with another, and the blood of Jesus his Son cleanseth us from all sin.   8If we say that we have no sin, we deceive ourselves, and the truth is not in us.   9If we confess our sins, he is faithful and righteous to forgive us our sins, and to cleanse us from all unrighteousness.   10If we say that we have not sinned, we make him a liar, and his word is not in us.      - American Standard Version
1 Mosebog 3:12Adam svarede: "Kvinden, som du satte ved min Side, gav mig af Træet, og så spiste jeg." - Dansk bibel
Kolosser 3:1-31Seid ihr nun mit Christo auferstanden, so suchet, was droben ist, da Christus ist, sitzend zu der Rechten Gottes.   2Trachtet nach dem, was droben ist, nicht nach dem, was auf Erden ist.   3Denn ihr seid gestorben, und euer Leben ist verborgen mit Christo in Gott.    - Luther bibel

Trackbacked to:
Open Trackback @ Samantha Burns dot com
Cao’s Blog
Diane’s Stuff

Open trackback problems (sorry)

Thanks to Cao over at Cao’s blog for pointing out that the link to my open trackback post was broken.

I was wondering why I haven’t got any for a long time.

I’m going to have to ping everyone to let them know it’s back up and active.

Please accept my heartfelt apology. 🙂

Mark B.

Su. InMuscatine
Su. Onemanbandwidth
Su. The Blazer Blog
Su. Miceland
Su. Where are my socks?
Su. Peakah’s Provocations
Su. Otimaster
Su. Grandinite
Su. Free Constitution
Su. Conservative Culture (Su, T)
Su. – a metamorphoself
Su. The Amboy Times
Su. Stageleft
M. Courting Destiny (M, W)
M. Bloggin’ Outloud (M, F.)
M. The Land of Ozz
M. DragonLady’s World
M. Committees of Correspondence
M. The Tar Pit
M. Pirates! Man your Women!
M. WebKittyn Warbles
M. Forward Biased
M. Urban Paradise
M. Perri Nelson’s Website (M, W, F)
T. The Liberal Wrong Wing
T. Tor’s Rants
T. Those Bastards! (T, F.)
T. The Business of America is Business
T. RightPundits.com (T, F)
T. historymike’s musings
T. Common Folk Using Common Sense
T. Rightlinx
T. The Median Sib
T. The Path to Endarkenment
T. Stingray: a blog for salty Christians
T. Planck’s Constant
T. Renaissance Blogger (T, Th.)
T. Signaleer
W. third world county (W, F.)
W. Gribbit’s Word (W, S.)
W. Stop The ACLU (W, S.)
W. Diane’s Stuff
W. Stuck On Stupid
W. This May…Or Not
W. rashbre central
W. Cigar Intelligence Agency (W, Wknds)
W. Jack of All Trades
W. Right Truth
W. Chaotic Synaptic Activity
Th. Liberal Common Sense
Th. TMH’s Bacon Bits
Th. customerservant.com
Th. A Quiet Noise
Th. Mental Rhinorrhea
Th. Sed Vitae (Th, F)
Th. Republispin
Th. Diary of the Mad Pigeon
F. Pirate’s Cove (M, F)
F. Dan Mancini
F. MacBros’ Place
F. The World According To Carl
F. Gospel Fiction
F. Comedian Jenée: People are Idiots
F. Woman Honor Thyself
F. Publius Rendezvous (wknd)
F. Madman Returns
F. The Hill Chronicles
S. The Crazy Rants of Samantha Burns
S. Point Five
S. 7 Deadly Sins
S. Assorted Babble
S. Church and State
S. Selective Amnesia
S. Case Notes from the Artsy Asylum
S. Neocon Express
D. The Conservative Cat
D. Don Surber
D. The Dumb Ox
D. NIF
D. Right Wing Nation
D. Colbert Report
D. imagine kitty magazine
D. partyblog.ca
D. Robinik Open Blog
D. Culturetastic
D. Rightwing Guy
Wknd. Oblogatory Anecdotes
Wknd. Borknat
Wknd. Blue Star Chronicles
Wknd. The Right Nation
Wknd. Leaning Straight Up
Wknd. The Uncooperative Blogger
Wknd. Stuck On Stupid
Wknd. The Bullwinkle Blog
Wknd. 123beta (F, Wknd)
Wknd. Robinik.net
Wknd. The Clash of Civilizations (W, F, Wknd)

Open Trackback Alliance

Please note: Imagine Kitty Magazine is changing direction and is no longer encouraging trackbacks of a political nature. Right wing or left wing, bashing or backing will most likely be denied. The line between the “right” and the “left” is so blurred that it all seems so pointless. You’re not going to change anyone’s mind anyway, so let’s give it a break.

Open Trackback Alliance

Please trackback to this this URL and link to this URL in your article and your trackback will show on the front page of this blog. For now the 10 most recent trackbacks will show but this may change in the future depending how many participate.

From the Open Trackback Alliance FAQ:

The entire concept is to encourage bloggers to showcase their best recent articles on other blogs which may not otherwise recognize or know about their works.

Open Trackback Alliance members have agreed to create an open article at least once a week, which anyone can create a link to their own blog articles…

So link up your best article. Let’s see what you’ve got. 🙂

Trackbacked to:
The Crazy Rants of Samantha Burns

Open Trackback Weekend

I think I am going to switch my open trackback day to the weekend. Probably Friday through Sunday.

Every Weekend I will try to have an Open Trackback article.

From the Open Trackback Alliance FAQ:

The entire concept is to encourage bloggers to showcase their best recent articles on other blogs which may not otherwise recognize or know about their works.

Open Trackback Alliance members have agreed to create an open article at least once a week, which anyone can create a link to their own blog articles…

So link up your best article. Let’s see what you’ve got. 🙂

The following have linked to this article:

Props to Akismet

Akismet has not let a single spam get through. It is worth switching to WordPress just to get this plugin. I’ve been getting quite a bit of sucky spam comments lately. I’m sure this has something to do with my page views going from about 40 per day to over 170 per day.

Spammers, you suck! Losers.

Trackbacked to:
The Crazy Rants of Samantha Burns
Third World County
Bloggin’ Outloud
MacBros’ Place
The Conservative Cat
Right Wing Nation
MacStansbury.org

Open trackback Friday

I’m posting this one on Thursday night and will let it run until Sunday night. My son has tomorrow off of school so we’re going to do something fun.

Every Friday I will try to have an Open Trackback article.

From the Open Trackback Alliance FAQ:

The entire concept is to encourage bloggers to showcase their best recent articles on other blogs which may not otherwise recognize or know about their works.

Open Trackback Alliance members have agreed to create an open article at least once a week, which anyone can create a link to their own blog articles…

So link up your best article. Let’s see what you’ve got. 🙂

The following have linked to this article:

My suggestion to anyone trackbacking to my blog using WordPress 2.x would be to go to your admin panel, under Options -> Discussion uncheck the box that says “Attempt to notify any Weblogs linked to from the article (slows down posting.)” This is what I have done, it speeds up posting and also stops outgoing pingbacks.

With trackbacks you get a nice summary of the incoming post, with pingbacks you get a what the WordPress development team calls “context” and what I call nonsense. If only I could suppress incoming pingbacks without suppressing incoming trackbacks as well peace would rule the world.

Open Trackback Friday

I’m posting this one on Thursday night and will let it run until Sunday night. My son has tomorrow off of school so we’re going to do something fun.

Every Friday I will try to have an Open Trackback article.

From the Open Trackback Alliance FAQ:

The entire concept is to encourage bloggers to showcase their best recent articles on other blogs which may not otherwise recognize or know about their works.

Open Trackback Alliance members have agreed to create an open article at least once a week, which anyone can create a link to their own blog articles…

So link up your best article. Let’s see what you’ve got. 🙂

The following have linked to this article:

My suggestion to anyone trackbacking to my blog using WordPress 2.x would be to go to your admin panel, under Options -> Discussion uncheck the box that says “Attempt to notify any Weblogs linked to from the article (slows down posting.)” This is what I have done, it speeds up posting and also stops outgoing pingbacks.

With trackbacks you get a nice summary of the incoming post, with pingbacks you get a what the WordPress development team calls “context” and what I call nonsense. If only I could suppress incoming pingbacks without suppressing incoming trackbacks as well peace would rule the world.

More news on the WordPress trackback issue

In my WordPress Trac Ticket concerning the WordPress teams preference of pingbacks over trackbacks, I went ahead and reopened the ticket with the following complaint.

I’m going to go ahead and disagree with you completely on this. You say “More contextual”, I say “More nonsensical”. It just doesn’t work the way you think it does in practice, maybe in theory but not in actual use of the software. With a trackback you get a purposeful summary (the first few words of the post) with a pingback you get partial sentences and a few words that just happened to surround the link to your blog.

It may “handle international encoding better” but why not make trackbacks do the same?

I can understand how they are more “spam resistant”, I’ll give you that one (one out of four isn’t so hot though). With new spam suppression software available I don’t see this as much of a problem.

“Better link text”? No. Adding the post title to the link doesn’t look as nice as trackbacks Blog name followed by an unlinked post title. The trackback way is much preferred.

It seems that some people are using my fix of switching the code in execute-pings.php so that trackbacks go out first.

<?php
require_once(’../wp-config.php’);
// Do Enclosures
while ($enclosure = $wpdb->get_row(”SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = ‘_encloseme’ LIMIT 1″)) {
$wpdb->query(”DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = ‘_encloseme’;”);
do_enclose($enclosure->post_content, $enclosure->ID);
}
// Do Trackbacks
$trackbacks = $wpdb->get_results(”SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status != ‘draft’”);
if ( is_array($trackbacks) ) {
foreach ( $trackbacks as $trackback ) {
do_trackbacks($trackback->ID);
}
}
// Do pingbacks
while ($ping = $wpdb->get_row(”SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = ‘_pingme’ LIMIT 1″)) {
$wpdb->query(”DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = ‘_pingme’;”);
pingback($ping->post_content, $ping->ID);
}
?>

Thanks for listening. I’m just politely disagreeing with you and letting you know that I’m not the only one that feels this way about it.

Anyone wanting to try this out can download execute-pings.php here.

You may then test this out by using this post. If you include a trackback and a ping back the trackback will be sent out first ensuring its reception.

This post is considered “Open Trackback” with no time limits.

The following have linked to this article:

Linked to:
The Crazy Rants of Samantha Burns
Diane’s Stuff (twice) Sorry Diane (I always do that to her).

Open Trackback Day!

Every Friday I will try to have an Open Trackback article.

From the Open Trackback Alliance FAQ:

The entire concept is to encourage bloggers to showcase their best recent articles on other blogs which may not otherwise recognize or know about their works.

Open Trackback Alliance members have agreed to create an open article at least once a week, which anyone can create a link to their own blog articles…

So link up your best article. Let’s see what you’ve got. 🙂

The following have linked to this article:

To the WordPress development team. Here’s proof that pingbacks stink compared to trackbacks (see comments). With trackbacks you get a nice summary of the incoming post, with pingbacks you get a what you call “context” and what I call nonsense. If only I could suppress incoming pingbacks without suppressing incoming trackbacks as well peace would rule the world.

My suggestion to anyone trackbacking to my blog using WordPress 2.x would be to go to your admin panel, under Options -> Discussion uncheck the box that says “Attempt to notify any Weblogs linked to from the article (slows down posting.)” This is what I have done, it speeds up posting and also stops outgoing pingbacks.

Changes to execute-pings.php

In my disagreement with the powers-that-be of the WordPress creators and coders, I expressed the need for Trackbacks to take precedence over Pingbacks. They marked my trac ticket as WONTFIX so I did it myself.

I simply rearranged the order in which the pings are sent putting trackbacks before pingbacks:
<?php
require_once('../wp-config.php');
// Do Enclosures
while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';");
do_enclose($enclosure->post_content, $enclosure->ID);
}
// Do Trackbacks
$trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status != 'draft'");
if ( is_array($trackbacks) ) {
foreach ( $trackbacks as $trackback ) {
do_trackbacks($trackback->ID);
}
}
// Do pingbacks
while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
pingback($ping->post_content, $ping->ID);
}
?>

It seems to be working and it makes much more sense this way.

You can download the updated file here.

You may then test this out by using this post. If you include a trackback and a ping back the trackback will be sent out first ensuring its reception.

This post is considered “Open Trackback” with no time limits.

The following have linked to this article: