Plugin Directory

Changeset 2045208


Ignore:
Timestamp:
03/06/2019 12:29:30 PM (7 years ago)
Author:
soft8soft
Message:

New version 2.11.0

Location:
verge3d/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • verge3d/trunk/order.php

    r2026454 r2045208  
    8888            <p>Specify the link to that page/post in the "send order" puzzle to make it work.</p>
    8989          </div>
    90          
     90
    9191          <form id="orders-filter" method="get">
    9292            <!-- For plugins, we also need to ensure that the form posts back to our current page -->
     
    110110    );
    111111    wp_insert_post($post_arr);
    112    
     112
    113113    $order_email = get_option('v3d_order_email');
    114114    $order_from_name = get_option('v3d_order_email_from_name');
    115115    $order_from_email = get_option('v3d_order_email_from_email');
    116116
    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    
    126117    $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'));
    131126    }
    132127
     
    134129        $to = $order_email;
    135130        $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
    137136        wp_mail($to, $subject, $body, $headers, $attachments);
    138137    }
     
    141140        $to = $order['user_email'];
    142141        $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
    144147        wp_mail($to, $subject, $body, $headers, $attachments);
    145148    }
     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 */
     157function 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
     189function 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
     212function 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
     222function 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
     271function 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));
    146281}
    147282
     
    193328
    194329function v3d_delete_order($order_id) {
    195    
     330
    196331    $scr_url = get_post_meta($order_id, 'screenshot', true);
    197332
     
    210345    function __construct(){
    211346        global $status, $page;
    212                
     347
    213348        // Set parent defaults
    214349        parent::__construct( array(
     
    217352            'ajax'      => false
    218353        ) );
    219        
     354
    220355    }
    221356
     
    234369
    235370    function column_title($item){
    236        
     371
    237372        // Build row actions
    238373        $actions = array(
     
    242377                    sanitize_text_field($_REQUEST['page']), 'delete', $item['ID']),
    243378        );
    244        
     379
    245380        // Return the title contents
    246381        return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
     
    298433    function prepare_items() {
    299434        $per_page = 15;
    300        
     435
    301436        $columns = $this->get_columns();
    302437        $hidden = array();
    303438        $sortable = $this->get_sortable_columns();
    304        
     439
    305440        $this->_column_headers = array($columns, $hidden, $sortable);
    306441
     
    309444        // if no sort, default to title
    310445        $orderby = (!empty($_REQUEST['orderby'])) ?
    311                 sanitize_text_field($_REQUEST['orderby']) : 'title'; 
     446                sanitize_text_field($_REQUEST['orderby']) : 'title';
    312447        // if no order, default to asc
    313448        $order = (!empty($_REQUEST['order'])) ?
    314                 sanitize_text_field($_REQUEST['order']) : 'ASC'; 
     449                sanitize_text_field($_REQUEST['order']) : 'ASC';
    315450
    316451        $args = array(
     
    352487            );
    353488        }
    354        
     489
    355490        $current_page = $this->get_pagenum();
    356        
     491
    357492        $total_items = count($posts);
    358493
    359494        $posts = array_slice($posts, (($current_page-1)*$per_page), $per_page);
    360        
     495
    361496        $this->items = $posts;
    362        
     497
    363498        $this->set_pagination_args( array(
    364499            'total_items' => $total_items,
     
    376511    $atts = array_change_key_case((array)$atts, CASE_LOWER);
    377512
    378     $action = (!empty($_REQUEST['v3d_action'])) ? sanitize_text_field($_REQUEST['v3d_action']) : ''; 
     513    $action = (!empty($_REQUEST['v3d_action'])) ? sanitize_text_field($_REQUEST['v3d_action']) : '';
    379514    $title = (!empty($_REQUEST['v3d_title'])) ? sanitize_text_field($_REQUEST['v3d_title']) : '';
    380515    $content = (!empty($_REQUEST['v3d_content'])) ? sanitize_textarea_field($_REQUEST['v3d_content']) : '';
     
    422557
    423558    $upload_dir = v3d_get_upload_dir();
    424     $screenshot_dir = $upload_dir.'screenshots/'; 
     559    $screenshot_dir = $upload_dir.'screenshots/';
    425560    if (!is_dir($screenshot_dir)) {
    426561        mkdir($screenshot_dir, 0777, true);
     
    435570        return '';
    436571}
    437  
     572
    438573function v3d_order_shortcode_init() {
    439574    add_shortcode('verge3d_order', 'v3d_order_shortcode');
     
    452587
    453588function v3d_api_place_order(WP_REST_Request $request) {
    454  
     589
    455590    $params = $request->get_json_params();
    456591
     
    469604    } else {
    470605
    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
    476613    return $response;
    477614
     
    479616
    480617add_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    }
    485624});
  • verge3d/trunk/readme.txt

    r2026454 r2045208  
    33Tags: verge3d,3d,webgl,3dweb,web3d
    44Requires at least: 4.7
    5 Tested up to: 4.9.5
     5Tested up to: 5.1
    66Requires PHP: 5.6
    7 Stable tag: 2.10.0
     7Stable tag: 2.11.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1515
    1616Verge3D can be used to create product configurators, 3D presentations, online stores, e-learning apps, 3D portfolios, browser games and more.
     17
     18You can try this plugin live using this [Sandbox website](https://sandbox.soft8soft.com/).
    1719
    1820== Installation ==
     
    3335== Changelog ==
    3436
     37= 2.11 =
     38* Support for persistent file storage.
     39
    3540= 2.10 =
    3641* Support for JSON API and customized order templates.
  • verge3d/trunk/templates/order_email_body.php

    r2026454 r2045208  
    1515    .form-table th {
    1616      padding: 10px;
     17      text-align: left;
    1718    }
    1819    .form-table td {
     
    2425<body>
    2526  <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>
    2734
    2835    <h2>Order details</h2>
     
    3037    <table class="form-table">
    3138      <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>
    3247        <tr class="form-field">
    3348          <th scope="row">
  • verge3d/trunk/verge3d.php

    r2026454 r2045208  
    44Plugin URI: https://www.soft8soft.com/verge3d
    55Description: 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.10.0
     6Version: 2.11.0
    77Author: Soft8Soft LLC
    88Author URI: https://www.soft8soft.com
     
    1111
    1212include plugin_dir_path(__FILE__) . 'app.php';
     13include plugin_dir_path(__FILE__) . 'file_storage.php';
    1314include plugin_dir_path(__FILE__) . 'order.php';
    1415
     
    185186    register_setting('verge3d', 'v3d_order_email_from_name');
    186187    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
    187195
    188196    add_settings_section(
    189197        'v3d_ecommerce_settings',
    190         '',//'E-Commerce',
     198        'E-Commerce',
    191199        '',//'v3d_ecommerce_settings_cb',
    192200        'verge3d'
     
    208216        'v3d_ecommerce_settings'
    209217    );
     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
    210252}
    211253add_action('admin_init', 'v3d_settings_init');
     254
     255/* E-commerce settings UI */
    212256 
    213257function v3d_ecommerce_settings_cb() {
     
    234278    <input type="email" name="v3d_order_email_from_email" value="<?php echo isset($email) ? esc_attr($email) : ''; ?>">
    235279    <p class="description">From what e-mail customers will be receiving confirmations. For example john.smith@yourcompany.com</p>
     280    <?php
     281}
     282
     283function 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
     316function 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
     332function 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>
    236338    <?php
    237339}
Note: See TracChangeset for help on using the changeset viewer.