| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
//Main CLASS |
| 8 |
if (!class_exists("fep_main_class")) |
| 9 |
{ |
| 10 |
class fep_main_class |
| 11 |
{ |
| 12 |
|
| 13 |
private static $instance; |
| 14 |
|
| 15 |
public static function init() |
| 16 |
{ |
| 17 |
if(!self::$instance instanceof self) { |
| 18 |
self::$instance = new self; |
| 19 |
} |
| 20 |
return self::$instance; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
/******************************************MAIN DISPLAY BEGIN******************************************/ |
| 26 |
|
| 27 |
//Display the proper contents |
| 28 |
function main_shortcode_output( $atts, $content = null ) |
| 29 |
{ |
| 30 |
global $user_ID; |
| 31 |
if ($user_ID) |
| 32 |
{ |
| 33 |
|
| 34 |
if ( ! fep_current_user_can('access_message') ){ |
| 35 |
|
| 36 |
return apply_filters('fep_main_shortcode_output', '<div class="fep-error">'.__("You do not have permission to access message system", 'front-end-pm').'</div>' ); |
| 37 |
} |
| 38 |
|
| 39 |
$atts = shortcode_atts( array( |
| 40 |
'fepaction' => 'messagebox', |
| 41 |
'fep-filter' => 'show-all', |
| 42 |
), $atts, 'front-end-pm' ); |
| 43 |
|
| 44 |
if( empty($_GET['fepaction'] ) ) |
| 45 |
$_GET['fepaction'] = $atts['fepaction']; |
| 46 |
|
| 47 |
if( $_GET['fepaction'] == $atts['fepaction'] && empty($_GET['fep-filter'] ) ) |
| 48 |
$_GET['fep-filter'] = $atts['fep-filter']; |
| 49 |
|
| 50 |
//Add header |
| 51 |
$out = $this->Header(); |
| 52 |
|
| 53 |
//Add Menu |
| 54 |
$out .= $this->Menu(); |
| 55 |
$menu = Fep_Menu::init()->get_menu(); |
| 56 |
|
| 57 |
//Start the guts of the display |
| 58 |
$switch = ( isset($_GET['fepaction'] ) && $_GET['fepaction'] ) ? $_GET['fepaction'] : 'messagebox'; |
| 59 |
|
| 60 |
switch ($switch) |
| 61 |
{ |
| 62 |
case has_action("fep_switch_{$switch}"): |
| 63 |
ob_start(); |
| 64 |
do_action("fep_switch_{$switch}"); |
| 65 |
$out .= ob_get_contents(); |
| 66 |
ob_end_clean(); |
| 67 |
break; |
| 68 |
case has_filter("fep_filter_switch_{$switch}"): |
| 69 |
$out .= apply_filters( "fep_filter_switch_{$switch}", ''); |
| 70 |
break; |
| 71 |
case ( 'newmessage' == $switch && ! empty( $menu['newmessage'] ) ): |
| 72 |
$out .= $this->new_message(); |
| 73 |
break; |
| 74 |
case 'viewmessage': |
| 75 |
$out .= $this->view_message(); |
| 76 |
break; |
| 77 |
/* |
| 78 |
// See Fep_User_Settings Class |
| 79 |
case ( 'settings' == $switch && ! empty( $menu['settings'] ) ): |
| 80 |
$out .= $this->user_settings(); |
| 81 |
break; |
| 82 |
*/ |
| 83 |
/* |
| 84 |
// See Fep_Announcement Class |
| 85 |
case 'announcements': |
| 86 |
$out .= Fep_Announcement::init()->announcement_box(); |
| 87 |
break; |
| 88 |
case 'view_announcement': |
| 89 |
$out .= Fep_Announcement::init()->view_announcement(); |
| 90 |
break; |
| 91 |
*/ |
| 92 |
//case 'directory': // See Fep_Directory Class |
| 93 |
//$out .= $this->directory(); |
| 94 |
// break; |
| 95 |
case 'messagebox': |
| 96 |
default: //Message box is shown by Default |
| 97 |
$out .= $this->fep_message_box(); |
| 98 |
break; |
| 99 |
} |
| 100 |
|
| 101 |
//Add footer |
| 102 |
$out .= $this->Footer(); |
| 103 |
} |
| 104 |
else |
| 105 |
{ |
| 106 |
$out = "<div class='fep-error'>".sprintf(__("You must <a href='%s'>login</a> to view your message.", 'front-end-pm'), wp_login_url( get_permalink() ) )."</div>"; |
| 107 |
} |
| 108 |
return apply_filters('fep_main_shortcode_output', $out); |
| 109 |
} |
| 110 |
|
| 111 |
function Posted() |
| 112 |
{ |
| 113 |
_deprecated_function( __FUNCTION__, '4.9', 'fep_form_posted()' ); |
| 114 |
|
| 115 |
$action = !empty($_POST['fep_action']) ? $_POST['fep_action'] : ''; |
| 116 |
|
| 117 |
if( ! $action ) |
| 118 |
return; |
| 119 |
|
| 120 |
switch( $action ) { |
| 121 |
case has_action("fep_posted_action_{$action}"): |
| 122 |
do_action("fep_posted_action_{$action}", $this ); |
| 123 |
break; |
| 124 |
case 'newmessage' : |
| 125 |
if ( ! fep_current_user_can( 'send_new_message') ) |
| 126 |
return; |
| 127 |
|
| 128 |
Fep_Form::init()->validate_form_field(); |
| 129 |
if( count( fep_errors()->get_error_messages()) == 0 ){ |
| 130 |
if( $message_id = fep_send_message() ) { |
| 131 |
$message = get_post( $message_id ); |
| 132 |
|
| 133 |
if( 'publish' == $message->post_status ) { |
| 134 |
fep_success()->add( 'publish', __("Message successfully sent.", 'front-end-pm') ); |
| 135 |
} else { |
| 136 |
fep_success()->add( 'pending', __("Message successfully sent and waiting for admin moderation.", 'front-end-pm') ); |
| 137 |
} |
| 138 |
} else { |
| 139 |
fep_errors()->add( 'undefined', __("Something wrong. Please try again.", 'front-end-pm') ); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
break; |
| 144 |
case 'reply' : |
| 145 |
|
| 146 |
if( isset( $_GET['fep_id'] ) ){ |
| 147 |
$pID = absint( $_GET['fep_id'] ); |
| 148 |
} else { |
| 149 |
$pID = !empty($_GET['id']) ? absint($_GET['id']) : 0; |
| 150 |
} |
| 151 |
$parent_id = fep_get_parent_id( $pID ); |
| 152 |
|
| 153 |
if ( ! fep_current_user_can( 'send_reply', $parent_id ) ) |
| 154 |
return; |
| 155 |
|
| 156 |
Fep_Form::init()->validate_form_field( 'reply' ); |
| 157 |
if( count( fep_errors()->get_error_messages()) == 0 ){ |
| 158 |
if( $message_id = fep_send_message() ) { |
| 159 |
$message = get_post( $message_id ); |
| 160 |
|
| 161 |
if( 'publish' == $message->post_status ) { |
| 162 |
fep_success()->add( 'publish', __("Message successfully sent.", 'front-end-pm') ); |
| 163 |
} else { |
| 164 |
fep_success()->add( 'pending', __("Message successfully sent and waiting for admin moderation.", 'front-end-pm') ); |
| 165 |
} |
| 166 |
} else { |
| 167 |
fep_errors()->add( 'undefined', __("Something wrong. Please try again.", 'front-end-pm') ); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
break; |
| 172 |
case 'bulk_action' : |
| 173 |
$posted_bulk_action = ! empty($_POST['fep-bulk-action']) ? $_POST['fep-bulk-action'] : ''; |
| 174 |
if( ! $posted_bulk_action ) |
| 175 |
return; |
| 176 |
|
| 177 |
$token = ! empty($_POST['token']) ? $_POST['token'] : ''; |
| 178 |
|
| 179 |
if ( ! fep_verify_nonce( $token, 'bulk_action') ) { |
| 180 |
fep_errors()->add( 'token', __("Invalid Token. Please try again!", 'front-end-pm') ); |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
if( $bulk_action_return = Fep_Message::init()->bulk_action( $posted_bulk_action ) ) { |
| 185 |
fep_success()->add( 'success', $bulk_action_return ); |
| 186 |
} |
| 187 |
break; |
| 188 |
case 'announcement_bulk_action' : |
| 189 |
$posted_bulk_action = ! empty($_POST['fep-bulk-action']) ? $_POST['fep-bulk-action'] : ''; |
| 190 |
if( ! $posted_bulk_action ) |
| 191 |
return; |
| 192 |
|
| 193 |
$token = ! empty($_POST['token']) ? $_POST['token'] : ''; |
| 194 |
|
| 195 |
if ( ! fep_verify_nonce( $token, 'announcement_bulk_action') ) { |
| 196 |
fep_errors()->add( 'token', __("Invalid Token. Please try again!", 'front-end-pm') ); |
| 197 |
return; |
| 198 |
} |
| 199 |
|
| 200 |
if( $bulk_action_return = Fep_Announcement::init()->bulk_action( $posted_bulk_action ) ) { |
| 201 |
fep_success()->add( 'success', $bulk_action_return ); |
| 202 |
} |
| 203 |
break; |
| 204 |
case 'settings' : |
| 205 |
|
| 206 |
add_action ('fep_action_form_validated', array($this, 'settings_save'), 10, 2); |
| 207 |
|
| 208 |
Fep_Form::init()->validate_form_field( 'settings' ); |
| 209 |
|
| 210 |
if( count( fep_errors()->get_error_messages()) == 0 ){ |
| 211 |
fep_success()->add( 'saved', __("Settings successfully saved.", 'front-end-pm') ); |
| 212 |
} |
| 213 |
|
| 214 |
break; |
| 215 |
default: |
| 216 |
do_action("fep_posted_action", $this ); |
| 217 |
break; |
| 218 |
|
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
function settings_save( $where, $fields ) |
| 223 |
{ |
| 224 |
_deprecated_function( __FUNCTION__, '4.9', 'fep_user_settings_save()' ); |
| 225 |
|
| 226 |
if( 'settings' != $where ) |
| 227 |
return; |
| 228 |
|
| 229 |
if( !$fields || ! is_array( $fields ) ) |
| 230 |
return; |
| 231 |
|
| 232 |
$settings = array(); |
| 233 |
|
| 234 |
foreach( $fields as $field ) { |
| 235 |
$settings[$field['name']] = $field['posted-value']; |
| 236 |
} |
| 237 |
$settings = apply_filters('fep_filter_user_settings_before_save', $settings ); |
| 238 |
|
| 239 |
update_user_option( get_current_user_id(), 'FEP_user_options', $settings); |
| 240 |
} |
| 241 |
|
| 242 |
function Header() |
| 243 |
{ |
| 244 |
global $user_ID; |
| 245 |
|
| 246 |
$total_count = fep_get_user_message_count( 'total' ); |
| 247 |
$unread_count = fep_get_user_message_count( 'unread' ); |
| 248 |
$unread_ann_count = fep_get_user_announcement_count( 'unread' ); |
| 249 |
$max_total = fep_get_current_user_max_message_number(); |
| 250 |
$max_text = $max_total ? number_format_i18n($max_total) : __('unlimited', 'front-end-pm' ); |
| 251 |
|
| 252 |
$template = fep_locate_template( 'header.php'); |
| 253 |
|
| 254 |
ob_start(); |
| 255 |
include( $template ); |
| 256 |
return ob_get_clean(); |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
function Menu() |
| 261 |
{ |
| 262 |
$template = fep_locate_template( 'menu.php'); |
| 263 |
|
| 264 |
ob_start(); |
| 265 |
include( $template ); |
| 266 |
return ob_get_clean(); |
| 267 |
} |
| 268 |
|
| 269 |
function Footer() |
| 270 |
{ |
| 271 |
|
| 272 |
$template = fep_locate_template( 'footer.php'); |
| 273 |
|
| 274 |
ob_start(); |
| 275 |
include( $template ); |
| 276 |
return ob_get_clean(); |
| 277 |
} |
| 278 |
|
| 279 |
function fep_message_box($action = '', $total_message = false, $messages = false ) |
| 280 |
{ |
| 281 |
|
| 282 |
if ( !$action ){ |
| 283 |
$action = ( ! empty( $_GET['fepaction']) ) ? $_GET['fepaction']: 'messagebox'; |
| 284 |
} |
| 285 |
|
| 286 |
$g_filter = ! empty( $_GET['fep-filter'] ) ? $_GET['fep-filter'] : ''; |
| 287 |
|
| 288 |
if( false === $total_message ) { |
| 289 |
//$total_message = fep_get_user_message_count('total'); |
| 290 |
} |
| 291 |
|
| 292 |
if( false === $messages ){ |
| 293 |
$messages = Fep_Message::init()->user_messages( $action ); |
| 294 |
$total_message = Fep_Message::init()->found_messages; |
| 295 |
} |
| 296 |
|
| 297 |
$template = fep_locate_template( 'messagebox.php'); |
| 298 |
|
| 299 |
ob_start(); |
| 300 |
include( $template ); |
| 301 |
|
| 302 |
return apply_filters('fep_messagebox', ob_get_clean(), $action); |
| 303 |
} |
| 304 |
|
| 305 |
function user_settings() |
| 306 |
{ |
| 307 |
|
| 308 |
$template = fep_locate_template( 'settings.php'); |
| 309 |
|
| 310 |
ob_start(); |
| 311 |
include( $template ); |
| 312 |
return ob_get_clean(); |
| 313 |
|
| 314 |
} |
| 315 |
|
| 316 |
function new_message(){ |
| 317 |
|
| 318 |
$template = fep_locate_template( 'newmessage_form.php'); |
| 319 |
|
| 320 |
ob_start(); |
| 321 |
include( $template ); |
| 322 |
return ob_get_clean(); |
| 323 |
} |
| 324 |
|
| 325 |
function view_message() |
| 326 |
{ |
| 327 |
global $wpdb, $user_ID, $post; |
| 328 |
|
| 329 |
if( isset( $_GET['fep_id'] ) ){ |
| 330 |
$id = absint( $_GET['fep_id'] ); |
| 331 |
} else { |
| 332 |
$id = !empty($_GET['id']) ? absint($_GET['id']) : 0; |
| 333 |
} |
| 334 |
|
| 335 |
if ( ! $id || ! fep_current_user_can( 'view_message', $id ) ) { |
| 336 |
return "<div class='fep-error'>".__("You do not have permission to view this message!", 'front-end-pm')."</div>"; |
| 337 |
} |
| 338 |
|
| 339 |
$parent_id = fep_get_parent_id( $id ); |
| 340 |
|
| 341 |
$messages = fep_get_message_with_replies( $id ); |
| 342 |
|
| 343 |
$template = fep_locate_template( 'viewmessage.php'); |
| 344 |
|
| 345 |
ob_start(); |
| 346 |
include( $template ); |
| 347 |
return ob_get_clean(); |
| 348 |
|
| 349 |
} |
| 350 |
|
| 351 |
/******************************************MAIN DISPLAY END******************************************/ |
| 352 |
|
| 353 |
} //END CLASS |
| 354 |
} //ENDIF |
| 355 |
|
| 356 |
|
| 357 |
|