示例#1
0
 function get_content()
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     $filteropt = new stdClass();
     $filteropt->overflowdiv = true;
     if ($this->content_is_trusted()) {
         // fancy html allowed only on course, category and system blocks.
         $filteropt->noclean = true;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     if (isset($this->config->text)) {
         // rewrite url
         $this->config->text = file_rewrite_pluginfile_urls($this->config->text, 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
         // Default to FORMAT_HTML which is what will have been used before the
         // editor was properly implemented for the block.
         $format = FORMAT_HTML;
         // Check to see if the format has been properly set on the config
         if (isset($this->config->format)) {
             $format = $this->config->format;
         }
         $this->content->text = format_text($this->config->text, $format, $filteropt);
     } else {
         $this->content->text = '';
     }
     unset($filteropt);
     // memory footprint
     return $this->content;
 }
示例#2
0
 /**
  * Renders course info box.
  *
  * @param stdClass $course
  * @return string
  */
 public function course_info_box(stdClass $course)
 {
     global $CFG;
     $context = context_course::instance($course->id);
     $content = '';
     $content .= $this->output->box_start('generalbox info');
     $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null);
     $content .= format_text($summary, $course->summaryformat, array('overflowdiv' => true), $course->id);
     if (!empty($CFG->coursecontact)) {
         $coursecontactroles = explode(',', $CFG->coursecontact);
         foreach ($coursecontactroles as $roleid) {
             if ($users = get_role_users($roleid, $context, true)) {
                 foreach ($users as $teacher) {
                     $role = new stdClass();
                     $role->id = $teacher->roleid;
                     $role->name = $teacher->rolename;
                     $role->shortname = $teacher->roleshortname;
                     $role->coursealias = $teacher->rolecoursealias;
                     $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
                     $namesarray[] = role_get_name($role, $context) . ': <a href="' . $CFG->wwwroot . '/user/view.php?id=' . $teacher->id . '&amp;course=' . SITEID . '">' . $fullname . '</a>';
                 }
             }
         }
         if (!empty($namesarray)) {
             $content .= "<ul class=\"teachers\">\n<li>";
             $content .= implode('</li><li>', $namesarray);
             $content .= "</li></ul>";
         }
     }
     $content .= $this->output->box_end();
     return $content;
 }
示例#3
0
 /**
  * Returns list of courses that we offer to the caller for remote enrolment of their users
  *
  * Since Moodle 2.0, courses are made available for MNet peers by creating an instance
  * of enrol_mnet plugin for the course. Hidden courses are not returned. If there are two
  * instances - one specific for the host and one for 'All hosts', the setting of the specific
  * one is used. The id of the peer is kept in customint1, no other custom fields are used.
  *
  * @uses mnet_remote_client Callable via XML-RPC only
  * @return array
  */
 public function available_courses()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/filelib.php';
     if (!($client = get_mnet_remote_client())) {
         die('Callable via XML-RPC only');
     }
     // we call our id as 'remoteid' because it will be sent to the peer
     // the column aliases are required by MNet protocol API for clients 1.x and 2.0
     $sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat,\n                       c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name,\n                       cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat,\n                       e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename,\n                       e.customint1\n                  FROM {enrol} e\n            INNER JOIN {course} c ON c.id = e.courseid\n            INNER JOIN {course_categories} cat ON cat.id = c.category\n            INNER JOIN {role} r ON r.id = e.roleid\n                 WHERE e.enrol = 'mnet'\n                       AND (e.customint1 = 0 OR e.customint1 = ?)\n                       AND c.visible = 1\n              ORDER BY cat.sortorder, c.sortorder, c.shortname";
     $rs = $DB->get_recordset_sql($sql, array($client->id));
     $courses = array();
     foreach ($rs as $course) {
         // use the record if it does not exist yet or is host-specific
         if (empty($courses[$course->remoteid]) or $course->customint1 > 0) {
             unset($course->customint1);
             // the client does not need to know this
             $context = get_context_instance(CONTEXT_COURSE, $course->remoteid);
             // Rewrite file URLs so that they are correct
             $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', false);
             $courses[$course->remoteid] = $course;
         }
     }
     $rs->close();
     return array_values($courses);
     // can not use keys for backward compatibility
 }
 function get_content()
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     $filteropt = new stdClass();
     $filteropt->overflowdiv = true;
     if ($this->content_is_trusted()) {
         // fancy html allowed only on course, category and system blocks.
         $filteropt->noclean = true;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     if (isset($this->config->text)) {
         // rewrite url
         $this->config->text = file_rewrite_pluginfile_urls($this->config->text, 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
         $this->content->text = format_text($this->config->text, $this->config->format, $filteropt);
     } else {
         $this->content->text = '';
     }
     unset($filteropt);
     // memory footprint
     return $this->content;
 }
示例#5
0
 /**
  * The HTML version of the e-mail message.
  *
  * @param \stdClass $cm
  * @param \stdClass $post
  * @return string
  */
 public function format_message_text($cm, $post)
 {
     $message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', \context_module::instance($cm->id)->id, 'mod_forum', 'post', $post->id);
     $options = new \stdClass();
     $options->para = true;
     return format_text($message, $post->messageformat, $options);
 }
 function get_content()
 {
     global $CFG, $OUTPUT;
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return '';
     }
     $this->content = new stdClass();
     $options = new stdClass();
     $options->noclean = true;
     // Don't clean Javascripts etc
     $options->overflowdiv = true;
     $context = context_course::instance($this->page->course->id);
     $this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
     $this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options);
     if ($this->page->user_is_editing()) {
         if ($this->page->course->id == SITEID) {
             $editpage = $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=frontpagesettings';
         } else {
             $editpage = $CFG->wwwroot . '/course/edit.php?id=' . $this->page->course->id;
         }
         $this->content->text .= "<div class=\"editbutton\"><a href=\"{$editpage}\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" alt=\"" . get_string('edit') . "\" /></a></div>";
     }
     $this->content->footer = '';
     return $this->content;
 }
示例#7
0
 /**
  * Generate html for a section summary text
  *
  * @param stdClass $section The course_section entry from DB
  * @return string HTML to output.
  */
 protected function format_summary_text($section)
 {
     $context = context_course::instance($section->course);
     $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
     $options = new stdClass();
     $options->noclean = true;
     $options->overflowdiv = true;
     return format_text($summarytext, $section->summaryformat, $options);
 }
function groupselect_get_group_info($group)
{
    $group = clone $group;
    $context = context_course::instance($group->courseid);
    $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id);
    if (!isset($group->descriptionformat)) {
        $group->descriptionformat = FORMAT_MOODLE;
    }
    $options = new stdClass();
    $options->overflowdiv = true;
    return format_text($group->description, $group->descriptionformat, array('filter' => false, 'overflowdiv' => true, 'context' => $context));
}
示例#9
0
function realtimequiz_send_question($quizid, $context, $preview = false)
{
    global $DB;
    if (!($quiz = $DB->get_record('realtimequiz', array('id' => $quizid)))) {
        realtimequiz_send_error(get_string('badquizid', 'realtimequiz') . $quizid);
    } else {
        $questionid = $quiz->currentquestion;
        if (!($question = $DB->get_record('realtimequiz_question', array('id' => $questionid)))) {
            realtimequiz_send_error(get_string('badcurrentquestion', 'realtimequiz') . $questionid);
        } else {
            $answers = $DB->get_records('realtimequiz_answer', array('questionid' => $questionid), 'id');
            $questioncount = $DB->count_records('realtimequiz_question', array('quizid' => $quizid));
            echo '<status>showquestion</status>';
            echo "<question><questionnumber>{$question->questionnum}</questionnumber>";
            echo "<questioncount>{$questioncount}</questioncount>";
            $questiontext = format_text($question->questiontext, $question->questiontextformat);
            $questiontext = file_rewrite_pluginfile_urls($questiontext, 'pluginfile.php', $context->id, 'mod_realtimequiz', 'question', $questionid);
            echo "<questiontext><![CDATA[{$questiontext}]]></questiontext>";
            if ($preview) {
                $previewtime = $quiz->nextendtime - time();
                if ($previewtime > 0) {
                    echo "<delay>{$previewtime}</delay>";
                }
                $questiontime = $question->questiontime;
                if ($questiontime == 0) {
                    $questiontime = $quiz->questiontime;
                }
                echo "<questiontime>{$questiontime}</questiontime>";
            } else {
                $questiontime = $quiz->nextendtime - time();
                if ($questiontime < 0) {
                    $questiontime = 0;
                }
                echo "<questiontime>{$questiontime}</questiontime>";
            }
            echo '<answers>';
            foreach ($answers as $answer) {
                $answertext = $answer->answertext;
                echo "<answer id='{$answer->id}'><![CDATA[{$answertext}]]></answer>";
            }
            echo '</answers>';
            echo '</question>';
        }
    }
}
示例#10
0
 public function search_result($records, $subwiki) {
     global $CFG, $PAGE;
     $table = new html_table();
     $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id);
     $strsearchresults = get_string('searchresult', 'wiki');
     $totalcount = count($records);
     $html = $this->output->heading("$strsearchresults $totalcount");
     foreach ($records as $page) {
         $table->head = array('title' => format_string($page->title) . ' (' . html_writer::link($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $page->id, get_string('view', 'wiki')) . ')');
         $table->align = array('title' => 'left');
         $table->width = '100%';
         $table->data = array(array(file_rewrite_pluginfile_urls(format_text($page->cachedcontent, FORMAT_HTML), 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $subwiki->id)));
         $table->colclasses = array('wikisearchresults');
         $html .= html_writer::table($table);
     }
     $html = html_writer::tag('div', $html, array('class'=>'no-overflow'));
     return $this->output->container($html);
 }
示例#11
0
 function get_content()
 {
     global $CFG, $OUTPUT;
     require_once $CFG->libdir . '/filelib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return '';
     }
     $this->content = new stdClass();
     $options = new stdClass();
     $options->noclean = true;
     // Don't clean Javascripts etc
     $options->overflowdiv = true;
     $context = context_course::instance($this->page->course->id);
     $this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL);
     $this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options);
     $this->content->footer = '';
     return $this->content;
 }
示例#12
0
/**
 * implements a hook for the page_module block to add
 * the link allowing live refreshing of the content
 *
 *
 */
function customlabel_set_instance(&$block)
{
    global $USER, $CFG, $COURSE, $DB;
    // Transfer content from title to content.
    $block->title = '';
    // Fake unpacks object's load.
    $data = json_decode(base64_decode($block->moduleinstance->content));
    // If failed in getting content. It happens sometimes, ... do nothing to let content be safed manually
    if (is_null($data) || !is_object($data)) {
        return false;
    }
    // Realize a pseudo update.
    $data->title = $block->moduleinstance->title;
    $data->content = $block->moduleinstance->content;
    $data->labelclass = $block->moduleinstance->labelclass;
    // fixes broken serialized contents
    $context = context_module::instance($block->cm->id);
    if (!has_capability('customlabeltype/' . $data->labelclass . ':view', $context)) {
        return false;
    }
    if (!isset($block->moduleinstance->title)) {
        // Fixes broken serialized contents.
        $block->moduleinstance->title = '';
    }
    $instance = customlabel_load_class($data);
    $block->moduleinstance->processedcontent = $instance->make_content();
    $block->moduleinstance->name = $instance->title;
    // this realizes the template
    $block->moduleinstance->timemodified = time();
    $block->content->text = $block->moduleinstance->processedcontent;
    $block->moduleinstance->title = str_replace("'", "''", $block->moduleinstance->title);
    $result = $DB->update_record('customlabel', $block->moduleinstance);
    $context = context_module::instance($block->cm->id);
    $block->content->text = file_rewrite_pluginfile_urls($block->content->text, 'pluginfile.php', $context->id, 'mod_customlabel', 'contentfiles', 0);
    return true;
}
示例#13
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;
}
示例#14
0
文件: weblib.php 项目: hatone/moodle
/**
 * Formats activity intro text
 *
 * @global object
 * @uses CONTEXT_MODULE
 * @param string $module name of module
 * @param object $activity instance of activity
 * @param int $cmid course module id
 * @param bool $filter filter resulting html text
 * @return text
 */
function format_module_intro($module, $activity, $cmid, $filter = true)
{
    global $CFG;
    require_once "{$CFG->libdir}/filelib.php";
    $context = get_context_instance(CONTEXT_MODULE, $cmid);
    $options = array('noclean' => true, 'para' => false, 'filter' => $filter, 'context' => $context, 'overflowdiv' => true);
    $intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, 'mod_' . $module, 'intro', null);
    return trim(format_text($intro, $activity->introformat, $options, null));
}
示例#15
0
文件: pagelib.php 项目: Burick/moodle
    /**
     * Given an old page version, output the version content
     *
     * @global object $CFG
     * @global object $OUTPUT
     * @global object $PAGE
     */
    private function print_version_view() {
        global $CFG, $OUTPUT, $PAGE;
        $pageversion = wiki_get_version($this->version->id);

        if ($pageversion) {
            $restorelink = new moodle_url('/mod/wiki/restoreversion.php', array('pageid' => $this->page->id, 'versionid' => $this->version->id));
            echo $OUTPUT->heading(get_string('viewversion', 'wiki', $pageversion->version) . '<br />' . html_writer::link($restorelink->out(false), '(' . get_string('restorethis', 'wiki') . ')', array('class' => 'wiki_restore')) . '&nbsp;', 4);
            $userinfo = wiki_get_user_info($pageversion->userid);
            $heading = '<p><strong>' . get_string('modified', 'wiki') . ':</strong>&nbsp;' . userdate($pageversion->timecreated, get_string('strftimedatetime', 'langconfig'));
            $viewlink = new moodle_url('/user/view.php', array('id' => $userinfo->id));
            $heading .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('user') . ':</strong>&nbsp;' . html_writer::link($viewlink->out(false), fullname($userinfo));
            $heading .= '&nbsp;&nbsp;&rarr;&nbsp;' . $OUTPUT->user_picture(wiki_get_user_info($pageversion->userid), array('popup' => true)) . '</p>';
            print_container($heading, false, 'mdl-align wiki_modifieduser wiki_headingtime');
            $options = array('swid' => $this->subwiki->id, 'pretty_print' => true, 'pageid' => $this->page->id);

            $pageversion->content = file_rewrite_pluginfile_urls($pageversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);

            $parseroutput = wiki_parse_content($pageversion->contentformat, $pageversion->content, $options);
            $content = print_container(format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true)), false, '', '', true);
            echo $OUTPUT->box($content, 'generalbox wiki_contentbox');

        } else {
            print_error('versionerror', 'wiki');
        }
    }
示例#16
0
}

// Trigger a user profile viewed event.
profile_view($user, $usercontext);

// TODO WORK OUT WHERE THE NAV BAR IS!
echo $OUTPUT->header();
echo '<div class="userprofile">';

if ($user->description && !isset($hiddenfields['description'])) {
    echo '<div class="description">';
    if (!empty($CFG->profilesforenrolledusersonly) && !$currentuser &&
        !$DB->record_exists('role_assignments', array('userid' => $user->id))) {
        echo get_string('profilenotshown', 'moodle');
    } else {
        $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user',
                                                          'profile', null);
        echo format_text($user->description, $user->descriptionformat);
    }
    echo '</div>';
}

echo $OUTPUT->custom_block_region('content');

// Render custom blocks.
$renderer = $PAGE->get_renderer('core_user', 'myprofile');
$tree = core_user\output\myprofile\manager::build_tree($user, $currentuser);
echo $renderer->render($tree);

echo '</div>';  // Userprofile class.

echo $OUTPUT->footer();
 public function get_content()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/filelib.php';
     $this->page->requires->js('/blocks/slideshow/js/jquery.cycle2.min.js');
     $this->page->requires->js('/blocks/slideshow/js/spectrum.js');
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     if (!empty($this->config->text)) {
         $this->content->text = $this->config->text;
     } else {
         $this->content->text = '';
     }
     if (!empty($this->config->background)) {
         $this->content->background = $this->config->background;
     } else {
         $this->content->background = '#000000';
     }
     if (!empty($this->config->transparent)) {
         $this->content->transparent = $this->config->transparent;
     } else {
         $this->content->transparent = '';
     }
     if (!empty($this->config->normalblock)) {
         $this->content->normalblock = $this->config->normalblock;
     } else {
         $this->content->normalblock = '';
     }
     if (!empty($this->config->transition)) {
         $this->content->transition = $this->config->transition;
     } else {
         $this->content->transition = 'fade';
     }
     if (!empty($this->config->slidedelay)) {
         $this->content->slidedelay = $this->config->slidedelay;
     } else {
         $this->content->slidedelay = '4000';
     }
     if (!empty($this->config->slidespeed)) {
         $this->content->slidespeed = $this->config->slidespeed;
     } else {
         $this->content->slidespeed = '1000';
     }
     $this->content->text = '<div id="page-slideshow">';
     file_rewrite_pluginfile_urls($this->content->text, 'pluginfile.php', $this->context->id, 'block_slideshow', 'content', NULL);
     $table = 'files';
     $select = "component = 'block_slideshow' AND contextid = '" . $this->context->id . "' AND filename != '.'";
     $fields = 'filename';
     $sort = 'filename';
     $images = $DB->get_records_select($table, $select, NULL, $sort, $fields);
     foreach ($images as $image) {
         $imagefile = $image->filename;
         $url = $CFG->wwwroot . '/pluginfile.php/' . $this->context->id . '/block_slideshow/content/' . $imagefile;
         $this->content->text .= '<img src="' . $url . '" class="slide" />';
     }
     $this->content->text .= '</div><div style="clear:both;"> </div>';
     if ($this->content->transparent) {
         $ssbackground = 'transparent';
     } else {
         $ssbackground = $this->content->background;
     }
     $node = 'page-header';
     $currenttheme = $CFG->theme;
     switch ($currenttheme) {
         default:
             $node = 'page-header';
             break;
         case 'fusion':
         case 'nimble':
             $node = 'region-header';
             break;
         case 'magazine':
             $node = 'textcontainer-wrap';
             break;
         case 'overlay':
             $node = 'newheader';
             break;
         case 'splash':
             $node = 'page-header-wrapper';
             break;
     }
     $script = "\n\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\$(document).ready(function() {\n    \t\t\t\t\t\$('#page-slideshow').cycle({\n\t\t\t\t\t\t\tfx: '" . $this->content->transition . "',\n\t\t\t\t\t\t\tspeed: " . $this->content->slidespeed . ",\n\t\t\t\t\t\t\ttimeout: " . $this->content->slidedelay . ",\n\t\t\t\t\t  }); ";
     if (!$this->content->normalblock) {
         $script .= "\$('#inst" . $this->instance->id . "') .appendTo('#" . $node . "');\n\t\t\t\t\t\t\$('#page-header').css('height', 'auto');\n            \$('.block.block_slideshow').css({'margin':'0','border':'0','width':'100%','clear':'both','border-radius':'0','padding':'0','background':'" . $ssbackground . "'});\n            \$('.block.block_slideshow .corner-box').css({'margin':'0','border':'0','width':'100%','clear':'both','border-radius':'0','padding':'0','background':'" . $ssbackground . "'});";
     }
     $script .= "\n\t\t\t\t\t\t\$('#page-slideshow').width(\$('#inst" . $this->instance->id . "').width());\n\t\t\t\t\t\t\$('#page-slideshow').css('background', '" . $ssbackground . "');\n\t\t\t\t\t\t// \$('.block.block_slideshow .content #page-slideshow').css();\n\t\t\t\t\t\t// \$('.block.block_slideshow .content #page-slideshow img').css();\n\t\t\t\t\t});\n\n\t\t\t\t</script>";
     $this->content->text .= $script;
     // . "<h1>Normal Block:" . $this->content->normalblock . ";</h1>";
     return $this->content;
 }
示例#18
0
    /**
     * Display the content of the field in browse mode
     *
     * @param int $recordid
     * @param object $template
     * @return bool|string
     */
    function display_browse_field($recordid, $template) {
        global $DB;

        if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
            if (isset($content->content)) {
                $options = new stdClass();
                if ($this->field->param1 == '1') {  // We are autolinking this field, so disable linking within us
                    $options->filter = false;
                }
                $options->para = false;
                $str = file_rewrite_pluginfile_urls($content->content, 'pluginfile.php', $this->context->id, 'mod_data', 'content', $content->id, $this->get_options());
                $str = format_text($str, $content->content1, $options);
            } else {
                $str = '';
            }
            return $str;
        }
        return false;
    }
示例#19
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;
 }
示例#20
0
                echo '</span></pre>';
                echo '<br>';
                echo '</td></tr>';
            }
            $x++;
        }
        echo '</table></center>';
        echo '<br><p><p>';
        echo '<h2><center><b>Average class score is ' . $classaverage . '%</b></center></h2>';
    }
} else {
    // Show a single question
    echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter realtimequizplainbox');
    $question = $DB->get_record('realtimequiz_question', array('id' => $questionid));
    echo '<h2>' . get_string('question', 'realtimequiz') . $question->questionnum . '</h2>';
    $questiontext = file_rewrite_pluginfile_urls($question->questiontext, 'pluginfile.php', $context->id, 'mod_realtimequiz', 'question', $question->id);
    $questiontext = format_text($questiontext, $question->questiontextformat);
    echo '<p>' . $questiontext . '</p><br />';
    echo '<table border="1" class="realtimequiz_report_answer"><tr class="realtimequiz_report_question"><td width="30%">&nbsp;</td>';
    $answers = $DB->get_records('realtimequiz_answer', array('questionid' => $questionid), 'id');
    if (!empty($answers)) {
        foreach ($answers as $answer) {
            if ($answer->correct == 1) {
                echo '<td width="10%"><b>' . s($answer->answertext) . '</b></td>';
            } else {
                echo '<td width="10%">' . s($answer->answertext) . '</td>';
            }
        }
    }
    echo '</tr>';
    if ($showsession == 0) {
示例#21
0
 /**
  * Returns the contents field for the page properly formatted and with plugin
  * file url's converted
  * @return string
  */
 public function get_contents()
 {
     global $PAGE;
     if (!empty($this->properties->contents)) {
         if (!isset($this->properties->contentsformat)) {
             $this->properties->contentsformat = FORMAT_HTML;
         }
         $context = context_module::instance($PAGE->cm->id);
         $contents = file_rewrite_pluginfile_urls($this->properties->contents, 'pluginfile.php', $context->id, 'mod_lesson', 'page_contents', $this->properties->id);
         // Must do this BEFORE format_text()!
         return format_text($contents, $this->properties->contentsformat, array('context' => $context, 'noclean' => true, 'overflowdiv' => true));
         // Page edit is marked with XSS, we want all content here.
     } else {
         return '';
     }
 }
示例#22
0
/**
 * Generate any blog RSS feed via one function
 *
 * @param stdClass $context The context of the blog for which the feed it being generated
 * @param array    $args    An array of arguements needed to build the feed (contextid, token, componentname, type, id, tagid)
 */
function blog_rss_get_feed($context, $args)
{
    global $CFG, $SITE, $DB;
    if (empty($CFG->bloglevel)) {
        debugging('Blogging disabled on this site, RSS feeds are not available');
        return null;
    }
    if (empty($CFG->enablerssfeeds)) {
        debugging('Sorry, RSS feeds are disabled on this site');
        return '';
    }
    if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
        if (isguestuser()) {
            debugging(get_string('nopermissiontoshow', 'error'));
            return '';
        }
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    if (!has_capability('moodle/blog:view', $sitecontext)) {
        return null;
    }
    $type = clean_param($args[3], PARAM_ALPHA);
    $id = clean_param($args[4], PARAM_INT);
    // could be groupid / courseid  / userid  depending on $type
    $tagid = 0;
    if ($args[5] != 'rss.xml') {
        $tagid = clean_param($args[5], PARAM_INT);
    } else {
        $tagid = 0;
    }
    $filename = blog_rss_file_name($type, $id, $tagid);
    if (file_exists($filename)) {
        if (filemtime($filename) + 3600 > time()) {
            return $filename;
            // It's already done so we return cached version
        }
    }
    $courseid = $groupid = $userid = null;
    switch ($type) {
        case 'site':
            //$siteid = $id;
            break;
        case 'course':
            $courseid = $id;
            break;
        case 'group':
            $groupid = $id;
            break;
        case 'user':
            $userid = $id;
            break;
    }
    // Get all the entries from the database
    require_once $CFG->dirroot . '/blog/locallib.php';
    $blogheaders = blog_get_headers($courseid, $groupid, $userid, $tagid);
    $bloglisting = new blog_listing($blogheaders['filters']);
    $blogentries = $bloglisting->get_entries();
    // Now generate an array of RSS items
    if ($blogentries) {
        $items = array();
        foreach ($blogentries as $blog_entry) {
            $item = NULL;
            $item->author = fullname($DB->get_record('user', array('id' => $blog_entry->userid)));
            // TODO: this is slow
            $item->title = $blog_entry->subject;
            $item->pubdate = $blog_entry->lastmodified;
            $item->link = $CFG->wwwroot . '/blog/index.php?entryid=' . $blog_entry->id;
            $summary = file_rewrite_pluginfile_urls($blog_entry->summary, 'pluginfile.php', $sitecontext->id, 'blog', 'post', $blog_entry->id);
            $item->description = format_text($summary, $blog_entry->format);
            if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blog_entry->id))) {
                if ($blogtags) {
                    $item->tags = $blogtags;
                }
                $item->tagscheme = $CFG->wwwroot . '/tag';
            }
            $items[] = $item;
        }
        $articles = rss_add_items($items);
        /// Change structure to XML
    } else {
        $articles = '';
    }
    /// Get header and footer information
    switch ($type) {
        case 'user':
            $info = fullname($DB->get_record('user', array('id' => $id), 'firstname,lastname'));
            break;
        case 'course':
            $info = $DB->get_field('course', 'fullname', array('id' => $id));
            $info = format_string($info, true, array('context' => get_context_instance(CONTEXT_COURSE, $id)));
            break;
        case 'site':
            $info = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
            break;
        case 'group':
            $group = groups_get_group($id);
            $info = $group->name;
            //TODO: $DB->get_field('groups', 'name', array('id'=>$id))
            break;
        default:
            $info = '';
            break;
    }
    if ($tagid) {
        $info .= ': ' . $DB->get_field('tags', 'text', array('id' => $tagid));
    }
    $header = rss_standard_header(get_string($type . 'blog', 'blog', $info), $CFG->wwwroot . '/blog/index.php', get_string('intro', 'blog'));
    $footer = rss_standard_footer();
    // Save the XML contents to file.
    $rssdata = $header . $articles . $footer;
    if (blog_rss_save_file($type, $id, $tagid, $rssdata)) {
        return $filename;
    } else {
        return false;
        // Couldn't find it or make it
    }
}
示例#23
0
    // Display info about the group.
    if ($group = groups_get_group($currentgroup)) {
        if (!empty($group->description) or !empty($group->picture) and empty($group->hidepicture)) {
            $groupinfotable = new html_table();
            $groupinfotable->attributes['class'] = 'groupinfobox';
            $picturecell = new html_table_cell();
            $picturecell->attributes['class'] = 'left side picture';
            $picturecell->text = print_group_picture($group, $course->id, true, true, false);
            $contentcell = new html_table_cell();
            $contentcell->attributes['class'] = 'content';
            $contentheading = $group->name;
            if (has_capability('moodle/course:managegroups', $context)) {
                $aurl = new moodle_url('/group/group.php', array('id' => $group->id, 'courseid' => $group->courseid));
                $contentheading .= '&nbsp;' . $OUTPUT->action_icon($aurl, new pix_icon('t/edit', get_string('editgroupprofile')));
            }
            $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id);
            if (!isset($group->descriptionformat)) {
                $group->descriptionformat = FORMAT_MOODLE;
            }
            $options = array('overflowdiv' => true);
            $formatteddesc = format_text($group->description, $group->descriptionformat, $options);
            $contentcell->text = $OUTPUT->heading($contentheading, 3) . $formatteddesc;
            $groupinfotable->data[] = new html_table_row(array($picturecell, $contentcell));
            echo html_writer::table($groupinfotable);
        }
    }
}
// Define a table showing a list of users in the current role selection.
$tablecolumns = array();
$tableheaders = array();
if ($bulkoperations && $mode === MODE_BRIEF) {
示例#24
0
 /**
  * Prints or returns the HTML for this blog entry.
  *
  * @param bool $return
  * @return string
  */
 public function print_html($return = false)
 {
     global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
     $user = $DB->get_record('user', array('id' => $this->userid));
     $cmttext = '';
     if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
         require_once $CFG->dirroot . '/comment/lib.php';
         // Comments
         $cmt = new stdClass();
         $cmt->context = get_context_instance(CONTEXT_USER, $user->id);
         $cmt->courseid = $PAGE->course->id;
         $cmt->area = 'format_blog';
         $cmt->itemid = $this->id;
         $cmt->showcount = $CFG->blogshowcommentscount;
         $cmt->component = 'blog';
         $comment = new comment($cmt);
         $cmttext = $comment->output(true);
     }
     $this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
     $options = array('overflowdiv' => true);
     $template['body'] = format_text($this->summary, $this->summaryformat, $options) . $cmttext;
     $template['title'] = format_string($this->subject);
     $template['userid'] = $user->id;
     $template['author'] = fullname($user);
     $template['created'] = userdate($this->created);
     if ($this->created != $this->lastmodified) {
         $template['lastmod'] = userdate($this->lastmodified);
     }
     $template['publishstate'] = $this->publishstate;
     $stredit = get_string('edit');
     $strdelete = get_string('delete');
     // Check to see if the entry is unassociated with group/course level access
     $unassociatedentry = false;
     if (!empty($CFG->useblogassociations) && ($this->publishstate == 'group' || $this->publishstate == 'course')) {
         if (!$DB->record_exists('blog_association', array('blogid' => $this->id))) {
             $unassociatedentry = true;
         }
     }
     // Start printing of the blog
     $table = new html_table();
     $table->cellspacing = 0;
     $table->attributes['class'] = 'forumpost blog_entry blog' . ($unassociatedentry ? 'draft' : $template['publishstate']);
     $table->attributes['id'] = 'b' . $this->id;
     $table->width = '100%';
     $picturecell = new html_table_cell();
     $picturecell->attributes['class'] = 'picture left';
     $picturecell->text = $OUTPUT->user_picture($user);
     $table->head[] = $picturecell;
     $topiccell = new html_table_cell();
     $topiccell->attributes['class'] = 'topic starter';
     $titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), $template['title']);
     $topiccell->text = $OUTPUT->container($titlelink, 'subject');
     $topiccell->text .= $OUTPUT->container_start('author');
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $PAGE->course->id)));
     $by = new stdClass();
     $by->name = html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $PAGE->course->id)), $fullname);
     $by->date = $template['created'];
     $topiccell->text .= get_string('bynameondate', 'forum', $by);
     $topiccell->text .= $OUTPUT->container_end();
     if ($this->uniquehash && $this->content) {
         if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
             $urlparts = parse_url($externalblog->url);
             $topiccell->text .= $OUTPUT->container(get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig') . html_writer::link($urlparts['scheme'] . '://' . $urlparts['host'], $externalblog->name), 'externalblog');
         }
     }
     $topiccell->header = false;
     $table->head[] = $topiccell;
     // Actual content
     $mainrow = new html_table_row();
     $leftsidecell = new html_table_cell();
     $leftsidecell->attributes['class'] = 'left side';
     $mainrow->cells[] = $leftsidecell;
     $contentcell = new html_table_cell();
     $contentcell->attributes['class'] = 'content';
     $attachedimages = $OUTPUT->container($this->print_attachments(), 'attachments');
     // retrieve associations in case they're needed early
     $blogassociations = $DB->get_records('blog_association', array('blogid' => $this->id));
     // determine text for publish state
     switch ($template['publishstate']) {
         case 'draft':
             $blogtype = get_string('publishtonoone', 'blog');
             break;
         case 'site':
             $blogtype = get_string('publishtosite', 'blog');
             break;
         case 'public':
             $blogtype = get_string('publishtoworld', 'blog');
             break;
         default:
             $blogtype = '';
             break;
     }
     $contentcell->text .= $OUTPUT->container($blogtype, 'audience');
     $contentcell->text .= $template['body'];
     $contentcell->text .= $attachedimages;
     // Uniquehash is used as a link to an external blog
     if (!empty($this->uniquehash)) {
         $contentcell->text .= $OUTPUT->container_start('externalblog');
         $contentcell->text .= html_writer::link($this->uniquehash, get_string('linktooriginalentry', 'blog'));
         $contentcell->text .= $OUTPUT->container_end();
     }
     // Links to tags
     $officialtags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'official');
     $defaulttags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'default');
     if (!empty($CFG->usetags) && ($officialtags || $defaulttags)) {
         $contentcell->text .= $OUTPUT->container_start('tags');
         if ($officialtags) {
             $contentcell->text .= get_string('tags', 'tag') . ': ' . $OUTPUT->container($officialtags, 'officialblogtags');
             if ($defaulttags) {
                 $contentcell->text .= ', ';
             }
         }
         $contentcell->text .= $defaulttags;
         $contentcell->text .= $OUTPUT->container_end();
     }
     // Add associations
     if (!empty($CFG->useblogassociations) && $blogassociations) {
         $contentcell->text .= $OUTPUT->container_start('tags');
         $assocstr = '';
         $hascourseassocs = false;
         $assoctype = '';
         // First find and show the associated course
         foreach ($blogassociations as $assocrec) {
             $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid));
             if ($contextrec->contextlevel == CONTEXT_COURSE) {
                 $assocurl = new moodle_url('/course/view.php', array('id' => $contextrec->instanceid));
                 $text = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid));
                 //TODO: performance!!!!
                 $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('i/course', $text), null, array(), true);
                 $hascourseassocs = true;
                 $assoctype = get_string('course');
             }
         }
         // Now show mod association
         foreach ($blogassociations as $assocrec) {
             $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid));
             if ($contextrec->contextlevel == CONTEXT_MODULE) {
                 if ($hascourseassocs) {
                     $assocstr .= ', ';
                     $hascourseassocs = false;
                 }
                 $modinfo = $DB->get_record('course_modules', array('id' => $contextrec->instanceid));
                 $modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));
                 $assocurl = new moodle_url('/mod/' . $modname . '/view.php', array('id' => $modinfo->id));
                 $text = $DB->get_field($modname, 'name', array('id' => $modinfo->instance));
                 //TODO: performance!!!!
                 $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('icon', $text, $modname), null, array(), true);
                 $assocstr .= ', ';
                 $assoctype = get_string('modulename', $modname);
             }
         }
         $assocstr = substr($assocstr, 0, -2);
         $contentcell->text .= get_string('associated', 'blog', $assoctype) . ': ' . $assocstr;
         $contentcell->text .= $OUTPUT->container_end();
     }
     if ($unassociatedentry) {
         $contentcell->text .= $OUTPUT->container(get_string('associationunviewable', 'blog'), 'noticebox');
     }
     /// Commands
     $contentcell->text .= $OUTPUT->container_start('commands');
     if (blog_user_can_edit_entry($this) && empty($this->uniquehash)) {
         $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'edit', 'entryid' => $this->id)), $stredit) . ' | ';
         $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'delete', 'entryid' => $this->id)), $strdelete) . ' | ';
     }
     $contentcell->text .= html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog'));
     $contentcell->text .= $OUTPUT->container_end();
     if (isset($template['lastmod'])) {
         $contentcell->text .= '<div style="font-size: 55%;">';
         $contentcell->text .= ' [ ' . get_string('modified') . ': ' . $template['lastmod'] . ' ]';
         $contentcell->text .= '</div>';
     }
     $mainrow->cells[] = $contentcell;
     $table->data = array($mainrow);
     if ($return) {
         return html_writer::table($table);
     } else {
         echo html_writer::table($table);
     }
 }
示例#25
0
文件: lib.php 项目: nuckey/moodle
    /**
     * Factory method returning an instance of an assessment form
     *
     * @param moodle_url $actionurl URL of form handler, defaults to auto detect the current url
     * @param string $mode          Mode to open the form in: preview/assessment
     * @param stdClass $assessment
     * @param bool $editable
     * @param array $options
     */
    public function get_assessment_form(moodle_url $actionurl=null, $mode='preview', stdclass $assessment=null, $editable=true, $options=array()) {
        global $CFG;    // needed because the included files use it
        global $PAGE;
        global $DB;
        require_once(dirname(__FILE__) . '/assessment_form.php');

        $fields         = $this->prepare_form_fields($this->dimensions, $this->mappings);
        $nodimensions   = count($this->dimensions);

        // rewrite URLs to the embeded files
        for ($i = 0; $i < $nodimensions; $i++) {
            $fields->{'description__idx_'.$i} = file_rewrite_pluginfile_urls($fields->{'description__idx_'.$i},
                'pluginfile.php', $PAGE->context->id, 'workshopform_numerrors', 'description', $fields->{'dimensionid__idx_'.$i});
        }

        if ('assessment' === $mode and !empty($assessment)) {
            // load the previously saved assessment data
            $grades = $this->get_current_assessment_data($assessment);
            $current = new stdclass();
            for ($i = 0; $i < $nodimensions; $i++) {
                $dimid = $fields->{'dimensionid__idx_'.$i};
                if (isset($grades[$dimid])) {
                    $current->{'gradeid__idx_'.$i}      = $grades[$dimid]->id;
                    $current->{'grade__idx_'.$i}        = $grades[$dimid]->grade;
                    $current->{'peercomment__idx_'.$i}  = $grades[$dimid]->peercomment;
                }
            }
        }

        // set up the required custom data common for all strategies
        $customdata['workshop'] = $this->workshop;
        $customdata['strategy'] = $this;
        $customdata['mode']     = $mode;
        $customdata['options']  = $options;

        // set up strategy-specific custom data
        $customdata['nodims']   = $nodimensions;
        $customdata['fields']   = $fields;
        $customdata['current']  = isset($current) ? $current : null;
        $attributes = array('class' => 'assessmentform numerrors');

        return new workshop_numerrors_assessment_form($actionurl, $customdata, 'post', '', $attributes, $editable);
    }
 public function get_user_filtered_sessions_log_extended($userid)
 {
     global $DB;
     // All taked sessions (including previous groups).
     if ($this->pageparams->startdate && $this->pageparams->enddate) {
         $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND\n                      ats.sessdate >= :sdate AND ats.sessdate < :edate";
     } else {
         $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate";
     }
     // We need to add this concatination so that moodle will use it as the array index that is a string.
     // If the array's index is a number it will not merge entries.
     // It would be better as a UNION query but unfortunatly MS SQL does not seem to support doing a
     // DISTINCT on a the description field.
     $id = $DB->sql_concat(':value', 'ats.id');
     if ($this->get_group_mode()) {
         $sql = "SELECT {$id}, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description,\n                           al.statusid, al.remarks, ats.studentscanmark\n                      FROM {attendance_sessions} ats\n                RIGHT JOIN {attendance_log} al\n                        ON ats.id = al.sessionid AND al.studentid = :uid\n                 LEFT JOIN {groups_members} gm ON gm.userid = al.studentid AND gm.groupid = ats.groupid\n                     WHERE {$where} AND (ats.groupid = 0 or gm.id is NOT NULL)\n                  ORDER BY ats.sessdate ASC";
     } else {
         $sql = "SELECT {$id}, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description,\n                           al.statusid, al.remarks, ats.studentscanmark\n                      FROM {attendance_sessions} ats\n                RIGHT JOIN {attendance_log} al\n                        ON ats.id = al.sessionid AND al.studentid = :uid\n                     WHERE {$where}\n                  ORDER BY ats.sessdate ASC";
     }
     $params = array('uid' => $userid, 'aid' => $this->id, 'csdate' => $this->course->startdate, 'sdate' => $this->pageparams->startdate, 'edate' => $this->pageparams->enddate, 'value' => 'c');
     $sessions = $DB->get_records_sql($sql, $params);
     // All sessions for current groups.
     $groups = array_keys(groups_get_all_groups($this->course->id, $userid));
     $groups[] = 0;
     list($gsql, $gparams) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED, 'gid0');
     if ($this->pageparams->startdate && $this->pageparams->enddate) {
         $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND\n                      ats.sessdate >= :sdate AND ats.sessdate < :edate AND ats.groupid {$gsql}";
     } else {
         $where = "ats.attendanceid = :aid AND ats.sessdate >= :csdate AND ats.groupid {$gsql}";
     }
     $sql = "SELECT {$id}, ats.id, ats.groupid, ats.sessdate, ats.duration, ats.description,\n                       al.statusid, al.remarks, ats.studentscanmark\n                  FROM {attendance_sessions} ats\n             LEFT JOIN {attendance_log} al\n                    ON ats.id = al.sessionid AND al.studentid = :uid\n                 WHERE {$where}\n              ORDER BY ats.sessdate ASC";
     $params = array_merge($params, $gparams);
     $sessions = array_merge($sessions, $DB->get_records_sql($sql, $params));
     foreach ($sessions as $sess) {
         if (empty($sess->description)) {
             $sess->description = get_string('nodescription', 'attendance');
         } else {
             $sess->description = file_rewrite_pluginfile_urls($sess->description, 'pluginfile.php', $this->context->id, 'mod_attendance', 'session', $sess->id);
         }
     }
     return $sessions;
 }
示例#27
0
if ($edit) {
    $PAGE->navbar->add(get_string('mysubmission', 'workshop'), $workshop->submission_url(), navigation_node::TYPE_CUSTOM);
    $PAGE->navbar->add(get_string('editingsubmission', 'workshop'));
} elseif ($ownsubmission) {
    $PAGE->navbar->add(get_string('mysubmission', 'workshop'));
} else {
    $PAGE->navbar->add(get_string('submission', 'workshop'));
}
// Output starts here
$output = $PAGE->get_renderer('mod_workshop');
echo $output->header();
echo $output->heading(format_string($workshop->name), 2);
// show instructions for submitting as thay may contain some list of questions and we need to know them
// while reading the submitted answer
if (trim($workshop->instructauthors)) {
    $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, 'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
    print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
    echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv' => true)), array('generalbox', 'instructions'));
    print_collapsible_region_end();
}
// if in edit mode, display the form to edit the submission
if ($edit) {
    if (!empty($CFG->enableplagiarism)) {
        require_once $CFG->libdir . '/plagiarismlib.php';
        echo plagiarism_print_disclosure($cm->id);
    }
    $mform->display();
    echo $output->footer();
    die;
}
// else display the submission
示例#28
0
            rebuild_course_cache($SITE->id, true);
        }

        if (!empty($section->sequence) or !empty($section->summary) or $editing) {
            echo $OUTPUT->box_start('generalbox sitetopic');

            /// If currently moving a file then show the current clipboard
            if (ismoving($SITE->id)) {
                $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
                echo '<p><font size="2">';
                echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
                echo '</font></p>';
            }

            $context = get_context_instance(CONTEXT_COURSE, SITEID);
            $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
            $summaryformatoptions = new stdClass();
            $summaryformatoptions->noclean = true;
            $summaryformatoptions->overflowdiv = true;

            echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);

            if ($editing && has_capability('moodle/course:update', $context)) {
                $streditsummary = get_string('editsummary');
                echo "<a title=\"$streditsummary\" ".
                     " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
                     " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
            }

            print_section($SITE, $section, $mods, $modnamesused, true);
示例#29
0
function wiki_print_page_content($page, $context, $subwikiid)
{
    global $OUTPUT, $CFG;
    if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
        $content = wiki_refresh_cachedcontent($page);
        $page = $content['page'];
    }
    if (isset($content)) {
        $box = '';
        foreach ($content['sections'] as $s) {
            $box .= '<p>' . get_string('repeatedsection', 'wiki', $s) . '</p>';
        }
        if (!empty($box)) {
            echo $OUTPUT->box($box);
        }
    }
    $html = file_rewrite_pluginfile_urls($page->cachedcontent, 'pluginfile.php', $context->id, 'mod_wiki', 'attachments', $subwikiid);
    $html = format_text($html, FORMAT_MOODLE, array('overflowdiv' => true));
    echo $OUTPUT->box($html);
    if (!empty($CFG->usetags)) {
        $tags = tag_get_tags_array('wiki_pages', $page->id);
        echo $OUTPUT->container_start('wiki-tags');
        echo '<span class="wiki-tags-title">' . get_string('tags') . ': </span>';
        $links = array();
        foreach ($tags as $tagid => $tag) {
            $url = new moodle_url('/tag/index.php', array('tag' => $tag));
            $links[] = html_writer::link($url, $tag, array('title' => get_string('tagtitle', 'wiki', $tag)));
        }
        echo join($links, ", ");
        echo $OUTPUT->container_end();
    }
    wiki_increment_pageviews($page);
}
示例#30
0
文件: view.php 项目: verbazend/AWFA
}

if (has_capability('mod/feedback:edititems', $context)) {
    echo $OUTPUT->heading(get_string('description', 'feedback'), 4);
}
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
$options = (object)array('noclean'=>true);
echo format_module_intro('feedback', $feedback, $cm->id);
echo $OUTPUT->box_end();

if (has_capability('mod/feedback:edititems', $context)) {
    require_once($CFG->libdir . '/filelib.php');

    $page_after_submit_output = file_rewrite_pluginfile_urls($feedback->page_after_submit,
                                                            'pluginfile.php',
                                                            $context->id,
                                                            'mod_feedback',
                                                            'page_after_submit',
                                                            0);

    echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
    echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
    echo format_text($page_after_submit_output,
                     $feedback->page_after_submitformat,
                     array('overflowdiv'=>true));

    echo $OUTPUT->box_end();
}

if ( (intval($feedback->publish_stats) == 1) AND
                ( has_capability('mod/feedback:viewanalysepage', $context)) AND
                !( has_capability('mod/feedback:viewreports', $context)) ) {