/** * Imports BibleWorks $data as USFM code. * This is $data fit for the BibleWorks Version Database Compiler. * It a string of USFM code. * $keepTags: Whether to keep the grammatical tags in the BibleWorks text. * These are the tags between () or <>. */ public static function import($data, $keepTags) { // Databases. $database_books = Database_Books::getInstance(); // Storage for the generated USFM. $usfm = array(); // The data comes as one string. Make it an array. $data = explode("\n", $data); // Book / chapter trackers. $currentBibleWorksBookAbbreviation = ""; $currentChapter = 0; // Go through each line of data to be imported. foreach ($data as $line) { $line = trim($line); // Get the name of the book and remove the text fragment. // Upon encountering a new book, it generates USFM code for it. $bookAbbreviation = substr($line, 0, 3); $line = substr($line, 3, 10000); $line = trim($line); if ($bookAbbreviation != $currentBibleWorksBookAbbreviation) { $currentBibleWorksBookAbbreviation = $bookAbbreviation; $currentChapter = 0; $bookID = Filter_Books::interpretBook($bookAbbreviation); $book = $database_books->getUsfmFromId($bookID); $usfm[] = '\\id ' . $book; } // Get the chapter number and remove the text fragment. // Upon encountering a new chapter, it generates USFM code for it. $chapter = (int) $line; $line = substr($line, strlen($chapter) + 1, 10000); $line = trim($line); if ($chapter != $currentChapter) { $currentChapter = $chapter; $usfm[] = '\\c ' . $currentChapter; $usfm[] = '\\p'; } // Get the verse number and remove the text fragment and whitespace. $verse = (int) $line; $line = substr($line, strlen($verse), 10000); $line = trim($line); // Convert markup for italics and footnotes. $line = Filter_Bibleworks::italics($line); $line = Filter_Bibleworks::notes($line); // Deal with the grammatical tags. if (!$keepTags) { $malformed = array(); $line = Filter_Bibleworks::parenthesis($line, $malformed); $line = Filter_Bibleworks::chevrons($line, $malformed); } // Output the verse. $usfm[] = '\\v ' . $verse . ' ' . $line; } $usfm = implode("\n", $usfm); return $usfm; }
public function testItalics5() { $data = Filter_Bibleworks::italics("Mal]formed [italics]."); $this->assertEquals($data, 'Mal]formed \\add italics\\add*.'); }