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'));
}
/**
 * Sets up and displays the screen output for the sub nav item "portfolio/add"
 */
function bp_portfolio_screen_add()
{
    global $bp;
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    messages_remove_callback_values();
    if (isset($_POST['add'])) {
        // Check the nonce
        if (!wp_verify_nonce($_POST['_wpnonce'], 'project_form_nonce')) {
            bp_core_add_message(__('There was an error recording the project, please try again', 'bp-portfolio'), 'error');
            bp_core_load_template(apply_filters('bp_portfolio_template_personal', BP_PORTFOLIO_TEMPLATE . '/personal'));
        }
        if (empty($_POST['title-input']) or empty($_POST['url-input']) or empty($_POST['description'])) {
            bp_core_add_message(__('All fields are required', 'bp-portfolio'), 'error');
        } else {
            // Check the url
            if (!preg_match("/(ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?/", $_POST['url-input'])) {
                bp_core_add_message(__('Url must be a valid URL.', 'bp-portfolio'), 'error');
                bp_core_load_template(apply_filters('bp_portfolio_template_add', BP_PORTFOLIO_TEMPLATE . '/add'));
            }
            // Check description size
            if (strlen($_POST['description']) > BP_PORTFOLIO_DESC_MAX_SIZE) {
                $_POST['description'] = substr($_POST['description'], 0, BP_PORTFOLIO_DESC_MAX_SIZE);
            }
            // Save the item
            $posts = array('author_id' => bp_loggedin_user_id(), 'title' => $_POST['title-input'], 'description' => $_POST['description'], 'url' => $_POST['url-input']);
            // Is that a capture has been sent ?
            if (isset($_FILES['screenshot-input']) and $_FILES['screenshot-input']['error'] == 0) {
                $posts['screenshot'] = $_FILES['screenshot-input'];
            }
            if ($item = bp_portfolio_save_item($posts)) {
                bp_core_add_message(__('Project has been saved', 'bp-portfolio'));
                bp_core_redirect(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_portfolio_slug());
            } else {
                bp_core_add_message(__('There was an error recording the project, please try again', 'bp-portfolio'), 'error');
            }
        }
    }
    do_action('bp_portfolio_add_screen');
    // Displaying Content
    bp_core_load_template(apply_filters('bp_portfolio_template_add', BP_PORTFOLIO_TEMPLATE . '/add'));
}
Пример #3
0
/**
 * Load the Messages > Compose screen.
 *
 * @since BuddyPress (1.0.0)
 */
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();
    /**
     * 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'));
}
Пример #4
0
 function send()
 {
     global $nxtdb, $bp;
     $this->sender_id = apply_filters('messages_message_sender_id_before_save', $this->sender_id, $this->id);
     $this->thread_id = apply_filters('messages_message_thread_id_before_save', $this->thread_id, $this->id);
     $this->subject = apply_filters('messages_message_subject_before_save', $this->subject, $this->id);
     $this->message = apply_filters('messages_message_content_before_save', $this->message, $this->id);
     $this->date_sent = apply_filters('messages_message_date_sent_before_save', $this->date_sent, $this->id);
     do_action_ref_array('messages_message_before_save', array(&$this));
     // Make sure we have at least one recipient before sending.
     if (empty($this->recipients)) {
         return false;
     }
     $new_thread = false;
     // If we have no thread_id then this is the first message of a new thread.
     if (empty($this->thread_id)) {
         $this->thread_id = (int) $nxtdb->get_var($nxtdb->prepare("SELECT MAX(thread_id) FROM {$bp->messages->table_name_messages}")) + 1;
         $new_thread = true;
     }
     // First insert the message into the messages table
     if (!$nxtdb->query($nxtdb->prepare("INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent))) {
         return false;
     }
     $recipient_ids = array();
     if ($new_thread) {
         // Add an recipient entry for all recipients
         foreach ((array) $this->recipients as $recipient) {
             $nxtdb->query($nxtdb->prepare("INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count ) VALUES ( %d, %d, 1 )", $recipient->user_id, $this->thread_id));
             $recipient_ids[] = $recipient->user_id;
         }
         // Add a sender recipient entry if the sender is not in the list of recipients
         if (!in_array($this->sender_id, $recipient_ids)) {
             $nxtdb->query($nxtdb->prepare("INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, sender_only ) VALUES ( %d, %d, 1 )", $this->sender_id, $this->thread_id));
         }
     } else {
         // Update the unread count for all recipients
         $nxtdb->query($nxtdb->prepare("UPDATE {$bp->messages->table_name_recipients} SET unread_count = unread_count + 1, sender_only = 0, is_deleted = 0 WHERE thread_id = %d AND user_id != %d", $this->thread_id, $this->sender_id));
     }
     $this->id = $nxtdb->insert_id;
     messages_remove_callback_values();
     do_action_ref_array('messages_message_after_save', array(&$this));
     return $this->id;
 }
Пример #5
0
function messages_screen_compose()
{
    // Remove any saved message data from a previous session.
    messages_remove_callback_values();
    //var_dump($_POST['send_to_usernames']);
    $recipients = false;
    if (empty($_POST['send_to_usernames'])) {
        if (!empty($_POST['send-to-input'])) {
            // Replace commas with places
            $recipients = str_replace(',', ' ', $_POST['send-to-input']);
            $recipients = str_replace('  ', ' ', $recipients);
        }
    } else {
        $recipients = $_POST['send_to_usernames'];
    }
    if ($recipients || isset($_POST['send-notice']) && is_site_admin()) {
        messages_send_message($recipients, $_POST['subject'], $_POST['content'], $_POST['thread_id'], false, true);
    }
    do_action('messages_screen_compose');
    bp_core_load_template(apply_filters('messages_template_compose', 'messages/compose'));
}
 /**
  * Send a message.
  *
  * @return int|bool ID of the newly created message on success, false
  *                  on failure.
  */
 public function send()
 {
     global $wpdb;
     $bp = buddypress();
     $this->sender_id = apply_filters('messages_message_sender_id_before_save', $this->sender_id, $this->id);
     $this->thread_id = apply_filters('messages_message_thread_id_before_save', $this->thread_id, $this->id);
     $this->subject = apply_filters('messages_message_subject_before_save', $this->subject, $this->id);
     $this->message = apply_filters('messages_message_content_before_save', $this->message, $this->id);
     $this->date_sent = apply_filters('messages_message_date_sent_before_save', $this->date_sent, $this->id);
     /**
      * Fires before the current message item gets saved.
      *
      * Please use this hook to filter the properties above. Each part will be passed in.
      *
      * @since 1.0.0
      *
      * @param BP_Messages_Message $this Current instance of the message item being saved. Passed by reference.
      */
     do_action_ref_array('messages_message_before_save', array(&$this));
     // Make sure we have at least one recipient before sending.
     if (empty($this->recipients)) {
         return false;
     }
     $new_thread = false;
     // If we have no thread_id then this is the first message of a new thread.
     if (empty($this->thread_id)) {
         $this->thread_id = (int) $wpdb->get_var("SELECT MAX(thread_id) FROM {$bp->messages->table_name_messages}") + 1;
         $new_thread = true;
     }
     // First insert the message into the messages table
     if (!$wpdb->query($wpdb->prepare("INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent))) {
         return false;
     }
     $this->id = $wpdb->insert_id;
     $recipient_ids = array();
     if ($new_thread) {
         // Add an recipient entry for all recipients
         foreach ((array) $this->recipients as $recipient) {
             $wpdb->query($wpdb->prepare("INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count ) VALUES ( %d, %d, 1 )", $recipient->user_id, $this->thread_id));
             $recipient_ids[] = $recipient->user_id;
         }
         // Add a sender recipient entry if the sender is not in the list of recipients
         if (!in_array($this->sender_id, $recipient_ids)) {
             $wpdb->query($wpdb->prepare("INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, sender_only ) VALUES ( %d, %d, 1 )", $this->sender_id, $this->thread_id));
         }
     } else {
         // Update the unread count for all recipients
         $wpdb->query($wpdb->prepare("UPDATE {$bp->messages->table_name_recipients} SET unread_count = unread_count + 1, sender_only = 0, is_deleted = 0 WHERE thread_id = %d AND user_id != %d", $this->thread_id, $this->sender_id));
     }
     messages_remove_callback_values();
     /**
      * Fires after the current message item has been saved.
      *
      * @since 1.0.0
      *
      * @param BP_Messages_Message $this Current instance of the message item being saved. Passed by reference.
      */
     do_action_ref_array('messages_message_after_save', array(&$this));
     return $this->id;
 }
Пример #7
0
/**
 * 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'));
}
 function send()
 {
     global $wpdb, $bp;
     $this->sender_id = apply_filters('messages_message_sender_id_before_save', $this->sender_id, $this->id);
     $this->subject = apply_filters('messages_message_subject_before_save', $this->subject, $this->id);
     $this->message = apply_filters('messages_message_content_before_save', $this->message, $this->id);
     $this->date_sent = apply_filters('messages_message_date_sent_before_save', $this->date_sent, $this->id);
     $this->message_order = apply_filters('messages_message_order_before_save', $this->message_order, $this->id);
     $this->sender_is_group = apply_filters('messages_message_sender_is_group_before_save', $this->sender_is_group, $this->id);
     do_action('messages_message_before_save', $this);
     // First insert the message into the messages table
     if (!$wpdb->query($wpdb->prepare("INSERT INTO {$bp->messages->table_name_messages} ( sender_id, subject, message, date_sent, message_order, sender_is_group ) VALUES ( %d, %s, %s, FROM_UNIXTIME(%d), %d, %d )", $this->sender_id, $this->subject, $this->message, $this->date_sent, $this->message_order, $this->sender_is_group))) {
         return false;
     }
     // Next, if thread_id is set, we are adding to an existing thread, if not, start a new one.
     if ($this->thread_id) {
         // Select and update the current message ids for the thread.
         $the_ids = $wpdb->get_row($wpdb->prepare("SELECT message_ids, sender_ids FROM {$bp->messages->table_name_threads} WHERE id = %d", $this->thread_id));
         $message_ids = unserialize($the_ids->message_ids);
         $message_ids[] = $wpdb->insert_id;
         $message_ids = serialize($message_ids);
         // We need this so we can return the new message ID.
         $message_id = $wpdb->insert_id;
         // Update the sender ids for the thread
         $sender_ids = unserialize($the_ids->sender_ids);
         if (!in_array($this->sender_id, $sender_ids) || !$sender_ids) {
             $sender_ids[] = $this->sender_id;
         }
         $sender_ids = serialize($sender_ids);
         // Update the thread the message belongs to.
         $wpdb->query($wpdb->prepare("UPDATE {$bp->messages->table_name_threads} SET message_ids = %s, sender_ids = %s, last_message_id = %d, last_sender_id = %d WHERE id = %d", $message_ids, $sender_ids, $wpdb->insert_id, $this->sender_id, $this->thread_id));
         // Find the recipients and update the unread counts for each
         if (!$this->recipients) {
             $this->recipients = $this->get_recipients();
         }
         for ($i = 0; $i < count($this->recipients); $i++) {
             if ($this->recipients[$i]->user_id != $bp->loggedin_user->id) {
                 $wpdb->query($wpdb->prepare("UPDATE {$bp->messages->table_name_recipients} SET unread_count = unread_count + 1, sender_only = 0 WHERE thread_id = %d AND user_id = %d", $this->thread_id, $this->recipients[$i]));
             }
         }
     } else {
         // Create a new thread.
         $message_id = $wpdb->insert_id;
         $serialized_message_id = serialize(array((int) $message_id));
         $serialized_sender_id = serialize(array((int) $bp->loggedin_user->id));
         $sql = $wpdb->prepare("INSERT INTO {$bp->messages->table_name_threads} ( message_ids, sender_ids, first_post_date, last_post_date, last_message_id, last_sender_id ) VALUES ( %s, %s, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d), %d, %d )", $serialized_message_id, $serialized_sender_id, $this->date_sent, $this->date_sent, $message_id, $this->sender_id);
         if (false === $wpdb->query($sql)) {
             return false;
         }
         $this->thread_id = $wpdb->insert_id;
         // Add a new entry for each recipient;
         for ($i = 0; $i < count($this->recipients); $i++) {
             $wpdb->query($wpdb->prepare("INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count ) VALUES ( %d, %d, 1 )", $this->recipients[$i], $this->thread_id));
         }
         if (!in_array($this->sender_id, $this->recipients)) {
             // Finally, add a recipient entry for the sender, as replies need to go to this person too.
             $wpdb->query($wpdb->prepare("INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count, sender_only ) VALUES ( %d, %d, 0, 0 )", $this->sender_id, $this->thread_id));
         }
     }
     $this->id = $message_id;
     messages_remove_callback_values();
     do_action('messages_message_after_save', $this);
     return true;
 }