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


PHP forum_add_new_post函数代码示例

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


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

示例1: add_to_log

         // thread.
         $discussionurl = "view.php?f={$forum->id}";
     } else {
         $discussionurl = "discuss.php?d={$discussion->id}#p{$fromform->id}";
     }
     add_to_log($course->id, "forum", "update post", "{$discussionurl}&parent={$fromform->id}", "{$fromform->id}", $cm->id);
     redirect(forum_go_back_to("{$discussionurl}"), $message . $subscribemessage, $timemessage);
     exit;
 } else {
     if ($fromform->discussion) {
         // Adding a new post to an existing discussion
         unset($fromform->groupid);
         $message = '';
         $addpost = $fromform;
         $addpost->forum = $forum->id;
         if ($fromform->id = forum_add_new_post($addpost, $mform_post, $message)) {
             $timemessage = 2;
             if (!empty($message)) {
                 // if we're printing stuff about the file upload
                 $timemessage = 4;
             }
             if ($subscribemessage = forum_post_subscription($fromform, $forum)) {
                 $timemessage = 4;
             }
             if (!empty($fromform->mailnow)) {
                 $message .= get_string("postmailnow", "forum");
                 $timemessage = 4;
             } else {
                 $message .= '<p>' . get_string("postaddedsuccess", "forum") . '</p>';
                 $message .= '<p>' . get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
             }
开发者ID:njorth,项目名称:marginalia,代码行数:31,代码来源:post.php

示例2: add_discussion_post

    /**
     * Create new posts into an existing discussion.
     *
     * @param int $postid the post id we are going to reply to
     * @param string $subject new post subject
     * @param string $message new post message (only html format allowed)
     * @param array $options optional settings
     * @return array of warnings and the new post id
     * @since Moodle 3.0
     * @throws moodle_exception
     */
    public static function add_discussion_post($postid, $subject, $message, $options = array()) {
        global $DB, $CFG, $USER;
        require_once($CFG->dirroot . "/mod/forum/lib.php");

        $params = self::validate_parameters(self::add_discussion_post_parameters(),
                                            array(
                                                'postid' => $postid,
                                                'subject' => $subject,
                                                'message' => $message,
                                                'options' => $options
                                            ));
        // Validate options.
        $options = array(
            'discussionsubscribe' => true
        );
        foreach ($params['options'] as $option) {
            $name = trim($option['name']);
            switch ($name) {
                case 'discussionsubscribe':
                    $value = clean_param($option['value'], PARAM_BOOL);
                    break;
                default:
                    throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
            }
            $options[$name] = $value;
        }

        $warnings = array();

        if (!$parent = forum_get_post_full($params['postid'])) {
            throw new moodle_exception('invalidparentpostid', 'forum');
        }

        if (!$discussion = $DB->get_record("forum_discussions", array("id" => $parent->discussion))) {
            throw new moodle_exception('notpartofdiscussion', 'forum');
        }

        // Request and permission validation.
        $forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        if (!forum_user_can_post($forum, $discussion, $USER, $cm, $course, $context)) {
            throw new moodle_exception('nopostforum', 'forum');
        }

        $thresholdwarning = forum_check_throttling($forum, $cm);
        forum_check_blocking_threshold($thresholdwarning);

        // Create the post.
        $post = new stdClass();
        $post->discussion = $discussion->id;
        $post->parent = $parent->id;
        $post->subject = $params['subject'];
        $post->message = $params['message'];
        $post->messageformat = FORMAT_HTML;   // Force formatting for now.
        $post->messagetrust = trusttext_trusted($context);
        $post->itemid = 0;

        if ($postid = forum_add_new_post($post, null)) {

            $post->id = $postid;

            // Trigger events and completion.
            $params = array(
                'context' => $context,
                'objectid' => $post->id,
                'other' => array(
                    'discussionid' => $discussion->id,
                    'forumid' => $forum->id,
                    'forumtype' => $forum->type,
                )
            );
            $event = \mod_forum\event\post_created::create($params);
            $event->add_record_snapshot('forum_posts', $post);
            $event->add_record_snapshot('forum_discussions', $discussion);
            $event->trigger();

            // Update completion state.
            $completion = new completion_info($course);
            if ($completion->is_enabled($cm) &&
                    ($forum->completionreplies || $forum->completionposts)) {
                $completion->update_state($cm, COMPLETION_COMPLETE);
            }

            $settings = new stdClass();
            $settings->discussionsubscribe = $options['discussionsubscribe'];
//.........这里部分代码省略.........
开发者ID:uniedpa,项目名称:moodle,代码行数:101,代码来源:externallib.php

示例3: generate_forum_posts

 public function generate_forum_posts($course_users, $modules)
 {
     global $CFG, $DB, $USER;
     if (in_array('forum', $this->modules_list) && $this->get('discussions_per_forum') && $this->get('posts_per_discussion') && isset($modules['forum'])) {
         $discussions_count = 0;
         $posts_count = 0;
         foreach ($modules['forum'] as $forum) {
             $forum_users = $course_users[$forum->course];
             for ($i = 0; $i < $this->get('discussions_per_forum'); $i++) {
                 $mform = new fake_form();
                 require_once $CFG->dirroot . '/mod/forum/lib.php';
                 $discussion = new stdClass();
                 $discussion->course = $forum->course;
                 $discussion->forum = $forum->id;
                 $discussion->name = 'Test discussion';
                 $discussion->intro = 'This is just a test forum discussion';
                 $discussion->assessed = 0;
                 $discussion->messageformat = 1;
                 $discussion->messagetrust = 0;
                 $discussion->mailnow = false;
                 $discussion->groupid = -1;
                 $discussion->attachments = null;
                 $discussion->itemid = 752157083;
                 $message = '';
                 $super_global_user = clone $USER;
                 $user_id = $forum_users[array_rand($forum_users)];
                 $USER = $DB->get_record('user', array('id' => $user_id));
                 if ($discussion_id = forum_add_discussion($discussion, $mform, $message)) {
                     $discussion = $DB->get_record('forum_discussions', array('id' => $discussion_id));
                     $discussions_count++;
                     // Add posts to this discussion
                     $post_ids = array($discussion->firstpost);
                     for ($j = 0; $j < $this->get('posts_per_discussion'); $j++) {
                         $global_user = clone $USER;
                         $user_id = $forum_users[array_rand($forum_users)];
                         $USER = $DB->get_record('user', array('id' => $user_id));
                         $post = new stdClass();
                         $post->discussion = $discussion_id;
                         $post->subject = 'Re: test discussion';
                         $post->message = '<p>Nothing much to say, since this is just a test...</p>';
                         $post->format = 1;
                         $post->attachments = null;
                         $post->itemid = 752157083;
                         $post->parent = $post_ids[array_rand($post_ids)];
                         if ($post_ids[] = forum_add_new_post($post, $mform, $message)) {
                             $posts_count++;
                         }
                         $USER = $global_user;
                     }
                 }
                 $USER = $super_global_user;
                 if ($forum->type == 'single') {
                     break;
                 }
             }
         }
         if ($discussions_count > 0 && !$this->get('quiet')) {
             echo "{$discussions_count} forum discussions have been generated.{$this->eolchar}";
         }
         if ($posts_count > 0 && !$this->get('quiet')) {
             echo "{$posts_count} forum posts have been generated.{$this->eolchar}";
         }
         return true;
     }
     return null;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:66,代码来源:generator.php

示例4: process_message


//.........这里部分代码省略.........
        }

        $addpost = new \stdClass();
        $addpost->course       = $course->id;
        $addpost->forum        = $forum->id;
        $addpost->discussion   = $discussion->id;
        $addpost->modified     = $messagedata->timestamp;
        $addpost->subject      = clean_param($messagedata->envelope->subject, PARAM_TEXT);
        $addpost->parent       = $post->id;
        $addpost->itemid       = file_get_unused_draft_itemid();

        if (!empty($messagedata->html)) {
            $addpost->message = $messagedata->html;
            $addpost->messageformat = FORMAT_HTML;
        } else {
            $addpost->message = $messagedata->plain;
            $addpost->messageformat = FORMAT_PLAIN;
        }

        // We don't trust text coming from e-mail.
        $addpost->messagetrust = false;

        // Add attachments to the post.
        if (!empty($messagedata->attachments['attachment']) && count($messagedata->attachments['attachment'])) {
            $attachmentcount = count($messagedata->attachments['attachment']);
            if (empty($forum->maxattachments) || $forum->maxbytes == 1 ||
                    !has_capability('mod/forum:createattachment', $modcontext)) {
                // Attachments are not allowed.
                mtrace("--> User does not have permission to attach files in this forum. Rejecting e-mail.");

                $data = new \stdClass();
                $data->forum = $forum;
                $data->attachmentcount = $attachmentcount;
                throw new \core\message\inbound\processing_failed_exception('messageinboundattachmentdisallowed', 'mod_forum', $data);
            }

            if ($forum->maxattachments < $attachmentcount) {
                // Too many attachments.
                mtrace("--> User attached {$attachmentcount} files when only {$forum->maxattachments} where allowed. "
                     . " Rejecting e-mail.");

                $data = new \stdClass();
                $data->forum = $forum;
                $data->attachmentcount = $attachmentcount;
                throw new \core\message\inbound\processing_failed_exception('messageinboundfilecountexceeded', 'mod_forum', $data);
            }

            $filesize = 0;
            $addpost->attachments  = file_get_unused_draft_itemid();
            foreach ($messagedata->attachments['attachment'] as $attachment) {
                mtrace("--> Processing {$attachment->filename} as an attachment.");
                $this->process_attachment('*', $usercontext, $addpost->attachments, $attachment);
                $filesize += $attachment->filesize;
            }

            if ($forum->maxbytes < $filesize) {
                // Too many attachments.
                mtrace("--> User attached {$filesize} bytes of files when only {$forum->maxbytes} where allowed. "
                     . "Rejecting e-mail.");
                $data = new \stdClass();
                $data->forum = $forum;
                $data->maxbytes = display_size($forum->maxbytes);
                $data->filesize = display_size($filesize);
                throw new \core\message\inbound\processing_failed_exception('messageinboundfilesizeexceeded', 'mod_forum', $data);
            }
        }

        // Process any files in the message itself.
        if (!empty($messagedata->attachments['inline'])) {
            foreach ($messagedata->attachments['inline'] as $attachment) {
                mtrace("--> Processing {$attachment->filename} as an inline attachment.");
                $this->process_attachment('*', $usercontext, $addpost->itemid, $attachment);

                // Convert the contentid link in the message.
                $draftfile = \moodle_url::make_draftfile_url($addpost->itemid, '/', $attachment->filename);
                $addpost->message = preg_replace('/cid:' . $attachment->contentid . '/', $draftfile, $addpost->message);
            }
        }

        // Insert the message content now.
        $addpost->id = forum_add_new_post($addpost, true);

        // Log the new post creation.
        $params = array(
            'context' => $modcontext,
            'objectid' => $addpost->id,
            'other' => array(
                'discussionid'  => $discussion->id,
                'forumid'       => $forum->id,
                'forumtype'     => $forum->type,
            )
        );
        $event = \mod_forum\event\post_created::create($params);
        $event->add_record_snapshot('forum_posts', $addpost);
        $event->add_record_snapshot('forum_discussions', $discussion);
        $event->trigger();

        mtrace("--> Created a post {$addpost->id} in {$discussion->id}.");
        return $addpost;
    }
开发者ID:jtibbetts,项目名称:moodle,代码行数:101,代码来源:reply_handler.php


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