<?php
/**
 * Subscription section
 *
 * This is the template for the content of subscription section
 *
 * @package Theme Palace
 * @subpackage enlightme Pro
 * @since enlightme Pro 1.0.0
 */
if ( ! function_exists( 'enlightme_pro_add_subscription_section' ) ) :
    /**
    * Add subscription section
    *
    *@since enlightme Pro 1.0.0
    */
    function enlightme_pro_add_subscription_section() {
        $options = enlightme_pro_get_theme_options();

        // Check if subscription is enabled on frontpage
        $subscription_enable = apply_filters( 'enlightme_pro_section_status', true, 'subscription_section_enable' );
        
        if ( true !== $subscription_enable ) {
           return false;
        }

        // Render subscription section now.
        enlightme_pro_render_subscription_section();
    }
endif;

if ( ! function_exists( 'enlightme_pro_render_subscription_section' ) ) :
  /**
   * Start subscription section
   *
   * @return string subscription content
   * @since enlightme Pro 1.0.0
   *    
   */
function enlightme_pro_render_subscription_section() {
    if ( ! class_exists( 'Jetpack' ) ) {
       return;
    } elseif ( class_exists( 'Jetpack' ) ) {
        if ( ! Jetpack::is_module_active( 'subscriptions' ) )
           return;
    }
    $options = enlightme_pro_get_theme_options();

    $subscription_title             = ! empty( $options['subscription_title'] ) ? $options['subscription_title'] : '';
    $subscription_description       = ! empty( $options['subscription_description'] ) ? $options['subscription_description'] : '';
    $subscription_btn_title         = ! empty( $options['subscription_btn_title'] ) ? $options['subscription_btn_title'] : esc_html__( 'Subscribe Now', 'enlightme-pro' );
    $subscription_image          = ! empty( $options['subscription_image'] ) ? $options['subscription_image'] : '';

 ?>

 <div id="enlightme_pro_subscription_section">

    <div id="subscribe-now" class="relative page-section same-background">
        <div class="wrapper">
            <article>
                <div class="featured-image">
                    <img src="<?php echo esc_url($subscription_image); ?>" alt="<?php echo esc_attr($subscription_title); ?>">
                </div>

                <div class="entry-container">
                    <div class="section-header">
                        <?php if( !empty( $subscription_title ) ):
                            ?>
                            <h2 class="section-title"><?php echo esc_html($subscription_title); ?></h2>
                        <?php endif;
                        if( !empty( $subscription_description ) ): ?>                            
                            <p><?php echo esc_html($subscription_description); ?></p>                            
                        <?php endif; ?>
                    </div><!-- .section-header -->

                    <div class="subscribe-form-wrapper">
                        <?php 
                        $subscription_shortcode = '[jetpack_subscription_form title="" subscribe_text="" subscribe_button="' . esc_html( $subscription_btn_title ) . '" show_subscribers_total="0"]';
                        echo do_shortcode( wp_kses_post( $subscription_shortcode ) ); 
                        ?> 
                    </div><!-- .subscribe-form-wrapper -->
                </div>
            </article>
        </div><!-- .wrapper -->
    </div><!-- #subscribe-now -->

    </div>
    
    <?php }
endif;