예제 #1
0
파일: notes.php 프로젝트: alerque/bibledit
 /**
  * This imports one note from Bibledit-Gtk.
  * The note is available in $filename.
  * It returns the identifier of the note if imported successfully.
  * Else it returns NULL.
  */
 public static function importFromBibleditGtkFile($filename)
 {
     $note_identifier = NULL;
     if (file_exists($filename)) {
         // The note is in the format as used by Bibledit-Gtk.
         // The filename represents the note ID in Bibledit-Gtk.
         // This ID is not relevant for import.
         // Read the note.
         $note = file($filename);
         // line 0: date created.
         // This information is not used here. The same information will be in the logbook entries, see later.
         // line 1: user who created it.
         // This information is not used here. The same information will be in the logbook entries, see later.
         // line 2: note references.
         // Sample: Exod.29.23
         // Sample: Lev.26.16 Deut.28.22
         // It uses OSIS for book encoding.
         $passages = array();
         foreach (explode(" ", trim($note[2])) as $bibledit_gtk_reference) {
             $passages[] = Filter_Books::explodePassage($bibledit_gtk_reference);
         }
         // line 3: note category.
         $category = trim($note[3]);
         // line 4: Bible.
         $bible = trim($note[4]);
         // line 5: date modified.
         // This information is list since the note will be modified upon import.
         // line 6 and up: note text, "Logbook:", and logbook entries.
         // Summary will be taken from the first line.
         $summary = trim($note[6]);
         $contents = "";
         for ($i = 6; $i < count($note); $i++) {
             $contents .= $note[$i] . "\n";
         }
         // Store note.
         // (In client mode, upon sync to the server, these notes will be erased: Import them on the server).
         $database_notes = Database_Notes::getInstance();
         $note_identifier = $database_notes->storeNewNote($bible, 0, 0, 0, $summary, $contents, true);
         $database_notes->setPassages($note_identifier, $passages, true);
         $database_notes->setStatus($note_identifier, $category, true);
     }
     return $note_identifier;
 }
예제 #2
0
파일: books.php 프로젝트: alerque/bibledit
 public static function interpretPassage($currentPassage, $rawPassage)
 {
     $rawPassage = Filter_Books::cleanPassage($rawPassage);
     // Create an array with the bits of the raw input.
     $input = explode(" ", $rawPassage);
     // Go through the array from verse to chapter to book.
     // Check how many numerals it has after the book part.
     $numerals = array();
     $book = "";
     $invertedInput = array_reverse($input);
     foreach ($invertedInput as $bit) {
         if (Filter_Numeric::integer_in_string($bit) != "") {
             $numerals[] = $bit;
             array_pop($input);
         } else {
             $book = implode(" ", $input);
             break;
         }
     }
     // Deal with: Only book given, e.g. "Genesis".
     if ($book != "" && count($numerals) == 0) {
         return Filter_Books::explodePassage("{$book} 1 1");
     } else {
         if ($book == "" && count($numerals) == 1) {
             $book = $currentPassage[0];
             $chapter = $currentPassage[1];
             $verse = $numerals[0];
             $passage = Filter_Books::explodePassage("Unknown {$chapter} {$verse}");
             $passage[0] = $book;
             return $passage;
         } else {
             if ($book == "" && count($numerals) == 2) {
                 $book = $currentPassage[0];
                 $chapter = $numerals[1];
                 $verse = $numerals[0];
                 $passage = Filter_Books::explodePassage("Unknown {$chapter} {$verse}");
                 $passage[0] = $book;
                 return $passage;
             } else {
                 if ($book != "" && count($numerals) == 1) {
                     $chapter = $numerals[0];
                     return Filter_Books::explodePassage("{$book} {$chapter} 1");
                 } else {
                     if ($book != "" && count($numerals) == 2) {
                         return Filter_Books::explodePassage($rawPassage);
                     }
                 }
             }
         }
     }
     // Give up.
     return $currentPassage;
 }
예제 #3
0
 public function testExplodePassage()
 {
     $this->assertEquals(array(1, 2, 2), Filter_Books::explodePassage("Genesis 2:2"));
     $this->assertEquals(array(46, 2, 2), Filter_Books::explodePassage("1 Corinth. 2:2"));
     $this->assertEquals(array(22, 2, 2), Filter_Books::explodePassage("Song of Sol. 2:2"));
     $this->assertEquals(array(66, 2, 2), Filter_Books::explodePassage("Revelation 2:2"));
 }