$meta = '';
    }
    // Display header
    $navigation = array();
    $navigation[] = array('name' => shorten_text(htmlspecialchars($discussion->get_subject())), 'type' => 'forumng');
    if (class_exists('ouflags') && ou_get_is_mobile()) {
        ou_mobile_configure_theme();
    }
    $PAGEWILLCALLSKIPMAINDESTINATION = true;
    print_header_simple(format_string($forum->get_name()), '', build_navigation($navigation, $cm), '', $meta, true, $buttontext, navmenu($course, $cm));
    $forum->print_js($cm->id);
    if ($draftid) {
        $draft->print_js_variable($draftplayspaceid);
    }
    print '<div id="forumng-main" class="forumng-discuss forumng-nojs' . ($discussion->is_deleted() ? ' forumng-deleted-discussion' : '') . '">';
    print $forum->get_type()->display_switch_link();
    print skip_main_destination();
    // Get forum type to display main part of page
    $type = $forum->get_type();
    $type->print_discussion_page($discussion);
    print '</div>';
    if ($bad = forum_utils::is_bad_browser()) {
        print '<div class="forumng-bad-browser">' . get_string('badbrowser', 'forumng', $bad) . '</div>';
    }
    // Log request
    $discussion->log('view discussion');
    // Display footer
    print_footer($course);
} catch (forum_exception $e) {
    forum_utils::handle_exception($e);
}
 /**
  * Displays the discussion page.
  * @param forum_discussion $discussion Discussion
  */
 public function print_discussion_page($discussion)
 {
     $previousread = (int) $discussion->get_time_read();
     // 'Read date' option (used when viewing all posts so that they keep
     // their read/unread colouring)
     $timeread = optional_param('timeread', 0, PARAM_INT);
     if ($timeread) {
         $discussion->pretend_time_read($timeread);
         $previousread = $timeread;
     }
     // 'Expand all' option (always chosen for non-JS browsers)
     $expandall = optional_param('expand', 0, PARAM_INT) || forum_utils::is_bad_browser();
     // 'Expand all' option (always chosen for non-JS browsers)
     $collapseall = optional_param('collapse', 0, PARAM_INT);
     // Magic expand tracker (for use in JS only, never set server-side).
     // This tracks expanded posts, and makes the Back button 'work' in
     // the sense that it will expand these posts again.
     print '<form method="post" action="."><div>' . '<input type="hidden" id="expanded_posts" name="expanded_posts" ' . 'value="" /></div></form>';
     // Get content for all posts in the discussion
     $options = array();
     if ($expandall) {
         $options[forum_post::OPTION_CHILDREN_EXPANDED] = true;
     }
     if ($collapseall) {
         $options[forum_post::OPTION_CHILDREN_COLLAPSED] = true;
     }
     $content = $this->display_discussion($discussion, $options);
     // Some post display options use the read time to construct links
     // (usually for non-JS version) so that unread state is maintained.
     $options[forum_post::OPTION_READ_TIME] = $previousread;
     // Display expand all option if there are any 'Expand' links in content
     $fakedate = '&amp;timeread=' . $previousread;
     print '<div id="forumng-expandall">';
     $showexpandall = preg_match('~<a [^>]*href="discuss\\.php\\?d=[0-9]+[^"]*&amp;expand=1#p[0-9]+">~', $content);
     $showcollapseall = preg_match('~<div class="forumng-post forumng-full.*<div class="forumng-post forumng-full~s', $content);
     if ($showexpandall) {
         print '<a href="' . $discussion->get_url(forum::PARAM_HTML) . '&amp;expand=1' . $fakedate . '">' . get_string('expandall', 'forumng') . '</a>';
         if ($showcollapseall) {
             print ' &#x2022; ';
         }
     }
     if ($showcollapseall) {
         print '<a href="' . $discussion->get_url(forum::PARAM_HTML) . '&amp;collapse=1' . $fakedate . '">' . get_string('collapseall', 'forumng') . '</a> ';
     }
     print '</div>';
     // Display content
     print $content;
     // Print reply/edit forms for AJAX
     print $this->display_ajax_forms($discussion->get_forum());
     // Link back to forum
     print $discussion->display_link_back_to_forum();
     // Display discussion features (row of buttons)
     print $discussion->display_discussion_features();
     // Display the subscription options to this disucssion if available
     print $discussion->display_subscribe_options();
     // Atom/RSS links
     print $discussion->display_feed_links();
     // Set read data [shouldn't this logic be somewhere else as it is not
     // part of display?]
     if (forum::mark_read_automatically()) {
         $discussion->mark_read();
     }
 }
 /**
  * Prints out (immediately; must be after header) script tags and JS code
  * for the forum's JavaScript library, and required YUI libraries.
  * @param int $cmid If specified, passes this through to JS
  * @param int $absolute If true, use absolute path to embed the JS file. Default set to false
  */
 public function print_js($cmid = 0, $absolute = false)
 {
     $simple = get_user_preferences('forumng_simplemode', '');
     if (forum_utils::is_bad_browser() || $simple) {
         return;
     }
     global $CFG;
     if (ajaxenabled() || class_exists('ouflags')) {
         // YUI and basic script
         require_js(array('yui_yahoo', 'yui_event', 'yui_connection', 'yui_dom', 'yui_animation'));
         if ($absolute) {
             print '<script type="text/javascript" src="' . $CFG->wwwroot . '/mod/forumng/forumng.js"></script>';
         } else {
             print '<script type="text/javascript" src="forumng.js"></script>';
         }
         // Language strings and other data for JS
         $strings = '';
         $mainstrings = array('showadvanced' => null, 'hideadvanced' => null, 'rate' => null, 'expand' => '#', 'jserr_load' => null, 'jserr_save' => null, 'jserr_alter' => null, 'confirmdelete' => null, 'confirmundelete' => null, 'deletepostbutton' => null, 'undeletepostbutton' => null, 'js_nratings' => null, 'js_nratings1' => null, 'js_nopublicrating' => null, 'js_publicrating' => null, 'js_nouserrating' => null, 'js_userrating' => null, 'js_outof' => null, 'js_clicktosetrating' => null, 'js_clicktosetrating1' => null, 'js_clicktoclearrating' => null, 'edit_timeout' => null, 'selectlabel' => null, 'selectintro' => null, 'confirmselection' => null, 'selectedposts' => null, 'discussion' => null, 'selectorall' => null, 'flagon' => null, 'flagoff' => null, 'clearflag' => null, 'setflag' => null);
         if ($this->has_post_quota()) {
             $mainstrings['quotaleft_plural'] = (object) array('posts' => '#', 'period' => $this->get_max_posts_period(true, true));
             $mainstrings['quotaleft_singular'] = (object) array('posts' => '#', 'period' => $this->get_max_posts_period(true, true));
         }
         foreach ($mainstrings as $string => $value) {
             if ($strings !== '') {
                 $strings .= ',';
             }
             $strings .= $string . ':"' . addslashes_js(get_string($string, 'forumng', $value)) . '"';
         }
         foreach (array('cancel', 'delete', 'add', 'selectall', 'deselectall') as $string) {
             $strings .= ',core_' . $string . ':"' . addslashes_js(get_string($string)) . '"';
         }
         // Use star ratings where the scale is between 2 and 5 (3 and 6 stars)
         $scale = $this->get_rating_scale();
         if ($scale > 1 && $scale < 6) {
             $ratingstars = $scale;
         } else {
             $ratingstars = 0;
         }
         print '<script type="text/javascript">//<!--' . "\n" . 'forumng_pixpath="' . addslashes_js($CFG->pixpath) . '";' . 'forumng_modpixpath="' . addslashes_js($CFG->modpixpath . '/forumng') . '";' . 'forumng_strings={' . $strings . '};' . 'forumng_ratingstars=' . $ratingstars . ';' . ($cmid ? 'forumng_cmid=' . $cmid . ';' : '') . "\n" . '//--></script>';
     }
 }