public static function read($data) { $database_books = Database_Books::getInstance(); $output = array(); $data = Filter_String::string2array($data); foreach ($data as &$entry) { $entry = trim($entry); $entry = explode("=", $entry); if (count($entry) != 2) { continue; } $book = trim($entry[0]); $book = $database_books->getIdFromEnglish($book); if ($book == 0) { continue; } $abbrev = trim($entry[1]); if ($abbrev == "") { continue; } // Array (book => abbrev) does not support multiple abbreviations for one book, // but array (abbrev => book) does. $output[$abbrev] = intval($book); } return $output; }
$checks_sentences = new Checks_Sentences(); $checks_sentences->enterCapitals($database_config_bible->getSentenceStructureCapitals($bible)); $checks_sentences->enterSmallLetters($database_config_bible->getSentenceStructureSmallLetters($bible)); $end_marks = $database_config_bible->getSentenceStructureEndPunctuation($bible); $checks_sentences->enterEndMarks($end_marks); $center_marks = $database_config_bible->getSentenceStructureMiddlePunctuation($bible); $checks_sentences->enterCenterMarks($center_marks); $checks_sentences->enterDisregards($database_config_bible->getSentenceStructureDisregards($bible)); $checks_sentences->enterNames($database_config_bible->getSentenceStructureNames($bible)); $check_versification = $database_config_bible->getCheckChaptesVersesVersification($bible); $check_well_formed_usfm = $database_config_bible->getCheckWellFormedUsfm($bible); $checks_usfm = new Checks_Usfm($bible); $check_missing_punctuation_end_verse = $database_config_bible->getCheckMissingPunctuationEndVerse($bible); $check_patterns = $database_config_bible->getCheckPatterns($bible); $checking_patterns = $database_config_bible->getCheckingPatterns($bible); $checking_patterns = Filter_String::string2array($checking_patterns); $checking_patterns = array_filter($checking_patterns, 'strlen'); $books = $database_bibles->getBooks($bible); if ($check_versification) { Checks_Versification::books($bible, $books); } foreach ($books as $book) { $chapters = $database_bibles->getChapters($bible, $book); if ($check_versification) { Checks_Versification::chapters($bible, $book, $chapters); } foreach ($chapters as $chapter) { $chapterUsfm = $database_bibles->getChapter($bible, $book, $chapter); $verses = Filter_Usfm::getVerseNumbers($chapterUsfm); if ($check_versification) { Checks_Versification::verses($bible, $book, $chapter, $verses);
if ($currentbook) { $ipc_focus = Ipc_Focus::getInstance(); $book = $ipc_focus->getBook(); $bookhits = array(); foreach ($hits as $hit) { $details = $database_search->getBiblePassage($hit); if ($book == $details['book']) { $bookhits[] = $hit; } } $hits = $bookhits; } // Deal with how to share the results. if ($sharing != "load") { $loadedHits = $database_volatile->getValue($identifier, "hits"); $loadedHits = Filter_String::string2array($loadedHits); if ($sharing == "add") { $hits = array_merge($loadedHits, $hits); } if ($sharing == "remove") { $hits = array_diff($loadedHits, $hits); } if ($sharing == "intersect") { $hits = array_intersect($loadedHits, $hits); } $hits = array_unique($hits); } // Generate one string from the hits. $output = ""; foreach ($hits as $hit) { $output .= "{$hit}\n";
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; }
public function testReverse() { $this->assertEquals("drow", Filter_String::reverse("word")); $this->assertEquals("ῦοσ ὰτεμ", Filter_String::reverse("μετὰ σοῦ")); }
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;"); }