Plugin Directory

Changeset 2973378


Ignore:
Timestamp:
09/30/2023 08:46:34 PM (3 years ago)
Author:
Ickata
Message:

Ability to share sessions between browsers

Location:
image-editor-by-pixo/branches/2.4-beta1
Files:
8 copied

Legend:

Unmodified
Added
Removed
  • image-editor-by-pixo/branches/2.4-beta1/admin.js

    r2812513 r2973378  
    3434      theme    : 'wordpress',
    3535      alert    : true,
     36      sessions : Pixo.SESSIONS,
    3637      actions  : [{
    3738         caption     : 'Save',
     
    6465      filterStickers: function (stickers) {
    6566         return Pixo.STICKERS && Pixo.STICKERS.length ? Pixo.STICKERS : stickers;
     67      },
     68
     69      onClose: function (sessions) {
     70         if (sessions) {
     71            Pixo.SESSIONS = sessions;
     72           
     73            const xhr = new XMLHttpRequest();
     74            xhr.open('PUT', '/wp-json/pixo-editor/v1/sessions');
     75            xhr.setRequestHeader('Content-type', 'application/json');
     76            xhr.send(JSON.stringify(sessions));
     77         }
    6678      },
    6779   });
  • image-editor-by-pixo/branches/2.4-beta1/pixo.php

    r2891508 r2973378  
    44Plugin URI: https://pixoeditor.com
    55Description: Provides Pixo as a replacement of the default image editor in your WordPress installation, as well as integrates to your website front-end
    6 Version: 2.3.1
     6Version: 2.4-beta1
    77*/
    88
     
    2222define( 'PIXOEDITOR_OPTION_IMAGE_SIZE',   '__pixoeditor_image_size' );
    2323define( 'PIXOEDITOR_OPTION_STICKERS',     '__pixoeditor_stickers' );
     24define( 'PIXOEDITOR_OPTION_SESSIONS',     '__pixoeditor_sessions' );
     25define( 'PIXOEDITOR_OPTION_SESSIONS_ENABLED',   '__pixoeditor_sessions_enabled' );
    2426define( 'PIXOEDITOR_OPTION_FRONTEND_CONFIG',    '__pixoeditor_frontend_config' );
    2527define( 'PIXOEDITOR_OPTION_FRONTEND_GLOBAL',    '__pixoeditor_frontend_is_global' );
     
    4749include( dirname( __FILE__ ) . '/get-custom-stickers.php' );
    4850include( dirname( __FILE__ ) . '/frontend.php' );
     51
     52
     53/********************************************************* REST API ENDPOINTS */
     54
     55add_action('rest_api_init', 'pixoeditor__initRESTAPI');
     56function pixoeditor__initRESTAPI() {
     57   register_rest_route('pixo-editor/v1', '/sessions', array(
     58      'methods' => 'PUT',
     59      'callback' => 'pixoeditor__updateSessions',
     60      'permission_callback' => '__return_true',
     61   ));
     62   register_rest_route('pixo-editor/v1', '/sessions', array(
     63      'methods' => 'GET',
     64      'callback' => 'pixoeditor__getSessions',
     65      'permission_callback' => '__return_true',
     66   ));
     67};
     68
     69function pixoeditor__updateSessions($request) {
     70   $sessions = $request->get_body();
     71   return update_option(PIXOEDITOR_OPTION_SESSIONS, $sessions);
     72}
     73
     74function pixoeditor__getSessions() {
     75   return 'not implemented';
     76}
    4977
    5078
     
    111139   }
    112140   wp_enqueue_script( 'pixoeditor__bridge', 'https://pixoeditor.com/editor/scripts/bridge.m.js' );
    113    wp_enqueue_script( 'pixoeditor__admin', plugin_dir_url( __FILE__ ) . 'admin.js', array( 'media-models', 'jquery-ui-dialog' ), '2.2.1' );
     141   wp_enqueue_script( 'pixoeditor__admin', plugin_dir_url( __FILE__ ) . 'admin.js', array( 'media-models', 'jquery-ui-dialog' ), '2.4-beta1' );
    114142}
    115143
     
    148176         '" . pixoeditor__getCustomStickers( explode( ',', get_option( PIXOEDITOR_OPTION_STICKERS ) ) ) . "' || '[]'
    149177      );
     178      Pixo.SESSIONS = " . (get_option( PIXOEDITOR_OPTION_SESSIONS_ENABLED ) == '1' ? (get_option( PIXOEDITOR_OPTION_SESSIONS ) ?: 'null') : 'undefined') . ";
    150179     
    151180      (function () {
     
    671700<?php endif ?>
    672701
     702<h2>Sessions</h2>
     703<label>
     704   <input type="checkbox" name="<?php echo PIXOEDITOR_OPTION_SESSIONS_ENABLED ?>" value="1" <?php echo pixoeditor__getOption( PIXOEDITOR_OPTION_SESSIONS_ENABLED ) == '1' ? ' checked="checked"' : '' ?>" /> Enable cross-browser sessions
     705</label>
     706<p>This enables session restore between different browsers and computers. For example, edit and save image from your laptop, then open the saved image from your desktop computer. All changes will be editable/revertable!</p>
     707<p><i>Warning! This feature may increase the size of your database</i></p>
     708
     709<p class="submit">
     710   <input type="submit" name="save-settings" id="submit" class="button button-primary" value="Update Sessions">
     711</p>
     712
    673713<input type="hidden" name="<?php echo PIXOEDITOR_KEY_NONCE ?>" value="<?php echo wp_create_nonce( PIXOEDITOR_KEY_NONCE ) ?>" />
    674714<?php
     
    699739               sanitize_text_field( json_encode( $_POST[ PIXOEDITOR_OPTION_CONFIG ] ) )
    700740            );
     741            if (isset( $_POST[ PIXOEDITOR_OPTION_SESSIONS_ENABLED ] )) {
     742               pixoeditor__updateOption(
     743                  PIXOEDITOR_OPTION_SESSIONS_ENABLED,
     744                  sanitize_text_field( $_POST[ PIXOEDITOR_OPTION_SESSIONS_ENABLED ] )
     745               );
     746            } else {
     747               pixoeditor__updateOption( PIXOEDITOR_OPTION_SESSIONS_ENABLED, '' );
     748            }
    701749            isset( $_POST[ PIXOEDITOR_OPTION_FRONTEND_CONFIG ] ) && pixoeditor__updateOption(
    702750               PIXOEDITOR_OPTION_FRONTEND_CONFIG,
Note: See TracChangeset for help on using the changeset viewer.