Skip to content

Commit

Permalink
2024120600 release code
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroAps committed Dec 6, 2024
1 parent 2d07949 commit 1679021
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 49 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

services:
postgres:
image: postgres:12
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -38,8 +38,11 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.1'
moodle-branch: 'master'
- php: '8.3'
moodle-branch: 'main'
database: 'pgsql'
- php: '8.3'
moodle-branch: 'MOODLE_404_STABLE'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
Expand Down
89 changes: 44 additions & 45 deletions contentitem_return.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
* Handles content item return.
*
* @package mod_panoptosubmission
* @copyright 2021 Panopto
* @copyright 2024 Panopto
* @author Panopto
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once($CFG->dirroot . '/blocks/panopto/lib/lti/panoptoblock_lti_utility.php');
require_once($CFG->dirroot . '/blocks/panopto/lib/panopto_data.php');
require_once(dirname(__FILE__) . '/lib.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/mod/lti/lib.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/mod/lti/locallib.php');

Expand Down Expand Up @@ -68,57 +69,54 @@
}

// Get and validate frame and thumbnail sizes.
$framewidth = 720;
$fwidth = $contentitems->{'@graph'}[0]->placementAdvice->displayWidth;
if (!empty($fwidth)) {
$framewidth = is_numeric($fwidth) ? $fwidth : $framewidth;
}

$frameheight = 480;
$fheight = $contentitems->{'@graph'}[0]->placementAdvice->displayHeight;
if (!empty($fheight)) {
$frameheight = is_numeric($fheight) ? $fheight : $frameheight;
}

$thumbnailwidth = 128;
$twidth = $contentitems->{'@graph'}[0]->thumbnail->width;
if (!empty($twidth)) {
$thumbnailwidth = is_numeric($twidth) ? $twidth : $thumbnailwidth;
}

$thumbnailheight = 72;
$theight = $contentitems->{'@graph'}[0]->thumbnail->height;
if (!empty($theight)) {
$thumbnailheight = is_numeric($theight) ? $theight : $thumbnailheight;
}

$title = "";
$itemtitle = $contentitems->{'@graph'}[0]->title;
if (!empty($itemtitle)) {
$framewidth = panoptosubmission_get_property_or_default(
$contentitems->{'@graph'}[0]->placementAdvice ?? new stdClass(),
'displayWidth',
720
);

$frameheight = panoptosubmission_get_property_or_default(
$contentitems->{'@graph'}[0]->placementAdvice ?? new stdClass(),
'displayHeight',
480
);

$title = panoptosubmission_get_property_or_default(
$contentitems->{'@graph'}[0] ?? new stdClass(),
'title',
''
);

if (!empty($title)) {
$invalidcharacters = ["$", "%", "#", "<", ">"];
$cleantitle = str_replace($invalidcharacters, "", $itemtitle);
$title = is_string($cleantitle) ? $cleantitle : $title;
$title = str_replace($invalidcharacters, "", $title);
}

$url = "";
$contenturl = $contentitems->{'@graph'}[0]->url;
if (!empty($contenturl)) {
$url = panoptosubmission_get_property_or_default(
$contentitems->{'@graph'}[0] ?? new stdClass(),
'url',
''
);

if (!empty($url)) {
$panoptodata = new \panopto_data($courseid);
$baseurl = parse_url($contenturl, PHP_URL_HOST);
if (strcmp($panoptodata->servername, $baseurl) === 0) {
$url = $contenturl;
$baseurl = parse_url($url, PHP_URL_HOST);
if (strcmp($panoptodata->servername, $baseurl) !== 0) {
$url = '';
}
}

$thumbnailurl = "";
$thumbnailurlfinal = !empty($contentitems->{'@graph'}[0]->thumbnail->id)
? $contentitems->{'@graph'}[0]->thumbnail->id
: $contentitems->{'@graph'}[0]->thumbnail->{'@id'};
if (!empty($thumbnailurlfinal)) {
$thumbnailurl = is_string($thumbnailurlfinal) ? $thumbnailurlfinal : $thumbnailurl;
}
$thumbnail = $contentitems->{'@graph'}[0]->thumbnail ?? new stdClass();
$thumbnailurlfinal = panoptosubmission_get_property_or_default(
$thumbnail,
'id',
panoptosubmission_get_property_or_default($thumbnail, '@id', '')
);

$thumbnailwidth = panoptosubmission_get_property_or_default($thumbnail, 'width', 128);
$thumbnailheight = panoptosubmission_get_property_or_default($thumbnail, 'height', 72);

$customdata = $contentitems->{'@graph'}[0]->custom;
$customdata = $contentitems->{'@graph'}[0]->custom ?? new stdClass();

// In this version of Moodle LTI contentitem request we do not want the interactive viewer.
unset($customdata->use_panopto_interactive_view);
Expand All @@ -135,7 +133,7 @@
<?php else: ?>
/**
* Create and dispatch a custom event 'sessionSelected' with session details.
* This event should close the panopto popup and pass the new content URL to the existing iframe.
* This event should close the Panopto popup and pass the new content URL to the existing iframe.
*/
const detailObject = {
title: "<?php echo $title ?>",
Expand All @@ -157,4 +155,5 @@

parent.document.body.dispatchEvent(sessionSelectedEvent);
<?php endif; ?>

</script>
25 changes: 25 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,31 @@ function panoptosubmission_pluginfile(
send_stored_file($file, 0, 0, true, $options);
}

/**
* Retrieve a property in a case-insensitive way and assign default if missing or invalid.
*
* @param object $object The object to search.
* @param string $property The property name to find.
* @param mixed $default The default value to return if not found or invalid.
*/
function panoptosubmission_get_property_or_default($object, $property, $default) {
// Ensure the input is an object, return default otherwise.
if (!is_object($object)) {
return $default;
}

// Iterate over object properties in a case-insensitive manner.
foreach ($object as $key => $value) {
if (strcasecmp($key, $property) === 0) { // strcasecmp is case-insensitive.
// Return default if the value is strictly 0 or evaluates to false.
return ($value === 0 || !$value) ? $default : $value;
}
}

// Return default if the property is not found.
return $default;
}

/**
* Function to be run periodically according to the moodle cron
*
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

// The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2024070900;
$plugin->version = 2024120600;

// Requires this Moodle version - 4.1.0.
$plugin->requires = 2022112800;
Expand Down

0 comments on commit 1679021

Please sign in to comment.