当前位置: 首页>>代码示例>>PHP>>正文


PHP can_use_html_editor函数代码示例

本文整理汇总了PHP中can_use_html_editor函数的典型用法代码示例。如果您正苦于以下问题:PHP can_use_html_editor函数的具体用法?PHP can_use_html_editor怎么用?PHP can_use_html_editor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了can_use_html_editor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: MoodleQuickForm_htmleditor

 function MoodleQuickForm_htmleditor($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
 {
     parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
     // set the options, do not bother setting bogus ones
     if (is_array($options)) {
         foreach ($options as $name => $value) {
             if (isset($this->_options[$name])) {
                 if (is_array($value) && is_array($this->_options[$name])) {
                     $this->_options[$name] = @array_merge($this->_options[$name], $value);
                 } else {
                     $this->_options[$name] = $value;
                 }
             }
         }
     }
     if ($this->_options['canUseHtmlEditor'] == 'detect') {
         $this->_options['canUseHtmlEditor'] = can_use_html_editor();
     }
     if ($this->_options['canUseHtmlEditor']) {
         $this->_type = 'htmleditor';
         //$this->_elementTemplateType='wide';
     } else {
         $this->_type = 'textarea';
     }
     $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:26,代码来源:htmleditor.php

示例2: display_add_field

 function display_add_field($recordid = 0)
 {
     global $CFG, $DB;
     $text = '';
     $format = 0;
     if ($recordid) {
         if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
             $text = $content->content;
             $format = $content->content1;
         }
     }
     $str = '<div title="' . $this->field->description . '">';
     if (can_use_html_editor()) {
         // Show a rich text html editor.
         $str .= $this->gen_textarea(true, $text);
         $str .= helpbutton("richtext2", get_string("helprichtext"), 'moodle', true, true, '', true);
         $str .= '<input type="hidden" name="field_' . $this->field->id . '_content1' . '" value="' . FORMAT_HTML . '" />';
     } else {
         // Show a normal textarea. Also let the user specify the format to be used.
         $str .= $this->gen_textarea(false, $text);
         // Get the available text formats for this field.
         $formatsForField = format_text_menu();
         $str .= '<br />';
         $str .= choose_from_menu($formatsForField, 'field_' . $this->field->id . '_content1', $format, 'choose', '', '', true);
         $str .= helpbutton('textformat', get_string('helpformatting'), 'moodle', true, false, '', true);
     }
     $str .= '</div>';
     return $str;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:29,代码来源:field.class.php

示例3: print_question_formulation_and_controls

 function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options)
 {
     global $CFG;
     static $htmleditorused = false;
     $answers =& $question->options->answers;
     $readonly = empty($options->readonly) ? '' : 'disabled="disabled"';
     // Only use the rich text editor for the first essay question on a page.
     $usehtmleditor = can_use_html_editor() && !$htmleditorused;
     $formatoptions = new stdClass();
     $formatoptions->noclean = true;
     $formatoptions->para = false;
     $inputname = $question->name_prefix;
     $stranswer = get_string("answer", "quiz") . ': ';
     /// set question text and media
     $questiontext = format_text($question->questiontext, $question->questiontextformat, $formatoptions, $cmoptions->course);
     $image = get_question_image($question);
     // feedback handling
     $feedback = '';
     if ($options->feedback && !empty($answers)) {
         foreach ($answers as $answer) {
             $feedback = format_text($answer->feedback, '', $formatoptions, $cmoptions->course);
         }
     }
     // get response value
     if (isset($state->responses[''])) {
         $value = stripslashes_safe($state->responses['']);
     } else {
         $value = "";
     }
     // answer
     if (empty($options->readonly)) {
         // the student needs to type in their answer so print out a text editor
         $answer = print_textarea($usehtmleditor, 18, 80, 630, 400, $inputname, $value, $cmoptions->course, true);
     } else {
         // it is read only, so just format the students answer and output it
         $safeformatoptions = new stdClass();
         $safeformatoptions->para = false;
         $answer = format_text($value, FORMAT_MOODLE, $safeformatoptions, $cmoptions->course);
         $answer = '<div class="answerreview">' . $answer . '</div>';
     }
     include "{$CFG->dirroot}/question/type/essay/display.html";
     if ($usehtmleditor && empty($options->readonly)) {
         use_html_editor($inputname);
         $htmleditorused = true;
     }
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:46,代码来源:questiontype.php

示例4: display_add_field

 function display_add_field($recordid = 0)
 {
     global $CFG, $DB, $OUTPUT, $PAGE;
     $text = '';
     $format = 0;
     $str = '<div title="' . $this->field->description . '">';
     editors_head_setup();
     $options = array();
     $options['trusttext'] = false;
     $options['forcehttps'] = false;
     $options['subdirs'] = false;
     $options['maxfiles'] = 0;
     $options['maxbytes'] = 0;
     $options['changeformat'] = 0;
     $options['noclean'] = false;
     $itemid = $this->field->id;
     $field = 'field_' . $itemid;
     if ($recordid && ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) {
         $text = $content->content;
         $format = $content->content1;
         $text = clean_text($text, $format);
     } else {
         if (can_use_html_editor()) {
             $format = FORMAT_HTML;
         } else {
             $format = FORMAT_PLAIN;
         }
     }
     $editor = editors_get_preferred_editor($format);
     $strformats = format_text_menu();
     $formats = $editor->get_supported_formats();
     foreach ($formats as $fid) {
         $formats[$fid] = $strformats[$fid];
     }
     $editor->use_editor($field, $options);
     $str .= '<div><textarea id="' . $field . '" name="' . $field . '" rows="' . $this->field->param3 . '" cols="' . $this->field->param2 . '">' . s($text) . '</textarea></div>';
     $str .= '<div><select name="' . $field . '_content1">';
     foreach ($formats as $key => $desc) {
         $selected = $format == $key ? 'selected="selected"' : '';
         $str .= '<option value="' . s($key) . '" ' . $selected . '>' . $desc . '</option>';
     }
     $str .= '</select>';
     $str .= '</div>';
     $str .= '</div>';
     return $str;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:46,代码来源:field.class.php

示例5: loadeditor

 /**
  * Method to load necessary editor codes to
  * $CFG->editorsrc array.
  *
  * @todo example code.
  * @param mixed $args Course id or associative array holding course id and editor name.
  */
 function loadeditor($args)
 {
     global $CFG, $USER;
     if (is_array($args)) {
         // If args is an array search keys courseid and name.
         // Name represents editor name to load.
         if (!array_key_exists('courseid', $args)) {
             error("Required variable courseid is missing!");
         }
         if (!array_key_exists('name', $args)) {
             error("Required variable name is missing!");
         }
         $courseid = clean_param($args['courseid'], PARAM_INT);
         $editorname = strtolower(clean_param($args['name'], PARAM_ALPHA));
     } else {
         // If only single argument is passed
         // this must be course id.
         $courseid = clean_param($args, PARAM_INT);
     }
     $htmleditor = !empty($editorname) ? $editorname : intval($USER->htmleditor);
     if (can_use_html_editor()) {
         $CFG->editorsrc = array();
         $editorbaseurl = $CFG->httpswwwroot . '/lib/editor';
         $editorbasedir = $CFG->dirroot . '/lib/editor';
         switch ($htmleditor) {
             case 1:
             case 'htmlarea':
                 array_push($CFG->editorsrc, "{$editorbaseurl}/htmlarea/htmlarea.php?id={$courseid}");
                 array_push($CFG->editorsrc, "{$editorbaseurl}/htmlarea/lang/en.php");
                 $classfile = "{$editorbasedir}/htmlarea/htmlarea.class.php";
                 include_once $classfile;
                 return new htmlarea($courseid);
                 break;
             case 2:
             case 'tinymce':
                 array_push($CFG->editorsrc, "{$editorbaseurl}/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php");
                 array_push($CFG->editorsrc, "{$editorbaseurl}/tinymce/moodledialog.js");
                 $classfile = "{$editorbasedir}/tinymce/tinymce.class.php";
                 include_once $classfile;
                 return new tinymce($courseid);
                 break;
         }
     }
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:51,代码来源:editorlib.php

示例6: definition

 function definition()
 {
     global $CFG, $USER;
     $mform = $this->_form;
     // Informational paragraph
     $a = (object) array('email' => $USER->email, 'fullname' => fullname($USER, true));
     $mform->addElement('static', '', '', get_string('forward_info_' . ($this->_customdata->onlyselected ? 'selected' : 'all'), 'forumng', $a));
     // Email address
     $mform->addElement('text', 'email', get_string('forward_email', 'forumng'), array('size' => 48));
     $mform->setType('email', PARAM_RAW);
     $mform->setHelpButton('email', array('forward_email', get_string('forward_email', 'forumng'), 'forumng'));
     $mform->addRule('email', get_string('required'), 'required', null, 'client');
     // CC me
     $mform->addElement('checkbox', 'ccme', get_string('forward_ccme', 'forumng'));
     // Email subject
     $mform->addElement('text', 'subject', get_string('subject', 'forumng'), array('size' => 48));
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addRule('subject', get_string('required'), 'required', null, 'client');
     $mform->setDefault('subject', $this->_customdata->subject);
     // Special field just to tell javascript that we're trying to use the
     // html editor
     $mform->addElement('hidden', 'tryinghtmleditor', can_use_html_editor() ? 1 : 0);
     // Email message
     $mform->addElement('htmleditor', 'message', get_string('forward_intro', 'forumng'), array('cols' => 50, 'rows' => 15));
     $mform->setType('message', PARAM_RAW);
     $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
     // Message format
     $mform->addElement('format', 'format', get_string('format'));
     // Hidden fields
     if ($this->_customdata->postids) {
         foreach ($this->_customdata->postids as $postid) {
             $mform->addElement('hidden', 'selectp' . $postid, 1);
         }
     } else {
         $mform->addElement('hidden', 'all', 1);
     }
     $mform->addElement('hidden', 'd', $this->_customdata->discussionid);
     $mform->addElement('hidden', 'clone', $this->_customdata->cloneid);
     $mform->addElement('hidden', 'postselectform', 1);
     $this->add_action_buttons(true, get_string('forward', 'forumng'));
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:42,代码来源:forward_form.php

示例7: MoodleQuickForm_format

 /**
  * Class constructor
  *
  * @param     string    Select name attribute
  * @param     mixed     Label(s) for the select
  * @param     mixed     Either a typical HTML attribute string or an associative array
  * @param     mixed     Either a string returned from can_use_html_editor() or false for no html editor
  *                      default 'detect' tells element to use html editor if it is available.
  * @access    public
  * @return    void
  */
 function MoodleQuickForm_format($elementName = null, $elementLabel = null, $attributes = null, $useHtmlEditor = null)
 {
     if ($elementName == null) {
         $elementName = 'format';
     }
     if ($elementLabel == null) {
         $elementLabel = get_string('format');
     }
     HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     $this->_type = 'format';
     $this->_useHtmlEditor = $useHtmlEditor;
     if ($this->_useHtmlEditor === null) {
         $this->_useHtmlEditor = can_use_html_editor();
     }
     $this->setPersistantFreeze($this->_useHtmlEditor);
     if ($this->_useHtmlEditor) {
         $this->freeze();
     } else {
         $this->unfreeze();
     }
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:32,代码来源:format.php

示例8: ewiki_page_edit_form

function ewiki_page_edit_form(&$id, &$data, &$hidden_postdata)
{
    global $ewiki_plugins, $ewiki_config, $moodle_format;
    $content = optional_param('content', '');
    $version = optional_param('version', '');
    $o = '';
    #-- previously edited, or db fetched content
    if ($content || $version) {
        $data = array("version" => $version, "content" => $content);
    } else {
        if (empty($data["version"])) {
            $data["version"] = 1;
        }
        @($data["content"] .= "");
    }
    #-- normalize to DOS newlines
    $data["content"] = str_replace("\r\n", "\n", $data["content"]);
    $data["content"] = str_replace("\r", "\n", $data["content"]);
    $data["content"] = str_replace("\n", "\r\n", $data["content"]);
    $hidden_postdata["version"] =& $data["version"];
    #-- edit textarea/form
    // deleted name="ewiki", can not find the reference, and it's breaking xhtml
    $o .= ewiki_t("EDIT_FORM_1") . '<form method="post" enctype="multipart/form-data" action="' . ewiki_script("edit", $id) . '" ' . ' accept-charset="' . EWIKI_CHARSET . '">' . "\n";
    $o .= '<div>';
    #-- additional POST vars
    foreach ($hidden_postdata as $name => $value) {
        $o .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n";
    }
    ($cols = strtok($ewiki_config["edit_box_size"], "x*/,;:")) && ($rows = strtok("x, ")) || ($cols = 70) && ($rows = 15);
    global $ewiki_use_editor, $ewiki_editor_content;
    $ewiki_editor_content = 1;
    if ($ewiki_use_editor) {
        ob_start();
        $usehtmleditor = can_use_html_editor();
        echo '<table><tr><td>';
        if ($usehtmleditor) {
            //clean and convert before editing
            $options = new object();
            $options->smiley = false;
            $options->filter = false;
            $oldtext = format_text(ewiki_format($data["content"]), $moodle_format, $options);
        } else {
            $oldtext = ewiki_format($data["content"]);
        }
        print_textarea($usehtmleditor, $rows, $cols, 680, 400, "content", $oldtext);
        echo '</td></tr></table>';
        $o .= ob_get_contents();
        ob_end_clean();
    } else {
        ##### END MOODLE ADDITION #####
        $o .= '<textarea wrap="soft" id="ewiki_content" name="content" rows="' . $rows . '" cols="' . $cols . '">' . s($data["content"]) . "</textarea>" . $GLOBALS["ewiki_t"]["C"]["EDIT_TEXTAREA_RESIZE_JS"];
        ##### BEGIN MOODLE ADDITION #####
    }
    ##### END MOODLE ADDITION #####
    #-- more <input> elements before the submit button
    if ($pf_a = $ewiki_plugins["edit_form_insert"]) {
        foreach ($pf_a as $pf) {
            $o .= $pf($id, $data, $action);
        }
    }
    ##### BEGIN MOODLE ADDITION (Cancel Editing into Button) #####
    $o .= "\n<br />\n" . '<input type="submit" name="save" value="' . ewiki_t("SAVE") . '" />' . "\n" . '<input type="submit" name="preview" value="' . ewiki_t("PREVIEW") . '" />' . "\n" . '<input type="submit" name="canceledit" value="' . ewiki_t("CANCEL_EDIT") . '" />' . "\n";
    #      . ' &nbsp; <a href="'. ewiki_script("", $id) . '">' . ewiki_t("CANCEL_EDIT") . '</a>';
    ##### END MOODLE ADDITION #####
    #-- additional form elements
    if ($pf_a = $ewiki_plugins["edit_form_append"]) {
        foreach ($pf_a as $pf) {
            $o .= $pf($id, $data, $action);
        }
    }
    $o .= "\n</div></form>\n";
    //   . ewiki_t("EDIT_FORM_2");  // MOODLE DELETION
    return '<div class="edit-box">' . $o . '</div>';
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:74,代码来源:ewiki.php

示例9: message_contact_link

    echo '<li>';
    message_contact_link($user->id, 'add', false, 'discussion.php?id=' . $user->id . '&amp;noframesjs=' . $noframesjs . '&amp;newonly=' . $newonly . '&amp;last=' . $last, true);
    echo '</li><li>';
    message_contact_link($user->id, 'block', false, 'discussion.php?id=' . $user->id . '&amp;noframesjs=' . $noframesjs . '&amp;newonly=' . $newonly . '&amp;last=' . $last, true);
    echo '</li>';
}
echo '<li>';
message_history_link($user->id, 0, false, '', '', 'both');
echo '</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
// class="userinfo"
echo '<div id="send">';
echo '<form id="editing" method="post" action="discussion.php">';
$usehtmleditor = can_use_html_editor() && get_user_preferences('message_usehtmleditor', 0);
echo '<h1><label for="edit-message">' . get_string('sendmessage', 'message') . '</label></h1>';
echo '<div>';
if ($usehtmleditor) {
    print_textarea(true, 8, 34, 100, 100, 'message', $refreshedmessage);
    use_html_editor('message', 'formatblock subscript superscript copy cut paste clean undo redo justifyleft justifycenter justifyright justifyfull lefttoright righttoleft insertorderedlist insertunorderedlist outdent indent inserthorizontalrule createanchor nolink inserttable');
    echo '<input type="hidden" name="format" value="' . FORMAT_HTML . '" />';
} else {
    print_textarea(false, 8, 50, 0, 0, 'message', $refreshedmessage);
    echo '<input type="hidden" name="format" value="' . FORMAT_MOODLE . '" />';
}
echo '</div><div>';
echo '<input type="hidden" name="id" value="' . $user->id . '" />';
echo '<input type="hidden" name="start" value="' . $start . '" />';
echo '<input type="hidden" name="noframesjs" value="' . $noframesjs . '" />';
echo '<input type="hidden" name="last" value="' . time() . '" />';
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:discussion.php

示例10: get_context_instance

     } else {
         $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
     }
     if (!($forum->type == 'news' && !$post->parent && $discussion->timestart > time())) {
         if (time() - $post->created > $CFG->maxeditingtime and !has_capability('mod/forum:editanypost', $modcontext)) {
             error(get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)));
         }
     }
     if ($post->userid != $USER->id and !has_capability('mod/forum:editanypost', $modcontext)) {
         error("You can't edit other people's posts!");
     }
     // Load up the $post variable.
     $post->edit = $edit;
     $post->course = $course->id;
     $post->forum = $forum->id;
     trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext);
     unset($SESSION->fromdiscussion);
 } else {
     if (!empty($delete)) {
         // User is deleting a post
         if (!($post = forum_get_post_full($delete))) {
             error("Post ID was incorrect");
         }
         if (!($discussion = get_record("forum_discussions", "id", $post->discussion))) {
             error("This post is not part of a discussion!");
         }
         if (!($forum = get_record("forum", "id", $discussion->forum))) {
             error("The forum number was incorrect ({$discussion->forum})");
         }
         if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course))) {
             error('Could not get the course module for the forum instance.');
开发者ID:veritech,项目名称:pare-project,代码行数:31,代码来源:post.php

示例11: p

	<input type="hidden" name="id_podcast"  value="<?php 
    p($podcast->id);
    ?>
" />
	<input type="hidden" name="tab"         value="view" />
	<input type="hidden" name="action"      value="create" />
	<input type="hidden" name="pubdate"     value="<?php 
    echo podcast_date_format();
    ?>
" />
	<input type="hidden" name="date_html"      value="<?php 
    echo podcast_date_format_html($podcast->lang);
    ?>
" />
	<input type="hidden" name="duration"    value="00:00:00" />
	<input type="hidden" name="length"      value="000000" />
	<input type="submit" value="<?php 
    print_string('add_item', "podcast");
    ?>
" />
</center>
</form>
<?php 
}
// Editer un article
function podcast_edit_item($podcast, $id)
{
    global $CFG;
    global $USER;
    if (!($cm = get_record("course_modules", "id", $id))) {
        error("Course Module ID was incorrect");
    }
    get_item_podcast($podcast, $id);
}
// Afficher la liste des articles e editer
function get_item_podcast($podcast, $id)
{
    global $CFG;
    $browse = get_string('browse', 'podcast');
    $usehtmleditor = can_use_html_editor();
    if ($items = get_records("podcast_structure", "id_podcast", $podcast->id)) {
        foreach ($items as $item) {
            ?>
			<form name="form<?php 
            echo $item->id;
            ?>
" method="post" action="view.php">
			<center>
			<table cellpadding="5">
			<tr>
				<td align="right" valign="top"><b><?php 
            print_string("title", "podcast");
            ?>
</b></td>
				<td align="left"><input type="text" name="title" size="30" value="<?php 
            p(stripslashes($item->title));
            ?>
" />
				<a href="?id=<?php 
            echo $id;
            ?>
&amp;tab=edit&amp;action=delete&amp;id_item=<?php 
            echo $item->id;
            ?>
" style="color:red;font-size:0.8em;font-weight:bold;">
					<?php 
            print_string('delete', "podcast");
            ?>
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:68,代码来源:lib.php

示例12: print_instruction_form

function print_instruction_form($url, $opt, $label, $selects, $course, $instrid, $edittext = '', $editselect = '', $disabled = false)
{
    // Display Add Instruction Form
    print_box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel');
    $options = array('courseid' => $course->id, 'add' => $opt, 'instrid' => $instrid);
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><td>";
    print_form_start($url, "post");
    echo "<table border='0' cellpadding='5' cellspacing='5' width='650px'>";
    echo "<tr><th colspan='2' align='left'>Add Instructions</th></tr>";
    echo "<tr>";
    echo "<td>Instruction Type:</td>";
    echo "<td>";
    choose_from_menu($selects, 'typeid', $editselect, 'choose', '', '0', false, $disabled);
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>Instruction Text:</td>";
    echo "<td>";
    //print_textfield ('addkeyword', '','',25);
    //print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name);
    print_textarea(can_use_html_editor(), 15, 45, 371, 167, 'instr', $edittext);
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_button($label . " Instructions", $options);
    print_form_end();
    print_single_button($url, array('courseid' => $course->id), "Cancel");
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    print_box_end();
}
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:33,代码来源:view_instructions.php

示例13: can_use_richtext_editor

/**
 * Compatibility stub to provide backward compatibility
 *
 * Determines if the HTML editor is enabled.
 * @deprecated Use {@link can_use_html_editor()} instead.
 */
function can_use_richtext_editor()
{
    return can_use_html_editor();
}
开发者ID:nadavkav,项目名称:rtlMoodle,代码行数:10,代码来源:moodlelib.php

示例14: assignment_base

 /**
  * Constructor for the base assignment class
  *
  * Constructor for the base assignment class.
  * If cmid is set create the cm, course, assignment objects.
  * If the assignment is hidden and the user is not a teacher then
  * this prints a page header and notice.
  *
  * @param cmid   integer, the current course module id - not set for new assignments
  * @param assignment   object, usually null, but if we have it we pass it to save db access
  * @param cm   object, usually null, but if we have it we pass it to save db access
  * @param course   object, usually null, but if we have it we pass it to save db access
  */
 function assignment_base($cmid = 'staticonly', $assignment = NULL, $cm = NULL, $course = NULL)
 {
     if ($cmid == 'staticonly') {
         //use static functions only!
         return;
     }
     global $CFG;
     if ($cm) {
         $this->cm = $cm;
     } else {
         if (!($this->cm = get_coursemodule_from_id('assignment', $cmid))) {
             error('Course Module ID was incorrect');
         }
     }
     $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     if ($course) {
         $this->course = $course;
     } else {
         if (!($this->course = get_record('course', 'id', $this->cm->course))) {
             error('Course is misconfigured');
         }
     }
     if ($assignment) {
         $this->assignment = $assignment;
     } else {
         if (!($this->assignment = get_record('assignment', 'id', $this->cm->instance))) {
             error('assignment ID was incorrect');
         }
     }
     $this->assignment->cmidnumber = $this->cm->id;
     // compatibility with modedit assignment obj
     $this->assignment->courseid = $this->course->id;
     // compatibility with modedit assignment obj
     $this->strassignment = get_string('modulename', 'assignment');
     $this->strassignments = get_string('modulenameplural', 'assignment');
     $this->strsubmissions = get_string('submissions', 'assignment');
     $this->strlastmodified = get_string('lastmodified');
     $this->navigation[] = array('name' => $this->strassignments, 'link' => "index.php?id={$this->course->id}", 'type' => 'activity');
     $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strassignment . ': ' . format_string($this->assignment->name, true));
     // visibility
     $context = get_context_instance(CONTEXT_MODULE, $cmid);
     if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
         $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strassignment);
         $this->navigation[] = array('name' => $this->strassignment, 'link' => '', 'type' => 'activityinstance');
         $navigation = build_navigation($this->navigation);
         print_header($pagetitle, $this->course->fullname, $this->navigation, "", "", true, '', navmenu($this->course, $this->cm));
         notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}");
     }
     $this->currentgroup = groups_get_activity_group($this->cm);
     /// Set up things for a HTML editor if it's needed
     if ($this->usehtmleditor = can_use_html_editor()) {
         $this->defaultformat = FORMAT_HTML;
     } else {
         $this->defaultformat = FORMAT_MOODLE;
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:69,代码来源:lib.php

示例15: forum_restore_mods

function forum_restore_mods($mod, $restore)
{
    global $CFG, $DB;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Forum', $restore, $info['MOD']['#'], array('ASSESSTIMESTART', 'ASSESSTIMEFINISH'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the FORUM record structure
        $forum->course = $restore->course_id;
        $forum->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
        $forum->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $forum->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        // These get dropped in Moodle 1.7 when the new Roles System gets
        // set up. Therefore they might or not be there depending on whether
        // we are restoring a 1.6+ forum or a 1.7 or later forum backup.
        if (isset($info['MOD']['#']['OPEN']['0']['#'])) {
            $forum->open = backup_todb($info['MOD']['#']['OPEN']['0']['#']);
        }
        if (isset($info['MOD']['#']['ASSESSPUBLIC']['0']['#'])) {
            $forum->assesspublic = backup_todb($info['MOD']['#']['ASSESSPUBLIC']['0']['#']);
        }
        $forum->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
        $forum->assesstimestart = backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']);
        $forum->assesstimefinish = backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']);
        $forum->maxbytes = backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
        $forum->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']);
        $forum->forcesubscribe = backup_todb($info['MOD']['#']['FORCESUBSCRIBE']['0']['#']);
        $forum->trackingtype = backup_todb($info['MOD']['#']['TRACKINGTYPE']['0']['#']);
        $forum->rsstype = backup_todb($info['MOD']['#']['RSSTYPE']['0']['#']);
        $forum->rssarticles = backup_todb($info['MOD']['#']['RSSARTICLES']['0']['#']);
        $forum->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $forum->warnafter = isset($info['MOD']['#']['WARNAFTER']['0']['#']) ? backup_todb($info['MOD']['#']['WARNAFTER']['0']['#']) : '';
        $forum->blockafter = isset($info['MOD']['#']['BLOCKAFTER']['0']['#']) ? backup_todb($info['MOD']['#']['BLOCKAFTER']['0']['#']) : '';
        $forum->blockperiod = isset($info['MOD']['#']['BLOCKPERIOD']['0']['#']) ? backup_todb($info['MOD']['#']['BLOCKPERIOD']['0']['#']) : '';
        $forum->completiondiscussions = isset($info['MOD']['#']['COMPLETIONDISCUSSIONS']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONDISCUSSIONS']['0']['#']) : 0;
        $forum->completionreplies = isset($info['MOD']['#']['COMPLETIONREPLIES']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONREPLIES']['0']['#']) : 0;
        $forum->completionposts = isset($info['MOD']['#']['COMPLETIONPOSTS']['0']['#']) ? backup_todb($info['MOD']['#']['COMPLETIONPOSTS']['0']['#']) : 0;
        //We have to recode the scale field if it's <0 (positive is a grade, not a scale)
        if ($forum->scale < 0) {
            $scale = backup_getid($restore->backup_unique_code, "scale", abs($forum->scale));
            if ($scale) {
                $forum->scale = -$scale->new_id;
            }
        }
        $newid = $DB->insert_record("forum", $forum);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "forum") . " \"" . format_string($forum->name, true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            $forum->id = $newid;
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'forum', $mod->id)) {
                //Restore forum_subscriptions
                $status = forum_subscriptions_restore_mods($newid, $info, $restore);
                if ($status) {
                    //Restore forum_discussions
                    $status = forum_discussions_restore_mods($newid, $info, $restore);
                }
                if ($status) {
                    //Restore forum_read
                    $status = forum_read_restore_mods($newid, $info, $restore);
                }
            }
            // If forum type is single, just recreate the initial discussion/post automatically
            // if it hasn't been created still (because no user data was selected on backup or
            // restore.
            if ($forum->type == 'single' && !$DB->record_exists('forum_discussions', array('forum' => $newid))) {
                //Load forum/lib.php
                require_once $CFG->dirroot . '/mod/forum/lib.php';
                // Calculate the default format
                if (can_use_html_editor()) {
                    $defaultformat = FORMAT_HTML;
                } else {
                    $defaultformat = FORMAT_MOODLE;
                }
                //Create discussion/post data
                $sd = new stdClass();
                $sd->course = $forum->course;
                $sd->forum = $newid;
                $sd->name = $forum->name;
                $sd->intro = $forum->intro;
                $sd->assessed = $forum->assessed;
                $sd->messageformat = $defaultformat;
                $sd->mailnow = false;
                //Insert dicussion/post data
                $sdid = forum_add_discussion($sd, $sd->intro, $forum);
                //Now, mark the initial post of the discussion as mailed!
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:restorelib.php


注:本文中的can_use_html_editor函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。