<?php
/**
 * Collection of helper functions, and action hook functions.
 *
 * @package Cream_Blog
 */

if ( ! function_exists( 'glaze_blog_lite_fonts_url' ) ) {
	/**
	 * Return Font's URL.
	 *
	 * @since 1.0.0
	 * @return string Fonts URL.
	 */
	function glaze_blog_lite_fonts_url() {

		$fonts_url = '';
		$fonts     = array();
		$subsets   = 'latin,latin-ext';

		/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
		if ('off' !== _x('on', 'Poppins font: on or off', 'glaze-blog-lite')) {

			$fonts[] = 'Poppins:400,400i,500,600,700,700i';
		}

		/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
		if ('off' !== _x('on', 'Oswald font: on or off', 'glaze-blog-lite')) {

			$fonts[] = 'Oswald:400,500,600,700';
		}

		/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
		if ('off' !== _x('on', 'Pacifico font: on or off', 'glaze-blog-lite')) {

			$fonts[] = 'Pacifico';
		}

		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( 'glaze_blog_lite_navigation_fallback' ) ) {
	/**
	 * Callback function for 'fallback_cb' in argument of 'wp_nav_menu'.
	 *
	 * @since 1.0.0
	 */
	function glaze_blog_lite_navigation_fallback() {
		?>
		<ul class="primary-menu">
			<?php
			if ( current_user_can( 'edit_theme_options' ) ) {
				?>
				<li><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Add Menu', 'glaze-blog-lite' ); ?></a></li>
				<?php
			} else {
				wp_list_pages(
					array(
						'title_li' => '',
						'depth'    => 3,
					)
				);
			}
			?>
		</ul>
		<?php
	}
}


if ( ! function_exists( 'glaze_blog_lite_search_form' ) ) {
	/**
	 * Return custom search HTML template.
	 *
	 * @since 1.0.0
	 * @return HTML markup.
	 */
	function glaze_blog_lite_search_form() {

		$form = '<form role="search" method="get" id="search-form" class="clearfix" action="' . esc_url( home_url( '/' ) ) . '"><input type="search" name="s" placeholder="' . esc_attr__( 'Enter Keyword', 'glaze-blog-lite' ) . '" value="' . esc_attr( get_search_query() ) . '"><input type="submit" id="submit" value="' . esc_attr__( 'Search', 'glaze-blog-lite' ) . '"></form>';

		return $form;
	}
}
add_filter( 'get_search_form', 'glaze_blog_lite_search_form' );


if ( ! function_exists( 'glaze_blog_lite_excerpt_length' ) ) {
	/**
	 * Modify post excerpt length.
	 *
	 * @param int $length Excerpt length.
	 */
	function glaze_blog_lite_excerpt_length( $length ) {

		if ( is_admin() ) {

			return $length;
		}

		$excerpt_length = glaze_blog_lite_get_option( 'excerpt_length' );

		if ( absint( $excerpt_length ) > 0 ) {

			$excerpt_length = absint( $excerpt_length );
		}

		return $excerpt_length;
	}
}
add_filter( 'excerpt_length', 'glaze_blog_lite_excerpt_length' );


if ( ! function_exists( 'glaze_blog_lite_excerpt_more' ) ) {
	/**
	 * Trailing text for post excerpts.
	 *
	 * @param string $more The string shown within the more link.
	 * @return string
	 */
	function glaze_blog_lite_excerpt_more( $more ) {

		if ( is_admin() ) {

			return $more;
		}

		return '...';
	}
}
add_filter( 'excerpt_more', 'glaze_blog_lite_excerpt_more' );
