コード例 #1
0
ファイル: mailing.php プロジェクト: jerab/moodle-mod-praxe
 /**
  * Builds and returns the body of the email notification in plain text.
  *
  * @param object $post
  * @param object $userto
  * @return string The email body in plain text format.
  */
 public function makeMailText($post, $userto)
 {
     global $CFG, $cm;
     $praxe = praxe_record::getData();
     if (!isset($userto->viewfullnames[$praxe->id])) {
         if (!($cm = get_coursemodule_from_instance('praxe', $praxe->id, $this->course->id))) {
             print_error('Course Module ID was incorrect');
         }
         $modcontext = context_module::instance($cm->id);
         $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
     } else {
         $viewfullnames = $userto->viewfullnames[$praxe->id];
     }
     //$by = New stdClass;
     //$by->name = fullname($userfrom, $viewfullnames);
     //$by->date = userdate($post->modified, "", $userto->timezone);
     //$strbynameondate = get_string('bynameondate', 'forum', $by);
     $strpraxes = get_string('modulenameplural', 'praxe');
     $posttext = '';
     $posttext = $this->course->shortname . " -> " . $strpraxes . " -> " . format_string($praxe->name, true);
     $posttext .= "\n---------------------------------------------------------------------\n";
     $posttext .= format_string($this->subject, true);
     //$posttext .= "\n".$strbynameondate."\n";
     $posttext .= "\n---------------------------------------------------------------------\n";
     $posttext .= format_text_email(trusttext_strip($post), FORMAT_PLAIN);
     $posttext .= "\n\n---------------------------------------------------------------------\n";
     $site = get_site();
     foreach ($this->linkstofoot as $link) {
         $posttext .= $link->text . ": " . $link->link . "\t";
         //$posttext .= get_string('confirmorrefusestudent','praxe').": ".$CFG->wwwroot.'/course/view.php?id='.$cm->id."\n\n";
     }
     $posttext .= "\n\n" . $site->shortname . ": " . $CFG->wwwroot . "\n";
     return $posttext;
 }
コード例 #2
0
 function apply($discussion, $all, $selected, $formdata)
 {
     global $COURSE, $USER, $CFG;
     // Begin with standard text
     $a = (object) array('name' => fullname($USER, true));
     // TODO Is this needed? It doesn't work; $CFG->stylesheets not there
     //         $allhtml = "<head>";
     //         foreach ($CFG->stylesheets as $stylesheet) {
     //             $allhtml .= '<link rel="stylesheet" type="text/css" href="' .
     //                 $stylesheet . '" />' . "\n";
     //         }
     //         $allhtml .= "</head>\n';
     $allhtml = "<body id='forumng-email'>\n";
     $preface = get_string('forward_preface', 'forumngfeature_forward', $a);
     $allhtml .= $preface;
     $alltext = format_text_email($preface, FORMAT_HTML);
     // Include intro if specified
     if (!preg_match('~^(<br[^>]*>|<p>|</p>|\\s)*$~', $formdata->message['text'])) {
         $alltext .= "\n" . mod_forumng_cron::EMAIL_DIVIDER . "\n";
         $allhtml .= '<hr size="1" noshade="noshade" />';
         // Add intro
         $message = trusttext_strip($formdata->message['text']);
         $allhtml .= format_text($message, $formdata->message['format']);
         $alltext .= format_text_email($message, $formdata->message['format']);
     }
     // Get list of all post ids in discussion order
     $alltext .= "\n" . mod_forumng_cron::EMAIL_DIVIDER . "\n";
     $allhtml .= '<hr size="1" noshade="noshade" />';
     $poststext = '';
     $postshtml = '';
     $discussion->build_selected_posts_email($selected, $poststext, $postshtml);
     $alltext .= $poststext;
     $allhtml .= $postshtml . '</body>';
     $emails = preg_split('~[; ]+~', $formdata->email);
     $subject = $formdata->subject;
     foreach ($emails as $email) {
         $fakeuser = (object) array('email' => $email, 'mailformat' => 1, 'id' => 0);
         $from = $USER;
         $from->maildisplay = 999;
         // Nasty hack required for OU moodle
         if (!email_to_user($fakeuser, $from, $subject, $alltext, $allhtml)) {
             print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $formdata->email);
         }
     }
     // Log that it was sent
     $discussion->log('forward discussion', $formdata->email);
     if (!empty($formdata->ccme)) {
         if (!email_to_user($USER, $from, $subject, $alltext, $allhtml)) {
             print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $USER->email);
         }
     }
     $out = $discussion->init_page($discussion->get_moodle_url(), $this->get_page_name());
     print $out->header();
     print $out->box(get_string('forward_done', 'forumngfeature_forward'));
     print $out->continue_button(new moodle_url('/mod/forumng/discuss.php', $discussion->get_link_params_array()));
     print $out->footer();
 }
コード例 #3
0
 public function apply($discussion, $all, $selected, $formdata)
 {
     global $COURSE, $USER, $CFG;
     // Begin with standard text.
     $a = (object) array('name' => fullname($USER, true));
     $allhtml = "<body id='forumng-email'>\n";
     $preface = get_string('forward_preface', 'forumngfeature_forward', $a);
     $allhtml .= $preface;
     $alltext = format_text_email($preface, FORMAT_HTML);
     // Include intro if specified.
     if (!preg_match('~^(<br[^>]*>|<p>|</p>|\\s)*$~', $formdata->message['text'])) {
         $alltext .= "\n" . \mod_forumng_cron::EMAIL_DIVIDER . "\n";
         $allhtml .= '<hr size="1" noshade="noshade" />';
         // Add intro.
         $message = trusttext_strip($formdata->message['text']);
         $allhtml .= format_text($message, $formdata->message['format']);
         $alltext .= format_text_email($message, $formdata->message['format']);
     }
     // Get list of all post ids in discussion order.
     $alltext .= "\n" . \mod_forumng_cron::EMAIL_DIVIDER . "\n";
     $allhtml .= '<hr size="1" noshade="noshade" />';
     $poststext = '';
     $postshtml = '';
     $discussion->build_selected_posts_email($selected, $poststext, $postshtml);
     $alltext .= $poststext;
     $allhtml .= $postshtml . '</body>';
     $emails = preg_split('~[; ]+~', $formdata->email);
     $subject = $formdata->subject;
     foreach ($emails as $email) {
         $fakeuser = (object) array('email' => $email, 'mailformat' => 1, 'id' => -1);
         $from = $USER;
         $from->maildisplay = 999;
         // Nasty hack required for OU moodle.
         if (!email_to_user($fakeuser, $from, $subject, $alltext, $allhtml)) {
             print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $formdata->email);
         }
     }
     // Log that it was sent.
     $params = array('context' => $discussion->get_forum()->get_context(), 'objectid' => $discussion->get_id(), 'other' => array('logurl' => $discussion->get_log_url(), 'info' => $formdata->email));
     $event = \forumngfeature_forward\event\discussion_forwarded::create($params);
     $event->add_record_snapshot('course_modules', $discussion->get_course_module());
     $event->add_record_snapshot('course', $discussion->get_course());
     $event->trigger();
     if (!empty($formdata->ccme)) {
         if (!email_to_user($USER, $from, $subject, $alltext, $allhtml)) {
             print_error('error_forwardemail', 'forumng', $discussion->get_moodle_url(), $USER->email);
         }
     }
     if ($this->printout) {
         $out = $discussion->init_page($discussion->get_moodle_url(), $this->get_page_name());
         print $out->header();
         print $out->box(get_string('forward_done', 'forumngfeature_forward'));
         print $out->continue_button(new \moodle_url('/mod/forumng/discuss.php', $discussion->get_link_params_array()));
         print $out->footer();
     }
 }
コード例 #4
0
 function apply($discussion, $all, $selected, $formdata)
 {
     global $COURSE, $USER, $CFG;
     // Begin with standard text
     $a = (object) array('name' => fullname($USER, true));
     $allhtml = "<head>";
     foreach ($CFG->stylesheets as $stylesheet) {
         $allhtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n";
     }
     $allhtml .= "</head>\n<body id='forumng-email'>\n";
     $preface = get_string('forward_preface', 'forumng', $a);
     $allhtml .= $preface;
     $alltext = format_text_email($preface, FORMAT_HTML);
     // Include intro if specified
     if (!preg_match('~^(<br[^>]*>|<p>|</p>|\\s)*$~', $formdata->message)) {
         $alltext .= "\n" . forum_cron::EMAIL_DIVIDER . "\n";
         $allhtml .= '<hr size="1" noshade="noshade" />';
         // Add intro
         $message = trusttext_strip(stripslashes($formdata->message));
         $allhtml .= format_text($message, $formdata->format);
         $alltext .= format_text_email($message, $formdata->format);
     }
     // Get list of all post ids in discussion order
     $alltext .= "\n" . forum_cron::EMAIL_DIVIDER . "\n";
     $allhtml .= '<hr size="1" noshade="noshade" />';
     $poststext = '';
     $postshtml = '';
     $discussion->build_selected_posts_email($selected, $poststext, $postshtml);
     $alltext .= $poststext;
     $allhtml .= $postshtml . '</body>';
     $emails = preg_split('~[; ]+~', $formdata->email);
     $subject = stripslashes($formdata->subject);
     foreach ($emails as $email) {
         $fakeuser = (object) array('email' => $email, 'mailformat' => 1, 'id' => 0);
         $from = $USER;
         $from->maildisplay = 999;
         // Nasty hack required for OU moodle
         if (!email_to_user($fakeuser, $from, $subject, $alltext, $allhtml)) {
             print_error('error_forwardemail', 'forumng', $formdata->email);
         }
     }
     // Log that it was sent
     $discussion->log('forward discussion', $formdata->email);
     if (!empty($formdata->ccme)) {
         if (!email_to_user($USER, $from, $subject, $alltext, $allhtml)) {
             print_error('error_forwardemail', 'forumng', $USER->email);
         }
     }
     $discussion->print_subpage_header($this->get_page_name());
     print_box(get_string('forward_done', 'forumng'));
     print_continue('../../discuss.php?' . $discussion->get_link_params(forum::PARAM_PLAIN));
     print_footer($COURSE);
 }
コード例 #5
0
ファイル: import.php プロジェクト: verbazend/AWFA
            }
        } else {
            echo $OUTPUT->notification("Error while trying to create the new glossary.");
            echo $OUTPUT->footer();
            exit;
        }
    }

    $xmlentries = $xml['GLOSSARY']['#']['INFO'][0]['#']['ENTRIES'][0]['#']['ENTRY'];
    $sizeofxmlentries = sizeof($xmlentries);
    for($i = 0; $i < $sizeofxmlentries; $i++) {
        // Inserting the entries
        $xmlentry = $xmlentries[$i];
        $newentry = new stdClass();
        $newentry->concept = trim($xmlentry['#']['CONCEPT'][0]['#']);
        $newentry->definition = trusttext_strip($xmlentry['#']['DEFINITION'][0]['#']);
        if ( isset($xmlentry['#']['CASESENSITIVE'][0]['#']) ) {
            $newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#'];
        } else {
            $newentry->casesensitive = $CFG->glossary_casesensitive;
        }

        $permissiongranted = 1;
        if ( $newentry->concept and $newentry->definition ) {
            if ( !$glossary->allowduplicatedentries ) {
                // checking if the entry is valid (checking if it is duplicated when should not be)
                if ( $newentry->casesensitive ) {
                    $dupentry = $DB->record_exists_select('glossary_entries',
                                    'glossaryid = :glossaryid AND concept = :concept', array(
                                        'glossaryid' => $glossary->id,
                                        'concept'    => $newentry->concept));
コード例 #6
0
ファイル: weblib.php プロジェクト: JackCanada/moodle-hacks
function trusttext_prepare_edit(&$text, &$format, $usehtmleditor, $context)
{
    global $CFG;
    $options = new object();
    $options->smiley = false;
    $options->filter = false;
    if (!empty($CFG->enabletrusttext) and has_capability('moodle/site:trustcontent', $context) and trusttext_present($text)) {
        $options->noclean = true;
    } else {
        $options->noclean = false;
    }
    $text = trusttext_strip($text);
    if ($usehtmleditor) {
        $text = format_text($text, $format, $options);
        $format = FORMAT_HTML;
    } else {
        if (!$options->noclean) {
            $text = clean_text($text, $format);
        }
    }
}
コード例 #7
0
ファイル: lib.php プロジェクト: r007/PMoodle
/**
* Given the data about a posting, builds up the HTML to display it and
* returns the HTML in a string.  This is designed for sending via HTML email.
*/
function forum_make_mail_post($course, $forum, $discussion, $post, $userfrom, $userto, $ownpost = false, $reply = false, $link = false, $rate = false, $footer = "")
{
    global $CFG;
    if (!isset($userto->viewfullnames[$forum->id])) {
        if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id))) {
            error('Course Module ID was incorrect');
        }
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
    } else {
        $viewfullnames = $userto->viewfullnames[$forum->id];
    }
    // format the post body
    $options = new object();
    $options->para = true;
    $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $course->id);
    $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
    $output .= '<tr class="header"><td width="35" valign="top" class="picture left">';
    $output .= print_user_picture($userfrom, $course->id, $userfrom->picture, false, true);
    $output .= '</td>';
    if ($post->parent) {
        $output .= '<td class="topic">';
    } else {
        $output .= '<td class="topic starter">';
    }
    $output .= '<div class="subject">' . format_string($post->subject) . '</div>';
    $fullname = fullname($userfrom, $viewfullnames);
    $by = new object();
    $by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $userfrom->id . '&amp;course=' . $course->id . '">' . $fullname . '</a>';
    $by->date = userdate($post->modified, '', $userto->timezone);
    $output .= '<div class="author">' . get_string('bynameondate', 'forum', $by) . '</div>';
    $output .= '</td></tr>';
    $output .= '<tr><td class="left side" valign="top">';
    if (isset($userfrom->groups)) {
        $groups = $userfrom->groups[$forum->id];
    } else {
        if (!($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id))) {
            error('Course Module ID was incorrect');
        }
        $group = groups_get_all_groups($course->id, $userfrom->id, $cm->groupingid);
    }
    if ($groups) {
        $output .= print_group_picture($groups, $course->id, false, true, true);
    } else {
        $output .= '&nbsp;';
    }
    $output .= '</td><td class="content">';
    if ($post->attachment) {
        $post->course = $course->id;
        $output .= '<div class="attachments">';
        $output .= forum_print_attachments($post, 'html');
        $output .= "</div>";
    }
    $output .= $formattedtext;
    // Commands
    $commands = array();
    if ($post->parent) {
        $commands[] = '<a target="_blank" href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '&amp;parent=' . $post->parent . '">' . get_string('parent', 'forum') . '</a>';
    }
    if ($reply) {
        $commands[] = '<a target="_blank" href="' . $CFG->wwwroot . '/mod/forum/post.php?reply=' . $post->id . '">' . get_string('reply', 'forum') . '</a>';
    }
    $output .= '<div class="commands">';
    $output .= implode(' | ', $commands);
    $output .= '</div>';
    // Context link to post if required
    if ($link) {
        $output .= '<div class="link">';
        $output .= '<a target="_blank" href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '#p' . $post->id . '">' . get_string('postincontext', 'forum') . '</a>';
        $output .= '</div>';
    }
    if ($footer) {
        $output .= '<div class="footer">' . $footer . '</div>';
    }
    $output .= '</td></tr></table>' . "\n\n";
    return $output;
}
コード例 #8
0
ファイル: lib.php プロジェクト: nadavkav/MoodleTAO
function glossary_generate_export_file($glossary, $hook = "", $hook = 0)
{
    global $CFG;
    $co = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    $co .= glossary_start_tag("GLOSSARY", 0, true);
    $co .= glossary_start_tag("INFO", 1, true);
    $co .= glossary_full_tag("NAME", 2, false, $glossary->name);
    $co .= glossary_full_tag("INTRO", 2, false, $glossary->intro);
    $co .= glossary_full_tag("ALLOWDUPLICATEDENTRIES", 2, false, $glossary->allowduplicatedentries);
    $co .= glossary_full_tag("DISPLAYFORMAT", 2, false, $glossary->displayformat);
    $co .= glossary_full_tag("SHOWSPECIAL", 2, false, $glossary->showspecial);
    $co .= glossary_full_tag("SHOWALPHABET", 2, false, $glossary->showalphabet);
    $co .= glossary_full_tag("SHOWALL", 2, false, $glossary->showall);
    $co .= glossary_full_tag("ALLOWCOMMENTS", 2, false, $glossary->allowcomments);
    $co .= glossary_full_tag("USEDYNALINK", 2, false, $glossary->usedynalink);
    $co .= glossary_full_tag("DEFAULTAPPROVAL", 2, false, $glossary->defaultapproval);
    $co .= glossary_full_tag("GLOBALGLOSSARY", 2, false, $glossary->globalglossary);
    $co .= glossary_full_tag("ENTBYPAGE", 2, false, $glossary->entbypage);
    if ($entries = get_records("glossary_entries", "glossaryid", $glossary->id)) {
        $co .= glossary_start_tag("ENTRIES", 2, true);
        foreach ($entries as $entry) {
            $permissiongranted = 1;
            if ($hook) {
                switch ($hook) {
                    case "ALL":
                    case "SPECIAL":
                        break;
                    default:
                        $permissiongranted = $entry->concept[strlen($hook) - 1] == $hook;
                        break;
                }
            }
            if ($hook) {
                switch ($hook) {
                    case GLOSSARY_SHOW_ALL_CATEGORIES:
                        break;
                    case GLOSSARY_SHOW_NOT_CATEGORISED:
                        $permissiongranted = !record_exists("glossary_entries_categories", "entryid", $entry->id);
                        break;
                    default:
                        $permissiongranted = record_exists("glossary_entries_categories", "entryid", $entry->id, "categoryid", $hook);
                        break;
                }
            }
            if ($entry->approved and $permissiongranted) {
                $co .= glossary_start_tag("ENTRY", 3, true);
                $co .= glossary_full_tag("CONCEPT", 4, false, trim($entry->concept));
                $co .= glossary_full_tag("DEFINITION", 4, false, trusttext_strip($entry->definition));
                $co .= glossary_full_tag("FORMAT", 4, false, $entry->format);
                $co .= glossary_full_tag("USEDYNALINK", 4, false, $entry->usedynalink);
                $co .= glossary_full_tag("CASESENSITIVE", 4, false, $entry->casesensitive);
                $co .= glossary_full_tag("FULLMATCH", 4, false, $entry->fullmatch);
                $co .= glossary_full_tag("TEACHERENTRY", 4, false, $entry->teacherentry);
                if ($aliases = get_records("glossary_alias", "entryid", $entry->id)) {
                    $co .= glossary_start_tag("ALIASES", 4, true);
                    foreach ($aliases as $alias) {
                        $co .= glossary_start_tag("ALIAS", 5, true);
                        $co .= glossary_full_tag("NAME", 6, false, trim($alias->alias));
                        $co .= glossary_end_tag("ALIAS", 5, true);
                    }
                    $co .= glossary_end_tag("ALIASES", 4, true);
                }
                if ($catentries = get_records("glossary_entries_categories", "entryid", $entry->id)) {
                    $co .= glossary_start_tag("CATEGORIES", 4, true);
                    foreach ($catentries as $catentry) {
                        $category = get_record("glossary_categories", "id", $catentry->categoryid);
                        $co .= glossary_start_tag("CATEGORY", 5, true);
                        $co .= glossary_full_tag("NAME", 6, false, $category->name);
                        $co .= glossary_full_tag("USEDYNALINK", 6, false, $category->usedynalink);
                        $co .= glossary_end_tag("CATEGORY", 5, true);
                    }
                    $co .= glossary_end_tag("CATEGORIES", 4, true);
                }
                $co .= glossary_end_tag("ENTRY", 3, true);
            }
        }
        $co .= glossary_end_tag("ENTRIES", 2, true);
    }
    $co .= glossary_end_tag("INFO", 1, true);
    $co .= glossary_end_tag("GLOSSARY", 0, true);
    return $co;
}
コード例 #9
0
 /**
  * Display a post. This method is used for:
  * - The normal HTML display of a post
  * - HTML email of a post
  * - Text-only email of a post
  * These are all combined in one method since ordinarily they change at
  * the same time (i.e. if adding/hiding information it is usually added to
  * or hidden from all views).
  *
  * $options is an associative array from a forum_post::OPTION_xx constant.
  * All available options are always set - if they were not set by
  * the user, they will have been set to false before this call happens,
  * so there is no need to use empty() or isset().
  *
  * Options are as follows. These are available in email mode:
  *
  * OPTION_TIME_ZONE (int) - Moodle time zone
  * OPTION_VIEW_FULL_NAMES (bool) - If user is allowed to see full names
  * OPTION_EMAIL (bool) - True if this is an email (false = standard view)
  * OPTION_DIGEST (bool) - True if this is part of an email digest
  * OPTION_COMMAND_REPLY (bool) - True if 'Reply' link should be displayed
  *   (available in email too)
  *
  * These options only apply in non-email usage:
  *
  * OPTION_SUMMARY (bool) - True if the entire post should not be displayed,
  *   only a short summary
  * OPTION_NO_COMMANDS (bool) - True if this post is being printed on its own
  * OPTION_COMMAND_EDIT (bool) - Display 'Edit' command
  * OPTION_COMMAND_DELETE (bool) - Display 'Edit' command
  * OPTION_COMMAND_SPLIT (bool) - Display 'Split' command
  * OPTION_RATINGS_VIEW (bool) - True to display current ratings
  * OPTION_RATINGS_EDIT (bool) - True to display ratings edit combo
  * OPTION_LEAVE_DIV_OPEN (bool) - True to not close post div (means that
  *   child posts can be added within).
  * OPTION_EXPANDED (bool) - True to show full post, otherwise abbreviate
  * OPTION_DISCUSSION_SUBJECT (bool) - If true, and only IF post is a 
  *   discussion root, includes subject (HTML, shortened as it would be for
  *   header display) as a hidden field.
  *
  * @param forum_post $post Post object
  * @param bool $html True if using HTML, false to output in plain text
  * @param array $options Associative array of name=>option, as above
  * @return string HTML or text of post
  */
 public function display_post($post, $html, $options)
 {
     global $CFG, $USER, $THEME;
     $discussion = $post->get_discussion();
     $expanded = $options[forum_post::OPTION_EXPANDED];
     $export = $options[forum_post::OPTION_EXPORT];
     $email = $options[forum_post::OPTION_EMAIL];
     // When posts are deleted we hide a lot of info - except when the person
     // viewing it has the ability to view deleted posts.
     $deletedhide = $post->get_deleted() && !$options[forum_post::OPTION_VIEW_DELETED_INFO];
     // Hide deleted messages if they have no replies
     if ($deletedhide && !$email && !$post->has_children()) {
         // note: !email check is to deal with posts that are deleted
         // between when the mail list finds them, and when it sends out
         // mail. It would be confusing to send out a blank email so let's
         // not do that. Also, ->has_children() is not safe to call during
         // email processing because it doesn't load the whole discussion.
         return '';
     }
     // Save some bandwidth by not sending link full paths except in emails
     if ($options[forum_post::OPTION_FULL_ADDRESSES]) {
         $linkprefix = $CFG->wwwroot . '/mod/forumng/';
     } else {
         $linkprefix = '';
     }
     $postnumber = ($options[forum_post::OPTION_NO_COMMANDS] || $email) && !$options[forum_post::OPTION_VISIBLE_POST_NUMBERS] ? '' : $post->get_number();
     $lf = "\n";
     // Initialise result
     $out = '';
     if ($html) {
         if ($export) {
             $out .= '<hr />';
         }
         // Basic intro
         $classes = $expanded ? ' forumng-full' : ' forumng-short';
         $classes .= $post->is_important() ? ' forumng-important' : '';
         $classes .= !$email && !$options[forum_post::OPTION_UNREAD_NOT_HIGHLIGHTED] && $post->is_unread() ? ' forumng-unread' : ' forumng-read';
         $classes .= $post->get_deleted() ? ' forumng-deleted' : '';
         $classes .= ' forumng-p' . $postnumber;
         $out .= $lf . '<div class="forumng-post' . $classes . '"><a id="p' . $post->get_id() . '"></a>';
         if ($options[forum_post::OPTION_FIRST_UNREAD]) {
             $out .= '<a id="firstunread"></a>';
         }
         // Theme hooks
         if (!empty($THEME->forumng_post_hooks)) {
             for ($i = 1; $i <= $THEME->forumng_post_hooks; $i++) {
                 $out .= '<div class="forumng-' . $i . '"></div>';
             }
         }
     }
     if ($html || $options[forum_post::OPTION_VISIBLE_POST_NUMBERS]) {
         // Accessible text giving post a number so we can make links unique
         // etc.
         if ($postnumber) {
             $data = new stdClass();
             $data->num = $postnumber;
             if ($post->get_parent()) {
                 if ($html) {
                     $data->parent = '<a class="forumng-parentlink" href="#p' . $post->get_parent()->get_id() . '">' . $post->get_parent()->get_number() . '</a>';
                 } else {
                     $data->parent = $post->get_parent()->get_number();
                 }
                 $data->info = '';
                 if ($post->is_unread()) {
                     $data->info = get_string('postinfo_unread', 'forumng');
                 }
                 if (!$expanded) {
                     $data->info .= ' ' . get_string('postinfo_short', 'forumng');
                 }
                 if ($post->get_deleted()) {
                     $data->info .= ' ' . get_string('postinfo_deleted', 'forumng');
                 }
                 $data->info = trim($data->info);
                 if ($data->info) {
                     $data->info = ' (' . $data->info . ')';
                 }
                 $info = get_string('postnumreply', 'forumng', $data);
             } else {
                 $info = get_string('postnum', 'forumng', $data);
             }
             if ($options[forum_post::OPTION_VISIBLE_POST_NUMBERS]) {
                 if (!$html) {
                     $out .= "## " . $info . "\n";
                 }
             }
         }
     }
     // Discussion subject (root only)
     if ($options[forum_post::OPTION_DISCUSSION_SUBJECT] && $post->is_root_post()) {
         $out .= '<input type="hidden" name="discussion_subject" value="' . shorten_text(htmlspecialchars($post->get_subject())) . '" />';
     }
     // Pictures (HTML version only)
     if ($html && !$export && $options[forum_post::OPTION_USER_IMAGE]) {
         $out .= $lf . '<div class="forumng-pic">';
         // User picture
         $out .= $deletedhide ? '' : $post->display_user_picture();
         // Group pictures if any - only for expanded version
         if ($expanded) {
             $grouppics = $post->display_group_pictures();
             if ($grouppics) {
                 $out .= '<div class="forumng-grouppicss">' . $grouppics . '</div>';
             }
         }
         $out .= '</div>';
     }
     // Link used to expand post
     $expandlink = '';
     if (!$expanded && !$deletedhide) {
         $expandlink = '&nbsp;[<a class="forumng-expandlink" ' . 'href="' . $linkprefix . 'discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '&amp;expand=1#p' . $post->get_id() . '">' . get_string('expandall', 'forumng') . '</a>] <img src="' . $CFG->pixpath . '/spacer.gif" width="16" height="16" alt="" />';
     }
     // Byline
     $by = new stdClass();
     $by->name = $deletedhide ? '' : fullname($post->get_user(), $options[forum_post::OPTION_VIEW_FULL_NAMES]);
     $by->date = $deletedhide ? '' : userdate($post->get_created(), get_string('strftimedatetime', 'langconfig'), $options[forum_post::OPTION_TIME_ZONE]);
     if ($html) {
         $out .= $lf . '<div class="forumng-info"><h2 class="forumng-author">';
         $out .= $post->is_important() ? '<img src="' . $CFG->modpixpath . '/forumng/exclamation_mark.gif" alt="' . get_string('important', 'forumng') . '" ' . 'title = "' . get_string('important', 'forumng') . '"/>' : '';
         if ($export) {
             $out .= $by->name;
         } else {
             $out .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_user()->id . ($post->get_forum()->is_shared() ? '' : '&amp;course=' . $post->get_forum()->get_course_id()) . '">' . $by->name . '</a>';
         }
         if ($postnumber) {
             if ($options[forum_post::OPTION_VISIBLE_POST_NUMBERS]) {
                 $out .= '<span class="accesshide" style="position:static"> ' . $info . ' </span>';
             } else {
                 $out .= '<span class="accesshide"> ' . $info . ' </span>';
             }
         }
         $out .= $deletedhide ? '' : '</h2> <span class="forumng-separator">&#x2022;</span> ';
         $out .= '<span class="forumng-date">' . $by->date . '</span>';
         if ($edituser = $post->get_edit_user()) {
             $out .= ' <span class="forumng-separator">&#x2022;</span> ' . '<span class="forumng-edit">';
             $edit = new stdClass();
             $edit->date = userdate($post->get_modified(), get_string('strftimedatetime', 'langconfig'), $options[forum_post::OPTION_TIME_ZONE]);
             $edit->name = fullname($edituser, $options[forum_post::OPTION_VIEW_FULL_NAMES]);
             if ($edituser->id == $post->get_user()->id) {
                 $out .= get_string('editbyself', 'forumng', $edit->date);
             } else {
                 $out .= get_string('editbyother', 'forumng', $edit);
             }
             if ($options[forum_post::OPTION_COMMAND_HISTORY]) {
                 $out .= ' (<a href="history.php?' . $post->get_link_params(forum::PARAM_HTML) . '">' . get_string('history', 'forumng') . '</a>)';
             }
             $out .= '</span>';
         }
         if ($options[forum_post::OPTION_SELECTABLE]) {
             $out .= ' &#x2022; <input type="checkbox" name="selectp' . $post->get_id() . '" id="id_selectp' . $post->get_id() . '" /><label class="accesshide" for="id_selectp' . $post->get_id() . '">' . get_string('selectlabel', 'forumng', $postnumber) . '</label>';
         }
         if ($options[forum_post::OPTION_FLAG_CONTROL]) {
             $out .= '<div class="forumng-flag">' . '<input type="image" title="' . get_string($post->is_flagged() ? 'clearflag' : 'setflag', 'forumng') . '" src="' . $CFG->modpixpath . '/forumng/flag.' . ($post->is_flagged() ? 'on' : 'off') . '.png" alt="' . get_string($post->is_flagged() ? 'flagon' : 'flagoff', 'forumng') . '" name="action.flag.p_' . $post->get_id() . '.timeread_' . $options[forum_post::OPTION_READ_TIME] . '.flag_' . ($post->is_flagged() ? 0 : 1) . '"/></div>';
         }
         $out .= '</div>';
     } else {
         $out .= $by->name . ' - ' . $by->date . $lf;
         $out .= forum_cron::EMAIL_DIVIDER;
     }
     if ($post->get_deleted()) {
         $out .= '<p class="forumng-deleted-info"><strong>' . get_string('deletedpost', 'forumng') . '</strong> ';
         if ($deletedhide) {
             $out .= get_string($post->get_delete_user()->id == $post->get_user()->id ? 'deletedbyauthor' : 'deletedbymoderator', 'forumng', userdate($post->get_deleted()));
         } else {
             $a = new stdClass();
             $a->date = userdate($post->get_deleted());
             $a->user = '******' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_delete_user()->id . '&amp;course=' . $post->get_forum()->get_course_id() . '">' . fullname($post->get_delete_user(), $options[forum_post::OPTION_VIEW_FULL_NAMES]) . '</a>';
             $out .= get_string('deletedbyuser', 'forumng', $a);
         }
         $out .= '</p>';
     }
     // Get subject. This may make a db query when showing a single post
     // (which includes parent subject).
     if ($options[forum_post::OPTION_EMAIL] || $options[forum_post::OPTION_NO_COMMANDS]) {
         $subject = $post->get_effective_subject(true);
     } else {
         $subject = $post->get_subject();
     }
     // Otherwise, subject is only displayed if it has changed
     if ($subject !== null && $expanded && !$deletedhide) {
         if ($html) {
             $out .= $lf . '<h3 class="forumng-subject">';
             if ($options[forum_post::OPTION_DIGEST]) {
                 // Digest contains link to original post
                 $out .= '<a href="' . $linkprefix . 'discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '#p' . $post->get_id() . '">' . format_string($subject) . '</a>';
             } else {
                 $out .= format_string($subject);
             }
             $out .= '</h3>';
         } else {
             $out .= format_string($subject, true);
             if ($options[forum_post::OPTION_DIGEST]) {
                 // Link to original post
                 $out .= " <{$linkprefix}discuss.php?" . $discussion->get_link_params(forum::PARAM_HTML) . $discussion->get_id() . '#p' . $post->get_id() . '>';
             }
             $out .= $lf;
         }
     }
     // Get content of actual message in HTML
     if ($html) {
         $textoptions = new stdClass();
         // Don't put a <p> tag round post
         $textoptions->para = false;
         // Does not indicate that we trust the text, only that the
         // TRUSTTEXT marker is supported.
         $textoptions->trusttext = true;
         $message = format_text($post->get_message(), $post->get_format(), $textoptions, $post->get_forum()->get_course_id());
         if (!$expanded && !$deletedhide) {
             // When not expanded and no subject, we include a summary of the
             // message
             $stripped = strip_tags(preg_replace('~<script.*?</script>~s', '', $message));
             $messagetosummarise = $subject !== null ? '<h3>' . $subject . '</h3>&nbsp;' . $stripped : $stripped;
             $summary = self::nice_shorten_text($messagetosummarise, 50);
             $out .= $lf . '<div class="forumng-summary"><div class="forumng-text">' . $summary . '</div> ' . $expandlink . '</div>';
         }
     }
     // Start of post main section
     if ($expanded && !$deletedhide) {
         if ($html) {
             $out .= '<div class="forumng-postmain">';
         }
         // Attachments
         $attachments = $post->get_attachment_names();
         if (count($attachments)) {
             if ($html) {
                 $out .= $lf . '<ul class="forumng-attachments">';
             }
             if (count($attachments) == 1) {
                 $attachmentlabel = get_string('attachment', 'forumng');
             } else {
                 $attachmentlabel = get_string('attachments', 'forumng');
             }
             $out .= '<span class="accesshide">' . $attachmentlabel . '</span>';
             foreach ($attachments as $attachment) {
                 if ($html) {
                     require_once $CFG->libdir . '/filelib.php';
                     $iconsrc = $CFG->pixpath . '/f/' . mimeinfo('icon', $attachment);
                     $alt = get_mimetype_description(mimeinfo('type', $attachment));
                     $out .= '<li><a href="' . $linkprefix . 'attachment.php?' . $post->get_link_params(forum::PARAM_HTML) . '&amp;file=' . $attachment . '">' . '<img src="' . $iconsrc . '" alt="' . $alt . '" /> <span>' . htmlspecialchars($attachment) . '</span></a></li>';
                 } else {
                     // Right-align the entry to 70 characters
                     $padding = 70 - strlen($attachment);
                     if ($padding > 0) {
                         $out .= str_repeat(' ', $padding);
                     }
                     // Add filename
                     $out .= $attachment . $lf;
                 }
             }
             if ($html) {
                 $out .= '</ul>' . $lf;
             } else {
                 $out .= $lf;
                 // Extra line break after attachments
             }
         }
         // Display actual content
         if ($html) {
             if ($options[forum_post::OPTION_PRINTABLE_VERSION]) {
                 $message = preg_replace('~<a[^>]*\\shref\\s*=\\s*[\'"](http:.*?)[\'"][^>]*>' . '(?!(http:|www\\.)).*?</a>~', "\$0 [\$1]", $message);
             }
             $out .= $lf . '<div class="forumng-message">' . $message . '</div>';
         } else {
             $out .= format_text_email(trusttext_strip($post->get_message()), $post->get_format());
             $out .= "\n\n";
         }
         if ($html) {
             $out .= $lf . '<div class="forumng-postfooter">';
         }
         // Ratings
         $ratings = '';
         $ratingclasses = '';
         if ($options[forum_post::OPTION_RATINGS_VIEW]) {
             $ratingclasses .= ' forumng-canview';
             if ($post->get_num_ratings() >= $post->get_forum()->get_rating_threshold()) {
                 if ($html) {
                     $ratings .= '<div class="forumng-rating">';
                     $a = new stdClass();
                     $a->avg = '<strong id="rating_for_' . $post->get_id() . '">' . $post->get_average_rating(true) . '</strong>';
                     $a->num = '<span class="forumng-count">' . $post->get_num_ratings() . '</span>';
                     $ratings .= get_string('averagerating', 'forumng', $a);
                     $ratings .= '</div>';
                 } else {
                     $ratings .= strip_tags($post->get_average_rating(true));
                 }
             }
         }
         if ($options[forum_post::OPTION_RATINGS_EDIT] && $html) {
             $ratingclasses .= ' forumng-canedit';
             $ratings .= '<div class="forumng-editrating">' . get_string('yourrating', 'forumng') . ' ';
             $ratings .= choose_from_menu($post->get_forum()->get_rating_options(), 'rating' . $post->get_id(), $post->get_own_rating(), '-', '', forum_post::NO_RATING, true);
             $ratings .= '</div>';
         }
         if ($ratings) {
             $out .= '<div class="forumng-ratings' . $ratingclasses . '">' . $ratings . '</div>';
         }
         // Commands at bottom of mail
         if (class_exists('ouflags') && ou_get_is_mobile_from_cookies()) {
             $mobileclass = ' class="forumng-mobilepost-link"';
         } else {
             $mobileclass = '';
         }
         if ($html) {
             $commands = '';
             $expires = $post->can_ignore_edit_time_limit() ? '' : '&amp;expires=' . ($post->get_edit_time_limit() - time());
             // Jump box
             if ($options[forum_post::OPTION_JUMP_PREVIOUS] || $options[forum_post::OPTION_JUMP_NEXT] || $options[forum_post::OPTION_JUMP_PARENT]) {
                 $commands .= '<li class="forumng-jumpto">' . get_string('jumpto', 'forumng');
                 if ($nextid = $options[forum_post::OPTION_JUMP_NEXT]) {
                     $commands .= ' <a href="#p' . $nextid . '" class="forumng-next">' . get_string('jumpnext', 'forumng') . '</a>';
                 }
                 if ($pid = $options[forum_post::OPTION_JUMP_PREVIOUS]) {
                     if ($nextid) {
                         $commands .= ' (<a href="#p' . $pid . '" class="forumng-prev">' . get_string('jumppreviousboth', 'forumng') . '</a>)';
                     } else {
                         $commands .= ' <a href="#p' . $pid . '" class="forumng-prev">' . get_string('jumpprevious', 'forumng') . '</a>';
                     }
                 }
                 if ($parentid = $options[forum_post::OPTION_JUMP_PARENT]) {
                     $commands .= ' <a href="#p' . $parentid . '" class="forumng-parent">' . get_string('jumpparent', 'forumng') . '</a>';
                 }
                 $commands .= '</li>';
             }
             //Direct link
             if ($options[forum_post::OPTION_COMMAND_DIRECTLINK]) {
                 $commands .= '<li class="forumng-permalink"><a href="discuss.php?' . $discussion->get_link_params(forum::PARAM_HTML) . '#p' . $post->get_id() . '" title="' . get_string('directlinktitle', 'forumng') . '">' . get_string('directlink', 'forumng', $postnumber) . '</a></li>';
             }
             // Alert link
             if ($options[forum_post::OPTION_COMMAND_REPORT]) {
                 $commands .= '<li><a href="' . $linkprefix . 'alert.php?' . $post->get_link_params(forum::PARAM_HTML) . '" title="' . get_string('alert_linktitle', 'forumng') . '">' . get_string('alert_link', 'forumng', $postnumber) . '</a></li>';
             }
             // Split link
             if ($options[forum_post::OPTION_COMMAND_SPLIT]) {
                 $commands .= '<li class="forumng-split"><a href="' . $linkprefix . 'splitpost.php?' . $post->get_link_params(forum::PARAM_HTML) . '">' . get_string('split', 'forumng', $postnumber) . '</a></li>';
             }
             // Delete link
             if ($options[forum_post::OPTION_COMMAND_DELETE]) {
                 $commands .= '<li><a' . $mobileclass . ' href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(forum::PARAM_HTML) . $expires . '">' . get_string('delete', 'forumng', $postnumber) . '</a></li>';
             }
             // Undelete link
             if ($options[forum_post::OPTION_COMMAND_UNDELETE]) {
                 $commands .= '<li><a href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(forum::PARAM_HTML) . '&amp;delete=0">' . get_string('undelete', 'forumng', $postnumber) . '</a></li>';
             }
             // Edit link
             if ($options[forum_post::OPTION_COMMAND_EDIT]) {
                 $commands .= '<li><a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?' . $post->get_link_params(forum::PARAM_HTML) . $expires . '">' . get_string('edit', 'forumng', $postnumber) . '</a></li>';
             }
             // Reply link
             if ($options[forum_post::OPTION_COMMAND_REPLY]) {
                 $commands .= '<li class="forumng-replylink"><a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?replyto=' . $post->get_id() . $post->get_forum()->get_clone_param(forum::PARAM_HTML) . '">' . get_string('reply', 'forumng', $postnumber) . '</a></li>';
             }
             if ($commands) {
                 $out .= $lf . '<ul class="forumng-commands">' . $commands . '</ul>';
             }
         } else {
             // Reply link
             if ($options[forum_post::OPTION_COMMAND_REPLY]) {
                 $out .= forum_cron::EMAIL_DIVIDER;
                 if ($options[forum_post::OPTION_EMAIL]) {
                     $course = $post->get_forum()->get_course();
                     $out .= get_string("postmailinfo", "forumng", $course->shortname) . $lf;
                 }
                 $out .= "{$linkprefix}editpost.php?replyto=" . $post->get_id() . $post->get_forum()->get_clone_param(forum::PARAM_PLAIN) . $lf;
             }
             // Only the reply command is available in text mode
         }
         // End of post footer and main section
         if ($html) {
             $out .= '</div></div>';
         }
     }
     // End of post div
     if ($html) {
         $out .= '<div class="forumng-endpost"></div></div>';
         if ($export) {
             $out .= '<br /><br />';
         }
     }
     return $out;
 }
コード例 #10
0
ファイル: lib.php プロジェクト: njorth/marginalia
/**
* Given the data about a posting, builds up the HTML to display it and
* returns the HTML in a string.  This is designed for sending via HTML email.
*/
function forum_make_mail_post(&$post, $user, $touser, $course, $ownpost = false, $reply = false, $link = false, $rate = false, $footer = "")
{
    global $CFG, $USER;
    // the old caching was removed for now, because it did not work due to recent changes in cron
    $post->forum = get_field('forum_discussions', 'forum', 'id', $post->discussion);
    if (!($cm = get_coursemodule_from_instance('forum', $post->forum))) {
        mtrace('Course Module ID was incorrect');
    }
    $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
    // format the post body
    $options = new object();
    $options->para = true;
    $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $course->id);
    $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
    $output .= '<tr class="header"><td width="35" valign="top" class="picture left">';
    $output .= print_user_picture($user->id, $course->id, $user->picture, false, true);
    $output .= '</td>';
    if ($post->parent) {
        $output .= '<td class="topic" colspan="3">';
    } else {
        $output .= '<td class="topic starter" colspan="3">';
    }
    $output .= '<div class="subject ' . PM_TITLE_CLASS . '">' . format_string($post->subject) . '</div>';
    // #GEOF# Annotations must use a unique value for the user ID
    // This should be a string, and it should be human-readable and suitable for
    // outside consumption.  I'm therefore using username rather than ID.
    // If Moodle displayed these values, the fields wouldn'n need to be hidden.
    $rootpath = $CFG->wwwroot;
    //parse_url( $CFG->wwwroot );
    //$rootpath = $rootpath[ 'path' ];
    $refUrl = "{$rootpath}/mod/forum/permalink.php?p={$post->id}";
    $discussUrl = "{$rootpath}/mod/forum/discuss.php?d={$post->discussion}";
    // used for summary link
    // This class author, used by Marginalia, must preceed the one below, used by Moodle (well, not in Moodle 1.8).
    // Unfortunately I can't use that one - it's marked author but it is not, in fact, the author
    // - it also includes "by", the date, etc.  (grrr) #geof#
    echo "<span style='display:none' class='" . PM_AUTHOR_CLASS . "' title='" . htmlspecialchars($post->username) . "'>" . htmlspecialchars($post->firstname . ' ' . $post->lastname) . "</span>\n";
    echo "<abbr style='display:none' class='" . PM_DATE_CLASS . "' title='" . date('Ymd', $post->modified) . 'T' . date('HiO', $post->modified) . "'></abbr>\n";
    echo "<a style='display:none' rel='" . PM_URL_REL . "' href='{$refurl}'></a>\n";
    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $modcontext));
    $by = new object();
    $by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&amp;course=' . $course->id . '">' . $fullname . '</a>';
    $by->date = userdate($post->modified, '', $touser->timezone);
    // This, I presume, is to localize string display.  Unfortunately it's
    // unstructured text, so I can't insert the necessary <abbr> element with the date.
    // Instead that's done in a hidden tag above.
    $output .= '<div class="author">' . get_string('bynameondate', 'forum', $by) . '</div>';
    $output .= '</td></tr>';
    $output .= '<tr><td class="left side" valign="top">';
    if ($group = user_group($course->id, $user->id)) {
        $output .= print_group_picture($group, $course->id, false, true, true);
    } else {
        $output .= '&nbsp;';
    }
    $output .= '</td><td class="content">';
    if ($post->attachment) {
        $post->course = $course->id;
        $output .= '<div class="attachments">';
        $output .= forum_print_attachments($post, 'html');
        $output .= "</div>";
    }
    $output .= $formattedtext;
    // Commands
    $commands = array();
    if ($post->parent) {
        $commands[] = '<a target="_blank" href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '&amp;parent=' . $post->parent . '">' . get_string('parent', 'forum') . '</a>';
    }
    // The span below is to allow text-decoration:underline, which doesn't seem
    // to work otherwise (Firefox bug?)
    $commands[] = "<button class='smartquote'><span>Quote</span></button>";
    if ($reply) {
        $commands[] = '<a target="_blank" href="' . $CFG->wwwroot . '/mod/forum/post.php?reply=' . $post->id . '">' . get_string('reply', 'forum') . '</a>';
    }
    $output .= '<div class="commands">';
    $output .= implode(' | ', $commands);
    $output .= '</div>';
    // Context link to post if required
    if ($link) {
        $output .= '<div class="link">';
        $output .= '<a target="_blank" href="' . $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $post->discussion . '#p' . $post->id . '">' . get_string('postincontext', 'forum') . '</a>';
        $output .= '</div>';
    }
    if ($footer) {
        $output .= '<div class="footer">' . $footer . '</div>';
    }
    $output .= '</td></tr></table>' . "\n\n";
    return $output;
}
コード例 #11
0
ファイル: search.php プロジェクト: veritech/pare-project
    $message = str_replace('</fgw9sdpq4>', '</span>', $message);
    if ($missing_terms) {
        $strmissingsearchterms = get_string('missingsearchterms', 'forum');
        $post->message = '<p class="highlight2">' . $strmissingsearchterms . ' ' . $missing_terms . '</p>' . $message;
        $ttpresent = false;
    } else {
        $post->message = $message;
    }
    $fulllink = "<a href=\"discuss.php?d={$post->discussion}#p{$post->id}\">" . get_string("postincontext", "forum") . "</a>";
    //search terms already highlighted - fiedorow - 9/2/2005
    $SESSION->forum_search = true;
    // reconstruct the TRUSTTEXT properly after processing
    if ($ttpresent) {
        $post->message = trusttext_mark($post->message);
    } else {
        $post->message = trusttext_strip($post->message);
        //make 100% sure TRUSTTEXT marker was not created during processing
    }
    forum_print_post($post, $course->id, false, false, false, false, $fulllink);
    unset($SESSION->forum_search);
    echo "<br />";
}
print_paging_bar($totalcount, $page, $perpage, "search.php?search=" . urlencode(stripslashes($search)) . "&amp;id={$course->id}&amp;perpage={$perpage}&amp;");
print_footer($course);
/**
 * @todo Document this function
 */
function forum_print_big_search_form($course)
{
    global $CFG, $words, $subject, $phrase, $user, $userid, $fullwords, $notwords, $datefrom, $dateto;
    print_simple_box(get_string('searchforumintro', 'forum'), 'center', '', '', 'searchbox', 'intro');
コード例 #12
0
ファイル: import.php プロジェクト: gabrielrosset/moodle
         echo $OUTPUT->footer();
         exit;
     }
 }
 $xmlentries = $xml['GLOSSARY']['#']['INFO'][0]['#']['ENTRIES'][0]['#']['ENTRY'];
 $sizeofxmlentries = sizeof($xmlentries);
 for ($i = 0; $i < $sizeofxmlentries; $i++) {
     // Inserting the entries
     $xmlentry = $xmlentries[$i];
     $newentry = new stdClass();
     $newentry->concept = trim($xmlentry['#']['CONCEPT'][0]['#']);
     $definition = $xmlentry['#']['DEFINITION'][0]['#'];
     if (!is_string($definition)) {
         print_error('errorparsingxml', 'glossary');
     }
     $newentry->definition = trusttext_strip($definition);
     if (isset($xmlentry['#']['CASESENSITIVE'][0]['#'])) {
         $newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#'];
     } else {
         $newentry->casesensitive = $CFG->glossary_casesensitive;
     }
     $permissiongranted = 1;
     if ($newentry->concept and $newentry->definition) {
         if (!$glossary->allowduplicatedentries) {
             // checking if the entry is valid (checking if it is duplicated when should not be)
             if ($newentry->casesensitive) {
                 $dupentry = $DB->record_exists_select('glossary_entries', 'glossaryid = :glossaryid AND concept = :concept', array('glossaryid' => $glossary->id, 'concept' => $newentry->concept));
             } else {
                 $dupentry = $DB->record_exists_select('glossary_entries', 'glossaryid = :glossaryid AND LOWER(concept) = :concept', array('glossaryid' => $glossary->id, 'concept' => core_text::strtolower($newentry->concept)));
             }
             if ($dupentry) {
 $questiontype = $questiontypeparams[0];
 if ($questiontype == 'multichoice') {
     $answernumbering = $questiontypeparams[1];
     $concepts = array();
     foreach ($entries as $entry) {
         $concepts[] = $entry->concept;
     }
 } else {
     $usecase = $questiontypeparams[1];
 }
 foreach ($entries as $entry) {
     $counter++;
     $definition = trusttext_strip($entry->definition);
     $fs = get_file_storage();
     $entryfiles = $fs->get_area_files($context->id, 'mod_glossary', 'entry', $entry->id);
     $concept = trusttext_strip($entry->concept);
     $expout .= "\n\n<!-- question: {$counter}  -->\n";
     $nametext = writetext($concept);
     $qtformat = "html";
     $expout .= "  <question type=\"{$questiontype}\">\n";
     $expout .= "    <name>{$nametext}</name>\n";
     $expout .= "    <questiontext format=\"{$qtformat}\">\n";
     $expout .= writetext($definition);
     $expout .= writefiles($entryfiles);
     $expout .= "    </questiontext>\n";
     if ($questiontype == 'multichoice') {
         $expout .= "    <shuffleanswers>true</shuffleanswers>\n";
         $expout .= "    <answernumbering>" . $answernumbering . "</answernumbering>\n";
         $concepts2 = $concepts;
         foreach ($concepts2 as $key => $value) {
             if ($value == $concept) {
コード例 #14
0
ファイル: upgrade.php プロジェクト: nicolasconnault/moodle2.0
function xmldb_forum_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    // loads ddl manager and xmldb classes
    $result = true;
    //===== 1.9.0 upgrade line ======//
    if ($result and $oldversion < 2007101511) {
        //MDL-13866 - send forum ratins to gradebook again
        require_once $CFG->dirroot . '/mod/forum/lib.php';
        forum_upgrade_grades();
        upgrade_mod_savepoint($result, 2007101511, 'forum');
    }
    if ($result && $oldversion < 2007101512) {
        /// Cleanup the forum subscriptions
        notify('Removing stale forum subscriptions', 'notifysuccess');
        $roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW);
        $roles = array_keys($roles);
        list($usql, $params) = $DB->get_in_or_equal($roles);
        $sql = "SELECT fs.userid, f.id AS forumid\n                  FROM {forum} f\n                       JOIN {course} c                 ON c.id = f.course\n                       JOIN {context} ctx              ON (ctx.instanceid = c.id AND ctx.contextlevel = " . CONTEXT_COURSE . ")\n                       JOIN {forum_subscriptions} fs   ON fs.forum = f.id\n                       LEFT JOIN {role_assignments} ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid {$usql})\n                 WHERE ra.id IS NULL";
        if ($rs = $DB->get_recordset_sql($sql, $params)) {
            foreach ($rs as $remove) {
                $DB->delete_records('forum_subscriptions', array('userid' => $remove->userid, 'forum' => $remove->forumid));
                echo '.';
            }
            $rs->close();
        }
        upgrade_mod_savepoint($result, 2007101512, 'forum');
    }
    if ($result && $oldversion < 2008072800) {
        /// Define field completiondiscussions to be added to forum
        $table = new xmldb_table('forum');
        $field = new xmldb_field('completiondiscussions');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'blockperiod');
        /// Launch add field completiondiscussions
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('completionreplies');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiondiscussions');
        /// Launch add field completionreplies
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        /// Define field completionposts to be added to forum
        $field = new xmldb_field('completionposts');
        $field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionreplies');
        /// Launch add field completionposts
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_mod_savepoint($result, 2008072800, 'forum');
    }
    if ($result && $oldversion < 2008081900) {
        /////////////////////////////////////
        /// new file storage upgrade code ///
        /////////////////////////////////////
        $fs = get_file_storage();
        $empty = $DB->sql_empty();
        // silly oracle empty string handling workaround
        $sqlfrom = "FROM {forum_posts} p\n                    JOIN {forum_discussions} d ON d.id = p.discussion\n                    JOIN {forum} f ON f.id = d.forum\n                    JOIN {modules} m ON m.name = 'forum'\n                    JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = f.id)\n                   WHERE p.attachment <> '{$empty}' AND p.attachment <> '1'";
        $count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}");
        if ($rs = $DB->get_recordset_sql("SELECT p.id, p.attachment, d.forum, f.course, cm.id AS cmid {$sqlfrom} ORDER BY f.course, f.id, d.id")) {
            $pbar = new progress_bar('migrateforumfiles', 500, true);
            $i = 0;
            foreach ($rs as $post) {
                $i++;
                upgrade_set_timeout(60);
                // set up timeout, may also abort execution
                $pbar->update($i, $count, "Migrating forum posts - {$i}/{$count}.");
                $filepath = "{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum/{$post->forum}/{$post->id}/{$post->attachment}";
                if (!is_readable($filepath)) {
                    //file missing??
                    notify("File not readable, skipping: " . $filepath);
                    $post->attachment = '';
                    $DB->update_record('forum_posts', $post);
                    continue;
                }
                $context = get_context_instance(CONTEXT_MODULE, $post->cmid);
                $filearea = 'forum_attachment';
                $filename = clean_param($post->attachment, PARAM_FILE);
                if ($filename === '') {
                    notify("Unsupported post filename, skipping: " . $filepath);
                    $post->attachment = '';
                    $DB->update_record('forum_posts', $post);
                    continue;
                }
                if (!$fs->file_exists($context->id, $filearea, $post->id, '/', $filename)) {
                    $file_record = array('contextid' => $context->id, 'filearea' => $filearea, 'itemid' => $post->id, 'filepath' => '/', 'filename' => $filename, 'userid' => $post->userid);
                    if ($fs->create_file_from_pathname($file_record, $filepath)) {
                        $post->attachment = '1';
                        if ($DB->update_record('forum_posts', $post)) {
                            unlink($filepath);
                        }
                    }
                }
                // remove dirs if empty
                @rmdir("{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum/{$post->forum}/{$post->id}");
                @rmdir("{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum/{$post->forum}");
                @rmdir("{$CFG->dataroot}/{$post->course}/{$CFG->moddata}/forum");
            }
            $rs->close();
        }
        upgrade_mod_savepoint($result, 2008081900, 'forum');
    }
    if ($result && $oldversion < 2008090800) {
        /// Define field maxattachments to be added to forum
        $table = new xmldb_table('forum');
        $field = new xmldb_field('maxattachments', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'maxbytes');
        /// Conditionally launch add field maxattachments
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        /// forum savepoint reached
        upgrade_mod_savepoint($result, 2008090800, 'forum');
    }
    if ($result && $oldversion < 2009042000) {
        /// Rename field format on table forum_posts to messageformat
        $table = new xmldb_table('forum_posts');
        $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'message');
        /// Launch rename field format
        $dbman->rename_field($table, $field, 'messageformat');
        /// forum savepoint reached
        upgrade_mod_savepoint($result, 2009042000, 'forum');
    }
    if ($result && $oldversion < 2009042001) {
        /// Define field messagetrust to be added to forum_posts
        $table = new xmldb_table('forum_posts');
        $field = new xmldb_field('messagetrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'messageformat');
        /// Launch add field messagetrust
        $dbman->add_field($table, $field);
        /// forum savepoint reached
        upgrade_mod_savepoint($result, 2009042001, 'forum');
    }
    if ($result && $oldversion < 2009042002) {
        $trustmark = '#####TRUSTTEXT#####';
        $rs = $DB->get_recordset_sql("SELECT * FROM {forum_posts} WHERE message LIKE '{$trustmark}%'");
        foreach ($rs as $post) {
            if (strpos($post->entrycomment, $trustmark) !== 0) {
                // probably lowercase in some DBs
                continue;
            }
            $post->message = trusttext_strip($post->message);
            $post->messagetrust = 1;
            $DB->update_record('forum_posts', $post);
        }
        $rs->close();
        /// forum savepoint reached
        upgrade_mod_savepoint($result, 2009042002, 'forum');
    }
    if ($result && $oldversion < 2009042003) {
        /// Define field introformat to be added to forum
        $table = new xmldb_table('forum');
        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
        /// Launch add field introformat
        $dbman->add_field($table, $field);
        /// forum savepoint reached
        upgrade_mod_savepoint($result, 2009042003, 'forum');
    }
    if ($result && $oldversion < 2009042004) {
        /// set format to current
        $DB->set_field('forum', 'introformat', FORMAT_MOODLE, array());
        /// quiz savepoint reached
        upgrade_mod_savepoint($result, 2009042004, 'forum');
    }
    /// Dropping all enums/check contraints from core. MDL-18577
    if ($result && $oldversion < 2009042700) {
        /// Changing list of values (enum) of field type on table forum to none
        $table = new xmldb_table('forum');
        $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
        /// Launch change of list of values for field type
        $dbman->drop_enum_from_field($table, $field);
        /// forum savepoint reached
        upgrade_mod_savepoint($result, 2009042700, 'forum');
    }
    if ($result && $oldversion < 2009050400) {
        /// Clean existing wrong rates. MDL-18227
        $DB->delete_records('forum_ratings', array('post' => 0));
        /// forum savepoint reached
        upgrade_mod_savepoint($result, 2009050400, 'forum');
    }
    return $result;
}
コード例 #15
0
ファイル: upgrade.php プロジェクト: nicolasconnault/moodle2.0
function xmldb_glossary_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    $result = true;
    //===== 1.9.0 upgrade line ======//
    if ($result && $oldversion < 2008081900) {
        /////////////////////////////////////
        /// new file storage upgrade code ///
        /////////////////////////////////////
        $fs = get_file_storage();
        $empty = $DB->sql_empty();
        // silly oracle empty string handling workaround
        $sqlfrom = "FROM {glossary_entries} ge\n                    JOIN {glossary} g ON g.id = ge.glossaryid\n                    JOIN {modules} m ON m.name = 'glossary'\n                    JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = g.id)\n                   WHERE ge.attachment <> '{$empty}' AND ge.attachment <> '1'";
        $count = $DB->count_records_sql("SELECT COUNT('x') {$sqlfrom}");
        if ($rs = $DB->get_recordset_sql("SELECT ge.id, ge.userid, ge.attachment, ge.glossaryid, ge.sourceglossaryid, g.course, cm.id AS cmid {$sqlfrom} ORDER BY g.course, g.id")) {
            $pbar = new progress_bar('migrateglossaryfiles', 500, true);
            $i = 0;
            foreach ($rs as $entry) {
                $i++;
                upgrade_set_timeout(60);
                // set up timeout, may also abort execution
                $pbar->update($i, $count, "Migrating glossary entries - {$i}/{$count}.");
                $filepath = "{$CFG->dataroot}/{$entry->course}/{$CFG->moddata}/glossary/{$entry->glossaryid}/{$entry->id}/{$entry->attachment}";
                if ($entry->sourceglossaryid and !is_readable($filepath)) {
                    //eh - try the second possible location
                    $filepath = "{$CFG->dataroot}/{$entry->course}/{$CFG->moddata}/glossary/{$entry->sourceglossaryid}/{$entry->id}/{$entry->attachment}";
                }
                if (!is_readable($filepath)) {
                    //file missing??
                    notify("File not readable, skipping: {$filepath}");
                    $entry->attachment = '';
                    $DB->update_record('glossary_entries', $entry);
                    continue;
                }
                $context = get_context_instance(CONTEXT_MODULE, $entry->cmid);
                $filearea = 'glossary_attachment';
                $filename = clean_param($entry->attachment, PARAM_FILE);
                if ($filename === '') {
                    notify("Unsupported entry filename, skipping: " . $filepath);
                    $entry->attachment = '';
                    $DB->update_record('glossary_entries', $entry);
                    continue;
                }
                if (!$fs->file_exists($context->id, $filearea, $entry->id, '/', $filename)) {
                    $file_record = array('contextid' => $context->id, 'filearea' => $filearea, 'itemid' => $entry->id, 'filepath' => '/', 'filename' => $filename, 'userid' => $entry->userid);
                    if ($fs->create_file_from_pathname($file_record, $filepath)) {
                        $entry->attachment = '1';
                        if ($DB->update_record('glossary_entries', $entry)) {
                            unlink($filepath);
                        }
                    }
                }
                // remove dirs if empty
                @rmdir("{$CFG->dataroot}/{$entry->course}/{$CFG->moddata}/glossary/{$entry->glossaryid}/{$entry->id}");
                @rmdir("{$CFG->dataroot}/{$entry->course}/{$CFG->moddata}/glossary/{$entry->glossaryid}");
                @rmdir("{$CFG->dataroot}/{$entry->course}/{$CFG->moddata}/glossary");
            }
            $rs->close();
        }
        upgrade_mod_savepoint($result, 2008081900, 'glossary');
    }
    if ($result && $oldversion < 2009042000) {
        /// Rename field definitionformat on table glossary_entries to definitionformat
        $table = new xmldb_table('glossary_entries');
        $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'definition');
        /// Launch rename field definitionformat
        $dbman->rename_field($table, $field, 'definitionformat');
        /// glossary savepoint reached
        upgrade_mod_savepoint($result, 2009042000, 'glossary');
    }
    if ($result && $oldversion < 2009042001) {
        /// Define field definitiontrust to be added to glossary_entries
        $table = new xmldb_table('glossary_entries');
        $field = new xmldb_field('definitiontrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'definitionformat');
        /// Launch add field definitiontrust
        $dbman->add_field($table, $field);
        /// glossary savepoint reached
        upgrade_mod_savepoint($result, 2009042001, 'glossary');
    }
    if ($result && $oldversion < 2009042002) {
        /// Rename field format on table glossary_comments to NEWNAMEGOESHERE
        $table = new xmldb_table('glossary_comments');
        $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'entrycomment');
        /// Launch rename field format
        $dbman->rename_field($table, $field, 'entrycommentformat');
        /// glossary savepoint reached
        upgrade_mod_savepoint($result, 2009042002, 'glossary');
    }
    if ($result && $oldversion < 2009042003) {
        /// Define field entrycommenttrust to be added to glossary_comments
        $table = new xmldb_table('glossary_comments');
        $field = new xmldb_field('entrycommenttrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'entrycommentformat');
        /// Conditionally launch add field entrycommenttrust
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        /// glossary savepoint reached
        upgrade_mod_savepoint($result, 2009042003, 'glossary');
    }
    if ($result && $oldversion < 2009042004) {
        $trustmark = '#####TRUSTTEXT#####';
        $rs = $DB->get_recordset_sql("SELECT * FROM {glossary_entries} WHERE definition LIKE '{$trustmark}%'");
        foreach ($rs as $entry) {
            if (strpos($entry->definition, $trustmark) !== 0) {
                // probably lowercase in some DBs
                continue;
            }
            $entry->definition = trusttext_strip($entry->definition);
            $entry->definitiontrust = 1;
            $DB->update_record('glossary_entries', $entry);
        }
        $rs->close();
        /// glossary savepoint reached
        upgrade_mod_savepoint($result, 2009042004, 'glossary');
    }
    if ($result && $oldversion < 2009042005) {
        $trustmark = '#####TRUSTTEXT#####';
        $rs = $DB->get_recordset_sql("SELECT * FROM {glossary_comments} WHERE entrycomment LIKE '{$trustmark}%'");
        foreach ($rs as $comment) {
            if (strpos($comment->entrycomment, $trustmark) !== 0) {
                // probably lowercase in some DBs
                continue;
            }
            $comment->entrycomment = trusttext_strip($comment->entrycomment);
            $comment->entrycommenttrust = 1;
            $DB->update_record('glossary_comments', $comment);
        }
        $rs->close();
        /// glossary savepoint reached
        upgrade_mod_savepoint($result, 2009042005, 'glossary');
    }
    if ($result && $oldversion < 2009042006) {
        /// Define field introformat to be added to glossary
        $table = new xmldb_table('glossary');
        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
        /// Conditionally launch add field introformat
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        /// glossary savepoint reached
        upgrade_mod_savepoint($result, 2009042006, 'glossary');
    }
    return $result;
}
コード例 #16
0
ファイル: lib_cron.php プロジェクト: OctaveBabel/moodle-itop
/**
 * Builds and returns the body of the email notification in plain text.
 *
 * @param object $course
 * @param object $forum
 * @param object $discussion
 * @param object $post
 * @param object $userfrom
 * @param object $userto
 * @param boolean $bare
 * @return string The email body in plain text format.
 */
function referentiel_make_mail_text($type, $context, $course, $post, $userfrom, $userto, $bare = false)
{
    global $CFG, $USER;
    // DEBUG : cron_lib.php :
    // mtrace("referentiel_make_mail_text()");
    if (!isset($userto->viewfullnames[$post->id])) {
        $viewfullnames = has_capability('moodle/site:viewfullnames', $context, $userto->id);
    } else {
        $viewfullnames = $userto->viewfullnames[$post->id];
    }
    // groups
    if (isset($userfrom->groups)) {
        $groups = $userfrom->groups[$post->id];
    } else {
        $groups = groups_get_all_groups($course->id, $userfrom->id, $cm->groupingid);
    }
    $groupname = '';
    if ($groups) {
        // mtrace("\n lib.php :: 2038\n");
        // print_r($groups);
        foreach ($groups as $groupe) {
            // mtrace("\n lib.php :: 2041\n");
            // print_r($groupe);
            if (!empty($groupe->name)) {
                $groupname .= $groupe->name . ' ';
            }
        }
    }
    $by = new stdClass();
    $by->name = fullname($userfrom, $viewfullnames);
    $a = new stdClass();
    $a->site = $course->shortname;
    $posttext = '';
    if ($type == TYPE_CERTIFICAT) {
        if ($post->date_decision) {
            $by->date = userdate($post->date_decision, "", $userto->timezone);
        } else {
            $by->date = userdate(time(), "", $userto->timezone);
        }
        $strbynameondate = get_string('bynameondate', 'referentiel', $by);
        if (!empty($groupname)) {
            $strbynameondate .= ' - ' . get_string('groupe', 'referentiel', $groupname);
        }
        $strreferentiel = get_string('certificat', 'referentiel') . ' ' . referentiel_get_referentiel_name($post->ref_referentiel);
        if (!$bare) {
            $posttext = "{$course->shortname} -> ";
            $posttext .= format_string($strreferentiel, true);
            $posttext .= " ({$CFG->wwwroot}/)";
        }
        $posttext .= "\n" . $strbynameondate . "\n";
        $posttext .= format_text_email(trusttext_strip(get_string('certificat', 'referentiel') . ' ' . $post->id), FORMAT_PLAIN);
        $posttext .= "\n\n";
        $posttext .= format_text_email(trusttext_strip(get_string('certificat_sel_certificat_competences', 'referentiel')), FORMAT_PLAIN);
        $posttext .= "\n";
        $posttext .= format_text_email(trusttext_strip($post->competences_certificat), FORMAT_PLAIN);
        $posttext .= "\n\n";
        if ($post->commentaire_certificat) {
            $posttext .= format_text_email(trusttext_strip($post->commentaire_certificat), FORMAT_PLAIN);
            $posttext .= "\n\n";
        }
        if ($post->synthese_certificat) {
            $posttext .= format_text_email(trusttext_strip($post->synthese_certificat), FORMAT_PLAIN);
            $posttext .= "\n\n";
        }
        if (!$bare) {
            $posttext .= "---------------------------------------------------------------------\n";
            $a->type = get_string('certificat', 'referentiel');
            $posttext .= get_string("postmailinfo", "referentiel", $a) . "\n";
            $posttext .= "{$CFG->wwwroot}/\n";
        }
    } else {
        if ($type == TYPE_TACHE) {
            if (isset($post->auteurid) && $post->auteurid) {
                $auteur_info = referentiel_get_user_info($post->auteurid);
            } else {
                $auteur_info = get_string('un_enseignant', 'referentiel');
            }
            if ($post->date_modif) {
                $by->date = userdate($post->date_modif, "", $userto->timezone);
            } else {
                $by->date = userdate($post->date_creation, "", $userto->timezone);
            }
            $strbynameondate = get_string('bynameondate', 'referentiel', $by);
            if (!empty($groupname)) {
                $strbynameondate .= ' - ' . get_string('groupe', 'referentiel', $groupname);
            }
            $strreferentiel = get_string('referentiel', 'referentiel') . ': ' . referentiel_get_instance_name($post->ref_referentiel);
            if (!$bare) {
                $posttext = "{$course->shortname} -> {$strreferentiel} -> " . format_string($post->type_task, true);
            }
            $posttext .= "\n" . $strbynameondate . "\n";
            $posttext .= "\n---------------------------------------------------------------------\n";
            $posttext .= format_text_email(trusttext_strip(get_string('task', 'referentiel') . ' ' . $post->id), FORMAT_PLAIN);
            $posttext .= "\n---------------------------------------------------------------------\n\n";
            $posttext .= format_string($post->type_task, true);
            if ($bare) {
                $posttext .= "(" . get_string('postincontext', 'referentiel') . " {$CFG->wwwroot}/mod/referentiel/task.php?d={$post->ref_instance}&task_id={$post->id})";
            }
            $posttext .= "\n\n";
            $posttext .= format_text_email(trusttext_strip($post->description_task), FORMAT_PLAIN);
            $posttext .= "\n\n";
            $posttext .= format_text_email(trusttext_strip(get_string('certificat_sel_activite_competences', 'referentiel')), FORMAT_PLAIN);
            $posttext .= "\n";
            $posttext .= format_text_email(trusttext_strip($post->competences_task), FORMAT_PLAIN);
            $posttext .= "\n\n";
            if ($post->criteres_evaluation) {
                $posttext .= format_text_email(trusttext_strip(get_string('criteres_evaluation', 'referentiel') . ': ' . $post->criteres_evaluation), FORMAT_PLAIN);
                $posttext .= "\n\n";
            }
            if ($post->souscription_libre) {
                $posttext .= format_text_email(trusttext_strip(get_string('souscription_libre', 'referentiel')), FORMAT_PLAIN);
                $posttext .= "\n";
            }
            if (isset($post->cle_souscription) && $post->cle_souscription != '') {
                $posttext .= format_text_email(trusttext_strip(get_string('obtenir_cle_souscription', 'referentiel', $auteur_info)), FORMAT_PLAIN);
                $posttext .= "\n";
            }
            if (isset($post->tache_masquee) && $post->tache_masquee != 0) {
                $posttext .= format_text_email(trusttext_strip(get_string('tache_masquee_num', 'referentiel', $post->id)), FORMAT_PLAIN);
                $posttext .= "\n";
            }
            $posttext .= "\n";
            if (!$bare) {
                $posttext .= "---------------------------------------------------------------------\n";
                $a->type = get_string('task', 'referentiel');
                $posttext .= get_string("postmailinfo", "referentiel", $a) . "\n";
                $posttext .= "{$CFG->wwwroot}/mod/referentiel/task.php?d={$post->ref_instance}&task_id={$post->id}\n";
            }
        } else {
            // ACTIVITE
            if ($post->date_modif) {
                $by->date = userdate($post->date_modif, "", $userto->timezone);
            } else {
                if ($post->date_modif_student) {
                    $by->date = userdate($post->date_modif_student, "", $userto->timezone);
                } else {
                    $by->date = userdate($post->date_creation, "", $userto->timezone);
                }
            }
            $strbynameondate = get_string('bynameondate', 'referentiel', $by);
            if (!empty($groupname)) {
                $strbynameondate .= ' - ' . get_string('groupe', 'referentiel', $groupname);
            }
            $strreferentiel = get_string('referentiel', 'referentiel') . ': ' . referentiel_get_instance_name($post->ref_referentiel);
            if (!$bare) {
                $posttext = "{$course->shortname} -> {$strreferentiel} -> " . format_string($post->type_activite, true);
            }
            $posttext .= "\n" . $strbynameondate . "\n";
            $posttext .= "\n---------------------------------------------------------------------\n";
            $posttext .= format_text_email(trusttext_strip(get_string('activite', 'referentiel') . ' ' . $post->id), FORMAT_PLAIN);
            $posttext .= "\n---------------------------------------------------------------------\n";
            $posttext .= format_string($post->type_activite, true);
            if ($bare) {
                $posttext .= "(" . get_string('postincontext', 'referentiel') . " {$CFG->wwwroot}/mod/referentiel/activite.php?d={$post->ref_instance}&activite_id={$post->id})";
            }
            $posttext .= "\n";
            $posttext .= format_text_email(trusttext_strip(get_string('auteur', 'referentiel') . ' '), FORMAT_PLAIN);
            $posttext .= format_text_email(trusttext_strip(referentiel_get_user_info($post->userid)), FORMAT_PLAIN);
            $posttext .= "\n";
            $posttext .= format_text_email(trusttext_strip($post->type_activite), FORMAT_PLAIN);
            $posttext .= "\n";
            $posttext .= format_text_email(trusttext_strip($post->description_activite), FORMAT_PLAIN);
            $posttext .= "\n\n";
            $posttext .= format_text_email(trusttext_strip(get_string('certificat_sel_activite_competences', 'referentiel')), FORMAT_PLAIN);
            $posttext .= "\n";
            $posttext .= format_text_email(trusttext_strip($post->competences_activite), FORMAT_PLAIN);
            $posttext .= "\n\n";
            if ($post->commentaire_activite) {
                $posttext .= format_text_email(trusttext_strip($post->commentaire_activite), FORMAT_PLAIN);
                $posttext .= "\n\n";
            }
            if (!$bare) {
                $posttext .= "---------------------------------------------------------------------\n";
                $a->type = get_string('activite', 'referentiel');
                $posttext .= get_string("postmailinfo", "referentiel", $a) . "\n";
                $posttext .= "{$CFG->wwwroot}/mod/referentiel/activite.php?d={$post->ref_instance}&activite_id={$post->id}\n";
            }
        }
    }
    return $posttext;
}