<?php
/*
Plugin Name: Pagesections by Develoved
Plugin URI: themes.develoved.com
Description: This is a plugin that is meant to add the pagesections post type to a compatible theme by Develoved.
Version: 1.1.3
Author: develoved
Author URI: themes.develoved.com
Text Domain: dvl-pagesections
*/

require_once( 'inc.php' );

/**
 * Load plugin textdomain.
 */





function shrk_pagesections_load_textdomain() {
	load_plugin_textdomain( 'dvl-pagesections', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 
}
add_action( 'init', 'shrk_pagesections_load_textdomain' );

if (!function_exists('shrk_register_sections')) {

	function shrk_register_sections() {
		$labels = array(
			'name'               => esc_html__( 'Page Sections', 'dvl-pagesections' ),
			'singular_name'      => esc_html__( 'Page Section', 'dvl-pagesections' ),
			'add_new'            => esc_html__( 'Add New', 'dvl-pagesections' ),
			'add_new_item'       => esc_html__( 'Add New Page Section', 'dvl-pagesections' ),
			'edit_item'          => esc_html__( 'Edit Page Section', 'dvl-pagesections' ),
			'new_item'           => esc_html__( 'New Page Section', 'dvl-pagesections' ),
			'view_item'          => esc_html__( 'View Page Section', 'dvl-pagesections' ),
			'search_items'       => esc_html__( 'Search Page Sections', 'dvl-pagesections' ),
			'not_found'          => esc_html__( 'Nothing found', 'dvl-pagesections' ),
			'not_found_in_trash' => esc_html__( 'Nothing found in Trash', 'dvl-pagesections' ),
			'parent_item_colon'  => ''
			);  

		$args = array(
			'labels'              => $labels,
			'public'              => true,
			'exclude_from_search' => true,
			'show_ui'             => true,
			'capability_type'     => 'page',
			'hierarchical'        => false,
			'rewrite'             => true,
			'supports'            => array('title', 'editor', 'page-attributes'),
			'menu_icon'           => 'dashicons-align-center',
			'menu_position'       => 20,
			);
		register_post_type( 'pagesections', $args );
	}

	add_action('init', 'shrk_register_sections');
}

/* Add section Meta boxes */
function shrk_register_sections_meta(){
	if ( function_exists( 'shrk_add_meta_boxes' ) ) {
		shrk_add_meta_boxes( 'pagesections' );
	}
}
add_action('admin_menu', 'shrk_register_sections_meta');

/**
 * Enqueue scripts 
 */
function shrk_mod_pagesections_scripts() {
	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

	wp_enqueue_script( 'shrk-pagesections', plugin_dir_url( __FILE__ ) . 'js/pagesections' . $suffix . '.js', array( 'jquery' ), false, false );
}
add_action( 'wp_enqueue_scripts', 'shrk_mod_pagesections_scripts' );


function shrk_pagesections_meta_arr( $key ) {
	$arr = array();

	$arr['background_image_pos_css'] = array(
		'top_left'          => '0 0',
		'top_center'        => 'center 0',
		'top_right'         => '100% 0',
		'v_center_left'     => '0 center',
		'v_center_h_center' => 'center center',
		'v_center_right'    => '100% center',
		'bottom_left'       => '0 100%',
		'bottom_center'     => 'center 100%',
		'bottom_right'      => '100% 100%',
	);

	$arr['background_image_pos'] = array(
		'top_left'          => esc_html__( 'Top / Left', 'dvl-pagesections' ),
		'top_center'        => esc_html__( 'Top / Center', 'dvl-pagesections' ),
		'top_right'         => esc_html__( 'Top / Right', 'dvl-pagesections' ),
		'v_center_left'     => esc_html__( 'Vertical Center / Left', 'dvl-pagesections' ),
		'v_center_h_center' => esc_html__( 'Vertical Center / Horizontal Center', 'dvl-pagesections' ),
		'v_center_right'    => esc_html__( 'Vertical Center / Right', 'dvl-pagesections' ),
		'bottom_left'       => esc_html__( 'Bottom / Left', 'dvl-pagesections' ),
		'bottom_center'     => esc_html__( 'Bottom / Center', 'dvl-pagesections' ),
		'bottom_right'      => esc_html__( 'Bottom / Right', 'dvl-pagesections' ),
	);

	return isset( $arr[$key] ) ? $arr[$key] : false;
}

/**
 * Add meta options
 * (requires theme based on SHRK framework)
 */
function shrk_pagesections_metaconfig( $meta_options ) {
	$background_image_sizes   = array( 
									'cover'   => esc_html__( 'Fill (Cover)', 'dvl-pagesections' ),
									'contain' => esc_html__( 'Contain', 'dvl-pagesections' ),
									'auto'    => esc_html__( 'Initial image size (Auto)', 'dvl-pagesections' ),
								);

	$background_image_repeats = array( 
									'no-repeat' => esc_html__( 'No Repeat', 'dvl-pagesections' ),
									'repeat'    => esc_html__( 'Repeat', 'dvl-pagesections' ),
									'repeat-x'  => esc_html__( 'Repeat Horizontaly', 'dvl-pagesections' ),
									'repeat-y'  => esc_html__( 'Repeat Vertically', 'dvl-pagesections' ),
								);

	$background_image_v_pos   = array(
									'scroll'   => esc_html__( 'Scroll (Normal)', 'dvl-pagesections' ),
									'fixed'    => esc_html__( 'Fixed (Static)', 'dvl-pagesections' ),
									'parallax' => esc_html__( 'Parallax', 'dvl-pagesections' ),
								);


	$section_color_schemes =    array(
									'light' => esc_html__( 'Light background / Dark text', 'dvl-pagesections' ),
									'dark'  => esc_html__( 'Dark background / Light text', 'dvl-pagesections' ),
								);

	/**
	 * Set Meta options for the specific post type
	 *
	 * Example:
	 *	'section_key' => array(
	 *		'ms_label'    => 'Section Label',
	 *		'ms_context'  => 'side',
	 *		'ms_priority' => 'low',
	 * 		'ms_fields'   => array(
	 *			'option_key' => array(
	 *				"class" => 'class-applied-to-option-element', 
	 *				"name" => 'Option label',
	 *				"type" => 'text',
	 *				...
	 *			)
	 * 		)
	 */
	$meta_options['pagesections'] = array( 
		'general_section_settings' => array(          //first meta section
			"ms_label" => esc_html__( 'General Section Settings', 'dvl-pagesections' ),
			"ms_fields" => array(
				'section_color_scheme' => array(  
					"name"    => esc_html__('Color Scheme', 'dvl-pagesections'),
					"desc"    => esc_html__('Select the main colors scheme for this section, in relation to your background. For example if you choose a dark background for this section you should also choose \'Dark\' here.', 'dvl-pagesections'),
					"type"    => 'select',
					"options" => $section_color_schemes
				),
				'section_height' => array(  
					"name"    => esc_html__('Height / Padding', 'dvl-pagesections'),
					"desc"    => esc_html__('Set section padding / height', 'dvl-pagesections'),
					'options' => array(
						'no-padding'     => esc_html__( 'No padding', 'dvl-pagesections' ), 
						'no-y-padding'   => esc_html__( 'No vertical padding', 'dvl-pagesections' ),
						'small-padding'  => esc_html__( 'Small padding', 'dvl-pagesections' ),
						'medium-padding' => esc_html__( 'Medium padding', 'dvl-pagesections' ),
						'large-padding'  => esc_html__( 'Large padding', 'dvl-pagesections' ),
						'windowheight'   => esc_html__( 'Same as Window Height', 'dvl-pagesections' ),
						'customheight'   => esc_html__( 'Custom', 'dvl-pagesections' ),
					),
					'std'  => 'medium-padding',
					'type' => 'select'
				),
				'custom_window_height_val' => array(  
					"name"       => esc_html__('Custom Height in %', 'dvl-pagesections'),
					"desc"       => esc_html__('You can enter a percentage, relative to the window height. For example entering \'50%\' here will make the section half the window height. You can also enter a css value in px or em. (i.e. \'350px\')', 'dvl-pagesections'),
					"std"        => '70%',
					"type"       => 'text',
					"dependency" => Array('element' => "section_height", 'value' => array('customheight'))
				),
				'custom_section_padding' => array(  
					"name"       => esc_html__('Custom Padding', 'dvl-pagesections'),
					"desc"       => esc_html__('Enter a CSS value for the Top & Bottom padding of the section (i.e. 10px or 5em)', 'dvl-pagesections'),
					"std"        => '5em',
					"type"       => 'text',
					"dependency" => Array('element' => "section_height", 'value' => array('windowheight', 'customheight'))
				),
				'section_v_align' => array(  
					"name"    => esc_html__('Vertical alignment', 'dvl-pagesections'),
					"desc"    => esc_html__('Select the vertical alignment of the content within the section.', 'dvl-pagesections'),
					'type'    => 'select',
					'options' => array(
						'top'    => esc_html__( 'Top', 'dvl-pagesections' ),
						'middle' => esc_html__( 'Middle', 'dvl-pagesections' ),
						'bottom' => esc_html__( 'Bottom', 'dvl-pagesections' ),
						),
					'std'        => 'middle',
					"dependency" => Array('element' => "section_height", 'value' => array('windowheight', 'customheight'))
				),
				'section_full_width' => array(  
					"name"  => esc_html__('Full Width', 'dvl-pagesections'),
					"desc"  => esc_html__('If checked the actual content of this section will be 100% width. For example you can use this to create a full width gallery.', 'dvl-pagesections'),
					'std'   => 'off',
					'type'  => 'toggle'
				),
				'section_shadow' => array(
					"name"    => esc_html__('Show Inner shadow', 'dvl-pagesections'),
					"desc"    => esc_html__('Show a shadow inside the upper, lower or both, edges of the section.', 'dvl-pagesections'),
					'type'    => 'select',
					'options' => array(
						'none'        => esc_html__( 'No shadow', 'dvl-pagesections' ),
						'upper'       => esc_html__( 'Upper edge', 'dvl-pagesections' ),
						'lower'       => esc_html__( 'Lower edge', 'dvl-pagesections' ),
						'upper-lower' => esc_html__( 'Upper & Lower edge', 'dvl-pagesections' ),
						),
					'std' => 'none',
				),
			)
		),
		'background_settings' => array(          //second meta section
			"ms_label" => esc_html__( 'Background Settings', 'dvl-pagesections' ),
			"ms_fields" => array(
				array(
					"std" => esc_html__('Setup the background layers for this section. Those layers are overlayed on top of each other in the order they appear here. You can use transparency to partially display the next layers. For example you can enter a semi-transparent color value or a PNG image with transparency to overlay a video background!', 'dvl-pagesections'),
					"type" => 'info'
				),
				array(
					"type" => 'separator'
				),
				'section_bg_color' => array(  
					"name"  => esc_html__('Solid Color background', 'dvl-pagesections'),
					"desc"  => esc_html__('Show a solid color as a section background. Leave empty to disable', 'dvl-pagesections'),
					"std"   => '#fff',
					"type"  => 'color-alpha'
				),
				array(
					"type" => 'separator'
				),
				'section_image_overlay' => array(  
					"name"  => esc_html__('Pattern Overlay', 'dvl-pagesections'),
					"desc"  => esc_html__('Choose a PNG to show as a pattern overlay (tiled)', 'dvl-pagesections'),
					"type"  => 'upload_image'
				),
				array(
					"type" => 'separator'
				),
				'section_image' => array(  
					"name"  => esc_html__('Image background', 'dvl-pagesections'),
					"desc"  => esc_html__('Show an image as section background', 'dvl-pagesections'),
					"type"  => 'upload_image'
				),
				'section_image_size' => array(
					"name"    => esc_html__('Background Image size', 'dvl-pagesections'),
					"type"    => 'select',
					"options" => $background_image_sizes
				),
				'section_image_repeat' => array(
					"name"    => esc_html__('Background Image Repeat', 'dvl-pagesections'),
					"type"    => 'select',
					"options" => $background_image_repeats
				),
				'section_image_pos' => array(
					"name"    => esc_html__('Background Image Position', 'dvl-pagesections'),
					"type"    => 'select',
					"options" => shrk_pagesections_meta_arr( 'background_image_pos' ),
					"std"     => 'v_center_h_center'
				),
				'section_image_scroll_pos' => array(
					"name"    => esc_html__('Background Image Scroll Behaviour', 'dvl-pagesections'),
					"type"    => 'select',
					"options" => $background_image_v_pos
				),
				'section_image_parallax_speed' => array(  
					"name"       => esc_html__('Parallax Speed Ratio', 'dvl-pagesections'),
					"desc"       => esc_html__('Adjust parallax speed relative to page scrolling. ', 'dvl-pagesections'),
					"std"        => 50,
					"min"        => 5, //zero means empty var
					"max"        => 200,
					"step"       => 5,
					"type"       => 'range',
					"dependency" => Array('element' => "section_image_scroll_pos", 'value' => array('parallax'))
				),   
				'section_image_parallax_offset' => array(  
					"name"       => esc_html__('Parallax Vertical offset', 'dvl-pagesections'),
					"desc"       => esc_html__('Adjust Image offset in regard to your image proportions. You can use positive or negative values. Use a bare number.', 'dvl-pagesections'),
					"std"        => 0,
					"type"       => 'text',
					"dependency" => Array('element' => "section_image_scroll_pos", 'value' => array('parallax'))
				),
				'section_image_lazyload' => array(  
					"name"  => esc_html__('Lazy load image', 'dvl-pagesections'),
					"desc"  => esc_html__('If checked the background image of the section will be lazy loaded when it comes into the viewport.', 'dvl-pagesections'),
					'std'   => 'off',
					'type'  => 'toggle'
				),
				array(
						"type" => 'separator'
				),
				array(
					"std" => esc_html__('Select the video background for this section. You should upload an .MP4 and also an .WEBM file of the same video. You can also provide a fallback image for unsupported devices / browsers.', 'dvl-pagesections'),
					"type" => 'info'
				),
				'section_video_mp4' => array(  
					"name"             => esc_html__('Video (mp4)', 'dvl-pagesections'),
					"desc"             => esc_html__('Select the MP4 file.', 'dvl-pagesections'),
					"class"            => 'video mp4',
					"type"             => 'upload_video',
					"filetype_allowed" => 'mp4'
				),
				'section_video_webm' => array(  
					"name"             => esc_html__('Video (webm)', 'dvl-pagesections'),
					"desc"             => esc_html__('Select the WEBM file.', 'dvl-pagesections'),
					"class"            => 'video webm',
					"type"             => 'upload_video',
					"filetype_allowed" => 'webm'
				),
				'section_video_fallback_image' => array(  
					"name"  => esc_html__('Video fallback image', 'dvl-pagesections'),
					"desc"  => esc_html__('Image to show instead of video in unsupported devices / browsers.', 'dvl-pagesections'),
					"class" => '',
					"type"  => 'upload_image'
				),
				'section_video_autostart' => array(  
					"name"  => esc_html__('Auto start/stop', 'dvl-pagesections'),
					"desc"  => esc_html__('If checked the video will auto start playing when it is in the viewport and stop playing when it is outside the viewport.', 'dvl-pagesections'),
					'std'   => 'off',
					'type'  => 'toggle'
				),
				'section_video_attributes' => array(  // do not change id
					"class" => 'hidden', 
					"type"  => 'text'
				),
			) 
		),
		'advanced' => array(
			"ms_label" => esc_html__( 'Advanced', 'dvl-pagesections' ),
			"ms_fields" => array(
				'section_extra_class' => array(  //do not change id
					"name" => esc_html__( 'Extra section class', 'dvl-pagesections' ),
					"type" => 'text'
				)
			)
		)
	);

	return $meta_options;
}
add_filter( 'shrk_filter_meta_options_array', 'shrk_pagesections_metaconfig' );

?>