Example #1
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);
 }
 function read_notification(MM_Conversation_Model $model)
 {
     $setting = new MM_Setting_Model();
     $setting->load();
     $is_send = $setting->enable_receipt;
     //getting the messegers from this conv belong to this user
     if (!count($model->get_unread())) {
         return;
     }
     $messeger = $model->get_last_message();
     //check if this current user is sender
     if ($messeger->send_from == get_current_user_id()) {
         return;
     }
     if (!$is_send) {
         return;
     }
     if ($setting->user_receipt == true) {
         //check does user enable
         $sender_setting = get_user_meta($messeger->send_from, 'messages_user_setting', true);
         if (!$sender_setting) {
             $sender_setting = array('enable_receipt' => 1, 'prevent_receipt' => 0);
         }
         if ($sender_setting['enable_receipt'] != true) {
             //user don't enable it,
             return;
         }
         //user enable it, checking does the receiver block it
         $reciver_setting = get_user_meta($messeger->send_to, 'messages_user_setting', true);
         if (!$reciver_setting) {
             $reciver_setting = array('enable_receipt' => 1, 'prevent_receipt' => 0);
         }
         if ($reciver_setting['prevent_receipt'] == true) {
             //this user has block it, return
             return;
         }
     }
     //from here, we can send notification
     $data = array('SITE_NAME' => get_bloginfo('name'), 'FROM_NAME' => $messeger->get_name($messeger->send_from), 'POST_LINK' => add_query_arg('message_id', $model->id, get_permalink(mmg()->setting()->inbox_page, true)), 'FROM_MESSAGE' => $messeger->content, 'TO_NAME' => $messeger->get_name($messeger->send_to));
     $data = apply_filters('message_notification_params', $data, $this);
     $subject = stripslashes($setting->receipt_subject);
     $content = stripslashes($setting->receipt_content);
     foreach ($data as $key => $val) {
         $subject = str_replace($key, $val, $subject);
         $content = str_replace($key, $val, $content);
     }
     $sendto = get_userdata($messeger->send_from);
     $headers = array('Content-Type: text/html; charset=UTF-8');
     wp_mail($sendto->user_email, $subject, $content, $headers);
 }
 function inbox($atts)
 {
     $a = wp_parse_args($atts, array('nav_view' => 'both'));
     if (!is_user_logged_in()) {
         do_action('mmg_before_load_login_form');
         mmg()->load_script('login');
         return $this->render('shortcode/login', array('show_nav' => $this->can_show_nav($a['nav_view'])), false);
     }
     mmg()->load_script('inbox');
     add_action('wp_footer', array(&$this, 'render_compose_form'));
     //$a = shortcode_atts($atts, array());
     $type = mmg()->get('box', 'inbox');
     if (isset($_GET['query']) && !empty($_GET['query'])) {
         $type = 'search';
     }
     $total_pages = 0;
     switch ($type) {
         case 'inbox':
             $models = MM_Conversation_Model::get_conversation();
             $total_pages = mmg()->global['conversation_total_pages'];
             break;
         case 'unread':
             $models = MM_Conversation_Model::get_unread();
             $total_pages = mmg()->global['conversation_total_pages'];
             break;
         case 'read':
             $models = MM_Conversation_Model::get_read();
             $total_pages = mmg()->global['conversation_total_pages'];
             break;
         case 'sent':
             $models = MM_Conversation_Model::get_sent();
             $total_pages = mmg()->global['conversation_total_pages'];
             break;
         case 'archive':
             $models = MM_Conversation_Model::get_archive();
             $total_pages = mmg()->global['conversation_total_pages'];
             break;
         case 'setting':
             return $this->render('shortcode/setting', array('show_nav' => $this->can_show_nav($a['nav_view'])), false);
             break;
         case 'search':
             $models = MM_Conversation_Model::search(mmg()->get('query'));
             $total_pages = mmg()->global['conversation_total_pages'];
             break;
     }
     return $this->render('shortcode/inbox', array('models' => $models, 'total_pages' => $total_pages, 'paged' => mmg()->get('mpaged', 'int', 1), 'show_nav' => $this->can_show_nav($a['nav_view'])), false);
 }