*/
function votd_hcsb_heading ( ) {
global $votd;
echo $votd->getHeading ( );
}
/**
* WordPress Template Tag for inserting the text, reference, copyright
* information, and credits.
*
* Usage:
*/
function votd_hcsb_the_rest ( ) {
global $votd;
echo $votd->getText ( ) . '
— ' . $votd->getLinkedReference ( )
. '
' . $votd->getFooter ( );
}
/**
* WordPress Template Tag for inserting the just the text of the verse(s).
*
* Usage:
*/
function votd_hcsb_text ( ) {
global $votd;
echo $votd->getText ( );
}
/**
* WordPress Template Tag for inserting the reference in plain text.
*
* Usage:
*/
function votd_hcsb_reference ( ) {
global $votd;
echo $votd->getReference ( );
}
/**
* WordPress Template Tag for inserting the reference with a link to it on
* BibleGateway.com and HCSB copyright information.
*
* Usage:
*/
function votd_hcsb_linked_reference ( ) {
global $votd;
echo $votd->getLinkedReference ( );
}
/**
* WordPress Template Tag for inserting the footer with a link and credits
* for BibleGateway.com.
*
* Usage:
*/
function votd_hcsb_footer ( ) {
global $votd;
echo $votd->getFooter ( );
}
// Constants for options stored in the WordPress database.
define ( 'VOTD_DATE', 'votd_hcsb.current_date' );
define ( 'VOTD_HEAD', 'votd_hcsb.heading' );
define ( 'VOTD_TEXT', 'votd_hcsb.text' );
define ( 'VOTD_REF', 'votd_hcsb.reference' );
define ( 'VOTD_FOOT', 'votd_hcsb.footer' );
/**
* This class contains the guts of this plug-in. The only reason that the
* methods in this class are not private is for PHP4 compatibility. Use the
* template tags or the "get" methods only - all others may change completely
* in future revisions of this class.
*/
class VOTD_HCSB {
// Class variables (AKA properties).
var $heading = '';
var $text = '';
var $reference = '';
var $footer = '';
/**
* VerseHCSB Constructor.
*
* @return A VOTD_HCSB object with the reference text ready for display.
*/
function VOTD_HCSB ( ) {
// Determine if we've already obtained today's date.
$sDate = get_option ( VOTD_DATE );
if ( $sDate == '' ) {
// New installation - add the options
add_option ( VOTD_DATE, '', 'The last date the Verse of the Day was obtained', 'no' );
add_option ( VOTD_HEAD, '', 'The heading for the current Verse of the Day', 'no' );
add_option ( VOTD_TEXT, '', 'The text of the current Verse of the Day.', 'no' );
add_option ( VOTD_REF, '', 'The reference of the current Verse of the Day.', 'no' );
add_option ( VOTD_FOOT, '', 'The footer for the current Verse of the Day.', 'no' );
}
if ( $sDate != date ( 'Y-m-d' ) ) {
// Obtain the next day's verse of the day.
$this->obtainNewVerse ( );
update_option ( VOTD_DATE, date ( 'Y-m-d' ) );
} else {
// Populate the object from the WordPress database.
$this->heading = get_option ( VOTD_HEAD );
$this->text = get_option ( VOTD_TEXT );
$this->reference = get_option ( VOTD_REF );
$this->footer = get_option ( VOTD_FOOT );
}
}
/**
* Get the heading.
*
* @return string The heading - "Verse(s)/Passage of the Day".
*/
function getHeading ( ) {
return $this->heading;
}
/**
* Get the text of the verse(s).
*
* @return string The text of the verse(s).
*/
function getText ( ) {
return $this->text;
}
/**
* Get the reference of the verse(s).
*
* @return string The reference of the verse(s).
*/
function getReference ( ) {
return $this->reference;
}
/**
* Get the reference of the verse(s), with the reference linked to the
* verse(s) on BibleGateway.com and HCSB copyright information.
*
* @return string The reference link and HCSB copyright information.
*/
function getLinkedReference ( ) {
return 'reference ) . ';&version=77;"'
. ' title="View ' . $this->reference . ' at BibleGateway.com">'
. $this->reference . ' HCSB (© info)';
}
/**
* Get the footer, with credits and a link to BibleGateway.com.
*
* @return string The footer.
*/
function getFooter ( ) {
return $this->footer;
}
//--------------------------------------------------------------
////////// METHODS BELOW SHOULD BE CONSIDERED PRIVATE \\\\\\\\\\
//--------------------------------------------------------------
/**
* Obtain New Verse.
*
* Obtain the verse reference from BibleGateway.com's Verse of the Day
* service, then obtain the text from their regular user interface. Then,
* update the WordPress database so future displays will be quicker.
*/
function obtainNewVerse ( ) {
// Use RSS to get the reference from BibleGateway.com.
require_once ( ABSPATH . WPINC . '/rss-functions.php' );
$rss = @fetch_rss ( 'http://www.biblegateway.com/usage/votd/rss/votd.rdf?9' );
if ( ( isset ( $rss->items ) ) && ( 0 != count ( $rss->items ) ) ) {
$this->formatVerse($rss->items[0]['title']);
}
// Store the header and footer.
$sHeader = '';
$sFooter = '';
if ( strpos ( $this->reference, "-" ) ) {
$sHeader = $sFooter = 'Passage';
$sFooter .= ' Reference';
} else {
$sHeader = $sFooter = 'Verse';
if ( strpos ( $this->reference, ',' ) ) {
$sHeader .= 's';
$sFooter .= ' References';
} else {
$sFooter .= ' Reference';
}
}
$sHeader .= ' of the Day';
$sFooter .= ' Provided by BibleGateway.com';
update_option ( VOTD_HEAD, $sHeader );
$this->heading = $sHeader;
update_option ( VOTD_FOOT, $sFooter );
$this->footer = $sFooter;
}
/**
* Format the Verse(s).
*
* Get the text from the BibleGateway.com website, and reformat it.
*
* @param string $sReference The reference to look up.
*/
function formatVerse ( $sReference ) {
// Set the reference that we were passed.
update_option ( VOTD_REF, $sReference );
$this->reference = $sReference;
// Accrue the text in this variable.
$sText = '';
// Retrieve the page from BibleGateway.com as an array.
$sPage = file ( 'http://www.biblegateway.com/passage/?search='
. str_replace ( ' ', '+', $sReference ) . ';&version=77;' );
if ( strpos ( $sReference, ',' ) ) {
/** Multiple non-contiguous verse */
// Find the table with the output.
for ( $iKey = 0; $iKey < count ( $sPage ); $iKey++ ) {
$sLine = $sPage[$iKey];
if ( strpos ( $sLine, 'View commentary' ) ) {
// The next line is the actual text.
$sLine = $sPage[++$iKey];
// Fix the text.
if ( $sText > '' ) {
$sText .= ' ';
}
$sText .= $this->reformatText ( $sLine );
}
if ( strpos ( $sLine, '' ) ) {
// Remove the extra space.
$sText = substr ( $sText, 0, strlen ( $sText ) - 1 );
break;
}
}
} else {
/** Single verse or continguous passage */
// Find the line with the text.
foreach ( $sPage as $iKey => $sLine ) {
if ( strpos ( $sLine, 'result-text-style-normal') ) {
break;
}
}
// The next line is the actual text.
$sLine = $sPage[++$iKey];
$sText = $this->reformatText ( $sLine );
}
// Put nice quotes around the whole thing.
$sText = '“' . $sText . '”';
// Store this in the WordPress database.
update_option ( VOTD_TEXT, $sText );
$this->text = $sText;
}
/**
* Reformat web page to normal text.
*
* This will take the web page returned by the HTML get, and remove
* footnote/cross-reference links, It will also remove other HTML tags,
* while preserving the small-caps "Lord" found in the Old Testament.
* Finally, it will strip out the reference, as the passage has the book
* and chapter number in it if it's the first verse in a chapter.
*
* @param string $sText The text line with the verse/passage to reformat.
* @return string The properly formatted text.
*/
function reformatText ( $sText ) {
$sLine = $sText;
// Mask off footnotes and cross-references.
$sXref = 'Cross references:';
$sFoot = 'Footnotes:';
if ( ( strpos ( $sLine, $sXref ) ) && ( strpos ( $sLine, $sFoot ) ) ) {
if ( strpos ( $sLine, $sFoot ) > strpos ( $sLine, $sXref ) ) {
$sLine = substr ( $sLine, 0, strpos ( $sLine, $sXref ) );
} else {
$sLine = substr ( $sLine, 0, strpos ( $sLine, $sFoot) );
}
} elseif ( strpos ( $sLine, $sXref ) ) {
$sLine = substr ( $sLine, 0, strpos ( $sLine, $sXref ) );
} elseif ( strpos ( $sLine, $sFoot ) ) {
$sLine = substr ( $sLine, 0, strpos ( $sLine, $sFoot ) );
}
// Save off all capital lettered LORD.
$sLine = str_replace (
'LORD', 'LORD',
$sLine );
// Get rid of some tags including their contents (strip tags won't do that).
$sTags = array ( 'sup', 'span', 'h5' );
foreach ( $sTags as $sTag ) {
while ( strpos ( $sLine, "<{$sTag}" ) ) {
$sWorkLine = $sLine;
$iStart = strpos ( $sLine, "<{$sTag}" );
$iEnd = strpos ( $sLine, "{$sTag}>" ) + strlen ( $sTag ) + 3;
$sLine = substr ( $sWorkLine, 0, $iStart )
. substr ( $sWorkLine, $iEnd );
}
}
// Eliminate tags and non-breaking spaces
$sLine = trim ( str_replace ( ' ', '', strip_tags ( $sLine ) ) );
// Eliminate quotes if they're the first or last character in the text
if ( substr ( $sLine, 0, 1 ) == '"' ) {
$sLine = substr ( $sLine, 1 );
}
if ( substr ( $sLine, -1 ) == '"') {
$sLine = substr ( $sLine, 0, strlen($sLine) - 1 );
}
// Put special formatting back for all-caps LORD
$sLine = str_replace (
'LORD', 'Lord',
$sLine );
// Replace the book and chapter if it's found in the passage, and
// eliminate extra spaces
$sLine = trim ( str_replace (
substr ( $this->reference, 0, strpos ( $this->reference, ':' ) ),
'', $sLine ) );
// Return the finished product
return $sLine;
}
}
?>