<?php
/*
 * Template Name: Organic Custom
 * Description: The Page Template for Organic Custom Widgets
 */

/*-- Check for Overriding Template in theme --*/
if ( locate_template( 'organic-custom-template.php' ) != '' ) {

	// Load the overriding page template from the theme.
	get_template_part( 'organic', 'custom-template' );

} else {

	// Load the default Custom Template from the plugin.
	get_header(); ?>

	<!-- BEGIN .post class -->
	<div <?php post_class(); ?> id="page-<?php the_ID(); ?>">

		<!-- BEGIN .organic-ocw-container -->
		<div class="organic-ocw-container">

			<?php if ( ! post_password_required() ) { ?>

				<?php
				if ( have_posts() ) :
					while ( have_posts() ) :
						the_post();
						?>

						<?php if ( is_active_sidebar( ORGANIC_WIDGET_PREFIX . 'page-' . get_the_ID() . '-widget-area' ) ) { ?>

							<?php dynamic_sidebar( ORGANIC_WIDGET_PREFIX . 'page-' . get_the_ID() . '-widget-area' ); ?>

						<?php } else { ?>

							<!-- BEGIN .organic-widgets-card -->
							<div class="organic-widgets-card organic-widgets-no-content">

								<p class="text-center"><?php printf( wp_kses_post( __( 'This page has the "Organic Custom" page template applied. Begin <a href="%1$s">Adding Widgets</a> to the page within the WordPress Customizer.', 'organic-widgets-pro' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( Organic_Widgets_Pro_Admin::get_customize_url() ) ); ?></p>

							<!-- END .organic-widgets-card -->
							</div>

						<?php } ?>

					<?php endwhile; ?>
				<?php endif; ?>

			<?php } else { ?>

				<div class="password-form-wrapper">

					<svg class="password-lock-icon" version="1.1" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24">
						<path d="M18 10v-2c0-3.309-2.691-6-6-6s-6 2.691-6 6v2c-1.103 0-2 0.897-2 2v8c0 1.103 0.897 2 2 2h12c1.103 0 2-0.897 2-2v-8c0-1.103-0.897-2-2-2zM8 8c0-2.206 1.794-4 4-4s4 1.794 4 4v2h-8v-2zM18 20h-12v-8h12v8c0.003 0 0 0 0 0z"></path>
						<path d="M12 13c-1.103 0-2 0.897-2 2v3.5c0 0.275 0.225 0.5 0.5 0.5h3c0.275 0 0.5-0.225 0.5-0.5v-3.5c0-1.103-0.897-2-2-2zM13 18h-2v-3c0-0.55 0.45-1 1-1s1 0.45 1 1v3z"></path>
					</svg>

					<?php echo get_the_password_form(); ?>

				</div>

			<?php } ?>

		<!-- END .organic-ocw-container -->
		</div>

	<!-- END .post class -->
	</div>

	<?php
	get_footer();

}
