Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function init() {
if ( window.Raven && isEnabled( 'sentry' ) ) {
window.Raven.config( 'https://02c1c1625528468ea40a86143860cdb7@sentry.io/96319' ).install();
// This is an experiment to send uncaught error in Promises to Sentry
// We might want to remove it if we receive too many errors
window.addEventListener( 'unhandledrejection', ( err ) => {
window.Raven.captureException( err.reason );
} );
}
window.switchLocale = switchLocale;
if ( window.localeData ) {
i18n.setLocale( window.localeData );
}
injectTapEventPlugin();
// pre-load checkout chunk
sections.checkout();
}
return parseJson( response ).then( ( json ) => {
if ( json.success ) {
return setSuccess( true, json );
}
if ( 'rest_cookie_invalid_nonce' === json.code ) {
setError( json.code );
window.persistState = true;
alert( __( 'There was a problem saving your settings. Please try again after the page is reloaded.' ) );
location.reload();
return;
}
if ( 'validation_failure' === _.get( json, 'data.error' ) && _.get( json, 'data.data.fields' ) ) {
let fieldsStatus = json.data.data.fields;
// Some services still give the field errors in an array, keep backwards-compatibility
if ( _.isArray( fieldsStatus ) ) {
fieldsStatus = {};
json.data.data.fields.forEach( ( fieldName ) => fieldsStatus[ fieldName ] = EMPTY_ERROR );
}
return setFieldsStatus( fieldsStatus );
}
if ( json.data.message ) {
return setError( json.data.message, json );
),
siteTitlePlaceholder: i18n.translate( "E.g., Vail Renovations or Stevie's blog" ),
// Site topic step
siteTopicHeader: i18n.translate( 'What is your site about?' ),
siteTopicLabel: i18n.translate( 'What is your site about?' ),
siteTopicSubheader: i18n.translate(
"We'll add relevant content to your site to help you get started."
),
siteTopicInputPlaceholder: i18n.translate( 'Enter a topic or choose one from below.' ),
// Domains step
domainsStepHeader: i18n.translate( 'Give your site an address' ),
domainsStepSubheader: i18n.translate(
'Enter a keyword that describes your site to get started.'
),
domainsStepHeaderTestCopy: i18n.translate( "Let's get your site a domain!" ),
domainsStepSubheaderTestCopy: i18n.translate(
"Tell us your site's name or a few keywords, and we'll come up with some suggestions."
),
// Site styles step
siteStyleSubheader: i18n.translate(
'This will help you get started with a theme you might like. You can change it later.'
),
},
propertyKey,
null
);
"To set up this service, we're going to make some changes to the " +
'the DNS records for your domain.'
) }
<a>{ showRecordsLinkText }</a>
<p></p>
{ this.renderDnsTemplateRecords() }
{ this.renderConflictingRecords() }
);
/* eslint-enable jsx-a11y/anchor-is-valid,jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */
}
}
export default localize( DomainConnectAuthorizeRecords );
);
} );
if ( ! activeFilter ) {
next();
} else {
if ( currentSite && currentSite.domain ) {
// FIXME: Auto-converted from the Flux setTitle action. Please use instead.
context.store.dispatch( setTitle( i18n.translate( 'Stats', { textOnly: true } ) ) );
}
const gmtOffset = getSiteOption( context.store.getState(), siteId, 'gmt_offset' );
const momentSiteZone = i18n
.moment()
.utcOffset( Number.isFinite( gmtOffset ) ? gmtOffset : 0 );
if ( queryOptions.startDate && i18n.moment( queryOptions.startDate ).isValid() ) {
date = i18n.moment( queryOptions.startDate ).locale( 'en' );
numPeriodAgo = getNumPeriodAgo( momentSiteZone, date, activeFilter.period );
} else {
date = rangeOfPeriod( activeFilter.period, momentSiteZone.locale( 'en' ) ).startOf;
}
numPeriodAgo = parseInt( numPeriodAgo, 10 );
if ( numPeriodAgo ) {
if ( numPeriodAgo > 9 ) {
numPeriodAgo = '10plus';
}
numPeriodAgo = '-' + numPeriodAgo;
} else {
numPeriodAgo = '';
}
getTimeString = timestamp => {
var DAY_IN_SECONDS = 3600 * 24,
MAX_LENGTH = 15,
parsedTime = Date.parse( timestamp ),
momentTime,
timeString;
if ( isNaN( parsedTime ) ) {
return '';
}
const localeSlug = getLocaleSlug();
momentTime = moment( timestamp ).locale( localeSlug );
if ( Date.now() - parsedTime > 1000 * DAY_IN_SECONDS * 5 ) {
// 30 Apr 2015
timeString = momentTime.format( 'll' );
if ( timeString.length > MAX_LENGTH ) {
// 2015/4/30 if 'll' is too long, e.g. "30 de abr. de 2015"
timeString = momentTime.format( 'l' );
}
} else {
// simplified units, no "ago", e.g. 7 min, 4 hours, 2 days
timeString = momentTime.fromNow( true );
}
return timeString;
export function localizeUrl( fullUrl, locale ) {
const localeSlug = locale || ( typeof getLocaleSlug === 'function' ? getLocaleSlug() : 'en' );
const urlParts = url.parse( String( fullUrl ) );
if ( ! urlParts ) {
return fullUrl;
}
// Let's unify the URL.
urlParts.protocol = 'https';
if ( 'en.wordpress.com' === urlParts.hostname ) {
urlParts.host = 'wordpress.com';
}
if ( ! endsWith( urlParts.pathname, '.php' ) ) {
urlParts.pathname = ( urlParts.pathname + '/' ).replace( /\/+$/, '/' );
}
if ( ! localeSlug || 'en' === localeSlug ) {
return renderCard( {
status: '',
content: __( 'Loading…' ),
} );
}
if ( scanEnabled ) {
// Check for threats
const threats = this.props.scanThreats;
if ( threats !== 0 ) {
return renderCard( {
content: [
<h3>
{ __( 'Uh oh, %(number)s threat found.', 'Uh oh, %(number)s threats found.', {
count: threats,
args: { number: numberFormat( threats ) },
} ) }
</h3>,
<p>
{ __( '{{a}}View details at VaultPress.com{{/a}}', {
components: { a: <a href="https://dashboard.vaultpress.com/"> },
} ) }
<br>
{ __( '{{a}}Contact Support{{/a}}', {
components: { a: </a><a href="https://jetpack.com/support"> },
} ) }
</a></p><a href="https://jetpack.com/support">,
],
} );
}
// All good</a>
}
const { decimal, grouping, symbol, unitValue = 1000 } = THOUSANDS[ code ];
const sign = number < 0 ? '-' : '';
const absNumber = Math.abs( number );
// no-op if we have a small number
if ( absNumber < unitValue ) {
return `${ sign }${ absNumber }`;
}
//show 2 sig figs, otherwise take leading sig figs.
const decimals = absNumber < unitValue * 10 ? 1 : 0;
const value = numberFormat( absNumber / unitValue, {
decimals,
thousandsSep: grouping,
decPoint: decimal,
} );
return `${ sign }${ value }${ symbol }`;
}
function switchLocale( localeSlug ) {
setLocaleCookie( localeSlug );
if ( localeSlug === config( 'i18n_default_locale_slug' ) ) {
// sets the locale back to the default
i18n.setLocale();
return;
}
request.get( languageFileUrl( localeSlug ) ).end( function( error, response ) {
if ( error ) {
debug( 'Encountered an error loading locale file for ' + localeSlug + '. Falling back to English.' );
return;
}
i18n.setLocale( response.body );
} );
}