Skip to content

Commit

Permalink
Merge pull request moodlehq#4150 from crazyserver/MOBILE-4616
Browse files Browse the repository at this point in the history
Mobile 4616
  • Loading branch information
dpalou authored Aug 14, 2024
2 parents 976de68 + 00951b2 commit 4193bfc
Show file tree
Hide file tree
Showing 168 changed files with 2,024 additions and 1,390 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
cat circular-dependencies
lines=$(cat circular-dependencies | wc -l)
echo "Total circular dependencies: $lines"
test $lines -eq 131
test $lines -eq 130
- name: JavaScript code compatibility
run: |
npx check-es-compat www/*.js --polyfills="\{Array,String,TypedArray\}.prototype.at,Object.hasOwn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { CoreBlockBaseComponent } from '@features/block/classes/base-block-compo
import { CoreSite } from '@classes/sites/site';
import { CoreUtils } from '@services/utils/utils';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion';
import { IonSearchbar } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator';
Expand Down Expand Up @@ -375,7 +375,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
this.filters.show.custom = config?.displaygroupingcustomfield?.value == '1' && !!config?.customfieldsexport?.value;

this.filters.customFilters = this.filters.show.custom
? CoreTextUtils.parseJSON(config?.customfieldsexport?.value || '[]', [])
? CoreText.parseJSON(config?.customfieldsexport?.value || '[]', [])
: [];

// Check if any selector is shown and not disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
AddonBlockRecentlyAccessedItems,
AddonBlockRecentlyAccessedItemsItemCalculatedData,
} from '../../services/recentlyaccesseditems';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import { CoreLoadings } from '@services/loadings';
import { CoreUtils } from '@services/utils/utils';
import { CoreSharedModule } from '@/core/shared.module';
Expand Down Expand Up @@ -92,7 +92,7 @@ export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseCompo
e.preventDefault();
e.stopPropagation();

const url = CoreTextUtils.decodeHTMLEntities(item.viewurl);
const url = CoreText.decodeHTMLEntities(item.viewurl);
const modal = await CoreLoadings.show();

try {
Expand Down
4 changes: 2 additions & 2 deletions src/addons/block/timeline/components/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { CoreSites } from '@services/sites';
import { CoreLoadings } from '@services/loadings';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import { CoreEnrolledCourseDataWithOptions } from '@features/courses/services/courses-helper';
import { AddonBlockTimelineDayEvents } from '@addons/block/timeline/classes/section';
import { CoreSharedModule } from '@/core/shared.module';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class AddonBlockTimelineEventsComponent implements OnInit {
event.stopPropagation();

// Fix URL format.
url = CoreTextUtils.decodeHTMLEntities(url);
url = CoreText.decodeHTMLEntities(url);

const modal = await CoreLoadings.show();

Expand Down
4 changes: 2 additions & 2 deletions src/addons/blog/pages/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreNavigator } from '@services/navigator';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text';
import { CoreFileHelper } from '@services/file-helper';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
import { CoreArray } from '@singletons/array';
Expand Down Expand Up @@ -212,7 +212,7 @@ export class AddonBlogIndexPage implements OnInit, OnDestroy {
entry.contextInstanceId = entry.userid;
}

entry.summary = CoreTextUtils.replacePluginfileUrls(entry.summary, entry.summaryfiles || []);
entry.summary = CoreFileHelper.replacePluginfileUrls(entry.summary, entry.summaryfiles || []);

entry.user = await CoreUtils.ignoreErrors(CoreUser.getProfile(entry.userid, entry.courseid, true));
});
Expand Down
7 changes: 4 additions & 3 deletions src/addons/calendar/pages/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider }
import { CoreNetwork } from '@services/network';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import { CoreSites } from '@services/sites';
import { CoreCourse } from '@features/course/services/course';
import { CoreTimeUtils } from '@services/utils/time';
Expand All @@ -45,6 +45,7 @@ import { CoreConfig } from '@services/config';
import { CoreToasts, ToastDuration } from '@services/toasts';
import { CorePopovers } from '@services/popovers';
import { CoreLoadings } from '@services/loadings';
import { CoreUrl } from '@singletons/url';

/**
* Page that displays a single calendar event.
Expand Down Expand Up @@ -288,8 +289,8 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {

if (this.event.location) {
// Build a link to open the address in maps.
this.event.location = CoreTextUtils.decodeHTML(this.event.location);
this.event.encodedLocation = CoreTextUtils.buildAddressURL(this.event.location);
this.event.location = CoreText.decodeHTML(this.event.location);
this.event.encodedLocation = CoreUrl.buildAddressURL(this.event.location);
}

// Check if event was deleted in offine.
Expand Down
10 changes: 5 additions & 5 deletions src/addons/calendar/services/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreSites } from '@services/sites';
import { CoreSite } from '@classes/sites/site';
import { CoreNetwork } from '@services/network';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import { CoreTimeUtils } from '@services/utils/time';
import { CoreUrl } from '@singletons/url';
import { CoreUtils } from '@services/utils/utils';
Expand Down Expand Up @@ -330,7 +330,7 @@ export class AddonCalendarProvider {
): Promise<string> {

const getTimeHtml = (time: string, a11yLangKey: string): string =>
`<span aria-label="${Translate.instant(a11yLangKey, { $a: CoreTextUtils.cleanTags(time) })}">${time}</span>`;
`<span aria-label="${Translate.instant(a11yLangKey, { $a: CoreText.cleanTags(time) })}">${time}</span>`;
const getStartTimeHtml = (time: string): string => getTimeHtml(time, 'core.startingtime');
const getEndTimeHtml = (time: string): string => getTimeHtml(time, 'core.endingtime');

Expand Down Expand Up @@ -666,18 +666,18 @@ export class AddonCalendarProvider {
eventConverted.iscategoryevent = originalEvent.eventtype == AddonCalendarEventType.CATEGORY;
eventConverted.normalisedeventtype = this.getEventType(recordAsRecord);
try {
eventConverted.category = CoreTextUtils.parseJSON(recordAsRecord.category || '');
eventConverted.category = CoreText.parseJSON(recordAsRecord.category || '');
} catch {
// Ignore errors.
}

try {
eventConverted.course = CoreTextUtils.parseJSON(recordAsRecord.course || '');
eventConverted.course = CoreText.parseJSON(recordAsRecord.course || '');
} catch {
// Ignore errors.
}
try {
eventConverted.subscription = CoreTextUtils.parseJSON(recordAsRecord.subscription || '');
eventConverted.subscription = CoreText.parseJSON(recordAsRecord.subscription || '');
} catch {
// Ignore errors.
}
Expand Down
67 changes: 33 additions & 34 deletions src/addons/filter/displayh5p/services/handlers/displayh5p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { makeSingleton } from '@singletons';
import { CoreH5PPlayerComponent } from '@features/h5p/components/h5p-player/h5p-player';
import { CoreUrl } from '@singletons/url';
import { CoreH5PHelper } from '@features/h5p/classes/helper';
import { CoreText } from '@singletons/text';

/**
* Handler to support the Display H5P filter.
Expand All @@ -30,47 +31,45 @@ export class AddonFilterDisplayH5PHandlerService extends CoreFilterDefaultHandle
name = 'AddonFilterDisplayH5PHandler';
filterName = 'displayh5p';

protected template = document.createElement('template'); // A template element to convert HTML to element.

/**
* @inheritdoc
*/
filter(
text: string,
): string | Promise<string> {
this.template.innerHTML = text;

const h5pIframes = <HTMLIFrameElement[]> Array.from(this.template.content.querySelectorAll('iframe.h5p-iframe'));

// Replace all iframes with an empty div that will be treated in handleHtml.
h5pIframes.forEach((iframe) => {
const placeholder = document.createElement('div');

placeholder.classList.add('core-h5p-tmp-placeholder');
placeholder.setAttribute('data-player-src', iframe.src);

iframe.parentElement?.replaceChild(placeholder, iframe);
return CoreText.processHTML(text, (element) => {
const h5pIframes = <HTMLIFrameElement[]> Array.from(element.querySelectorAll('iframe.h5p-iframe'));

// Replace all iframes with an empty div that will be treated in handleHtml.
h5pIframes.forEach((iframe) => {
const placeholder = document.createElement('div');

placeholder.classList.add('core-h5p-tmp-placeholder');
placeholder.setAttribute('data-player-src', iframe.src);

iframe.parentElement?.replaceChild(placeholder, iframe);
});

// Handle H5P iframes embedded using the embed HTML code.
const embeddedH5PIframes = <HTMLIFrameElement[]> Array.from(
element.querySelectorAll('iframe.h5p-player'),
);

embeddedH5PIframes.forEach((iframe) => {
// Add the preventredirect param to allow authenticating if auto-login fails.
iframe.src = CoreUrl.addParamsToUrl(iframe.src, { preventredirect: false });

// Add resizer script so the H5P has the right height.
CoreH5PHelper.addResizerScript();

// If the iframe has a small height, add some minimum initial height so it's seen if auto-login fails.
const styleHeight = Number(iframe.style.height);
const height = Number(iframe.getAttribute('height'));
if ((!height || height < 400) && (!styleHeight || styleHeight < 400)) {
iframe.style.height = '400px';
}
});
});

// Handle H5P iframes embedded using the embed HTML code.
const embeddedH5PIframes = <HTMLIFrameElement[]> Array.from(this.template.content.querySelectorAll('iframe.h5p-player'));

embeddedH5PIframes.forEach((iframe) => {
// Add the preventredirect param to allow authenticating if auto-login fails.
iframe.src = CoreUrl.addParamsToUrl(iframe.src, { preventredirect: false });

// Add resizer script so the H5P has the right height.
CoreH5PHelper.addResizerScript();

// If the iframe has a small height, add some minimum initial height so it's seen if auto-login fails.
const styleHeight = Number(iframe.style.height);
const height = Number(iframe.getAttribute('height'));
if ((!height || height < 400) && (!styleHeight || styleHeight < 400)) {
iframe.style.height = '400px';
}
});

return this.template.innerHTML;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CoreFilterDefaultHandler } from '@features/filter/services/handlers/def
import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/services/filter';
import { CoreLang } from '@services/lang';
import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import { CoreUtils } from '@services/utils/utils';
import { CoreEvents } from '@singletons/events';
import { CoreSite } from '@classes/sites/site';
Expand Down Expand Up @@ -189,7 +189,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan
* @returns The whole text with the span inserted around the defined substring.
*/
protected insertSpan(text: string, start: number, end: number): string {
return CoreTextUtils.substrReplace(
return CoreText.substrReplace(
text,
'<span class="nolink">' + text.substring(start, end + 1) + '</span>',
start,
Expand Down
15 changes: 6 additions & 9 deletions src/addons/filter/mediaplugin/services/handlers/mediaplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { CoreText } from '@singletons/text';
import { AddonFilterMediaPluginVideoJS } from '@addons/filter/mediaplugin/services/videojs';
import { Injectable } from '@angular/core';

Expand All @@ -28,21 +29,17 @@ export class AddonFilterMediaPluginHandlerService extends CoreFilterDefaultHandl
name = 'AddonFilterMediaPluginHandler';
filterName = 'mediaplugin';

protected template = document.createElement('template'); // A template element to convert HTML to element.

/**
* @inheritdoc
*/
filter(text: string): string | Promise<string> {
this.template.innerHTML = text;

const videos = Array.from(this.template.content.querySelectorAll('video'));
return CoreText.processHTML(text, (element) => {
const videos = Array.from(element.querySelectorAll('video'));

videos.forEach((video) => {
AddonFilterMediaPluginVideoJS.treatYoutubeVideos(video);
videos.forEach((video) => {
AddonFilterMediaPluginVideoJS.treatYoutubeVideos(video);
});
});

return this.template.innerHTML;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/addons/filter/mediaplugin/services/videojs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CorePromisedValue } from '@classes/promised-value';
import { CoreExternalContentDirective } from '@directives/external-content';
import { CoreLang } from '@services/lang';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import { CoreUrl } from '@singletons/url';
import { makeSingleton } from '@singletons';
import { CoreDirectivesRegistry } from '@singletons/directives-registry';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class AddonFilterMediaPluginVideoJSService {
// Create player.
const videojs = await this.getVideoJS();
const dataSetupString = element.getAttribute('data-setup') || element.getAttribute('data-setup-lazy') || '{}';
const data = CoreTextUtils.parseJSON<VideoJSOptions>(dataSetupString, {});
const data = CoreText.parseJSON<VideoJSOptions>(dataSetupString, {});
const player = videojs(
element,
{
Expand Down Expand Up @@ -106,7 +106,7 @@ export class AddonFilterMediaPluginVideoJSService {
}

const dataSetupString = video.getAttribute('data-setup') || video.getAttribute('data-setup-lazy') || '{}';
const data = CoreTextUtils.parseJSON<VideoJSOptions>(dataSetupString, {});
const data = CoreText.parseJSON<VideoJSOptions>(dataSetupString, {});
const youtubeUrl = data.techOrder?.[0] == 'youtube' && CoreUrl.getYoutubeEmbedUrl(data.sources?.[0]?.src);

if (!youtubeUrl) {
Expand Down
3 changes: 1 addition & 2 deletions src/addons/messages/pages/discussion/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { AddonMessagesSync, AddonMessagesSyncProvider } from '../../services/mes
import { CoreUser } from '@features/user/services/user';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { CoreTextUtils } from '@services/utils/text';
import { CoreLogger } from '@singletons/logger';
import { CoreInfiniteLoadingComponent } from '@components/infinite-loading/infinite-loading';
import { Md5 } from 'ts-md5/dist/md5';
Expand Down Expand Up @@ -928,7 +927,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
*/
copyMessage(message: AddonMessagesConversationMessageFormatted): void {
const text = 'smallmessage' in message ? message.smallmessage || message.text || '' : message.text || '';
CoreText.copyToClipboard(CoreTextUtils.decodeHTMLEntities(text));
CoreText.copyToClipboard(CoreText.decodeHTMLEntities(text));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/addons/messages/pages/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreConstants } from '@/core/constants';
import { AddonNotificationsPreferencesNotificationProcessorState } from '@addons/notifications/services/notifications';
import { CorePlatform } from '@services/platform';
import { CoreTextUtils } from '@services/utils/text';
import { CoreErrorHelper } from '@services/error-helper';
import { CoreLoadings } from '@services/loadings';

/**
Expand Down Expand Up @@ -112,7 +112,7 @@ export class AddonMessagesSettingsPage implements OnInit, OnDestroy {
this.warningMessage.set(undefined);
} catch (error) {
if (error.errorcode === 'nopermissions') {
this.warningMessage.set(CoreTextUtils.getErrorMessageFromError(error));
this.warningMessage.set(CoreErrorHelper.getErrorMessageFromError(error));

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/addons/messages/services/messages-offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { CoreSites } from '@services/sites';
import { CoreNetwork } from '@services/network';
import { CoreTextUtils } from '@services/utils/text';
import { CoreText } from '@singletons/text';
import {
AddonMessagesOfflineConversationMessagesDBRecord,
AddonMessagesOfflineMessagesDBRecord,
Expand Down Expand Up @@ -227,7 +227,7 @@ export class AddonMessagesOfflineProvider {
text: message.text,
timecreated: message.timecreated,
deviceoffline: message.deviceoffline,
conversation: message.conversation ? CoreTextUtils.parseJSON(message.conversation, undefined) : undefined,
conversation: message.conversation ? CoreText.parseJSON(message.conversation, undefined) : undefined,
pending: true,
useridfrom: userIdFrom,
};
Expand Down
Loading

0 comments on commit 4193bfc

Please sign in to comment.