Skip to content

Commit

Permalink
Merge pull request #457 from kaltura/SUP-46972-Moodle-plugins-for-4.5
Browse files Browse the repository at this point in the history
Sup 46972 moodle plugins for 4.5
  • Loading branch information
roileviK authored Feb 20, 2025
2 parents f7dcabd + 988399f commit f6c823c
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 83 deletions.
133 changes: 70 additions & 63 deletions filter/kaltura/filter.php → filter/kaltura/classes/text_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace filter_kaltura;
use context_system;
use moodle_url;
use html_writer;

/**
* Kaltura filter script.
*
Expand All @@ -23,7 +28,7 @@
* @copyright (C) 2014 Remote-Learner.net Inc (http://www.remote-learner.net)
*/

class filter_kaltura extends moodle_text_filter {
class text_filter extends \core_filters\text_filter {
/** @var object $context The current page context. */
public static $pagecontext = null;

Expand All @@ -48,6 +53,7 @@ class filter_kaltura extends moodle_text_filter {
* @param object $page Moodle page object.
* @param object $context Page context object.
*/
#[\Override]
public function setup($page, $context) {
global $CFG;
require_once($CFG->dirroot.'/local/kaltura/locallib.php');
Expand Down Expand Up @@ -85,6 +91,66 @@ protected function get_course_context($context) {
return $coursecontext;
}

/**
* Change links to Kaltura into embedded Kaltura videos.
* @param array $link An array of elements matching the regular expression from class filter_kaltura - filter().
* @return string Kaltura embed video markup.
*/
function filter_kaltura_callback($link) {
$width = self::$defaultwidth;
$height = self::$defaultheight;
$source = '';

// Convert KAF URI anchor tags into iframe markup.
$count = count($link);
if ($count > 7) {
// Get the height and width of the iframe.
$properties = explode('||', $link[$count - 1]);

$width = $properties[2];
$height = $properties[3];

if (4 != count($properties)) {
return $link[0];
}

$source = self::$kafuri . '/browseandembed/index/media/entryid/' . $link[$count - 4] . $link[$count - 3];
}

// Convert v3 anchor tags into iframe markup.
if (7 == count($link) && $link[1] == self::$apiurl) {
$source = self::$kafuri.'/browseandembed/index/media/entryid/'.$link[4].'/playerSize/';
$source .= self::$defaultwidth.'x'.self::$defaultheight.'/playerSkin/'.$link[3];
}

$params = array(
'courseid' => self::$pagecontext->instanceid,
'height' => $height,
'width' => $width,
'withblocks' => 0,
'source' => $source

);

$url = new moodle_url('/filter/kaltura/lti_launch.php', $params);

$iframe = html_writer::tag('iframe', '', array(
'width' => $width,
'height' => $height,
'class' => 'kaltura-player-iframe',
'allowfullscreen' => 'true',
'allow' => 'autoplay *; fullscreen *; encrypted-media *; camera *; microphone *; display-capture *;',
'src' => $url->out(false),
'frameborder' => '0'
));

$iframeContainer = html_writer::tag('div', $iframe, array(
'class' => 'kaltura-player-container'
));

return $iframeContainer;
}

/**
* This function does the work of converting text that matches a regular expression into
* Kaltura video markup, so that links to Kaltura videos are displayed in the Kaltura
Expand All @@ -93,6 +159,7 @@ protected function get_course_context($context) {
* @param array $options An array of additional options.
* @return string The same text or modified text is returned.
*/
#[\Override]
public function filter($text, array $options = array()) {
global $CFG;

Expand Down Expand Up @@ -120,7 +187,7 @@ public function filter($text, array $options = array()) {
$uri = str_replace(array('.', '/', 'https'), array('\.', '\/', 'https?'), $uri);

$oldsearch = '/<a\s[^>]*href="('.$uri.')\/index\.php\/kwidget\/wid\/_([0-9]+)\/uiconf_id\/([0-9]+)\/entry_id\/([\d]+_([a-z0-9]+))\/v\/flash"[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($oldsearch, 'filter_kaltura_callback', $newtext);
$newtext = preg_replace_callback($oldsearch, [$this, 'filter_kaltura_callback'], $newtext);

// Search for newer versoin of Kaltura embedded anchor tag format.
$kafuri = self::$kafuri;
Expand Down Expand Up @@ -151,7 +218,7 @@ public function filter($text, array $options = array()) {
$search .= '))\/browseandembed\/index\/media\/entryid\/([\d]+_[a-z0-9]+)(\/([a-zA-Z0-9]+\/[a-zA-Z0-9]+\/)*)"[^>]*>([^>]*)<\/a>/is';
}

$newtext = preg_replace_callback($search, 'filter_kaltura_callback', $newtext);
$newtext = preg_replace_callback($search, [$this, 'filter_kaltura_callback'], $newtext);

if (empty($newtext) || $newtext === $text) {
// Error or not filtered.
Expand All @@ -162,63 +229,3 @@ public function filter($text, array $options = array()) {
return $newtext;
}
}

/**
* Change links to Kaltura into embedded Kaltura videos.
* @param array $link An array of elements matching the regular expression from class filter_kaltura - filter().
* @return string Kaltura embed video markup.
*/
function filter_kaltura_callback($link) {
$width = filter_kaltura::$defaultwidth;
$height = filter_kaltura::$defaultheight;
$source = '';

// Convert KAF URI anchor tags into iframe markup.
$count = count($link);
if ($count > 7) {
// Get the height and width of the iframe.
$properties = explode('||', $link[$count - 1]);

$width = $properties[2];
$height = $properties[3];

if (4 != count($properties)) {
return $link[0];
}

$source = filter_kaltura::$kafuri . '/browseandembed/index/media/entryid/' . $link[$count - 4] . $link[$count - 3];
}

// Convert v3 anchor tags into iframe markup.
if (7 == count($link) && $link[1] == filter_kaltura::$apiurl) {
$source = filter_kaltura::$kafuri.'/browseandembed/index/media/entryid/'.$link[4].'/playerSize/';
$source .= filter_kaltura::$defaultwidth.'x'.filter_kaltura::$defaultheight.'/playerSkin/'.$link[3];
}

$params = array(
'courseid' => filter_kaltura::$pagecontext->instanceid,
'height' => $height,
'width' => $width,
'withblocks' => 0,
'source' => $source

);

$url = new moodle_url('/filter/kaltura/lti_launch.php', $params);

$iframe = html_writer::tag('iframe', '', array(
'width' => $width,
'height' => $height,
'class' => 'kaltura-player-iframe',
'allowfullscreen' => 'true',
'allow' => 'autoplay *; fullscreen *; encrypted-media *; camera *; microphone *; display-capture *;',
'src' => $url->out(false),
'frameborder' => '0'
));

$iframeContainer = html_writer::tag('div', $iframe, array(
'class' => 'kaltura-player-container'
));

return $iframeContainer;
}
2 changes: 1 addition & 1 deletion mod/kalvidassign/grade_submissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

if (!empty($mode)) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
throw new \moodle_exception('confirmsesskeybad', 'error');
}
}

Expand Down
6 changes: 3 additions & 3 deletions mod/kalvidassign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ function kalvidassign_validate_cmid ($cmid) {
global $DB;

if (!$cm = get_coursemodule_from_id('kalvidassign', $cmid)) {
print_error('invalidcoursemodule');
throw new \moodle_exception('invalidcoursemodule');
}

if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
print_error('coursemisconf');
throw new \moodle_exception('coursemisconf');
}

if (!$kalvidassignobj = $DB->get_record('kalvidassign', array('id' => $cm->instance))) {
print_error('invalidid', 'kalvidassign');
throw new \moodle_exception('invalidid', 'kalvidassign');
}

return array($cm, $course, $kalvidassignobj);
Expand Down
4 changes: 2 additions & 2 deletions mod/kalvidassign/lti_launch.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
$source = $source = local_kaltura_add_kaf_uri_token($source);

if (!$cm = get_coursemodule_from_id('kalvidassign', $cmid)) {
print_error('invalidcoursemodule');
throw new \moodle_exception('invalidcoursemodule');
}

if (!$kalvidassignobj = $DB->get_record('kalvidassign', array('id' => $cm->instance))) {
print_error('invalidid', 'kalvidassign');
throw new \moodle_exception('invalidid', 'kalvidassign');
}

$submissionParams = array('vidassignid' => $kalvidassignobj->id, 'userid' => $USER->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/kalvidassign/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ public function display_grade_feedback($kalvidassign, $context) {

// We need the teacher info
if (!$teacher = $DB->get_record('user', array('id'=>$gradeby))) {
print_error('cannotfindteacher');
throw new \moodle_exception('cannotfindteacher');
}

// Print the feedback
Expand Down
2 changes: 1 addition & 1 deletion mod/kalvidassign/single_submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
require_login($course->id, false, $cm);

if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
throw new \moodle_exception('confirmsesskeybad', 'error');
}

global $CFG, $PAGE, $OUTPUT, $USER;
Expand Down
14 changes: 7 additions & 7 deletions mod/kalvidassign/submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
require_once(dirname(__FILE__).'/locallib.php');

if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
throw new \moodle_exception('confirmsesskeybad', 'error');
}

$entryid = required_param('entry_id', PARAM_TEXT);
Expand All @@ -40,15 +40,15 @@
$source = local_kaltura_build_kaf_uri($source);

if (! $cm = get_coursemodule_from_id('kalvidassign', $cmid)) {
print_error('invalidcoursemodule');
throw new \moodle_exception('invalidcoursemodule');
}

if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
print_error('coursemisconf');
throw new \moodle_exception('coursemisconf');
}

if (! $kalvidassignobj = $DB->get_record('kalvidassign', array('id' => $cm->instance))) {
print_error('invalidid', 'kalvidassign');
throw new \moodle_exception('invalidid', 'kalvidassign');
}

require_course_login($course->id, true, $cm);
Expand All @@ -59,18 +59,18 @@


if (kalvidassign_assignemnt_submission_expired($kalvidassignobj)) {
print_error('assignmentexpired', 'kalvidassign', 'course/view.php?id='.$course->id);
throw new \moodle_exception('assignmentexpired', 'kalvidassign', 'course/view.php?id='.$course->id);
}

echo $OUTPUT->header();

if (empty($entryid)) {
print_error('emptyentryid', 'kalvidassign', new moodle_url('/mod/kalvidassign/view.php', array('id' => $cm->id)));
throw new \moodle_exception('emptyentryid', 'kalvidassign', new moodle_url('/mod/kalvidassign/view.php', array('id' => $cm->id)));
}

// If the entry_id field is not empty but the source field is empty, then the data for this activity has not yet been migrated.
if (empty($source)) {
print_error('activity_not_migrated', 'kalvidassign', new moodle_url('/mod/kalvidassign/view.php', array('id' => $cm->id)));
throw new \moodle_exception('activity_not_migrated', 'kalvidassign', new moodle_url('/mod/kalvidassign/view.php', array('id' => $cm->id)));
}

$param = array('vidassignid' => $kalvidassignobj->id, 'userid' => $USER->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/kalvidassign/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// Retrieve module instance.
if (empty($id)) {
print_error('invalidid', 'kalvidassign');
throw new \moodle_exception('invalidid', 'kalvidassign');
}

if (!empty($id)) {
Expand Down
8 changes: 4 additions & 4 deletions mod/kalvidres/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@

// Retrieve module instance.
if (empty($id)) {
print_error('invalidid', 'kalvidres');
throw new \moodle_exception('invalidid', 'kalvidres');
}

if (!empty($id)) {

if (!$cm = get_coursemodule_from_id('kalvidres', $id)) {
print_error('invalidcoursemodule');
throw new \moodle_exception('invalidcoursemodule');
}

if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
print_error('coursemisconf');
throw new \moodle_exception('coursemisconf');
}

if (!$kalvidres = $DB->get_record('kalvidres', array("id" => $cm->instance))) {
print_error('invalidid', 'kalvidres');
throw new \moodle_exception('invalidid', 'kalvidres');
}
}

Expand Down

0 comments on commit f6c823c

Please sign in to comment.