Example #1
0
 /**
  * This filter produces files in USFM, html and text format.
  * The text files are to be used for showing the differences between them.
  * The files contain all verses that differ.
  * $bible: The Bible to go through.
  * $directory: The existing directory where to put the files.
  * Two files are created: verses_old.usfm and verses_new.usfm.
  * The book chapter.verse precede each verse.
  */
 public static function produceVerseLevel($bible, $directory)
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_modifications = Database_Modifications::getInstance();
     $database_books = Database_Books::getInstance();
     $database_config_bible = Database_Config_Bible::getInstance();
     $stylesheet = $database_config_bible->getExportStylesheet($bible);
     $old_vs_usfm = array();
     $new_vs_usfm = array();
     $filter_text_old = new Filter_Text($bible);
     $filter_text_old->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
     $filter_text_old->text_text = new Text_Text();
     $filter_text_new = new Filter_Text($bible);
     $filter_text_new->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
     $filter_text_new->text_text = new Text_Text();
     $books = $database_modifications->getTeamDiffBooks($bible);
     foreach ($books as $book) {
         $bookname = $database_books->getEnglishFromId($book);
         $chapters = $database_modifications->getTeamDiffChapters($bible, $book);
         foreach ($chapters as $chapter) {
             // Go through the combined verse numbers in the old and new chapter.
             $old_chapter_usfm = $database_modifications->getTeamDiff($bible, $book, $chapter);
             $new_chapter_usfm = $database_bibles->getChapter($bible, $book, $chapter);
             $old_verse_numbers = Filter_Usfm::getVerseNumbers($old_chapter_usfm);
             $new_verse_numbers = Filter_Usfm::getVerseNumbers($new_chapter_usfm);
             $verses = array_merge($old_verse_numbers, $new_verse_numbers);
             $verses = array_unique($verses);
             sort($verses, SORT_NUMERIC);
             foreach ($verses as $verse) {
                 $old_verse_text = Filter_Usfm::getVerseText($old_chapter_usfm, $verse);
                 $new_verse_text = Filter_Usfm::getVerseText($new_chapter_usfm, $verse);
                 if ($old_verse_text != $new_verse_text) {
                     $usfmCode = "\\p {$bookname} {$chapter}.{$verse} {$old_verse_text}";
                     $old_vs_usfm[] = $usfmCode;
                     $filter_text_old->addUsfmCode($usfmCode);
                     $usfmCode = "\\p {$bookname} {$chapter}.{$verse} {$new_verse_text}";
                     $new_vs_usfm[] = $usfmCode;
                     $filter_text_new->addUsfmCode($usfmCode);
                 }
             }
         }
     }
     file_put_contents("{$directory}/verses_old.usfm", implode("\n", $old_vs_usfm));
     file_put_contents("{$directory}/verses_new.usfm", implode("\n", $new_vs_usfm));
     $filter_text_old->run($stylesheet);
     $filter_text_new->run($stylesheet);
     $filter_text_old->html_text_standard->save("{$directory}/verses_old.html");
     $filter_text_new->html_text_standard->save("{$directory}/verses_new.html");
     $filter_text_old->text_text->save("{$directory}/verses_old.txt");
     $filter_text_new->text_text->save("{$directory}/verses_new.txt");
 }
Example #2
0
 private function outputAsIs($marker, $isOpeningMarker)
 {
     // Output the marker in monospace font.
     if ($isOpeningMarker) {
         // Add opening marker as it is.
         $this->newParagraph("mono");
         $this->addText(Filter_Usfm::getOpeningUsfm($marker));
     } else {
         // Add closing marker to existing paragraph.
         $this->addText(Filter_Usfm::getClosingUsfm($marker));
     }
 }
Example #3
0
 private static function getPreviousVerse($bible, $book, $chapter, $verse)
 {
     $verse--;
     if ($bible != "") {
         $database_bibles = Database_Bibles::getInstance();
         $verses = Filter_Usfm::getVerseNumbers($database_bibles->getChapter($bible, $book, $chapter));
         if (!in_array($verse, $verses)) {
             $verse = array_shift($verses);
         }
     }
     $passage = array($book, $chapter, $verse);
     return $passage;
 }
Example #4
0
 public static function getText($resource, $book, $chapter, $verse)
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_resources = Database_Resources::getInstance();
     $database_usfmresources = Database_UsfmResources::getInstance();
     $database_offlineresources = Database_OfflineResources::getInstance();
     $bibles = $database_bibles->getBibles();
     $usfms = $database_usfmresources->getResources();
     $externals = $database_resources->getNames();
     $isBible = in_array($resource, $bibles);
     $isUsfm = in_array($resource, $usfms);
     if ($isBible || $isUsfm) {
         if ($isBible) {
             $chapter_usfm = $database_bibles->getChapter($resource, $book, $chapter);
         }
         if ($isUsfm) {
             $chapter_usfm = $database_usfmresources->getUsfm($resource, $book, $chapter);
         }
         $verse_usfm = Filter_Usfm::getVerseText($chapter_usfm, $verse);
         $database_config_user = Database_Config_User::getInstance();
         $stylesheet = $database_config_user->getStylesheet();
         $filter_text = new Filter_Text($resource);
         $filter_text->text_text = new Text_Text();
         $filter_text->addUsfmCode($verse_usfm);
         $filter_text->run($stylesheet);
         $text = $filter_text->text_text->get();
     } else {
         if (in_array($resource, $externals)) {
             // Use offline copy if it exists, else fetch it online.
             if ($database_offlineresources->exists($resource, $book, $chapter, $verse)) {
                 $text = $database_offlineresources->get($resource, $book, $chapter, $verse);
             } else {
                 $text = Resource_Logic::getExternal($resource, $book, $chapter, $verse, true);
             }
             $text = Filter_Html::html2text($text);
         } else {
             $text = "";
         }
     }
     return $text;
 }
Example #5
0
 /**
  * This function adds something to a word list array, prefixed by the current passage.
  * $list: which list to add the text to.
  * The word is extracted from the input USFM. The Usfm pointer points to the current marker,
  * and the text following that marker is added to the word list array.
  */
 private function addToWordList(&$list)
 {
     $text = Filter_Usfm::peekTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
     $text .= " (";
     $text .= $this->getCurrentPassageText();
     $text .= ")";
     $list[] = $text;
 }
Example #6
0
/*
Copyright (©) 2003-2014 Teus Benschop.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
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::TRANSLATOR_LEVEL);
$bible = $_GET['bible'];
$book = $_GET['book'];
$chapter = $_GET['chapter'];
$database_bibles = Database_Bibles::getInstance();
$usfm = $database_bibles->getChapter($bible, $book, $chapter);
$ipc_focus = Ipc_Focus::getInstance();
$verse = $ipc_focus->getVerse();
$startingOffset = Filter_Usfm::verseNumber2offset($usfm, $verse);
$endingOffset = Filter_Usfm::verseNumber2offset($usfm, $verse + 1) - 1;
$data = array('start' => $startingOffset, 'end' => $endingOffset);
echo json_encode($data);
Example #7
0
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
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::TRANSLATOR_LEVEL);
$bible = $_GET['bible'];
$book = $_GET['book'];
$chapter = $_GET['chapter'];
$offset = $_GET['offset'];
$database_bibles = Database_Bibles::getInstance();
$ipc_focus = Ipc_Focus::getInstance();
$usfm = $database_bibles->getChapter($bible, $book, $chapter);
$verse = Filter_Usfm::offset2verseNumber($usfm, $offset);
// Only update navigation in case the verse changed.
// This avoids unnecessary focus operations in the clients.
if ($verse != $ipc_focus->getVerse()) {
    $ipc_focus->set($book, $chapter, $verse);
}
//$startingOffset = Filter_Usfm::verseNumber2offset ($usfm, $verse);
//$endingOffset = Filter_Usfm::verseNumber2offset ($usfm, $verse + 1) - 1;
//$substring = mb_substr ($usfm, 0, $offset);
//$lineNumber = mb_substr_count ($substring, "\n");
//$data = array ('line' => $lineNumber);
//echo json_encode ($data);
Example #8
0
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);
        }
        foreach ($verses as $verse) {
            $verseUsfm = Filter_Usfm::getVerseText($chapterUsfm, $verse);
            if ($check_double_spaces_usfm) {
                Checks_Space::doubleSpaceUsfm($bible, $book, $chapter, $verse, $verseUsfm);
            }
        }
        $filter_text = new Filter_Text($bible);
        $filter_text->initializeHeadingsAndTextPerVerse();
        $filter_text->addUsfmCode($chapterUsfm);
        $filter_text->run($stylesheet);
        $verses_headings = $filter_text->verses_headings;
        $verses_text = $filter_text->getVersesText();
        if ($check_full_stop_in_headings) {
            Checks_Headers::noPunctuationAtEnd($bible, $book, $chapter, $verses_headings, $center_marks, $end_marks);
        }
        if ($check_space_before_punctuation) {
            Checks_Space::spaceBeforePunctuation($bible, $book, $chapter, $verses_text);
Example #9
0
     $absent[] = Locale_Translate::_("Bible/Resource") . " " . $compare . " " . Locale_Translate::_("does not contain") . " {$bookName} {$chapter}.";
     continue;
 }
 $bible_chapter_usfm = $database_bibles->getChapter($bible, $book, $chapter);
 $compare_chapter_usfm = $database_bibles->getChapter($compare, $book, $chapter);
 if ($compare_chapter_usfm == "") {
     $compare_chapter_usfm = $database_usfmresources->getUsfm($compare, $book, $chapter);
 }
 $bible_verse_numbers = Filter_Usfm::getVerseNumbers($bible_chapter_usfm);
 $compare_verse_numbers = Filter_Usfm::getVerseNumbers($compare_chapter_usfm);
 $verses = array_merge($bible_verse_numbers, $compare_verse_numbers);
 $verses = array_unique($verses);
 sort($verses, SORT_NUMERIC);
 foreach ($verses as $verse) {
     $bible_verse_usfm = Filter_Usfm::getVerseText($bible_chapter_usfm, $verse);
     $compare_verse_usfm = Filter_Usfm::getVerseText($compare_chapter_usfm, $verse);
     if ($bible_verse_usfm != $compare_verse_usfm) {
         $filter_text_bible = new Filter_Text($bible);
         $filter_text_compare = new Filter_Text($compare);
         $filter_text_bible->html_text_standard = new Html_Text("");
         $filter_text_compare->html_text_standard = new Html_Text("");
         $filter_text_bible->text_text = new Text_Text();
         $filter_text_compare->text_text = new Text_Text();
         $filter_text_bible->addUsfmCode($bible_verse_usfm);
         $filter_text_compare->addUsfmCode($compare_verse_usfm);
         $filter_text_bible->run($stylesheet);
         $filter_text_compare->run($stylesheet);
         $bible_html = $filter_text_bible->html_text_standard->getInnerHtml();
         $compare_html = $filter_text_compare->html_text_standard->getInnerHtml();
         $bible_text = $filter_text_bible->text_text->get();
         $compare_text = $filter_text_compare->text_text->get();
Example #10
0
        if ($xref['verse'] == $verse) {
            $xrefs[] = array($xref['offset'], $xref['text']);
        }
    }
    if (empty($xrefs)) {
        continue;
    }
    // Get the USFM for the current verse in the target Bible, if any.
    if (!isset($usfmArray[$verse])) {
        continue;
    }
    $usfm = $usfmArray[$verse];
    // Get the length of the text of the verse in the source Bible without the xrefs.
    // Get the ratio for positioning the xrefs by comparing the lengths of source and target verse text.
    $sourceUsfm = $database_bibles->getChapter($sourceBible, $book, $chapter);
    $sourceUsfm = Filter_Usfm::getVerseText($sourceUsfm, $verse);
    $sourceUsfm = Filter_Usfm::removeNotes($sourceUsfm, array("x"));
    $sourceLength = mb_strlen($sourceUsfm);
    $targetLength = mb_strlen($usfm);
    $ratio = $targetLength / $sourceLength;
    // Insert the notes.
    $usfm = Filter_Usfm::insertNotes($usfm, $xrefs, $ratio);
    $usfmArray[$verse] = $usfm;
}
$usfm = implode("\n", $usfmArray);
Bible_Logic::storeChapter($targetBible, $book, $chapter, $usfm);
$header = new Assets_Header(Locale_Translate::_("Cross references"));
$header->run();
$view = new Assets_View(__FILE__);
$view->render("insert.php");
Assets_Page::footer();
Example #11
0
 private function addResult($text, $modifier)
 {
     $current = $this->usfmItem;
     $next = Filter_Usfm::peekTextFollowingMarker($this->usfmMarkersAndText, $this->usfmMarkersAndTextPointer);
     $next = substr($next, 0, 20);
     switch ($modifier) {
         case Checks_Usfm::displayNothing:
             break;
         case Checks_Usfm::displayCurrent:
             $text .= ": " . $current;
             break;
         case Checks_Usfm::displayNext:
             $text .= ": " . $next;
             break;
         case Checks_Usfm::displayFull:
             $text .= ": " . $current . $next;
             break;
     }
     $this->checkingResults[] = array((int) $this->verseNumber => $text);
 }
Example #12
0
 public static function peekTextFollowingMarker($usfm, $pointer)
 {
     return Filter_Usfm::getTextFollowingMarker($usfm, $pointer);
 }
Example #13
0
$count = count($identifiers);
$view->view->count = $count;
$summaries = array();
$verse_texts = array();
$contents = array();
foreach ($identifiers as $identifier) {
    $summary = $database_notes->getSummary($identifier);
    $passages = $database_notes->getPassages($identifier);
    $verses = Filter_Books::passagesDisplayInline($passages);
    $summaries[] = $summary . " | " . $verses;
    $verse_text = "";
    if ($passage_inclusion_selector) {
        $passages = $database_notes->getPassages($identifier);
        foreach ($passages as $passage) {
            $usfm = $database_bibles->getChapter($bible, $passage[0], $passage[1]);
            $text = Filter_Usfm::getVerseText($usfm, $passage[2]);
            $verse_text .= $text;
            $verse_text .= "\n";
        }
    }
    $verse_texts[] = nl2br($verse_text);
    $content = "";
    if ($text_inclusion_selector) {
        $content = $database_notes->getContents($identifier);
    }
    $contents[] = $content;
}
$view->view->summaries = $summaries;
$view->view->versetexts = $verse_texts;
$view->view->contents = $contents;
$view->render("notes.php");
Example #14
0
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::TRANSLATOR_LEVEL);
$database_config_user = Database_Config_User::getInstance();
$database_bibles = Database_Bibles::getInstance();
$bible = $database_config_user->getTargetXrefBible();
$book = intval($_GET['book']);
$chapter = intval($_GET['chapter']);
$verse = $_GET['verse'];
$focus = intval($_GET['focus']);
$move = intval($_GET['move']);
$usfmArray = array();
$usfmString = $database_bibles->getChapter($bible, $book, $chapter);
if ($usfmString == "") {
    die;
}
$verses = Filter_Usfm::getVerseNumbers($usfmString);
$verses = array_unique($verses);
foreach ($verses as $vs) {
    $usfmArray[$vs] = Filter_Usfm::getVerseText($usfmString, $vs);
}
$usfm = $usfmArray[$verse];
if ($usfm == "") {
    die;
}
$usfm = Filter_Usfm::moveNote($usfm, $move, $focus);
if ($usfm == "") {
    die;
}
$usfmArray[$verse] = $usfm;
$usfm = implode("\n", $usfmArray);
Bible_Logic::storeChapter($bible, $book, $chapter, $usfm);
Example #15
0
    $standardPlainText = $database_search->getBibleVerseText($bible, $book, $chapter, $verse);
    if ($casesensitive) {
        $standardPlainText = str_replace($searchfor, $replacewith, $standardPlainText, $standardReplacementCount);
    } else {
        $needles = Filter_Search::needles($searchfor, $standardPlainText);
        $standardPlainText = str_replace($needles, $replacewith, $standardPlainText, $standardReplacementCount);
    }
}
// Get the old USFM into an array of verse => USFM fragment.
$usfmArray = array();
$usfmString = $database_bibles->getChapter($bible, $book, $chapter);
$verses = Filter_Usfm::getVerseNumbers($usfmString);
$verses = array_unique($verses);
sort($verses, SORT_NUMERIC);
foreach ($verses as $vs) {
    $usfmArray[$vs] = Filter_Usfm::getVerseText($usfmString, $vs);
}
// Do the replacing in the correct verse of the raw USFM, and count how many replacements were made.
$usfm = $usfmArray[$verse];
$usfmReplacementCount = 0;
if ($casesensitive) {
    $usfm = str_replace($searchfor, $replacewith, $usfm, $usfmReplacementCount);
} else {
    $needles = Filter_Search::needles($searchfor, $usfm);
    $usfm = str_replace($needles, $replacewith, $usfm, $usfmReplacementCount);
}
$usfmArray[$verse] = $usfm;
// Create the updated chapter USFM as a string.
$updatedUsfm = implode("\n", $usfmArray);
// Text filter for getting the new plain text from the new USFM.
// This is for search/replace in plain text, not in USFM.
Example #16
0
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::TRANSLATOR_LEVEL);
$database_config_user = Database_Config_User::getInstance();
$database_bibles = Database_Bibles::getInstance();
$ipc_focus = Ipc_Focus::getInstance();
$bible = $database_config_user->getTargetXrefBible();
$book = $ipc_focus->getBook();
$chapter = $ipc_focus->getChapter();
$usfm = $database_bibles->getChapter($bible, $book, $chapter);
if (isset($_GET['overwrite'])) {
    $usfm = Filter_Usfm::removeNotes($usfm, array("x"));
    Bible_Logic::storeChapter($bible, $book, $chapter, $usfm);
}
// Count the cross references in this chapter.
$xrefs = Filter_Usfm::extractNotes($usfm, array("x"));
// Count the number of xref openers / closers in this chapter.
$opener = Filter_Usfm::getOpeningUsfm("x");
str_replace($opener, "", $usfm, $openers);
$closer = Filter_Usfm::getClosingUsfm("x");
str_replace($closer, "", $usfm, $closers);
if (empty($xrefs)) {
    Filter_Url::redirect("insert.php");
    die;
}
$header = new Assets_Header(Locale_Translate::_("Cross references"));
$header->run();
$view = new Assets_View(__FILE__);
$view->view->count = count($xrefs);
$view->view->tags = $openers - $closers;
$view->render("clear.php");
Assets_Page::footer();
Example #17
0
function processIdentifiers($user, $bible, $book, $chapter, $oldId, $newId, &$email)
{
    if ($oldId != 0) {
        $database_modifications = Database_Modifications::getInstance();
        $database_config_user = Database_Config_User::getInstance();
        $database_config_bible = Database_Config_Bible::getInstance();
        $database_bibles = Database_Bibles::getInstance();
        $database_history = Database_History::getInstance();
        $stylesheet = $database_config_bible->getExportStylesheet($bible);
        $old_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $oldId);
        $old_chapter_usfm = $old_chapter_usfm['oldtext'];
        $new_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $newId);
        $new_chapter_usfm = $new_chapter_usfm['newtext'];
        $timestamp = $database_modifications->getUserTimestamp($user, $bible, $book, $chapter, $newId);
        $old_verse_numbers = Filter_Usfm::getVerseNumbers($old_chapter_usfm);
        $new_verse_numbers = Filter_Usfm::getVerseNumbers($new_chapter_usfm);
        $verses = array_merge($old_verse_numbers, $new_verse_numbers);
        $verses = array_unique($verses);
        sort($verses, SORT_NUMERIC);
        foreach ($verses as $verse) {
            $old_verse_usfm = Filter_Usfm::getVerseText($old_chapter_usfm, $verse);
            $new_verse_usfm = Filter_Usfm::getVerseText($new_chapter_usfm, $verse);
            if ($old_verse_usfm != $new_verse_usfm) {
                $filter_text_old = new Filter_Text($bible);
                $filter_text_new = new Filter_Text($bible);
                $filter_text_old->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
                $filter_text_new->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
                $filter_text_old->text_text = new Text_Text();
                $filter_text_new->text_text = new Text_Text();
                $filter_text_old->addUsfmCode($old_verse_usfm);
                $filter_text_new->addUsfmCode($new_verse_usfm);
                $filter_text_old->run($stylesheet);
                $filter_text_new->run($stylesheet);
                $old_html = $filter_text_old->html_text_standard->getInnerHtml();
                $new_html = $filter_text_new->html_text_standard->getInnerHtml();
                $old_text = $filter_text_old->text_text->get();
                $new_text = $filter_text_new->text_text->get();
                if ($old_text != $new_text) {
                    $modification = Filter_Diff::diff($old_text, $new_text);
                    $email .= "<div>";
                    $email .= Filter_Books::passageDisplay($book, $chapter, $verse);
                    $email .= " ";
                    $email .= $modification;
                    $email .= "</div>";
                    if ($database_config_user->getUserUserChangesNotificationsOnline($user)) {
                        $changeNotificationUsers = array($user);
                        $database_modifications->recordNotification($changeNotificationUsers, "☺", $bible, $book, $chapter, $verse, $old_html, $modification, $new_html);
                    }
                    $database_history->record($timestamp, $user, $bible, $book, $chapter, $verse, $old_html, $modification, $new_html);
                }
            }
        }
    }
}
Example #18
0
 private function cleanUSFM($usfm)
 {
     // The user may accidentally omit or erase the note caller.
     // The note caller is one character that immediately follows the note opener.
     // E.g.: \f + ...\f*.
     // Check for missing note caller, and if it's not there, add the default "+".
     // Also replace a double space after a note opener.
     foreach ($this->noteOpeners as $noteOpener) {
         $opener = Filter_Usfm::getOpeningUsfm($noteOpener);
         $usfm = str_replace($opener . " ", $opener, $usfm);
         $pos = mb_strpos($usfm, $opener);
         while ($pos !== false) {
             $isClean = true;
             // Check that the character that follows the note opener is a non-space.
             $pos2 = $pos + mb_strlen($opener);
             $character = mb_substr($usfm, $pos2, 1);
             if ($character == " ") {
                 $isClean = false;
             }
             // Check that the following character is not a space.
             $pos2++;
             $character = mb_substr($usfm, $pos2, 1);
             if ($character != " ") {
                 $isClean = false;
             }
             // Fix the note caller is necessary.
             if (!$isClean) {
                 $database_logs = Database_Logs::getInstance();
                 $database_logs->log("Fixing note caller in {$usfm}");
                 $pos2--;
                 $usfm = mb_substr($usfm, 0, $pos2) . "+" . mb_substr($usfm, $pos2);
             }
             // Next iteration.
             $pos = mb_strpos($usfm, $opener, $pos + 5);
         }
     }
     return $usfm;
 }
Example #19
0
 public function updateSearchFields($name, $book, $chapter)
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_config_bible = Database_Config_Bible::getInstance();
     $usfm = $database_bibles->getChapter($name, $book, $chapter);
     $stylesheet = $database_config_bible->getExportStylesheet($name);
     // Data to store.
     $usfmraw = array();
     $usfmlower = array();
     $plainraw = array();
     $plainlower = array();
     // Get the verses in the chapter.
     $verses = Filter_Usfm::getVerseNumbers($usfm);
     $verses = array_unique($verses);
     sort($verses, SORT_NUMERIC);
     // One column contains the raw USFM as it is, and another one the lowercase text.
     foreach ($verses as $verse) {
         $raw = Filter_Usfm::getVerseText($usfm, $verse);
         $lower = mb_convert_case($raw, MB_CASE_LOWER);
         $usfmraw[$verse] = $raw;
         $usfmlower[$verse] = $lower;
     }
     // Text filter for getting the plain text.
     $filter_text = new Filter_Text($name);
     $filter_text->text_text = new Text_Text();
     $filter_text->initializeHeadingsAndTextPerVerse();
     $filter_text->addUsfmCode($usfm);
     $filter_text->run($stylesheet);
     // Get the clean verse texts.
     $texts = $filter_text->getVersesText();
     foreach ($texts as $verse => $text) {
         if (!isset($plainraw[$verse])) {
             $plainraw[$verse] = "";
         }
         $plainraw[$verse] .= "{$text}\n";
     }
     // Add any clean headings.
     $headings = $filter_text->verses_headings;
     foreach ($headings as $verse => $heading) {
         if (!isset($plainraw[$verse])) {
             $plainraw[$verse] = "";
         }
         $plainraw[$verse] .= "{$heading}\n";
     }
     // Create the lower case plain text.
     foreach ($plainraw as $verse => $raw) {
         $plainlower[$verse] = mb_convert_case($raw, MB_CASE_LOWER);
     }
     // Get all possible verses.
     $allverses = array_merge(array_keys($usfmraw), array_keys($plainraw));
     $allverses = array_unique($allverses);
     // Store everything.
     Database_SQLite::exec($this->db, "BEGIN;");
     $name = Database_SQLiteInjection::no($name);
     $book = Database_SQLiteInjection::no($book);
     $chapter = Database_SQLiteInjection::no($chapter);
     $query = "DELETE FROM bibles WHERE bible = '{$name}' AND book = {$book} AND chapter = {$chapter};";
     Database_SQLite::exec($this->db, $query);
     foreach ($allverses as $verse) {
         if ($verse == "") {
             $verse = 0;
         }
         $verse = (int) $verse;
         @($ur = Database_SQLiteInjection::no($usfmraw[$verse]));
         @($ul = Database_SQLiteInjection::no($usfmlower[$verse]));
         @($pr = Database_SQLiteInjection::no($plainraw[$verse]));
         @($pl = Database_SQLiteInjection::no($plainlower[$verse]));
         $query = "INSERT INTO bibles (bible, book, chapter, verse, usfmraw, usfmlower, plainraw, plainlower) VALUES ('{$name}', {$book}, {$chapter}, {$verse}, '{$ur}', '{$ul}', '{$pr}', '{$pl}');";
         Database_SQLite::exec($this->db, $query);
     }
     Database_SQLite::exec($this->db, "COMMIT;");
 }
Example #20
0
$database_bibles = Database_Bibles::getInstance();
$database_jobs->setProgress($jobId, Locale_Translate::_("The document is being created..."));
$resources = $database_config_user->getPrintResourcesForUser($user);
$from = $database_config_user->getPrintPassageFromForUser($user);
$passage = explode(".", $from);
$from = Filter_Books::passage2integer($passage);
$to = $database_config_user->getPrintPassageToForUser($user);
$passage = explode(".", $to);
$to = Filter_Books::passage2integer($passage);
$result = array();
$books = $database_bibles->getBooks($bible);
foreach ($books as $book) {
    $chapters = $database_bibles->getChapters($bible, $book);
    foreach ($chapters as $chapter) {
        $usfm = $database_bibles->getChapter($bible, $book, $chapter);
        $verses = Filter_Usfm::getVerseNumbers($usfm);
        foreach ($verses as $verse) {
            $passage = Filter_Books::passage2integer(array($book, $chapter, $verse));
            if ($passage >= $from && $passage <= $to) {
                $passageText = Filter_Books::passageDisplay($book, $chapter, $verse);
                $database_jobs->setProgress($jobId, $passageText);
                $result[] = '<div class="nextresource">';
                $result[] = "<p>{$passageText}</p>";
                foreach ($resources as $resource) {
                    $result[] = "<p>";
                    $result[] = $resource;
                    $html = Resource_Logic::getHtml($resource, $book, $chapter, $verse);
                    $result[] = $html;
                    $result[] = "</p>";
                }
                $result[] = "</div>";
Example #21
0
 public function testGetNewNotePositionSix()
 {
     // It tests whether a note is not inserted within another note.
     $usfm = '\\v 1 Zvino namazuva\\x + Gen.1.1.\\x* okutonga kwavatongi nzara yakange iripo panyika.';
     $position = Filter_Usfm::getNewNotePosition($usfm, 10, 0);
     $this->assertEquals(10, $position);
     $position = Filter_Usfm::getNewNotePosition($usfm, 20, 0);
     $this->assertEquals(21, $position);
 }
Example #22
0
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::TRANSLATOR_LEVEL);
$database_config_user = Database_Config_User::getInstance();
$database_bibles = Database_Bibles::getInstance();
$ipc_focus = Ipc_Focus::getInstance();
$bible = $database_config_user->getTargetXrefBible();
$currentBook = $ipc_focus->getBook();
$currentChapter = $ipc_focus->getChapter();
$currentPassage = array($currentBook, $currentChapter, 1);
$currentLocation = Filter_Books::passage2integer($currentPassage);
$books = $database_bibles->getBooks($bible);
foreach ($books as $book) {
    $chapters = $database_bibles->getChapters($bible, $book);
    foreach ($chapters as $chapter) {
        if ($chapter == 0) {
            continue;
        }
        $passage = array($book, $chapter, 1);
        $location = Filter_Books::passage2integer($passage);
        if ($location > $currentLocation) {
            $usfm = $database_bibles->getChapter($bible, $book, $chapter);
            $xrefs = Filter_Usfm::extractNotes($usfm, array("x"));
            if (empty($xrefs)) {
                $ipc_focus->set($book, $chapter, 1);
                Filter_Url::redirect("index.php");
                die;
            }
        }
    }
}
Filter_Url::redirect("index.php");
Example #23
0
<?php

/*
Copyright (©) 2003-2014 Teus Benschop.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
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::TRANSLATOR_LEVEL);
$bible = $_GET['bible'];
$book = $_GET['book'];
$chapter = $_GET['chapter'];
$verse = $_GET['verse'];
$database_bibles = Database_Bibles::getInstance();
$usfm = $database_bibles->getChapter($bible, $book, $chapter);
$usfm = Filter_Usfm::getVerseText($usfm, $verse);
echo Checksum_Logic::send($usfm);
Example #24
0
\v 17 Obey them that have the rule over you, and submit yourselves: for they watch for your souls, as they that must give account, that they may do it with joy, and not with grief: for that\add is\add* unprofitable for you.
\p
\v 18 Pray for us: for we trust we have a good conscience, in all things willing to live honestly.
\v 19 But I beseech \add you\add* the rather to do this, that I may be restored to you the sooner.
\v 20 Now the God of peace, that brought again from the dead our Lord Jesus, that great shepherd of the sheep, through the blood of the everlasting covenant,
\v 21 Make you perfect in every good work to do his will, working in you that which is wellpleasing in his sight, through JesusChrist; to whom \add be\add* glory for ever and ever. Amen.
\v 22 And I beseech you, brethren, suffer the word of exhortation: for I have written a letter unto you in few words.
\v 23 Know ye that \add our\add* brother Timothy is set at liberty; with whom, if he come shortly, I will see you.
\p
\v 24 Salute all them that have the rule over you, and all the saints. They of Italy salute you.
\p
\v 25 Grace \add be\add* with you all. Amen.
EOD;
$data[] = $usfm;
foreach ($data as $usfm) {
    $book_chapter_text = Filter_Usfm::import($usfm, "Standard");
    foreach ($book_chapter_text as $data) {
        $book_number = $data[0];
        $chapter_number = $data[1];
        $chapter_data = $data[2];
        if ($book_number > 0) {
            Bible_Logic::storeChapter("KJV", $book_number, $chapter_number, $chapter_data);
        }
    }
}
// Clean out nearly empty chapters from the Bibles.
$bibles = $database_bibles->getBibles();
foreach ($bibles as $bible) {
    $books = $database_bibles->getBooks($bible);
    foreach ($books as $book) {
        $chapters = $database_bibles->getChapters($bible, $book);
Example #25
0
}
// Get the old chapter USFM into an array of verse => USFM fragment.
$usfmString = $database_bibles->getChapter($bible, $book, $chapter);
$verses = Filter_Usfm::getVerseNumbers($usfmString);
$verses = array_unique($verses);
sort($verses, SORT_NUMERIC);
$usfmArray = array();
foreach ($verses as $vs) {
    $usfmArray[$vs] = Filter_Usfm::getVerseText($usfmString, $vs);
}
// Store the verse USFM in the array.
$usfmArray[$verse] = $usfm;
// Create the updated chapter USFM as a string.
$usfm = implode("\n", $usfmArray);
$stylesheet = $database_config_user->getStylesheet();
$book_chapter_text = Filter_Usfm::import($usfm, $stylesheet);
foreach ($book_chapter_text as $data) {
    $book_number = $data[0];
    $chapter_number = $data[1];
    $chapter_data_to_save = $data[2];
    if (($book_number == $book || $book_number == 0) && $chapter_number == $chapter) {
        // Collect some data about the changes for this user.
        $username = $session_logic->currentUser();
        $oldID = $database_bibles->getChapterId($bible, $book, $chapter);
        $oldText = $database_bibles->getChapter($bible, $book, $chapter);
        // Safely store the chapter.
        $saved = Filter_Bibles::safeStoreChapter($bible, $book, $chapter, $chapter_data_to_save);
        if ($saved) {
            // Store details for the user's changes.
            $newID = $database_bibles->getChapterId($bible, $book, $chapter);
            $newText = $chapter_data_to_save;
Example #26
0
 $database_logs->log("{$history} {$path}", Filter_Roles::MANAGER_LEVEL);
 $data = Filter_Git::explodePath($path);
 if ($data) {
     $book = $data['book'];
     $chapter = $data['chapter'];
     $data = Filter_Git::changes($directory, $sha1, $path);
     $oldusfm = $data['old'];
     $newusfm = $data['new'];
     $oldverses = Filter_Usfm::getVerseNumbers($oldusfm);
     $newverses = Filter_Usfm::getVerseNumbers($newusfm);
     $verses = array_merge($oldverses, $newverses);
     $verses = array_unique($verses);
     sort($verses, SORT_NUMERIC);
     foreach ($verses as $verse) {
         $old_verse_usfm = Filter_Usfm::getVerseText($oldusfm, $verse);
         $new_verse_usfm = Filter_Usfm::getVerseText($newusfm, $verse);
         if ($old_verse_usfm != $new_verse_usfm) {
             $filter_text_old = new Filter_Text($bible);
             $filter_text_new = new Filter_Text($bible);
             $filter_text_old->html_text_standard = new Html_Text("");
             $filter_text_new->html_text_standard = new Html_Text("");
             $filter_text_old->text_text = new Text_Text();
             $filter_text_new->text_text = new Text_Text();
             $filter_text_old->addUsfmCode($old_verse_usfm);
             $filter_text_new->addUsfmCode($new_verse_usfm);
             $filter_text_old->run($stylesheet);
             $filter_text_new->run($stylesheet);
             $old_html = $filter_text_old->html_text_standard->getInnerHtml();
             $new_html = $filter_text_new->html_text_standard->getInnerHtml();
             $old_text = $filter_text_old->text_text->get();
             $new_text = $filter_text_new->text_text->get();