Пример #1
0
// Prepares a sample Bible.
// The output of this is supposed to be manually put into the source tree, folder "samples".
// This will be used to quickly create a sample Bible, that is fast, even on mobile devices.
void demo_prepare_sample_bible ()
{
  Database_Bibles database_bibles;
  // Remove the Bible to remove all stuff that might have been in it.
  database_bibles.deleteBible (demo_sample_bible_name ());
  search_logic_delete_bible (demo_sample_bible_name ());
  // Create a new one.
  database_bibles.createBible (demo_sample_bible_name ());
  // Location of the USFM files for the sample Bible.
  string directory = filter_url_create_root_path ("demo");
  vector <string> files = filter_url_scandir (directory);
  for (auto file : files) {
    // Only process the USFM files.
    if (filter_url_get_extension (file) == "usfm") {
      cout << file << endl;
      // Read the USFM.
      file = filter_url_create_path (directory, file);
      string usfm = filter_url_file_get_contents (file);
      usfm = filter_string_str_replace ("  ", " ", usfm);
      // Import the USFM into the Bible.
      vector <BookChapterData> book_chapter_data = usfm_import (usfm, styles_logic_standard_sheet ());
      for (auto data : book_chapter_data) {
        Bible_Logic::storeChapter (demo_sample_bible_name (), data.book, data.chapter, data.data);
      }
    }
  }
  // Clean the destination location for the Bible.
  string destination = sample_bible_bible_path ();
  filter_url_rmdir (destination);
  // Copy the Bible data to the destination.
  string source = database_bibles.bibleFolder (demo_sample_bible_name ());
  filter_url_dir_cp (source, destination);
  // Clean the destination location for the Bible search index.
  destination = sample_bible_index_path ();
  filter_url_rmdir (destination);
  // Create destination location.
  filter_url_mkdir (destination);
  // Copy the index files over to the destination.
  source = search_logic_index_folder ();
  files = filter_url_scandir (source);
  for (auto file : files) {
    if (file.find (demo_sample_bible_name ()) != string::npos) {
      string source_file = filter_url_create_path (source, file);
      string destination_file = filter_url_create_path (destination, file);
      filter_url_file_cp (source_file, destination_file);
    }
  }
}
Пример #2
0
// Import the USFM in $data into $bible.
void bible_import_usfm (string data, string bible, int book, int chapter)
{
  if (book && chapter) {}
  string stylesheet = styles_logic_standard_sheet ();
  vector <BookChapterData> book_chapter_text = usfm_import (data, stylesheet);
  for (auto & data : book_chapter_text) {
    int book_number = data.book;
    int chapter_number = data.chapter;
    string chapter_data = data.data;
    if (book_number > 0) {
      bible_logic_store_chapter (bible, book_number, chapter_number, chapter_data);
      string book_name = Database_Books::getUsfmFromId (book_number);
      Database_Logs::log ("Imported " + book_name + " " + convert_to_string (chapter_number));
    } else {
      Database_Logs::log ("Could not import this data: " + chapter_data.substr (0, 1000));
    }
  }
}
Пример #3
0
string editusfm_save (void * webserver_request)
{
    Webserver_Request * request = (Webserver_Request *) webserver_request;


    string bible = request->post["bible"];
    int book = convert_to_int (request->post["book"]);
    int chapter = convert_to_int (request->post["chapter"]);
    string usfm = request->post["usfm"];
    string checksum = request->post["checksum"];


    if (request->post.count ("bible") && request->post.count ("book") && request->post.count ("chapter") && request->post.count ("usfm")) {
        if (Checksum_Logic::get (usfm) == checksum) {
            usfm = filter_url_tag_to_plus (usfm);
            usfm = filter_string_trim (usfm);
            if (usfm != "") {
                if (unicode_string_is_valid (usfm)) {
                    string stylesheet = request->database_config_user()->getStylesheet();
                    vector <BookChapterData> book_chapter_text = usfm_import (usfm, stylesheet);
                    for (BookChapterData & data : book_chapter_text) {
                        int book_number = data.book;
                        int chapter_number = data.chapter;
                        string chapter_data_to_save = data.data;
                        if (((book_number == book) || (book_number == 0)) && (chapter_number == chapter)) {
                            string ancestor_usfm = getLoadedUsfm (webserver_request, bible, book, chapter, "editusfm");
                            // Collect some data about the changes for this user.
                            string username = request->session_logic()->currentUser ();
                            int oldID = request->database_bibles()->getChapterId (bible, book, chapter);
                            string oldText = ancestor_usfm;
                            string newText = chapter_data_to_save;
                            // Merge if the ancestor is there and differs from what's in the database.
                            if (!ancestor_usfm.empty ()) {
                                string server_usfm = request->database_bibles ()->getChapter (bible, book, chapter);
                                if (server_usfm != ancestor_usfm) {
                                    // Prioritize the USFM to save.
                                    chapter_data_to_save = filter_merge_run (ancestor_usfm, server_usfm, chapter_data_to_save);
                                    Database_Logs::log (translate ("Merging and saving chapter."));
                                }
                            }
                            // Check on write access.
                            if (access_bible_book_write (request, "", bible, book)) {
                                // Safely store the chapter.
                                string message = usfm_safely_store_chapter (request, bible, book, chapter, chapter_data_to_save);
                                if (message.empty()) {
#ifndef CLIENT_PREPARED
                                    // Server configuration: Store details for the user's changes.
                                    int newID = request->database_bibles()->getChapterId (bible, book, chapter);
                                    Database_Modifications database_modifications;
                                    database_modifications.recordUserSave (username, bible, book, chapter, oldID, oldText, newID, newText);
                                    Database_Git::store_chapter (username, bible, book, chapter, oldText, newText);
#endif
                                    // Store a copy of the USFM loaded in the editor for later reference.
                                    storeLoadedUsfm (webserver_request, bible, book, chapter, "editusfm");
                                    return locale_logic_text_saved ();
                                }
                                return message;
                            } else {
                                return translate("No write access");
                            }
                        } else {
                            Database_Logs::log ("The following data could not be saved and was discarded: " + chapter_data_to_save);
                            return translate("Passage mismatch");
                        }
                    }
                } else {
                    Database_Logs::log ("The text was not valid Unicode UTF-8. The chapter could not saved and has been reverted to the last good version.");
                    return translate("Needs Unicode");
                }
            } else {
                Database_Logs::log ("There was no text. Nothing was saved. The original text of the chapter was reloaded.");
                return translate("Nothing to save");
            }
        } else {
            request->response_code = 409;
            return translate("Checksum error");
        }
    } else {
        return translate("Nothing to save");
    }
    return translate ("Confusing data");
}