MediaWiki Extension for BLB Script Tagger

Contents

This extension adds BlueLetterBible's tagger.

For a full description of what the BLB Tagger can do, see http://www.blueletterbible.org/freeoffer/BLB_ScriptTagger/

For a demonstration of BLB Tagger in action, see http://www.txbobsc.com/life/am_aic/, or simply hover over one of these: Rom 3:23, Rom 6:23, Rom 5:8, Rom 10:9-10, John 3:16, John 1:12, I John 5:11-12.

Installation

Copy this file to your Mediawiki extensions folder at

extensions/BlueLetterBibleTagger/BlueLetterBibleTagger.php

Add the following lines at the end of your Localsettings.php

# Add BlueLetterBibleTagger extension (by Bob Sander-Cederlof)
require_once("extensions/BlueLetterBibleTagger/BlueLetterBibleTagger.php");

Usage

On any page with scripture references, anywhere on the page, add this:

<blbtagger />

This will cause the following line to be added between <head> and </head>:

<script type="text/javascript" src="http://www.blueletterbible.org/scripts/blbToolTip/BLB_ScriptTagger-min.js"></script>

When that file runs, it will scan trough the page for all Bible references and add links to them so that hovering will cause a tooltip to display with the Bible content.

There are five optional attributes that can be used to select which Bible translation to use, and control other features.

Optional Attributes

Attribute  Default Description
vers 'NKJV' What default translation should we display the verses in?
links 'all' What should we do with references that are already links with an <a> tag?
'all' - Point all linked references to the verse on Blue Letter Bible and create the hover-over effect.
'hover' - Leave the reference links alone, but still create the hover-over effect.
'none' - Leave the reference links alone altogether.
hidev false Do you want to hide version tags attached to the references?
neww true When a link in the hover-over is clicked, should it open in a new window?
style 'par' Do you want the verses to show up line-by-line, or in paragraphs?
'line' - Line-by-Line
'par' - Paragraph

Available Translations

ASV American Standard Version
DBY Darby Translation
ESV English Standard Version
HNV Hebrew Names Version
KJV King James Version
NASB New American Standard Bible
NIV New International Version
NKJV New King James Version
NLT New Living Translation
RSV Revised Standard Version
RVR Reina-Valera 1960 Version
VUL Latin Vulgate
WEB Webster's Bible
YLT Young's Literal Translation

Example with Attributes

If you include any attributes, special BlueLetterBible variables will be assigned. For example, if you write:

       <blbtagger vers="KJV" style="line" neww="true" />

This will be added to the <head>...</head> section:

       <script type="text/javascript" src="http://www.blueletterbible.org/scripts/blbToolTip/BLB_ScriptTagger-min.js"></script>
       <script type="text/javascript">
               BLB.Tagger.Translation="KJV";
               BLB.Tagger.Style="line";
               BLB.Tagger.TargetNewWindow=true;
       </script>

Source Code for the extension

To get the source code, either download the zipped file, or

  1. Double-click anywhere on the source code below (which will select all the code)
  2. Copy and paste into a new file named BlueLetterBibleTagger.php

<?php
/**
 *     BlueLetterBibleTagger
 *
 * @author Bob Sander-Cederlof bobsc5@verizon.net
 * @copyright Copyright © 2012, Bob Sander-Cederlof
 *
 * This extension adds BlueLetterBible's tagger.
 * http://www.blueletterbible.org/freeoffer/BLB_ScriptTagger/
 *
 * Installation:
 *     1. Copy this file to your Mediawiki extensions folder at
 *             extensions/BlueLetterBibleTagger/BlueLetterBibleTagger.php
 *     2. Add the following line at the end of your Localsettings.php
 *             require_once("extensions/BlueLetterBibleTagger/BlueLetterBibleTagger.php");
 *
 * Usage:
 *     On any page with scripture references, anywhere on the page, add this:
 *             <blbtagger />
 *     This will cause the following line to be added between <head> and </head>:
 *             <script type="text/javascript" src="http://www.blueletterbible.org/scripts/blbToolTip/BLB_ScriptTagger-min.js"></script> 
 *     When that file runs, it will scan trough the page for all Bible references and add links
 *     to them so that hovering will cause a tooltip to display with the Bible content.
 *
 *     There are five optional attributes that can be used to select which Bible translation
 *     to use, and control other features.
 *
 * Attribute   Default Description
 * vers                'NKJV'  What default translation should we display the verses in?
 * links               'all'   What should we do with references that are already links with an <a> tag?
 *                                             'all' - Point all linked references to the verse on Blue Letter Bible and create the hover-over effect.
 *                                             'hover' - Leave the reference links alone, but still create the hover-over effect.
 *                                             'none' - Leave the reference links alone altogether.
 * hidev               false   Do you want to hide version tags attached to the references?
 * neww                        true    When a link in the hover-over is clicked, should it open in a new window?
 * style               'par'   Do you want the verses to show up line-by-line, or in paragraphs?
 *                                             'line' - Line-by-Line
 *                                             'par' - Paragraph
 *
 *     Available Translations
 * ASV American Standard Version
 * DBY Darby Translation
 * ESV English Standard Version
 * HNV Hebrew Names Version
 * KJV King James Version
 * NASB        New American Standard Bible
 * NIV New International Version
 * NKJV        New King James Version
 * NLT New Living Translation
 * RSV Revised Standard Version
 * RVR Reina-Valera 1960 Version
 * VUL Latin Vulgate
 * WEB Webster's Bible
 * YLT Young's Literal Translation
 *
 *     If you include any attributes, special BlueLetterBible variables will be assigned.
 *     For example, if you write:
 *             <blbtagger vers="KJV" style="line" neww="true" />
 *     This will be added to the <head>...</head> section 
 *     after the line loading BLB_ScriptTagger-min.js:
 *             <script type="text/javascript">
 *                     BLB.Tagger.Translation="KJV";
 *                     BLB.Tagger.Style="line";
 *                     BLB.Tagger.TargetNewWindow=true;
 *             </script>
 *
 *     For a full description of what the BLB Tagger can do, see
 *             http://www.blueletterbible.org/freeoffer/BLB_ScriptTagger/
 */

if( !defined( 'MEDIAWIKI' ) ) {
       echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
       die(-1);
}

// adding hook
$wgHooks['ParserFirstCallInit'][] = 'wfBlueLetterBibleTaggerParserInit';

$wgExtensionCredits['parserhook']['BlueLetterBibleTagger'] = array(
       'path'          => __FILE__,
       'name'          => 'BlueLetterBibleTagger',
       'description'   => 'installs BlueLetterBible Tagger on the current page.',
       'version'       => '1.0',
       'author'        => 'Bob Sander-Cederlof'
);

$wgBlueLetterBibleTaggerOnce = 0;

// ParserFirstCallInit hook callback
function wfBlueLetterBibleTaggerParserInit(Parser &$parser) {
       global $wgBlueLetterBibleTaggerOnce;
       $wgBlueLetterBibleTaggerOnce = 0;
       $parser->setHook('blbtagger', 'wfBlueLetterBibleTaggerRender');
       return true;
}

function wfBlueLetterBibleTaggerRender($input, $args, $parser, $frame) {
       global $wgBlueLetterBibleTaggerOnce;
       
               $bibParms = '';
       // only process the first one of these tags we find, ignore all the rest.
       if ($wgBlueLetterBibleTaggerOnce == 0) {
               $parmXlate = array(
               'vers'  => 'Translation',            // NKJV, NLT, NIV, ESV, RVR, NASB, KJV, ASV, 
                                                                               // DBY, HNV, WEB, YLT, RSV, VUL
               'links' => 'HyperLinks',             // all, hover, none
               'hidev' => 'HideVersions',           // true, false
               'neww'  => 'TargetNewWindow',        // false, true
               'style' => 'Style'                           // par, line
               );
               // Start with just loading BLB_ScriptTagger-min.js 
               $parser->getOutput()->addHeadItem( 
                       PHP_EOL.'<!-- Blue Letter Bible Tagger -->' .
                       PHP_EOL.'<script type="text/javascript"' .
                       ' src="http://www.blueletterbible.org/scripts/blbToolTip/BLB_ScriptTagger-min.js"></script>'.PHP_EOL
               );

               // if any args, then add them
               $bibParms = '';
               foreach ($parmXlate as $key => $value) {
                       $parm = getValidBLBParm($key, $args);   // if not there or not valid, returns ''
                       if (strlen($parm)) {
                               $blbParms = $blbParms . '       BLB.Tagger.' . $value . ' = ' . $parm . ';'.PHP_EOL;
                       }
               }
               if ($blbParms != '') {
                       $parser->getOutput()->addHeadItem( '<script type="text/javascript">'.PHP_EOL . $blbParms . '</script>'.PHP_EOL );
               }
       
               $wgBlueLetterBibleTaggerOnce = 1;
       }
       return '<!-- Blue Letter Bible Tagger installed -->';
}

// for security, be sure these are valid strings
function getValidBLBParm( $key, array $args)
{
       $outParm = '';  // return '' is no valid value for given key
       
       $validParms = array(
               'vers'  => ' NKJV NLT NIV ESV RVR NASB KJV ASV DBY HNV WEB YLT RSV VUL ',
               'links' => ' all hover none ',
               'hidev' => ' true false ',
               'neww'  => ' false true ',
               'style' => ' par line '
       );      
       
       // if user provided this key, the validate it.
       if( isset( $args[$key] ) && $args[$key] ) {
               $rawparm = trim($args[$key]);   // just in case, trim whitespace
               // search with space at both ends so we don't match just part of a valid value
               $possibles = $validParms[$key];
               if (strstr($possibles, ' '.$rawparm.' ')) {
                       if ($rawparm != 'true' && $rawparm != 'false') {
                               $outParm = '"'.$rawparm.'"';
                       } else {
                               $outParm = $rawparm;
                       }
               }
       }
       return $outParm;
}