<?php

/*
 * This PHP class provides easy access to the Murray M'Cheyne daily
 * Bible reading data server at http://www.edginet.org/
 *
 * Usage instructions are at http://www.edginet.org/mcheyne/server.html
 *
 * You are free to use either this class or the M'Cheyne data server
 * directly subject to the following two conditions.
 *
 * (1) You must include on any web page that uses the data from the
 *     server a readable acknowledgement similar to one of the
 *     following at your option:
 *
 *       "M'Cheyne daily Bible readings provided by www.edginet.org"
 *
 *     or
 *
 *       "The Interactive M'Cheyne Bible Calendar is at
 *        www.edginet.org/mcheyne/calendar.php"
 *
 *     where the URLs are hyperlinks with the corresponding targets.
 *
 * (2) You must preserve this notice and the copyright notice below on
 *     any versions of this code that you alter or redistribute in any
 *     way.
 *
 * Copyright, (c) 2003 Ben Edgington.
 *
 */

class McheyneData
{

    var $version, $day, $mday, $month, $year, $tz, $cal, $bible, $quote;
    var $refs, $urls;

    function McheyneData($bible = 'niv', $cal = 'classic', $tz = NULL, $day = NULL) {

        $query = "bible=$bible&cal=$cal";
        if (isset($tz)) {
            $query .= "&tz=$tz";
        }
        if (isset($day)) {
            $query .= "&day=$day";
        }
        $query .= "&ref=".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];

        $file = 'http://www.edginet.org/mcheyne/server.php';

        $contents = implode('',file("$file?$query"));

        $ver_arr   = $this->_scan( $contents, 'version');
        $day_arr   = $this->_scan( $contents, 'day');
        $mday_arr  = $this->_scan( $contents, 'mday');
        $month_arr = $this->_scan( $contents, 'month');
        $year_arr  = $this->_scan( $contents, 'year');
        $tz_arr    = $this->_scan( $contents, 'timezone');
        $quote_arr = $this->_scan( $contents, 'quote');
        $cal_arr   = $this->_scan( $contents, 'calendar');
        $bible_arr = $this->_scan( $contents, 'bible');
        $ref_arr   = $this->_scan( $contents, 'reference');
        $url_arr   = $this->_scan( $contents, 'url');

        $this->version = $ver_arr[1][0];
        $this->day     = $day_arr[1][0];
        $this->mday    = $mday_arr[1][0];
        $this->month   = $month_arr[1][0];
        $this->year    = $year_arr[1][0];
        $this->tz      = $tz_arr[1][0];
        $this->quote   = $quote_arr[1][0];
        $this->cal     = $cal_arr[1][0];
        $this->bible   = $bible_arr[1][0];
        $this->refs    = $ref_arr[1];
        $this->urls    = $url_arr[1];

    }

    function _scan( $string, $tag) {

        preg_match_all ("/<$tag>(.*)<\/$tag>/isU", $string, $arr);
        return $arr;

    }

}

?>