Changeset 2045208
- Timestamp:
- 03/06/2019 12:29:30 PM (7 years ago)
- Location:
- verge3d/trunk
- Files:
-
- 2 added
- 4 edited
-
file_storage.php (added)
-
order.php (modified) (18 diffs)
-
readme.txt (modified) (3 diffs)
-
templates/order_email_body.php (modified) (3 diffs)
-
templates/order_email_pdf.php (added)
-
verge3d.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
verge3d/trunk/order.php
r2026454 r2045208 88 88 <p>Specify the link to that page/post in the "send order" puzzle to make it work.</p> 89 89 </div> 90 90 91 91 <form id="orders-filter" method="get"> 92 92 <!-- For plugins, we also need to ensure that the form posts back to our current page --> … … 110 110 ); 111 111 wp_insert_post($post_arr); 112 112 113 113 $order_email = get_option('v3d_order_email'); 114 114 $order_from_name = get_option('v3d_order_email_from_name'); 115 115 $order_from_email = get_option('v3d_order_email_from_email'); 116 116 117 $headers[] = 'Content-Type: text/html; charset=UTF-8';118 if (!empty($order_from_name) || !empty($order_from_email)) {119 $headers[] = 'From: "'.$order_from_name.'" <'.$order_from_email.'>';120 }121 122 ob_start();123 include v3d_get_template('order_email_body.php');124 $body_template = ob_get_clean();125 126 117 $attachments = array(); 127 if (!empty($order['screenshot'])) { 128 $scr_file = v3d_get_upload_dir().'screenshots/'.basename($order['screenshot']); 129 if (is_file($scr_file)) 130 $attachments[] = $scr_file; 118 119 if (!empty($order_email) || !empty($order['user_email'])) { 120 $headers[] = 'Content-Type: text/html; charset=UTF-8'; 121 if (!empty($order_from_name) || !empty($order_from_email)) { 122 $headers[] = 'From: "'.$order_from_name.'" <'.$order_from_email.'>'; 123 } 124 125 $attachments = v3d_gen_email_attachments($order, get_option('v3d_order_email_attach_pdf')); 131 126 } 132 127 … … 134 129 $to = $order_email; 135 130 $subject = 'New order notification'; 136 $body = $body_template; 131 132 ob_start(); 133 include v3d_get_template('order_email_body.php'); 134 $body = ob_get_clean(); 135 137 136 wp_mail($to, $subject, $body, $headers, $attachments); 138 137 } … … 141 140 $to = $order['user_email']; 142 141 $subject = 'Order notification'; 143 $body = $body_template; 142 143 ob_start(); 144 include v3d_get_template('order_email_body.php'); 145 $body = ob_get_clean(); 146 144 147 wp_mail($to, $subject, $body, $headers, $attachments); 145 148 } 149 150 v3d_cleanup_email_attachments($attachments); 151 } 152 153 /** 154 * Exec external program in a portable way 155 * https://www.binarytides.com/execute-shell-commands-php/ 156 */ 157 function v3d_terminal($command) { 158 // system 159 if (function_exists('system')) { 160 ob_start(); 161 system($command , $return_var); 162 $output = ob_get_contents(); 163 ob_end_clean(); 164 } 165 // passthru 166 else if (function_exists('passthru')) { 167 ob_start(); 168 passthru($command , $return_var); 169 $output = ob_get_contents(); 170 ob_end_clean(); 171 } 172 // exec 173 else if (function_exists('exec')) { 174 exec($command , $output , $return_var); 175 $output = implode("n" , $output); 176 } 177 // shell_exec 178 else if (function_exists('shell_exec')) { 179 $output = shell_exec($command) ; 180 } 181 else { 182 $output = 'Command execution not possible on this system'; 183 $return_var = 1; 184 } 185 186 return array('output' => $output , 'status' => $return_var); 187 } 188 189 function v3d_get_chrome_path() { 190 191 $chrome_path = get_option('v3d_chrome_path'); 192 193 if (!empty($chrome_path)) 194 return $chrome_path; 195 196 # perform search in system paths 197 198 $CHROME_PATHS = [ 199 'chromium-browser', 200 'google-chrome', 201 'chromium' 202 ]; 203 204 foreach ($CHROME_PATHS as $p) { 205 if (v3d_terminal($p.' --version')['status'] == 0) 206 return $p; 207 } 208 209 return ''; 210 } 211 212 function v3d_get_attachments_tmp_dir($attachments) { 213 if (empty($attachments)) { 214 $temp_dir = get_temp_dir().uniqid('v3d_email_att'); 215 mkdir($temp_dir, 0777, true); 216 return $temp_dir.'/'; 217 } else { 218 return dirname($attachments[0]).'/'; 219 } 220 } 221 222 function v3d_gen_email_attachments($order, $use_pdf) { 223 224 $attachments = array(); 225 226 if (!empty($order['screenshot'])) { 227 $scr_file = v3d_get_upload_dir().'screenshots/'.basename($order['screenshot']); 228 if (is_file($scr_file)) { 229 $att_path = v3d_get_attachments_tmp_dir($attachments).'order_screenshot.'.pathinfo($scr_file, PATHINFO_EXTENSION); 230 copy($scr_file, $att_path); 231 $attachments[] = $att_path; 232 } 233 } 234 235 if ($use_pdf && is_file(v3d_get_template('order_email_pdf.php'))) { 236 ob_start(); 237 include v3d_get_template('order_email_pdf.php'); 238 $pdf_html_text = ob_get_clean(); 239 } else { 240 return $attachments; 241 } 242 243 $temp_dir = get_temp_dir(); 244 $pdf_html = $temp_dir.wp_unique_filename($temp_dir, uniqid('v3d_email_att').'.html'); 245 $pdf = v3d_get_attachments_tmp_dir($attachments).'order_details.pdf'; 246 247 $success = file_put_contents($pdf_html, $pdf_html_text); 248 if ($success) { 249 250 $chrome_path = v3d_get_chrome_path(); 251 252 if (!empty($chrome_path)) { 253 254 // NOTE: undocumented wkhtmltopdf feature 255 if (basename($chrome_path) == 'wkhtmltopdf') 256 v3d_terminal($chrome_path.' -s Letter --print-media-type '.$pdf_html.' '.$pdf); 257 else 258 v3d_terminal($chrome_path.' --headless --disable-gpu --print-to-pdf='.$pdf.' '.$pdf_html); 259 260 if (is_file($pdf)) 261 $attachments[] = $pdf; 262 } 263 264 @unlink($pdf_html); 265 } 266 267 return $attachments; 268 269 } 270 271 function v3d_cleanup_email_attachments($attachments) { 272 273 if (empty($attachments)) 274 return; 275 276 foreach ($attachments as $a) { 277 @unlink($a); 278 } 279 280 rmdir(v3d_get_attachments_tmp_dir($attachments)); 146 281 } 147 282 … … 193 328 194 329 function v3d_delete_order($order_id) { 195 330 196 331 $scr_url = get_post_meta($order_id, 'screenshot', true); 197 332 … … 210 345 function __construct(){ 211 346 global $status, $page; 212 347 213 348 // Set parent defaults 214 349 parent::__construct( array( … … 217 352 'ajax' => false 218 353 ) ); 219 354 220 355 } 221 356 … … 234 369 235 370 function column_title($item){ 236 371 237 372 // Build row actions 238 373 $actions = array( … … 242 377 sanitize_text_field($_REQUEST['page']), 'delete', $item['ID']), 243 378 ); 244 379 245 380 // Return the title contents 246 381 return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s', … … 298 433 function prepare_items() { 299 434 $per_page = 15; 300 435 301 436 $columns = $this->get_columns(); 302 437 $hidden = array(); 303 438 $sortable = $this->get_sortable_columns(); 304 439 305 440 $this->_column_headers = array($columns, $hidden, $sortable); 306 441 … … 309 444 // if no sort, default to title 310 445 $orderby = (!empty($_REQUEST['orderby'])) ? 311 sanitize_text_field($_REQUEST['orderby']) : 'title'; 446 sanitize_text_field($_REQUEST['orderby']) : 'title'; 312 447 // if no order, default to asc 313 448 $order = (!empty($_REQUEST['order'])) ? 314 sanitize_text_field($_REQUEST['order']) : 'ASC'; 449 sanitize_text_field($_REQUEST['order']) : 'ASC'; 315 450 316 451 $args = array( … … 352 487 ); 353 488 } 354 489 355 490 $current_page = $this->get_pagenum(); 356 491 357 492 $total_items = count($posts); 358 493 359 494 $posts = array_slice($posts, (($current_page-1)*$per_page), $per_page); 360 495 361 496 $this->items = $posts; 362 497 363 498 $this->set_pagination_args( array( 364 499 'total_items' => $total_items, … … 376 511 $atts = array_change_key_case((array)$atts, CASE_LOWER); 377 512 378 $action = (!empty($_REQUEST['v3d_action'])) ? sanitize_text_field($_REQUEST['v3d_action']) : ''; 513 $action = (!empty($_REQUEST['v3d_action'])) ? sanitize_text_field($_REQUEST['v3d_action']) : ''; 379 514 $title = (!empty($_REQUEST['v3d_title'])) ? sanitize_text_field($_REQUEST['v3d_title']) : ''; 380 515 $content = (!empty($_REQUEST['v3d_content'])) ? sanitize_textarea_field($_REQUEST['v3d_content']) : ''; … … 422 557 423 558 $upload_dir = v3d_get_upload_dir(); 424 $screenshot_dir = $upload_dir.'screenshots/'; 559 $screenshot_dir = $upload_dir.'screenshots/'; 425 560 if (!is_dir($screenshot_dir)) { 426 561 mkdir($screenshot_dir, 0777, true); … … 435 570 return ''; 436 571 } 437 572 438 573 function v3d_order_shortcode_init() { 439 574 add_shortcode('verge3d_order', 'v3d_order_shortcode'); … … 452 587 453 588 function v3d_api_place_order(WP_REST_Request $request) { 454 589 455 590 $params = $request->get_json_params(); 456 591 … … 469 604 } else { 470 605 471 $response = new WP_Error('wrong_order_params', 'Wrong order params', array('status' => 400)); 472 473 } 474 475 $response->header('Access-Control-Allow-Origin', '*'); 606 $response = new WP_REST_Response(array('error' => 'Bad request'), 400); 607 608 } 609 610 if (get_option('v3d_cross_domain')) 611 $response->header('Access-Control-Allow-Origin', '*'); 612 476 613 return $response; 477 614 … … 479 616 480 617 add_action('rest_api_init', function () { 481 register_rest_route('verge3d/v1', '/place_order', array( 482 'methods' => 'POST', 483 'callback' => 'v3d_api_place_order', 484 )); 618 if (get_option('v3d_order_api')) { 619 register_rest_route('verge3d/v1', '/place_order', array( 620 'methods' => 'POST', 621 'callback' => 'v3d_api_place_order', 622 )); 623 } 485 624 }); -
verge3d/trunk/readme.txt
r2026454 r2045208 3 3 Tags: verge3d,3d,webgl,3dweb,web3d 4 4 Requires at least: 4.7 5 Tested up to: 4.9.55 Tested up to: 5.1 6 6 Requires PHP: 5.6 7 Stable tag: 2.1 0.07 Stable tag: 2.11.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 15 15 16 16 Verge3D can be used to create product configurators, 3D presentations, online stores, e-learning apps, 3D portfolios, browser games and more. 17 18 You can try this plugin live using this [Sandbox website](https://sandbox.soft8soft.com/). 17 19 18 20 == Installation == … … 33 35 == Changelog == 34 36 37 = 2.11 = 38 * Support for persistent file storage. 39 35 40 = 2.10 = 36 41 * Support for JSON API and customized order templates. -
verge3d/trunk/templates/order_email_body.php
r2026454 r2045208 15 15 .form-table th { 16 16 padding: 10px; 17 text-align: left; 17 18 } 18 19 .form-table td { … … 24 25 <body> 25 26 <div class="wrap"> 26 <p>Thank you for your order! We're processing it now and will contact with you soon.</p> 27 28 <p><?php 29 if ($to == $order['user_email']) 30 echo 'Thank you for your order! We\'re processing it now and will contact with you soon.'; 31 else 32 echo 'You\'ve received a new customer order from '.$order['user_name']; 33 ?></p> 27 34 28 35 <h2>Order details</h2> … … 30 37 <table class="form-table"> 31 38 <tbody> 39 <tr class="form-field"> 40 <th scope="row"> 41 Date 42 </th> 43 <td> 44 <?php echo date('j M Y') ?> 45 </td> 46 </tr> 32 47 <tr class="form-field"> 33 48 <th scope="row"> -
verge3d/trunk/verge3d.php
r2026454 r2045208 4 4 Plugin URI: https://www.soft8soft.com/verge3d 5 5 Description: Verge3D is the most artist-friendly toolkit for creating interactive web-based experiences. It can be used to create product configurators, 3D presentations, online stores, e-learning apps, 3D portfolios, browser games and more. 6 Version: 2.1 0.06 Version: 2.11.0 7 7 Author: Soft8Soft LLC 8 8 Author URI: https://www.soft8soft.com … … 11 11 12 12 include plugin_dir_path(__FILE__) . 'app.php'; 13 include plugin_dir_path(__FILE__) . 'file_storage.php'; 13 14 include plugin_dir_path(__FILE__) . 'order.php'; 14 15 … … 185 186 register_setting('verge3d', 'v3d_order_email_from_name'); 186 187 register_setting('verge3d', 'v3d_order_email_from_email'); 188 register_setting('verge3d', 'v3d_order_email_attach_pdf', array('default' => 0)); 189 register_setting('verge3d', 'v3d_chrome_path'); 190 191 register_setting('verge3d', 'v3d_order_api', array('default' => 1)); 192 register_setting('verge3d', 'v3d_file_api', array('default' => 1)); 193 register_setting('verge3d', 'v3d_cross_domain', array('default' => 1)); 194 187 195 188 196 add_settings_section( 189 197 'v3d_ecommerce_settings', 190 ' ',//'E-Commerce',198 'E-Commerce', 191 199 '',//'v3d_ecommerce_settings_cb', 192 200 'verge3d' … … 208 216 'v3d_ecommerce_settings' 209 217 ); 218 219 add_settings_field( 220 'v3d_order_email_pdf', 221 'Order e-mail PDF attachment', 222 'v3d_order_email_pdf_cb', 223 'verge3d', 224 'v3d_ecommerce_settings' 225 ); 226 227 228 add_settings_section( 229 'v3d_security_settings', 230 'Security', 231 '', 232 'verge3d' 233 ); 234 235 add_settings_field( 236 'v3d_rest_api', 237 'Enable REST APIs', 238 'v3d_rest_api_cb', 239 'verge3d', 240 'v3d_security_settings' 241 ); 242 243 add_settings_field( 244 'v3d_cross_domain', 245 'Cross-domain requests', 246 'v3d_cross_domain_cb', 247 'verge3d', 248 'v3d_security_settings' 249 ); 250 251 210 252 } 211 253 add_action('admin_init', 'v3d_settings_init'); 254 255 /* E-commerce settings UI */ 212 256 213 257 function v3d_ecommerce_settings_cb() { … … 234 278 <input type="email" name="v3d_order_email_from_email" value="<?php echo isset($email) ? esc_attr($email) : ''; ?>"> 235 279 <p class="description">From what e-mail customers will be receiving confirmations. For example john.smith@yourcompany.com</p> 280 <?php 281 } 282 283 function v3d_order_email_pdf_cb() { 284 // get the value of the setting we've registered with register_setting() 285 $chrome_path = get_option('v3d_chrome_path'); 286 287 ?> 288 <fieldset> 289 <label> 290 <input type="checkbox" id="v3d_order_email_attach_pdf" name="v3d_order_email_attach_pdf" value="1" <?php checked(1, get_option('v3d_order_email_attach_pdf')); ?>"> 291 Attach 292 <p class="description">Please install Chrome/Chromium browser on the server in order to use this feature.</p> 293 </label> 294 <br> 295 <input type="text" id="v3d_chrome_path" name="v3d_chrome_path" value="<?php echo isset($chrome_path) ? esc_attr($chrome_path) : ''; ?>"> 296 <p class="description">Path to the Chrome/Chromium browser to perform PDF conversion. Leave blank if you installed it system-wide.</p> 297 </fieldset> 298 299 <script type="text/javascript"> 300 var attachPdfCheckbox = document.getElementById("v3d_order_email_attach_pdf"); 301 302 function showHideChromePath() { 303 document.getElementById("v3d_chrome_path").disabled = 304 !attachPdfCheckbox.checked; 305 } 306 307 attachPdfCheckbox.onchange = showHideChromePath; 308 showHideChromePath(); 309 310 </script> 311 <?php 312 } 313 314 /* Security settings UI */ 315 316 function v3d_rest_api_cb() { 317 ?> 318 <fieldset> 319 <label> 320 <input type="checkbox" name="v3d_order_api" value="1" <?php checked(1, get_option('v3d_order_api')); ?>"> 321 Order management 322 </label> 323 <br> 324 <label> 325 <input type="checkbox" name="v3d_file_api" value="1" <?php checked(1, get_option('v3d_file_api')); ?>"> 326 File storage 327 </label> 328 </fieldset> 329 <?php 330 } 331 332 function v3d_cross_domain_cb() { 333 ?> 334 <label> 335 <input type="checkbox" name="v3d_cross_domain" value="1" <?php checked(1, get_option('v3d_cross_domain')); ?>"> 336 Allow 337 </label> 236 338 <?php 237 339 }
Note: See TracChangeset
for help on using the changeset viewer.