Ejemplo n.º 1
0
 /**
  * This function does the processing of the USFM code,
  * formatting the document and extracting other useful information.
  */
 private function processUsfm()
 {
     // Go through the USFM code.
     $processedBooksCount = 0;
     $this->usfmMarkersAndTextPointer = 0;
     while ($this->unprocessedUsfmCodeAvailable()) {
         $this->getUsfmNextChapter();
         for ($this->chapterUsfmMarkersAndTextPointer = 0; $this->chapterUsfmMarkersAndTextPointer < count($this->chapterUsfmMarkersAndText); $this->chapterUsfmMarkersAndTextPointer++) {
             $currentItem = $this->chapterUsfmMarkersAndText[$this->chapterUsfmMarkersAndTextPointer];
             if (Filter_Usfm::isUsfmMarker($currentItem)) {
                 // Indicator describing the marker.
                 $isOpeningMarker = Filter_Usfm::isOpeningMarker($currentItem);
                 $isEmbeddedMarker = Filter_Usfm::isEmbeddedMarker($currentItem);
                 // Clean up the marker, so we remain with the basic version, e.g. 'id'.
                 $marker = Filter_Usfm::getMarker($currentItem);
                 if (array_key_exists($marker, $this->styles)) {
                     $style = $this->styles[$marker];
                     switch ($style['type']) {
                         case StyleTypeIdentifier:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             switch ($style['subtype']) {
                                 case IdentifierSubtypeBook:
                                     // Get book number.
                                     $s = Filter_Usfm::getBookIdentifier($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     $s = str_replace(Filter_Character::softHyphen(), "", $s);
                                     // Remove possible soft hyphen.
                                     $database_books = Database_Books::getInstance();
                                     $this->currentBookIdentifier = $database_books->getIdFromUsfm($s);
                                     // Reset chapter and verse numbers.
                                     $this->currentChapterNumber = 0;
                                     $this->currentVerseNumber = "0";
                                     // Throw away whatever follows the \id, e.g. 'GEN xxx xxx'.
                                     Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     // Whether to insert a new page before the book. But never before the first book.
                                     if ($style['userbool1']) {
                                         if ($processedBooksCount) {
                                             if ($this->odf_text_standard) {
                                                 $this->odf_text_standard->newPageBreak();
                                             }
                                             if ($this->odf_text_text_only) {
                                                 $this->odf_text_text_only->newPageBreak();
                                             }
                                             if ($this->odf_text_text_and_note_citations) {
                                                 $this->odf_text_text_and_note_citations->newPageBreak();
                                             }
                                             if ($this->html_text_standard) {
                                                 $this->html_text_standard->newPageBreak();
                                             }
                                             if ($this->html_text_linked) {
                                                 $this->html_text_linked->newPageBreak();
                                             }
                                         }
                                     }
                                     $processedBooksCount++;
                                     // Reset notes.
                                     $this->resetNoteCitations('book');
                                     // Online Bible.
                                     if ($this->onlinebible_text) {
                                         $this->onlinebible_text->storeData();
                                     }
                                     // eSword.
                                     if ($this->esword_text) {
                                         $this->esword_text->newBook($this->currentBookIdentifier);
                                     }
                                     // Done.
                                     break;
                                 case IdentifierSubtypeEncoding:
                                     $this->addToFallout("Text encoding indicator not supported. Encoding is always in UTF8: \\{$marker}", true);
                                     break;
                                 case IdentifierSubtypeComment:
                                     $this->addToInfo("Comment: \\{$marker}", true);
                                     break;
                                 case IdentifierSubtypeRunningHeader:
                                     // This information already went into the Info document during the preprocessing stage.
                                     // Remove it from the USFM input stream.
                                     Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     // Ideally this information should be inserted in the headers of the standard text document.
                                     // UserBool2RunningHeaderLeft:
                                     // UserBool3RunningHeaderRight:
                                     break;
                                 case IdentifierSubtypeLongTOC:
                                     // This information already went into the Info document. Remove it from the USFM stream.
                                     Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     break;
                                 case IdentifierSubtypeShortTOC:
                                     // This information already went into the Info document. Remove it from the USFM stream.
                                     Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     break;
                                 case IdentifierSubtypeBookAbbrev:
                                     // This information already went into the Info document. Remove it from the USFM stream.
                                     Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     break;
                                 case IdentifierSubtypeChapterLabel:
                                     // This information is already in the object. Remove it from the USFM stream.
                                     Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     break;
                                 case IdentifierSubtypePublishedChapterMarker:
                                     // This information is already in the object. Remove it from the USFM stream.
                                     Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                                     break;
                                 case IdentifierSubtypeCommentWithEndmarker:
                                     if ($isOpeningMarker) {
                                         $this->addToInfo("Comment: \\{$marker}", true);
                                     }
                                     break;
                                 default:
                                     $this->addToFallout("Unknown markup: \\{$marker}", true);
                                     break;
                             }
                             break;
                         case StyleTypeNotUsedComment:
                             $this->addToFallout("Unknown markup: \\{$marker}", true);
                             break;
                         case StyleTypeNotUsedRunningHeader:
                             $this->addToFallout("Unknown markup: \\{$marker}", true);
                             break;
                         case StyleTypeStartsParagraph:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             switch ($style['subtype']) {
                                 case ParagraphSubtypeMainTitle:
                                 case ParagraphSubtypeSubTitle:
                                 case ParagraphSubtypeSectionHeading:
                                     $this->newParagraph($style, true);
                                     $this->heading_started = true;
                                     $this->text_started = false;
                                     break;
                                 case ParagraphSubtypeNormalParagraph:
                                 default:
                                     $this->newParagraph($style, false);
                                     $this->heading_started = false;
                                     $this->text_started = true;
                                     if (is_array($this->verses_text)) {
                                         // If a new paragraph starts within an existing verse,
                                         // add a space to the text already in that verse.
                                         if (isset($this->verses_text[$this->currentVerseNumber])) {
                                             $this->verses_text[$this->currentVerseNumber] .= " ";
                                         }
                                         // Record the position within the text where this new paragraph starts.
                                         $contents = implode('', $this->verses_text);
                                         $this->paragraph_start_positions[] = mb_strlen($contents);
                                         unset($contents);
                                     }
                                     break;
                             }
                             break;
                         case StyleTypeInlineText:
                             // Support for a normal and an embedded character style.
                             if ($isOpeningMarker) {
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->openTextStyle($style, false, $isEmbeddedMarker);
                                 }
                                 if ($this->odf_text_text_only) {
                                     $this->odf_text_text_only->openTextStyle($style, false, $isEmbeddedMarker);
                                 }
                                 if ($this->odf_text_text_and_note_citations) {
                                     $this->odf_text_text_and_note_citations->openTextStyle($style, false, $isEmbeddedMarker);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->openTextStyle($style, false, $isEmbeddedMarker);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->openTextStyle($style, false, $isEmbeddedMarker);
                                 }
                             } else {
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(false, $isEmbeddedMarker);
                                 }
                                 if ($this->odf_text_text_only) {
                                     $this->odf_text_text_only->closeTextStyle(false, $isEmbeddedMarker);
                                 }
                                 if ($this->odf_text_text_and_note_citations) {
                                     $this->odf_text_text_and_note_citations->closeTextStyle(false, $isEmbeddedMarker);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(false, $isEmbeddedMarker);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(false, $isEmbeddedMarker);
                                 }
                             }
                             break;
                         case StyleTypeChapterNumber:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             if ($this->onlinebible_text) {
                                 $this->onlinebible_text->storeData();
                             }
                             // Get the chapter number.
                             $number = Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                             $number = Filter_Numeric::integer_in_string($number);
                             // Update this object.
                             $this->currentChapterNumber = $number;
                             $this->currentVerseNumber = "0";
                             // If there is a published chapter character, the chapter number takes that value.
                             foreach ($this->publishedChapterMarkers as $publishedChapterMarker) {
                                 if ($publishedChapterMarker['book'] == $this->currentBookIdentifier) {
                                     if ($publishedChapterMarker['chapter'] == $this->currentChapterNumber) {
                                         $number = $publishedChapterMarker['value'];
                                     }
                                 }
                             }
                             // Enter text for the running headers.
                             $database_books = Database_Books::getInstance();
                             $runningHeader = $database_books->getEnglishFromId($this->currentBookIdentifier);
                             foreach ($this->runningHeaders as $item) {
                                 if ($item['book'] == $this->currentBookIdentifier) {
                                     $runningHeader = $item['value'];
                                 }
                             }
                             $runningHeader = "{$runningHeader} {$number}";
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->newHeading1($runningHeader, true);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->newHeading1($runningHeader, true);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->newHeading1($runningHeader, true);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->newHeading1($runningHeader, false);
                             }
                             // This is the phase of outputting the chapter number in the text body.
                             // It always outputs the chapter number to the clear text export.
                             if (isset($this->text_text)) {
                                 $this->text_text->paragraph($number);
                             }
                             // The chapter number is only output when there is more than one chapter in a book.
                             if ($this->numberOfChaptersPerBook[$this->currentBookIdentifier] > 1) {
                                 if ($style['userbool1']) {
                                     // Output the chapter number at the first verse, not here.
                                     // Store it for later processing.
                                     $this->outputChapterTextAtFirstVerse = $number;
                                 } else {
                                     // Output the chapter in a new paragraph.
                                     // If the chapter label \cl is entered once before chapter 1 (\c 1)
                                     // it represents the text for "chapter" to be used throughout the current book.
                                     // If \cl is used after each individual chapter marker, it represents the particular text
                                     // to be used for the display of the current chapter heading
                                     // (usually done if numbers are being presented as words, not numerals).
                                     $labelEntireBook = "";
                                     $labelCurrentChapter = "";
                                     foreach ($this->chapterLabels as $pchapterLabel) {
                                         if ($pchapterLabel['book'] == $this->currentBookIdentifier) {
                                             if ($pchapterLabel['chapter'] == 0) {
                                                 $labelEntireBook = $pchapterLabel['value'];
                                             }
                                             if ($pchapterLabel['chapter'] == $this->currentChapterNumber) {
                                                 $labelCurrentChapter = $pchapterLabel['value'];
                                             }
                                         }
                                     }
                                     if ($labelEntireBook != "") {
                                         $number = "{$labelEntireBook} {$number}";
                                     }
                                     if ($labelCurrentChapter != "") {
                                         $number = $labelCurrentChapter;
                                     }
                                     // The chapter number shows in a new paragraph.
                                     // Keep it together with the next paragraph.
                                     $this->newParagraph($style, true);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addText($number);
                                     }
                                     if ($this->odf_text_text_only) {
                                         $this->odf_text_text_only->addText($number);
                                     }
                                     if ($this->odf_text_text_and_note_citations) {
                                         $this->odf_text_text_and_note_citations->addText($number);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->addText($number);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->addText($number);
                                     }
                                 }
                             }
                             // Output chapter number for other formats.
                             if ($this->esword_text) {
                                 $this->esword_text->newChapter($this->currentChapterNumber);
                             }
                             // Open a paragraph for the notes. It takes the style of the footnote content marker, usually 'ft'.
                             // This is done specifically for the version that has the notes only.
                             $this->ensureNoteParagraphStyle($this->standardContentMarkerFootEndNote, $this->styles[$this->standardContentMarkerFootEndNote]);
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->newParagraph($this->standardContentMarkerFootEndNote);
                             }
                             // UserBool2ChapterInLeftRunningHeader -> no headings implemented yet.
                             // UserBool3ChapterInRightRunningHeader -> no headings implemented yet.
                             // Reset.
                             $this->resetNoteCitations('chapter');
                             // Done.
                             break;
                         case StyleTypeVerseNumber:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             if ($this->onlinebible_text) {
                                 $this->onlinebible_text->storeData();
                             }
                             // Care for the situation that a new verse starts a new paragraph.
                             if ($style['userbool1']) {
                                 if ($this->odf_text_standard) {
                                     if ($this->odf_text_standard->currentParagraphContent != "") {
                                         $this->odf_text_standard->newParagraph($this->odf_text_standard->currentParagraphStyle);
                                     }
                                 }
                                 if ($this->odf_text_text_only) {
                                     if ($this->odf_text_text_only->currentParagraphContent != "") {
                                         $this->odf_text_text_only->newParagraph($this->odf_text_text_only->currentParagraphStyle);
                                     }
                                 }
                                 if ($this->odf_text_text_and_note_citations) {
                                     if ($this->odf_text_text_and_note_citations->currentParagraphContent != "") {
                                         $this->odf_text_text_and_note_citations->newParagraph($this->odf_text_text_and_note_citations->currentParagraphStyle);
                                     }
                                 }
                                 if ($this->html_text_standard) {
                                     if ($this->html_text_standard->currentParagraphContent != "") {
                                         $this->html_text_standard->newParagraph($this->html_text_standard->currentParagraphStyle);
                                     }
                                 }
                                 if ($this->html_text_linked) {
                                     if ($this->html_text_linked->currentParagraphContent != "") {
                                         $this->html_text_linked->newParagraph($this->html_text_linked->currentParagraphStyle);
                                     }
                                 }
                                 if (isset($this->text_text)) {
                                     $this->text_text->paragraph();
                                 }
                             }
                             // Deal with the case of a pending chapter number.
                             if (isset($this->outputChapterTextAtFirstVerse)) {
                                 $database_config_bible = Database_Config_Bible::getInstance();
                                 if (!$database_config_bible->getExportChapterDropCapsFrames($this->bible)) {
                                     $dropCapsLength = mb_strlen($this->outputChapterTextAtFirstVerse);
                                     $this->applyDropCapsToCurrentParagraph($dropCapsLength);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addText($this->outputChapterTextAtFirstVerse);
                                     }
                                     if ($this->odf_text_text_only) {
                                         $this->odf_text_text_only->addText($this->outputChapterTextAtFirstVerse);
                                     }
                                     if ($this->odf_text_text_and_note_citations) {
                                         $this->odf_text_text_and_note_citations->addText($this->outputChapterTextAtFirstVerse);
                                     }
                                 } else {
                                     $this->putChapterNumberInFrame($this->outputChapterTextAtFirstVerse);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->openTextStyle(array("marker" => "dropcaps"), false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->addText($this->outputChapterTextAtFirstVerse);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->openTextStyle(array("marker" => "dropcaps"), false, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->addText($this->outputChapterTextAtFirstVerse);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(false, false);
                                 }
                             }
                             // Temporarily retrieve the text that follows the \v verse marker.
                             $textFollowingMarker = Filter_Usfm::getTextFollowingMarker($this->chapterUsfmMarkersAndText, $this->chapterUsfmMarkersAndTextPointer);
                             // Extract the verse number, and store it in the object.
                             $number = Filter_Usfm::peekVerseNumber($textFollowingMarker);
                             $this->currentVerseNumber = $number;
                             // Output the verse number. But only if no chapter number was put here.
                             if (!isset($this->outputChapterTextAtFirstVerse)) {
                                 // If the current paragraph has text already, then insert a space.
                                 if ($this->odf_text_standard) {
                                     if ($this->odf_text_standard->currentParagraphContent != "") {
                                         $this->odf_text_standard->addText(" ");
                                     }
                                 }
                                 if ($this->odf_text_text_only) {
                                     if ($this->odf_text_text_only->currentParagraphContent != "") {
                                         $this->odf_text_text_only->addText(" ");
                                     }
                                 }
                                 if ($this->odf_text_text_and_note_citations) {
                                     if ($this->odf_text_text_and_note_citations->currentParagraphContent != "") {
                                         $this->odf_text_text_and_note_citations->addText(" ");
                                     }
                                 }
                                 if ($this->html_text_standard) {
                                     if ($this->html_text_standard->currentParagraphContent != "") {
                                         $this->html_text_standard->addText(" ");
                                     }
                                 }
                                 if ($this->html_text_linked) {
                                     if ($this->html_text_linked->currentParagraphContent != "") {
                                         $this->html_text_linked->addText(" ");
                                     }
                                 }
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->openTextStyle($style, false, false);
                                 }
                                 if ($this->odf_text_text_only) {
                                     $this->odf_text_text_only->openTextStyle($style, false, false);
                                 }
                                 if ($this->odf_text_text_and_note_citations) {
                                     $this->odf_text_text_and_note_citations->openTextStyle($style, false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->openTextStyle($style, false, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->openTextStyle($style, false, false);
                                 }
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->addText($number);
                                 }
                                 if ($this->odf_text_text_only) {
                                     $this->odf_text_text_only->addText($number);
                                 }
                                 if ($this->odf_text_text_and_note_citations) {
                                     $this->odf_text_text_and_note_citations->addText($number);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->addText($number);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->addText($number);
                                 }
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(false, false);
                                 }
                                 if ($this->odf_text_text_only) {
                                     $this->odf_text_text_only->closeTextStyle(false, false);
                                 }
                                 if ($this->odf_text_text_and_note_citations) {
                                     $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(false, false);
                                 }
                             }
                             // Clear text output.
                             if (isset($this->text_text)) {
                                 if ($this->text_text->line() != "") {
                                     $this->text_text->text(" ");
                                 }
                                 $this->text_text->text($number);
                                 // Clear text output always has a space following the verse.
                                 // Important for outputting the first verse.
                                 $this->text_text->text(" ");
                             }
                             // If there was any text following the \v marker, remove the verse number,
                             // put the remainder back into the object, and update the pointer.
                             if ($textFollowingMarker != "") {
                                 @($pos = strpos($textFollowingMarker, $number));
                                 if ($pos !== false) {
                                     $textFollowingMarker = substr($textFollowingMarker, $pos + strlen($number));
                                 }
                                 // If a chapter number was put, remove any whitespace from the start of the following text.
                                 // Remove whitespace from the start of the following text, and replace it with the en-space.
                                 // This en-space is a fixed-width space.
                                 // This type of space makes the layout of the text following the verse number look tidier.
                                 // But if a chapter number was put, than do not put any space at the start of the following verse.
                                 $textFollowingMarker = ltrim($textFollowingMarker);
                                 if (!isset($this->outputChapterTextAtFirstVerse)) {
                                     $textFollowingMarker = Filter_Character::enSpace() . $textFollowingMarker;
                                 }
                                 $this->chapterUsfmMarkersAndText[$this->chapterUsfmMarkersAndTextPointer] = $textFollowingMarker;
                                 $this->chapterUsfmMarkersAndTextPointer--;
                             }
                             // Unset the chapter variable, whether it was used or not. This makes it ready for subsequent use.
                             unset($this->outputChapterTextAtFirstVerse);
                             // Other export formats.
                             if ($this->onlinebible_text) {
                                 $this->onlinebible_text->newVerse($this->currentBookIdentifier, $this->currentChapterNumber, $this->currentVerseNumber);
                             }
                             if ($this->esword_text) {
                                 $this->esword_text->newVerse($this->currentVerseNumber);
                             }
                             // Done.
                             break;
                         case StyleTypeFootEndNote:
                             $this->processNote();
                             break;
                         case StyleTypeCrossreference:
                             $this->processNote();
                             break;
                         case StyleTypePeripheral:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             switch ($style['subtype']) {
                                 case PeripheralSubtypePublication:
                                 case PeripheralSubtypeTableOfContents:
                                 case PeripheralSubtypePreface:
                                 case PeripheralSubtypeIntroduction:
                                 case PeripheralSubtypeGlossary:
                                 case PeripheralSubtypeConcordance:
                                 case PeripheralSubtypeIndex:
                                 case PeripheralSubtypeMapIndex:
                                 case PeripheralSubtypeCover:
                                 case PeripheralSubtypeSpine:
                                 default:
                                     $this->addToFallout("Unknown pheripheral marker \\{$marker}", false);
                                     break;
                             }
                             break;
                         case StyleTypePicture:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             $this->addToFallout("Picture formatting not yet implemented", true);
                             break;
                         case StyleTypePageBreak:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->newPageBreak();
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->newPageBreak();
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->newPageBreak();
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->newPageBreak();
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->newPageBreak();
                             }
                             if (isset($this->text_text)) {
                                 $this->text_text->paragraph();
                             }
                             break;
                         case StyleTypeTableElement:
                             if ($this->odf_text_standard) {
                                 $this->odf_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_only) {
                                 $this->odf_text_text_only->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_text_and_note_citations) {
                                 $this->odf_text_text_and_note_citations->closeTextStyle(false, false);
                             }
                             if ($this->odf_text_notes) {
                                 $this->odf_text_notes->closeTextStyle(false, false);
                             }
                             if ($this->html_text_standard) {
                                 $this->html_text_standard->closeTextStyle(false, false);
                             }
                             if ($this->html_text_linked) {
                                 $this->html_text_linked->closeTextStyle(false, false);
                             }
                             switch ($style['subtype']) {
                                 case TableElementSubtypeRow:
                                     $this->addToFallout("Table elements not yet implemented", false);
                                     break;
                                 case TableElementSubtypeHeading:
                                 case TableElementSubtypeCell:
                                     $this->newParagraph($style, false);
                                     break;
                                 default:
                                     break;
                             }
                             // UserInt1TableColumnNumber:
                             break;
                         case StyleTypeWordlistElement:
                             switch ($style['subtype']) {
                                 case WorListElementSubtypeWordlistGlossaryDictionary:
                                     if ($isOpeningMarker) {
                                         $this->addToWordList($this->wordListGlossaryDictionary);
                                     }
                                     break;
                                 case WorListElementSubtypeHebrewWordlistEntry:
                                     if ($isOpeningMarker) {
                                         $this->addToWordList($this->hebrewWordList);
                                     }
                                     break;
                                 case WorListElementSubtypeGreekWordlistEntry:
                                     if ($isOpeningMarker) {
                                         $this->addToWordList($this->greekWordList);
                                     }
                                     break;
                                 case WorListElementSubtypeSubjectIndexEntry:
                                     if ($isOpeningMarker) {
                                         $this->addToWordList($this->subjectIndex);
                                     }
                                     break;
                                 default:
                                     if ($isOpeningMarker) {
                                         $this->addToFallout("Unknown word list marker \\{$marker}", false);
                                     }
                                     break;
                             }
                             // UserString1WordListEntryAddition:
                             break;
                         default:
                             // This marker is not yet implemented. Add to fallout, plus any text that follows.
                             $this->addToFallout("Marker not yet implemented \\{$marker}, possible formatting error:", true);
                             break;
                     }
                 } else {
                     // Here is an unknown marker. Add to fallout, plus any text that follows.
                     $this->addToFallout("Unknown marker \\{$marker}, formatting error:", true);
                 }
             } else {
                 // Here is no marker. Treat it as text.
                 if ($this->odf_text_standard) {
                     $this->odf_text_standard->addText($currentItem);
                 }
                 if ($this->odf_text_text_only) {
                     $this->odf_text_text_only->addText($currentItem);
                 }
                 if ($this->odf_text_text_and_note_citations) {
                     $this->odf_text_text_and_note_citations->addText($currentItem);
                 }
                 if ($this->html_text_standard) {
                     $this->html_text_standard->addText($currentItem);
                 }
                 if ($this->html_text_linked) {
                     $this->html_text_linked->addText($currentItem);
                 }
                 if ($this->onlinebible_text) {
                     $this->onlinebible_text->addText($currentItem);
                 }
                 if ($this->esword_text) {
                     $this->esword_text->addText($currentItem);
                 }
                 if (isset($this->text_text)) {
                     $this->text_text->text($currentItem);
                 }
                 if (is_array($this->verses_headings) && $this->heading_started) {
                     if (!isset($this->verses_headings[$this->currentVerseNumber])) {
                         $this->verses_headings[$this->currentVerseNumber] = "";
                     }
                     $this->verses_headings[$this->currentVerseNumber] .= $currentItem;
                 }
                 if (is_array($this->verses_text) && $this->text_started) {
                     if (isset($this->verses_text[$this->currentVerseNumber])) {
                         $this->verses_text[$this->currentVerseNumber] .= $currentItem;
                     } else {
                         // The verse text straight after the \v starts with an enSpace. Remove it.
                         $item = str_replace(Filter_Character::enSpace(), " ", $currentItem);
                         $this->verses_text[$this->currentVerseNumber] = ltrim($item);
                         unset($item);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private function process()
 {
     $this->markersAndTextPointer = 0;
     $markersAndTextCount = count($this->markersAndText);
     for ($this->markersAndTextPointer = 0; $this->markersAndTextPointer < $markersAndTextCount; $this->markersAndTextPointer++) {
         $currentItem = $this->markersAndText[$this->markersAndTextPointer];
         if (Filter_Usfm::isUsfmMarker($currentItem)) {
             // Store indicator whether the marker is an opening marker.
             $isOpeningMarker = Filter_Usfm::isOpeningMarker($currentItem);
             $isEmbeddedMarker = Filter_Usfm::isEmbeddedMarker($currentItem);
             // Clean up the marker, so we remain with the basic version, e.g. 'id'.
             $marker = Filter_Usfm::getMarker($currentItem);
             if (array_key_exists($marker, $this->styles)) {
                 $style = $this->styles[$marker];
                 switch ($style['type']) {
                     case StyleTypeIdentifier:
                     case StyleTypeNotUsedComment:
                     case StyleTypeNotUsedRunningHeader:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypeStartsParagraph:
                         $this->closeTextStyle(false, false);
                         $this->newParagraph($marker);
                         break;
                     case StyleTypeInlineText:
                         if ($isOpeningMarker) {
                             $this->openTextStyle($style, false, $isEmbeddedMarker);
                         } else {
                             $this->closeTextStyle(false, $isEmbeddedMarker);
                         }
                         break;
                     case StyleTypeChapterNumber:
                         $this->closeTextStyle(false, false);
                         $this->newParagraph($marker);
                         break;
                     case StyleTypeVerseNumber:
                         // Close any existing text style.
                         $this->closeTextStyle(false, false);
                         // Output the space before the verse number in case the paragraph already has some text.
                         if ($this->currentParagraphContent != "") {
                             $this->addText(" ");
                         }
                         // Open verse style, record verse/length, add verse number, close style again, and add a space.
                         $this->openTextStyle($style, false, false);
                         $textFollowingMarker = Filter_Usfm::getTextFollowingMarker($this->markersAndText, $this->markersAndTextPointer);
                         $number = Filter_Usfm::peekVerseNumber($textFollowingMarker);
                         $this->verseStartOffsets[intval($number)] = $this->textLength;
                         $this->addText($number);
                         $this->closeTextStyle(false, false);
                         $this->addText(" ");
                         // If there was any text following the \v marker, remove the verse number,
                         // put the remainder back into the object, and update the pointer.
                         if ($textFollowingMarker != "") {
                             $pos = strpos($textFollowingMarker, $number);
                             if ($pos !== false) {
                                 $textFollowingMarker = substr($textFollowingMarker, $pos + strlen($number));
                             }
                             $textFollowingMarker = ltrim($textFollowingMarker);
                             $this->markersAndText[$this->markersAndTextPointer] = $textFollowingMarker;
                             $this->markersAndTextPointer--;
                         }
                         break;
                     case StyleTypeFootEndNote:
                         switch ($style['subtype']) {
                             case FootEndNoteSubtypeFootnote:
                             case FootEndNoteSubtypeEndnote:
                                 $this->closeTextStyle(false, false);
                                 if ($isOpeningMarker) {
                                     $this->noteOpened = true;
                                     $caller = $this->noteCount % 9 + 1;
                                     $this->addNote($caller, $marker, false);
                                 } else {
                                     $this->closeCurrentNote();
                                     $this->noteOpened = false;
                                 }
                                 break;
                             case FootEndNoteSubtypeStandardContent:
                             case FootEndNoteSubtypeContent:
                             case FootEndNoteSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     $this->openTextStyle($style, true, $isEmbeddedMarker);
                                 } else {
                                     $this->closeTextStyle(true, $isEmbeddedMarker);
                                 }
                                 break;
                             case FootEndNoteSubtypeParagraph:
                             default:
                                 $this->closeTextStyle(false, false);
                                 break;
                         }
                         break;
                     case StyleTypeCrossreference:
                         switch ($style['subtype']) {
                             case CrossreferenceSubtypeCrossreference:
                                 $this->closeTextStyle(false, false);
                                 if ($isOpeningMarker) {
                                     $this->noteOpened = true;
                                     $caller = $this->noteCount % 9 + 1;
                                     $this->addNote($caller, $marker, false);
                                 } else {
                                     $this->closeCurrentNote();
                                     $this->noteOpened = false;
                                 }
                                 break;
                             case CrossreferenceSubtypeContent:
                             case CrossreferenceSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     $this->openTextStyle($style, true, $isEmbeddedMarker);
                                 } else {
                                     $this->closeTextStyle(true, $isEmbeddedMarker);
                                 }
                                 break;
                             case CrossreferenceSubtypeStandardContent:
                             default:
                                 // The style of the standard content is already used in the note's body.
                                 // Clear the text style to get the correct style for the note paragraph.
                                 $this->closeTextStyle(false, false);
                                 break;
                         }
                         break;
                     case StyleTypePeripheral:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypePicture:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypePageBreak:
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                     case StyleTypeTableElement:
                         $this->closeTextStyle(false, false);
                         switch ($style['subtype']) {
                             case TableElementSubtypeRow:
                                 $this->outputAsIs($marker, $isOpeningMarker);
                                 break;
                             case TableElementSubtypeHeading:
                             case TableElementSubtypeCell:
                                 $this->openTextStyle($style, false, false);
                                 break;
                             default:
                                 $this->openTextStyle($style, false, false);
                                 break;
                         }
                         break;
                     case StyleTypeWordlistElement:
                         if ($isOpeningMarker) {
                             $this->openTextStyle($style, false, false);
                         } else {
                             $this->closeTextStyle(false, false);
                         }
                         break;
                     default:
                         // This marker is known in the stylesheet, but not yet implemented here.
                         $this->closeTextStyle(false, false);
                         $this->outputAsIs($marker, $isOpeningMarker);
                         break;
                 }
             } else {
                 // This is a marker unknown in the stylesheet.
                 $this->closeTextStyle(false, false);
                 $this->outputAsIs($marker, $isOpeningMarker);
             }
         } else {
             // Here is no marker. Treat it as text.
             if ($this->noteOpened) {
                 $this->addNoteText($currentItem);
             } else {
                 $this->addText($currentItem);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public function testPeekVerseNumber()
 {
     $this->assertEquals("1", Filter_Usfm::peekVerseNumber("1"));
     $this->assertEquals("1", Filter_Usfm::peekVerseNumber("1 "));
     $this->assertEquals("1a", Filter_Usfm::peekVerseNumber("1a"));
     $this->assertEquals("2-3", Filter_Usfm::peekVerseNumber("2-3"));
     $this->assertEquals("2b,3", Filter_Usfm::peekVerseNumber("2b,3"));
     $this->assertEquals("2b,3,", Filter_Usfm::peekVerseNumber("2b,3, 4"));
     $this->assertEquals("2a-3b", Filter_Usfm::peekVerseNumber("2a-3b And he said"));
 }
Ejemplo n.º 4
0
 private function malformedVerseNumber()
 {
     if ($this->usfmItem == '\\v ') {
         $code = Filter_Usfm::peekTextFollowingMarker($this->usfmMarkersAndText, $this->usfmMarkersAndTextPointer);
         $cleanVerseNumber = Filter_Usfm::peekVerseNumber($code);
         $dirtyVerseNumber = explode(" ", $code);
         $dirtyVerseNumber = $dirtyVerseNumber[0];
         if ($cleanVerseNumber != $dirtyVerseNumber) {
             $this->addResult("Malformed verse number", Checks_Usfm::displayFull);
         }
     }
 }