Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/leadin/scripts/iframe
File: useAppEmbedder.ts
import { useEffect } from 'react';
[0] Fix | Delete
import Raven from '../lib/Raven';
[1] Fix | Delete
[2] Fix | Delete
import {
[3] Fix | Delete
accountName,
[4] Fix | Delete
adminUrl,
[5] Fix | Delete
connectionStatus,
[6] Fix | Delete
deviceId,
[7] Fix | Delete
hubspotBaseUrl,
[8] Fix | Delete
leadinQueryParams,
[9] Fix | Delete
locale,
[10] Fix | Delete
plugins,
[11] Fix | Delete
portalDomain,
[12] Fix | Delete
portalEmail,
[13] Fix | Delete
portalId,
[14] Fix | Delete
reviewSkippedDate,
[15] Fix | Delete
refreshToken,
[16] Fix | Delete
impactLink,
[17] Fix | Delete
theme,
[18] Fix | Delete
lastAuthorizeTime,
[19] Fix | Delete
lastDeauthorizeTime,
[20] Fix | Delete
lastDisconnectTime,
[21] Fix | Delete
leadinPluginVersion,
[22] Fix | Delete
phpVersion,
[23] Fix | Delete
wpVersion,
[24] Fix | Delete
contentEmbed,
[25] Fix | Delete
requiresContentEmbedScope,
[26] Fix | Delete
decryptError,
[27] Fix | Delete
LeadinConfig,
[28] Fix | Delete
} from '../constants/leadinConfig';
[29] Fix | Delete
import { App, AppIframe } from './constants';
[30] Fix | Delete
import { messageMiddleware } from './messageMiddleware';
[31] Fix | Delete
import { resizeWindow, useIframeNotRendered } from '../utils/iframe';
[32] Fix | Delete
[33] Fix | Delete
type PartialLeadinConfig = Pick<
[34] Fix | Delete
LeadinConfig,
[35] Fix | Delete
| 'accountName'
[36] Fix | Delete
| 'adminUrl'
[37] Fix | Delete
| 'connectionStatus'
[38] Fix | Delete
| 'deviceId'
[39] Fix | Delete
| 'plugins'
[40] Fix | Delete
| 'portalDomain'
[41] Fix | Delete
| 'portalEmail'
[42] Fix | Delete
| 'portalId'
[43] Fix | Delete
| 'reviewSkippedDate'
[44] Fix | Delete
| 'refreshToken'
[45] Fix | Delete
| 'impactLink'
[46] Fix | Delete
| 'theme'
[47] Fix | Delete
| 'trackConsent'
[48] Fix | Delete
| 'lastAuthorizeTime'
[49] Fix | Delete
| 'lastDeauthorizeTime'
[50] Fix | Delete
| 'lastDisconnectTime'
[51] Fix | Delete
| 'leadinPluginVersion'
[52] Fix | Delete
| 'phpVersion'
[53] Fix | Delete
| 'wpVersion'
[54] Fix | Delete
| 'contentEmbed'
[55] Fix | Delete
| 'requiresContentEmbedScope'
[56] Fix | Delete
| 'decryptError'
[57] Fix | Delete
>;
[58] Fix | Delete
[59] Fix | Delete
type AppIntegrationConfig = Pick<LeadinConfig, 'adminUrl'>;
[60] Fix | Delete
[61] Fix | Delete
const getIntegrationConfig = (): AppIntegrationConfig => {
[62] Fix | Delete
return {
[63] Fix | Delete
adminUrl: leadinQueryParams.adminUrl,
[64] Fix | Delete
};
[65] Fix | Delete
};
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* A modified version of the original leadinConfig that is passed to some integrated apps.
[69] Fix | Delete
*
[70] Fix | Delete
* Important:
[71] Fix | Delete
* Try not to add new fields here.
[72] Fix | Delete
* This config is already too large and broad in scope.
[73] Fix | Delete
* It tightly couples the apps that use it with the WordPress plugin.
[74] Fix | Delete
* Consider instead passing new required fields as new entry to PluginAppOptions or app-specific options.
[75] Fix | Delete
*/
[76] Fix | Delete
type AppLeadinConfig = {
[77] Fix | Delete
admin: string;
[78] Fix | Delete
company: string;
[79] Fix | Delete
email: string;
[80] Fix | Delete
firstName: string;
[81] Fix | Delete
irclickid: string;
[82] Fix | Delete
justConnected: string;
[83] Fix | Delete
lastName: string;
[84] Fix | Delete
mpid: string;
[85] Fix | Delete
nonce: string;
[86] Fix | Delete
websiteName: string;
[87] Fix | Delete
} & PartialLeadinConfig;
[88] Fix | Delete
[89] Fix | Delete
const getLeadinConfig = (): AppLeadinConfig => {
[90] Fix | Delete
const utm_query_params = Object.keys(leadinQueryParams)
[91] Fix | Delete
.filter(x => /^utm/.test(x))
[92] Fix | Delete
.reduce(
[93] Fix | Delete
(p: { [key: string]: string }, c: string) => ({
[94] Fix | Delete
[c]: leadinQueryParams[c],
[95] Fix | Delete
...p,
[96] Fix | Delete
}),
[97] Fix | Delete
{}
[98] Fix | Delete
);
[99] Fix | Delete
return {
[100] Fix | Delete
accountName,
[101] Fix | Delete
admin: leadinQueryParams.admin,
[102] Fix | Delete
adminUrl,
[103] Fix | Delete
company: leadinQueryParams.company,
[104] Fix | Delete
connectionStatus,
[105] Fix | Delete
deviceId,
[106] Fix | Delete
email: leadinQueryParams.email,
[107] Fix | Delete
firstName: leadinQueryParams.firstName,
[108] Fix | Delete
irclickid: leadinQueryParams.irclickid,
[109] Fix | Delete
justConnected: leadinQueryParams.justConnected,
[110] Fix | Delete
lastName: leadinQueryParams.lastName,
[111] Fix | Delete
lastAuthorizeTime,
[112] Fix | Delete
lastDeauthorizeTime,
[113] Fix | Delete
lastDisconnectTime,
[114] Fix | Delete
leadinPluginVersion,
[115] Fix | Delete
mpid: leadinQueryParams.mpid,
[116] Fix | Delete
nonce: leadinQueryParams.nonce,
[117] Fix | Delete
phpVersion,
[118] Fix | Delete
plugins,
[119] Fix | Delete
portalDomain,
[120] Fix | Delete
portalEmail,
[121] Fix | Delete
portalId,
[122] Fix | Delete
reviewSkippedDate,
[123] Fix | Delete
theme,
[124] Fix | Delete
trackConsent: leadinQueryParams.trackConsent,
[125] Fix | Delete
websiteName: leadinQueryParams.websiteName,
[126] Fix | Delete
wpVersion,
[127] Fix | Delete
contentEmbed,
[128] Fix | Delete
requiresContentEmbedScope,
[129] Fix | Delete
decryptError,
[130] Fix | Delete
...utm_query_params,
[131] Fix | Delete
};
[132] Fix | Delete
};
[133] Fix | Delete
[134] Fix | Delete
const getAppOptions = (app: App, createRoute = false) => {
[135] Fix | Delete
const {
[136] Fix | Delete
IntegratedAppOptions,
[137] Fix | Delete
FormsAppOptions,
[138] Fix | Delete
LiveChatAppOptions,
[139] Fix | Delete
PluginAppOptions,
[140] Fix | Delete
}: any = window;
[141] Fix | Delete
let options;
[142] Fix | Delete
switch (app) {
[143] Fix | Delete
case App.Plugin:
[144] Fix | Delete
options = new PluginAppOptions().setLeadinConfig(getLeadinConfig());
[145] Fix | Delete
break;
[146] Fix | Delete
case App.PluginSettings:
[147] Fix | Delete
options = new PluginAppOptions()
[148] Fix | Delete
.setLeadinConfig(getLeadinConfig())
[149] Fix | Delete
.setPluginSettingsInit();
[150] Fix | Delete
break;
[151] Fix | Delete
case App.Forms:
[152] Fix | Delete
options = new FormsAppOptions().setIntegratedAppConfig(
[153] Fix | Delete
getIntegrationConfig()
[154] Fix | Delete
);
[155] Fix | Delete
if (createRoute) {
[156] Fix | Delete
options = options.setCreateFormAppInit();
[157] Fix | Delete
}
[158] Fix | Delete
break;
[159] Fix | Delete
case App.LiveChat:
[160] Fix | Delete
options = new LiveChatAppOptions();
[161] Fix | Delete
if (createRoute) {
[162] Fix | Delete
options = options.setCreateLiveChatAppInit();
[163] Fix | Delete
}
[164] Fix | Delete
break;
[165] Fix | Delete
default:
[166] Fix | Delete
options = new IntegratedAppOptions();
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
return options;
[170] Fix | Delete
};
[171] Fix | Delete
[172] Fix | Delete
export default function useAppEmbedder(
[173] Fix | Delete
app: App,
[174] Fix | Delete
createRoute: boolean,
[175] Fix | Delete
container: HTMLElement | null
[176] Fix | Delete
) {
[177] Fix | Delete
console.info(
[178] Fix | Delete
'HubSpot plugin - starting app embedder for:',
[179] Fix | Delete
AppIframe[app],
[180] Fix | Delete
container
[181] Fix | Delete
);
[182] Fix | Delete
const iframeNotRendered = useIframeNotRendered(AppIframe[app]);
[183] Fix | Delete
[184] Fix | Delete
useEffect(() => {
[185] Fix | Delete
const { IntegratedAppEmbedder }: any = window;
[186] Fix | Delete
[187] Fix | Delete
if (IntegratedAppEmbedder) {
[188] Fix | Delete
const options = getAppOptions(app, createRoute)
[189] Fix | Delete
.setLocale(locale)
[190] Fix | Delete
.setDeviceId(deviceId)
[191] Fix | Delete
.setRefreshToken(refreshToken);
[192] Fix | Delete
[193] Fix | Delete
const embedder = new IntegratedAppEmbedder(
[194] Fix | Delete
AppIframe[app],
[195] Fix | Delete
portalId,
[196] Fix | Delete
hubspotBaseUrl,
[197] Fix | Delete
resizeWindow,
[198] Fix | Delete
refreshToken ? '' : impactLink
[199] Fix | Delete
).setOptions(options);
[200] Fix | Delete
[201] Fix | Delete
embedder.subscribe(messageMiddleware(embedder));
[202] Fix | Delete
embedder.attachTo(container, true);
[203] Fix | Delete
embedder.postStartAppMessage(); // lets the app know all all data has been passed to it
[204] Fix | Delete
[205] Fix | Delete
(window as any).embedder = embedder;
[206] Fix | Delete
}
[207] Fix | Delete
}, []);
[208] Fix | Delete
[209] Fix | Delete
if (iframeNotRendered) {
[210] Fix | Delete
console.error('HubSpot plugin Iframe not rendered', {
[211] Fix | Delete
portalId,
[212] Fix | Delete
container,
[213] Fix | Delete
appName: AppIframe[app],
[214] Fix | Delete
hasIntegratedAppEmbedder: !!(window as any).IntegratedAppEmbedder,
[215] Fix | Delete
});
[216] Fix | Delete
Raven.captureException(new Error('Leadin Iframe not rendered'), {
[217] Fix | Delete
fingerprint: ['USE_APP_EMBEDDER', 'IFRAME_SETUP_ERROR'],
[218] Fix | Delete
extra: {
[219] Fix | Delete
portalId,
[220] Fix | Delete
container,
[221] Fix | Delete
app,
[222] Fix | Delete
hubspotBaseUrl,
[223] Fix | Delete
impactLink,
[224] Fix | Delete
appName: AppIframe[app],
[225] Fix | Delete
hasRefreshToken: !!refreshToken,
[226] Fix | Delete
},
[227] Fix | Delete
});
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
return iframeNotRendered;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function