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] 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; + } } /**