setupLinks();
$this->adminOps = $this->getAdminOps();
}
function fepActivate()
{
global $wpdb;
$charset_collate = '';
if( $wpdb->has_cap('collation'))
{
if(!empty($wpdb->charset))
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if(!empty($wpdb->collate))
$charset_collate .= " COLLATE $wpdb->collate";
}
$installed_ver = get_option( "fep_db_version" );
$fep_db_version = 1.1;
if( $installed_ver != $fep_db_version ) {
$sqlMsgs = "CREATE TABLE ".$this->fepTable."(
`id` int(11) NOT NULL auto_increment,
`parent_id` int(11) NOT NULL default '0',
`from_user` int(11) NOT NULL default '0',
`to_user` int(11) NOT NULL default '0',
`last_sender` int(11) NOT NULL default '0',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`last_date` datetime NOT NULL default '0000-00-00 00:00:00',
`message_title` varchar(65) NOT NULL,
`message_contents` longtext NOT NULL,
`message_read` int(11) NOT NULL default '0',
`to_del` int(11) NOT NULL default '0',
`from_del` int(11) NOT NULL default '0',
PRIMARY KEY (`id`))
{$charset_collate};";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sqlMsgs);
update_option( "fep_db_version", $fep_db_version );
}
}
function translation()
{
//SETUP TEXT DOMAIN FOR TRANSLATIONS
$plugin_dir = basename(dirname(__FILE__));
load_plugin_textdomain('fep', false, $plugin_dir.'/languages/');
}
function widget($args)
{
global $user_ID;
$uData = get_userdata($user_ID);
$this->setPageURLs();
echo $args['before_widget'];
if (!$uData)
echo __("Login to view your messages", "fep");
else
{
$numNew = $this->getNewMsgs_btn();
$numAnn = $this->getAnnouncementsNum_btn();
$numNewadm = $this->getNewMsgs_admin();
echo "".__("Inbox", "fep")."".$numNew."
".__("Announcement", "fep")."".$numAnn."";
if (current_user_can('manage_options'))
echo "".__("Other's Message", "fep")."".$numNewadm."";
}
echo $args['after_widget'];
}
function widget_text($args)
{
global $user_ID;
$uData = get_userdata($user_ID);
$this->setPageURLs();
echo $args['before_widget'];
echo $args['before_title'].__("Messages", "fep").$args['after_title'];
if (!$uData)
echo __("Login to view your messages", "fep");
else
{
$numNew = $this->getNewMsgs();
$numAnn = $this->getAnnouncementsNum();
$numNewadm = $this->getNewMsgs_admin();
echo __("Hi", "fep")." ".$uData->display_name.",
".
__("You have", "fep")." (".$numNew.") ".__("new message(s)", "fep")."
".
__("There are", "fep")." (".$numAnn.") ".__("announcement(s)", "fep")."
";
if (current_user_can('manage_options'))
echo "".__("Other's Message(s)", "fep")."".$numNewadm."
";
echo "".__("View Message Box", "fep")."
";
}
echo $args['after_widget'];
}
//Setup some variables
var $adminOpsName = "FEP_options";
var $adminOps = array();
var $userOpsName = "FEP_uOptions";
var $userOps = array();
var $error = "";
var $success = "";
var $pluginDir = "";
var $pluginURL = "";
var $styleDir = "";
var $styleURL = "";
var $pageURL = "";
var $actionURL = "";
var $jsURL = "";
var $fepTable = "";
function jsInit()
{
if (isset($_GET['fepjscript']))
if($_GET['fepjscript'] == '1')
{
global $wpdb, $user_ID;
require_once('js/search.php');
}
}
function setupLinks() //And DB table name too :)
{
global $wpdb;
$this->pluginDir = plugin_dir_path( __FILE__ )."/";
$this->pluginURL = plugins_url()."/front-end-pm/";
$this->styleDir = $this->pluginDir."style/";
$this->styleURL = $this->pluginURL."style/";
$this->jsURL = $this->pluginURL."js/";
$this->fepTable = $wpdb->prefix."fep_messages";
}
function fep_enqueue_scripts()
{
wp_enqueue_style( 'fep-style', $this->styleURL . 'style.css' );
wp_enqueue_script( 'fep-script', $this->jsURL . 'script.js', array(), '1.0.0', true );
}
function getPageID()
{
global $wpdb;
return $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%[front-end-pm]%' AND post_status = 'publish' AND post_type = 'page' LIMIT 1");
}
function setPageURLs()
{
global $wp_rewrite;
if($wp_rewrite->using_permalinks())
$delim = "?";
else
$delim = "&";
$this->pageURL = get_permalink($this->getPageID());
$this->actionURL = $this->pageURL.$delim."fepaction=";
}
/******************************************SETUP END******************************************/
/******************************************ADMIN SETTINGS PAGE BEGIN******************************************/
function addAdminPage()
{
add_menu_page('Front End PM', 'Front End PM', 'manage_options', 'fep-admin-settings', array(&$this, "dispAdminPage"),plugins_url( 'front-end-pm/images/msgBox.gif' ));
add_submenu_page('fep-admin-settings', 'Front End PM - ' .__('Settings','cp'), __('Settings','cp'), 'manage_options', 'fep-admin-settings', array(&$this, "dispAdminPage"));
add_submenu_page('fep-admin-settings', 'Front End PM - ' .__('Instruction','cp'), __('Instruction','cp'), 'manage_options', 'fep-instruction', array(&$this, "dispInstructionPage"));
}
function dispAdminPage()
{
if ($this->pmAdminSave())
echo "
".__("Options successfully saved", "fep")."
[front-end-pm]".__("Please enter a valid email address!", "fep")."
".__("First four fields support only positive numbers!", "fep")."
"; return $form; } function fep_createPage_action(){ if (isset($_POST['fep-create-page'])){ $titlePre = wp_strip_all_tags($_POST['fep-create-page-title']); $title = utf8_encode($titlePre); $slugPre = wp_strip_all_tags($_POST['fep-create-page-slug']); $slug = utf8_encode($slugPre); if ($this->getPageID() !=''){ echo "
" .sprintf(__("Already created page %s for \"Front End PM\". Please use that page instead!", "fep"),get_permalink($this->getPageID()),get_the_title($this->getPageID()))."
" .__("You must enter a valid Title!", "fep")."
" .__("Invalid Token. Please try again!", "fep")."
" .__("Page for \"Front End PM\" successfully created!", "fep")."
" .__("Something wrong.Please try again to create page!", "fep")."
" .sprintf(__("Page %s for \"Front End PM\" successfully created!", "fep"),get_permalink($pageID),get_the_title($pageID))."
".__("Set your preferences below", "fep").":
"; return $prefs; } function pmUserSave() { global $user_ID; if (isset($_POST['fep-user-save'])) { $saveUserOps = array( 'allow_emails' => $_POST['allow_emails'], 'allow_messages' => $_POST['allow_messages'], 'allow_ann' => $_POST['allow_ann'] ); update_user_meta($user_ID, $this->userOpsName, $saveUserOps); return true; } return false; } function getUserOps($ID) { $pmUserOps = array( 'allow_emails' => 'true', 'allow_messages' => 'true', 'allow_ann' => 'true' ); //Get old values if they exist $userOps = get_user_meta($ID, $this->userOpsName, true); if (!empty($userOps)) { foreach ($userOps as $key => $option) $pmUserOps[$key] = $option; } update_user_meta($ID, $this->userOpsName, $pmUserOps); return $pmUserOps; } /******************************************USER SETTINGS PAGE END******************************************/ /******************************************NEW MESSAGE PAGE BEGIN******************************************/ function dispNewMsg() { global $user_ID; $token = $this->getToken(); $adminOps = $this->getAdminOps(); if (isset($_GET['to'])){ $to = $_GET['to']; }else{ $to = '';} if (!$this->have_permission()) { $this->error = __("You cannot send messages because you are blocked by administrator!", "fep"); return; } if ($this->adminOps['disable_new'] == 'on' && !current_user_can('manage_options')) { $this->error = __("Send new message is disabled for users!", "fep"); return; } if (!$this->isBoxFull($user_ID, $adminOps['num_messages'], '1')) { $message_to = ( isset( $_REQUEST['message_to'] ) ) ? $_REQUEST['message_to']: ''; $message_top = ( isset( $_REQUEST['message_top'] ) ) ? $_REQUEST['message_top']: ''; $message_title = ( isset( $_REQUEST['message_title'] ) ) ? $_REQUEST['message_title']: ''; $message_content = ( isset( $_REQUEST['message_content'] ) ) ? $_REQUEST['message_content']: ''; $newMsg = "".__("Create New Message", "fep").":
"; $newMsg .= ""; return $newMsg; } else { $this->error = __("You cannot send messages because your message box is full! Please delete some messages.", "fep"); return; } } /******************************************NEW MESSAGE PAGE END******************************************/ /******************************************READ MESSAGE PAGE BEGIN******************************************/ function dispReadMsg() { global $wpdb, $user_ID; $pID = $_GET['id']; $wholeThread = $this->getWholeThread($pID); $token = $this->getToken(); $threadOut = "".__("Message Thread", "fep").":
| ".__("Sender", "fep")." | ".__("Message", "fep")." |
|---|---|
| ".$uData->display_name." ".$this->formatDate($post->date)." ".get_avatar($post->from_user, 60)." | ";
if ($post->parent_id == 0) //If it is the parent message
{
$threadOut .= "".__("Subject", "fep").": ".$this->output_filter($post->message_title)." ".apply_filters("comment_text", $this->autoembed($this->output_filter($post->message_contents)))." | ".apply_filters("comment_text", $this->autoembed($this->output_filter($post->message_contents)))." | "; } } $threadOut .= "
".__("Add Reply", "fep").":
"; } else { $this->error = __("You cannot send messages because you are blocked by administrator!", "fep"); } if ($user_ID != $post->from_user) //Update only if the reader is not the sender ??? $wpdb->query($wpdb->prepare("UPDATE {$this->fepTable} SET message_read = 1 WHERE id = %d", $pID)); return $threadOut; } function dispReadMsg_admin() { global $wpdb, $user_ID; $pID = $_GET['id']; $wholeThread = $this->getWholeThread($pID); $token = $this->getToken(); $threadOut = "".__("Message Thread", "fep").":
| ".__("Sender", "fep")." | ".__("Message", "fep")." |
|---|---|
| ".$uData->display_name." ".$this->formatDate($post->date)." ".get_avatar($post->from_user, 60)." | ";
if ($post->parent_id == 0) //If it is the parent message
{
$threadOut .= "".__("Subject", "fep").": ".$this->output_filter($post->message_title)." ".apply_filters("comment_text", $this->autoembed($this->output_filter($post->message_contents)))." | ".apply_filters("comment_text", $this->autoembed($this->output_filter($post->message_contents)))." | "; } } //SHOW THE REPLY FORM $threadOut .= "
".__("Add Reply", "fep").":
"; return $threadOut; } function getWholeThread($id) { global $wpdb; $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$this->fepTable} WHERE id = %d OR parent_id = %d ORDER BY id ASC", $id, $id)); return $results; } function getInfo($id) { global $wpdb; $to = $wpdb->get_var($wpdb->prepare("SELECT to_user FROM {$this->fepTable} WHERE id = %d", $id)); $from = $wpdb->get_var($wpdb->prepare("SELECT from_user FROM {$this->fepTable} WHERE id = %d", $id)); return array ( 'to' => $to , 'from' => $from ); } function convertToUser($to) { $user = get_user_by( 'login' , $to ); $result = $user->user_login; return $result; } function convertToDisplay($to) { $user = get_user_by( 'login' , $to ); $result = $user->display_name; return $result; } /******************************************READ MESSAGE PAGE END******************************************/ /******************************************CHECK MESSAGE PAGE BEGIN******************************************/ function dispCheckMsg() { global $wpdb, $user_ID; $from = $_POST['message_from']; if ($_POST['message_to']) { $preTo = $_POST['message_to']; } else { $preTo = $_POST['message_top']; } $to = $this->convertToID($preTo); $title = $this->input_filter($_POST['message_title']); $content = $this->input_filter($_POST['message_content']); $parentID = $_POST['parent_id']; $date = current_time('mysql'); $adminOps = $this->getAdminOps(); if ($to) $toUserOps = $this->getUserOps($to); //Check for errors first if (!$to || !$title || !$content || ($from != $user_ID)) { if (!$to) $theError = __("You must enter a valid recipient!", "fep"); if (!$title) $theError = __("You must enter a valid subject!", "fep"); if (!$content) $theError = __("You must enter some message content!", "fep"); if ($from != $user_ID) $theError = __("You do not have permission to send this message!", "fep"); $this->error = $theError; return $this->dispNewMsg(); } if ($toUserOps['allow_messages'] != 'true') { $this->error = __("This user does not want to receive messages!", "fep"); return; } if ($this->isBoxFull($to, $adminOps['num_messages'], $parentID)) { $this->error = __("Your or Recipients Message Box Is Full!", "fep"); return; } if (!$this->have_permission()) { $this->error = __("You cannot send messages because you are blocked by administrator!", "fep"); return; } $timeDelay = $this->TimeDelay($adminOps['time_delay']); if ($timeDelay['diffr'] < $adminOps['time_delay'] && !current_user_can('manage_options')) { $this->error = sprintf(__("Please wait at least more %s to send another message!", "fep"),$timeDelay['time']); return; } if ($parentID != 0) { $mgsInfo = $this->getInfo($parentID); if ($mgsInfo['to'] != $user_ID && $mgsInfo['from'] != $user_ID && !current_user_can( 'manage_options' )) { $this->error = __("You do not have permission to send this message!", "fep"); return; } } // Check if a form has been sent $postedToken = filter_input(INPUT_POST, 'token'); if (empty($postedToken)) { $this->error = __("Invalid Token. Please try again!", "fep"); return; } if(!$this->isTokenValid($postedToken)){ // Actually This is not first form submission. First Submission Pass this condition and inserted into db. $this->success = __("Your message was successfully sent!", "fep"); return; } //If no errors then continue on if ($parentID == 0) $wpdb->query($wpdb->prepare("INSERT INTO {$this->fepTable} (from_user, to_user, message_title, message_contents, parent_id, last_sender, date, last_date) VALUES ( %d, %d, %s, %s, %d, %d, %s, %s )", $from, $to, $title, $content, $parentID, $from, $date, $date)); else { $wpdb->query($wpdb->prepare("INSERT INTO {$this->fepTable} (from_user, to_user, message_title, message_contents, parent_id, date) VALUES ( %d, %d, %s, %s, %d, %s)", $from, $to, $title, $content, $parentID, $date)); $wpdb->query($wpdb->prepare("UPDATE {$this->fepTable} SET message_read = 0,last_sender = %d,last_date = %s, to_del = 0, from_del = 0 WHERE id = %d", $from, $date, $parentID)); } $this->success = __("Your message was successfully sent!", "fep"); $this->sendEmail($to, $from, $title); return; } function isBoxFull($to, $boxSize, $parentID) { global $wpdb; $get_messages = $wpdb->get_results($wpdb->prepare("SELECT id FROM {$this->fepTable} WHERE (to_user = %d AND parent_id = 0 AND to_del <> 1) OR (from_user = %d AND parent_id = 0 AND from_del <> 1)", $to, $to)); $num = $wpdb->num_rows; if ($boxSize == 0 || $num < $boxSize || $parentID != 0 || current_user_can('manage_options') || user_can( $to, 'manage_options' )) return false; else return true; } function sendEmail($to, $from, $title) { $toOptions = $this->getUserOps($to); $notify = $toOptions['allow_emails']; if ($notify == 'true') { $sendername = get_bloginfo("name"); $sendermail = get_bloginfo("admin_email"); $uData = get_userdata($from); $sendfrom = $uData->display_name; $headers = "MIME-Version: 1.0\r\n" . "From: ".$sendername." "."<".$sendermail.">\r\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\r\n"; $subject = "" . get_bloginfo("name").": New Message"; $message = "You have received a new message in \r\n"; $message .= get_bloginfo("name")."\r\n"; $message .= "From: ".$sendfrom. "\r\n"; $message .= "Subject: ".$title. "\r\n"; $message .= "Please Click the following link to view full Message. \r\n"; $message .= $this->pageURL."\r\n"; $mUser = get_userdata($to); $mailTo = $mUser->user_email; wp_mail($mailTo, $subject, $message); } } function convertToID($preTo) { global $user_ID; $user = get_user_by( 'login' , $preTo ); $result = $user->ID; if ($result != $user_ID && $result) return $result; else return 0; } /******************************************CHECK MESSAGE PAGE END******************************************/ /******************************************MESSAGE-BOX PAGE BEGIN******************************************/ function dispMsgBox() { global $wpdb, $user_ID; $adminOps = $this->getAdminOps(); $numMsgs = $this->getUserNumMsgs(); if ($numMsgs) { $msgsOut = "".__("Your Messages", "fep").":
"; $numPgs = $numMsgs / $adminOps['messages_page']; if ($numPgs > 1) { $msgsOut .= "".__("Page", "fep").": "; for ($i = 0; $i < $numPgs; $i++) if ($_GET['pmpage'] != $i) $msgsOut .= "".($i+1)." "; else $msgsOut .= "[".($i+1)."] "; $msgsOut .= "
"; } $msgsOut .= "| ".__("Started By", "fep")." | ".__("To", "fep")." | ".__("Subject", "fep")." | ".__("Last Reply By", "fep")." | ".__("Delete", "fep")." | ||
|---|---|---|---|---|---|---|
| " .$uSend->display_name. " ".$this->formatDate($msg->date)." | "; }
else {
$msgsOut .= "" .$uSend->display_name. " ".$this->formatDate($msg->date)." | "; }
if ($toUser->ID != $user_ID){
$msgsOut .= "" .$toUser->display_name. " | ";} else { $msgsOut .= "" .$toUser->display_name. " | ";} $msgsOut .= "".$this->output_filter($msg->message_title)." ".$read." | ";
$msgsOut .= "" .$uLast->display_name. " ".$this->formatDate($msg->last_date)." | ";
$msgsOut .= "".__("Delete", "fep")." |
".__("All Messages", "fep").":
"; $numPgs = $numMsgs / $adminOps['messages_page']; if ($numPgs > 1) { $msgsOut .= "".__("Page", "fep").": "; for ($i = 0; $i < $numPgs; $i++) if ($_GET['apmpage'] != $i) $msgsOut .= "".($i+1)." "; else $msgsOut .= "[".($i+1)."] "; $msgsOut .= "
"; } $msgsOut .= "| ".__("Started By", "fep")." | ".__("To", "fep")." | ".__("Subject", "fep")." | ".__("Last Reply By", "fep")." | ".__("Delete", "fep")." |
|---|---|---|---|---|
| " .$uSend->display_name. " ".$this->formatDate($msg->date)." | ";
$msgsOut .= "" .$toUser->display_name. " | "; $msgsOut .= "".$this->output_filter($msg->message_title)." ".$read." | ";
$msgsOut .= "" .$uLast->display_name. " ".$this->formatDate($msg->last_date)." | ";
$msgsOut .= "".__("Delete", "fep")." |
".__("Announcements", "fep").":
"; if (current_user_can('manage_options')) { $announce .= $this->dispAnnounceForm(); } $this->error = __("There are no announcements!", "fep"); } else { $announce = "".__("Announcements", "fep").":
"; if (current_user_can('manage_options')) { $announce .= $this->dispAnnounceForm(); } $announce .= "| ".__("Subject", "fep").": ".$this->output_filter($announcement->message_title).
" ".__("Date", "fep").": ".$this->formatDate($announcement->date); if (current_user_can('manage_options')) { $announce .= " ".__("Added by", "fep").": ".get_userdata($announcement->from_user)->display_name; $announce .= " ".__("Delete", "fep").""; } $announce .= " "; $announce .= "".__("Message", "fep").": ".apply_filters("comment_text", $this->output_filter($announcement->message_contents))." |
".__("Add a new announcement below", "fep")."
"; return $form; } function getAnnouncements() { global $wpdb; //message_read = 2 indicates that the msg is an announcement :) $results = $wpdb->get_results("SELECT * FROM {$this->fepTable} WHERE message_read = 2 ORDER BY id DESC"); return $results; } function getAnnouncementsNum() { global $wpdb; //message_read = 2 indicates that the msg is an announcement :) $results = $wpdb->get_results("SELECT id FROM {$this->fepTable} WHERE message_read = 2 ORDER BY id DESC"); return $wpdb->num_rows; } function getAnnouncementsNum_btn(){ if ($this->getAnnouncementsNum()){ $newmgs = " ("; $newmgs .= $this->getAnnouncementsNum(); $newmgs .=")"; } else { $newmgs ="";} return $newmgs; } function addAnnouncement() { global $wpdb,$user_ID; $adminOps = $this->getAdminOps(); $title = $this->input_filter($_POST['message_title']); $contents = $this->input_filter($_POST['message_content']); $from = $_POST['message_from']; $date = current_time('mysql'); $read = '2'; if (!$title || !$contents || $from != $user_ID) { if (!$title) $theError = __("You must enter a valid subject!", "fep"); if (!$contents) $theError = __("You must enter some content!", "fep"); if ($from != $user_ID) $theError = __("Please try again!", "fep"); $this->error = $theError; return $this->dispAnnounceForm(); } // Check if a form has been sent $postedToken = filter_input(INPUT_POST, 'token'); if (empty($postedToken)) { $this->error = __("Invalid Token. Please try again!", "fep"); return; } if(!$this->isTokenValid($postedToken)){ // Actually This is not first form submission. First Submission Pass this condition and inserted into db. $this->success = __("The announcement was successfully added!", "fep"); return; } //if nothing wrong continue $wpdb->query($wpdb->prepare("INSERT INTO {$this->fepTable} (from_user, message_title, message_contents, date, message_read) VALUES ( %s, %s, %s, %s, %d )",$from, $title, $contents, $date, $read)); if ($adminOps['notify_ann'] == 'on') { $this->notify_users($title); $this->success = __("The announcement was successfully added and sent email to all users!", "fep"); return; } else { $this->success = __("The announcement was successfully added!", "fep"); return; } } function deleteAnnouncement() { global $wpdb; if (isset($_GET['id'])){$delID = $_GET['id'];} if (isset($_GET['del'])){$delm = $_GET['del'];}else{ $delm = ''; } if (current_user_can('manage_options') && $delm) //Make sure only admins can delete announcements { $wpdb->query($wpdb->prepare("DELETE FROM {$this->fepTable} WHERE id = %d", $delID)); return true; } return false; } //Mass emails when announcement is created function notify_users($title) { $domain_name = preg_replace('/^www\./','',$_SERVER['SERVER_NAME']); $usersarray = get_users("orderby=ID"); $adminOps = $this->getAdminOps(); $to = $adminOps['ann_to']; $from = 'noreply@'.$domain_name; $bcc = array(); foreach ($usersarray as $user) { $toOptions = $this->getUserOps($user->ID); $notify = $toOptions['allow_ann']; if (in_array($notify == 'true',$usersarray)){ $bcc[] = $user->user_email; } } $chunked_bcc = array_chunk($bcc, 25); $subject = "" . get_bloginfo("name").": New Announcement"; $message = "A new Announcement is Published in \r\n"; $message .= get_bloginfo("name")."\r\n"; $message .= "Title: ".$title. "\r\n"; $message .= "Please Click the following link to view full Announcement. \r\n"; $message .= $this->actionURL."viewannouncements \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; } /******************************************VIEW ANNOUNCEMENTS END******************************************/ /******************************************MAIN DISPLAY BEGIN******************************************/ function dispHeader() { global $user_ID, $user_login; $numNew = $this->getNewMsgs(); $numAnn = $this->getAnnouncementsNum(); $msgBoxSize = $this->getUserNumMsgs(); $adminOps = $this->getAdminOps(); if ($adminOps['num_messages'] == 0 || current_user_can('manage_options')) $msgBoxTotal = __("Unlimited", "fep"); else $msgBoxTotal = $adminOps['num_messages']; $header = "".__("Welcome", "fep").": ".$this->convertToDisplay($user_login)."
";
$header .= __("You have", "fep")." (".$numNew.") ".__("new messages", "fep").
" ".__("and", "fep")." (".$numAnn.") ".__("announcement(s)", "fep")."
";
if ($msgBoxTotal == __("Unlimited", "fep") || $msgBoxSize < $msgBoxTotal)
$header .= __("Message box size", "fep").": ".$msgBoxSize." ".__("of", "fep")." ".$msgBoxTotal."
".__("Total Users", "fep").": (".$total.")
"; $numPgs = $total / $adminOps['user_page']; if ($numPgs > 1) { $directory .= "".__("Page", "fep").": "; for ($i = 0; $i < $numPgs; $i++) if ($_GET['upage'] != $i) $directory .= "".($i+1)." "; else $directory .= "[".($i+1)."] "; $directory .= "
"; } $directory .= "| ".__("User", "fep")." | ".__("Send Message", "fep")." |
|---|---|
| ".$u->display_name." | "; $directory .= "".__("Send Message", "fep")." |
".__("You must be logged-in to view your message.", "fep")."
"; } return $out; } /******************************************MAIN DISPLAY END******************************************/ /******************************************MISC. FUNCTIONS BEGIN******************************************/ /** * Creates a token usable in a form * @return string */ function session(){ if(!isset($_SESSION)) { session_start(); } } function getToken(){ $token = sha1(mt_rand()); if(!isset($_SESSION['tokens'])){ $_SESSION['tokens'] = array($token => 1); }else{ $_SESSION['tokens'][$token] = 1; } return $token; } /** * Check if a token is valid. Removes it from the valid tokens list * @param string $token The token * @return bool */ function isTokenValid($token){ if(!empty($_SESSION['tokens'][$token])){ unset($_SESSION['tokens'][$token]); return true; } return false; } //Check is user blocked by admin function have_permission(){ global $current_user; $adminOps = $this->getAdminOps(); $wpusers = (array) explode(',', $adminOps['have_permission']); $valid_wpusers = array(); foreach($wpusers as $wpuser){ $wpuser = trim($wpuser); if($wpuser!=''){ $user = get_user_by('login', $wpuser); if($user){ $valid_wpusers[] = $user->ID; } $valid_wpusers = array_unique($valid_wpusers); if(in_array($current_user->ID, $valid_wpusers)){ return false; } } } return true; } function get_users() { global $wpdb; if (isset($_GET['upage'])){ $page = $_GET['upage']; }else{$page = 0;} $adminOps = $this->getAdminOps(); $start = $page * $adminOps['user_page']; $end = $adminOps['user_page']; $users = $wpdb->get_results($wpdb->prepare("SELECT display_name, user_login, ID FROM $wpdb->users ORDER BY display_name ASC LIMIT %d, %d",$start,$end)); return $users; } function get_form_buttons() { $button = '
';
return $button;
}
function output_filter($string)
{
$parser = new fepBBCParser();
$html = stripslashes($parser->bbc2html($string));
return ent2ncr($html);
}
function input_filter($string)
{
$newStr = esc_attr($string);
return wp_strip_all_tags($newStr);
}
function getUserNumMsgs()
{
global $wpdb, $user_ID;
$get_messages = $wpdb->get_results($wpdb->prepare("SELECT id FROM {$this->fepTable} WHERE (to_user = %d AND parent_id = 0 AND message_read <> 2 AND to_del <> 1) OR (from_user = %d AND parent_id = 0 AND message_read <> 2 AND from_del <> 1)", $user_ID, $user_ID));
$num = $wpdb->num_rows;
return $num;
}
function formatDate($date)
{
$now = current_time('mysql');
//return date('M d, h:i a', strtotime($date));
return human_time_diff(strtotime($date),strtotime($now)).' ago';
}
function TimeDelay($DeTime)
{
global $wpdb, $user_ID;
$now = current_time('mysql');
$Dtime = $DeTime * 60;
$Prev = $wpdb->get_var($wpdb->prepare("SELECT last_date FROM {$this->fepTable} WHERE parent_id = 0 AND last_sender = %d ORDER BY last_date DESC LIMIT 1", $user_ID));
$diff = strtotime($now) - strtotime($Prev);
$diffr = $diff/60;
$next = strtotime($Prev) + $Dtime;
$Ntime = human_time_diff(strtotime($now),$next);
return array('diffr' => $diffr, 'time' => $Ntime);
}
function is_positive($str) {
return (is_numeric($str) && $str > 0 && $str == round($str));
}
function getNewMsgs()
{
global $wpdb, $user_ID;
$get_pms = $wpdb->get_results($wpdb->prepare("SELECT id FROM {$this->fepTable} WHERE (to_user = %d AND parent_id = 0 AND to_del <> 1 AND message_read = 0 AND last_sender <> %d) OR (from_user = %d AND parent_id = 0 AND from_del <> 1 AND message_read = 0 AND last_sender <> %d)", $user_ID, $user_ID, $user_ID, $user_ID));
return $wpdb->num_rows;
}
function getNewMsgs_btn(){
if ($this->getNewMsgs()){
$newmgs = " (";
$newmgs .= $this->getNewMsgs();
$newmgs .=")";
} else {
$newmgs = "";}
return $newmgs;
}
function getNewMsgs_admin()
{
global $wpdb, $user_ID;
$get_pmss = $wpdb->get_results($wpdb->prepare("SELECT id FROM {$this->fepTable} WHERE to_user <> %d AND from_user <> %d AND last_sender <> %d AND message_read = 0 AND parent_id = 0", $user_ID, $user_ID, $user_ID));
if ($wpdb->num_rows){
$newmgs = " (";
$newmgs .= $wpdb->num_rows;
$newmgs .=")";
} else {
$newmgs ="";}
return $newmgs;
}
function autoembed($string)
{
global $wp_embed;
if (is_object($wp_embed))
return $wp_embed->autoembed($string);
else
return $string;
}
function get_version()
{
$plugin_data = implode('', file($this->pluginDir."front-end-pm.php"));
if (preg_match("|Version:(.*)|i", $plugin_data, $version))
$version = $version[1];
return $version;
}
/******************************************MISC. FUNCTIONS END******************************************/
} //END CLASS
} //ENDIF
?>