Merge branches 'file-storage-interface' and 'master' of https://github.com/h5p/h5p-php-library into file-storage-interface

pull/17/head
Thomas Marstrander 2016-02-24 09:49:11 +01:00
commit 92e4ab0f9e
3 changed files with 64 additions and 4 deletions

View File

@ -334,6 +334,16 @@ interface H5PFrameworkInterface {
*/ */
public function getLibraryUsage($libraryId); public function getLibraryUsage($libraryId);
/**
* Get a key value list of library version and count of content created
* using that library.
*
* @return array
* Array containing library, major and minor version - content count
* e.g. "H5P.CoursePresentation 1.6" => "14"
*/
public function getLibraryContentCount();
/** /**
* Loads a library * Loads a library
* *
@ -1664,7 +1674,7 @@ class H5PCore {
'js/h5p-utils.js', 'js/h5p-utils.js',
); );
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 woff2 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';
public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $fs, $development_mode, $h5pD, $disableFileCheck; public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $fs, $development_mode, $h5pD, $disableFileCheck;
@ -1713,6 +1723,8 @@ class H5PCore {
if ($development_mode & H5PDevelopment::MODE_LIBRARY) { if ($development_mode & H5PDevelopment::MODE_LIBRARY) {
$this->h5pD = new H5PDevelopment($this->h5pF, $path . '/', $language); $this->h5pD = new H5PDevelopment($this->h5pF, $path . '/', $language);
} }
$this->detectSiteType();
} }
/** /**
@ -2390,6 +2402,51 @@ class H5PCore {
return $html; return $html;
} }
/**
* Detects if the site was accessed from localhost,
* through a local network or from the internet.
*/
public function detectSiteType() {
$type = $this->h5pF->getOption('site_type', 'local');
// Determine remote/visitor origin
$localhostPattern = '/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/i';
// localhost
if ($type !== 'internet' && !preg_match($localhostPattern, $_SERVER['REMOTE_ADDR'])) {
if (filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) {
// Internet
$this->h5pF->setOption('site_type', 'internet');
}
elseif ($type === 'local') {
// Local network
$this->h5pF->setOption('site_type', 'network');
}
}
}
/**
* Get a list of installed libraries, different minor versions will
* return separate entries.
*
* @return array
* A distinct array of installed libraries
*/
public function getLibrariesInstalled() {
$librariesInstalled = [];
$libs = $this->h5pF->loadLibraries();
foreach($libs as $library) {
foreach($library as $libVersion) {
$librariesInstalled[] = $libVersion->name.' '.$libVersion->major_version.'.'.$libVersion->minor_version.'.'.$libVersion->patch_version;
}
}
return $librariesInstalled;
}
/** /**
* Fetch a list of libraries' metadata from h5p.org. * Fetch a list of libraries' metadata from h5p.org.
* Save URL tutorial to database. Each platform implementation * Save URL tutorial to database. Each platform implementation
@ -2399,6 +2456,10 @@ class H5PCore {
$platformInfo = $this->h5pF->getPlatformInfo(); $platformInfo = $this->h5pF->getPlatformInfo();
$platformInfo['autoFetchingDisabled'] = $fetchingDisabled; $platformInfo['autoFetchingDisabled'] = $fetchingDisabled;
$platformInfo['uuid'] = $this->h5pF->getOption('site_uuid', ''); $platformInfo['uuid'] = $this->h5pF->getOption('site_uuid', '');
$platformInfo['siteType'] = $this->h5pF->getOption('site_type', 'local');
$platformInfo['libraryContentCount'] = $this->h5pF->getLibraryContentCount();
$platformInfo['librariesInstalled'] = $this->getLibrariesInstalled();
// Adding random string to GET to be sure nothing is cached // Adding random string to GET to be sure nothing is cached
$random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5);
$json = $this->h5pF->fetchExternalData('http://h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random)); $json = $this->h5pF->fetchExternalData('http://h5p.org/libraries-metadata.json?api=1&platform=' . urlencode(json_encode($platformInfo)) . '&x=' . urlencode($random));

View File

@ -16,4 +16,4 @@
$frame.change(toggle); $frame.change(toggle);
toggle(); toggle();
}); });
})(jQuery); })(H5P.jQuery);

View File

@ -1610,8 +1610,7 @@ H5P.setFinished = function (contentId, score, maxScore, time) {
}; };
// Post the results // Post the results
// TODO: Should we use a variable with the complete path? H5P.jQuery.post(H5PIntegration.ajax.setFinished, {
H5P.jQuery.post(H5PIntegration.ajaxPath + 'setFinished', {
contentId: contentId, contentId: contentId,
score: score, score: score,
maxScore: maxScore, maxScore: maxScore,