├── assets ├── icon-128x128.png ├── icon-256x256.png ├── screenshot-1.jpg ├── screenshot-2.jpg ├── screenshot-3.jpg ├── screenshot-4.jpg ├── screenshot-5.jpg ├── screenshot-6.jpg ├── banner-1544x500.jpg └── banner-772x250.jpg ├── images ├── product_thumbnail.png └── document.svg ├── templates ├── order_failed.php ├── order_success.php ├── send_form_email_body.php ├── payment_paypal.php ├── order_email_body.php ├── order_form.php └── order_pdf.php ├── js ├── woo_product_composite.js ├── admin-media.js ├── woo_product.js ├── admin-upload.js └── order.js ├── download_file.php ├── elementor_widget.php ├── payment.php ├── css ├── main.css └── admin.css ├── utils.php ├── send_form.php ├── file_storage.php ├── readme.txt ├── woo_product.php ├── product.php ├── currencies.php ├── LICENSE └── app.php /assets/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/icon-128x128.png -------------------------------------------------------------------------------- /assets/icon-256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/icon-256x256.png -------------------------------------------------------------------------------- /assets/screenshot-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/screenshot-1.jpg -------------------------------------------------------------------------------- /assets/screenshot-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/screenshot-2.jpg -------------------------------------------------------------------------------- /assets/screenshot-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/screenshot-3.jpg -------------------------------------------------------------------------------- /assets/screenshot-4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/screenshot-4.jpg -------------------------------------------------------------------------------- /assets/screenshot-5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/screenshot-5.jpg -------------------------------------------------------------------------------- /assets/screenshot-6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/screenshot-6.jpg -------------------------------------------------------------------------------- /assets/banner-1544x500.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/banner-1544x500.jpg -------------------------------------------------------------------------------- /assets/banner-772x250.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/assets/banner-772x250.jpg -------------------------------------------------------------------------------- /images/product_thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Soft8Soft/verge3d-wordpress-plugin/HEAD/images/product_thumbnail.png -------------------------------------------------------------------------------- /templates/order_failed.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /templates/order_success.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /js/woo_product_composite.js: -------------------------------------------------------------------------------- 1 | (function ($, window, document, undefined) { 2 | $('.composite_data').on('wc-composite-initializing', function(event, composite) { 3 | composite.actions.add_action('component_selection_changed', function(c) { 4 | if (window.v3d_on_product_update) 5 | window.v3d_on_product_update(); 6 | }, 100); 7 | 8 | composite.actions.add_action('component_quantity_changed', function(c) { 9 | if (window.v3d_on_product_update) 10 | window.v3d_on_product_update(); 11 | }, 100); 12 | 13 | window.v3d_woo_composite = composite; 14 | 15 | }); 16 | })(jQuery, window, document); 17 | -------------------------------------------------------------------------------- /templates/send_form_email_body.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | 18 |

Here is what the form contains:

19 | 20 | 21 | $value): ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /download_file.php: -------------------------------------------------------------------------------- 1 | start_controls_section( 26 | 'section_title', 27 | [ 28 | 'label' => 'Application', 29 | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, 30 | ] 31 | ); 32 | 33 | global $post; 34 | 35 | $app_posts = get_posts(array( 36 | 'posts_per_page' => -1, 37 | 'post_type' => 'v3d_app', 38 | 'post_status' => 'publish', 39 | )); 40 | 41 | $app_options[''] = __('None (select a value)', 'verge3d'); 42 | 43 | foreach ($app_posts as $app_post) 44 | $app_options[$app_post->ID] = $app_post->post_title; 45 | 46 | $this->add_control( 47 | 'v3d_app_id', 48 | array( 49 | 'label' => esc_html__('Application', 'verge3d'), 50 | 'type' => \Elementor\Controls_Manager::SELECT, 51 | 'default' => '', 52 | 'options' => $app_options, 53 | ) 54 | ); 55 | 56 | $this->end_controls_section(); 57 | } 58 | 59 | protected function render() { 60 | $app_posts = get_posts(array( 61 | 'posts_per_page' => -1, 62 | 'post_type' => 'v3d_app', 63 | 'post_status' => 'publish', 64 | )); 65 | 66 | if (!empty($app_posts)) { 67 | $settings = $this->get_settings_for_display(); 68 | $app_id = $settings['v3d_app_id']; 69 | if (!empty($app_id) && !empty(get_post($app_id))) { 70 | echo v3d_gen_app_iframe_html($app_id); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /js/admin-media.js: -------------------------------------------------------------------------------- 1 | jQuery(document).ready(function($) { 2 | let image_frame; 3 | const imgContainer = $('#image_preview_wrapper'); 4 | const addImgLink = $('#upload_image_button'); 5 | const delImgLink = $('#clear_image_button'); 6 | const imgIdInput = $('#image_attachment_id'); 7 | 8 | addImgLink.on('click', function(event) { 9 | 10 | event.preventDefault(); 11 | 12 | // If the media image_frame already exists, reopen it. 13 | if (image_frame) { 14 | image_frame.open(); 15 | return; 16 | } 17 | 18 | // Create a new media frame 19 | image_frame = wp.media({ 20 | title: 'Select or Upload Media Of Your Chosen Persuasion', 21 | button: { 22 | text: 'Use this media' 23 | }, 24 | multiple: false // Set to true to allow multiple files to be selected 25 | }); 26 | 27 | // When an image is selected in the media frame... 28 | image_frame.on('select', function() { 29 | // Get media attachment details from the frame state 30 | const attachment = image_frame.state().get('selection').first().toJSON(); 31 | 32 | // Send the attachment URL to our custom image input field. 33 | imgContainer.html(''); 34 | imgContainer.append(''); 35 | 36 | // Send the attachment id to our hidden input 37 | imgIdInput.val(attachment.id); 38 | 39 | // Hide the add image link 40 | addImgLink.addClass('hidden'); 41 | 42 | // Unhide the remove image link 43 | delImgLink.removeClass('hidden'); 44 | }); 45 | 46 | // Finally, open the modal on click 47 | image_frame.open(); 48 | 49 | }); 50 | 51 | delImgLink.on('click', function(event) { 52 | 53 | event.preventDefault(); 54 | 55 | // Clear out the preview image 56 | imgContainer.html(''); 57 | 58 | // Un-hide the add image link 59 | addImgLink.removeClass('hidden'); 60 | 61 | // Hide the delete image link 62 | delImgLink.addClass('hidden'); 63 | 64 | // Delete the image id from the hidden input 65 | imgIdInput.val(''); 66 | 67 | }); 68 | 69 | }); 70 | -------------------------------------------------------------------------------- /payment.php: -------------------------------------------------------------------------------- 1 | 'PayPal', 69 | 'date' => time() 70 | ); 71 | v3d_update_order($order_id, $order, false); 72 | v3d_send_emails('new', $order, $order_id); 73 | 74 | ob_start(); 75 | include v3d_get_template('order_success.php'); 76 | wp_die(ob_get_clean()); 77 | } else { 78 | $order['status'] = 'failed'; 79 | v3d_update_order($order_id, $order, false); 80 | 81 | ob_start(); 82 | include v3d_get_template('order_failed.php'); 83 | wp_die(ob_get_clean()); 84 | } 85 | } 86 | add_action('wp_ajax_v3d_payment_done', 'v3d_payment_done'); 87 | add_action('wp_ajax_nopriv_v3d_payment_done', 'v3d_payment_done'); 88 | -------------------------------------------------------------------------------- /css/main.css: -------------------------------------------------------------------------------- 1 | .v3d-iframe { 2 | border-width: 0px; 3 | max-width: 100%; 4 | } 5 | 6 | .v3d-order-form input { 7 | width: 100%; 8 | } 9 | 10 | .v3d-order-form img { 11 | max-width: 100px; 12 | max-height: 50px; 13 | } 14 | 15 | .v3d-order-email img, 16 | .v3d-order-pdf img { 17 | display: block; 18 | } 19 | 20 | .v3d-order-email th, .v3d-order-email td { 21 | padding: 2px; 22 | } 23 | 24 | .v3d-order-email th { 25 | width: 30mm; 26 | text-align: left; 27 | } 28 | 29 | .v3d-asterix { 30 | color: red; 31 | } 32 | 33 | .v3d-order-email textarea { 34 | min-width: 200px; 35 | min-height: 100px; 36 | resize: none; 37 | } 38 | 39 | .v3d-order-email .form-field input { 40 | width: 100%; 41 | } 42 | 43 | .v3d-order-email .button { 44 | display: block; 45 | margin: auto; 46 | } 47 | 48 | .v3d-user-info-table { 49 | display: inline-block; 50 | vertical-align: top; 51 | } 52 | 53 | .v3d-order-pdf .v3d-user-info-table:nth-of-type(2) { 54 | margin-left: 20mm; 55 | } 56 | 57 | .v3d-order-pdf .v3d-additonal-info { 58 | margin: 2mm 0; 59 | } 60 | 61 | .v3d-user-info-table th { 62 | text-align: left; 63 | } 64 | 65 | .v3d-order-email .v3d-user-info-table td { 66 | padding: 5px; 67 | } 68 | 69 | table.v3d-order-items-table, .v3d-order-items-table th, .v3d-order-items-table td, 70 | table.v3d-order-downloads-table, .v3d-order-downloads-table th, .v3d-order-downloads-table td { 71 | border: 1px solid; 72 | border-collapse: collapse; 73 | padding: 10px; 74 | } 75 | 76 | .v3d-order-downloads-table th, .v3d-order-downloads-table td { 77 | min-width: 300px; 78 | } 79 | 80 | tr.v3d-bold-border-total { 81 | border-top-width: 2px; 82 | border-top-style: solid; 83 | } 84 | 85 | .item-title { 86 | min-width: 300px; 87 | } 88 | 89 | .v3d-order-email .has-text-align-left, 90 | .v3d-order-pdf .has-text-align-left { 91 | text-align: left; 92 | } 93 | 94 | .v3d-order-email .has-text-align-center, 95 | .v3d-order-pdf .has-text-align-center { 96 | text-align: center; 97 | } 98 | 99 | .v3d-order-email .has-text-align-right, 100 | .v3d-order-pdf .has-text-align-right { 101 | text-align: right; 102 | } 103 | 104 | .v3d-order-pdf { 105 | max-width: 215mm; 106 | } 107 | 108 | .v3d-order-pdf h1 { 109 | display: inline-block; 110 | } 111 | 112 | .v3d-order-pdf h1:nth-of-type(1) { 113 | margin-left: 30mm; 114 | } 115 | 116 | .v3d-order-pdf h1:nth-of-type(2) { 117 | float: right; 118 | margin-right: 30mm; 119 | font-weight: lighter; 120 | } 121 | 122 | .v3d-order-pdf table.v3d-order-items-table { 123 | width: 100% 124 | } 125 | 126 | a.v3d-product-gallery-empty-a { 127 | line-height: 0px; 128 | display: block; 129 | } 130 | -------------------------------------------------------------------------------- /css/admin.css: -------------------------------------------------------------------------------- 1 | .v3d-hint { 2 | border: 1px solid #e5e5e5; 3 | box-shadow: 0 1px 1px rgba(0,0,0,.04); 4 | background: #fff; 5 | padding: .1em 1.5em; 6 | margin-top: 10px; 7 | } 8 | 9 | .v3d-admin-attachments { 10 | max-width: 100px; 11 | max-height: 50px; 12 | } 13 | 14 | td.v3d-admin-order-items-row { 15 | padding-top: 0px; 16 | padding-bottom: 0px; 17 | } 18 | 19 | div.v3d-admin-order-items { 20 | width: 95%; 21 | } 22 | 23 | .v3d-upload-progress { 24 | margin: 20px; 25 | } 26 | 27 | .v3d-red { 28 | color: red; 29 | } 30 | 31 | .v3d-green { 32 | color: green; 33 | } 34 | 35 | .dialog-bg { 36 | display: none; 37 | position: fixed; 38 | align-items: center; 39 | justify-content: center; 40 | z-index: 1000; 41 | left: 0; 42 | top: 0; 43 | width: 100%; 44 | height: 100%; 45 | overflow: hidden; 46 | background-color: rgba(0,0,0,0.4); 47 | } 48 | 49 | .dialog { 50 | background-color: #f2f2f2; 51 | font-size: 14px; 52 | padding: 5px; 53 | max-width: 800px; 54 | max-height: 600px; 55 | overflow: hidden; 56 | filter: drop-shadow(0px 0px 6px #00000034); 57 | } 58 | 59 | .dialog-email-sent { 60 | padding: 15px; 61 | } 62 | 63 | .dialog-email-sent button.button { 64 | display: block; 65 | margin: 0px auto; 66 | padding: 0px 25px; 67 | } 68 | 69 | .dialog-heading { 70 | line-height: 1.3; 71 | text-align: center; 72 | padding: 10px; 73 | font-weight: 600; 74 | } 75 | 76 | .dialog-item { 77 | line-height: 1.3; 78 | text-align: left; 79 | } 80 | 81 | .dialog-item th { 82 | padding: 10px; 83 | font-weight: 600; 84 | } 85 | 86 | .dialog-buttons { 87 | margin: 0px auto; 88 | padding: 10px; 89 | } 90 | 91 | .v3d-wide-input { 92 | min-width: 300px; 93 | } 94 | 95 | .v3d-half-width { 96 | width: 49%; 97 | } 98 | 99 | .v3d-full-width { 100 | width: 100%; 101 | } 102 | 103 | table.v3d-side-panel-table th { 104 | padding: 5px; 105 | } 106 | 107 | table.v3d-side-panel-table td { 108 | padding: 5px; 109 | } 110 | 111 | a.v3d-side-panel-button { 112 | text-align: center; 113 | } 114 | 115 | fieldset.v3d-one-line-checkers label { 116 | padding-right: 20px; 117 | } 118 | 119 | textarea.v3d-wide-textarea { 120 | min-width: 50%; 121 | height: 75px; 122 | vertical-align: top; 123 | } 124 | 125 | textarea.v3d-tall-textarea { 126 | height: 300px; 127 | } 128 | 129 | p.error { 130 | color: red; 131 | } 132 | 133 | table.order_items th { 134 | padding: 10px; 135 | } 136 | 137 | table.order_items td { 138 | padding: 10px 8px; 139 | } 140 | 141 | table.order_items td.check-column { 142 | padding: 0px; 143 | } 144 | 145 | .form-field input[type="number"] { 146 | max-width: 100px; 147 | } 148 | 149 | -------------------------------------------------------------------------------- /templates/payment_paypal.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 24 | 25 |
Please proceed with the preferred payment option:
26 | 27 |
28 | 29 | 30 | 31 | 80 | -------------------------------------------------------------------------------- /utils.php: -------------------------------------------------------------------------------- 1 | substr($data_url, $mime_start, $mime_length), 57 | 'data' => base64_decode(substr($data_url, strpos($data_url, ',') + 1)) 58 | ); 59 | } else { 60 | return null; 61 | } 62 | } 63 | 64 | /** 65 | * WordPress MIMEs + Verge3D MIMEs 66 | */ 67 | function v3d_get_allowed_mime_types() { 68 | $allowed_mimes = get_allowed_mime_types(); 69 | 70 | $v3d_mimes = get_option('v3d_upload_mime_types'); 71 | if (!empty($v3d_mimes)) { 72 | foreach (explode(PHP_EOL, $v3d_mimes) as $line) { 73 | $line = wp_strip_all_tags($line); 74 | $line_split = preg_split('/ +/', $line, null, PREG_SPLIT_NO_EMPTY); 75 | 76 | if (count($line_split) != 2) 77 | continue; 78 | 79 | $mime = trim($line_split[0]); 80 | $ext = trim($line_split[1]); 81 | 82 | if (!empty($mime) && !empty($ext)) 83 | $allowed_mimes[$ext] = $mime; 84 | } 85 | } 86 | 87 | return $allowed_mimes; 88 | } 89 | 90 | function v3d_check_mime($mime) { 91 | $allowed_mimes = v3d_get_allowed_mime_types(); 92 | return in_array(strtolower($mime), array_map('strtolower', $allowed_mimes)); 93 | } 94 | 95 | function v3d_inline_image($path) { 96 | $type = pathinfo($path, PATHINFO_EXTENSION); 97 | $data = file_get_contents($path); 98 | return v3d_create_data_url('image/'. $type, $data); 99 | } 100 | 101 | if (DEBUG_WP_MAIL) { 102 | function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) { 103 | $mail_dir = v3d_get_upload_dir() . 'mail-debug/'; 104 | if (is_dir($mail_dir)) 105 | v3d_rmdir($mail_dir, false); 106 | else 107 | mkdir($mail_dir, 0777, true); 108 | 109 | file_put_contents($mail_dir . 'message.html', $message); 110 | 111 | $info = sprintf("To: %s\nSubject: %s\n", $to, $subject); 112 | if ($headers) 113 | foreach ($headers as $h) 114 | $info = sprintf("%s%s\n", $info, $h); 115 | file_put_contents($mail_dir . 'info.txt', $info); 116 | 117 | foreach ($attachments as $a) 118 | copy($a, $mail_dir . basename($a)); 119 | return true; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /js/woo_product.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | var v3d_woo_product_info_cb = null; 4 | 5 | function v3d_woo_form_get_quantity(formData) { 6 | var qtyElems = document.body.querySelectorAll('input.qty'); 7 | 8 | if (qtyElems.length == 0) { 9 | formData.append('quantity', 1); 10 | } else { 11 | for (var i = 0; i < qtyElems.length; i++) { 12 | var qtyElem = qtyElems[i]; 13 | formData.append(qtyElem.name, qtyElem.value); 14 | } 15 | } 16 | } 17 | 18 | function v3d_woo_form_get_product_id(formData) { 19 | var varIdElem = document.body.querySelector('input[name=add-to-cart]') || document.body.querySelector('button[name=add-to-cart]'); 20 | if (!varIdElem) 21 | console.error('Verge3D: Product ID not found!'); 22 | formData.append('product_id', varIdElem ? varIdElem.value : -1); 23 | } 24 | 25 | function v3d_woo_form_get_variation_id(formData) { 26 | var varIdElem = document.body.querySelector('input[name=variation_id]'); 27 | formData.append('variation_id', varIdElem ? varIdElem.value : -1); 28 | } 29 | 30 | function v3d_woo_form_get_attributes(formData) { 31 | var attElems = document.body.querySelectorAll('table.variations select'); 32 | for (var i = 0; i < attElems.length; i++) { 33 | var attElem = attElems[i]; 34 | formData.append(attElem.name, attElem.value); 35 | } 36 | } 37 | 38 | /** 39 | * Get components of the composite product 40 | */ 41 | function v3d_woo_form_get_components(formData) { 42 | if (window.v3d_woo_composite) { 43 | const components = window.v3d_woo_composite.api.get_composite_configuration(); 44 | for (const id in components) { 45 | const component = components[id]; 46 | for (const key in component) { 47 | if (key == 'selection_meta') 48 | for (let i = 0; i < component[key].length; i++) { 49 | const meta_key = component[key][i].meta_key.toLowerCase(); 50 | const meta_value = component[key][i].meta_value; 51 | formData.append(`components[${id}][attributes][${meta_key}]`, meta_value); 52 | } 53 | else 54 | formData.append(`components[${id}][${key}]`, component[key]); 55 | } 56 | } 57 | } 58 | } 59 | 60 | function v3d_woo_get_product_info(callback) { 61 | v3d_woo_product_info_cb = callback; 62 | v3d_woo_request_product_info(); 63 | } 64 | window.v3d_woo_get_product_info = v3d_woo_get_product_info; 65 | 66 | 67 | function v3d_woo_request_product_info() { 68 | var formData = new FormData(); 69 | formData.append('action', 'v3d_woo_get_product_info'); 70 | v3d_woo_form_get_quantity(formData); 71 | v3d_woo_form_get_product_id(formData); 72 | v3d_woo_form_get_variation_id(formData); 73 | v3d_woo_form_get_attributes(formData); 74 | v3d_woo_form_get_components(formData); 75 | 76 | var req = new XMLHttpRequest(); 77 | // registered in php via v3d_load_woo_scripts 78 | req.open('POST', v3d_ajax_object.ajax_url); 79 | req.send(formData); 80 | req.addEventListener('load', function() { 81 | var response = JSON.parse(req.response); 82 | 83 | if (v3d_woo_product_info_cb) 84 | v3d_woo_product_info_cb(response); 85 | }); 86 | } 87 | 88 | function v3d_on_product_update() { 89 | if (v3d_ajax_object.switch_on_update) { 90 | const cover_div = document.querySelector('div[data-thumb-v3d-app-cover-src]'); 91 | if (cover_div) { 92 | const cover_src = cover_div.dataset.thumbV3dAppCoverSrc; 93 | if (cover_src) { 94 | const thumb = document.querySelector(`li img[src="${cover_src}"]`); 95 | // HACK: switch twice 96 | if (thumb) { 97 | thumb.click(); 98 | setTimeout(e => thumb.click(), 30); 99 | } 100 | } 101 | } 102 | } 103 | v3d_woo_request_product_info(); 104 | } 105 | window.v3d_on_product_update = v3d_on_product_update; 106 | 107 | window.addEventListener('load', function() { 108 | 109 | var qtyElems = document.body.querySelectorAll('input.qty'); 110 | for (var i = 0; i < qtyElems.length; i++) 111 | qtyElems[i].onchange = v3d_on_product_update; 112 | 113 | var varFormElem = document.body.querySelector('.variations_form'); 114 | if (varFormElem) 115 | varFormElem.woocommerce_variation_has_changed = v3d_on_product_update; 116 | 117 | }); 118 | 119 | 120 | })(); 121 | -------------------------------------------------------------------------------- /js/admin-upload.js: -------------------------------------------------------------------------------- 1 | 2 | const V3D_IGNORE_EXT = [ 3 | 'blend', 4 | 'blend1', 5 | 'max', 6 | 'ma', // maya 7 | 'mb', // maya 8 | 'mat', // max material file 9 | 'mel' // e.g workspace.mel 10 | ]; 11 | 12 | const CHUNK_SIZE = 1000000; // 1MB 13 | 14 | const ERROR_CONN = 'Upload failed 🤔 Please check your connection.'; 15 | const ERROR_CONN_MIME = ERROR_CONN +' Also ensure that MIME types for app files are whitelisted in Verge3D > Settings > Security.'; 16 | 17 | async function v3d_handle_uploads(app_id) { 18 | 19 | const url = v3d_ajax_object.ajax_url; 20 | const security = v3d_ajax_object.security; 21 | 22 | try { 23 | const formData = new FormData(); 24 | formData.append('action', 'v3d_cleanup_app'); 25 | formData.append('security', security); 26 | formData.append('app', app_id); 27 | const res = await (await fetch(url, { method: 'POST', body: formData })).text(); 28 | if (res != 'ok') { 29 | alert(ERROR_CONN); 30 | return; 31 | } 32 | } catch { 33 | alert(ERROR_CONN); 34 | return; 35 | } 36 | 37 | const input = document.getElementById('appfiles'); 38 | const progressElem = document.getElementById('upload_progress'); 39 | const statusElem = document.getElementById('upload_status'); 40 | let progressCounter = 0; 41 | let errorState = false; 42 | 43 | function updateProgress() { 44 | progressCounter++; 45 | progressElem.innerText = progressCounter + '/' + input.files.length; 46 | 47 | if (progressCounter == input.files.length) { 48 | 49 | if (errorState) { 50 | statusElem.className = 'v3d-red'; 51 | statusElem.innerText = 'Error!'; 52 | alert(ERROR_CONN_MIME); 53 | } else { 54 | statusElem.className = 'v3d-green'; 55 | statusElem.innerText = 'Success!'; 56 | } 57 | 58 | } else { 59 | statusElem.innerText = ''; 60 | } 61 | } 62 | 63 | for (let i = 0; i < input.files.length; i++) { 64 | const file = input.files[i]; 65 | const name = file.name; 66 | const path = file.webkitRelativePath; 67 | const ext = path.split('.').pop(); 68 | 69 | // prevent upload of some files (such as .DS_Store) 70 | if (V3D_IGNORE_EXT.includes(ext) || path.includes('v3d_app_data') || name.startsWith('.')) { 71 | updateProgress(); 72 | continue; 73 | } 74 | 75 | console.log('Uploading ' + path); 76 | 77 | if (file.size < CHUNK_SIZE) { 78 | const formData = new FormData(); 79 | formData.append('action', 'v3d_upload_app_file'); 80 | formData.append('security', security); 81 | formData.append('app', app_id); 82 | formData.append('apppath', path); 83 | formData.append('appfile', file); 84 | 85 | fetch(url, { method: 'POST', body: formData }).then(response => { 86 | updateProgress(); 87 | 88 | response.text().then(text => { 89 | if (text != 'ok') 90 | errorState = true; 91 | }); 92 | 93 | }).catch(error => { 94 | errorState = true; 95 | }); 96 | 97 | } else { 98 | let start = 0; 99 | let end = CHUNK_SIZE; 100 | let chunks = []; 101 | 102 | while (start < file.size) { 103 | let chunk = file.slice(start, end); 104 | chunks.push(chunk); 105 | start = end; 106 | end = start + CHUNK_SIZE; 107 | } 108 | 109 | chunks.forEach((chunk, index) => { 110 | let formData = new FormData(); 111 | formData.append('action', 'v3d_upload_app_file'); 112 | formData.append('security', security); 113 | formData.append('app', app_id); 114 | formData.append('apppath', path); 115 | formData.append('appfile', chunk); 116 | formData.append('chunk', index); 117 | formData.append('maxchunks', chunks.length); 118 | 119 | fetch(url, { method: 'POST', body: formData }).then(response => { 120 | if (index == chunks.length - 1) 121 | updateProgress(); 122 | 123 | response.text().then(text => { 124 | if (text != 'ok') 125 | errorState = true; 126 | }); 127 | 128 | }).catch(error => { 129 | errorState = true; 130 | }); 131 | }); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /send_form.php: -------------------------------------------------------------------------------- 1 | $value) { 9 | if (is_array($value)) 10 | $value = v3d_sanitize_form_fields($value); 11 | else 12 | $value = sanitize_textarea_field($value); 13 | 14 | $array_out[sanitize_textarea_field($key)] = $value; 15 | } 16 | 17 | return $array_out; 18 | } 19 | 20 | function v3d_api_send_form(WP_REST_Request $request) { 21 | $response = new WP_REST_Response( 22 | array( 23 | 'status' => 'ok', 24 | 'statusText' => 'Email sent' 25 | ) 26 | ); 27 | $error_msg = ''; 28 | 29 | $form_fields = v3d_sanitize_form_fields($request->get_body_params()); 30 | 31 | if (!empty($form_fields)) { 32 | $to = get_option('v3d_order_email'); 33 | $order_from_name = get_option('v3d_order_email_from_name'); 34 | $order_from_email = get_option('v3d_order_email_from_email'); 35 | 36 | $headers[] = 'Content-Type: text/html; charset=UTF-8'; 37 | if (!empty($order_from_name) || !empty($order_from_email)) { 38 | $headers[] = 'From: "'.$order_from_name.'" <'.$order_from_email.'>'; 39 | } 40 | 41 | $subject = get_option('v3d_send_form_email_subject'); 42 | 43 | ob_start(); 44 | include v3d_get_template('send_form_email_body.php'); 45 | $message = ob_get_clean(); 46 | 47 | $attachments = array(); 48 | 49 | if (get_option('v3d_send_form_email_attachments')) { 50 | foreach ($request->get_file_params() as $key => $file) { 51 | if ($error_msg !== '') 52 | break; 53 | 54 | if (is_array($file['name'])) { 55 | $names = $file['name']; 56 | $tmp_names = $file['tmp_name']; 57 | $errors = $file['error']; 58 | } else { 59 | $names = [$file['name']]; 60 | $tmp_names = [$file['tmp_name']]; 61 | $errors = [$file['error']]; 62 | } 63 | 64 | for ($i = 0; $i < count($names); $i++) { 65 | if ($errors[$i] !== UPLOAD_ERR_OK) { 66 | $error_msg = 'File upload error'; 67 | break; 68 | } 69 | 70 | $name = sanitize_file_name($names[$i]); 71 | $att_path_tmp = v3d_get_attachments_tmp_dir($attachments).$name; 72 | 73 | if (!move_uploaded_file($tmp_names[$i], $att_path_tmp)) { 74 | $error_msg = 'File upload error'; 75 | break; 76 | } 77 | 78 | $validate = wp_check_filetype($att_path_tmp, v3d_get_allowed_mime_types()); 79 | if ($validate['type'] === false) { 80 | $error_msg = 'Forbidden MIME type for '.$name; 81 | break; 82 | } 83 | 84 | $attachments[] = $att_path_tmp; 85 | } 86 | } 87 | } 88 | } else { 89 | $error_msg = 'Form is empty'; 90 | } 91 | 92 | if ($error_msg === '') { 93 | $to = apply_filters('v3d_send_form_to', $to, $form_fields); 94 | $subject = apply_filters('v3d_send_form_subject', $subject, $form_fields); 95 | $message = apply_filters('v3d_send_form_message', $message, $form_fields); 96 | $headers = apply_filters('v3d_send_form_headers', $headers, $form_fields); 97 | $attachments = apply_filters('v3d_send_form_attachments', $attachments, $form_fields); 98 | 99 | if (!wp_mail($to, $subject, $message, $headers, $attachments)) { 100 | $error_msg = 'Unable to send email'; 101 | } 102 | } 103 | 104 | if ($error_msg !== '') { 105 | $response->set_data(array( 106 | 'status' => 'error', 107 | 'statusText' => $error_msg 108 | )); 109 | $response->set_status(400); 110 | } 111 | 112 | foreach ($attachments as $a) { 113 | @unlink($a); 114 | } 115 | 116 | rmdir(v3d_get_attachments_tmp_dir($attachments)); 117 | 118 | if (get_option('v3d_cross_domain')) 119 | $response->header('Access-Control-Allow-Origin', '*'); 120 | 121 | return $response; 122 | } 123 | 124 | add_action('rest_api_init', function() { 125 | if (get_option('v3d_send_form_api')) { 126 | register_rest_route('verge3d/v1', '/send_form', array( 127 | 'methods' => 'POST', 128 | 'callback' => 'v3d_api_send_form', 129 | 'permission_callback' => '__return_true' 130 | )); 131 | } 132 | }); 133 | -------------------------------------------------------------------------------- /file_storage.php: -------------------------------------------------------------------------------- 1 | get_body(); 12 | 13 | if (!empty($data)) { 14 | $upload_dir = v3d_get_upload_dir() . FILES_SUBDIR; 15 | if (!is_dir($upload_dir)) { 16 | mkdir($upload_dir, 0777, true); 17 | } 18 | 19 | $id = v3d_unique_filename(); 20 | $filename = $upload_dir.$id; 21 | $mime = $request->get_content_type()['value']; 22 | 23 | if (v3d_check_mime($mime)) { 24 | $success = file_put_contents($filename, v3d_create_data_url($mime, $data)); 25 | if ($success) 26 | $response->set_data(array( 27 | 'status' => 'ok', 28 | 'statusText' => 'Yay! File uploaded successfully.', 29 | 'id' => $id, 30 | 'link' => rest_url('verge3d/v1/get_file/'.$id), 31 | 'size' => strlen($data) 32 | )); 33 | else 34 | $error_msg = 'Oh no! Could not save file on the server.'; 35 | } else 36 | $error_msg = 'Upload error, MIME type is not allowed: ' . $mime; 37 | 38 | } else { 39 | $error_msg = 'Upload error, file is empty'; 40 | } 41 | 42 | if ($error_msg !== '') { 43 | $response->set_data(array( 44 | 'status' => 'error', 45 | 'statusText' => $error_msg 46 | )); 47 | $response->set_status(400); 48 | } 49 | 50 | if (get_option('v3d_cross_domain')) 51 | $response->header('Access-Control-Allow-Origin', '*'); 52 | 53 | return $response; 54 | } 55 | 56 | function v3d_api_get_file(WP_REST_Request $request) { 57 | 58 | $response = new WP_REST_Response(); 59 | $error_msg = ''; 60 | 61 | $id = $request->get_param('id'); 62 | 63 | if (!empty($id)) { 64 | $upload_dir = v3d_get_upload_dir() . FILES_SUBDIR; 65 | 66 | $file = $upload_dir.$id; 67 | 68 | // COMPAT: < 4.7 69 | $compat_json_storage = false; 70 | if (!is_file($file)) { 71 | $file = $file.'.json'; 72 | $compat_json_storage = true; 73 | } 74 | 75 | if (is_file($file)) { 76 | $data = file_get_contents($file); 77 | 78 | if (!$compat_json_storage) { 79 | $parsed = v3d_parse_data_url($data); 80 | $mime = $parsed['mime']; 81 | 82 | if (v3d_check_mime($mime)) { 83 | $response->header('Content-Type', $mime); 84 | $response->set_data($parsed['data']); 85 | } else 86 | $error_msg = 'MIME type is not allowed: ' . $mime; 87 | } else { 88 | // hack to prevent JSON decoding of base64-encoded strings 89 | $response->header('Content-Type', 'text/plain'); 90 | $response->set_data($data); 91 | } 92 | 93 | if ($error_msg === '') 94 | add_filter('rest_pre_serve_request', 'v3d_api_get_file_response', 20, 2); 95 | 96 | } else 97 | $error_msg = 'File not found'; 98 | 99 | } else { 100 | $error_msg = 'Bad request'; 101 | } 102 | 103 | if ($error_msg !== '') { 104 | $response->set_data(array( 105 | 'status' => 'error', 106 | 'statusText' => $error_msg 107 | )); 108 | $response->set_status(400); 109 | } 110 | 111 | if (get_option('v3d_cross_domain')) 112 | $response->header('Access-Control-Allow-Origin', '*'); 113 | 114 | return $response; 115 | } 116 | 117 | function v3d_api_get_file_response($served, $result) { 118 | $data = $result->get_data(); 119 | 120 | if (is_string($data)) { 121 | echo $data; 122 | return true; 123 | } 124 | 125 | return $served; 126 | } 127 | 128 | add_action('rest_api_init', function () { 129 | if (get_option('v3d_file_api')) { 130 | 131 | register_rest_route('verge3d/v1', '/upload_file', array( 132 | 'methods' => 'POST', 133 | 'callback' => 'v3d_api_upload_file', 134 | 'permission_callback' => '__return_true', 135 | )); 136 | 137 | register_rest_route('verge3d/v1', '/get_file/(?P\w+)', array( 138 | 'methods' => 'GET', 139 | 'callback' => 'v3d_api_get_file', 140 | 'args' => array( 141 | 'id' => array( 142 | 'validate_callback' => function($param, $request, $key) { 143 | // allow hex numbers 144 | return (trim($param, '0..9A..Fa..f') === ''); 145 | } 146 | ), 147 | ), 148 | 'permission_callback' => '__return_true', 149 | )); 150 | } 151 | }); 152 | -------------------------------------------------------------------------------- /templates/order_email_body.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 |

37 | 38 | 39 | 40 | 41 | 42 | 45 | 48 | 49 | 50 | 53 | 56 | 57 | 58 | 61 | 64 | 65 | 66 | 69 | 72 | 73 | 74 | 77 | 80 | 81 | 82 | 83 | 86 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 |
ItemPriceQuantityAmount
Subtotal
Discount
Tax
Total
139 | 140 | 141 |

Downloads

142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | $d) { 152 | ?> 153 | 154 | 155 | 156 | 157 | 160 |
ProductFile
161 | 162 | 163 | 164 |
165 | 166 | 167 | -------------------------------------------------------------------------------- /images/document.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 22 | 23 | 25 | image/svg+xml 26 | 28 | 29 | 30 | 31 | 32 | 52 | 54 | 56 | 59 | 63 | 64 | 66 | 68 | 72 | 73 | 75 | 77 | 82 | 83 | 89 | 92 | 93 | 95 | 98 | 99 | 107 | 116 | 124 | 126 | 129 | 134 | 139 | 144 | 145 | 147 | 150 | 155 | 156 | 157 | 163 | 167 | 174 | 178 | 182 | 183 | -------------------------------------------------------------------------------- /templates/order_form.php: -------------------------------------------------------------------------------- 1 | Order form is empty. Please check your Puzzles logic.

'; 6 | return; 7 | } 8 | ?> 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 48 | 53 | 54 | 55 | 56 | 57 |
ItemPriceQuantityAmount
Total
46 | 47 | 49 | 50 | 51 | 52 |
58 | 59 | 60 | 61 | 62 | 65 | 68 | 69 | 70 | 71 | 74 | 77 | 78 | 79 | 82 | 85 | 86 | 87 | 90 | 93 | 94 | 95 | 96 | 97 | 99 | 100 | 103 | 106 | 107 | 108 | 111 | 114 | 115 | 116 | 119 | 122 | 123 | 124 | 127 | 130 | 131 | 132 | 135 | 138 | 139 | 140 | 143 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 154 | 155 | 158 | 161 | 162 | 163 | 166 | 169 | 170 | 171 | 174 | 177 | 178 | 179 | 182 | 185 | 186 | 187 | 190 | 193 | 194 | 195 | 198 | 201 | 202 | 203 | 204 |
63 | 64 | 66 | 67 |
72 | 73 | 75 | 76 |
80 | 81 | 83 | 84 |
88 | 89 | 91 | 92 |
Billing address 98 |
101 | 102 | 104 | 105 |
109 | 110 | 112 | 113 |
117 | 118 | 120 | 121 |
125 | 126 | 128 | 129 |
133 | 134 | 136 | 137 |
141 | 142 | 144 | 145 |
Shipping address 153 |
156 | 157 | 159 | 160 |
164 | 165 | 167 | 168 |
172 | 173 | 175 | 176 |
180 | 181 | 183 | 184 |
188 | 189 | 191 | 192 |
196 | 197 | 199 | 200 |
205 | 206 |
207 | 208 |
209 |
210 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Verge3D Publishing and E-Commerce === 2 | Contributors: soft8soft 3 | Tags: verge3d,3d,webgl,3dweb,ecommerce 4 | Requires at least: 5.0 5 | Tested up to: 6.8.1 6 | Requires PHP: 7.0 7 | Stable tag: 4.10.0 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Verge3D application publising and e-commerce plugin for WordPress. 12 | 13 | == Description == 14 | 15 | Verge3D is the most artist-friendly toolkit for creating interactive WebGL-based and immersive AR/VR experiences. Among the features of this framework are top-class graphics, integration with your favorite modeling suites, efficient web-friendly format for loading assets, seamless integration with WordPress and WooCommerce plugin. Interactivity is enabled with Puzzles, an intuitive and easy-to-learn visual scripting environment. 16 | 17 | Verge3D can be used to create product configurators, 3D presentations, online stores, e-learning apps, 3D portfolios, browser games, and more. 18 | 19 | You can try this plugin live using this [sandbox website](https://sandbox.soft8soft.com/) or follow the quick-start guide [here](https://www.soft8soft.com/making-3d-product-configurator-for-woocommerce/). 20 | 21 | = Take 3D web for a spin = 22 | 23 | The high-tech WebGL technology becomes accessible with Verge3D. Your beautiful content will live on your WordPress website and thus will be available to billions of Internet users. 24 | 25 | Interactivity, true 360 view and zooming capabilities bring your creation to entirely new level of engagement. It will work everywhere, from a small smartphone to workstation and even a TV set. We designed and assembled all tools you need in one place and called it Verge3D! 26 | 27 | = Quality real-time graphics = 28 | 29 | With Verge3D, real-time graphics are no longer associated with video games. Realistic visuals become possible with a sophisticated yet easy-to-use material system which is fully consistent with the modeling suite of your choice. 30 | 31 | On the other hand, physically based rendering (PBR) which comes with Verge3D simplifies the task of creating engaging 3D Web content even more. You no longer need to be an experienced 3D specialist or graphics programmer to achieve a high level of representation. We already took care of it! 32 | 33 | = Use familiar tools = 34 | 35 | We designed Verge3D to be closely integrated with your favorite tools. You can create your 3D content in Blender, 3ds Max, or Maya, and export straight to a web page. You can also preview your scene in the browser using the Sneak Peek feature. 36 | 37 | But, of course, aside from the 3D part, there is also web! With Verge3D, you can completely forget about building HTML/CSS layouts and JavaScript coding by 38 | hand. Verge3D perfectly works with WordPress and WooCoommerce, as well as the design software such as Webflow or Google Web Designer. 39 | 40 | = Interactivity without coding = 41 | 42 | Verge3D Puzzles are a fun, yet powerful tool to develop smart web applications of any complexity. With Puzzles, you can easily add behavior scenarios to your 3D content, making it interactive and responsive to user actions. Puzzles will increase efficiency of your team by distributing responsibilities between programmers and designers. 43 | 44 | This amazing tool can be used both for fast prototyping and in production. For 3D artists, this invaluable tool overcomes technological barriers of web development thus making it possible to apply their creativity in the realm of interactive 3D Web! 45 | 46 | = No vendor locks, no strings attached = 47 | 48 | It’s up to you to decide whether to keep your 3D works private, show to your partners or share with the general public. Verge3D-based apps are hosted on your own WordPress servers and have no dependencies on any cloud platforms. 49 | 50 | As such, you are in control of your own data, being able to choose how to store it, where and for how long. 51 | 52 | 53 | == Installation == 54 | 55 | 1. Install and activate the plugin via the "Plugins" menu in WordPress admin interface. 56 | 2. Verge3D menu should appear in the admin panel. 57 | 3. Use the Verge3D->Applications submenu to upload your first 3D application. 58 | 59 | == Frequently Asked Questions == 60 | No questions yet. Please ask them on the [Verge3D Forums](https://www.soft8soft.com/forums/) 61 | 62 | == Screenshots == 63 | 1. 3D product customizer with WooCommerce integration 64 | 2. Scooter - interactive configurator with 1000000+ combinations 65 | 3. Verge3D features direct export from Blender, 3ds Max, or Maya 66 | 4. Used by NASA and other companies and organizations throughout the world 67 | 5. Interactive WebGL-based online shop 68 | 6. Easy-to-use application and orders management. 69 | 70 | == Changelog == 71 | 72 | = 4.10.0 = 73 | * Verge3D 4.10.0 version bump. 74 | 75 | = 4.9.5 = 76 | * Forbid optaining info for private/password-protected WooCommerce products. 77 | 78 | = 4.9.3 = 79 | * Fixed possible security issues. 80 | 81 | = 4.8.3 = 82 | * Fixed bug with Chrome/Chromium not able to produce PDF attachments/quotes/invoices. 83 | * Fixed possible security issues. 84 | * Remove unusable product_admin_form.php template. 85 | 86 | = 4.8.2 = 87 | * Fixed app uploading error on macOS and Linux. 88 | 89 | = 4.8.1 = 90 | * Fixed security issue with possible XSS. 91 | 92 | = 4.8.0 = 93 | * Verge3D 4.8 version bump. 94 | 95 | = 4.7.0 = 96 | * Support REST API for form submissions. 97 | * Support REST API for order submissions via FormData. 98 | * Preserve MIME type for uploaded files. 99 | * Improve error reporting for admin interface and REST API. 100 | * Security fixes. 101 | 102 | = 4.6.0 = 103 | * Support chunked uploads. Allows publishing huge assets with no tweaking of PHP settings. 104 | * More security improvements. 105 | 106 | = 4.5.3 = 107 | * Implement proper MIME filter for uploaded files. 108 | * Fix uploaded file types not being ignored. 109 | * Security fixes. 110 | 111 | = 4.5.2 = 112 | * Fix order page layout in latest WordPress versions. 113 | * Security fixes. 114 | 115 | = 4.5.1 = 116 | * Fix order page layout in latest WordPress versions. 117 | * Security fixes. 118 | 119 | = 4.4 = 120 | * Verge3D widget for Elementor. 121 | * Support WooCommerce Composite Products extension. 122 | 123 | = 4.3 = 124 | * Verge3D 4.3 version bump. 125 | 126 | = 4.2 = 127 | * Support 3D items in WooCommerce product gallery. 128 | * Fix indentation in Gutenberg editor. 129 | * Fix app layout on mobiles. 130 | 131 | = 4.1 = 132 | * Support itemized orders with server-side price calculation. 133 | * Quotes and invoices generator. 134 | * Downloadable products. 135 | * PayPal payments. 136 | * Billing and shipping info. 137 | * Improved plugin security. 138 | 139 | = 4.0 = 140 | * Fix issue with WooCommerce product ID. 141 | 142 | = 3.9 = 143 | * Fix issue with debug notices. 144 | 145 | = 3.8 = 146 | * Verge3D 3.8 version bump. 147 | 148 | = 3.7 = 149 | * Verge3D 3.7 version bump. 150 | 151 | = 3.6 = 152 | * Fixed error with missing wc_add_to_cart_params structure 153 | 154 | = 3.5 = 155 | * Verge3D 3.5 version bump. 156 | 157 | = 3.4 = 158 | * Verge3D 3.4 version bump. 159 | 160 | = 3.3 = 161 | * Support WooCommerce global attributes. Fix issue with incorrectly uploaded Maya assets. 162 | 163 | = 3.2 = 164 | * Verge3D 3.2 version bump. 165 | 166 | = 3.1 = 167 | * Verge3D 3.1 version bump. 168 | 169 | = 3.0 = 170 | * Verge3D 3.0 version bump. 171 | 172 | = 2.17.2 = 173 | * Fix issue with product permalinks. 174 | 175 | = 2.17 = 176 | * Verge3D 2.17 version bump. 177 | 178 | = 2.16.1 = 179 | * Support international attribute names in WooCommerce. 180 | 181 | = 2.16 = 182 | * Add WooCommerce integration. Improve application upload interface. 183 | 184 | = 2.15 = 185 | * Verge3D 2.15 version bump. 186 | 187 | = 2.14 = 188 | * Verge3D 2.14 version bump. 189 | 190 | = 2.13 = 191 | * Improve application upload speed, fix various issues with server limits. 192 | 193 | = 2.12 = 194 | * Add order id field to order forms. Support order filter/verification hook. 195 | 196 | = 2.11 = 197 | * Support for persistent file storage. 198 | 199 | = 2.10 = 200 | * Support for JSON API and customized order templates. 201 | 202 | = 2.8 = 203 | * Fixed issue in applications with multiple HTML files 204 | 205 | = 2.7.1 = 206 | * Minor update, fixes possible security issues 207 | 208 | = 2.7 = 209 | * Initial release, compatible with Verge3D 2.7 210 | 211 | -------------------------------------------------------------------------------- /js/order.js: -------------------------------------------------------------------------------- 1 | /** 2 | * We store order items state in the form hidden input 3 | */ 4 | function set_form_order_items(items) { 5 | const form = document.querySelector('form'); 6 | 7 | let order_items = form.querySelector('input[name="order_items"'); 8 | if (order_items) { 9 | order_items.value = JSON.stringify(items); 10 | } else { 11 | order_items = document.createElement('input'); 12 | order_items.type = 'hidden'; 13 | order_items.name = 'order_items'; 14 | order_items.value = JSON.stringify(items); 15 | form.appendChild(order_items); 16 | } 17 | } 18 | 19 | function get_form_order_items() { 20 | const form = document.querySelector('form'); 21 | 22 | const order_items = form.querySelector('input[name="order_items"'); 23 | if (order_items) { 24 | return JSON.parse(order_items.value); 25 | } else { 26 | return []; 27 | } 28 | } 29 | 30 | function set_form_order_item(id, item) { 31 | const order_items = get_form_order_items(); 32 | order_items[id] = item; 33 | set_form_order_items(order_items); 34 | } 35 | 36 | function append_form_order_item(item) { 37 | const order_items = get_form_order_items(); 38 | order_items.push(item); 39 | set_form_order_items(order_items); 40 | } 41 | 42 | function get_form_order_item(id) { 43 | const order_items = get_form_order_items(); 44 | return order_items[id]; 45 | } 46 | 47 | /** 48 | * Requesting server just to get proper HTML, no database modifications here 49 | */ 50 | function fetch_order_items_html() { 51 | 52 | const order_items = get_form_order_items(); 53 | 54 | const form_data = new FormData(); 55 | form_data.append('action', 'v3d_ajax_fetch_order_items'); 56 | form_data.append('order_items', JSON.stringify(order_items)); 57 | 58 | const req = new XMLHttpRequest(); 59 | req.open('POST', ajax_object.ajax_url); 60 | req.send(form_data); 61 | req.addEventListener('load', function() { 62 | const response = JSON.parse(req.response); 63 | document.getElementById('the-list').innerHTML = response.rows; 64 | document.querySelectorAll('.tablenav-pages > .displaying-num').forEach(elem => { 65 | elem.innerHTML = response.total_items_i18n; 66 | }); 67 | }); 68 | } 69 | 70 | function fetch_product_info(callback) { 71 | 72 | const form_data = new FormData(); 73 | form_data.append('action', 'v3d_ajax_fetch_product_info'); 74 | 75 | const req = new XMLHttpRequest(); 76 | req.open('POST', ajax_object.ajax_url); 77 | req.send(form_data); 78 | req.addEventListener('load', function() { 79 | const response = JSON.parse(req.response); 80 | callback(response); 81 | }); 82 | } 83 | 84 | function add_custom_item_cb() { 85 | append_form_order_item({ 86 | 'title': 'Some product', 87 | 'sku': '', 88 | 'price': 0, 89 | 'quantity': 1 90 | }); 91 | fetch_order_items_html(); 92 | } 93 | 94 | 95 | function delete_item_cb(id) { 96 | const order_items = get_form_order_items(); 97 | order_items.splice(Number(id), 1); 98 | set_form_order_items(order_items); 99 | fetch_order_items_html(); 100 | }; 101 | 102 | function delete_bulk_items_cb(e) { 103 | const select = document.getElementById('bulk-action-selector-top'); 104 | const option = select.selectedOptions[0].value; 105 | if (option == 'delete_order_item') { 106 | const order_items = get_form_order_items(); 107 | const checkers = document.querySelectorAll('input[name="order_item[]"]'); 108 | 109 | for (let i = checkers.length-1; i >=0; i--) { 110 | const checker = checkers[i]; 111 | 112 | if (checker.checked) 113 | order_items.splice(Number(checker.value), 1); 114 | } 115 | 116 | set_form_order_items(order_items); 117 | fetch_order_items_html(); 118 | } 119 | } 120 | 121 | /** 122 | * Add product item dialog callbacks 123 | */ 124 | function add_product_item_cb() { 125 | fetch_product_info(function(products) { 126 | 127 | let optionsHTML = ''; 128 | 129 | products.forEach(p => { 130 | optionsHTML += ``; 131 | }); 132 | 133 | document.getElementById('add_product_item_select').innerHTML = optionsHTML; 134 | document.getElementById('add_product_item_quantity').value = 1; 135 | 136 | const add_product_item_dia = document.getElementById('add_product_item'); 137 | add_product_item_dia.style.display = 'flex'; 138 | }); 139 | } 140 | 141 | function add_product_item_save_cb() { 142 | 143 | const select = document.getElementById('add_product_item_select'); 144 | const option = select.selectedOptions[0]; 145 | 146 | append_form_order_item({ 147 | 'title': option.innerText, 148 | 'sku': option.value, 149 | 'price': option.dataset.price, 150 | 'quantity': document.getElementById('add_product_item_quantity').value 151 | }); 152 | 153 | document.getElementById('add_product_item').style.display = 'none'; 154 | 155 | fetch_order_items_html(); 156 | } 157 | 158 | function add_product_item_cancel_cb() { 159 | document.getElementById('add_product_item').style.display = 'none'; 160 | } 161 | 162 | /** 163 | * Edit order item callbacks 164 | */ 165 | function edit_order_item_cb(id) { 166 | 167 | const order_item = get_form_order_item(id); 168 | 169 | document.getElementById('edit_order_item_title').value = order_item['title']; 170 | document.getElementById('edit_order_item_sku').value = order_item['sku']; 171 | document.getElementById('edit_order_item_price').value = order_item['price']; 172 | document.getElementById('edit_order_item_quantity').value = order_item['quantity']; 173 | 174 | const edit_order_item_dia = document.getElementById('edit_order_item'); 175 | edit_order_item_dia.style.display = 'flex'; 176 | edit_order_item_dia.dataset.order_item_id = id; 177 | } 178 | 179 | function edit_order_item_save_cb() { 180 | 181 | const edit_order_item_dia = document.getElementById('edit_order_item'); 182 | 183 | const id = edit_order_item_dia.dataset.order_item_id; 184 | 185 | set_form_order_item(id, { 186 | 'title': document.getElementById('edit_order_item_title').value, 187 | 'sku': document.getElementById('edit_order_item_sku').value, 188 | 'price': document.getElementById('edit_order_item_price').value, 189 | 'quantity': document.getElementById('edit_order_item_quantity').value 190 | }); 191 | 192 | edit_order_item_dia.style.display = 'none'; 193 | 194 | fetch_order_items_html(); 195 | } 196 | 197 | function edit_order_item_cancel_cb() { 198 | document.getElementById('edit_order_item').style.display = 'none'; 199 | } 200 | 201 | async function send_pdf_cb(pdftype) { 202 | const form_data = new FormData(); 203 | form_data.append('action', 'v3d_ajax_send_pdf'); 204 | form_data.append('order', ajax_object.order_id); 205 | form_data.append('pdftype', pdftype); 206 | 207 | const options = { 208 | method: 'POST', 209 | body: form_data 210 | } 211 | 212 | let info; 213 | 214 | try { 215 | const response = await fetch(ajax_object.ajax_url, options); 216 | if (!response.ok) 217 | info = 'Failed to make request'; 218 | else 219 | info = (await response.json()).statusText; 220 | } catch (e) { 221 | info = 'Failed to make request'; 222 | } 223 | 224 | document.querySelector('#dialog-email-sent').style.display = 'flex'; 225 | document.querySelector('#dialog-email-sent div.dialog-heading').textContent = info; 226 | } 227 | 228 | function email_sent_close_cb() { 229 | document.querySelector('#dialog-email-sent').style.display = 'none'; 230 | } 231 | 232 | window.addEventListener('load', function() { 233 | 234 | // NOTE: prevent internal form submit 235 | const doaction_btn = document.getElementById('doaction'); 236 | const doaction2_btn = document.getElementById('doaction2'); 237 | 238 | if (doaction_btn) { 239 | doaction_btn.type = 'button'; 240 | doaction2_btn.type = 'button'; 241 | document.getElementById('doaction').addEventListener('click', delete_bulk_items_cb); 242 | } 243 | }); 244 | 245 | -------------------------------------------------------------------------------- /templates/order_pdf.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 |

34 |

35 | 36 |
37 | 38 | 39 | 40 | 41 | 45 | 46 | 47 | 48 | 49 | 54 | 55 | 56 | 57 | 58 | 61 | 62 | 63 | 64 | 65 | 68 | 69 | 70 | 71 | 72 |
73 | 74 |
75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 88 | 89 | 93 | 94 | 95 | 96 | 97 | 102 | 103 | 104 | 105 | 106 | 109 | 110 | 111 | 112 | 115 | 116 | 117 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 137 | 138 | 139 | 140 | 145 | 146 | 147 | 148 | 149 | 152 | 153 | 154 | 155 | 156 | 157 |
158 | 159 |
160 | 161 | 162 | 163 | 166 | 169 | 170 | 171 | 172 | 175 | 178 | 179 | 180 | 181 | 182 |
183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 |
ItemPriceQuantityAmount
Subtotal
Discount ()
Tax ()
Total
229 | 230 | 231 |
Additional notes:
232 | 233 | 234 |
235 | 236 | 237 | -------------------------------------------------------------------------------- /woo_product.php: -------------------------------------------------------------------------------- 1 | admin_url('admin-ajax.php'), 13 | 'switch_on_update' => $switch_on_update 14 | )); 15 | } 16 | add_action('wp_enqueue_scripts', 'v3d_load_woo_scripts'); 17 | 18 | 19 | function v3d_bootstap_woo_product_composite($dependencies) { 20 | wp_register_script('v3d_woo_product_composite', plugin_dir_url(__FILE__) . 'js/woo_product_composite.js'); 21 | $dependencies[] = 'v3d_woo_product_composite'; 22 | return $dependencies; 23 | } 24 | 25 | function v3d_plugins_loaded() { 26 | global $woocommerce_composite_products; 27 | add_filter('woocommerce_composite_script_dependencies', 'v3d_bootstap_woo_product_composite'); 28 | } 29 | add_action('plugins_loaded', 'v3d_plugins_loaded'); 30 | 31 | 32 | // Verge3D tab in product data (admin) 33 | 34 | function v3d_product_tab($tabs) { 35 | $tabs['verge3d'] = array( 36 | 'label' => __('Verge3D', 'verge3d'), 37 | 'target' => 'v3d_product_options', 38 | 'class' => array('show_if_verge3d'), 39 | 'priority' => 100 40 | ); 41 | 42 | return $tabs; 43 | } 44 | add_filter('woocommerce_product_data_tabs', 'v3d_product_tab'); 45 | 46 | 47 | function v3d_product_tab_content() { 48 | ?>
ID, 'v3d_app_id', true); 54 | if (empty($app_id)) 55 | $app_id = ''; 56 | 57 | $app_posts = get_posts(array( 58 | 'posts_per_page' => -1, 59 | 'post_type' => 'v3d_app', 60 | 'post_status' => 'publish', 61 | )); 62 | 63 | $app_options[''] = __('None (select a value)', 'verge3d'); 64 | 65 | foreach ($app_posts as $app_post) 66 | $app_options[$app_post->ID] = $app_post->post_title; 67 | 68 | woocommerce_wp_select(array( 69 | 'id' => 'v3d_app_id', 70 | 'label' => __('Application', 'verge3d'), 71 | 'options' => $app_options, 72 | 'value' => $app_id, 73 | 'desc_tip' => 'true', 74 | 'description' => __('Verge3D application which will be displayed on the product page.', 'verge3d'), 75 | )); 76 | 77 | 78 | woocommerce_wp_checkbox(array( 79 | 'id' => 'v3d_app_show_gallery', 80 | 'label' => __('Show as gallery item', 'verge3d'), 81 | 'value' => get_post_meta(get_the_ID(), 'v3d_app_show_gallery', true), 82 | 'desc_tip' => 'true', 83 | 'description' => __('Show application as last thumbnail in the gallery. If disabled, all 2D images will be replaced by 3D app.', 'verge3d'), 84 | )); 85 | 86 | woocommerce_wp_checkbox(array( 87 | 'id' => 'v3d_app_switch_on_update', 88 | 'label' => __('Switch to 3D on update', 'verge3d'), 89 | 'value' => get_post_meta(get_the_ID(), 'v3d_app_switch_on_update', true), 90 | 'desc_tip' => 'true', 91 | 'description' => __('Automatically slide to 3D app when product updates (gallery mode only).', 'verge3d'), 92 | )); 93 | 94 | ?>
95 | 107 |
-1, 133 | 'post_type' => 'v3d_app', 134 | 'post_status' => 'publish', 135 | )); 136 | 137 | if (!empty($app_posts)) { 138 | $app_id = get_post_meta($product->get_id(), 'v3d_app_id', true); 139 | if (!empty($app_id) && !empty(get_post($app_id))) { 140 | return v3d_gen_app_iframe_html($app_id); 141 | } else 142 | return ''; 143 | } 144 | } 145 | 146 | 147 | function v3d_product_image($html) { 148 | global $product; 149 | 150 | if (get_post_meta(get_the_ID(), 'v3d_app_show_gallery', true)) 151 | return $html; 152 | 153 | $app_iframe = v3d_get_product_iframe($product); 154 | if (!empty($app_iframe)) 155 | return $app_iframe; 156 | else 157 | return $html; 158 | } 159 | add_filter('woocommerce_single_product_image_thumbnail_html', 'v3d_product_image'); 160 | 161 | 162 | function v3d_show_product_thumbnails() { 163 | global $product; 164 | 165 | if (!get_post_meta(get_the_ID(), 'v3d_app_show_gallery', true)) 166 | return; 167 | 168 | $app_iframe = v3d_get_product_iframe($product); 169 | if (empty($app_iframe)) 170 | return; 171 | 172 | $app_id = get_post_meta($product->get_id(), 'v3d_app_id', true); 173 | if (!empty($app_id) && !empty(get_post($app_id))) { 174 | $cover_att_id = get_post_meta($app_id, 'cover_attachment_id', true); 175 | 176 | $thumbnail_src = wp_get_attachment_image_src($cover_att_id, 'thumbnail'); 177 | $full_src = wp_get_attachment_image_src($cover_att_id, 'full'); 178 | $alt_text = trim(strip_tags(get_post_meta($cover_att_id, '_wp_attachment_image_alt', true))); 179 | } 180 | 181 | if (!is_array($thumbnail_src)) { 182 | $default_url = plugin_dir_url(__FILE__) . 'images/product_thumbnail.png'; 183 | $thumbnail_src = [$default_url]; 184 | $full_src = [$default_url]; 185 | $alt_text = '3D preview'; 186 | } 187 | 188 | $html = ''; 189 | 190 | echo $html; 191 | } 192 | add_action('woocommerce_product_thumbnails', 'v3d_show_product_thumbnails', 30); 193 | 194 | 195 | function v3d_parse_request_attributes() { 196 | 197 | $attrs = array(); 198 | 199 | foreach ($_REQUEST as $key => $value) { 200 | if (strpos($key, 'attribute_') !== false) 201 | $attrs[preg_replace('/^pa_/', '', urldecode(str_replace('attribute_', '', $key)))] = $value; 202 | } 203 | 204 | return $attrs; 205 | } 206 | 207 | function v3d_product_get_attributes($product) { 208 | $attrs = array(); 209 | 210 | // NOTE: using get_attributes() alone does not work 211 | foreach ($product->get_attributes() as $attr_key => $attr_value) { 212 | // remove global attributes prefix if any 213 | $attrs[preg_replace('/^pa_/', '', urldecode($attr_key))] = $product->get_attribute($attr_key); 214 | } 215 | 216 | return $attrs; 217 | } 218 | 219 | function v3d_get_product_info() { 220 | 221 | $product_id = $_REQUEST['product_id']; 222 | $product = wc_get_product($product_id); 223 | 224 | $response = array(); 225 | 226 | // forbid obtainting info for private / password-protected products 227 | if (!empty($product) && $product->is_visible() && !post_password_required($product_id)) { 228 | $response['status'] = 'ok'; 229 | 230 | $quantity = $_REQUEST['quantity']; 231 | 232 | $response['name'] = $product->get_name(); 233 | $response['type'] = $product->get_type(); 234 | $response['quantity'] = intval($quantity); 235 | 236 | $response['sku'] = $product->get_sku(); 237 | $response['price'] = floatval($product->get_price()); 238 | 239 | $response['weight'] = floatval($product->get_weight()); 240 | $response['length'] = floatval($product->get_length()); 241 | $response['width'] = floatval($product->get_width()); 242 | $response['height'] = floatval($product->get_height()); 243 | 244 | $response['attributes'] = v3d_product_get_attributes($product); 245 | 246 | if ($product->is_type('variable')) { 247 | 248 | // preserving non-variable attributes 249 | foreach (v3d_parse_request_attributes() as $attr_key => $attr_value) { 250 | $response['attributes'][$attr_key] = $attr_value; 251 | } 252 | 253 | if (!empty($_REQUEST['variation_id'])) { 254 | $variation = wc_get_product($_REQUEST['variation_id']); 255 | 256 | $response['name'] = $variation->get_name(); 257 | 258 | if (!empty($variation->get_sku())) 259 | $response['sku'] = $variation->get_sku(); 260 | if (!empty($variation->get_price())) 261 | $response['price'] = floatval($variation->get_price()); 262 | 263 | if (!empty($variation->get_weight())) 264 | $response['weight'] = floatval($variation->get_weight()); 265 | if (!empty($variation->get_length())) 266 | $response['length'] = floatval($variation->get_length()); 267 | if (!empty($variation->get_width())) 268 | $response['width'] = floatval($variation->get_width()); 269 | if (!empty($variation->get_height())) 270 | $response['height'] = floatval($variation->get_height()); 271 | } 272 | 273 | } else if ($product->is_type('grouped')) { 274 | 275 | unset($response['price']); 276 | unset($response['quantity']); 277 | unset($response['weight']); 278 | unset($response['length']); 279 | unset($response['width']); 280 | unset($response['height']); 281 | 282 | $response['children'] = array(); 283 | 284 | foreach ($product->get_children() as $child_id) { 285 | $child = wc_get_product($child_id); 286 | $child_response = array(); 287 | 288 | $child_response['name'] = $child->get_name(); 289 | $child_response['quantity'] = intval($quantity[$child_id]); 290 | 291 | $child_response['sku'] = $child->get_sku(); 292 | $child_response['price'] = floatval($child->get_price()); 293 | 294 | $child_response['weight'] = floatval($child->get_weight()); 295 | 296 | $child_response['length'] = floatval($child->get_length()); 297 | $child_response['width'] = floatval($child->get_width()); 298 | $child_response['height'] = floatval($child->get_height()); 299 | 300 | $child_response['attributes'] = v3d_product_get_attributes($child); 301 | 302 | array_push($response['children'], $child_response); 303 | } 304 | 305 | } else if ($product->is_type('composite')) { 306 | 307 | $response['components'] = array(); 308 | 309 | if (!empty($_REQUEST['components'])) { 310 | foreach ($_REQUEST['components'] as $comp_id => $comp) { 311 | 312 | $comp_response = array(); 313 | 314 | $comp_response['title'] = $comp['title']; 315 | $comp_response['id'] = $comp_id; 316 | 317 | $comp_response['type'] = $comp['product_type']; 318 | $comp_response['quantity'] = intval($comp['quantity']); 319 | 320 | $child = wc_get_product($comp['product_id']); 321 | 322 | if (!empty($child)) { 323 | $comp_response['name'] = $comp['selection_title']; 324 | $comp_response['sku'] = $child->get_sku(); 325 | $comp_response['weight'] = floatval($child->get_weight()); 326 | $comp_response['length'] = floatval($child->get_length()); 327 | $comp_response['width'] = floatval($child->get_width()); 328 | $comp_response['height'] = floatval($child->get_height()); 329 | $comp_response['attributes'] = v3d_product_get_attributes($child); 330 | } else { 331 | $comp_response['name'] = ''; 332 | $comp_response['sku'] = ''; 333 | $comp_response['weight'] = 0; 334 | $comp_response['length'] = 0; 335 | $comp_response['width'] = 0; 336 | $comp_response['height'] = 0; 337 | $comp_response['attributes'] = []; 338 | } 339 | 340 | if ($comp['product_type'] == 'variable') { 341 | if (!empty($comp['variation_id'])) { 342 | $variation = wc_get_product($comp['variation_id']); 343 | 344 | $comp_response['name'] = $variation->get_name(); 345 | 346 | if (!empty($variation->get_sku())) 347 | $comp_response['sku'] = $variation->get_sku(); 348 | 349 | if (!empty($variation->get_weight())) 350 | $comp_response['weight'] = floatval($variation->get_weight()); 351 | if (!empty($variation->get_length())) 352 | $comp_response['length'] = floatval($variation->get_length()); 353 | if (!empty($variation->get_width())) 354 | $comp_response['width'] = floatval($variation->get_width()); 355 | if (!empty($variation->get_height())) 356 | $comp_response['height'] = floatval($variation->get_height()); 357 | 358 | foreach ($comp['attributes'] as $attr_key => $attr_value) { 359 | $comp_response['attributes'][$attr_key] = $attr_value; 360 | } 361 | } else { 362 | // nothing selected, reset all attributes to empty strings 363 | foreach ($comp_response['attributes'] as $attr_key => $attr_value) { 364 | $comp_response['attributes'][$attr_key] = ''; 365 | } 366 | } 367 | } 368 | 369 | // make empty array an object to be properly handled by JSON encode 370 | if (empty($comp_response['attributes'])) 371 | $comp_response['attributes'] = (object)array(); 372 | 373 | array_push($response['components'], $comp_response); 374 | } 375 | } 376 | } 377 | 378 | // make empty array an object to be properly handled by JSON encode 379 | if (empty($response['attributes'])) 380 | $response['attributes'] = (object)array(); 381 | 382 | } else { 383 | $response['status'] = 'error'; 384 | $response['error'] = 'Product not found'; 385 | } 386 | 387 | wp_send_json($response); 388 | } 389 | add_action('wp_ajax_v3d_woo_get_product_info', 'v3d_get_product_info'); 390 | add_action('wp_ajax_nopriv_v3d_woo_get_product_info', 'v3d_get_product_info'); 391 | 392 | -------------------------------------------------------------------------------- /product.php: -------------------------------------------------------------------------------- 1 | _args['plural']); 62 | 63 | foreach ($product as $o) 64 | if (!empty(intval($o))) 65 | v3d_delete_product(intval($o)); 66 | } else { 67 | check_admin_referer('product-delete'); 68 | 69 | if (!empty(intval($product))) { 70 | v3d_delete_product($product); 71 | } 72 | } 73 | 74 | v3d_redirect_product_list(); 75 | } else { 76 | echo 'Bad request'; 77 | return; 78 | } 79 | 80 | break; 81 | default: 82 | $productTable->prepare_items(); 83 | 84 | ?> 85 |
86 |

87 | 88 |

E-Commerce Products

89 | Add New 90 | 91 |
92 | 93 | 94 | 95 | display() ?> 96 | 97 |
98 |
99 | (!empty($_REQUEST['title'])) ? 107 | sanitize_text_field($_REQUEST['title']) : 'My Product', 108 | 'post_status' => 'publish', 109 | 'post_type' => 'v3d_product', 110 | 'meta_input' => array( 111 | 'sku' => (!empty($_REQUEST['sku'])) ? sanitize_text_field($_REQUEST['sku']) : '', 112 | 'price' => (!empty($_REQUEST['price'])) ? sanitize_text_field($_REQUEST['price']) : 0, 113 | 'download_link' => (!empty($_REQUEST['download_link'])) ? sanitize_text_field($_REQUEST['download_link']) : '', 114 | ), 115 | ); 116 | return wp_insert_post($post_arr); 117 | } 118 | 119 | function v3d_update_product($product_id) { 120 | $post_arr = array( 121 | 'ID' => $product_id, 122 | 'post_title' => (!empty($_REQUEST['title'])) ? 123 | sanitize_text_field($_REQUEST['title']) : 'My Product', 124 | 'post_status' => 'publish', 125 | 'post_type' => 'v3d_product', 126 | 'meta_input' => array( 127 | 'sku' => (!empty($_REQUEST['sku'])) ? sanitize_text_field($_REQUEST['sku']) : '', 128 | 'price' => (!empty($_REQUEST['price'])) ? sanitize_text_field($_REQUEST['price']) : 0, 129 | 'download_link' => (!empty($_REQUEST['download_link'])) ? sanitize_text_field($_REQUEST['download_link']) : '', 130 | ), 131 | ); 132 | 133 | wp_update_post($post_arr); 134 | } 135 | 136 | function v3d_display_product($product_id) { 137 | if ($product_id > -1) { 138 | $title = get_the_title($product_id); 139 | $sku = get_post_meta($product_id, 'sku', true); 140 | $price = get_post_meta($product_id, 'price', true); 141 | $download_link = get_post_meta($product_id, 'download_link', true); 142 | } else { 143 | $title = ''; 144 | $sku = ''; 145 | $price = 0; 146 | $download_link = ''; 147 | } 148 | 149 | ?> 150 |
151 |

-1 ? 'Update Product' : 'Create Product' ?>

152 |
153 | 154 | 155 | 156 | -1 ? 'product-edit' : 'product-create'); ?> 157 | 158 | 159 | 160 | 161 | 162 | 165 | 168 | 169 | 170 | 173 | 176 | 177 | 178 | 181 | 184 | 185 | 186 | 189 | 193 | 194 | 195 | 196 |
163 | 164 | 166 | 167 |
171 | 172 | 174 | 175 |
179 | 180 | 182 | 183 |
187 | 188 | 190 | 191 |

Specified for downloadable products.

192 |
197 |

198 |
199 |
200 | -1, 210 | 'orderby' => 'title', 211 | 'order' => 'ASC', 212 | 'post_type' => 'v3d_product', 213 | 'post_status' => 'publish', 214 | 'suppress_filters' => true, 215 | ); 216 | $posts = get_posts($args); 217 | 218 | $products = array(); 219 | 220 | foreach ($posts as $p) { 221 | $products[] = array( 222 | 'id' => $p->ID, 223 | 'title' => get_the_title($p->ID), 224 | 'sku' => get_post_meta($p->ID, 'sku', true), 225 | 'price' => get_post_meta($p->ID, 'price', true), 226 | 'download_link' => get_post_meta($p->ID, 'download_link', true), 227 | ); 228 | } 229 | 230 | return $products; 231 | } 232 | 233 | function v3d_find_product_by_sku($sku) { 234 | $products = v3d_get_products(); 235 | 236 | foreach ($products as $p) { 237 | if ($p['sku'] === $sku) 238 | return $p; 239 | } 240 | 241 | return null; 242 | } 243 | 244 | class V3D_Product_List_Table extends WP_List_Table { 245 | 246 | function __construct(){ 247 | global $status, $page; 248 | 249 | // Set parent defaults 250 | parent::__construct( array( 251 | 'singular' => 'product', 252 | 'plural' => 'products', 253 | 'ajax' => false 254 | ) ); 255 | 256 | } 257 | 258 | function column_default($item, $column_name) { 259 | switch ($column_name) { 260 | case 'sku': 261 | case 'price': 262 | return $item[$column_name]; 263 | default: 264 | return print_r($item, true); // show the whole array for troubleshooting purposes 265 | } 266 | } 267 | 268 | function column_title($item) { 269 | 270 | // build row actions 271 | 272 | $edit_url = sprintf('?page=%s&action=editform&product=%s', esc_attr($_REQUEST['page']), $item['ID']); 273 | $edit_url = wp_nonce_url($edit_url, 'product-edit'); 274 | $delete_url = sprintf('?page=%s&action=delete&product=%s', esc_attr($_REQUEST['page']), $item['ID']); 275 | $delete_url = wp_nonce_url($delete_url, 'product-delete'); 276 | 277 | $actions = array( 278 | 'edit' => 'Edit', 279 | 'delete' => 'Delete' 280 | ); 281 | 282 | // return the title contents 283 | return sprintf('%1$s (id:%2$s)%3$s', 284 | /*$1%s*/ $item['title'], 285 | /*$2%s*/ $item['ID'], 286 | /*$3%s*/ $this->row_actions($actions) 287 | ); 288 | } 289 | 290 | 291 | // bulk actions callback 292 | function column_cb($item){ 293 | return sprintf('', 294 | $this->_args['singular'], $item['ID']); 295 | } 296 | 297 | function get_columns(){ 298 | $columns = array( 299 | 'cb' => '', //Render a checkbox instead of text 300 | 'title' => 'Title', 301 | 'sku' => 'SKU', 302 | 'price' => 'Price', 303 | ); 304 | return $columns; 305 | } 306 | 307 | function get_sortable_columns() { 308 | $sortable_columns = array( 309 | 'title' => array('title', false), 310 | 'sku' => array('sku', false), 311 | 'price' => array('price', false), 312 | ); 313 | return $sortable_columns; 314 | } 315 | 316 | function get_bulk_actions() { 317 | $actions = array( 318 | 'delete' => 'Delete' 319 | ); 320 | return $actions; 321 | } 322 | 323 | function prepare_items() { 324 | $per_page = 15; 325 | 326 | $columns = $this->get_columns(); 327 | $hidden = array(); 328 | $sortable = $this->get_sortable_columns(); 329 | 330 | $this->_column_headers = array($columns, $hidden, $sortable); 331 | 332 | // if no sort, default to title 333 | $orderby = !empty($_REQUEST['orderby']) ? sanitize_text_field($_REQUEST['orderby']) : 'title'; 334 | // if no order, default to asc 335 | $order = !empty($_REQUEST['order']) ? sanitize_text_field($_REQUEST['order']) : 'ASC'; 336 | 337 | $args = array( 338 | 'posts_per_page' => -1, 339 | 'offset' => 0, 340 | 'category' => '', 341 | 'category_name' => '', 342 | 'orderby' => $orderby, 343 | 'order' => $order, 344 | 'include' => '', 345 | 'exclude' => '', 346 | 'meta_key' => '', 347 | 'meta_value' => '', 348 | 'post_type' => 'v3d_product', 349 | 'post_mime_type' => '', 350 | 'post_parent' => '', 351 | 'author' => '', 352 | 'author_name' => '', 353 | 'post_status' => 'publish', 354 | 'suppress_filters' => true, 355 | 'fields' => '', 356 | ); 357 | 358 | if ($orderby == 'sku') { 359 | $args['meta_key'] = 'sku'; 360 | $args['orderby'] = 'meta_value'; 361 | } else if ($orderby == 'price') { 362 | $args['meta_key'] = 'price'; 363 | $args['orderby'] = 'meta_value_num'; 364 | } 365 | 366 | $q_posts = get_posts($args); 367 | 368 | $posts = array(); 369 | 370 | foreach ($q_posts as $q_post) { 371 | 372 | $title = get_the_title($q_post->ID); 373 | $sku = get_post_meta($q_post->ID, 'sku', true); 374 | $price = get_post_meta($q_post->ID, 'price', true); 375 | 376 | $posts[] = array( 377 | 'ID' => $q_post->ID, 378 | 'title' => !empty($title) ? $title : 'N/A', 379 | 'sku' => !empty($sku) ? $sku : 'N/A', 380 | 'price' => isset($price) ? v3d_price($price) : 'N/A', 381 | ); 382 | } 383 | 384 | $current_page = $this->get_pagenum(); 385 | 386 | $total_items = count($posts); 387 | 388 | $posts = array_slice($posts, (($current_page-1)*$per_page), $per_page); 389 | 390 | $this->items = $posts; 391 | 392 | $this->set_pagination_args(array( 393 | 'total_items' => $total_items, 394 | 'per_page' => $per_page, 395 | 'total_pages' => ceil($total_items/$per_page) 396 | )); 397 | } 398 | } 399 | 400 | function v3d_redirect_product($product_id=-1) { 401 | 402 | $params = '?page=verge3d_product'; 403 | 404 | if ($product_id > -1) { 405 | $params .= ('&action=edit&product='.$product_id); 406 | } 407 | 408 | ?> 409 | 412 | 417 | 420 | get_param('sku'))); 426 | if (!empty($sku)) { 427 | 428 | $product = v3d_find_product_by_sku($sku); 429 | 430 | if (!empty($product)) { 431 | $product_info = array( 432 | 'status' => 'ok', 433 | 'title' => $product['title'], 434 | 'sku' => $product['sku'], 435 | 'price' => $product['price'], 436 | 'currency' => v3d_currency_symbol(), 437 | ); 438 | $response = new WP_REST_Response($product_info); 439 | } else 440 | $response = new WP_REST_Response(array('error' => 'Product not found')); 441 | 442 | } else { 443 | 444 | $response = new WP_REST_Response(array('error' => 'Bad request'), 400); 445 | 446 | } 447 | 448 | if (get_option('v3d_cross_domain')) 449 | $response->header('Access-Control-Allow-Origin', '*'); 450 | 451 | return $response; 452 | 453 | } 454 | 455 | add_action('rest_api_init', function () { 456 | if (get_option('v3d_product_api')) { 457 | register_rest_route('verge3d/v1', '/get_product_info/(?P.+)', array( 458 | 'methods' => 'GET', 459 | 'callback' => 'v3d_api_get_product_info', 460 | 'args' => array( 461 | 'sku' => array( 462 | 'validate_callback' => function($param, $request, $key) { 463 | return is_string($param); 464 | } 465 | ), 466 | ), 467 | 'permission_callback' => '__return_true', 468 | )); 469 | } 470 | }); 471 | -------------------------------------------------------------------------------- /currencies.php: -------------------------------------------------------------------------------- 1 | 'ALL', 5 | 'countryname'=> 'Albania', 6 | 'name'=> 'Albanian lek', 7 | 'symbol'=> 'L'), 8 | 9 | array('code'=> 'AFN', 10 | 'countryname'=> 'Afghanistan', 11 | 'name'=> 'Afghanistan Afghani', 12 | 'symbol'=> '؋'), 13 | 14 | array('code'=> 'ARS', 15 | 'countryname'=> 'Argentina', 16 | 'name'=> 'Argentine Peso', 17 | 'symbol'=> '$'), 18 | 19 | array('code'=> 'AWG', 20 | 'countryname'=> 'Aruba', 21 | 'name'=> 'Aruban florin', 22 | 'symbol'=> 'ƒ'), 23 | 24 | array('code'=> 'AUD', 25 | 'countryname'=> 'Australia', 26 | 'name'=> 'Australian Dollar', 27 | 'symbol'=> 'A$'), 28 | 29 | array('code'=> 'AZN', 30 | 'countryname'=> 'Azerbaijan', 31 | 'name'=> 'Azerbaijani Manat', 32 | 'symbol'=> '₼'), 33 | 34 | array('code'=> 'BSD', 35 | 'countryname'=> 'The Bahamas', 36 | 'name'=> 'Bahamas Dollar', 37 | 'symbol'=> 'B$'), 38 | 39 | array('code'=> 'BBD', 40 | 'countryname'=> 'Barbados', 41 | 'name'=> 'Barbados Dollar', 42 | 'symbol'=> 'Bds$'), 43 | 44 | array('code'=> 'BDT', 45 | 'countryname'=> 'People\'s Republic of Bangladesh', 46 | 'name'=> 'Bangladeshi taka', 47 | 'symbol'=> '৳'), 48 | 49 | array('code'=> 'BYN', 50 | 'countryname'=> 'Belarus', 51 | 'name'=> 'Belarus Ruble', 52 | 'symbol'=> 'Br'), 53 | 54 | array('code'=> 'BZD', 55 | 'countryname'=> 'Belize', 56 | 'name'=> 'Belize Dollar', 57 | 'symbol'=> 'BZ$'), 58 | 59 | array('code'=> 'BMD', 60 | 'countryname'=> 'British Overseas Territory of Bermuda', 61 | 'name'=> 'Bermudian Dollar', 62 | 'symbol'=> 'BD$'), 63 | 64 | array('code'=> 'BOP', 65 | 'countryname'=> 'Bolivia', 66 | 'name'=> 'Boliviano', 67 | 'symbol'=> 'Bs'), 68 | 69 | array('code'=> 'BAM', 70 | 'countryname'=> 'Bosnia and Herzegovina', 71 | 'name'=> 'Bosnia-Herzegovina Convertible Marka', 72 | 'symbol'=> 'KM'), 73 | 74 | array('code'=> 'BWP', 75 | 'countryname'=> 'Botswana', 76 | 'name'=> 'Botswana pula', 77 | 'symbol'=> 'P'), 78 | 79 | array('code'=> 'BGN', 80 | 'countryname'=> 'Bulgaria', 81 | 'name'=> 'Bulgarian lev', 82 | 'symbol'=> 'лв'), 83 | 84 | array('code'=> 'BRL', 85 | 'countryname'=> 'Brazil', 86 | 'name'=> 'Brazilian real', 87 | 'symbol'=> 'R$'), 88 | 89 | array('code'=> 'BND', 90 | 'countryname'=> 'Sultanate of Brunei', 91 | 'name'=> 'Brunei dollar', 92 | 'symbol'=> 'B$'), 93 | 94 | array('code'=> 'KHR', 95 | 'countryname'=> 'Cambodia', 96 | 'name'=> 'Cambodian riel', 97 | 'symbol'=> '៛'), 98 | 99 | array('code'=> 'CAD', 100 | 'countryname'=> 'Canada', 101 | 'name'=> 'Canadian dollar', 102 | 'symbol'=> 'C$'), 103 | 104 | array('code'=> 'KYD', 105 | 'countryname'=> 'Cayman Islands', 106 | 'name'=> 'Cayman Islands dollar', 107 | 'symbol'=> '$'), 108 | 109 | array('code'=> 'CLP', 110 | 'countryname'=> 'Chile', 111 | 'name'=> 'Chilean peso', 112 | 'symbol'=> '$'), 113 | 114 | array('code'=> 'CNY', 115 | 'countryname'=> 'China', 116 | 'name'=> 'Chinese Yuan Renminbi', 117 | 'symbol'=> '¥'), 118 | 119 | array('code'=> 'COP', 120 | 'countryname'=> 'Colombia', 121 | 'name'=> 'Colombian peso', 122 | 'symbol'=> '$'), 123 | 124 | array('code'=> 'CRC', 125 | 'countryname'=> 'Costa Rica', 126 | 'name'=> 'Costa Rican colón', 127 | 'symbol'=> '₡'), 128 | 129 | array('code'=> 'HRK', 130 | 'countryname'=> 'Croatia', 131 | 'name'=> 'Croatian kuna', 132 | 'symbol'=> 'kn'), 133 | 134 | array('code'=> 'CUP', 135 | 'countryname'=> 'Cuba', 136 | 'name'=> 'Cuban peso', 137 | 'symbol'=> '₱'), 138 | 139 | array('code'=> 'CZK', 140 | 'countryname'=> 'Czech Republic', 141 | 'name'=> 'Czech koruna', 142 | 'symbol'=> 'Kč'), 143 | 144 | array('code'=> 'DKK', 145 | 'countryname'=> 'Denmark, Greenland, and the Faroe Islands', 146 | 'name'=> 'Danish krone', 147 | 'symbol'=> 'kr'), 148 | 149 | array('code'=> 'DOP', 150 | 'countryname'=> 'Dominican Republic', 151 | 'name'=> 'Dominican peso', 152 | 'symbol'=> 'RD$'), 153 | 154 | array('code'=> 'XCD', 155 | 'countryname'=> 'Antigua and Barbuda, Commonwealth of Dominica, Grenada, Montserrat, St. Kitts and Nevis, Saint Lucia and St. Vincent and the Grenadines', 156 | 'name'=> 'Eastern Caribbean dollar', 157 | 'symbol'=> '$'), 158 | 159 | array('code'=> 'EGP', 160 | 'countryname'=> 'Egypt', 161 | 'name'=> 'Egyptian pound', 162 | 'symbol'=> '£'), 163 | 164 | array('code'=> 'SVC', 165 | 'countryname'=> 'El Salvador', 166 | 'name'=> 'Salvadoran colón', 167 | 'symbol'=> '$'), 168 | 169 | array('code'=> 'EEK', 170 | 'countryname'=> 'Estonia', 171 | 'name'=> 'Estonian kroon', 172 | 'symbol'=> 'Kr'), 173 | 174 | array('code'=> 'EUR', 175 | 'countryname'=> 'European Union, Italy, Belgium, Bulgaria, Croatia, Cyprus, Czechia, Denmark, Estonia, Finland, France, Germany, 176 | Greece, Hungary, Ireland, Latvia, Lithuania, Luxembourg, Malta, Netherlands, Poland, 177 | Portugal, Romania, Slovakia, Slovenia, Spain, Sweden', 178 | 'name'=> 'Euro', 179 | 'symbol'=> '€'), 180 | 181 | array('code'=> 'FKP', 182 | 'countryname'=> 'Falkland Islands', 183 | 'name'=> 'Falkland Islands (Malvinas) Pound', 184 | 'symbol'=> 'FK£'), 185 | 186 | array('code'=> 'FJD', 187 | 'countryname'=> 'Fiji', 188 | 'name'=> 'Fijian dollar', 189 | 'symbol'=> 'FJ$'), 190 | 191 | array('code'=> 'GHC', 192 | 'countryname'=> 'Ghana', 193 | 'name'=> 'Ghanaian cedi', 194 | 'symbol'=> 'GH¢'), 195 | 196 | array('code'=> 'GIP', 197 | 'countryname'=> 'Gibraltar', 198 | 'name'=> 'Gibraltar pound', 199 | 'symbol'=> '£'), 200 | 201 | array('code'=> 'GTQ', 202 | 'countryname'=> 'Guatemala', 203 | 'name'=> 'Guatemalan quetzal', 204 | 'symbol'=> 'Q'), 205 | 206 | array('code'=> 'GGP', 207 | 'countryname'=> 'Guernsey', 208 | 'name'=> 'Guernsey pound', 209 | 'symbol'=> 'Q'), 210 | 211 | array('code'=> 'GYD', 212 | 'countryname'=> 'Guyana', 213 | 'name'=> 'Guyanese dollar', 214 | 'symbol'=> 'GY$'), 215 | 216 | array('code'=> 'HNL', 217 | 'countryname'=> 'Honduras', 218 | 'name'=> 'Honduran lempira', 219 | 'symbol'=> 'L'), 220 | 221 | array('code'=> 'HKD', 222 | 'countryname'=> 'Hong Kong', 223 | 'name'=> 'Hong Kong dollar', 224 | 'symbol'=> 'HK$'), 225 | 226 | array('code'=> 'HUF', 227 | 'countryname'=> 'Hungary', 228 | 'name'=> 'Hungarian forint', 229 | 'symbol'=> 'Ft'), 230 | 231 | array('code'=> 'ISK', 232 | 'countryname'=> 'Iceland', 233 | 'name'=> 'Icelandic króna', 234 | 'symbol'=> 'íkr'), 235 | 236 | array('code'=> 'INR', 237 | 'countryname'=> 'India', 238 | 'name'=> 'Indian rupee', 239 | 'symbol'=> '₹'), 240 | 241 | array('code'=> 'IDR', 242 | 'countryname'=> 'Indonesia', 243 | 'name'=> 'Indonesian rupiah', 244 | 'symbol'=> 'Rp'), 245 | 246 | array('code'=> 'IRR', 247 | 'countryname'=> 'Iran', 248 | 'name'=> 'Iranian rial', 249 | 'symbol'=> '﷼'), 250 | 251 | array('code'=> 'IMP', 252 | 'countryname'=> 'Isle of Man', 253 | 'name'=> 'Manx pound', 254 | 'symbol'=> '£'), 255 | 256 | array('code'=> 'ILS', 257 | 'countryname'=> 'Israel, Palestinian territories of the West Bank and the Gaza Strip', 258 | 'name'=> 'Israeli Shekel', 259 | 'symbol'=> '₪'), 260 | 261 | array('code'=> 'JMD', 262 | 'countryname'=> 'Jamaica', 263 | 'name'=> 'Jamaican dollar', 264 | 'symbol'=> 'J$'), 265 | 266 | array('code'=> 'JPY', 267 | 'countryname'=> 'Japan', 268 | 'name'=> 'Japanese yen', 269 | 'symbol'=> '¥'), 270 | 271 | array('code'=> 'JEP', 272 | 'countryname'=> 'Jersey', 273 | 'name'=> 'Jersey pound', 274 | 'symbol'=> '£'), 275 | 276 | array('code'=> 'KZT', 277 | 'countryname'=> 'Kazakhstan', 278 | 'name'=> 'Kazakhstani tenge', 279 | 'symbol'=> '₸'), 280 | 281 | array('code'=> 'KPW', 282 | 'countryname'=> 'North Korea', 283 | 'name'=> 'North Korean won', 284 | 'symbol'=> '₩'), 285 | 286 | array('code'=> 'KPW', 287 | 'countryname'=> 'South Korea', 288 | 'name'=> 'South Korean won', 289 | 'symbol'=> '₩'), 290 | 291 | array('code'=> 'KGS', 292 | 'countryname'=> 'Kyrgyz Republic', 293 | 'name'=> 'Kyrgyzstani som', 294 | 'symbol'=> 'лв'), 295 | 296 | array('code'=> 'LAK', 297 | 'countryname'=> 'Laos', 298 | 'name'=> 'Lao kip', 299 | 'symbol'=> '₭'), 300 | 301 | array('code'=> 'LAK', 302 | 'countryname'=> 'Laos', 303 | 'name'=> 'Latvian lats', 304 | 'symbol'=> '€'), 305 | 306 | array('code'=> 'LVL', 307 | 'countryname'=> 'Laos', 308 | 'name'=> 'Latvian lats', 309 | 'symbol'=> '€'), 310 | 311 | array('code'=> 'LBP', 312 | 'countryname'=> 'Lebanon', 313 | 'name'=> 'Lebanese pound', 314 | 'symbol'=> 'L£'), 315 | 316 | array('code'=> 'LRD', 317 | 'countryname'=> 'Liberia', 318 | 'name'=> 'Liberian dollar', 319 | 'symbol'=> 'LD$'), 320 | 321 | array('code'=> 'LTL', 322 | 'countryname'=> 'Lithuania', 323 | 'name'=> 'Lithuanian litas', 324 | 'symbol'=> '€'), 325 | 326 | array('code'=> 'MKD', 327 | 'countryname'=> 'North Macedonia', 328 | 'name'=> 'Macedonian denar', 329 | 'symbol'=> 'ден'), 330 | 331 | array('code'=> 'MYR', 332 | 'countryname'=> 'Malaysia', 333 | 'name'=> 'Malaysian ringgit', 334 | 'symbol'=> 'RM'), 335 | 336 | array('code'=> 'MUR', 337 | 'countryname'=> 'Mauritius', 338 | 'name'=> 'Mauritian rupee', 339 | 'symbol'=> 'Rs'), 340 | 341 | array('code'=> 'MXN', 342 | 'countryname'=> 'Mexico', 343 | 'name'=> 'Mexican peso', 344 | 'symbol'=> 'Mex$'), 345 | 346 | array('code'=> 'MNT', 347 | 'countryname'=> 'Mongolia', 348 | 'name'=> 'Mongolian tögrög', 349 | 'symbol'=> '₮'), 350 | 351 | 352 | array('code'=> 'MZN', 353 | 'countryname'=> 'Mozambique', 354 | 'name'=> 'Mozambican metical', 355 | 'symbol'=> 'MT'), 356 | 357 | array('code'=> 'NAD', 358 | 'countryname'=> 'Namibia', 359 | 'name'=> 'Namibian dollar', 360 | 'symbol'=> 'N$'), 361 | 362 | array('code'=> 'NPR', 363 | 'countryname'=> 'Federal Democratic Republic of Nepal', 364 | 'name'=> 'Nepalese rupee', 365 | 'symbol'=> 'Rs.'), 366 | 367 | array('code'=> 'ANG', 368 | 'countryname'=> 'Curaçao and Sint Maarten', 369 | 'name'=> 'Netherlands Antillean guilder', 370 | 'symbol'=> 'ƒ'), 371 | 372 | array('code'=> 'NZD', 373 | 'countryname'=> 'New Zealand, the Cook Islands, Niue, the Ross Dependency, Tokelau, the Pitcairn Islands', 374 | 'name'=> 'New Zealand dollar', 375 | 'symbol'=> '$'), 376 | 377 | 378 | array('code'=> 'NIO', 379 | 'countryname'=> 'Nicaragua', 380 | 'name'=> 'Nicaraguan córdoba', 381 | 'symbol'=> 'C$'), 382 | 383 | array('code'=> 'NGN', 384 | 'countryname'=> 'Nigeria', 385 | 'name'=> 'Nigerian naira', 386 | 'symbol'=> '₦'), 387 | 388 | array('code'=> 'NOK', 389 | 'countryname'=> 'Norway and its dependent territories', 390 | 'name'=> 'Norwegian krone', 391 | 'symbol'=> 'kr'), 392 | 393 | array('code'=> 'OMR', 394 | 'countryname'=> 'Oman', 395 | 'name'=> 'Omani rial', 396 | 'symbol'=> '﷼'), 397 | 398 | array('code'=> 'PKR', 399 | 'countryname'=> 'Pakistan', 400 | 'name'=> 'Pakistani rupee', 401 | 'symbol'=> 'Rs'), 402 | 403 | array('code'=> 'PAB', 404 | 'countryname'=> 'Panama', 405 | 'name'=> 'Panamanian balboa', 406 | 'symbol'=> 'B/.'), 407 | 408 | array('code'=> 'PYG', 409 | 'countryname'=> 'Paraguay', 410 | 'name'=> 'Paraguayan Guaraní', 411 | 'symbol'=> '₲'), 412 | 413 | array('code'=> 'PEN', 414 | 'countryname'=> 'Peru', 415 | 'name'=> 'Sol', 416 | 'symbol'=> 'S/.'), 417 | 418 | array('code'=> 'PHP', 419 | 'countryname'=> 'Philippines', 420 | 'name'=> 'Philippine peso', 421 | 'symbol'=> '₱'), 422 | 423 | array('code'=> 'PLN', 424 | 'countryname'=> 'Poland', 425 | 'name'=> 'Polish złoty', 426 | 'symbol'=> 'zł'), 427 | 428 | array('code'=> 'QAR', 429 | 'countryname'=> 'State of Qatar', 430 | 'name'=> 'Qatari Riyal', 431 | 'symbol'=> '﷼'), 432 | 433 | array('code'=> 'RON', 434 | 'countryname'=> 'Romania', 435 | 'name'=> 'Romanian leu (Leu românesc)', 436 | 'symbol'=> 'L'), 437 | 438 | array('code'=> 'RUB', 439 | 'countryname'=> 'Russian Federation, Abkhazia and South Ossetia, Donetsk and Luhansk', 440 | 'name'=> 'Russian ruble', 441 | 'symbol'=> '₽'), 442 | 443 | array('code'=> 'SHP', 444 | 'countryname'=> 'Saint Helena, Ascension and Tristan da Cunha', 445 | 'name'=> 'Saint Helena pound', 446 | 'symbol'=> '£'), 447 | 448 | array('code'=> 'SAR', 449 | 'countryname'=> 'Saudi Arabia', 450 | 'name'=> 'Saudi riyal', 451 | 'symbol'=> '﷼'), 452 | 453 | array('code'=> 'RSD', 454 | 'countryname'=> 'Serbia', 455 | 'name'=> 'Serbian dinar', 456 | 'symbol'=> 'din'), 457 | 458 | array('code'=> 'SCR', 459 | 'countryname'=> 'Seychelles', 460 | 'name'=> 'Seychellois rupee', 461 | 'symbol'=> 'Rs'), 462 | 463 | array('code'=> 'SGD', 464 | 'countryname'=> 'Singapore', 465 | 'name'=> 'Singapore dollar', 466 | 'symbol'=> 'S$'), 467 | 468 | array('code'=> 'SBD', 469 | 'countryname'=> 'Solomon Islands', 470 | 'name'=> 'Solomon Islands dollar', 471 | 'symbol'=> 'SI$'), 472 | 473 | array('code'=> 'SOS', 474 | 'countryname'=> 'Somalia', 475 | 'name'=> 'Somali shilling', 476 | 'symbol'=> 'Sh.So'), 477 | 478 | array('code'=> 'ZAR', 479 | 'countryname'=> 'South Africa', 480 | 'name'=> 'South African rand', 481 | 'symbol'=> 'R'), 482 | 483 | array('code'=> 'LKR', 484 | 'countryname'=> 'Sri Lanka', 485 | 'name'=> 'Sri Lankan rupee', 486 | 'symbol'=> 'Rs'), 487 | 488 | 489 | array('code'=> 'SEK', 490 | 'countryname'=> 'Sweden', 491 | 'name'=> 'Swedish krona', 492 | 'symbol'=> 'kr'), 493 | 494 | 495 | array('code'=> 'CHF', 496 | 'countryname'=> 'Switzerland', 497 | 'name'=> 'Swiss franc', 498 | 'symbol'=> 'CHf'), 499 | 500 | array('code'=> 'SRD', 501 | 'countryname'=> 'Suriname', 502 | 'name'=> 'Suriname Dollar', 503 | 'symbol'=> 'Sr$'), 504 | 505 | array('code'=> 'SYP', 506 | 'countryname'=> 'Syria', 507 | 'name'=> 'Syrian pound', 508 | 'symbol'=> '£S'), 509 | 510 | array('code'=> 'TWD', 511 | 'countryname'=> 'Taiwan', 512 | 'name'=> 'New Taiwan dollar', 513 | 'symbol'=> 'NT$'), 514 | 515 | 516 | array('code'=> 'THB', 517 | 'countryname'=> 'Thailand', 518 | 'name'=> 'Thai baht', 519 | 'symbol'=> '฿'), 520 | 521 | 522 | array('code'=> 'TTD', 523 | 'countryname'=> 'Trinidad and Tobago', 524 | 'name'=> 'Trinidad and Tobago dollar', 525 | 'symbol'=> 'TT$'), 526 | 527 | array('code'=> 'TRY', 528 | 'countryname'=> 'Turkey, Turkish Republic of Northern Cyprus', 529 | 'name'=> 'Turkey Lira', 530 | 'symbol'=> '₺'), 531 | 532 | array('code'=> 'TVD', 533 | 'countryname'=> 'Tuvalu', 534 | 'name'=> 'Tuvaluan dollar', 535 | 'symbol'=> 'TV$'), 536 | 537 | array('code'=> 'UAH', 538 | 'countryname'=> 'Ukraine', 539 | 'name'=> 'Ukrainian hryvnia', 540 | 'symbol'=> '₴'), 541 | 542 | array('code'=> 'GBP', 543 | 'countryname'=> 'United Kingdom, Jersey, Guernsey, the Isle of Man, Gibraltar, South Georgia and the South Sandwich Islands, the British Antarctic Territory, and Tristan da Cunha', 544 | 'name'=> 'Pound sterling', 545 | 'symbol'=> '£'), 546 | 547 | array('code'=> 'UGX', 548 | 'countryname'=> 'Uganda', 549 | 'name'=> 'Ugandan shilling', 550 | 'symbol'=> 'USh'), 551 | 552 | 553 | array('code'=> 'USD', 554 | 'countryname'=> 'United States', 555 | 'name'=> 'United States dollar', 556 | 'symbol'=> '$'), 557 | 558 | array('code'=> 'UYU', 559 | 'countryname'=> 'Uruguayan', 560 | 'name'=> 'Peso Uruguayolar', 561 | 'symbol'=> '$U'), 562 | 563 | array('code'=> 'UZS', 564 | 'countryname'=> 'Uzbekistan', 565 | 'name'=> 'Uzbekistani soʻm', 566 | 'symbol'=> 'лв'), 567 | 568 | array('code'=> 'VEF', 569 | 'countryname'=> 'Venezuela', 570 | 'name'=> 'Venezuelan bolívar', 571 | 'symbol'=> 'Bs'), 572 | 573 | array('code'=> 'VND', 574 | 'countryname'=> 'Vietnam', 575 | 'name'=> 'Vietnamese dong (Đồng)', 576 | 'symbol'=> '₫'), 577 | 578 | array('code'=> 'VND', 579 | 'countryname'=> 'Yemen', 580 | 'name'=> 'Yemeni rial', 581 | 'symbol'=> '﷼'), 582 | 583 | array('code'=> 'ZWD', 584 | 'countryname'=> 'Zimbabwe', 585 | 'name'=> 'Zimbabwean dollar', 586 | 'symbol'=> 'Z$'), 587 | ); 588 | 589 | function v3d_currency_name() { 590 | $currency = get_option('v3d_currency'); 591 | 592 | global $v3d_currencies; 593 | 594 | foreach ($v3d_currencies as $c) { 595 | if ($c['code'] == $currency) 596 | return $c['name']; 597 | } 598 | 599 | return ''; 600 | } 601 | 602 | function v3d_currency_symbol() { 603 | $currency = get_option('v3d_currency'); 604 | 605 | global $v3d_currencies; 606 | 607 | foreach ($v3d_currencies as $c) { 608 | if ($c['code'] == $currency) 609 | return $c['symbol']; 610 | } 611 | 612 | return ''; 613 | } 614 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /app.php: -------------------------------------------------------------------------------- 1 | 28 | 29 |
30 |

New Verge3D application

31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 43 | 44 |
40 | 41 |
45 |

46 |
47 |
48 | 49 | (!empty($_REQUEST['title'])) ? 57 | sanitize_text_field($_REQUEST['title']) : 'My App', 58 | 'post_status' => 'publish', 59 | 'post_type' => 'v3d_app', 60 | 'meta_input' => array( 61 | 'canvas_width' => V3D_DEFAULT_CANVAS_WIDTH, 62 | 'canvas_height' => V3D_DEFAULT_CANVAS_HEIGHT, 63 | 'allow_fullscreen' => 1, 64 | 'xr_spatial_tracking' => 1, 65 | 'loading' => 'auto', 66 | ), 67 | ); 68 | $app_id = wp_insert_post($post_arr); 69 | v3d_redirect_app($app_id); 70 | break; 71 | 72 | case 'edit': 73 | $app_id = intval($_REQUEST['app']); 74 | 75 | if (empty($app_id)) { 76 | echo 'Bad request'; 77 | return; 78 | } 79 | 80 | $title = get_the_title($app_id); 81 | 82 | $canvas_width = get_post_meta($app_id, 'canvas_width', true); 83 | $canvas_height = get_post_meta($app_id, 'canvas_height', true); 84 | $allow_fullscreen = get_post_meta($app_id, 'allow_fullscreen', true); 85 | $xr_spatial_tracking = get_post_meta($app_id, 'xr_spatial_tracking', true); 86 | $loading = get_post_meta($app_id, 'loading', true); 87 | $cover_att_id = get_post_meta($app_id, 'cover_attachment_id', true); 88 | 89 | $cover_src = wp_get_attachment_image_src($cover_att_id, 'full'); 90 | $has_cover = is_array($cover_src); 91 | 92 | $upload_stats = v3d_get_upload_stats($app_id); 93 | 94 | wp_enqueue_media(); 95 | wp_enqueue_script('v3d_media_script', plugin_dir_url( __FILE__ ) . 'js/admin-media.js'); 96 | 97 | ?> 98 |
99 |

Manage Verge3D Application

100 |

Settings

101 | 102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 113 | 116 | 117 | 118 | 121 | 124 | 125 | 126 | 129 | 132 | 133 | 134 | 137 | 140 | 141 | 142 | 145 | 148 | 149 | 150 | 153 | 160 | 161 | 162 | 165 | 175 | 176 | 177 |
111 | 112 | 114 | 115 |
119 | 120 | 122 | 123 |
127 | 128 | 130 | 131 |
135 | 136 | 138 | > 139 |
143 | 144 | 146 | > 147 |
151 | 152 | 154 | 159 |
163 | 164 | 166 |
167 | 168 | 169 | 170 |
171 | 172 | 173 | 174 |
178 |

179 |
180 | 181 |

Files

182 |
183 | 184 | 185 | 186 | 189 | 196 | 197 | 198 | 201 | 207 | 208 | 209 |
187 | 188 | 190 | 191 | Stored files with total size . 192 | 193 | No files uploaded yet. 194 | 195 |
199 | 200 | 202 | 203 | 204 | 205 | 206 |
210 |
211 |
212 | $app_id, 232 | 'post_title' => $title, 233 | 'meta_input' => array( 234 | 'canvas_width' => $canvas_width, 235 | 'canvas_height' => $canvas_height, 236 | 'allow_fullscreen' => $allow_fullscreen, 237 | 'xr_spatial_tracking' => $xr_spatial_tracking, 238 | 'loading' => $loading, 239 | 'cover_attachment_id' => $cover_att_id, 240 | ), 241 | ); 242 | wp_update_post($post_arr); 243 | } 244 | 245 | v3d_redirect_app($app_id); 246 | } else { 247 | echo 'Bad request'; 248 | return; 249 | } 250 | 251 | break; 252 | 253 | case 'delete': 254 | if (!empty($_REQUEST['app'])) { 255 | $app = $_REQUEST['app']; 256 | 257 | // process bulk request 258 | if (is_array($app)) { 259 | check_admin_referer('bulk-' . $appTable->_args['plural']); 260 | 261 | foreach ($app as $a) 262 | if (!empty(intval($a))) 263 | v3d_delete_app(intval($a)); 264 | } else { 265 | check_admin_referer('app-delete'); 266 | 267 | if (!empty(intval($app))) 268 | v3d_delete_app(intval($app)); 269 | } 270 | 271 | v3d_redirect_app(); 272 | } else { 273 | echo 'Bad request'; 274 | return; 275 | } 276 | 277 | break; 278 | 279 | default: 280 | $appTable->prepare_items(); 281 | 282 | ?> 283 |
284 |

285 |

Verge3D Applications

286 | Add New 287 | 288 |
289 |

Use [verge3d id=""] shortcode to embed Verge3D applications in your pages/posts.

290 |
291 | 292 |
293 | 294 | 295 | 296 | 302 | display() ?> 303 |
304 |
305 | '.' && $t <> '..') { 319 | list($num, $size) = v3d_foldersize(rtrim($path, '/') . '/' . $t); 320 | $num_files += $num; 321 | $total_size += $size; 322 | } 323 | } else { 324 | $num_files +=1; 325 | $total_size += filesize(rtrim($path, '/') . '/' . $t); 326 | } 327 | } 328 | return [$num_files, $total_size]; 329 | } 330 | 331 | function v3d_get_upload_stats($app_id) { 332 | $upload_dir = v3d_get_upload_dir(); 333 | $upload_app_dir = $upload_dir.$app_id; 334 | 335 | if (is_dir($upload_app_dir)) { 336 | return v3d_foldersize($upload_app_dir); 337 | } else 338 | return null; 339 | } 340 | 341 | function v3d_format_size($size) { 342 | $mod = 1024; 343 | $units = explode(' ', 'B KB MB GB TB PB'); 344 | for ($i = 0; $size > $mod; $i++) { 345 | $size /= $mod; 346 | } 347 | return round($size, 2) . ' ' . $units[$i]; 348 | } 349 | 350 | 351 | function v3d_delete_app($app_id) { 352 | wp_delete_post($app_id); 353 | 354 | $upload_dir = v3d_get_upload_dir(); 355 | $upload_app_dir = $upload_dir.$app_id; 356 | 357 | if (is_dir($upload_app_dir)) 358 | v3d_rmdir($upload_app_dir); 359 | } 360 | 361 | 362 | class V3D_App_List_Table extends WP_List_Table { 363 | 364 | function __construct(){ 365 | // set parent defaults 366 | parent::__construct(array( 367 | 'singular' => 'app', 368 | 'plural' => 'apps', 369 | 'ajax' => false 370 | )); 371 | } 372 | 373 | function column_default($item, $column_name) { 374 | switch( $column_name){ 375 | case 'shortcode': 376 | case 'url': 377 | case 'date': 378 | return $item[$column_name]; 379 | default: 380 | return print_r($item, true); //Show the whole array for troubleshooting purposes 381 | } 382 | } 383 | 384 | function column_title($item) { 385 | // build row actions 386 | 387 | $edit_url = sprintf('?page=%s&action=edit&app=%s', esc_attr($_REQUEST['page']), $item['ID']); 388 | $edit_url = wp_nonce_url($edit_url, 'app-edit'); 389 | $delete_url = sprintf('?page=%s&action=delete&app=%s', esc_attr($_REQUEST['page']), $item['ID']); 390 | $delete_url = wp_nonce_url($delete_url, 'app-delete'); 391 | 392 | $actions = array( 393 | 'edit' => 'Edit', 394 | 'delete' => 'Delete' 395 | ); 396 | 397 | // return the title contents 398 | return sprintf('%1$s (id:%2$s)%3$s', 399 | /*$1%s*/ $item['title'], 400 | /*$2%s*/ $item['ID'], 401 | /*$3%s*/ $this->row_actions($actions) 402 | ); 403 | } 404 | 405 | function column_cb($item){ 406 | return sprintf( 407 | '', 408 | /*$1%s*/ $this->_args['singular'], // simply repurpose the table's singular label ("movie") 409 | /*$2%s*/ $item['ID'] // the value of the checkbox should be the record's id 410 | ); 411 | } 412 | 413 | function get_columns(){ 414 | $columns = array( 415 | 'cb' => '', // render a checkbox instead of text 416 | 'title' => 'Title', 417 | 'shortcode' => 'Shortcode', 418 | 'url' => 'URL', 419 | 'date' => 'Date' 420 | ); 421 | return $columns; 422 | } 423 | 424 | function get_sortable_columns() { 425 | $sortable_columns = array( 426 | 'title' => array('title', false), // true means it's already sorted 427 | 'date' => array('date', false) 428 | ); 429 | return $sortable_columns; 430 | } 431 | 432 | function get_bulk_actions() { 433 | $actions = array( 434 | 'delete' => 'Delete' 435 | ); 436 | return $actions; 437 | } 438 | 439 | function prepare_items() { 440 | $per_page = 15; 441 | 442 | $columns = $this->get_columns(); 443 | $hidden = array(); 444 | $sortable = $this->get_sortable_columns(); 445 | 446 | $this->_column_headers = array($columns, $hidden, $sortable); 447 | 448 | // if no sort, default to title 449 | $orderby = (!empty($_REQUEST['orderby'])) ? 450 | sanitize_text_field($_REQUEST['orderby']) : 'title'; 451 | // if no order, default to asc 452 | $order = (!empty($_REQUEST['order'])) ? 453 | sanitize_text_field($_REQUEST['order']) : 'ASC'; 454 | 455 | $args = array( 456 | 'posts_per_page' => -1, 457 | 'offset' => 0, 458 | 'category' => '', 459 | 'category_name' => '', 460 | 'orderby' => $orderby, 461 | 'order' => $order, 462 | 'include' => '', 463 | 'exclude' => '', 464 | 'meta_key' => '', 465 | 'meta_value' => '', 466 | 'post_type' => 'v3d_app', 467 | 'post_mime_type' => '', 468 | 'post_parent' => '', 469 | 'author' => '', 470 | 'author_name' => '', 471 | 'post_status' => 'publish', 472 | 'suppress_filters' => true, 473 | 'fields' => '', 474 | ); 475 | $q_posts = get_posts($args); 476 | 477 | $posts = array(); 478 | 479 | 480 | foreach ($q_posts as $q_post) { 481 | $url = v3d_get_app_url($q_post->ID); 482 | $id = $q_post->ID; 483 | $posts[] = array( 484 | 'ID' => $id, 485 | 'title' => $q_post->post_title, 486 | 'shortcode' => '[verge3d id="' . $q_post->ID . '"]', 487 | 'url' => sprintf('%s', $url, basename($url)), 488 | 'date' => get_the_time(get_option('date_format').' '.get_option('time_format'), $id), 489 | ); 490 | } 491 | 492 | $current_page = $this->get_pagenum(); 493 | 494 | $total_items = count($posts); 495 | 496 | $posts = array_slice($posts, (($current_page-1)*$per_page), $per_page); 497 | 498 | $this->items = $posts; 499 | 500 | $this->set_pagination_args( array( 501 | 'total_items' => $total_items, 502 | 'per_page' => $per_page, 503 | 'total_pages' => ceil($total_items/$per_page) 504 | ) ); 505 | } 506 | } 507 | 508 | function v3d_iframe_allow_html($name, $value) { 509 | if (!empty($value)) 510 | return $name.';'; 511 | else 512 | return $name.' \'none\';'; 513 | } 514 | 515 | function v3d_gen_app_iframe_html($app_id, $wrap_to_figure=false) { 516 | $url = v3d_get_app_url($app_id); 517 | if (empty($url)) 518 | return ''; 519 | 520 | $canvas_width = get_post_meta($app_id, 'canvas_width', true); 521 | $canvas_height = get_post_meta($app_id, 'canvas_height', true); 522 | $allow_fullscreen = get_post_meta($app_id, 'allow_fullscreen', true); 523 | $xr_spatial_tracking = get_post_meta($app_id, 'xr_spatial_tracking', true); 524 | $loading = get_post_meta($app_id, 'loading', true); 525 | 526 | ob_start(); 527 | ?> 528 | ' : ''; ?> 529 | 535 | ' : ''; ?> 536 | ''], $atts, $tag); 544 | 545 | $app_id = $v3d_atts['id']; 546 | 547 | return v3d_gen_app_iframe_html($app_id, true); 548 | } 549 | 550 | function v3d_shortcodes_init() { 551 | add_shortcode('verge3d', 'v3d_shortcode'); 552 | } 553 | add_action('init', 'v3d_shortcodes_init'); 554 | 555 | 556 | function v3d_redirect_app($app_id=-1) { 557 | 558 | $params = '?page=verge3d_app'; 559 | 560 | if ($app_id > -1) { 561 | $params .= ('&action=edit&app='.$app_id); 562 | } 563 | 564 | ?> 565 | 568 | admin_url('admin-ajax.php'), 615 | 'security' => wp_create_nonce('v3d_app_ajax_action') 616 | )); 617 | } 618 | add_action('admin_enqueue_scripts', 'v3d_enqueue_upload_script'); 619 | 620 | 621 | add_action('wp_ajax_v3d_upload_app_file', 'v3d_upload_app_file'); 622 | 623 | function v3d_upload_app_file() { 624 | 625 | if (!current_user_can('manage_verge3d')) 626 | wp_die('error'); 627 | 628 | check_ajax_referer('v3d_app_ajax_action', 'security', true); 629 | 630 | $count = 0; 631 | 632 | if (!empty($_REQUEST['app'])) { 633 | $app_id = intval($_REQUEST['app']); 634 | } else { 635 | wp_die('error'); 636 | } 637 | 638 | $upload_dir = v3d_get_upload_dir(); 639 | $upload_app_dir = $upload_dir.$app_id; 640 | 641 | if (!is_dir($upload_app_dir)) 642 | mkdir($upload_app_dir, 0777, true); 643 | 644 | if (!empty($_FILES['appfile'])) { 645 | if (strlen($_FILES['appfile']['name']) > 1 && $_FILES['appfile']['error'] == UPLOAD_ERR_OK) { 646 | $fullpath = strip_tags(sanitize_text_field($_REQUEST['apppath'])); 647 | 648 | // strip first directory name 649 | $fullpath = explode("/", $fullpath); 650 | array_shift($fullpath); 651 | $fullpath = implode("/", $fullpath); 652 | 653 | // prevent harmful file types to be uploaded to the server 654 | $validate = wp_check_filetype($fullpath, v3d_get_allowed_mime_types()); 655 | if ($validate['type'] === false) { 656 | wp_die('error'); 657 | } 658 | 659 | $path = dirname($fullpath); 660 | 661 | if (!is_dir($upload_app_dir.'/'.$path)) { 662 | mkdir($upload_app_dir.'/'.$path); 663 | } 664 | 665 | if (isset($_REQUEST['chunk']) && isset($_REQUEST['maxchunks'])) { 666 | $postfix = '.uploadpart.' . intval($_REQUEST['chunk']); 667 | } else { 668 | $postfix = ''; 669 | } 670 | 671 | if (!move_uploaded_file($_FILES['appfile']['tmp_name'], $upload_app_dir.'/'.$fullpath.$postfix)) { 672 | wp_die('error'); 673 | } 674 | 675 | if (!empty($postfix)) { 676 | $chunks = glob($upload_app_dir.'/'.$fullpath.'.uploadpart.*'); 677 | 678 | if (count($chunks) == intval($_REQUEST['maxchunks'])) { 679 | sort($chunks, SORT_NATURAL); 680 | $final_file = fopen($upload_app_dir.'/'.$fullpath, 'w'); 681 | 682 | foreach ($chunks as $chunk) { 683 | $chunk_data = file_get_contents($chunk); 684 | fwrite($final_file, $chunk_data); 685 | unlink($chunk); 686 | } 687 | 688 | fclose($final_file); 689 | } 690 | } 691 | 692 | wp_die('ok'); 693 | 694 | } 695 | } 696 | 697 | wp_die('error'); 698 | } 699 | 700 | 701 | add_action('wp_ajax_v3d_cleanup_app', 'v3d_cleanup_app'); 702 | 703 | function v3d_cleanup_app() { 704 | 705 | if (!current_user_can('manage_verge3d')) 706 | wp_die('error'); 707 | 708 | check_ajax_referer('v3d_app_ajax_action', 'security', true); 709 | 710 | if (!empty($_REQUEST['app'])) { 711 | $app_id = intval($_REQUEST['app']); 712 | } else { 713 | wp_die('error'); 714 | } 715 | 716 | $upload_dir = v3d_get_upload_dir(); 717 | $upload_app_dir = $upload_dir.$app_id; 718 | 719 | if (is_dir($upload_app_dir)) { 720 | v3d_rmdir($upload_app_dir, false); 721 | } 722 | 723 | wp_die('ok'); 724 | } 725 | --------------------------------------------------------------------------------