From 1679021f6cdd880951ba161dcfcb0832a69222df Mon Sep 17 00:00:00 2001 From: Adis Date: Fri, 6 Dec 2024 21:06:23 +0100 Subject: [PATCH] 2024120600 release code --- .github/workflows/moodle-plugin-ci.yml | 9 ++- contentitem_return.php | 89 +++++++++++++------------- lib.php | 25 ++++++++ version.php | 2 +- 4 files changed, 76 insertions(+), 49 deletions(-) diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index fb77a72..225002c 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -15,7 +15,7 @@ jobs: services: postgres: - image: postgres:12 + image: postgres:13 env: POSTGRES_USER: 'postgres' POSTGRES_HOST_AUTH_METHOD: 'trust' @@ -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' diff --git a/contentitem_return.php b/contentitem_return.php index 1ea687a..bbe56b3 100644 --- a/contentitem_return.php +++ b/contentitem_return.php @@ -18,7 +18,7 @@ * 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 */ @@ -26,6 +26,7 @@ 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'); @@ -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); @@ -135,7 +133,7 @@ /** * 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: "", @@ -157,4 +155,5 @@ parent.document.body.dispatchEvent(sessionSelectedEvent); + diff --git a/lib.php b/lib.php index 8508b82..4dbfb72 100644 --- a/lib.php +++ b/lib.php @@ -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 * diff --git a/version.php b/version.php index d532754..f681604 100644 --- a/version.php +++ b/version.php @@ -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;