Ejemplo n.º 1
0
 function get_wpd_data($thumbnail_code, $values, $cart_item_key)
 {
     $variation_id = $values["variation_id"];
     if (isset($_SESSION["wpc_design_pricing_options"][$cart_item_key]) && !empty($_SESSION["wpc_design_pricing_options"][$cart_item_key])) {
         $wpc_design_pricing_options_data = WPD_Design::get_design_pricing_options_data($_SESSION["wpc_design_pricing_options"][$cart_item_key]);
         $thumbnail_code .= "<br>" . $wpc_design_pricing_options_data;
     }
     if (isset($_SESSION["wpc_generated_data"][$variation_id][$cart_item_key]) && isset($_SESSION["wpc_generated_data"][$variation_id][$cart_item_key]["output"])) {
         $thumbnail_code .= "<br>";
         $customization_list = $_SESSION["wpc_generated_data"][$variation_id][$cart_item_key];
         $upload_dir = wp_upload_dir();
         $modals = "";
         //        var_dump($customization_list["output"]);
         $i = 0;
         foreach ($customization_list["output"]["files"] as $customisation_key => $customization) {
             $tmp_dir = $customization_list["output"]["working_dir"];
             $generation_url = $upload_dir["baseurl"] . "/WPC/{$tmp_dir}/{$customisation_key}/";
             if (isset($customization["preview"])) {
                 $image = $generation_url . $customization["preview"];
             } else {
                 $image = $generation_url . $customization["image"];
             }
             $original_part_img_url = $customization_list[$customisation_key]["original_part_img"];
             //$modal_id=$variation_id."_".$cart_item_key."$customisation_key-". uniqid();//Creates issue on checkout page
             $modal_id = $variation_id . "_" . $cart_item_key . "{$customisation_key}-{$i}";
             $thumbnail_code .= '<span><a class="button" data-toggle="modal" data-target="#' . $modal_id . '">' . ucfirst($customisation_key) . '</a></span>';
             $modals .= '<div class="modal fade wpc-modal wpc_part" id="' . $modal_id . '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                 <div class="modal-dialog">
                                   <div class="modal-content">
                                     <div class="modal-header">
                                       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                       <h4 class="modal-title">Preview</h4>
                                     </div>
                                     <div class="modal-body txt-center">
                                         <div style="background-image:url(' . $original_part_img_url . ')"><img src="' . $image . '"></div>
                                     </div>
                                   </div>
                                 </div>
                               </div>';
             $i++;
         }
         array_push(wpd_retarded_actions::$code, $modals);
         add_action('wp_footer', array('wpd_retarded_actions', 'display_code'), 10, 1);
         $edit_item_url = '';
         if (get_option('permalink_structure')) {
             $edit_item_url .= WPD_Product::get_url(false) . "edit/{$variation_id}/{$cart_item_key}/";
         } else {
             $edit_item_url = WPD_Product::get_url($variation_id) . '&edit=' . $cart_item_key;
         }
         $thumbnail_code .= '<a class="button alt" href="' . $edit_item_url . '">Edit</a>';
     } else {
         if (isset($_SESSION["wpc-uploaded-designs"][$cart_item_key])) {
             $thumbnail_code .= "<br>";
             foreach ($_SESSION["wpc-uploaded-designs"][$cart_item_key] as $custom_design) {
                 $thumbnail_code .= '<span class="wpd-custom-design"><a class="button" href=' . $custom_design . '>' . __("Custom design", "wpd") . '</a></span>';
             }
         }
     }
     return $thumbnail_code;
 }
    function get_editor()
    {
        global $wpc_options_settings, $wp_query, $wpdb;
        $wpd_query_vars = array();
        ob_start();
        $product = wc_get_product($this->item_id);
        if (!WPD_Product::has_part($this->root_item_id)) {
            _e('Error: No active part defined for this product. A customizable product should have at least one part defined.', 'wpd');
            return;
        }
        $wpc_metas = get_post_meta($this->root_item_id, 'wpc-metas', true);
        $general_options = $wpc_options_settings['wpc-general-options'];
        $product_price = $product->price;
        //        $shop_currency_symbol=get_woocommerce_currency_symbol();
        $colors_options = $wpc_options_settings['wpc-colors-options'];
        $wpc_output_options = $wpc_options_settings['wpc-output-options'];
        if (isset($wpc_output_options['wpc-generate-layers']) && $wpc_output_options['wpc-generate-layers'] === "yes") {
            $generate_layers = true;
        } else {
            $generate_layers = false;
        }
        $product_metas = WPD_Admin::get_proper_value($wpc_metas, $this->item_id, array());
        $canvas_w = WPD_Product::get_option($product_metas, $general_options, "canvas-w", 800);
        $canvas_h = WPD_Product::get_option($product_metas, $general_options, "canvas-h", 500);
        $watermark = WPD_Admin::get_proper_value($product_metas, "watermark", "");
        $bounding_box_array = WPD_Admin::get_proper_value($wpc_metas, 'bounding_box', array());
        $clip_w = WPD_Admin::get_proper_value($bounding_box_array, "width", "");
        $clip_h = WPD_Admin::get_proper_value($bounding_box_array, "height", "");
        $clip_x = WPD_Admin::get_proper_value($bounding_box_array, "x", "");
        $clip_y = WPD_Admin::get_proper_value($bounding_box_array, "y", "");
        $clip_radius = WPD_Admin::get_proper_value($bounding_box_array, "radius", "");
        $clip_radius_rect = WPD_Admin::get_proper_value($bounding_box_array, "r_radius", 0);
        $clip_type = WPD_Admin::get_proper_value($bounding_box_array, "type", "");
        $clip_border = WPD_Admin::get_proper_value($bounding_box_array, "border_color", "");
        $wpc_output_product_settings = WPD_Admin::get_proper_value($product_metas, 'output-settings', array());
        $output_w = WPD_Product::get_option($wpc_output_product_settings, $wpc_output_options, "wpc-min-output-width", $canvas_w);
        $output_loop_delay = WPD_Product::get_option($wpc_output_product_settings, $wpc_output_options, "wpc-output-loop-delay", 1000);
        $svg_colorization = WPD_Admin::get_proper_value($colors_options, "wpc-svg-colorization", 'by-path');
        $wpc_palette_type = WPD_Admin::get_proper_value($colors_options, 'wpc-color-palette', 'unlimited');
        $palette = WPD_Admin::get_proper_value($colors_options, 'wpc-custom-palette', '');
        $palette_tpl = "";
        if (isset($general_options['wpc-redirect-after-cart']) && !empty($general_options['wpc-redirect-after-cart'])) {
            $redirect_after = $general_options['wpc-redirect-after-cart'];
        } else {
            $redirect_after = 0;
        }
        $wpc_img_format = "png";
        if (!empty($palette) && is_array($palette)) {
            foreach ($palette as $color) {
                $hex = str_replace("#", "", $color);
                $palette_tpl .= '<span style="background-color: ' . $color . '" data-color="' . $hex . '" class="wpc-custom-color"></span>';
            }
        }
        if (isset($wp_query->query_vars["edit"])) {
            $variation_id = $wp_query->query_vars["product_id"];
            $cart_item_key = $wp_query->query_vars["edit"];
            $wpd_query_vars["edit"] = $cart_item_key;
            $data = $_SESSION["wpc_generated_data"][$variation_id][$cart_item_key];
            //Useful when editing cart item
            $data = stripslashes_deep($data);
        } else {
            if (isset($wp_query->query_vars["oid"])) {
                $order_item_id = $wp_query->query_vars["oid"];
                $wpd_query_vars["oid"] = $order_item_id;
                $sql = "select meta_value FROM " . $wpdb->prefix . "woocommerce_order_itemmeta where order_item_id={$order_item_id} and meta_key='wpc_data'";
                //echo $sql;
                $wpc_data = $wpdb->get_var($sql);
                $data = unserialize($wpc_data);
            }
        }
        if (isset($data) && !empty($data)) {
            $design = new WPD_Design();
            $a_price = $design->get_additional_price($this->root_item_id, $data);
            $product_price += $a_price;
            ?>
            <script>
                var to_load =<?php 
            echo json_encode($data);
            ?>
;
            </script>
            <?php 
        }
        $editor_params = array("canvas_w" => $canvas_w, "canvas_h" => $canvas_h, "watermark" => $watermark, "clip_w" => $clip_w, "clip_h" => $clip_h, "clip_x" => $clip_x, "clip_r" => $clip_radius, "clip_rr" => $clip_radius_rect, "clip_y" => $clip_y, "clip_type" => $clip_type, "clip_border" => $clip_border, "output_w" => $output_w, "output_loop_delay" => $output_loop_delay, "svg_colorization" => $svg_colorization, "palette_type" => $wpc_palette_type, "print_layers" => $generate_layers, "output_format" => $wpc_img_format, "global_variation_id" => $this->item_id, "redirect_after" => $redirect_after, "palette_tpl" => $palette_tpl, "translated_strings" => array("loading_msg" => __("Just a moment", "wpd"), "deletion_error_msg" => __("The deletion of this object is not allowed", "wpd"), "loading_msg" => __("Just a moment", "wpd"), "empty_object_msg" => __("The edition area is empty.", "wpd"), "delete_all_msg" => __("Do you really want to delete all items in the design area ?", "wpd"), "delete_msg" => __("Do you really want to delete the selected items ?", "wpd"), "empty_txt_area_msg" => __("Please enter the text to add.", "wpd")), "query_vars" => $wpd_query_vars);
        $this->register_styles();
        $this->register_scripts();
        $text_options = WPD_Admin::get_proper_value($wpc_options_settings, 'wpc-texts-options', array());
        $shapes_options = WPD_Admin::get_proper_value($wpc_options_settings, 'wpc-shapes-options', array());
        $cliparts_options = WPD_Admin::get_proper_value($wpc_options_settings, 'wpc-images-options', array());
        $uploads_options = WPD_Admin::get_proper_value($wpc_options_settings, 'wpc-upload-options', array());
        $designs_options = WPD_Admin::get_proper_value($wpc_options_settings, 'wpc-designs-options', array());
        $text_tab_visible = WPD_Admin::get_proper_value($text_options, 'visible-tab', 'yes');
        $shape_tab_visible = WPD_Admin::get_proper_value($shapes_options, 'visible-tab', 'yes');
        $clipart_tab_visible = WPD_Admin::get_proper_value($cliparts_options, 'visible-tab', 'yes');
        $design_tab_visible = WPD_Admin::get_proper_value($designs_options, 'visible-tab', 'yes');
        $upload_tab_visible = WPD_Admin::get_proper_value($uploads_options, 'visible-tab', 'yes');
        ?>
        <script>
            var wpd =<?php 
        echo json_encode($editor_params);
        ?>
;
        </script>
        <div class='wpc-container'>
            <?php 
        $this->get_toolbar();
        ?>
            <div class="wpc-editor-wrap">
                <div class="wpc-editor-col">
                    <div id="wpc-tools-box-container" class="Accordion" tabindex="0">
                        <?php 
        if ($text_tab_visible == "yes") {
            ?>
                            <div class="AccordionPanel" id="text-panel">
                                <div id="text-tools" class="AccordionPanelTab"><?php 
            _e("TEXT", "wpd");
            ?>
</div>
                                <div class="AccordionPanelContent">
                                    <?php 
            $this->get_text_tools($text_options);
            ?>
                                </div>
                            </div>
                            <?php 
        }
        if ($shape_tab_visible == "yes") {
            ?>
                            <div class="AccordionPanel" id="shapes-panel">
                                <div id="shapes-tools" class="AccordionPanelTab"><?php 
            _e("SHAPES", "wpd");
            ?>
</div>
                                <div class="AccordionPanelContent">
                                    <?php 
            $this->get_shapes_tools($shapes_options);
            ?>
                                </div>
                            </div>
                            <?php 
        }
        if ($upload_tab_visible == "yes") {
            //Create a conflict for admin post page so we disable it
            //                            if (!is_admin()) {
            ?>
                            <div class="AccordionPanel" id="uploads-panel">
                                <div id="upload-tools" class="AccordionPanelTab"><?php 
            _e("UPLOADS", "wpd");
            ?>
</div>
                                <div class="AccordionPanelContent">
                                    <?php 
            $this->get_uploads_tools($uploads_options);
            ?>
                                 
                                </div>
                            </div>
                            <?php 
            //                                    }
        }
        if ($clipart_tab_visible == "yes") {
            ?>
                            <div class="AccordionPanel" id="cliparts-panel">
                                <div id="arts-tools" class="AccordionPanelTab"><?php 
            _e("CLIPARTS", "wpd");
            ?>
</div>
                                <div class="AccordionPanelContent">
                                    <?php 
            $this->get_images_tools($cliparts_options);
            ?>
                                 
                                </div>
                            </div>
                            <?php 
        }
        if ($design_tab_visible == "yes") {
            ?>

                        <div class="AccordionPanel" id="user-designs-panel">
                            <div id="designs-tools" class="AccordionPanelTab"><?php 
            _e("MY DESIGNS", "wpd");
            ?>
</div>
                            <div class="AccordionPanelContent">
                                <?php 
            $this->get_user_designs_tools();
            ?>
                            </div>
                        </div>
                        <?php 
        }
        ?>

                    </div>

                </div>
                <div class="wpc-editor-col-2">
                    <div id="wpc-editor-container">
                        <canvas id="wpc-editor" ></canvas>
                    </div>

                    <div id="product-part-container" class="">
                        <?php 
        $this->get_parts();
        ?>
                    </div>
                    <?php 
        if (!is_admin()) {
            WPD_Design::get_option_form($this->root_item_id, $wpc_metas);
        }
        ?>
                    <div id="debug"></div>

                </div>
                <?php 
        //We don't show the column at all if there is nothing to show inside
        if (isset($general_options['wpc-download-btn'])) {
            $download_btn = $general_options['wpc-download-btn'];
        }
        if (isset($general_options['wpc-preview-btn'])) {
            $preview_btn = $general_options['wpc-preview-btn'];
        }
        if (isset($general_options['wpc-cart-btn'])) {
            $cart_btn = $general_options['wpc-cart-btn'];
        }
        if (isset($preview_btn) && $preview_btn !== "0" || isset($download_btn) && $download_btn !== "0" || isset($save_btn) && $save_btn !== "0" || isset($cart_btn) && $cart_btn !== "0") {
            ?>
                <div class=" wpc-editor-col">
                    <?php 
            $this->get_design_actions_box();
            if (!is_admin()) {
                $this->get_cart_actions_box();
            }
            ?>
                      
                </div>
                <?php 
        }
        ?>
            </div>

        </div>
        <?php 
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }