| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 6 |
//Main CLASS |
| 7 |
if ( ! class_exists( 'fep_main_class' ) ) { |
| 8 |
class fep_main_class { |
| 9 |
private static $instance; |
| 10 |
|
| 11 |
public static function init() { |
| 12 |
if ( ! self::$instance instanceof self ) { |
| 13 |
self::$instance = new self; |
| 14 |
} |
| 15 |
return self::$instance; |
| 16 |
} |
| 17 |
|
| 18 |
/******************************************MAIN DISPLAY BEGIN******************************************/ |
| 19 |
//Display the proper contents |
| 20 |
function main_shortcode_output( $atts, $content = null ) { |
| 21 |
global $user_ID; |
| 22 |
if ( is_user_logged_in() ) { |
| 23 |
if ( ! fep_current_user_can( 'access_message' ) ) { |
| 24 |
return apply_filters( 'fep_main_shortcode_output', '<div class="fep-error">' . __( 'You do not have permission to access message system', 'front-end-pm' ) . '</div>' ); |
| 25 |
} |
| 26 |
$atts = shortcode_atts( array( |
| 27 |
'fepaction' => 'messagebox', |
| 28 |
'fep-filter' => 'show-all', |
| 29 |
), $atts, 'front-end-pm' ); |
| 30 |
if ( empty( $_GET['fepaction'] ) ) { |
| 31 |
$_GET['fepaction'] = $atts['fepaction']; |
| 32 |
} |
| 33 |
if ( $_GET['fepaction'] == $atts['fepaction'] && empty( $_GET['fep-filter'] ) ) { |
| 34 |
$_GET['fep-filter'] = $atts['fep-filter']; |
| 35 |
} |
| 36 |
|
| 37 |
//Add header |
| 38 |
$out = $this->Header(); |
| 39 |
|
| 40 |
//Add Menu |
| 41 |
$out .= $this->Menu(); |
| 42 |
$menu = Fep_Menu::init()->get_menu(); |
| 43 |
|
| 44 |
//Start the guts of the display |
| 45 |
$switch = ( isset( $_GET['fepaction'] ) && $_GET['fepaction'] ) ? $_GET['fepaction'] : 'messagebox'; |
| 46 |
switch ( $switch ) { |
| 47 |
case has_action( "fep_switch_{$switch}" ): |
| 48 |
ob_start(); |
| 49 |
do_action( "fep_switch_{$switch}" ); |
| 50 |
$out .= ob_get_contents(); |
| 51 |
ob_end_clean(); |
| 52 |
break; |
| 53 |
case has_filter( "fep_filter_switch_{$switch}" ): |
| 54 |
$out .= apply_filters( "fep_filter_switch_{$switch}", '' ); |
| 55 |
break; |
| 56 |
case ( 'newmessage' == $switch && ! empty( $menu['newmessage'] ) ): |
| 57 |
$out .= $this->new_message(); |
| 58 |
break; |
| 59 |
case 'viewmessage': |
| 60 |
$out .= $this->view_message(); |
| 61 |
break; |
| 62 |
case 'messagebox': |
| 63 |
default: //Message box is shown by Default |
| 64 |
$out .= $this->fep_message_box(); |
| 65 |
break; |
| 66 |
} |
| 67 |
|
| 68 |
//Add footer |
| 69 |
$out .= $this->Footer(); |
| 70 |
} else { |
| 71 |
$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>'; |
| 72 |
} |
| 73 |
return apply_filters( 'fep_main_shortcode_output', $out); |
| 74 |
} |
| 75 |
|
| 76 |
function Header() { |
| 77 |
global $user_ID; |
| 78 |
$total_count = fep_get_user_message_count( 'total' ); |
| 79 |
$unread_count = fep_get_user_message_count( 'unread' ); |
| 80 |
$unread_ann_count = fep_get_user_announcement_count( 'unread' ); |
| 81 |
$max_total = fep_get_current_user_max_message_number(); |
| 82 |
$max_text = $max_total ? number_format_i18n( $max_total) : __( 'unlimited', 'front-end-pm' ); |
| 83 |
$template = fep_locate_template( 'header.php' ); |
| 84 |
ob_start(); |
| 85 |
include( $template ); |
| 86 |
return ob_get_clean(); |
| 87 |
} |
| 88 |
|
| 89 |
function Menu() { |
| 90 |
$template = fep_locate_template( 'menu.php' ); |
| 91 |
ob_start(); |
| 92 |
include( $template ); |
| 93 |
return ob_get_clean(); |
| 94 |
} |
| 95 |
|
| 96 |
function Footer() { |
| 97 |
$template = fep_locate_template( 'footer.php' ); |
| 98 |
ob_start(); |
| 99 |
include( $template ); |
| 100 |
return ob_get_clean(); |
| 101 |
} |
| 102 |
|
| 103 |
function fep_message_box() { |
| 104 |
$box_content = Fep_Messages::init()->user_messages(); |
| 105 |
$template = fep_locate_template( 'box-message.php' ); |
| 106 |
ob_start(); |
| 107 |
include( $template ); |
| 108 |
return apply_filters( 'fep_messagebox', ob_get_clean() ); |
| 109 |
} |
| 110 |
|
| 111 |
function new_message() { |
| 112 |
$template = fep_locate_template( 'form-message.php' ); |
| 113 |
ob_start(); |
| 114 |
include( $template ); |
| 115 |
return ob_get_clean(); |
| 116 |
} |
| 117 |
|
| 118 |
function view_message() { |
| 119 |
|
| 120 |
if ( isset( $_GET['fep_id'] ) ) { |
| 121 |
$id = absint( $_GET['fep_id'] ); |
| 122 |
} else { |
| 123 |
$id = ! empty( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; |
| 124 |
} |
| 125 |
if ( ! $id || ! is_numeric( $id )) { |
| 126 |
return '<div class="fep-error">' . __( 'You do not have permission to view this message!', 'front-end-pm' ) . '</div>'; |
| 127 |
} |
| 128 |
$messages = Fep_Messages::init()->get_message_with_replies( $id ); |
| 129 |
|
| 130 |
if ( ! fep_current_user_can( 'view_message', $id ) ) { |
| 131 |
return '<div class="fep-error">' . __( 'You do not have permission to view this message!', 'front-end-pm' ) . '</div>'; |
| 132 |
} |
| 133 |
$parent_id = fep_get_parent_id( $id ); |
| 134 |
$template = fep_locate_template( 'view-message.php' ); |
| 135 |
|
| 136 |
ob_start(); |
| 137 |
include( $template ); |
| 138 |
$return = ob_get_clean(); |
| 139 |
|
| 140 |
return apply_filters( 'fep_filter_viewmessage', $return, $id ); |
| 141 |
} |
| 142 |
/******************************************MAIN DISPLAY END******************************************/ |
| 143 |
} //END CLASS |
| 144 |
} //ENDIF |
| 145 |
|