MDL-22054 converting block name strings to pluginname
[moodle.git] / blocks / news_items / block_news_items.php
1 <?php
3 class block_news_items extends block_base {
4     function init() {
5         $this->title = get_string('pluginname', 'block_news_items');
6         $this->version = 2007101509;
7     }
9     function get_content() {
10         global $CFG, $USER;
12         if ($this->content !== NULL) {
13             return $this->content;
14         }
16         $this->content = new stdClass;
17         $this->content->text = '';
18         $this->content->footer = '';
20         if (empty($this->instance)) {
21             return $this->content;
22         }
25         if ($this->page->course->newsitems) {   // Create a nice listing of recent postings
27             require_once($CFG->dirroot.'/mod/forum/lib.php');   // We'll need this
29             $text = '';
31             if (!$forum = forum_get_course_forum($this->page->course->id, 'news')) {
32                 return '';
33             }
35             $modinfo = get_fast_modinfo($this->page->course);
36             if (empty($modinfo->instances['forum'][$forum->id])) {
37                 return '';
38             }
39             $cm = $modinfo->instances['forum'][$forum->id];
41             $context = get_context_instance(CONTEXT_MODULE, $cm->id);
43         /// User must have perms to view discussions in that forum
44             if (!has_capability('mod/forum:viewdiscussion', $context)) {
45                 return '';
46             }
48         /// First work out whether we can post to this group and if so, include a link
49             $groupmode    = groups_get_activity_groupmode($cm);
50             $currentgroup = groups_get_activity_group($cm, true);
53             if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) {
54                 $text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
55                           get_string('addanewtopic', 'forum').'</a>...</div>';
56             }
58         /// Get all the recent discussions we're allowed to see
60             if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false,
61                                                        $currentgroup, $this->page->course->newsitems) ) {
62                 $text .= '('.get_string('nonews', 'forum').')';
63                 $this->content->text = $text;
64                 return $this->content;
65             }
67         /// Actually create the listing now
69             $strftimerecent = get_string('strftimerecent');
70             $strmore = get_string('more', 'forum');
72         /// Accessibility: markup as a list.
73             $text .= "\n<ul class='unlist'>\n";
74             foreach ($discussions as $discussion) {
76                 $discussion->subject = $discussion->name;
78                 $discussion->subject = format_string($discussion->subject, true, $forum->course);
80                 $text .= '<li class="post">'.
81                          '<div class="head">'.
82                          '<div class="date">'.userdate($discussion->modified, $strftimerecent).'</div>'.
83                          '<div class="name">'.fullname($discussion).'</div></div>'.
84                          '<div class="info">'.$discussion->subject.' '.
85                          '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'.
86                          $strmore.'...</a></div>'.
87                          "</li>\n";
88             }
89             $text .= "</ul>\n";
91             $this->content->text = $text;
93             $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'.
94                                       get_string('oldertopics', 'forum').'</a> ...';
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                 }
105                 if (!isloggedin()) {
106                     $userid = 0;
107                 } else {
108                     $userid = $USER->id;
109                 }
110                 $this->content->footer .= '<br />'.rss_get_link($this->page->course->id, $userid, 'forum', $forum->id, $tooltiptext);
111             }
113         }
115         return $this->content;
116     }