diff --git a/ajax.php b/ajax.php
index 512c2058..255a1cb7 100644
--- a/ajax.php
+++ b/ajax.php
@@ -365,7 +365,7 @@
}
$logo = isset($_FILES['logo']) ? $_FILES['logo'] : null;
- $formData = [
+ $formdata = [
'name' => required_param('name', PARAM_TEXT),
'email' => required_param('email', PARAM_EMAIL),
'description' => optional_param('description', '', PARAM_TEXT),
@@ -379,7 +379,7 @@
];
$core = framework::instance();
- $result = $core->hubRegisterAccount($formData, $logo);
+ $result = $core->hubRegisterAccount($formdata, $logo);
if ($result['success'] === false) {
$core->h5pF->setErrorMessage($result['message']);
@@ -439,7 +439,7 @@
// Update Hub status for content before proceeding
$newstate = hvp_update_hub_status($content);
- $synced = $newstate ? $newstate : intval($content['synced']);
+ $synced = $newstate !== false ? $newstate : intval($content['synced']);
if ($synced === \H5PContentHubSyncStatus::WAITING) {
\H5PCore::ajaxError(get_string('contentissyncing', 'hvp'));
@@ -462,37 +462,35 @@
// Add the icon and any screenshots
$files = array(
- 'icon' => !empty($_FILES['icon']) ? $_FILES['icon'] : NULL,
- 'screenshots' => !empty($_FILES['screenshots']) ? $_FILES['screenshots'] : NULL,
+ 'icon' => !empty($_FILES['icon']) ? $_FILES['icon'] : null,
+ 'screenshots' => !empty($_FILES['screenshots']) ? $_FILES['screenshots'] : null,
);
try {
$isedit = !empty($content['contentHubId']);
$updatecontent = $synced === \H5PContentHubSyncStatus::NOT_SYNCED && $isedit;
if ($updatecontent) {
- // node has been edited since the last time it was published
- $data['resync'] = 1;
+ // node has been edited since the last time it was published
+ $data['resync'] = 1;
}
- $result = $core->hubPublishContent($data, $files, $isedit ? $content['contentHubId'] : NULL);
+ $result = $core->hubPublishContent($data, $files, $isedit ? $content['contentHubId'] : null);
$fields = array(
- 'shared' => 1, // Content is always shared after sharing or editing
+ 'shared' => 1, // Content is always shared after sharing or editing
);
if (!$isedit) {
- $fields['hub_id'] = $result->content->id;
- // Sync will not happen on 'edit info', only for 'publish' or 'sync'.
- $fields['synced'] = \H5PContentHubSyncStatus::WAITING;
- }
- else if ($updatecontent) {
- $fields['synced'] = \H5PContentHubSyncStatus::WAITING;
+ $fields['hub_id'] = $result->content->id;
+ // Sync will not happen on 'edit info', only for 'publish' or 'sync'.
+ $fields['synced'] = \H5PContentHubSyncStatus::WAITING;
+ } else if ($updatecontent) {
+ $fields['synced'] = \H5PContentHubSyncStatus::WAITING;
}
// Store the content hub id
$core->h5pF->updateContentFields($cm->instance, $fields);
H5PCore::ajaxSuccess();
- }
- catch (Exception $e) {
+ } catch (Exception $e) {
H5PCore::ajaxError(!empty($e->errors) ? $e->errors : $e->getMessage());
}
diff --git a/classes/admin_setting_html.php b/classes/admin_setting_html.php
index efba5611..48fe941e 100644
--- a/classes/admin_setting_html.php
+++ b/classes/admin_setting_html.php
@@ -14,22 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+defined('MOODLE_INTERNAL') || die();
+
/**
* No setting - just html
* Note: since admin_setting is not namespaced, this can not be namespaced and put into a class
*/
class admin_setting_html extends admin_setting {
- private $hubInfo;
+ private $hubinfo;
/**
* not a setting, just html
*
* @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
*/
- public function __construct($name, $translation, $hubInfo) {
+ public function __construct($name, $translation, $hubinfo) {
$this->nosave = true;
- $this->hubInfo = $hubInfo;
+ $this->hubinfo = $hubinfo;
parent::__construct($name, $translation, '', '');
}
@@ -64,6 +66,6 @@ public function write_setting($data) {
*/
public function output_html($data, $query = '') {
global $OUTPUT;
- return $OUTPUT->render_from_template('mod_hvp/content_hub_registration_box', $this->hubInfo);
+ return $OUTPUT->render_from_template('mod_hvp/content_hub_registration_box', $this->hubinfo);
}
}
\ No newline at end of file
diff --git a/classes/content_hub_service.php b/classes/content_hub_service.php
index b0e1cced..64fc040b 100644
--- a/classes/content_hub_service.php
+++ b/classes/content_hub_service.php
@@ -35,22 +35,22 @@ class content_hub_service {
* @return array
* @throws Exception
*/
- public static function getRegistrationUISettings() {
- $core = framework::instance();
- $registrationUrl = new moodle_url('/mod/hvp/ajax.php', [
+ public static function get_registration_ui_settings() {
+ $core = framework::instance();
+ $registrationurl = new moodle_url('/mod/hvp/ajax.php', [
'action' => 'contenthubregistration',
]);
- $accountSettingsUrl = new moodle_url('/admin/settings.php?section=modsettinghvp');
+ $accountsettingsurl = new moodle_url('/admin/settings.php?section=modsettinghvp');
return [
- 'registrationURL' => $registrationUrl->out(true),
- 'accountSettingsUrl' => $accountSettingsUrl->out(true),
- 'token' => $core::createToken('contentHubRegistration'),
- 'l10n' => $core->getLocalization(),
- 'licenseAgreementTitle' => get_string('contenthub:licenseagreementtitle', 'hvp',),
- 'licenseAgreementDescription' => get_string('contenthub:licenseagreementdescription', 'hvp',),
- 'licenseAgreementMainText' => get_string('contenthub:licenseagreementmaintext', 'hvp',),
- 'accountInfo' => $core->hubAccountInfo(),
+ 'registrationURL' => $registrationurl->out(true),
+ 'accountSettingsUrl' => $accountsettingsurl->out(true),
+ 'token' => $core::createToken('contentHubRegistration'),
+ 'l10n' => $core->getLocalization(),
+ 'licenseAgreementTitle' => get_string('contenthub:licenseagreementtitle', 'hvp'),
+ 'licenseAgreementDescription' => get_string('contenthub:licenseagreementdescription', 'hvp'),
+ 'licenseAgreementMainText' => get_string('contenthub:licenseagreementmaintext', 'hvp'),
+ 'accountInfo' => $core->hubAccountInfo(),
];
}
}
diff --git a/classes/framework.php b/classes/framework.php
index 5595627f..5970e6e2 100644
--- a/classes/framework.php
+++ b/classes/framework.php
@@ -164,7 +164,7 @@ public function getPlatformInfo() {
* @inheritdoc
*/
// @codingStandardsIgnoreLine
- public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $allData = false, $headers = array(), $files = array(), $method = 'POST') {
+ public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $alldata = false, $headers = array(), $files = array(), $method = 'POST') {
global $CFG;
if (!empty($files)) {
@@ -177,29 +177,25 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
foreach ($value as $subvalue) {
$curldata[$key . '[]'] = $subvalue;
}
- }
- else {
+ } else {
$curldata[$key] = $value;
}
}
foreach ($files as $name => $file) {
- if ($file === NULL) {
+ if ($file === null) {
continue;
- }
- elseif (is_array($file['name'])) {
+ } else if (is_array($file['name'])) {
// Array of files uploaded (multiple)
- for ($i = 0; $i < count($file['name']); $i++) {
+ for ($i = 0; $i < count($file['name']); $i ++) {
$curldata[$name . '[]'] = new \CurlFile($file['tmp_name'][$i], $file['type'][$i], $file['name'][$i]);
}
- }
- else {
+ } else {
// Single file
$curldata[$name] = new \CurlFile($file['tmp_name'], $file['type'], $file['name']);
}
}
- }
- elseif (!empty($data)) {
+ } else if (!empty($data)) {
// application/x-www-form-urlencoded
$curldata = format_postdata_for_curlcall($data);
}
@@ -208,10 +204,10 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
'CURLOPT_SSL_VERIFYPEER' => true,
'CURLOPT_CONNECTTIMEOUT' => 20,
'CURLOPT_FOLLOWLOCATION' => 1,
- 'CURLOPT_MAXREDIRS' => 5,
+ 'CURLOPT_MAXREDIRS' => 5,
'CURLOPT_RETURNTRANSFER' => true,
- 'CURLOPT_NOBODY' => false,
- 'CURLOPT_TIMEOUT' => 300,
+ 'CURLOPT_NOBODY' => false,
+ 'CURLOPT_TIMEOUT' => 300,
);
if ($stream !== null) {
@@ -220,14 +216,14 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
// Generate local tmp file path.
$localfolder = $CFG->tempdir . uniqid('/hvp-');
- $stream = $localfolder . '.h5p';
+ $stream = $localfolder . '.h5p';
// Add folder and file paths to H5P Core.
$interface = self::instance('interface');
$interface->getUploadedH5pFolderPath($localfolder);
$interface->getUploadedH5pPath($stream);
- $stream = fopen($stream, 'w');
+ $stream = fopen($stream, 'w');
$options['CURLOPT_FILE'] = $stream;
}
@@ -240,11 +236,9 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
if (empty($data) || $method === 'GET') {
$response = $curl->get($url, array(), $options);
- }
- elseif ($method === 'POST') {
+ } else if ($method === 'POST') {
$response = $curl->post($url, $curldata, $options);
- }
- elseif ($method === 'PUT') {
+ } else if ($method === 'PUT') {
$response = $curl->put($url, $curldata, $options);
}
@@ -253,27 +247,27 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
@chmod($stream, $CFG->filepermissions);
}
- $error_no = $curl->get_errno();
+ $errorno = $curl->get_errno();
// Error handling
- if ($error_no) {
- if ($allData) {
+ if ($errorno) {
+ if ($alldata) {
$response = null;
- }
- else {
+ } else {
$this->setErrorMessage($response, 'failed-fetching-external-data');
- return FALSE;
+
+ return false;
}
}
- if ($allData) {
+ if ($alldata) {
$info = $curl->get_info();
+
return [
- 'status' => intval($info['http_code']),
- 'data' => empty($response) ? null : $response,
- 'headers' => $curl->get_raw_response(),
+ 'status' => intval($info['http_code']),
+ 'data' => empty($response) ? null : $response,
+ 'headers' => $curl->get_raw_response(),
];
- }
- else {
+ } else {
return $response;
}
}
@@ -1765,22 +1759,21 @@ public function replaceContentHubMetadataCache($metadata, $lang = 'en') {
// Check if exist in database
$cache = $DB->get_record_sql(
- 'SELECT id
+ 'SELECT id
FROM {hvp_content_hub_cache}
WHERE language = ?',
- array($lang)
+ array($lang)
);
if ($cache) {
- // Update
- $DB->execute("UPDATE {hvp_content_hub_cache} SET json = ? WHERE id = ?", array($metadata, $cache->id));
- }
- else {
- // Insert
- $DB->insert_record('hvp_content_hub_cache', (object) array(
- 'json' => $metadata,
- 'language' => $lang,
- 'last_checked' => time(),
- ));
+ // Update
+ $DB->execute("UPDATE {hvp_content_hub_cache} SET json = ? WHERE id = ?", array($metadata, $cache->id));
+ } else {
+ // Insert
+ $DB->insert_record('hvp_content_hub_cache', (object) array(
+ 'json' => $metadata,
+ 'language' => $lang,
+ 'last_checked' => time(),
+ ));
}
}
diff --git a/content_hub_registration.php b/content_hub_registration.php
index d5a00c50..16c56c9d 100644
--- a/content_hub_registration.php
+++ b/content_hub_registration.php
@@ -22,12 +22,12 @@
*/
use mod_hvp\content_hub_service;
-global $PAGE, $SITE, $OUTPUT, $CFG;
-
require_once("../../config.php");
require_once($CFG->libdir.'/adminlib.php');
require_once("locallib.php");
+global $PAGE, $SITE, $OUTPUT, $CFG;
+
// No guest autologin.
require_login(0, false);
@@ -40,7 +40,7 @@
$PAGE->set_title("{$SITE->shortname}: " . get_string('upgrade', 'hvp'));
$PAGE->set_heading(get_string('contenthub:settings:heading', 'mod_hvp'));
-$settings = content_hub_service::getRegistrationUISettings();
+$settings = content_hub_service::get_registration_ui_settings();
$PAGE->requires->data_for_js('H5PSettings', $settings, true);
$PAGE->requires->css(new moodle_url('library/styles/h5p.css'));
$PAGE->requires->css(new moodle_url('library/styles/h5p-hub-registration.css'));
diff --git a/settings.php b/settings.php
index 4d1c7d66..7724e973 100644
--- a/settings.php
+++ b/settings.php
@@ -113,9 +113,9 @@
);
// Content Hub
- try {
- $hubInfo = $core->hubAccountInfo();
+ $hubinfo = $core->hubAccountInfo();
+ if ($hubinfo) {
$settings->add(new admin_setting_heading(
'mod_hvp/content_hub_settings',
get_string('contenthub:settings:heading', 'hvp'),
@@ -125,12 +125,9 @@
$settings->add(new admin_setting_html(
'mod_hvp/content_hub_settings_box',
get_string('contenthub:settings:box', 'hvp'),
- $hubInfo
+ $hubinfo
));
}
- catch (Exception $e) {
- // Not showing account form
- }
// Load js for disable hub confirmation dialog functionality.
$PAGE->requires->js('/mod/hvp/library/js/jquery.js', true);
diff --git a/share.php b/share.php
index e6de17fc..5458c942 100644
--- a/share.php
+++ b/share.php
@@ -42,14 +42,14 @@
// Check if Hub registered, if not redirect to hub registration
if (empty(get_config('mod_hvp', 'site_uuid')) || empty(get_config('mod_hvp', 'hub_secret'))) {
- if (!has_capability('mod/hvp:contenthubregistration', $context)) {
- print_error('nohubregistration');
- }
- redirect(new moodle_url('/mod/hvp/content_hub_registration.php', ['id' => $id]));
+ if (!has_capability('mod/hvp:contenthubregistration', \context_system::instance())) {
+ print_error('nohubregistration');
+ }
+ redirect(new moodle_url('/mod/hvp/content_hub_registration.php'));
}
// Try to load existing content from the Hub
-$core = \mod_hvp\framework::instance();
+$core = \mod_hvp\framework::instance();
$content = $core->loadContent($cm->instance);
$action = optional_param('action', '', PARAM_TEXT);
@@ -69,14 +69,13 @@
$core = \mod_hvp\framework::instance();
if ($action === 'sync') {
// Sync content already shared on the Hub
- $slug = $content['slug'] ? $content['slug'] . '-' : '';
- $filename = "{$slug}{$content['id']}.h5p";
+ $slug = $content['slug'] ? $content['slug'] . '-' : '';
+ $filename = "{$slug}{$content['id']}.h5p";
$exporturl = \moodle_url::make_pluginfile_url($cm->module, 'mod_hvp', 'exports', 0, '/', $filename)->out(false);
if ($core->hubSyncContent($content['contentHubId'], $exporturl)) {
$core->h5pF->updateContentFields($content['id'], array('synced' => \H5PContentHubSyncStatus::WAITING));
}
- }
- elseif ($action === 'unpublish') {
+ } else if ($action === 'unpublish') {
// Unpublish content already shared on the Hub
if ($core->hubUnpublishContent($content['contentHubId'])) {
$core->h5pF->updateContentFields($content['id'], array('shared' => 0));
@@ -88,28 +87,28 @@
$hubcontent = !empty($content['contentHubId']) ? $core->hubRetrieveContent($content['contentHubId']) : null;
if (empty($content['contentHubId'])) {
- // Try to populate with license from content
- $license = !empty($content['metadata']['license']) ? $content['metadata']['license'] : null;
- $licenseVersion = !empty($license) && !empty($content['metadata']['licenseVersion']) ? $content['metadata']['licenseVersion'] : null;
- $hubcontent = [
- 'license' => $license,
- 'licenseVersion' => $licenseVersion,
- ];
+ // Try to populate with license from content
+ $license = !empty($content['metadata']['license']) ? $content['metadata']['license'] : null;
+ $licenseversion = !empty($license) && !empty($content['metadata']['licenseVersion']) ? $content['metadata']['licenseVersion'] : null;
+ $hubcontent = [
+ 'license' => $license,
+ 'licenseVersion' => $licenseversion,
+ ];
}
// Prepare settings for the UI
-$locale = \mod_hvp\framework::get_language();
+$locale = \mod_hvp\framework::get_language();
$settings = [
- 'token' => \H5PCore::createToken('share_' . $id),
- 'publishURL' => (new \moodle_url('/mod/hvp/ajax.php', array('action' => 'share', 'id' => $id)))->out(false),
- 'returnURL' => (new \moodle_url('/mod/hvp/view.php', array('id' => $id)))->out(false),
- 'l10n' => $core->getLocalization(),
- 'metadata' => json_decode($core->getUpdatedContentHubMetadataCache($locale)),
- 'title' => $cm->name,
- 'contentType' => "{$content['library']['name']} {$content['library']['majorVersion']}.{$content['library']['minorVersion']}",
- 'language' => $locale,
- 'hubContent' => $hubcontent,
- 'context' => $content['shared'] !== '1' ? 'share' : 'edit',
+ 'token' => \H5PCore::createToken('share_' . $id),
+ 'publishURL' => (new \moodle_url('/mod/hvp/ajax.php', array('action' => 'share', 'id' => $id)))->out(false),
+ 'returnURL' => (new \moodle_url('/mod/hvp/view.php', array('id' => $id)))->out(false),
+ 'l10n' => $core->getLocalization(),
+ 'metadata' => json_decode($core->getUpdatedContentHubMetadataCache($locale)),
+ 'title' => $cm->name,
+ 'contentType' => "{$content['library']['name']} {$content['library']['majorVersion']}.{$content['library']['minorVersion']}",
+ 'language' => $locale,
+ 'hubContent' => $hubcontent,
+ 'context' => empty($content['shared']) ? 'share' : 'edit',
];
// Configure page.
@@ -120,7 +119,7 @@
// Load JavaScript and styles
$PAGE->requires->js(new \moodle_url(\mod_hvp\view_assets::getsiteroot() . '/mod/hvp/library/js/h5p-hub-sharing.js'), true);
foreach (\H5PCore::$styles as $style) {
- $PAGE->requires->css(new \moodle_url(\mod_hvp\view_assets::getsiteroot() . "/mod/hvp/library/{$style}"));
+ $PAGE->requires->css(new \moodle_url(\mod_hvp\view_assets::getsiteroot() . "/mod/hvp/library/{$style}"));
}
$PAGE->requires->css(new \moodle_url(\mod_hvp\view_assets::getsiteroot() . '/mod/hvp/library/styles/h5p-hub-sharing.css'));
@@ -129,14 +128,14 @@
echo $OUTPUT->heading(format_string($cm->name));
?>
-
-
- Waiting for JavaScript
-
-
-
+
+
+ Waiting for JavaScript
+
+
+
footer();