示例#1
0
 public function response()
 {
     // The databases to access.
     $database_config_user = Database_Config_User::getInstance();
     $database_volatile = Database_Volatile::getInstance();
     $database_bibles = Database_Bibles::getInstance();
     // The resources to display in the Consistency tool.
     $resources = array();
     $resources[] = Access_Bible::clamp($database_config_user->getBible());
     $resources = array_merge($resources, $database_config_user->getConsistencyResources());
     // The passages entered in the Consistency tool.
     $passages = $database_volatile->getValue($this->id, "passages");
     $passages = trim($passages);
     $passages = Filter_String::string2array($passages);
     // The translations from the Consistency tool.
     $translations = $database_volatile->getValue($this->id, "translations");
     $translations = trim($translations);
     $translations = Filter_String::string2array($translations);
     // Contains the response to display.
     $response = array();
     // Go through the passages interpreting them.
     $previousPassage = array(1, 1, 1);
     foreach ($passages as $line) {
         $line = trim($line);
         if ($line == "") {
             continue;
         }
         $range_sequence = Filter_Books::handleSequencesRanges($line);
         foreach ($range_sequence as $line) {
             $passage = Filter_Books::interpretPassage($previousPassage, $line);
             if ($passage[0] != 0) {
                 $book = $passage[0];
                 $chapter = $passage[1];
                 $verse = $passage[2];
                 $line = Filter_Books::linkForOpeningEditorAt($book, $chapter, $verse);
                 $line .= " ";
                 // Check whether the chapter identifier has changed for this reference.
                 // If so, set a flag so the data can be re-assembled for this verse.
                 // If there was no change, then the data can be fetched from the volatile database.
                 $redoPassage = false;
                 $passageKey = "{$book}.{$chapter}.{$verse}";
                 $currentChapterId = $database_bibles->getChapterId($resources[0], $book, $chapter);
                 $storedChapterId = $database_volatile->getValue($this->id, "{$passageKey}.id");
                 if ($currentChapterId != $storedChapterId) {
                     $database_volatile->setValue($this->id, "{$passageKey}.id", $currentChapterId);
                     $redoPassage = true;
                 }
                 // Go through each resource.
                 foreach ($resources as $resource) {
                     // Produce new verse text if the passage is to be redone, or else fetch the existing text.
                     if ($redoPassage) {
                         $text = $this->verseText($resource, $book, $chapter, $verse);
                         if ($translations != "") {
                             $text = Filter_Markup::words($translations, $text);
                         }
                         $database_volatile->setValue($this->id, "{$passageKey}.{$resource}", $text);
                     } else {
                         $text = $database_volatile->getValue($this->id, "{$passageKey}.{$resource}");
                     }
                     // Formatting.
                     if (count($resources) > 1) {
                         $line .= "<br>";
                     }
                     $line .= $text;
                 }
                 $response[] = $line;
                 $previousPassage = $passage;
             } else {
                 $response[] = '<span class="error">' . Locale_Translate::_("Unknown passage") . " " . $line . '</span>';
             }
         }
     }
     $output = "";
     foreach ($response as $line) {
         $output .= "<div>{$line}</div>\n";
     }
     return $output;
 }
示例#2
0
 public static function setPassage($bible, $passage)
 {
     $ipc_focus = Ipc_Focus::getInstance();
     $currentBook = $ipc_focus->getBook();
     $currentChapter = $ipc_focus->getChapter();
     $currentVerse = $ipc_focus->getVerse();
     $passage = trim($passage);
     if ($passage == "" || $passage == "+") {
         $passage = Navigation_Passage::getNextVerse($bible, $currentBook, $currentChapter, $currentVerse);
     } else {
         if ($passage == "-") {
             $passage = Navigation_Passage::getPreviousVerse($bible, $currentBook, $currentChapter, $currentVerse);
         } else {
             $passage = Filter_Books::interpretPassage(array($currentBook, $currentChapter, $currentVerse), $passage);
         }
     }
     if ($passage[0] != 0) {
         $ipc_focus->set($passage[0], $passage[1], $passage[2]);
         Navigation_Passage::recordHistory($passage[0], $passage[1], $passage[2]);
     }
 }
示例#3
0
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::CONSULTANT_LEVEL);
$database_notes = Database_Notes::getInstance();
$notes_logic = Notes_Logic::getInstance();
$id = $_GET['id'];
if (isset($_POST['submit'])) {
    $verses = explode("\n", $_POST['verses']);
    $passages = array();
    $previousPassage = array(1, 1, 1);
    foreach ($verses as $line) {
        $line = trim($line);
        if ($line != "") {
            $passage = Filter_Books::interpretPassage($previousPassage, $line);
            if ($passage[0] != 0) {
                $passages[] = $passage;
                $previousPassage = $passage;
            }
        }
    }
    $notes_logic->setPassages($id, $passages);
    Filter_Url::redirect("actions.php?id={$id}");
    die;
}
$assets_header = new Assets_Header(Locale_Translate::_("Note passages"));
$assets_header->run();
$view = new Assets_View(__FILE__);
$view->view->id = $id;
$verses = Filter_Books::passagesDisplayMultiline($database_notes->getPassages($id));
示例#4
0
 public function testInterpretPassage()
 {
     $currentPassage = array(2, 4, 6);
     $standard = array(1, 2, 3);
     $output = Filter_Books::interpretPassage($currentPassage, " Genesis 2 3");
     $this->assertEquals($standard, $output);
     $standard = array(46, 2, 3);
     $output = Filter_Books::interpretPassage($currentPassage, "1  Corinthians 2:3");
     $this->assertEquals($standard, $output);
     $standard = array(22, 2, 3);
     $output = Filter_Books::interpretPassage($currentPassage, "Song of Solomon 2.3");
     $this->assertEquals($standard, $output);
     $standard = $currentPassage;
     $output = Filter_Books::interpretPassage($currentPassage, "");
     $this->assertEquals($standard, $output);
     $standard = array(0, 1, 1);
     $output = Filter_Books::interpretPassage($currentPassage, "Genesis Exodus");
     $this->assertEquals($standard, $output);
     $standard = array(2, 1, 1);
     $output = Filter_Books::interpretPassage($currentPassage, "Exodus");
     $this->assertEquals($standard, $output);
     $standard = array(2, 4, 11);
     $output = Filter_Books::interpretPassage($currentPassage, "11");
     $this->assertEquals($standard, $output);
     $standard = array(2, 11, 14);
     $output = Filter_Books::interpretPassage($currentPassage, "11 14");
     $this->assertEquals($standard, $output);
     $standard = array(22, 2, 1);
     $output = Filter_Books::interpretPassage($currentPassage, "Song of Solomon 2");
     $this->assertEquals($standard, $output);
 }
示例#5
0
 public function import($name, $data)
 {
     // Delete existing mapping with this name.
     $this->delete($name);
     // Begin a transaction for better speed.
     Database_SQLite::exec($this->db, "BEGIN;");
     $lastPassage = array(1, 1, 1);
     $lastOriginal = array(1, 1, 1);
     $name = Database_SQLiteInjection::no($name);
     $data = Filter_String::string2array($data);
     foreach ($data as $line) {
         // Each line looks like this:
         // Haggai 2:15 = Haggai 2:14
         // At the left is the passage in this versification.
         // At the right is the passage in the original Hebrew and Greek versification.
         $line = trim($line);
         if ($line == "") {
             continue;
         }
         // Cut the line into two: The two passages.
         $entry = explode("=", $line);
         if (count($entry) != 2) {
             continue;
         }
         $passage = trim($entry[0]);
         $original = trim($entry[1]);
         $passage = Filter_Books::interpretPassage($lastPassage, $passage);
         $lastPassage = $passage;
         $original = Filter_Books::interpretPassage($lastOriginal, $original);
         $lastOriginal = $original;
         $book = (int) $passage[0];
         $chapter = (int) $passage[1];
         $verse = (int) $passage[2];
         $origbook = (int) $original[0];
         $origchapter = (int) $original[1];
         $origverse = (int) $original[2];
         $query = "INSERT INTO maps VALUES ('{$name}', {$book}, {$chapter}, {$verse}, {$origbook}, {$origchapter}, {$origverse});";
         Database_SQLite::exec($this->db, $query);
     }
     // Commit the transaction.
     Database_SQLite::exec($this->db, "COMMIT;");
 }