From ff496d9a38b19ea66f24da64563dba1079310511 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Tue, 21 Feb 2017 14:01:49 +0100 Subject: [PATCH 01/12] Check for H5P requirements. HFP-502 --- h5p.classes.php | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index b0ad889..d211b3f 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2758,6 +2758,84 @@ class H5PCore { return $token === substr(hash('md5', $action . $time_factor . $_SESSION['h5p_token']), -16, 13) || // Under 12 hours $token === substr(hash('md5', $action . ($time_factor - 1) . $_SESSION['h5p_token']), -16, 13); // Between 12-24 hours } + + /** + * Check that all H5P requirements for the server setup is met. + */ + public function check_setup_for_requirements() { + $disable_hub = FALSE; + + if (!class_exists('ZipArchive')) { + $this->h5pF->setErrorMessage('Your PHP version does not support ZipArchive.'); + $disable_hub = TRUE; + } + + if (!extension_loaded('mbstring')) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly') + ); + $disable_hub = TRUE; + } + + // Check php version >= 5.2 + $php_version = explode('.', phpversion()); + if ($php_version[0] < 5 || ($php_version[0] === 5 && $php_version[1] < 2)) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your PHP version is too old. H5P needs at least version 5.2 to function properly') + ); + $disable_hub = TRUE; + } + + // Check max upload and post size + function return_bytes($val) { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + switch($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; + } + + $max_upload_size = ini_get('upload_max_filesize'); + $max_post_size = ini_get('post_max_size'); + $byte_threshold = 5000000; // 5MB + if (return_bytes($max_upload_size) < $byte_threshold) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your PHP max upload size option is too small. You should consider to increase it to more than 5MB.') + ); + } + + if (return_bytes($max_post_size) < $byte_threshold) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your PHP max post size option is too small. You should consider to increase it to more than 5MB.') + ); + } + + // Check SSL + if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your server does not have SSL enabled. SSL should be enabled to ensure a secure connection with the H5P hub.') + ); + $disable_hub = TRUE; + } + + // Disable hub, and inform how to re-enable it + $this->h5pF->setOption('disable_hub', $disable_hub); + if ($disable_hub) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('H5P hub communication has been disabled because one or more H5P requirements failed.') + ); + $this->h5pF->setErrorMessage( + $this->h5pF->t('When you have revised your server setup you may re-enable H5P hub communication in H5P Settings.') + ); + } + } } /** From c70f8521bb7add642eff0fc0e1b9d208679030ff Mon Sep 17 00:00:00 2001 From: thomasmars Date: Tue, 21 Feb 2017 14:31:01 +0100 Subject: [PATCH 02/12] Use core naming convention for requirements function HFP-502 --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index d211b3f..3deda1e 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2762,7 +2762,7 @@ class H5PCore { /** * Check that all H5P requirements for the server setup is met. */ - public function check_setup_for_requirements() { + public function checkSetupForRequirements() { $disable_hub = FALSE; if (!class_exists('ZipArchive')) { From c4affb23dd6f4ea0ebe57dbe634a7457b32d1fdb Mon Sep 17 00:00:00 2001 From: thomasmars Date: Tue, 21 Feb 2017 17:37:01 +0100 Subject: [PATCH 03/12] Added confirmation dialog functionality when disabling hub. Refactored server setup check into check and var updates. Moved bytes string parsing out of server setup check and fixed naming convention. Fixed indentation to match library core instead of Moodle style. --- h5p.classes.php | 161 ++++++++++++++++++--------------- js/settings/h5p-disable-hub.js | 66 ++++++++++++++ 2 files changed, 155 insertions(+), 72 deletions(-) create mode 100644 js/settings/h5p-disable-hub.js diff --git a/h5p.classes.php b/h5p.classes.php index 3deda1e..1d0c5d9 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2759,82 +2759,99 @@ class H5PCore { $token === substr(hash('md5', $action . ($time_factor - 1) . $_SESSION['h5p_token']), -16, 13); // Between 12-24 hours } - /** - * Check that all H5P requirements for the server setup is met. - */ + /** + * Check if the current server setup is valid and set error messages + * + * @return bool True if errors was found + */ + public function checkSetupErrorMessage() { + $disable_hub = FALSE; + + if (!class_exists('ZipArchive')) { + $this->h5pF->setErrorMessage('Your PHP version does not support ZipArchive.'); + $disable_hub = TRUE; + } + + if (!extension_loaded('mbstring')) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly') + ); + $disable_hub = TRUE; + } + + // Check php version >= 5.2 + $php_version = explode('.', phpversion()); + if ($php_version[0] < 5 || ($php_version[0] === 5 && $php_version[1] < 2)) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your PHP version is too old. H5P needs at least version 5.2 to function properly') + ); + $disable_hub = TRUE; + } + + $max_upload_size = ini_get('upload_max_filesize'); + $max_post_size = ini_get('post_max_size'); + $byte_threshold = 5000000; // 5MB + if (self::returnBytes($max_upload_size) < $byte_threshold) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your PHP max upload size option is too small. You should consider to increase it to more than 5MB.') + ); + } + + if (self::returnBytes($max_post_size) < $byte_threshold) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your PHP max post size option is too small. You should consider to increase it to more than 5MB.') + ); + } + + // Check SSL + if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { + $this->h5pF->setErrorMessage( + $this->h5pF->t('Your server does not have SSL enabled. SSL should be enabled to ensure a secure connection with the H5P hub.') + ); + $disable_hub = TRUE; + } + + return $disable_hub; + } + + /** + * Check that all H5P requirements for the server setup is met. + */ public function checkSetupForRequirements() { - $disable_hub = FALSE; + $disable_hub = $this->checkSetupErrorMessage(); - if (!class_exists('ZipArchive')) { - $this->h5pF->setErrorMessage('Your PHP version does not support ZipArchive.'); - $disable_hub = TRUE; - } + // Disable hub, and inform how to re-enable it + $this->h5pF->setOption('disable_hub', $disable_hub); + if ($disable_hub) { + $this->h5pF->setErrorMessage( + $this->h5pF->t('H5P hub communication has been disabled because one or more H5P requirements failed.') + ); + $this->h5pF->setErrorMessage( + $this->h5pF->t('When you have revised your server setup you may re-enable H5P hub communication in H5P Settings.') + ); + } + } - if (!extension_loaded('mbstring')) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly') - ); - $disable_hub = TRUE; - } + /** + * Return bytes from php_ini string value + * + * @param string $val + * + * @return int|string + */ + public static function returnBytes($val) { + $val = trim($val); + $last = strtolower($val[strlen($val) - 1]); + switch ($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } - // Check php version >= 5.2 - $php_version = explode('.', phpversion()); - if ($php_version[0] < 5 || ($php_version[0] === 5 && $php_version[1] < 2)) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your PHP version is too old. H5P needs at least version 5.2 to function properly') - ); - $disable_hub = TRUE; - } - - // Check max upload and post size - function return_bytes($val) { - $val = trim($val); - $last = strtolower($val[strlen($val)-1]); - switch($last) { - case 'g': - $val *= 1024; - case 'm': - $val *= 1024; - case 'k': - $val *= 1024; - } - - return $val; - } - - $max_upload_size = ini_get('upload_max_filesize'); - $max_post_size = ini_get('post_max_size'); - $byte_threshold = 5000000; // 5MB - if (return_bytes($max_upload_size) < $byte_threshold) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your PHP max upload size option is too small. You should consider to increase it to more than 5MB.') - ); - } - - if (return_bytes($max_post_size) < $byte_threshold) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your PHP max post size option is too small. You should consider to increase it to more than 5MB.') - ); - } - - // Check SSL - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your server does not have SSL enabled. SSL should be enabled to ensure a secure connection with the H5P hub.') - ); - $disable_hub = TRUE; - } - - // Disable hub, and inform how to re-enable it - $this->h5pF->setOption('disable_hub', $disable_hub); - if ($disable_hub) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('H5P hub communication has been disabled because one or more H5P requirements failed.') - ); - $this->h5pF->setErrorMessage( - $this->h5pF->t('When you have revised your server setup you may re-enable H5P hub communication in H5P Settings.') - ); - } + return $val; } } diff --git a/js/settings/h5p-disable-hub.js b/js/settings/h5p-disable-hub.js new file mode 100644 index 0000000..b525bd4 --- /dev/null +++ b/js/settings/h5p-disable-hub.js @@ -0,0 +1,66 @@ +/* global H5PDisableHubData */ + +/** + * Global data for disable hub functionality + * + * @typedef {object} H5PDisableHubData Data passed in from the backend + * + * @property {string} selector Selector for the disable hub check-button + * @property {string} overlaySelector Selector for the element that the confirmation dialog will mask + * @property {Array} errors Errors found with the current server setup + * + * @property {string} header Header of the confirmation dialog + * @property {string} confirmationDialogMsg Body of the confirmation dialog + * @property {string} cancelLabel Cancel label of the confirmation dialog + * @property {string} confirmLabel Confirm button label of the confirmation dialog + * + */ +/** + * Utility that makes it possible to force the user to confirm that he really + * wants to use the H5P hub without proper server settings. + */ +(function ($) { + + + + $(document).on('ready', function () { + + // No data found + if (!H5PDisableHubData) { + return; + } + + // No errors found, no need for confirmation dialog + if (!H5PDisableHubData.errors || !H5PDisableHubData.errors.length) { + return; + } + + var selector = H5PDisableHubData.selector; + var dialogHtml = '
' + + '

' + H5PDisableHubData.errors.join('

') + '

' + + '

' + H5PDisableHubData.confirmationDialogMsg + '

'; + + // Create confirmation dialog, make sure to include translations + var confirmationDialog = new H5P.ConfirmationDialog({ + headerText: H5PDisableHubData.header, + dialogText: dialogHtml, + cancelText: H5PDisableHubData.cancelLabel, + confirmText: H5PDisableHubData.confirmLabel + }).appendTo($(H5PDisableHubData.overlaySelector).get(0)); + + confirmationDialog.on('confirmed', function () { + disableButton.get(0).checked = false; + }); + + confirmationDialog.on('canceled', function () { + disableButton.get(0).checked = true; + }); + + var disableButton = $(selector); + disableButton.change(function () { + if (!$(this).is(':checked')) { + confirmationDialog.show(disableButton.offset().top); + } + }); + }); +})(H5P.jQuery); From 46d4d403f450c3033e1efd35eb79956f7478687b Mon Sep 17 00:00:00 2001 From: thomasmars Date: Tue, 21 Feb 2017 20:01:30 +0100 Subject: [PATCH 04/12] Added default selectors for disable hub elements. HFP-503 --- js/settings/h5p-disable-hub.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/js/settings/h5p-disable-hub.js b/js/settings/h5p-disable-hub.js index b525bd4..e78970a 100644 --- a/js/settings/h5p-disable-hub.js +++ b/js/settings/h5p-disable-hub.js @@ -21,8 +21,6 @@ */ (function ($) { - - $(document).on('ready', function () { // No data found @@ -35,7 +33,11 @@ return; } - var selector = H5PDisableHubData.selector; + H5PDisableHubData.selector = H5PDisableHubData.selector || + '.h5p-settings-disable-hub-checkbox'; + H5PDisableHubData.overlaySelector = H5PDisableHubData.overlaySelector || + '.h5p-settings-container'; + var dialogHtml = '
' + '

' + H5PDisableHubData.errors.join('

') + '

' + '

' + H5PDisableHubData.confirmationDialogMsg + '

'; @@ -56,7 +58,7 @@ disableButton.get(0).checked = true; }); - var disableButton = $(selector); + var disableButton = $(H5PDisableHubData.selector); disableButton.change(function () { if (!$(this).is(':checked')) { confirmationDialog.show(disableButton.offset().top); From 24fd6b1bc521ab464c39a3c18012b8ec232b2b11 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Wed, 22 Feb 2017 11:14:35 +0100 Subject: [PATCH 05/12] Made server setup check return errors instead of setting them. This is useful in cases where you want to process the error messages differently HFP-502 --- h5p.classes.php | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 1d0c5d9..76780a3 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2762,67 +2762,62 @@ class H5PCore { /** * Check if the current server setup is valid and set error messages * - * @return bool True if errors was found + * @return array Errors found */ public function checkSetupErrorMessage() { - $disable_hub = FALSE; + $errors = array(); if (!class_exists('ZipArchive')) { - $this->h5pF->setErrorMessage('Your PHP version does not support ZipArchive.'); - $disable_hub = TRUE; + $errors[] = $this->h5pF->t('Your PHP version does not support ZipArchive.'); } if (!extension_loaded('mbstring')) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly') - ); - $disable_hub = TRUE; + $errors[] = + $this->h5pF->t('The mbstring PHP extension is not loaded. H5P need this to function properly'); } // Check php version >= 5.2 $php_version = explode('.', phpversion()); if ($php_version[0] < 5 || ($php_version[0] === 5 && $php_version[1] < 2)) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your PHP version is too old. H5P needs at least version 5.2 to function properly') - ); - $disable_hub = TRUE; + $errors[] = + $this->h5pF->t('Your PHP version is too old. H5P needs at least version 5.2 to function properly'); } $max_upload_size = ini_get('upload_max_filesize'); $max_post_size = ini_get('post_max_size'); $byte_threshold = 5000000; // 5MB if (self::returnBytes($max_upload_size) < $byte_threshold) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your PHP max upload size option is too small. You should consider to increase it to more than 5MB.') - ); + $errors[] = + $this->h5pF->t('Your PHP max upload size option is too small. You should consider to increase it to more than 5MB.'); } if (self::returnBytes($max_post_size) < $byte_threshold) { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your PHP max post size option is too small. You should consider to increase it to more than 5MB.') - ); + $errors[] = + $this->h5pF->t('Your PHP max post size option is too small. You should consider to increase it to more than 5MB.'); } // Check SSL if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { - $this->h5pF->setErrorMessage( - $this->h5pF->t('Your server does not have SSL enabled. SSL should be enabled to ensure a secure connection with the H5P hub.') - ); - $disable_hub = TRUE; + $errors[] = + $this->h5pF->t('Your server does not have SSL enabled. SSL should be enabled to ensure a secure connection with the H5P hub.'); } - return $disable_hub; + return $errors; } /** * Check that all H5P requirements for the server setup is met. */ public function checkSetupForRequirements() { - $disable_hub = $this->checkSetupErrorMessage(); + $errors = $this->checkSetupErrorMessage(); - // Disable hub, and inform how to re-enable it - $this->h5pF->setOption('disable_hub', $disable_hub); - if ($disable_hub) { + $this->h5pF->setOption('disable_hub', !empty($errors)); + if (!empty($errors)) { + foreach ($errors as $err) { + $this->h5pF->setErrorMessage($err); + } + + // Inform how to re-enable hub $this->h5pF->setErrorMessage( $this->h5pF->t('H5P hub communication has been disabled because one or more H5P requirements failed.') ); From 1f7d03dfd462f887887e02df93e4e03858b0c550 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Wed, 22 Feb 2017 18:03:23 +0100 Subject: [PATCH 06/12] Don't use verb in setting name. HFP-502 --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 76780a3..135e8aa 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2811,7 +2811,7 @@ class H5PCore { public function checkSetupForRequirements() { $errors = $this->checkSetupErrorMessage(); - $this->h5pF->setOption('disable_hub', !empty($errors)); + $this->h5pF->setOption('hub_is_disabled', !empty($errors)); if (!empty($errors)) { foreach ($errors as $err) { $this->h5pF->setErrorMessage($err); From ff531a157c242a34d22afe9a992e984ed6a8e024 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Wed, 22 Feb 2017 18:29:21 +0100 Subject: [PATCH 07/12] Improved error msg and check for openssl extension HFP-502 --- h5p.classes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 135e8aa..b1898fe 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2780,7 +2780,7 @@ class H5PCore { $php_version = explode('.', phpversion()); if ($php_version[0] < 5 || ($php_version[0] === 5 && $php_version[1] < 2)) { $errors[] = - $this->h5pF->t('Your PHP version is too old. H5P needs at least version 5.2 to function properly'); + $this->h5pF->t('Your PHP version is outdated. H5P requires version 5.2 to function properly. Version 5.6 or later is recommended.'); } $max_upload_size = ini_get('upload_max_filesize'); @@ -2797,7 +2797,7 @@ class H5PCore { } // Check SSL - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { + if (!extension_loaded('openssl')) { $errors[] = $this->h5pF->t('Your server does not have SSL enabled. SSL should be enabled to ensure a secure connection with the H5P hub.'); } From aa861fc8ce278ce7f6036715644b4a75e0ae5a83 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Thu, 23 Feb 2017 14:20:56 +0100 Subject: [PATCH 08/12] Make disable hub, into enable hub to match the checkbox state. Implemented write access check HFP-502 --- h5p-default-storage.class.php | 25 +++++++++++++++++++++++++ h5p-file-storage.interface.php | 8 ++++++++ h5p.classes.php | 19 +++++++++++++++---- js/settings/h5p-disable-hub.js | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index 0c67341..19cb2fe 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -386,6 +386,31 @@ class H5PDefaultStorage implements \H5PFileStorage { } } + /** + * Check if server setup has write permission to + * the required folders + * + * @return bool True if server has the proper write access + */ + public function hasWriteAccess() { + $dirs = array( + '/content', + '/libraries', + '/cachedassets', + '/temp', + '/editor', + '/exports' + ); + + // Check that directories are writable + $has_write_access = TRUE; + foreach ($dirs as $dir) { + $has_write_access = $has_write_access && self::dirReady($this->path . $dir); + } + + return $has_write_access; + } + /** * Recursive function for copying directories. * diff --git a/h5p-file-storage.interface.php b/h5p-file-storage.interface.php index 3c621f7..93ca771 100644 --- a/h5p-file-storage.interface.php +++ b/h5p-file-storage.interface.php @@ -171,4 +171,12 @@ interface H5PFileStorage { * @param int $contentId */ public function removeContentFile($file, $contentId); + + /** + * Check if server setup has write permission to + * the required folders + * + * @return bool True if server has the proper write access + */ + public function hasWriteAccess(); } diff --git a/h5p.classes.php b/h5p.classes.php index b1898fe..c4ad467 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2783,19 +2783,30 @@ class H5PCore { $this->h5pF->t('Your PHP version is outdated. H5P requires version 5.2 to function properly. Version 5.6 or later is recommended.'); } - $max_upload_size = ini_get('upload_max_filesize'); - $max_post_size = ini_get('post_max_size'); + // Check write access + if (!$this->fs->hasWriteAccess()) { + $errors[] = + $this->h5pF->t('A problem with the server write access was detected. Please make sure that your server can write to your data folder.'); + } + + $max_upload_size = self::returnBytes(ini_get('upload_max_filesize')); + $max_post_size = self::returnBytes(ini_get('post_max_size')); $byte_threshold = 5000000; // 5MB - if (self::returnBytes($max_upload_size) < $byte_threshold) { + if ($max_upload_size < $byte_threshold) { $errors[] = $this->h5pF->t('Your PHP max upload size option is too small. You should consider to increase it to more than 5MB.'); } - if (self::returnBytes($max_post_size) < $byte_threshold) { + if ($max_post_size < $byte_threshold) { $errors[] = $this->h5pF->t('Your PHP max post size option is too small. You should consider to increase it to more than 5MB.'); } + if ($max_upload_size > $max_post_size) { + $errors[] = + $this->h5pF->t('Your PHP max upload size is bigger than your max post size. This is known to cause issues in some installations.'); + } + // Check SSL if (!extension_loaded('openssl')) { $errors[] = diff --git a/js/settings/h5p-disable-hub.js b/js/settings/h5p-disable-hub.js index e78970a..7864695 100644 --- a/js/settings/h5p-disable-hub.js +++ b/js/settings/h5p-disable-hub.js @@ -60,7 +60,7 @@ var disableButton = $(H5PDisableHubData.selector); disableButton.change(function () { - if (!$(this).is(':checked')) { + if ($(this).is(':checked')) { confirmationDialog.show(disableButton.offset().top); } }); From a32f210188fea97279f7b34d35868a140322c10e Mon Sep 17 00:00:00 2001 From: thomasmars Date: Thu, 23 Feb 2017 14:22:56 +0100 Subject: [PATCH 09/12] Fixed enable hub button state after confirming dialog HFP-502 --- js/settings/h5p-disable-hub.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/settings/h5p-disable-hub.js b/js/settings/h5p-disable-hub.js index 7864695..406e8b2 100644 --- a/js/settings/h5p-disable-hub.js +++ b/js/settings/h5p-disable-hub.js @@ -51,17 +51,17 @@ }).appendTo($(H5PDisableHubData.overlaySelector).get(0)); confirmationDialog.on('confirmed', function () { - disableButton.get(0).checked = false; + enableButton.get(0).checked = true; }); confirmationDialog.on('canceled', function () { - disableButton.get(0).checked = true; + enableButton.get(0).checked = false; }); - var disableButton = $(H5PDisableHubData.selector); - disableButton.change(function () { + var enableButton = $(H5PDisableHubData.selector); + enableButton.change(function () { if ($(this).is(':checked')) { - confirmationDialog.show(disableButton.offset().top); + confirmationDialog.show(enableButton.offset().top); } }); }); From e88a23d26505364d3d4772833c03c8aaaf461930 Mon Sep 17 00:00:00 2001 From: thomasmars Date: Thu, 23 Feb 2017 14:54:37 +0100 Subject: [PATCH 10/12] Changed hub variable name to match new settings name HFP-502 --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index c4ad467..d942c25 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2822,7 +2822,7 @@ class H5PCore { public function checkSetupForRequirements() { $errors = $this->checkSetupErrorMessage(); - $this->h5pF->setOption('hub_is_disabled', !empty($errors)); + $this->h5pF->setOption('hub_is_enabled', !empty($errors)); if (!empty($errors)) { foreach ($errors as $err) { $this->h5pF->setErrorMessage($err); From 585f4d238a3fdec161178209e20607c75e654b7a Mon Sep 17 00:00:00 2001 From: thomasmars Date: Thu, 23 Feb 2017 15:22:55 +0100 Subject: [PATCH 11/12] Fixed incorrect hub enabled value after server check HFP-502 --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index d942c25..4ea0e70 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2822,7 +2822,7 @@ class H5PCore { public function checkSetupForRequirements() { $errors = $this->checkSetupErrorMessage(); - $this->h5pF->setOption('hub_is_enabled', !empty($errors)); + $this->h5pF->setOption('hub_is_enabled', empty($errors)); if (!empty($errors)) { foreach ($errors as $err) { $this->h5pF->setErrorMessage($err); From 1dec6453fdb249789125c3dc3b36dc3f30e3baae Mon Sep 17 00:00:00 2001 From: thomasmars Date: Fri, 24 Feb 2017 09:47:44 +0100 Subject: [PATCH 12/12] Check write access of H5P folder HFP-502 --- h5p-default-storage.class.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index 19cb2fe..3ea2ba9 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -390,25 +390,10 @@ class H5PDefaultStorage implements \H5PFileStorage { * Check if server setup has write permission to * the required folders * - * @return bool True if server has the proper write access + * @return bool True if site can write to the H5P files folder */ public function hasWriteAccess() { - $dirs = array( - '/content', - '/libraries', - '/cachedassets', - '/temp', - '/editor', - '/exports' - ); - - // Check that directories are writable - $has_write_access = TRUE; - foreach ($dirs as $dir) { - $has_write_access = $has_write_access && self::dirReady($this->path . $dir); - } - - return $has_write_access; + return self::dirReady($this->path); } /**