Ejemplo n.º 1
0
 /**
  * This function does the processing of the USFM code for one note,
  * formatting the document and extracting information.
  */
 private function processNote()
 {
     for (; $this->chapterUsfmMarkersAndTextPointer < count($this->chapterUsfmMarkersAndText); $this->chapterUsfmMarkersAndTextPointer++) {
         $currentItem = $this->chapterUsfmMarkersAndText[$this->chapterUsfmMarkersAndTextPointer];
         if (Filter_Usfm::isUsfmMarker($currentItem)) {
             // Flags about the nature of 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. 'f'.
             $marker = Filter_Usfm::getMarker($currentItem);
             if (array_key_exists($marker, $this->styles)) {
                 $style = $this->styles[$marker];
                 switch ($style['type']) {
                     case StyleTypeVerseNumber:
                         // Verse found. The note should have stopped here. Incorrect note markup.
                         $this->addToFallout("The note did not close at the end of the verse. The text is not correct.", false);
                         break 2;
                     case StyleTypeFootEndNote:
                         switch ($style['subtype']) {
                             case FootEndNoteSubtypeFootnote:
                                 if ($isOpeningMarker) {
                                     $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerFootEndNote]);
                                     $citation = $this->getNoteCitation($style);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addNote($citation, $marker);
                                     }
                                     // Note citation in superscript in the document with text and note citations.
                                     if ($this->odf_text_text_and_note_citations) {
                                         $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle;
                                         $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript");
                                         $this->odf_text_text_and_note_citations->addText($citation);
                                         $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle;
                                     }
                                     // Add space if the paragraph has text already.
                                     if ($this->odf_text_notes) {
                                         if ($this->odf_text_notes->currentParagraphContent != "") {
                                             $this->odf_text_notes->addText(" ");
                                         }
                                     }
                                     // Add the note citation. And a no-break space after it.
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->addText($citation . Filter_Character::noBreakSpace());
                                     }
                                     // Open note in the web pages.
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->addNote($citation, $this->standardContentMarkerFootEndNote);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->addNote($citation, $this->standardContentMarkerFootEndNote);
                                     }
                                     // Online Bible. Footnotes do not seem to behave as they ought in the Online Bible compiler.
                                     // Just take them out, then.
                                     //if ($this->onlinebible_text) $this->onlinebible_text->addNote ();
                                 } else {
                                     break 3;
                                 }
                                 break;
                             case FootEndNoteSubtypeEndnote:
                                 if ($isOpeningMarker) {
                                     $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerFootEndNote]);
                                     $citation = $this->getNoteCitation($style);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addNote($citation, $marker, true);
                                     }
                                     // Note citation in superscript in the document with text and note citations.
                                     if ($this->odf_text_text_and_note_citations) {
                                         $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle;
                                         $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript");
                                         $this->odf_text_text_and_note_citations->addText($citation);
                                         $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle;
                                     }
                                     // Open note in the web page.
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->addNote($citation, $this->standardContentMarkerFootEndNote, true);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->addNote($citation, $this->standardContentMarkerFootEndNote, true);
                                     }
                                     // Online Bible.
                                     //if ($this->onlinebible_text) $this->onlinebible_text->addNote ();
                                 } else {
                                     break 3;
                                 }
                                 break;
                             case FootEndNoteSubtypeStandardContent:
                                 // The style of the standard content is already used in the note's body.
                                 // If means that the text style should be cleared
                                 // in order to return to the correct style for the paragraph.
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->odf_text_notes) {
                                     $this->odf_text_notes->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(true, false);
                                 }
                                 break;
                             case FootEndNoteSubtypeContent:
                             case FootEndNoteSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->openTextStyle($style, false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                 } else {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->closeTextStyle(false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                 }
                                 break;
                             case FootEndNoteSubtypeParagraph:
                                 // The style of this is not yet implemented.
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->odf_text_notes) {
                                     $this->odf_text_notes->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(true, false);
                                 }
                                 break;
                             default:
                                 break;
                         }
                         // UserBool1NoteAppliesToApocrypha: For xref too?
                         break;
                     case StyleTypeCrossreference:
                         switch ($style['subtype']) {
                             case CrossreferenceSubtypeCrossreference:
                                 if ($isOpeningMarker) {
                                     $this->ensureNoteParagraphStyle($marker, $this->styles[$this->standardContentMarkerCrossReference]);
                                     $citation = $this->getNoteCitation($style);
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->addNote($citation, $marker);
                                     }
                                     // Note citation in superscript in the document with text and note citations.
                                     if ($this->odf_text_text_and_note_citations) {
                                         $currentTextStyle = $this->odf_text_text_and_note_citations->currentTextStyle;
                                         $this->odf_text_text_and_note_citations->currentTextStyle = array("superscript");
                                         $this->odf_text_text_and_note_citations->addText($citation);
                                         $this->odf_text_text_and_note_citations->currentTextStyle = $currentTextStyle;
                                     }
                                     // Add a space if the paragraph has text already.
                                     if ($this->odf_text_notes) {
                                         if ($this->odf_text_notes->currentParagraphContent != "") {
                                             $this->odf_text_notes->addText(" ");
                                         }
                                     }
                                     // Add the note citation. And a no-break space (NBSP) after it.
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->addText($citation . Filter_Character::noBreakSpace());
                                     }
                                     // Open note in the web page.
                                     $this->ensureNoteParagraphStyle($this->standardContentMarkerCrossReference, $this->styles[$this->standardContentMarkerCrossReference]);
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->addNote($citation, $this->standardContentMarkerCrossReference);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->addNote($citation, $this->standardContentMarkerCrossReference);
                                     }
                                     // Online Bible.
                                     //if ($this->onlinebible_text) $this->onlinebible_text->addNote ();
                                 } else {
                                     break 3;
                                 }
                                 break;
                             case CrossreferenceSubtypeStandardContent:
                                 // The style of the standard content is already used in the note's body.
                                 // If means that the text style should be cleared
                                 // in order to return to the correct style for the paragraph.
                                 if ($this->odf_text_standard) {
                                     $this->odf_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->odf_text_notes) {
                                     $this->odf_text_notes->closeTextStyle(false, false);
                                 }
                                 if ($this->html_text_standard) {
                                     $this->html_text_standard->closeTextStyle(true, false);
                                 }
                                 if ($this->html_text_linked) {
                                     $this->html_text_linked->closeTextStyle(true, false);
                                 }
                                 break;
                             case CrossreferenceSubtypeContent:
                             case CrossreferenceSubtypeContentWithEndmarker:
                                 if ($isOpeningMarker) {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->openTextStyle($style, false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->openTextStyle($style, true, $isEmbeddedMarker);
                                     }
                                 } else {
                                     if ($this->odf_text_standard) {
                                         $this->odf_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->odf_text_notes) {
                                         $this->odf_text_notes->closeTextStyle(false, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_standard) {
                                         $this->html_text_standard->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                     if ($this->html_text_linked) {
                                         $this->html_text_linked->closeTextStyle(true, $isEmbeddedMarker);
                                     }
                                 }
                                 break;
                             default:
                                 break;
                         }
                         break;
                     default:
                         $this->addToFallout("Marker not suitable in note context \\{$marker}", false);
                         break;
                 }
             } else {
                 // Here is an unknown marker. Add the marker to fallout, plus any text that follows.
                 $this->addToFallout("Unknown marker \\{$marker}", true);
             }
         } else {
             // Here is no marker. Treat it as text.
             if ($this->odf_text_standard) {
                 $this->odf_text_standard->addNoteText($currentItem);
             }
             if ($this->odf_text_notes) {
                 $this->odf_text_notes->addText($currentItem);
             }
             if ($this->html_text_standard) {
                 $this->html_text_standard->addNoteText($currentItem);
             }
             if ($this->html_text_linked) {
                 $this->html_text_linked->addNoteText($currentItem);
             }
         }
     }
     // "Close" the current note, so that any following note text, if malformed,
     // will be added to a new note, not to the last one created.
     if ($this->odf_text_standard) {
         $this->odf_text_standard->closeCurrentNote();
     }
     if ($this->odf_text_notes) {
         $this->odf_text_notes->closeTextStyle(false, false);
     }
     if ($this->html_text_standard) {
         $this->html_text_standard->closeCurrentNote();
     }
     if ($this->html_text_linked) {
         $this->html_text_linked->closeCurrentNote();
     }
     //if ($this->onlinebible_text) $this->onlinebible_text->closeCurrentNote ();
 }
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 testIsUsfmMarker()
 {
     $this->assertTrue(Filter_Usfm::isUsfmMarker('\\id'));
     $this->assertTrue(Filter_Usfm::isUsfmMarker('\\c '));
     $this->assertFalse(Filter_Usfm::isUsfmMarker('c'));
     $this->assertTrue(Filter_Usfm::isUsfmMarker('\\add '));
     $this->assertTrue(Filter_Usfm::isUsfmMarker('\\add*'));
     $this->assertTrue(Filter_Usfm::isUsfmMarker('\\+add*'));
 }
Ejemplo n.º 4
0
 public function check($usfm)
 {
     $this->newLineInUsfm($usfm);
     $this->forwardSlash($usfm);
     $this->usfmMarkersAndText = Filter_Usfm::getMarkersAndText($usfm);
     for ($this->usfmMarkersAndTextPointer = 0; $this->usfmMarkersAndTextPointer < count($this->usfmMarkersAndText); $this->usfmMarkersAndTextPointer++) {
         $this->usfmItem = $this->usfmMarkersAndText[$this->usfmMarkersAndTextPointer];
         if (Filter_Usfm::isUsfmMarker($this->usfmItem)) {
             // Get the current verse number.
             if ($this->usfmItem == '\\v ') {
                 $verseCode = Filter_Usfm::peekTextFollowingMarker($this->usfmMarkersAndText, $this->usfmMarkersAndTextPointer);
                 $this->verseNumber = Filter_Usfm::peekVerseNumber($verseCode);
             }
             $this->malformedVerseNumber();
             $this->markerInStylesheet();
             $this->malformedId();
             $this->widowBackSlash();
             $this->matchingEndmarker();
         } else {
         }
     }
 }