diff --git a/src/addons/filter/multilang/services/handlers/multilang.ts b/src/addons/filter/multilang/services/handlers/multilang.ts index 6824e5d4a..518f12f1d 100644 --- a/src/addons/filter/multilang/services/handlers/multilang.ts +++ b/src/addons/filter/multilang/services/handlers/multilang.ts @@ -40,8 +40,8 @@ export class AddonFilterMultilangHandlerService extends CoreFilterDefaultHandler */ async filter( text: string, - filter: CoreFilterFilter, // eslint-disable-line @typescript-eslint/no-unused-vars - options: CoreFilterFormatTextOptions, // eslint-disable-line @typescript-eslint/no-unused-vars + filter?: CoreFilterFilter, // eslint-disable-line @typescript-eslint/no-unused-vars + options?: CoreFilterFormatTextOptions, // eslint-disable-line @typescript-eslint/no-unused-vars siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars ): Promise { let language = await CoreLang.getCurrentLanguage(); diff --git a/src/addons/notifications/services/notifications.ts b/src/addons/notifications/services/notifications.ts index 38bd4b982..ed445daf1 100644 --- a/src/addons/notifications/services/notifications.ts +++ b/src/addons/notifications/services/notifications.ts @@ -19,7 +19,6 @@ import { CoreWSExternalWarning } from '@services/ws'; import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUser } from '@features/user/services/user'; -import { AddonMessages, AddonMessagesMarkMessageReadResult } from '@addons/messages/services/messages'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreLogger } from '@singletons/logger'; import { makeSingleton } from '@singletons'; @@ -320,7 +319,7 @@ export class AddonNotificationsProvider { async markNotificationRead( notificationId: number, siteId?: string, - ): Promise { + ): Promise { const site = await CoreSites.getSite(siteId); diff --git a/src/core/constants.ts b/src/core/constants.ts index 255be2450..37a8b370f 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -59,7 +59,6 @@ export class CoreConstants { static readonly SETTINGS_NOTIFICATION_SOUND = 'CoreSettingsNotificationSound'; static readonly SETTINGS_SYNC_ONLY_ON_WIFI = 'CoreSettingsSyncOnlyOnWifi'; static readonly SETTINGS_DEBUG_DISPLAY = 'CoreSettingsDebugDisplay'; - static readonly SETTINGS_REPORT_IN_BACKGROUND = 'CoreSettingsReportInBackground'; // @deprecated since 3.5.0 static readonly SETTINGS_SEND_ON_ENTER = 'CoreSettingsSendOnEnter'; static readonly SETTINGS_ZOOM_LEVEL = 'CoreSettingsZoomLevel'; static readonly SETTINGS_COLOR_SCHEME = 'CoreSettingsColorScheme'; diff --git a/src/core/pipes/pipes.module.ts b/src/core/pipes/pipes.module.ts index a45223af7..b8b197300 100644 --- a/src/core/pipes/pipes.module.ts +++ b/src/core/pipes/pipes.module.ts @@ -22,7 +22,6 @@ import { CoreFormatDatePipe } from './format-date'; import { CoreNoTagsPipe } from './no-tags'; import { CoreSecondsToHMSPipe } from './seconds-to-hms'; import { CoreTimeAgoPipe } from './time-ago'; -import { CoreToLocaleStringPipe } from './to-locale-string'; @NgModule({ declarations: [ @@ -34,7 +33,6 @@ import { CoreToLocaleStringPipe } from './to-locale-string'; CoreNoTagsPipe, CoreSecondsToHMSPipe, CoreTimeAgoPipe, - CoreToLocaleStringPipe, ], exports: [ CoreBytesToSizePipe, @@ -45,7 +43,6 @@ import { CoreToLocaleStringPipe } from './to-locale-string'; CoreNoTagsPipe, CoreSecondsToHMSPipe, CoreTimeAgoPipe, - CoreToLocaleStringPipe, ], }) export class CorePipesModule {} diff --git a/src/core/pipes/to-locale-string.ts b/src/core/pipes/to-locale-string.ts deleted file mode 100644 index d64df8a6d..000000000 --- a/src/core/pipes/to-locale-string.ts +++ /dev/null @@ -1,66 +0,0 @@ -// (C) Copyright 2015 Moodle Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { Pipe, PipeTransform } from '@angular/core'; -import { CoreTimeUtils } from '@services/utils/time'; - -import { CoreLogger } from '@singletons/logger'; - -/** - * Filter to format a timestamp to a locale string. Timestamp can be in seconds or milliseconds. - * - * @deprecated since 3.6. Use coreFormatDate instead. - */ -@Pipe({ - name: 'coreToLocaleString', -}) -export class CoreToLocaleStringPipe implements PipeTransform { - - protected logger: CoreLogger; - - constructor() { - this.logger = CoreLogger.getInstance('CoreToLocaleStringPipe'); - } - - /** - * Format a timestamp to a locale string. - * - * @param timestamp The timestamp (can be in seconds or milliseconds). - * @return Formatted time. - */ - transform(timestamp: number | string): string { - if (typeof timestamp == 'string') { - // Convert the value to a number. - const numberTimestamp = parseInt(timestamp, 10); - if (isNaN(numberTimestamp)) { - this.logger.error('Invalid value received', timestamp); - - return timestamp; - } - timestamp = numberTimestamp; - } - - if (timestamp < 0) { - // Date not valid. - return ''; - } - if (timestamp < 100000000000) { - // Timestamp is in seconds, convert it to milliseconds. - timestamp = timestamp * 1000; - } - - return CoreTimeUtils.userDate(timestamp, 'core.strftimedatetimeshort'); - } - -} diff --git a/src/core/services/app.ts b/src/core/services/app.ts index 87ec78cd8..4c5cfc1e2 100644 --- a/src/core/services/app.ts +++ b/src/core/services/app.ts @@ -677,7 +677,7 @@ export class CoreAppProvider { /** * Reset StatusBar color if any was set. * - * @deprecated Use setStatusBarColor passing the color of the new statusbar color loaded on remote theme or no color to reset. + * @deprecated since 3.9.5. Use setStatusBarColor passing the color of the new statusbar color, or no color to reset. */ resetStatusBarColor(): void { this.setStatusBarColor(); diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 73a57f8b9..17048560b 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -39,6 +39,8 @@ import { CoreFormFields, CoreForms } from '../../singletons/form'; import { CoreModalLateralTransitionEnter, CoreModalLateralTransitionLeave } from '@classes/modal-lateral-transition'; import { CoreZoomLevel } from '@features/settings/services/settings-helper'; import { CoreErrorWithTitle } from '@classes/errors/errorwithtitle'; +import { AddonFilterMultilangHandler } from '@addons/filter/multilang/services/handlers/multilang'; +import { CoreSites } from '@services/sites'; /* * "Utils" service with helper functions for UI, DOM elements and HTML code. @@ -275,58 +277,6 @@ export class CoreDomUtilsProvider { return newChanges; } - /** - * Extract the downloadable URLs from an HTML code. - * - * @param html HTML code. - * @return List of file urls. - * @deprecated since 3.8. Use CoreFilepoolProvider.extractDownloadableFilesFromHtml instead. - */ - extractDownloadableFilesFromHtml(html: string): string[] { - this.logger.error('The function extractDownloadableFilesFromHtml has been moved to CoreFilepoolProvider.' + - ' Please use that function instead of this one.'); - - const urls: string[] = []; - - const element = this.convertToElement(html); - const elements: AnchorOrMediaElement[] = Array.from(element.querySelectorAll('a, img, audio, video, source, track')); - - for (let i = 0; i < elements.length; i++) { - const element = elements[i]; - let url = 'href' in element ? element.href : element.src; - - if (url && CoreUrlUtils.isDownloadableUrl(url) && urls.indexOf(url) == -1) { - urls.push(url); - } - - // Treat video poster. - if (element.tagName == 'VIDEO' && element.getAttribute('poster')) { - url = element.getAttribute('poster') || ''; - if (url && CoreUrlUtils.isDownloadableUrl(url) && urls.indexOf(url) == -1) { - urls.push(url); - } - } - } - - return urls; - } - - /** - * Extract the downloadable URLs from an HTML code and returns them in fake file objects. - * - * @param html HTML code. - * @return List of fake file objects with file URLs. - * @deprecated since 3.8. Use CoreFilepoolProvider.extractDownloadableFilesFromHtmlAsFakeFileObjects instead. - */ - extractDownloadableFilesFromHtmlAsFakeFileObjects(html: string): {fileurl: string}[] { - const urls = this.extractDownloadableFilesFromHtml(html); - - // Convert them to fake file objects. - return urls.map((url) => ({ - fileurl: url, - })); - } - /** * Search all the URLs in a CSS file content. * @@ -1196,9 +1146,9 @@ export class CoreDomUtilsProvider { async showAlertWithOptions(options: AlertOptions = {}, autocloseTime?: number): Promise { const hasHTMLTags = CoreTextUtils.hasHTMLTags( options.message || ''); - if (hasHTMLTags) { - // Format the text. - options.message = await CoreTextUtils.formatText( options.message); + if (hasHTMLTags && !CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.7')) { + // Treat multilang. + options.message = await AddonFilterMultilangHandler.filter( options.message); } const alertId = Md5.hashAsciiStr((options.header || '') + '#' + (options.message || '')); @@ -2046,9 +1996,6 @@ function fixMDPopoverPosition(baseEl: HTMLElement, ev?: Event): void { export const CoreDomUtils = makeSingleton(CoreDomUtilsProvider); -type AnchorOrMediaElement = - HTMLAnchorElement | HTMLImageElement | HTMLAudioElement | HTMLVideoElement | HTMLSourceElement | HTMLTrackElement; - /** * Options for the openPopover function. */ diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 572594b66..a0b157901 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -17,7 +17,6 @@ import { SafeUrl } from '@angular/platform-browser'; import { ModalOptions } from '@ionic/core'; import { CoreApp } from '@services/app'; -import { CoreLang } from '@services/lang'; import { CoreAnyError, CoreError } from '@classes/errors/error'; import { DomSanitizer, makeSingleton, Translate } from '@singletons'; import { CoreWSFile } from '@services/ws'; @@ -507,33 +506,6 @@ export class CoreTextUtilsProvider { return text; } - /** - * Formats a text, treating multilang tags and cleaning HTML if needed. - * - * @param text Text to format. - * @param clean Whether HTML tags should be removed. - * @param singleLine Whether new lines should be removed. Only valid if clean is true. - * @param shortenLength Number of characters to shorten the text. - * @param highlight Text to highlight. - * @return Promise resolved with the formatted text. - * @deprecated since 3.8.0. Please use CoreFilterProvider.formatText instead. - */ - formatText(text: string, clean?: boolean, singleLine?: boolean, shortenLength?: number, highlight?: string): Promise { - return this.treatMultilangTags(text).then((formatted) => { - if (clean) { - formatted = this.cleanTags(formatted, singleLine); - } - if (shortenLength && shortenLength > 0) { - formatted = this.shortenText(formatted, shortenLength); - } - if (highlight) { - formatted = this.highlightText(formatted, highlight); - } - - return formatted; - }); - } - /** * Get the error message from an error object. * @@ -709,7 +681,7 @@ export class CoreTextUtilsProvider { } /** - * @deprecated Use CoreText instead. + * @deprecated since 3.9.5. Use CoreText instead. */ removeEndingSlash(text?: string): string { return CoreText.removeEndingSlash(text); @@ -997,43 +969,6 @@ export class CoreTextUtilsProvider { return features; } - /** - * Treat the multilang tags from a HTML code, leaving only the current language. - * - * @param text The text to be treated. - * @return Promise resolved with the formatted text. - * @deprecated since 3.8.0. Now this is handled by AddonFilterMultilangHandler. - */ - treatMultilangTags(text: string): Promise { - if (!text || typeof text != 'string') { - return Promise.resolve(''); - } - - return CoreLang.getCurrentLanguage().then((language) => { - // Match the current language. - const anyLangRegEx = /<(?:lang|span)[^>]+lang="[a-zA-Z0-9_-]+"[^>]*>(.*?)<\/(?:lang|span)>/g; - let currentLangRegEx = new RegExp('<(?:lang|span)[^>]+lang="' + language + '"[^>]*>(.*?)', 'g'); - - if (!text.match(currentLangRegEx)) { - // Current lang not found. Try to find the first language. - const matches = text.match(anyLangRegEx); - if (matches && matches[0]) { - language = matches[0].match(/lang="([a-zA-Z0-9_-]+)"/)![1]; - currentLangRegEx = new RegExp('<(?:lang|span)[^>]+lang="' + language + '"[^>]*>(.*?)', 'g'); - } else { - // No multi-lang tag found, stop. - return text; - } - } - // Extract contents of current language. - text = text.replace(currentLangRegEx, '$1'); - // Delete the rest of languages - text = text.replace(anyLangRegEx, ''); - - return text; - }); - } - /** * Remove all ocurrences of a certain character from the start and end of a string. * diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index 2acf447f2..b654777f7 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -21,14 +21,13 @@ import { CoreApp } from '@services/app'; import { CoreEvents } from '@singletons/events'; import { CoreFile } from '@services/file'; import { CoreLang } from '@services/lang'; -import { CoreWS, CoreWSFile } from '@services/ws'; +import { CoreWS } from '@services/ws'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; import { CoreWSError } from '@classes/errors/wserror'; import { makeSingleton, Clipboard, InAppBrowser, FileOpener, WebIntent, QRScanner, Translate, NgZone } from '@singletons'; import { CoreLogger } from '@singletons/logger'; -import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreViewerQRScannerComponent } from '@features/viewer/components/qr-scanner/qr-scanner'; import { CoreCanceledError } from '@classes/errors/cancelederror'; import { CoreFileEntry } from '@services/file-helper'; @@ -1379,31 +1378,6 @@ export class CoreUtilsProvider { } } - /** - * Sum the filesizes from a list of files checking if the size will be partial or totally calculated. - * - * @param files List of files to sum its filesize. - * @return File size and a boolean to indicate if it is the total size or only partial. - * @deprecated since 3.8.0. Use CorePluginFileDelegate.getFilesSize instead. - */ - sumFileSizes(files: CoreWSFile[]): CoreFileSizeSum { - const result = { - size: 0, - total: true, - }; - - files.forEach((file) => { - if (typeof file.filesize == 'undefined') { - // We don't have the file size, cannot calculate its total size. - result.total = false; - } else { - result.size += file.filesize; - } - }); - - return result; - } - /** * Set a timeout to a Promise. If the time passes before the Promise is resolved or rejected, it will be automatically * rejected.