From 43748bc4b8ea36e0536e683e794112bfe3351978 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Fri, 15 Jul 2016 15:33:11 +0200 Subject: [PATCH 1/6] Add documentation regarding stylePatterns --- h5p.classes.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 1021375..20ac82a 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2863,6 +2863,7 @@ class H5PContentValidator { // Determine allowed style tags $stylePatterns = array(); + // All styles must be start to end patterns (^...$) if (isset($semantics->font)) { if (isset($semantics->font->size) && $semantics->font->size) { $stylePatterns[] = '/^font-size: *[0-9.]+(em|px|%) *;?$/i'; @@ -3519,6 +3520,7 @@ class H5PContentValidator { // Allow certain styles foreach ($allowedStyles as $pattern) { if (preg_match($pattern, $match[1])) { + // All patterns are start to end patterns, and CKEditor adds one span per style $attrArr[] = 'style="' . $match[1] . '"'; break; } From 9f7b545f0201452b7568a049f9ce7f9d19ba1abe Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 15 Jul 2016 16:14:32 +0200 Subject: [PATCH 2/6] Added lost part of old fix HVP-212 --- js/h5p.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/h5p.js b/js/h5p.js index 5de66e2..60cfdd4 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -134,6 +134,7 @@ H5P.init = function (target) { }); dialog.open(); } + // If previousState is false we don't have a previous state }); // Create new instance. @@ -1849,7 +1850,7 @@ H5P.createTitle = function (rawTitle, maxLength) { H5PIntegration.contents = H5PIntegration.contents || {}; var content = H5PIntegration.contents['cid-' + contentId] || {}; var preloadedData = content.contentUserData; - if (preloadedData && preloadedData[subContentId] && preloadedData[subContentId][dataId]) { + if (preloadedData && preloadedData[subContentId] && preloadedData[subContentId][dataId] !== undefined) { if (preloadedData[subContentId][dataId] === 'RESET') { done(undefined, null); return; From 8b31f88ca84f9eb2e99699dad0a10bbc53fc9c4e Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Wed, 27 Jul 2016 16:17:58 +0200 Subject: [PATCH 3/6] Increase performance by removing unused code --- h5p.classes.php | 163 ------------------------------------------- library-support.json | 143 ------------------------------------- 2 files changed, 306 deletions(-) delete mode 100644 library-support.json diff --git a/h5p.classes.php b/h5p.classes.php index 20ac82a..8dc37ac 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -92,36 +92,6 @@ interface H5PFrameworkInterface { */ public function loadLibraries(); - /** - * Saving the unsupported library list - * - * @param array - * A list of unsupported libraries. Each list entry contains: - * - name: MachineName for the library - * - downloadUrl: URL to a location a new version of the library may be downloaded from - * - currentVersion: The unsupported version of the library installed on the system. - * This is an associative array containing: - * - major: The major version of the library - * - minor: The minor version of the library - * - patch: The patch version of the library - */ - public function setUnsupportedLibraries($libraries); - - /** - * Returns unsupported libraries - * - * @return array - * A list of unsupported libraries. Each entry contains an associative array with: - * - name: MachineName for the library - * - downloadUrl: URL to a location a new version of the library may be downloaded from - * - currentVersion: The unsupported version of the library installed on the system. - * This is an associative array containing: - * - major: The major version of the library - * - minor: The minor version of the library - * - patch: The patch version of the library - */ - public function getUnsupportedLibraries(); - /** * Returns the URL to the library admin page * @@ -1355,9 +1325,6 @@ class H5PStorage { // Remove temp content folder H5PCore::deleteFileTree($basePath); } - - // Update supported library list if necessary: - $this->h5pC->validateLibrarySupport(TRUE); } /** @@ -2122,9 +2089,6 @@ class H5PCore { */ public function deleteLibrary($libraryId) { $this->h5pF->deleteLibrary($libraryId); - - // Force update of unsupported libraries list: - $this->validateLibrarySupport(TRUE); } /** @@ -2335,133 +2299,6 @@ class H5PCore { return $obj ? (object) $newArr : $newArr; } - /** - * Check if currently installed H5P libraries are supported by - * the current version of core. Which versions of which libraries are supported is - * defined in the library-support.json file. - * - * @param boolean $force If TRUE, unsupported libraries list are rebuilt. If FALSE, list is - * rebuilt only if non-existing - */ - public function validateLibrarySupport($force = false) { - if (!$force && $this->h5pF->getUnsupportedLibraries() !== NULL) { - return; - } - - $minVersions = $this->getMinimumVersionsSupported(realpath(dirname(__FILE__)) . '/library-support.json'); - if ($minVersions === NULL) { - return; - } - - // Get all libraries installed, check if any of them is not supported: - $libraries = $this->h5pF->loadLibraries(); - $unsupportedLibraries = array(); - - // Iterate over all installed libraries - foreach ($libraries as $library_name => $versions) { - if (!isset($minVersions[$library_name])) { - continue; - } - $min = $minVersions[$library_name]; - - // For each version of this library, check if it is supported - foreach ($versions as $library) { - if (!$this->isLibraryVersionSupported($library, $min->versions)) { - // Current version of this library is not supported - $unsupportedLibraries[] = array ( - 'name' => $library_name, - 'downloadUrl' => $min->downloadUrl, - 'currentVersion' => array ( - 'major' => $library->major_version, - 'minor' => $library->minor_version, - 'patch' => $library->patch_version, - ) - ); - } - } - } - $this->h5pF->setUnsupportedLibraries($unsupportedLibraries); - } - - /** - * Returns a list of the minimum version of libraries that are supported. - * This is needed because some old libraries are no longer supported by core. - * - * TODO: Make it possible for the systems to cache this list between requests. - * - * @param string $path to json file - * @return array indexed using library names - */ - public function getMinimumVersionsSupported($path) { - $minSupported = array(); - - // Get list of minimum version for libraries. Some old libraries are no longer supported. - $libraries = file_get_contents($path); - if ($libraries !== FALSE) { - $libraries = json_decode($libraries); - if ($libraries !== NULL) { - foreach ($libraries as $library) { - $minSupported[$library->machineName] = (object) array( - 'versions' => $library->minimumVersions, - 'downloadUrl' => $library->downloadUrl - ); - } - } - } - - return empty($minSupported) ? NULL : $minSupported; - } - - /** - * Check if a specific version of a library is supported - * - * @param array $library An array containing versions - * @param array $minimumVersions - * @return bool TRUE if supported, otherwise FALSE - */ - public function isLibraryVersionSupported ($library, $minimumVersions) { - $major_supported = $minor_supported = $patch_supported = false; - foreach ($minimumVersions as $minimumVersion) { - // A library is supported if: - // --- major is higher than any minimum version - // --- minor is higher than any minimum version for a given major - // --- major and minor equals and patch is >= supported - /** @var object $library */ - $major_supported |= ($library->major_version > $minimumVersion->major); - - if ($library->major_version == $minimumVersion->major) { - $minor_supported |= ($library->minor_version > $minimumVersion->minor); - } - - if ($library->major_version == $minimumVersion->major && - $library->minor_version == $minimumVersion->minor) { - $patch_supported |= ($library->patch_version >= $minimumVersion->patch); - } - } - - return ($patch_supported || $minor_supported || $major_supported); - } - - /** - * Helper function for creating markup for the unsupported libraries list - * - * @param $libraries - * @return string Html - */ - public function createMarkupForUnsupportedLibraryList($libraries) { - $html = '
The following versions of H5P libraries are not supported anymore:
    '; - - foreach ($libraries as $library) { - $downloadUrl = $library['downloadUrl']; - $libraryName = $library['name']; - $currentVersion = $library['currentVersion']['major'] . '.' . $library['currentVersion']['minor'] .'.' . $library['currentVersion']['patch']; - $html .= "
  • $libraryName ($currentVersion)
  • "; - } - - $html .= '

These libraries may cause problems on this site. See here for more info
'; - return $html; - } - /** * Detects if the site was accessed from localhost, * through a local network or from the internet. diff --git a/library-support.json b/library-support.json deleted file mode 100644 index 26130cb..0000000 --- a/library-support.json +++ /dev/null @@ -1,143 +0,0 @@ -[ - { - "machineName": "H5P.CoursePresentation", - "downloadUrl": "http://h5p.org/presentation", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 64 - }, - { - "major": 1, - "minor": 1, - "patch": 10 - } - ] - }, - { - "machineName": "H5P.Blanks", - "downloadUrl": "http://h5p.org/fill-in-the-blanks", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 65 - } - ] - }, - { - "machineName": "H5P.Dialogcards", - "downloadUrl": "http://h5p.org/dialog-cards", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 28 - } - ] - }, - { - "machineName": "H5P.DragQuestion", - "downloadUrl": "http://h5p.org/drag-and-drop", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 61 - } - ] - }, - { - "machineName": "H5P.InteractiveVideo", - "downloadUrl": "http://h5p.org/interactive-video", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 31 - }, - { - "major": 1, - "minor": 1, - "patch": 10 - }, - { - "major": 1, - "minor": 2, - "patch": 10 - } - ] - }, - { - "machineName": "H5P.Flashcards", - "downloadUrl": "http://h5p.org/flashcards", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 37 - } - ] - }, - { - "machineName": "H5P.ImageHotspots", - "downloadUrl": "http://h5p.org/image-hotspots", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 5 - } - ] - }, - { - "machineName": "H5P.JoubelUI", - "downloadUrl": "http://h5p.org/fill-in-the-blanks", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 6 - } - ] - }, - { - "machineName": "H5P.MultiChoice", - "downloadUrl": "http://h5p.org/multichoice", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 51 - } - ] - }, - { - "machineName": "H5P.QuestionSet", - "downloadUrl": "http://h5p.org/question-set", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 53 - } - ] - }, - { - "machineName": "H5P.Summary", - "downloadUrl": "http://h5p.org/summary", - "minimumVersions": [ - { - "major": 1, - "minor": 0, - "patch": 38 - }, - { - "major": 1, - "minor": 1, - "patch": 4 - } - ] - } -] \ No newline at end of file From 44633fc1db2be4c2a6c70932df79378d1282ed58 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 29 Jul 2016 13:46:14 +0200 Subject: [PATCH 4/6] Updated regexp to support existing content to new content copy HFJ-2099 --- h5p.classes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 20ac82a..acca6bf 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -3101,8 +3101,8 @@ class H5PContentValidator { private function _validateFilelike(&$file, $semantics, $typeValidKeys = array()) { // Do not allow to use files from other content folders. $matches = array(); - if (preg_match('/^(\.\.\/){1,2}(\d+|editor)\/(.+)$/', $file->path, $matches)) { - $file->path = $matches[3]; + if (preg_match('/^(\.\.\/){1,2}(.*content\/)?(\d+|editor)\/(.+)$/', $file->path, $matches)) { + $file->path = $matches[4]; } // Make sure path and mime does not have any special chars From 832aebf5e07aea6986426c2291a56485385923b3 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 29 Jul 2016 14:15:00 +0200 Subject: [PATCH 5/6] Moved regexp from editor to core HFJ-2099 --- h5p.classes.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 5829b20..7b30f51 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1738,6 +1738,9 @@ class H5PCore { $this->detectSiteType(); $this->fullPluginPath = preg_replace('/\/[^\/]+[\/]?$/', '' , dirname(__FILE__)); + + // Standard regex for converting copied files paths + $this->relativePathRegExp = '/^((\.\.\/){1,2})(.*content\/)?(\d+|editor)\/(.+)$/'; } /** @@ -2938,8 +2941,8 @@ class H5PContentValidator { private function _validateFilelike(&$file, $semantics, $typeValidKeys = array()) { // Do not allow to use files from other content folders. $matches = array(); - if (preg_match('/^(\.\.\/){1,2}(.*content\/)?(\d+|editor)\/(.+)$/', $file->path, $matches)) { - $file->path = $matches[4]; + if (preg_match($this->h5pC->relativePathRegExp, $file->path, $matches)) { + $file->path = $matches[5]; } // Make sure path and mime does not have any special chars From 888a46844bf675212223799927c3f59433be4995 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 2 Aug 2016 12:57:43 +0200 Subject: [PATCH 6/6] Bumped core version --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 7b30f51..64c2ab5 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1665,7 +1665,7 @@ class H5PCore { public static $coreApi = array( 'majorVersion' => 1, - 'minorVersion' => 7 + 'minorVersion' => 8 ); public static $styles = array( 'styles/h5p.css',