id ) ) { return sprintf( '%s', esc_url( get_permalink($product->id) ), esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $product->product_type ), esc_html( fpd_get_option( 'fpd_label_add_to_cart_text' ) ) ); } return $handler; } //add customize button add the end of catalog item public function add_catalog_customize_button() { global $product; if( is_fancy_product( $product->id ) ) { printf( '%s', esc_url( get_permalink($product->id) ), esc_html( fpd_get_option( 'fpd_label_add_to_cart_text' ) ) ); } } //add fancy-product class in body public function add_fancy_product_class( $classes ) { global $post; if( is_fancy_product( $post->ID ) ) { $product_settings = new FPD_Product_Settings( $post->ID ); $classes[] = 'fancy-product'; if( $product_settings->customize_button_enabled || (isset($_GET['cart_item_key']) && $product_settings->get_option('open_in_lightbox')) ) { $classes[] = 'fpd-customize-button-visible'; } else { $classes[] = 'fpd-customize-button-hidden'; } //check if tablets are supported if( fpd_get_option( 'fpd_disable_on_tablets' ) ) $classes[] = 'fpd-hidden-tablets'; //check if smartphones are supported if( fpd_get_option( 'fpd_disable_on_smartphones' ) ) $classes[] = 'fpd-hidden-mobile'; if( $product_settings->get_option( 'fullwidth_summary' ) ) $classes[] = 'fpd-fullwidth-summary'; } return $classes; } public function before_product_container() { global $post; if( is_fancy_product( $post->ID ) ) { //add product designer $product_settings = new FPD_Product_Settings( $post->ID ); $position = $product_settings->get_option('placement'); if( $position == 'fpd-replace-image') { add_action( 'woocommerce_before_single_product_summary', array( &$this, 'add_product_designer'), 15 ); } else if( $position == 'fpd-under-title') { add_action( 'woocommerce_single_product_summary', array( &$this, 'add_product_designer'), 6 ); } else if( $position == 'fpd-after-summary') { add_action( 'woocommerce_after_single_product_summary', array( &$this, 'add_product_designer'), 1 ); } else { add_action( 'fpd_product_designer', array( &$this, 'add_product_designer') ); } //remove product image, there you gonna see the product designer if( $product_settings->get_option('hide_product_image') || ($position == 'fpd-replace-image' && (!$product_settings->customize_button_enabled)) ) { remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 ); } } } //the actual product designer will be added public function add_product_designer() { global $post; $product_settings = new FPD_Product_Settings( $post->ID ); $open_in_lightbox = $product_settings->get_option('open_in_lightbox') && trim($product_settings->get_option('start_customizing_button')) != ''; if( is_fancy_product( $product_settings->master_id ) && (!$product_settings->customize_button_enabled || $open_in_lightbox) ) { FPD_Scripts_Styles::$add_script = true; $selector = 'fancy-product-designer-'.$product_settings->master_id.''; //get availabe fonts $available_fonts = $product_settings->get_option('font_families[]') === false ? FPD_Fonts::get_enabled_fonts() : $product_settings->get_option('font_families[]'); if( !is_array($available_fonts) ) $available_fonts = str_split($available_fonts, strlen($available_fonts)); //woocommerce if( get_post_type( $post ) === 'product' ) { $this->output_wc_start(); } //get assigned categories $fancy_content_ids = fpd_has_content( $product_settings->master_id ); if( !is_array($fancy_content_ids) || sizeof($fancy_content_ids) === 0 ) { return; } //define the designer margins $designer_margins = $product_settings->get_option('designer_margin'); $margin_styles = ''; if( !empty($designer_margins) ) { @parse_str($designer_margins, $designer_margins); foreach($designer_margins as $margin_key => $margin_val) { $margin_styles .= 'margin-'.$margin_key.':'.$margin_val.'px;'; } } //add class if lightbox is enabled $modal_box_css = $open_in_lightbox ? ' fpd-lightbox-enabled' : ''; $source_type = get_post_meta( $product_settings->master_id, 'fpd_source_type', true ); ?>
output_wc_js(); } else { $this->output_shortcode_js(); } } } public function reset_share_permalink( $url, $post ) { if( isset($post->ID) && is_fancy_product( $post->ID ) && isset($_GET['share_id']) ) { $url = add_query_arg( 'share_id', $_GET['share_id'], $url ); } return $url; } public function set_product_image($url) { global $post; if( isset($post->ID) && is_fancy_product( $post->ID ) && isset($_GET['share_id']) ) { $transient_key = 'fpd_share_'.$_GET['share_id']; $transient_val = get_transient($transient_key); return $transient_val === false ? $url : $transient_val['image_url']; } return $url; } public function add_share() { global $post; $product_settings = new FPD_Product_Settings( $post->ID ); $open_in_lightbox = $product_settings->get_option('open_in_lightbox') && trim($product_settings->get_option('start_customizing_button')) != ''; if( is_fancy_product( $post->ID ) && (!$product_settings->customize_button_enabled || $open_in_lightbox) ) { echo $this->get_share_html(); } } public function create_share_url() { if( !isset($_POST['image']) || !isset($_POST['product']) ) die; if (!preg_match('/data:([^;]*);base64,(.*)/', $_POST['image'], $matches)) { echo json_encode(array( 'error' => __('Image string is not a valid Data URL.', 'radykal') )); die; } $share_dir = WP_CONTENT_DIR . '/uploads/fpd_shares/'; if( !file_exists($share_dir) ) wp_mkdir_p($share_dir); $today = date('Y-m-d'); $timestamp = strtotime('now'); if( !file_exists($share_dir.'/'.$today) ) wp_mkdir_p($share_dir.'/'.$today); // Decode the data $image_content = base64_decode($matches[2]); $image_name = $timestamp.".png"; //create png from decoded base 64 string and save the image in the parent folder $result = @file_put_contents($share_dir.'/'.$today.'/'.$image_name, $image_content); if($result === false) { echo json_encode(array( 'error' => __('Image could not be created. Please try again!', 'radykal') )); die; } //set transient to store product $cache_days = intval(fpd_get_option('fpd_sharing_cache_days')) * DAY_IN_SECONDS; $transient_val = array( 'image_url' => content_url('/uploads/fpd_shares/'.$today.'/'.$image_name), 'product' => $_POST['product'] ); $transient_result = set_transient('fpd_share_'.$timestamp, $transient_val, $cache_days); if( $transient_result ) { echo json_encode(array( 'share_id' => $timestamp, 'image_url' => content_url('/uploads/fpd_shares/'.$today.'/'.$image_name) )); } die; } public function fpd_shortcode_handler( $atts ) { extract( shortcode_atts( array( ), $atts, 'fpd' ) ); ob_start(); echo $this->add_customize_button(); echo $this->add_product_designer(); $output = ob_get_contents(); ob_end_clean(); return $output; } public function fpd_form_shortcode_handler( $atts ) { extract( shortcode_atts( array( 'button' => 'Send', 'name_placeholder' => 'Enter your name here', 'email_placeholder' => 'Enter your email here', 'currency' => '$', ), $atts, 'fpd_form' ) ); ob_start(); ?> ID); $open_in_lightbox = $product_settings->get_option('open_in_lightbox') && trim($product_settings->get_option('start_customizing_button')) != ''; if( (is_fancy_product($post->ID) && ($product_settings->customize_button_enabled || $open_in_lightbox )) ) { $button_class = trim(fpd_get_option('fpd_start_customizing_css_class')) == '' ? 'fpd-start-customizing-button' : fpd_get_option('fpd_start_customizing_css_class'); $button_class .= $open_in_lightbox ? ' fpd-disabled' : ''; $label = $open_in_lightbox ? '' : $product_settings->get_option('start_customizing_button'); ?>
'; _e('Sorry, but the cart item could not be found!', 'radykal'); echo '
'; return; } } else if( isset($_GET['order']) && isset($_GET['item_id']) ) { //load ordered product in designer $order = new WC_Order( $_GET['order'] ); $item_meta = $order->get_item_meta( $_GET['item_id'], 'fpd_data' ); $this->form_views = $item_meta[0]["fpd_product"]; if( $product->is_downloadable() && $order->is_download_permitted() ) { $this->disable_export_btns = false; ?>