MDL-47252 mod_forum: fixed whitespace
[moodle.git] / blocks / news_items / block_news_items.php
blob092ae4bb46a88c77052ca2f969d93a608f401272
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This file contains the news item block class, based upon block_base.
20 * @package block_news_items
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 /**
26 * Class block_news_items
28 * @package block_news_items
29 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class block_news_items extends block_base {
33 function init() {
34 $this->title = get_string('pluginname', 'block_news_items');
37 function get_content() {
38 global $CFG, $USER;
40 if ($this->content !== NULL) {
41 return $this->content;
44 $this->content = new stdClass;
45 $this->content->text = '';
46 $this->content->footer = '';
48 if (empty($this->instance)) {
49 return $this->content;
53 if ($this->page->course->newsitems) { // Create a nice listing of recent postings
55 require_once($CFG->dirroot.'/mod/forum/lib.php'); // We'll need this
57 $text = '';
59 if (!$forum = forum_get_course_forum($this->page->course->id, 'news')) {
60 return '';
63 $modinfo = get_fast_modinfo($this->page->course);
64 if (empty($modinfo->instances['forum'][$forum->id])) {
65 return '';
67 $cm = $modinfo->instances['forum'][$forum->id];
69 if (!$cm->uservisible) {
70 return '';
73 $context = context_module::instance($cm->id);
75 /// User must have perms to view discussions in that forum
76 if (!has_capability('mod/forum:viewdiscussion', $context)) {
77 return '';
80 /// First work out whether we can post to this group and if so, include a link
81 $groupmode = groups_get_activity_groupmode($cm);
82 $currentgroup = groups_get_activity_group($cm, true);
85 if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
86 $text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
87 get_string('addanewtopic', 'forum').'</a>...</div>';
90 /// Get all the recent discussions we're allowed to see
92 if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false,
93 $currentgroup, $this->page->course->newsitems) ) {
94 $text .= '('.get_string('nonews', 'forum').')';
95 $this->content->text = $text;
96 return $this->content;
99 /// Actually create the listing now
101 $strftimerecent = get_string('strftimerecent');
102 $strmore = get_string('more', 'forum');
104 /// Accessibility: markup as a list.
105 $text .= "\n<ul class='unlist'>\n";
106 foreach ($discussions as $discussion) {
108 $discussion->subject = $discussion->name;
110 $discussion->subject = format_string($discussion->subject, true, $forum->course);
112 $text .= '<li class="post">'.
113 '<div class="head clearfix">'.
114 '<div class="date">'.userdate($discussion->modified, $strftimerecent).'</div>'.
115 '<div class="name">'.fullname($discussion).'</div></div>'.
116 '<div class="info"><a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.$discussion->subject.'</a></div>'.
117 "</li>\n";
119 $text .= "</ul>\n";
121 $this->content->text = $text;
123 $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
124 get_string('oldertopics', 'forum').'</a> ...';
126 /// If RSS is activated at site and forum level and this forum has rss defined, show link
127 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
128 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype && $forum->rssarticles) {
129 require_once($CFG->dirroot.'/lib/rsslib.php'); // We'll need this
130 if ($forum->rsstype == 1) {
131 $tooltiptext = get_string('rsssubscriberssdiscussions','forum');
132 } else {
133 $tooltiptext = get_string('rsssubscriberssposts','forum');
135 if (!isloggedin()) {
136 $userid = $CFG->siteguest;
137 } else {
138 $userid = $USER->id;
141 $this->content->footer .= '<br />'.rss_get_link($context->id, $userid, 'mod_forum', $forum->id, $tooltiptext);
146 return $this->content;