From 28e833b867936fd0c0b7f7f4eb76cb863691652e Mon Sep 17 00:00:00 2001 From: otacke Date: Thu, 12 Mar 2020 18:48:36 +0100 Subject: [PATCH 1/3] Add options to activate storing user state in localStorage Requires changes in h5p-php-library to take effect --- admin/class-h5p-plugin-admin.php | 4 ++++ admin/views/settings.php | 27 +++++++++++++++++++++------ public/class-h5p-plugin.php | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/admin/class-h5p-plugin-admin.php b/admin/class-h5p-plugin-admin.php index 4c9d695..7d99440 100644 --- a/admin/class-h5p-plugin-admin.php +++ b/admin/class-h5p-plugin-admin.php @@ -454,6 +454,9 @@ public function display_settings_page() { $save_content_frequency = filter_input(INPUT_POST, 'save_content_frequency', FILTER_VALIDATE_INT); update_option('h5p_save_content_frequency', $save_content_frequency); + $save_content_storages = filter_input(INPUT_POST, 'save_content_storages', FILTER_VALIDATE_INT); + update_option('h5p_save_content_storages', $save_content_storages); + $show_toggle_view_others_h5p_contents = filter_input(INPUT_POST, 'show_toggle_view_others_h5p_contents', FILTER_VALIDATE_INT); update_option('h5p_show_toggle_view_others_h5p_contents', $show_toggle_view_others_h5p_contents); @@ -496,6 +499,7 @@ public function display_settings_page() { $track_user = get_option('h5p_track_user', TRUE); $save_content_state = get_option('h5p_save_content_state', FALSE); $save_content_frequency = get_option('h5p_save_content_frequency', 30); + $save_content_storages = get_option('h5p_save_content_storages', 1); $show_toggle_view_others_h5p_contents = get_option('h5p_show_toggle_view_others_h5p_contents', 0); $insert_method = get_option('h5p_insert_method', 'id'); $enable_lrs_content_types = get_option('h5p_enable_lrs_content_types', FALSE); diff --git a/admin/views/settings.php b/admin/views/settings.php index 817ca58..6697200 100644 --- a/admin/views/settings.php +++ b/admin/views/settings.php @@ -113,13 +113,28 @@ plugin_slug); ?> -

- - -

+ + + + plugin_slug); ?> + + + + + + plugin_slug); ?> + + diff --git a/public/class-h5p-plugin.php b/public/class-h5p-plugin.php index 94dbd93..a21a1cf 100644 --- a/public/class-h5p-plugin.php +++ b/public/class-h5p-plugin.php @@ -388,6 +388,7 @@ public static function update_database() { add_option('h5p_track_user', TRUE); add_option('h5p_save_content_state', FALSE); add_option('h5p_save_content_frequency', 30); + add_option('h5p_save_content_storages', 1); add_option('h5p_site_key', get_option('h5p_h5p_site_uuid', FALSE)); add_option('h5p_show_toggle_view_others_h5p_contents', 0); add_option('h5p_content_type_cache_updated_at', 0); @@ -798,6 +799,27 @@ public function get_h5p_url($absolute = FALSE) { return $absolute ? $url[$id]['abs'] : $url[$id]['rel']; } + /** + * Get the storages for save content state. + * + * @since 1.15.1 + * @return string + */ + public function get_h5p_save_content_storages() { + $save_content_storages = array(); + + $option = get_option('h5p_save_content_storages', FALSE); + + if (($option & H5PSaveContentStorages::DATABASE) === H5PSaveContentStorages::DATABASE) { + $save_content_storages['database'] = TRUE; + } + if (($option & H5PSaveContentStorages::LOCALSTORAGE) === H5PSaveContentStorages::LOCALSTORAGE) { + $save_content_storages['localStorage'] = TRUE; + } + + return $save_content_storages; + } + /** * Get H5P language code from WordPress. * @@ -1174,6 +1196,7 @@ public function get_core_settings() { 'contentUserData' => admin_url('admin-ajax.php?token=' . wp_create_nonce('h5p_contentuserdata') . '&action=h5p_contents_user_data&content_id=:contentId&data_type=:dataType&sub_content_id=:subContentId') ), 'saveFreq' => get_option('h5p_save_content_state', FALSE) ? get_option('h5p_save_content_frequency', 30) : FALSE, + 'saveContentStorages' => $this->get_h5p_save_content_storages(), 'siteUrl' => get_site_url(), 'l10n' => array( 'H5P' => $core->getLocalization(), @@ -1604,6 +1627,7 @@ public static function uninstall() { delete_option('h5p_ext_communication'); delete_option('h5p_save_content_state'); delete_option('h5p_save_content_frequency'); + delete_option('h5p_save_content_storages'); delete_option('h5p_show_toggle_view_others_h5p_contents'); delete_option('h5p_update_available'); delete_option('h5p_current_update'); From 6a3f4833f045d76c1f2ad9d9032b4ba0ff5dbef1 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Tue, 17 Mar 2020 18:12:23 +0100 Subject: [PATCH 2/3] Only populate H5PIntegration.saveContentStorages if resume allowed --- public/class-h5p-plugin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/class-h5p-plugin.php b/public/class-h5p-plugin.php index a21a1cf..da968b2 100644 --- a/public/class-h5p-plugin.php +++ b/public/class-h5p-plugin.php @@ -808,6 +808,10 @@ public function get_h5p_url($absolute = FALSE) { public function get_h5p_save_content_storages() { $save_content_storages = array(); + if (get_option('h5p_save_content_state', FALSE) != TRUE) { + return $save_content_storages; + } + $option = get_option('h5p_save_content_storages', FALSE); if (($option & H5PSaveContentStorages::DATABASE) === H5PSaveContentStorages::DATABASE) { From ed64aa2f9ebfacbce0a280571c809556b6c860c0 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Tue, 17 Mar 2020 18:13:33 +0100 Subject: [PATCH 3/3] Use saveContentStorages.localStorage for prefix Some identifier for localStorage items is necessary because there may be multiple sites on the same domain --- public/class-h5p-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/class-h5p-plugin.php b/public/class-h5p-plugin.php index da968b2..cf5dbb3 100644 --- a/public/class-h5p-plugin.php +++ b/public/class-h5p-plugin.php @@ -818,7 +818,7 @@ public function get_h5p_save_content_storages() { $save_content_storages['database'] = TRUE; } if (($option & H5PSaveContentStorages::LOCALSTORAGE) === H5PSaveContentStorages::LOCALSTORAGE) { - $save_content_storages['localStorage'] = TRUE; + $save_content_storages['localStorage'] = 'WP-bid-' . get_current_blog_id() . '-'; } return $save_content_storages;