private function get_element_anchor($type, $title, $source, $parameters)
 {
     $parameters_string = FPD_Parameters::convert_parameters_to_string($parameters, $type);
     if ($type == 'image') {
         return "<img data-src='{$source}' title='{$title}' data-parameters='{$parameters_string}' />";
     } else {
         $source = stripslashes($source);
         return "<span title='{$title}' data-parameters='{$parameters_string}'>{$source}</span>";
     }
 }
        private function get_variation_items($attribute_name, $options, $grid_item_layout = 'vertical', $columns = 3)
        {
            $orderby = wc_attribute_orderby($attribute_name);
            switch ($orderby) {
                case 'name':
                    $args = array('orderby' => 'name', 'hide_empty' => false, 'menu_order' => false);
                    break;
                case 'id':
                    $args = array('orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false);
                    break;
                case 'menu_order':
                    $args = array('menu_order' => 'ASC', 'hide_empty' => false);
                    break;
            }
            $terms = get_terms($attribute_name, $args);
            ob_start();
            if (isset($terms->errors)) {
                ?>
				<div class="column"><?php 
                printf(__('No attributes found for this taxonomy. Be sure that they are visible on the product page and you created them via the <a href="%s" target="_blank">Attributes admin page</a>.'), admin_url() . 'edit.php?post_type=product&page=product_attributes');
                ?>
</div>
				<?php 
                return false;
            }
            foreach ($terms as $term) {
                if (!in_array($term->slug, $options)) {
                    continue;
                }
                $fpd_params = '';
                $fpd_thumbnail = '';
                if (class_exists('FPD_Parameters')) {
                    $fpd_params = get_option('mspc_variation_fpd_params_' . $term->term_id, '');
                    $fpd_params_array = array();
                    if (!empty($fpd_params)) {
                        if (strpos($fpd_params, 'enabled') !== false) {
                            //convert string to array
                            parse_str($fpd_params, $fpd_params_array);
                            $fpd_params = FPD_Parameters::convert_parameters_to_string($fpd_params_array);
                        }
                    }
                    $fpd_thumbnail = get_option('mspc_variation_fpd_thumbnail_' . $term->term_id, '');
                }
                $image_html = '';
                $image_url = get_option('mspc_variation_image_' . $term->term_id);
                if ($image_url !== false && !empty($image_url)) {
                    $image_id = $this->get_image_id($image_url);
                    $stage_image = wp_get_attachment_image_src($image_id, empty($fpd_params) ? 'shop_single' : 'full');
                    $image_thumb = empty($fpd_thumbnail) ? $stage_image[0] : $fpd_thumbnail;
                    $image_html = '<img src="' . $image_thumb . '" alt="' . $term->name . '" class="mspc-attribute-image rounded ui image" />';
                }
                $description_html = '';
                if (!empty($term->description)) {
                    $description_html = '<p>' . $term->description . '</p>';
                }
                if ($grid_item_layout == 'vertical') {
                    ?>

				<div class="mspc-variation mspc-vertical column" data-parameters='<?php 
                    echo $fpd_params;
                    ?>
' data-image='<?php 
                    echo $stage_image[0];
                    ?>
'>
					<div class="mspc-clearfix">
						<div class="mspc-radio ui radio checkbox">
							<input type="radio" name="<?php 
                    echo $attribute_name;
                    ?>
" value="<?php 
                    echo esc_attr($term->slug);
                    ?>
">
							<label></label>
						</div>
						<?php 
                    echo $image_html;
                    ?>
						<div class="mspc-text-wrapper">
							<strong class="mspc-attribute-title"><?php 
                    echo $term->name;
                    ?>
</strong>
							<?php 
                    echo $description_html;
                    ?>
						</div>
					</div>
				</div>

				<?php 
                } else {
                    ?>

				<div class="mspc-variation mspc-horizontal column" data-parameters='<?php 
                    echo $fpd_params;
                    ?>
' data-image='<?php 
                    echo $stage_image[0];
                    ?>
'>
					<div class="mspc-clearfix">
						<?php 
                    echo $image_html;
                    ?>
						<div class="mspc-text-wrapper">
							<strong class="mspc-attribute-title"><?php 
                    echo $term->name;
                    ?>
</strong>
							<?php 
                    echo $description_html;
                    ?>
							<div class="mspc-radio ui radio checkbox">
								<input type="radio" name="<?php 
                    echo $attribute_name;
                    ?>
" value="<?php 
                    echo esc_attr($term->slug);
                    ?>
">
								<label></label>
							</div>
						</div>
					</div>
				</div>

				<?php 
                }
            }
            $output = ob_get_contents();
            ob_end_clean();
            return $output;
        }
        public function output()
        {
            ?>
			<div class="fpd-design">
				<?php 
            //get all category terms
            $category_terms = get_terms('fpd_design_category', array('hide_empty' => false, 'include' => $this->category_ids));
            //general parameters
            $general_parameters_array = $this->default_image_options;
            $final_parameters;
            //loop through all categories
            if (is_array($category_terms)) {
                foreach ($category_terms as $category_term) {
                    //get attachments from fancy design category
                    $args = array('posts_per_page' => -1, 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'ASC', 'fpd_design_category' => $category_term->slug);
                    $designs = get_posts($args);
                    //category parameters
                    $category_parameters_array = array();
                    $category_parameters = get_option('fpd_category_parameters_' . $category_term->slug);
                    if (strpos($category_parameters, 'enabled') !== false) {
                        //convert string to array
                        parse_str($category_parameters, $category_parameters_array);
                    }
                    if (!empty($designs)) {
                        ?>
						<div class="fpd-category" title="<?php 
                        echo $category_term->name;
                        ?>
">
							<?php 
                        if (is_array($designs)) {
                            foreach ($designs as $design) {
                                //merge general parameters with category parameters
                                $final_parameters = array_merge($general_parameters_array, $category_parameters_array);
                                //single element parameters
                                $single_design_parameters = get_post_meta($design->ID, 'fpd_parameters', true);
                                if (strpos($single_design_parameters, 'enabled') !== false) {
                                    $single_design_parameters_array = array();
                                    parse_str($single_design_parameters, $single_design_parameters_array);
                                    $final_parameters = array_merge($final_parameters, $single_design_parameters_array);
                                }
                                //convert array to string
                                $design_parameters_str = FPD_Parameters::convert_parameters_to_string($final_parameters);
                                //get design thumbnail
                                $design_thumbnail = get_post_meta($design->ID, 'fpd_thumbnail', true);
                                //custom thumbnail
                                if (empty($design_thumbnail)) {
                                    $design_thumbnail = wp_get_attachment_image_src($design->ID, 'medium');
                                    $design_thumbnail = $design_thumbnail[0] ? $design_thumbnail[0] : $design->guid;
                                }
                                $origin_image = wp_get_attachment_image_src($design->ID, 'full');
                                $origin_image = $origin_image[0] ? $origin_image[0] : $design->guid;
                                if (isset($origin_image)) {
                                    echo "<img data-src='{$origin_image}' title='{$design->post_title}' data-parameters='{$design_parameters_str}' data-thumbnail='{$design_thumbnail}' />";
                                }
                            }
                        }
                        ?>
						</div>
						<?php 
                    }
                }
            }
            ?>
			</div>
			<?php 
        }
 public function get_custom_image_parameters_string()
 {
     $strip_from_option_key = 'fpd_uploaded_designs_parameter_';
     $custom_images_parameters = array();
     $custom_image_options = FPD_Settings_Default_Element_Options::get_options();
     $custom_image_options = $custom_image_options['default-custom-image-options'];
     foreach ($custom_image_options as $option) {
         if (isset($option['default']) && strpos($option['id'], $strip_from_option_key) !== false) {
             $parameter = str_replace($strip_from_option_key, '', $option['id']);
             $pure_key = str_replace('fpd_', '', $option['id']);
             $custom_images_parameters[$parameter] = $this->get_option($pure_key);
         }
     }
     return FPD_Parameters::convert_parameters_to_string($custom_images_parameters);
 }