From 15793a612444e67d8f9acc5e6da7dfa1ea9dfb1f Mon Sep 17 00:00:00 2001
From: Al Faller
Date: Thu, 2 Sep 2021 14:34:03 -0400
Subject: [PATCH 1/2] Adding the ability to use system temp
---
admin/class-h5p-plugin-admin.php | 4 ++++
admin/views/settings.php | 10 ++++++++++
public/class-h5p-plugin.php | 1 +
public/class-h5p-wordpress.php | 22 +++++++++++++++-------
4 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/admin/class-h5p-plugin-admin.php b/admin/class-h5p-plugin-admin.php
index 6ae12d2..9e879ce 100644
--- a/admin/class-h5p-plugin-admin.php
+++ b/admin/class-h5p-plugin-admin.php
@@ -465,6 +465,9 @@ public function display_settings_page() {
$enable_lrs_content_types = filter_input(INPUT_POST, 'enable_lrs_content_types', FILTER_VALIDATE_BOOLEAN);
update_option('h5p_enable_lrs_content_types', $enable_lrs_content_types);
+ $use_system_temp_dir = filter_input(INPUT_POST, 'use_system_temp_dir', FILTER_VALIDATE_BOOLEAN);
+ update_option('h5p_use_system_temp_dir', $use_system_temp_dir);
+
// TODO: Make it possible to change site key
// $site_key = filter_input(INPUT_POST, 'site_key', FILTER_SANITIZE_SPECIAL_CHARS);
// if (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $site_key)) {
@@ -497,6 +500,7 @@ public function display_settings_page() {
$about = get_option('h5p_icon', TRUE);
$track_user = get_option('h5p_track_user', TRUE);
$save_content_state = get_option('h5p_save_content_state', FALSE);
+ $use_system_temp_dir = get_option('h5p_use_system_temp_dir', FALSE);
$save_content_frequency = get_option('h5p_save_content_frequency', 30);
$show_toggle_view_others_h5p_contents = get_option('h5p_show_toggle_view_others_h5p_contents', 0);
$insert_method = get_option('h5p_insert_method', 'id');
diff --git a/admin/views/settings.php b/admin/views/settings.php
index 817ca58..7331c48 100644
--- a/admin/views/settings.php
+++ b/admin/views/settings.php
@@ -189,6 +189,16 @@ class="h5p-settings-disable-hub-checkbox"
+
+ | plugin_slug); ?> |
+
+
+ |
+
+
plugin_slug); ?>
diff --git a/public/class-h5p-plugin.php b/public/class-h5p-plugin.php
index ee96b88..db90d36 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_icon', TRUE);
add_option('h5p_track_user', TRUE);
add_option('h5p_save_content_state', FALSE);
+ add_option('h5p_use_system_temp_dir', FALSE);
add_option('h5p_save_content_frequency', 30);
add_option('h5p_site_key', get_option('h5p_h5p_site_uuid', FALSE));
add_option('h5p_show_toggle_view_others_h5p_contents', 0);
diff --git a/public/class-h5p-wordpress.php b/public/class-h5p-wordpress.php
index c2f01f6..bff2986 100644
--- a/public/class-h5p-wordpress.php
+++ b/public/class-h5p-wordpress.php
@@ -92,9 +92,13 @@ public function getUploadedH5pFolderPath() {
static $dir;
if (is_null($dir)) {
- $plugin = H5P_Plugin::get_instance();
- $core = $plugin->get_h5p_instance('core');
- $dir = $core->fs->getTmpPath();
+ if (get_option('h5p_use_system_temp_dir', FALSE)) {
+ $path = sys_get_temp_dir();
+ } else {
+ $plugin = H5P_Plugin::get_instance();
+ $core = $plugin->get_h5p_instance('core');
+ $dir = $core->fs->getTmpPath();
+ }
}
return $dir;
@@ -107,11 +111,15 @@ public function getUploadedH5pPath() {
static $path;
if (is_null($path)) {
- $plugin = H5P_Plugin::get_instance();
- $core = $plugin->get_h5p_instance('core');
- $path = $core->fs->getTmpPath() . '.h5p';
+ if (get_option('h5p_use_system_temp_dir', FALSE)) {
+ $path = sys_get_temp_dir() . '.h5p';
+ } else {
+ $plugin = H5P_Plugin::get_instance();
+ $core = $plugin->get_h5p_instance('core');
+ $path = $core->fs->getTmpPath() . '.h5p';
+ }
}
-
+
return $path;
}
From 935a0393adf412ab7800a145e6c9344926644bc6 Mon Sep 17 00:00:00 2001
From: Al Faller
Date: Thu, 2 Sep 2021 14:57:19 -0400
Subject: [PATCH 2/2] Fixing some typos
---
public/class-h5p-wordpress.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/public/class-h5p-wordpress.php b/public/class-h5p-wordpress.php
index bff2986..6b1606a 100644
--- a/public/class-h5p-wordpress.php
+++ b/public/class-h5p-wordpress.php
@@ -93,7 +93,7 @@ public function getUploadedH5pFolderPath() {
if (is_null($dir)) {
if (get_option('h5p_use_system_temp_dir', FALSE)) {
- $path = sys_get_temp_dir();
+ $dir = sys_get_temp_dir() . "/" . uniqid('h5p-');
} else {
$plugin = H5P_Plugin::get_instance();
$core = $plugin->get_h5p_instance('core');
@@ -112,14 +112,13 @@ public function getUploadedH5pPath() {
if (is_null($path)) {
if (get_option('h5p_use_system_temp_dir', FALSE)) {
- $path = sys_get_temp_dir() . '.h5p';
+ $path = sys_get_temp_dir() . '/' . uniqid('h5p-') . '.h5p';
} else {
$plugin = H5P_Plugin::get_instance();
$core = $plugin->get_h5p_instance('core');
$path = $core->fs->getTmpPath() . '.h5p';
}
}
-
return $path;
}