| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 6 |
function fep_register_metadata_table(){ |
| 7 |
global $wpdb; |
| 8 |
$wpdb->fep_messagemeta = FEP_META_TABLE; |
| 9 |
$wpdb->fep_messages = FEP_MESSAGE_TABLE; |
| 10 |
} |
| 11 |
|
| 12 |
function fep_create_database(){ |
| 13 |
global $wpdb; |
| 14 |
if ( is_multisite() ) { |
| 15 |
$installed_ver = get_site_option( 'fep_db_version' ); |
| 16 |
} else { |
| 17 |
$installed_ver = get_option( 'fep_db_version' ); |
| 18 |
} |
| 19 |
|
| 20 |
if ( version_compare( $installed_ver, '1011', '<' ) && $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', FEP_MESSAGE_TABLE ) ) && $wpdb->get_var( $wpdb->prepare( 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s', DB_NAME, FEP_MESSAGE_TABLE, 'id' ) ) ) { |
| 21 |
if ( ! $wpdb->get_var( 'SELECT COUNT(*) FROM ' . FEP_MESSAGE_TABLE . ' WHERE id IS NOT NULL LIMIT 1' ) ) { |
| 22 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . FEP_MESSAGE_TABLE ); |
| 23 |
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'fep_meta' ); |
| 24 |
} else { |
| 25 |
$wpdb->query( sprintf( 'ALTER TABLE %1$s RENAME %1$s_old', FEP_MESSAGE_TABLE ) ); |
| 26 |
} |
| 27 |
} |
| 28 |
if ( version_compare( $installed_ver, FEP_DB_VERSION, '!=' ) ) { |
| 29 |
$charset_collate = $wpdb->get_charset_collate(); |
| 30 |
|
| 31 |
$sql_message = "CREATE TABLE $wpdb->fep_messages ( |
| 32 |
mgs_id bigint(20) unsigned NOT NULL auto_increment, |
| 33 |
mgs_parent bigint(20) unsigned NOT NULL default '0', |
| 34 |
mgs_author bigint(20) unsigned NOT NULL default '0', |
| 35 |
mgs_created datetime NOT NULL default '0000-00-00 00:00:00', |
| 36 |
mgs_title text NOT NULL, |
| 37 |
mgs_content mediumtext NOT NULL, |
| 38 |
mgs_type varchar(20) NOT NULL DEFAULT 'message', |
| 39 |
mgs_status varchar(20) NOT NULL DEFAULT 'pending', |
| 40 |
mgs_last_reply_by bigint(20) unsigned NOT NULL default '0', |
| 41 |
mgs_last_reply_time datetime NOT NULL default '0000-00-00 00:00:00', |
| 42 |
mgs_last_reply_excerpt varchar(255) NOT NULL DEFAULT '', |
| 43 |
PRIMARY KEY (mgs_id), |
| 44 |
KEY mgs_parent_last_time (mgs_parent,mgs_last_reply_time), |
| 45 |
KEY mgs_type_created (mgs_type,mgs_created) |
| 46 |
) $charset_collate;"; |
| 47 |
|
| 48 |
$sql_perticipiants = "CREATE TABLE " . FEP_PARTICIPANT_TABLE . " ( |
| 49 |
per_id bigint(20) unsigned NOT NULL auto_increment, |
| 50 |
mgs_id bigint(20) unsigned NOT NULL default '0', |
| 51 |
mgs_participant bigint(20) unsigned NOT NULL default '0', |
| 52 |
mgs_read bigint(20) unsigned NOT NULL default '0', |
| 53 |
mgs_parent_read bigint(20) unsigned NOT NULL default '0', |
| 54 |
mgs_deleted bigint(20) unsigned NOT NULL default '0', |
| 55 |
mgs_archived bigint(20) unsigned NOT NULL default '0', |
| 56 |
PRIMARY KEY (per_id), |
| 57 |
UNIQUE KEY mgs_id_participant (mgs_id,mgs_participant) |
| 58 |
) $charset_collate;"; |
| 59 |
|
| 60 |
$sql_meta = "CREATE TABLE $wpdb->fep_messagemeta ( |
| 61 |
meta_id bigint(20) unsigned NOT NULL auto_increment, |
| 62 |
fep_message_id bigint(20) unsigned NOT NULL default '0', |
| 63 |
meta_key varchar(255) default NULL, |
| 64 |
meta_value longtext, |
| 65 |
PRIMARY KEY (meta_id), |
| 66 |
KEY fep_message_id (fep_message_id), |
| 67 |
KEY meta_key (meta_key(191)) |
| 68 |
) $charset_collate;"; |
| 69 |
|
| 70 |
$sql_attachments = "CREATE TABLE " . FEP_ATTACHMENT_TABLE . " ( |
| 71 |
att_id bigint(20) unsigned NOT NULL auto_increment, |
| 72 |
mgs_id bigint(20) unsigned NOT NULL default '0', |
| 73 |
att_mime varchar(100) NOT NULL default '', |
| 74 |
att_file varchar(255) NOT NULL default '', |
| 75 |
att_status varchar(20) NOT NULL default '', |
| 76 |
PRIMARY KEY (att_id), |
| 77 |
KEY mgs_id (mgs_id) |
| 78 |
) $charset_collate;"; |
| 79 |
|
| 80 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 81 |
dbDelta( $sql_message ); |
| 82 |
dbDelta( $sql_perticipiants ); |
| 83 |
dbDelta( $sql_meta ); |
| 84 |
dbDelta( $sql_attachments ); |
| 85 |
|
| 86 |
if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', FEP_MESSAGE_TABLE ) ) ){ |
| 87 |
if ( is_multisite() ) { |
| 88 |
update_site_option( 'fep_db_version', FEP_DB_VERSION ); |
| 89 |
} else { |
| 90 |
update_option( 'fep_db_version', FEP_DB_VERSION, true ); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
function fep_include_require_files() { |
| 97 |
require_once( FEP_PLUGIN_DIR . 'includes/class-fep-cache.php' ); |
| 98 |
require_once( FEP_PLUGIN_DIR . 'includes/class-fep-message.php' ); |
| 99 |
require_once( FEP_PLUGIN_DIR . 'includes/fep-message-meta.php' ); |
| 100 |
require_once( FEP_PLUGIN_DIR . 'includes/class-fep-participants.php' ); |
| 101 |
require_once( FEP_PLUGIN_DIR . 'includes/class-fep-attachments.php' ); |
| 102 |
require_once( FEP_PLUGIN_DIR . 'includes/class-fep-message-query.php' ); |
| 103 |
|
| 104 |
$fep_files = array( |
| 105 |
'announcement' => FEP_PLUGIN_DIR . 'includes/class-fep-announcements.php', |
| 106 |
'attachment' => FEP_PLUGIN_DIR . 'includes/class-fep-attachment.php', |
| 107 |
'directory' => FEP_PLUGIN_DIR . 'includes/class-fep-directory.php', |
| 108 |
'email' => FEP_PLUGIN_DIR . 'includes/class-fep-emails.php', |
| 109 |
'form' => FEP_PLUGIN_DIR . 'includes/class-fep-form.php', |
| 110 |
'menu' => FEP_PLUGIN_DIR . 'includes/class-fep-menu.php', |
| 111 |
'messages' => FEP_PLUGIN_DIR . 'includes/class-fep-messages.php', |
| 112 |
'shortcodes' => FEP_PLUGIN_DIR . 'includes/class-fep-shortcodes.php', |
| 113 |
'user-settings' => FEP_PLUGIN_DIR . 'includes/class-fep-user-settings.php', |
| 114 |
'main' => FEP_PLUGIN_DIR . 'includes/fep-class.php', |
| 115 |
'widgets' => FEP_PLUGIN_DIR . 'includes/fep-widgets.php', |
| 116 |
'rest' => FEP_PLUGIN_DIR . 'includes/class-fep-rest-api.php', |
| 117 |
); |
| 118 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 119 |
$fep_files['ajax'] = FEP_PLUGIN_DIR . 'includes/class-fep-ajax.php'; |
| 120 |
} |
| 121 |
if ( is_admin() ) { |
| 122 |
$fep_files['table'] = FEP_PLUGIN_DIR . 'admin/class-fep-wp-list-table.php'; |
| 123 |
$fep_files['attachment-table'] = FEP_PLUGIN_DIR . 'admin/class-fep-attachments-list-table.php'; |
| 124 |
$fep_files['admin-pages'] = FEP_PLUGIN_DIR . 'admin/class-fep-admin-pages.php'; |
| 125 |
$fep_files['settings'] = FEP_PLUGIN_DIR . 'admin/class-fep-admin-settings.php'; |
| 126 |
$fep_files['update'] = FEP_PLUGIN_DIR . 'admin/class-fep-update.php'; |
| 127 |
$fep_files['pro-info'] = FEP_PLUGIN_DIR . 'admin/class-fep-pro-info.php'; |
| 128 |
} |
| 129 |
$fep_files = apply_filters( 'fep_include_files', $fep_files ); |
| 130 |
foreach ( $fep_files as $fep_file ) { |
| 131 |
require_once( $fep_file ); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
function fep_get_option( $option, $default = '', $section = 'FEP_admin_options' ) { |
| 136 |
$options = get_option( $section ); |
| 137 |
if ( ! is_array( $options ) ) { |
| 138 |
$options = array(); |
| 139 |
} |
| 140 |
|
| 141 |
$is_default = false; |
| 142 |
if ( isset( $options[ $option ] ) ) { |
| 143 |
$value = $options[ $option ]; |
| 144 |
} else { |
| 145 |
$value = $default; |
| 146 |
$is_default = true; |
| 147 |
} |
| 148 |
return apply_filters( 'fep_get_option', $value, $option, $default, $is_default ); |
| 149 |
} |
| 150 |
|
| 151 |
function fep_update_option( $option, $value = '', $section = 'FEP_admin_options' ) { |
| 152 |
if ( empty( $option ) ) { |
| 153 |
return false; |
| 154 |
} |
| 155 |
if ( ! is_array( $option ) ) { |
| 156 |
$option = array( $option => $value ); |
| 157 |
} |
| 158 |
|
| 159 |
$options = get_option( $section ); |
| 160 |
if ( ! is_array( $options ) ) { |
| 161 |
$options = array(); |
| 162 |
} |
| 163 |
return update_option( $section, wp_parse_args( $option, $options ) ); |
| 164 |
} |
| 165 |
|
| 166 |
function fep_get_user_option( $option, $default = '', $userid = '', $section = 'FEP_user_options' ) { |
| 167 |
if( ! $userid ){ |
| 168 |
$userid = get_current_user_id(); |
| 169 |
} |
| 170 |
$options = get_user_meta( $userid, $section, true ); |
| 171 |
$is_default = false; |
| 172 |
if ( isset( $options[ $option ] ) ) { |
| 173 |
$value = $options[ $option ]; |
| 174 |
} else { |
| 175 |
$value = $default; |
| 176 |
$is_default = true; |
| 177 |
} |
| 178 |
return apply_filters( 'fep_get_user_option', $value, $option, $default, $userid, $is_default ); |
| 179 |
} |
| 180 |
|
| 181 |
function fep_update_user_option( $option, $value = '', $userid = '', $section = 'FEP_user_options' ) { |
| 182 |
if ( empty( $option ) ) { |
| 183 |
return false; |
| 184 |
} |
| 185 |
if ( ! is_array( $option ) ) { |
| 186 |
$option = array( $option => $value ); |
| 187 |
} |
| 188 |
if ( ! $userid ) { |
| 189 |
$userid = get_current_user_id(); |
| 190 |
} |
| 191 |
|
| 192 |
$options = get_user_meta( $userid, $section, true ); |
| 193 |
if ( ! is_array( $options ) ) { |
| 194 |
$options = array(); |
| 195 |
} |
| 196 |
return update_user_meta( $userid, $section, wp_parse_args( $option, $options ) ); |
| 197 |
} |
| 198 |
|
| 199 |
function fep_translation() { |
| 200 |
// SETUP TEXT DOMAIN FOR TRANSLATIONS |
| 201 |
load_plugin_textdomain( 'front-end-pm', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 202 |
} |
| 203 |
|
| 204 |
function fep_enqueue_scripts() { |
| 205 |
wp_register_style( 'fep-common-style', FEP_PLUGIN_URL . 'assets/css/common-style.css', array(), FEP_PLUGIN_VERSION ); |
| 206 |
wp_register_style( 'fep-style', FEP_PLUGIN_URL . 'assets/css/style.css', array(), FEP_PLUGIN_VERSION ); |
| 207 |
if ( 'always' == fep_get_option( 'load_css','only_in_message_page' ) ) { |
| 208 |
wp_enqueue_style( 'fep-style' ); |
| 209 |
} elseif ( 'only_in_message_page' == fep_get_option( 'load_css','only_in_message_page' ) && |
| 210 |
fep_page_id() && ( is_page( fep_page_id() ) || is_single( fep_page_id() ) ) ) { |
| 211 |
wp_enqueue_style( 'fep-style' ); |
| 212 |
} |
| 213 |
wp_enqueue_style( 'fep-common-style' ); |
| 214 |
|
| 215 |
$important = ''; |
| 216 |
|
| 217 |
if ( apply_filters( 'fep_add_important_to_inline_css', false ) ) { |
| 218 |
$important = ' !important'; |
| 219 |
} |
| 220 |
|
| 221 |
$custom_css = '#fep-wrapper{'; |
| 222 |
$custom_css .= 'background-color:' . fep_get_option( 'bg_color' ) . $important . ';'; |
| 223 |
$custom_css .= 'color:' . fep_get_option( 'text_color', '#000000' ) . $important . ';'; |
| 224 |
$custom_css .= '}'; |
| 225 |
$custom_css .= ' #fep-wrapper a:not(.fep-button,.fep-button-active) {color:' . fep_get_option( 'link_color', '#000080' ) . $important . ';}'; |
| 226 |
$custom_css .= ' .fep-button{'; |
| 227 |
$custom_css .= 'background-color:' . fep_get_option( 'btn_bg_color', '#F0FCFF' ) . $important . ';'; |
| 228 |
$custom_css .= 'color:' . fep_get_option( 'btn_text_color', '#000000' ) . $important . ';'; |
| 229 |
$custom_css .= '}'; |
| 230 |
$custom_css .= ' .fep-button:hover,.fep-button-active{'; |
| 231 |
$custom_css .= 'background-color:' . fep_get_option( 'active_btn_bg_color', '#D3EEF5' ) . $important . ';'; |
| 232 |
$custom_css .= 'color:' . fep_get_option( 'active_btn_text_color', '#000000' ) . $important . ';'; |
| 233 |
$custom_css .= '}'; |
| 234 |
$custom_css .= ' .fep-odd-even > div:nth-child(odd) {background-color:' . fep_get_option( 'odd_color', '#F2F7FC' ) . $important . ';}'; |
| 235 |
$custom_css .= ' .fep-odd-even > div:nth-child(even) {background-color:' . fep_get_option( 'even_color', '#FAFAFA' ) . $important . ';}'; |
| 236 |
$custom_css .= ' .fep-message .fep-message-title-heading, .fep-per-message .fep-message-title{background-color:' . fep_get_option( 'mgs_heading_color', '#F2F7FC' ) . $important . ';}'; |
| 237 |
$custom_css .= ' #fep-content-single-heads .fep-message-head:hover,#fep-content-single-heads .fep-message-head-active{'; |
| 238 |
$custom_css .= 'background-color:' . fep_get_option( 'active_btn_bg_color', '#D3EEF5' ) . $important . ';'; |
| 239 |
$custom_css .= 'color:' . fep_get_option( 'active_btn_text_color', '#000000' ) . $important . ';'; |
| 240 |
$custom_css .= '}'; |
| 241 |
$custom_css .= trim( stripslashes( fep_get_option( 'custom_css' ) ) ); |
| 242 |
if ( $custom_css ) { |
| 243 |
wp_add_inline_style( 'fep-common-style', $custom_css ); |
| 244 |
} |
| 245 |
wp_register_script( 'fep-script', FEP_PLUGIN_URL . 'assets/js/script.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 246 |
wp_localize_script( 'fep-script', 'fep_script', |
| 247 |
array( |
| 248 |
'root' => esc_url_raw( rest_url( 'front-end-pm/v1' ) ), |
| 249 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 250 |
'no_match' => __( 'No matches found', 'front-end-pm' ), |
| 251 |
) |
| 252 |
); |
| 253 |
wp_register_script( 'fep-notification-script', FEP_PLUGIN_URL . 'assets/js/notification.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 254 |
$call_on_ready = ( isset( $_GET['fepaction'] ) && |
| 255 |
( ( 'viewmessage' == $_GET['fepaction'] && fep_get_new_message_number() ) || ( 'view_announcement' == $_GET['fepaction'] && fep_get_new_announcement_number() ) ) |
| 256 |
) ? true : false; |
| 257 |
wp_localize_script( 'fep-notification-script', 'fep_notification_script', |
| 258 |
apply_filters( 'fep_filter_notification_script_localize', array( |
| 259 |
'root' => esc_url_raw( rest_url( 'front-end-pm/v1' ) ), |
| 260 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 261 |
'interval' => apply_filters( 'fep_filter_ajax_notification_interval', 2 * MINUTE_IN_SECONDS * 1000 ), |
| 262 |
'skip' => apply_filters( 'fep_filter_skip_notification_call', 2 ), // How many times notification ajax call will be skipped if browser tab not opened |
| 263 |
'show_in_title' => fep_get_option( 'show_unread_count_in_title', '1' ), |
| 264 |
'show_in_desktop' => fep_get_option( 'show_unread_count_in_desktop', '1' ), |
| 265 |
'call_on_ready' => apply_filters( 'fep_filter_notification_call_on_ready', $call_on_ready ), |
| 266 |
'play_sound' => fep_get_option( 'play_sound', '1' ), |
| 267 |
'sound_url' => FEP_PLUGIN_URL . 'assets/audio/plucky.mp3', |
| 268 |
'icon_url' => FEP_PLUGIN_URL . 'assets/images/desktop-notification-32.png', |
| 269 |
'mgs_notification_title'=> __( 'New Message. ', 'front-end-pm' ), |
| 270 |
'mgs_notification_body' => __( 'You have received a new message. ', 'front-end-pm' ), |
| 271 |
'mgs_notification_url' => fep_query_url( 'messagebox' ), |
| 272 |
'ann_notification_title'=> __( 'New Announcement. ', 'front-end-pm' ), |
| 273 |
'ann_notification_body' => __( 'You have received a new announcement. ', 'front-end-pm' ), |
| 274 |
'ann_notification_url' => fep_query_url( 'announcements' ), |
| 275 |
) |
| 276 |
) |
| 277 |
); |
| 278 |
wp_register_script( 'fep-replies-show-hide', FEP_PLUGIN_URL . 'assets/js/replies-show-hide.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 279 |
wp_register_script( 'fep-attachment-script', FEP_PLUGIN_URL . 'assets/js/attachment.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 280 |
wp_localize_script( 'fep-attachment-script', 'fep_attachment_script', array( |
| 281 |
'remove' => esc_js( __( 'Remove', 'front-end-pm' ) ), |
| 282 |
'maximum' => esc_js( fep_get_option( 'attachment_no', 4 ) ), |
| 283 |
'max_text' => esc_js( sprintf( __( 'Maximum %s allowed', 'front-end-pm' ), sprintf( _n( '%s file', '%s files', fep_get_option( 'attachment_no', 4 ), 'front-end-pm' ), number_format_i18n( fep_get_option( 'attachment_no', 4 ) ) ) ) ) |
| 284 |
) |
| 285 |
); |
| 286 |
wp_register_script( 'fep-form-submit', FEP_PLUGIN_URL . 'assets/js/form-submit.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 287 |
wp_localize_script( 'fep-form-submit', 'fep_form_submit', |
| 288 |
array( |
| 289 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 290 |
'token' => wp_create_nonce( 'fep-form' ), |
| 291 |
'refresh_text' => __( 'Refresh this page and try again. ', 'front-end-pm' ), |
| 292 |
'processing_text' => __( 'Processing... ', 'front-end-pm' ), |
| 293 |
) |
| 294 |
); |
| 295 |
wp_register_script( 'fep-block-unblock-script', FEP_PLUGIN_URL . 'assets/js/block-unblock.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 296 |
wp_localize_script( 'fep-block-unblock-script', 'fep_block_unblock_script', array( |
| 297 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 298 |
'token' => wp_create_nonce( 'fep-block-unblock-script' ), |
| 299 |
'confirm' => __( 'Do you really want to block %s? If you click "OK" then this user will not be able to send you any more messages.' ), |
| 300 |
) |
| 301 |
); |
| 302 |
wp_register_script( 'fep-view-message', FEP_PLUGIN_URL . 'assets/js/view-message.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 303 |
wp_localize_script( 'fep-view-message', 'fep_view_message', array( |
| 304 |
'root' => esc_url_raw( rest_url( 'front-end-pm/v1' ) ), |
| 305 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 306 |
'feppage' => ! empty( $_GET['feppage'] ) ? absint( $_GET['feppage'] ) : 1, |
| 307 |
'toggle' => apply_filters( 'fep_filter_message_toggle_feature', true ), |
| 308 |
) |
| 309 |
); |
| 310 |
wp_register_script( 'fep-cb-check-uncheck-all', FEP_PLUGIN_URL . 'assets/js/check-uncheck-all.js', array( 'jquery' ), FEP_PLUGIN_VERSION, true ); |
| 311 |
} |
| 312 |
|
| 313 |
function fep_common_scripts() { |
| 314 |
wp_register_style( 'fep-tokeninput-style', FEP_PLUGIN_URL . 'assets/css/token-input-facebook.css' ); |
| 315 |
wp_register_script( 'fep-tokeninput-script', FEP_PLUGIN_URL . 'assets/js/jquery.tokeninput.js', array( 'jquery' ), '6.1', true ); |
| 316 |
wp_register_script( 'fep-tokeninput', FEP_PLUGIN_URL . 'assets/js/fep-tokeninput.js', array( 'fep-tokeninput-script' ), FEP_PLUGIN_VERSION, true ); |
| 317 |
} |
| 318 |
|
| 319 |
function fep_tokeninput_localize( $args ) { |
| 320 |
static $count = 1; |
| 321 |
|
| 322 |
$args = wp_parse_args( $args, |
| 323 |
array( |
| 324 |
'ajaxurl' => esc_url_raw( rest_url( 'front-end-pm/v1/users/' . $args['for'] . '/' ) ), |
| 325 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 326 |
'method' => 'GET', |
| 327 |
'theme' => 'facebook', |
| 328 |
'hintText' => __( 'Type user name', 'front-end-pm'), |
| 329 |
'noResultsText' => __( 'No matches found', 'front-end-pm' ), |
| 330 |
'searchingText' => __( 'Searching...', 'front-end-pm' ), |
| 331 |
'width' => '250px', |
| 332 |
'tokenLimit' => null, |
| 333 |
// Following have to be overwritten. |
| 334 |
'selector' => '', // Field id |
| 335 |
'for' => '', |
| 336 |
'prePopulate' => [], |
| 337 |
) |
| 338 |
); |
| 339 |
$args = apply_filters( 'fep_filter_tokeninput_localize', $args ); |
| 340 |
wp_localize_script( 'fep-tokeninput', "fep_tokeninput_{$count}", $args ); |
| 341 |
$count++; |
| 342 |
} |
| 343 |
|
| 344 |
function fep_page_id() { |
| 345 |
return (int) apply_filters( 'fep_page_id_filter', fep_get_option( 'page_id', 0 ) ); |
| 346 |
} |
| 347 |
|
| 348 |
function fep_action_url( $action = '', $arg = array() ) { |
| 349 |
return fep_query_url( $action, $arg ); |
| 350 |
} |
| 351 |
|
| 352 |
function fep_query_url( $action, $arg = array() ) { |
| 353 |
$args = array( 'fepaction' => $action ); |
| 354 |
$args = array_merge( $args, $arg ); |
| 355 |
$url = esc_url( fep_query_url_without_esc( $action, $arg ) ); |
| 356 |
return apply_filters( 'fep_query_url_filter', $url, $args ); |
| 357 |
} |
| 358 |
|
| 359 |
function fep_query_url_raw( $action, $arg = array() ) { |
| 360 |
return esc_url_raw( fep_query_url_without_esc( $action, $arg ) ); |
| 361 |
} |
| 362 |
|
| 363 |
function fep_query_url_without_esc( $action, $arg = array() ) { |
| 364 |
$args = array( 'fepaction' => $action ); |
| 365 |
$args = array_merge( $args, $arg ); |
| 366 |
if ( fep_page_id() ) { |
| 367 |
$url = add_query_arg( $args, get_permalink( fep_page_id() ) ); |
| 368 |
} else { |
| 369 |
$url = add_query_arg( $args ); |
| 370 |
} |
| 371 |
return apply_filters( 'fep_query_url_without_esc_filter', $url, $args ); |
| 372 |
} |
| 373 |
|
| 374 |
if ( ! function_exists( 'fep_create_nonce' ) ) : |
| 375 |
/** |
| 376 |
* Creates a token usable in a form |
| 377 |
* return nonce with time |
| 378 |
* @return string |
| 379 |
*/ |
| 380 |
function fep_create_nonce( $action = -1 ) { |
| 381 |
$time = time(); |
| 382 |
$nonce = wp_create_nonce( $time . $action ); |
| 383 |
return $nonce . '-' . $time; |
| 384 |
} |
| 385 |
endif; |
| 386 |
|
| 387 |
if ( ! function_exists( 'fep_verify_nonce' ) ) : |
| 388 |
/** |
| 389 |
* Check if a token is valid. Mark it as used |
| 390 |
* @param string $_nonce The token |
| 391 |
* @return bool |
| 392 |
*/ |
| 393 |
function fep_verify_nonce( $_nonce, $action = -1) { |
| 394 |
$parts = explode( '-', $_nonce ); // Extract timestamp and nonce part of $_nonce |
| 395 |
|
| 396 |
// bad formatted onetime-nonce |
| 397 |
if ( empty( $parts[0] ) || empty( $parts[1] ) ) { |
| 398 |
return false; |
| 399 |
} |
| 400 |
$nonce = $parts[0]; // Original nonce generated by WordPress. |
| 401 |
$generated = $parts[1]; // Time when generated |
| 402 |
$expire = (int) $generated + HOUR_IN_SECONDS; //We want these nonces to have a short lifespan |
| 403 |
$time = time(); |
| 404 |
|
| 405 |
//Verify the nonce part and check that it has not expired |
| 406 |
if ( ! wp_verify_nonce( $nonce, $generated.$action ) || $time > $expire ) { |
| 407 |
return false; |
| 408 |
} |
| 409 |
|
| 410 |
//Get used nonces |
| 411 |
$used_nonces = get_option( '_fep_used_nonces' ); |
| 412 |
if ( ! is_array( $used_nonces ) ) { |
| 413 |
$used_nonces = array(); |
| 414 |
} |
| 415 |
|
| 416 |
//Nonce already used. |
| 417 |
if ( isset( $used_nonces[ $nonce] ) ) { |
| 418 |
return false; |
| 419 |
} |
| 420 |
foreach ( $used_nonces as $nonces => $timestamp ) { |
| 421 |
if ( $timestamp < $time ) { |
| 422 |
//This nonce has expired, so we don't need to keep it any longer |
| 423 |
unset( $used_nonces[ $nonces ] ); |
| 424 |
} |
| 425 |
} |
| 426 |
$used_nonces[ $nonce ] = $expire; // Add nonce to used nonces |
| 427 |
update_option( '_fep_used_nonces', $used_nonces, 'no' ); |
| 428 |
return true; |
| 429 |
} |
| 430 |
endif; |
| 431 |
|
| 432 |
function fep_error( $wp_error) { |
| 433 |
if ( ! is_wp_error( $wp_error) ) { |
| 434 |
return ''; |
| 435 |
} |
| 436 |
if ( 0 == count( $wp_error->get_error_messages() ) ) { |
| 437 |
return ''; |
| 438 |
} |
| 439 |
$errors = $wp_error->get_error_messages(); |
| 440 |
if ( is_admin() ) { |
| 441 |
$html = '<div id="message" class="error">'; |
| 442 |
} else { |
| 443 |
$html = '<div class="fep-wp-error">'; |
| 444 |
} |
| 445 |
foreach ( $errors as $error) { |
| 446 |
$html .= '<strong>' . __( 'Error', 'front-end-pm' ) . ': </strong>' . esc_html( $error ) . '<br />'; |
| 447 |
} |
| 448 |
$html .= '</div>'; |
| 449 |
return $html; |
| 450 |
} |
| 451 |
|
| 452 |
function fep_get_new_message_number() { |
| 453 |
return fep_get_user_message_count( 'unread' ); |
| 454 |
} |
| 455 |
|
| 456 |
function fep_get_new_message_button( $args = array() ) { |
| 457 |
if ( ! fep_current_user_can( 'access_message' ) ) { |
| 458 |
return ''; |
| 459 |
} |
| 460 |
$args = wp_parse_args( $args, array( |
| 461 |
'show_bracket' => '1', |
| 462 |
'hide_if_zero' => '1', |
| 463 |
'ajax' => '1', |
| 464 |
'class' => 'fep-font-red', |
| 465 |
) ); |
| 466 |
$args['class'] = fep_sanitize_html_class( $args['class'] ); |
| 467 |
$new = number_format_i18n( fep_get_new_message_number() ); |
| 468 |
if ( empty( $args['ajax'] ) ) { |
| 469 |
if ( ! $new && $args['hide_if_zero'] ) { |
| 470 |
return ''; |
| 471 |
} |
| 472 |
$ret = ''; |
| 473 |
if ( $args['show_bracket'] ) { |
| 474 |
$ret .= '( '; |
| 475 |
} |
| 476 |
$ret .= '<span class="' . $args['class'] . '">' . $new . '</span>'; |
| 477 |
if ( $args['show_bracket'] ) { |
| 478 |
$ret .= ' )'; |
| 479 |
} |
| 480 |
return $ret; |
| 481 |
} |
| 482 |
wp_enqueue_script( 'fep-notification-script' ); |
| 483 |
$args['class'] = $args['class'] . ' fep_unread_message_count'; |
| 484 |
if ( $args['hide_if_zero'] ) { |
| 485 |
$args['class'] = $args['class'] . ' fep_unread_message_count_hide_if_zero'; |
| 486 |
} |
| 487 |
$ret = ''; |
| 488 |
if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) { |
| 489 |
$ret .= '<span class="fep_unread_message_count_hide_if_zero fep-hide">(</span>'; |
| 490 |
} elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) { |
| 491 |
$ret .= '<span class="fep_unread_message_count_hide_if_zero">(</span>'; |
| 492 |
} elseif ( $args['show_bracket'] ) { |
| 493 |
$ret .= '( '; |
| 494 |
} |
| 495 |
if ( ! $new && $args['hide_if_zero'] ) { |
| 496 |
$args['class'] = $args['class'] . ' fep-hide'; |
| 497 |
} |
| 498 |
$ret .= '<span class="' . $args['class'] . '">' . $new . '</span>'; |
| 499 |
if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) { |
| 500 |
$ret .= '<span class="fep_unread_message_count_hide_if_zero fep-hide">)</span>'; |
| 501 |
} elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) { |
| 502 |
$ret .= '<span class="fep_unread_message_count_hide_if_zero">)</span>'; |
| 503 |
} elseif ( $args['show_bracket'] ) { |
| 504 |
$ret .= ' )'; |
| 505 |
} |
| 506 |
return $ret; |
| 507 |
} |
| 508 |
|
| 509 |
function fep_get_new_announcement_number() { |
| 510 |
return fep_get_user_announcement_count( 'unread' ); |
| 511 |
} |
| 512 |
|
| 513 |
function fep_get_new_announcement_button( $args = array() ) { |
| 514 |
if ( ! fep_current_user_can( 'access_message' ) ) { |
| 515 |
return ''; |
| 516 |
} |
| 517 |
$args = wp_parse_args( $args, array( |
| 518 |
'show_bracket' => '1', |
| 519 |
'hide_if_zero' => '1', |
| 520 |
'ajax' => '1', |
| 521 |
'class' => 'fep-font-red', |
| 522 |
) ); |
| 523 |
$args['class'] = fep_sanitize_html_class( $args['class'] ); |
| 524 |
$new = number_format_i18n( fep_get_new_announcement_number() ); |
| 525 |
if ( empty( $args['ajax'] ) ) { |
| 526 |
if ( ! $new && $args['hide_if_zero'] ) { |
| 527 |
return ''; |
| 528 |
} |
| 529 |
$ret = ''; |
| 530 |
if ( $args['show_bracket'] ) { |
| 531 |
$ret .= '( '; |
| 532 |
} |
| 533 |
$ret .= '<span class="' . $args['class'] . '">' . $new . '</span>'; |
| 534 |
if ( $args['show_bracket'] ) { |
| 535 |
$ret .= ' )'; |
| 536 |
} |
| 537 |
return $ret; |
| 538 |
} |
| 539 |
wp_enqueue_script( 'fep-notification-script' ); |
| 540 |
$args['class'] = $args['class'] . ' fep_unread_announcement_count'; |
| 541 |
if ( $args['hide_if_zero'] ) { |
| 542 |
$args['class'] = $args['class'] . ' fep_unread_announcement_count_hide_if_zero'; |
| 543 |
} |
| 544 |
$ret = ''; |
| 545 |
if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) { |
| 546 |
$ret .= '<span class="fep_unread_announcement_count_hide_if_zero fep-hide">(</span>'; |
| 547 |
} elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) { |
| 548 |
$ret .= '<span class="fep_unread_announcement_count_hide_if_zero">(</span>'; |
| 549 |
} elseif ( $args['show_bracket'] ) { |
| 550 |
$ret .= '( '; |
| 551 |
} |
| 552 |
if ( ! $new && $args['hide_if_zero'] ) { |
| 553 |
$args['class'] = $args['class'] . ' fep-hide'; |
| 554 |
} |
| 555 |
$ret .= '<span class="' . $args['class'] . '">' . $new . '</span>'; |
| 556 |
|
| 557 |
if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) { |
| 558 |
$ret .= '<span class="fep_unread_announcement_count_hide_if_zero fep-hide">)</span>'; |
| 559 |
} elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) { |
| 560 |
$ret .= '<span class="fep_unread_announcement_count_hide_if_zero">)</span>'; |
| 561 |
} elseif ( $args['show_bracket'] ) { |
| 562 |
$ret .= ' )'; |
| 563 |
} |
| 564 |
return $ret; |
| 565 |
} |
| 566 |
|
| 567 |
function fep_is_user_blocked( $login = '' ) { |
| 568 |
global $user_login; |
| 569 |
if ( ! $login && $user_login ) { |
| 570 |
$login = $user_login; |
| 571 |
} |
| 572 |
if ( $login ) { |
| 573 |
$wpusers = explode( ',', fep_get_option( 'have_permission' ) ); |
| 574 |
$wpusers = array_map( 'trim', $wpusers ); |
| 575 |
if ( in_array( $login, $wpusers) ) { |
| 576 |
return true; |
| 577 |
} |
| 578 |
} //User not logged in |
| 579 |
return false; |
| 580 |
} |
| 581 |
|
| 582 |
function fep_is_user_whitelisted( $login = '' ) { |
| 583 |
global $user_login; |
| 584 |
if ( ! $login && $user_login ) { |
| 585 |
$login = $user_login; |
| 586 |
} |
| 587 |
if ( $login ) { |
| 588 |
$wpusers = explode( ',', fep_get_option( 'whitelist_username' ) ); |
| 589 |
$wpusers = array_map( 'trim', $wpusers ); |
| 590 |
if ( in_array( $login, $wpusers) ) { |
| 591 |
return true; |
| 592 |
} |
| 593 |
} //User not logged in |
| 594 |
return false; |
| 595 |
} |
| 596 |
|
| 597 |
function fep_get_userdata( $data, $need = 'ID', $type = 'slug' ) { |
| 598 |
if ( ! $data ) { |
| 599 |
return ''; |
| 600 |
} |
| 601 |
$type = strtolower( $type ); |
| 602 |
if ( 'user_nicename' == $type ) { |
| 603 |
$type = 'slug'; |
| 604 |
} |
| 605 |
if ( ! in_array( $type, array ( 'id', 'slug', 'email', 'login' ) ) ) { |
| 606 |
return ''; |
| 607 |
} |
| 608 |
$user = get_user_by( $type , $data ); |
| 609 |
if ( $user ) { |
| 610 |
return $user->$need; |
| 611 |
} else { |
| 612 |
return ''; |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
function fep_user_name( $id ) { |
| 617 |
$which = apply_filters( 'fep_filter_show_which_name', 'display_name' ); |
| 618 |
switch ( $which ) { |
| 619 |
case 'first_last_name': |
| 620 |
$name = fep_get_userdata( $id, 'first_name', 'id' ) . ' ' . fep_get_userdata( $id, 'last_name', 'id' ); |
| 621 |
break; |
| 622 |
case 'last_first_name': |
| 623 |
$name = fep_get_userdata( $id, 'last_name', 'id' ) . ' ' . fep_get_userdata( $id, 'first_name', 'id' ); |
| 624 |
break; |
| 625 |
case 'first_name': |
| 626 |
case 'last_name': |
| 627 |
case 'user_login': |
| 628 |
case 'user_nicename': |
| 629 |
$name = fep_get_userdata( $id, $which, 'id' ); |
| 630 |
break; |
| 631 |
case 'display_name': |
| 632 |
default: |
| 633 |
$name = fep_get_userdata( $id, 'display_name', 'id' ); |
| 634 |
break; |
| 635 |
} |
| 636 |
return apply_filters( 'fep_filter_user_name', trim( $name ), $id ); |
| 637 |
} |
| 638 |
|
| 639 |
function fep_get_user_message_count( $value = 'all', $force = false, $user_id = false ) { |
| 640 |
return Fep_Messages::init()->user_message_count( $value, $force, $user_id ); |
| 641 |
} |
| 642 |
|
| 643 |
function fep_get_user_announcement_count( $value = 'all', $force = false, $user_id = false ) { |
| 644 |
return FEP_Announcements::init()->get_user_announcement_count( $value, $force, $user_id ); |
| 645 |
} |
| 646 |
|
| 647 |
function fep_get_message( $id ) { |
| 648 |
return FEP_Message::get_instance( $id ); |
| 649 |
} |
| 650 |
|
| 651 |
function fep_get_replies( $id ) { |
| 652 |
$args = array( |
| 653 |
'mgs_type' => 'message', |
| 654 |
'mgs_status' => 'publish', |
| 655 |
'mgs_parent' => $id, |
| 656 |
'per_page' => 0, |
| 657 |
'order' => 'ASC', |
| 658 |
); |
| 659 |
$args = apply_filters( 'fep_filter_get_replies', $args ); |
| 660 |
return new FEP_Message_Query( $args ); |
| 661 |
} |
| 662 |
|
| 663 |
function fep_get_attachments( $mgs_id = 0, $fields = '' ) { |
| 664 |
if ( '' !== $fields ) { |
| 665 |
_deprecated_argument( __FUNCTION__, '10.1.1' ); |
| 666 |
} |
| 667 |
if ( ! $mgs_id ) { |
| 668 |
$mgs_id = fep_get_the_id(); |
| 669 |
} |
| 670 |
if ( ! $mgs_id ) { |
| 671 |
return array(); |
| 672 |
} |
| 673 |
return FEP_Attachments::init()->get( $mgs_id ); |
| 674 |
} |
| 675 |
function fep_get_messages( $args = [] ){ |
| 676 |
$args = wp_parse_args( $args, array( |
| 677 |
'count_total' => false, |
| 678 |
)); |
| 679 |
$query = new FEP_Message_Query( $args ); |
| 680 |
return $query->get_results(); |
| 681 |
} |
| 682 |
|
| 683 |
function fep_get_parent_id( $id ) { |
| 684 |
if ( ! $id ) { |
| 685 |
return 0; |
| 686 |
} |
| 687 |
$parent = $id; |
| 688 |
do { |
| 689 |
$message = FEP_Message::get_instance( $parent ); |
| 690 |
if( $message ){ |
| 691 |
$parent = $message->mgs_parent; |
| 692 |
$id = $message->mgs_id; |
| 693 |
} else { |
| 694 |
$parent = 0; |
| 695 |
} |
| 696 |
} while( $parent ); |
| 697 |
// climb up the hierarchy until we reach parent = 0 |
| 698 |
return $id; |
| 699 |
} |
| 700 |
|
| 701 |
function fep_update_reply_info( $mgs_id ) { |
| 702 |
$updated = false; |
| 703 |
|
| 704 |
if ( ! $mgs_id || ! is_numeric( $mgs_id ) ) { |
| 705 |
return $updated; |
| 706 |
} |
| 707 |
$args = array( |
| 708 |
'mgs_type' => 'message', |
| 709 |
'mgs_status' => 'publish', |
| 710 |
'per_page' => 1, |
| 711 |
'mgs_id' => $mgs_id, |
| 712 |
'include_child' => true, |
| 713 |
'orderby' => 'mgs_created', |
| 714 |
'order' => 'DESC', |
| 715 |
); |
| 716 |
$messages = fep_get_messages( $args ); |
| 717 |
if ( $messages && ! empty( $messages[0] ) && $message = FEP_Message::get_instance( $mgs_id ) ) { |
| 718 |
$updated = $message->update( |
| 719 |
array( |
| 720 |
'mgs_last_reply_by' => $messages[0]->mgs_author, |
| 721 |
'mgs_last_reply_excerpt' => fep_get_the_excerpt_from_content( 100, $messages[0]->mgs_content ), |
| 722 |
'mgs_last_reply_time' => $messages[0]->mgs_created, |
| 723 |
) |
| 724 |
); |
| 725 |
} |
| 726 |
return $updated; |
| 727 |
} |
| 728 |
|
| 729 |
function fep_format_date( $date ) { |
| 730 |
|
| 731 |
if ( '0000-00-00 00:00:00' === $date ) { |
| 732 |
$h_time = __( 'Unpublished', 'front-end-pm' ); |
| 733 |
} else { |
| 734 |
$time = strtotime( $date ); |
| 735 |
//$time = get_post_time( 'G', true, $post, false ); |
| 736 |
if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) { |
| 737 |
if ( $t_diff < 0 ) { |
| 738 |
$h_time = sprintf( __( '%s from now', 'front-end-pm' ), human_time_diff( $time ) ); |
| 739 |
} else { |
| 740 |
$h_time = sprintf( __( '%s ago', 'front-end-pm' ), human_time_diff( $time ) ); |
| 741 |
} |
| 742 |
} else { |
| 743 |
$h_time = mysql2date( get_option( 'date_format' ). ' ' .get_option( 'time_format' ), get_date_from_gmt( $date ) ); |
| 744 |
} |
| 745 |
} |
| 746 |
return apply_filters( 'fep_formate_date', $h_time, $date ); |
| 747 |
} |
| 748 |
|
| 749 |
function fep_sort_by_priority( $a, $b ) { |
| 750 |
if ( ! isset( $a['priority'] ) || ! isset( $b['priority'] ) || $a['priority'] === $b['priority'] ) { |
| 751 |
return 0; |
| 752 |
} |
| 753 |
return ( $a['priority'] < $b['priority'] ) ? -1 : 1; |
| 754 |
} |
| 755 |
|
| 756 |
function fep_pagination( $total = null, $per_page = null, $list_class = 'fep-pagination' ) { |
| 757 |
$total = apply_filters( 'fep_pagination_total', $total); |
| 758 |
if ( null === $per_page ) { |
| 759 |
$per_page = fep_get_option( 'messages_page', 15 ); |
| 760 |
} |
| 761 |
$per_page = apply_filters( 'fep_pagination_per_page', $per_page ); |
| 762 |
$last = ceil( absint( $total) / absint( $per_page ) ); |
| 763 |
if ( $last <= 1 ) { |
| 764 |
return ''; |
| 765 |
} |
| 766 |
// $numPgs = $total_message / fep_get_option( 'messages_page', 50 ); |
| 767 |
$page = ( ! empty( $_GET['feppage'] ) ) ? absint( $_GET['feppage'] ) : 1; |
| 768 |
$links = ( isset( $_GET['links'] ) ) ? absint( $_GET['links'] ) : 2; |
| 769 |
$start = ( ( $page - $links ) > 0 ) ? $page - $links : 1; |
| 770 |
$end = ( ( $page + $links ) < $last ) ? $page + $links : $last; |
| 771 |
$html = '<div class="fep-align-centre"><ul class="' . $list_class . '">'; |
| 772 |
$class = ( $page == 1 ) ? "disabled" : ''; |
| 773 |
$html .= '<li class="' . $class . '"><a href="' . esc_url( add_query_arg( 'feppage', ( $page - 1 ) ) ) . '">«</a></li>'; |
| 774 |
if ( $start > 1 ) { |
| 775 |
$html .= '<li><a href="' . esc_url( add_query_arg( 'feppage', 1 ) ) . '">' . number_format_i18n( 1 ) . '</a></li>'; |
| 776 |
$html .= '<li class="disabled"><span>...</span></li>'; |
| 777 |
} |
| 778 |
for ( $i = $start ; $i <= $end; $i++ ) { |
| 779 |
$class = ( $page == $i ) ? "active" : ''; |
| 780 |
$html .= '<li class="' . $class . '"><a href="' . esc_url( add_query_arg( 'feppage', $i ) ) . '">' . number_format_i18n( $i ) . '</a></li>'; |
| 781 |
} |
| 782 |
if ( $end < $last ) { |
| 783 |
$html .= '<li class="disabled"><span>...</span></li>'; |
| 784 |
$html .= '<li><a href="' . esc_url( add_query_arg( 'feppage', $last ) ) . '">' . number_format_i18n( $last ) . '</a></li>'; |
| 785 |
} |
| 786 |
$class = ( $page == $last ) ? "disabled" : ''; |
| 787 |
$html .= '<li class="' . $class . '"><a href="' . esc_url( add_query_arg( 'feppage', ( $page + 1 ) ) ) . '">»</a></li>'; |
| 788 |
$html .= '</ul></div>'; |
| 789 |
return $html; |
| 790 |
} |
| 791 |
|
| 792 |
function fep_pagination_prev_next( $has_more_row ) { |
| 793 |
$feppage = ! empty( $_GET['feppage'] ) ? absint( $_GET['feppage'] ) : 1; |
| 794 |
|
| 795 |
if ( $feppage > 1 || $has_more_row ) : |
| 796 |
?> |
| 797 |
<div class="fep_pagination_prev_next fep-align-centre"> |
| 798 |
<ul class="fep-pagination fep-pagination-ul"> |
| 799 |
<li class="fep-pagination-li<?php echo ( 1 === $feppage ) ? ' disabled' : ''; ?>"> |
| 800 |
<a class="fep-pagination-a" data-fep_action="<?php echo ( 1 === $feppage ) ? '' : 'prev'; ?>" href="<?php echo esc_url( add_query_arg( 'feppage', $feppage - 1 ) ); ?>" title="<?php esc_attr_e( 'Previous', 'front-end-pm' ); ?>">«</a> |
| 801 |
</li> |
| 802 |
<li class="fep-pagination-li active"><span class="fep-pagination-span"><?php echo number_format_i18n( $feppage ); ?></span> |
| 803 |
</li> |
| 804 |
<li class="fep-pagination-li<?php echo ( ! $has_more_row ) ? ' disabled' : ''; ?>"> |
| 805 |
<a class="fep-pagination-a" data-fep_action="<?php echo ( ! $has_more_row ) ? '' : 'next'; ?>" href="<?php echo esc_url( add_query_arg( 'feppage', $feppage + 1 ) ); ?>" title="<?php esc_attr_e( 'Next', 'front-end-pm' ); ?>">»</a> |
| 806 |
</li> |
| 807 |
</ul> |
| 808 |
</div> |
| 809 |
<?php |
| 810 |
endif; |
| 811 |
} |
| 812 |
|
| 813 |
function fep_is_user_admin( $user_id = 0 ) { |
| 814 |
$admin_cap = apply_filters( 'fep_admin_cap', 'manage_options' ); |
| 815 |
if ( $user_id ) { |
| 816 |
return user_can( $user_id, $admin_cap ); |
| 817 |
} |
| 818 |
return current_user_can( $admin_cap ); |
| 819 |
} |
| 820 |
|
| 821 |
function fep_current_user_can( $cap, $id = false ) { |
| 822 |
$can = false; |
| 823 |
if ( ! is_user_logged_in() || fep_is_user_blocked() ) { |
| 824 |
return apply_filters( 'fep_current_user_can', $can, $cap, $id ); |
| 825 |
} |
| 826 |
$no_role_access = apply_filters( 'fep_no_role_access', false, $cap, $id ); |
| 827 |
$roles = wp_get_current_user()->roles; |
| 828 |
switch ( $cap ) { |
| 829 |
case has_filter( "fep_current_user_can_{$cap}" ): |
| 830 |
$can = apply_filters( "fep_current_user_can_{$cap}", $can, $cap, $id ); |
| 831 |
break; |
| 832 |
case 'access_message': |
| 833 |
if ( fep_is_user_whitelisted() || array_intersect( fep_get_option( 'userrole_access', array() ), $roles ) || ( ! $roles && $no_role_access ) ) { |
| 834 |
$can = true; |
| 835 |
} |
| 836 |
break; |
| 837 |
case 'send_new_message': |
| 838 |
if ( fep_is_user_whitelisted() || array_intersect( fep_get_option( 'userrole_new_message', array() ), $roles ) || ( ! $roles && $no_role_access ) ) { |
| 839 |
$can = true; |
| 840 |
} |
| 841 |
break; |
| 842 |
case 'send_new_message_to': |
| 843 |
if ( is_numeric( $id ) ) { |
| 844 |
// $id == user ID |
| 845 |
if ( $id && $id != get_current_user_id() && fep_current_user_can( 'access_message' ) && fep_current_user_can( 'send_new_message' ) && ( fep_is_user_whitelisted() || ( fep_get_user_option( 'allow_messages', 1, $id ) && ! fep_is_user_blocked_for_user( $id ) ) ) ) { |
| 846 |
$can = true; |
| 847 |
} |
| 848 |
// $id == user_nicename |
| 849 |
// Backward compability ( do not use ) |
| 850 |
} elseif ( $id && $id != fep_get_userdata( get_current_user_id(), 'user_nicename', 'id' ) && fep_current_user_can( 'access_message' ) && fep_current_user_can( 'send_new_message' ) && ( fep_is_user_whitelisted() || ( fep_get_user_option( 'allow_messages', 1, fep_get_userdata( $id ) ) && ! fep_is_user_blocked_for_user( fep_get_userdata( $id ) ) ) ) ) { |
| 851 |
$can = true; |
| 852 |
} |
| 853 |
break; |
| 854 |
case 'send_reply': |
| 855 |
if ( ! $id || fep_get_message_status( $id ) !== 'publish' ) { |
| 856 |
} elseif ( fep_is_user_whitelisted() || fep_is_user_admin() ) { |
| 857 |
$can = true; |
| 858 |
} elseif ( in_array( get_current_user_id(), fep_get_participants( $id, true ) ) && ( array_intersect( fep_get_option( 'userrole_reply', array() ), $roles ) || ( ! $roles && $no_role_access ) ) ) { |
| 859 |
$can = true; |
| 860 |
} |
| 861 |
if ( $can ) { |
| 862 |
$participants = FEP_Participants::init()->get( $id ); |
| 863 |
foreach ( $participants as $participant ) { |
| 864 |
if ( $participant->mgs_deleted && ! fep_get_option( 'reply_deleted_mgs' ) ) { |
| 865 |
$can = false; |
| 866 |
break; |
| 867 |
} |
| 868 |
if ( ! fep_is_user_whitelisted() && fep_is_user_blocked_for_user( $participant->mgs_participant ) ) { |
| 869 |
$can = false; |
| 870 |
break; |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
break; |
| 875 |
case 'view_message': |
| 876 |
case 'view_announcement': |
| 877 |
if ( $id && ( ( in_array( get_current_user_id(), fep_get_participants( $id, true ) ) && fep_get_message_status( $id ) == 'publish' ) || fep_is_user_admin() || fep_is_user_whitelisted() ) ) { |
| 878 |
$can = true; |
| 879 |
} |
| 880 |
break; |
| 881 |
case 'delete_message': // only for himself |
| 882 |
case 'delete_announcement': // only for himself |
| 883 |
if ( $id && in_array( get_current_user_id(), fep_get_participants( $id, true ) ) && fep_get_message_status( $id ) == 'publish' ) { |
| 884 |
$can = true; |
| 885 |
} |
| 886 |
break; |
| 887 |
case 'access_directory': |
| 888 |
if ( fep_is_user_admin() || fep_is_user_whitelisted() || fep_get_option( 'show_directory', 1 ) ) { |
| 889 |
$can = true; |
| 890 |
} |
| 891 |
break; |
| 892 |
case 'add_announcement': |
| 893 |
if ( fep_is_user_admin() ) { |
| 894 |
$can = true; |
| 895 |
} |
| 896 |
break; |
| 897 |
default : |
| 898 |
break; |
| 899 |
} |
| 900 |
return apply_filters( 'fep_current_user_can', $can, $cap, $id ); |
| 901 |
} |
| 902 |
|
| 903 |
function fep_is_read( $parent = false, $mgs_id = false, $user_id = false ) { |
| 904 |
if ( ! $user_id ) { |
| 905 |
$user_id = get_current_user_id(); |
| 906 |
} |
| 907 |
if ( ! $mgs_id ) { |
| 908 |
$mgs_id = fep_get_the_id(); |
| 909 |
} |
| 910 |
if ( ! $mgs_id || ! $user_id ) { |
| 911 |
return false; |
| 912 |
} |
| 913 |
$participant = FEP_Participants::init()->get( $mgs_id, $user_id ); |
| 914 |
$return = 0; |
| 915 |
if( $participant ){ |
| 916 |
if( $parent ){ |
| 917 |
$return = $participant->mgs_parent_read; |
| 918 |
} else { |
| 919 |
$return = $participant->mgs_read; |
| 920 |
} |
| 921 |
} |
| 922 |
return (int) $return; |
| 923 |
} |
| 924 |
|
| 925 |
function fep_make_read( $parent = false, $mgs_id = false, $user_id = false ) { |
| 926 |
if ( ! $user_id ) { |
| 927 |
$user_id = get_current_user_id(); |
| 928 |
} |
| 929 |
if ( ! $mgs_id ) { |
| 930 |
$mgs_id = fep_get_the_id(); |
| 931 |
} |
| 932 |
if ( ! $mgs_id || ! $user_id ) { |
| 933 |
return false; |
| 934 |
} |
| 935 |
$return = false; |
| 936 |
|
| 937 |
if( $parent ){ |
| 938 |
$return = FEP_Participants::init()->mark( $mgs_id, $user_id, ['parent_read' => true ] ); |
| 939 |
} else { |
| 940 |
$return = FEP_Participants::init()->mark( $mgs_id, $user_id, ['read' => true ] ); |
| 941 |
} |
| 942 |
return $return; |
| 943 |
} |
| 944 |
|
| 945 |
function fep_get_the_excerpt_from_content( $count = 100, $excerpt = '' ) { |
| 946 |
|
| 947 |
$excerpt = strip_shortcodes( $excerpt ); |
| 948 |
$excerpt = wp_strip_all_tags( $excerpt ); |
| 949 |
$excerpt = substr( $excerpt, 0, $count ); |
| 950 |
$excerpt = substr( $excerpt, 0, strripos( $excerpt, ' ' ) ); |
| 951 |
$excerpt = $excerpt. ' ... '; |
| 952 |
return apply_filters( 'fep_get_the_excerpt_from_content', $excerpt, $count ); |
| 953 |
} |
| 954 |
|
| 955 |
function fep_get_current_user_max_message_number() { |
| 956 |
$roles = wp_get_current_user()->roles; |
| 957 |
$count_array = array(); |
| 958 |
if ( $roles && is_array( $roles ) ) { |
| 959 |
foreach ( $roles as $role ) { |
| 960 |
$count = fep_get_option( "message_box_{$role}", 50 ); |
| 961 |
if ( ! $count ) { |
| 962 |
return 0; |
| 963 |
} |
| 964 |
$count_array[] = $count; |
| 965 |
} |
| 966 |
} |
| 967 |
if ( $count_array ) { |
| 968 |
return max( $count_array); |
| 969 |
} else { |
| 970 |
return 0; // FIX ME. 0 = unlimited !!!! |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
function fep_add_email_filters( $for = 'message' ) { |
| 975 |
do_action( 'fep_action_after_add_email_filters', $for ); |
| 976 |
} |
| 977 |
|
| 978 |
function fep_remove_email_filters( $for = 'message' ) { |
| 979 |
do_action( 'fep_action_after_remove_email_filters', $for ); |
| 980 |
} |
| 981 |
|
| 982 |
function fep_delete_message( $mgs_id, $user_id = 0 ) { |
| 983 |
if ( ! $user_id ) { |
| 984 |
$user_id = get_current_user_id(); |
| 985 |
} |
| 986 |
if ( ! $mgs_id || ! $user_id ) { |
| 987 |
return false; |
| 988 |
} |
| 989 |
|
| 990 |
$return = FEP_Participants::init()->mark( $mgs_id, $user_id, ['delete' => true ] ); |
| 991 |
|
| 992 |
$should_delete_from_db = true; |
| 993 |
foreach ( FEP_Participants::init()->get( $mgs_id ) as $participant ) { |
| 994 |
if ( ! $participant->mgs_deleted ) { |
| 995 |
$should_delete_from_db = false; |
| 996 |
break; |
| 997 |
} |
| 998 |
} |
| 999 |
if ( apply_filters( 'fep_filter_delete_from_db', $should_delete_from_db, $mgs_id ) ) { |
| 1000 |
$args = [ |
| 1001 |
'mgs_id' => $mgs_id, |
| 1002 |
'per_page' => 0, //unlimited |
| 1003 |
'mgs_status' => 'any', |
| 1004 |
]; |
| 1005 |
if( 'threaded' == fep_get_message_view() && apply_filters( 'fep_erase_replies_if_threaded', true ) ){ |
| 1006 |
$args['include_child'] = true; |
| 1007 |
} |
| 1008 |
$messages = fep_get_messages( $args ); |
| 1009 |
foreach( $messages as $message ){ |
| 1010 |
$message->delete(); |
| 1011 |
} |
| 1012 |
} |
| 1013 |
return $return; |
| 1014 |
} |
| 1015 |
|
| 1016 |
function fep_send_message( $message = null, $override = array() ) { |
| 1017 |
if ( null === $message ) { |
| 1018 |
$message = $_POST; |
| 1019 |
} |
| 1020 |
if ( ! empty( $message['fep_parent_id'] ) ) { |
| 1021 |
$message['mgs_parent'] = absint( $message['fep_parent_id'] ); |
| 1022 |
$message['mgs_status'] = fep_get_option( 'reply_post_status', 'publish' ); |
| 1023 |
$message['message_title'] = __( 'RE:', 'front-end-pm' ). ' ' . wp_slash( fep_get_message_field( 'mgs_title', $message['mgs_parent'] ) ); |
| 1024 |
$message['message_to_id'] = fep_get_participants( $message['mgs_parent'], ! fep_get_option( 'reply_deleted_mgs' ) ); |
| 1025 |
} else { |
| 1026 |
$message['mgs_status'] = fep_get_option( 'parent_post_status','publish' ); |
| 1027 |
$message['mgs_parent'] = 0; |
| 1028 |
} |
| 1029 |
$message = apply_filters( 'fep_filter_message_before_send', $message ); |
| 1030 |
if ( empty( $message['message_title'] ) || empty( $message['message_content'] ) ) { |
| 1031 |
return false; |
| 1032 |
} |
| 1033 |
// Create post array |
| 1034 |
$post = array( |
| 1035 |
'mgs_title' => $message['message_title'], |
| 1036 |
'mgs_content' => $message['message_content'], |
| 1037 |
'mgs_status' => $message['mgs_status'], |
| 1038 |
'mgs_parent' => $message['mgs_parent'], |
| 1039 |
'mgs_type' => 'message', |
| 1040 |
'mgs_author' => get_current_user_id(), |
| 1041 |
'mgs_created' => current_time( 'mysql', true ), |
| 1042 |
); |
| 1043 |
|
| 1044 |
if ( $override && is_array( $override ) ) { |
| 1045 |
$post = wp_parse_args( $override, $post ); |
| 1046 |
} |
| 1047 |
if( ! $post['mgs_parent'] && 'threaded' === fep_get_message_view() ){ |
| 1048 |
$post['mgs_last_reply_by'] = $post['mgs_author']; |
| 1049 |
$post['mgs_last_reply_excerpt'] = fep_get_the_excerpt_from_content( 100, $post['mgs_content'] ); |
| 1050 |
$post['mgs_last_reply_time'] = $post['mgs_created']; |
| 1051 |
} |
| 1052 |
|
| 1053 |
$post = apply_filters( 'fep_filter_message_after_override', $post, $message ); |
| 1054 |
|
| 1055 |
$post = wp_unslash( $post ); |
| 1056 |
|
| 1057 |
$new_message = new FEP_Message; |
| 1058 |
$message_id = $new_message->insert( $post ); |
| 1059 |
// Insert the message into the database |
| 1060 |
if ( ! $message_id ) { |
| 1061 |
return false; |
| 1062 |
} |
| 1063 |
/* |
| 1064 |
$inserted_message = FEP_Message::get_instance( $message_id ); |
| 1065 |
if( ! $inserted_message ){ |
| 1066 |
return false; |
| 1067 |
} |
| 1068 |
*/ |
| 1069 |
if( ! empty( $message['message_to_id'] ) ){ |
| 1070 |
$message['message_to_id'] = (array) $message['message_to_id']; |
| 1071 |
$message['message_to_id'][] = $new_message->mgs_author; |
| 1072 |
$new_message->insert_participants( $message['message_to_id'] ); |
| 1073 |
} |
| 1074 |
if ( is_multisite() ) { |
| 1075 |
fep_add_meta( $message_id, '_fep_blog_id', get_current_blog_id() ); |
| 1076 |
} |
| 1077 |
do_action( 'fep_action_message_after_send', $message_id, $message, $new_message ); |
| 1078 |
do_action( 'fep_action_message_after_sent', $message_id, $message, $new_message ); |
| 1079 |
|
| 1080 |
fep_status_change( 'new', $new_message ); |
| 1081 |
|
| 1082 |
return $message_id; |
| 1083 |
} |
| 1084 |
|
| 1085 |
function fep_status_change( $old_status, $message ){ |
| 1086 |
if( ! $old_status || ! is_object( $message ) ){ |
| 1087 |
return false; |
| 1088 |
} |
| 1089 |
$new_status = $message->mgs_status; |
| 1090 |
|
| 1091 |
if( $old_status == $new_status ){ |
| 1092 |
return false; |
| 1093 |
} |
| 1094 |
do_action( "fep_transition_post_status", $new_status, $old_status, $message ); |
| 1095 |
|
| 1096 |
do_action( "fep_status_{$old_status}_to_{$new_status}", $message ); |
| 1097 |
|
| 1098 |
do_action( "fep_status_to_{$new_status}", $message, $old_status ); |
| 1099 |
|
| 1100 |
do_action( "fep_transition_{$message->mgs_type}_status", $new_status, $old_status, $message ); |
| 1101 |
|
| 1102 |
do_action( "fep_{$message->mgs_type}_status_{$old_status}_to_{$new_status}", $message ); |
| 1103 |
|
| 1104 |
do_action( "fep_{$message->mgs_type}_status_to_{$new_status}", $message, $old_status ); |
| 1105 |
} |
| 1106 |
|
| 1107 |
function fep_delete_counts_cache( $new_status, $old_status, $message ) { |
| 1108 |
wp_cache_delete( $message->mgs_type, 'fep_counts' ); |
| 1109 |
} |
| 1110 |
|
| 1111 |
function fep_send_message_transition_post_status( $new_status, $old_status, $message ) { |
| 1112 |
if ( 'message' != $message->mgs_type ) { |
| 1113 |
return; |
| 1114 |
} |
| 1115 |
|
| 1116 |
if ( 'new' === $old_status ) { |
| 1117 |
if ( 'threaded' === fep_get_message_view() && $message->mgs_parent ) { |
| 1118 |
$unmark = [ |
| 1119 |
'parent_read' => true, |
| 1120 |
]; |
| 1121 |
if ( fep_get_option( 'reply_deleted_mgs' ) ) { |
| 1122 |
$unmark['delete'] = true; |
| 1123 |
} |
| 1124 |
FEP_Participants::init()->unmark( $message->mgs_parent, false, $unmark ); |
| 1125 |
FEP_Participants::init()->mark( $message->mgs_parent, $message->mgs_author, [ 'parent_read' => true ] ); |
| 1126 |
} |
| 1127 |
FEP_Participants::init()->mark( $message->mgs_id, $message->mgs_author, [ 'parent_read' => true ] ); |
| 1128 |
} |
| 1129 |
if ( 'publish' == $new_status || 'publish' == $old_status ) { |
| 1130 |
if( 'threaded' === fep_get_message_view() && $message->mgs_parent ) { |
| 1131 |
fep_update_reply_info( $message->mgs_parent ); |
| 1132 |
} |
| 1133 |
$participants = fep_get_participants( $message->mgs_id, true ); |
| 1134 |
foreach ( $participants as $participant ) { |
| 1135 |
delete_user_meta( $participant, '_fep_user_message_count' ); |
| 1136 |
if ( $participant != $message->mgs_author && 'publish' == $new_status ) { |
| 1137 |
delete_user_meta( $participant, '_fep_notification_dismiss' ); |
| 1138 |
} |
| 1139 |
} |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
function fep_add_announcement( $announcement = null, $override = array() ) { |
| 1144 |
if ( null === $announcement ) { |
| 1145 |
$announcement = $_POST; |
| 1146 |
} |
| 1147 |
$announcement = apply_filters( 'fep_filter_announcement_before_added', $announcement ); |
| 1148 |
if ( empty( $announcement['message_title'] ) || empty( $announcement['message_content'] ) ) { |
| 1149 |
return false; |
| 1150 |
} |
| 1151 |
// Create post array |
| 1152 |
$post = array( |
| 1153 |
'mgs_title' => $announcement['message_title'], |
| 1154 |
'mgs_content' => $announcement['message_content'], |
| 1155 |
'mgs_status' => 'publish', |
| 1156 |
'mgs_type' => 'announcement', |
| 1157 |
'mgs_author' => get_current_user_id(), |
| 1158 |
'mgs_created' => current_time( 'mysql', true ), |
| 1159 |
); |
| 1160 |
|
| 1161 |
if ( $override && is_array( $override ) ) { |
| 1162 |
$post = wp_parse_args( $override, $post ); |
| 1163 |
} |
| 1164 |
$post = apply_filters( 'fep_filter_announcement_after_override', $post, $announcement ); |
| 1165 |
|
| 1166 |
$post = wp_unslash( $post ); |
| 1167 |
|
| 1168 |
$new_message = new FEP_Message; |
| 1169 |
$announcement_id = $new_message->insert( $post ); |
| 1170 |
|
| 1171 |
// Insert the message into the database |
| 1172 |
if ( ! $announcement_id ) { |
| 1173 |
return false; |
| 1174 |
} |
| 1175 |
/* |
| 1176 |
$inserted_announcement = FEP_Message::get_instance( $announcement_id ); |
| 1177 |
if( ! $inserted_announcement ){ |
| 1178 |
return false; |
| 1179 |
} |
| 1180 |
*/ |
| 1181 |
if ( ! empty( $announcement['announcement_roles'] ) && is_array( $announcement['announcement_roles'] ) ) { |
| 1182 |
$user_ids = get_users( [ 'fields' => 'ids', 'role__in' => $announcement['announcement_roles'] ] ); |
| 1183 |
$user_ids[] = $new_message->mgs_author; |
| 1184 |
|
| 1185 |
$user_ids = apply_filters( 'fep_filter_announcement_participant_ids', $user_ids, $announcement_id, $announcement, $new_message ); |
| 1186 |
|
| 1187 |
$new_message->insert_participants( $user_ids ); |
| 1188 |
|
| 1189 |
foreach( $announcement['announcement_roles'] as $role ){ |
| 1190 |
fep_add_meta( $announcement_id, '_fep_participant_roles', $role ); |
| 1191 |
} |
| 1192 |
} |
| 1193 |
if ( is_multisite() ) { |
| 1194 |
fep_add_meta( $announcement_id, '_fep_blog_id', get_current_blog_id() ); |
| 1195 |
} |
| 1196 |
|
| 1197 |
FEP_Participants::init()->mark( $new_message->mgs_id, $new_message->mgs_author, ['read' => true, 'parent_read' => true ] ); |
| 1198 |
|
| 1199 |
do_action( 'fep_action_announcement_after_added', $announcement_id, $announcement, $new_message ); |
| 1200 |
|
| 1201 |
fep_status_change( 'new', $new_message ); |
| 1202 |
|
| 1203 |
return $announcement_id; |
| 1204 |
} |
| 1205 |
|
| 1206 |
function fep_backticker_encode( $text ) { |
| 1207 |
$text = $text[1]; |
| 1208 |
$text = str_replace( '&lt;', '<', $text ); |
| 1209 |
$text = str_replace( '&gt;', '>', $text ); |
| 1210 |
$text = htmlspecialchars( $text, ENT_QUOTES ); |
| 1211 |
$text = preg_replace( '|\n+|', '\n', $text ); |
| 1212 |
$text = nl2br( $text ); |
| 1213 |
$text = str_replace( '\t', ' ', $text ); |
| 1214 |
$text = preg_replace( '/^ /', ' ', $text ); |
| 1215 |
$text = preg_replace( '/(?<= | |\n) /', ' ', $text ); |
| 1216 |
return "<code>$text</code>"; |
| 1217 |
} |
| 1218 |
|
| 1219 |
function fep_backticker_display_code( $text ) { |
| 1220 |
//$text = preg_replace_callback( "|`(.*?)`|", "fep_backticker_encode", $text ); |
| 1221 |
$text = preg_replace_callback( '!`(?:\r\n|\n|\r|)(.*?)(?:\r\n|\n|\r|)`!ims', 'fep_backticker_encode', $text ); |
| 1222 |
$text = str_replace( '<code></code>', '`', $text ); |
| 1223 |
return $text; |
| 1224 |
} |
| 1225 |
|
| 1226 |
function fep_backticker_code_input_filter( $message ) { |
| 1227 |
$message['message_content'] = fep_backticker_display_code( $message['message_content'] ); |
| 1228 |
return $message; |
| 1229 |
} |
| 1230 |
|
| 1231 |
function fep_footer_credit() { |
| 1232 |
$style = ''; |
| 1233 |
if ( ! fep_get_option( 'show_branding', 1 ) ) { |
| 1234 |
$style = ' style="display:none;"'; |
| 1235 |
} |
| 1236 |
echo '<div' . $style . '><a href="https://www.shamimsplugins.com/products/front-end-pm-pro/" target="_blank">Front End PM</a></div>'; |
| 1237 |
} |
| 1238 |
|
| 1239 |
function fep_notification_div() { |
| 1240 |
if ( ! fep_current_user_can( 'access_message' ) ) { |
| 1241 |
return; |
| 1242 |
} |
| 1243 |
if ( ! fep_get_option( 'show_notification', 1 ) ) { |
| 1244 |
return; |
| 1245 |
} |
| 1246 |
wp_enqueue_script( 'fep-notification-script' ); |
| 1247 |
$unread_count = fep_get_new_message_number(); |
| 1248 |
$sm = sprintf( _n( '%s message', '%s messages', $unread_count, 'front-end-pm' ), number_format_i18n( $unread_count ) ); |
| 1249 |
$unread_ann_count = fep_get_new_announcement_number(); |
| 1250 |
$sa = sprintf( _n( '%s announcement', '%s announcements', $unread_ann_count, 'front-end-pm' ), number_format_i18n( $unread_ann_count ) ); |
| 1251 |
$class = 'fep-notification-bar'; |
| 1252 |
if ( ! $unread_count && ! $unread_ann_count ) { |
| 1253 |
$class .= ' fep-hide'; |
| 1254 |
} elseif ( get_user_meta( get_current_user_id(), '_fep_notification_dismiss', true ) ) { |
| 1255 |
$class .= ' fep-hide'; |
| 1256 |
} |
| 1257 |
$show = '<div id="fep-notification-bar" class="' . $class . '"><p>'; |
| 1258 |
$show .= __( 'You have', 'front-end-pm' ); |
| 1259 |
$class = 'fep_unread_message_count_hide_if_zero'; |
| 1260 |
if ( ! $unread_count ) { |
| 1261 |
$class .= ' fep-hide'; |
| 1262 |
} |
| 1263 |
$show .= '<span class="' . $class . '"> <a href="' . fep_query_url( 'messagebox' ) . '"><span class="fep_unread_message_count_text">' . $sm . '</span></a></span>'; |
| 1264 |
$class = 'fep_hide_if_anyone_zero'; |
| 1265 |
if ( ! $unread_count || ! $unread_ann_count ) { |
| 1266 |
$class .= ' fep-hide'; |
| 1267 |
} |
| 1268 |
$show .= '<span class="' . $class . '"> ' . __( 'and', 'front-end-pm' ) . '</span>'; |
| 1269 |
$class = 'fep_unread_announcement_count_hide_if_zero'; |
| 1270 |
if ( ! $unread_ann_count ) { |
| 1271 |
$class .= ' fep-hide'; |
| 1272 |
} |
| 1273 |
$show .= '<span class="' . $class . '"> <a href="' . fep_query_url( 'announcements' ) . '"><span class="fep_unread_announcement_count_text">' . $sa . '</span></a></span>'; |
| 1274 |
$show .= ' '; |
| 1275 |
$show .= __( 'unread', 'front-end-pm' ); |
| 1276 |
$show .= '</p>'; |
| 1277 |
$show .= '<button aria-label="' . esc_attr( 'Dismiss notice', 'front-end-pm' ) . '" class="fep-notice-dismiss">×</button>'; |
| 1278 |
$show .= '</div>'; |
| 1279 |
echo apply_filters( 'fep_header_notification', $show ); |
| 1280 |
} |
| 1281 |
|
| 1282 |
function fep_auth_redirect() { |
| 1283 |
if ( ! fep_page_id() || ( ! is_page( fep_page_id() ) && ! is_single( fep_page_id() ) ) ) { |
| 1284 |
return; |
| 1285 |
} |
| 1286 |
do_action( 'fep_template_redirect' ); |
| 1287 |
if ( apply_filters( 'fep_using_auth_redirect', false ) ) { |
| 1288 |
auth_redirect(); |
| 1289 |
} |
| 1290 |
} |
| 1291 |
|
| 1292 |
function fep_auth_redirect_scheme( $scheme ) { |
| 1293 |
if ( ! apply_filters( 'fep_using_auth_redirect', false ) ) { |
| 1294 |
return $scheme; |
| 1295 |
} |
| 1296 |
if ( is_admin() || ! fep_page_id() || ( ! is_page( fep_page_id() ) && ! is_single( fep_page_id() ) ) ) { |
| 1297 |
return $scheme; |
| 1298 |
} |
| 1299 |
return 'logged_in'; |
| 1300 |
} |
| 1301 |
|
| 1302 |
function fep_array_trim( $array ) { |
| 1303 |
if ( ! is_array( $array ) ) { |
| 1304 |
return trim( $array ); |
| 1305 |
} |
| 1306 |
return array_map( 'fep_array_trim', $array ); |
| 1307 |
} |
| 1308 |
|
| 1309 |
function fep_is_pro() { |
| 1310 |
return file_exists( FEP_PLUGIN_DIR . 'pro/pro-features.php' ); |
| 1311 |
} |
| 1312 |
|
| 1313 |
function fep_errors() { |
| 1314 |
static $errors; // Will hold global variable safely |
| 1315 |
return isset( $errors ) ? $errors : ( $errors = new WP_Error() ); |
| 1316 |
} |
| 1317 |
|
| 1318 |
function fep_success() { |
| 1319 |
static $success; // Will hold global variable safely |
| 1320 |
return isset( $success ) ? $success : ( $success = new WP_Error() ); |
| 1321 |
} |
| 1322 |
|
| 1323 |
function fep_info_output() { |
| 1324 |
do_action( 'fep_action_info_output' ); |
| 1325 |
|
| 1326 |
$html = ''; |
| 1327 |
if ( fep_success()->get_error_messages() ) { |
| 1328 |
$html .= '<div class="fep-success">'; |
| 1329 |
foreach ( fep_success()->get_error_messages() as $s ) { |
| 1330 |
$html .= esc_html( $s ). '<br />'; |
| 1331 |
} |
| 1332 |
$html .= '</div>'; |
| 1333 |
} |
| 1334 |
if ( fep_errors()->get_error_messages() ) { |
| 1335 |
$html .= '<div class="fep-wp-error">'; |
| 1336 |
foreach ( fep_errors()->get_error_messages() as $e ) { |
| 1337 |
$html .= '<strong>' . __( 'Error', 'front-end-pm' ) . ': </strong>' . esc_html( $e ) . '<br />'; |
| 1338 |
} |
| 1339 |
$html .= '</div>'; |
| 1340 |
} |
| 1341 |
return $html; |
| 1342 |
} |
| 1343 |
|
| 1344 |
function fep_locate_template( $template_names, $load = false, $require_once = true ) { |
| 1345 |
$locations = array(); |
| 1346 |
$locations[10] = trailingslashit( STYLESHEETPATH ) . 'front-end-pm/'; |
| 1347 |
$locations[20] = trailingslashit( TEMPLATEPATH ) . 'front-end-pm/'; |
| 1348 |
$locations[30] = FEP_PLUGIN_DIR . 'pro/templates/'; |
| 1349 |
$locations[40] = FEP_PLUGIN_DIR . 'templates/'; |
| 1350 |
$locations = apply_filters( 'fep_template_locations', $locations ); |
| 1351 |
|
| 1352 |
// sort the $locations based on priority |
| 1353 |
ksort( $locations, SORT_NUMERIC ); |
| 1354 |
$template = ''; |
| 1355 |
if ( ! is_array( $template_names ) ) { |
| 1356 |
$template_names = explode( ',', $template_names ); |
| 1357 |
} |
| 1358 |
foreach ( $template_names as $template_name ) { |
| 1359 |
$template_name = trim( $template_name ); |
| 1360 |
if ( empty( $template_name ) ) { |
| 1361 |
continue; |
| 1362 |
} |
| 1363 |
if ( strpos( $template_name, '../' ) !== false || strpos( $template_name, '..\\' ) !== false ) { |
| 1364 |
continue; |
| 1365 |
} |
| 1366 |
foreach ( $locations as $location ) { |
| 1367 |
if ( file_exists( $location . $template_name ) ) { |
| 1368 |
$template = $location . $template_name; |
| 1369 |
break 2; |
| 1370 |
} |
| 1371 |
} |
| 1372 |
} |
| 1373 |
if ( ( true == $load ) && ! empty( $template ) ) { |
| 1374 |
load_template( $template, $require_once ); |
| 1375 |
} |
| 1376 |
return apply_filters( 'fep_locate_template', $template, $template_names, $load, $require_once ); |
| 1377 |
} |
| 1378 |
|
| 1379 |
function fep_form_posted() { |
| 1380 |
$action = ! empty( $_POST['fep_action'] ) ? $_POST['fep_action'] : ''; |
| 1381 |
if ( ! $action ) { |
| 1382 |
return; |
| 1383 |
} |
| 1384 |
if ( ! fep_current_user_can( 'access_message' ) ) { |
| 1385 |
return; |
| 1386 |
} |
| 1387 |
$menu = Fep_Menu::init()->get_menu(); |
| 1388 |
switch ( $action ) { |
| 1389 |
case has_action( "fep_posted_action_{$action}" ): |
| 1390 |
do_action( "fep_posted_action_{$action}" ); |
| 1391 |
break; |
| 1392 |
case ( 'newmessage' == $action && ! empty( $menu['newmessage'] ) ): |
| 1393 |
case 'shortcode-newmessage': |
| 1394 |
if ( ! fep_current_user_can( 'send_new_message' ) ) { |
| 1395 |
fep_errors()->add( 'permission', __( 'You do not have permission to send new message!', 'front-end-pm' ) ); |
| 1396 |
break; |
| 1397 |
} |
| 1398 |
Fep_Form::init()->validate_form_field( $action ); |
| 1399 |
if ( count( fep_errors()->get_error_messages() ) == 0 ) { |
| 1400 |
if ( $message_id = fep_send_message() ) { |
| 1401 |
if ( 'publish' == fep_get_message_status( $message_id ) ) { |
| 1402 |
fep_success()->add( 'publish', __( 'Message successfully sent.', 'front-end-pm' ) ); |
| 1403 |
} else { |
| 1404 |
fep_success()->add( 'pending', __( 'Message successfully sent and waiting for admin moderation.', 'front-end-pm' ) ); |
| 1405 |
} |
| 1406 |
} else { |
| 1407 |
fep_errors()->add( 'undefined', __( 'Something wrong. Please try again.', 'front-end-pm' ) ); |
| 1408 |
} |
| 1409 |
} |
| 1410 |
break; |
| 1411 |
case 'reply': |
| 1412 |
$parent_id = isset( $_POST['fep_parent_id'] ) ? absint( $_POST['fep_parent_id'] ) : 0; |
| 1413 |
if ( ! fep_current_user_can( 'send_reply', $parent_id ) ) { |
| 1414 |
fep_errors()->add( 'permission', __( 'You do not have permission to send reply to this message!', 'front-end-pm' ) ); |
| 1415 |
break; |
| 1416 |
} |
| 1417 |
Fep_Form::init()->validate_form_field( 'reply' ); |
| 1418 |
if ( 0 == count( fep_errors()->get_error_messages() ) ) { |
| 1419 |
if ( $message_id = fep_send_message() ) { |
| 1420 |
if ( 'publish' == fep_get_message_status( $message_id ) ) { |
| 1421 |
fep_success()->add( 'publish', __( 'Message successfully sent.', 'front-end-pm' ) ); |
| 1422 |
} else { |
| 1423 |
fep_success()->add( 'pending', __( 'Message successfully sent and waiting for admin moderation.', 'front-end-pm' ) ); |
| 1424 |
} |
| 1425 |
} else { |
| 1426 |
fep_errors()->add( 'undefined', __( 'Something wrong. Please try again.', 'front-end-pm' ) ); |
| 1427 |
} |
| 1428 |
} |
| 1429 |
break; |
| 1430 |
case 'bulk_action': |
| 1431 |
case 'announcement_bulk_action': |
| 1432 |
case 'directory_bulk_action': |
| 1433 |
$posted_bulk_action = ! empty( $_POST['fep-bulk-action'] ) ? $_POST['fep-bulk-action'] : ''; |
| 1434 |
if ( ! $posted_bulk_action ) { |
| 1435 |
break; |
| 1436 |
} |
| 1437 |
$token = ! empty( $_POST['token'] ) ? $_POST['token'] : ''; |
| 1438 |
if ( ! fep_verify_nonce( $token, $action ) ) { |
| 1439 |
fep_errors()->add( 'token', __( 'Invalid Token. Please try again!', 'front-end-pm' ) ); |
| 1440 |
break; |
| 1441 |
} |
| 1442 |
do_action( "fep_posted_bulk_{$action}", $posted_bulk_action ); |
| 1443 |
break; |
| 1444 |
default: |
| 1445 |
do_action( 'fep_posted_action' ); |
| 1446 |
break; |
| 1447 |
} |
| 1448 |
do_action( 'fep_posted_action_after', $action ); |
| 1449 |
|
| 1450 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 1451 |
$response = array(); |
| 1452 |
if ( count( fep_errors()->get_error_messages() ) > 0 ) { |
| 1453 |
$response['fep_return'] = 'error'; |
| 1454 |
} elseif ( count( fep_success()->get_error_messages() ) > 0 ) { |
| 1455 |
$response['fep_return'] = 'success'; |
| 1456 |
} else { |
| 1457 |
$response['fep_return'] = ''; |
| 1458 |
} |
| 1459 |
$response['info'] = fep_info_output(); |
| 1460 |
if( ! empty( $_POST['fep_redirect'] ) ) { |
| 1461 |
$response['fep_redirect'] = wp_validate_redirect( wp_sanitize_redirect( $_POST['fep_redirect'] ) ); |
| 1462 |
} |
| 1463 |
wp_send_json( $response ); |
| 1464 |
} elseif ( ! empty( $_POST['fep_redirect'] ) ) { |
| 1465 |
wp_safe_redirect( $_POST['fep_redirect'] ); |
| 1466 |
exit; |
| 1467 |
} |
| 1468 |
} |
| 1469 |
|
| 1470 |
function fep_get_participants( $message_id, $exclude_deleted = false ) { |
| 1471 |
if ( empty( $message_id ) || ! is_numeric( $message_id ) ) { |
| 1472 |
return array(); |
| 1473 |
} |
| 1474 |
|
| 1475 |
$participants = FEP_Participants::init()->get( $message_id, false, $exclude_deleted ); |
| 1476 |
$return = []; |
| 1477 |
|
| 1478 |
foreach( $participants as $participant ){ |
| 1479 |
$return[] = $participant->mgs_participant; |
| 1480 |
} |
| 1481 |
return $return; |
| 1482 |
} |
| 1483 |
|
| 1484 |
function fep_get_participant_roles( $announcement_id ) { |
| 1485 |
|
| 1486 |
$roles = fep_get_meta( $announcement_id, '_fep_participant_roles' ); |
| 1487 |
if( ! is_array( $roles ) ){ |
| 1488 |
$roles = []; |
| 1489 |
} |
| 1490 |
return $roles; |
| 1491 |
} |
| 1492 |
|
| 1493 |
function fep_get_message_view() { |
| 1494 |
$message_view = fep_get_option( 'message_view', 'threaded' ); |
| 1495 |
$message_view = apply_filters( 'fep_get_message_view', $message_view ); |
| 1496 |
if ( ! $message_view || ! in_array( $message_view, array( 'threaded', 'individual' ) ) ) { |
| 1497 |
$message_view = 'threaded'; |
| 1498 |
} |
| 1499 |
return $message_view; |
| 1500 |
} |
| 1501 |
|
| 1502 |
function fep_get_blocked_users_for_user( $userid = '' ) { |
| 1503 |
$return = array(); |
| 1504 |
if ( $blocked_users = fep_get_user_option( 'blocked_users', '', $userid ) ) { |
| 1505 |
$blocked_users = explode( ',', $blocked_users ); |
| 1506 |
$return = array_filter( array_map( 'absint', $blocked_users ) ); |
| 1507 |
} |
| 1508 |
return apply_filters( 'fep_get_blocked_users_for_user', $return, $userid ); |
| 1509 |
} |
| 1510 |
|
| 1511 |
function fep_is_user_blocked_for_user( $userid, $check_id = '' ) { |
| 1512 |
$blocked_users = fep_get_blocked_users_for_user( $userid ); |
| 1513 |
if ( ! $check_id ) { |
| 1514 |
$check_id = get_current_user_id(); |
| 1515 |
} |
| 1516 |
if ( in_array( $check_id, $blocked_users ) ) { |
| 1517 |
return true; |
| 1518 |
} |
| 1519 |
return false; |
| 1520 |
} |
| 1521 |
|
| 1522 |
function fep_block_users_for_user( $user_ids, $userid = '' ) { |
| 1523 |
if ( is_numeric( $user_ids ) ) { |
| 1524 |
$user_ids = array( $user_ids ); |
| 1525 |
} |
| 1526 |
if ( ! $user_ids || ! is_array( $user_ids ) ) { |
| 1527 |
return 0; |
| 1528 |
} |
| 1529 |
$blocked_users = fep_get_blocked_users_for_user( $userid ); |
| 1530 |
$need_block = array_diff( $user_ids, $blocked_users ); |
| 1531 |
if ( $need_block ) { |
| 1532 |
$blocked_users = array_unique( array_merge( $blocked_users, $need_block ) ); |
| 1533 |
fep_update_user_option( 'blocked_users', implode( ',', $blocked_users ) ); |
| 1534 |
} |
| 1535 |
return count( $need_block ); |
| 1536 |
} |
| 1537 |
|
| 1538 |
function fep_unblock_users_for_user( $user_ids, $userid = '' ) { |
| 1539 |
if ( is_numeric( $user_ids ) ) { |
| 1540 |
$user_ids = array( $user_ids ); |
| 1541 |
} |
| 1542 |
if ( ! $user_ids || ! is_array( $user_ids ) ) { |
| 1543 |
return 0; |
| 1544 |
} |
| 1545 |
$blocked_users = fep_get_blocked_users_for_user( $userid = '' ); |
| 1546 |
$need_unblock = array_intersect( $blocked_users, $user_ids ); |
| 1547 |
if ( $need_unblock ) { |
| 1548 |
$blocked_users = array_unique( array_diff( $blocked_users, $need_unblock ) ); |
| 1549 |
fep_update_user_option( 'blocked_users', implode( ',', $blocked_users ) ); |
| 1550 |
} |
| 1551 |
return count( $need_unblock ); |
| 1552 |
} |
| 1553 |
|
| 1554 |
function fep_sanitize_html_class( $class ) { |
| 1555 |
if ( $class ) { |
| 1556 |
if ( ! is_array( $class ) ) { |
| 1557 |
$class = explode( ' ', $class ); |
| 1558 |
} |
| 1559 |
$class = array_map( 'sanitize_html_class', $class ); |
| 1560 |
$class = implode( ' ', array_unique( array_filter( $class ) ) ); |
| 1561 |
} |
| 1562 |
if ( ! is_string( $class ) ) { |
| 1563 |
$class = ''; |
| 1564 |
} |
| 1565 |
return apply_filters( 'fep_sanitize_html_class', $class ); |
| 1566 |
} |
| 1567 |
|
| 1568 |
function fep_show_unread_count_in_title( $title ) { |
| 1569 |
if ( fep_get_option( 'show_unread_count_in_title', 1 ) && fep_current_user_can( 'access_message' ) ) { |
| 1570 |
wp_enqueue_script( 'fep-notification-script' ); |
| 1571 |
if ( $count = fep_get_new_message_number() ) { |
| 1572 |
$count = number_format_i18n( $count ); |
| 1573 |
$title['title'] = "($count) " . $title['title']; |
| 1574 |
} |
| 1575 |
} |
| 1576 |
return $title; |
| 1577 |
} |
| 1578 |
|
| 1579 |
function fep_pre_get_document_title( $title ) { |
| 1580 |
if ( ! empty( $title ) && fep_get_option( 'show_unread_count_in_title', 1 ) && fep_current_user_can( 'access_message' ) ) { |
| 1581 |
wp_enqueue_script( 'fep-notification-script' ); |
| 1582 |
if ( $count = fep_get_new_message_number() ) { |
| 1583 |
$count = number_format_i18n( $count ); |
| 1584 |
$title = "($count) " . $title; |
| 1585 |
} |
| 1586 |
} |
| 1587 |
return $title; |
| 1588 |
} |
| 1589 |
|
| 1590 |
function fep_is_func_disabled( $function ) { |
| 1591 |
$disabled = explode( ',', ini_get( 'disable_functions' ) ); |
| 1592 |
return in_array( $function, $disabled ); |
| 1593 |
} |
| 1594 |
|
| 1595 |
//new |
| 1596 |
|
| 1597 |
function fep_set_current_message( $message ){ |
| 1598 |
global $fep_message; |
| 1599 |
if( $message instanceof FEP_Message ){ |
| 1600 |
$fep_message = $message; |
| 1601 |
} else { |
| 1602 |
$fep_message = null; |
| 1603 |
} |
| 1604 |
return $fep_message; |
| 1605 |
} |
| 1606 |
|
| 1607 |
function fep_get_current_message(){ |
| 1608 |
global $fep_message; |
| 1609 |
if( isset( $fep_message ) && ( $fep_message instanceof FEP_Message ) ){ |
| 1610 |
return $fep_message; |
| 1611 |
} else { |
| 1612 |
return null; |
| 1613 |
} |
| 1614 |
} |
| 1615 |
|
| 1616 |
function fep_get_message_field( $field, $mgs_id = 0 ){ |
| 1617 |
if( $mgs_id && is_numeric( $mgs_id ) ){ |
| 1618 |
$message = fep_get_message( $mgs_id ); |
| 1619 |
} else { |
| 1620 |
$message = fep_get_current_message(); |
| 1621 |
} |
| 1622 |
$value = false; |
| 1623 |
if( $message && isset( $message->$field ) ){ |
| 1624 |
$value = $message->$field; |
| 1625 |
} |
| 1626 |
return apply_filters( 'fep_get_message_field', $value, $field, $mgs_id, $message ); |
| 1627 |
} |
| 1628 |
|
| 1629 |
function fep_get_the_id( $mgs_id = 0 ){ |
| 1630 |
$id = fep_get_message_field( 'mgs_id', $mgs_id ); |
| 1631 |
|
| 1632 |
return apply_filters( 'fep_get_the_id', (int) $id, $mgs_id ); |
| 1633 |
} |
| 1634 |
|
| 1635 |
function fep_get_the_title( $mgs_id = 0 ){ |
| 1636 |
$title = fep_get_message_field( 'mgs_title', $mgs_id ); |
| 1637 |
|
| 1638 |
return apply_filters( 'fep_get_the_title', $title, $mgs_id ); |
| 1639 |
} |
| 1640 |
|
| 1641 |
function fep_get_the_content( $mgs_id = 0 ){ |
| 1642 |
$content = fep_get_message_field( 'mgs_content', $mgs_id ); |
| 1643 |
|
| 1644 |
return apply_filters( 'fep_get_the_content', $content, $mgs_id ); |
| 1645 |
} |
| 1646 |
|
| 1647 |
function fep_get_the_excerpt( $mgs_id = 0 ){ |
| 1648 |
if( 'threaded' === fep_get_message_view() && 'message' === fep_get_message_field( 'mgs_type', $mgs_id ) ){ |
| 1649 |
$excerpt = fep_get_message_field( 'mgs_last_reply_excerpt', $mgs_id ); |
| 1650 |
} else { |
| 1651 |
$excerpt = fep_get_the_excerpt_from_content( 100, fep_get_message_field( 'mgs_content', $mgs_id ) ); |
| 1652 |
} |
| 1653 |
|
| 1654 |
return apply_filters( 'fep_get_the_excerpt', $excerpt, $mgs_id ); |
| 1655 |
} |
| 1656 |
|
| 1657 |
function fep_get_message_status( $mgs_id = 0 ){ |
| 1658 |
$status = fep_get_message_field( 'mgs_status', $mgs_id ); |
| 1659 |
|
| 1660 |
return apply_filters( 'fep_get_message_status', $status, $mgs_id ); |
| 1661 |
} |
| 1662 |
|
| 1663 |
function fep_get_the_date( $which = 'created', $mgs_id = 0 ){ |
| 1664 |
if( 'created' == $which ){ |
| 1665 |
$field = 'mgs_created'; |
| 1666 |
} else { |
| 1667 |
$field = 'mgs_last_reply_time'; |
| 1668 |
} |
| 1669 |
$date = fep_get_message_field( $field, $mgs_id ); |
| 1670 |
if( ! $date ){ |
| 1671 |
$date = '0000-00-00 00:00:00'; |
| 1672 |
} |
| 1673 |
|
| 1674 |
return apply_filters( 'fep_get_the_date', $date, $which, $mgs_id ); |
| 1675 |
} |
| 1676 |
|
| 1677 |
function fep_participants_view( $mgs_id = 0 ) { |
| 1678 |
$wp_roles = wp_roles(); |
| 1679 |
|
| 1680 |
if( 'announcement' == fep_get_message_field( 'mgs_type', $mgs_id ) ){ |
| 1681 |
$roles = fep_get_participant_roles( fep_get_the_id( $mgs_id ) ); |
| 1682 |
foreach( $roles as $role ){ |
| 1683 |
if( $wp_roles->is_role( $role ) ) |
| 1684 |
echo translate_user_role( $wp_roles->roles[ $role ]['name'] ) .'<br />'; |
| 1685 |
} |
| 1686 |
} elseif( 'message' == fep_get_message_field( 'mgs_type', $mgs_id ) ){ |
| 1687 |
if( $group = apply_filters( 'fep_is_group_message', false, $mgs_id ) ){ |
| 1688 |
echo esc_html( $group ); |
| 1689 |
} elseif( $recipients = fep_get_participants( fep_get_the_id( $mgs_id ) ) ){ |
| 1690 |
foreach ( $recipients as $recipient ) { |
| 1691 |
if( fep_get_message_field( 'mgs_author', $mgs_id ) != $recipient ) |
| 1692 |
echo fep_user_name( $recipient ) . '<br />'; |
| 1693 |
} |
| 1694 |
} |
| 1695 |
} |
| 1696 |
} |
| 1697 |
|
| 1698 |
function fep_get_statuses( $for = 'message' ){ |
| 1699 |
$statuses = [ |
| 1700 |
'pending' => __('Pending', 'front-end-pm' ), |
| 1701 |
'publish' => __('Publish', 'front-end-pm' ), |
| 1702 |
]; |
| 1703 |
return apply_filters( 'fep_get_statuses', $statuses, $for ); |
| 1704 |
} |
| 1705 |
|
| 1706 |
function fep_recursive_remove_directory( $directory ) { |
| 1707 |
foreach ( glob( "{$directory}/*" ) as $file ) { |
| 1708 |
if ( is_dir( $file ) ) { |
| 1709 |
fep_recursive_remove_directory( $file ); |
| 1710 |
} else { |
| 1711 |
unlink( $file ); |
| 1712 |
} |
| 1713 |
} |
| 1714 |
rmdir( $directory ); |
| 1715 |
} |
| 1716 |
|
| 1717 |
function fep_fs_uninstall_cleanup() { |
| 1718 |
global $wpdb; |
| 1719 |
|
| 1720 |
$fep_options = get_option( 'FEP_admin_options' ); |
| 1721 |
|
| 1722 |
if ( is_array( $fep_options ) && ! empty( $fep_options['delete_data_on_uninstall'] ) ) { |
| 1723 |
|
| 1724 |
/** Delete all the Plugin Options */ |
| 1725 |
delete_option( 'FEP_admin_options' ); |
| 1726 |
delete_option( 'fep_updated_versions' ); |
| 1727 |
delete_site_option( 'fep_db_version' ); |
| 1728 |
|
| 1729 |
delete_metadata( 'user', 0, 'FEP_user_options', '', true ); |
| 1730 |
delete_metadata( 'user', 0, '_fep_user_message_count', '', true ); |
| 1731 |
delete_metadata( 'user', 0, '_fep_user_announcement_count', '', true ); |
| 1732 |
delete_metadata( 'user', 0, '_fep_notification_dismiss', '', true ); |
| 1733 |
|
| 1734 |
// Remove all database tables of Front End PM (if any). |
| 1735 |
$fep_tables = [ |
| 1736 |
'message' => defined( 'FEP_MESSAGE_TABLE' ) ? FEP_MESSAGE_TABLE : $wpdb->base_prefix . 'fep_messages', |
| 1737 |
'meta' => defined( 'FEP_META_TABLE' ) ? FEP_META_TABLE : $wpdb->base_prefix . 'fep_messagemeta', |
| 1738 |
'participants' => defined( 'FEP_PARTICIPANT_TABLE' ) ? FEP_PARTICIPANT_TABLE : $wpdb->base_prefix . 'fep_participants', |
| 1739 |
'attachments' => defined( 'FEP_ATTACHMENT_TABLE' ) ? FEP_ATTACHMENT_TABLE : $wpdb->base_prefix . 'fep_attachments', |
| 1740 |
]; |
| 1741 |
foreach ( $fep_tables as $fep_table ) { |
| 1742 |
$wpdb->query( "DROP TABLE IF EXISTS $fep_table" ); |
| 1743 |
} |
| 1744 |
|
| 1745 |
// Need to improve delete attachments files for multisite. |
| 1746 |
if( ! is_multisite() ){ |
| 1747 |
$wp_upload_dir = wp_upload_dir(); |
| 1748 |
if ( $wp_upload_dir && false === $wp_upload_dir['error'] ) { |
| 1749 |
fep_recursive_remove_directory( $wp_upload_dir['basedir'] . '/front-end-pm' ); |
| 1750 |
} |
| 1751 |
} |
| 1752 |
|
| 1753 |
// Remove any transients we've left behind |
| 1754 |
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_fep\_%'" ); |
| 1755 |
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_timeout\_fep\_%'" ); |
| 1756 |
} |
| 1757 |
} |
| 1758 |
|
| 1759 |
function fep_fs_support_forum_url( $wp_org_support_forum_url ) { |
| 1760 |
return 'https://www.shamimsplugins.com/support/forum/front-end-pm-pro/'; |
| 1761 |
} |
| 1762 |
|
| 1763 |
function fep_create_htaccess_index( $path ) { |
| 1764 |
if ( wp_is_writable( $path ) ) { |
| 1765 |
wp_mkdir_p( $path ); |
| 1766 |
|
| 1767 |
if( ! file_exists( $path . '/.htaccess' ) ){ |
| 1768 |
// Create the file if it doesn't exist |
| 1769 |
file_put_contents( $path . '/.htaccess', "Options -Indexes\ndeny from all\n" ); |
| 1770 |
} |
| 1771 |
if( ! file_exists( $path . '/index.php' ) ){ |
| 1772 |
// Create the file if it doesn't exist |
| 1773 |
file_put_contents( $path . '/index.php', "<?php\n// Silence is golden." ); |
| 1774 |
} |
| 1775 |
|
| 1776 |
} |
| 1777 |
} |
| 1778 |
|
| 1779 |
|