Merge branch 'master' into improved-file-handling

moodle-rc3 moodle-1.0-rc.2
Frode Petterson 2016-08-02 13:37:26 +02:00
commit d946f32b81
3 changed files with 10 additions and 310 deletions

View File

@ -92,36 +92,6 @@ interface H5PFrameworkInterface {
*/ */
public function loadLibraries(); 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 * Returns the URL to the library admin page
* *
@ -1355,9 +1325,6 @@ class H5PStorage {
// Remove temp content folder // Remove temp content folder
H5PCore::deleteFileTree($basePath); H5PCore::deleteFileTree($basePath);
} }
// Update supported library list if necessary:
$this->h5pC->validateLibrarySupport(TRUE);
} }
/** /**
@ -1698,7 +1665,7 @@ class H5PCore {
public static $coreApi = array( public static $coreApi = array(
'majorVersion' => 1, 'majorVersion' => 1,
'minorVersion' => 7 'minorVersion' => 8
); );
public static $styles = array( public static $styles = array(
'styles/h5p.css', 'styles/h5p.css',
@ -1771,6 +1738,9 @@ class H5PCore {
$this->detectSiteType(); $this->detectSiteType();
$this->fullPluginPath = preg_replace('/\/[^\/]+[\/]?$/', '' , dirname(__FILE__)); $this->fullPluginPath = preg_replace('/\/[^\/]+[\/]?$/', '' , dirname(__FILE__));
// Standard regex for converting copied files paths
$this->relativePathRegExp = '/^((\.\.\/){1,2})(.*content\/)?(\d+|editor)\/(.+)$/';
} }
/** /**
@ -2122,9 +2092,6 @@ class H5PCore {
*/ */
public function deleteLibrary($libraryId) { public function deleteLibrary($libraryId) {
$this->h5pF->deleteLibrary($libraryId); $this->h5pF->deleteLibrary($libraryId);
// Force update of unsupported libraries list:
$this->validateLibrarySupport(TRUE);
} }
/** /**
@ -2335,133 +2302,6 @@ class H5PCore {
return $obj ? (object) $newArr : $newArr; 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 = '<div><span>The following versions of H5P libraries are not supported anymore:<span><ul>';
foreach ($libraries as $library) {
$downloadUrl = $library['downloadUrl'];
$libraryName = $library['name'];
$currentVersion = $library['currentVersion']['major'] . '.' . $library['currentVersion']['minor'] .'.' . $library['currentVersion']['patch'];
$html .= "<li><a href=\"$downloadUrl\">$libraryName</a> ($currentVersion)</li>";
}
$html .= '</ul><span><br>These libraries may cause problems on this site. See <a href="http://h5p.org/releases/h5p-core-1.3">here</a> for more info</div>';
return $html;
}
/** /**
* Detects if the site was accessed from localhost, * Detects if the site was accessed from localhost,
* through a local network or from the internet. * through a local network or from the internet.
@ -2863,6 +2703,7 @@ class H5PContentValidator {
// Determine allowed style tags // Determine allowed style tags
$stylePatterns = array(); $stylePatterns = array();
// All styles must be start to end patterns (^...$)
if (isset($semantics->font)) { if (isset($semantics->font)) {
if (isset($semantics->font->size) && $semantics->font->size) { if (isset($semantics->font->size) && $semantics->font->size) {
$stylePatterns[] = '/^font-size: *[0-9.]+(em|px|%) *;?$/i'; $stylePatterns[] = '/^font-size: *[0-9.]+(em|px|%) *;?$/i';
@ -3100,8 +2941,8 @@ class H5PContentValidator {
private function _validateFilelike(&$file, $semantics, $typeValidKeys = array()) { private function _validateFilelike(&$file, $semantics, $typeValidKeys = array()) {
// Do not allow to use files from other content folders. // Do not allow to use files from other content folders.
$matches = array(); $matches = array();
if (preg_match('/^(\.\.\/){1,2}(\d+|editor)\/(.+)$/', $file->path, $matches)) { if (preg_match($this->h5pC->relativePathRegExp, $file->path, $matches)) {
$file->path = $matches[3]; $file->path = $matches[5];
} }
// Make sure path and mime does not have any special chars // Make sure path and mime does not have any special chars
@ -3519,6 +3360,7 @@ class H5PContentValidator {
// Allow certain styles // Allow certain styles
foreach ($allowedStyles as $pattern) { foreach ($allowedStyles as $pattern) {
if (preg_match($pattern, $match[1])) { if (preg_match($pattern, $match[1])) {
// All patterns are start to end patterns, and CKEditor adds one span per style
$attrArr[] = 'style="' . $match[1] . '"'; $attrArr[] = 'style="' . $match[1] . '"';
break; break;
} }

View File

@ -134,6 +134,7 @@ H5P.init = function (target) {
}); });
dialog.open(); dialog.open();
} }
// If previousState is false we don't have a previous state
}); });
// Create new instance. // Create new instance.
@ -1847,7 +1848,7 @@ H5P.createTitle = function (rawTitle, maxLength) {
H5PIntegration.contents = H5PIntegration.contents || {}; H5PIntegration.contents = H5PIntegration.contents || {};
var content = H5PIntegration.contents['cid-' + contentId] || {}; var content = H5PIntegration.contents['cid-' + contentId] || {};
var preloadedData = content.contentUserData; var preloadedData = content.contentUserData;
if (preloadedData && preloadedData[subContentId] && preloadedData[subContentId][dataId]) { if (preloadedData && preloadedData[subContentId] && preloadedData[subContentId][dataId] !== undefined) {
if (preloadedData[subContentId][dataId] === 'RESET') { if (preloadedData[subContentId][dataId] === 'RESET') {
done(undefined, null); done(undefined, null);
return; return;

View File

@ -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
}
]
}
]