MDL-22054 converting block name strings to pluginname
[moodle.git] / blocks / news_items / block_news_items.php
CommitLineData
4ca6cfbf 1<?php
0f3fe4b6 2
e89d741a 3class block_news_items extends block_base {
9b4b78fd 4 function init() {
8e5c60bd 5 $this->title = get_string('pluginname', 'block_news_items');
433c242f 6 $this->version = 2007101509;
89adb174 7 }
8
0f3fe4b6 9 function get_content() {
cb640229 10 global $CFG, $USER;
0f3fe4b6 11
675dbdd9 12 if ($this->content !== NULL) {
13 return $this->content;
14 }
15
9b4b78fd 16 $this->content = new stdClass;
17 $this->content->text = '';
18 $this->content->footer = '';
19
20 if (empty($this->instance)) {
0f3fe4b6 21 return $this->content;
22 }
23
0f3fe4b6 24
cb640229 25 if ($this->page->course->newsitems) { // Create a nice listing of recent postings
90ec387a 26
27 require_once($CFG->dirroot.'/mod/forum/lib.php'); // We'll need this
1519aa2b 28
90ec387a 29 $text = '';
30
cb640229 31 if (!$forum = forum_get_course_forum($this->page->course->id, 'news')) {
08103c93 32 return '';
90ec387a 33 }
34
cb640229 35 $modinfo = get_fast_modinfo($this->page->course);
dd97c328 36 if (empty($modinfo->instances['forum'][$forum->id])) {
08103c93
ML
37 return '';
38 }
dd97c328 39 $cm = $modinfo->instances['forum'][$forum->id];
f39bba50 40
08103c93 41 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
90ec387a 42
5e71406d 43 /// User must have perms to view discussions in that forum
44 if (!has_capability('mod/forum:viewdiscussion', $context)) {
45 return '';
46 }
47
08103c93 48 /// First work out whether we can post to this group and if so, include a link
d9bf1982 49 $groupmode = groups_get_activity_groupmode($cm);
50 $currentgroup = groups_get_activity_group($cm, true);
5e71406d 51
90ec387a 52
08103c93 53 if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
99b054e4 54 $text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
90ec387a 55 get_string('addanewtopic', 'forum').'</a>...</div>';
90ec387a 56 }
57
58 /// Get all the recent discussions we're allowed to see
59
4ca6cfbf 60 if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false,
cb640229 61 $currentgroup, $this->page->course->newsitems) ) {
90ec387a 62 $text .= '('.get_string('nonews', 'forum').')';
63 $this->content->text = $text;
64 return $this->content;
65 }
66
67 /// Actually create the listing now
68
69 $strftimerecent = get_string('strftimerecent');
70 $strmore = get_string('more', 'forum');
71
5489fce7 72 /// Accessibility: markup as a list.
73 $text .= "\n<ul class='unlist'>\n";
90ec387a 74 foreach ($discussions as $discussion) {
75
76 $discussion->subject = $discussion->name;
77
c3cb9fb9 78 $discussion->subject = format_string($discussion->subject, true, $forum->course);
90ec387a 79
5489fce7 80 $text .= '<li class="post">'.
0710337e 81 '<div class="head">'.
49f7d01d 82 '<div class="date">'.userdate($discussion->modified, $strftimerecent).'</div>'.
83 '<div class="name">'.fullname($discussion).'</div></div>'.
0710337e 84 '<div class="info">'.$discussion->subject.' '.
90ec387a 85 '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.
0710337e 86 $strmore.'...</a></div>'.
5489fce7 87 "</li>\n";
90ec387a 88 }
5489fce7 89 $text .= "</ul>\n";
90ec387a 90
91 $this->content->text = $text;
92
93 $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
94 get_string('oldertopics', 'forum').'</a> ...';
95
f39bba50 96 /// If RSS is activated at site and forum level and this forum has rss defined, show link
97 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
98 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype && $forum->rssarticles) {
99 require_once($CFG->dirroot.'/lib/rsslib.php'); // We'll need this
100 if ($forum->rsstype == 1) {
101 $tooltiptext = get_string('rsssubscriberssdiscussions','forum',format_string($forum->name));
102 } else {
103 $tooltiptext = get_string('rsssubscriberssposts','forum',format_string($forum->name));
104 }
4f0c2d00 105 if (!isloggedin()) {
f39bba50 106 $userid = 0;
107 } else {
108 $userid = $USER->id;
109 }
cb640229 110 $this->content->footer .= '<br />'.rss_get_link($this->page->course->id, $userid, 'forum', $forum->id, $tooltiptext);
f39bba50 111 }
112
0f3fe4b6 113 }
90ec387a 114
0f3fe4b6 115 return $this->content;
116 }
117}
118
4ca6cfbf 119