Example #1
0
/**
 * This function is in lib and not in BlogInfo because entries being searched
 * might be found in any number of blogs rather than just one.
 *
 * This function builds an array which can be used by the included
 * template file, making predefined and nicely formatted variables available
 * to the template. Template creators will not need to become intimate
 * with the internal objects and vars of moodle blog nor will they need to worry
 * about properly formatting their data
 *
 *   @param BlogEntry blogEntry - a hopefully fully populated BlogEntry object
 *   @param string viewtype Default is 'full'. If 'full' then display this blog entry
 *     in its complete form (eg. archive page). If anything other than 'full'
 *     display the entry in its abbreviated format (eg. index page)
 */
function blog_print_entry($blogEntry, $viewtype = 'full', $filtertype = '', $filterselect = '', $mode = 'loud')
{
    global $USER, $CFG, $COURSE, $ME;
    $template['body'] = format_text($blogEntry->summary, $blogEntry->format);
    $template['title'] = '<a id=b"' . s($blogEntry->id) . ' /">';
    //enclose the title in nolink tags so that moodle formatting doesn't autolink the text
    $template['title'] .= '<span class="nolink">' . format_string($blogEntry->subject) . '</span>';
    $template['userid'] = $blogEntry->userid;
    $template['author'] = fullname(get_record('user', 'id', $blogEntry->userid));
    $template['created'] = userdate($blogEntry->created);
    if ($blogEntry->created != $blogEntry->lastmodified) {
        $template['lastmod'] = userdate($blogEntry->lastmodified);
    }
    $template['publishstate'] = $blogEntry->publishstate;
    /// preventing user to browse blogs that they aren't supposed to see
    /// This might not be too good since there are multiple calls per page
    /*
            if (!blog_user_can_view_user_post($template['userid'])) {
                error ('you can not view this post');
            }*/
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $user = get_record('user', 'id', $template['userid']);
    /// Start printing of the blog
    echo '<table cellspacing="0" class="forumpost blogpost blog' . $template['publishstate'] . '" width="100%">';
    echo '<tr class="header"><td class="picture left">';
    print_user_picture($user, SITEID, $user->picture);
    echo '</td>';
    echo '<td class="topic starter"><div class="subject">' . $template['title'] . '</div><div class="author">';
    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id)));
    $by = new object();
    $by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $COURSE->id . '">' . $fullname . '</a>';
    $by->date = $template['created'];
    print_string('bynameondate', 'forum', $by);
    echo '</div></td></tr>';
    echo '<tr><td class="left side">';
    /// Actual content
    echo '</td><td class="content">' . "\n";
    if ($blogEntry->attachment) {
        echo '<div class="attachments">';
        $attachedimages = blog_print_attachments($blogEntry);
        echo '</div>';
    } else {
        $attachedimages = '';
    }
    switch ($template['publishstate']) {
        case 'draft':
            $blogtype = get_string('publishtonoone', 'blog');
            break;
        case 'site':
            $blogtype = get_string('publishtosite', 'blog');
            break;
        case 'public':
            $blogtype = get_string('publishtoworld', 'blog');
            break;
        default:
            $blogtype = '';
            break;
    }
    echo '<div class="audience">' . $blogtype . '</div>';
    // Print whole message
    echo $template['body'];
    /// Print attachments
    echo $attachedimages;
    /// Links to tags
    if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_csv('post', $blogEntry->id))) {
        echo '<div class="tags">';
        if ($blogtags) {
            print get_string('tags', 'tag') . ': ' . $blogtags;
        }
        echo '</div>';
    }
    /// Commands
    echo '<div class="commands">';
    if (blog_user_can_edit_post($blogEntry)) {
        echo '<a href="' . $CFG->wwwroot . '/blog/edit.php?action=edit&amp;id=' . $blogEntry->id . '">' . $stredit . '</a>';
        echo '| <a href="' . $CFG->wwwroot . '/blog/edit.php?action=delete&amp;id=' . $blogEntry->id . '">' . $strdelete . '</a> | ';
    }
    echo '<a href="' . $CFG->wwwroot . '/blog/index.php?postid=' . $blogEntry->id . '">' . get_string('permalink', 'blog') . '</a>';
    echo '</div>';
    if (isset($template['lastmod'])) {
        echo '<div style="font-size: 55%;">';
        echo ' [ ' . get_string('modified') . ': ' . $template['lastmod'] . ' ]';
        echo '</div>';
    }
    echo '</td></tr></table>' . "\n\n";
}
Example #2
0
/**
 * This function is in lib and not in BlogInfo because entries being searched
 * might be found in any number of blogs rather than just one.
 *
 * This function builds an array which can be used by the included
 * template file, making predefined and nicely formatted variables available
 * to the template. Template creators will not need to become intimate
 * with the internal objects and vars of moodle blog nor will they need to worry
 * about properly formatting their data
 *
 *   @param BlogEntry blogEntry - a hopefully fully populated BlogEntry object
 *   @param string viewtype Default is 'full'. If 'full' then display this blog entry
 *     in its complete form (eg. archive page). If anything other than 'full'
 *     display the entry in its abbreviated format (eg. index page)
 */
function blog_print_entry($blogEntry, $viewtype = 'full', $filtertype = '', $filterselect = '', $mode = 'loud')
{
    global $USER, $CFG, $COURSE, $ME;
    $template['body'] = format_text($blogEntry->summary, $blogEntry->format);
    //$template['title'] = '<a name="'. $blogEntry->subject .'"></a>';
    //enclose the title in nolink tags so that moodle formatting doesn't autolink the text
    $template['title'] = '<span class="nolink">' . $blogEntry->subject . '</span>';
    $template['userid'] = $blogEntry->userid;
    $template['author'] = fullname(get_record('user', 'id', $blogEntry->userid));
    $template['lastmod'] = userdate($blogEntry->lastmodified);
    $template['created'] = userdate($blogEntry->created);
    $template['publishstate'] = $blogEntry->publishstate;
    /// preventing user to browse blogs that they aren't supposed to see
    /// This might not be too good since there are multiple calls per page
    /*
            if (!blog_user_can_view_user_post($template['userid'])) {
                error ('you can not view this post');
            }*/
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $user = get_record('user', 'id', $template['userid']);
    /// Start printing of the blog
    echo '<table cellspacing="0" class="forumpost blogpost blog' . $template['publishstate'] . '" width="100%">';
    echo '<tr class="header"><td class="picture left">';
    print_user_picture($template['userid'], SITEID, $user->picture);
    echo '</td>';
    echo '<td class="topic starter"><div class="subject">' . $template['title'] . '</div><div class="author">';
    $fullname = fullname($user, $template['userid']);
    $by = new object();
    $by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $COURSE->id . '">' . $fullname . '</a>';
    $by->date = $template['lastmod'];
    print_string('bynameondate', 'forum', $by);
    echo '</div></td></tr>';
    echo '<tr><td class="left side">';
    /// Actual content
    echo '</td><td class="content">' . "\n";
    if ($blogEntry->attachment) {
        echo '<div class="attachments">';
        $attachedimages = blog_print_attachments($blogEntry);
        echo '</div>';
    } else {
        $attachedimages = '';
    }
    switch ($template['publishstate']) {
        case 'draft':
            $blogtype = get_string('publishtonoone', 'blog');
            break;
        case 'site':
            $blogtype = get_string('publishtosite', 'blog');
            break;
        case 'public':
            $blogtype = get_string('publishtoworld', 'blog');
            break;
        default:
            $blogtype = '';
            break;
    }
    echo '<div class="audience">' . $blogtype . '</div>';
    // Print whole message
    echo format_text($template['body']);
    /// Print attachments
    echo $attachedimages;
    /// Links to tags
    /*
    if ($blogtags = get_records_sql('SELECT t.* FROM '.$CFG->prefix.'tags t, '.$CFG->prefix.'blog_tag_instance ti
                                 WHERE t.id = ti.tagid
                                 AND ti.entryid = '.$blogEntry->id)) {
    */
    if (!empty($CFG->usetags) && ($blogtags = get_item_tags('blog', $blogEntry->id))) {
        echo '<div class="tags">';
        if ($blogtags) {
            print_string('tags');
            echo ': ';
            foreach ($blogtags as $key => $blogtag) {
                //$taglist[] = '<a href="index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;tagid='.$blogtag->id.'">'.tag_display_name($blogtag).'</a>';  // Blog tag only
                $taglist[] = '<a href="' . $CFG->wwwroot . '/tag/index.php?id=' . $blogtag->id . '">' . tag_display_name($blogtag) . '</a>';
                // General tag link
            }
            echo implode(', ', $taglist);
        }
        echo '</div>';
    }
    /// Commands
    echo '<div class="commands">';
    if (blog_user_can_edit_post($blogEntry)) {
        echo '<a href="' . $CFG->wwwroot . '/blog/edit.php?action=edit&amp;id=' . $blogEntry->id . '">' . $stredit . '</a>';
        echo '| <a href="' . $CFG->wwwroot . '/blog/edit.php?action=delete&amp;id=' . $blogEntry->id . '">' . $strdelete . '</a>';
    }
    echo '</div>';
    echo '</td></tr></table>' . "\n\n";
}