<?php
/**
 * Content Posts Blocks Widget
 *
 * @package    Hoot
 * @subpackage Brigsby
 */

/**
* Class Hoot_Content_Posts_Blocks_Widget
*/
class Hoot_Content_Posts_Blocks_Widget extends HybridExtend_WP_Widget {

	function __construct() {

		$settings['id'] = 'hoot-posts-blocks-widget';
		$settings['name'] = __( 'Hoot > Content Blocks (Posts)', 'brigsby' );
		$settings['widget_options'] = array(
			'description'	=> __('Display Styled Content Blocks.', 'brigsby'),
			// 'classname'		=> 'hoot-posts-blocks-widget', // CSS class applied to frontend widget container via 'before_widget' arg
		);
		$settings['control_options'] = array();
		$settings['form_options'] = array(
			//'name' => can be empty or false to hide the name
			array(
				'name'		=> __( "Title (optional)", 'brigsby' ),
				'id'		=> 'title',
				'type'		=> 'text',
			),
			array(
				'name'		=> __( 'Blocks Style', 'brigsby' ),
				'id'		=> 'style',
				'type'		=> 'images',
				'std'		=> 'style1',
				'options'	=> array(
					'style1'	=> HYBRIDEXTEND_INCURI . 'admin/images/content-block-style-1.png',
					'style2'	=> HYBRIDEXTEND_INCURI . 'admin/images/content-block-style-2.png',
					// 'style3'	=> HYBRIDEXTEND_INCURI . 'admin/images/content-block-style-3.png',
					'style4'	=> HYBRIDEXTEND_INCURI . 'admin/images/content-block-style-4.png',
				),
			),
			array(
				'name'		=> __( 'Category (Optional)', 'brigsby' ),
				'desc'		=> __( 'Leave empty to display posts from all categories.', 'brigsby' ),
				'id'		=> 'category',
				'type'		=> 'select',
				'options'	=> array( '0' => '' ) + HybridExtend_WP_Widget::get_tax_list('category') ,
			),
			array(
				'name'		=> __( 'No. Of Columns', 'brigsby' ),
				'id'		=> 'columns',
				'type'		=> 'smallselect',
				'std'		=> '4',
				'options'	=> array(
					'1'	=> __( '1', 'brigsby' ),
					'2'	=> __( '2', 'brigsby' ),
					'3'	=> __( '3', 'brigsby' ),
					'4'	=> __( '4', 'brigsby' ),
					'5'	=> __( '5', 'brigsby' ),
				),
			),
			array(
				'name'		=> __( 'Number of Posts to show', 'brigsby' ),
				'desc'		=> __( 'Default: 4', 'brigsby' ),
				'id'		=> 'count',
				'type'		=> 'text',
				'settings'	=> array( 'size' => 3, ),
				'sanitize'	=> 'absint',
			),
			array(
				'name'		=> __( 'Offset', 'brigsby' ),
				'desc'		=> __( 'Number of posts to skip from the start. Leave empty to start from the latest post.', 'brigsby' ),
				'id'		=> 'offset',
				'type'		=> 'text',
				'settings'	=> array( 'size' => 3, ),
				'sanitize'	=> 'absint',
			),
			array(
				'name'		=> __( 'Show Author', 'brigsby' ),
				'id'		=> 'show_author',
				'type'		=> 'checkbox',
			),
			array(
				'name'		=> __( 'Show Post Date', 'brigsby' ),
				'id'		=> 'show_date',
				'type'		=> 'checkbox',
			),
			array(
				'name'		=> __( 'Show number of comments', 'brigsby' ),
				'id'		=> 'show_comments',
				'type'		=> 'checkbox',
			),
			array(
				'name'		=> __( 'Show categories', 'brigsby' ),
				'id'		=> 'show_cats',
				'type'		=> 'checkbox',
			),
			array(
				'name'		=> __( 'Show tags', 'brigsby' ),
				'id'		=> 'show_tags',
				'type'		=> 'checkbox',
			),
			array(
				'name'		=> __( 'Content', 'brigsby' ),
				'id'		=> 'fullcontent',
				'type'		=> 'select',
				'std'		=> 'excerpt',
				'options'	=> array(
					'excerpt'	=> __( 'Display Excerpt', 'brigsby' ),
					'content'	=> __( 'Display Full Content', 'brigsby' ),
					'none'		=> __( 'None', 'brigsby' ),
				),
			),
			array(
				'name'		=> __( 'Custom Excerpt Length', 'brigsby' ),
				'desc'		=> __( 'Select \'Display Excerpt\' in option above. Leave empty for default excerpt length.', 'brigsby' ),
				'id'		=> 'excerptlength',
				'type'		=> 'text',
				'settings'	=> array( 'size' => 3, ),
				'sanitize'	=> 'absint',
			),
			array(
				'name'		=> __( 'Border', 'brigsby' ),
				'desc'		=> __( 'Top and bottom borders.', 'brigsby' ),
				'id'		=> 'border',
				'type'		=> 'select',
				'std'		=> 'none none',
				'options'	=> array(
					'line line'		=> __( 'Top - Line || Bottom - Line', 'brigsby' ),
					'line shadow'	=> __( 'Top - Line || Bottom - StrongLine', 'brigsby' ),
					'line none'		=> __( 'Top - Line || Bottom - None', 'brigsby' ),
					'shadow line'	=> __( 'Top - StrongLine || Bottom - Line', 'brigsby' ),
					'shadow shadow'	=> __( 'Top - StrongLine || Bottom - StrongLine', 'brigsby' ),
					'shadow none'	=> __( 'Top - StrongLine || Bottom - None', 'brigsby' ),
					'none line'		=> __( 'Top - None || Bottom - Line', 'brigsby' ),
					'none shadow'	=> __( 'Top - None || Bottom - StrongLine', 'brigsby' ),
					'none none'		=> __( 'Top - None || Bottom - None', 'brigsby' ),
				),
			),
			array(
				'name'		=> __( 'Widget CSS', 'brigsby' ),
				'id'		=> 'customcss',
				'type'		=> 'collapse',
				'fields'	=> array(
					array(
						'name'		=> __( 'Custom CSS Class', 'brigsby' ),
						'desc'		=> __( 'Give this widget a custom css classname', 'brigsby' ),
						'id'		=> 'class',
						'type'		=> 'text',
					),
					array(
						'name'		=> __( 'Margin Top', 'brigsby' ),
						'desc'		=> __( '(in pixels) Leave empty to load default margins', 'brigsby' ),
						'id'		=> 'mt',
						'type'		=> 'text',
						'settings'	=> array( 'size' => 3 ),
						'sanitize'	=> 'integer',
					),
					array(
						'name'		=> __( 'Margin Bottom', 'brigsby' ),
						'desc'		=> __( '(in pixels) Leave empty to load default margins', 'brigsby' ),
						'id'		=> 'mb',
						'type'		=> 'text',
						'settings'	=> array( 'size' => 3 ),
						'sanitize'	=> 'integer',
					),
				),
			),
		);

		$settings = apply_filters( 'hoot_content_posts_blocks_widget_settings', $settings );

		parent::__construct( $settings['id'], $settings['name'], $settings['widget_options'], $settings['control_options'], $settings['form_options'] );

	}

	/**
	 * Echo the widget content
	 */
	function display_widget( $instance, $before_title = '', $title='', $after_title = '' ) {
		extract( $instance, EXTR_SKIP );
		include( hybridextend_locate_widget( 'content-posts-blocks' ) ); // Loads the widget/content-posts-blocks or template-parts/widget-content-posts-blocks.php template.
	}

}

/**
 * Register Widget
 */
function hoot_content_posts_blocks_widget_register(){
	register_widget('Hoot_Content_Posts_Blocks_Widget');
}
add_action('widgets_init', 'hoot_content_posts_blocks_widget_register');