<?php
/**
 * Block
 *
 * @author  Jegstudio
 * @since   1.0.0
 * @package gutenverse-news
 */

namespace GUTENVERSE\NEWS\Block;

use Gutenverse\Framework\Options;
use GUTENVERSE\NEWS\Block\Grab;

/**
 * Class Init
 *
 * @package Gutenverse-News
 */
class Block extends Grab {


	/**
	 * Method get_content
	 *
	 * @return string
	 */
	public function get_content() {
		$headercat = '';
		$headeraut = '';
		$headertag = '';
		$inclpost  = '';
		$exclpost  = '';
		$inclcat   = '';
		$exclcat   = '';
		$incltag   = '';
		$excltag   = '';
		$inclaut   = '';
		$enbdate   = '';
		foreach ( $this->attributes['headerCategory'] as $cat ) {
			if ( '' === $headercat ) {
				$headercat = $cat['value'];
			} else {
				$headercat .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['headerAuthor'] as $cat ) {
			if ( '' === $headeraut ) {
				$headeraut = $cat['value'];
			} else {
				$headeraut .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['headerTag'] as $cat ) {
			if ( '' === $headertag ) {
				$headertag = $cat['value'];
			} else {
				$headertag .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['includePost'] as $cat ) {
			if ( '' === $inclpost ) {
				$inclpost = $cat['value'];
			} else {
				$inclpost .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['excludePost'] as $cat ) {
			if ( '' === $exclpost ) {
				$exclpost = $cat['value'];
			} else {
				$exclpost .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['includeCategory'] as $cat ) {
			if ( '' === $inclcat ) {
				$inclcat = $cat['value'];
			} else {
				$inclcat .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['excludeCategory'] as $cat ) {
			if ( '' === $exclcat ) {
				$exclcat = $cat['value'];
			} else {
				$exclcat .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['includeTag'] as $cat ) {
			if ( '' === $incltag ) {
				$incltag = $cat['value'];
			} else {
				$incltag .= ',' . $cat['value'];
			}
		}
		foreach ( $this->attributes['excludeTag'] as $cat ) {
			if ( '' === $excltag ) {
				$excltag = $cat['value'];
			} else {
				$excltag .= ',' . $cat['value'];
			}
		}

		foreach ( $this->attributes['includeAuthor'] as $cat ) {
			if ( '' === $inclaut ) {
				$inclaut = $cat['value'];
			} else {
				$inclaut .= ',' . $cat['value'];
			}
		}
		if ( isset( $this->attributes['showDate'] ) && $this->attributes['showDate'] ) {
			$enbdate = true;
		}
		$image_load = Options::get_instance()->get_image_load( 'normal', $this->attributes['normalImage'], $this->attributes['imageLoad'] );
		$attr       = array(
			'first_title'                  => $this->attributes['title'],
			'second_title'                 => $this->attributes['second_title'],
			'url'                          => $this->attributes['url_title'],
			'header_type'                  => $this->attributes['headerType'],
			'header_icon'                  => $this->attributes['icon'],
			'header_background'            => '',
			'header_secondary_background'  => '',
			'header_text_color'            => '',
			'header_line_color'            => '',
			'header_accent_color'          => '',
			'header_filter_category'       => $headercat,
			'header_filter_author'         => $headeraut,
			'header_filter_tag'            => $headertag,
			'header_filter_text'           => $this->attributes['headerDefault'],
			'post_type'                    => $this->attributes['postType'],
			'content_type'                 => $this->attributes['contentType'],
			'number_post'                  => $this->attributes['numberPost'],
			'post_offset'                  => $this->attributes['postOffset'],
			'unique_content'               => $this->attributes['uniqueContent'],
			'include_post'                 => $inclpost,
			'included_only'                => $this->attributes['includeOnly'],
			'exclude_post'                 => $exclpost,
			'include_category'             => $inclcat,
			'exclude_category'             => $exclcat,
			'include_author'               => $inclaut,
			'include_tag'                  => $incltag,
			'exclude_tag'                  => $excltag,
			'sort_by'                      => $this->attributes['sortBy'],
			'date_format'                  => $this->attributes['metaDateFormat'],
			'date_format_custom'           => $this->attributes['metaDateFormatCustom'],
			'excerpt_length'               => $this->attributes['excerptLength'],
			'excerpt_ellipsis'             => $this->attributes['excerptEllipsis'],
			'pagination_mode'              => $this->attributes['paginationMode'],
			'pagination_nextprev_showtext' => $this->attributes['showNavText'],
			'pagination_number_post'       => $this->attributes['paginationPost'],
			'pagination_scroll_limit'      => $this->attributes['loadLimit'],
			'boxed'                        => $this->attributes['enableBoxed'],
			'boxed_shadow'                 => $this->attributes['enableBoxed'] ? $this->attributes['enableBoxShadow'] : false,
			'el_id'                        => '',
			'el_class'                     => '',
			'scheme'                       => '',
			'column_width'                 => $this->attributes['columnWidth'],
			'title_color'                  => '',
			'accent_color'                 => '',
			'alt_color'                    => '',
			'excerpt_color'                => '',
			'css'                          => '',
			'compatible_column_notice'     => '',
			'show_date'                    => $enbdate,
			'short_code'                   => $this->attributes['gvnewsModule'],
			'renderedImageSizeMain'        => isset( $this->attributes['renderedImageSizeMain'] ) ? $this->attributes['renderedImageSizeMain'] : '',
			'renderedImageSizeSecond'      => isset( $this->attributes['renderedImageSizeSecond'] ) ? $this->attributes['renderedImageSizeSecond'] : '',
			'disable_readmore'             => isset( $this->attributes['readmoreButtonDisabled'] ) ? $this->attributes['readmoreButtonDisabled'] : false,
			'meta_settings'                => array(
				'show_meta'    => isset( $this->attributes['showMeta'] ) ? $this->attributes['showMeta'] : true,
				'meta_date'    => isset( $this->attributes['showMetaDate'] ) ? $this->attributes['showMetaDate'] : true,
				'meta_author'  => isset( $this->attributes['showMetaAuthor'] ) ? $this->attributes['showMetaAuthor'] : true,
				'meta_comment' => isset( $this->attributes['showMetaComment'] ) ? $this->attributes['showMetaComment'] : true,
			),
			'list_icon'                    => isset( $this->attributes['listIcon'] ) ? $this->attributes['listIcon'] : '',
			'list_icon_type'               => isset( $this->attributes['listIconType'] ) ? $this->attributes['listIconType'] : 'icon',
			'list_icon_svg'                => isset( $this->attributes['listIconSVG'] ) ? $this->attributes['listIconSVG'] : '',
			'icon_type'                    => isset( $this->attributes['iconType'] ) ? $this->attributes['iconType'] : 'icon',
			'icon_svg'                     => isset( $this->attributes['iconSVG'] ) ? $this->attributes['iconSVG'] : '',
			'content_container_background' => isset( $this->attributes['contentContainerBackground'] ) ? $this->attributes['contentContainerBackground'] : array(),
			'gutter_width'                 => isset( $this->attributes['gutterWidth'] ) ? $this->attributes['gutterWidth'] : 30,
			'image_load'                   => $image_load,
			'header_html_tag'              => isset( $this->attributes['headerHtmlTag'] ) ? $this->attributes['headerHtmlTag'] : 'h3',
			'post_title_html_tag'          => isset( $this->attributes['postTitleHtmlTag'] ) ? $this->attributes['postTitleHtmlTag'] : 'h3',
			'fetch_priority_high'          => isset( $this->attributes['fetchPriorityHigh'] ) ? $this->attributes['fetchPriorityHigh'] : false,
			'pagination_prev_icon'         => isset( $this->attributes['paginationPrevIcon'] ) ? $this->attributes['paginationPrevIcon'] : 'fas fa-chevron-left',
			'pagination_prev_icon_type'    => isset( $this->attributes['paginationPrevIconType'] ) ? $this->attributes['paginationPrevIconType'] : 'icon',
			'pagination_prev_icon_svg'     => isset( $this->attributes['paginationPrevIconSVG'] ) ? $this->attributes['paginationPrevIconSVG'] : '',
			'pagination_next_icon'         => isset( $this->attributes['paginationNextIcon'] ) ? $this->attributes['paginationNextIcon'] : 'fas fa-chevron-right',
			'pagination_next_icon_type'    => isset( $this->attributes['paginationNextIconType'] ) ? $this->attributes['paginationNextIconType'] : 'icon',
			'pagination_next_icon_svg'     => isset( $this->attributes['paginationNextIconSVG'] ) ? $this->attributes['paginationNextIconSVG'] : '',
			'noContentText'                => isset( $this->attributes['noContentText'] ) ? $this->attributes['noContentText'] : 'No Content Available',
		);
		$sccontent  = '';

		return $this->get_module( $attr, $sccontent );
	}

	/**
	 * Check if this block is Pro.
	 *
	 * @return boolean
	 */
	public function check_pro() {
		$deprecated = array(
			'GUTENVERSE\NEWS\Block\Module\Module_10',
			'GUTENVERSE\NEWS\Block\Module\Module_11',
			'GUTENVERSE\NEWS\Block\Module\Module_12',
			'GUTENVERSE\NEWS\Block\Module\Module_13',
			'GUTENVERSE\NEWS\Block\Module\Module_14',
			'GUTENVERSE\NEWS\Block\Module\Module_15',
			'GUTENVERSE\NEWS\Block\Module\Module_16',
			'GUTENVERSE\NEWS\Block\Module\Module_18',
			'GUTENVERSE\NEWS\Block\Module\Module_19',
			'GUTENVERSE\NEWS\Block\Module\Module_20',
			'GUTENVERSE\NEWS\Block\Module\Module_22',
			'GUTENVERSE\NEWS\Block\Module\Module_23',
			'GUTENVERSE\NEWS\Block\Module\Module_24',
			'GUTENVERSE\NEWS\Block\Module\Module_25',
			'GUTENVERSE\NEWS\Block\Module\Module_26',
			'GUTENVERSE\NEWS\Block\Module\Module_27',
			'GUTENVERSE\NEWS\Block\Module\Module_28',
			'GUTENVERSE\NEWS\Block\Module\Module_29',
			'GUTENVERSE\NEWS\Block\Module\Module_30',
			'GUTENVERSE\NEWS\Block\Module\Module_31',
			'GUTENVERSE\NEWS\Block\Module\Module_32',
			'GUTENVERSE\NEWS\Block\Module\Module_33',
			'GUTENVERSE\NEWS\Block\Module\Module_34',
			'GUTENVERSE\NEWS\Block\Module\Module_35',
			'GUTENVERSE\NEWS\Block\Module\Module_36',
			'GUTENVERSE\NEWS\Block\Module\Module_37',
			'GUTENVERSE\NEWS\Block\Module\Module_38',
			'GUTENVERSE\NEWS\Block\Module\Module_39',
		);
		if ( current_user_can( 'edit_pages' ) && ! gutenverse_pro_active() && in_array( $this->attributes['gvnewsModule'], $deprecated ) ) {
			return true;
		}
		return false;
	}
}
