Using the M'Cheyne daily Bible reading server

Introduction

In order to make it easier for other sites to incorporate the M'Cheyne daily Bible readings into their own pages I have created the M'Cheyne server. The source code is available, and you can see the raw output. The server can make URLs linking to any of eight different Bible versions; it can deliver readings based on either the Classic or the Carson variants of the calendar; and it even understands timezones.

When you access the URL of the server it delivers up that day's readings in a form that is easily interpreted by a PHP or Perl script. I have written a PHP class that can be used to interrogate the server and interpret the data which is described below.

You are free to use either the class or the M'Cheyne data server directly on the condition that you include on any web page that uses the data from the server a readable acknowledgement similar to one of the following (at your option),

I'd be glad to help get this up and running for you, so feel free to contact me me. And please drop me a line if you do use the data on your web page. Have a look at my M'Cheyne page for more information about Robert Murray M'Cheyne's daily Bible reading plan.

Usage instructions

To use the server to include the M'Cheyne readings in your own webpages you first need to make sure that your webserver is able to run PHP. The page in which you want to include the readings should be given an extension ".php" rather than ".html" or ".htm". I will refer to it as mcheyne.php for convenience. In the following everything between <?php and ?> markers is PHP script. It can be freely interspersed with HTML.

First copy the server access class, data.inc and save it on your own server.

Next insert the following code into your mcheyne.php page somewhere near the top.

<?php
include "data.inc";
$mc = new McheyneData('niv', 'classic', 0);
?>

The McheyneData constructor takes four parameters, all of which are optional.

  1. The Bible version for the generated links. See the interactive calendar for options. It should be lowercase. If omitted 'niv' is assumed.
  2. The calendar version, either 'classic' or 'carson', again lowercase. If omitted 'classic' is assumed.
  3. Your timezone relative to GMT, from -12 to +12. If omitted the timezone is GMT, and the readings will change at midnight GMT, which may be quite different from your local midnight.
  4. The day number from 0 to 364. If it is omitted today's readings are delivered, taking the timezone onto account, otherwise readings for the specified day are returned and timezone is ignored. There are exactly 365 readings specified, so you may have to deal with Feb 29 as a special case in leap years.

When the $mc object is created it will automatically interrogate the M'Cheyne server and set up several variables which you can then use in your web page.

$mc->versionVersion number of the server
$mc->dayDay of the year
$mc->mdayDay of the month
$mc->monthMonth name
$mc->yearThe year
$mc->tzThe timezone
$mc->quoteThe M'Cheyne Bible quote for the month
$mc->calCalendar version
$mc->bibleBible version
$mc->refsArray of Bible references
$mc->urlsArray of URLs pointing to Bible texts

Examples

As an example, I use the following code to show my current readings on my homepage,

<?php
include "data.inc";
$mc = new McheyneData('niv', 'carson', 0);
if ($mc->year % 2) {
    $ref1 = $mc->refs[2];
    $ref2 = $mc->refs[3];
    $url1 = $mc->urls[2];
    $url2 = $mc->urls[3];
} else {
    $ref1 = $mc->refs[0];
    $ref2 = $mc->refs[1];
    $url1 = $mc->urls[0];
    $url2 = $mc->urls[1];
}
echo "<a href=\"$url1\">$ref1</a>, <a href=\"$url2\">$ref2</a>";
?>

Outside the PHP region you can simply insert the data into ordinary HTML like this, for example

<?php
include "data.inc";
$mc = new McheyneData('niv', 'carson', 0);
?>

<h1>
M'Cheyne readings for <?php echo $mc->mday." ".$mc->month." ".$mc->year; ?>
</h1>

<p>These are today's readings,</p>
<ul>
<li><?php echo $mc->refs[0]; ?></li>
<li><?php echo $mc->refs[1]; ?></li>
<li><?php echo $mc->refs[2]; ?></li>
<li><?php echo $mc->refs[3]; ?></li>
</ul>

For a real example of this have a look at the source code for the interactive M'Cheyne calendar.

XML and XSL

In case you are interested in this kind of stuff, the document served up by the M'Cheyne server is a valid and well-formed XML 1.0 document with a suitable DTD. It also includes an XML stylesheet so that, if your browser supports it, the XML document is transformed into viewable HTML on access. Mozilla 1.0, Netscape 7 and Internet Explorer 6 seem to handle this reliably, but Opera doesn't support it. If you point one of these browsers at the server you should see a simple webpage with the data nicely formatted rather than the raw output. See my XML & XSL page for more information.

RSS

Another option for using the readings is to use the M'Cheyne RSS feed. This is certainly a convenient way to access the readings on a day-to-day basis.

SOAP

Currently the M'Cheyne server just uses the HTTP GET protocol and delivers up its own XML. I am contemplating implementing it as a SOAP service so that it can be used as a web service in standard ways. If this would be of interest to you then please drop me a line and I'll look into it a bit further.