<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
} // Exit if accessed directly
// This file is included from functions.php. It will be loaded only when the wp_head action is called from WordPress.

if ( ! function_exists( 'aweaver_generate_wphead' ) ) {    /* Allow child to override this */
	function aweaver_generate_wphead() {
		/* this guy does ALL the work for generating theme look - it writes out the over-rides to the standard style.css */
		global $aweaver_main_options;

		global $post;

		if ( is_object( $post ) ) {
			aweaver_set_cur_page_id( get_the_ID() );
		}    // we're on a page now, so set the post id for the rest of the session
		else {
			aweaver_set_cur_page_id( 0 );
		}    // no page

		printf( "<!-- %s %s ( %s ) %s --> ", esc_html( ABSOLUTE_WVR_THEMENAME ), esc_html( ABSOLUTE_WVR_VERSION ),
			esc_html( 'style_version' ), esc_html( 'themename' ) );


		do_action( 'aweaverplus_show_version' );

		if ( aweaver_use_inline_css( aweaver_get_css_filename() ) ) { // generate inline CSS
			echo( '<style type="text/css">' . "\n" );
			if ( is_customize_preview() )    // don't use cached CSS from customizer
			{
				$css = '';
			} else {
				$css = aweaver_getopt_default( 'wvrx_css_saved', '' );
			}

			if ( $css == '' || $css[0] != '/' ) {               // there isn't an entry in the DB, so do it on the fly
				require_once( get_template_directory() . '/includes/generatecss.php' );    // include only now at runtime. ( Not a template file )
				aweaver_output_style( 'echo' );
			} else {
				aweaver_echo_css( $css );
			}
			echo( "\n</style> <!-- end of main options style section -->\n" );
		}

		/* now head options */
		aweaver_echo_css( aweaver_getopt( 'head_opts' ) );   /* let the user have the last word! */

		if ( is_single() ) {
			$per_page_code = aweaver_get_per_post_value( 'page-head-code' );
		} else {
			$per_page_code = aweaver_get_per_page_value( 'page-head-code' );
		}
		if ( ! empty( $per_page_code ) ) {
			aweaver_echo_css( $per_page_code );
		}


		if ( $ppsb = aweaver_get_per_page_value( '_pp_sidebar_width' ) > 0 ) {
			require_once( get_template_directory() . '/includes/generatecss.php' );    // include only now at runtime. ( Not a template file )
			$ppsb = aweaver_get_per_page_value( '_pp_sidebar_width' );
			echo "<style type=\"text/css\"> /* Per Page Sidebar Width */\n";
			aweaver_sidebar_style( 'echo', $ppsb );
			echo "</style>\n";
		}

		echo( "\n<!-- End of Absolute Weaver options -->\n" );
	}
}
