]> git.mjollnir.org Git - moodle.git/commitdiff
output MDL-19077 Implemented periodic refresh to meta refresh by delay
authorsamhemelryk <samhemelryk>
Tue, 30 Jun 2009 07:57:41 +0000 (07:57 +0000)
committersamhemelryk <samhemelryk>
Tue, 30 Jun 2009 07:57:41 +0000 (07:57 +0000)
Also created layout-popup.php for standardwhite theme to provide a simpler template

lib/outputlib.php
lib/pagelib.php
theme/standardwhite/layout-popup.php [new file with mode: 0644]

index 09eae9f2f42c238f53641f99b6a0fde6f83305fd..70d0f8c333817afe5530a45ee11d6d3f1e1f0fd7 100644 (file)
@@ -787,6 +787,14 @@ class moodle_core_renderer extends moodle_renderer_base {
         }
         // This is only set by the {@link redirect()} method
         $output .= $this->metarefreshtag;
+
+        // Check if a periodic refresh delay has been set and make sure we arn't
+        // already meta refreshing
+        if ($this->metarefreshtag=='' && $this->page->periodicrefreshdelay!==null) {
+            $metarefesh = '<meta http-equiv="refresh" content="%d;url=%s" />';
+            $output .= sprintf($metarefesh, $this->page->periodicrefreshdelay, $this->page->url->out());
+        }
+
         ob_start();
         include($CFG->javascript);
         $output .= ob_get_contents();
@@ -912,6 +920,8 @@ class moodle_core_renderer extends moodle_renderer_base {
                     $this->metarefreshtag = '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />'."\n";
                     $this->page->requires->js_function_call('document.location.replace', array($url))->after_delay($delay+3);
                 }
+                $this->page->set_generaltype('popup');
+                $this->page->set_title('redirect');
                 $output = $this->header();
                 $output .= $this->notification($message, $messageclass);
                 $output .= $this->footer();
index 14686bb693a26c2fe19753f85ca21c2daba69d23..53e551c0682661c728d7b0b38a4d632ed65cb33c 100644 (file)
@@ -124,6 +124,14 @@ class moodle_page {
 
     protected $_button = '';
 
+    /**
+     * Sets the page to refresh after a given delay (in seconds) using meta refresh
+     * in {@link standard_head_html()} in outputlib.php
+     * If set to null(default) the page is not refreshed
+     * @var int|null
+     */
+    protected $_periodicrefreshdelay = null;
+
     /**
      * This is simply to improve backwards compatability. If old code relies on
      * a page class that implements print_header, or complex logic in
@@ -386,6 +394,13 @@ class moodle_page {
         return $this->_button;
     }
 
+    /**
+     *
+     */
+    public function get_periodicrefreshdelay() {
+        return $this->_periodicrefreshdelay;
+    }
+
     /**
      * PHP overloading magic to make the $PAGE->course syntax work by redirecting
      * it to the corresponding $PAGE->get_course() method if there is one, and
@@ -731,6 +746,26 @@ class moodle_page {
         $this->_cacheable = $cacheable;
     }
 
+    /**
+     * Sets the page to periodically refresh
+     *
+     * This function must be called before $OUTPUT->header has been called or
+     * a coding exception will be thrown.
+     *
+     * @param int $delay Sets the delay before refreshing the page, if set to null
+     *                    refresh is cancelled
+     */
+    public function set_periodic_refresh_delay($delay=null) {
+        if ($this->_state > self::STATE_BEFORE_HEADER) {
+            throw new coding_exception('You cannot set a periodic refresh delay after the header has been printed');
+        }
+        if ($delay===null) {
+            $this->_periodicrefreshdelay = null;
+        } else if (is_int($delay)) {
+            $this->_periodicrefreshdelay = $delay;
+        }
+    }
+
 /// Initialisation methods =====================================================
 /// These set various things up in a default way.
 
diff --git a/theme/standardwhite/layout-popup.php b/theme/standardwhite/layout-popup.php
new file mode 100644 (file)
index 0000000..b4ada2a
--- /dev/null
@@ -0,0 +1,34 @@
+<?php echo $OUTPUT->doctype() ?>
+<html <?php echo $OUTPUT->htmlattributes() ?>>
+<head>
+    <title><?php echo $PAGE->title ?></title>
+    <link rel="shortcut icon" href="<?php echo $CFG->themewww .'/'. current_theme() ?>/favicon.ico" />
+    <?php echo $OUTPUT->standard_head_html() ?>
+</head>
+<body id="<?php echo $PAGE->pagetype ?>" class="<?php echo $PAGE->bodyclasses ?>">
+<?php echo $OUTPUT->standard_top_of_body_html() ?>
+
+<div id="page">
+
+<?php if ($navigation) { // This is the navigation bar with breadcrumbs  ?>
+    <div class="navbar clearfix">
+        <div class="breadcrumb"><?php print_navigation($navigation); ?></div>
+        <div class="navbutton"><?php echo $PAGE->button; ?></div>
+    </div>
+<?php } else if ($PAGE->heading) { // If no navigation, but a heading, then print a line ?>
+    <hr />
+<?php } ?>
+<!-- END OF HEADER -->
+
+    <div id="content" class="clearfix">
+        [MAIN CONTENT GOES HERE]
+    </div>
+
+<!-- START OF FOOTER -->
+    <div id="footer" class="clearfix">
+
+    </div>
+</div>
+<?php echo $OUTPUT->standard_end_of_body_html() ?>
+</body>
+</html>
\ No newline at end of file