From 79223e6a0d7a822fa61b59efca276a0393d5f94b Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 29 Aug 2014 16:30:44 +0200 Subject: [PATCH 01/27] Adde support for restricted h5p content types. --- js/h5p-library-list.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/js/h5p-library-list.js b/js/h5p-library-list.js index a18eb93..a11e477 100644 --- a/js/h5p-library-list.js +++ b/js/h5p-library-list.js @@ -37,6 +37,7 @@ var H5PLibraryList= H5PLibraryList || {}; $.each (libraries.listData, function (index, library) { var $libraryRow = H5PUtils.createTableRow([ library.title, + '', library.numContent, library.numContentDependencies, library.numLibraryDependencies, @@ -47,6 +48,8 @@ var H5PLibraryList= H5PLibraryList || {}; ' ]); + H5PLibraryList.addRestricted($('.h5p-admin-restricted', $libraryRow), library.restrictedUrl, library.restricted); + if (library.upgradeUrl === null) { $('.h5p-admin-upgrade-library', $libraryRow).remove(); } @@ -82,6 +85,34 @@ var H5PLibraryList= H5PLibraryList || {}; return $table; }; + H5PLibraryList.addRestricted = function ($checkbox, url, selected) { + if (selected === null) { + $checkbox.remove(); + } + else { + $checkbox.change(function () { + $checkbox.attr('disabled', true); + + $.ajax({ + dataType: 'json', + url: url, + cache: false + }).fail(function () { + $checkbox.attr('disabled', false); + + // Reset + $checkbox.attr('checked', !$checkbox.is(':checked')); + }).done(function (result) { + url = result.url; + $checkbox.attr('disabled', false); + }); + }); + + if (selected) { + $checkbox.attr('checked', true); + } + } + }; // Initialize me: $(document).ready(function () { From 4729287406b32319737bf73d2f128b10fc939af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Fri, 5 Sep 2014 09:59:16 +0200 Subject: [PATCH 02/27] Added H5PCore::getLibrariesMetadata and H5PFrameworkInterface::getPlatformInfo --- h5p.classes.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 15ef52f..8bdf336 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -4,6 +4,13 @@ */ interface H5PFrameworkInterface { + /** + * Returns info for the current platform + * + * @return array An array containing info + */ + public function getPlatformInfo(); + /** * Show the user an error message * @@ -1359,7 +1366,9 @@ class H5PCore { public static $defaultContentWhitelist = 'json png jpg jpeg gif bmp tif tiff svg eot ttf woff otf webm mp4 ogg mp3 txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile'; public static $defaultLibraryWhitelistExtras = 'js css'; - + + const SECONDS_IN_WEEK = 604800; + public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $path, $development_mode, $h5pD; private $exportEnabled; @@ -2000,6 +2009,30 @@ class H5PCore { $html .= '
These libraries may cause problems on this site. See here for more info'; return $html; } + + /** + * Get a list of libraries' metadata from h5p.org. Cache it, and refetch once a week. + * + * @return mixed An object of objects keyed by machineName + */ + public function getLibrariesMetadata() { + // Fetch from cache: + $metadata = $this->h5pF->cacheGet('libraries','metadata'); + + // If not available in cache, or older than a week => refetch! + if ($metadata === NULL || $metadata->lastTimeFetched < (time() - self::SECONDS_IN_WEEK)) { + $platformInfo = $this->h5pF->getPlatformInfo(); + $json = file_get_contents('http://h5p.org/libraries-metadata.json?platform=' . json_encode($platformInfo)); + + $metadata = new stdClass(); + $metadata->json = ($json === FALSE ? NULL : json_decode($json)); + $metadata->lastTimeFetched = time(); + + $this->h5pF->cacheSet('libraries','metadata', $metadata); + } + + return $metadata->json; + } } /** From 764ba2761d561759d22598d78b92ca4289bc5616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Fri, 5 Sep 2014 14:12:46 +0200 Subject: [PATCH 03/27] Fixed bug in validation, which made library-upload on library admin page fail --- h5p.classes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 8bdf336..060c1f1 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -616,9 +616,10 @@ class H5PValidator { $missingLibraries = $this->getMissingLibraries($libraries); foreach ($missingLibraries as $missing) { if ($this->h5pF->getLibraryId($missing['machineName'], $missing['majorVersion'], $missing['minorVersion'])) { - unset($missingLibraries[$missing['machineName']]); + unset($missingLibraries[H5PCore::libraryToString($missing)]); } } + if (!empty($missingLibraries)) { foreach ($missingLibraries as $library) { $this->h5pF->setErrorMessage($this->h5pF->t('Missing required library @library', array('@library' => H5PCore::libraryToString($library)))); From a7939bf5ad0a3493bd0a0086808cc69e9853badf Mon Sep 17 00:00:00 2001 From: falcon Date: Wed, 8 Oct 2014 10:16:16 +0200 Subject: [PATCH 04/27] Improve comments --- h5p.classes.php | 145 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 109 insertions(+), 36 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index e9ef67c..7ee6d62 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -7,7 +7,10 @@ interface H5PFrameworkInterface { /** * Returns info for the current platform * - * @return array An array containing info + * @return array + * An associative array containing: + * - name: The name of the plattform, for instance "Wordpress" + * - version: The version of the pattform, for instance "4.0" */ public function getPlatformInfo(); @@ -15,7 +18,7 @@ interface H5PFrameworkInterface { * Show the user an error message * * @param string $message - * The error message + * The error message */ public function setErrorMessage($message); @@ -40,54 +43,77 @@ interface H5PFrameworkInterface { * - @variable: escape plain text to HTML * - %variable: escape text and theme as a placeholder for user-submitted * content - * @return string Translated string + * @return string + * Translated string */ public function t($message, $replacements = array()); /** * Get the Path to the last uploaded h5p * - * @return string Path to the folder where the last uploaded h5p for this session is located. + * @return string + * Path to the folder where the last uploaded h5p for this session is located. */ public function getUploadedH5pFolderPath(); /** - * @return string Path to the folder where all h5p files are stored + * @return string + * Path to the folder where all h5p files are stored */ public function getH5pPath(); /** * Get the path to the last uploaded h5p file * - * @return string Path to the last uploaded h5p + * @return string + * Path to the last uploaded h5p */ public function getUploadedH5pPath(); /** - * Get the list of the current installed libraries + * Get a list of the current installed libraries * - * @return array Associative array containg one item per machine name. This item contains an array of libraries. + * @return array + * Associative array containg one entry per machine name. + * For each machineName there is a list of libraries(with different versions) */ public function loadLibraries(); /** * Saving the unsupported library list * - * @param array A list of unsupported libraries + * @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 the 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 * - * @return string URL to admin page + * @return string + * URL to admin page */ public function getAdminUrl(); @@ -95,13 +121,13 @@ interface H5PFrameworkInterface { * Get id to an excisting library * * @param string $machineName - * The librarys machine name + * The librarys machine name * @param int $majorVersion - * The librarys major version + * The librarys major version * @param int $minorVersion - * The librarys minor version + * The librarys minor version * @return int - * The id of the specified library or FALSE + * The id of the specified library or FALSE */ public function getLibraryId($machineName, $majorVersion, $minorVersion); @@ -111,8 +137,12 @@ interface H5PFrameworkInterface { * The default extension list is part of h5p, but admins should be allowed to modify it * * @param boolean $isLibrary + * TRUE if this is the whitelist for a library. FALSE if it is the whitelist + * for the content folder we are getting * @param string $defaultContentWhitelist + * A string of file extensions separated by whitespace * @param string $defaultLibraryWhitelist + * A string of file extensions separated by whitespace */ public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist); @@ -120,10 +150,14 @@ interface H5PFrameworkInterface { * Is the library a patched version of an existing library? * * @param object $library - * The library data for a library we are checking + * An associateve array containing: + * - machineName: The library machineName + * - majorVersion: The librarys majorVersion + * - minorVersion: The librarys minorVersion + * - patchVersion: The librarys patchVersion * @return boolean - * TRUE if the library is a patched version of an excisting library - * FALSE otherwise + * TRUE if the library is a patched version of an excisting library + * FALSE otherwise */ public function isPatchedLibrary($library); @@ -151,23 +185,53 @@ interface H5PFrameworkInterface { * Also fills in the libraryId in the libraryData object if the object is new * * @param object $libraryData - * Object holding the information that is to be stored + * Associative array containing: + * - libraryId: The id of the library if it is an existing library. + * - title: The library's name + * - machineName: The library machineName + * - majorVersion: The library's majorVersion + * - minorVersion: The library's minorVersion + * - patchVersion: The library's patchVersion + * - runnable: 1 if the library is a content type, 0 otherwise + * - fullscreen(optional): 1 if the library supports fullscreen, 0 otherwise + * - embedTypes(optional): list of supported embed types + * - preloadedJs(optional): list of associative arrays containing: + * - path: path to a js file relative to the library root folder + * - preloadedCss(optional): list of associative arrays containing: + * - path: path to css file relative to the library root folder + * - dropLibraryCss(optional): list of associative arrays containing: + * - machineName: machine name for the librarys that are to drop their css + * - semantics(optional): Json describing the content structure for the library + * - language(optional): associative array containing: + * - languageCode: Translation in json format */ public function saveLibraryData(&$libraryData, $new = TRUE); /** * Insert new content. * - * @param object $content + * @param array $content + * An associative array containing: + * - id: The content id + * - params: The content in json format + * - library: An associative array containing: + * - libraryId: The id of the main library for this content * @param int $contentMainId + * Main id for the content if this is a system that supports versioning */ public function insertContent($content, $contentMainId = NULL); /** * Update old content. * - * @param object $content + * @param array $content + * An associative array containing: + * - id: The content id + * - params: The content in json format + * - library: An associative array containing: + * - libraryId: The id of the main library for this content * @param int $contentMainId + * Main id for the content if this is a system that supports versioning */ public function updateContent($content, $contentMainId = NULL); @@ -175,25 +239,31 @@ interface H5PFrameworkInterface { * Save what libraries a library is dependending on * * @param int $libraryId - * Library Id for the library we're saving dependencies for + * Library Id for the library we're saving dependencies for * @param array $dependencies - * List of dependencies in the format used in library.json + * List of dependencies as associative arrays containing: + * - machineName: The library machineName + * - majorVersion: The library's majorVersion + * - minorVersion: The library's minorVersion * @param string $dependency_type - * What type of dependency this is, for instance it might be an editor dependency + * What type of dependency this is, the following values are allowed: + * - editor + * - preloaded + * - dynamic */ public function saveLibraryDependencies($libraryId, $dependencies, $dependency_type); /** - * Copies library usage + * Give an H5P the same library dependencies as a given H5P * * @param int $contentId - * Framework specific id identifying the content + * Id identifying the content * @param int $copyFromId - * Framework specific id identifying the content to be copied + * Id identifying the content to be copied * @param int $contentMainId - * Framework specific main id for the content, typically used in frameworks - * That supports versioning. (In this case the content id will typically be - * the version id, and the contentMainId will be the frameworks content id + * Main id for the content, typically used in frameworks + * That supports versioning. (In this case the content id will typically be + * the version id, and the contentMainId will be the frameworks content id */ public function copyLibraryUsage($contentId, $copyFromId, $contentMainId = NULL); @@ -201,7 +271,7 @@ interface H5PFrameworkInterface { * Deletes content data * * @param int $contentId - * Framework specific id identifying the content + * Id identifying the content */ public function deleteContentData($contentId); @@ -209,7 +279,7 @@ interface H5PFrameworkInterface { * Delete what libraries a content item is using * * @param int $contentId - * Content Id of the content we'll be deleting library usage for + * Content Id of the content we'll be deleting library usage for */ public function deleteLibraryUsage($contentId); @@ -217,11 +287,14 @@ interface H5PFrameworkInterface { * Saves what libraries the content uses * * @param int $contentId - * Framework specific id identifying the content + * Id identifying the content * @param array $librariesInUse - * List of libraries the content uses. Libraries consist of arrays with: - * - libraryId stored in $librariesInUse[]['library']['libraryId'] - * - libraryId stored in $librariesInUse[]['preloaded'] + * List of libraries the content uses. Libraries consist of associative arrays with: + * - library: Associative array containing: + * - dropLibraryCss(optional): commasepareted list of machineNames + * - machineName: Machine name for the library + * - libraryId: Id of the library + * - type: The dependency type (editor, preloaded or dynamic) */ public function saveLibraryUsage($contentId, $librariesInUse); From c131a339a158d6047f478e27e9f7fdb5be8f51e3 Mon Sep 17 00:00:00 2001 From: falcon Date: Thu, 9 Oct 2014 19:29:20 +0200 Subject: [PATCH 05/27] Finish up commenting the interface functions --- h5p.classes.php | 130 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 106 insertions(+), 24 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 7ee6d62..75bf60e 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -294,7 +294,10 @@ interface H5PFrameworkInterface { * - dropLibraryCss(optional): commasepareted list of machineNames * - machineName: Machine name for the library * - libraryId: Id of the library - * - type: The dependency type (editor, preloaded or dynamic) + * - type: The dependency type. Allowed values: + * - editor + * - dynamic + * - preloaded */ public function saveLibraryUsage($contentId, $librariesInUse); @@ -303,8 +306,11 @@ interface H5PFrameworkInterface { * dependencies to other libraries * * @param int $library_id - * @return array The array contains two elements, keyed by 'content' and 'libraries'. - * Each element contains a number + * Library identifier + * @return array + * Associative array containing: + * - content: Number of content using the library + * - libraries: Number of libraries depending on the library */ public function getLibraryUsage($libraryId); @@ -312,62 +318,128 @@ interface H5PFrameworkInterface { * Loads a library * * @param string $machineName + * The library's machine name * @param int $majorVersion + * The library's major version * @param int $minorVersion + * The library's minor version * @return array|FALSE - * Array representing the library with dependency descriptions - * FALSE if the library doesn't exist + * FALSE if the library doesn't exist. + * Otherwise an associative array containing: + * - libraryId: The id of the library if it is an existing library. + * - title: The library's name + * - machineName: The library machineName + * - majorVersion: The library's majorVersion + * - minorVersion: The library's minorVersion + * - patchVersion: The library's patchVersion + * - runnable: 1 if the library is a content type, 0 otherwise + * - fullscreen(optional): 1 if the library supports fullscreen, 0 otherwise + * - embedTypes(optional): list of supported embed types + * - preloadedJs(optional): comma separated string with js file paths + * - preloadedCss(optional): comma separated sting with css file paths + * - dropLibraryCss(optional): list of associative arrays containing: + * - machineName: machine name for the librarys that are to drop their css + * - semantics(optional): Json describing the content structure for the library + * - preloadedDependencies(optional): list of associative arrays containing: + * - machineName: Machine name for a library this library is depending on + * - majorVersion: Major version for a library this library is depending on + * - minorVersion: Minor for a library this library is depending on + * - dynamicDependencies(optional): list of associative arrays containing: + * - machineName: Machine name for a library this library is depending on + * - majorVersion: Major version for a library this library is depending on + * - minorVersion: Minor for a library this library is depending on + * - editorDependencies(optional): list of associative arrays containing: + * - machineName: Machine name for a library this library is depending on + * - majorVersion: Major version for a library this library is depending on + * - minorVersion: Minor for a library this library is depending on */ public function loadLibrary($machineName, $majorVersion, $minorVersion); /** * Loads library semantics. * - * @param string $name library identifier. - * @param int $majorVersion library identifier. - * @param int $minorVersion library identifier. - * @return string semantics. + * @param string $machineName + * Machine name for the library + * @param int $majorVersion + * The library's major version + * @param int $minorVersion + * The library's minor version + * @return string + * The library's semantics as json */ - public function loadLibrarySemantics($name, $majorVersion, $minorVersion); + public function loadLibrarySemantics($machineName, $majorVersion, $minorVersion); /** * Makes it possible to alter the semantics, adding custom fields, etc. * * @param array $semantics - * @param string $name library identifier. - * @param int $majorVersion library identifier. - * @param int $minorVersion library identifier. + * Associative array representing the semantics + * @param string $machineName + * The library's machine name + * @param int $majorVersion + * The library's major version + * @param int $minorVersion + * The library's minor version */ - public function alterLibrarySemantics(&$semantics, $name, $majorVersion, $minorVersion); + public function alterLibrarySemantics(&$semantics, $machineName, $majorVersion, $minorVersion); /** * Delete all dependencies belonging to given library * * @param int $libraryId - * Library Id + * Library identifier */ public function deleteLibraryDependencies($libraryId); /** * Delete a library from database and file system * - * @param mixed $library Library + * @param int $libraryId + * Library identifier */ - public function deleteLibrary($library); + public function deleteLibrary($libraryId); /** * Load content. * - * @return object Content, null if not found. + * @param int $id + * Content identifier + * @return array + * Associative array containing: + * - contentId: Identifier for the content + * - params: json content as string + * - embedType: csv of embed types + * - title: The contents title + * - language: Language code for the content + * - libraryId: Id for the main library + * - libraryName: The library machine name + * - libraryMajorVersion: The library's majorVersion + * - libraryMinorVersion: The library's minorVersion + * - libraryEmbedTypes: CSV of the main library's embed types + * - libraryFullscreen: 1 if fullscreen is supported. 0 otherwise. */ public function loadContent($id); /** * Load dependencies for the given content of the given type. * - * @param int $id content. - * @param int $type dependency. + * @param int $id + * Content identifier + * @param int $type + * Dependency types. Allowed values: + * - editor + * - preloaded + * - dynamic * @return array + * List of associative arrays containing: + * - libraryId: The id of the library if it is an existing library. + * - machineName: The library machineName + * - majorVersion: The library's majorVersion + * - minorVersion: The library's minorVersion + * - patchVersion: The library's patchVersion + * - preloadedJs(optional): comma separated string with js file paths + * - preloadedCss(optional): comma separated sting with css file paths + * - dropCss(optional): csv of machine names */ public function loadContentDependencies($id, $type = NULL); @@ -375,7 +447,11 @@ interface H5PFrameworkInterface { * Get data from cache. * * @param string $group + * Identifier for the cache group * @param string $key + * Unique identifier within the group + * @return mixed + * Whatever has been stored in the cache. NULL if the entry doesn't exist */ public function cacheGet($group, $key); @@ -383,8 +459,11 @@ interface H5PFrameworkInterface { * Store data in cache. * * @param string $group + * The cache group where the data should be stored * @param string $key + * A unique key identifying where the data should be stored * @param mixed $data + * The data you want to cache */ public function cacheSet($group, $key, $data); @@ -392,20 +471,22 @@ interface H5PFrameworkInterface { * Delete data from cache. * * @param string $group + * Identifier for the cache group * @param string $key + * Unique identifier within the group */ public function cacheDel($group, $key = NULL); /** * Will invalidate the cache for the content that uses the specified library. * This means that the content dependencies has to be rebuilt, and the parameters refiltered. - * - * @param int $library_id + * + * @param int $libraryId */ - public function invalidateContentCache($library_id); + public function invalidateContentCache($libraryId); /** - * Get content without cache. + * Get number of content that hasn't been cached */ public function getNotCached(); @@ -413,6 +494,7 @@ interface H5PFrameworkInterface { * Get number of contents using library as main library. * * @param int $library_id + * Identifier for a library */ public function getNumContent($library_id); } From c9914966f334c4e3f23270e11b0f24acd643f0fe Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 10 Oct 2014 13:56:48 +0200 Subject: [PATCH 06/27] Space fix. --- h5p.classes.php | 340 ++++++++++++++++++++++++------------------------ 1 file changed, 170 insertions(+), 170 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 75bf60e..72264ec 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -6,14 +6,14 @@ interface H5PFrameworkInterface { /** * Returns info for the current platform - * - * @return array + * + * @return array * An associative array containing: * - name: The name of the plattform, for instance "Wordpress" * - version: The version of the pattform, for instance "4.0" */ public function getPlatformInfo(); - + /** * Show the user an error message * @@ -69,19 +69,19 @@ interface H5PFrameworkInterface { * Path to the last uploaded h5p */ public function getUploadedH5pPath(); - + /** * Get a list of the current installed libraries - * - * @return array + * + * @return array * Associative array containg one entry per machine name. * For each machineName there is a list of libraries(with different versions) */ public function loadLibraries(); - + /** * Saving the unsupported library list - * + * * @param array * A list of unsupported libraries. Each list entry contains: * - name: MachineName for the library @@ -93,10 +93,10 @@ interface H5PFrameworkInterface { * - 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 @@ -108,10 +108,10 @@ interface H5PFrameworkInterface { * - patch: The patch version of the library */ public function getUnsupportedLibraries(); - + /** * Returns the URL to the library admin page - * + * * @return string * URL to admin page */ @@ -145,7 +145,7 @@ interface H5PFrameworkInterface { * A string of file extensions separated by whitespace */ public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist); - + /** * Is the library a patched version of an existing library? * @@ -203,13 +203,13 @@ interface H5PFrameworkInterface { * - machineName: machine name for the librarys that are to drop their css * - semantics(optional): Json describing the content structure for the library * - language(optional): associative array containing: - * - languageCode: Translation in json format + * - languageCode: Translation in json format */ public function saveLibraryData(&$libraryData, $new = TRUE); - + /** * Insert new content. - * + * * @param array $content * An associative array containing: * - id: The content id @@ -220,10 +220,10 @@ interface H5PFrameworkInterface { * Main id for the content if this is a system that supports versioning */ public function insertContent($content, $contentMainId = NULL); - + /** * Update old content. - * + * * @param array $content * An associative array containing: * - id: The content id @@ -234,7 +234,7 @@ interface H5PFrameworkInterface { * Main id for the content if this is a system that supports versioning */ public function updateContent($content, $contentMainId = NULL); - + /** * Save what libraries a library is dependending on * @@ -302,9 +302,9 @@ interface H5PFrameworkInterface { public function saveLibraryUsage($contentId, $librariesInUse); /** - * Get number of content/nodes using a library, and the number of + * Get number of content/nodes using a library, and the number of * dependencies to other libraries - * + * * @param int $library_id * Library identifier * @return array @@ -368,7 +368,7 @@ interface H5PFrameworkInterface { * The library's semantics as json */ public function loadLibrarySemantics($machineName, $majorVersion, $minorVersion); - + /** * Makes it possible to alter the semantics, adding custom fields, etc. * @@ -378,7 +378,7 @@ interface H5PFrameworkInterface { * The library's machine name * @param int $majorVersion * The library's major version - * @param int $minorVersion + * @param int $minorVersion * The library's minor version */ public function alterLibrarySemantics(&$semantics, $machineName, $majorVersion, $minorVersion); @@ -390,15 +390,15 @@ interface H5PFrameworkInterface { * Library identifier */ public function deleteLibraryDependencies($libraryId); - + /** * Delete a library from database and file system - * + * * @param int $libraryId * Library identifier */ public function deleteLibrary($libraryId); - + /** * Load content. * @@ -419,7 +419,7 @@ interface H5PFrameworkInterface { * - libraryFullscreen: 1 if fullscreen is supported. 0 otherwise. */ public function loadContent($id); - + /** * Load dependencies for the given content of the given type. * @@ -442,10 +442,10 @@ interface H5PFrameworkInterface { * - dropCss(optional): csv of machine names */ public function loadContentDependencies($id, $type = NULL); - + /** * Get data from cache. - * + * * @param string $group * Identifier for the cache group * @param string $key @@ -454,10 +454,10 @@ interface H5PFrameworkInterface { * Whatever has been stored in the cache. NULL if the entry doesn't exist */ public function cacheGet($group, $key); - + /** * Store data in cache. - * + * * @param string $group * The cache group where the data should be stored * @param string $key @@ -466,17 +466,17 @@ interface H5PFrameworkInterface { * The data you want to cache */ public function cacheSet($group, $key, $data); - + /** * Delete data from cache. - * + * * @param string $group * Identifier for the cache group * @param string $key * Unique identifier within the group */ public function cacheDel($group, $key = NULL); - + /** * Will invalidate the cache for the content that uses the specified library. * This means that the content dependencies has to be rebuilt, and the parameters refiltered. @@ -484,15 +484,15 @@ interface H5PFrameworkInterface { * @param int $libraryId */ public function invalidateContentCache($libraryId); - + /** * Get number of content that hasn't been cached */ public function getNotCached(); - + /** * Get number of contents using library as main library. - * + * * @param int $library_id * Identifier for a library */ @@ -609,14 +609,14 @@ class H5PValidator { // Extract and then remove the package file. $zip = new ZipArchive; - + // Only allow files with the .h5p extension: if (strtolower(substr($tmpPath, -3)) !== 'h5p') { $this->h5pF->setErrorMessage($this->h5pF->t('The file you uploaded is not a valid HTML5 Package (It does not have the .h5p file extension)')); H5PCore::deleteFileTree($tmpDir); return; } - + if ($zip->open($tmpPath) === true) { $zip->extractTo($tmpDir); $zip->close(); @@ -644,7 +644,7 @@ class H5PValidator { if ($skipContent === TRUE) { continue; } - + $mainH5pData = $this->getJsonData($filePath); if ($mainH5pData === FALSE) { $valid = FALSE; @@ -702,7 +702,7 @@ class H5PValidator { } $libraryH5PData = $this->getLibraryData($file, $filePath, $tmpDir); - + if ($libraryH5PData !== FALSE) { // Library's directory name must be: // - @@ -738,7 +738,7 @@ class H5PValidator { } if ($valid) { if ($upgradeOnly) { - // When upgrading, we opnly add allready installed libraries, + // When upgrading, we opnly add allready installed libraries, // and new dependent libraries $upgrades = array(); foreach ($libraries as &$library) { @@ -756,25 +756,25 @@ class H5PValidator { } } } - + $libraries = $upgrades; } - + $this->h5pC->librariesJsonData = $libraries; - + if ($skipContent === FALSE) { $this->h5pC->mainJsonData = $mainH5pData; $this->h5pC->contentJsonData = $contentJsonData; $libraries['mainH5pData'] = $mainH5pData; // Check for the dependencies in h5p.json as well as in the libraries } - + $missingLibraries = $this->getMissingLibraries($libraries); foreach ($missingLibraries as $missing) { if ($this->h5pF->getLibraryId($missing['machineName'], $missing['majorVersion'], $missing['minorVersion'])) { unset($missingLibraries[H5PCore::libraryToString($missing)]); } } - + if (!empty($missingLibraries)) { foreach ($missingLibraries as $library) { $this->h5pF->setErrorMessage($this->h5pF->t('Missing required library @library', array('@library' => H5PCore::libraryToString($library)))); @@ -1183,7 +1183,7 @@ class H5PStorage { public $h5pF; public $h5pC; - + public $contentId = NULL; // Quick fix so WP can get ID of new content. /** @@ -1214,11 +1214,11 @@ class H5PStorage { $library_saved = FALSE; $upgradedLibsCount = 0; $mayUpdateLibraries = $this->h5pF->mayUpdateLibraries(); - + foreach ($this->h5pC->librariesJsonData as &$library) { $libraryId = $this->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']); $library['saveDependencies'] = TRUE; - + if (!$libraryId) { $new = TRUE; } @@ -1263,21 +1263,21 @@ class H5PStorage { if (isset($library['editorDependencies'])) { $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor'); } - + // Make sure libraries dependencies, parameter filtering and export files gets regenerated for all content who uses this library. $this->h5pF->invalidateContentCache($library['libraryId']); - + $upgradedLibsCount++; } } - + if (!$skipContent) { $current_path = $this->h5pF->getUploadedH5pFolderPath() . DIRECTORY_SEPARATOR . 'content'; - + // Find out which libraries are used by this package/content $librariesInUse = array(); $this->h5pC->findLibraryDependencies($librariesInUse, $this->h5pC->mainJsonData); - + // Save content if ($content === NULL) { $content = array(); @@ -1294,19 +1294,19 @@ class H5PStorage { if (!is_dir($contents_path)) { mkdir($contents_path, 0777, true); } - + // Move the content folder $destination_path = $contents_path . DIRECTORY_SEPARATOR . $contentId; @rename($current_path, $destination_path); - + // Save the content library dependencies $this->h5pF->saveLibraryUsage($contentId, $librariesInUse); H5PCore::deleteFileTree($this->h5pF->getUploadedH5pFolderPath()); } - + // Update supported library list if neccessary: $this->h5pC->validateLibrarySupport(TRUE); - + if ($upgradeOnly) { // TODO - support translation $this->h5pF->setInfoMessage($this->h5pF->t('@num libraries were upgraded!', array('@num' => $upgradedLibsCount))); @@ -1314,7 +1314,7 @@ class H5PStorage { return $library_saved; } - + /** * Delete an H5P package * @@ -1383,7 +1383,7 @@ Class H5PExport { $this->h5pF = $H5PFramework; $this->h5pC = $H5PCore; } - + /** * Return path to h5p package. * @@ -1396,7 +1396,7 @@ Class H5PExport { $h5pDir = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR; $tempPath = $h5pDir . 'temp' . DIRECTORY_SEPARATOR . $content['id']; $zipPath = $h5pDir . 'exports' . DIRECTORY_SEPARATOR . $content['id'] . '.h5p'; - + // Temp dir to put the h5p files in @mkdir($tempPath, 0777, TRUE); @mkdir($h5pDir . 'exports', 0777, TRUE); @@ -1413,8 +1413,8 @@ Class H5PExport { // Build h5p.json $h5pJson = array ( 'title' => $content['title'], - // TODO - stop using 'und', this is not the preferred way. - // Either remove language from the json if not existing, or use "language": null + // TODO - stop using 'und', this is not the preferred way. + // Either remove language from the json if not existing, or use "language": null 'language' => isset($content['language']) ? $content['language'] : 'und', 'mainLibrary' => $content['library']['name'], 'embedTypes' => $embedTypes, @@ -1423,7 +1423,7 @@ Class H5PExport { // Add dependencies to h5p foreach ($content['dependencies'] as $dependency) { $library = $dependency['library']; - + // Copy library to h5p $source = isset($library['path']) ? $library['path'] : $h5pDir . 'libraries' . DIRECTORY_SEPARATOR . H5PCore::libraryToString($library, TRUE); $destination = $tempPath . DIRECTORY_SEPARATOR . $library['machineName']; @@ -1431,7 +1431,7 @@ Class H5PExport { // Do not add editor dependencies to h5p json. if ($dependency['type'] === 'editor') { - continue; + continue; } $h5pJson[$dependency['type'] . 'Dependencies'][] = array( @@ -1495,7 +1495,7 @@ Class H5PExport { */ private function addEditorLibraries($libraries, $editorLibraries) { foreach ($editorLibraries as $editorLibrary) { - $libraries[$editorLibrary['machineName']] = $editorLibrary; + $libraries[$editorLibrary['machineName']] = $editorLibrary; } return $libraries; } @@ -1524,9 +1524,9 @@ class H5PCore { public static $defaultContentWhitelist = 'json png jpg jpeg gif bmp tif tiff svg eot ttf woff otf webm mp4 ogg mp3 txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile'; public static $defaultLibraryWhitelistExtras = 'js css'; - - const SECONDS_IN_WEEK = 604800; - + + const SECONDS_IN_WEEK = 604800; + public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $path, $development_mode, $h5pD; private $exportEnabled; @@ -1542,12 +1542,12 @@ class H5PCore { */ public function __construct($H5PFramework, $path, $language = 'en', $export = FALSE, $development_mode = H5PDevelopment::MODE_NONE) { $this->h5pF = $H5PFramework; - + $this->h5pF = $H5PFramework; $this->path = $path; $this->exportEnabled = $export; $this->development_mode = $development_mode; - + if ($development_mode & H5PDevelopment::MODE_LIBRARY) { $this->h5pD = new H5PDevelopment($this->h5pF, $path, $language); } @@ -1555,7 +1555,7 @@ class H5PCore { /** * Save content and clear cache. - * + * * @param array $content * @return int Content ID */ @@ -1564,17 +1564,17 @@ class H5PCore { $this->h5pF->updateContent($content, $contentMainId); } else { - $content['id'] = $this->h5pF->insertContent($content, $contentMainId); + $content['id'] = $this->h5pF->insertContent($content, $contentMainId); } - + if (!isset($content['filtered'])) { // TODO: Add filtered to all impl. and remove $this->h5pF->cacheDel('parameters', $content['id']); } - + return $content['id']; } - + /** * Load content. * @@ -1583,7 +1583,7 @@ class H5PCore { */ public function loadContent($id) { $content = $this->h5pF->loadContent($id); - + if ($content !== NULL) { $content['library'] = array( 'id' => $content['libraryId'], @@ -1594,7 +1594,7 @@ class H5PCore { 'fullscreen' => $content['libraryFullscreen'], ); unset($content['libraryId'], $content['libraryName'], $content['libraryEmbedTypes'], $content['libraryFullscreen']); - + // // TODO: Move to filterParameters? // if ($this->development_mode & H5PDevelopment::MODE_CONTENT) { // // TODO: Remove Drupal specific stuff @@ -1608,13 +1608,13 @@ class H5PCore { // } // } } - + return $content; } - + /** * Filter content run parameters, rebuild content dependecy cache and export file. - * + * * @param Object $content * @return Object NULL on failure. */ @@ -1630,7 +1630,7 @@ class H5PCore { if ($params !== NULL) { return $params; } - + // Validate and filter against main library semantics. $validator = new H5PContentValidator($this->h5pF, $this); $params = (object) array( @@ -1640,17 +1640,17 @@ class H5PCore { $validator->validateLibrary($params, (object) array('options' => array($params->library))); $params = json_encode($params->params); - + // Update content dependencies. $content['dependencies'] = $validator->getDependencies(); $this->h5pF->deleteLibraryUsage($content['id']); $this->h5pF->saveLibraryUsage($content['id'], $content['dependencies']); - + if ($this->exportEnabled) { // Recreate export file $exporter = new H5PExport($this->h5pF, $this); $exporter->createExportFile($content); - + // TODO: Should we rather create the file once first accessed, like imagecache? } @@ -1658,7 +1658,7 @@ class H5PCore { $this->h5pF->cacheSet('parameters', $content['id'], $params); return $params; } - + /** * Find the files required for this content to work. * @@ -1667,10 +1667,10 @@ class H5PCore { */ public function loadContentDependencies($id, $type = NULL) { $dependencies = $this->h5pF->loadContentDependencies($id, $type); - + if ($this->development_mode & H5PDevelopment::MODE_LIBRARY) { $developmentLibraries = $this->h5pD->getLibraries(); - + foreach ($dependencies as $key => $dependency) { $libraryString = H5PCore::libraryToString($dependency); if (isset($developmentLibraries[$libraryString])) { @@ -1679,13 +1679,13 @@ class H5PCore { } } } - + return $dependencies; } - + /** * Get all dependency assets of the given type - * + * * @param array $dependency * @param string $type * @param array $assets @@ -1695,12 +1695,12 @@ class H5PCore { if (empty($dependency[$type]) || $dependency[$type][0] === '') { return; } - + // Check if we should skip CSS. if ($type === 'preloadedCss' && (isset($dependency['dropCss']) && $dependency['dropCss'] === '1')) { return; } - + foreach ($dependency[$type] as $file) { $assets[] = (object) array( 'path' => $dependency['path'] . '/' . trim(is_array($file) ? $file['path'] : $file), @@ -1708,23 +1708,23 @@ class H5PCore { ); } } - + /** * Combines path with cache buster / version. - * + * * @param array $assets * @return array */ public function getAssetsUrls($assets) { $urls = array(); - + foreach ($assets as $asset) { $urls[] = $asset->path . $asset->version; } - + return $urls; } - + /** * Return file paths for all dependecies files. * @@ -1742,14 +1742,14 @@ class H5PCore { $dependency['preloadedJs'] = explode(',', $dependency['preloadedJs']); $dependency['preloadedCss'] = explode(',', $dependency['preloadedCss']); } - + $dependency['version'] = "?ver={$dependency['majorVersion']}.{$dependency['minorVersion']}.{$dependency['patchVersion']}"; $this->getDependencyAssets($dependency, 'preloadedJs', $files['scripts']); $this->getDependencyAssets($dependency, 'preloadedCss', $files['styles']); } return $files; } - + /** * Load library semantics. * @@ -1761,20 +1761,20 @@ class H5PCore { // Try to load from dev lib $semantics = $this->h5pD->getSemantics($name, $majorVersion, $minorVersion); } - + if ($semantics === NULL) { // Try to load from DB. $semantics = $this->h5pF->loadLibrarySemantics($name, $majorVersion, $minorVersion); } - + if ($semantics !== NULL) { $semantics = json_decode($semantics); $this->h5pF->alterLibrarySemantics($semantics, $name, $majorVersion, $minorVersion); } - + return $semantics; } - + /** * Load library. * @@ -1789,31 +1789,31 @@ class H5PCore { $library['semantics'] = $this->h5pD->getSemantics($name, $majorVersion, $minorVersion); } } - + if ($library === NULL) { // Try to load from DB. $library = $this->h5pF->loadLibrary($name, $majorVersion, $minorVersion); } - + return $library; } - + /** * Deletes a library - * + * * @param unknown $libraryId */ public function deleteLibrary($libraryId) { $this->h5pF->deleteLibrary($libraryId); - + // Force update of unsupported libraries list: $this->validateLibrarySupport(TRUE); } - + /** - * Recursive. Goes through the dependency tree for the given library and + * Recursive. Goes through the dependency tree for the given library and * adds all the dependencies to the given array in a flat format. - * + * * @param array $librariesUsed Flat list of all dependencies. * @param array $library To find all dependencies for. * @param bool $editor Used interally to force all preloaded sub dependencies of an editor dependecy to be editor dependencies. @@ -1824,18 +1824,18 @@ class H5PCore { if (!isset($library[$property])) { continue; // Skip, no such dependencies. } - + if ($type === 'preloaded' && $editor === TRUE) { // All preloaded dependencies of an editor library is set to editor. $type = 'editor'; } - + foreach ($library[$property] as $dependency) { $dependencyKey = $type . '-' . $dependency['machineName']; if (isset($dependencies[$dependencyKey]) === TRUE) { continue; // Skip, already have this. } - + $dependencyLibrary = $this->loadLibrary($dependency['machineName'], $dependency['majorVersion'], $dependency['minorVersion']); if ($dependencyLibrary) { $dependencies[$dependencyKey] = array( @@ -1964,7 +1964,7 @@ class H5PCore { } return FALSE; } - + /** * Determine the correct embed type to use. * @@ -1973,32 +1973,32 @@ class H5PCore { public static function determineEmbedType($contentEmbedType, $libraryEmbedTypes) { // Detect content embed type $embedType = strpos(strtolower($contentEmbedType), 'div') !== FALSE ? 'div' : 'iframe'; - + if ($libraryEmbedTypes !== NULL && $libraryEmbedTypes !== '') { // Check that embed type is available for library $embedTypes = strtolower($libraryEmbedTypes); if (strpos($embedTypes, $embedType) === FALSE) { // Not available, pick default. $embedType = strpos($embedTypes, 'div') !== FALSE ? 'div' : 'iframe'; - } + } } - + return $embedType; } - + /** * Get the absolute version for the library as a human readable string. - * + * * @param object $library * @return string */ public static function libraryVersion($library) { return $library->major_version . '.' . $library->minor_version . '.' . $library->patch_version; } - + /** * Detemine which versions content with the given library can be upgraded to. - * + * * @param object $library * @param array $versions * @return array @@ -2014,13 +2014,13 @@ class H5PCore { return $upgrades; } - + /** * Converts all the properties of the given object or array from * snake_case to camelCase. Useful after fetching data from the database. - * + * * Note that some databases does not support camelCase. - * + * * @param mixed $arr input * @param boolean $obj return object * @return mixed object or array @@ -2039,36 +2039,36 @@ class H5PCore { return $obj ? (object) $newArr : $newArr; } - + /** * Check if currently installed H5P libraries are supported by * the current versjon of core. Which versions of which libraries are supported is * defined in the library-support.json file. * - * @param boolean If TRUE, unsupported libraries list are rebuilt. If FALSE, list is + * @param boolean If TRUE, unsupported libraries list are rebuilt. If FALSE, list is * rebuilt only if non-existing */ public function validateLibrarySupport($force = false) { if (!($this->h5pF->getUnsupportedLibraries() === NULL || $force)) { 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)) { @@ -2084,23 +2084,23 @@ class H5PCore { ); } } - + $this->h5pF->setUnsupportedLibraries(empty($unsupportedLibraries) ? NULL : $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) { @@ -2114,13 +2114,13 @@ class H5PCore { } } } - + return empty($minSupported) ? NULL : $minSupported; } - + /** * Check if a specific version of a library is supported - * + * * @param object library * @param array An array containing versions * @return boolean TRUE if supported, otherwise FALSE @@ -2133,62 +2133,62 @@ class H5PCore { // --- minor is higher than any minimumversion for a given major // --- major and minor equals and patch is >= supported $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 - * + * Helper function for creating markup for the unsupported libraries list + * * TODO: Make help text translatable - * + * * @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; } - + /** * Get a list of libraries' metadata from h5p.org. Cache it, and refetch once a week. - * + * * @return mixed An object of objects keyed by machineName */ public function getLibrariesMetadata() { // Fetch from cache: $metadata = $this->h5pF->cacheGet('libraries','metadata'); - + // If not available in cache, or older than a week => refetch! if ($metadata === NULL || $metadata->lastTimeFetched < (time() - self::SECONDS_IN_WEEK)) { $platformInfo = $this->h5pF->getPlatformInfo(); $json = file_get_contents('http://h5p.org/libraries-metadata.json?platform=' . json_encode($platformInfo)); - + $metadata = new stdClass(); $metadata->json = ($json === FALSE ? NULL : json_decode($json)); $metadata->lastTimeFetched = time(); - + $this->h5pF->cacheSet('libraries','metadata', $metadata); } - + return $metadata->json; } } @@ -2226,24 +2226,24 @@ class H5PContentValidator { 'select' => 'validateSelect', 'library' => 'validateLibrary', ); - + // Keep track of the libraries we load to avoid loading it multiple times. $this->libraries = array(); // TODO: Should this possible be done in core's loadLibrary? This might be done multiple places. - + // Keep track of all dependencies for the given content. $this->dependencies = array(); } /** * Get the flat dependecy tree. - * + * * @return array */ public function getDependencies() { return $this->dependencies; } - + /** * Validate given text value against text semantics. */ @@ -2468,19 +2468,19 @@ class H5PContentValidator { $validkeys = array_merge($validkeys, $semantics->extraAttributes); // TODO: Validate extraAttributes } $this->filterParams($file, $validkeys); - + if (isset($file->width)) { $file->width = intval($file->width); } - + if (isset($file->height)) { $file->height = intval($file->height); } - + if (isset($file->codecs)) { $file->codecs = htmlspecialchars($file->codecs, ENT_QUOTES, 'UTF-8', FALSE); } - + if (isset($file->quality)) { if (!is_object($file->quality) || !isset($file->quality->level) || !isset($file->quality->label)) { unset($file->quality); @@ -2491,7 +2491,7 @@ class H5PContentValidator { $file->quality->label = htmlspecialchars($file->quality->label, ENT_QUOTES, 'UTF-8', FALSE); } } - + if (isset($file->copyright)) { $this->validateGroup($file->copyright, H5PContentValidator::getCopyrightSemantics()); } @@ -2594,7 +2594,7 @@ class H5PContentValidator { $value = new stdClass(); return; } - + if (!isset($this->libraries[$value->library])) { $libspec = H5PCore::libraryFromString($value->library); $library = $this->h5pC->loadLibrary($libspec['machineName'], $libspec['majorVersion'], $libspec['minorVersion']); @@ -2888,7 +2888,7 @@ class H5PContentValidator { /** * Processes an HTML attribute value and strips dangerous protocols from URLs. - * + * * @param $string * The string with the attribute value. * @param $decode @@ -2961,10 +2961,10 @@ class H5PContentValidator { return $uri; } - + public static function getCopyrightSemantics() { static $semantics; - + if ($semantics === NULL) { $semantics = (object) array( 'name' => 'copyright', @@ -3062,7 +3062,7 @@ class H5PContentValidator { ) ); } - + return $semantics; } } From 0a8bd6a5b5edeff495bd31de0208ba342775dddb Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 10 Oct 2014 13:57:43 +0200 Subject: [PATCH 07/27] Fixed typos. --- h5p.classes.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 72264ec..f6f9855 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -118,7 +118,7 @@ interface H5PFrameworkInterface { public function getAdminUrl(); /** - * Get id to an excisting library + * Get id to an existing library * * @param string $machineName * The librarys machine name @@ -156,7 +156,7 @@ interface H5PFrameworkInterface { * - minorVersion: The librarys minorVersion * - patchVersion: The librarys patchVersion * @return boolean - * TRUE if the library is a patched version of an excisting library + * TRUE if the library is a patched version of an existing library * FALSE otherwise */ public function isPatchedLibrary($library); @@ -305,7 +305,7 @@ interface H5PFrameworkInterface { * Get number of content/nodes using a library, and the number of * dependencies to other libraries * - * @param int $library_id + * @param int $libraryId * Library identifier * @return array * Associative array containing: @@ -493,10 +493,10 @@ interface H5PFrameworkInterface { /** * Get number of contents using library as main library. * - * @param int $library_id + * @param int $libraryId * Identifier for a library */ - public function getNumContent($library_id); + public function getNumContent($libraryId); } /** From ad03edf6620d8d55204b1ac8d4e70e080cd79cda Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Thu, 30 Oct 2014 15:51:20 +0100 Subject: [PATCH 08/27] Added generic fallback for libraries that hasn't implemented getCopyrights. --- js/h5p.js | 73 +++++++++++++++++++++++++++++++++++++++++++++----- styles/h5p.css | 4 ++- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 9cea78d..65bf07e 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -70,11 +70,12 @@ H5P.init = function () { window.location.href = contentData.exportUrl; }); } - if (instance.getCopyrights !== undefined) { - // Display copyrights button - H5P.jQuery('
  • ' + H5P.t('copyrights') + '
  • ').appendTo($actions).click(function () { - H5P.openCopyrightsDialog($actions, instance); - }); + + // Display copyrights button + H5P.jQuery('
  • ' + H5P.t('copyrights') + '
  • ').appendTo($actions).click(function () { + H5P.openCopyrightsDialog($actions, instance, library.params, contentId); + }); + } if (contentData.embedCode !== undefined) { // Display embed button @@ -482,19 +483,77 @@ H5P.Dialog = function (name, title, content, $element) { * @param {object} instance to get copyright information from. * @returns {undefined} */ -H5P.openCopyrightsDialog = function ($element, instance) { - var copyrights = instance.getCopyrights(); +H5P.openCopyrightsDialog = function ($element, instance, parameters, contentId) { + var copyrights; + if (instance.getCopyrights !== undefined) { + // Use the instance's own copyright generator + copyrights = instance.getCopyrights(); + } + else { + // Create a generic flat copyright list + copyrights = new H5P.ContentCopyrights(); + H5P.findCopyrights(copyrights, parameters, contentId); + } + if (copyrights !== undefined) { + // Convert to string copyrights = copyrights.toString(); } if (copyrights === undefined || copyrights === '') { + // Use no copyrights default text copyrights = H5P.t('noCopyrights'); } + // Open dialog with copyright information var dialog = new H5P.Dialog('copyrights', H5P.t('copyrightInformation'), copyrights, $element); dialog.open(); }; +/** + * Gather a flat list of copyright information from the given parameters. + * + * @param {H5P.ContentCopyrights} info Used to collect all information in. + * @param {(Object|Arrray)} parameters To search for file objects in. + * @param {Number} contentId Used to insert thumbnails for images. + * @returns {undefined} + */ +H5P.findCopyrights = function (info, parameters, contentId) { + // Cycle through parameters + for (var field in parameters) { + if (!parameters.hasOwnProperty(field)) { + continue; // Do not check + } + var value = parameters[field]; + + if (value instanceof Array) { + // Cycle through array + H5P.findCopyrights(info, value, contentId); + } + else if (value instanceof Object) { + // Check if object is a file with copyrights + if (value.copyright === undefined || + value.copyright.license === undefined || + value.path === undefined || + value.mime === undefined) { + + // Nope, cycle throught object + H5P.findCopyrights(info, value, contentId); + } + else { + // Found file, add copyrights + var copyrights = new H5P.MediaCopyright(value.copyright); + if (value.width !== undefined && value.height !== undefined) { + copyrights.setThumbnail(new H5P.Thumbnail(H5P.getPath(value.path, contentId), value.width, value.height)); + } + info.addMedia(copyrights); + } + } + else { + } + } +}; + + /** * Display a dialog containing the embed code. * diff --git a/styles/h5p.css b/styles/h5p.css index c9099c6..3ceb8e8 100644 --- a/styles/h5p.css +++ b/styles/h5p.css @@ -234,6 +234,8 @@ div.h5p-fullscreen { font-size: 1.5em; margin: 0.25em 0; position: absolute; + line-height: 1.25em; + padding: 0; } .h5p-embed-dialog .h5p-inner { width: 50%; @@ -322,4 +324,4 @@ div.h5p-fullscreen { padding-left: 38px; min-height: 30px; line-height: 30px; -} \ No newline at end of file +} From dd83933a0a82797345b0650e434d7fa7f7149f2b Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sat, 1 Nov 2014 13:47:24 +0100 Subject: [PATCH 09/27] Remove } --- js/h5p.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/h5p.js b/js/h5p.js index 65bf07e..9ae10ea 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -76,7 +76,6 @@ H5P.init = function () { H5P.openCopyrightsDialog($actions, instance, library.params, contentId); }); - } if (contentData.embedCode !== undefined) { // Display embed button H5P.jQuery('
  • ' + H5P.t('embed') + '
  • ').appendTo($actions).click(function () { From f01d002f66cdd22df360d69aa7bf3b6b4ce55d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Sat, 1 Nov 2014 17:05:15 +0100 Subject: [PATCH 10/27] Major post review changes --- h5p.classes.php | 102 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 18 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index dffb390..2df9901 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -11,9 +11,18 @@ interface H5PFrameworkInterface { * An associative array containing: * - name: The name of the plattform, for instance "Wordpress" * - version: The version of the pattform, for instance "4.0" + * - uuid: UUID for site installation */ public function getPlatformInfo(); + /** + * Set the tutorial URL for a library. All versions of the library is set + * + * @param string $machineName + * @param string $tutorialUrl + */ + public function setLibraryTutorialUrl($machineName, $tutorialUrl); + /** * Show the user an error message * @@ -2028,6 +2037,34 @@ class H5PCore { return $obj ? (object) $newArr : $newArr; } + /** + * Generates a UUID v4. Taken from: http://php.net/manual/en/function.uniqid.php + * + * @return string uuid + */ + public static function generateUUID() { + return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + + // 32 bits for "time_low" + mt_rand(0, 0xffff), mt_rand(0, 0xffff), + + // 16 bits for "time_mid" + mt_rand(0, 0xffff), + + // 16 bits for "time_hi_and_version", + // four most significant bits holds version number 4 + mt_rand(0, 0x0fff) | 0x4000, + + // 16 bits, 8 bits for "clk_seq_hi_res", + // 8 bits for "clk_seq_low", + // two most significant bits holds zero and one for variant DCE1.1 + mt_rand(0, 0x3fff) | 0x8000, + + // 48 bits for "node" + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) + ); + } + /** * Check if currently installed H5P libraries are supported by * the current versjon of core. Which versions of which libraries are supported is @@ -2157,27 +2194,56 @@ class H5PCore { } /** - * Get a list of libraries' metadata from h5p.org. Cache it, and refetch once a week. - * - * @return mixed An object of objects keyed by machineName + * Fetch a list of libraries' metadata from h5p.org. + * Save URL tutorial to database. Each platform implementation + * is responsible for invoking this, eg using cron */ - public function getLibrariesMetadata() { - // Fetch from cache: - $metadata = $this->h5pF->cacheGet('libraries','metadata'); - - // If not available in cache, or older than a week => refetch! - if ($metadata === NULL || $metadata->lastTimeFetched < (time() - self::SECONDS_IN_WEEK)) { - $platformInfo = $this->h5pF->getPlatformInfo(); - $json = file_get_contents('http://h5p.org/libraries-metadata.json?platform=' . json_encode($platformInfo)); - - $metadata = new stdClass(); - $metadata->json = ($json === FALSE ? NULL : json_decode($json)); - $metadata->lastTimeFetched = time(); - - $this->h5pF->cacheSet('libraries','metadata', $metadata); + public function fetchLibrariesMetadata($fetchingDisabled = FALSE) { + $platformInfo = $this->h5pF->getPlatformInfo(); + $platformInfo['autoFetchingDisabled'] = $fetchingDisabled; + $json = H5PExternalDataFetcher::fetchJson('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo))); + if ($json !== NULL) { + foreach ($json as $machineName => $libInfo) { + $this->h5pF->setLibraryTutorialUrl($machineName, $libInfo->tutorialUrl); + } } + } +} - return $metadata->json; +/** + * Class responsible for fetching external data (using http) + */ +class H5PExternalDataFetcher { + + public static function fetchJson($url) { + $json = self::fetch($url); + return ($json === NULL) ? NULL : json_decode($json); + } + + public static function fetch($url) { + if (ini_get('allow_url_fopen') == TRUE) { + return self::fetchFopen($url); + } + else if (function_exists('curl_init')) { + return self::fetchCurl($url); + } + else { + // Enable 'allow_url_fopen' or install cURL. + // TODO - this could be reported to the user. + return NULL; + } + } + + private static function fetchFopen($url) { + return file_get_contents($url); + } + + private static function fetchCurl($url) { + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + $result = curl_exec($curl); + curl_close($curl); + return $result; } } From c1f403af3fc789ef75f6beda46cf5cc9ff053131 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sun, 2 Nov 2014 13:38:56 +0100 Subject: [PATCH 11/27] Comment out old interface functions --- h5p.classes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 5b23280..18b48e6 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2163,7 +2163,7 @@ class H5PCore { */ public function getLibrariesMetadata() { // Fetch from cache: - $metadata = $this->h5pF->cacheGet('libraries','metadata'); + //$metadata = $this->h5pF->cacheGet('libraries','metadata'); // If not available in cache, or older than a week => refetch! if ($metadata === NULL || $metadata->lastTimeFetched < (time() - self::SECONDS_IN_WEEK)) { @@ -2174,7 +2174,7 @@ class H5PCore { $metadata->json = ($json === FALSE ? NULL : json_decode($json)); $metadata->lastTimeFetched = time(); - $this->h5pF->cacheSet('libraries','metadata', $metadata); + //$this->h5pF->cacheSet('libraries','metadata', $metadata); } return $metadata->json; From f306d24f23dfe6a5df2d49f8fecc7ce669caf82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Sun, 2 Nov 2014 13:46:09 +0100 Subject: [PATCH 12/27] Moved UUID-generation to backend Added h5pVersion in platforminfo Avoiding json beeing cached both locally and on backend --- h5p.classes.php | 52 ++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 398dbc7..f719f6d 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -11,7 +11,7 @@ interface H5PFrameworkInterface { * An associative array containing: * - name: The name of the plattform, for instance "Wordpress" * - version: The version of the pattform, for instance "4.0" - * - uuid: UUID for site installation + * - h5pVersion: The version of the H5P plugin/module */ public function getPlatformInfo(); @@ -2037,34 +2037,6 @@ class H5PCore { return $obj ? (object) $newArr : $newArr; } - /** - * Generates a UUID v4. Taken from: http://php.net/manual/en/function.uniqid.php - * - * @return string uuid - */ - public static function generateUUID() { - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - - // 32 bits for "time_low" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - - // 16 bits for "time_mid" - mt_rand(0, 0xffff), - - // 16 bits for "time_hi_and_version", - // four most significant bits holds version number 4 - mt_rand(0, 0x0fff) | 0x4000, - - // 16 bits, 8 bits for "clk_seq_hi_res", - // 8 bits for "clk_seq_low", - // two most significant bits holds zero and one for variant DCE1.1 - mt_rand(0, 0x3fff) | 0x8000, - - // 48 bits for "node" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - } - /** * Check if currently installed H5P libraries are supported by * the current versjon of core. Which versions of which libraries are supported is @@ -2201,10 +2173,18 @@ class H5PCore { public function fetchLibrariesMetadata($fetchingDisabled = FALSE) { $platformInfo = $this->h5pF->getPlatformInfo(); $platformInfo['autoFetchingDisabled'] = $fetchingDisabled; - $json = H5PExternalDataFetcher::fetchJson('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo))); + $platformInfo['uuid'] = $this->h5pF->getOption('h5p_site_uuid', ''); + // Adding random string to GET to be sure nothing is cached + $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); + $json = H5PExternalDataFetcher::fetchJson('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); if ($json !== NULL) { - foreach ($json as $machineName => $libInfo) { - $this->h5pF->setLibraryTutorialUrl($machineName, $libInfo->tutorialUrl); + if (isset($json->libraries)) { + foreach ($json->libraries as $machineName => $libInfo) { + $this->h5pF->setLibraryTutorialUrl($machineName, $libInfo->tutorialUrl); + } + } + if($platformInfo['uuid'] === '' && isset($json->uuid)) { + $this->h5pF->setOption('h5p_site_uuid', $json->uuid); } } } @@ -2228,8 +2208,8 @@ class H5PExternalDataFetcher { return self::fetchCurl($url); } else { - // Enable 'allow_url_fopen' or install cURL. - // TODO - this could be reported to the user. + // We have no transport mechanisme to use for communicating with h5p.org + // This may be reported to the user in future versions. return NULL; } } @@ -2241,6 +2221,8 @@ class H5PExternalDataFetcher { private static function fetchCurl($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + // To be sure curl does not cache anything + curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE); $result = curl_exec($curl); curl_close($curl); return $result; @@ -2364,7 +2346,7 @@ class H5PContentValidator { */ public function validateContentFiles($contentPath, $isLibrary = FALSE) { if ($this->h5pC->disableFileCheck === TRUE) { - return TRUE; + return TRUE; } // Scan content directory for files, recurse into sub directories. From a2c84189b01d14cef4ca2995fc41014861faa9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Sun, 2 Nov 2014 14:29:13 +0100 Subject: [PATCH 13/27] Moving external file fetching out of core --- h5p.classes.php | 50 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index f719f6d..1fe6d6c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -15,6 +15,14 @@ interface H5PFrameworkInterface { */ public function getPlatformInfo(); + /** + * Fetches a file from a remote server using HTTP GET + * + * @param $url + * @return string The content (response body). NULL if something went wrong + */ + public function fetchExternalData($url); + /** * Set the tutorial URL for a library. All versions of the library is set * @@ -2176,8 +2184,9 @@ class H5PCore { $platformInfo['uuid'] = $this->h5pF->getOption('h5p_site_uuid', ''); // Adding random string to GET to be sure nothing is cached $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); - $json = H5PExternalDataFetcher::fetchJson('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); + $json = $this->h5pF->fetchExternalFile('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); if ($json !== NULL) { + $json = json_decode($json); if (isset($json->libraries)) { foreach ($json->libraries as $machineName => $libInfo) { $this->h5pF->setLibraryTutorialUrl($machineName, $libInfo->tutorialUrl); @@ -2190,45 +2199,6 @@ class H5PCore { } } -/** - * Class responsible for fetching external data (using http) - */ -class H5PExternalDataFetcher { - - public static function fetchJson($url) { - $json = self::fetch($url); - return ($json === NULL) ? NULL : json_decode($json); - } - - public static function fetch($url) { - if (ini_get('allow_url_fopen') == TRUE) { - return self::fetchFopen($url); - } - else if (function_exists('curl_init')) { - return self::fetchCurl($url); - } - else { - // We have no transport mechanisme to use for communicating with h5p.org - // This may be reported to the user in future versions. - return NULL; - } - } - - private static function fetchFopen($url) { - return file_get_contents($url); - } - - private static function fetchCurl($url) { - $curl = curl_init($url); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // To be sure curl does not cache anything - curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE); - $result = curl_exec($curl); - curl_close($curl); - return $result; - } -} - /** * Functions for validating basic types from H5P library semantics. */ From 3d370da1e108ec84c4c73419ce8439bb6514056d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Sun, 2 Nov 2014 16:22:27 +0100 Subject: [PATCH 14/27] Fixed usage of non-existent function --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 1fe6d6c..bfd76ce 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2184,7 +2184,7 @@ class H5PCore { $platformInfo['uuid'] = $this->h5pF->getOption('h5p_site_uuid', ''); // Adding random string to GET to be sure nothing is cached $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); - $json = $this->h5pF->fetchExternalFile('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); + $json = $this->h5pF->fetchExternalData('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); if ($json !== NULL) { $json = json_decode($json); if (isset($json->libraries)) { From 48f7969ff9134679bd27885936e984b85dfeb19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Sun, 2 Nov 2014 16:57:57 +0100 Subject: [PATCH 15/27] Whitespaces? --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index bfd76ce..7d964ba 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2316,7 +2316,7 @@ class H5PContentValidator { */ public function validateContentFiles($contentPath, $isLibrary = FALSE) { if ($this->h5pC->disableFileCheck === TRUE) { - return TRUE; + return TRUE; } // Scan content directory for files, recurse into sub directories. From 41ed0c18e4fa2ccec5c89958a1237554e759005b Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sun, 2 Nov 2014 17:52:39 +0100 Subject: [PATCH 16/27] Add htmlSpecialChars --- h5p.classes.php | 2 +- js/h5p.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 7d964ba..b4fc7a7 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1526,7 +1526,7 @@ class H5PCore { public static $coreApi = array( 'majorVersion' => 1, - 'minorVersion' => 3 + 'minorVersion' => 4 ); public static $styles = array( 'styles/h5p.css', diff --git a/js/h5p.js b/js/h5p.js index d53f8e2..fe257f2 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -1099,3 +1099,10 @@ if (H5P.jQuery) { } }); } + + /** + * Mimics how php's htmlspecialchars works (the way we use it) + */ +H5P.htmlSpecialChars = function(string) { + return string.toString().replace(//g, '>').replace(/'/g, ''').replace(/"/g, '"'); +}; \ No newline at end of file From 7c3ddea71a7431ec455597260759583019740e50 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sun, 2 Nov 2014 19:13:14 +0100 Subject: [PATCH 17/27] Become node_clone compatible again --- h5p.classes.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index b4fc7a7..e77258c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1648,19 +1648,23 @@ class H5PCore { // Update content dependencies. $content['dependencies'] = $validator->getDependencies(); - $this->h5pF->deleteLibraryUsage($content['id']); - $this->h5pF->saveLibraryUsage($content['id'], $content['dependencies']); - if ($this->exportEnabled) { - // Recreate export file - $exporter = new H5PExport($this->h5pF, $this); - $exporter->createExportFile($content); + // Sometimes the parameters are filtered before content has been created + if ($content['id']) { + $this->h5pF->deleteLibraryUsage($content['id']); + $this->h5pF->saveLibraryUsage($content['id'], $content['dependencies']); - // TODO: Should we rather create the file once first accessed, like imagecache? + if ($this->exportEnabled) { + // Recreate export file + $exporter = new H5PExport($this->h5pF, $this); + $exporter->createExportFile($content); + + // TODO: Should we rather create the file once first accessed, like imagecache? + } + + // Cache. + $this->h5pF->setFilteredParameters($content['id'], $params); } - - // Cache. - $this->h5pF->setFilteredParameters($content['id'], $params); return $params; } From 415e2171341e79d8eae9801054aeea0509336347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Mon, 3 Nov 2014 07:02:45 +0100 Subject: [PATCH 18/27] Fixed URL to h5p.org --- h5p.classes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index e77258c..e31964b 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2188,7 +2188,7 @@ class H5PCore { $platformInfo['uuid'] = $this->h5pF->getOption('h5p_site_uuid', ''); // Adding random string to GET to be sure nothing is cached $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); - $json = $this->h5pF->fetchExternalData('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); + $json = $this->h5pF->fetchExternalData('http://h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); if ($json !== NULL) { $json = json_decode($json); if (isset($json->libraries)) { @@ -2320,7 +2320,7 @@ class H5PContentValidator { */ public function validateContentFiles($contentPath, $isLibrary = FALSE) { if ($this->h5pC->disableFileCheck === TRUE) { - return TRUE; + return TRUE; } // Scan content directory for files, recurse into sub directories. From 57db1d99266ca51d08e0d3e916369a9a8ed11397 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Mon, 3 Nov 2014 10:15:23 +0100 Subject: [PATCH 19/27] Revert "Add htmlSpecialChars" This reverts commit 41ed0c18e4fa2ccec5c89958a1237554e759005b. --- h5p.classes.php | 2 +- js/h5p.js | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index e31964b..827903a 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1526,7 +1526,7 @@ class H5PCore { public static $coreApi = array( 'majorVersion' => 1, - 'minorVersion' => 4 + 'minorVersion' => 3 ); public static $styles = array( 'styles/h5p.css', diff --git a/js/h5p.js b/js/h5p.js index fe257f2..d53f8e2 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -1099,10 +1099,3 @@ if (H5P.jQuery) { } }); } - - /** - * Mimics how php's htmlspecialchars works (the way we use it) - */ -H5P.htmlSpecialChars = function(string) { - return string.toString().replace(//g, '>').replace(/'/g, ''').replace(/"/g, '"'); -}; \ No newline at end of file From 2d7824aa932a6b217bc16a4f7b53c6ab654a1790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Thu, 6 Nov 2014 11:13:24 +0100 Subject: [PATCH 20/27] Fix for language containing empty string in H5P export (h5p.json) --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 827903a..905b72c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1433,7 +1433,7 @@ Class H5PExport { 'title' => $content['title'], // TODO - stop using 'und', this is not the preferred way. // Either remove language from the json if not existing, or use "language": null - 'language' => isset($content['language']) ? $content['language'] : 'und', + 'language' => (isset($content['language']) && strlen(trim($content['language'])) !== 0) ? $content['language'] : 'und', 'mainLibrary' => $content['library']['name'], 'embedTypes' => $embedTypes, ); From 60d166c6da256bb2d5a66be2f4927efd229b6fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20J=C3=B8rgensen?= Date: Wed, 19 Nov 2014 12:43:59 +0100 Subject: [PATCH 21/27] Made creation of h5p export file overwrite existing file --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 905b72c..9a456a5 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1465,7 +1465,7 @@ Class H5PExport { // Create new zip instance. $zip = new ZipArchive(); - $zip->open($zipPath, ZIPARCHIVE::CREATE); + $zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);); // Get all files and folders in $tempPath $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempPath . DIRECTORY_SEPARATOR)); From 9ed2e48fb5c97ce398ba7176ca678f2d3e50209c Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 25 Nov 2014 10:55:32 +0100 Subject: [PATCH 22/27] Fixed parse error. --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 9a456a5..36151b1 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1465,7 +1465,7 @@ Class H5PExport { // Create new zip instance. $zip = new ZipArchive(); - $zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);); + $zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); // Get all files and folders in $tempPath $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempPath . DIRECTORY_SEPARATOR)); From fb07f54e3517bff606934b0b056188afce24524d Mon Sep 17 00:00:00 2001 From: falcon Date: Thu, 27 Nov 2014 23:14:15 +0100 Subject: [PATCH 23/27] Make it possible to do the dependency transactions in an atomic way --- h5p-development.class.php | 2 ++ h5p.classes.php | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/h5p-development.class.php b/h5p-development.class.php index 75e9daf..7f33689 100644 --- a/h5p-development.class.php +++ b/h5p-development.class.php @@ -93,6 +93,7 @@ class H5PDevelopment { // TODO: Should we remove libraries without files? Not really needed, but must be cleaned up some time, right? // Go trough libraries and insert dependencies. Missing deps. will just be ignored and not available. (I guess?!) + $this->h5pF->lockDependencyStorage(); foreach ($this->libraries as $library) { $this->h5pF->deleteLibraryDependencies($library['libraryId']); // This isn't optimal, but without it we would get duplicate warnings. @@ -104,6 +105,7 @@ class H5PDevelopment { } } } + $this->h5pF->unlockDependencyStorage(); // TODO: Deps must be inserted into h5p_nodes_libraries as well... ? But only if they are used?! } diff --git a/h5p.classes.php b/h5p.classes.php index 36151b1..5940e06 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -408,6 +408,17 @@ interface H5PFrameworkInterface { */ public function deleteLibraryDependencies($libraryId); + /** + * Start an atomic operation against the dependency storage + */ + public function lockDependencyStorage(); + + /** + * Stops an atomic operation against the dependency storage + */ + public function unlockDependencyStorage(); + + /** * Delete a library from database and file system * From e7b7cd2abe219de096f1a9b5fcb2704f427deebc Mon Sep 17 00:00:00 2001 From: git Date: Fri, 9 Jan 2015 09:59:29 +0100 Subject: [PATCH 24/27] Issue https://www.drupal.org/node/2402099 by drinkdecaf: H5P on Pantheon Environments --- h5p.classes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 5940e06..619463a 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1275,7 +1275,8 @@ class H5PStorage { } $destination_path = $libraries_path . DIRECTORY_SEPARATOR . H5PCore::libraryToString($library, TRUE); H5PCore::deleteFileTree($destination_path); - rename($library['uploadDirectory'], $destination_path); + $this->h5pC->copyFileTree($library['uploadDirectory'], $destination_path); + H5PCore::deleteFileTree($library['uploadDirectory']); $library_saved = TRUE; } From ae8609dd86084aa78b7d8d0c8f0b57840a414597 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 9 Jan 2015 10:00:40 +0100 Subject: [PATCH 25/27] Replaced another rename function. --- h5p.classes.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 619463a..af50df5 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -412,13 +412,13 @@ interface H5PFrameworkInterface { * Start an atomic operation against the dependency storage */ public function lockDependencyStorage(); - + /** * Stops an atomic operation against the dependency storage */ public function unlockDependencyStorage(); - - + + /** * Delete a library from database and file system * @@ -1327,7 +1327,8 @@ class H5PStorage { // Move the content folder $destination_path = $contents_path . DIRECTORY_SEPARATOR . $contentId; - @rename($current_path, $destination_path); + $this->h5pC->copyFileTree($current_path, $destination_path); + H5PCore::deleteFileTree($current_path); // Save the content library dependencies $this->h5pF->saveLibraryUsage($contentId, $librariesInUse); From b0e6bed5173b18e7939ac8c01b15a359747e4f61 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Tue, 27 Jan 2015 11:28:02 +0100 Subject: [PATCH 26/27] Update README.txt --- README.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.txt b/README.txt index f6ff53d..a6caa31 100644 --- a/README.txt +++ b/README.txt @@ -1,13 +1,12 @@ This folder contains the h5p general library. The files within this folder are not specific to any framework. Any interaction with LMS, CMS or other frameworks is done through interfaces. Plattforms needs to implement -the following interfaces in order for the h5p libraries to work: - - - TODO: Fill in here - -In addition frameworks need to do the following: +the H5PFrameworkInterface(in h5p.classes.php) and also do the following: - Provide a form for uploading h5p packages. - Place the uploaded h5p packages in a temporary directory + +++ -See existing implementations for details. For instance the Drupal h5p module located on drupal.org/project/h5p \ No newline at end of file +See existing implementations for details. For instance the Drupal h5p module located on drupal.org/project/h5p + +We will make available documentations and tutorials for creating platform integrations in the future From ae6329595ba603179d62992c206458004d01606b Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Fri, 30 Jan 2015 10:59:40 +0100 Subject: [PATCH 27/27] Add ordering of libraries --- h5p.classes.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 5940e06..1503ad4 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1305,8 +1305,8 @@ class H5PStorage { // Find out which libraries are used by this package/content $librariesInUse = array(); - $this->h5pC->findLibraryDependencies($librariesInUse, $this->h5pC->mainJsonData); - + $nextWeight = $this->h5pC->findLibraryDependencies($librariesInUse, $this->h5pC->mainJsonData); + // Save content if ($content === NULL) { $content = array(); @@ -1836,9 +1836,12 @@ class H5PCore { * * @param array $librariesUsed Flat list of all dependencies. * @param array $library To find all dependencies for. - * @param bool $editor Used interally to force all preloaded sub dependencies of an editor dependecy to be editor dependencies. + * @param int $nextWeight An integer determining the order of the libraries + * when they are loaded + * @param bool $editor Used interally to force all preloaded sub dependencies + * of an editor dependecy to be editor dependencies. */ - public function findLibraryDependencies(&$dependencies, $library, $editor = FALSE) { + public function findLibraryDependencies(&$dependencies, $library, $nextWeight = 1, $editor = FALSE) { foreach (array('dynamic', 'preloaded', 'editor') as $type) { $property = $type . 'Dependencies'; if (!isset($library[$property])) { @@ -1862,7 +1865,8 @@ class H5PCore { 'library' => $dependencyLibrary, 'type' => $type ); - $this->findLibraryDependencies($dependencies, $dependencyLibrary, $type === 'editor'); + $nextWeight = $this->findLibraryDependencies($dependencies, $dependencyLibrary, $nextWeight, $type === 'editor'); + $dependencies[$dependencyKey]['weight'] = $nextWeight++; } else { // This site is missing a dependency! @@ -1870,6 +1874,7 @@ class H5PCore { } } } + return $nextWeight; } /** @@ -2220,8 +2225,7 @@ class H5PCore { class H5PContentValidator { public $h5pF; public $h5pC; - private $typeMap; - private $libraries, $dependencies; + private $typeMap, $libraries, $dependencies, $nextWeight; /** * Constructor for the H5PContentValidator @@ -2247,6 +2251,7 @@ class H5PContentValidator { 'select' => 'validateSelect', 'library' => 'validateLibrary', ); + $this->nextWeight = 1; // Keep track of the libraries we load to avoid loading it multiple times. $this->libraries = array(); @@ -2634,7 +2639,8 @@ class H5PContentValidator { 'type' => 'preloaded' ); - $this->h5pC->findLibraryDependencies($this->dependencies, $library); + $this->nextWeight = $this->h5pC->findLibraryDependencies($this->dependencies, $library, $this->nextWeight); + $this->dependencies[$depkey]['weight'] = $this->nextWeight++; } } else {