<?php
/** composer fields template */
if ( ! function_exists( 'newsmax_composer_templates' ) ) {
	function newsmax_composer_templates() {
		$template = array();
		global $pagenow;
		if ( ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) && get_current_screen()->post_type == 'page' ) {
			if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
				return;
			}

			$str = '';
			$str .= '<div class="ruby-block-item">';
			$str .= '<input type="hidden" class="ruby-block-order">';
			$str .= '<input type="hidden" class="ruby-block-name">';
			$str .= '<div class="ruby-block-bar">';
			$str .= '<i class="ruby-block-move">#</i>';
			$str .= '<div class="ruby-block-label"></div>';
			$str .= '<div class="ruby-block-toolbox">';
			$str .= '<a class="ruby-block-open-option" href="#">+</a>';
			$str .= '<a class="ruby-block-delete" href="#">x</a>';
			$str .= '</div>';
			$str .= '</div>';
			$str .= '<div class="ruby-block-options-wrap hidden">';
			$str .= '<div class="ruby-block-description"></div>';
			$str .= '<div class="ruby-filter-link"></div>';
			$str .= '<div class="ruby-block-content"></div>';
			$str .= '</div>';
			$str .= '</div>';
			$template['block'] = $str;

			// block option
			$str = '';
			$str .= '<div class="ruby-block-option">';
			$str .= '<div class="ruby-block-option-label-wrap">';
			$str .= '<label class="ruby-block-option-label"></label>';
			$str .= '<div class="ruby-block-option-description"></div>';
			$str .= '</div>';
			$str .= '<div class="ruby-block-option-inner"></div>';
			$str .= '</div>';
			$template['block_option'] = $str;


			$template['input']['text']           = '<input class="ruby-field ruby-text" type="text">';
			$template['input']['num']            = '<input class="ruby-field ruby-number" type="number" name="quantity" min="0">';
			$template['input']['posts_per_page'] = '<input class="ruby-field ruby-number" type="number" name="quantity" min="1">';
			$template['input']['textarea']       = '<textarea class="ruby-field ruby-textarea" rows="9"></textarea>';
			$template['input']['category']       = newsmax_category_dropdown_select();
			$template['input']['categories']     = newsmax_categories_dropdown_select();
			$template['input']['post_format']    = newsmax_post_format_dropdown_select();
			$template['input']['enable']         = newsmax_enable_dropdown_select();
			$template['input']['authors']        = newsmax_author_dropdown_select();
			$template['input']['orderby']        = newsmax_orderby_dropdown_select();
			$template['input']['viewmore']       = newsmax_viewmore_dropdown_select();
			$template['input']['custom_html']    = '<textarea class="ruby-field ruby-raw-html" rows="9"></textarea>';
			$template['input']['summary_type']   = newsmax_summary_dropdown_select();
			$template['input']['position']       = newsmax_position_dropdown_select();
			$template['input']['wrap_mode']      = newsmax_wrapmode_dropdown_select();


			$template['title']['title']           = esc_html__( 'Title', 'newsmax-core' );
			$template['title']['title_url']       = esc_html__( 'Title Url', 'newsmax-core' );
			$template['title']['category_id']     = esc_html__( 'Category Filter', 'newsmax-core' );
			$template['title']['category_ids']    = esc_html__( 'Multiple Categories Filter', 'newsmax-core' );
			$template['title']['tags']            = esc_html__( 'Tags slug filter', 'newsmax-core' );
			$template['title']['post_format']     = esc_html__( 'Post Format Filter', 'newsmax-core' );
			$template['title']['authors']         = esc_html__( 'Authors Filter', 'newsmax-core' );
			$template['title']['posts_per_page']  = esc_html__( 'Number Of Posts', 'newsmax-core' );
			$template['title']['slides_per_page'] = esc_html__( 'Number Of Slider', 'newsmax-core' );
			$template['title']['offset']          = esc_html__( 'Post Offset', 'newsmax-core' );
			$template['title']['orderby']         = esc_html__( 'Sort Order', 'newsmax-core' );
			$template['title']['excerpt']         = esc_html__( 'Post Excerpt', 'newsmax-core' );
			$template['title']['readmore']        = esc_html__( 'Read More Button', 'newsmax-core' );
			$template['title']['big_first']       = esc_html__( '1st Classic Post', 'newsmax-core' );
			$template['title']['summary_type']    = esc_html__( 'Classic Summary Type', 'newsmax-core' );
			$template['title']['position']        = esc_html__( 'Big Column Position', 'newsmax-core' );
			$template['title']['excerpt_classic'] = esc_html__( 'Classic Post Excerpt', 'newsmax-core' );
			$template['title']['auto_play']       = esc_html__( 'Autoplay Video', 'newsmax-core' );

			// default descriptions
			$template['desc']['title']           = esc_html__( 'optional - input a title for this block.', 'newsmax-core' );
			$template['desc']['title_url']       = esc_html__( 'optional - input a title URL for this block.', 'newsmax-core' );
			$template['desc']['sub_title']       = esc_html__( 'optional - show sub title of block.', 'newsmax-core' );
			$template['desc']['category_id']     = esc_html__( 'filter posts by category ID.', 'newsmax-core' );
			$template['desc']['category_ids']    = esc_html__( 'filter posts by category IDs. This option will override on "category filter" option.', 'newsmax-core' );
			$template['desc']['tags']            = esc_html__( 'filter posts by tags, Each tags separated by commas (for example: tag1,tag2,tag3).', 'newsmax-core' );
			$template['desc']['authors']         = esc_html__( 'filter posts by authors.', 'newsmax-core' );
			$template['desc']['posts_per_page']  = esc_html__( 'select number of posts you want to show at once.', 'newsmax-core' );
			$template['desc']['slides_per_page'] = esc_html__( 'select number of slides you want to show at once.', 'newsmax-core' );
			$template['desc']['offset']          = esc_html__( 'select number of posts to displace or pass over. Leave blank or set 0 if you want to show at the beginning.', 'newsmax-core' );
			$template['desc']['orderby']         = esc_html__( 'select a sort order type for this block.', 'newsmax-core' );
			$template['desc']['excerpt']         = esc_html__( 'select a value for the post excerpt length (for grid and list layout), leave blank or set 0 if you want to disable it.', 'newsmax-core' );
			$template['desc']['excerpt_classic'] = esc_html__( 'select a value for the post excerpt length (Classic layout), this option only applies when you enable Use Post Excerpt option, leave blank or set 0 if you want to disable it.', 'newsmax-core' );
			$template['desc']['readmore']        = esc_html__( 'show or hide the "Read More" button for this block.', 'newsmax-core' );
			$template['desc']['big_first']       = esc_html__( 'show the classic layout at top of the blog post listing.', 'newsmax-core' );
			$template['desc']['summary_type']    = esc_html__( 'select a summary type for classic layouts.', 'newsmax-core' );
			$template['desc']['position']        = esc_html__( 'select position for the big column.', 'newsmax-core' );
			$template['desc']['post_format']     = esc_html__( 'filter posts by post format types.', 'newsmax-core' );
			$template['desc']['auto_play']       = esc_html__( 'autoplay the first video when scrolling to this block.', 'newsmax-core' );

			$template['title']['header_color'] = esc_html__( 'Header Color', 'newsmax-core' );
			$template['desc']['header_color']  = esc_html__( 'select a color (hex color) for this block title, for example: #ffffff.', 'newsmax-core' );

			$template['title']['text_style'] = esc_html__( 'Text Color', 'newsmax-core' );
			$template['desc']['text_style']  = esc_html__( 'Select text style for this block, this option will apply to header border, ajax filter text and post contents (does not apply to overlay contents).', 'newsmax-core' );
			$template['input']['text_style'] = newsmax_text_style_dropdown_select();

			$template['title']['share'] = esc_html__( 'Share Icons', 'newsmax-core' );
			$template['desc']['share']  = esc_html__( 'enable or disable share on social icons for this block.', 'newsmax-core' );
			$template['input']['share'] = newsmax_enable_dropdown_select( true );

			$template['title']['meta_info'] = esc_html__( 'Meta Tags Info', 'newsmax-core' );
			$template['desc']['meta_info']  = esc_html__( 'enable or disable entry meta tags info for this block.', 'newsmax-core' );
			$template['input']['meta_info'] = newsmax_enable_dropdown_select( true );

			$template['title']['cat_info'] = esc_html__( 'Category Info', 'newsmax-core' );
			$template['desc']['cat_info']  = esc_html__( 'enable or disable the category info for this block', 'newsmax-core' );
			$template['input']['cat_info'] = newsmax_enable_dropdown_select( true );

			// block col image
			$template['title']['col_title']     = esc_html__( 'Column Heading', 'newsmax-core' );
			$template['desc']['col_title']      = esc_html__( 'input a heading for this column.', 'newsmax-core' );
			$template['title']['destination']   = esc_html__( 'Destination URL', 'newsmax-core' );
			$template['desc']['destination']    = esc_html__( 'input a destination URL.', 'newsmax-core' );
			$template['title']['num_of_col']    = esc_html__( 'Number of Columns', 'newsmax-core' );
			$template['desc']['num_of_col']     = esc_html__( 'select a number of columns per row.', 'newsmax-core' );
			$template['input']['num_of_col']    = newsmax_number_of_columns_select();
			$template['title']['col_img_style'] = esc_html__( 'Block Style', 'newsmax-core' );
			$template['desc']['col_img_style']  = esc_html__( 'select a style for this block.', 'newsmax-core' );
			$template['input']['col_img_style'] = newsmax_col_img_style_select();

			// raw HTMl
			$template['title']['raw_html'] = esc_html__( 'Raw HTML', 'newsmax-core' );
			$template['desc']['raw_html']  = esc_html__( 'input raw HTML content for this section.', 'newsmax-core' );
			$template['input']['raw_html'] = '<textarea class="ruby-field raw-html" rows="14"></textarea>';

			// block code box
			$template['title']['wrap_mode']   = esc_html__( 'Block Wrapper Mode', 'newsmax-core' );
			$template['title']['custom_html'] = esc_html__( 'Custom HTML', 'newsmax-core' );
			$template['title']['shortcode']   = esc_html__( 'ShortCodes', 'newsmax-core' );
			$template['desc']['wrap_mode']    = esc_html__( 'display contents of this block in full-width or wrapper mode.', 'newsmax-core' );
			$template['desc']['custom_html']  = esc_html__( 'input your text, HTML codes or video embed codes...', 'newsmax-core' );
			$template['desc']['shortcode']    = esc_html__( 'input a subscribe form shortcode.', 'newsmax-core' );

			// block advertising
			$template['title']['ad_title']  = esc_html__( 'Ad title', 'newsmax-core' );
			$template['title']['ad_url']    = esc_html__( 'Ad URL', 'newsmax-core' );
			$template['title']['ad_image']  = esc_html__( 'Ad Image URL', 'newsmax-core' );
			$template['title']['ad_script'] = esc_html__( 'Adsense Script', 'newsmax-core' );
			$template['desc']['ad_title']   = esc_html__( 'input your advertising title.', 'newsmax-core' );
			$template['desc']['ad_url']     = esc_html__( 'input your destination URL.', 'newsmax-core' );
			$template['desc']['ad_image']   = esc_html__( ' input your attachment image URL. This option will override on the scripts. Leave blank if you want to use scripts.', 'newsmax-core' );
			$template['desc']['ad_script']  = esc_html__( 'input your script codes or raw HTML.', 'newsmax-core' );

			// block style
			$template['title']['block_style'] = esc_html__( 'Blog Style', 'newsmax-core' );
			$template['desc']['block_style']  = esc_html__( 'select a color style for this block', 'newsmax-core' );
			$template['input']['block_style'] = newsmax_block_style_dropdown_select();

			// thumbnail
			$template['title']['thumb_position'] = esc_html__( 'Thumbnail Position', 'newsmax-core' );
			$template['desc']['thumb_position']  = esc_html__( 'select position for post thumbnails.', 'newsmax-core' );

			// block subscribe
			$template['title']['image_url']   = esc_html__( 'Image URL', 'newsmax-core' );
			$template['title']['description'] = esc_html__( 'Short Description', 'newsmax-core' );
			$template['desc']['image_url']    = esc_html__( 'input a background image URL', 'newsmax-core' );
			$template['desc']['description']  = esc_html__( 'input a short description.', 'newsmax-core' );

			// ajax dropdown filer
			$template['title']['ajax_dropdown'] = esc_html__( 'Ajax Dropdown Filter Type', 'newsmax-core' );
			$template['desc']['ajax_dropdown']  = esc_html__( 'select a type for ajax dropdown filters for displaying at the right of this block header.', 'newsmax-core' );
			$template['input']['ajax_dropdown'] = newsmax_ajax_filter_dropdown_select();

			// ajax dropdown filer id
			$template['title']['ajax_dropdown_id'] = esc_html__( 'Ajax Dropdown Filter IDs', 'newsmax-core' );
			$template['desc']['ajax_dropdown_id']  = esc_html__( 'input IDs of the filter type (category IDs, author IDs, OR tag names) you want to show, separated by commas, Leave blank if you want to show all.', 'newsmax-core' );

			// ajax dropdown text
			$template['title']['ajax_dropdown_text'] = esc_html__( 'First Item Title', 'newsmax-core' );
			$template['desc']['ajax_dropdown_text']  = esc_html__( 'input a title for the first item (All) of this dropdown filter list.', 'newsmax-core' );

			// ajax pagination
			$template['title']['pagination'] = esc_html__( 'Ajax Pagination', 'newsmax-core' );
			$template['desc']['pagination']  = esc_html__( 'select a pagination type for this block.', 'newsmax-core' );
			$template['input']['pagination'] = newsmax_pagination_dropdown_select();

			// grid style
			$template['title']['grid_style'] = esc_html__( 'Grid Style', 'newsmax-core' );
			$template['desc']['grid_style']  = esc_html__( 'select a grid style for this block.', 'newsmax-core' );
			$template['input']['grid_style'] = newsmax_grid_style_dropdown_select();

			// background image
			$template['title']['background'] = esc_html__( 'Background Color', 'newsmax-core' );
			$template['desc']['background']  = esc_html__( 'select a wrapper background color (hex) for this block, for example: #282828.', 'newsmax-core' );

			$template['title']['background_image'] = esc_html__( 'Background Image', 'newsmax-core' );
			$template['desc']['background_image']  = esc_html__( 'input an attachment image URL as a background for this block. This option will override on background color settings.', 'newsmax-core' );

			// unload
			$template['unload']                 = esc_html__( 'The changes you made will be lost if you navigate away from this page.', 'newsmax-core' );
			$template['confirm_section_delete'] = esc_html__( 'Are you sure to delete this section?', 'newsmax-core' );
			$template['confirm_block_delete']   = esc_html__( 'Are you sure to delete this block?', 'newsmax-core' );

			// sidebar
			$str = '';
			$str .= '<div class="ruby-template-field-sidebar-label"><label>' . esc_html__( 'Select Sidebar Options', 'newsmax-core' ) . '</label>';
			$str .= '<div class="ruby-sidebar-select-wrap">';
			$str .= '<div class="ruby-sidebar-select-el">';
			$str .= '<div class="sidebar-label">' . esc_html__( 'Sidebar Name', 'newsmax-core' ) . '</div>';
			$str .= '<select class ="ruby-sidebar-select">';

			// sidebar select
			$data_sidebar = $GLOBALS['wp_registered_sidebars'];

			if ( is_array( $data_sidebar ) ) {
				foreach ( $data_sidebar as $sidebar ) {
					if ( ! empty( $sidebar['id'] ) && ! empty( $sidebar['name'] ) ) {
						switch ( $sidebar['id'] ) {
							case 'newsmax_ruby_sidebar_navigation' :
							case 'newsmax_ruby_blog_column_1' :
							case 'newsmax_ruby_blog_column_2' :
							case 'newsmax_ruby_blog_column_3' :
							case 'newsmax_ruby_sidebar_footer_fullwidth':
							case 'newsmax_ruby_sidebar_footer_1' :
							case 'newsmax_ruby_sidebar_footer_2' :
							case 'newsmax_ruby_sidebar_footer_3' :
							case 'newsmax_ruby_sidebar_footer_4' :
								break;
							default:
								$str .= '<option value="' . esc_attr( $sidebar['id'] ) . '">' . ucwords( $sidebar['name'] ) . '</option>';
								break;
						}
					}
				};
			}
			$str .= '</select>';
			$str .= '</div>';
			$str .= '<div class="ruby-sidebar-select-el">';
			$str .= '<div class="sidebar-label">' . esc_html__( 'Sidebar Position', 'newsmax-core' ) . '</div>';
			$str .= '<select class="ruby-sidebar-position">';
			$str .= '<option selected value ="right">' . esc_html__( 'Right', 'newsmax-core' ) . '</option>';
			$str .= '<option  value ="left">' . esc_html__( 'Left', 'newsmax-core' ) . '</option>';
			$str .= '</select>';
			$str .= '</div>';

			$str .= '<div class="ruby-sidebar-select-el">';
			$str .= '<div class="sidebar-label">' . esc_html__( 'Sidebar Sticky', 'newsmax-core' ) . '</div>';
			$str .= '<select class="ruby-sidebar-sticky">';
			$str .= '<option selected value ="default">' . esc_html__( 'Default From Theme Options', 'newsmax-core' ) . '</option>';
			$str .= '<option  value ="stick">' . esc_html__( 'Stick', 'newsmax-core' ) . '</option>';
			$str .= '<option value ="none">' . esc_html__( 'None', 'newsmax-core' ) . '</option>';
			$str .= '</select>';
			$str .= '</div>';

			$str .= '</div></div>';
			$template['input']['sidebar'] = $str;

			// full width section
			$str = '';
			$str .= '<div class="ruby-section fullwidth-section">';
			$str .= '<div class="ruby-section-bar">';
			$str .= '<i class="ruby-section-move">#</i>';
			$str .= '<div class="ruby-section-label"></div>';
			$str .= '<div class="ruby-section-toolbox">';
			$str .= '<a class="ruby-section-open-option" href="#">+</a>';
			$str .= '<a class="ruby-section-delete" href="#">x</a>';
			$str .= '</div>';
			$str .= '</div>';
			$str .= '<div class="ruby-block-wrap clearfix">';
			$str .= '<div class="section-menu-wrap">';
			$str .= '<div class="ruby-toolbox"><a href="#" class="add-block-select">' . esc_html__( 'Add Block', 'newsmax-core' ) . '</a>';
			$str .= '<div class="block-select-wrap"></div>';
			$str .= '</div>';
			$str .= '</div>';
			$str .= '<div class="ruby-block fullwidth-block">';
			$str .= '<input type="hidden" class="ruby-section-order" name="newsmax_ruby_section_order[]">';
			$str .= '<input type="hidden" class="ruby-section-type">';
			$str .= '<div class="ruby-section-empty">' . esc_html__( 'Click on " <strong>BLOCK</strong> " images to add a new block.', 'newsmax-core' ) . '</div>';
			$str .= '<div class="ruby-section-loading">' . esc_html__( 'Loading ...', 'newsmax-core' ) . '</div>';
			$str .= '</div>';
			$str .= '</div>';
			$str .= '</div>';
			$template['section_full_width'] = $str;

			// has sidebar section
			$str = '';
			$str .= '<div class="ruby-section has-sidebar-section">';
			$str .= '<div class="ruby-section-bar">';
			$str .= '<i class="ruby-section-move">#</i>';
			$str .= '<div class="ruby-section-label"></div>';
			$str .= '<div class="ruby-section-toolbox">';
			$str .= '<a class="ruby-section-open-option" href="#">+</a>';
			$str .= '<a class="ruby-section-delete" href="#">x</a>';
			$str .= '</div>';
			$str .= '</div>';
			$str .= '<div class="ruby-block-wrap clearfix">';
			$str .= '<div class="section-menu-wrap">';
			$str .= '<div class="ruby-section-sidebar">';
			$str .= '</div>';
			$str .= '<div class="ruby-toolbox"><a href="#" class="add-block-select">' . esc_html__( 'Add Block', 'newsmax-core' ) . '</a>';
			$str .= '<div class="block-select-wrap"></div>';
			$str .= '</div>';
			$str .= '</div>';
			$str .= '<div class="ruby-block content-block">';
			$str .= '<input type="hidden" class="ruby-section-order" name="newsmax_ruby_section_order[]">';
			$str .= '<input type="hidden" class="ruby-section-type">';
			$str .= '<div class="ruby-section-empty">' . html_entity_decode( esc_html__( 'Click on " <strong>BLOCK</strong> " images to add a new block.', 'newsmax-core' ) ) . '</div>';
			$str .= '<div class="ruby-section-loading">' . esc_html__( 'Loading ...', 'newsmax-core' ) . '</div>';
			$str .= '</div>';

			$str .= '</div>';
			$str .= '</div>';

			$template['section_has_sidebar'] = $str;

			return $template;
		}
	}
}

/** js templates */
if ( ! function_exists( 'newsmax_composer_js_templates' ) ) {
	function newsmax_composer_js_templates() {
		global $pagenow;
		if ( ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) && get_current_screen()->post_type == 'page' ) :
			if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
				return;
			} ?>
			<script type="text/html" id="tmpl-newsmax-composer-switch-btn">
				<div class="newsmax-composer-switch-mode">
					<a id="newsmax_switch_mode" title="switch to Ruby Composer" class="ruby-composer-switch-btn" href="#"><i class="dashicons dashicons-migrate"></i>
						<?php esc_html_e( 'Ruby Composer', 'newsmax-core' ); ?>
					</a>
				</div>
			</script>
			<script type="text/html" id="tmpl-newsmax-composer-panel">
				<?php echo ruby_composer_panel_template(); ?>
			</script>
			<script type="text/html" id="tmpl-rbc-js-loaded">
				<input type="hidden" class="rbc-field" name="rbc_js_loaded" value="1">
			</script>
		<?php
		endif;
	}
}

/** panel template */
if ( ! function_exists( 'ruby_composer_panel_template' ) ) {
	function ruby_composer_panel_template() {

		$str = '';
		$str .= '<div id="newsmax_composer_editor" class="ruby-composer-editor ruby-composer-gutenberg is-hidden">';
		$str .= '<div class="ruby-composer-title"><h3>' . esc_html__( 'Ruby Composer', 'newsmax-core' ) . '</h3></div>';
		$str .= '<div class="ruby-composer-loading"></div>';
		$str .= '<div class="ruby-toolbox"><a href="#" id="page_composer_section_select" class="add-section-select">' . esc_html__( 'select your section', 'newsmax-core' ) . '</a>';
		$str .= '<div id="newsmax_section_select" class="section-select-wrap"></div>';
		$str .= '</div>';
		$str .= '<div class="ruby-sections-wrap">';
		$str .= '<div class="ruby-section-empty">' . esc_html__( 'Click on "SECTION" images to create a new section.', 'newsmax-core' ) . '</div>';
		$str .= '</div>';
		$str .= '</div>';

		return $str;
	}
}


/** setup sections */
if ( ! function_exists( 'newsmax_composer_sections' ) ) {
	function newsmax_composer_sections() {

		$sections = array(
			'section_full_width'  => array(
				'title' => esc_html__( 'Full Width Section', 'newsmax-core' ),
				'img'   => NEWSMAX_CORE_URL . '/composer/assets/section-full-width.png',
				'decs'  => esc_html__( 'Display content without sidebar', 'newsmax-core' ),
			),
			'section_has_sidebar' => array(
				'title' => esc_html__( 'Has Sidebar Section', 'newsmax-core' ),
				'img'   => NEWSMAX_CORE_URL . '/composer/assets/section-has-sidebar.png',
				'decs'  => esc_html__( 'Display content width sidebar', 'newsmax-core' ),
			),

		);
		return $sections;
	}
}


/**
 * @return string
 * select category
 */
if ( ! function_exists( 'newsmax_category_dropdown_select' ) ) {
	function newsmax_category_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		$ruby_categories = get_categories( array(
			'hide_empty' => 0,
		) );

		$ruby_category_array_walker = new newsmax_category_array_walker;
		$ruby_category_array_walker->walk( $ruby_categories, 4 );
		$ruby_categories_buffer = $ruby_category_array_walker->cat_array;

		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="0" selected="selected">' . esc_html__( '-- All categories --', 'newsmax-core' ) . '</option>';
		foreach ( $ruby_categories_buffer as $ruby_category_name => $category_id ) {
			$str .= '<option value="' . esc_attr( $category_id ) . '">';
			$str .= esc_html( $ruby_category_name );
			$str .= '</option>';
		}

		$str .= '</select><!--#category select-->';

		return $str;
	}
}

if ( ! function_exists( 'newsmax_categories_dropdown_select' ) ) {
	function newsmax_categories_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		if ( ! is_admin() ) {
			return false;
		}

		$ruby_categories = get_categories( array(
			'hide_empty' => 0,
		) );

		$ruby_category_array_walker = new newsmax_category_array_walker;
		$ruby_category_array_walker->walk( $ruby_categories, 4 );
		$ruby_categories_buffer = $ruby_category_array_walker->cat_array;

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select" multiple="multiple">';
		$str .= '<option value="0" selected="selected">' . esc_html__( '-- Disable --', 'newsmax-core' ) . '</option>';
		foreach ( $ruby_categories_buffer as $ruby_category_name => $category_id ) {
			$str .= '<option value="' . esc_attr( $category_id ) . '">';
			$str .= esc_html( $ruby_category_name );
			$str .= '</option>';
		}

		$str .= '</select><!--#categories select-->';

		return $str;
	}
}

/**
 * @return string
 * format dropdown select
 */
if ( ! function_exists( 'newsmax_post_format_dropdown_select' ) ) {
	function newsmax_post_format_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="0" selected="selected">' . esc_html__( '-- All --', 'newsmax-core' ) . '</option>';
		$str .= '<option value="default">' . esc_html__( 'Default', 'newsmax-core' ) . '</option>';
		$str .= '<option value="gallery">' . esc_html__( 'Gallery', 'newsmax-core' ) . '</option>';
		$str .= '<option value="video">' . esc_html__( 'Video', 'newsmax-core' ) . '</option>';
		$str .= '<option value="audio">' . esc_html__( 'Audio', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}

}


/**
 * @param bool $enable
 *
 * @return string
 * enable or disable dropdown select
 */
if ( ! function_exists( 'newsmax_enable_dropdown_select' ) ) {
	function newsmax_enable_dropdown_select( $disable = false ) {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		if ( true == $disable ) {
			$str .= '<option value="0">' . esc_html__( '-- Disable --', 'newsmax-core' ) . '</option>';
			$str .= '<option value="1"  selected="selected">' . esc_html__( 'Enable', 'newsmax-core' ) . '</option>';
		} else {
			$str .= '<option value="0" selected="selected">' . esc_html__( '-- Disable --', 'newsmax-core' ) . '</option>';
			$str .= '<option value="1">' . esc_html__( 'Enable', 'newsmax-core' ) . '</option>';
		}

		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * select author
 */
if ( ! function_exists( 'newsmax_author_dropdown_select' ) ) {
	function newsmax_author_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		return wp_dropdown_users(
			array(
				'show_option_all' => esc_html__( 'All Authors', 'newsmax-core' ),
				'orderby'         => 'ID',
				'class'           => 'ruby-field',
				'echo'            => 0,
				'multi'           => true,
				'hierarchical'    => true
			)
		);
	}
}


/**
 * @return string
 * Order config
 */
if ( ! function_exists( 'newsmax_orderby_dropdown_select' ) ) {
	function newsmax_orderby_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		$orderby_data = array(
			'date_post'               => esc_html__( 'Latest Post', 'newsmax-core' ),
			'comment_count'           => esc_html__( 'Popular Comment', 'newsmax-core' ),
			'popular'                 => esc_html__( 'Popular View', 'newsmax-core' ),
			'popular_week'            => esc_html__( 'Popular Week View', 'newsmax-core' ),
			'top_review'              => esc_html__( 'Top Review', 'newsmax-core' ),
			'last_review'             => esc_html__( 'Latest Review', 'newsmax-core' ),
			'post_type'               => esc_html__( 'Post Type', 'newsmax-core' ),
			'rand'                    => esc_html__( 'Random', 'newsmax-core' ),
			'author'                  => esc_html__( 'Author', 'newsmax-core' ),
			'alphabetical_order_decs' => esc_html__( 'Title DECS', 'newsmax-core' ),
			'alphabetical_order_asc'  => esc_html__( 'Title ACS', 'newsmax-core' )
		);

		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		foreach ( $orderby_data as $val => $title ) {
			$str .= '<option value="' . esc_attr( $val ) . '">' . esc_html( $title ) . '</option>';
		}
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * viewmore dropdown select
 */
if ( ! function_exists( 'newsmax_viewmore_dropdown_select' ) ) {
	function newsmax_viewmore_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="0"  selected="selected">' . esc_html__( '-- Disable --', 'newsmax-core' ) . '</option>';
		$str .= '<option value="1">' . esc_html__( 'Enable', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}

/**
 * @return string
 * summary select config
 */
if ( ! function_exists( 'newsmax_summary_dropdown_select' ) ) {
	function newsmax_summary_dropdown_select() {

		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="excerpt">' . esc_html__( 'Use Post Excerpt', 'newsmax-core' ) . '</option>';
		$str .= '<option value="moretag">' . esc_html__( 'Use More Tag', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * position dropdown select
 */
if ( ! function_exists( 'newsmax_position_dropdown_select' ) ) {
	function newsmax_position_dropdown_select() {
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="0">' . esc_html__( '-- Float Left --', 'newsmax-core' ) . '</option>';
		$str .= '<option value="1">' . esc_html__( 'Float Right', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * wrapper mode config
 */
if ( ! function_exists( 'newsmax_wrapmode_dropdown_select' ) ) {
	function newsmax_wrapmode_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="1" selected="selected">' . esc_html__( '-- Has Wrapper --', 'newsmax-core' ) . '</option>';
		$str .= '<option value="0">' . esc_html__( 'Full Width', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * text style select
 */
if ( ! function_exists( 'newsmax_text_style_dropdown_select' ) ) {
	function newsmax_text_style_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="dark" selected="selected">' . esc_html__( ' -- Dark -- ', 'newsmax-core' ) . '</option>';
		$str .= '<option value="light">' . esc_html__( 'Light', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * number of columns
 */
if ( ! function_exists( 'newsmax_number_of_columns_select' ) ) {
	function newsmax_number_of_columns_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="1">' . esc_html__( '1 column', 'newsmax-core' ) . '</option>';
		$str .= '<option value="2">' . esc_html__( '2 columns', 'newsmax-core' ) . '</option>';
		$str .= '<option value="3" selected="selected">' . esc_html__( ' -- 3 columns -- ', 'newsmax-core' ) . '</option>';
		$str .= '<option value="4">' . esc_html__( '4 columns', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * number of columns
 */
if ( ! function_exists( 'newsmax_col_img_style_select' ) ) {
	function newsmax_col_img_style_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="1" selected="selected">' . esc_html__( '-- Style 1 ---', 'newsmax-core' ) . '</option>';
		$str .= '<option value="2">' . esc_html__( 'Style 2 (Overlay)', 'newsmax-core' ) . '</option>';
		$str .= '<option value="3">' . esc_html__( 'Style 3 (Overlay)', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * block style select
 */
if ( ! function_exists( 'newsmax_block_style_dropdown_select' ) ) {
	function newsmax_block_style_dropdown_select() {
		if ( ! is_admin() ) {
			return false;
		}

		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="light" selected="selected">' . esc_html__( '-- Light --', 'newsmax-core' ) . '</option>';
		$str .= '<option value="dark">' . esc_html__( 'Dark', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * ajax filter type
 */
if ( ! function_exists( 'newsmax_ajax_filter_dropdown_select' ) ) {
	function newsmax_ajax_filter_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		$ajax_filter_dropdown_select_data = array(
			'0'        => esc_html__( '-- Disable --', 'newsmax-core' ),
			'category' => esc_html__( 'by Categories', 'newsmax-core' ),
			'tag'      => esc_html__( 'by Tags Names', 'newsmax-core' ),
			'author'   => esc_html__( 'by Authors', 'newsmax-core' ),
			'popular'  => esc_html__( 'by Popular', 'newsmax-core' ),

		);

		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		foreach ( $ajax_filter_dropdown_select_data as $val => $title ) {
			$str .= '<option value="' . esc_attr( $val ) . '">' . esc_html( $title ) . '</option>';
		}
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * pagination select config
 */
if ( ! function_exists( 'newsmax_pagination_dropdown_select' ) ) {
	function newsmax_pagination_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="0" selected="selected">' . esc_html__( ' -- Disable -- ', 'newsmax-core' ) . '</option>';
		$str .= '<option value="next_prev">' . esc_html__( 'Next Prev', 'newsmax-core' ) . '</option>';
		$str .= '<option value="loadmore">' . esc_html__( 'Load More', 'newsmax-core' ) . '</option>';
		$str .= '<option value="infinite_scroll">' . esc_html__( 'infinite Scroll', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


/**
 * @return string
 * grid style select
 */
if ( ! function_exists( 'newsmax_grid_style_dropdown_select' ) ) {
	function newsmax_grid_style_dropdown_select() {

		if ( ! is_admin() ) {
			return false;
		}

		// render
		$str = '';
		$str .= '<select class="ruby-field ruby-field-select">';
		$str .= '<option value="1" selected="selected">' . esc_html__( ' -- Style 1 -- ', 'newsmax-core' ) . '</option>';
		$str .= '<option value="2">' . esc_html__( 'Style 2 (Top Title)', 'newsmax-core' ) . '</option>';
		$str .= '<option value="3">' . esc_html__( 'Style 3 (Middle Title)', 'newsmax-core' ) . '</option>';
		$str .= '<option value="4">' . esc_html__( 'Style 4 (Rainbow)', 'newsmax-core' ) . '</option>';
		$str .= '<option value="5">' . esc_html__( 'Style 5 (Rainbow + Middle Title)', 'newsmax-core' ) . '</option>';
		$str .= '</select>';

		return $str;
	}
}


if ( ! class_exists( 'newsmax_category_array_walker' ) ) {
	class newsmax_category_array_walker extends Walker {

		var $tree_type = 'category';
		var $cat_array = array();
		var $db_fields = array(
			'id'     => 'term_id',
			'parent' => 'parent'
		);

		public function start_lvl( &$output, $depth = 0, $args = array() ) {
		}

		public function end_lvl( &$output, $depth = 0, $args = array() ) {
		}

		public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
			$this->cat_array[ str_repeat( ' - ', $depth ) . $object->name . ' - [ ID: ' . $object->term_id . ' / Posts: ' . $object->category_count . ' ]' ] = $object->term_id;
		}

		public function end_el( &$output, $object, $depth = 0, $args = array() ) {
		}

	}
}
