From c9914966f334c4e3f23270e11b0f24acd643f0fe Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 10 Oct 2014 13:56:48 +0200 Subject: [PATCH] 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; } }