Moved UUID-generation to backend

Added h5pVersion in platforminfo
Avoiding json beeing cached both locally and on backend
namespaces
Pål Jørgensen 2014-11-02 13:46:09 +01:00
parent cc40f2316c
commit f306d24f23
1 changed files with 17 additions and 35 deletions

View File

@ -11,7 +11,7 @@ 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"
* - uuid: UUID for site installation * - h5pVersion: The version of the H5P plugin/module
*/ */
public function getPlatformInfo(); public function getPlatformInfo();
@ -2037,34 +2037,6 @@ class H5PCore {
return $obj ? (object) $newArr : $newArr; 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 * Check if currently installed H5P libraries are supported by
* the current versjon of core. Which versions of which libraries are supported is * the current versjon of core. Which versions of which libraries are supported is
@ -2201,10 +2173,18 @@ class H5PCore {
public function fetchLibrariesMetadata($fetchingDisabled = FALSE) { public function fetchLibrariesMetadata($fetchingDisabled = FALSE) {
$platformInfo = $this->h5pF->getPlatformInfo(); $platformInfo = $this->h5pF->getPlatformInfo();
$platformInfo['autoFetchingDisabled'] = $fetchingDisabled; $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) { if ($json !== NULL) {
foreach ($json as $machineName => $libInfo) { if (isset($json->libraries)) {
$this->h5pF->setLibraryTutorialUrl($machineName, $libInfo->tutorialUrl); 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); return self::fetchCurl($url);
} }
else { else {
// Enable 'allow_url_fopen' or install cURL. // We have no transport mechanisme to use for communicating with h5p.org
// TODO - this could be reported to the user. // This may be reported to the user in future versions.
return NULL; return NULL;
} }
} }
@ -2241,6 +2221,8 @@ class H5PExternalDataFetcher {
private static function fetchCurl($url) { private static function fetchCurl($url) {
$curl = curl_init($url); $curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 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); $result = curl_exec($curl);
curl_close($curl); curl_close($curl);
return $result; return $result;