Ejemplo n.º 1
0
normalizePost.decodeEntities = function decodeEntities( post, callback ) {
	forEach( [ 'excerpt', 'title', 'site_name' ], function( prop ) {
		if ( post[ prop ] ) {
			post[ prop ] = formatting.decodeEntities( post[ prop ] );
		}
	} );

	if ( post.parent && post.parent.title ) {
		post.parent.title = formatting.decodeEntities( post.parent.title );
	}

	if ( post.author ) {
		if ( post.author.name ) {
			post.author.name = formatting.decodeEntities( post.author.name );
		}
		if ( post.author.avatar_URL ) {
			post.author.avatar_URL = safeImageURL( post.author.avatar_URL );
		}
	}

	if ( post.tags ) {
		// tags is an object
		forOwn( post.tags, function( tag ) {
			tag.name = formatting.decodeEntities( tag.name );
		} );
	}

	callback();
};
Ejemplo n.º 2
0
export default function decodeEntities( post ) {
	forEach( [ 'excerpt', 'title', 'site_name' ], function( prop ) {
		if ( post[ prop ] ) {
			post[ prop ] = decode( post[ prop ] );
		}
	} );

	if ( post.parent && post.parent.title ) {
		post.parent.title = decode( post.parent.title );
	}

	if ( post.author ) {
		if ( post.author.name ) {
			post.author.name = decode( post.author.name );
		}
		if ( post.author.avatar_URL ) {
			post.author.avatar_URL = safeImageURL( post.author.avatar_URL );
		}
	}

	if ( post.tags ) {
		// tags is an object
		forOwn( post.tags, function( tag ) {
			tag.name = decode( tag.name );
		} );
	}

	return post;
}
Ejemplo n.º 3
0
export default function decodeEntities( post, fields = DEFAULT_FIELDS ) {
	fields.forEach( function( prop ) {
		if ( post[ prop ] ) {
			post[ prop ] = decode( post[ prop ] );
		}
	} );

	if ( post.parent && post.parent.title ) {
		post.parent.title = decode( post.parent.title );
	}

	if ( post.author ) {
		if ( post.author.name ) {
			post.author.name = decode( post.author.name );
		}
		if ( post.author.avatar_URL ) {
			post.author.avatar_URL = safeImageURL( post.author.avatar_URL );
		}
	}

	if ( post.tags ) {
		// tags is an object
		forOwn( post.tags, function( tag ) {
			tag.name = decode( tag.name );
		} );
	}

	return post;
}
Ejemplo n.º 4
0
/*
 * Decodes entities in those specific user settings properties
 * that the REST API returns already HTML-encoded
 */
function decodeUserSettingsEntities( data ) {
	let decodedValues = {
		display_name: data.display_name && decodeEntities( data.display_name ),
		description: data.description && decodeEntities( data.description ),
		user_URL: data.user_URL && decodeEntities( data.user_URL )
	};

	return assign( {}, data, decodedValues );
}
function normalizeInvite( data ) {
	return {
		inviteKey: data.invite.invite_slug,
		date: data.invite.invite_date,
		role: decodeEntities( data.invite.meta.role ),
		sentTo: decodeEntities( data.invite.meta.sent_to ),
		forceMatchingEmail: data.invite.meta.force_matching_email,
		site: Object.assign( filterObjectProperties( data.blog_details ), { ID: parseInt( data.invite.blog_id, 10 ) } ),
		inviter: filterObjectProperties( data.inviter ),
		knownUser: data.invite.meta.known
	}
}
Ejemplo n.º 6
0
function adaptFeed( feed ) {
	return {
		feed_ID: +feed.feed_ID,
		blog_ID: +feed.blog_ID,
		name: feed.name && decodeEntities( feed.name ),
		URL: feed.URL,
		feed_URL: feed.feed_URL,
		is_following: feed.is_following,
		subscribers_count: feed.subscribers_count,
		description: feed.description && decodeEntities( feed.description ),
		last_update: feed.last_update,
		image: feed.image,
	};
}
Ejemplo n.º 7
0
export function customPostToProduct( customPost ) {
	if ( ! isValidSimplePaymentsProduct( customPost ) ) {
		throw new TransformerError( 'Custom post is not a valid simple payment product', customPost );
	}

	const metadataAttributes = customPostMetadataToProductAttributes( customPost.metadata );

	return {
		ID: customPost.ID,
		description: decodeEntities( customPost.content ),
		title: decodeEntities( customPost.title ),
		featuredImageId: getFeaturedImageId( customPost ),
		...metadataAttributes,
	};
}
Ejemplo n.º 8
0
	renderStateAction() {
		const { authorizeSuccess } = this.props.authorizationData;
		if (
			this.props.isFetchingAuthorizationSite ||
			this.isAuthorizing() ||
			this.retryingAuth ||
			authorizeSuccess
		) {
			return (
				<div className="jetpack-connect__logged-in-form-loading">
					<span>{ this.getButtonText() }</span> <Spinner size={ 20 } duration={ 3000 } />
				</div>
			);
		}

		const { blogname } = this.props.authQuery;

		return (
			<LoggedOutFormFooter className="jetpack-connect__action-disclaimer">
				<Disclaimer siteName={ decodeEntities( blogname ) } />
				<Button
					primary
					disabled={ this.isAuthorizing() || this.props.hasXmlrpcError }
					onClick={ this.handleSubmit }
				>
					{ this.getButtonText() }
				</Button>
			</LoggedOutFormFooter>
		);
	}
	const renderState = ( state, index ) => {
		const { name, selected, code, disabled } = state;

		const onToggle = event => {
			event.stopPropagation();
			if ( disabled ) {
				return;
			}
			actions.toggleStateSelected( code, ! selected );
		};

		const inputId = `state-${ index }`;

		return (
			<li key={ index } className="shipping-zone__location-dialog-list-item">
				<label htmlFor={ inputId }>
					<FormCheckbox
						id={ inputId }
						onChange={ onToggle }
						className="shipping-zone__location-dialog-list-item-checkbox"
						checked={ selected }
						disabled={ disabled }
					/>
					{ decodeEntities( name ) }
				</label>
			</li>
		);
	};
	const renderLocation = ( location, index ) => {
		if ( ! loaded ) {
			return (
				<ListItem key={ index } className="shipping-zone__location is-placeholder" >
					<ListItemField className="shipping-zone__location-title">
						<div className="shipping-zone__placeholder-flag" />
						<span />
					</ListItemField>
					<ListItemField className="shipping-zone__location-summary">
						<span />
						<span />
					</ListItemField>
				</ListItem>
			);
		}

		return (
			<ListItem key={ index } className="shipping-zone__location" >
				<ListItemField className="shipping-zone__location-title">
					{ getLocationFlag( location ) }
					{ decodeEntities( location.name ) }
				</ListItemField>
				<ListItemField className="shipping-zone__location-summary">
					{ getLocationDescription( location ) }
				</ListItemField>
			</ListItem>
		);
	};
Ejemplo n.º 11
0
	renderOption = option => {
		return (
			<option key={ `${ option.continent }-${ option.code }` } value={ option.code }>
				{ decodeEntities( option.name ) }
			</option>
		);
	};
Ejemplo n.º 12
0
export function details( context, next ) {
	const { slug } = context.params;
	const user = getCurrentUser( context.store.getState() );
	const themeName = ( getThemeDetails( context.store.getState(), slug ) || false ).name;
	const title = i18n.translate( '%(themeName)s Theme', {
		args: { themeName }
	} );
	const Head = user
		? require( 'layout/head' )
		: require( 'my-sites/themes/head' );

	const props = {
		themeSlug: slug,
		contentSection: context.params.section,
		title: decodeEntities( title ) + ' — WordPress.com', // TODO: Use lib/screen-title's buildTitle. Cf. https://github.com/Automattic/wp-calypso/issues/3796
		isLoggedIn: !! user
	};

	const ConnectedComponent = ( { themeSlug, contentSection } ) => (
		<ThemeDetailsComponent id={ themeSlug } >
			<ThemeSheetComponent section={ contentSection } />
		</ThemeDetailsComponent>
	);

	context.primary = makeElement( ConnectedComponent, Head, context.store, props );
	context.secondary = null; // When we're logged in, we need to remove the sidebar.
	next();
}
Ejemplo n.º 13
0
	renderItem( item, _recurse = false ) {
		const { site } = this.props;

		// if item has a parent and it is in current props.categories, do not render
		if ( item.parent && ! _recurse && includes( this.catIds, item.parent ) ) {
			return;
		}
		const children = this.getChildren( item.id );
		const itemId = item.id;
		const link = getLink( '/store/products/category/:site/' + itemId, site );
		const description = decodeEntities( stripHTML( item.description ) );

		return (
			<div key={ 'product-category-' + itemId } className="product-categories__list-item">
				<CompactCard key={ itemId } className="product-categories__list-item-card" href={ link }>
					<div className="product-categories__list-item-wrapper">
						<div className="product-categories__list-thumb">
							<ImageThumb src={ ( item.image && item.image.src ) || '' } alt="" />
						</div>
						<span className="product-categories__list-item-info">
							<span className="product-categories__list-item-name">{ item.name }</span>
							<Count count={ item.count } />
							<span className="product-categories__list-item-description">{ description }</span>
						</span>
					</div>
				</CompactCard>
				{ children.length > 0 && (
					<div className="product-categories__list-nested">
						{ children.map( child => this.renderItem( child, true ) ) }
					</div>
				) }
			</div>
		);
	}
	return mapValues( object, value => {
		if ( 'object' === typeof value ) {
			return filterObjectProperties( value );
		}

		return value ? decodeEntities( value ) : value;
	} );
Ejemplo n.º 15
0
	return map( response.sites, site => ( {
		feedId: site.feed_id,
		blogId: site.blog_id,
		title: decodeEntities( site.blog_title ),
		url: site.blog_url,
		railcar: site.railcar,
		algorithm: response.algorithm,
	} ) );
Ejemplo n.º 16
0
		return transform( plugin, function( returnData, item, key ) {
			switch ( key ) {
				case 'short_description':
				case 'description':
				case 'name':
				case 'slug':
					returnData[ key ] = decodeEntities( item );
					break;
				case 'author':
					returnData.author = item;
					returnData.author_name = PluginUtils.extractAuthorName( item );
					returnData.author_url = plugin.author_url || PluginUtils.extractAuthorUrl( item );
					break;
				case 'sections':
					let cleanItem = {};
					for ( let sectionKey of Object.keys( item ) ) {
						cleanItem[ sectionKey] = sanitizeHtml( item[ sectionKey ], {
							allowedTags: [ 'h4', 'h5', 'h6', 'blockquote', 'code', 'b', 'i', 'em', 'strong', 'a', 'p', 'img', 'ul', 'ol', 'li' ],
							allowedAttributes: { a: [ 'href' ], img: [ 'src' ] },
							allowedSchemes: [ 'http', 'https' ],
							transformTags: {
								h1: 'h3',
								h2: 'h3',
							}
						} );
					}
					returnData.sections = cleanItem;
					returnData.screenshots = cleanItem.screenshots ? PluginUtils.extractScreenshots( cleanItem.screenshots ) : null;
					break;
				case 'num_ratings':
				case 'rating':
					returnData[ key ] = parseInt( item, 10 );
					break;
				case 'ratings':
					for ( let prop in item ) {
						item[ prop ] = parseInt( item[ prop ], 10 );
					}
					returnData[ key ] = item;
					break;
				case 'icons':
					if ( item ) {
						returnData.icon = item[ '2x' ] || item[ '1x' ] || item.svg || item.default;
					}
					break;
				case 'homepage':
				case 'plugin_url':
					returnData.plugin_url = item;
					break;
				case 'compatibility':
					returnData[ key ] = PluginUtils.normalizeCompatibilityList( item );
					break;
				default:
					returnData[ key ] = item;
			}
		} );
Ejemplo n.º 17
0
function startEditing( post ) {
	resetState();
	post = normalize( post );
	if ( post.title ) {
		post.title = decodeEntities( post.title );
	}
	_previewUrl = utils.getPreviewURL( post );
	_savedPost = Object.freeze( post );
	_post = _savedPost;
	_isLoading = false;
}
Ejemplo n.º 18
0
function receiveList( newList ) {
	const existing = ListStore.get( newList.owner, newList.slug );

	newList.URL = getListURL( newList );
	newList.title = decodeEntities( newList.title );

	if ( ! isEqual( existing, newList ) ) {
		lists[ keyForList( newList.owner, newList.slug ) ] = newList;
		ListStore.emit( 'change' );
	}
}
Ejemplo n.º 19
0
		noscripts.forEach( function( noscript ) {
			if ( ! noscript.firstChild ) {
				return;
			}
			let firstChildData = formatting.decodeEntities( noscript.firstChild.data );
			let match = firstChildData.match( '^<a href="http:\/\/polldaddy.com\/poll\/([0-9]+)' );
			if ( match ) {
				let p = document.createElement( 'p' );
				p.innerHTML = '<a rel="external" target="_blank" href="http://polldaddy.com/poll/' + match[1] + '">' + i18n.translate( 'Take our poll' ) + '</a>';
				noscript.parentNode.replaceChild( p, noscript );
			}
		} );
Ejemplo n.º 20
0
	return transform( plugin, function( returnData, item, key ) {
		switch ( key ) {
			case 'short_description':
			case 'description':
			case 'name':
			case 'slug':
				returnData[ key ] = decodeEntities( item );
				break;
			case 'author':
				returnData.author = item;
				returnData.author_name = extractAuthorName( item );
				returnData.author_url = plugin.author_url || extractAuthorUrl( item );
				break;
			case 'sections':
				const cleanItem = {};
				for ( const sectionKey of Object.keys( item ) ) {
					cleanItem[ sectionKey ] = sanitizeSectionContent( item[ sectionKey ] );
				}
				returnData.sections = cleanItem;
				returnData.screenshots = cleanItem.screenshots
					? extractScreenshots( cleanItem.screenshots )
					: null;
				break;
			case 'num_ratings':
			case 'rating':
				returnData[ key ] = parseInt( item, 10 );
				break;
			case 'ratings':
				for ( const prop in item ) {
					item[ prop ] = parseInt( item[ prop ], 10 );
				}
				returnData[ key ] = item;
				break;
			case 'icons':
				if ( item ) {
					returnData.icon = item[ '2x' ] || item[ '1x' ] || item.svg || item.default;
				}
				break;
			case 'homepage':
			case 'plugin_url':
				returnData.plugin_url = item;
				break;
			case 'compatibility':
				returnData[ key ] = normalizeCompatibilityList( item );
				break;
			default:
				returnData[ key ] = item;
		}
	} );
Ejemplo n.º 21
0
function updatePost( post ) {
	post = normalize( post );
	if ( post.title ) {
		post.title = decodeEntities( post.title );
	}
	_previewUrl = utils.getPreviewURL( post );
	_savedPost = Object.freeze( post );
	_post = _savedPost;
	_isNew = false;
	_loadingError = null;

	// To ensure that edits made while an update is inflight are not lost, we need to apply them to the updated post.
	_queue.forEach( function( change ) {
		set( change );
	} );
}
Ejemplo n.º 22
0
	state => {
		let title = '';

		const unreadCount = getDocumentHeadCappedUnreadCount( state );
		if ( unreadCount ) {
			title += `(${ unreadCount }) `;
		}

		title += compact( [
			getDocumentHeadTitle( state ),
			isSiteSection( state ) && getSiteTitle( state, getSelectedSiteId( state ) ),
		] ).join( ' ‹ ' );

		if ( title ) {
			title = decodeEntities( title ) + ' — ';
		}

		return title + 'WordPress.com';
	},
Ejemplo n.º 23
0
	renderFooterLinks() {
		const { translate } = this.props;
		const { authorizeSuccess, isAuthorizing } = this.props.authorizationData;
		const { blogname, redirectAfterAuth } = this.props.authQuery;
		const backToWpAdminLink = (
			<LoggedOutFormLinkItem href={ redirectAfterAuth }>
				<Gridicon size={ 18 } icon="arrow-left" />{' '}
				{ translate( 'Return to %(sitename)s', {
					args: { sitename: decodeEntities( blogname ) },
				} ) }
			</LoggedOutFormLinkItem>
		);

		if ( this.retryingAuth || isAuthorizing || authorizeSuccess || this.redirecting ) {
			return null;
		}

		return (
			<LoggedOutFormLinks>
				{ this.isWaitingForConfirmation() ? backToWpAdminLink : null }
				<LoggedOutFormLinkItem
					href={ login( {
						isJetpack: true,
						isNative: config.isEnabled( 'login/native-login-links' ),
						redirectTo: window.location.href,
					} ) }
				>
					{ translate( 'Sign in as a different user' ) }
				</LoggedOutFormLinkItem>
				<LoggedOutFormLinkItem onClick={ this.handleSignOut }>
					{ translate( 'Create a new account' ) }
				</LoggedOutFormLinkItem>
				<JetpackConnectHappychatButton eventName="calypso_jpc_authorize_chat_initiated">
					<HelpButton />
				</JetpackConnectHappychatButton>
			</LoggedOutFormLinks>
		);
	}
Ejemplo n.º 24
0
function buildTitle( title, options ) {
	let pageTitle = '';

	options = toImmutable( options );

	if ( options.get( 'count' ) ) {
		pageTitle += '(' + options.get( 'count' ) + ') ';
	}

	pageTitle += title;

	if ( options.get( 'siteID' ) ) {
		pageTitle = appendSite( pageTitle, options );
	}

	if ( pageTitle ) {
		pageTitle = decodeEntities( pageTitle ) + ' — WordPress.com';
	} else {
		pageTitle = 'WordPress.com';
	}

	return pageTitle;
}
Ejemplo n.º 25
0
function receiveFeed( feedId, attributes ) {
	var feed = feeds[ feedId ];
	if ( ! feed ) {
		feed = new FeedRecord( { feed_ID: feedId } );
	}
	attributes = pick( attributes, [
		'feed_ID',
		'blog_ID',
		'name',
		'URL',
		'feed_URL',
		'subscribers_count',
		'state',
		'error'
	] );
	if ( attributes.name ) {
		attributes.name = decodeEntities( attributes.name );
	}
	if ( ! attributes.state ) {
		attributes.state = State.COMPLETE;
	}
	feed = feed.merge( attributes );
	setFeed( feedId, feed );
}
Ejemplo n.º 26
0
		forOwn( post.tags, function( tag ) {
			tag.name = formatting.decodeEntities( tag.name );
		} );
Ejemplo n.º 27
0
	forEach( [ 'excerpt', 'title', 'site_name' ], function( prop ) {
		if ( post[ prop ] ) {
			post[ prop ] = formatting.decodeEntities( post[ prop ] );
		}
	} );
Ejemplo n.º 28
0
	extractAuthorName: function( authorElementSource ) {
		if ( ! authorElementSource ) {
			return '';
		}
		return decodeEntities( authorElementSource.replace( /(<([^>]+)>)/ig, '' ) );
	},
Ejemplo n.º 29
0
	forEach( [ 'excerpt', 'title', 'site_name' ], function( prop ) {
		if ( post[ prop ] ) {
			post[ prop ] = decode( post[ prop ] );
		}
	} );
Ejemplo n.º 30
0
		forOwn( post.tags, function( tag ) {
			tag.name = decode( tag.name );
		} );