<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
} // Exit if accessed directly
/**
 * The template for displaying the footer.
 *
 * Contains all content after the closing of the id=main div
 *
 */

function aweaver_footer() {

	if ( aweaver_getopt( 'footer_hide' ) != 'hide' ) {
		$f_class = aweaver_area_class( 'footer', 'pad', '-trbl', 'margin-none' );        // $f_class does not need escaping
		?>
	<footer id="colophon" <?php echo 'class="colophon ';
	aweaver_trusted_echo( $f_class );
	echo '"';
	aweaver_schema( 'footer' ); ?>>
		<div id="colophon-inside" class="block-inside">
		<?php // +since: 3.1.10: removed role='contentinfo' on footer

		if ( apply_filters( 'aweaver_replace_pb_area', 'footer' ) == 'footer' ) {
			if ( aweaver_has_widgetarea( 'footer-widget-area' ) ) {
				$p_class = aweaver_area_class( 'footer_sb', 'pad', '', 'margin-bottom' );
				aweaver_put_widgetarea( 'footer-widget-area', $p_class );
				aweaver_clear_both( 'footer-widget-area' );
			}

			/* ======== EXTRA HTML ======== */

			$extra = aweaver_get_per_page_value( '_pp_footer_html' );
			if ( $extra == '' ) {
				$extra = aweaver_getopt( 'footer_html_text' );
			}            // $extra is privileged user defined, not translated, no escaping necessary

			$hide = aweaver_getopt_default( 'footer_html_hide', 'hide-none' );

			if ( $extra == '' && is_customize_preview() ) {
				echo '<div id="footer-html" style="display:inline;"></div>';        // need the area there for customizer live preview
			} elseif ( $extra != '' && $hide != 'hide' ) {

				$c_class = aweaver_area_class( 'footer_html', 'not-pad', '-none', 'margin-none' );    // no translations - no need for escaping

				if ( aweaver_getopt_expand( 'expand_header-html' ) ) {
					$c_class .= ' wvrx-expand-full';
				}

				// see if the content is just an int, assume it to be a post id if so.
				// it seems that if a string has an int in it, the ( int ) cast will just cast that part, and throw away the rest.
				// we want an int and only an int, so we double cast to test, and that seems to work

				$post_idw = (int) trim( $extra );

				if ( ( string ) $post_idw == $extra && $post_idw != 0 ) {        // assume a number only is a post id to provide as replacement
					$builder_content = apply_filters( 'aweaver_page_builder_content', $post_idw, 'footer-html', $c_class );
					// $builder_content is generated by a page builder, and cannot be sanitized here or it will break that content
					// We have to assume that the page builder generates properly sanitized content.
					aweaver_trusted_echo( $builder_content );
				} else {
					?>
					<div id="footer-html" class="<?php aweaver_trusted_echo( $c_class ); ?>">
						<?php echo do_shortcode( $extra ); ?>
					</div> <!-- #footer-html -->
				<?php }
			}

			/* ======== COPYRIGHT AREA ======== */

			$date = getdate();
			$yearw = $date['year'];
			if ( aweaver_getopt_expand( 'expand_site-ig-wrap' ) ) {
				echo '<div id="site-ig-wrap" class="wvrx-expand-full">';
			} else {
				echo '<div id="site-ig-wrap">';
			}
			echo '<span id="site-info">' . "\n";

			$cp = aweaver_getopt( 'copyright' );
			$copy = '';
			if ( strlen( $cp ) > 0 ) {
				if ( $cp != '&nbsp;' )    // really leave nothing if specify blank
				{
					$copy = do_shortcode( $cp );
				}
			} else {
				$copy = '&copy;' . $yearw . ' - <a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr( get_bloginfo( 'name', 'display' ) ) .
				        '" rel="home">' . get_bloginfo( 'name' ) . '</a>';
			}
			// $copy has already been escaped. It might contain user define HTML tags, and does not need more sanitizing here.
			aweaver_trusted_echo( apply_filters( 'aweaver_copyright', $copy ) );
			?>
			</span> <!-- #site-info -->
			<?php
			$privacy_link = '';
			if ( function_exists( 'get_the_privacy_policy_link' ) ) {
				$privacy_link = get_the_privacy_policy_link( '', '' );
			}

			if ( ! aweaver_getopt( '_hide_poweredby' ) ) {
				$powered_by = '<span id="site-generator">'
				              . '<a href="' . esc_url( esc_html__( '//wordpress.org/', 'absolute-weaver' ) ) . '" title="'
				              . esc_html__( 'Proudly powered by WordPress', 'absolute-weaver' )
				              . '" target="_blank" rel="nofollow"><span style="font-size:120%;padding-top:2px;" class="genericon genericon-wordpress"></span> - '
				              . aweaver_site_link( '', 'Absolute Weaver Theme', '', false )
				              . $privacy_link . '</span> <!-- #site-generator -->';
				// Powered by may contain theme or user defined HTML code, and can not be further escaped
				aweaver_trusted_echo( apply_filters( 'aweaver_poweredby', $powered_by ) );
			} else {
				echo '<span id="site-generator">';
				aweaver_trusted_echo( $privacy_link );
				echo '</span>';        // privacy link already generated by WP core, no escaping
			}
			aweaver_clear_both( 'site-generator' ); ?>
			</div><!-- #site-ig-wrap -->
			<?php aweaver_clear_both( 'site-ig-wrap' ); ?>
			</div></footer><!-- #colophon-inside, #colophon -->
			<?php
			aweaver_clear_both( 'colophon' );
		} else {    // end if not footer pagebuilder replacement
			echo "</div></footer><!-- #colophon-inside, #colophon -->\n";
			aweaver_clear_both( 'colophon' );
		}
	} // end if !hide_footer


	do_action( 'aweaverplus_action', 'footer' );

	echo "</div><!-- /#wrapper --><div class='clear-wrapper-end' style='clear:both;'></div>\n";
	aweaver_inject_area( 'postfooter' );        // and this is the end options insertion
	do_action( 'aweaverplus_action', 'postfooter' );
	echo "\n<a href=\"#page-top\" id=\"page-bottom\">&uarr;</a>\n";

	if ( ! ( $content_h_ff = aweaver_getopt( 'content_h_font_family' ) ) ) {
		$content_h_ff = '0';
	}

	$font_size = aweaver_getopt_default( 'content_h_font_size', 'default' );
	switch ( $font_size ) {
		case 'xxs-font-size':
			$h_fontmult = 0.625;
			break;
		case 'xs-font-size':
			$h_fontmult = 0.75;
			break;
		case 's-font-size':
			$h_fontmult = 0.875;
			break;
		case 'l-font-size':
			$h_fontmult = 1.125;
			break;
		case 'xl-font-size':
			$h_fontmult = 1.25;
			break;
		case 'xxl-font-size':
			$h_fontmult = 1.5;
			break;
		default:
			$h_fontmult = 1;
			break;
	}


	if ( isset( $GLOBALS['aweaver_sb_layout'] ) ) {
		$sb_layout = $GLOBALS['aweaver_sb_layout'];
	} else {
		$sb_layout = 'none';
	}

	$local = array(
		'hideTip'             => ( aweaver_getopt( 'hide_tooltip' ) ) ? '1' : '0',
		'hFontFamily'         => $content_h_ff,
		'hFontMult'           => $h_fontmult,
		'sbLayout'            => $sb_layout,
		'flowColor'           => ( aweaver_getopt( 'flow_color' ) ) ? '1' : '0',
		'full_browser_height' => ( aweaver_getopt( 'full_browser_height' ) ) ? '1' : '0',
		'primary'             => ( aweaver_getopt( 'primary_eq_widgets' ) ) ? '1' : '0',    // #primary-widget-area
		'secondary'           => ( aweaver_getopt( 'secondary_eq_widgets' ) ) ? '1' : '0',  // '#secondary-widget-area',
		'top'                 => ( aweaver_getopt( 'top_eq_widgets' ) ) ? '1' : '0',        // '.widget-area-top',
		'bottom'              => ( aweaver_getopt( 'bottom_eq_widgets' ) ) ? '1' : '0',     // '.widget-area-bottom',
		'header_sb'           => ( aweaver_getopt( 'header_sb_eq_widgets' ) ) ? '1' : '0',  // '#header-widget-area',
		'footer_sb'           => ( aweaver_getopt( 'footer_sb_eq_widgets' ) ) ? '1' : '0',   // '#footer-widget-area',
	);

	wp_localize_script( 'aweaverJSLibEnd', 'wvrxEndOpts', $local );      // in footer.php because don't know the values yet in functions.php
}

aweaver_footer();
wp_footer();
?>
</body>
</html>
