<?php

/**
 * Custom coded by Spiderfly Studios https://www.spiderflystudios.com
 * WooCommerce Product Short Description
 * Displays the short description for the current product.
 */

if( !class_exists( 'woocommerce' ) )
{
	add_shortcode('av_wc_shortdesc', 'avia_please_install_woo');
	return;
}

if ( !class_exists( 'avia_sc_wc_shortdesc' ) )
{
	class avia_sc_wc_shortdesc extends aviaShortcodeTemplate
	{
		/**
		 * Create the config array for the shortcode button
		 */
		function shortcode_insert_button()
		{
			$template_url = get_stylesheet_directory_uri();
			$child_sc_imgs = $template_url.'/shortcodes/spiderfly-elements/images/';
			$this->config['name']		= __('Short Description', 'avia_framework' );
			$this->config['tab']		= __('WooCommerce', 'avia_framework' );
			$this->config['icon']		= $child_sc_imgs."short-desc.png";
			$this->config['order']		= 82;
			$this->config['target']		= 'avia-target-insert';
			$this->config['shortcode'] 	= 'av_wc_shortdesc';
			$this->config['tooltip'] 	= __('Displays the short description for the current product.', 'avia_framework' );
			$this->config['drag-level'] = 3;
			$this->config['tinyMCE'] 	= array('disable' => "true");
			$this->config['posttype'] 	= array('product',__('This element can only be used on single product pages','avia_framework'));
		}


		/**
			 * Popup Elements
			 *
			 * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
			 * opens a modal window that allows to edit the element properties
			 *
			 * @return void
			 */
			function popup_elements()
			{
				$this->elements = array(
					
					array(
							"type" 	=> "tab_container", 'nodescription' => true
						),
						
					array(
							"type" 	=> "tab",
							"name"  => __("Content" , 'avia_framework'),
							'nodescription' => true
						),
					
					array(	"name" 	=> __("Font Size", 'avia_framework' ),
							"desc" 	=> __("Size of the text in px", 'avia_framework' ),
				            "id" 	=> "size",
				            "type" 	=> "select",
				            "subtype" => AviaHtmlHelper::number_array(8,40,1, array( __("Default Size", 'avia_framework' )=>'')),
				            "std" => "16"),
							
					array(
							"type" 	=> "close_div",
							'nodescription' => true
						),
					
					array(
							"type" 	=> "tab",
							"name"	=> __("Colors",'avia_framework' ),
							'nodescription' => true
						),
					
					
					array(
							"name" 	=> __("Font Colors", 'avia_framework' ),
							"desc" 	=> __("Either use the themes default colors or apply some custom ones", 'avia_framework' ),
							"id" 	=> "font_color",
							"type" 	=> "select",
							"std" 	=> "",
							"subtype" => array( __('Default', 'avia_framework' )=>'',
												__('Define Custom Colors', 'avia_framework' )=>'custom'),
					),
					
					array(	
							"name" 	=> __("Custom Font Color", 'avia_framework' ),
							"desc" 	=> __("Select a custom font color. Leave empty to use the default", 'avia_framework' ),
							"id" 	=> "color",
							"type" 	=> "colorpicker",
							"std" 	=> "",
							"required" => array('font_color','equals','custom')
						),	
						
					array(
							"type" 	=> "close_div",
							'nodescription' => true
						),
						
					
					array(
							"type" 	=> "tab",
							"name"	=> __("Screen Options",'avia_framework' ),
							'nodescription' => true
						),
					
							array(
								"name" 	=> __("Element Visibility",'avia_framework' ),
								"desc" 	=> __("Set the visibility for this element, based on the device screensize.", 'avia_framework' ),
								"type" 	=> "heading",
								"description_class" => "av-builder-note av-neutral",
								),
							
							array(	
									"desc" 	=> __("Hide on large screens (wider than 990px - eg: Desktop)", 'avia_framework'),
									"id" 	=> "av-desktop-hide",
									"std" 	=> "",
									"container_class" => 'av-multi-checkbox',
									"type" 	=> "checkbox"),
							
							array(	
								
									"desc" 	=> __("Hide on medium sized screens (between 768px and 989px - eg: Tablet Landscape)", 'avia_framework'),
									"id" 	=> "av-medium-hide",
									"std" 	=> "",
									"container_class" => 'av-multi-checkbox',
									"type" 	=> "checkbox"),
									
							array(	
								
									"desc" 	=> __("Hide on small screens (between 480px and 767px - eg: Tablet Portrait)", 'avia_framework'),
									"id" 	=> "av-small-hide",
									"std" 	=> "",
									"container_class" => 'av-multi-checkbox',
									"type" 	=> "checkbox"),
									
							array(	
								
									"desc" 	=> __("Hide on very small screens (smaller than 479px - eg: Smartphone Portrait)", 'avia_framework'),
									"id" 	=> "av-mini-hide",
									"std" 	=> "",
									"container_class" => 'av-multi-checkbox',
									"type" 	=> "checkbox"),
							
							
							array(
								"name" 	=> __("Font Size",'avia_framework' ),
								"desc" 	=> __("Set the font size for the element content, based on the device screensize.", 'avia_framework' ),
								"type" 	=> "heading",
								"description_class" => "av-builder-note av-neutral",
								),
								
							
							
								
							array(	"name" 	=> __("Font Size for medium sized screens", 'avia_framework' ),
				            "id" 	=> "av-medium-font-size",
				            "type" 	=> "select",
				            "subtype" => AviaHtmlHelper::number_array(10,60,1, array( __("Default", 'avia_framework' )=>''), "px"),
				            "std" => ""),
				            
				            array(	"name" 	=> __("Font Size for small screens", 'avia_framework' ),
				            "id" 	=> "av-small-font-size",
				            "type" 	=> "select",
				            "subtype" => AviaHtmlHelper::number_array(10,60,1, array( __("Default", 'avia_framework' )=>''), "px"),
				            "std" => ""),
				            
							array(	"name" 	=> __("Font Size for very small screens", 'avia_framework' ),
				            "id" 	=> "av-mini-font-size",
				            "type" 	=> "select",
				            "subtype" => AviaHtmlHelper::number_array(10,60,1, array( __("Default", 'avia_framework' )=>''), "px"),
				            "std" => ""),
					
						
					array(
							"type" 	=> "close_div",
							'nodescription' => true
						),	
					
						
					array(
							"type" 	=> "close_div",
							'nodescription' => true
						),
				);

			}


		/**
		 * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
		 * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
		 * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
		 *
		 *
		 * @param array $params this array holds the default values for $content and $args.
		 * @return $params the return array usually holds an innerHtml key that holds item specific markup.
		 */
		function editor_element($params)
		{
			$params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
			$params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
			$params['content'] 	 = NULL; //remove to allow content elements
			return $params;
		}



		/**
		 * Frontend Shortcode Handler
		 *
		 * @param array $atts array of attributes
		 * @param string $content text within enclosing form of shortcode element
		 * @param string $shortcodename the shortcode found, when == callback name
		 * @return string $output returns the modified html string
		 */

		function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
			{
				extract(AviaHelper::av_mobile_sizes($atts)); //return $av_font_classes, $av_title_font_classes and $av_display_classes 

				extract(shortcode_atts(array( 
				
				'font_color' => "",
				'color' => '',
				'size' => '',
				
				), $atts, $this->config['shortcode']));
				
				
				$custom_class = !empty($meta['custom_class']) ? $meta['custom_class'] : "";
                $output = '';
                $markup = avia_markup_helper(array('context' => 'entry','echo'=>false, 'custom_markup'=>$meta['custom_markup']));
                $markup_text = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'custom_markup'=>$meta['custom_markup']));
				
				$extra_styling = "";
				
				if($size)
				{
					$extra_styling .= "font-size:{$size}px; ";
				}
				
				if($font_color == "custom")
				{
					$custom_class  .= " av_inherit_color";
					$extra_styling .= !empty($color) ? "color:{$color}; " : "";
				}
				
				if($extra_styling) $extra_styling = " style='{$extra_styling}'" ;
				
				global $product;
				if ( $product->post->post_excerpt ) {
				$shortdesc = $product->post->post_excerpt;
                $output .= '<section class="av_textblock_section '.$av_display_classes.'" '.$markup.'>';
                $output .= "<div class='avia_textblock {$custom_class} {$av_font_classes}' {$extra_styling} {$markup_text}><p>".$shortdesc."</p></div>";
                $output .= '</section>';
				}
                return $output;
			}

	}
}