/** * Given a course and a date, prints a summary of all the new * messages posted in the course since that date * * @global object * @global object * @global object * @uses CONTEXT_MODULE * @uses VISIBLEGROUPS * @param object $course * @param bool $viewfullnames capability * @param int $timestart * @return bool success */ function forum_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; // do not use log table if possible, it may be huge and is expensive to join with other tables if (!$posts = $DB->get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid, d.timestart, d.timeend, d.userid AS duserid, u.firstname, u.lastname, u.email, u.picture FROM {forum_posts} p JOIN {forum_discussions} d ON d.id = p.discussion JOIN {forum} f ON f.id = d.forum JOIN {user} u ON u.id = p.userid WHERE p.created > ? AND f.course = ? ORDER BY p.id ASC", array($timestart, $course->id))) { // order by initial posting date return false; } $modinfo = get_fast_modinfo($course); $groupmodes = array(); $cms = array(); $strftimerecent = get_string('strftimerecent'); $printposts = array(); foreach ($posts as $post) { if (!isset($modinfo->instances['forum'][$post->forum])) { // not visible continue; } $cm = $modinfo->instances['forum'][$post->forum]; if (!$cm->uservisible) { continue; } $context = context_module::instance($cm->id); if (!has_capability('mod/forum:viewdiscussion', $context)) { continue; } if (!empty($CFG->forum_enabletimedposts) and $USER->id != $post->duserid and (($post->timestart > 0 and $post->timestart > time()) or ($post->timeend > 0 and $post->timeend < time()))) { if (!has_capability('mod/forum:viewhiddentimedposts', $context)) { continue; } } $groupmode = groups_get_activity_groupmode($cm, $course); if ($groupmode) { if ($post->groupid == -1 or $groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) { // oki (Open discussions have groupid -1) } else { // separate mode if (isguestuser()) { // shortcut continue; } if (is_null($modinfo->groups)) { $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo } if (!array_key_exists($post->groupid, $modinfo->groups[0])) { continue; } } } $printposts[] = $post; } unset($posts); if (!$printposts) { return false; } echo $OUTPUT->heading(get_string('newforumposts', 'forum').':', 3); echo "\n<ul class='unlist'>\n"; foreach ($printposts as $post) { $subjectclass = empty($post->parent) ? ' bold' : ''; echo '<li><div class="head">'. '<div class="date">'.userdate($post->modified, $strftimerecent).'</div>'. '<div class="name">'.fullname($post, $viewfullnames).'</div>'. '</div>'; echo '<div class="info'.$subjectclass.'">'; if (empty($post->parent)) { echo '"<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">'; } else { echo '"<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'&parent='.$post->parent.'#p'.$post->id.'">'; } $post->subject = break_up_long_words(format_string($post->subject, true)); echo $post->subject; echo "</a>\"</div></li>\n"; } echo "</ul>\n"; return true; }
/** * Returns the html list item of a feed item * * @param mixed item simplepie_item representing the feed item * @return string html li representing the rss feed item */ function get_item_html($item) { $link = $item->get_link(); $title = $item->get_title(); $description = $item->get_description(); if (empty($title)) { // no title present, use portion of description $title = textlib::substr(strip_tags($description), 0, 20) . '...'; } else { $title = break_up_long_words($title, 30); } if (empty($link)) { $link = $item->get_id(); } else { try { // URLs in our RSS cache will be escaped (correctly as theyre store in XML) // html_writer::link() will re-escape them. To prevent double escaping unescape here. // This can by done using htmlspecialchars_decode() but moodle_url also has that effect. $link = new moodle_url($link); } catch (moodle_exception $e) { // Catching the exception to prevent the whole site to crash in case of malformed RSS feed $link = ''; } } $r = html_writer::start_tag('li'); $r .= html_writer::start_tag('div', array('class' => 'link')); $r .= html_writer::link($link, s($title), array('onclick' => 'this.target="_blank"')); $r .= html_writer::end_tag('div'); if ($this->config->display_description && !empty($description)) { $formatoptions = new stdClass(); $formatoptions->para = false; $r .= html_writer::start_tag('div', array('class' => 'description')); $description = format_text($description, FORMAT_HTML, $formatoptions, $this->page->course->id); $description = break_up_long_words($description, 30); $r .= $description; $r .= html_writer::end_tag('div'); } $r .= html_writer::end_tag('li'); return $r; }
/** * Given a course and a date, prints a summary of all the new * messages posted in the course since that date * * @global object * @global object * @global object * @uses CONTEXT_MODULE * @uses VISIBLEGROUPS * @param object $course * @param bool $viewfullnames capability * @param int $timestart * @return bool success */ function forum_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; // do not use log table if possible, it may be huge and is expensive to join with other tables $allnamefields = user_picture::fields('u', null, 'duserid'); if (!($posts = $DB->get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,\n d.timestart, d.timeend, {$allnamefields}\n FROM {forum_posts} p\n JOIN {forum_discussions} d ON d.id = p.discussion\n JOIN {forum} f ON f.id = d.forum\n JOIN {user} u ON u.id = p.userid\n WHERE p.created > ? AND f.course = ?\n ORDER BY p.id ASC", array($timestart, $course->id)))) { // order by initial posting date return false; } $modinfo = get_fast_modinfo($course); $groupmodes = array(); $cms = array(); $strftimerecent = get_string('strftimerecent'); $printposts = array(); foreach ($posts as $post) { if (!isset($modinfo->instances['forum'][$post->forum])) { // not visible continue; } $cm = $modinfo->instances['forum'][$post->forum]; if (!$cm->uservisible) { continue; } $context = context_module::instance($cm->id); if (!has_capability('mod/forum:viewdiscussion', $context)) { continue; } if (!empty($CFG->forum_enabletimedposts) and $USER->id != $post->duserid and ($post->timestart > 0 and $post->timestart > time() or $post->timeend > 0 and $post->timeend < time())) { if (!has_capability('mod/forum:viewhiddentimedposts', $context)) { continue; } } // Check that the user can see the discussion. if (forum_is_user_group_discussion($cm, $post->groupid)) { $printposts[] = $post; } } unset($posts); if (!$printposts) { return false; } echo $OUTPUT->heading(get_string('newforumposts', 'forum') . ':', 3); echo "\n<ul class='unlist'>\n"; foreach ($printposts as $post) { $subjectclass = empty($post->parent) ? ' bold' : ''; echo '<li><div class="head">' . '<div class="date">' . userdate($post->modified, $strftimerecent) . '</div>' . '<div class="name">' . fullname($post, $viewfullnames) . '</div>' . '</div>'; echo '<div class="info' . $subjectclass . '">'; if (empty($post->parent)) { echo '"<a href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '">'; } else { echo '"<a href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '&parent=' . $post->parent . '#p' . $post->id . '">'; } $post->subject = break_up_long_words(format_string($post->subject, true)); echo $post->subject; echo "</a>\"</div></li>\n"; } echo "</ul>\n"; return true; }
/** * Returns the html list item of a feed item * * @param mixed item simplepie_item representing the feed item * @return string html li representing the rss feed item */ function get_item_html($item) { $link = $item->get_link(); $title = $item->get_title(); $description = $item->get_description(); if (empty($title)) { // no title present, use portion of description $title = substr(strip_tags($description), 0, 20) . '...'; } else { $title = break_up_long_words($title, 30); } if (empty($link)) { $link = $item->get_id(); } $r = html_writer::start_tag('li'); $r .= html_writer::start_tag('div', array('class' => 'link')); $r .= html_writer::link(clean_param($link, PARAM_URL), s($title), array('onclick' => 'this.target="_blank"')); $r .= html_writer::end_tag('div'); if ($this->config->display_description && !empty($description)) { $description = break_up_long_words($description, 30); $formatoptions = new stdClass(); $formatoptions->para = false; $r .= html_writer::start_tag('div', array('class' => 'description')); $r .= format_text($description, FORMAT_HTML, $formatoptions, $this->page->course->id); $r .= html_writer::end_tag('div'); } $r .= html_writer::end_tag('li'); return $r; }
/** * Given a course and a date, prints a summary of all the new * messages posted in the course since that date * * @global object * @global object * @global object * @uses CONTEXT_MODULE * @uses VISIBLEGROUPS * @param object $course * @param bool $viewfullnames capability * @param int $timestart * @return bool success */ function forum_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; // do not use log table if possible, it may be huge and is expensive to join with other tables $allnamefields = user_picture::fields('u', null, 'duserid'); if (!($posts = $DB->get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,\n d.timestart, d.timeend, {$allnamefields}\n FROM {forum_posts} p\n JOIN {forum_discussions} d ON d.id = p.discussion\n JOIN {forum} f ON f.id = d.forum\n JOIN {user} u ON u.id = p.userid\n WHERE p.created > ? AND f.course = ?\n ORDER BY p.id ASC", array($timestart, $course->id)))) { // order by initial posting date return false; } $modinfo = get_fast_modinfo($course); $groupmodes = array(); $cms = array(); $strftimerecent = get_string('strftimerecent'); $printposts = array(); foreach ($posts as $post) { if (!isset($modinfo->instances['forum'][$post->forum])) { // not visible continue; } $cm = $modinfo->instances['forum'][$post->forum]; if (!$cm->uservisible) { continue; } $context = context_module::instance($cm->id); if (!has_capability('mod/forum:viewdiscussion', $context)) { continue; } if (!empty($CFG->forum_enabletimedposts) and $USER->id != $post->duserid and ($post->timestart > 0 and $post->timestart > time() or $post->timeend > 0 and $post->timeend < time())) { if (!has_capability('mod/forum:viewhiddentimedposts', $context)) { continue; } } // Check that the user can see the discussion. if (forum_is_user_group_discussion($cm, $post->groupid)) { $printposts[] = $post; } } unset($posts); if (!$printposts) { return false; } echo $OUTPUT->heading(get_string('newforumposts', 'forum') . ':', 3); $list = html_writer::start_tag('ul', ['class' => 'unlist']); foreach ($printposts as $post) { $subjectclass = empty($post->parent) ? ' bold' : ''; $authorhidden = forum_is_author_hidden($post, (object) ['type' => $post->forumtype]); $list .= html_writer::start_tag('li'); $list .= html_writer::start_div('head'); $list .= html_writer::div(userdate($post->modified, $strftimerecent), 'date'); if (!$authorhidden) { $list .= html_writer::div(fullname($post, $viewfullnames), 'name'); } $list .= html_writer::end_div(); // Head. $list .= html_writer::start_div('info' . $subjectclass); $discussionurl = new moodle_url('/mod/forum/discuss.php', ['d' => $post->discussion]); if (!empty($post->parent)) { $discussionurl->param('parent', $post->parent); $discussionurl->set_anchor('p' . $post->id); } $post->subject = break_up_long_words(format_string($post->subject, true)); $list .= html_writer::link($discussionurl, $post->subject); $list .= html_writer::end_div(); // Info. $list .= html_writer::end_tag('li'); } $list .= html_writer::end_tag('ul'); echo $list; return true; }
/** * @param int $rssid The feed to be displayed * @param bool $display_description Should the description information from the feed be displayed or simply the title? * @param int $shownumentries The maximum number of feed entries to be displayed. * @param bool $showtitle True if the feed title should be displayed above the feed entries. * @return string|NULL */ function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle = false) { global $CFG; $returnstring = ''; $now = time(); require_once $CFG->libdir . '/rsslib.php'; require_once MAGPIE_DIR . 'rss_fetch.inc'; if (!defined('MAGPIE_OUTPUT_ENCODING')) { define('MAGPIE_OUTPUT_ENCODING', 'utf-8'); // see bug 3107 } $rss_record = get_record('block_rss_client', 'id', $rssid); if (isset($rss_record) && isset($rss_record->id)) { // By capturing the output from fetch_rss this way // error messages do not display and clutter up the moodle interface // however, we do lose out on seeing helpful messages like "cache hit", etc. ob_start(); $rss = fetch_rss($rss_record->url); $rsserror = ob_get_contents(); ob_end_clean(); if ($rss === false) { if (debugging() && !empty($rsserror)) { // There was a failure in loading the rss feed, print link to full error text return '<a href="' . $CFG->wwwroot . '/blocks/rss_client/block_rss_client_error.php?error=' . urlencode($rsserror) . '">Error loading a feed.</a><br />'; //Daryl Hawes note: localize this line } } // first we must verify that the rss feed is loaded // by checking $rss and $rss->items exist before using them if (empty($rss) || empty($rss->items)) { return ''; } if ($shownumentries > 0 && $shownumentries < count($rss->items)) { $rss->items = array_slice($rss->items, 0, $shownumentries); } if (empty($rss_record->preferredtitle)) { if (isset($rss->channel['title'])) { // Just in case feed is dead $feedtitle = $this->format_title($rss->channel['title']); } else { $feedtitle = ''; } } else { $feedtitle = $this->format_title($rss_record->preferredtitle); } if (isset($this->config) && isset($this->config->block_rss_client_show_channel_image) && $this->config->block_rss_client_show_channel_image && isset($rss->image) && isset($rss->image['link']) && isset($rss->image['title']) && isset($rss->image['url'])) { $rss->image['title'] = s($rss->image['title']); $returnstring .= "\n" . '<div class="image" title="' . $rss->image['title'] . '"><a href="' . $rss->image['link'] . '"><img src="' . $rss->image['url'] . '" alt="' . $rss->image['title'] . '" /></a></div>'; } if ($showtitle) { $returnstring .= '<div class="title">' . $feedtitle . '</div>'; } $formatoptions->para = false; /// Accessibility: markup as a list. $returnstring .= '<ul class="list">' . "\n"; foreach ($rss->items as $item) { if ($item['title'] == '') { // no title present, use portion of description $item['title'] = substr(strip_tags($item['description']), 0, 20) . '...'; } else { $item['title'] = break_up_long_words($item['title'], 30); } if ($item['link'] == '') { $item['link'] = $item['guid']; } $item['title'] = s($item['title']); $item['link'] = str_replace('&', '&', $item['link']); $returnstring .= '<li><div class="link"><a href="' . $item['link'] . '" onclick="this.target=\'_blank\'" >' . $item['title'] . "</a></div>\n"; if ($display_description && !empty($item['description'])) { $item['description'] = break_up_long_words($item['description'], 30); $returnstring .= '<div class="description">' . format_text($item['description'], FORMAT_MOODLE, $formatoptions, $this->courseid) . '</div>'; } $returnstring .= "</li>\n"; } $returnstring .= "</ul>\n"; if (!empty($rss->channel['link'])) { $rss->channel['link'] = str_replace('&', '&', $rss->channel['link']); if (!empty($this->config) && isset($this->config->block_rss_client_show_channel_link) && $this->config->block_rss_client_show_channel_link) { $this->content->footer = '<a href="' . $rss->channel['link'] . '">' . get_string('clientchannellink', 'block_rss_client') . '</a>'; } if (!empty($feedtitle)) { $feedtitle = '<a href="' . $rss->channel['link'] . '">' . $feedtitle . '</a>'; } } } // if block has no custom title if (empty($this->config) || !empty($this->config) && empty($this->config->title)) { // if the feed has a title if (!empty($feedtitle) and $feedtitle != '<a href="' . $rss->channel['link'] . '"></a>') { // set the block's title to the feed's title $this->title = strip_tags($feedtitle); } } return $returnstring; }
/** * Format an RSS item description * * @param string $description * @return string */ public function format_description($description) { $description = format_text($description, FORMAT_HTML, array('para' => false)); $description = break_up_long_words($description, 30); return $description; }
/** * Given a course and a date, prints a summary of all the new * messages posted in the course since that date */ function forum_print_recent_activity($course, $isteacher, $timestart) { global $CFG; $LIKE = sql_ilike(); $heading = false; $content = false; if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'forum\' AND ' . 'action ' . $LIKE . ' \'add %\' ', 'time ASC'))) { return false; } $strftimerecent = get_string('strftimerecent'); $mygroupid = mygroupid($course->id); $groupmode = array(); // To cache group modes $count = 0; foreach ($logs as $log) { //Get post info, I'll need it later if ($post = forum_get_post_from_log($log)) { //Create a temp valid module structure (course,id) $tempmod = new object(); $tempmod->course = $log->course; $tempmod->id = $post->forum; //Obtain the visible property from the instance $coursecontext = get_context_instance(CONTEXT_COURSE, $tempmod->course); $modvisible = instance_is_visible('forum', $tempmod) || has_capability('moodle/course:viewhiddenactivities', $coursecontext); } //Only if the post exists and mod is visible if ($post && $modvisible) { if (!isset($cm[$post->forum])) { $cm[$post->forum] = get_coursemodule_from_instance('forum', $post->forum, $course->id); } $modcontext = get_context_instance(CONTEXT_MODULE, $cm[$post->forum]->id); // Check whether this is belongs to a discussion in a group that // should NOT be accessible to the current user if (!has_capability('moodle/site:accessallgroups', $modcontext) && $post->groupid != -1) { // Open discussions have groupid -1 $groupmode[$post->forum] = groups_get_activity_groupmode($cm[$post->forum]); if ($groupmode[$post->forum]) { //hope i didn't break anything if (!@in_array($mygroupid, $post->groupid)) { continue; } } } if (!$heading) { print_headline(get_string('newforumposts', 'forum') . ':', 3); $heading = true; $content = true; } $date = userdate($post->modified, $strftimerecent); $subjectclass = $log->action == 'add discussion' ? ' bold' : ''; //Accessibility: markup as a list. if ($count < 1) { echo "\n<ul class='unlist'>\n"; } $count++; echo '<li><div class="head">' . '<div class="date">' . $date . '</div>' . '<div class="name">' . fullname($post, has_capability('moodle/site:viewfullnames', $coursecontext)) . '</div>' . '</div>'; echo '<div class="info' . $subjectclass . '">'; echo '"<a href="' . $CFG->wwwroot . '/mod/forum/' . str_replace('&', '&', $log->url) . '">'; $post->subject = break_up_long_words(format_string($post->subject, true)); echo $post->subject; echo "</a>\"</div></li>\n"; } } echo "</ul>\n"; return $content; }
/** * Given a course and a date, prints a summary of all the new * messages posted in the course since that date as HTML media objects * * @global object $CFG * @global object $USER * @global object $DB * @global object $OUTPUT * @uses CONTEXT_MODULE * @uses VISIBLEGROUPS * @param object $course * @param bool $viewfullnames capability * @param int $timestart * @return string recent activity */ function hsuforum_recent_activity($course, $viewfullnames, $timestart, $forumid = null) { global $CFG, $USER, $DB, $OUTPUT; $limitfrom = 0; $limitnum = 0; $andforumid = ''; if ($forumid !== null) { $andforumid = 'AND d.forum = ?'; $limitnum = 6; } $allnamefields = user_picture::fields('u', null, 'duserid'); $sql = "SELECT p.*, f.anonymous as forumanonymous, f.type AS forumtype,\n d.forum, d.groupid, d.timestart, d.timeend, {$allnamefields}\n FROM {hsuforum_posts} p\n JOIN {hsuforum_discussions} d ON d.id = p.discussion\n JOIN {hsuforum} f ON f.id = d.forum\n JOIN {user} u ON u.id = p.userid\n WHERE p.created > ?\n AND f.course = ?\n AND (p.privatereply = 0 OR p.privatereply = ? OR p.userid = ?)\n {$andforumid}\n ORDER BY p.created DESC\n "; $params = array($timestart, $course->id, $USER->id, $USER->id, $forumid); if (!($posts = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum))) { return ''; } $modinfo = get_fast_modinfo($course); $config = get_config('hsuforum'); $groupmodes = array(); $cms = array(); $out = ''; foreach ($posts as $post) { if (!isset($modinfo->instances['hsuforum'][$post->forum])) { // not visible continue; } $cm = $modinfo->instances['hsuforum'][$post->forum]; if (!$cm->uservisible) { continue; } $context = context_module::instance($cm->id); if (!has_capability('mod/hsuforum:viewdiscussion', $context)) { continue; } if (!empty($config->enabletimedposts) and $USER->id != $post->duserid and ($post->timestart > 0 and $post->timestart > time() or $post->timeend > 0 and $post->timeend < time())) { if (!has_capability('mod/hsuforum:viewhiddentimedposts', $context)) { continue; } } // Check that the user can see the discussion. if (hsuforum_is_user_group_discussion($cm, $post->groupid)) { $postuser = hsuforum_extract_postuser($post, hsuforum_get_cm_forum($cm), context_module::instance($cm->id)); $userpicture = new user_picture($postuser); $userpicture->link = false; $userpicture->alttext = false; $userpicture->size = 100; $picture = $OUTPUT->render($userpicture); $url = $CFG->wwwroot . '/mod/hsuforum/discuss.php?d=' . $post->discussion; if (!empty($post->parent)) { $url .= '#p' . $post->id; } $postusername = fullname($postuser, $viewfullnames); $postsubject = break_up_long_words(format_string($post->subject, true)); $posttime = hsuforum_relative_time($post->modified); $out .= hsuforum_media_object($url, $picture, $postusername, $posttime, $postsubject); } } if ($out) { $out = "<h3 class='hsuforum-recent-heading'>" . get_string('newforumposts', 'hsuforum') . "</h3>" . $out; } return $out; }
/** * Given a course and a time, this module should find recent activity * that has occurred in newmodule activities and print it out. * Return true if there was output, or false is there was none. * * @param object $course * @param bool $isteacher * @param int $timestart * @return boolean true on success, false on failure. **/ function oublog_print_recent_activity($course, $isteacher, $timestart) { global $CFG, $DB, $OUTPUT; include_once 'locallib.php'; $sql = "SELECT i.oublogid, p.id AS postid, p.*, u.firstname, u.lastname, u.email, u.idnumber, i.userid\n FROM {oublog_posts} p\n INNER JOIN {oublog_instances} i ON p.oubloginstancesid = i.id\n INNER JOIN {oublog} b ON i.oublogid = b.id\n INNER JOIN {user} u ON i.userid = u.id\n WHERE b.course = ? AND p.deletedby IS NULL AND p.timeposted >= ? "; if (!($rs = $DB->get_recordset_sql($sql, array($course->id, $timestart)))) { return true; } $modinfo = get_fast_modinfo($course); $strftimerecent = get_string('strftimerecent'); echo $OUTPUT->heading(get_string('newblogposts', 'oublog'), 3); echo "\n<ul class='unlist'>\n"; foreach ($rs as $blog) { if (!isset($modinfo->instances['oublog'][$blog->oublogid])) { // not visible continue; } $cm = $modinfo->instances['oublog'][$blog->oublogid]; if (!$cm->uservisible) { continue; } if (!has_capability('mod/oublog:view', context_module::instance($cm->id))) { continue; } if (!has_capability('mod/oublog:view', context_user::instance($blog->userid))) { continue; } $groupmode = oublog_get_activity_groupmode($cm, $course); if ($groupmode) { if ($blog->groupid && $groupmode != VISIBLEGROUPS) { // separate mode if (isguestuser()) { // shortcut continue; } if (is_null($modinfo->groups)) { $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo } if (!array_key_exists($blog->groupid, $modinfo->groups[0])) { continue; } } } echo '<li><div class="head">' . '<div class="date">' . oublog_date($blog->timeposted, $strftimerecent) . '</div>' . '<div class="name">' . fullname($blog) . '</div>' . '</div>'; echo '<div class="info">'; echo "<a href=\"{$CFG->wwwroot}/mod/oublog/viewpost.php?post={$blog->postid}\">"; echo break_up_long_words(format_string(empty($blog->title) ? $blog->message : $blog->title)); echo '</a>'; echo '</div>'; } $rs->close(); echo "</ul>\n"; }
/** * Returns the html list item of a feed item * * @param mixed item simplepie_item representing the feed item * @return string html li representing the rss feed item */ function get_item_html($item) { $link = $item->get_link(); $title = $item->get_title(); $description = $item->get_description(); if (empty($title)) { // no title present, use portion of description $title = substr(strip_tags($description), 0, 20) . '...'; } else { $title = break_up_long_words($title, 30); } if (empty($link)) { $link = $item->get_id(); } $r = "<li>\n"; $r .= '<div class="link"><a href="' . $link . '" onclick="this.target=\'_blank\'" >' . "\n"; $r .= s($title); $r .= "</a></div>\n"; if ($this->config->display_description && !empty($description)) { $description = break_up_long_words($description, 30); $formatoptions = new object(); $formatoptions->para = false; $r .= '<div class="description">'; $r .= format_text($description, FORMAT_HTML, $formatoptions, $this->page->course->id); $r .= '</div>'; } $r .= '</li>'; return $r; }
/** * Returns the html list item of a feed item * * @param mixed item simplepie_item representing the feed item * @return string html li representing the rss feed item */ function get_item_html($item) { $link = $item->get_link(); $title = $item->get_title(); $description = $item->get_description(); if (empty($title)) { // no title present, use portion of description $title = textlib::substr(strip_tags($description), 0, 20) . '...'; } else { $title = break_up_long_words($title, 30); } if (empty($link)) { $link = $item->get_id(); } else { //URLs in our RSS cache will be escaped (correctly as theyre store in XML) //html_writer::link() will re-escape them. To prevent double escaping unescape here. //This can by done using htmlspecialchars_decode() but moodle_url also has that effect $link = new moodle_url($link); } $r = html_writer::start_tag('li'); $r .= html_writer::start_tag('div', array('class' => 'rsslink')); $r .= html_writer::link(clean_param($link, PARAM_URL), s($title), array('onclick' => 'this.target="_blank"')); $r .= html_writer::end_tag('div'); $description = break_up_long_words($description, 30); $description = textlib::substr(strip_tags($description), 0, 255) . ''; $formatoptions = new stdClass(); $formatoptions->para = false; $r .= html_writer::start_tag('div', array('class' => 'rssdescription')); $r .= format_text($description, FORMAT_HTML, $formatoptions, $this->page->course->id); $r .= html_writer::end_tag('div'); $r .= html_writer::start_tag('div', array('class' => 'rssimage')); /** * Gets the thumbnail from the RSS feed. * Currently works best with BBC news feeds * with little success on others. * Need help on this bit. * */ if ($enclosure = $item->get_enclosure()) { foreach ((array) $enclosure->get_thumbnail(1) as $thumbnail) { $r .= '<img src="' . $thumbnail . '"/>' . "\n"; } } $r .= html_writer::end_tag('div'); $r .= html_writer::end_tag('li'); return $r; }