From 9ee5d2ebe7169970802a68dfad8fc347d1c0ee0f Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Tue, 25 Apr 2017 15:37:04 +0200 Subject: [PATCH] HFP-967 Update content validator to handle headers and tables --- h5p.classes.php | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 19488c8..cb83ea1 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -567,7 +567,7 @@ interface H5PFrameworkInterface { /** * Will trigger after the export file is created. */ - public function afterExportCreated(); + public function afterExportCreated($content, $filename); /** * Check if user has permissions to an action @@ -1610,16 +1610,19 @@ Class H5PExport { foreach ($files as $file) { // Please note that the zip format has no concept of folders, we must // use forward slashes to separate our directories. - $zip->addFile(realpath($file->absolutePath), $file->relativePath); + if (file_exists(realpath($file->absolutePath))) { + $zip->addFile(realpath($file->absolutePath), $file->relativePath); + } } // Close zip and remove tmp dir $zip->close(); H5PCore::deleteFileTree($tmpPath); + $filename = $content['slug'] . '-' . $content['id'] . '.h5p'; try { // Save export - $this->h5pC->fs->saveExport($tmpFile, $content['slug'] . '-' . $content['id'] . '.h5p'); + $this->h5pC->fs->saveExport($tmpFile, $filename); } catch (Exception $e) { $this->h5pF->setErrorMessage($this->h5pF->t($e->getMessage())); @@ -1627,7 +1630,7 @@ Class H5PExport { } unlink($tmpFile); - $this->h5pF->afterExportCreated(); + $this->h5pF->afterExportCreated($content, $filename); return true; } @@ -2471,12 +2474,13 @@ class H5PCore { $this->h5pF->setInfoMessage( $this->h5pF->t('Your site was successfully registered with the H5P Hub.') ); - $this->h5pF->setInfoMessage( - $this->h5pF->t('You have been provided a unique key that identifies you with the Hub when receiving new updates. The key is available for viewing in the "H5P Settings" page.') - ); + // TODO: Uncomment when key is once again available in H5P Settings +// $this->h5pF->setInfoMessage( +// $this->h5pF->t('You have been provided a unique key that identifies you with the Hub when receiving new updates. The key is available for viewing in the "H5P Settings" page.') +// ); } - if ($this->h5pF->getOption('h5p_send_usage_statistics', TRUE)) { + if ($this->h5pF->getOption('send_usage_statistics', TRUE)) { $siteData = array_merge( $registrationData, array( @@ -2776,10 +2780,6 @@ class H5PCore { * @param null|int $status_code Http response code */ private static function printJson($data, $status_code = NULL) { - if ($status_code !== NULL) { - http_response_code($status_code); - } - header('Cache-Control: no-cache'); header('Content-type: application/json; charset=utf-8'); print json_encode($data); @@ -2835,19 +2835,9 @@ class H5PCore { public function updateContentTypeCache($postData = NULL) { $interface = $this->h5pF; - // Set uuid - if (!$postData || !isset($postData['uuid'])) { - $site_uuid = $this->h5pF->getOption('site_uuid', ''); - - // Register site with site uuid if we don't already have it - // and try to update content type cache again when this is done - if (empty($site_uuid)) { - return $this->fetchLibrariesMetadata(); - } - - $postData = array( - 'uuid' => $site_uuid - ); + // Make sure data is sent! + if (!isset($postData) || !isset($postData['uuid'])) { + return $this->fetchLibrariesMetadata(); } $postData['current_cache'] = $this->h5pF->getOption('content_type_cache_updated_at', 0); @@ -2856,7 +2846,7 @@ class H5PCore { $endpoint = H5PHubEndpoints::CONTENT_TYPES; $data = $interface->fetchExternalData("{$protocol}://{$endpoint}", $postData); - if (! $this->h5pF->getOption('h5p_hub_is_enabled', TRUE)) { + if (! $this->h5pF->getOption('hub_is_enabled', TRUE)) { return TRUE; } @@ -3029,7 +3019,7 @@ class H5PContentValidator { public $h5pF; public $h5pC; private $typeMap, $libraries, $dependencies, $nextWeight; - private static $allowed_styleable_tags = array('span', 'p', 'div'); + private static $allowed_styleable_tags = array('span', 'p', 'div','h1','h2','h3', 'td'); /** * Constructor for the H5PContentValidator