Exemple #1
0
// This runs on the server.
// It gets the html or text contents for a $resource for serving it to a client.
string resource_logic_get_contents_for_client (string resource, int book, int chapter, int verse)
{
  // Lists of the various types of resources.
  Database_UsfmResources database_usfmresources;
  vector <string> externals = resource_external_names ();
  vector <string> usfms = database_usfmresources.getResources ();
  
  // Possible SWORD details in case the client requests a SWORD resource.
  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 isExternal = in_array (resource, externals);
  bool isUsfm = in_array (resource, usfms);
  bool isSword = (!sword_source.empty () && !sword_module.empty ());
  
  if (isExternal) {
    // The server fetches it from the web.
    return resource_external_cloud_fetch_cache_extract (resource, book, chapter, verse);
  }
  
  if (isUsfm) {
    // Fetch from database and convert to html.
    string 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);
    return filter_text.html_text_standard->getInnerHtml ();
  }
  
  if (isSword) {
    // Fetch it from a SWORD module.
    return sword_logic_get_text (sword_source, sword_module, book, chapter, verse);
  }

  // Nothing found.
  return "Bibledit Cloud could not localize this resource";
}
Exemple #2
0
// Checks the installed modules, whether they need to be updated.
void sword_logic_update_installed_modules ()
{
  Database_Logs::log ("Updating installed SWORD modules");

  vector <string> available_modules = sword_logic_get_available ();

  vector <string> installed_modules = sword_logic_get_installed ();
  for (auto & installed_module : installed_modules) {
    string module = sword_logic_get_installed_module (installed_module);
    string installed_version = sword_logic_get_version (installed_module);
    for (auto & available_module : available_modules) {
      if (sword_logic_get_remote_module (available_module) == module) {
        if (sword_logic_get_version (available_module) != installed_version) {
          string source = sword_logic_get_source (available_module);
          // Uninstall module.
          sword_logic_uninstall_module (module);
          // Clear the cache.
          Database_Versifications database_versifications;
          vector <int> books = database_versifications.getMaximumBooks ();
          for (auto & book : books) {
            vector <int> chapters = database_versifications.getMaximumChapters (book);
            for (auto & chapter : chapters) {
              vector <int> verses = database_versifications.getMaximumVerses (book, chapter);
              for (auto & verse : verses) {
                string schema = sword_logic_virtual_url (module, book, chapter, verse);
                database_filebased_cache_remove (schema);
              }
            }
          }
          // Schedule module installation.
          sword_logic_install_module_schedule (source, module);
        }
        continue;
      }
    }
  }
  
  Database_Logs::log ("Ready updating installed SWORD modules");
}
Exemple #3
0
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;
}
Exemple #4
0
// 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;
}
Exemple #5
0
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;
}
Exemple #6
0
string resource_sword (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  
  if (request->query.count ("refresh")) {
    tasks_logic_queue (REFRESHSWORDMODULES);
    redirect_browser (request, journal_index_url ());
  }

  
  if (request->query.count ("update")) {
    tasks_logic_queue (UPDATESWORDMODULES, {});
    redirect_browser (request, journal_index_url ());
  }
  
  
  /*
   It used to be possible to manually install or uninstall SWORD modules.
   However it was observed that on the open Bibledit demo, 
   there were bursts of installed SWORD modules.
   That made Bibledit unresponsive or just get stuck.
   Likely the web crawlers of the search engines click all links to install all modules.
   The answer to this problem was to remove manual install or uninstall of SWORD modules.
   */
  
  
  string page;
  Assets_Header header = Assets_Header (translate("Resources"), request);
  header.addBreadCrumb (menu_logic_settings_menu (), menu_logic_settings_text ());
  page = header.run ();
  Assets_View view;

  
  map <string, string> installed_modules;
  {
    vector <string> modules = sword_logic_get_installed ();
    for (auto module : modules) {
      string name = sword_logic_get_installed_module (module);
      string version = sword_logic_get_version (module);
      installed_modules [name] = version;
    }
  }
  
  vector <string> available_modules = sword_logic_get_available ();
  string moduleblock;
  for (auto & available_module : available_modules) {
    string source = sword_logic_get_source (available_module);
    string module = sword_logic_get_remote_module (available_module);
    moduleblock.append ("<p>");
    moduleblock.append (available_module);
    if (!installed_modules [module].empty ()) {
      moduleblock.append (" (" + translate ("installed") + ") ");
      string version = sword_logic_get_version (available_module);
      if (version != installed_modules[module]) {
        moduleblock.append (" (" + translate ("to be updated") + ")");
      }
    }
    moduleblock.append ("</p>\n");
  }
  view.set_variable ("moduleblock", moduleblock);

  
#ifdef HAVE_CLIENT
  view.enable_zone ("client");
#else
  view.enable_zone ("server");
#endif
  
  
  page += view.render ("resource", "sword");
  page += Assets_Page::footer ();
  return page;
}