public function duplicate($new_product_id) { $new_fp = new Fancy_Product($new_product_id); foreach ($this->get_views() as $view) { $new_fp->add_view($view->title, $view->elements, $view->thumbnail, $view->view_order); } }
public function output() { ?> <div class="wrap" id="fpd-product-builder"> <h2 class="fpd-clearfix"> <?php _e('Fancy Product Builder', 'radykal'); ?> <?php fpd_admin_display_version_info(); ?> </h2> <?php global $wpdb, $woocommerce; $request_view_id = isset($_GET['view_id']) ? $_GET['view_id'] : NULL; //get all fancy products $fancy_products = array(); if (fpd_table_exists(FPD_PRODUCTS_TABLE)) { $fancy_products = $wpdb->get_results("SELECT * FROM " . FPD_PRODUCTS_TABLE . " ORDER BY title ASC"); } if (sizeof($fancy_products) == 0) { echo '<div class="updated"><p><strong>' . __('There are no fancy products!', 'radykal') . '</strong></p></div></div>'; exit; } //save elements of view if (isset($_POST['save_elements'])) { check_admin_referer('fpd_save_elements'); $request_view_id = $_POST['view_id']; $elements = array(); for ($i = 0; $i < sizeof($_POST['element_types']); $i++) { $element = array(); $element['type'] = $_POST['element_types'][$i]; $element['title'] = $_POST['element_titles'][$i]; $element['source'] = $_POST['element_sources'][$i]; $parameters = array(); parse_str($_POST['element_parameters'][$i], $parameters); if (is_array($parameters)) { foreach ($parameters as $key => $value) { if ($value == '') { $parameters[$key] = NULL; } else { $parameters[$key] = preg_replace('/\\s+/', '', $value); } } } $element['parameters'] = $parameters; array_push($elements, $element); } $fancy_view = new Fancy_View($request_view_id); $fancy_view->update(array('elements' => serialize($elements))); $requested_view_elements = $elements; echo '<div class="updated"><p><strong>' . __('Elements saved.', 'radykal') . '</strong></p></div>'; } ?> <br class="clear" /> <p class="description"><?php _e('Select the view of your Fancy Product:', 'radykal'); ?> </p> <select id="fpd-view-switcher" class="radykal-select2" style="width: 38%;"> <?php if (is_array($fancy_products)) { foreach ($fancy_products as $fancy_product) { $fancy_product_id = $fancy_product->ID; echo '<optgroup label="' . $fancy_product->title . '" id="' . $fancy_product_id . '">'; $fancy_product = new Fancy_Product($fancy_product_id); $views = $fancy_product->get_views(); if (is_array($views)) { for ($i = 0; $i < sizeof($views); ++$i) { $view = $views[$i]; //get first view if ($request_view_id == NULL) { $request_view_id = $view->ID; } //get requested view if ($request_view_id == $view->ID && !isset($requested_view_elements)) { $requested_view_elements = unserialize($view->elements); } echo '<option value="' . $view->ID . '" ' . selected($request_view_id, $view->ID, false) . '>' . $view->title . '</option>'; } } echo '</optgroup>'; } } ?> </select> <?php //create instance of selected fancy view $fancy_view = new Fancy_View($request_view_id); $product_id = $fancy_view->get_product_id(); //get stage dimensions $fancy_product = new Fancy_Product($product_id); $stage_width = $fancy_product->get_option('stage_width'); $stage_height = $fancy_product->get_option('stage_height'); ?> <a href="#" id="fpd-save-layers" class="button-primary fpd-right"><?php _e('Save Layers', 'radykal'); ?> </a> <div id="fpd-layers-container" class="fpd-clearfix"> <!-- Manage elements --> <div id="fpd-manage-elements" class="fpd-panel"> <form method="post" id="fpd-submit"> <input type="submit" class="fpd-hidden" name="save_elements" /> <?php wp_nonce_field('fpd_save_elements'); ?> <h3 class="fpd-clearfix"> <span><?php _e('Layers', 'radykal'); ?> </span> </h3> <div id="fpd-add-element"> <a href="#" class="add-new-h2" id="fpd-add-image-element"><?php _e('Add Image', 'radykal'); ?> </a> <a href="#" class="add-new-h2" id="fpd-add-text-element"><?php _e('Add Text', 'radykal'); ?> </a> <a href="#" class="add-new-h2" id="fpd-add-curved-text-element"><?php _e('Add Curved Text', 'radykal'); ?> </a> <a href="#" class="add-new-h2" id="fpd-add-upload-zone"><?php _e('Add Upload Zone', 'radykal'); ?> </a> </div> <input type="hidden" value="<?php echo $request_view_id; ?> " name="view_id" /> <p class="description"><?php _e('Change the layer order by dragging elements up or down.', 'radykal'); ?> </p> <ul id="fpd-elements-list"> <?php $index = 0; if (is_array($requested_view_elements)) { foreach ($requested_view_elements as $view_element) { echo self::get_element_list_item($index, $view_element['title'], $view_element['type'], stripslashes($view_element['source']), http_build_query($view_element['parameters'])); $index++; } } ?> </ul> </form> </div> <!-- Edit Parameters --> <div id="fpd-edit-parameters" class="fpd-panel"> <h3><?php _e('Layer Options', 'radykal'); ?> : <span id="fpd-edit-parameters-for"></span></h3> <?php require_once FPD_PLUGIN_ADMIN_DIR . '/views/html-product-builder-parameters-form.php'; ?> </div> </div><!-- Manage Layers Box --> <!-- Product Stage --> <div id="fpd-product-stage" class="fpd-panel"> <h3 class="fpd-clearfix"><?php _e('Product Stage', 'radykal'); ?> <span class="description"><?php echo $stage_width; ?> px * <?php echo $stage_height; ?> px</span> </h3> <div id="fpd-element-toolbar"> <a href="#" class="button button-secondary fpd-center-horizontal"><?php _e('Center Horizontal', 'radykal'); ?> </a> <a href="#" class="button button-secondary fpd-center-vertical"><?php _e('Center Vertical', 'radykal'); ?> </a> <a href="#" class="button button-secondary fpd-dupliacte-layer"><?php _e('Duplicate Layer', 'radykal'); ?> </a> </div> <div id="fpd-fabric-stage-wrapper"> <canvas id="fpd-fabric-stage" width="<?php echo $stage_width; ?> " height="<?php echo $stage_height; ?> "></canvas> </div> </div> </div> <?php }
public function output() { global $wpdb; $page_links = false; if (isset($_POST['run_updater'])) { FPD_Install::do_upgrade('2.0.0'); update_option('fpd_hide_run_updater', 'yes'); } if (isset($_POST['fpd_filter_by'])) { update_option('fpd_admin_filter_by', $_POST['fpd_filter_by']); } if (isset($_POST['fpd_order_by'])) { update_option('fpd_admin_order_by', $_POST['fpd_order_by']); } $filter_by = get_option('fpd_admin_filter_by', 'title'); $order_by = get_option('fpd_admin_order_by', 'ASC'); $where = ''; if (isset($_POST['fpd_search_products_string']) && !empty($_POST['fpd_search_products_string'])) { $where = "WHERE title LIKE '%{$_POST['fpd_search_products_string']}%'"; } $categories = array(); if (fpd_table_exists(FPD_CATEGORIES_TABLE)) { $categories = $wpdb->get_results("SELECT * FROM " . FPD_CATEGORIES_TABLE . " ORDER BY title ASC"); } $products = array(); if (fpd_table_exists(FPD_PRODUCTS_TABLE)) { $pagenum = isset($_GET['paged']) ? absint($_GET['paged']) : 1; $limit = 20; $offset = ($pagenum - 1) * $limit; $total = $wpdb->get_var("SELECT COUNT(ID) FROM " . FPD_PRODUCTS_TABLE . ""); $num_of_pages = ceil($total / $limit); $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $num_of_pages, 'current' => $pagenum)); $products = $wpdb->get_results("SELECT * FROM " . FPD_PRODUCTS_TABLE . " " . $where . " ORDER BY " . $filter_by . " " . $order_by . " LIMIT {$limit} OFFSET {$offset}"); } //select by category if (isset($_GET['category_id'])) { $page_links = false; $products = $wpdb->get_results("SELECT * FROM " . FPD_PRODUCTS_TABLE . " WHERE ID IN (SELECT product_id FROM " . FPD_CATEGORY_PRODUCTS_REL_TABLE . " WHERE category_id={$_GET['category_id']})"); } if (isset($_GET['info'])) { $info_url = $_GET['info'] == 'activated' ? 'http://assets.fancyproductdesigner.com/info-modals/installed.html' : 'http://assets.fancyproductdesigner.com/info-modals/updated.html'; require_once FPD_PLUGIN_ADMIN_DIR . '/modals/modal-updated-installed-info.php'; } require_once FPD_PLUGIN_ADMIN_DIR . '/modals/modal-load-demo.php'; require_once FPD_PLUGIN_ADMIN_DIR . '/modals/modal-load-template.php'; require_once FPD_PLUGIN_ADMIN_DIR . '/modals/modal-edit-product-options.php'; require_once FPD_PLUGIN_ADMIN_DIR . '/modals/modal-edit-view-options.php'; ?> <div class="wrap" id="fpd-manage-products"> <h2> <?php _e('Manage Fancy Products', 'radykal'); ?> <?php fpd_admin_display_version_info(); ?> </h2> <?php if (get_option('fpd_hide_run_updater', 'yes') !== 'yes') { ?> <div class="fpd-panel"> <h3>Update</h3> <p>Your action is required to update to the latest version.</p> <form method="POST"> <input type="submit" name="run_updater" value="Run Updater" class="button-primary" /> </form> </div> <?php } ?> <div class="fpd-clearfix"> <div id="fpd-products" class="fpd-panel"> <input type="file" value="Upload" class="fpd-hidden" id="fpd-file-import" /> <h3> <?php _e('Fancy Products', 'radykal'); ?> <a href="#" id="fpd-add-product" class="add-new-h2" style="float: none; margin-left: 10px;"><?php _e('Add New', 'radykal'); ?> </a> <a href="#" id="fpd-import-product" class="add-new-h2"><?php _e('Import', 'radykal'); ?> </a> <a href="#" id="fpd-load-template" class="add-new-h2"><?php _e('Load Template', 'radykal'); ?> </a> <a href="#" id="fpd-load-demo" class="add-new-h2 fpd-admin-tooltip" title="<?php _e('Load a demo to get started', 'radykal'); ?> "><?php _e('Load Demo', 'radykal'); ?> </a> </h3> <div id="fpd-products-nav" class="fpd-clearfix"> <form method="POST"> <span class="description"><?php _e('Filter:', 'radykal'); ?> </span> <select name="fpd_filter_by"> <option value="ID" <?php selected($filter_by, 'ID'); ?> ><?php _e('ID', 'radykal'); ?> </option> <option value="title" <?php selected($filter_by, 'title'); ?> ><?php _e('Title', 'radykal'); ?> </option> </select> <select name="fpd_order_by"> <option value="ASC" <?php selected($order_by, 'ASC'); ?> ><?php _e('Ascending', 'radykal'); ?> </option> <option value="DESC" <?php selected($order_by, 'DESC'); ?> ><?php _e('Descending', 'radykal'); ?> </option> </select> </form> <form method="POST" name="fpd_search_products"> <input type="text" name="fpd_search_products_string" placeholder="<?php _e('Search Fancy Products...', 'radykal'); ?> " /> <input type="submit" class="button button-secondary" value="<?php _e('Search', 'radykal'); ?> " /> </form> </div> <?php if (empty($products)) { ?> <p class="fpd-error-message"><strong><?php _e('No Fancy Products found!', 'radykal'); ?> </strong></p> <?php } ?> <ul id="fpd-products-list"> <?php foreach ($products as $product) { $fancy_product = new Fancy_Product($product->ID); $category_ids = $fancy_product->get_category_ids(); echo self::get_product_item_html($product->ID, $product->title, implode(',', $category_ids), stripslashes($product->options)); echo '<ul class="fpd-views-list">'; $product_views = $fancy_product->get_views(); if (!empty($product_views)) { foreach ($product_views as $view) { $view_options = isset($view->options) ? stripslashes($view->options) : ''; echo self::get_view_item_html($view->ID, $view->thumbnail, $view->title, $view_options); } } echo '</ul>'; } ?> </ul> <?php if ($page_links) { echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 0;">' . $page_links . '</div></div>'; } ?> <div class="fpd-ui-blocker"></div> </div> <div id="fpd-categories" class="fpd-panel"> <h3> <?php _e('Categories', 'radykal'); ?> <a href="#" id="fpd-add-category" class="add-new-h2"><?php _e('Add New', 'radykal'); ?> </a> </h3> <ul id="fpd-categories-list"> <?php foreach ($categories as $category) { echo self::get_category_item_html($category->ID, $category->title); } ?> </ul> <div class="fpd-ui-blocker"></div> </div> </div> </div> <?php }
private function get_product_html($product_id) { $fancy_product = new Fancy_Product($product_id); $views_data = $fancy_product->get_views(); $output = ''; if (!empty($views_data)) { $first_view = $views_data[0]; $product_options = fpd_convert_obj_string_to_array($fancy_product->get_options()); $view_options = fpd_convert_obj_string_to_array($first_view->options); $view_options = array_merge((array) $product_options, (array) $view_options); $view_options = Fancy_View::options_to_string($view_options); ob_start(); echo "<div class='fpd-product' title='" . esc_attr($first_view->title) . "' title='" . esc_attr($first_view->title) . "' data-thumbnail='" . esc_attr($first_view->thumbnail) . "' data-options='" . $view_options . "'>"; echo $this->get_element_anchors_from_view($first_view->elements); //sub views if (sizeof($views_data) > 1) { for ($i = 1; $i < sizeof($views_data); $i++) { $sub_view = $views_data[$i]; $view_options = fpd_convert_obj_string_to_array($sub_view->options); $view_options = array_merge((array) $product_options, (array) $view_options); $view_options = Fancy_View::options_to_string($view_options); ?> <div class="fpd-product" title="<?php echo esc_attr($sub_view->title); ?> " data-thumbnail="<?php echo esc_attr($sub_view->thumbnail); ?> " data-options='<?php echo $view_options; ?> '> <?php echo $this->get_element_anchors_from_view($sub_view->elements); ?> </div> <?php } } echo '</div>'; //product $output = ob_get_contents(); ob_end_clean(); } return $output; }
public static function do_upgrade($to_version) { global $wpdb; if ($to_version === '1.1.3') { $wpdb->query("ALTER TABLE " . FPD_VIEWS_TABLE . " ADD view_order INT COLLATE utf8_general_ci NULL DEFAULT 0;"); } else { if ($to_version === '2.0.0') { $views = $wpdb->get_results("SELECT * FROM " . FPD_VIEWS_TABLE . " GROUP BY product_id"); foreach ($views as $view) { //check if product exists, otherwise delete it from views table if (get_post_status($view->product_id) === false) { $wpdb->query($wpdb->prepare("DELETE FROM " . FPD_VIEWS_TABLE . " WHERE product_id=%d", $view->product_id)); } else { $check_title = get_the_title($view->product_id); if (!empty($check_title)) { $product_id = Fancy_Product::create($check_title); //create product $fancy_product_settings = new FPD_Product_Settings($view->product_id); //get stage dimensions and add them in the product options $product_options = array(); if ($fancy_product_settings->get_individual_option('stage_width')) { $product_options['stage_width'] = $fancy_product_settings->get_individual_option('stage_width'); } if ($fancy_product_settings->get_individual_option('stage_height')) { $product_options['stage_height'] = $fancy_product_settings->get_individual_option('stage_height'); } $fancy_product = new Fancy_Product($product_id); if (sizeof($product_options) !== 0) { $fancy_product->update(null, json_encode($product_options)); } //assign product to wc product update_post_meta($view->product_id, 'fpd_source_type', 'product'); $product_array = array($product_id); update_post_meta($view->product_id, 'fpd_products', $product_array); //update product id of views $wpdb->update(FPD_VIEWS_TABLE, array('product_id' => $product_id), array('product_id' => $view->product_id), array('%d'), array('%d')); } } } //add options to views table $wpdb->query("ALTER TABLE " . FPD_VIEWS_TABLE . " ADD options TEXT COLLATE utf8_general_ci NULL DEFAULT '';"); } } }
public function export_product() { if (!isset($_GET['id'])) { exit; } check_ajax_referer('fpd_ajax_nonce', '_ajax_nonce'); $id = $_GET['id']; $fp = new Fancy_Product($id); $views = $fp->get_views(); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=fancy_product_' . $id . '.json'); $output = '{'; foreach ($views as $view) { $output .= '"' . $view->ID . '": {'; $output .= '"title": "' . $view->title . '",'; $elements = unserialize($view->elements); for ($i = 0; $i < sizeof($elements); $i++) { $source = $elements[$i]['source']; if ($elements[$i]['type'] == 'image' && base64_encode(base64_decode($source, true)) !== $source) { $image_content = base64_encode(fpd_admin_get_file_content($source)); if ($image_content !== false) { $image_type = explode(".", basename($source), 2); $image_type = $image_type[1]; $elements[$i]['source'] = $image_type . ',' . $image_content; } } } $output .= '"elements": ' . stripslashes(json_encode($elements)) . ','; $output .= '"thumbnail_name": "' . basename($view->thumbnail) . '",'; $thumbnail_content = base64_encode(fpd_admin_get_file_content(stripslashes($view->thumbnail))); $output .= '"thumbnail": "' . ($thumbnail_content === false ? stripslashes($view->thumbnail) : $thumbnail_content) . '"},'; } $output = rtrim($output, ","); $output .= '}'; echo $output; die; }