|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 class block_news_items extends block_base { 00004 function init() { 00005 $this->title = get_string('pluginname', 'block_news_items'); 00006 } 00007 00008 function get_content() { 00009 global $CFG, $USER; 00010 00011 if ($this->content !== NULL) { 00012 return $this->content; 00013 } 00014 00015 $this->content = new stdClass; 00016 $this->content->text = ''; 00017 $this->content->footer = ''; 00018 00019 if (empty($this->instance)) { 00020 return $this->content; 00021 } 00022 00023 00024 if ($this->page->course->newsitems) { // Create a nice listing of recent postings 00025 00026 require_once($CFG->dirroot.'/mod/forum/lib.php'); // We'll need this 00027 00028 $text = ''; 00029 00030 if (!$forum = forum_get_course_forum($this->page->course->id, 'news')) { 00031 return ''; 00032 } 00033 00034 $modinfo = get_fast_modinfo($this->page->course); 00035 if (empty($modinfo->instances['forum'][$forum->id])) { 00036 return ''; 00037 } 00038 $cm = $modinfo->instances['forum'][$forum->id]; 00039 00040 if (!$cm->uservisible) { 00041 return ''; 00042 } 00043 00044 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00045 00047 if (!has_capability('mod/forum:viewdiscussion', $context)) { 00048 return ''; 00049 } 00050 00052 $groupmode = groups_get_activity_groupmode($cm); 00053 $currentgroup = groups_get_activity_group($cm, true); 00054 00055 00056 if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context)) { 00057 $text .= '<div class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'. 00058 get_string('addanewtopic', 'forum').'</a>...</div>'; 00059 } 00060 00062 00063 if (! $discussions = forum_get_discussions($cm, 'p.modified DESC', false, 00064 $currentgroup, $this->page->course->newsitems) ) { 00065 $text .= '('.get_string('nonews', 'forum').')'; 00066 $this->content->text = $text; 00067 return $this->content; 00068 } 00069 00071 00072 $strftimerecent = get_string('strftimerecent'); 00073 $strmore = get_string('more', 'forum'); 00074 00076 $text .= "\n<ul class='unlist'>\n"; 00077 foreach ($discussions as $discussion) { 00078 00079 $discussion->subject = $discussion->name; 00080 00081 $discussion->subject = format_string($discussion->subject, true, $forum->course); 00082 00083 $text .= '<li class="post">'. 00084 '<div class="head clearfix">'. 00085 '<div class="date">'.userdate($discussion->modified, $strftimerecent).'</div>'. 00086 '<div class="name">'.fullname($discussion).'</div></div>'. 00087 '<div class="info">'.$discussion->subject.' '. 00088 '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->discussion.'">'. 00089 $strmore.'...</a></div>'. 00090 "</li>\n"; 00091 } 00092 $text .= "</ul>\n"; 00093 00094 $this->content->text = $text; 00095 00096 $this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'">'. 00097 get_string('oldertopics', 'forum').'</a> ...'; 00098 00100 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) && 00101 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype && $forum->rssarticles) { 00102 require_once($CFG->dirroot.'/lib/rsslib.php'); // We'll need this 00103 if ($forum->rsstype == 1) { 00104 $tooltiptext = get_string('rsssubscriberssdiscussions','forum'); 00105 } else { 00106 $tooltiptext = get_string('rsssubscriberssposts','forum'); 00107 } 00108 if (!isloggedin()) { 00109 $userid = 0; 00110 } else { 00111 $userid = $USER->id; 00112 } 00113 00114 $this->content->footer .= '<br />'.rss_get_link($context->id, $userid, 'mod_forum', $forum->id, $tooltiptext); 00115 } 00116 00117 } 00118 00119 return $this->content; 00120 } 00121 } 00122 00123