<?php
/**
 * Setup user-read text strings. This function allows
 * to have all of the framework's common localized text
 * strings in once place.
 *
 * The filter "themeblvd_frontend_locals"
 * can be used to add/remove strings.
 *
 * @since 2.1.0
 */
function themeblvd_get_all_locals() {
	$locals = array (
		'404'						=> __('Apologies, but the page you\'re looking for can\'t be found.', 'gnar'),
		'404_title'					=> __('404 Error', 'gnar'),
		'all'						=> __('All', 'gnar'),
		'archive_no_posts'			=> __('Apologies, but there are no posts to display.', 'gnar'),
		'archive'					=> __('Archive', 'gnar'),
		'aside'						=> __('Aside', 'gnar'),
		'audio'						=> __('Audio', 'gnar'),
		'by'						=> __('by', 'gnar'),
		'cancel_reply_link'			=> __('Cancel reply', 'gnar'),
		'cart'						=> __('Shopping Cart', 'gnar'),
		'categories'				=> __('Categories', 'gnar'),
		'category'					=> __('Category', 'gnar'),
		'chat'						=> __('Chat', 'gnar'),
		'close'						=> __('Close', 'gnar'),
		'comment_navigation'		=> __('Comment navigation', 'gnar'),
		'comment'					=> __('Comment', 'gnar'),
		'comments'					=> __('Comments', 'gnar'),
		'comments_closed'			=> __('Comments are closed.', 'gnar'),
		'comments_newer'			=> __('Newer Comments &rarr;', 'gnar'),
		'comments_no_password'		=> __('This post is password protected. Enter the password to view any comments.', 'gnar'),
		'comments_notes_after'		=> __('You may use these HTML tags and attributes: %s', 'gnar'),
		'comments_older'			=> __('&larr; Older Comments', 'gnar'),
		'comments_title_single'		=> __('One comment on &ldquo;%2$s&rdquo;', 'gnar'),
		'comments_title_multiple'	=> __('%1$s comments on &ldquo;%2$s&rdquo;', 'gnar'),
		'contact_facebook'			=> __('Facebook', 'gnar'),
		'contact_gplus'				=> __('Google+', 'gnar'),
		'contact_linkedin'			=> __('LinkedIn', 'gnar'),
		'contact_pinterest'			=> __('Pinterest', 'gnar'),
		'contact_twitter'			=> __('Twitter', 'gnar'),
		'contact_us'				=> __('Contact Us', 'gnar'),
		'crumb_404'					=> __('Error 404', 'gnar'),
		'crumb_author'				=> __('Articles posted by', 'gnar'),
		'crumb_search'				=> __('Search results for', 'gnar'),
		'crumb_tag'					=> __('Posts tagged', 'gnar'),
		'crumb_tag_products'		=> __('Products tagged', 'gnar'),
		'edit_attachment'			=> __('Edit Attachment', 'gnar'),
		'edit_page'					=> __('Edit Page', 'gnar'),
		'edit_post'					=> __('Edit Post', 'gnar'),
		'edit_profile'				=> __('Edit Profile', 'gnar'),
		'email'						=> __('Email', 'gnar'),
		'enlarge'					=> __('Enlarge Image', 'gnar'),
		'gallery'					=> __('Gallery', 'gnar'),
		'go_to_link'				=> __('Visit Website', 'gnar'),
		'home'						=> __('Home', 'gnar'),
		'image'						=> __('Image', 'gnar'),
		'in'						=> __('in', 'gnar'),
		'invalid_layout'			=> __('Invalid Layout ID: The layout ID currently assigned to this page no longer exists.', 'gnar'),
		'label_submit'				=> __('Post Comment', 'gnar'),
		'language'					=> __('Set Language', 'gnar'),
		'last_30'					=> __('The Last 30 Posts', 'gnar'),
		'leave_comment'				=> __('Leave a Comment', 'gnar'),
		'lightbox_counter'			=> __('%curr% of %total%', 'gnar'),
		'lightbox_error'			=> __('The lightbox media could not be loaded.', 'gnar'),
		'link'						=> __('Link', 'gnar'),
		'link_to_lightbox'			=> __('Link to lightbox', 'gnar'),
		'loading'					=> __('Loading...', 'gnar'),
		'login_text'				=> __('Log in to Reply', 'gnar'),
		'monthly_archives'			=> __('Monthly Archives', 'gnar'),
		'my_account'				=> __('My Account', 'gnar'),
		'name'						=> __('Name', 'gnar'),
		'no_builder_plugin'			=> __('In order for your custom layout to be displayed, you must be have the %s plugin installed.', 'gnar'),
		'page'						=> __('Page', 'gnar'),
		'pages'						=> __('Pages', 'gnar'),
		'page_num'					=> __('Page %s', 'gnar'),
		'play'						=> __('Play Movie', 'gnar'),
		'posted_on'					=> __('Posted on', 'gnar'),
		'posted_in'					=> __('Posted in', 'gnar'),
		'posts_per_category'		=> __('Posts per category', 'gnar'),
		'navigation' 				=> __('Navigation', 'gnar'),
		'next'						=> __('Next', 'gnar'),
		'no_comments'				=> __('No Comments', 'gnar'),
		'no_slider' 				=> __('Slider does not exist.', 'gnar'),
		'no_slider_selected' 		=> __('Oops! You have not selected a slider in your layout.', 'gnar'),
		'no_video'					=> __('The video url could not retrieve a video.', 'gnar'),
		'previous'					=> __('Previous', 'gnar'),
		'quote'						=> __('Quote', 'gnar'),
		'read_more'					=> __('Read More', 'gnar'),
		'related_posts'				=> __('Related Posts', 'gnar'),
		'reply'						=> __('Reply', 'gnar'),
		'search'					=> __('Search the site...', 'gnar'),
		'search_2'					=> __('Search', 'gnar'),
		'search_no_results'			=> __('Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'gnar'),
		'search_results'			=> __('%s total search results found for: %s', 'gnar'),
		'status'					=> __('Status', 'gnar'),
		'tag'						=> __('Tag', 'gnar'),
		'tags'						=> __('Tags', 'gnar'),
		'title_reply'				=> __('Leave a Reply', 'gnar'),
		'title_reply_to'			=> __('Leave a Reply to %s', 'gnar'),
		'top'						=> __('Top', 'gnar'),
		'via'						=> __('via', 'gnar'),
		'video'						=> __('Video', 'gnar'),
		'view_post'					=> __('View Post', 'gnar'),
		'view_item'					=> __('View Item Details', 'gnar'),
		'view_posts_by'				=> __('View all posts by %s', 'gnar'),
		'website'					=> __('Website', 'gnar')
	);

	// Return with framework's filter applied
	return apply_filters( 'themeblvd_frontend_locals', $locals );
}

/**
 * Return user read text string.
 *
 * @since 2.0.0
 *
 * @param string $id Key for $locals array
 * @return string $text Localized and filtered text string
 */
function themeblvd_get_local( $id ) {

	$text = null;
	$locals = themeblvd_get_all_locals();

	// Set text string
	if ( isset( $locals[$id] ) ) {
		$text = $locals[$id];
	}

	return esc_html($text);
}

/**
 * Setup JavaScript localized strings for
 * themeblvd.js
 *
 * The filter "themeblvd_js_locals"
 * can be used to add/remove strings or other
 * variables we want to pass through to our primary
 * "themeblvd" script.
 *
 * @since 2.2.0
 */
function themeblvd_get_js_locals() {

	$locals = array (
		'scroll_to_top'		=> 'true',
		'custom_buttons'	=> 'true'
	);

	// Is this mobile? -- body class isn't always reliable.
	if ( wp_is_mobile() ) {
		$locals['mobile'] = 'true';
	} else {
		$locals['mobile'] = 'false';
	}

	// Extend $locals to accomodate scripts being included
	// through our "themeblvd_global_config" filter.
	// This allows people to remove jQuery plugin files
	// w/out having to also remove functions from themeblvd.js.
	if ( themeblvd_supports( 'assets', 'bootstrap' ) ) {
		$locals['bootstrap'] = 'true';
	}

	// Magnific Popup Lightbox integration
	if ( themeblvd_supports( 'assets', 'magnific_popup' ) ) {

		$locals['magnific_popup'] = 'true';

		// Magnific Popup animation
		$locals['lightbox_animation'] = themeblvd_get_option( 'lightbox_animation' );

		// Disable standard lightbox on mobile?
		if ( 'yes' == themeblvd_get_option( 'lightbox_mobile' ) ) {
			$locals['lightbox_mobile'] = '768';
		} else {
			$locals['lightbox_mobile'] = '0';
		}

		// Disable iframe lightboxes (i.e. video, google maps) on mobile?
		if ( 'yes' == themeblvd_get_option( 'lightbox_mobile_iframe' ) ) {
			$locals['lightbox_mobile_iframe'] = '768';
		} else {
			$locals['lightbox_mobile_iframe'] = '0';
		}

		// Disable gallery lightboxes on mobile?
		if ( 'yes' == themeblvd_get_option( 'lightbox_mobile_gallery' ) ) {
			$locals['lightbox_mobile_gallery'] = '768';
		} else {
			$locals['lightbox_mobile_gallery'] = '0';
		}

		// Text strings
		$locals['lightbox_error'] = themeblvd_get_local('lightbox_error');
		$locals['lightbox_close'] = themeblvd_get_local('close');
		$locals['lightbox_loading'] = themeblvd_get_local('loading');
		$locals['lightbox_counter'] = themeblvd_get_local('lightbox_counter');
		$locals['lightbox_next'] = themeblvd_get_local('next');
		$locals['lightbox_previous'] = themeblvd_get_local('previous');

	}

	// Gallery integration
	if ( themeblvd_supports( 'display', 'gallery' ) ) {

		$locals['gallery'] = 'true';

		if ( apply_filters('themeblvd_gallery_thumb_frame', false) ) {
			$locals['gallery_thumb_frame'] = 'true';
		} else {
			$locals['gallery_thumb_frame'] = 'false';
		}
	}

	// Superfish for drop down menus
	if ( themeblvd_supports('assets', 'superfish') ) {
		$locals['superfish'] = 'true';
	}

	// Responsive nav menu fixed to the side on mobile
	if ( themeblvd_supports('display', 'responsive') && themeblvd_supports('display', 'mobile_side_menu') ) {

		$locals['mobile_panel'] = 'true';
		$locals['mobile_panel_class'] = implode( ' ', apply_filters( 'themeblvd_mobile_panel_class', array() ) );
		$locals['mobile_menu_viewport_max'] = '992';

		$locals['mobile_menu_location'] = 'right';

		if ( is_rtl() ) {
			$locals['mobile_menu_location'] = 'left';
		}
	}

	// Side Panel
	if ( themeblvd_do_side_panel() ) {
		$locals['side_panel'] = 'true';
	}

	// Sticky header
	$locals['sticky'] = 'false';

	if ( themeblvd_config('sticky') && ! wp_is_mobile() && ! themeblvd_is_ie( array('7', '8', '9') ) ) {
		$locals['sticky'] = 'true';
		$locals['sticky_class'] = implode( ' ', apply_filters( 'themeblvd_sticky_class', array() ) );
		$locals['sticky_offset'] = apply_filters('themeblvd_sticky_offset', '48');
		$locals['sticky_logo'] = apply_filters('themeblvd_sticky_logo_uri', ''); // Optional override, so theme's header logo isn't used
	}

	// Custom scroll-to-section offset
	if ( $offset = apply_filters('themeblvd_scroll_to_section_offset', '') ) {
		$locals['scroll_to_section_offset'] = $offset;
	}

	// Tab deep linking -- i.e. link to a tab on a page and set it open
	if ( apply_filters( 'themeblvd_tabs_deep_linking', false ) ) {
		$locals['tabs_deep_linking'] = 'true';
	}

	return apply_filters( 'themeblvd_js_locals', $locals );
}
