string resource_cache (void * webserver_request) { Webserver_Request * request = (Webserver_Request *) webserver_request; string resource = request->query ["resource"]; string page; Assets_Header header = Assets_Header (menu_logic_resources_text (), request); header.addBreadCrumb (menu_logic_settings_menu (), menu_logic_settings_text ()); page = header.run (); Assets_View view; if (request->query.count ("clear")) { sendreceive_resources_clear_all (); } vector <string> resources = Database_Config_General::getResourcesToCache (); if (!resources.empty ()) { view.enable_zone ("scheduled"); view.set_variable ("scheduled", filter_string_implode (resources, " | ")); } vector <string> listed_resources; string block; // Display the available USFM resources. resources = client_logic_usfm_resources_get (); for (auto & resource : resources) { block.append ("<p>"); block.append ("<a href=\"download?name=" + resource + "\">" + resource + "</a>"); block.append ("</p>\n"); } listed_resources.insert (listed_resources.end (), resources.begin (), resources.end ()); // Display the available external resources. resources = resource_external_names (); for (auto & resource : resources) { block.append ("<p>"); block.append ("<a href=\"download?name=" + resource + "\">" + resource + "</a>"); block.append ("</p>\n"); } listed_resources.insert (listed_resources.end (), resources.begin (), resources.end ()); // Display the available SWORD resources. resources = sword_logic_get_available (); for (auto & resource : resources) { string source = sword_logic_get_source (resource); string module = sword_logic_get_remote_module (resource); string name = "[" + source + "][" + module + "]"; block.append ("<p>"); block.append ("<a href=\"download?name=" + name + "\">" + resource + "</a>"); block.append ("</p>\n"); } listed_resources.insert (listed_resources.end (), resources.begin (), resources.end ()); // Display any old USFM resources still available on the client. Database_UsfmResources database_usfmresources; resources = database_usfmresources.getResources (); for (auto & resource : resources) { if (in_array (resource, listed_resources)) continue; block.append ("<p>"); block.append ("<a href=\"download?name=" + resource + "&old=yes\">" + resource + "</a>"); block.append ("</p>\n"); } // Display any offline resources still available on the client. Database_OfflineResources database_offlineresources; resources = database_offlineresources.names (); for (auto & resource : resources) { if (in_array (resource, listed_resources)) continue; block.append ("<p>"); block.append ("<a href=\"download?name=" + resource + "&old=yes\">" + resource + "</a>"); block.append ("</p>\n"); } // Display the list. view.set_variable ("block", block); page += view.render ("resource", "cache"); page += Assets_Page::footer (); return page; }
// This is the most basic version that fetches the text of a $resource. // It works on server and on client. // It uses the cache. string resource_logic_get_verse (void * webserver_request, string resource, int book, int chapter, int verse) { Webserver_Request * request = (Webserver_Request *) webserver_request; string data; Database_UsfmResources database_usfmresources; Database_ImageResources database_imageresources; // Lists of the various types of resources. // As from February 2016 a client no longer automatically downloads USFM resources from the Cloud. // But a client takes in account existing USFM resources it has downloaded before. vector <string> bibles = request->database_bibles()->getBibles (); vector <string> local_usfms = database_usfmresources.getResources (); vector <string> remote_usfms; if (config_logic_client_prepared ()) { remote_usfms = client_logic_usfm_resources_get (); } vector <string> externals = resource_external_names (); vector <string> images = database_imageresources.names (); vector <string> lexicons = lexicon_logic_resource_names (); // Possible SWORD details. string sword_module = sword_logic_get_remote_module (resource); string sword_source = sword_logic_get_source (resource); // Determine the type of the current resource. bool isBible = in_array (resource, bibles); bool isLocalUsfm = in_array (resource, local_usfms); bool isRemoteUsfm = in_array (resource, remote_usfms); bool isExternal = in_array (resource, externals); bool isImage = in_array (resource, images); bool isLexicon = in_array (resource, lexicons); bool isSword = (!sword_source.empty () && !sword_module.empty ()); if (isBible || isLocalUsfm) { string chapter_usfm; if (isBible) chapter_usfm = request->database_bibles()->getChapter (resource, book, chapter); if (isLocalUsfm) chapter_usfm = database_usfmresources.getUsfm (resource, book, chapter); string verse_usfm = usfm_get_verse_text (chapter_usfm, verse); string stylesheet = styles_logic_standard_sheet (); Filter_Text filter_text = Filter_Text (resource); filter_text.html_text_standard = new Html_Text (""); filter_text.addUsfmCode (verse_usfm); filter_text.run (stylesheet); data = filter_text.html_text_standard->getInnerHtml (); } else if (isRemoteUsfm) { data = resource_logic_client_fetch_cache_from_cloud (resource, book, chapter, verse); } else if (isExternal) { if (config_logic_client_prepared ()) { // A client fetches it from the cache or from the Cloud, // or, for older versions, from the offline resources database. // As of 12 December 2015, the offline resources database is not needed anymore. // It can be removed after a year or so. Database_OfflineResources database_offlineresources; if (database_offlineresources.exists (resource, book, chapter, verse)) { data = database_offlineresources.get (resource, book, chapter, verse); } else { data = resource_logic_client_fetch_cache_from_cloud (resource, book, chapter, verse); } } else { // The server fetches it from the web, via the http cache. data.append (resource_external_cloud_fetch_cache_extract (resource, book, chapter, verse)); } } else if (isImage) { vector <string> images = database_imageresources.get (resource, book, chapter, verse); for (auto & image : images) { data.append ("<div><img src=\"/resource/imagefetch?name=" + resource + "&image=" + image + "\" alt=\"Image resource\" style=\"width:100%\"></div>"); } } else if (isLexicon) { data = lexicon_logic_get_html (request, resource, book, chapter, verse); } else if (isSword) { data = sword_logic_get_text (sword_source, sword_module, book, chapter, verse); } else { // Nothing found. } // Any font size given in a paragraph style may interfere with the font size setting for the resources // as given in Bibledit. For that reason remove the class name from a paragraph style. for (unsigned int i = 0; i < 5; i++) { string fragment = "p class=\""; size_t pos = data.find (fragment); if (pos != string::npos) { size_t pos2 = data.find ("\"", pos + fragment.length () + 1); if (pos2 != string::npos) { data.erase (pos + 1, pos2 - pos + 1); } } } // NET Bible updates. data = filter_string_str_replace ("<span class=\"s ", "<span class=\"", data); return data; }
string resource_organize (void * webserver_request) { Webserver_Request * request = (Webserver_Request *) webserver_request; string checkbox = request->post ["checkbox"]; bool checked = convert_to_bool (request->post ["checked"]); if (request->query.count ("add") || request->post.count ("add")) { string add = request->query["add"]; if (add.empty ()) add = request->post ["add"]; vector <string> resources = request->database_config_user()->getActiveResources (); resources.push_back (add); request->database_config_user()->setActiveResources (resources); request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization); } if (request->query.count ("remove")) { size_t remove = convert_to_int (request->query["remove"]); vector <string> resources = request->database_config_user()->getActiveResources (); if (remove < resources.size ()) { resources.erase (resources.begin () + remove); } request->database_config_user()->setActiveResources (resources); request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization); } if (request->query.count ("moveup")) { size_t moveup = convert_to_int (request->query["moveup"]); vector <string> resources = request->database_config_user()->getActiveResources (); array_move_up_down (resources, moveup, true); request->database_config_user()->setActiveResources (resources); request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization); } if (request->query.count ("movedown")) { size_t movedown = convert_to_int (request->query["movedown"]); vector <string> resources = request->database_config_user()->getActiveResources (); array_move_up_down (resources, movedown, false); request->database_config_user()->setActiveResources (resources); request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization); } string page; Assets_Header header = Assets_Header (translate("Resources"), request); page = header.run (); Assets_View view; // Active resources. vector <string> active_resources = request->database_config_user()->getActiveResources (); string activesblock; for (size_t i = 0; i < active_resources.size (); i++) { activesblock.append ("<p>"); activesblock.append ("<a href=\"?remove=" + convert_to_string (i) + "\">"); activesblock.append (emoji_wastebasket ()); activesblock.append ("</a>"); activesblock.append (" "); activesblock.append ("<a href=\"?moveup=" + convert_to_string (i) + "\">"); activesblock.append (unicode_black_up_pointing_triangle ()); activesblock.append ("</a>"); activesblock.append ("<a href=\"?movedown=" + convert_to_string (i) + "\">"); activesblock.append (unicode_black_down_pointing_triangle ()); activesblock.append ("</a>"); activesblock.append (" "); activesblock.append (active_resources [i]); activesblock.append ("</p>"); activesblock.append ("\n"); } view.set_variable ("activesblock", activesblock); // Context before. if (request->query.count ("before")) { Dialog_Entry dialog_entry = Dialog_Entry ("organize", translate("Please enter the number of verses"), convert_to_string (request->database_config_user ()->getResourceVersesBefore ()), "before", translate ("How many verses of context to display before the focused verse.")); page += dialog_entry.run (); return page; } if (request->post.count ("before")) { int value = convert_to_int (request->post["entry"]); if ((value >= 0) && (value <= 100)) { request->database_config_user ()->setResourceVersesBefore (value); } } view.set_variable ("before", convert_to_string (request->database_config_user ()->getResourceVersesBefore ())); // Context after. if (request->query.count ("after")) { Dialog_Entry dialog_entry = Dialog_Entry ("organize", translate("Please enter the number of verses"), convert_to_string (request->database_config_user ()->getResourceVersesAfter ()), "after", translate ("How many verses of context to display after the focused verse.")); page += dialog_entry.run (); return page; } if (request->post.count ("after")) { int value = convert_to_int (request->post["entry"]); if ((value >= 0) && (value <= 100)) { request->database_config_user ()->setResourceVersesAfter (value); } } view.set_variable ("after", convert_to_string (request->database_config_user ()->getResourceVersesAfter ())); if (checkbox == "related") { request->database_config_user ()->setIncludeRelatedPassages (checked); return ""; } view.set_variable ("related", get_checkbox_status (request->database_config_user ()->getIncludeRelatedPassages ())); if (request->query.count ("install")) { vector <string> usfm_resources = client_logic_usfm_resources_get (); vector <string> original_language_resources = resource_external_get_original_language_resources (); vector <string> bible_resources = resource_external_get_bibles (); vector <string> commentary_resources = resource_external_get_commentaries (); vector <string> general_resources = resource_external_get_general_resources (); vector <string> sword_resources = sword_logic_get_available (); vector <string> installable_resources; installable_resources.insert (installable_resources.end (), usfm_resources.begin (), usfm_resources.end ()); installable_resources.insert (installable_resources.end (), original_language_resources.begin (), original_language_resources.end ()); installable_resources.insert (installable_resources.end (), bible_resources.begin (), bible_resources.end ()); installable_resources.insert (installable_resources.end (), commentary_resources.begin (), commentary_resources.end ()); installable_resources.insert (installable_resources.end (), general_resources.begin (), general_resources.end ()); installable_resources.insert (installable_resources.end (), sword_resources.begin (), sword_resources.end ()); vector <string> installing_resources = Database_Config_General::getResourcesToCache (); vector <string> active_resources = request->database_config_user()->getActiveResources (); for (auto & resource : active_resources) { if (in_array (resource, installable_resources)) { if (!in_array (resource, installing_resources)) { installing_resources.push_back (resource); Database_Config_General::setResourcesToCache (installing_resources); } } } tasks_logic_queue (SYNCRESOURCES); view.set_variable ("success", translate ("Will install the resources.") + " " + translate ("The journal displays the progress.")); } #ifdef HAVE_CLIENT view.enable_zone ("client"); #endif page += view.render ("resource", "organize"); page += Assets_Page::footer (); return page; }
string resource_logic_get_html (void * webserver_request, string resource, int book, int chapter, int verse, bool add_verse_numbers) { Webserver_Request * request = (Webserver_Request *) webserver_request; string html; Database_UsfmResources database_usfmresources; Database_ImageResources database_imageresources; Database_Mappings database_mappings; // Lists of the various types of resources. vector <string> bibles = request->database_bibles()->getBibles (); vector <string> usfms; if (config_logic_client_prepared ()) { usfms = client_logic_usfm_resources_get (); // As from February 2016 a client no longer automatically downloads USFM resources off the server. // But a client takes in account existing USFM resources it has downloaded before. vector <string> old_usfms = database_usfmresources.getResources (); usfms.insert (usfms.end (), old_usfms.begin (), old_usfms.end ()); } else { usfms = database_usfmresources.getResources (); } vector <string> externals = resource_external_names (); vector <string> images = database_imageresources.names (); vector <string> lexicons = lexicon_logic_resource_names (); // Possible SWORD details. string sword_module = sword_logic_get_remote_module (resource); string sword_source = sword_logic_get_source (resource); // Determine the type of the current resource. bool isBible = in_array (resource, bibles); bool isUsfm = in_array (resource, usfms); bool isExternal = in_array (resource, externals); bool isImage = in_array (resource, images); bool isLexicon = in_array (resource, lexicons); bool isSword = (!sword_source.empty () && !sword_module.empty ()); // Retrieve versification system of the active Bible. string bible = request->database_config_user ()->getBible (); string bible_versification = Database_Config_Bible::getVersificationSystem (bible); // Determine the versification system of the current resource. string resource_versification; if (isBible || isUsfm) { resource_versification = Database_Config_Bible::getVersificationSystem (bible); } else if (isExternal) { resource_versification = resource_external_mapping (resource); } else if (isImage) { } else if (isLexicon) { resource_versification = database_mappings.original (); if (resource == KJV_LEXICON_NAME) resource_versification = "English"; } else if (isSword) { resource_versification = "English"; } else { } // If the resource versification system differs from the Bible's versification system, // map the focused verse of the Bible to a verse in the Resource. // There are resources without versification system: Do nothing about them. vector <Passage> passages; if ((bible_versification != resource_versification) && !resource_versification.empty ()) { passages = database_mappings.translate (bible_versification, resource_versification, book, chapter, verse); } else { passages.push_back (Passage ("", book, chapter, convert_to_string (verse))); } // If there's been a mapping, the resource should include the verse number for clarity. if (passages.size () != 1) add_verse_numbers = true; for (auto passage : passages) { if (verse != convert_to_int (passage.verse)) { add_verse_numbers = true; } } for (auto passage : passages) { int book = passage.book; int chapter = passage.chapter; int verse = convert_to_int (passage.verse); string possible_included_verse; if (add_verse_numbers) possible_included_verse = convert_to_string (verse) + " "; if (isImage) possible_included_verse.clear (); html.append (resource_logic_get_verse (webserver_request, resource, book, chapter, verse)); } return html; }