function test_set_formats()
 {
     $button = new portfolio_add_button();
     $button->set_callback_options('assignment_portfolio_caller', array('id' => 6), '/mod/assignment/lib.php');
     $formats = array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_IMAGE);
     $button->set_formats($formats);
     $this->assertEqual(2, count($button->get_formats()));
 }
Example #2
0
 public function apply($discussion, $all, $selected, $formdata)
 {
     global $COURSE, $USER, $CFG;
     if (!$CFG->enableportfolios) {
         return '';
     }
     /*
      * It is necessary to encode the array of selected discussion posts as text in order to
      * pass the data in the button callback options because it gets filtered as PARAM_ALPHA
      */
     if (is_array($selected) && !empty($selected)) {
         $seltext = implode('x', $selected);
         $letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');
         $posts = '';
         $selarray = str_split($seltext);
         foreach ($selarray as $char) {
             $posts .= $char == 'x' ? $char : $letters[$char];
         }
     } else {
         $posts = '';
     }
     // get the id of the forum
     $forumobj = $discussion->get_forum();
     $forumngid = $forumobj->get_id();
     require_once $CFG->libdir . '/portfoliolib.php';
     // check if the forum is shared and pass the cloneid in the callback options
     $linkparams = $discussion->get_link_params_array();
     if (array_key_exists('clone', $linkparams)) {
         $cloneid = $linkparams['clone'];
     } else {
         $cloneid = 0;
     }
     $button = new portfolio_add_button();
     $button->set_callback_options('forumng_all_portfolio_caller', array('forumngid' => $forumngid, 'cloneid' => $cloneid, 'posts' => $posts, 'discussionid' => $discussion->get_id()), 'mod_forumng');
     $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
     // redirect to the export page
     redirect($button->to_html(PORTFOLIO_ADD_FAKE_URL));
 }
Example #3
0
/**
 * Print a forum post
 *
 * @global object
 * @global object
 * @uses FORUM_MODE_THREADED
 * @uses PORTFOLIO_FORMAT_PLAINHTML
 * @uses PORTFOLIO_FORMAT_FILE
 * @uses PORTFOLIO_FORMAT_RICHHTML
 * @uses PORTFOLIO_ADD_TEXT_LINK
 * @uses CONTEXT_MODULE
 * @param object $post The post to print.
 * @param object $discussion
 * @param object $forum
 * @param object $cm
 * @param object $course
 * @param boolean $ownpost Whether this post belongs to the current user.
 * @param boolean $reply Whether to print a 'reply' link at the bottom of the message.
 * @param boolean $link Just print a shortened version of the post as a link to the full post.
 * @param string $footer Extra stuff to print after the message.
 * @param string $highlight Space-separated list of terms to highlight.
 * @param int $post_read true, false or -99. If we already know whether this user
 *          has read this post, pass that in, otherwise, pass in -99, and this
 *          function will work it out.
 * @param boolean $dummyifcantsee When forum_user_can_see_post says that
 *          the current user can't see this post, if this argument is true
 *          (the default) then print a dummy 'you can't see this post' post.
 *          If false, don't output anything at all.
 * @param bool|null $istracked
 * @return void
 */
function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost = false, $reply = false, $link = false, $footer = "", $highlight = "", $postisread = null, $dummyifcantsee = true, $istracked = null, $return = false)
{
    global $USER, $CFG, $OUTPUT;
    require_once $CFG->libdir . '/filelib.php';
    // String cache
    static $str;
    // This is an extremely hacky way to ensure we only print the 'unread' anchor
    // the first time we encounter an unread post on a page. Ideally this would
    // be moved into the caller somehow, and be better testable. But at the time
    // of dealing with this bug, this static workaround was the most surgical and
    // it fits together with only printing th unread anchor id once on a given page.
    static $firstunreadanchorprinted = false;
    $modcontext = context_module::instance($cm->id);
    $post->course = $course->id;
    $post->forum = $forum->id;
    $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id);
    if (!empty($CFG->enableplagiarism)) {
        require_once $CFG->libdir . '/plagiarismlib.php';
        $post->message .= plagiarism_get_links(array('userid' => $post->userid, 'content' => $post->message, 'cmid' => $cm->id, 'course' => $post->course, 'forum' => $post->forum));
    }
    // caching
    if (!isset($cm->cache)) {
        $cm->cache = new stdClass();
    }
    if (!isset($cm->cache->caps)) {
        $cm->cache->caps = array();
        $cm->cache->caps['mod/forum:viewdiscussion'] = has_capability('mod/forum:viewdiscussion', $modcontext);
        $cm->cache->caps['moodle/site:viewfullnames'] = has_capability('moodle/site:viewfullnames', $modcontext);
        $cm->cache->caps['mod/forum:editanypost'] = has_capability('mod/forum:editanypost', $modcontext);
        $cm->cache->caps['mod/forum:splitdiscussions'] = has_capability('mod/forum:splitdiscussions', $modcontext);
        $cm->cache->caps['mod/forum:deleteownpost'] = has_capability('mod/forum:deleteownpost', $modcontext);
        $cm->cache->caps['mod/forum:deleteanypost'] = has_capability('mod/forum:deleteanypost', $modcontext);
        $cm->cache->caps['mod/forum:viewanyrating'] = has_capability('mod/forum:viewanyrating', $modcontext);
        $cm->cache->caps['mod/forum:exportpost'] = has_capability('mod/forum:exportpost', $modcontext);
        $cm->cache->caps['mod/forum:exportownpost'] = has_capability('mod/forum:exportownpost', $modcontext);
    }
    if (!isset($cm->uservisible)) {
        $cm->uservisible = \core_availability\info_module::is_user_visible($cm, 0, false);
    }
    if ($istracked && is_null($postisread)) {
        $postisread = forum_tp_is_post_read($USER->id, $post);
    }
    if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) {
        $output = '';
        if (!$dummyifcantsee) {
            if ($return) {
                return $output;
            }
            echo $output;
            return;
        }
        $output .= html_writer::tag('a', '', array('id' => 'p' . $post->id));
        $output .= html_writer::start_tag('div', array('class' => 'forumpost clearfix', 'role' => 'region', 'aria-label' => get_string('hiddenforumpost', 'forum')));
        $output .= html_writer::start_tag('div', array('class' => 'row header'));
        $output .= html_writer::tag('div', '', array('class' => 'left picture'));
        // Picture
        if ($post->parent) {
            $output .= html_writer::start_tag('div', array('class' => 'topic'));
        } else {
            $output .= html_writer::start_tag('div', array('class' => 'topic starter'));
        }
        $output .= html_writer::tag('div', get_string('forumsubjecthidden', 'forum'), array('class' => 'subject', 'role' => 'header'));
        // Subject.
        $output .= html_writer::tag('div', get_string('forumauthorhidden', 'forum'), array('class' => 'author', 'role' => 'header'));
        // Author.
        $output .= html_writer::end_tag('div');
        $output .= html_writer::end_tag('div');
        // row
        $output .= html_writer::start_tag('div', array('class' => 'row'));
        $output .= html_writer::tag('div', ' ', array('class' => 'left side'));
        // Groups
        $output .= html_writer::tag('div', get_string('forumbodyhidden', 'forum'), array('class' => 'content'));
        // Content
        $output .= html_writer::end_tag('div');
        // row
        $output .= html_writer::end_tag('div');
        // forumpost
        if ($return) {
            return $output;
        }
        echo $output;
        return;
    }
    if (empty($str)) {
        $str = new stdClass();
        $str->edit = get_string('edit', 'forum');
        $str->delete = get_string('delete', 'forum');
        $str->reply = get_string('reply', 'forum');
        $str->parent = get_string('parent', 'forum');
        $str->pruneheading = get_string('pruneheading', 'forum');
        $str->prune = get_string('prune', 'forum');
        $str->displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
        $str->markread = get_string('markread', 'forum');
        $str->markunread = get_string('markunread', 'forum');
    }
    $discussionlink = new moodle_url('/mod/forum/discuss.php', array('d' => $post->discussion));
    // Build an object that represents the posting user
    $postuser = new stdClass();
    $postuserfields = explode(',', user_picture::fields());
    $postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
    $postuser->id = $post->userid;
    $postuser->fullname = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']);
    $postuser->profilelink = new moodle_url('/user/view.php', array('id' => $post->userid, 'course' => $course->id));
    // Prepare the groups the posting user belongs to
    if (isset($cm->cache->usersgroups)) {
        $groups = array();
        if (isset($cm->cache->usersgroups[$post->userid])) {
            foreach ($cm->cache->usersgroups[$post->userid] as $gid) {
                $groups[$gid] = $cm->cache->groups[$gid];
            }
        }
    } else {
        $groups = groups_get_all_groups($course->id, $post->userid, $cm->groupingid);
    }
    // Prepare the attachements for the post, files then images
    list($attachments, $attachedimages) = forum_print_attachments($post, $cm, 'separateimages');
    // Determine if we need to shorten this post
    $shortenpost = $link && strlen(strip_tags($post->message)) > $CFG->forum_longpost;
    // Prepare an array of commands
    $commands = array();
    // Add a permalink.
    $permalink = new moodle_url($discussionlink);
    $permalink->set_anchor('p' . $post->id);
    $commands[] = array('url' => $permalink, 'text' => get_string('permalink', 'forum'));
    // SPECIAL CASE: The front page can display a news item post to non-logged in users.
    // Don't display the mark read / unread controls in this case.
    if ($istracked && $CFG->forum_usermarksread && isloggedin()) {
        $url = new moodle_url($discussionlink, array('postid' => $post->id, 'mark' => 'unread'));
        $text = $str->markunread;
        if (!$postisread) {
            $url->param('mark', 'read');
            $text = $str->markread;
        }
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p' . $post->id);
        }
        $commands[] = array('url' => $url, 'text' => $text);
    }
    // Zoom in to the parent specifically
    if ($post->parent) {
        $url = new moodle_url($discussionlink);
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p' . $post->parent);
        }
        $commands[] = array('url' => $url, 'text' => $str->parent);
    }
    // Hack for allow to edit news posts those are not displayed yet until they are displayed
    $age = time() - $post->created;
    if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
        $age = 0;
    }
    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        if (has_capability('moodle/course:manageactivities', $modcontext)) {
            // The first post in single simple is the forum description.
            $commands[] = array('url' => new moodle_url('/course/modedit.php', array('update' => $cm->id, 'sesskey' => sesskey(), 'return' => 1)), 'text' => $str->edit);
        }
    } else {
        if ($ownpost && $age < $CFG->maxeditingtime || $cm->cache->caps['mod/forum:editanypost']) {
            $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('edit' => $post->id)), 'text' => $str->edit);
        }
    }
    if ($cm->cache->caps['mod/forum:splitdiscussions'] && $post->parent && $forum->type != 'single') {
        $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('prune' => $post->id)), 'text' => $str->prune, 'title' => $str->pruneheading);
    }
    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        // Do not allow deleting of first post in single simple type.
    } else {
        if ($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost'] || $cm->cache->caps['mod/forum:deleteanypost']) {
            $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('delete' => $post->id)), 'text' => $str->delete);
        }
    }
    if ($reply) {
        $commands[] = array('url' => new moodle_url('/mod/forum/post.php#mformforum', array('reply' => $post->id)), 'text' => $str->reply);
    }
    if ($CFG->enableportfolios && ($cm->cache->caps['mod/forum:exportpost'] || $ownpost && $cm->cache->caps['mod/forum:exportownpost'])) {
        $p = array('postid' => $post->id);
        require_once $CFG->libdir . '/portfoliolib.php';
        $button = new portfolio_add_button();
        $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id), 'mod_forum');
        if (empty($attachments)) {
            $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
        } else {
            $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
        }
        $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
        if (!empty($porfoliohtml)) {
            $commands[] = $porfoliohtml;
        }
    }
    // Finished building commands
    // Begin output
    $output = '';
    if ($istracked) {
        if ($postisread) {
            $forumpostclass = ' read';
        } else {
            $forumpostclass = ' unread';
            // If this is the first unread post printed then give it an anchor and id of unread.
            if (!$firstunreadanchorprinted) {
                $output .= html_writer::tag('a', '', array('id' => 'unread'));
                $firstunreadanchorprinted = true;
            }
        }
    } else {
        // ignore trackign status if not tracked or tracked param missing
        $forumpostclass = '';
    }
    $topicclass = '';
    if (empty($post->parent)) {
        $topicclass = ' firstpost starter';
    }
    if (!empty($post->lastpost)) {
        $forumpostclass .= ' lastpost';
    }
    // Flag to indicate whether we should hide the author or not.
    $authorhidden = forum_is_author_hidden($post, $forum);
    $postbyuser = new stdClass();
    $postbyuser->post = $post->subject;
    $postbyuser->user = $postuser->fullname;
    $discussionbyuser = get_string('postbyuser', 'forum', $postbyuser);
    $output .= html_writer::tag('a', '', array('id' => 'p' . $post->id));
    // Begin forum post.
    $output .= html_writer::start_div('forumpost clearfix' . $forumpostclass . $topicclass, ['role' => 'region', 'aria-label' => $discussionbyuser]);
    // Begin header row.
    $output .= html_writer::start_div('row header clearfix');
    // User picture.
    if (!$authorhidden) {
        $picture = $OUTPUT->user_picture($postuser, ['courseid' => $course->id]);
        $output .= html_writer::div($picture, 'left picture');
        $topicclass = 'topic' . $topicclass;
    }
    // Begin topic column.
    $output .= html_writer::start_div($topicclass);
    $postsubject = $post->subject;
    if (empty($post->subjectnoformat)) {
        $postsubject = format_string($postsubject);
    }
    $output .= html_writer::div($postsubject, 'subject', ['role' => 'heading', 'aria-level' => '2']);
    if ($authorhidden) {
        $bytext = userdate($post->modified);
    } else {
        $by = new stdClass();
        $by->date = userdate($post->modified);
        $by->name = html_writer::link($postuser->profilelink, $postuser->fullname);
        $bytext = get_string('bynameondate', 'forum', $by);
    }
    $bytextoptions = ['role' => 'heading', 'aria-level' => '2'];
    $output .= html_writer::div($bytext, 'author', $bytextoptions);
    // End topic column.
    $output .= html_writer::end_div();
    // End header row.
    $output .= html_writer::end_div();
    // Row with the forum post content.
    $output .= html_writer::start_div('row maincontent clearfix');
    // Show if author is not hidden or we have groups.
    if (!$authorhidden || $groups) {
        $output .= html_writer::start_div('left');
        $groupoutput = '';
        if ($groups) {
            $groupoutput = print_group_picture($groups, $course->id, false, true, true);
        }
        if (empty($groupoutput)) {
            $groupoutput = '&nbsp;';
        }
        $output .= html_writer::div($groupoutput, 'grouppictures');
        $output .= html_writer::end_div();
        // Left side.
    }
    $output .= html_writer::start_tag('div', array('class' => 'no-overflow'));
    $output .= html_writer::start_tag('div', array('class' => 'content'));
    $options = new stdClass();
    $options->para = false;
    $options->trusted = $post->messagetrust;
    $options->context = $modcontext;
    if ($shortenpost) {
        // Prepare shortened version by filtering the text then shortening it.
        $postclass = 'shortenedpost';
        $postcontent = format_text($post->message, $post->messageformat, $options);
        $postcontent = shorten_text($postcontent, $CFG->forum_shortpost);
        $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum'));
        $postcontent .= html_writer::tag('div', '(' . get_string('numwords', 'moodle', count_words($post->message)) . ')', array('class' => 'post-word-count'));
    } else {
        // Prepare whole post
        $postclass = 'fullpost';
        $postcontent = format_text($post->message, $post->messageformat, $options, $course->id);
        if (!empty($highlight)) {
            $postcontent = highlight($highlight, $postcontent);
        }
        if (!empty($forum->displaywordcount)) {
            $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)), array('class' => 'post-word-count'));
        }
        $postcontent .= html_writer::tag('div', $attachedimages, array('class' => 'attachedimages'));
    }
    // Output the post content
    $output .= html_writer::tag('div', $postcontent, array('class' => 'posting ' . $postclass));
    $output .= html_writer::end_tag('div');
    // Content
    $output .= html_writer::end_tag('div');
    // Content mask
    $output .= html_writer::end_tag('div');
    // Row
    $output .= html_writer::start_tag('div', array('class' => 'row side'));
    $output .= html_writer::tag('div', '&nbsp;', array('class' => 'left'));
    $output .= html_writer::start_tag('div', array('class' => 'options clearfix'));
    if (!empty($attachments)) {
        $output .= html_writer::tag('div', $attachments, array('class' => 'attachments'));
    }
    // Output ratings
    if (!empty($post->rating)) {
        $output .= html_writer::tag('div', $OUTPUT->render($post->rating), array('class' => 'forum-post-rating'));
    }
    // Output the commands
    $commandhtml = array();
    foreach ($commands as $command) {
        if (is_array($command)) {
            $commandhtml[] = html_writer::link($command['url'], $command['text']);
        } else {
            $commandhtml[] = $command;
        }
    }
    $output .= html_writer::tag('div', implode(' | ', $commandhtml), array('class' => 'commands'));
    // Output link to post if required
    if ($link) {
        if (forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
            $langstring = 'discussthistopic';
        } else {
            $langstring = 'viewthediscussion';
        }
        if ($post->replies == 1) {
            $replystring = get_string('repliesone', 'forum', $post->replies);
        } else {
            $replystring = get_string('repliesmany', 'forum', $post->replies);
        }
        if (!empty($discussion->unread) && $discussion->unread !== '-') {
            $replystring .= ' <span class="sep">/</span> <span class="unread">';
            if ($discussion->unread == 1) {
                $replystring .= get_string('unreadpostsone', 'forum');
            } else {
                $replystring .= get_string('unreadpostsnumber', 'forum', $discussion->unread);
            }
            $replystring .= '</span>';
        }
        $output .= html_writer::start_tag('div', array('class' => 'link'));
        $output .= html_writer::link($discussionlink, get_string($langstring, 'forum'));
        $output .= '&nbsp;(' . $replystring . ')';
        $output .= html_writer::end_tag('div');
        // link
    }
    // Output footer if required
    if ($footer) {
        $output .= html_writer::tag('div', $footer, array('class' => 'footer'));
    }
    // Close remaining open divs
    $output .= html_writer::end_tag('div');
    // content
    $output .= html_writer::end_tag('div');
    // row
    $output .= html_writer::end_tag('div');
    // forumpost
    // Mark the forum post as read if required
    if ($istracked && !$CFG->forum_usermarksread && !$postisread) {
        forum_tp_mark_post_read($USER->id, $post, $forum->id);
    }
    if ($return) {
        return $output;
    }
    echo $output;
    return;
}
Example #4
0
/**
 * takes a list of records, the current data, a search string,
 * and mode to display prints the translated template
 *
 * @global object
 * @global object
 * @param string $template
 * @param array $records
 * @param object $data
 * @param string $search
 * @param int $page
 * @param bool $return
 * @return mixed
 */
function data_print_template($template, $records, $data, $search='', $page=0, $return=false) {
    global $CFG, $DB, $OUTPUT;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);

    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;

    if (empty($dataid)) {
        $dataid = $data->id;
    } else if ($dataid != $data->id) {
        $fields = NULL;
    }

    if (empty($fields)) {
        $fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id));
        foreach ($fieldrecords as $fieldrecord) {
            $fields[]= data_get_field($fieldrecord, $data);
        }
        $isteacher = has_capability('mod/data:managetemplates', $context);
    }

    if (empty($records)) {
        return;
    }

    foreach ($records as $record) {   // Might be just one for the single template

    // Replacing tags
        $patterns = array();
        $replacement = array();

    // Then we generate strings to replace for normal tags
        foreach ($fields as $field) {
            $patterns[]='[['.$field->field->name.']]';
            $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
        }

    // Replacing special tags (##Edit##, ##Delete##, ##More##)
        $patterns[]='##edit##';
        $patterns[]='##delete##';
        if (has_capability('mod/data:manageentries', $context) or data_isowner($record->id)) {
            $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d='
                             .$data->id.'&amp;rid='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.get_string('edit').'" title="'.get_string('edit').'" /></a>';
            $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
                             .$data->id.'&amp;delete='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="'.get_string('delete').'" title="'.get_string('delete').'" /></a>';
        } else {
            $replacement[] = '';
            $replacement[] = '';
        }

        $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;rid=' . $record->id;
        if ($search) {
            $moreurl .= '&amp;filter=1';
        }
        $patterns[]='##more##';
        $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('i/search') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>';

        $patterns[]='##moreurl##';
        $replacement[] = $moreurl;

        $patterns[]='##user##';
        $replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid.
                               '&amp;course='.$data->course.'">'.fullname($record).'</a>';

        $patterns[]='##export##';

        if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate')
            && ((has_capability('mod/data:exportentry', $context)
                || (data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))))) {
            require_once($CFG->libdir . '/portfoliolib.php');
            $button = new portfolio_add_button();
            $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), '/mod/data/locallib.php');
            list($formats, $files) = data_portfolio_caller::formats($fields, $record);
            $button->set_formats($formats);
            $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
        } else {
            $replacement[] = '';
        }

        $patterns[] = '##timeadded##';
        $replacement[] = userdate($record->timecreated);

        $patterns[] = '##timemodified##';
        $replacement [] = userdate($record->timemodified);

        $patterns[]='##approve##';
        if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)){
            $replacement[] = '<span class="approve"><a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;approve='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('i/approve') . '" class="icon" alt="'.get_string('approve').'" /></a></span>';
        } else {
            $replacement[] = '';
        }

        $patterns[]='##comments##';
        if (($template == 'listtemplate') && ($data->comments)) {

            if (!empty($CFG->usecomments)) {
                require_once($CFG->dirroot  . '/comment/lib.php');
                list($context, $course, $cm) = get_context_info_array($context->id);
                $cmt = new stdClass();
                $cmt->context = $context;
                $cmt->course  = $course;
                $cmt->cm      = $cm;
                $cmt->area    = 'database_entry';
                $cmt->itemid  = $record->id;
                $cmt->showcount = true;
                $cmt->component = 'mod_data';
                $comment = new comment($cmt);
                $replacement[] = $comment->output(true);
            }
        } else {
            $replacement[] = '';
        }

        // actual replacement of the tags
        $newtext = str_ireplace($patterns, $replacement, $data->{$template});

        // no more html formatting and filtering - see MDL-6635
        if ($return) {
            return $newtext;
        } else {
            echo $newtext;

            // hack alert - return is always false in singletemplate anyway ;-)
            /**********************************
             *    Printing Ratings Form       *
             *********************************/
            if ($template == 'singletemplate') {    //prints ratings options
                data_print_ratings($data, $record);
            }

            /**********************************
             *    Printing Comments Form       *
             *********************************/
            if (($template == 'singletemplate') && ($data->comments)) {
                if (!empty($CFG->usecomments)) {
                    require_once($CFG->dirroot . '/comment/lib.php');
                    list($context, $course, $cm) = get_context_info_array($context->id);
                    $cmt = new stdClass();
                    $cmt->context = $context;
                    $cmt->course  = $course;
                    $cmt->cm      = $cm;
                    $cmt->area    = 'database_entry';
                    $cmt->itemid  = $record->id;
                    $cmt->showcount = true;
                    $cmt->component = 'mod_data';
                    $comment = new comment($cmt);
                    $comment->output(false);
                }
            }
        }
    }
}
Example #5
0
/**
 * takes a list of records, the current data, a search string,
 * and mode to display prints the translated template
 *
 * @global object
 * @global object
 * @param string $template
 * @param array $records
 * @param object $data
 * @param string $search
 * @param int $page
 * @param bool $return
 * @param object $jumpurl a moodle_url by which to jump back to the record list (can be null)
 * @return mixed
 */
function data_print_template($template, $records, $data, $search = '', $page = 0, $return = false, moodle_url $jumpurl = null)
{
    global $CFG, $DB, $OUTPUT;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = context_module::instance($cm->id);
    static $fields = NULL;
    static $isteacher;
    static $dataid = NULL;
    if (empty($dataid)) {
        $dataid = $data->id;
    } else {
        if ($dataid != $data->id) {
            $fields = NULL;
        }
    }
    if (empty($fields)) {
        $fieldrecords = $DB->get_records('data_fields', array('dataid' => $data->id));
        foreach ($fieldrecords as $fieldrecord) {
            $fields[] = data_get_field($fieldrecord, $data);
        }
        $isteacher = has_capability('mod/data:managetemplates', $context);
    }
    if (empty($records)) {
        return;
    }
    if (!$jumpurl) {
        $jumpurl = new moodle_url('/mod/data/view.php', array('d' => $data->id));
    }
    $jumpurl = new moodle_url($jumpurl, array('page' => $page, 'sesskey' => sesskey()));
    // Check whether this activity is read-only at present
    $readonly = data_in_readonly_period($data);
    foreach ($records as $record) {
        // Might be just one for the single template
        // Replacing tags
        $patterns = array();
        $replacement = array();
        // Then we generate strings to replace for normal tags
        foreach ($fields as $field) {
            $patterns[] = '[[' . $field->field->name . ']]';
            $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
        }
        $canmanageentries = has_capability('mod/data:manageentries', $context);
        // Replacing special tags (##Edit##, ##Delete##, ##More##)
        $patterns[] = '##edit##';
        $patterns[] = '##delete##';
        if ($canmanageentries || !$readonly && data_isowner($record->id)) {
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id . '&amp;rid=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>';
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;delete=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>';
        } else {
            $replacement[] = '';
            $replacement[] = '';
        }
        $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;rid=' . $record->id;
        if ($search) {
            $moreurl .= '&amp;filter=1';
        }
        $patterns[] = '##more##';
        $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('t/preview') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>';
        $patterns[] = '##moreurl##';
        $replacement[] = $moreurl;
        $patterns[] = '##delcheck##';
        if ($canmanageentries) {
            $replacement[] = html_writer::checkbox('delcheck[]', $record->id, false, '', array('class' => 'recordcheckbox'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##user##';
        $replacement[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->userid . '&amp;course=' . $data->course . '">' . fullname($record) . '</a>';
        $patterns[] = '##userpicture##';
        $ruser = user_picture::unalias($record, null, 'userid');
        $replacement[] = $OUTPUT->user_picture($ruser, array('courseid' => $data->course));
        $patterns[] = '##export##';
        if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') && (has_capability('mod/data:exportentry', $context) || data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))) {
            require_once $CFG->libdir . '/portfoliolib.php';
            $button = new portfolio_add_button();
            $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), 'mod_data');
            list($formats, $files) = data_portfolio_caller::formats($fields, $record);
            $button->set_formats($formats);
            $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##timeadded##';
        $replacement[] = userdate($record->timecreated);
        $patterns[] = '##timemodified##';
        $replacement[] = userdate($record->timemodified);
        $patterns[] = '##approve##';
        if (has_capability('mod/data:approve', $context) && $data->approval && !$record->approved) {
            $approveurl = new moodle_url($jumpurl, array('approve' => $record->id));
            $approveicon = new pix_icon('t/approve', get_string('approve', 'data'), '', array('class' => 'iconsmall'));
            $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($approveurl, $approveicon), array('class' => 'approve'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##disapprove##';
        if (has_capability('mod/data:approve', $context) && $data->approval && $record->approved) {
            $disapproveurl = new moodle_url($jumpurl, array('disapprove' => $record->id));
            $disapproveicon = new pix_icon('t/block', get_string('disapprove', 'data'), '', array('class' => 'iconsmall'));
            $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($disapproveurl, $disapproveicon), array('class' => 'disapprove'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##comments##';
        if ($template == 'listtemplate' && $data->comments) {
            if (!empty($CFG->usecomments)) {
                require_once $CFG->dirroot . '/comment/lib.php';
                list($context, $course, $cm) = get_context_info_array($context->id);
                $cmt = new stdClass();
                $cmt->context = $context;
                $cmt->course = $course;
                $cmt->cm = $cm;
                $cmt->area = 'database_entry';
                $cmt->itemid = $record->id;
                $cmt->showcount = true;
                $cmt->component = 'mod_data';
                $comment = new comment($cmt);
                $replacement[] = $comment->output(true);
            }
        } else {
            $replacement[] = '';
        }
        // actual replacement of the tags
        $newtext = str_ireplace($patterns, $replacement, $data->{$template});
        // no more html formatting and filtering - see MDL-6635
        if ($return) {
            return $newtext;
        } else {
            echo $newtext;
            // hack alert - return is always false in singletemplate anyway ;-)
            /**********************************
             *    Printing Ratings Form       *
             *********************************/
            if ($template == 'singletemplate') {
                //prints ratings options
                data_print_ratings($data, $record);
            }
            /**********************************
             *    Printing Comments Form       *
             *********************************/
            if ($template == 'singletemplate' && $data->comments) {
                if (!empty($CFG->usecomments)) {
                    require_once $CFG->dirroot . '/comment/lib.php';
                    list($context, $course, $cm) = get_context_info_array($context->id);
                    $cmt = new stdClass();
                    $cmt->context = $context;
                    $cmt->course = $course;
                    $cmt->cm = $cm;
                    $cmt->area = 'database_entry';
                    $cmt->itemid = $record->id;
                    $cmt->showcount = true;
                    $cmt->component = 'mod_data';
                    $comment = new comment($cmt);
                    $comment->output(false);
                }
            }
        }
    }
}
function referentiel_menu_certificat($context, $certificat_id, $referentiel_instance_id, $verrou, $userid = 0, $select_acc = 0, $rang = 0, $dossier_ferme)
{
    global $CFG;
    global $OUTPUT;
    global $USER;
    $s = "";
    $s .= '<tr valign="top">';
    $s .= '<td align="center" colspan="6">' . "\n";
    $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=listcertifsingle&amp;sesskey=' . sesskey() . '#certificat_' . $certificat_id . '"><img src="' . $OUTPUT->pix_url('search', 'referentiel') . '" alt="' . get_string('plus', 'referentiel') . '" title="' . get_string('plus', 'referentiel') . '" /></a>' . "\n";
    if (!$dossier_ferme) {
        $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=updatecertif&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/edit') . '" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>' . "\n";
    }
    if (has_capability('mod/referentiel:comment', $context) && !$dossier_ferme) {
        //		or referentiel_certificat_isowner($certificat_id)) {
        $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=commentcertif&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('feedback', 'referentiel') . '" alt="' . get_string('comment', 'referentiel') . '" title="' . get_string('comment', 'referentiel') . '" /></a>' . "\n";
    }
    if (has_capability('mod/referentiel:managecertif', $context)) {
        $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=deletecertif&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/delete') . '" alt="' . get_string('certificat_initialiser', 'referentiel') . '" title="' . get_string('certificat_initialiser', 'referentiel') . '" /></a>' . "\n";
        if (!$dossier_ferme) {
            if ($verrou) {
                $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=deverrouiller&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/go') . '" alt="' . get_string('deverrouiller', 'referentiel') . '" title="' . get_string('deverrouiller', 'referentiel') . '" /></a>' . "\n";
            } else {
                $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=verrouiller&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/stop') . '" alt="' . get_string('verrouiller', 'referentiel') . '" title="' . get_string('verrouiller', 'referentiel') . '" /></a>' . "\n";
            }
            $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=clorecertificat&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('cadenas_f', 'referentiel') . '" alt="' . get_string('c_clore', 'referentiel') . '" title="' . get_string('c_clore', 'referentiel') . '" /></a>' . "\n";
        } else {
            $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=ouvrircertificat&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('cadenas_o', 'referentiel') . '" alt="' . get_string('c_ouvrir', 'referentiel') . '" title="' . get_string('c_ouvrir', 'referentiel') . '" /></a>' . "\n";
        }
        if (referentiel_site_can_print_referentiel($referentiel_instance_id)) {
            $s .= '&nbsp; <a href="' . $CFG->wwwroot . '/mod/referentiel/print_certificat.php?d=' . $referentiel_instance_id . '&amp;select_acc=' . $select_acc . '&amp;certificat_id=' . $certificat_id . '&amp;userid=' . $userid . '&amp;mode=printcertif&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('printer', 'referentiel') . '" alt="' . get_string('print', 'referentiel') . '" title="' . get_string('print', 'referentiel') . '" /></a>' . "\n";
        }
    }
    // Portofolio
    if (!empty($CFG->enableportfolios)) {
        require_once $CFG->libdir . '/portfoliolib.php';
        // Mahara export stuff
        $button = new portfolio_add_button();
        // Version anterieure à Moodle 2.4
        // $button->set_callback_options('referentiel_portfolio_caller',
        //            array('instanceid' => $referentiel_instance_id, 'certificatid' => $certificat_id, 'report' => 0, 'export_format' => ''), '/mod/referentiel/portfolio/mahara/locallib_portfolio.php');
        // Version Moodle 2.4
        $button->set_callback_options('referentiel_portfolio_caller', array('instanceid' => $referentiel_instance_id, 'certificatid' => $certificat_id, 'report' => 0, 'export_format' => ''), 'mod_referentiel');
        $button->set_formats(array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_LEAP2A));
        $s .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
        // Mahara ATranscript stuff
        // Ne pas activer pour le moment (juin 2012) car le developpement n'est pas achevé
        if (MAHARA_ARTEFACT_ATRANSCRIPT) {
            $button = new portfolio_add_button();
            // Version antérieure à Moodle 2.4
            //            $button->set_callback_options('atranscript_portfolio_caller',
            //                array('instanceid' => $referentiel_instance_id, 'userid' => $USER->id, 'certificatid' => $certificat_id, 'export_format' => PORTFOLIO_FORMAT_LEAP2A), '/mod/referentiel/portfolio/mahara/atranscript_artefact/locallib_portfolio.php');
            // Version  Moodle 2.4
            $button->set_callback_options('atranscript_portfolio_caller', array('instanceid' => $referentiel_instance_id, 'userid' => $USER->id, 'certificatid' => $certificat_id, 'export_format' => PORTFOLIO_FORMAT_LEAP2A), 'mod_referentiel');
            $button->set_formats(array(PORTFOLIO_FORMAT_LEAP2A));
            $s .= $button->to_html(PORTFOLIO_ADD_ICON_LINK, get_string('atranscript', 'referentiel'));
            // $s.=$button->to_html(PORTFOLIO_ADD_TEXT_LINK);
        }
    }
    $s .= '</td></tr>' . "\n";
    if ($rang % 2 == 0) {
        $s .= '<td class="couleur_paire" heigth="4" colspan="6"></td>' . "\n";
    } else {
        $s .= '<td class="couleur_impaire" heigth="4" colspan="6"></td>' . "\n";
    }
    return $s;
}
Example #7
0
/**
 *
 * @global object
 * @global object
 * @global object
 * @param object $course
 * @param object $cm
 * @param object $glossary
 * @param object $entry
 * @param string $mode
 * @param string $hook
 * @param string $type
 * @return string|void
 */
function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$hook='', $type = 'print') {
    global $USER, $CFG, $DB, $OUTPUT;

    $context = get_context_instance(CONTEXT_MODULE, $cm->id);

    $output = false;   //To decide if we must really return text in "return". Activate when needed only!
    $importedentry = ($entry->sourceglossaryid == $glossary->id);
    $ismainglossary = $glossary->mainglossary;


    $return = '<span class="commands">';
    // Differentiate links for each entry.
    $altsuffix = ': '.strip_tags(format_text($entry->concept));

    if (!$entry->approved) {
        $output = true;
        $return .= get_string('entryishidden','glossary');
    }

    $iscurrentuser = ($entry->userid == $USER->id);

    if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) {
        // only teachers can export entries so check it out
        if (has_capability('mod/glossary:export', $context) and !$ismainglossary and !$importedentry) {
            $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1,'course'=>$course->id));
            if ( $mainglossary ) {  // if there is a main glossary defined, allow to export the current entry
                $output = true;
                $return .= ' <a title="'.get_string('exporttomainglossary','glossary') . '" href="exportentry.php?id='.$entry->id.'&amp;prevmode='.$mode.'&amp;hook='.urlencode($hook).'"><img src="'.$OUTPUT->pix_url('export', 'glossary').'" class="iconsmall" alt="'.get_string('exporttomainglossary','glossary').$altsuffix.'" /></a>';
            }
        }

        if ( $entry->sourceglossaryid ) {
            $icon = $OUTPUT->pix_url('minus', 'glossary');   // graphical metaphor (minus) for deleting an imported entry
        } else {
            $icon = $OUTPUT->pix_url('t/delete');
        }

        //Decide if an entry is editable:
        // -It isn't a imported entry (so nobody can edit a imported (from secondary to main) entry)) and
        // -The user is teacher or he is a student with time permissions (edit period or editalways defined).
        $ineditperiod = ((time() - $entry->timecreated <  $CFG->maxeditingtime) || $glossary->editalways);
        if ( !$importedentry and (has_capability('mod/glossary:manageentries', $context) or ($entry->userid == $USER->id and ($ineditperiod and has_capability('mod/glossary:write', $context))))) {
            $output = true;
            $return .= " <a title=\"" . get_string("delete") . "\" href=\"deleteentry.php?id=$cm->id&amp;mode=delete&amp;entry=$entry->id&amp;prevmode=$mode&amp;hook=".urlencode($hook)."\"><img src=\"";
            $return .= $icon;
            $return .= "\" class=\"iconsmall\" alt=\"" . get_string("delete") .$altsuffix."\" /></a> ";

            $return .= " <a title=\"" . get_string("edit") . "\" href=\"edit.php?cmid=$cm->id&amp;id=$entry->id&amp;mode=$mode&amp;hook=".urlencode($hook)."\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" class=\"iconsmall\" alt=\"" . get_string("edit") .$altsuffix. "\" /></a>";
        } elseif ( $importedentry ) {
            $return .= " <font size=\"-1\">" . get_string("exportedentry","glossary") . "</font>";
        }
    }
    if (!empty($CFG->enableportfolios) && (has_capability('mod/glossary:exportentry', $context) || ($iscurrentuser && has_capability('mod/glossary:exportownentry', $context)))) {
        require_once($CFG->libdir . '/portfoliolib.php');
        $button = new portfolio_add_button();
        $button->set_callback_options('glossary_entry_portfolio_caller',  array('id' => $cm->id, 'entryid' => $entry->id), '/mod/glossary/locallib.php');

        $filecontext = $context;
        if ($entry->sourceglossaryid == $cm->instance) {
            if ($maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
                $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
            }
        }
        $fs = get_file_storage();
        if ($files = $fs->get_area_files($filecontext->id, 'mod_glossary', 'attachment', $entry->id, "timemodified", false)) {
            $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
        } else {
            $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
        }

        $return .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
    }
    $return .= "&nbsp;&nbsp;"; // just to make up a little the output in Mozilla ;)

    $return .= '</span>';

    if (!empty($CFG->usecomments) && has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
        require_once($CFG->dirroot . '/comment/lib.php');
        $cmt = new stdClass();
        $cmt->component = 'mod_glossary';
        $cmt->context  = $context;
        $cmt->course   = $course;
        $cmt->cm       = $cm;
        $cmt->area     = 'glossary_entry';
        $cmt->itemid   = $entry->id;
        $cmt->showcount = true;
        $comment = new comment($cmt);
        $return .= '<div>'.$comment->output(true).'</div>';
        $output = true;
    }

    //If we haven't calculated any REAL thing, delete result ($return)
    if (!$output) {
        $return = '';
    }
    //Print or get
    if ($type == 'print') {
        echo $return;
    } else {
        return $return;
    }
}
Example #8
0
 function view()
 {
     global $OUTPUT, $CFG, $USER, $PAGE;
     $edit = optional_param('edit', 0, PARAM_BOOL);
     $saved = optional_param('saved', 0, PARAM_BOOL);
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     require_capability('mod/assignment:view', $context);
     $submission = $this->get_submission($USER->id, false);
     //Guest can not submit nor edit an assignment (bug: 4604)
     if (!is_enrolled($this->context, $USER, 'mod/assignment:submit')) {
         $editable = false;
     } else {
         $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
     }
     $editmode = ($editable and $edit);
     if ($editmode) {
         // prepare form and process submitted data
         $editoroptions = array('noclean' => false, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->course->maxbytes);
         $data = new stdClass();
         $data->id = $this->cm->id;
         $data->edit = 1;
         if ($submission) {
             $data->sid = $submission->id;
             $data->text = $submission->data1;
             $data->textformat = $submission->data2;
         } else {
             $data->sid = NULL;
             $data->text = '';
             $data->textformat = NULL;
         }
         $data = file_prepare_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $data->sid);
         $mform = new mod_assignment_online_edit_form(null, array($data, $editoroptions));
         if ($mform->is_cancelled()) {
             redirect($PAGE->url);
         }
         if ($data = $mform->get_data()) {
             $submission = $this->get_submission($USER->id, true);
             //create the submission if needed & its id
             $data = file_postupdate_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $submission->id);
             $submission = $this->update_submission($data);
             //TODO fix log actions - needs db upgrade
             add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
             $this->email_teachers($submission);
             //redirect to get updated submission date and word count
             redirect(new moodle_url($PAGE->url, array('saved' => 1)));
         }
     }
     add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
     /// print header, etc. and display form if needed
     if ($editmode) {
         $this->view_header(get_string('editmysubmission', 'assignment'));
     } else {
         $this->view_header();
     }
     $this->view_intro();
     $this->view_dates();
     if ($saved) {
         echo $OUTPUT->notification(get_string('submissionsaved', 'assignment'), 'notifysuccess');
     }
     if (is_enrolled($this->context, $USER)) {
         if ($editmode) {
             echo $OUTPUT->box_start('generalbox', 'onlineenter');
             $mform->display();
         } else {
             echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter', 'online');
             if ($submission && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                 $text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $this->context->id, 'mod_assignment', $this->filearea, $submission->id);
                 echo format_text($text, $submission->data2, array('overflowdiv' => true));
                 if ($CFG->enableportfolios) {
                     require_once $CFG->libdir . '/portfoliolib.php';
                     $button = new portfolio_add_button();
                     $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
                     $fs = get_file_storage();
                     if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', $this->filearea, $submission->id, "timemodified", false)) {
                         $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
                     } else {
                         $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
                     }
                     $button->render();
                 }
             } else {
                 if ($this->isopen()) {
                     //fix for #4206
                     echo '<div style="text-align:center">' . get_string('emptysubmission', 'assignment') . '</div>';
                 }
             }
         }
         echo $OUTPUT->box_end();
         if (!$editmode && $editable) {
             if (!empty($submission)) {
                 $submitbutton = "editmysubmission";
             } else {
                 $submitbutton = "addsubmission";
             }
             echo "<div style='text-align:center'>";
             echo $OUTPUT->single_button(new moodle_url('view.php', array('id' => $this->cm->id, 'edit' => '1')), get_string($submitbutton, 'assignment'));
             echo "</div>";
         }
     }
     $this->view_feedback();
     $this->view_footer();
 }
Example #9
0
                if (empty($data->listtemplate)) {
                    echo $OUTPUT->notification(get_string('nolisttemplate', 'data'));
                    data_generate_default_template($data, 'listtemplate', 0, false, false);
                }
                echo $data->listtemplateheader;
                data_print_template('listtemplate', $records, $data, $search, $page);
                echo $data->listtemplatefooter;
                echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
            }
        }
    }
    $search = trim($search);
    if (empty($records)) {
        $records = array();
    }
    if ($mode == '' && !empty($CFG->enableportfolios)) {
        require_once $CFG->libdir . '/portfoliolib.php';
        $button = new portfolio_add_button();
        $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), '/mod/data/locallib.php');
        if (data_portfolio_caller::has_files($data)) {
            $button->set_formats(array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A));
            // no plain html for us
        }
        echo $button->to_html(PORTFOLIO_ADD_FULL_FORM);
    }
    //Advanced search form doesn't make sense for single (redirects list view)
    if (($maxcount || $mode == 'asearch') && $mode != 'single') {
        data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
    }
}
echo $OUTPUT->footer();
 /**
  * Produces a list of links to the files uploaded by a user
  *
  * @param $userid int optional id of the user. If 0 then $USER->id is used.
  * @param $return boolean optional defaults to false. If true the list is returned rather than printed
  * @return string optional
  */
 function print_user_files($userid = 0, $return = false)
 {
     global $CFG, $USER;
     $mode = optional_param('mode', '', PARAM_ALPHA);
     $offset = optional_param('offset', 0, PARAM_INT);
     if (!$userid) {
         if (!isloggedin()) {
             return '';
         }
         $userid = $USER->id;
     }
     $output = '';
     $submission = $this->get_submission($userid);
     $candelete = $this->can_delete_files($submission);
     $strdelete = get_string('delete');
     if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission) and !empty($mode)) {
         // only during grading
         $output .= '<strong>' . get_string('draft', 'assignment') . ':</strong><br />';
     }
     if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) {
         // only during grading
         $npurl = $CFG->wwwroot . "/mod/assignment/type/upload/notes.php?id={$this->cm->id}&amp;userid={$userid}&amp;offset={$offset}&amp;mode=single";
         $output .= '<a href="' . $npurl . '">' . get_string('notes', 'assignment') . '</a><br />';
     }
     $fs = get_file_storage();
     $browser = get_file_browser();
     if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
         $button = new portfolio_add_button();
         foreach ($files as $file) {
             $filename = $file->get_filename();
             $mimetype = $file->get_mimetype();
             $icon = mimeinfo_from_type('icon', $mimetype);
             $path = $browser->encodepath($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/assignment_submission/' . $userid . '/' . $filename);
             $output .= '<a href="' . $path . '" ><img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . s($filename) . '</a>';
             if ($candelete) {
                 $delurl = "{$CFG->wwwroot}/mod/assignment/delete.php?id={$this->cm->id}&amp;file=" . rawurlencode($filename) . "&amp;userid={$submission->userid}&amp;mode={$mode}&amp;offset={$offset}";
                 $output .= '<a href="' . $delurl . '">&nbsp;' . '<img title="' . $strdelete . '" src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt="" /></a> ';
             }
             if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
                 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/lib.php');
                 $button->set_formats(portfolio_format_from_file($file));
                 $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
             }
             $output .= '<br />';
         }
         if (count($files) > 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
             $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/lib.php');
             $button->set_formats(PORTFOLIO_FORMAT_FILE);
             $output .= $button->to_html();
         }
     }
     if ($this->drafts_tracked() and $this->isopen() and has_capability('mod/assignment:grade', $this->context) and $mode != '') {
         // we do not want it on view.php page
         if ($this->can_unfinalize($submission)) {
             $options = array('id' => $this->cm->id, 'userid' => $userid, 'action' => 'unfinalize', 'mode' => $mode, 'offset' => $offset);
             $output .= print_single_button('upload.php', $options, get_string('unfinalize', 'assignment'), 'post', '_self', true);
         } else {
             if ($this->can_finalize($submission)) {
                 $options = array('id' => $this->cm->id, 'userid' => $userid, 'action' => 'finalizeclose', 'mode' => $mode, 'offset' => $offset);
                 $output .= print_single_button('upload.php', $options, get_string('finalize', 'assignment'), 'post', '_self', true);
             }
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     if ($return) {
         return $output;
     }
     echo $output;
 }
Example #11
0
 /**
  * Renders the 'export entire wiki' link.
  * @param object $subwiki Subwiki data object
  * @param bool $anyfiles True if any page of subwiki contains files
  * @return string HTML content of list item with link, or nothing if none
  */
 public function render_export_all_li($subwiki, $anyfiles)
 {
     global $CFG;
     if (!$CFG->enableportfolios) {
         return '';
     }
     require_once $CFG->libdir . '/portfoliolib.php';
     $button = new portfolio_add_button();
     $button->set_callback_options('ouwiki_all_portfolio_caller', array('subwikiid' => $subwiki->id), '/mod/ouwiki/portfoliolib.php');
     if ($anyfiles) {
         $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
     } else {
         $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
     }
     return html_writer::tag('li', $button->to_html(PORTFOLIO_ADD_TEXT_LINK));
 }
Example #12
0
 /**
  * Produces a list of links to the files uploaded by a user
  *
  * @param $userid int optional id of the user. If 0 then $USER->id is used.
  * @param $return boolean optional defaults to false. If true the list is returned rather than printed
  * @return string optional
  */
 function print_user_files($userid = 0, $return = false)
 {
     global $CFG, $USER, $OUTPUT;
     if (!$userid) {
         if (!isloggedin()) {
             return '';
         }
         $userid = $USER->id;
     }
     $output = '';
     $fs = get_file_storage();
     $browser = get_file_browser();
     $found = false;
     if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
         $button = new portfolio_add_button();
         foreach ($files as $file) {
             $filename = $file->get_filename();
             $found = true;
             $mimetype = $file->get_mimetype();
             $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/assignment_submission/' . $userid . '/' . $filename);
             $output .= '<a href="' . $path . '" ><img src="' . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />' . s($filename) . '</a>';
             if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
                 $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()));
                 $button->set_formats(portfolio_format_from_file($file));
                 $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
             }
             $output .= '<br />';
         }
         if (count($files) > 1 && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
             $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id));
             $button->set_formats(PORTFOLIO_PORMAT_FILE);
             $output .= '<br />' . $button->to_html();
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     if ($return) {
         return $output;
     }
     echo $output;
 }
Example #13
0
        if ($canoverride) {
            $displayassessment->add_action($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop'));
        }
        echo $output->render($displayassessment);
        if ($workshop->phase == workshop::PHASE_CLOSED and has_capability('mod/workshop:viewallassessments', $workshop->context)) {
            if (strlen(trim($assessment->feedbackreviewer)) > 0) {
                echo $output->render(new workshop_feedback_reviewer($assessment));
            }
        }
    }
}
if (!$edit and $canoverride) {
    // display a form to override the submission grade
    $feedbackform->display();
}
// If portfolios are enabled and we are not on the edit/removal confirmation screen, display a button to export this page.
// The export is not offered if the submission is seen as a published one (it has no relation to the current user.
if (!empty($CFG->enableportfolios)) {
    if (!$delete and !$edit and !$seenaspublished and $submission->id and ($ownsubmission or $canviewall or $isreviewer)) {
        if (has_capability('mod/workshop:exportsubmissions', $workshop->context)) {
            require_once $CFG->libdir . '/portfoliolib.php';
            $button = new portfolio_add_button();
            $button->set_callback_options('mod_workshop_portfolio_caller', array('id' => $workshop->cm->id, 'submissionid' => $submission->id), 'mod_workshop');
            $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
            echo html_writer::start_tag('div', array('class' => 'singlebutton'));
            echo $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportsubmission', 'workshop'));
            echo html_writer::end_tag('div');
        }
    }
}
echo $output->footer();
Example #14
0
 public static function add_button($resource, $format = null, $return = false)
 {
     if (!has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $resource->cm->id))) {
         return;
     }
     if (!is_callable(array($resource, 'portfolio_prepare_package')) || !is_callable(array($resource, 'portfolio_get_sha1'))) {
         debugging(get_string('portfolionotimplemented', 'resource'));
         return false;
     }
     $callersupports = array(self::type_to_format($resource->resource->type));
     if ($resource->resource->type == 'file') {
         // $callersupports = array(portfolio_format_from_file($file);
     }
     $button = new portfolio_add_button();
     $button->set_callback_options('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php');
     $button->set_formats($callersupports);
     if ($return) {
         return $button->to_html($format);
     }
     $button->render($format);
 }
Example #15
0
 /**
  * Print a single blog post
  *
  * @param object $oublog Blog object
  * @param object $post Structure containing all post info and comments
  * @param string $baseurl Base URL of current page
  * @param string $blogtype Blog level ie course or above
  * @param bool $canmanageposts Has capability toggle
  * @param bool $canaudit Has capability toggle
  * @param bool $cancomment Has capability toggle
  * @param bool $forexport Export output rendering toggle
  * @param bool $email Email output rendering toggle
  * @return bool
  */
 public function render_post($cm, $oublog, $post, $baseurl, $blogtype, $canmanageposts = false, $canaudit = false, $commentcount = true, $forexport = false, $format = false, $email = false)
 {
     global $CFG, $USER;
     $output = '';
     $modcontext = context_module::instance($cm->id);
     // Get rid of any existing tag from the URL as we only support one at a time.
     $baseurl = preg_replace('~&amp;tag=[^&]*~', '', $baseurl);
     $strcomment = get_string('comment', 'oublog');
     $strtags = get_string('tags', 'oublog');
     $stredit = get_string('edit', 'oublog');
     $strdelete = get_string('delete', 'oublog');
     $strpermalink = get_string('permalink', 'oublog');
     $row = '';
     if (isset($post->row)) {
         $row = $post->row % 2 ? 'oublog-odd' : 'oublog-even';
     }
     $extraclasses = $post->deletedby ? ' oublog-deleted' : '';
     $extraclasses .= ' oublog-hasuserpic';
     $extraclasses .= ' ' . $row;
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post' . $extraclasses));
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top'));
     $fs = get_file_storage();
     if ($files = $fs->get_area_files($modcontext->id, 'mod_oublog', 'attachment', $post->id, "timemodified", false)) {
         $output .= html_writer::start_tag('div', array('class' => 'oublog-post-attachments'));
         $output .= get_string('attachments', 'mod_oublog') . ': ';
         foreach ($files as $file) {
             if (!$forexport && !$email) {
                 $filename = $file->get_filename();
                 $mimetype = $file->get_mimetype();
                 $iconimage = html_writer::empty_tag('img', array('src' => $this->output->pix_url(file_mimetype_icon($mimetype)), 'alt' => $mimetype, 'class' => 'icon'));
                 if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC) {
                     $fileurlbase = '/mod/oublog/pluginfile.php';
                 } else {
                     $fileurlbase = '/pluginfile.php';
                 }
                 $filepath = '/' . $modcontext->id . '/mod_oublog/attachment/' . $post->id . '/' . $filename;
                 $path = moodle_url::make_file_url($fileurlbase, $filepath, true);
                 $output .= html_writer::start_tag('div', array('class' => 'oublog-post-attachment'));
                 $output .= html_writer::tag('a', $iconimage, array('href' => $path));
                 $output .= html_writer::tag('a', s($filename), array('href' => $path));
                 $output .= html_writer::end_tag('div');
             } else {
                 $filename = $file->get_filename();
                 if (is_object($format)) {
                     $output .= $format->file_output($file) . ' ';
                 } else {
                     $output .= $filename . ' ';
                 }
             }
         }
         $output .= html_writer::end_tag('div');
     }
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top-content'));
     if (!$forexport) {
         $output .= html_writer::start_tag('div', array('class' => 'oublog-userpic'));
         $postuser = new object();
         $postuser->id = $post->userid;
         $postuser->firstname = $post->firstname;
         $postuser->lastname = $post->lastname;
         $postuser->email = $post->email;
         $postuser->imagealt = $post->imagealt;
         $postuser->picture = $post->picture;
         $postuser->firstnamephonetic = $post->firstnamephonetic;
         $postuser->lastnamephonetic = $post->lastnamephonetic;
         $postuser->middlename = $post->middlename;
         $postuser->alternatename = $post->alternatename;
         $output .= $this->output->user_picture($postuser, array('courseid' => $oublog->course, 'size' => 70));
         $output .= html_writer::end_tag('div');
     }
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top-details'));
     $formattedtitle = format_string($post->title);
     if (trim($formattedtitle) !== '') {
         $output .= html_writer::tag('h2', format_string($post->title), array('class' => 'oublog-title'));
     } else {
         if (!$forexport) {
             $posttitle = get_accesshide(get_string('newpost', 'mod_oublog', oublog_get_displayname($oublog)));
             $output .= html_writer::tag('h2', $posttitle, array('class' => 'oublog-title'));
         }
     }
     if ($post->deletedby) {
         $deluser = new stdClass();
         // Get user name fields.
         $delusernamefields = get_all_user_name_fields(false, null, 'del');
         foreach ($delusernamefields as $namefield => $retnamefield) {
             $deluser->{$namefield} = $post->{$retnamefield};
         }
         $a = new stdClass();
         $a->fullname = html_writer::tag('a', fullname($deluser), array('href' => $CFG->wwwroot . '/user/view.php?id=' . $post->deletedby));
         $a->timedeleted = oublog_date($post->timedeleted);
         $output .= html_writer::tag('div', get_string('deletedby', 'oublog', $a), array('class' => 'oublog-post-deletedby'));
     }
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-date'));
     $output .= oublog_date($post->timeposted);
     $output .= html_writer::empty_tag('br', array());
     $output .= ' ';
     if ($blogtype == 'course' || strpos($_SERVER['REQUEST_URI'], 'allposts.php') != 0) {
         $output .= html_writer::start_tag('div', array('class' => 'oublog-postedby'));
         if (!$forexport) {
             $output .= get_string('postedby', 'oublog', '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->userid . '&amp;course=' . $oublog->course . '">' . fullname($post) . '</a>');
         } else {
             $output .= get_string('postedby', 'oublog', fullname($post));
         }
         $output .= html_writer::end_tag('div');
     }
     $output .= html_writer::end_tag('div');
     if (!$oublog->individual) {
         $output .= html_writer::start_tag('div', array('class' => 'oublog-post-visibility'));
         $output .= oublog_get_visibility_string($post->visibility, $blogtype == 'personal');
         $output .= html_writer::end_tag('div');
     }
     if (isset($post->edits) && ($canaudit || $post->userid == $USER->id)) {
         $output .= html_writer::start_tag('div', array('class' => 'oublog-post-editsummary'));
         foreach ($post->edits as $edit) {
             $a = new stdClass();
             $a->editby = fullname($edit);
             $a->editdate = oublog_date($edit->timeupdated);
             if (!$forexport && !$email) {
                 if ($edit->userid == $post->userid) {
                     $output .= '- ' . html_writer::tag('a', get_string('editsummary', 'oublog', $a), array('href' => $CFG->wwwroot . '/mod/oublog/viewedit.php?edit=' . $edit->id));
                 } else {
                     $output .= '- ' . html_writer::tag('a', get_string('editonsummary', 'oublog', $a), array('href' => $CFG->wwwroot . '/mod/oublog/viewedit.php?edit=' . $edit->id));
                 }
             } else {
                 if ($edit->userid == $post->userid) {
                     $output .= '- ' . get_string('editsummary', 'oublog', $a);
                 } else {
                     $output .= '- ' . get_string('editonsummary', 'oublog', $a);
                 }
             }
             $output .= html_writer::empty_tag('br', array());
         }
         $output .= html_writer::end_tag('div');
     } else {
         if ($post->lasteditedby) {
             $edit = new StdClass();
             // Get user name fields.
             $editusernamefields = get_all_user_name_fields(false, null, 'ed');
             foreach ($editusernamefields as $namefield => $retnamefield) {
                 $edit->{$namefield} = $post->{$retnamefield};
             }
             $a = new stdClass();
             $a->editby = fullname($edit);
             $a->editdate = oublog_date($post->timeupdated);
             $output .= html_writer::tag('div', get_string('editsummary', 'oublog', $a), array('class' => 'oublog-post-editsummary'));
         }
     }
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-content'));
     if (!$forexport) {
         if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC || $email) {
             $fileurlbase = 'mod/oublog/pluginfile.php';
         } else {
             $fileurlbase = 'pluginfile.php';
         }
         $post->message = file_rewrite_pluginfile_urls($post->message, $fileurlbase, $modcontext->id, 'mod_oublog', 'message', $post->id);
     } else {
         require_once $CFG->libdir . '/portfoliolib.php';
         $post->message = portfolio_rewrite_pluginfile_urls($post->message, $modcontext->id, 'mod_oublog', 'message', $post->id, $format);
     }
     $posttextoptions = new stdClass();
     if (trusttext_active() && has_capability('moodle/site:trustcontent', $modcontext, $post->userid)) {
         // Support trusted text when initial author is safe (post editors are not checked!).
         $posttextoptions->trusted = true;
         $posttextoptions->context = $modcontext;
     }
     $output .= format_text($post->message, FORMAT_HTML, $posttextoptions);
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-bottom'));
     if (isset($post->tags)) {
         $output .= html_writer::start_tag('div', array('class' => 'oublog-post-tags')) . $strtags . ': ';
         $tagcounter = 1;
         foreach ($post->tags as $taglink) {
             $taglinktext = $taglink;
             if ($tagcounter < count($post->tags)) {
                 $taglinktext .= ',';
             }
             if (!$forexport && !$email) {
                 $output .= html_writer::tag('a', $taglinktext, array('href' => $baseurl . '&tag=' . urlencode($taglink))) . ' ';
             } else {
                 $output .= $taglinktext . ' ';
             }
             $tagcounter++;
         }
         $output .= html_writer::end_tag('div');
     }
     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-links'));
     if (!$forexport && !$email) {
         $output .= html_writer::tag('a', $strpermalink, array('href' => $CFG->wwwroot . '/mod/oublog/viewpost.php?post=' . $post->id)) . ' ';
     }
     if (!$post->deletedby) {
         if ($post->userid == $USER->id || $canmanageposts) {
             if (!$forexport && !$email) {
                 $output .= html_writer::tag('a', $stredit, array('href' => $CFG->wwwroot . '/mod/oublog/editpost.php?blog=' . $post->oublogid . '&post=' . $post->id)) . ' ';
                 if ($post->userid !== $USER->id) {
                     // Add email and 'oublog_deleteandemail' to delete link.
                     $output .= html_writer::tag('a', $strdelete, array('href' => $CFG->wwwroot . '/mod/oublog/deletepost.php?blog=' . $post->oublogid . '&post=' . $post->id . '&delete=1', 'class' => 'oublog_deleteandemail_' . $post->id));
                     self::render_oublog_print_delete_dialog($cm->id, $post->id);
                 } else {
                     $output .= html_writer::tag('a', $strdelete, array('href' => $CFG->wwwroot . '/mod/oublog/deletepost.php?blog=' . $post->oublogid . '&post=' . $post->id . '&delete=1'));
                 }
             }
         }
         // Show portfolio export link.
         if (!empty($CFG->enableportfolios) && (has_capability('mod/oublog:exportpost', $modcontext) || $post->userid == $USER->id && has_capability('mod/oublog:exportownpost', $modcontext))) {
             if (!$forexport && !$email) {
                 require_once $CFG->libdir . '/portfoliolib.php';
                 $button = new portfolio_add_button();
                 $button->set_callback_options('oublog_portfolio_caller', array('postid' => $post->id), 'mod_oublog');
                 if (empty($files)) {
                     $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
                 } else {
                     $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
                 }
                 $output .= $button->to_html(PORTFOLIO_ADD_TEXT_LINK) . ' ';
             }
         }
         // Show OU Alerts reporting link.
         if (isloggedin() && oublog_oualerts_enabled() && oublog_get_reportingemail($oublog) && !($post->userid == $USER->id) && !$post->deletedby) {
             $itemnurl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
             $reportlink = oualerts_generate_alert_form_url('oublog', $modcontext->id, 'post', $post->id, $itemnurl, $itemnurl, '', false, true);
             if ($reportlink != '' && !$forexport && !$email) {
                 $output .= html_writer::tag('a', get_string('postalert', 'oublog'), array('href' => $reportlink));
             }
         }
         // Show comments.
         if ($post->allowcomments) {
             // If this is the current user's post, show pending comments too.
             $showpendingcomments = $post->userid == $USER->id && !empty($post->pendingcomments);
             if ((isset($post->comments) || $showpendingcomments) && $commentcount) {
                 // Show number of comments.
                 if (isset($post->comments)) {
                     $linktext = get_string(count($post->comments) == 1 ? 'onecomment' : 'ncomments', 'oublog', count($post->comments));
                 }
                 // Show number of pending comments.
                 if (isset($post->pendingcomments)) {
                     // Use different string if we already have normal comments too.
                     if (isset($post->comments)) {
                         $linktext .= get_string($post->pendingcomments == 1 ? 'onependingafter' : 'npendingafter', 'oublog', $post->pendingcomments);
                     } else {
                         $linktext = get_string($post->pendingcomments == 1 ? 'onepending' : 'npending', 'oublog', $post->pendingcomments);
                     }
                 }
                 if (!$forexport) {
                     // Display link.
                     $output .= html_writer::tag('a', $linktext, array('href' => $CFG->wwwroot . '/mod/oublog/viewpost.php?post=' . $post->id . '#oublogcomments'));
                 } else {
                     $output .= $linktext;
                 }
                 // Display information about most recent comment.
                 if (isset($post->comments)) {
                     $last = array_pop($post->comments);
                     array_push($post->comments, $last);
                     $a = new stdClass();
                     if ($last->userid) {
                         $a->fullname = fullname($last);
                     } else {
                         $a->fullname = s($last->authorname);
                     }
                     $a->timeposted = oublog_date($last->timeposted, true);
                     $output .= ' ' . get_string('lastcomment', 'oublog', $a);
                 }
             } else {
                 if (oublog_can_comment($cm, $oublog, $post)) {
                     if (!$forexport && !$email) {
                         $output .= html_writer::tag('a', $strcomment, array('href' => $CFG->wwwroot . '/mod/oublog/editcomment.php?blog=' . $post->oublogid . '&post=' . $post->id));
                     }
                 }
             }
         }
     }
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     return $output;
 }
Example #16
0
/**
 * Returns attachments as formated text/html optionally with separate images
 * @param object $post
 * @param object $cm
 * @param string type - html/text/separateimages
 * @return mixed string or array of (html text withouth images and image HTML)
 */
function forum_print_attachments($post, $cm, $type)
{
    global $CFG, $DB, $USER;
    if (empty($post->attachment)) {
        return $type !== 'separateimages' ? '' : array('', '');
    }
    if (!in_array($type, array('separateimages', 'html', 'text'))) {
        return $type !== 'separateimages' ? '' : array('', '');
    }
    if (!($context = get_context_instance(CONTEXT_MODULE, $cm->id))) {
        return $type !== 'separateimages' ? '' : array('', '');
    }
    $strattachment = get_string('attachment', 'forum');
    $fs = get_file_storage();
    $browser = get_file_browser();
    $imagereturn = '';
    $output = '';
    $canexport = has_capability('mod/forum:exportpost', $context) || $post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context);
    if ($files = $fs->get_area_files($context->id, 'forum_attachment', $post->id, "timemodified", false)) {
        $button = new portfolio_add_button();
        foreach ($files as $file) {
            $filename = $file->get_filename();
            $mimetype = $file->get_mimetype();
            $icon = mimeinfo_from_type('icon', $mimetype);
            $iconimage = '<img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />';
            $path = $browser->encodepath($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/forum_attachment/' . $post->id . '/' . $filename);
            if ($type == 'html') {
                $output .= "<a href=\"{$path}\">{$iconimage}</a> ";
                $output .= "<a href=\"{$path}\">" . s($filename) . "</a>";
                if ($canexport) {
                    $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()));
                    $button->set_formats(portfolio_format_from_file($file));
                    $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
                }
                $output .= "<br />";
            } else {
                if ($type == 'text') {
                    $output .= "{$strattachment} " . s($filename) . ":\n{$path}\n";
                } else {
                    //'returnimages'
                    if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) {
                        // Image attachments don't get printed as links
                        $imagereturn .= "<br /><img src=\"{$path}\" alt=\"\" />";
                        if ($canexport) {
                            $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()));
                            $button->set_formats(portfolio_format_from_file($file));
                            $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
                        }
                    } else {
                        $output .= "<a href=\"{$path}\">{$iconimage}</a> ";
                        $output .= filter_text("<a href=\"{$path}\">" . s($filename) . "</a>");
                        if ($canexport) {
                            $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()));
                            $button->set_formats(portfolio_format_from_file($file));
                            $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
                        }
                        $output .= '<br />';
                    }
                }
            }
        }
    }
    if ($type !== 'separateimages') {
        return $output;
    } else {
        return array($output, $imagereturn);
    }
}
 /**
  * @param stdClass $post
  * @param stdClass $discussion
  * @param stdClass $cm
  * @param bool $canreply
  * @return array
  * @throws coding_exception
  * @author Mark Nielsen
  */
 public function post_get_commands($post, $discussion, $cm, $canreply)
 {
     global $CFG, $USER;
     $discussionlink = new moodle_url('/mod/hsuforum/discuss.php', array('d' => $post->discussion));
     $ownpost = (isloggedin() and $post->userid == $USER->id);
     $commands = array();
     if (!property_exists($post, 'privatereply')) {
         throw new coding_exception('Must set post\'s privatereply property!');
     }
     $forum = hsuforum_get_cm_forum($cm);
     if ($canreply and empty($post->privatereply)) {
         $postuser = hsuforum_extract_postuser($post, $forum, context_module::instance($cm->id));
         $replytitle = get_string('replybuttontitle', 'hsuforum', strip_tags($postuser->fullname));
         $commands['reply'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('reply' => $post->id)), get_string('reply', 'hsuforum'), array('title' => $replytitle, 'class' => 'hsuforum-reply-link btn btn-default'));
     }
     // Hack for allow to edit news posts those are not displayed yet until they are displayed
     $age = time() - $post->created;
     if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
         $age = 0;
     }
     if ($ownpost && $age < $CFG->maxeditingtime || local::cached_has_capability('mod/hsuforum:editanypost', context_module::instance($cm->id))) {
         $commands['edit'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('edit' => $post->id)), get_string('edit', 'hsuforum'));
     }
     if ($ownpost && $age < $CFG->maxeditingtime && local::cached_has_capability('mod/hsuforum:deleteownpost', context_module::instance($cm->id)) || local::cached_has_capability('mod/hsuforum:deleteanypost', context_module::instance($cm->id))) {
         $commands['delete'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('delete' => $post->id)), get_string('delete', 'hsuforum'));
     }
     if (local::cached_has_capability('mod/hsuforum:splitdiscussions', context_module::instance($cm->id)) && $post->parent && !$post->privatereply && $forum->type != 'single') {
         $commands['split'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('prune' => $post->id)), get_string('prune', 'hsuforum'), array('title' => get_string('pruneheading', 'hsuforum')));
     }
     if ($CFG->enableportfolios && empty($forum->anonymous) && (local::cached_has_capability('mod/hsuforum:exportpost', context_module::instance($cm->id)) || $ownpost && local::cached_has_capability('mod/hsuforum:exportownpost', context_module::instance($cm->id)))) {
         require_once $CFG->libdir . '/portfoliolib.php';
         $button = new portfolio_add_button();
         $button->set_callback_options('hsuforum_portfolio_caller', array('postid' => $post->id), 'mod_hsuforum');
         list($attachments, $attachedimages) = hsuforum_print_attachments($post, $cm, 'separateimages');
         if (empty($attachments)) {
             $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
         } else {
             $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
         }
         $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
         if (!empty($porfoliohtml)) {
             $commands['portfolio'] = $porfoliohtml;
         }
     }
     $rating = $this->post_rating($post);
     if (!empty($rating)) {
         $commands['rating'] = $rating;
     }
     return $commands;
 }
Example #18
0
 /**
  * Render the content in editor that is often used by plugin.
  *
  * @param string $filearea
  * @param int  $submissionid
  * @param string $plugintype
  * @param string $editor
  * @param string $component
  * @return string
  */
 public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component)
 {
     global $CFG;
     $result = '';
     $plugin = $this->get_submission_plugin_by_type($plugintype);
     $text = $plugin->get_editor_text($editor, $submissionid);
     $format = $plugin->get_editor_format($editor, $submissionid);
     $finaltext = file_rewrite_pluginfile_urls($text, 'pluginfile.php', $this->get_context()->id, $component, $filearea, $submissionid);
     $params = array('overflowdiv' => true, 'context' => $this->get_context());
     $result .= format_text($finaltext, $format, $params);
     if ($CFG->enableportfolios) {
         require_once $CFG->libdir . '/portfoliolib.php';
         $button = new portfolio_add_button();
         $portfolioparams = array('cmid' => $this->get_course_module()->id, 'sid' => $submissionid, 'plugin' => $plugintype, 'editor' => $editor, 'area' => $filearea);
         $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign');
         $fs = get_file_storage();
         if ($files = $fs->get_area_files($this->context->id, $component, $filearea, $submissionid, 'timemodified', false)) {
             $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
         } else {
             $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
         }
         $result .= $button->to_html();
     }
     return $result;
 }
Example #19
0
                echo $data->listtemplatefooter;

                echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
            }

        }
    }

    $search = trim($search);
    if (empty($records)) {
        $records = array();
    }

    if ($mode == '' && !empty($CFG->enableportfolios)) {
        require_once($CFG->libdir . '/portfoliolib.php');
        $button = new portfolio_add_button();
        $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), '/mod/data/locallib.php');
        if (data_portfolio_caller::has_files($data)) {
            $button->set_formats(array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A)); // no plain html for us
        }
        echo $button->to_html(PORTFOLIO_ADD_FULL_FORM);
    }

    //Advanced search form doesn't make sense for single (redirects list view)
    if (($maxcount || $mode == 'asearch') && $mode != 'single') {
        data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
    }
}

echo $OUTPUT->footer();
Example #20
0
/**
 * Print a forum post
 *
 * @global object
 * @global object
 * @uses FORUM_MODE_THREADED
 * @uses PORTFOLIO_FORMAT_PLAINHTML
 * @uses PORTFOLIO_FORMAT_FILE
 * @uses PORTFOLIO_FORMAT_RICHHTML
 * @uses PORTFOLIO_ADD_TEXT_LINK
 * @uses CONTEXT_MODULE
 * @param object $post The post to print.
 * @param object $discussion
 * @param object $forum
 * @param object $cm
 * @param object $course
 * @param boolean $ownpost Whether this post belongs to the current user.
 * @param boolean $reply Whether to print a 'reply' link at the bottom of the message.
 * @param boolean $link Just print a shortened version of the post as a link to the full post.
 * @param string $footer Extra stuff to print after the message.
 * @param string $highlight Space-separated list of terms to highlight.
 * @param int $post_read true, false or -99. If we already know whether this user
 *          has read this post, pass that in, otherwise, pass in -99, and this
 *          function will work it out.
 * @param boolean $dummyifcantsee When forum_user_can_see_post says that
 *          the current user can't see this post, if this argument is true
 *          (the default) then print a dummy 'you can't see this post' post.
 *          If false, don't output anything at all.
 * @param bool|null $istracked
 * @return void
 */
function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=false, $reply=false, $link=false,
                          $footer="", $highlight="", $postisread=null, $dummyifcantsee=true, $istracked=null, $return=false) {
    global $USER, $CFG, $OUTPUT;

    require_once($CFG->libdir . '/filelib.php');

    // String cache
    static $str;

    $modcontext = context_module::instance($cm->id);

    $post->course = $course->id;
    $post->forum  = $forum->id;
    $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id);
    if (!empty($CFG->enableplagiarism)) {
        require_once($CFG->libdir.'/plagiarismlib.php');
        $post->message .= plagiarism_get_links(array('userid' => $post->userid,
            'content' => $post->message,
            'cmid' => $cm->id,
            'course' => $post->course,
            'forum' => $post->forum));
    }

    // caching
    if (!isset($cm->cache)) {
        $cm->cache = new stdClass;
    }

    if (!isset($cm->cache->caps)) {
        $cm->cache->caps = array();
        $cm->cache->caps['mod/forum:viewdiscussion']   = has_capability('mod/forum:viewdiscussion', $modcontext);
        $cm->cache->caps['moodle/site:viewfullnames']  = has_capability('moodle/site:viewfullnames', $modcontext);
        $cm->cache->caps['mod/forum:editanypost']      = has_capability('mod/forum:editanypost', $modcontext);
        $cm->cache->caps['mod/forum:splitdiscussions'] = has_capability('mod/forum:splitdiscussions', $modcontext);
        $cm->cache->caps['mod/forum:deleteownpost']    = has_capability('mod/forum:deleteownpost', $modcontext);
        $cm->cache->caps['mod/forum:deleteanypost']    = has_capability('mod/forum:deleteanypost', $modcontext);
        $cm->cache->caps['mod/forum:viewanyrating']    = has_capability('mod/forum:viewanyrating', $modcontext);
        $cm->cache->caps['mod/forum:exportpost']       = has_capability('mod/forum:exportpost', $modcontext);
        $cm->cache->caps['mod/forum:exportownpost']    = has_capability('mod/forum:exportownpost', $modcontext);
    }

    if (!isset($cm->uservisible)) {
        $cm->uservisible = coursemodule_visible_for_user($cm);
    }

    if ($istracked && is_null($postisread)) {
        $postisread = forum_tp_is_post_read($USER->id, $post);
    }

    if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) {
        $output = '';
        if (!$dummyifcantsee) {
            if ($return) {
                return $output;
            }
            echo $output;
            return;
        }
        $output .= html_writer::tag('a', '', array('id'=>'p'.$post->id));
        $output .= html_writer::start_tag('div', array('class'=>'forumpost clearfix'));
        $output .= html_writer::start_tag('div', array('class'=>'row header'));
        $output .= html_writer::tag('div', '', array('class'=>'left picture')); // Picture
        if ($post->parent) {
            $output .= html_writer::start_tag('div', array('class'=>'topic'));
        } else {
            $output .= html_writer::start_tag('div', array('class'=>'topic starter'));
        }
        $output .= html_writer::tag('div', get_string('forumsubjecthidden','forum'), array('class'=>'subject')); // Subject
        $output .= html_writer::tag('div', get_string('forumauthorhidden','forum'), array('class'=>'author')); // author
        $output .= html_writer::end_tag('div');
        $output .= html_writer::end_tag('div'); // row
        $output .= html_writer::start_tag('div', array('class'=>'row'));
        $output .= html_writer::tag('div', '&nbsp;', array('class'=>'left side')); // Groups
        $output .= html_writer::tag('div', get_string('forumbodyhidden','forum'), array('class'=>'content')); // Content
        $output .= html_writer::end_tag('div'); // row
        $output .= html_writer::end_tag('div'); // forumpost

        if ($return) {
            return $output;
        }
        echo $output;
        return;
    }

    if (empty($str)) {
        $str = new stdClass;
        $str->edit         = get_string('edit', 'forum');
        $str->delete       = get_string('delete', 'forum');
        $str->reply        = get_string('reply', 'forum');
        $str->parent       = get_string('parent', 'forum');
        $str->pruneheading = get_string('pruneheading', 'forum');
        $str->prune        = get_string('prune', 'forum');
        $str->displaymode     = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
        $str->markread     = get_string('markread', 'forum');
        $str->markunread   = get_string('markunread', 'forum');
    }

    $discussionlink = new moodle_url('/mod/forum/discuss.php', array('d'=>$post->discussion));

    // Build an object that represents the posting user
    $postuser = new stdClass;
    $postuser->id        = $post->userid;
    $postuser->firstname = $post->firstname;
    $postuser->lastname  = $post->lastname;
    $postuser->imagealt  = $post->imagealt;
    $postuser->picture   = $post->picture;
    $postuser->email     = $post->email;
    // Some handy things for later on
    $postuser->fullname    = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']);
    $postuser->profilelink = new moodle_url('/user/view.php', array('id'=>$post->userid, 'course'=>$course->id));

    // Prepare the groups the posting user belongs to
    if (isset($cm->cache->usersgroups)) {
        $groups = array();
        if (isset($cm->cache->usersgroups[$post->userid])) {
            foreach ($cm->cache->usersgroups[$post->userid] as $gid) {
                $groups[$gid] = $cm->cache->groups[$gid];
            }
        }
    } else {
        $groups = groups_get_all_groups($course->id, $post->userid, $cm->groupingid);
    }

    // Prepare the attachements for the post, files then images
    list($attachments, $attachedimages) = forum_print_attachments($post, $cm, 'separateimages');

    // Determine if we need to shorten this post
    $shortenpost = ($link && (strlen(strip_tags($post->message)) > $CFG->forum_longpost));


    // Prepare an array of commands
    $commands = array();

    // SPECIAL CASE: The front page can display a news item post to non-logged in users.
    // Don't display the mark read / unread controls in this case.
    if ($istracked && $CFG->forum_usermarksread && isloggedin()) {
        $url = new moodle_url($discussionlink, array('postid'=>$post->id, 'mark'=>'unread'));
        $text = $str->markunread;
        if (!$postisread) {
            $url->param('mark', 'read');
            $text = $str->markread;
        }
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p'.$post->id);
        }
        $commands[] = array('url'=>$url, 'text'=>$text);
    }

    // Zoom in to the parent specifically
    if ($post->parent) {
        $url = new moodle_url($discussionlink);
        if ($str->displaymode == FORUM_MODE_THREADED) {
            $url->param('parent', $post->parent);
        } else {
            $url->set_anchor('p'.$post->parent);
        }
        $commands[] = array('url'=>$url, 'text'=>$str->parent);
    }

    // Hack for allow to edit news posts those are not displayed yet until they are displayed
    $age = time() - $post->created;
    if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
        $age = 0;
    }

    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        if (has_capability('moodle/course:manageactivities', $modcontext)) {
            // The first post in single simple is the forum description.
            $commands[] = array('url'=>new moodle_url('/course/modedit.php', array('update'=>$cm->id, 'sesskey'=>sesskey(), 'return'=>1)), 'text'=>$str->edit);
        }
    } else if (($ownpost && $age < $CFG->maxeditingtime) || $cm->cache->caps['mod/forum:editanypost']) {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('edit'=>$post->id)), 'text'=>$str->edit);
    }

    if ($cm->cache->caps['mod/forum:splitdiscussions'] && $post->parent && $forum->type != 'single') {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('prune'=>$post->id)), 'text'=>$str->prune, 'title'=>$str->pruneheading);
    }

    if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
        // Do not allow deleting of first post in single simple type.
    } else if (($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost']) || $cm->cache->caps['mod/forum:deleteanypost']) {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('delete'=>$post->id)), 'text'=>$str->delete);
    }

    if ($reply) {
        $commands[] = array('url'=>new moodle_url('/mod/forum/post.php#mformforum', array('reply'=>$post->id)), 'text'=>$str->reply);
    }

    if ($CFG->enableportfolios && ($cm->cache->caps['mod/forum:exportpost'] || ($ownpost && $cm->cache->caps['mod/forum:exportownpost']))) {
        $p = array('postid' => $post->id);
        require_once($CFG->libdir.'/portfoliolib.php');
        $button = new portfolio_add_button();
        $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id), 'mod_forum');
        if (empty($attachments)) {
            $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
        } else {
            $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
        }

        $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
        if (!empty($porfoliohtml)) {
            $commands[] = $porfoliohtml;
        }
    }
    // Finished building commands


    // Begin output

    $output  = '';

    if ($istracked) {
        if ($postisread) {
            $forumpostclass = ' read';
        } else {
            $forumpostclass = ' unread';
            $output .= html_writer::tag('a', '', array('name'=>'unread'));
        }
    } else {
        // ignore trackign status if not tracked or tracked param missing
        $forumpostclass = '';
    }

    $topicclass = '';
    if (empty($post->parent)) {
        $topicclass = ' firstpost starter';
    }

    $output .= html_writer::tag('a', '', array('id'=>'p'.$post->id));
    $output .= html_writer::start_tag('div', array('class'=>'forumpost clearfix'.$forumpostclass.$topicclass));
    $output .= html_writer::start_tag('div', array('class'=>'row header clearfix'));
    $output .= html_writer::start_tag('div', array('class'=>'left picture'));
    $output .= $OUTPUT->user_picture($postuser, array('courseid'=>$course->id));
    $output .= html_writer::end_tag('div');


    $output .= html_writer::start_tag('div', array('class'=>'topic'.$topicclass));

    $postsubject = $post->subject;
    if (empty($post->subjectnoformat)) {
        $postsubject = format_string($postsubject);
    }
    $output .= html_writer::tag('div', $postsubject, array('class'=>'subject'));

    $by = new stdClass();
    $by->name = html_writer::link($postuser->profilelink, $postuser->fullname);
    $by->date = userdate($post->modified);
    $output .= html_writer::tag('div', get_string('bynameondate', 'forum', $by), array('class'=>'author'));

    $output .= html_writer::end_tag('div'); //topic
    $output .= html_writer::end_tag('div'); //row

    $output .= html_writer::start_tag('div', array('class'=>'row maincontent clearfix'));
    $output .= html_writer::start_tag('div', array('class'=>'left'));

    $groupoutput = '';
    if ($groups) {
        $groupoutput = print_group_picture($groups, $course->id, false, true, true);
    }
    if (empty($groupoutput)) {
        $groupoutput = '&nbsp;';
    }
    $output .= html_writer::tag('div', $groupoutput, array('class'=>'grouppictures'));

    $output .= html_writer::end_tag('div'); //left side
    $output .= html_writer::start_tag('div', array('class'=>'no-overflow'));
    $output .= html_writer::start_tag('div', array('class'=>'content'));
    if (!empty($attachments)) {
        $output .= html_writer::tag('div', $attachments, array('class'=>'attachments'));
    }

    $options = new stdClass;
    $options->para    = false;
    $options->trusted = $post->messagetrust;
    $options->context = $modcontext;
    if ($shortenpost) {
        // Prepare shortened version
        $postclass    = 'shortenedpost';
        $postcontent  = format_text(forum_shorten_post($post->message), $post->messageformat, $options, $course->id);
        $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum'));
        $postcontent .= html_writer::tag('div', '('.get_string('numwords', 'moodle', count_words($post->message)).')',
            array('class'=>'post-word-count'));
    } else {
        // Prepare whole post
        $postclass    = 'fullpost';
        $postcontent  = format_text($post->message, $post->messageformat, $options, $course->id);
        if (!empty($highlight)) {
            $postcontent = highlight($highlight, $postcontent);
        }
        if (!empty($forum->displaywordcount)) {
            $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)),
                array('class'=>'post-word-count'));
        }
        $postcontent .= html_writer::tag('div', $attachedimages, array('class'=>'attachedimages'));
    }

    // Output the post content
    $output .= html_writer::tag('div', $postcontent, array('class'=>'posting '.$postclass));
    $output .= html_writer::end_tag('div'); // Content
    $output .= html_writer::end_tag('div'); // Content mask
    $output .= html_writer::end_tag('div'); // Row

    $output .= html_writer::start_tag('div', array('class'=>'row side'));
    $output .= html_writer::tag('div','&nbsp;', array('class'=>'left'));
    $output .= html_writer::start_tag('div', array('class'=>'options clearfix'));

    // Output ratings
    if (!empty($post->rating)) {
        $output .= html_writer::tag('div', $OUTPUT->render($post->rating), array('class'=>'forum-post-rating'));
    }

    // Output the commands
    $commandhtml = array();
    foreach ($commands as $command) {
        if (is_array($command)) {
            $commandhtml[] = html_writer::link($command['url'], $command['text']);
        } else {
            $commandhtml[] = $command;
        }
    }
    $output .= html_writer::tag('div', implode(' | ', $commandhtml), array('class'=>'commands'));

    // Output link to post if required
    if ($link) {
        if ($post->replies == 1) {
            $replystring = get_string('repliesone', 'forum', $post->replies);
        } else {
            $replystring = get_string('repliesmany', 'forum', $post->replies);
        }

        $output .= html_writer::start_tag('div', array('class'=>'link'));
        $output .= html_writer::link($discussionlink, get_string('discussthistopic', 'forum'));
        $output .= '&nbsp;('.$replystring.')';
        $output .= html_writer::end_tag('div'); // link
    }

    // Output footer if required
    if ($footer) {
        $output .= html_writer::tag('div', $footer, array('class'=>'footer'));
    }

    // Close remaining open divs
    $output .= html_writer::end_tag('div'); // content
    $output .= html_writer::end_tag('div'); // row
    $output .= html_writer::end_tag('div'); // forumpost

    // Mark the forum post as read if required
    if ($istracked && !$CFG->forum_usermarksread && !$postisread) {
        forum_tp_mark_post_read($USER->id, $post, $forum->id);
    }

    if ($return) {
        return $output;
    }
    echo $output;
    return;
}
 /**
  * Renders the 'export entire wiki' link.
  *
  * @param object $subwiki Subwiki data object
  * @param bool $anyfiles True if any page of subwiki contains files
  * @param array $wikiparamsarray associative array
  * @return string HTML content of list item with link, or nothing if none
  */
 public function render_export_all_li($subwiki, $anyfiles, $wikiparamsarray)
 {
     global $CFG;
     if (!$CFG->enableportfolios) {
         return '';
     }
     $button = new portfolio_add_button();
     $button->set_callback_options('ouwiki_all_portfolio_caller', $wikiparamsarray, 'mod_ouwiki');
     if ($anyfiles) {
         $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
     } else {
         $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
     }
     return html_writer::tag('li', $button->to_html(PORTFOLIO_ADD_TEXT_LINK));
 }