예제 #1
0
 function sent_notification(MM_Message_Model $model)
 {
     //send message
     $setting = new MM_Setting_Model();
     $setting->load();
     $link = add_query_arg('message_id', $model->id, get_permalink(mmg()->setting()->inbox_page));
     $data = array('SITE_NAME' => get_bloginfo('name'), 'FROM_NAME' => $model->get_name($model->send_from), 'POST_LINK' => $link, 'FROM_MESSAGE' => $model->content);
     $data = apply_filters('message_notification_params', $data, $this);
     $subject = stripslashes($setting->noti_subject);
     $content = stripslashes($setting->noti_content);
     foreach ($data as $key => $val) {
         $subject = str_replace($key, $val, $subject);
         $content = str_replace($key, $val, $content);
     }
     $sendto = get_userdata($model->send_to);
     $from = get_userdata($model->send_from);
     //prepare atachments
     $attachments = array();
     if ($model->attachment) {
         $ids = explode(',', $model->attachment);
         $ids = array_filter($ids);
         foreach ($ids as $id) {
             if (filter_var($id, FILTER_VALIDATE_INT)) {
                 $upload = IG_Uploader_Model::model()->find($id);
                 if (is_object($upload) && $upload->file) {
                     $attachments[] = get_attached_file($upload->file);
                 }
             }
         }
     }
     $headers = array('From: ' . $model->get_name($model->send_from) . ' <' . $from->user_email . '>', 'Content-Type: text/html; charset=UTF-8');
     wp_mail($sendto->user_email, $subject, $content, $headers, $attachments);
 }
예제 #2
0
 function index_new_message(MM_Message_Model $model)
 {
     $key = "mm_notification";
     delete_user_meta($model->send_to, $key);
     $cache = array();
     $cache['status'] = 1;
     //clean up messages
     $cache['messages'] = array();
     $unreads = MM_Conversation_Model::get_unread($model->send_to);
     $message = array('id' => $model->id, 'from' => $model->get_name($model->send_from), 'subject' => $model->subject, 'text' => mmg()->trim_text($model->content, 100));
     $cache['messages'][] = $message;
     $cache['count'] = count($unreads);
     add_user_meta($model->send_to, $key, $cache);
 }
 public static function get_sent()
 {
     $per_page = mmg()->setting()->per_page;
     $paged = mmg()->get('mpaged', 1);
     $offset = ($paged - 1) * $per_page;
     $total_pages = ceil(self::count_all() / $per_page);
     mmg()->global['conversation_total_pages'] = $total_pages;
     $messages = MM_Message_Model::model()->find_by_attributes(array('send_from' => get_current_user_id()));
     $ids = array();
     foreach ($messages as $message) {
         $ids[] = $message->conversation_id;
     }
     $ids = array_unique(array_filter($ids));
     if (empty($ids)) {
         return array();
     }
     $model = new MM_Conversation_Model();
     global $wpdb;
     $sql = "SELECT conversation.id FROM " . $model->get_table() . " conversation\r\n                INNER JOIN " . MM_Message_Status_Model::model()->get_table() . " mstat ON mstat.conversation_id=conversation.id\r\n                WHERE mstat.status IN (" . implode(',', array(MM_Message_Status_Model::STATUS_READ, MM_Message_Status_Model::STATUS_UNREAD)) . ")\r\n                AND conversation.id IN (" . implode(',', $ids) . ") AND site_id=%d\r\n                GROUP BY conversation.id ORDER BY conversation.date_created DESC LIMIT %d,%d";
     $sql = $wpdb->prepare($sql, get_current_blog_id(), $offset, $per_page);
     $ids = $wpdb->get_col($sql);
     if (empty($ids)) {
         return array();
     }
     $models = $model->find_all_by_ids($ids, false, false, 'date_created DESC');
     return $models;
 }
예제 #4
0
<?php

$model = new MM_Message_Model();
?>
    <div class="ig-container">
        <div class="mmessage-container">
            <div>
                <div class="modal" id="compose-form-container">
                    <div class="modal-dialog">
                        <div class="modal-content" id="compose-modal">
                            <div class="modal-header">
                                <h4 class="modal-title"><?php 
_e("Compose Message", mmg()->domain);
?>
</h4>
                            </div>
                            <?php 
$form = new IG_Active_Form($model);
$form->open(array("attributes" => array("class" => "compose-form form-horizontal", "id" => "compose-form")));
?>
                            <div class="modal-body">
                                <div style="margin-bottom: 0"
                                     class="form-group <?php 
echo $model->has_error("send_to") ? "has-error" : null;
?>
">
                                    <?php 
$form->label("send_to", array("text" => "Send To", "attributes" => array("class" => "control-label col-sm-2 hidden-xs hidden-sm")));
?>
                                    <div class="col-md-10 col-sm-12 col-xs-12">
                                        <?php 
예제 #5
0
<?php

$model = new MM_Message_Model();
?>
<div class="ig-container">
    <div class="mmessage-container">
        <div>
            <div class="modal" id="compose-form-container-admin-bar">
                <div class="modal-dialog">
                    <div class="modal-content" id="compose-modal-admin-bar">
                        <div class="modal-header">
                            <h4 class="modal-title"><?php 
_e("Compose Message", mmg()->domain);
?>
</h4>
                        </div>
                        <?php 
$form = new IG_Active_Form($model);
$form->open(array("attributes" => array("class" => "compose-form form-horizontal", "id" => "compose-form-admin-bar")));
?>
                        <div class="modal-body">

                            <div style="margin-bottom: 0"
                                 class="form-group <?php 
echo $model->has_error("send_to") ? "has-error" : null;
?>
">
                                <?php 
$form->label("send_to", array("text" => "Send To", "attributes" => array("class" => "control-label col-sm-2 hidden-xs hidden-sm")));
?>
                                <div class="col-md-10 col-sm-12 col-xs-12">
 function _send_message($user_id, $model)
 {
     //create new conservation
     $conservation = new MM_Conversation_Model();
     $conservation->status = MM_Message_Status_Model::STATUS_UNREAD;
     $conservation->save();
     //save message
     $m = new MM_Message_Model();
     $m->import($model->export());
     $m->send_to = $user_id;
     $m->conversation_id = $conservation->id;
     $m->status = MM_Message_Model::UNREAD;
     $m->save();
     //update index
     $conservation->update_index($m->id);
     do_action('mm_message_sent', $m);
     //update status
     $model = new MM_Message_Status_Model();
     $model->user_id = $user_id;
     $model->conversation_id = $conservation->id;
     $model->status = MM_Message_Status_Model::STATUS_UNREAD;
     $model->type = MM_Message_Status_Model::TYPE_CONVERSATION;
     $model->save();
     //we need both for each sender & reciver
     $model = new MM_Message_Status_Model();
     $model->user_id = get_current_user_id();
     $model->conversation_id = $conservation->id;
     //because we send so status should be read
     $model->status = MM_Message_Status_Model::STATUS_READ;
     $model->type = MM_Message_Status_Model::TYPE_CONVERSATION;
     $model->save();
 }