From 9b76fccfcecb223dbd5129e5baa379e0dcea8708 Mon Sep 17 00:00:00 2001 From: Thomas Marstrander Date: Tue, 2 Feb 2016 16:29:48 +0100 Subject: [PATCH 1/6] HFJ-1610 - Gather statistics on dev or prod server. --- h5p.classes.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 3ccfd5f..4cbfa0a 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1700,6 +1700,8 @@ class H5PCore { if ($development_mode & H5PDevelopment::MODE_LIBRARY) { $this->h5pD = new H5PDevelopment($this->h5pF, $path . '/', $language); } + + $this->detectSiteType(); } /** @@ -2370,6 +2372,29 @@ class H5PCore { 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'); + } + } + } + /** * Fetch a list of libraries' metadata from h5p.org. * Save URL tutorial to database. Each platform implementation @@ -2379,6 +2404,8 @@ class H5PCore { $platformInfo = $this->h5pF->getPlatformInfo(); $platformInfo['autoFetchingDisabled'] = $fetchingDisabled; $platformInfo['uuid'] = $this->h5pF->getOption('site_uuid', ''); + $platformInfo['siteType'] = $this->h5pF->getOption('site_type', 'local'); + // Adding random string to GET to be sure nothing is cached $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)); From 2e0498cd3acc1e9962cd7d4ccc6bc7f72c45fa83 Mon Sep 17 00:00:00 2001 From: Thomas Marstrander Date: Wed, 3 Feb 2016 15:36:35 +0100 Subject: [PATCH 2/6] HFJ-1610 - Track number of contents per library type. --- h5p.classes.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 4cbfa0a..838d80a 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -334,6 +334,16 @@ interface H5PFrameworkInterface { */ 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 * @@ -2405,6 +2415,7 @@ class H5PCore { $platformInfo['autoFetchingDisabled'] = $fetchingDisabled; $platformInfo['uuid'] = $this->h5pF->getOption('site_uuid', ''); $platformInfo['siteType'] = $this->h5pF->getOption('site_type', 'local'); + $platformInfo['libraryContentCount'] = $this->h5pF->getLibraryContentCount(); // Adding random string to GET to be sure nothing is cached $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); From 5287d455b2f3ad6f4965759b6a9c9fde581dacf0 Mon Sep 17 00:00:00 2001 From: Thomas Marstrander Date: Wed, 3 Feb 2016 15:58:49 +0100 Subject: [PATCH 3/6] HFJ-1610 - Track libraries installed. --- h5p.classes.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 838d80a..c8662a1 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2405,6 +2405,28 @@ class H5PCore { } } + /** + * 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. * Save URL tutorial to database. Each platform implementation @@ -2416,6 +2438,7 @@ class H5PCore { $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 $random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5); From b42b28ab03c7e379dc4f02b911b64f0fba240d52 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Thu, 11 Feb 2016 15:00:08 +0100 Subject: [PATCH 4/6] Use correct jQuery HFJ-1610 --- js/disable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/disable.js b/js/disable.js index 83d740c..0bfbb07 100644 --- a/js/disable.js +++ b/js/disable.js @@ -16,4 +16,4 @@ $frame.change(toggle); toggle(); }); -})(jQuery); +})(H5P.jQuery); From bfcf4228dbfbd56d3e9c0d4bee3fd2d6edbf4d1b Mon Sep 17 00:00:00 2001 From: Thomas Marstrander Date: Mon, 22 Feb 2016 10:38:33 +0100 Subject: [PATCH 5/6] Use variable with complete path HFJ-1695 --- js/h5p.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/h5p.js b/js/h5p.js index 934d8f6..06f5ccb 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -1609,8 +1609,7 @@ H5P.setFinished = function (contentId, score, maxScore, time) { }; // Post the results - // TODO: Should we use a variable with the complete path? - H5P.jQuery.post(H5PIntegration.ajaxPath + 'setFinished', { + H5P.jQuery.post(H5PIntegration.ajax.setFinished, { contentId: contentId, score: score, maxScore: maxScore, From 6bfffbcf30ae6383af684218415a6ab1415d406c Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 23 Feb 2016 13:10:08 +0100 Subject: [PATCH 6/6] Added woff2 as a safe file type --- h5p.classes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index c8662a1..9627610 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1664,7 +1664,7 @@ class H5PCore { '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 $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $path, $development_mode, $h5pD, $disableFileCheck;