3 class block_news_items
extends block_base
{
5 $this->title
= get_string('latestnews');
6 $this->version
= 2007101509;
9 function get_content() {
10 global $CFG, $USER, $COURSE;
12 if ($this->content
!== NULL) {
13 return $this->content
;
16 $this->content
= new stdClass
;
17 $this->content
->text
= '';
18 $this->content
->footer
= '';
20 if (empty($this->instance
)) {
21 return $this->content
;
25 if ($COURSE->newsitems
) { // Create a nice listing of recent postings
27 require_once($CFG->dirroot
.'/mod/forum/lib.php'); // We'll need this
31 if (!$forum = forum_get_course_forum($COURSE->id
, 'news')) {
35 $modinfo = get_fast_modinfo($COURSE);
36 if (empty($modinfo->instances
['forum'][$forum->id
])) {
39 $cm = $modinfo->instances
['forum'][$forum->id
];
41 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
43 /// First work out whether we can post to this group and if so, include a link
44 $groupmode = groups_get_activity_groupmode($cm);
45 $currentgroup = groups_get_activity_group($cm, true);
48 if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
49 $text .= '<div class="newlink"><a href="'.$CFG->wwwroot
.'/mod/forum/post.php?forum='.$forum->id
.'">'.
50 get_string('addanewtopic', 'forum').'</a>...</div>';
53 /// Get all the recent discussions we're allowed to see
55 if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false,
56 $currentgroup, $COURSE->newsitems
) ) {
57 $text .= '('.get_string('nonews', 'forum').')';
58 $this->content
->text
= $text;
59 return $this->content
;
62 /// Actually create the listing now
64 $strftimerecent = get_string('strftimerecent');
65 $strmore = get_string('more', 'forum');
67 /// Accessibility: markup as a list.
68 $text .= "\n<ul class='unlist'>\n";
69 foreach ($discussions as $discussion) {
71 $discussion->subject
= $discussion->name
;
73 $discussion->subject
= format_string($discussion->subject
, true, $forum->course
);
75 $text .= '<li class="post">'.
77 '<div class="date">'.userdate($discussion->modified
, $strftimerecent).'</div>'.
78 '<div class="name">'.fullname($discussion).'</div></div>'.
79 '<div class="info">'.$discussion->subject
.' '.
80 '<a href="'.$CFG->wwwroot
.'/mod/forum/discuss.php?d='.$discussion->discussion
.'">'.
81 $strmore.'...</a></div>'.
86 $this->content
->text
= $text;
88 $this->content
->footer
= '<a href="'.$CFG->wwwroot
.'/mod/forum/view.php?f='.$forum->id
.'">'.
89 get_string('oldertopics', 'forum').'</a> ...';
91 /// If RSS is activated at site and forum level and this forum has rss defined, show link
92 if (isset($CFG->enablerssfeeds
) && isset($CFG->forum_enablerssfeeds
) &&
93 $CFG->enablerssfeeds
&& $CFG->forum_enablerssfeeds
&& $forum->rsstype
&& $forum->rssarticles
) {
94 require_once($CFG->dirroot
.'/lib/rsslib.php'); // We'll need this
95 if ($forum->rsstype
== 1) {
96 $tooltiptext = get_string('rsssubscriberssdiscussions','forum',format_string($forum->name
));
98 $tooltiptext = get_string('rsssubscriberssposts','forum',format_string($forum->name
));
100 if (empty($USER->id
)) {
105 $this->content
->footer
.= '<br />'.rss_get_link($COURSE->id
, $userid, 'forum', $forum->id
, $tooltiptext);
110 return $this->content
;