Ejemplo n.º 1
0
        internal static string GetOriginalCopyrightAndLicenseNotice(BookData bookData, HtmlDom dom)
        {
            var originalMetadata = GetOriginalMetadata(dom, bookData);

            // As of BL-7898, we are using the existence of an original copyright/license to determine if we are working with a derivative.
            if (!IsDerivative(originalMetadata))
            {
                return(null);
            }

            // The originalTitle strategy used here is not ideal. We would prefer to have a placeholder specifically for it
            // in both EditTab.FrontMatter.OriginalCopyrightSentence and EditTab.FrontMatter.OriginalHadNoCopyrightSentence.
            // But we don't want to require a new set of translations if we can avoid it.
            var encodedTitle  = dom.GetBookSetting("originalTitle")?.GetExactAlternative("*");
            var originalTitle = HttpUtility.HtmlDecode(encodedTitle);

            var titleCitation = "<cite data-book=\"originalTitle\"" +
                                (string.IsNullOrEmpty(originalTitle) ? " class=\"missingOriginalTitle\">" : ">") + originalTitle +
                                "</cite>";

            var languagePriorityIdsNotLang1 = bookData.GetLanguagePrioritiesForLocalizedTextOnPage(false);
            var originalLicenseSentence     = GetOriginalLicenseSentence(languagePriorityIdsNotLang1, originalMetadata.License, out string licenseOnly);

            var rawCopyright = originalMetadata.CopyrightNotice;
            // If we have all the pieces available, we want to use this one.
            // At the very least it's easier to localize into the format the language wants to use.
            var fullFormatString = LocalizationManager.GetString(
                "EditTab.FrontMatter.FullOriginalCopyrightLicenseSentence",
                "Adapted from original, {0}, {1}. Licensed under {2}.",
                "On the Credits page of a book being translated, Bloom shows the original copyright. {0} is original title, {1} is original copyright, and {2} is license information.",
                languagePriorityIdsNotLang1,
                out string langUsed);

            // The last condition here (langUsed ==...) is meant to detect if the string has been translated
            // into the current language or not.
            if (!string.IsNullOrEmpty(originalTitle) && !string.IsNullOrEmpty(rawCopyright) &&
                !string.IsNullOrEmpty(licenseOnly) && langUsed == languagePriorityIdsNotLang1.First())
            {
                return(string.Format(fullFormatString, titleCitation, rawCopyright, licenseOnly));
            }
            var copyrightNotice = GetOriginalCopyrightSentence(
                languagePriorityIdsNotLang1,
                rawCopyright,
                titleCitation).Trim();

            return((copyrightNotice + " " + originalLicenseSentence).Trim());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Propagating the copyright and license information in the bloomDataDiv to template fields
        /// found in the pages of the book (normally just the credits page).
        /// </summary>
        /// <remarks>This is "internal" just as a convention, that it is accessible for testing purposes only</remarks>
        internal static void UpdateDomFromDataDiv(HtmlDom dom, string bookFolderPath, BookData bookData, bool useOriginalCopyright)
        {
            CopyItemToFieldsInPages(dom, "copyright");
            CopyItemToFieldsInPages(dom, "licenseUrl");
            CopyItemToFieldsInPages(dom, "licenseDescription", languagePreferences: bookData.GetLanguagePrioritiesForLocalizedTextOnPage().ToArray());
            CopyItemToFieldsInPages(dom, "licenseNotes");
            CopyItemToFieldsInPages(dom, "licenseImage", valueAttribute: "src");
            // If we're using the original copyright, we don't need to show it separately.
            // See https://issues.bloomlibrary.org/youtrack/issue/BL-7381.
            CopyStringToFieldsInPages(dom, "originalCopyrightAndLicense",
                                      useOriginalCopyright ? null : GetOriginalCopyrightAndLicenseNotice(bookData, dom), "*");

            if (!String.IsNullOrEmpty(bookFolderPath))             //unit tests may not be interested in checking this part
            {
                UpdateBookLicenseIcon(GetMetadata(dom, bookData), bookFolderPath);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Call this when we have a new set of metadata to use. It
        /// 1) sets the bloomDataDiv with the data,
        /// 2) causes any template fields in the book to get the new values
        /// 3) updates the license image on disk
        /// </summary>
        public static void SetMetadata(Metadata metadata, HtmlDom dom, string bookFolderPath, BookData bookData,
                                       bool useOriginalCopyright)
        {
            dom.SetBookSetting("copyright", "*", ConvertNewLinesToHtmlBreaks(metadata.CopyrightNotice));
            dom.SetBookSetting("licenseUrl", "*", metadata.License.Url);
            // This is for backwards compatibility. The book may have  licenseUrl in 'en' created by an earlier version of Bloom.
            // For backwards compatibility, GetMetaData will read that if it doesn't find a '*' license first. So now that we're
            // setting a licenseUrl for '*', we must make sure the 'en' one is gone, because if we're setting a non-CC license,
            // the new URL will be empty and the '*' one will go away, possibly exposing the 'en' one to be used by mistake.
            // See BL-3166.
            dom.SetBookSetting("licenseUrl", "en", null);
            string languageUsedForDescription;

            //This part is unfortunate... the license description, which is always localized, doesn't belong in the datadiv; it
            //could instead just be generated when we update the page. However, for backwards compatibility (prior to 3.6),
            //we localize it and place it in the datadiv.
            dom.RemoveBookSetting("licenseDescription");
            var description = metadata.License.GetDescription(bookData.GetLanguagePrioritiesForLocalizedTextOnPage(), out languageUsedForDescription);

            dom.SetBookSetting("licenseDescription", languageUsedForDescription, ConvertNewLinesToHtmlBreaks(description));

            // Book may have old licenseNotes, typically in 'en'. This can certainly show up again if licenseNotes in '*' is removed,
            // and maybe anyway. Safest to remove it altogether if we are setting it using the new scheme.
            dom.RemoveBookSetting("licenseNotes");
            dom.SetBookSetting("licenseNotes", "*", ConvertNewLinesToHtmlBreaks(metadata.License.RightsStatement));

            // we could do away with licenseImage in the bloomDataDiv, since the name is always the same, but we keep it for backward compatibility
            if (metadata.License is CreativeCommonsLicense)
            {
                dom.SetBookSetting("licenseImage", "*", "license.png");
            }
            else
            {
                //CC licenses are the only ones we know how to show an image for
                dom.RemoveBookSetting("licenseImage");
            }

            UpdateDomFromDataDiv(dom, bookFolderPath, bookData, useOriginalCopyright);
        }