Resolve conflicts

namespaces
Svein-Tore Griff With 2014-11-02 21:07:08 +01:00
commit 658db52f89
2 changed files with 59 additions and 30 deletions

View File

@ -11,9 +11,26 @@ interface H5PFrameworkInterface {
* An associative array containing: * An associative array containing:
* - name: The name of the plattform, for instance "Wordpress" * - name: The name of the plattform, for instance "Wordpress"
* - version: The version of the pattform, for instance "4.0" * - version: The version of the pattform, for instance "4.0"
* - h5pVersion: The version of the H5P plugin/module
*/ */
public function getPlatformInfo(); 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
*
* @param string $machineName
* @param string $tutorialUrl
*/
public function setLibraryTutorialUrl($machineName, $tutorialUrl);
/** /**
* Show the user an error message * Show the user an error message
* *
@ -1509,7 +1526,7 @@ class H5PCore {
public static $coreApi = array( public static $coreApi = array(
'majorVersion' => 1, 'majorVersion' => 1,
'minorVersion' => 3 'minorVersion' => 4
); );
public static $styles = array( public static $styles = array(
'styles/h5p.css', 'styles/h5p.css',
@ -1631,19 +1648,23 @@ class H5PCore {
// Update content dependencies. // Update content dependencies.
$content['dependencies'] = $validator->getDependencies(); $content['dependencies'] = $validator->getDependencies();
$this->h5pF->deleteLibraryUsage($content['id']);
$this->h5pF->saveLibraryUsage($content['id'], $content['dependencies']);
if ($this->exportEnabled) { // Sometimes the parameters are filtered before content has been created
// Recreate export file if ($content['id']) {
$exporter = new H5PExport($this->h5pF, $this); $this->h5pF->deleteLibraryUsage($content['id']);
$exporter->createExportFile($content); $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; return $params;
} }
@ -2157,27 +2178,28 @@ class H5PCore {
} }
/** /**
* Get a list of libraries' metadata from h5p.org. Cache it, and refetch once a week. * Fetch a list of libraries' metadata from h5p.org.
* * Save URL tutorial to database. Each platform implementation
* @return mixed An object of objects keyed by machineName * is responsible for invoking this, eg using cron
*/ */
public function getLibrariesMetadata() { public function fetchLibrariesMetadata($fetchingDisabled = FALSE) {
// Fetch from cache: $platformInfo = $this->h5pF->getPlatformInfo();
// $metadata = $this->h5pF->cacheGet('libraries','metadata'); $platformInfo['autoFetchingDisabled'] = $fetchingDisabled;
$platformInfo['uuid'] = $this->h5pF->getOption('h5p_site_uuid', '');
// If not available in cache, or older than a week => refetch! // Adding random string to GET to be sure nothing is cached
if ($metadata === NULL || $metadata->lastTimeFetched < (time() - self::SECONDS_IN_WEEK)) { $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5);
$platformInfo = $this->h5pF->getPlatformInfo(); $json = $this->h5pF->fetchExternalData('http://h5p.lvh.me/h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random));
$json = file_get_contents('http://h5p.org/libraries-metadata.json?platform=' . json_encode($platformInfo)); if ($json !== NULL) {
$json = json_decode($json);
$metadata = new stdClass(); if (isset($json->libraries)) {
$metadata->json = ($json === FALSE ? NULL : json_decode($json)); foreach ($json->libraries as $machineName => $libInfo) {
$metadata->lastTimeFetched = time(); $this->h5pF->setLibraryTutorialUrl($machineName, $libInfo->tutorialUrl);
}
// $this->h5pF->cacheSet('libraries','metadata', $metadata); }
if($platformInfo['uuid'] === '' && isset($json->uuid)) {
$this->h5pF->setOption('h5p_site_uuid', $json->uuid);
}
} }
return $metadata->json;
} }
} }

View File

@ -1261,3 +1261,10 @@ if (H5P.jQuery) {
} }
}); });
} }
/**
* Mimics how php's htmlspecialchars works (the way we use it)
*/
H5P.htmlSpecialChars = function(string) {
return string.toString().replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&#039;').replace(/"/g, '&quot;');
};