From 17a6649b95707c3d1526005e35f878e5c4587482 Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Tue, 30 Jun 2009 07:57:41 +0000 Subject: [PATCH] output MDL-19077 Implemented periodic refresh to meta refresh by delay Also created layout-popup.php for standardwhite theme to provide a simpler template --- lib/outputlib.php | 10 ++++++++ lib/pagelib.php | 35 ++++++++++++++++++++++++++++ theme/standardwhite/layout-popup.php | 34 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 theme/standardwhite/layout-popup.php diff --git a/lib/outputlib.php b/lib/outputlib.php index 09eae9f2f4..70d0f8c333 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -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 = ''; + $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 = ''."\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(); diff --git a/lib/pagelib.php b/lib/pagelib.php index 14686bb693..53e551c068 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -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 index 0000000000..b4ada2ae2d --- /dev/null +++ b/theme/standardwhite/layout-popup.php @@ -0,0 +1,34 @@ +doctype() ?> +htmlattributes() ?>> + + <?php echo $PAGE->title ?> + + standard_head_html() ?> + + +standard_top_of_body_html() ?> + +
+ + + +heading) { // If no navigation, but a heading, then print a line ?> +
+ + + +
+ [MAIN CONTENT GOES HERE] +
+ + + +
+standard_end_of_body_html() ?> + + \ No newline at end of file -- 2.39.5