Ejemplo n.º 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");
 }
Ejemplo n.º 2
0
$database_config_bible = Database_Config_Bible::getInstance();
$database_bibles = Database_Bibles::getInstance();
$database_books = Database_Books::getInstance();
$stylesheet = $database_config_bible->getExportStylesheet($bible);
// Create stylesheet.
$styles_sheets = new Styles_Sheets();
$styles_sheets->create($stylesheet, $filecss, false, $bible);
// Copy font to the output directory.
$font = $database_config_bible->getTextFont($bible);
if ($font) {
    if (Fonts_Logic::fontExists($font)) {
        $fontpath = Fonts_Logic::getFontPath($font);
        copy($fontpath, "{$directory}/{$font}");
    }
}
$filter_text = new Filter_Text($bible);
$filter_text->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
$filter_text->html_text_standard->customClass = Filter_CustomCSS::getClass($bible);
// Load one book.
$chapters = $database_bibles->getChapters($bible, $book);
foreach ($chapters as $chapter) {
    $usfm = $database_bibles->getChapter($bible, $book, $chapter);
    $usfm = trim($usfm);
    // Use small chunks of USFM at a time for much better performance.
    $filter_text->addUsfmCode($usfm);
}
// Convert the USFM.
$filter_text->run($stylesheet);
// Save file.
$filter_text->html_text_standard->save($filename);
$database_logs->log(Locale_Translate::_("Exported to html") . " {$bible} " . Export_Logic::baseBookFileName($book), Filter_Roles::TRANSLATOR_LEVEL);
Ejemplo n.º 3
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;");
 }
Ejemplo n.º 4
0
 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);
     }
     if ($check_sentence_structure || $check_paragraph_structure) {
         $checks_sentences->initialize();
         if ($check_sentence_structure) {
             $checks_sentences->check($verses_text);
Ejemplo n.º 5
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);
                }
            }
        }
    }
}
Ejemplo n.º 6
0
// 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.
if ($searchplain) {
    $filter_text = new Filter_Text($bible);
    $filter_text->text_text = new Text_Text();
    $filter_text->initializeHeadingsAndTextPerVerse();
    $filter_text->addUsfmCode($updatedUsfm);
    $filter_text->run($stylesheet);
}
// Get the updated plain text of the correct verse of the updated USFM.
// This is for search/replace in plain text, not in USFM.
if ($searchplain) {
    $updatedPlainText = "";
    $texts = $filter_text->getVersesText();
    foreach ($texts as $vs => $text) {
        if ($vs == $verse) {
            $updatedPlainText .= "{$text}\n";
        }
    }
Ejemplo n.º 7
0
*/
require_once "../bootstrap/bootstrap.php";
// Security: The script runs from the cli SAPI only.
Filter_Cli::assert();
ignore_user_abort(true);
set_time_limit(0);
$bible = Filter_Cli::argument(@$argv, 1);
$directory = Export_Logic::bibleDirectory($bible) . "/onlinebible";
if (!file_exists($directory)) {
    mkdir($directory, 0777, true);
}
$filename = "{$directory}/bible.exp";
$database_logs = Database_Logs::getInstance();
$database_config_bible = Database_Config_Bible::getInstance();
$database_bibles = Database_Bibles::getInstance();
$database_books = Database_Books::getInstance();
$stylesheet = $database_config_bible->getExportStylesheet($bible);
$filter_text_bible = new Filter_Text($bible);
$filter_text_bible->onlinebible_text = new Onlinebible_Text();
$books = $database_bibles->getBooks($bible);
foreach ($books as $book) {
    $chapters = $database_bibles->getChapters($bible, $book);
    foreach ($chapters as $chapter) {
        $chapter_data = $database_bibles->getChapter($bible, $book, $chapter);
        $chapter_data = trim($chapter_data);
        $filter_text_bible->addUsfmCode($chapter_data);
    }
}
$filter_text_bible->run($stylesheet);
$filter_text_bible->onlinebible_text->save($filename);
$database_logs->log($bible . ": " . Locale_Translate::_("Exported to Online Bible"), Filter_Roles::TRANSLATOR_LEVEL);
Ejemplo n.º 8
0
// The input parameters.
$bible = Filter_Cli::argument(@$argv, 1);
// Create folders for the information.
$directory = Export_Logic::bibleDirectory($bible) . "/info";
if (!file_exists($directory)) {
    mkdir($directory, 0777, true);
}
// Filenames for the various types of OpenDocument files.
$informationdFilename = "{$directory}/information.html";
$falloutFilename = "{$directory}/fallout.html";
$database_logs = Database_Logs::getInstance();
$database_config_bible = Database_Config_Bible::getInstance();
$database_bibles = Database_Bibles::getInstance();
$database_books = Database_Books::getInstance();
$stylesheet = $database_config_bible->getExportStylesheet($bible);
$filter_text = new Filter_Text($bible);
$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);
        $usfm = trim($usfm);
        // Use small chunks of USFM at a time for much better performance.
        $filter_text->addUsfmCode($usfm);
    }
}
// Go through USFM to find the info and fallout.
$filter_text->run($stylesheet);
// Save files.
$filter_text->produceInfoDocument($informationdFilename);
$filter_text->produceFalloutDocument($falloutFilename);
Ejemplo n.º 9
0
    public function testEmbeddedOpenDocumentThree()
    {
        // Open character style, open embedded character style, then closing the outer one closes the embedded one also.
        $usfm = <<<'EOD'
\id GEN
\c 1
\p
\v 1 I will sing \add to the \+nd Lord\add*.
EOD;
        $filter_text = new Filter_Text("phpunit");
        $filter_text->odf_text_standard = new Odf_Text("phpunit");
        $filter_text->addUsfmCode($usfm);
        $filter_text->run("Standard");
        $filter_text->odf_text_standard->save("/tmp/TextTest.odt");
        $filter_text->odf_text_standard->save("/tmp/TextTest2.odt");
        $odt = shell_exec("odt2txt /tmp/TextTest.odt");
        $standard = <<<'EOD'
Genesis 1
=========

1 I will sing to the Lord.
EOD;
        $this->assertEquals($standard, trim($odt));
    }
Ejemplo n.º 10
0
 $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();
         if ($bible_text != $compare_text) {
             $modification = Filter_Diff::diff($compare_text, $bible_text);
             $result[] = Filter_Books::passageDisplay($book, $chapter, $verse) . " " . $modification;
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
 $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();
         $modification = Filter_Diff::diff($old_text, $new_text);
         $database_history->record($timestamp, $author, $bible, $book, $chapter, $verse, $old_html, $modification, $new_html);
     }