Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * handleEmailNew - handles an email received from $from with subject $subject and body $body.
  * Returns true if the mail was processed, else false.
  * The email is considered to have been processed if it created a new Consultation Note.
  */
 public function handleEmailNew($from, $subject, $body)
 {
     // Store the original subject.
     $originalSubject = $subject;
     // Check that the subject indicates that a new consultation note is to be created.
     $pos = strpos(strtolower($subject), "new note");
     if ($pos === false) {
         return false;
     }
     // There is a new note. Remove that bit from the $subject.
     $subject = substr($subject, 0, $pos) . substr($subject, $pos + 8);
     // Clean the subject line.
     $subject = trim($subject);
     $subject = str_replace(".", " ", $subject);
     $subject = str_replace(":", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     // Check that the $from address of the email belongs to an existing user.
     $from = Filter_Email::extractEmail($from);
     $database_users = Database_Users::getInstance();
     if (!$database_users->emailExists($from)) {
         return false;
     }
     $username = $database_users->getEmailToUser($from);
     // Extract book, chapter, verse, and note summary from the $subject
     $book = NULL;
     $chapter = NULL;
     $verse = NULL;
     $summary = NULL;
     $subject = explode(" ", $subject);
     if (count($subject) > 0) {
         $book = Filter_Books::interpretBook($subject[0]);
     }
     if (count($subject) > 1) {
         $chapter = Filter_Numeric::integer_in_string($subject[1]);
     }
     if (count($subject) > 2) {
         $verse = Filter_Numeric::integer_in_string($subject[2]);
     }
     unset($subject[0]);
     unset($subject[1]);
     unset($subject[2]);
     $summary = implode(" ", $subject);
     unset($subject);
     // Check book, chapter, verse, and summary. Give feedback if there's anything wrong.
     $noteCheck = "";
     if (!(is_numeric($book) && $book > 0)) {
         $noteCheck .= Locale_Translate::_("Unknown book");
     }
     if (!is_numeric($chapter)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown chapter");
     }
     if (!is_numeric($verse)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown verse");
     }
     if ($summary == NULL || $summary == "") {
         $noteCheck .= " " . Locale_Translate::_("Unknown summary");
     }
     // Mail user if the note could not be posted.
     $database_mail = Database_Mail::getInstance();
     if ($noteCheck != "") {
         $subject = Locale_Translate::_("Your new note could not be posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $noteCheck);
         return false;
     }
     // Clean the email's body.
     $body = Filter_Email::extractBody($body);
     // Post the note.
     $session_logic = Session_Logic::getInstance();
     $sessionuser = $session_logic->currentUser();
     $session_logic->setUsername($username);
     $database_notes = Database_Notes::getInstance();
     $identifier = $database_notes->storeNewNote("", $book, $chapter, $verse, $summary, $body, false);
     $this->handlerNewNote($identifier);
     $session_logic->setUsername($sessionuser);
     // Mail confirmation to the $username.
     $database_config_user = Database_Config_User::getInstance();
     if ($database_config_user->getUserNotifyMeOfMyPosts($username)) {
         $subject = Locale_Translate::_("Your new note was posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $body);
     }
     // Log operation.
     $database_logs = Database_Logs::getInstance();
     $database_logs->log("New note posted" . ":" . " " . $body);
     // Job done.
     return true;
 }
Beispiel #3
0
 public static function explodePassage($text)
 {
     $text = Filter_Books::cleanPassage($text);
     // Cut the text in its parts.
     $text = explode(" ", $text);
     // Defaults to empty passage.
     $passage = array(0, 0, 0);
     // Take the bits.
     $verse = array_pop($text);
     if (isset($verse)) {
         $passage[2] = $verse;
     }
     $chapter = array_pop($text);
     if (isset($chapter)) {
         $passage[1] = $chapter;
     }
     $book = implode(" ", $text);
     if ($book != "") {
         $book = Filter_Books::interpretBook($book);
         $passage[0] = $book;
     }
     // Return the result.
     return $passage;
 }
Beispiel #4
0
 public function testInterpretBookPartialNames()
 {
     $this->assertEquals(1, Filter_Books::interpretBook("G"));
     $this->assertEquals(1, Filter_Books::interpretBook("g"));
     $this->assertEquals(1, Filter_Books::interpretBook("ge"));
     $this->assertEquals(1, Filter_Books::interpretBook("gene"));
     $this->assertEquals(46, Filter_Books::interpretBook("1 Cori"));
     $this->assertEquals(46, Filter_Books::interpretBook("1 cori"));
     $this->assertEquals(46, Filter_Books::interpretBook("1 corint"));
     $this->assertEquals(46, Filter_Books::interpretBook("1cor"));
     $this->assertEquals(22, Filter_Books::interpretBook("song"));
     $this->assertEquals(22, Filter_Books::interpretBook("song of"));
     $this->assertEquals(22, Filter_Books::interpretBook("song of sol"));
     $this->assertEquals(11, Filter_Books::interpretBook("1ki"));
 }