-
Improvement
-
Resolution: Won't Do
-
Minor
-
None
-
2.5.7, 2.6.4, 2.7.1, 2.8.7, 2.9.1
-
MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE, MOODLE_28_STABLE, MOODLE_29_STABLE
-
The user policy, which is configured in Moodle with a full URL, is displayed in an iframe after an user has logged in for the first time.
Using an iframe has some downsides:
- Downside for usability: For long policy texts and small screens, there may appear two scrollbars.
- Downside for themes: The content of the iframe has to be styled separately and is not controlled implicitly be the theme's styles (at least that's what we experienced, maybe I am talking rubbish here)
- Downsides for impaired users: Inline text is always better than iframes for screenreaders
Therefore, we propose to display the policy text directly within the HTML code of the /user/policy.php file.
To prevent that existing policy file settings have to be changed, we have developed a replacement which uses CURL for fetching the policy file.
diff --git a/user/policy.php b/user/policy.php
|
index 5186868..f1556e3 100644
|
--- a/user/policy.php
|
+++ b/user/policy.php
|
@@ -73,6 +73,97 @@ $PAGE->navbar->add($strpolicyagreement);
|
echo $OUTPUT->header();
|
echo $OUTPUT->heading($strpolicyagreement);
|
|
+/* KIZ MODIFICATION START
|
+ REASON: We want to display the user policy directly instead of using an iframe */
|
+ // Set xml error handling
|
+ $errorSetting = libxml_use_internal_errors(true);
|
+ libxml_clear_errors();
|
+
|
+ // Init curl
|
+ $ch = curl_init();
|
+
|
+ // Fetch policy HTML Page
|
+ curl_setopt ($ch, CURLOPT_URL, $sitepolicy);
|
+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
|
+ $curldoc = curl_exec($ch);
|
+
|
+ // Was server unreachable?
|
+ if ($curldoc == false) {
|
+ // Inform admin directly by mail rather than using messaging
|
+ @mail(get_admin()->email,
|
+ 'WARNING: cURL error (Connection failed)',
|
+ 'cURL error when displaying user policy (Connection failed): '.$sitepolicy);
|
+
|
+ // Quit with error message
|
+ print_error('serverconnection','core_error');
|
+ }
|
+
|
+ // Or was there an http error?
|
+ else if (curl_getinfo($ch,CURLINFO_HTTP_CODE) > 200) {
|
+ // Inform admin directly by mail rather than using messaging
|
+ @mail(get_admin()->email,
|
+ 'WARNING: cURL error (HTTP Code '.curl_getinfo($ch,CURLINFO_HTTP_CODE).')',
|
+ 'cURL error when displaying user policy (HTTP Code '.curl_getinfo($ch,CURLINFO_HTTP_CODE).'): '.$sitepolicy);
|
+
|
+ // Quit with error message
|
+ print_error('serverconnection','core_error');
|
+ }
|
+
|
+ // Otherwise the document should have arrived
|
+ else {
|
+ // load dom
|
+ $policydoc = new DOMDocument();
|
+ $policydoc->loadHTML($curldoc);
|
+
|
+ // extract body node
|
+ $bodynode = $policydoc->getElementsByTagName('body')->item(0);
|
+
|
+ // Build new dom tree with content of body node
|
+ $html = new DOMDocument();
|
+ foreach ($bodynode->childNodes as $child) {
|
+ // If node is DOMComment, remove node
|
+ if (get_class($child) == 'DOMComment')
|
+ continue;
|
+ else {
|
+ // Add element to html code
|
+ $html->appendChild($html->importNode($child, true));
|
+ }
|
+ }
|
+
|
+ // Clean html code
|
+ $nodes = $html->getElementsByTagName('*');
|
+ foreach ($nodes as $node) {
|
+ // Remove class attribute
|
+ if ($node->hasAttribute('class'))
|
+ $node->removeAttribute('class');
|
+ // Remove id attribute
|
+ if ($node->hasAttribute('id'))
|
+ $node->removeAttribute('id');
|
+ // Remove style attribute
|
+ if ($node->hasAttribute('style'))
|
+ $node->removeAttribute('style');
|
+ }
|
+
|
+ // Print html code
|
+ echo '<div id="policybox">';
|
+ echo $html->saveHTML();
|
+ echo '</div>';
|
+ }
|
+
|
+ // Curl close
|
+ curl_close($ch);
|
+
|
+ // Reset xml error handling
|
+ libxml_clear_errors();
|
+ libxml_use_internal_errors($errorSetting);
|
+
|
+/* KIZ MODIFICATION END */
|
+/* ORIGINAL START
|
$mimetype = mimeinfo('type', $sitepolicy);
|
if ($mimetype == 'document/unknown') {
|
// Fallback for missing index.php, index.html.
|
@@ -85,6 +176,7 @@ $clicktoopen = '<a href="'.$sitepolicy.'" onclick="this.target=\'_blank\'">'.$st
|
echo '<div class="noticebox">';
|
echo resourcelib_embed_general($sitepolicy, $strpolicyagreement, $clicktoopen, $mimetype);
|
echo '</div>';
|
+ ORIGINAL END */
|
|
$formcontinue = new single_button(new moodle_url('policy.php', array('agree' => 1)), get_string('yes'));
|
$formcancel = new single_button(new moodle_url($CFG->wwwroot.'/login/logout.php', array('agree' => 0)), get_string('no'));
|
If the CURL solution is too big for you, a simple rich text configuration box where admins can input the policy text, may suffice for most installations. This would also solve the problem that the policy text has to be hosted separately.