<?php if(! defined('ABSPATH')){ return; }
/*
Name: Latest Posts 4
Description: Create and display a Latest Posts 4 element
Class: TH_LatestPosts4
Category: content
Level: 3
*/

/**
 * Class TH_LatestPosts4
 *
 * Create and display a Latest Posts 4 element
 *
 * @package  Kallyas
 * @category Page Builder
 * @author   Team Hogash
 * @since    3.8.0
 */
class TH_LatestPosts4 extends ZnElements
{
    public static function getName(){
        return __( "Latest Posts 4", 'zn_framework' );
    }

    /**
     * This method is used to display the output of the element.
     * @return void
     */
    function element()
    {
        $options = $this->data['options'];

        $style = (isset($options['lp_style_select']) ? $options['lp_style_select'] : 'default-style');
        $placement = (isset($options['lp_placement']) ? $options['lp_placement'] : 'normal');


        // required inside /inc/...
        global $post;

        // Check what categories were selected..if any
        $blog_category = array(0);
        if ( ! empty ( $options['lp_blog_categories'] ) ) {
            $blog_category = array_values($options['lp_blog_categories']);
        }

        $postTitle = (isset($options['lp_title']) ? $options['lp_title'] : '');

        // HOW MANY POSTS
        $num_posts = 5;
        if ('default-style' == $style ) {
            $num_posts = (isset($options['lp_num_posts']) ? intval($options['lp_num_posts']) : $num_posts);
        }

        $GLOBALS['lp_info'] = array(
            'options' => $options,
            'post' => $post,
            'blog_category' => $blog_category,
            'num_posts' => $num_posts,
            'postTitle' => $postTitle,
            'placement' => $placement,
        );

        $styleClass = 'default-style';
        if('default-style' != $style){
            $styleClass .= ' '.$style;
        }
        ?>
            <div class="latest_posts <?php echo $styleClass;?>">
                <?php
                    $path = dirname(__FILE__). '/inc/'.$style.'.php';
                    if(is_file($path)){
                        include($path);
                    }
                ?>
            </div>
            <!-- end // latest posts style 2 -->
    <?php
    }

    /**
     * This method is used to retrieve the configurable options of the element.
     * @return array The list of options that compose the element and then passed as the argument for the render() function
     */
    function options()
    {
        return array (
            array (
                "name"        => __( "Style", 'zn_framework' ),
                "description" => __( "Please select the style you want to use.", 'zn_framework' ),
                "id"          => "lp_style_select",
                "std"         => "default-style",
                "options"     => array (
                    'default-style' => __( 'Default Style', 'zn_framework' ),
                    'kl-style-2'    => __( 'Style 2 (since v4.0)', 'zn_framework' ),
                ),
                "type"        => "select",
            ),
            array (
                "name"        => __( "Boxes placement", 'zn_framework' ),
                "description" => __( "Please select the boxes placement.", 'zn_framework' ),
                "id"          => "lp_placement",
                "std"         => "normal",
                "options"     => array (
                    'normal' => __( 'Normal (title left-top)', 'zn_framework' ),
                    'flipped'    => __( 'Flipped (title box, bottom-right)', 'zn_framework' ),
                ),
                "type"        => "select",
                "dependency"  => array('element' => 'lp_style_select', 'value' => array('kl-style-2')),
            ),
            array (
                "name"        => __( "Title", 'zn_framework' ),
                "description" => __( "Enter a title for your Latest Posts element", 'zn_framework' ),
                "id"          => "lp_title",
                "std"         => "",
                "type"        => "text",
            ),
            array (
                "name"        => __( "Number of posts", 'zn_framework' ),
                "description" => __( "Enter the number of posts that you want to show", 'zn_framework' ),
                "id"          => "lp_num_posts",
                "std"         => "3",
                "type"        => "text",
                "dependency"  => array('element' => 'lp_style_select', 'value' => array('default-style')),
            ),
            array (
                "name"        => __( "Blog Category", 'zn_framework' ),
                "description" => __( "Select the blog category to show items", 'zn_framework' ),
                "id"          => "lp_blog_categories",
                "multiple"    => true,
                "std"         => "0",
                "type"        => "select",
                "options"     => WpkZn::getBlogCategories()
            )
        );
    }
}
