public static function get_orders($limit = 5, $offset = 0) { if (fpd_table_exists(FPD_ORDERS_TABLE)) { global $wpdb; return $wpdb->get_results("SELECT * FROM " . FPD_ORDERS_TABLE . " ORDER BY ID DESC LIMIT {$limit} OFFSET {$offset}"); } return false; }
public function add_product($product_id) { global $wpdb, $charset_collate; //create products table if necessary if (!fpd_table_exists(FPD_CATEGORY_PRODUCTS_REL_TABLE)) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; //create many-to-many relationship category/products table $category_products_rel_sql_string = "category_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t product_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t PRIMARY KEY (category_id, product_id),\n\t\t\t\t\t\t\t CONSTRAINT " . $wpdb->prefix . "_fpd_category_fk FOREIGN KEY (category_id) REFERENCES " . FPD_CATEGORIES_TABLE . " (ID) ON DELETE CASCADE,\n\t\t\t\t\t\t\t CONSTRAINT " . $wpdb->prefix . "_fpd_product_fk FOREIGN KEY (product_id) REFERENCES " . FPD_PRODUCTS_TABLE . " (ID) ON DELETE CASCADE"; $sql = "CREATE TABLE " . FPD_CATEGORY_PRODUCTS_REL_TABLE . " ({$category_products_rel_sql_string}) {$charset_collate};"; dbDelta($sql); } $inserted = $wpdb->insert(FPD_CATEGORY_PRODUCTS_REL_TABLE, array('category_id' => $this->id, 'product_id' => $product_id), array('%d', '%d')); return $inserted ? $wpdb->insert_id : false; }
public static function create($title, $views) { global $wpdb, $charset_collate; //create templates table if necessary if (!fpd_table_exists(FPD_TEMPLATES_TABLE)) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; //create table $views_sql = "ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t title TEXT COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t views LONGTEXT COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t\t\t\t PRIMARY KEY (ID)"; $sql = "CREATE TABLE " . FPD_TEMPLATES_TABLE . " ({$views_sql}) {$charset_collate};"; dbDelta($sql); } $inserted = $wpdb->insert(FPD_TEMPLATES_TABLE, array('title' => $title, 'views' => $views), array('%s', '%s')); return $inserted; }
function fpd_has_content($post_id) { $source_type = get_post_meta($post_id, 'fpd_source_type', true); if (empty($source_type) || $source_type == 'category') { if (!fpd_table_exists(FPD_CATEGORIES_TABLE)) { return false; } } else { if (!fpd_table_exists(FPD_VIEWS_TABLE)) { return false; } } //get assigned categories $product_settings = new FPD_Product_Settings($post_id); $ids = $product_settings->get_content_ids(); //check if categories are not empty return empty($ids) ? false : $ids; }
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 deinstall() { global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM %s WHERE option_name LIKE 'fpd_%'", $wpdb->options)); $wpdb->query("SET FOREIGN_KEY_CHECKS=0;"); if (fpd_table_exists(FPD_CATEGORIES_TABLE)) { $wpdb->query("DROP TABLE " . FPD_CATEGORIES_TABLE . ""); } if (fpd_table_exists(FPD_PRODUCTS_TABLE)) { $wpdb->query("DROP TABLE " . FPD_PRODUCTS_TABLE . ""); } if (fpd_table_exists(FPD_CATEGORY_PRODUCTS_REL_TABLE)) { $wpdb->query("DROP TABLE " . FPD_CATEGORY_PRODUCTS_REL_TABLE . ""); } if (fpd_table_exists(FPD_VIEWS_TABLE)) { $wpdb->query("DROP TABLE " . FPD_VIEWS_TABLE . ""); } if (fpd_table_exists(FPD_TEMPLATES_TABLE)) { $wpdb->query("DROP TABLE " . FPD_TEMPLATES_TABLE . ""); } $wpdb->query("SET FOREIGN_KEY_CHECKS=1;"); }
public function new_view() { if (!isset($_POST['title']) || !isset($_POST['product_id'])) { die; } check_ajax_referer('fpd_ajax_nonce', '_ajax_nonce'); $title = trim($_POST['title']); $thumbnail = trim($_POST['thumbnail']); $product_id = trim($_POST['product_id']); $elements = isset($_POST['elements']) ? trim($_POST['elements']) : false; $add_to_library = isset($_POST['add_images_to_library']) ? (bool) intval($_POST['add_images_to_library']) : false; global $wpdb, $charset_collate; //create views table if necessary if (!fpd_table_exists(FPD_VIEWS_TABLE)) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; //create table $views_sql = "ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t\t product_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t title TEXT COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t thumbnail TEXT COLLATE utf8_general_ci NOT NULL,\n\t\t\t\t elements LONGTEXT COLLATE utf8_general_ci NULL,\n\t\t\t\t view_order INT COLLATE utf8_general_ci NULL,\n\t\t\t\t options TEXT COLLATE utf8_general_ci NULL,\n\t\t\t\t\t\t\t PRIMARY KEY (ID)"; $sql = "CREATE TABLE " . FPD_VIEWS_TABLE . " ({$views_sql}) {$charset_collate};"; dbDelta($sql); } //check if thumbnail is base64 encoded, if yes, create and upload image to wordpress media library if (base64_encode(base64_decode($thumbnail, true)) === $thumbnail) { $thumbnail = fpd_admin_upload_image_to_wp($_POST['thumbnail_name'], $thumbnail, $add_to_library); } //check if elements are posted if ($elements !== false) { $elements = json_decode(stripslashes($elements), true); //loop through all elements for ($i = 0; $i < sizeof($elements); $i++) { $element = $elements[$i]; if ($element['type'] == 'image') { //get parts of source string $image_parts = explode(',', $element['source']); $type = @$image_parts[0]; //type of image $base64_image = @$image_parts[1]; //the base 64 encoded image string //check if string is base64 encoded if (!is_null($base64_image) && base64_encode(base64_decode($base64_image, true)) === $base64_image) { if (isset($type)) { if (strpos($type, 'png') !== false) { $type = 'png'; } else { $type = 'jpeg'; } } $elements[$i]['source'] = fpd_admin_upload_image_to_wp($element['title'] . '.' . $type, $base64_image, $add_to_library); } } } //serialize for database $elements = serialize($elements); } //add view to fancy product $fp = new Fancy_Product($product_id); $view_id = $fp->add_view($title, $elements, $thumbnail); //send answer header('Content-Type: application/json'); if ($view_id) { echo json_encode(array('html' => FPD_Admin_Manage_Fancy_Products::get_view_item_html($view_id, $thumbnail, $title, ''))); } else { echo json_encode(0); } die; }
public function get_views() { global $wpdb; $views = array(); if (fpd_table_exists(FPD_VIEWS_TABLE)) { $views = $wpdb->get_results("SELECT * FROM " . FPD_VIEWS_TABLE . " WHERE product_id=" . $this->id . " ORDER BY view_order ASC"); //updates the image sources to the current domain and protocol foreach ($views as $view_key => $view) { //update thumbnail source $view->thumbnail = $this->reset_image_source($view->thumbnail); $elements = @unserialize($view->elements); if (is_array($elements)) { foreach ($elements as $key => $element) { if ($element['type'] == 'image') { $updated_image = $this->reset_image_source($element['source']); $element['source'] = $updated_image; } $elements[$key] = $element; } } $view->elements = serialize($elements); } } return $views; }
} } ?> </select> </p> <p class="form-field fpd-products"> <label><strong><?php _e('Fancy Products', 'radykal'); ?> </strong></label> <select multiple="multiple" data-placeholder="<?php _e('Select one ore more!', 'radykal'); ?> " name="fpd_products[]" class="radykal-select2" style="width: 100%;"> <?php if (fpd_table_exists(FPD_PRODUCTS_TABLE)) { $products = $wpdb->get_results("SELECT * FROM " . FPD_PRODUCTS_TABLE . " ORDER BY ID ASC"); foreach ($products as $fpd_product) { $selected = @in_array($fpd_product->ID, $selected_products) ? 'selected="selected"' : ''; echo '<option value="' . $fpd_product->ID . '" ' . $selected . '>' . $fpd_product->title . '</option>'; } } ?> </select> </p> </p> </div> </div> <script type="text/javascript">
<div class="fpd-modal-wrapper" id="fpd-modal-load-template"> <div class="fpd-modal-dialog"> <a href="#" class="fpd-close-modal">×</a> <h3><?php _e('Load a template', 'radykal'); ?> </h3> <div class="fpd-modal-content"> <?php $no_templates_info = '<p>' . __('No templates created. You can create a template via the action bar in a product list item.', 'radykal') . '</p>'; if (fpd_table_exists(FPD_TEMPLATES_TABLE)) { $templates = $wpdb->get_results("SELECT * FROM " . FPD_TEMPLATES_TABLE . " ORDER BY title ASC"); if (sizeof($templates) == 0) { echo $no_templates_info; } echo '<ul>'; foreach ($templates as $template) { // double quotes required echo FPD_Admin_Manage_Fancy_Products::get_template_link_html($template->ID, $template->title); } echo '</ul>'; } else { echo $no_templates_info; } ?> </ul> </div> </div> </div>