Merge branch 'master' into always-set-language-on-export

namespaces
Svein-Tore Griff With 2014-11-01 12:42:41 +01:00
commit 9f0da3119e
10 changed files with 808 additions and 568 deletions

View File

@ -153,14 +153,14 @@ class H5PDevelopment {
* @param int $minorVersion of the library. * @param int $minorVersion of the library.
* @return string Translation * @return string Translation
*/ */
public function getLanguage($name, $majorVersion, $minorVersion) { public function getLanguage($name, $majorVersion, $minorVersion, $language) {
$library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion); $library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion);
if (isset($this->libraries[$library]) === FALSE) { if (isset($this->libraries[$library]) === FALSE) {
return NULL; return NULL;
} }
return $this->getFileContents($this->libraries[$library]['path'] . '/language/' . $this->language . '.json'); return $this->getFileContents($this->libraries[$library]['path'] . '/language/' . $language . '.json');
} }
/** /**
@ -175,4 +175,3 @@ class H5PDevelopment {
return $name . ' ' . $majorVersion . '.' . $minorVersion; return $name . ' ' . $majorVersion . '.' . $minorVersion;
} }
} }

View File

@ -4,11 +4,21 @@
*/ */
interface H5PFrameworkInterface { interface H5PFrameworkInterface {
/**
* Returns info for the current platform
*
* @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 * Show the user an error message
* *
* @param string $message * @param string $message
* The error message * The error message
*/ */
public function setErrorMessage($message); public function setErrorMessage($message);
@ -33,68 +43,91 @@ interface H5PFrameworkInterface {
* - @variable: escape plain text to HTML * - @variable: escape plain text to HTML
* - %variable: escape text and theme as a placeholder for user-submitted * - %variable: escape text and theme as a placeholder for user-submitted
* content * content
* @return string Translated string * @return string
* Translated string
*/ */
public function t($message, $replacements = array()); public function t($message, $replacements = array());
/** /**
* Get the Path to the last uploaded h5p * 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(); 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(); public function getH5pPath();
/** /**
* Get the path to the last uploaded h5p file * 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(); 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(); public function loadLibraries();
/** /**
* Saving the unsupported library list * 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); public function setUnsupportedLibraries($libraries);
/** /**
* Returns unsupported 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(); public function getUnsupportedLibraries();
/** /**
* Returns the URL to the library admin page * Returns the URL to the library admin page
* *
* @return string URL to admin page * @return string
* URL to admin page
*/ */
public function getAdminUrl(); public function getAdminUrl();
/** /**
* Get id to an excisting library * Get id to an existing library
* *
* @param string $machineName * @param string $machineName
* The librarys machine name * The librarys machine name
* @param int $majorVersion * @param int $majorVersion
* The librarys major version * The librarys major version
* @param int $minorVersion * @param int $minorVersion
* The librarys minor version * The librarys minor version
* @return int * @return int
* The id of the specified library or FALSE * The id of the specified library or FALSE
*/ */
public function getLibraryId($machineName, $majorVersion, $minorVersion); public function getLibraryId($machineName, $majorVersion, $minorVersion);
@ -104,8 +137,12 @@ interface H5PFrameworkInterface {
* The default extension list is part of h5p, but admins should be allowed to modify it * The default extension list is part of h5p, but admins should be allowed to modify it
* *
* @param boolean $isLibrary * @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 * @param string $defaultContentWhitelist
* A string of file extensions separated by whitespace
* @param string $defaultLibraryWhitelist * @param string $defaultLibraryWhitelist
* A string of file extensions separated by whitespace
*/ */
public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist); public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist);
@ -113,10 +150,14 @@ interface H5PFrameworkInterface {
* Is the library a patched version of an existing library? * Is the library a patched version of an existing library?
* *
* @param object $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 * @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 * FALSE otherwise
*/ */
public function isPatchedLibrary($library); public function isPatchedLibrary($library);
@ -144,23 +185,53 @@ interface H5PFrameworkInterface {
* Also fills in the libraryId in the libraryData object if the object is new * Also fills in the libraryId in the libraryData object if the object is new
* *
* @param object $libraryData * @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); public function saveLibraryData(&$libraryData, $new = TRUE);
/** /**
* Insert new content. * 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 * @param int $contentMainId
* Main id for the content if this is a system that supports versioning
*/ */
public function insertContent($content, $contentMainId = NULL); public function insertContent($content, $contentMainId = NULL);
/** /**
* Update old content. * 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 * @param int $contentMainId
* Main id for the content if this is a system that supports versioning
*/ */
public function updateContent($content, $contentMainId = NULL); public function updateContent($content, $contentMainId = NULL);
@ -168,25 +239,31 @@ interface H5PFrameworkInterface {
* Save what libraries a library is dependending on * Save what libraries a library is dependending on
* *
* @param int $libraryId * @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 * @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 * @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); public function saveLibraryDependencies($libraryId, $dependencies, $dependency_type);
/** /**
* Copies library usage * Give an H5P the same library dependencies as a given H5P
* *
* @param int $contentId * @param int $contentId
* Framework specific id identifying the content * Id identifying the content
* @param int $copyFromId * @param int $copyFromId
* Framework specific id identifying the content to be copied * Id identifying the content to be copied
* @param int $contentMainId * @param int $contentMainId
* Framework specific main id for the content, typically used in frameworks * Main id for the content, typically used in frameworks
* That supports versioning. (In this case the content id will typically be * That supports versioning. (In this case the content id will typically be
* the version id, and the contentMainId will be the frameworks content id * the version id, and the contentMainId will be the frameworks content id
*/ */
public function copyLibraryUsage($contentId, $copyFromId, $contentMainId = NULL); public function copyLibraryUsage($contentId, $copyFromId, $contentMainId = NULL);
@ -194,7 +271,7 @@ interface H5PFrameworkInterface {
* Deletes content data * Deletes content data
* *
* @param int $contentId * @param int $contentId
* Framework specific id identifying the content * Id identifying the content
*/ */
public function deleteContentData($contentId); public function deleteContentData($contentId);
@ -202,7 +279,7 @@ interface H5PFrameworkInterface {
* Delete what libraries a content item is using * Delete what libraries a content item is using
* *
* @param int $contentId * @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); public function deleteLibraryUsage($contentId);
@ -210,11 +287,17 @@ interface H5PFrameworkInterface {
* Saves what libraries the content uses * Saves what libraries the content uses
* *
* @param int $contentId * @param int $contentId
* Framework specific id identifying the content * Id identifying the content
* @param array $librariesInUse * @param array $librariesInUse
* List of libraries the content uses. Libraries consist of arrays with: * List of libraries the content uses. Libraries consist of associative arrays with:
* - libraryId stored in $librariesInUse[<place>]['library']['libraryId'] * - library: Associative array containing:
* - libraryId stored in $librariesInUse[<place>]['preloaded'] * - dropLibraryCss(optional): commasepareted list of machineNames
* - machineName: Machine name for the library
* - libraryId: Id of the library
* - type: The dependency type. Allowed values:
* - editor
* - dynamic
* - preloaded
*/ */
public function saveLibraryUsage($contentId, $librariesInUse); public function saveLibraryUsage($contentId, $librariesInUse);
@ -222,9 +305,12 @@ interface H5PFrameworkInterface {
* 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 * dependencies to other libraries
* *
* @param int $library_id * @param int $libraryId
* @return array The array contains two elements, keyed by 'content' and 'libraries'. * Library identifier
* Each element contains a number * @return array
* Associative array containing:
* - content: Number of content using the library
* - libraries: Number of libraries depending on the library
*/ */
public function getLibraryUsage($libraryId); public function getLibraryUsage($libraryId);
@ -232,109 +318,186 @@ interface H5PFrameworkInterface {
* Loads a library * Loads a library
* *
* @param string $machineName * @param string $machineName
* The library's machine name
* @param int $majorVersion * @param int $majorVersion
* The library's major version
* @param int $minorVersion * @param int $minorVersion
* The library's minor version
* @return array|FALSE * @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); public function loadLibrary($machineName, $majorVersion, $minorVersion);
/** /**
* Loads library semantics. * Loads library semantics.
* *
* @param string $name library identifier. * @param string $machineName
* @param int $majorVersion library identifier. * Machine name for the library
* @param int $minorVersion library identifier. * @param int $majorVersion
* @return string semantics. * 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. * Makes it possible to alter the semantics, adding custom fields, etc.
* *
* @param array $semantics * @param array $semantics
* @param string $name library identifier. * Associative array representing the semantics
* @param int $majorVersion library identifier. * @param string $machineName
* @param int $minorVersion library identifier. * 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 * Delete all dependencies belonging to given library
* *
* @param int $libraryId * @param int $libraryId
* Library Id * Library identifier
*/ */
public function deleteLibraryDependencies($libraryId); public function deleteLibraryDependencies($libraryId);
/** /**
* Delete a library from database and file system * Delete a library from database and file system
* *
* @param mixed $library Library * @param stdClass $library
* Library object with id, name, major version and minor version.
*/ */
public function deleteLibrary($library); public function deleteLibrary($library);
/** /**
* Load content. * 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); public function loadContent($id);
/** /**
* Load dependencies for the given content of the given type. * Load dependencies for the given content of the given type.
* *
* @param int $id content. * @param int $id
* @param int $type dependency. * Content identifier
* @param int $type
* Dependency types. Allowed values:
* - editor
* - preloaded
* - dynamic
* @return array * @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); public function loadContentDependencies($id, $type = NULL);
/** /**
* Get data from cache. * Get stored setting.
* *
* @param string $group * @param string $name
* @param string $key * Identifier for the setting
* @param string $default
* Optional default value if settings is not set
* @return mixed
* Whatever has been stored as the setting
*/ */
public function cacheGet($group, $key); public function getOption($name, $default = NULL);
/** /**
* Store data in cache. * Stores the given setting.
* For example when did we last check h5p.org for updates to our libraries.
* *
* @param string $group * @param string $name
* @param string $key * Identifier for the setting
* @param mixed $data * @param mixed $value Data
* Whatever we want to store as the setting
*/ */
public function cacheSet($group, $key, $data); public function setOption($name, $value);
/** /**
* Delete data from cache. * This will set the filtered parameters for the given content.
* *
* @param string $group * @param int $content_id
* @param string $key * @param string $parameters filtered
*/ */
public function cacheDel($group, $key = NULL); public function setFilteredParameters($content_id, $parameters = '');
/** /**
* Will invalidate the cache for the content that uses the specified library. * Will clear filtered params for all the content that uses the specified
* This means that the content dependencies has to be rebuilt, and the parameters refiltered. * library. This means that the content dependencies will have to be rebuilt,
* and the parameters refiltered.
* *
* @param int $library_id * @param int $library_id
*/ */
public function invalidateContentCache($library_id); public function clearFilteredParameters($library_id);
/** /**
* Get content without cache. * Get number of contents that has to get their content dependencies rebuilt
* and parameters refiltered.
*
* @return int
*/ */
public function getNotCached(); public function getNumNotFiltered();
/** /**
* Get number of contents using library as main library. * Get number of contents using library as main library.
* *
* @param int $library_id * @param int $libraryId
* @return int
*/ */
public function getNumContent($library_id); public function getNumContent($libraryId);
} }
/** /**
@ -1103,7 +1266,7 @@ class H5PStorage {
} }
// Make sure libraries dependencies, parameter filtering and export files gets regenerated for all content who uses this library. // Make sure libraries dependencies, parameter filtering and export files gets regenerated for all content who uses this library.
$this->h5pF->invalidateContentCache($library['libraryId']); $this->h5pF->clearFilteredParameters($library['libraryId']);
$upgradedLibsCount++; $upgradedLibsCount++;
} }
@ -1147,7 +1310,7 @@ class H5PStorage {
if ($upgradeOnly) { if ($upgradeOnly) {
// TODO - support translation // TODO - support translation
$this->h5pF->setInfoMessage($upgradedLibsCount . ' libraries were upgraded!'); $this->h5pF->setInfoMessage($this->h5pF->t('@num libraries were upgraded!', array('@num' => $upgradedLibsCount)));
} }
return $library_saved; return $library_saved;
@ -1363,6 +1526,8 @@ 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 $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'; public static $defaultLibraryWhitelistExtras = 'js css';
const SECONDS_IN_WEEK = 604800;
public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $path, $development_mode, $h5pD; public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $path, $development_mode, $h5pD;
private $exportEnabled; private $exportEnabled;
@ -1403,11 +1568,6 @@ class H5PCore {
$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']; return $content['id'];
} }
@ -1455,16 +1615,8 @@ class H5PCore {
* @return Object NULL on failure. * @return Object NULL on failure.
*/ */
public function filterParameters($content) { public function filterParameters($content) {
if (isset($content['filtered'])) { if (isset($content['filtered']) && $content['filtered'] !== '') {
$params = ($content['filtered'] === '' ? NULL : $content['filtered']); return $content['filtered'];
}
else {
// TODO: Add filtered to all impl. and remove
$params = $this->h5pF->cacheGet('parameters', $content['id']);
}
if ($params !== NULL) {
return $params;
} }
// Validate and filter against main library semantics. // Validate and filter against main library semantics.
@ -1491,7 +1643,7 @@ class H5PCore {
} }
// Cache. // Cache.
$this->h5pF->cacheSet('parameters', $content['id'], $params); $this->h5pF->setFilteredParameters($content['id'], $params);
return $params; return $params;
} }
@ -2003,6 +2155,30 @@ class H5PCore {
$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>'; $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; 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;
}
} }
/** /**
@ -2410,7 +2586,7 @@ class H5PContentValidator {
if (!isset($this->libraries[$value->library])) { if (!isset($this->libraries[$value->library])) {
$libspec = H5PCore::libraryFromString($value->library); $libspec = H5PCore::libraryFromString($value->library);
$library = $this->h5pC->loadLibrary($libspec['machineName'], $libspec['majorVersion'], $libspec['minorVersion']); $library = $this->h5pC->loadLibrary($libspec['machineName'], $libspec['majorVersion'], $libspec['minorVersion']);
$library['semantics'] = json_decode($library['semantics']); $library['semantics'] = $this->h5pC->loadLibrarySemantics($libspec['machineName'], $libspec['majorVersion'], $libspec['minorVersion']);
$this->libraries[$value->library] = $library; $this->libraries[$value->library] = $library;
// Find all dependencies for this library // Find all dependencies for this library

View File

@ -1,3 +1,4 @@
/*jshint -W083 */
var H5PUpgrades = H5PUpgrades || {}; var H5PUpgrades = H5PUpgrades || {};
(function ($) { (function ($) {
@ -212,18 +213,28 @@ var H5PUpgrades = H5PUpgrades || {};
var current = 0; // Track progress var current = 0; // Track progress
asyncSerial(parameters, function (id, params, next) { asyncSerial(parameters, function (id, params, next) {
// Make params possible to work with try {
params = JSON.parse(params); // Make params possible to work with
params = JSON.parse(params);
if (!(params instanceof Object)) {
throw true;
}
}
catch (event) {
return next(info.errorContent.replace('%id', id) + ' ' + info.errorParamsBroken);
}
// Upgrade this content. // Upgrade this content.
self.upgrade(info.library.name, new Version(info.library.version), self.version, params, function (err, params) { self.upgrade(info.library.name, new Version(info.library.version), self.version, params, function (err, params) {
if (!err) { if (err) {
upgraded[id] = JSON.stringify(params); return next(info.errorContent.replace('%id', id) + ' ' + err);
current++;
self.throbber.setProgress(Math.round((info.total - self.left + current) / (info.total / 100)) + ' %');
} }
next(err);
upgraded[id] = JSON.stringify(params);
current++;
self.throbber.setProgress(Math.round((info.total - self.left + current) / (info.total / 100)) + ' %');
next();
}); });
}, function (err) { }, function (err) {
@ -374,14 +385,16 @@ var H5PUpgrades = H5PUpgrades || {};
} }
else { else {
// We found an upgrade hook, run it // We found an upgrade hook, run it
if (upgrade.contentUpgrade !== undefined && typeof upgrade.contentUpgrade === 'function') { var unnecessaryWrapper = (upgrade.contentUpgrade !== undefined ? upgrade.contentUpgrade : upgrade);
upgrade.contentUpgrade(params, function (err, upgradedParams) {
try {
unnecessaryWrapper(params, function (err, upgradedParams) {
params = upgradedParams; params = upgradedParams;
nextMinor(err); nextMinor(err);
}); });
} }
else { catch (err) {
nextMinor(info.errorScript.replace('%lib', library.name + ' ' + newVersion)); next(err);
} }
} }
}, nextMajor); }, nextMajor);

View File

@ -1,3 +1,5 @@
/*jshint multistr: true */
/** /**
* *
*/ */
@ -130,8 +132,8 @@ var H5P = H5P || (function () {
if (document.documentElement.requestFullScreen) { if (document.documentElement.requestFullScreen) {
fullScreenBrowserPrefix = ''; fullScreenBrowserPrefix = '';
} }
else if (document.documentElement.webkitRequestFullScreen else if (document.documentElement.webkitRequestFullScreen &&
&& navigator.userAgent.indexOf('Android') === -1 // Skip Android navigator.userAgent.indexOf('Android') === -1 // Skip Android
) { ) {
safariBrowser = navigator.userAgent.match(/Version\/(\d)/); safariBrowser = navigator.userAgent.match(/Version\/(\d)/);
safariBrowser = (safariBrowser === null ? 0 : parseInt(safariBrowser[1])); safariBrowser = (safariBrowser === null ? 0 : parseInt(safariBrowser[1]));

View File

@ -257,7 +257,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {};
H5PLibraryDetails.updatePager(); H5PLibraryDetails.updatePager();
}; };
var inputTimer = undefined; var inputTimer;
$('input', H5PLibraryDetails.$search).on('change keypress paste input', function () { $('input', H5PLibraryDetails.$search).on('change keypress paste input', function () {
// Here we start the filtering // Here we start the filtering
// We wait at least 500 ms after last input to perform search // We wait at least 500 ms after last input to perform search

View File

@ -1,4 +1,5 @@
var H5PLibraryList= H5PLibraryList || {}; /*jshint multistr: true */
var H5PLibraryList = H5PLibraryList || {};
(function ($) { (function ($) {
@ -23,9 +24,9 @@ var H5PLibraryList= H5PLibraryList || {};
* @param {object} libraries List of libraries and headers * @param {object} libraries List of libraries and headers
*/ */
H5PLibraryList.createLibraryList = function (libraries) { H5PLibraryList.createLibraryList = function (libraries) {
var t = H5PIntegration.i18n.H5P;
if(libraries.listData === undefined || libraries.listData.length === 0) { if(libraries.listData === undefined || libraries.listData.length === 0) {
return; return $('<div>' + t.NA + '</div>');
} }
// Create table // Create table
@ -33,13 +34,22 @@ var H5PLibraryList= H5PLibraryList || {};
$table.addClass('libraries'); $table.addClass('libraries');
// Add libraries // Add libraries
var t = H5PIntegration.i18n.H5P;
$.each (libraries.listData, function (index, library) { $.each (libraries.listData, function (index, library) {
var $libraryRow = H5PUtils.createTableRow([ var $libraryRow = H5PUtils.createTableRow([
library.title, library.title,
library.numContent, '<input class="h5p-admin-restricted" type="checkbox"/>',
library.numContentDependencies, {
library.numLibraryDependencies, text: library.numContent,
class: 'h5p-admin-center'
},
{
text: library.numContentDependencies,
class: 'h5p-admin-center'
},
{
text: library.numLibraryDependencies,
class: 'h5p-admin-center'
},
'<div class="h5p-admin-buttons-wrapper">\ '<div class="h5p-admin-buttons-wrapper">\
<button class="h5p-admin-upgrade-library"></button>\ <button class="h5p-admin-upgrade-library"></button>\
<button class="h5p-admin-view-library" title="' + t.viewLibrary + '"></button>\ <button class="h5p-admin-view-library" title="' + t.viewLibrary + '"></button>\
@ -47,10 +57,13 @@ var H5PLibraryList= H5PLibraryList || {};
</div>' </div>'
]); ]);
H5PLibraryList.addRestricted($('.h5p-admin-restricted', $libraryRow), library.restrictedUrl, library.restricted);
var hasContent = !(library.numContent === '' || library.numContent === 0);
if (library.upgradeUrl === null) { if (library.upgradeUrl === null) {
$('.h5p-admin-upgrade-library', $libraryRow).remove(); $('.h5p-admin-upgrade-library', $libraryRow).remove();
} }
else if (library.upgradeUrl === false || library.numContent === 0) { else if (library.upgradeUrl === false || !hasContent) {
$('.h5p-admin-upgrade-library', $libraryRow).attr('disabled', true); $('.h5p-admin-upgrade-library', $libraryRow).attr('disabled', true);
} }
else { else {
@ -65,7 +78,7 @@ var H5PLibraryList= H5PLibraryList || {};
}); });
var $deleteButton = $('.h5p-admin-delete-library', $libraryRow); var $deleteButton = $('.h5p-admin-delete-library', $libraryRow);
if (libraries.notCached !== undefined || library.numContent !== 0 || (library.numContentDependencies !== '' && library.numContentDependencies !== 0) || (library.numLibraryDependencies !== '' && library.numLibraryDependencies !== 0)) { if (libraries.notCached !== undefined || hasContent || (library.numContentDependencies !== '' && library.numContentDependencies !== 0) || (library.numLibraryDependencies !== '' && library.numLibraryDependencies !== 0)) {
// Disabled delete if content. // Disabled delete if content.
$deleteButton.attr('disabled', true); $deleteButton.attr('disabled', true);
} }
@ -82,6 +95,34 @@ var H5PLibraryList= H5PLibraryList || {};
return $table; 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: // Initialize me:
$(document).ready(function () { $(document).ready(function () {

View File

@ -16,7 +16,7 @@ var H5PUtils = H5PUtils || {};
$.each(headers, function (index, value) { $.each(headers, function (index, value) {
if (!(value instanceof Object)) { if (!(value instanceof Object)) {
value = { value = {
text: value html: value
}; };
} }
@ -38,7 +38,13 @@ var H5PUtils = H5PUtils || {};
var $tr = $('<tr></tr>'); var $tr = $('<tr></tr>');
$.each(rows, function (index, value) { $.each(rows, function (index, value) {
$tr.append('<td>' + value + '</td>'); if (!(value instanceof Object)) {
value = {
html: value
};
}
$('<td/>', value).appendTo($tr);
}); });
return $tr; return $tr;

View File

@ -1,3 +1,4 @@
/*jshint multistr: true */
// TODO: Should we split up the generic parts needed by the editor(and others), and the parts needed to "run" H5Ps? // TODO: Should we split up the generic parts needed by the editor(and others), and the parts needed to "run" H5Ps?
var H5P = H5P || {}; var H5P = H5P || {};
@ -11,9 +12,7 @@ H5P.$window = H5P.jQuery(window);
if (document.documentElement.requestFullScreen) { if (document.documentElement.requestFullScreen) {
H5P.fullScreenBrowserPrefix = ''; H5P.fullScreenBrowserPrefix = '';
} }
else if (document.documentElement.webkitRequestFullScreen else if (document.documentElement.webkitRequestFullScreen) {
&& navigator.userAgent.indexOf('Android') === -1 // Skip Android
) {
H5P.safariBrowser = navigator.userAgent.match(/Version\/(\d)/); H5P.safariBrowser = navigator.userAgent.match(/Version\/(\d)/);
H5P.safariBrowser = (H5P.safariBrowser === null ? 0 : parseInt(H5P.safariBrowser[1])); H5P.safariBrowser = (H5P.safariBrowser === null ? 0 : parseInt(H5P.safariBrowser[1]));
@ -62,7 +61,7 @@ H5P.init = function () {
H5P.jQuery('<div class="h5p-content-controls"><div role="button" tabindex="1" class="h5p-enable-fullscreen" title="' + H5P.t('fullscreen') + '"></div></div>').prependTo($container).children().click(function () { H5P.jQuery('<div class="h5p-content-controls"><div role="button" tabindex="1" class="h5p-enable-fullscreen" title="' + H5P.t('fullscreen') + '"></div></div>').prependTo($container).children().click(function () {
H5P.fullScreen($container, instance); H5P.fullScreen($container, instance);
}); });
}; }
var $actions = H5P.jQuery('<ul class="h5p-actions"></ul>'); var $actions = H5P.jQuery('<ul class="h5p-actions"></ul>');
if (contentData.exportUrl !== '') { if (contentData.exportUrl !== '') {
@ -290,7 +289,7 @@ H5P.getPath = function (path, contentId) {
if (contentId !== undefined) { if (contentId !== undefined) {
prefix = H5PIntegration.getContentPath(contentId); prefix = H5PIntegration.getContentPath(contentId);
} }
else if (window['H5PEditor'] !== undefined) { else if (window.H5PEditor !== undefined) {
prefix = H5PEditor.filesPath; prefix = H5PEditor.filesPath;
} }
else { else {
@ -344,9 +343,10 @@ H5P.classFromName = function (name) {
* @return {Object} Instance. * @return {Object} Instance.
*/ */
H5P.newRunnable = function (library, contentId, $attachTo, skipResize) { H5P.newRunnable = function (library, contentId, $attachTo, skipResize) {
var nameSplit, versionSplit;
try { try {
var nameSplit = library.library.split(' ', 2); nameSplit = library.library.split(' ', 2);
var versionSplit = nameSplit[1].split('.', 2); versionSplit = nameSplit[1].split('.', 2);
} }
catch (err) { catch (err) {
return H5P.error('Invalid library string: ' + library.library); return H5P.error('Invalid library string: ' + library.library);
@ -358,12 +358,13 @@ H5P.newRunnable = function (library, contentId, $attachTo, skipResize) {
} }
// Find constructor function // Find constructor function
var constructor;
try { try {
nameSplit = nameSplit[0].split('.'); nameSplit = nameSplit[0].split('.');
var constructor = window; constructor = window;
for (var i = 0; i < nameSplit.length; i++) { for (var i = 0; i < nameSplit.length; i++) {
constructor = constructor[nameSplit[i]]; constructor = constructor[nameSplit[i]];
}; }
if (typeof constructor !== 'function') { if (typeof constructor !== 'function') {
throw null; throw null;
} }
@ -565,7 +566,7 @@ H5P.ContentCopyrights = function () {
} }
// Add sub content rights // Add sub content rights
for (var i = 0; i < content.length; i++) { for (i = 0; i < content.length; i++) {
html += content[i]; html += content[i];
} }

1
js/jquery.js vendored

File diff suppressed because one or more lines are too long

View File

@ -245,3 +245,6 @@ button.h5p-admin.disabled:hover {
font-size: 1.5em; font-size: 1.5em;
font-weight: bold; font-weight: bold;
} }
#h5p-admin-container .h5p-admin-center {
text-align: center;
}