Beispiel #1
0
/**
 * Returns the SQL text to be used to compare one TEXT (clob) column with
 * one varchar column, because some RDBMS doesn't support such direct
 * comparisons.
 * @param string fieldname the name of the TEXT field we need to order by
 * @param string number of chars to use for the ordering (defaults to 32)
 * @return string the piece of SQL code to be used in your statement.
 */
function sql_compare_text($fieldname, $numchars = 32)
{
    return sql_order_by_text($fieldname, $numchars);
}
/**
 * @param int $courseid The id of the course the user is currently viewing
 * @param int $userid We need this to know which feeds the user is allowed to manage
 * @param int $rssid If present the rss entry matching this id alone will be displayed
 *            as long as the user is allowed to manage this feed
 * @param object $context we need the context object to check what the user is allowed to do.
 */
function rss_display_feeds($courseid, $userid, $rssid = '', $context)
{
    global $db, $USER, $CFG;
    global $blogid;
    //hackish, but if there is a blogid it would be good to preserve it
    require_once $CFG->libdir . '/tablelib.php';
    $select = '';
    $managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
    $manageownfeeds = has_capability('block/rss_client:manageownfeeds', $context);
    if ($rssid != '') {
        $select = 'id = ' . $rssid . ' AND ';
    }
    if ($managesharedfeeds) {
        $select .= '(userid = ' . $userid . ' OR shared = 1)';
    } else {
        if ($manageownfeeds) {
            $select .= 'userid = ' . $userid;
        }
    }
    $table = new flexible_table('rss-display-feeds');
    $table->define_columns(array('feed', 'actions'));
    $table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
    $table->set_attribute('cellspacing', '0');
    $table->set_attribute('id', 'rssfeeds');
    $table->set_attribute('class', 'generaltable generalbox');
    $table->column_class('feed', 'feed');
    $table->column_class('actions', 'actions');
    $table->setup();
    $feeds = get_records_select('block_rss_client', $select, sql_order_by_text('title'));
    if (!empty($feeds)) {
        foreach ($feeds as $feed) {
            if (!empty($feed->preferredtitle)) {
                $feedtitle = stripslashes_safe($feed->preferredtitle);
            } else {
                $feedtitle = stripslashes_safe($feed->title);
            }
            if ($feed->userid == $USER->id && $manageownfeeds || $feed->shared && $managesharedfeeds) {
                $feedicons = '<a href="' . $CFG->wwwroot . '/blocks/rss_client/block_rss_client_action.php?id=' . $courseid . '&amp;act=rssedit&amp;rssid=' . $feed->id . '&amp;shared=' . $feed->shared . '&amp;blogid=' . $blogid . '">' . '<img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>&nbsp;' . '<a href="' . $CFG->wwwroot . '/blocks/rss_client/block_rss_client_action.php?id=' . $courseid . '&amp;act=delfeed&amp;sesskey=' . sesskey() . '&amp;rssid=' . $feed->id . '&amp;shared=' . $feed->shared . 'blogid=' . $blogid . '"
                onclick="return confirm(\'' . get_string('deletefeedconfirm', 'block_rss_client') . '\');">' . '<img src="' . $CFG->pixpath . '/t/delete.gif" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>';
            } else {
                $feedicons = '';
            }
            $feedinfo = '
    <div class="title">
        <a href="' . $CFG->wwwroot . '/blocks/rss_client/block_rss_client_action.php?id=' . $courseid . '&amp;act=view&amp;rssid=' . $feed->id . '&amp;blogid=' . $blogid . '">
        ' . $feedtitle . '</a>
    </div>
    <div class="url">
        <a href="' . $feed->url . '">' . $feed->url . '</a>
    </div>
    <div class="description">' . $feed->description . '</div>';
            $table->add_data(array($feedinfo, $feedicons));
        }
    }
    $table->print_html();
}