forked from SpenserJ/Moodle2-Panopto
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plug-in version 2016101227 with mutliple updates.
Merge from Panopto private repository. - Update the code to follow Moodle coding guideline. - Fix issues reported on GitHub #26, #35, #37 - Add help message to setting items. - Change the default setting of “Asynchronous enrollment sync” and “Automatically provision newly created courses” as Yes. - Minimum Moodle version is set to 2.7.
- Loading branch information
1 parent
62e476d
commit 4572d44
Showing
25 changed files
with
1,317 additions
and
793 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ Fork the block, fix a bug or add a new feature, and send us a pull-request. Or, | |
## Copyright | ||
|
||
Copyright Panopto 2009 - 2013 / With contributions from Spenser Jones ([email protected]) | ||
|
||
## License | ||
|
||
The Panopto plugin for Moodle is free software: you can redistribute it and/or modify | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,69 +15,74 @@ | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* manages the single sign on logic between panopto and moodle | ||
* | ||
* @package block_panopto | ||
* @copyright Panopto 2009 - 2015 /With contributions from Spenser Jones ([email protected]) | ||
* @copyright Panopto 2009 - 2016 /With contributions from Spenser Jones ([email protected]) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
global $CFG, $USER; | ||
|
||
if (empty($CFG)) { | ||
require_once("../../config.php"); | ||
require_once('../../config.php'); | ||
} | ||
require_once($CFG->libdir . '/weblib.php'); | ||
require_once("lib/block_panopto_lib.php"); | ||
require_once('lib/block_panopto_lib.php'); | ||
|
||
$servername = required_param("serverName", PARAM_HOST); | ||
$callbackurl = required_param("callbackURL", PARAM_URL); | ||
$expiration = preg_replace('/[^0-9\.]/', '', required_param("expiration", PARAM_RAW)); // A float doesn't have the required precision. | ||
$requestauthcode = required_param("authCode", PARAM_ALPHANUM); | ||
$action = optional_param("action", "", PARAM_ALPHA); | ||
$servername = required_param('serverName', PARAM_HOST); | ||
$callbackurl = required_param('callbackURL', PARAM_URL); | ||
|
||
$relogin = ($action == "relogin"); | ||
// A float doesn't have the required precision. | ||
$expiration = preg_replace('/[^0-9\.]/', '', required_param('expiration', PARAM_RAW)); | ||
|
||
if ($relogin || (isset($USER->username) && ($USER->username == "guest"))) { | ||
$requestauthcode = required_param('authCode', PARAM_ALPHANUM); | ||
$action = optional_param('action', '', PARAM_ALPHA); | ||
|
||
$relogin = ($action == 'relogin'); | ||
|
||
if ($relogin || (isset($USER->username) && ($USER->username == 'guest'))) { | ||
require_logout(); | ||
|
||
// Return to this page, minus the "action=relogin" parameter. | ||
redirect($CFG->wwwroot . "/blocks/panopto/SSO.php" . | ||
redirect($CFG->wwwroot . '/blocks/panopto/SSO.php' . | ||
"?authCode=$requestauthcode" . | ||
"&serverName=$servername" . | ||
"&expiration=$expiration" . | ||
"&callbackURL=" . urlencode($callbackurl)); | ||
'&callbackURL=' . urlencode($callbackurl)); | ||
return; | ||
} | ||
|
||
// No course ID (0). Don't autologin guests (false). | ||
require_login(0, false); | ||
|
||
// Reproduce canonically-ordered incoming auth payload. | ||
$requestauthpayload = "serverName=" . $servername . "&expiration=" . $expiration; | ||
$requestauthpayload = 'serverName=' . $servername . '&expiration=' . $expiration; | ||
|
||
// Verify passed in parameters are properly signed. | ||
if (panopto_validate_auth_code($requestauthpayload, $requestauthcode)) { | ||
$userkey = panopto_decorate_username($USER->username); | ||
|
||
// Generate canonically-ordered auth payload string. | ||
$responseparams ="serverName=" . $servername . "&externalUserKey=" . $userkey . "&expiration=" . $expiration; | ||
$responseparams = 'serverName=' . $servername . '&externalUserKey=' . $userkey . '&expiration=' . $expiration; | ||
// Sign payload with shared key and hash. | ||
$responseauthcode = panopto_generate_auth_code($responseparams); | ||
|
||
// Encode user key in case the backslash causes a sequence to be interpreted as an escape sequence | ||
// (e.g. in the case of usernames that begin with digits). | ||
// Maintain the original canonical string to avoid signature mismatch. | ||
$responseparamsencoded = "serverName=" . $servername . "&externalUserKey=" . urlencode($userkey) . "&expiration=" . $expiration; | ||
$responseparamsencoded = 'serverName=' . $servername . '&externalUserKey=' . urlencode($userkey) . '&expiration=' . $expiration; | ||
|
||
$separator = (strpos($callbackurl, "?") ? "&" : "?"); | ||
$redirecturl = $callbackurl . $separator . $responseparamsencoded . "&authCode=" . $responseauthcode; | ||
$separator = (strpos($callbackurl, '?') ? '&' : '?'); | ||
$redirecturl = $callbackurl . $separator . $responseparamsencoded . '&authCode=' . $responseauthcode; | ||
|
||
// Redirect to Panopto Focus login page. | ||
redirect($redirecturl); | ||
} else { | ||
echo $OUTPUT->header(); | ||
|
||
echo "Invalid auth code."; | ||
echo 'Invalid auth code.'; | ||
|
||
echo $OUTPUT->footer(); | ||
} | ||
/* End of file SSO.php */ | ||
/* End of file SSO.php */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,59 +13,52 @@ | |
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file contains the main logic for the block_panopto package. | ||
* | ||
* @package block_panopto | ||
* @copyright Panopto 2009 - 2015 /With contributions from Spenser Jones ([email protected]) | ||
* @copyright Panopto 2009 - 2016 /With contributions from Spenser Jones ([email protected]) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once("lib/panopto_data.php"); | ||
require_once('lib/panopto_data.php'); | ||
require_once(dirname(__FILE__) . '/../../lib/accesslib.php'); | ||
|
||
/** | ||
* Base class for the Panopto block for Moodle. | ||
* | ||
* | ||
* @package block_panopto | ||
* @copyright Panopto 2009 - 2015 | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class block_panopto extends block_base { | ||
|
||
/** | ||
*ID of the div element containing the contents of the Panopto block. | ||
*/ | ||
* ID of the div element containing the contents of the Panopto block. | ||
*/ | ||
const CONTENTID = 'block_panopto_content'; | ||
|
||
/** | ||
*Name of the panopto block. Should match the block's directory name on the server. | ||
* Name of the panopto block. Should match the block's directory name on the server. | ||
* | ||
* @var string $blockname the name of the current block. | ||
*/ | ||
public $blockname = "panopto"; | ||
public $blockname = 'panopto'; | ||
|
||
/** | ||
* Set system properties of plugin. | ||
*/ | ||
public function init() { | ||
global $COURSE; | ||
$this->title = get_string('pluginname', 'block_panopto'); | ||
} | ||
|
||
/** | ||
* Block has global config (display "Settings" link on blocks admin page). | ||
*/ | ||
public function has_config() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Save global block data in mdl_config_plugins table instead of global CFG variable. | ||
* Block has global config (display "Settings" link on blocks admin page). | ||
*/ | ||
public function config_save($data) { | ||
|
||
foreach ($data as $name => $value) { | ||
set_config($name, trim($value), $this->blockname); | ||
} | ||
public function has_config() { | ||
return true; | ||
} | ||
|
||
|
@@ -78,22 +71,22 @@ public function instance_allow_config() { | |
|
||
/** | ||
* Save per-instance config in custom table instead of mdl_block_instance configdata column. | ||
* | ||
* @param array $data the data being set on panopto | ||
* @param bool $nolongerused depcrecated variable | ||
*/ | ||
public function instance_config_save($data, $nolongerused = false) { | ||
global $COURSE; | ||
if (!empty($data->course)) { | ||
panopto_data::set_panopto_course_id($COURSE->id, $data->course); | ||
|
||
// If role mapping info is given, map roles. | ||
if (!empty($data->creator) || !empty($data->publisher)) { | ||
panopto_data::set_course_role_permissions($COURSE->id, $data->publisher, $data->creator); | ||
|
||
// Get course context. | ||
$context = context_course::instance($COURSE->id); | ||
} | ||
} else { | ||
// If server is not set globally, there will be no other form values to push into config. | ||
return true; | ||
if (!empty($data->course)) { | ||
panopto_data::set_panopto_course_id($this->page->course->id, $data->course); | ||
// Add roles mapping. | ||
$publisherroles = (isset($data->publisher)) ? $data->publisher : array(); | ||
$creatorroles = (isset($data->creator)) ? $data->creator : array(); | ||
self::set_course_role_permissions( | ||
$this->page->course->id, | ||
$publisherroles, | ||
$creatorroles | ||
); | ||
} | ||
} | ||
|
||
|
@@ -102,7 +95,7 @@ public function instance_config_save($data, $nolongerused = false) { | |
* Hittesh Ahuja - University of Bath. | ||
*/ | ||
public function cron() { | ||
global $CFG, $USER, $DB; | ||
global $DB; | ||
$panoptodata = new panopto_data(null); | ||
|
||
// Check Panopto Focus API Settings exist. | ||
|
@@ -137,81 +130,78 @@ public function cron() { | |
* Generate HTML for block contents. | ||
*/ | ||
public function get_content() { | ||
global $COURSE; | ||
|
||
|
||
global $COURSE, $PAGE; | ||
|
||
if ($this->content !== null) { | ||
return $this->content; | ||
} | ||
|
||
$this->content = new stdClass; | ||
//Initialize $this->content->text to an empty string here to avoid trying to append to it before | ||
+ //it has been initialized and throwing a warning. Bug 33163 | ||
+ $this->content->text = ""; | ||
|
||
|
||
|
||
// Initialize $this->content->text to an empty string here to avoid trying to append to it before | ||
// It has been initialized and throwing a warning. Bug 33163. | ||
$this->content->text = ''; | ||
$this->content->footer = ''; | ||
|
||
global $PAGE; | ||
|
||
$params = array('id' => self::CONTENTID, 'courseid' => $COURSE->id); | ||
|
||
$PAGE->requires->yui_module('moodle-block_panopto-asyncload', | ||
'M.block_panopto.asyncload.init', | ||
array($params), | ||
null, | ||
true); | ||
|
||
$this->content->text = html_writer::tag('div', "<font id='loading_text'>" . get_string('fetching_content', 'block_panopto') . "</font>", $params); | ||
$this->content->text .= '<script type="text/javascript"> | ||
// Function to pop up Panopto live note taker. | ||
function panopto_launchNotes(url) { | ||
// Open empty notes window, then POST SSO form to it. | ||
var notesWindow = window.open("", "PanoptoNotes", "width=500,height=800,resizable=1,scrollbars=0,status=0,location=0"); | ||
document.SSO.action = url; | ||
document.SSO.target = "PanoptoNotes"; | ||
document.SSO.submit(); | ||
// Ensure the new window is brought to the front of the z-order. | ||
notesWindow.focus(); | ||
} | ||
function panopto_startSSO(linkElem) { | ||
document.SSO.action = linkElem.href; | ||
document.SSO.target = "_blank"; | ||
document.SSO.submit(); | ||
// Cancel default link navigation. | ||
return false; | ||
} | ||
function panopto_toggleHiddenLectures() { | ||
var showAllToggle = document.getElementById("showAllToggle"); | ||
var hiddenLecturesDiv = document.getElementById("hiddenLecturesDiv"); | ||
if(hiddenLecturesDiv.style.display == "block") { | ||
hiddenLecturesDiv.style.display = "none"; | ||
showAllToggle.innerHTML = "' . get_string('show_all', 'block_panopto') . '"; | ||
} else { | ||
hiddenLecturesDiv.style.display = "block"; | ||
showAllToggle.innerHTML = "' . get_string('show_less', 'block_panopto') . '"; | ||
} | ||
} | ||
</script>'; | ||
|
||
$this->content->text = html_writer::tag('div', "<font id='loading_text'>" . | ||
get_string('fetching_content', 'block_panopto') . '</font>', $params); | ||
|
||
$this->content->text .= '<script type="text/javascript">' . | ||
'// Function to pop up Panopto live note taker.' . | ||
'function panopto_launchNotes(url) {' . | ||
'// Open empty notes window, then POST SSO form to it.' . | ||
'var notesWindow = window.open("", "PanoptoNotes", ' . | ||
'"width=500,height=800,resizable=1,scrollbars=0,status=0,location=0");' . | ||
'document.SSO.action = url;' . | ||
'document.SSO.target = "PanoptoNotes";' . | ||
'document.SSO.submit();' . | ||
|
||
'// Ensure the new window is brought to the front of the z-order.' . | ||
'notesWindow.focus();' . | ||
'}' . | ||
|
||
'function panopto_startSSO(linkElem) {' . | ||
'document.SSO.action = linkElem.href;' . | ||
'document.SSO.target = "_blank";' . | ||
'document.SSO.submit();' . | ||
|
||
'// Cancel default link navigation.' . | ||
'return false;' . | ||
'}' . | ||
|
||
'function panopto_toggleHiddenLectures() {' . | ||
'var showAllToggle = document.getElementById("showAllToggle");' . | ||
'var hiddenLecturesDiv = document.getElementById("hiddenLecturesDiv");' . | ||
|
||
'if(hiddenLecturesDiv.style.display == "block") {' . | ||
'hiddenLecturesDiv.style.display = "none";' . | ||
'showAllToggle.innerHTML = "' . get_string('show_all', 'block_panopto') . '";' . | ||
'} else {' . | ||
'hiddenLecturesDiv.style.display = "block";' . | ||
'showAllToggle.innerHTML = "' . get_string('show_less', 'block_panopto') . '";' . | ||
'}' . | ||
'}' . | ||
'</script>'; | ||
|
||
return $this->content; | ||
} | ||
|
||
/** | ||
* Return applicable formats | ||
* Which page types this block may appear on | ||
* @return array | ||
*/ | ||
public function applicable_formats() { | ||
return array( | ||
'my' => false, | ||
'all' => true | ||
); | ||
// Since block is dealing with courses and enrolments the only possible. | ||
// place where Panopto block can be used is the course. | ||
return array('course-view' => true); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.