/**
 * Process a request to view a single message thread.
 */
function messages_action_conversation()
{
    // Bail if not viewing a single conversation
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    // Get the thread ID from the action variable
    $thread_id = (int) bp_action_variable(0);
    if (!messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
    }
    // Check if a new reply has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message', 'send_message_nonce');
        $new_reply = messages_new_message(array('thread_id' => $thread_id, 'subject' => !empty($_POST['subject']) ? $_POST['subject'] : false, 'content' => $_POST['content']));
        // Send the reply
        if (!empty($new_reply)) {
            bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
        } else {
            bp_core_add_message(__('There was a problem sending your reply. Please try again.', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
    }
    // Mark message read
    messages_mark_thread_read($thread_id);
    /**
     * Fires after processing a view request for a single message thread.
     *
     * @since BuddyPress (1.7.0)
     */
    do_action('messages_action_conversation');
}
 /**
  * profile_screen_new_request()
  * 
  * Action to notify site_admin that a new request has been sent
  */
 function profile_screen_new_request($field_id, $field_value)
 {
     //required to search for superadmins
     require_once ABSPATH . 'wp-admin/includes/user.php';
     global $bp;
     if ($field_value == __('Apply for Teacher', 'bpsp')) {
         $users_search = new WP_User_Search(null, null, 'administrator');
         $superadmins = $users_search->get_results();
         $content = $this->request_message($bp->loggedin_user->userdata, true);
         $subject = $this->request_message($bp->loggedin_user->userdata, false, true);
         if (!is_super_admin()) {
             messages_new_message(array('recipients' => $superadmins, 'subject' => $subject, 'content' => $content));
         }
     }
     if ($field_value == __('Teacher', 'bpsp') && !is_super_admin()) {
         wp_die(__('BuddyPress Courseware error, you are not allowed to assign Teachers.'));
     }
     // Add an action every time a new teacher is added
     if ($field_value == __('Teacher', 'bpsp') && is_super_admin()) {
         do_action('courseware_new_teacher_added', $bp->displayed_user->id);
     }
     // Add an action every time a teacher is removed
     if ($field_value != __('Teacher', 'bpsp')) {
         do_action('courseware_new_teacher_removed', $bp->displayed_user->id);
     }
 }
Exemple #3
0
 /**
  * @group messages_new_message
  */
 public function test_messages_new_message_invalid_recipient_error_message()
 {
     $u1 = $this->factory->user->create();
     // attempt to send a private message to an invalid username
     $t1 = messages_new_message(array('sender_id' => $u1, 'recipients' => array('homerglumpkin'), 'subject' => 'A new message', 'content' => 'Hey there!', 'error_type' => 'wp_error'));
     $this->assertSame('Message could not be sent because you have entered an invalid username. Please try again.', $t1->get_error_message());
 }
Exemple #4
0
 /**
  * Create a single message
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function create_item($request)
 {
     if (!empty($request['id'])) {
         return new WP_Error('bp_json_message_exists', __('Cannot create existing message.', BP_API_PLUGIN_SLUG), array('status' => 400));
     }
     $message = $this->prepare_item_for_database($request);
     $message_id = messages_new_message(array('sender_id' => $message->sender_id ? $message->sender_id : bp_loggedin_user_id(), 'thread_id' => $message->thread_id, 'recipients' => $message->recipients, 'subject' => $message->subject, 'content' => $message->content, 'date_sent' => $message->date_sent ? $message->date_sent : bp_core_current_time()));
     if (!$message_id) {
         return new WP_Error('bp_json_message_create', __('Error creating new message.', BP_API_PLUGIN_SLUG), array('status' => 500));
     }
     $this->update_additional_fields_for_object($message, $request);
     /**
      * Fires after a message is created via the REST API
      *
      * @param object $message Data used to create message
      * @param WP_REST_Request $request Request object.
      * @param bool $bool A boolean that is false.
      */
     do_action('bp_json_insert_message', $message, $request, false);
     $response = $this->get_item(array('id' => $message_id, 'context' => 'view'));
     $response = rest_ensure_response($response);
     $response->set_status(201);
     $response->header('Location', rest_url('/users/' . $message_id));
     return $response;
 }
function messages_action_conversation()
{
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    $thread_id = (int) bp_action_variable(0);
    if (!$thread_id || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
    }
    // Check if a new reply has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message', 'send_message_nonce');
        // Send the reply
        if (messages_new_message(array('thread_id' => $thread_id, 'subject' => !empty($_POST['subject']) ? $_POST['subject'] : false, 'content' => $_POST['content']))) {
            bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
        } else {
            bp_core_add_message(__('There was a problem sending your reply, please try again', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
    }
    // Mark message read
    messages_mark_thread_read($thread_id);
    do_action('messages_action_conversation');
}
function messages_action_view_message()
{
    global $thread_id, $bp;
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    $thread_id = (int) bp_action_variable(0);
    if (!$thread_id || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !is_super_admin()) {
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug());
    }
    // Check if a new reply has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message', 'send_message_nonce');
        // Send the reply
        if (messages_new_message(array('thread_id' => $thread_id, 'subject' => $_POST['subject'], 'content' => $_POST['content']))) {
            bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
        } else {
            bp_core_add_message(__('There was a problem sending your reply, please try again', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
    }
    // Mark message read
    messages_mark_thread_read($thread_id);
    // Decrease the unread count in the nav before it's rendered
    $name = sprintf(__('Messages <span>%s</span>', 'buddypress'), bp_get_total_unread_messages_count());
    $bp->bp_nav[$bp->messages->slug]['name'] = $name;
    do_action('messages_action_view_message');
    bp_core_new_subnav_item(array('name' => sprintf(__('From: %s', 'buddypress'), BP_Messages_Thread::get_last_sender($thread_id)), 'slug' => 'view', 'parent_url' => trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()), 'parent_slug' => bp_get_messages_slug(), 'screen_function' => true, 'position' => 40, 'user_has_access' => bp_is_my_profile(), 'link' => bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . (int) $thread_id));
    bp_core_load_template(apply_filters('messages_template_view_message', 'members/single/home'));
}
Exemple #7
0
 /**
  * @group messages_new_message
  */
 public function test_messages_new_message_wp_error_generic()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     // Emulate a plugin disabling messages.
     add_action('messages_message_before_save', array($this, 'remove_recipients_before_save'));
     // send a private message
     $t1 = messages_new_message(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A new message', 'content' => 'Hey there!', 'error_type' => 'wp_error'));
     $this->assertNotEmpty($t1->get_error_code());
     remove_action('messages_message_before_save', array($this, 'remove_recipients_before_save'));
 }
Exemple #8
0
function bp_send_harmony_message($user1, $user2)
{
    global $bp;
    //check_admin_referer(message_check”); // adjust if needed
    $sender_id = $user1;
    // moderator id ?
    $recip_id = $user2;
    // denied image user id ?
    $nameofreciept = bp_get_profile_field_data('field=Name&user_id=' . $user2);
    if ($thread_id = messages_new_message(array('sender_id' => $sender_id, 'subject' => 'You have a match!', 'content' => 'Let me introduce you to ' . $nameofreciept, 'recipients' => $recip_id))) {
        // bp_core_add_message( __( 'Image Denied Message was sent.', 'buddypress' ) );
    } else {
        // bp_core_add_message( __( 'There was an error sending that Private Message.', 'buddypress' ), 'error' );
    }
}
 /**
  * send_message( $data )
  *
  * Generates a message about graded assignment and sends it to the student
  * @param Mixed $data required to send the message etc...
  */
 function send_message($data)
 {
     if (isset($data['grade'])) {
         $content = $this->gradebook_update_message($data, true);
         $subject = $this->gradebook_update_message($data, false, true);
         $recipients = $data['grade']['uid'];
     } elseif (isset($data['response'])) {
         $content = $this->response_added_message($data, true);
         $subject = $this->response_added_message($data, false, true);
         $recipients = $data['assignment']->post_author;
     }
     // Hack: ob_*() - to get rid of nasy warnings on messages_new_message()
     ob_start();
     messages_new_message(array('recipients' => $recipients, 'subject' => $subject, 'content' => $content));
     ob_clean();
 }
Exemple #10
0
 /**
  * @group counts
  */
 public function test_get_unread_count()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     // send a private message
     $t1 = messages_new_message(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A new message', 'content' => 'Hey there!'));
     // get unread count for $u2
     $this->set_current_user($u2);
     $this->assertEquals(1, messages_get_unread_count($u2));
     // send another message and get recheck unread count
     $t2 = messages_new_message(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'A new message', 'content' => 'Hey there!'));
     $this->assertEquals(2, messages_get_unread_count($u2));
     // mark one message as read
     messages_mark_thread_read($t1);
     // recheck unread count
     $this->assertEquals(1, messages_get_unread_count($u2));
 }
function messages_screen_compose()
{
    global $bp;
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Remove any saved message data from a previous session.
    messages_remove_callback_values();
    // Check if the message form has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message');
        // Check we have what we need
        if (empty($_POST['subject']) || empty($_POST['content'])) {
            bp_core_add_message(__('There was an error sending that message, please try again', 'buddypress'), 'error');
        } else {
            // If this is a notice, send it
            if (isset($_POST['send-notice'])) {
                if (messages_send_notice($_POST['subject'], $_POST['content'])) {
                    bp_core_add_message(__('Notice sent successfully!', 'buddypress'));
                    bp_core_redirect($bp->loggedin_user->domain . $bp->messages->slug . '/inbox/');
                } else {
                    bp_core_add_message(__('There was an error sending that notice, please try again', 'buddypress'), 'error');
                }
            } else {
                // Filter recipients into the format we need - array( 'username/userid', 'username/userid' )
                $autocomplete_recipients = explode(',', $_POST['send-to-input']);
                $typed_recipients = explode(' ', $_POST['send_to_usernames']);
                $recipients = array_merge((array) $autocomplete_recipients, (array) $typed_recipients);
                $recipients = apply_filters('bp_messages_recipients', $recipients);
                // Send the message
                if ($thread_id = messages_new_message(array('recipients' => $recipients, 'subject' => $_POST['subject'], 'content' => $_POST['content']))) {
                    bp_core_add_message(__('Message sent successfully!', 'buddypress'));
                    bp_core_redirect($bp->loggedin_user->domain . $bp->messages->slug . '/view/' . $thread_id . '/');
                } else {
                    bp_core_add_message(__('There was an error sending that message, please try again', 'buddypress'), 'error');
                }
            }
        }
    }
    do_action('messages_screen_compose');
    bp_core_load_template(apply_filters('messages_template_compose', 'members/single/home'));
}
 /**
  * profile_screen_new_request( $field_id, $field_value )
  * 
  * Action to notify site_admin that a new request has been sent
  * @param Int $field_id, the id of the xprofile field
  * @param String $field_value, the value of the field
  */
 function profile_screen_new_request($field_id, $field_value)
 {
     global $bp;
     if ($field_value == __('Apply for Teacher', 'bpsp')) {
         $superadmins = self::get_admins();
         $content = $this->request_message($bp->loggedin_user->userdata, true);
         $subject = $this->request_message($bp->loggedin_user->userdata, false, true);
         if (!is_super_admin()) {
             messages_new_message(array('recipients' => $superadmins, 'subject' => $subject, 'content' => $content));
         }
     }
     if ($field_value == __('Teacher', 'bpsp') && !is_super_admin()) {
         wp_die(__('BuddyPress Courseware error, you are not allowed to assign Teachers.', 'bpsp'));
     }
     // Add an action every time a new teacher is added
     if ($field_value == __('Teacher', 'bpsp') && is_super_admin()) {
         do_action('courseware_new_teacher_added', $bp->displayed_user->id);
     }
     // Add an action every time a teacher is removed
     if ($field_value != __('Teacher', 'bpsp')) {
         do_action('courseware_new_teacher_removed', $bp->displayed_user->id);
     }
 }
/**
 * Send a private message reply to a thread via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_messages_send_reply()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if (!empty($result)) {
        // Get the zebra line classes correct on ajax requests
        global $thread_template;
        bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id']));
        if ($thread_template->message_count % 2 == 1) {
            $class = 'odd';
        } else {
            $class = 'even alt';
        }
        ?>

		<div class="message-box new-message <?php 
        echo $class;
        ?>
">
			<div class="message-metadata">
				<?php 
        do_action('bp_before_message_meta');
        ?>
				<?php 
        echo bp_loggedin_user_avatar('type=thumb&width=30&height=30');
        ?>

				<strong><a href="<?php 
        echo bp_loggedin_user_domain();
        ?>
"><?php 
        bp_loggedin_user_fullname();
        ?>
</a> <span class="activity"><?php 
        printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time()));
        ?>
</span></strong>

				<?php 
        do_action('bp_after_message_meta');
        ?>
			</div>

			<?php 
        do_action('bp_before_message_content');
        ?>

			<div class="message-content">
				<?php 
        echo stripslashes(apply_filters('bp_get_the_thread_message_content', $_REQUEST['content']));
        ?>
			</div>

			<?php 
        do_action('bp_after_message_content');
        ?>

			<div class="clear"></div>
		</div>
	<?php 
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
    }
    exit;
}
 /**
  * @group get_recipients
  * @group cache
  */
 public function test_get_recipients_cache_should_be_busted_when_thread_message_is_sent()
 {
     global $wpdb;
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $t1 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'Foo'));
     $thread = new BP_Messages_Thread($t1);
     $recipients = $thread->get_recipients();
     // Verify that the cache is populated.
     $num_queries = $wpdb->num_queries;
     $recipients_cached = $thread->get_recipients();
     $this->assertEquals($num_queries, $wpdb->num_queries);
     messages_new_message(array('sender_id' => $u2, 'thread_id' => $t1, 'recipients' => array($u1), 'subject' => 'Bar', 'content' => 'Baz'));
     // Cache should be empty.
     $num_queries = $wpdb->num_queries;
     $recipients_uncached = $thread->get_recipients();
     $this->assertEquals($num_queries + 1, $wpdb->num_queries);
 }
 function wplms_instructor_reply_user_comment()
 {
     $id = $_POST['id'];
     $message = $_POST['message'];
     if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security') || !is_numeric($id)) {
         _e('Security check Failed. Contact Administrator.', 'vibe');
         die;
     }
     if (bp_is_active('messages')) {
         $user_id = get_current_user_id();
         $instructor_ids = apply_filters('wplms_course_instructors', get_post_field('post_author', $id), $id);
         if (!is_array($instructor_ids)) {
             $instructor_ids = array($instructor_ids);
         }
         $message .= ' <a href="' . get_permalink($id) . '">' . get_the_title($id) . '</a>';
         foreach ($instructor_ids as $instructor_id) {
             messages_new_message(array('sender_id' => $user_id, 'subject' => sprintf(__('Instructor reply requested for unit %s paragraph %s', 'vibe'), get_the_title($id), $_POST['section']), 'content' => $message, 'recipients' => $instructor_id));
             echo 'balle';
         }
     }
     die;
 }
Exemple #16
0
function bpdd_import_users_messages()
{
    $messages = array();
    require dirname(__FILE__) . '/data/messages.php';
    // first level messages
    for ($i = 0; $i < 33; $i++) {
        $messages[] = messages_new_message(array('sender_id' => bpdd_get_random_users_ids(1, 'string'), 'recipients' => bpdd_get_random_users_ids(1, 'array'), 'subject' => $messages_subjects[array_rand($messages_subjects)], 'content' => $messages_content[array_rand($messages_content)], 'date_sent' => bpdd_get_random_date(15, 5)));
    }
    for ($i = 0; $i < 33; $i++) {
        $messages[] = messages_new_message(array('sender_id' => bpdd_get_random_users_ids(1, 'string'), 'recipients' => bpdd_get_random_users_ids(2, 'array'), 'subject' => $messages_subjects[array_rand($messages_subjects)], 'content' => $messages_content[array_rand($messages_content)], 'date_sent' => bpdd_get_random_date(13, 3)));
    }
    for ($i = 0; $i < 33; $i++) {
        $messages[] = messages_new_message(array('sender_id' => bpdd_get_random_users_ids(1, 'string'), 'recipients' => bpdd_get_random_users_ids(3, 'array'), 'subject' => $messages_subjects[array_rand($messages_subjects)], 'content' => $messages_content[array_rand($messages_content)], 'date_sent' => bpdd_get_random_date(10)));
    }
    $messages[] = messages_new_message(array('sender_id' => bpdd_get_random_users_ids(1, 'string'), 'recipients' => bpdd_get_random_users_ids(5, 'array'), 'subject' => $messages_subjects[array_rand($messages_subjects)], 'content' => $messages_content[array_rand($messages_content)], 'date_sent' => bpdd_get_random_date(5)));
    return $messages;
}
Exemple #17
0
function bp_dtheme_ajax_messages_send_reply()
{
    global $bp;
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if ($result) {
        ?>
		<div class="message-box new-message">
			<div class="message-metadata">
				<?php 
        do_action('bp_before_message_meta');
        ?>
				<?php 
        echo bp_loggedin_user_avatar('type=thumb&width=30&height=30');
        ?>

				<strong><a href="<?php 
        echo $bp->loggedin_user->domain;
        ?>
"><?php 
        echo $bp->loggedin_user->fullname;
        ?>
</a> <span class="activity"><?php 
        printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time()));
        ?>
</span></strong>

				<?php 
        do_action('bp_after_message_meta');
        ?>
			</div>

			<?php 
        do_action('bp_before_message_content');
        ?>

			<div class="message-content">
				<?php 
        echo stripslashes(apply_filters('bp_get_the_thread_message_content', $_REQUEST['content']));
        ?>
			</div>

			<?php 
        do_action('bp_after_message_content');
        ?>

			<div class="clear"></div>
		</div>
	<?php 
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
    }
}
/**
 * Send a private message reply to a thread via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_messages_send_reply()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if (!empty($result)) {
        // pretend we're in the message loop
        global $thread_template;
        bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id']));
        // set the current message to the 2nd last
        $thread_template->message = end($thread_template->thread->messages);
        $thread_template->message = prev($thread_template->thread->messages);
        // set current message to current key
        $thread_template->current_message = key($thread_template->thread->messages);
        // now manually iterate message like we're in the loop
        bp_thread_the_message();
        // manually call oEmbed
        // this is needed because we're not at the beginning of the loop
        bp_messages_embed();
        ?>

		<div class="message-box new-message <?php 
        bp_the_thread_message_css_class();
        ?>
">
			<div class="message-metadata">
				<?php 
        /**
         * Fires before the single message header is displayed.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_before_message_meta');
        ?>
				<?php 
        echo bp_loggedin_user_avatar('type=thumb&width=30&height=30');
        ?>

				<strong><a href="<?php 
        echo bp_loggedin_user_domain();
        ?>
"><?php 
        bp_loggedin_user_fullname();
        ?>
</a> <span class="activity"><?php 
        printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time()));
        ?>
</span></strong>

				<?php 
        /**
         * Fires after the single message header is displayed.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_after_message_meta');
        ?>
			</div>

			<?php 
        /**
         * Fires before the message content for a private message.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_before_message_content');
        ?>

			<div class="message-content">
				<?php 
        bp_the_thread_message_content();
        ?>
			</div>

			<?php 
        /**
         * Fires after the message content for a private message.
         *
         * @since BuddyPress (1.1.0)
         */
        do_action('bp_after_message_content');
        ?>

			<div class="clear"></div>
		</div>
	<?php 
        // clean up the loop
        bp_thread_messages();
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
    }
    exit;
}
/**
 * Send a private message reply to a thread via a POST request.
 *
 * @since 1.2.0
 *
 * @return string HTML
 */
function bp_legacy_theme_ajax_messages_send_reply()
{
    // Bail if not a POST action.
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if (!empty($result)) {
        // Pretend we're in the message loop.
        global $thread_template;
        bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id']));
        // Set the current message to the 2nd last.
        $thread_template->message = end($thread_template->thread->messages);
        $thread_template->message = prev($thread_template->thread->messages);
        // Set current message to current key.
        $thread_template->current_message = key($thread_template->thread->messages);
        // Now manually iterate message like we're in the loop.
        bp_thread_the_message();
        // Manually call oEmbed
        // this is needed because we're not at the beginning of the loop.
        bp_messages_embed();
        // Add new-message css class.
        add_filter('bp_get_the_thread_message_css_class', create_function('$retval', '
			$retval[] = "new-message";
			return $retval;
		'));
        // Output single message template part.
        bp_get_template_part('members/single/messages/message');
        // Clean up the loop.
        bp_thread_messages();
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>';
    }
    exit;
}
function wplms_give_assignment_marks()
{
    $answer_id = $_POST['id'];
    $value = $_POST['aval'];
    $remarks = $_POST['message'];
    if (is_numeric($answer_id) && is_numeric($value)) {
        update_comment_meta($answer_id, 'marks', $value);
        $comment = get_comment($answer_id);
        if (is_object($comment)) {
            update_post_meta($comment->comment_post_ID, $comment->user_id, $value);
        }
        $max_marks = get_post_meta($comment->comment_post_ID, 'vibe_assignment_marks', true);
        $message = __('You\'ve obtained ', 'wplms-assignments') . $value . (is_numeric($max_marks) ? '/' . $max_marks : '') . __(' in Assignment :', 'wplms-assignments') . ' <a href="' . get_permalink($comment->comment_post_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>
      <a href="' . bp_core_get_user_domain($comment->user_id) . 'course/course-results/?action=' . $comment->comment_post_ID . '">' . __('Check Results', 'wplms-assignments') . '</a>
      <h3>' . __('Additional Remarks form Instructor', 'wplms-assignments') . '</h3>
      <br />' . $remarks;
        $message_id = '';
        if (function_exists('messages_new_message')) {
            $message_id = messages_new_message(array('sender_id' => get_current_user_id(), 'subject' => __('Assignment results available', 'wplms-assignments'), 'content' => $message, 'recipients' => $comment->user_id));
        }
        do_action('wplms_evaluate_assignment', $comment->comment_post_ID, $value, $comment->user_id, $max_marks, $message_id);
    }
    die;
}
Exemple #21
0
 function create_object($args)
 {
     $message_id = messages_new_message($args);
     return $message_id;
 }
/**
 * Load the Messages > Compose screen.
 */
function messages_screen_compose()
{
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Remove any saved message data from a previous session.
    messages_remove_callback_values();
    // Check if the message form has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message');
        // Check we have what we need
        if (empty($_POST['subject']) || empty($_POST['content'])) {
            bp_core_add_message(__('There was an error sending that message. Please try again.', 'buddypress'), 'error');
        } else {
            // If this is a notice, send it
            if (isset($_POST['send-notice'])) {
                if (messages_send_notice($_POST['subject'], $_POST['content'])) {
                    bp_core_add_message(__('Notice sent successfully!', 'buddypress'));
                    bp_core_redirect(bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox/');
                } else {
                    bp_core_add_message(__('There was an error sending that notice. Please try again.', 'buddypress'), 'error');
                }
            } else {
                // Filter recipients into the format we need - array( 'username/userid', 'username/userid' )
                $autocomplete_recipients = explode(',', $_POST['send-to-input']);
                $typed_recipients = explode(' ', $_POST['send_to_usernames']);
                $recipients = array_merge((array) $autocomplete_recipients, (array) $typed_recipients);
                /**
                 * Filters the array of recipients to receive the composed message.
                 *
                 * @since BuddyPress (1.2.10)
                 *
                 * @param array $recipients Array of recipients to receive message.
                 */
                $recipients = apply_filters('bp_messages_recipients', $recipients);
                $thread_id = messages_new_message(array('recipients' => $recipients, 'subject' => $_POST['subject'], 'content' => $_POST['content']));
                // Send the message
                if (!empty($thread_id)) {
                    bp_core_add_message(__('Message sent successfully!', 'buddypress'));
                    bp_core_redirect(bp_loggedin_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
                } else {
                    bp_core_add_message(__('There was an error sending that message. Please try again.', 'buddypress'), 'error');
                }
            }
        }
    }
    /**
     * Fires right before the loading of the Messages compose screen template file.
     *
     * @since BuddyPress (1.0.0)
     */
    do_action('messages_screen_compose');
    /**
     * Filters the template to load for the Messages compose screen.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param string $template Path to the messages template to load.
     */
    bp_core_load_template(apply_filters('messages_template_compose', 'members/single/home'));
}
Exemple #23
0
function apoc_private_message_reply()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Check the nonce and register the new message
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    // If the new message was registered successfully
    if ($result) {
        $user = new Apoc_User(get_current_user_id(), 'reply');
        ?>
	<li class="reply new-message">

		<header class="reply-header">
			<time class="reply-time">Right Now</time>
		</header>	

		<section class="reply-body">	
			<div class="reply-author">
				<?php 
        echo $user->block;
        ?>
			</div>
			<div class="reply-content">
				<?php 
        echo wpautop(stripslashes($_REQUEST['content']));
        ?>
			</div>
			<?php 
        $user->signature();
        ?>
		</section>				
	</li>
	
	<?php 
        // Otherwise, process errors
    } else {
        echo '<p class="error">There was a problem sending that reply. Please try again.</p>';
    }
    exit;
}
Exemple #24
0
 function dash_contact_message()
 {
     if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'vibe_security')) {
         _e('Security error', 'wplms-dashboard');
         die;
     }
     $members = json_decode(stripslashes($_POST['to']));
     $subject = $_POST['subject'];
     $message = $_POST['message'];
     if (!$members || !$subject || !$message) {
         echo _e('Please enter to/subject/message', 'wplms-dashboard');
         die;
     }
     $sender_id = get_current_user_id();
     $sent = 0;
     if (bp_is_active('messages')) {
         foreach ($members as $member) {
             if (messages_new_message(array('sender_id' => $sender_id, 'subject' => $subject, 'content' => $message, 'recipients' => $member))) {
                 $sent++;
             }
         }
     }
     echo sprintf(__('Message sent to %s members', 'wplms-dashboard'), $send);
     die;
 }
Exemple #25
0
/**
 * Send a private message reply to a thread via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_dtheme_ajax_messages_send_reply()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('messages_send_message');
    $result = messages_new_message(array('thread_id' => $_REQUEST['thread_id'], 'content' => $_REQUEST['content']));
    if ($result) {
        ?>
		<div class="message-box new-message">
			<div class="message-metadata">
				<?php 
        do_action('bp_before_message_meta');
        ?>
				<?php 
        echo bp_loggedin_user_avatar('type=thumb&width=30&height=30');
        ?>

				<strong><a href="<?php 
        echo bp_loggedin_user_domain();
        ?>
"><?php 
        bp_loggedin_user_fullname();
        ?>
</a> <span class="activity"><?php 
        printf(__('Sent %s', 'logicalboneshug'), bp_core_time_since(bp_core_current_time()));
        ?>
</span></strong>

				<?php 
        do_action('bp_after_message_meta');
        ?>
			</div>

			<?php 
        do_action('bp_before_message_content');
        ?>

			<div class="message-content">
				<?php 
        echo stripslashes(apply_filters('bp_get_the_thread_message_content', $_REQUEST['content']));
        ?>
			</div>

			<?php 
        do_action('bp_after_message_content');
        ?>

			<div class="clear"></div>
		</div>
	<?php 
    } else {
        echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'logicalboneshug') . '</p></div>';
    }
    exit;
}
function lpr_assignment_start()
{
    global $post;
    if (!isset($_POST['security'])) {
        return;
    }
    if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'assignment' . $post->ID)) {
        wp_die(__('Security check failed !', 'learn_press'));
        exit;
    }
    $user_id = get_current_user_id();
    $assignment_taken = get_user_meta($user_id, $post->ID, true);
    $current_time = current_time('timestamp');
    if (isset($_POST['start_assignment'])) {
        if (add_user_meta($user_id, $post->ID, $current_time)) {
            return;
        } else {
            wp_die(__('Assignment can not be re-started', 'learn_press'));
        }
    }
    if (isset($_POST['continue_assignment'])) {
        //Added Security measure, if someone renames the hidden field and submits
        $start_time = get_user_meta($user_id, $post->ID, true);
        $time = get_post_meta($post->ID, '_lpr_assignment_deadline');
        $assignment_duration_parameter = apply_filters('lpr_assignment_duration_parameter', 86400);
        $time_limit = intval($start_time) + intval($time) * $assignment_duration_parameter;
        if ($time_limit > $current_time) {
            return;
        } else {
            wp_die(__('TIME EXPIRED, PLEASE SUBMIT THE ASSIGNMENT', 'learn_press'));
        }
    }
    if (isset($_POST['submit_assignment'])) {
        if (add_post_meta($post->ID, $user_id, 0)) {
            if (function_exists('messages_new_message')) {
                $message = __('Assignment ', 'learn_press') . get_the_title($post->ID) . __(' submitted by student ', 'learn_press') . get_edit_user_link($user_id);
                messages_new_message(array('sender_id' => $user_id, 'subject' => __('Assignment submitted by Student', 'learn_press'), 'content' => $message, 'recipients' => $post->post_author));
            }
            return;
        }
        return;
    }
}
Exemple #27
0
function messages_action_view_message() {
	global $bp, $thread_id;

	if ( $bp->current_component != $bp->messages->slug || $bp->current_action != 'view' )
		return false;

	$thread_id = $bp->action_variables[0];

	if ( !$thread_id || !messages_is_valid_thread( $thread_id ) || ( !messages_check_thread_access($thread_id) && !is_super_admin() ) )
		bp_core_redirect( $bp->displayed_user->domain . $bp->current_component );

	/* Check if a new reply has been submitted */
	if ( isset( $_POST['send'] ) ) {

		/* Check the nonce */
		check_admin_referer( 'messages_send_message', 'send_message_nonce' );

		/* Send the reply */
		if ( messages_new_message( array( 'thread_id' => $thread_id, 'subject' => $_POST['subject'], 'content' => $_POST['content'] ) ) )
			bp_core_add_message( __( 'Your reply was sent successfully', 'buddypress' ) );
		else
			bp_core_add_message( __( 'There was a problem sending your reply, please try again', 'buddypress' ), 'error' );

		bp_core_redirect( $bp->displayed_user->domain . $bp->current_component . '/view/' . $thread_id . '/' );
	}

	/* Mark message read */
	messages_mark_thread_read( $thread_id );

	do_action( 'messages_action_view_message' );

	bp_core_new_subnav_item( array( 'name' => sprintf( __( 'From: %s', 'buddypress'), BP_Messages_Thread::get_last_sender($thread_id) ), 'slug' => 'view', 'parent_url' => $bp->loggedin_user->domain . $bp->messages->slug . '/', 'parent_slug' => $bp->messages->slug, 'screen_function' => true, 'position' => 40, 'user_has_access' => bp_is_my_profile() ) );
	bp_core_load_template( apply_filters( 'messages_template_view_message', 'members/single/home' ) );
}
 function wplms_send_event_invitations()
 {
     if (!isset($_POST['send_invitations'])) {
         return;
     }
     if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'vibe' . $course_id)) {
         echo '<div class="error">';
         _e('Security check Failed. Contact Administrator.', 'wplms-events');
         echo '</div>';
         return;
     }
     if (isset($_POST['invitation_subject']) && $_POST['invitation_subject'] != '') {
         $subject = html_entity_decode($_POST['invitation_subject']);
     } else {
         echo '<div class="error">';
         _e('Please enter a Invitation subject', 'wplms-events');
         echo '</div>';
         return;
     }
     if (isset($_POST['invitation_message']) && $_POST['invitation_message'] != '') {
         $message = html_entity_decode($_POST['invitation_message']);
     } else {
         echo '<div class="error">';
         _e('Please enter a Invitation Message', 'wplms-events');
         echo '</div>';
         return;
     }
     $event_id = get_the_ID();
     $course_id = get_post_meta($event_id, 'vibe_event_course', true);
     $message .= '<br /><ul>
     <li>' . __('EVENT : ', 'wplms-events') . get_the_title($event_id) . '<a href="' . get_permalink($event_id) . '">' . __('view event', 'wplms-events') . '</a></li>
     <li>' . __('COURSE : ', 'wplms-events') . get_the_title($course_id) . '<a href="' . get_permalink($course_id) . '">' . __('view course', 'wplms-events') . '</a></li>';
     $students = bp_course_get_students_undertaking($course_id);
     foreach ($students as $student) {
         $links = '';
         $check_invite = get_post_meta($event_id, $student, true);
         if (!isset($check_invite) || $check_invite == '') {
             $acceptnoncelink = wp_nonce_url(get_permalink($event_id) . '?accept', 'vibe_' . $event_id . $student, 'security');
             $rejectnoncelink = wp_nonce_url(get_permalink($event_id) . '?reject', 'vibe_' . $event_id . $student, 'security');
             $links = '<li>
             <a href="' . $acceptnoncelink . '" class="button small"><span> ' . __('ACCEPT', 'wplms-events') . '</span></a>
             <a href="' . $rejectnoncelink . '" class="button small"><span> ' . __('REJECT', 'wplms-events') . '</span></a>
             </li></ul>';
             messages_new_message(array('sender_id' => get_current_user_id(), 'subject' => $subject, 'content' => $message . $links, 'recipients' => $student));
         }
     }
     $vsi = get_post_meta($event_id, 'vibe_send_invitation', true);
     if (!isset($vsi)) {
         $vsi = 0;
     }
     $vsi++;
     update_post_meta($event_id, 'vibe_send_invitation', $vsi);
     echo '<div class="success">';
     _e('Invitation Message successfully sent to ', 'wplms-events');
     echo count($students) . __(' Students', 'wplms-events');
     echo '</div>';
     return;
 }
function bp_course_quiz_auto_submit($quiz_id, $user_id)
{
    $quiz_auto_evaluate = get_post_meta($quiz_id, 'vibe_quiz_auto_evaluate', true);
    if (vibe_validate($quiz_auto_evaluate)) {
        // Auto Evaluate for Quiz Enabled, Quiz auto evaluate, autoevaluate
        $total_marks = 0;
        $questions = vibe_sanitize(get_post_meta($quiz_id, 'quiz_questions' . $user_id, false));
        if (!isset($questions) || !is_array($questions)) {
            // Fallback for Older versions
            $questions = vibe_sanitize(get_post_meta($quiz_id, 'vibe_quiz_questions', false));
        }
        if (count($questions)) {
            $sum = $max_sum = 0;
            foreach ($questions['ques'] as $key => $question) {
                // Grab all the Questions
                if (isset($question) && $question) {
                    $type = get_post_meta($question, 'vibe_question_type', true);
                    $auto_evaluate_question_types = vibe_get_option('auto_eval_question_type');
                    if (isset($auto_evaluate_question_types) && is_Array($auto_evaluate_question_types) && count($auto_evaluate_question_types)) {
                        // Validated
                    } else {
                        $auto_evaluate_question_types = array('single');
                    }
                    if (isset($type) && in_array($type, $auto_evaluate_question_types)) {
                        $correct_answer = get_post_meta($question, 'vibe_question_answer', true);
                        $comments_query = new WP_Comment_Query();
                        $comments = $comments_query->query(array('post_id' => $question, 'user_id' => $user_id, 'number' => 1, 'status' => 'approve'));
                        foreach ($comments as $comment) {
                            $comment->comment_content = trim($comment->comment_content, ',');
                            if ($comment->comment_content == $correct_answer) {
                                $marks = $questions['marks'][$key];
                                $total_marks = $total_marks + $marks;
                            } else {
                                if ($type == 'multiple') {
                                    if (!strlen($comment->comment_content)) {
                                        $marks = 0;
                                    } else {
                                        $marked_answers = explode(',', $comment->comment_content);
                                        if (!is_array($marks_answers)) {
                                            // Force Array Form
                                            $marks_answers = array($marks_answers);
                                        }
                                        $correct_answers = explode(',', $correct_answer);
                                        if (!is_array($correct_answers)) {
                                            // Force Array Form
                                            $correct_answers = array($correct_answers);
                                        }
                                        sort($marked_answers);
                                        sort($correct_answers);
                                        if (array_diff($marked_answers, $correct_answers) == array_diff($correct_answers, $marked_answers)) {
                                            $marks = $questions['marks'][$key];
                                            $total_marks = $total_marks + $marks;
                                        } else {
                                            $marks = apply_filters('wplms_incorrect_quiz_answer', 0, $comment->comment_content, $question);
                                        }
                                    }
                                } elseif ($type == 'smalltext' || $type == 'fillblank') {
                                    if (strpos($correct_answer, ',')) {
                                        $correct_answers_array = explode(',', $correct_answer);
                                        foreach ($correct_answers_array as $c_answer) {
                                            if (strtolower($c_answer) == strtolower($comment->comment_content)) {
                                                $marks = $questions['marks'][$key];
                                                $total_marks = $total_marks + $marks;
                                                break;
                                            }
                                        }
                                    }
                                } else {
                                    $marks = apply_filters('wplms_incorrect_quiz_answer', 0, $comment->comment_content, $question);
                                }
                            }
                            update_comment_meta($comment->comment_ID, 'marks', $marks);
                        }
                        //END-For
                    }
                }
            }
            if (update_post_meta($quiz_id, $user_id, $total_marks)) {
                $message = __('You\'ve obtained ', 'vibe') . $total_marks . __(' out of ', 'vibe') . array_sum($questions['marks']) . __(' in quiz ', 'vibe') . ' <a href="' . get_permalink($quiz_id) . '">' . get_the_title($quiz_id) . '</a>';
                $sender_id = get_post_field('post_author', $quiz_id);
                if (!is_numeric($sender_id)) {
                    $sender_id = get_current_user_id();
                }
                if (function_exists('messages_new_message')) {
                    messages_new_message(array('sender_id' => $sender_id, 'subject' => __('Quiz results available', 'vibe'), 'content' => $message, 'recipients' => $user_id));
                }
                $max_marks = array_sum($questions['marks']);
                $activity_id = bp_course_record_activity(array('action' => __('Quiz Auto Evaluated', 'vibe'), 'content' => __('Quiz ', 'vibe') . get_the_title($quiz_id) . __(' auto evaluated for student ', 'vibe') . bp_core_get_userlink($user_id) . __(' with marks ', 'vibe') . ' = ' . $total_marks . __('/', 'vibe') . $max_marks, 'type' => 'evaluate_quiz', 'primary_link' => get_permalink($quiz_id), 'item_id' => $quiz_id, 'secondary_item_id' => $user_id));
                bp_course_record_activity_meta(array('id' => $activity_id, 'meta_key' => 'instructor', 'meta_value' => get_post_field('post_author', $quiz_id)));
                do_action('badgeos_wplms_evaluate_quiz', $quiz_id, $total_marks, $user_id);
            }
        }
    } else {
        // End Auto evaluate and Send notification to instructor
        if (function_exists('messages_new_message')) {
            $instructor_id = get_post_field('post_author', $quiz_id);
            $course_id = get_post_meta($quiz_id, 'vibe_course', true);
            if (isset($course_id) && is_numeric($course_id)) {
                $quiz_link = '<a href="' . get_permalink($course_id) . '?action=admin&submissions">' . get_the_title($quiz_id) . '</a>';
            } else {
                $quiz_link = get_the_title($quiz_id);
            }
            $message = sprintf(__('Quiz %s submitted by student %s for evaluation', 'vibe'), $quiz_link, bp_core_get_userlink($user_id));
            messages_new_message(array('sender_id' => $user_id, 'subject' => __('Quiz submitted for evaluation', 'vibe'), 'content' => $message, 'recipients' => $instructor_id));
        }
    }
}
 function send_bulk_message()
 {
     $course_id = $_POST['course'];
     if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'security' . $course_id)) {
         echo 'Security check failed !';
         die;
     }
     $members = json_decode(stripslashes($_POST['members']));
     $sender = $_POST['sender'];
     $subject = stripslashes($_POST['subject']);
     if (!isset($subject)) {
         _e('Set a Subject for the message', 'vibe');
         die;
     }
     $message = stripslashes($_POST['message']);
     if (!isset($message)) {
         _e('Set a Subject for the message', 'vibe');
         die;
     }
     $sent = 0;
     if (count($members) > 0) {
         foreach ($members as $member) {
             if (bp_is_active('messages')) {
                 if (messages_new_message(array('sender_id' => $sender, 'subject' => $subject, 'content' => $message, 'recipients' => $member))) {
                     $sent++;
                 }
             }
         }
         echo __('Messages Sent to ', 'vibe') . $sent . __(' members', 'vibe');
     } else {
         echo __('Please select members', 'vibe');
     }
     do_action('wplms_bulk_action', 'bulk_message', $course_id, $members);
     die;
 }