function notify_users($message_id, $mgs)
 {
     $domain_name = preg_replace('/^www\\./', '', $_SERVER['SERVER_NAME']);
     $usersarray = get_users("orderby=ID");
     $to = fep_get_option('ann_to', get_bloginfo('admin_email'));
     $from = 'noreply@' . $domain_name;
     $bcc = array();
     foreach ($usersarray as $user) {
         $notify = fep_get_user_option('allow_ann', 1, $user->ID);
         if ($notify == '1') {
             $bcc[] = $user->user_email;
         }
     }
     //var_dump($bcc);
     $chunked_bcc = array_chunk($bcc, 25);
     $subject = get_bloginfo("name") . ': ' . __('New Announcement', 'fep');
     $message = __('A new Announcement is Published in ', 'fep') . "\r\n";
     $message .= get_bloginfo("name") . "\r\n";
     $message .= sprintf(__("Title: %s", 'fep'), $mgs['message_title']) . "\r\n";
     $message .= __('Please Click the following link to view full Announcement.', 'fep') . "\r\n";
     $message .= fep_action_url('announcements') . "\r\n";
     foreach ($chunked_bcc as $bcc_chunk) {
         $headers = array();
         $headers['From'] = 'From: ' . get_bloginfo("name") . '<' . $from . '>';
         $headers['Bcc'] = 'Bcc: ' . implode(', ', $bcc_chunk);
         wp_mail($to, $subject, $message, $headers);
     }
     return;
 }
 function newmessage()
 {
     $class = 'fep-button';
     if (is_page(fep_page_id()) && isset($_GET['fepaction']) && $_GET['fepaction'] == 'newmessage') {
         $class = 'fep-button-active';
     }
     echo "<a class='{$class}' href='" . fep_action_url('newmessage') . "'>" . __('New Message', 'fep') . '</a>';
 }
 function directory()
 {
     if (fep_get_option('hide_directory', 0) == '1' && !current_user_can('manage_options')) {
         echo fep_message_box();
         return;
     }
     $page = isset($_GET['feppage']) && $_GET['feppage'] ? absint($_GET['feppage']) : 0;
     $offset = $page * fep_get_option('user_page', 50);
     $args = array('number' => fep_get_option('user_page', 50), 'offset' => $offset, 'orderby' => 'display_name', 'order' => 'ASC');
     $args = apply_filters('fep_directory_arguments', $args);
     // The Query
     $user_query = new WP_User_Query($args);
     $total = $user_query->get_total();
     if (!empty($user_query->results)) {
         $directory = "<p><strong>" . __("Total Users", 'fep') . ": (" . $total . ")</strong></p>";
         $numPgs = $total / fep_get_option('user_page', 50);
         if ($numPgs > 1) {
             $directory .= "<p><strong>" . __("Page", 'fep') . ": </strong> ";
             for ($i = 0; $i < $numPgs; $i++) {
                 if ($_GET['feppage'] != $i) {
                     $directory .= "<a href='" . fep_action_url() . "directory&feppage=" . $i . "'>" . ($i + 1) . "</a> ";
                 } else {
                     $directory .= "[<b>" . ($i + 1) . "</b>] ";
                 }
             }
             $directory .= "</p>";
         }
         $directory .= "<table><tr class='fep-head'>\r\n        <th width='40%'>" . __("User", 'fep') . "</th>\r\n        <th width='30%'>" . __("View Messages between", 'fep') . "</th>\r\n\t\t<th width='30%'>" . __("Send Message", 'fep') . "</th></tr>";
         $a = 0;
         foreach ($user_query->results as $u) {
             $directory .= "<tr class='fep-trodd" . $a . "'><td>" . $u->display_name . "</td>";
             $directory .= "<td><a href='" . fep_action_url() . "between&with={$u->user_login}'>" . __("View Messages between", 'fep') . "</a></td>";
             $directory .= "<td><a href='" . fep_action_url() . "newmessage&to={$u->user_login}'>" . __("Send Message", 'fep') . "</a></td></tr>";
             if ($a) {
                 $a = 0;
             } else {
                 $a = 1;
             }
         }
         $directory .= "</table>";
     } else {
         $directory = "<div id='fep-error'>" . __("No users found.", 'fep') . "</div>";
     }
     echo apply_filters('fep_directory_output', $directory);
 }
 function form()
 {
     global $user_ID;
     $token = fep_create_nonce('add_announcement');
     $message_title = isset($_REQUEST['message_title']) ? esc_html($_REQUEST['message_title']) : '';
     $message_content = isset($_REQUEST['message_content']) ? esc_textarea($_REQUEST['message_content']) : '';
     $form = "<form action='" . fep_action_url('addannouncement') . "' method='post' enctype='multipart/form-data'>\r\n      " . __("Subject", 'fep') . ":<br/>\r\n      <input type='text' name='message_title' value='{$message_title}' /><br/>";
     ob_start();
     do_action('fep_announcement_form_before_content');
     echo __("Message", 'fep') . ":<br/>";
     if ('wp_editor' == fep_get_option('editor_type') || current_user_can('manage_options')) {
         wp_editor($message_content, 'message_content', array('teeny' => false, 'media_buttons' => false, 'textarea_rows' => 8));
     } elseif ('teeny' == fep_get_option('editor_type', 'teeny')) {
         wp_editor($message_content, 'message_content', array('teeny' => true, 'media_buttons' => false, 'textarea_rows' => 8));
     } else {
         echo "<textarea name='message_content' placeholder='Message Content'>{$message_content}</textarea>";
     }
     do_action('fep_announcement_form_after_content');
     $form .= ob_get_contents();
     ob_end_clean();
     $form .= "<input type='hidden' name='message_from' value='{$user_ID}' />\r\n\t  <input type='hidden' name='token' value='{$token}' /><br/>\r\n      <input type='submit' name='add-announcement' value='" . __("Submit", 'fep') . "' />\r\n      </form>";
     return $form;
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     global $user_ID;
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
     }
     $show_messagebox = isset($instance['show_messagebox']) ? $instance['show_messagebox'] : false;
     $show_announcement = isset($instance['show_announcement']) ? $instance['show_announcement'] : false;
     echo "Welcome " . fep_get_userdata($user_ID, 'display_name', 'id') . '<br />';
     echo __('You have', 'fep');
     if ($show_messagebox) {
         $New_mgs = fep_get_new_message_number();
         $sm = $New_mgs > 1 ? 's' : '';
         echo "<a href='" . fep_action_url('messagebox') . "'>" . sprintf(__(" %d new message%s", 'fep'), $New_mgs, $sm) . '</a>';
     }
     if ($show_messagebox && $show_announcement) {
         echo __(' and', 'fep');
     }
     if ($show_announcement) {
         $New_ann = 0;
         if (class_exists('fep_announcement_class')) {
             $New_ann = fep_announcement_class::init()->getAnnouncementsNum();
         }
         $sa = $New_ann > 1 ? 's' : '';
         echo "<a href='" . fep_action_url('announcements') . "'>" . sprintf(__(" %d new announcement%s", 'fep'), $New_ann, $sa) . '</a>';
     }
     do_action('fep_text_widget');
     echo $args['after_widget'];
 }
function fep_reply_form($args = '')
{
    global $user_ID;
    $defaults = array('message_from' => $user_ID, 'message_to' => '', 'message_top' => '', 'message_title' => '', 'parent_id' => 0, 'token' => fep_create_nonce('new_message'));
    $args = wp_parse_args($args, $defaults);
    $reply_form = "\r\n      <p><strong>" . __("Add Reply", 'fep') . ":</strong></p>\r\n      <form action='" . fep_action_url('checkmessage') . "' method='post' enctype='multipart/form-data'><br/>";
    ob_start();
    do_action('fep_reply_form_before_content');
    if ('wp_editor' == fep_get_option('editor_type') || current_user_can('manage_options')) {
        wp_editor('', 'message_content', array('teeny' => false, 'media_buttons' => false));
    } elseif ('teeny' == fep_get_option('editor_type', 'teeny')) {
        wp_editor('', 'message_content', array('teeny' => true, 'media_buttons' => false));
    } else {
        echo "<textarea name='message_content' placeholder='" . __('Message Content', 'fep') . "'></textarea>";
    }
    do_action('fep_reply_form_after_content');
    $reply_form .= ob_get_contents();
    ob_end_clean();
    $reply_form .= "\r\n      <input type='hidden' name='message_to' value='" . $args['message_to'] . "' />\r\n\t  <input type='hidden' name='message_top' value='" . $args['message_top'] . "' />\r\n      <input type='hidden' name='message_title' value='" . $args['message_title'] . "' />\r\n      <input type='hidden' name='message_from' value='" . $args['message_from'] . "' />\r\n      <input type='hidden' name='parent_id' value='" . $args['parent_id'] . "' />\r\n\t  <input type='hidden' name='token' value='" . $args['token'] . "' /><br/>\r\n      <input type='submit' name='new_message' value='" . __("Send Message", 'fep') . "' />\r\n      </form>";
    return apply_filters('fep_reply_form', $reply_form);
}
 function display_attachment($message_id)
 {
     $attachment = fep_get_message_meta($message_id, 'attachment');
     $token = fep_create_nonce('download');
     if ($attachment) {
         echo "<hr /><strong>" . __("Attachment", 'fep') . ":</strong><br />";
         foreach ($attachment as $meta) {
             $unserialized_file = maybe_unserialize($meta->field_value);
             if ($unserialized_file['type'] && $unserialized_file['url'] && $unserialized_file['file']) {
                 $attachment_id = $meta->meta_id;
                 echo "<a href='" . fep_action_url("download&amp;id={$attachment_id}&amp;token={$token}") . "' title='Download " . basename($unserialized_file['url']) . "'>" . basename($unserialized_file['url']) . "</a><br />";
             }
         }
     }
 }
 function delete_url($del_url, $id)
 {
     if (current_user_can('manage_options')) {
         $token = fep_create_nonce('delete_message_admin');
         $del_url = fep_action_url("deletemessageadmin&id={$id}&token={$token}");
     }
     return $del_url;
 }
Example #9
0
 function view_message()
 {
     global $wpdb, $user_ID;
     $pID = absint($_GET['id']);
     $order = isset($_GET['order']) && strtoupper($_GET['order']) == 'DESC' ? 'DESC' : 'ASC';
     if ('ASC' == $order) {
         $anti_order = 'DESC';
     } else {
         $anti_order = 'ASC';
     }
     if (!$pID) {
         return "<div id='fep-error'>" . __("You do not have permission to view this message!", 'fep') . "</div>";
     }
     $wholeThread = $this->getWholeThread($pID, $order);
     $threadOut = "<p><strong>" . __("Message Thread", 'fep') . ":</strong></p>";
     ob_start();
     do_action('fep_display_in_message_header', $pID, $wholeThread);
     $threadOut .= ob_get_contents();
     ob_end_clean();
     $threadOut .= "\r\n      <table><tr><th width='15%'>" . __("Sender", 'fep') . "</th><th width='85%'>" . __("Message", 'fep') . "</th></tr>";
     foreach ($wholeThread as $post) {
         //Check for privacy errors first
         if ($post->to_user != $user_ID && $post->from_user != $user_ID && !current_user_can('manage_options')) {
             return "<div id='fep-error'>" . __("You do not have permission to view this message!", 'fep') . "</div>";
         }
         //setup info for the reply form
         if ($post->parent_id == 0) {
             $to = $post->from_user;
             if ($to == $user_ID) {
                 //Make sure user doesn't send a message to himself
                 $to = $post->to_user;
             }
             $message_title = $post->message_title;
             if (substr_count($message_title, __("Re:", 'fep')) < 1) {
                 //Prevent all the Re:'s from happening
                 $re = __("Re:", 'fep');
             } else {
                 $re = "";
             }
         }
         $threadOut .= "<tr><td><a href='" . fep_action_url() . "between&with=" . fep_get_userdata($post->from_user, 'user_login', 'id') . "'>" . fep_get_userdata($post->from_user, 'display_name', 'id') . "</a><br/><small><a href='" . fep_action_url() . "viewmessage&id={$pID}&order={$anti_order}'>" . fep_format_date($post->send_date) . "</a></small><br/>" . get_avatar($post->from_user, 60) . "</td>";
         if ($post->parent_id == 0) {
             $threadOut .= "<td class='fep-pmtext'><strong>" . __("Subject", 'fep') . ": </strong>" . fep_output_filter($post->message_title, true) . "<hr/>" . fep_output_filter($post->message_contents) . "";
             ob_start();
             do_action('fep_display_after_parent_message', $post->id);
             $threadOut .= ob_get_contents();
             ob_end_clean();
             $threadOut .= "</td></tr>";
             if ($post->status == 0 && $user_ID != $post->last_sender && ($user_ID == $post->from_user || $user_ID == $post->to_user)) {
                 //Update only if the reader is not last sender
                 $wpdb->update(FEP_MESSAGES_TABLE, array('status' => 1), array('id' => $post->id), array('%d'), array('%d'));
             }
         } else {
             $threadOut .= "<td class='fep-pmtext'>" . fep_output_filter($post->message_contents) . "";
             ob_start();
             do_action('fep_display_after_reply_message', $post->id);
             $threadOut .= ob_get_contents();
             ob_end_clean();
             $threadOut .= "</td></tr>";
         }
     }
     $threadOut .= "</table>";
     //SHOW THE REPLY FORM
     if (fep_is_user_blocked()) {
         $threadOut .= "<div id='fep-error'>" . __("You cannot send messages because you are blocked by administrator!", 'fep') . "</div>";
     } else {
         $reply_args = array('message_to' => fep_get_userdata($to, 'user_login', 'id'), 'message_top' => fep_get_userdata($to, 'display_name', 'id'), 'message_title' => $re . $message_title, 'message_from' => $user_ID, 'parent_id' => $pID);
         $threadOut .= fep_reply_form($reply_args);
     }
     return $threadOut;
 }
Example #10
0
function fep_delete_message_link($pID, $wholeThread)
{
    $token = fep_create_nonce('delete_message');
    $del_url = fep_action_url("deletemessage&id={$pID}&token={$token}");
    echo "<p><a href='" . apply_filters('fep_delete_message_url', $del_url, $pID) . "' onclick='return confirm(\"" . __('Are you sure?', 'fep') . "\");'>" . __("Delete", 'fep') . "</a></p>";
}