<?php
/*
 * Class MP_Profit_Plugin_Testimonials
 * add testimonials section
 */

class MP_Profit_Plugin_Testimonials {

    public function __construct() {
        add_action('mp_profit_section_testimonials', array($this, 'get_html'));
    }

    /*
     * Get default sidebar 
     */

    public function get_default_sidebar() {
        $args = array(
            'before_title' => '',
            'after_title' => '',
            'before_widget' => '<div class="widget %1$s col-xs-12 col-sm-12 col-md-12 col-lg-12">',
            'after_widget' => '</div>',
        );
        $instance = array(
            'position' => __('Financial adviser', 'mp-profit'),
            'name' => __('Abraham Smith', 'mp-profit'),
            'blockquote' => __('I was able to increase the awareness about the services I provide after partnershipping with Profit Consulting. These guys know their business better than anyone else.', 'mp-profit')
        );
        wp_cache_delete('widget-mp-profit-testimonial', 'widget');
        the_widget('MP_Profit_Plugin_Widget_Testimonial', $instance, $args);
        $instance = array(
            'position' => __('Designer, Magazine.', 'mp-profit'),
            'name' => __('Betty Page', 'mp-profit'),
            'blockquote' => __('Summing up my own experience of working with this company I\'d say just two words - double pleasure! The consultation price is affordable for the designer on budget and the communication with the stuff is a real delight.', 'mp-profit')
        );
        the_widget('MP_Profit_Plugin_Widget_Testimonial', $instance, $args);
        $instance = array(
            'position' => __('Manager, NY Times.', 'mp-profit'),
            'name' => __('James Dean', 'mp-profit'),
            'blockquote' => __('You guys always rock! I continue using the services of Profit Consulting for a couple of years already and never had a chance to be frustrated.', 'mp-profit')
        );
        the_widget('MP_Profit_Plugin_Widget_Testimonial', $instance, $args);
    }

    /*
     * Get sidebar 
     */

    public function get_sidebar() {
        /*
         * mp_profit_before_sidebar_testimonials hook
         *
         * @hooked mp_profit_before_sidebar_testimonials - 10 
         */
        do_action('mp_profit_before_sidebar_testimonials');
        ?>
        <div class="row">
            <?php
            if (is_active_sidebar('sidebar-testimonials')) :
                dynamic_sidebar('sidebar-testimonials');
            else:
                $this->get_default_sidebar();
            endif;
            ?>
            <?php
            /*
             * mp_profit_after_sidebar_testimonials hook
             *
             * @hooked mp_profit_after_sidebar_testimonials - 10 
             */
            do_action('mp_profit_after_sidebar_testimonials');
        }

        /*
         * Get title 
         */

        public function get_title() {
            $mp_profit_testimonials_title = esc_html(get_theme_mod('mp_profit_testimonials_title'));
            if (get_theme_mod('mp_profit_testimonials_title', false) === false) :
                ?> 
                <h2 class="section-title"><?php _e('Testimonials', 'mp-profit'); ?></h2>
                <?php
            else:
                if (!empty($mp_profit_testimonials_title)):
                    ?>
                    <h2 class="section-title"><?php echo $mp_profit_testimonials_title; ?></h2>
                    <?php
                endif;
            endif;
        }

        /*
         * Get subtitle 
         */

        public function get_subtitle() {
            $mp_profit_testimonials_subtitle = esc_html(get_theme_mod('mp_profit_testimonials_subtitle'));
            if (get_theme_mod('mp_profit_testimonials_subtitle', false) === false) :
                ?> 
                <div class="section-subtitle"><?php _e('What our happy customers say', 'mp-profit'); ?></div>
                <?php
            else:
                if (!empty($mp_profit_testimonials_subtitle)):
                    ?>
                    <div class="section-subtitle"><?php echo $mp_profit_testimonials_subtitle; ?></div>
                    <?php
                endif;
            endif;
        }

        public function get_html() {
            ?>
            <section id="testimonials" class="testimonials-section grey-section default-section">
                <div class="container">
                    <div class="section-content">
                        <?php
                        $this->get_title();
                        $this->get_subtitle();
                        $this->get_sidebar();
                        ?>
                    </div>
                </div>
        </div>
        </section>
        <?php
    }

}
