Skip to content

Commit

Permalink
Fix complaints from moodle ci linter
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmars committed Apr 14, 2021
1 parent 0f43d79 commit 9d9e785
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 75 deletions.
18 changes: 9 additions & 9 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
break;

case 'contenthubregistration':
// Check permission
// Check permission.
$context = \context_system::instance();
if (!has_capability('mod/hvp:contenthubregistration', $context)) {
\H5PCore::ajaxError(get_string('contenthub:nopermissions', 'hvp'), 'NO_PERMISSION', 403);
Expand Down Expand Up @@ -433,12 +433,12 @@
'age' => optional_param('age', null, PARAM_RAW),
);

// Load content
// Load content.
$core = \mod_hvp\framework::instance();
$cm = get_coursemodule_from_id('hvp', $id);
$content = $core->loadContent($cm->instance);

// Update Hub status for content before proceeding
// Update Hub status for content before proceeding.
$newstate = hvp_update_hub_status($content);
$synced = $newstate !== false ? $newstate : intval($content['synced']);

Expand All @@ -447,10 +447,10 @@
break;
}

// Create URL
// Create URL.
$data['download_url'] = hvp_create_hub_export_url($cm->id, $content);

// Get file size
// Get file size.
$slug = $content['slug'] ? $content['slug'] . '-' : '';
$filecontext = context_course::instance($cm->course);
$file = get_file_storage()->get_file($filecontext->id, 'mod_hvp', 'exports', 0, '/', "{$slug}{$content['id']}.h5p");
Expand All @@ -461,7 +461,7 @@
$size = $file->get_filesize();
$data['size'] = empty($size) ? -1 : $size;

// Add the icon and any screenshots
// Add the icon and any screenshots.
$files = array(
'icon' => !empty($_FILES['icon']) ? $_FILES['icon'] : null,
'screenshots' => !empty($_FILES['screenshots']) ? $_FILES['screenshots'] : null,
Expand All @@ -471,13 +471,13 @@
$isedit = !empty($content['contentHubId']);
$updatecontent = $synced === \H5PContentHubSyncStatus::NOT_SYNCED && $isedit;
if ($updatecontent) {
// node has been edited since the last time it was published
// Node has been edited since the last time it was published.
$data['resync'] = 1;
}
$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;
Expand All @@ -487,7 +487,7 @@
$fields['synced'] = \H5PContentHubSyncStatus::WAITING;
}

// Store the content hub id
// Store the content hub id.
$core->h5pF->updateContentFields($cm->instance, $fields);

H5PCore::ajaxSuccess();
Expand Down
2 changes: 1 addition & 1 deletion classes/admin_setting_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function get_defaultsetting() {
* @return string Always returns an empty string
*/
public function write_setting($data) {
// do not write any setting
// Do not write any setting.
return '';
}

Expand Down
16 changes: 8 additions & 8 deletions classes/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
$curldata = array();
foreach ($data as $key => $value) {
if (empty($value)) {
continue; // Skip empty values
continue; // Skip empty values.
}
if (is_array($value)) {
foreach ($value as $i => $subvalue) {
Expand All @@ -186,17 +186,17 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
if ($file === null) {
continue;
} else if (is_array($file['name'])) {
// Array of files uploaded (multiple)
// Array of files uploaded (multiple).
for ($i = 0; $i < count($file['name']); $i ++) {
$curldata["{$name}[{$i}]"] = new \CurlFile($file['tmp_name'][$i], $file['type'][$i], $file['name'][$i]);
}
} else {
// Single file
// Single file.
$curldata[$name] = new \CurlFile($file['tmp_name'], $file['type'], $file['name']);
}
}
} else if (!empty($data)) {
// application/x-www-form-urlencoded
// Application/x-www-form-urlencoded.
$curldata = format_postdata_for_curlcall($data);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ public function fetchExternalData($url, $data = null, $blocking = true, $stream
}

$errorno = $curl->get_errno();
// Error handling
// Error handling.
if ($errorno) {
if ($alldata) {
$response = null;
Expand Down Expand Up @@ -1854,18 +1854,18 @@ public function libraryHasUpgrade($library) {
public function replaceContentHubMetadataCache($metadata, $lang = 'en') {
global $DB;

// Check if exist in database
// Check if exist in database.
$cache = $DB->get_record_sql(
'SELECT id
FROM {hvp_content_hub_cache}
WHERE language = ?',
array($lang)
);
if ($cache) {
// Update
// Update.
$DB->execute("UPDATE {hvp_content_hub_cache} SET json = ? WHERE id = ?", array($metadata, $cache->id));
} else {
// Insert
// Insert.
$DB->insert_record('hvp_content_hub_cache', (object) array(
'json' => $metadata,
'language' => $lang,
Expand Down
2 changes: 1 addition & 1 deletion db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
'mod/hvp:contenthubregistration' => [
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => [], // only admins by default
'archetypes' => [], // Only admins by default.
],

);
20 changes: 10 additions & 10 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,21 @@ function hvp_upgrade_2020082800() {
* Drop old unused unique index, add nonunique index.
*/
function hvp_upgrade_2020091500() {
global $DB;
$dbman = $DB->get_manager();
$table = new xmldb_table('hvp_xapi_results');
$index = new xmldb_index('results', XMLDB_INDEX_NOTUNIQUE, ['content_id', 'user_id']);
$dbman->add_index($table, $index);

$oldindex = new xmldb_index('result', XMLDB_INDEX_UNIQUE, ['id', 'content_id', 'user_id']);
$dbman->drop_index($table, $oldindex);
global $DB;
$dbman = $DB->get_manager();
$table = new xmldb_table('hvp_xapi_results');
$index = new xmldb_index('results', XMLDB_INDEX_NOTUNIQUE, ['content_id', 'user_id']);
$dbman->add_index($table, $index);

$oldindex = new xmldb_index('result', XMLDB_INDEX_UNIQUE, ['id', 'content_id', 'user_id']);
$dbman->drop_index($table, $oldindex);
}

function hvp_upgrade_2020112600() {
global $DB;
$dbman = $DB->get_manager();

// Add Content Hub fields to main content table
// Add Content Hub fields to main content table.
$table = new xmldb_table('hvp');
if (!$dbman->field_exists($table, 'shared')) {
$dbman->add_field($table, new xmldb_field('shared', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'completionpass'));
Expand All @@ -550,7 +550,7 @@ function hvp_upgrade_2020112600() {
$dbman->add_field($table, new xmldb_field('hub_id', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'synced'));
}

// Create table for caching content hub metadata
// Create table for caching content hub metadata.
$table = new xmldb_table('hvp_content_hub_cache');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('language', XMLDB_TYPE_CHAR, '31', null, XMLDB_NOTNULL, null, null);
Expand Down
4 changes: 2 additions & 2 deletions lang/en/hvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@
$string['gradeheading'] = 'Results for {$a}';
$string['assistivetechnologieslabel'] = 'Assistive Technologies label';

// Content hub
// Content hub.
$string['contenthub:settings:heading'] = 'H5P Hub Account Settings';
$string['contenthub:settings:box'] = 'Content Hub Account';
$string['contenthub:licenseagreementtitle'] = 'End User License Agreement (EULA)';
Expand Down Expand Up @@ -588,7 +588,7 @@
$string['updateregistrationonhub'] = 'Save account settings';
$string['successfullyupdated'] = 'Your H5P Hub account settings have successfully been changed';

# Content hub
// Content hub.
$string['age'] = 'Typical age';
$string['agedescription'] = 'The target audience of this content. Possible input formats separated by commas: "1,34-45,-50,59-".';
$string['invalidage'] = 'Invalid input format for Typical age. Possible input formats separated by commas: "1, 34-45, -50, -59-".';
Expand Down
9 changes: 4 additions & 5 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function hvp_delete_instance($id) {
array($hvp->main_library_id)
);

// Only log event if we found library
// Only log event if we found library.
if ($library) {
// Log content delete.
new \mod_hvp\event(
Expand Down Expand Up @@ -293,7 +293,7 @@ function hvp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload
return false; // Invalid context.
}

// Allow download if valid temporary hash
// Allow download if valid temporary hash.
$ishub = false;
$hub = optional_param('hub', null, PARAM_RAW);
if ($hub) {
Expand All @@ -305,12 +305,11 @@ function hvp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload
$signature = hash_hmac('SHA512', $data, get_config('mod_hvp', 'hub_secret'), true);

if ($time < (time() - 43200) || !hash_equals($signature, $hash)) {
// No valid hash
// No valid hash.
return false;
}
$ishub = true;
}
elseif (!has_capability('mod/hvp:view', $context)) {
} else if (!has_capability('mod/hvp:view', $context)) {
// No permission.
return false;
}
Expand Down
55 changes: 29 additions & 26 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,21 +670,22 @@ function hvp_attempt_submitted_handler($event) {
* @param $content
*/
function hvp_update_hub_status($content) {
$synced = intval($content['synced']);
$synced = intval($content['synced']);

// Only check sync status when waiting
if (empty($content['contentHubId']) || $synced !== H5PContentHubSyncStatus::WAITING) {
return false;
}
// Only check sync status when waiting.
if (empty($content['contentHubId']) || $synced !== H5PContentHubSyncStatus::WAITING) {
return false;
}

$core = \mod_hvp\framework::instance();
$newstate = $core->getHubContentStatus($content['contentHubId'], $synced);
if ($newstate !== false) {
$core->h5pF->updateContentFields($content['id'], array('synced' => $newstate));
return $newstate;
}
$core = \mod_hvp\framework::instance();
$newstate = $core->getHubContentStatus($content['contentHubId'], $synced);
if ($newstate !== false) {
$core->h5pF->updateContentFields($content['id'], array('synced' => $newstate));

return false;
return $newstate;
}

return false;
}

/**
Expand All @@ -693,25 +694,27 @@ function hvp_update_hub_status($content) {
* @param $content
*/
function hvp_create_hub_export_url($cmid, $content) {
// Create URL
$modulecontext = \context_module::instance($cmid);
$slug = $content['slug'] ? $content['slug'] . '-' : '';
$filename = "{$slug}{$content['id']}.h5p";
$exporturl = \moodle_url::make_pluginfile_url($modulecontext->id, 'mod_hvp', 'exports', '', '', $filename)->out(false);

// To prevent anyone else from downloading we add an extra token
$time = time();
$data = $time . ':' . get_config('mod_hvp', 'site_uuid');
$hash = hash_hmac('SHA512', $data, get_config('mod_hvp', 'hub_secret'), true);
$token = hvp_base64_encode($time) . '.' . hvp_base64_encode($hash);

return "$exporturl?hub=$token";
// Create URL.
$modulecontext = \context_module::instance($cmid);
$slug = $content['slug'] ? $content['slug'] . '-' : '';
$filename = "{$slug}{$content['id']}.h5p";
$exporturl = \moodle_url::make_pluginfile_url($modulecontext->id, 'mod_hvp', 'exports', '', '', $filename)
->out(false);

// To prevent anyone else from downloading we add an extra token.
$time = time();
$data = $time . ':' . get_config('mod_hvp', 'site_uuid');
$hash = hash_hmac('SHA512', $data, get_config('mod_hvp', 'hub_secret'), true);
$token = hvp_base64_encode($time) . '.' . hvp_base64_encode($hash);

return "$exporturl?hub=$token";
}

/**
* URL compatible base64 encoding.
*
* @param string $string
* @param string $string
*
* @return string
*/
function hvp_base64_encode($string) {
Expand Down
6 changes: 3 additions & 3 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ public function validation($data, $files) {
public function data_postprocessing($data) {
// Determine disabled content features.

// mod_form may be loaded without the H5P editor, so we have to check if
// Mod_form may be loaded without the H5P editor, so we have to check if
// data is present if we want to process them.
$hasDisplayOptions = isset($data->frame)
$hasdisplayoptions = isset($data->frame)
|| isset($data->export)
|| isset($data->embed)
|| isset($data->copyright);
if ($hasDisplayOptions) {
if ($hasdisplayoptions) {
$options = array(
\H5PCore::DISPLAY_OPTION_FRAME => isset($data->frame) ? $data->frame : 0,
\H5PCore::DISPLAY_OPTION_DOWNLOAD => isset($data->export) ? $data->export : 0,
Expand Down
2 changes: 1 addition & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
)
);

// Content Hub
// Content Hub.
$hubinfo = $core->hubAccountInfo();
$settings->add(new admin_setting_heading(
'mod_hvp/content_hub_settings',
Expand Down
Loading

0 comments on commit 9d9e785

Please sign in to comment.