<?php
/**
 * Helper functions.
 *
 * @package Construction_Kit
 */

if ( ! function_exists( 'construction_kit_fonts_url' ) ) {
	/**
	 * Register Google fonts.
	 *
	 * @return string Google fonts URL for the theme.
	 */
	function construction_kit_fonts_url() {
		$fonts_url = '';
		$fonts     = array();
		$subsets   = 'latin,latin-ext';

		/* translators: If there are characters in your language that are not supported by Barlow, translate this to 'off'. Do not translate into your own language. */
		if ( 'off' !== _x( 'on', 'Raleway font: on or off', 'construction-kit' ) ) {
			$fonts[] = 'Raleway:300,300i,400,400i,500,500i,600,600i,700,700i';
		}

		/* translators: If there are characters in your language that are not supported by Playfair Display, translate this to 'off'. Do not translate into your own language. */
		if ( 'off' !== _x( 'on', 'Muli font: on or off', 'construction-kit' ) ) {
			$fonts[] = 'Muli:300,300i,400,400i,600,600i,700,700i';
		}

		if ( $fonts ) {
			$fonts_url = add_query_arg( array(
				'family' => urlencode( implode( '|', $fonts ) ),
				'subset' => urlencode( $subsets ),
			), '//fonts.googleapis.com/css' );
		}

		return $fonts_url;
	}
}

if ( ! function_exists( 'construction_kit_apply_theme_shortcode' ) ) :

	/**
	 * Apply theme shortcode.
	 *
	 * @param string $string Content.
	 *
	 * @return string Modified content.
	 * @since 1.0.0
	 *
	 */
	function construction_kit_apply_theme_shortcode( $string ) {

		if ( empty( $string ) ) {
			return $string;
		}

		$search = array( '[the-year]', '[the-site-title]' );

		$replace = array(
			date_i18n( esc_html_x( 'Y', 'year date format', 'construction-kit' ) ),
			esc_html( get_bloginfo( 'name', 'display' ) ),
		);

		$string = str_replace( $search, $replace, $string );

		return $string;

	}

endif;
