PluginProbe
Front End PM / 7.3
Front End PM v7.3
trunk 1.1 1.2 1.3 10.1.1 10.1.2 10.1.3 10.1.4 10.1.5 10.1.6 10.1.7 10.2.1 11.1.1 11.2.1 11.2.2 11.2.3 11.3.1 11.3.3 11.3.4 11.3.5 11.3.6 11.3.7 11.3.8 11.3.9 11.4.1 All 58 releases
← All changes | functions.php +1465 -1254 trunk7.3 View file →
@@ -1,353 +1,338 @@
1 1 <?php
2 +
2 3 if ( ! defined( 'ABSPATH' ) ) {
3 4 exit; // Exit if accessed directly.
4 5 }
5 6
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 - }
7 +function fep_plugin_activate(){
19 8
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' );
9 + _deprecated_function( __FUNCTION__, '4.4' );
10 + //Deprecated in 4.4
11 + //Move inside Front_End_Pm class
103 12
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 13 }
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 14
135 15 function fep_get_option( $option, $default = '', $section = 'FEP_admin_options' ) {
136 - $options = get_option( $section );
137 - if ( ! is_array( $options ) ) {
16 +
17 + $options = get_option( $section );
18 +
19 + if( ! is_array( $options ) )
138 20 $options = array();
139 - }
140 21
141 22 $is_default = false;
142 - if ( isset( $options[ $option ] ) ) {
143 - $value = $options[ $option ];
144 - } else {
23 +
24 + if ( isset( $options[$option] ) ) {
25 + $value = $options[$option];
26 + } else {
145 27 $value = $default;
146 28 $is_default = true;
147 29 }
148 - return apply_filters( 'fep_get_option', $value, $option, $default, $is_default );
30 +
31 + return apply_filters('fep_get_option', $value, $option, $default, $is_default );
149 32 }
150 33
151 34 function fep_update_option( $option, $value = '', $section = 'FEP_admin_options' ) {
152 - if ( empty( $option ) ) {
35 +
36 + if( empty( $option ) )
153 37 return false;
154 - }
155 - if ( ! is_array( $option ) ) {
38 + if( ! is_array( $option ) )
156 39 $option = array( $option => $value );
157 - }
40 +
41 + $options = get_option( $section );
42 +
43 + if( ! is_array( $options ) )
44 + $options = array();
158 45
159 - $options = get_option( $section );
160 - if ( ! is_array( $options ) ) {
161 - $options = array();
162 - }
163 - return update_option( $section, wp_parse_args( $option, $options ) );
46 + return update_option( $section, wp_parse_args( $option, $options ) );
164 47 }
165 48
166 49 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 {
50 +
51 + $options = get_user_option( $section, $userid ); //if $userid = '' current user option will be return
52 +
53 + $is_default = false;
54 +
55 + if ( isset( $options[$option] ) ) {
56 + $value = $options[$option];
57 + } else {
175 58 $value = $default;
176 59 $is_default = true;
177 60 }
178 - return apply_filters( 'fep_get_user_option', $value, $option, $default, $userid, $is_default );
61 +
62 + return apply_filters('fep_get_user_option', $value, $option, $default, $userid, $is_default );
179 63 }
180 64
181 65 function fep_update_user_option( $option, $value = '', $userid = '', $section = 'FEP_user_options' ) {
182 - if ( empty( $option ) ) {
66 +
67 + if( empty( $option ) )
183 68 return false;
69 +
70 + if( ! is_array( $option ) )
71 + $option = array( $option => $value );
72 +
73 + if( ! $userid )
74 + $userid = get_current_user_id();
75 +
76 + $options = get_user_option( $section, $userid );
77 +
78 + if( ! is_array( $options ) )
79 + $options = array();
80 +
81 + return update_user_option( $userid, $section, wp_parse_args( $option, $options ) );
82 +}
83 +
84 +if ( !function_exists('fep_get_plugin_caps') ) :
85 +
86 +function fep_get_plugin_caps( $edit_published = false, $for = 'both' ){
87 + $message_caps = array(
88 + 'delete_published_fep_messages' => 1,
89 + 'delete_private_fep_messages' => 1,
90 + 'delete_others_fep_messages' => 1,
91 + 'delete_fep_messages' => 1,
92 + 'publish_fep_messages' => 1,
93 + 'read_private_fep_messages' => 1,
94 + 'edit_private_fep_messages' => 1,
95 + 'edit_others_fep_messages' => 1,
96 + 'edit_fep_messages' => 1,
97 + 'create_fep_messages' => 1,
98 + );
99 +
100 + $announcement_caps = array(
101 + 'delete_published_fep_announcements' => 1,
102 + 'delete_private_fep_announcements' => 1,
103 + 'delete_others_fep_announcements' => 1,
104 + 'delete_fep_announcements' => 1,
105 + 'publish_fep_announcements' => 1,
106 + 'read_private_fep_announcements' => 1,
107 + 'edit_private_fep_announcements' => 1,
108 + 'edit_others_fep_announcements' => 1,
109 + 'edit_fep_announcements' => 1,
110 + 'create_fep_announcements' => 1,
111 + );
112 +
113 + if( 'fep_message' == $for ) {
114 + $caps = $message_caps;
115 + if( $edit_published ) {
116 + $caps['edit_published_fep_messages'] = 1;
117 + }
118 + } elseif( 'fep_announcement' == $for ){
119 + $caps = $announcement_caps;
120 + if( $edit_published ) {
121 + $caps['edit_published_fep_announcements'] = 1;
122 + }
123 + } else {
124 + $caps = array_merge( $message_caps, $announcement_caps );
125 + if( $edit_published ) {
126 + $caps['edit_published_fep_messages'] = 1;
127 + $caps['edit_published_fep_announcements'] = 1;
128 + }
184 129 }
185 - if ( ! is_array( $option ) ) {
186 - $option = array( $option => $value );
130 + return $caps;
131 +}
132 +
133 +endif;
134 +
135 +if ( !function_exists('fep_add_caps_to_roles') ) :
136 +
137 +function fep_add_caps_to_roles( $roles = array( 'administrator', 'editor' ), $edit_published = true ) {
138 +
139 + if( ! is_array( $roles ) )
140 + $roles = array();
141 +
142 + $caps = fep_get_plugin_caps( $edit_published );
143 +
144 + foreach( $roles as $role ) {
145 + $role_obj = get_role( $role );
146 + if( !$role_obj )
147 + continue;
148 +
149 + foreach( $caps as $cap => $val ) {
150 + if( $val )
151 + $role_obj->add_cap( $cap );
152 + }
187 153 }
188 - if ( ! $userid ) {
189 - $userid = get_current_user_id();
154 +}
155 +
156 +endif;
157 +
158 +if ( defined( 'WP_UNINSTALL_PLUGIN' ) ) return;
159 +
160 +add_action('after_setup_theme', 'fep_include_require_files');
161 +
162 +function fep_include_require_files() {
163 +
164 + $fep_files = array(
165 + 'announcement' => FEP_PLUGIN_DIR. 'includes/class-fep-announcement.php',
166 + 'attachment' => FEP_PLUGIN_DIR. 'includes/class-fep-attachment.php',
167 + 'cpt' => FEP_PLUGIN_DIR. 'includes/class-fep-cpt.php',
168 + 'directory' => FEP_PLUGIN_DIR. 'includes/class-fep-directory.php',
169 + 'email' => FEP_PLUGIN_DIR. 'includes/class-fep-emails.php',
170 + 'form' => FEP_PLUGIN_DIR. 'includes/class-fep-form.php',
171 + 'menu' => FEP_PLUGIN_DIR. 'includes/class-fep-menu.php',
172 + 'message' => FEP_PLUGIN_DIR. 'includes/class-fep-message.php',
173 + 'shortcodes' => FEP_PLUGIN_DIR. 'includes/class-fep-shortcodes.php',
174 + 'user-settings' => FEP_PLUGIN_DIR. 'includes/class-fep-user-settings.php',
175 + 'main' => FEP_PLUGIN_DIR. 'includes/fep-class.php',
176 + 'widgets' => FEP_PLUGIN_DIR. 'includes/fep-widgets.php'
177 + );
178 + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
179 + $fep_files['ajax'] = FEP_PLUGIN_DIR. 'includes/class-fep-ajax.php';
190 180 }
181 +
182 + if( is_admin() ) {
183 + $fep_files['settings'] = FEP_PLUGIN_DIR. 'admin/class-fep-admin-settings.php';
184 + $fep_files['update'] = FEP_PLUGIN_DIR. 'admin/class-fep-update.php';
185 + $fep_files['pro-info'] = FEP_PLUGIN_DIR. 'admin/class-fep-pro-info.php';
186 + }
187 +
188 + $fep_files = apply_filters('fep_include_files', $fep_files );
191 189
192 - $options = get_user_meta( $userid, $section, true );
193 - if ( ! is_array( $options ) ) {
194 - $options = array();
190 + foreach ( $fep_files as $fep_file ) {
191 + require_once( $fep_file );
192 + }
193 +}
194 +
195 +function fep_plugin_update(){
196 +
197 + _deprecated_function( __FUNCTION__, '4.9', 'Fep_Update class' );
198 +
199 + $prev_ver = fep_get_option( 'plugin_version', '4.1' );
200 +
201 + if( version_compare( $prev_ver, FEP_PLUGIN_VERSION, '!=' ) ) {
202 +
203 + do_action( 'fep_plugin_update', $prev_ver );
204 +
205 + fep_update_option( 'plugin_version', FEP_PLUGIN_VERSION );
195 206 }
196 - return update_user_meta( $userid, $section, wp_parse_args( $option, $options ) );
207 +
197 208 }
198 209
199 -function fep_translation() {
200 - // SETUP TEXT DOMAIN FOR TRANSLATIONS
201 - load_plugin_textdomain( 'front-end-pm', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
210 +function fep_plugin_update_from_first( $prev_ver ){
211 +
212 + if( is_admin() && '4.1' == $prev_ver ) { //any previous version of 4.1 also return 4.1
213 + fep_plugin_activate();
214 + }
215 +
202 216 }
217 +add_action( 'fep_plugin_update', 'fep_plugin_update_from_first' );
203 218
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' ) ) {
219 +add_action('after_setup_theme', 'fep_translation');
220 +
221 +function fep_translation()
222 + {
223 + //SETUP TEXT DOMAIN FOR TRANSLATIONS
224 + load_plugin_textdomain('front-end-pm', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
225 + }
226 +
227 +add_action('wp_enqueue_scripts', 'fep_enqueue_scripts');
228 +
229 +function fep_enqueue_scripts()
230 + {
231 +
232 + wp_register_style( 'fep-common-style', FEP_PLUGIN_URL . 'assets/css/common-style.css', array(), '7.1' );
233 + wp_register_style( 'fep-style', FEP_PLUGIN_URL . 'assets/css/style.css', array(), '7.1' );
234 + wp_register_style( 'fep-tokeninput-style', FEP_PLUGIN_URL . 'assets/css/token-input-facebook.css' );
235 +
236 + if( 'always' == fep_get_option('load_css','only_in_message_page') ){
208 237 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() ) ) ) {
238 + } elseif( 'only_in_message_page' == fep_get_option('load_css','only_in_message_page') && fep_page_id() && ( is_page( fep_page_id() ) || is_single( fep_page_id() ) ) ){
211 239 wp_enqueue_style( 'fep-style' );
212 240 }
213 241 wp_enqueue_style( 'fep-common-style' );
214 242
215 - $important = '';
216 -
217 - if ( apply_filters( 'fep_add_important_to_inline_css', false ) ) {
218 - $important = ' !important';
219 - }
220 -
221 243 $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 . ';';
244 + $custom_css .= 'background-color:' . fep_get_option('bg_color') . ';';
245 + $custom_css .= 'color:' . fep_get_option('text_color','#000000') . ';';
224 246 $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 . ';';
247 + $custom_css .= '#fep-wrapper a:not(.fep-button,.fep-button-active){color:' . fep_get_option('link_color','#000080') . ';}';
248 + $custom_css .= '.fep-button{';
249 + $custom_css .= 'background-color:' . fep_get_option('btn_bg_color', '#F0FCFF') . ';';
250 + $custom_css .= 'color:' . fep_get_option('btn_text_color','#000000') . ';';
229 251 $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 . ';';
252 + $custom_css .= '.fep-button:hover,.fep-button-active{';
253 + $custom_css .= 'background-color:' . fep_get_option('active_btn_bg_color','#D3EEF5') . ';';
254 + $custom_css .= 'color:' . fep_get_option('active_btn_text_color','#000000') . ';';
233 255 $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 ) {
256 + $custom_css .= '.fep-odd-even > div:nth-child(odd){background-color:' . fep_get_option('odd_color','#F2F7FC') . ';}';
257 + $custom_css .= '.fep-odd-even > div:nth-child(even){background-color:' . fep_get_option('even_color','#FAFAFA') . ';}';
258 + $custom_css .= '.fep-message .fep-message-title-heading, .fep-per-message .fep-message-title{background-color:' . fep_get_option('mgs_heading_color','#F2F7FC') . ';}';
259 + $custom_css .= trim( stripslashes(fep_get_option('custom_css') ) );
260 + if( $custom_css ) {
243 261 wp_add_inline_style( 'fep-common-style', $custom_css );
244 262 }
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' ),
263 +
264 + wp_register_script( 'fep-script', FEP_PLUGIN_URL . 'assets/js/script.js', array( 'jquery' ), '3.1', true );
265 + wp_localize_script( 'fep-script', 'fep_script',
266 + array(
267 + 'ajaxurl' => admin_url( 'admin-ajax.php' ),
268 + 'nonce' => wp_create_nonce('fep-autosuggestion')
269 + )
270 + );
271 +
272 + wp_register_script( 'fep-notification-script', FEP_PLUGIN_URL . 'assets/js/notification.js', array( 'jquery' ), '7.2', true );
273 + $call_on_ready = ( isset($_GET['fepaction']) &&
274 + ( ( $_GET['fepaction'] == 'viewmessage' && fep_get_new_message_number() ) || ( $_GET['fepaction'] == 'view_announcement' && fep_get_new_announcement_number() ) )
275 + ) ? '1' : '0';
276 + wp_localize_script( 'fep-notification-script', 'fep_notification_script',
277 + apply_filters( 'fep_filter_notification_script_localize', array(
278 + 'ajaxurl' => admin_url( 'admin-ajax.php' ),
279 + 'nonce' => wp_create_nonce('fep-notification'),
280 + 'interval' => apply_filters( 'fep_filter_ajax_notification_interval', MINUTE_IN_SECONDS * 1000 ),
281 + 'skip' => apply_filters( 'fep_filter_skip_notification_call', 2 ), //How many times notification ajax call will be skipped if browser tab not opened
282 + 'show_in_title' => fep_get_option( 'show_unread_count_in_title', '1' ),
264 283 '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' ),
284 + 'call_on_ready' => apply_filters( 'fep_filter_notification_call_on_ready', $call_on_ready ),
285 + 'play_sound' => fep_get_option( 'play_sound', '1' ),
286 + 'sound_url' => FEP_PLUGIN_URL . 'assets/audio/plucky.mp3',
287 + 'icon_url' => FEP_PLUGIN_URL . 'assets/images/desktop-notification-32.png',
288 + 'mgs_notification_title'=> __('New Message.', 'front-end-pm'),
289 + 'mgs_notification_body' => __('You have received a new message.', 'front-end-pm'),
271 290 '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' ),
291 + 'ann_notification_title'=> __('New Announcement.', 'front-end-pm'),
292 + 'ann_notification_body' => __('You have received a new announcement.', 'front-end-pm'),
274 293 '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' );
294 + ))
295 + );
296 +
297 +
298 + wp_register_script( 'fep-replies-show-hide', FEP_PLUGIN_URL . 'assets/js/replies-show-hide.js', array( 'jquery' ), '3.1', true );
299 +
300 + wp_register_script( 'fep-attachment-script', FEP_PLUGIN_URL . 'assets/js/attachment.js', array( 'jquery' ), '6.1', true );
301 + wp_localize_script( 'fep-attachment-script', 'fep_attachment_script',
302 + array(
303 + 'remove' => esc_js(__('Remove', 'front-end-pm')),
304 + 'maximum' => esc_js( fep_get_option('attachment_no', 4 ) ),
305 + '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 )) ) ) )
306 +
307 + )
308 + );
309 + wp_register_script( 'fep-shortcode-newmessage', FEP_PLUGIN_URL . 'assets/js/shortcode-newmessage.js', array( 'jquery' ), '6.1', true );
310 + wp_localize_script( 'fep-shortcode-newmessage', 'fep_shortcode_newmessage',
311 + array(
312 + 'ajaxurl' => admin_url( 'admin-ajax.php' ),
313 + 'token' => wp_create_nonce('fep_message'),
314 + 'refresh_text' => __('Refresh this page and try again.', 'front-end-pm'),
315 + )
316 + );
315 317 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 + wp_register_script( 'fep-block-unblock-script', FEP_PLUGIN_URL . 'assets/js/block-unblock.js', array( 'jquery' ), '6.1', true );
319 + wp_localize_script( 'fep-block-unblock-script', 'fep_block_unblock_script',
320 + array(
321 + 'ajaxurl' => admin_url( 'admin-ajax.php' ),
322 + 'token' => wp_create_nonce('fep-block-unblock-script')
323 + )
324 + );
325 + }
318 326
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 327 function fep_page_id() {
345 - return (int) apply_filters( 'fep_page_id_filter', fep_get_option( 'page_id', 0 ) );
328 +
329 + return (int) apply_filters( 'fep_page_id_filter', fep_get_option('page_id', 0 ) );
346 330 }
347 331
348 332 function fep_action_url( $action = '', $arg = array() ) {
349 - return fep_query_url( $action, $arg );
333 +
334 + return fep_query_url( $action, $arg );
350 335 }
351 336
352 337 function fep_query_url( $action, $arg = array() ) {
353 338 $args = array( 'fepaction' => $action );
@@ -352,468 +337,513 @@
352 337 function fep_query_url( $action, $arg = array() ) {
353 338 $args = array( 'fepaction' => $action );
354 339 $args = array_merge( $args, $arg );
355 340 $url = esc_url( fep_query_url_without_esc( $action, $arg ) );
341 +
356 342 return apply_filters( 'fep_query_url_filter', $url, $args );
357 343 }
358 344
359 -function fep_query_url_raw( $action, $arg = array() ) {
360 - return esc_url_raw( fep_query_url_without_esc( $action, $arg ) );
361 -}
362 -
363 345 function fep_query_url_without_esc( $action, $arg = array() ) {
346 +
364 347 $args = array( 'fepaction' => $action );
365 348 $args = array_merge( $args, $arg );
349 +
366 350 if ( fep_page_id() ) {
367 351 $url = add_query_arg( $args, get_permalink( fep_page_id() ) );
368 352 } else {
369 353 $url = add_query_arg( $args );
370 354 }
355 +
371 356 return apply_filters( 'fep_query_url_without_esc_filter', $url, $args );
372 357 }
373 358
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 - }
359 +if ( !function_exists('fep_create_nonce') ) :
360 + /**
361 + * Creates a token usable in a form
362 + * return nonce with time
363 + * @return string
364 + */
365 + function fep_create_nonce($action = -1) {
366 + $time = time();
367 + $nonce = wp_create_nonce($time.$action);
368 + return $nonce . '-' . $time;
369 + }
370 +
385 371 endif;
386 372
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 - */
373 +if ( !function_exists('fep_verify_nonce') ) :
374 + /**
375 + * Check if a token is valid. Mark it as used
376 + * @param string $_nonce The token
377 + * @return bool
378 + */
393 379 function fep_verify_nonce( $_nonce, $action = -1) {
394 - $parts = explode( '-', $_nonce ); // Extract timestamp and nonce part of $_nonce
395 380
396 - // bad formatted onetime-nonce
397 - if ( empty( $parts[0] ) || empty( $parts[1] ) ) {
398 - return false;
381 + //Extract timestamp and nonce part of $_nonce
382 + $parts = explode( '-', $_nonce );
383 +
384 + // bad formatted onetime-nonce
385 + if ( empty( $parts[0] ) || empty( $parts[1] ) )
386 + return false;
387 +
388 + $nonce = $parts[0]; // Original nonce generated by WordPress.
389 + $generated = $parts[1]; //Time when generated
390 +
391 + $expire = (int) $generated + HOUR_IN_SECONDS; //We want these nonces to have a short lifespan
392 + $time = time();
393 +
394 + //Verify the nonce part and check that it has not expired
395 + if( ! wp_verify_nonce( $nonce, $generated.$action ) || $time > $expire )
396 + return false;
397 +
398 + //Get used nonces
399 + $used_nonces = get_option('_fep_used_nonces');
400 +
401 + if(! is_array( $used_nonces ) )
402 + $used_nonces = array();
403 +
404 + //Nonce already used.
405 + if( isset( $used_nonces[$nonce] ) )
406 + return false;
407 +
408 + foreach ($used_nonces as $nonces => $timestamp){
409 + if( $timestamp < $time ){
410 + //This nonce has expired, so we don't need to keep it any longer
411 + unset( $used_nonces[$nonces] );
399 412 }
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();
413 + }
404 414
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 - }
415 + //Add nonce to used nonces
416 + $used_nonces[$nonce] = $expire;
417 + update_option( '_fep_used_nonces', $used_nonces, 'no' );
418 + return true;
419 +}
430 420 endif;
431 421
432 -function fep_error( $wp_error) {
433 - if ( ! is_wp_error( $wp_error) ) {
422 +function fep_error($wp_error){
423 + if(!is_wp_error($wp_error)){
434 424 return '';
435 425 }
436 - if ( 0 == count( $wp_error->get_error_messages() ) ) {
426 + if(count($wp_error->get_error_messages())==0){
437 427 return '';
438 428 }
439 429 $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">';
430 + if (is_admin())
431 + $html = '<div id="message" class="error">';
432 + else
433 + $html = '<div class="fep-wp-error">';
434 + foreach($errors as $error){
435 + $html .= '<strong>' . __('Error', 'front-end-pm') . ': </strong>'.esc_html($error).'<br />';
444 436 }
445 - foreach ( $errors as $error) {
446 - $html .= '<strong>' . __( 'Error', 'front-end-pm' ) . ': </strong>' . esc_html( $error ) . '<br />';
447 - }
448 437 $html .= '</div>';
449 438 return $html;
450 439 }
451 440
452 -function fep_get_new_message_number() {
453 - return fep_get_user_message_count( 'unread' );
454 -}
441 +function fep_get_new_message_number()
442 + {
443 +
444 + return fep_get_user_message_count( 'unread' );
445 + }
455 446
456 -function fep_get_new_message_button( $args = array() ) {
457 - if ( ! fep_current_user_can( 'access_message' ) ) {
458 - return '';
459 - }
447 +function fep_get_new_message_button( $args = array() ){
448 + if ( ! fep_current_user_can( 'access_message' ) )
449 + return '';
450 +
460 451 $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'] ) {
452 + 'show_bracket' => '1',
453 + 'hide_if_zero' => '1',
454 + 'ajax' => '1',
455 + 'class' => 'fep-font-red',
456 + ) );
457 +
458 + $new = fep_get_new_message_number();
459 +
460 + if( empty( $args['ajax'] ) ){
461 + if( ! $new && $args['hide_if_zero'] ){
470 462 return '';
471 463 }
472 464 $ret = '';
473 - if ( $args['show_bracket'] ) {
474 - $ret .= '( ';
465 +
466 + if( $args['show_bracket'] ){
467 + $ret .= '(';
475 468 }
476 469 $ret .= '<span class="' . $args['class'] . '">' . $new . '</span>';
477 - if ( $args['show_bracket'] ) {
478 - $ret .= ' )';
470 + if( $args['show_bracket'] ){
471 + $ret .= ')';
479 472 }
473 +
480 474 return $ret;
481 475 }
476 +
482 477 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';
478 +
479 + $args['class'] = $args['class'] . ' fep_unread_message_count';
480 +
481 + if( $args['hide_if_zero'] ){
482 + $args['class'] = $args['class'] . ' fep_unread_message_count_hide_if_zero';
486 483 }
484 +
487 485 $ret = '';
488 - if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) {
486 +
487 + if( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ){
489 488 $ret .= '<span class="fep_unread_message_count_hide_if_zero fep-hide">(</span>';
490 - } elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) {
489 + } elseif( $args['show_bracket'] && $args['hide_if_zero'] ){
491 490 $ret .= '<span class="fep_unread_message_count_hide_if_zero">(</span>';
492 - } elseif ( $args['show_bracket'] ) {
493 - $ret .= '( ';
491 + } elseif( $args['show_bracket'] ){
492 + $ret .= '(';
494 493 }
495 - if ( ! $new && $args['hide_if_zero'] ) {
496 - $args['class'] = $args['class'] . ' fep-hide';
494 + if( ! $new && $args['hide_if_zero'] ){
495 + $args['class'] = $args['class'] . ' fep-hide';
497 496 }
498 497 $ret .= '<span class="' . $args['class'] . '">' . $new . '</span>';
499 - if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) {
498 +
499 + if( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ){
500 500 $ret .= '<span class="fep_unread_message_count_hide_if_zero fep-hide">)</span>';
501 - } elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) {
501 + } elseif( $args['show_bracket'] && $args['hide_if_zero'] ){
502 502 $ret .= '<span class="fep_unread_message_count_hide_if_zero">)</span>';
503 - } elseif ( $args['show_bracket'] ) {
504 - $ret .= ' )';
503 + } elseif( $args['show_bracket'] ){
504 + $ret .= ')';
505 505 }
506 +
506 507 return $ret;
507 508 }
508 509
509 -function fep_get_new_announcement_number() {
510 - return fep_get_user_announcement_count( 'unread' );
511 -}
510 +function fep_get_new_announcement_number()
511 + {
512 512
513 -function fep_get_new_announcement_button( $args = array() ) {
514 - if ( ! fep_current_user_can( 'access_message' ) ) {
515 - return '';
516 - }
513 + return fep_get_user_announcement_count( 'unread' );
514 + }
515 +
516 +function fep_get_new_announcement_button( $args = array() ){
517 + if ( ! fep_current_user_can( 'access_message' ) )
518 + return '';
519 +
517 520 $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'] ) {
521 + 'show_bracket' => '1',
522 + 'hide_if_zero' => '1',
523 + 'ajax' => '1',
524 + 'class' => 'fep-font-red',
525 + ) );
526 +
527 + $new = fep_get_new_announcement_number();
528 +
529 + if( empty( $args['ajax'] ) ){
530 + if( ! $new && $args['hide_if_zero'] ){
527 531 return '';
528 532 }
529 533 $ret = '';
530 - if ( $args['show_bracket'] ) {
531 - $ret .= '( ';
534 +
535 + if( $args['show_bracket'] ){
536 + $ret .= '(';
532 537 }
533 538 $ret .= '<span class="' . $args['class'] . '">' . $new . '</span>';
534 - if ( $args['show_bracket'] ) {
535 - $ret .= ' )';
539 + if( $args['show_bracket'] ){
540 + $ret .= ')';
536 541 }
542 +
537 543 return $ret;
538 544 }
545 +
539 546 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';
547 +
548 + $args['class'] = $args['class'] . ' fep_unread_announcement_count';
549 +
550 + if( $args['hide_if_zero'] ){
551 + $args['class'] = $args['class'] . ' fep_unread_announcement_count_hide_if_zero';
543 552 }
553 +
544 554 $ret = '';
545 - if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) {
555 +
556 + if( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ){
546 557 $ret .= '<span class="fep_unread_announcement_count_hide_if_zero fep-hide">(</span>';
547 - } elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) {
558 + } elseif( $args['show_bracket'] && $args['hide_if_zero'] ){
548 559 $ret .= '<span class="fep_unread_announcement_count_hide_if_zero">(</span>';
549 - } elseif ( $args['show_bracket'] ) {
550 - $ret .= '( ';
560 + } elseif( $args['show_bracket'] ){
561 + $ret .= '(';
551 562 }
552 - if ( ! $new && $args['hide_if_zero'] ) {
553 - $args['class'] = $args['class'] . ' fep-hide';
563 + if( ! $new && $args['hide_if_zero'] ){
564 + $args['class'] = $args['class'] . ' fep-hide';
554 565 }
555 566 $ret .= '<span class="' . $args['class'] . '">' . $new . '</span>';
556 -
557 - if ( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ) {
567 +
568 + if( $args['show_bracket'] && $args['hide_if_zero'] && ! $new ){
558 569 $ret .= '<span class="fep_unread_announcement_count_hide_if_zero fep-hide">)</span>';
559 - } elseif ( $args['show_bracket'] && $args['hide_if_zero'] ) {
570 + } elseif( $args['show_bracket'] && $args['hide_if_zero'] ){
560 571 $ret .= '<span class="fep_unread_announcement_count_hide_if_zero">)</span>';
561 - } elseif ( $args['show_bracket'] ) {
562 - $ret .= ' )';
572 + } elseif( $args['show_bracket'] ){
573 + $ret .= ')';
563 574 }
575 +
564 576 return $ret;
565 577 }
566 578
567 -function fep_is_user_blocked( $login = '' ) {
579 +function fep_is_user_blocked( $login = '' ){
568 580 global $user_login;
569 - if ( ! $login && $user_login ) {
570 - $login = $user_login;
571 - }
572 - if ( $login ) {
573 - $wpusers = explode( ',', fep_get_option( 'have_permission' ) );
581 + if ( !$login && $user_login )
582 + $login = $user_login;
583 +
584 + if ($login){
585 + $wpusers = explode(',', fep_get_option('have_permission') );
586 +
574 587 $wpusers = array_map( 'trim', $wpusers );
575 - if ( in_array( $login, $wpusers) ) {
576 - return true;
577 - }
588 +
589 + if( in_array( $login, $wpusers) )
590 + return true;
578 591 } //User not logged in
579 592 return false;
580 593 }
581 594
582 -function fep_is_user_whitelisted( $login = '' ) {
595 +function fep_is_user_whitelisted( $login = '' ){
583 596 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 - }
597 + if ( !$login && $user_login )
598 + $login = $user_login;
599 +
600 + if ($login){
601 + $wpusers = explode(',', fep_get_option('whitelist_username') );
602 +
603 + $wpusers = array_map( 'trim', $wpusers );
604 +
605 + if(in_array( $login, $wpusers))
606 + return true;
593 607 } //User not logged in
594 608 return false;
595 609 }
596 610
597 -function fep_get_userdata( $data, $need = 'ID', $type = 'slug' ) {
598 - if ( ! $data ) {
599 - return '';
611 +function fep_get_userdata($data, $need = 'ID', $type = 'slug' )
612 + {
613 + if (!$data)
614 + return '';
615 +
616 + $type = strtolower($type);
617 +
618 + if( 'user_nicename' == $type )
619 + $type = 'slug';
620 +
621 + if ( !in_array($type, array ('id', 'slug', 'email', 'login' )))
622 + return '';
623 +
624 + $user = get_user_by( $type , $data);
625 +
626 + if ( $user && in_array($need, array('ID', 'user_login', 'display_name', 'user_email', 'user_nicename', 'user_registered' )))
627 + return $user->$need;
628 + else
629 + return '';
600 630 }
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;
631 +
632 +function fep_get_user_message_count( $value = 'all', $force = false, $user_id = false )
633 +{
634 + return Fep_Message::init()->user_message_count( $value, $force, $user_id );
635 +}
636 +
637 +function fep_get_user_announcement_count( $value = 'all', $force = false, $user_id = false )
638 +{
639 + return Fep_Announcement::init()->get_user_announcement_count( $value, $force, $user_id );
640 +}
641 +
642 +function fep_get_message( $id )
643 +{
644 + $post = get_post( $id );
645 +
646 + if( $post && in_array( get_post_type( $post ), array( 'fep_message', 'fep_announcement') ) ){
647 + return $post;
611 648 } else {
612 - return '';
649 + return null;
613 650 }
614 -}
615 651
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 652 }
638 653
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 );
654 +function fep_get_replies( $id )
655 +{
656 + $args = array(
657 + 'post_type' => 'fep_message',
658 + 'post_status' => 'publish',
659 + 'post_parent' => $id,
660 + 'posts_per_page' => -1,
661 + 'order'=> 'ASC'
662 + );
663 +
664 + $args = apply_filters( 'fep_filter_get_replies', $args );
665 +
666 + return new WP_Query( $args );
641 667 }
642 668
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 -}
669 +function fep_get_attachments( $post_id = 0, $fields = '' ) {
646 670
647 -function fep_get_message( $id ) {
648 - return FEP_Message::get_instance( $id );
671 + if( ! $post_id ) {
672 + $post_id = get_the_ID();
673 + }
674 +
675 + if( ! $post_id ) {
676 + return array();
677 + }
678 + $args = array(
679 + 'post_type' => 'attachment',
680 + 'posts_per_page' => -1,
681 + 'post_status' => array( 'publish', 'inherit' ),
682 + 'post_parent' => $post_id,
683 + 'fields' => $fields,
684 + );
685 +
686 + $args = apply_filters( 'fep_filter_get_attachments', $args );
687 +
688 + return get_posts( $args );
649 689 }
650 690
651 -function fep_get_replies( $id ) {
691 +function fep_get_message_with_replies( $id )
692 +{
693 +
652 694 $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 );
695 + 'post_type' => 'fep_message',
696 + 'post_status' => 'publish',
697 + 'posts_per_page' => -1,
698 + 'order'=> 'ASC'
699 + );
700 +
701 + if( 'threaded' == fep_get_message_view() ) {
702 + $args['post_parent'] = fep_get_parent_id( $id );
703 + $args['fep_include_parent'] = true;
704 + } else {
705 + $args['post__in'] = array( $id );
706 + }
707 +
708 + $args = apply_filters( 'fep_filter_get_message_with_replies', $args );
709 +
710 + return new WP_Query( $args );
661 711 }
662 712
663 -function fep_get_attachments( $mgs_id = 0, $fields = '' ) {
664 - if ( '' !== $fields ) {
665 - _deprecated_argument( __FUNCTION__, '10.1.1' );
713 +add_filter( 'posts_where' , 'fep_posts_where', 10, 2 );
714 +
715 +function fep_posts_where( $where, $q ) {
716 +
717 + global $wpdb;
718 +
719 + if ( true === $q->get( 'fep_include_parent' ) && $q->get( 'post_parent' ) ){
720 + $where .= $wpdb->prepare( " OR ( $wpdb->posts.ID = %d AND $wpdb->posts.post_status = %s )", $q->get( 'post_parent' ), $q->get( 'post_status' ) );
666 721 }
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 );
722 +
723 + return $where;
674 724 }
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 725
683 726 function fep_get_parent_id( $id ) {
684 - if ( ! $id ) {
727 +
728 + if( ! $id )
685 729 return 0;
686 - }
687 - $parent = $id;
730 +
688 731 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 );
732 + $parent = $id;
733 + } while( $id = wp_get_post_parent_id( $id ) );
697 734 // climb up the hierarchy until we reach parent = 0
698 - return $id;
699 -}
735 +
736 + return $parent;
700 737
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 738 }
728 739
729 -function fep_format_date( $date ) {
740 +add_filter( 'the_time', 'fep_format_date', 10, 2 ) ;
730 741
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 ) );
742 +function fep_format_date( $date, $d = '' )
743 + {
744 + global $post;
745 +
746 + if( is_admin() || ! in_array( get_post_type(), apply_filters( 'fep_post_types_for_time', array( 'fep_message', 'fep_announcement' ) ) ) )
747 + return $date;
748 +
749 +
750 + if ( '0000-00-00 00:00:00' === $post->post_date ) {
751 + $h_time = __( 'Unpublished', 'front-end-pm' );
752 + } else {
753 + $m_time = $post->post_date;
754 + //$time = strtotime( $post->post_date_gmt );
755 + $time = get_post_time( 'G', true, $post, false );
756 +
757 + if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) {
758 + if ( $t_diff < 0 ) {
759 + $h_time = sprintf( __( '%s from now', 'front-end-pm' ), human_time_diff( $time ) );
760 + } else {
761 + $h_time = sprintf( __( '%s ago', 'front-end-pm' ), human_time_diff( $time ) );
762 + }
739 763 } else {
740 - $h_time = sprintf( __( '%s ago', 'front-end-pm' ), human_time_diff( $time ) );
764 + $h_time = mysql2date( get_option( 'date_format' ). ' '.get_option( 'time_format' ), $m_time );
741 765 }
742 - } else {
743 - $h_time = mysql2date( get_option( 'date_format' ). ' ' .get_option( 'time_format' ), get_date_from_gmt( $date ) );
744 766 }
745 - }
746 - return apply_filters( 'fep_formate_date', $h_time, $date );
747 -}
748 767
768 +
769 + return apply_filters( 'fep_formate_date', $h_time, $date, $d );
770 + }
771 +
772 + function fep_output_filter($string, $title = false)
773 + {
774 + $string = stripslashes($string);
775 +
776 + if ($title) {
777 + $html = apply_filters('fep_filter_display_title', $string);
778 + } else {
779 + $html = apply_filters('fep_filter_display_message', $string);
780 + }
781 +
782 + return $html;
783 + }
784 +
749 785 function fep_sort_by_priority( $a, $b ) {
750 - if ( ! isset( $a['priority'] ) || ! isset( $b['priority'] ) || $a['priority'] === $b['priority'] ) {
751 - return 0;
786 + if ( ! isset( $a['priority'] ) || ! isset( $b['priority'] ) || $a['priority'] === $b['priority'] ) {
787 + return 0;
788 + }
789 + return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
752 790 }
753 - return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
754 -}
755 791
792 +
756 793 function fep_pagination( $total = null, $per_page = null, $list_class = 'fep-pagination' ) {
794 +
757 795 $total = apply_filters( 'fep_pagination_total', $total);
758 - if ( null === $per_page ) {
759 - $per_page = fep_get_option( 'messages_page', 15 );
796 +
797 + if( null === $per_page ) {
798 + $per_page = fep_get_option('messages_page',15);
760 799 }
761 - $per_page = apply_filters( 'fep_pagination_per_page', $per_page );
762 - $last = ceil( absint( $total) / absint( $per_page ) );
763 - if ( $last <= 1 ) {
800 + $per_page = apply_filters( 'fep_pagination_per_page', $per_page);
801 +
802 + $last = ceil( absint($total) / absint($per_page) );
803 +
804 + if( $last <= 1 )
764 805 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 ) ) ) . '">&laquo;</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 ) ) ) . '">&raquo;</a></li>';
788 - $html .= '</ul></div>';
789 - return $html;
806 +
807 + //$numPgs = $total_message / fep_get_option('messages_page',50);
808 + $page = ( ! empty( $_GET['feppage'] )) ? absint($_GET['feppage']) : 1;
809 + $links = ( isset( $_GET['links'] ) ) ? absint($_GET['links']) : 2;
810 +
811 + $start = ( ( $page - $links ) > 0 ) ? $page - $links : 1;
812 + $end = ( ( $page + $links ) < $last ) ? $page + $links : $last;
813 +
814 + $html = '<div class="fep-align-centre"><ul class="' . $list_class . '">';
815 +
816 + $class = ( $page == 1 ) ? "disabled" : "";
817 + $html .= '<li class="' . $class . '"><a href="' . esc_url( add_query_arg( 'feppage', ( $page - 1 ) ) ) . '">&laquo;</a></li>';
818 +
819 + if ( $start > 1 ) {
820 + $html .= '<li><a href="' . esc_url( add_query_arg( 'feppage', 1 ) ) . '">' . number_format_i18n( 1 ) . '</a></li>';
821 + $html .= '<li class="disabled"><span>...</span></li>';
822 + }
823 +
824 + for ( $i = $start ; $i <= $end; $i++ ) {
825 + $class = ( $page == $i ) ? "active" : "";
826 + $html .= '<li class="' . $class . '"><a href="' . esc_url( add_query_arg( 'feppage', $i ) ) . '">' . number_format_i18n( $i ) . '</a></li>';
827 + }
828 +
829 + if ( $end < $last ) {
830 + $html .= '<li class="disabled"><span>...</span></li>';
831 + $html .= '<li><a href="' . esc_url( add_query_arg( 'feppage', $last ) ) . '">' . number_format_i18n( $last ) . '</a></li>';
832 + }
833 +
834 + $class = ( $page == $last ) ? "disabled" : "";
835 + $html .= '<li class="' . $class . '"><a href="' . esc_url( add_query_arg( 'feppage', ( $page + 1 ) ) ) . '">&raquo;</a></li>';
836 +
837 + $html .= '</ul></div>';
838 +
839 + return $html;
790 840 }
791 841
792 -function fep_pagination_prev_next( $has_more_row ) {
793 - $feppage = ! empty( $_GET['feppage'] ) ? absint( $_GET['feppage'] ) : 1;
842 +function fep_is_user_admin( $user_id = 0 ){
794 843
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' ); ?>">&laquo;</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' ); ?>">&raquo;</a>
806 - </li>
807 - </ul>
808 - </div>
809 - <?php
810 - endif;
811 -}
812 -
813 -function fep_is_user_admin( $user_id = 0 ) {
814 844 $admin_cap = apply_filters( 'fep_admin_cap', 'manage_options' );
815 - if ( $user_id ) {
845 + if( $user_id ){
816 846 return user_can( $user_id, $admin_cap );
817 847 }
818 848 return current_user_can( $admin_cap );
819 849 }
@@ -819,690 +849,1050 @@
819 849 }
820 850
821 851 function fep_current_user_can( $cap, $id = false ) {
822 852 $can = false;
823 - if ( ! is_user_logged_in() || fep_is_user_blocked() ) {
853 +
854 + if( ! is_user_logged_in() || fep_is_user_blocked() ) {
824 855 return apply_filters( 'fep_current_user_can', $can, $cap, $id );
825 856 }
826 857 $no_role_access = apply_filters( 'fep_no_role_access', false, $cap, $id );
827 858 $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;
859 +
860 + switch( $cap ) {
832 861 case 'access_message':
833 - if ( fep_is_user_whitelisted() || array_intersect( fep_get_option( 'userrole_access', array() ), $roles ) || ( ! $roles && $no_role_access ) ) {
862 + if( fep_is_user_whitelisted() || array_intersect( fep_get_option('userrole_access', array() ), $roles ) || ( ! $roles && $no_role_access ) ){
834 863 $can = true;
835 864 }
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 ) ) {
865 + break;
866 + case 'send_new_message' :
867 + if( fep_is_user_whitelisted() || array_intersect( fep_get_option('userrole_new_message', array() ), $roles ) || ( ! $roles && $no_role_access ) ){
839 868 $can = true;
840 869 }
841 - break;
842 - case 'send_new_message_to':
843 - if ( is_numeric( $id ) ) {
870 + break;
871 + case 'send_new_message_to' :
872 + if( is_numeric( $id ) ){
844 873 // $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 ) ) ) ) {
874 + if ( $id && $id != get_current_user_id() && fep_current_user_can('access_message') && fep_current_user_can('send_new_message') && fep_get_user_option( 'allow_messages', 1, $id ) && ! fep_is_user_blocked_for_user( $id ) ){
846 875 $can = true;
847 876 }
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 ) ) ) ) ) {
877 + // $id == user_nicename
878 + // Backward compability ( do not use )
879 + } 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_get_user_option( 'allow_messages', 1, fep_get_userdata( $id ) ) && ! fep_is_user_blocked_for_user( fep_get_userdata( $id ) ) ){
851 880 $can = true;
852 881 }
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() ) {
882 + break;
883 + case 'send_reply' :
884 + if( ! $id || ( ! in_array( get_current_user_id(), fep_get_participants( $id ) ) && ! fep_is_user_admin() ) || get_post_status ( $id ) != 'publish' ) {
885 +
886 + } elseif( fep_is_user_whitelisted() || fep_is_user_admin() || array_intersect( fep_get_option('userrole_reply', array() ), $roles ) || ( ! $roles && $no_role_access ) ){
857 887 $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' ) ) {
888 + $participants = fep_get_participants( $id );
889 + foreach( $participants as $participant ){
890 + if( fep_is_user_blocked_for_user( $participant ) ){
865 891 $can = false;
866 892 break;
867 893 }
868 - if ( ! fep_is_user_whitelisted() && fep_is_user_blocked_for_user( $participant->mgs_participant ) ) {
869 - $can = false;
870 - break;
871 - }
872 894 }
873 895 }
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() ) ) {
896 + break;
897 + case 'view_message' :
898 + if( $id && ( ( in_array( get_current_user_id(), fep_get_participants( $id ) ) && get_post_status ( $id ) == 'publish' ) || fep_is_user_admin() )) {
878 899 $can = true;
879 900 }
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' ) {
901 + break;
902 + case 'delete_message' : //only for himself
903 + if( $id && in_array( get_current_user_id(), fep_get_participants( $id ) ) && get_post_status ( $id ) == 'publish' ) {
884 904 $can = true;
885 905 }
886 - break;
887 - case 'access_directory':
888 - if ( fep_is_user_admin() || fep_is_user_whitelisted() || fep_get_option( 'show_directory', 1 ) ) {
906 + break;
907 + case 'access_directory' :
908 + if( fep_is_user_admin() || fep_get_option('show_directory', 1 ) ) {
889 909 $can = true;
890 910 }
891 - break;
892 - case 'add_announcement':
893 - if ( fep_is_user_admin() ) {
911 + break;
912 + case 'add_announcement' :
913 + if( fep_is_user_admin() || current_user_can('create_fep_announcements') ) {
894 914 $can = true;
895 915 }
896 - break;
897 - default :
898 - break;
916 + break;
917 + case 'view_announcement' :
918 + if( $id && ( ( ( array_intersect( fep_get_participant_roles( $id ), $roles ) || ( ! $roles && $no_role_access ) ) && get_post_status ( $id ) == 'publish') || fep_is_user_admin() || get_post_field( 'post_author', $id ) == get_current_user_id() ) ) {
919 + $can = true;
920 + }
921 + break;
922 + default :
923 + $can = apply_filters( 'fep_current_user_can_' . $cap, $can, $cap, $id );
924 + break;
899 925 }
900 926 return apply_filters( 'fep_current_user_can', $can, $cap, $id );
901 927 }
902 928
903 -function fep_is_read( $parent = false, $mgs_id = false, $user_id = false ) {
904 - if ( ! $user_id ) {
929 +function fep_is_read( $parent = false, $post_id = false, $user_id = false )
930 +{
931 + if( ! $user_id ) {
905 932 $user_id = get_current_user_id();
906 933 }
907 - if ( ! $mgs_id ) {
908 - $mgs_id = fep_get_the_id();
934 + if( ! $post_id ) {
935 + $post_id = get_the_ID();
909 936 }
910 - if ( ! $mgs_id || ! $user_id ) {
937 + if( !$post_id || !$user_id ) {
911 938 return false;
912 939 }
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;
940 + if( $parent ) {
941 + if( 'threaded' == fep_get_message_view() ){
942 + return get_post_meta( fep_get_parent_id( $post_id ), '_fep_parent_read_by_'. $user_id, true );
918 943 } else {
919 - $return = $participant->mgs_read;
944 + return get_post_meta( $post_id, '_fep_parent_read_by_'. $user_id, true );
920 945 }
921 946 }
922 - return (int) $return;
947 + $read_by = get_post_meta( $post_id, '_fep_read_by', true );
948 +
949 +
950 + if( is_array( $read_by ) && in_array( $user_id, $read_by ) ) {
951 + return true;
952 + }
953 +
954 + return false;
923 955 }
924 956
925 -function fep_make_read( $parent = false, $mgs_id = false, $user_id = false ) {
926 - if ( ! $user_id ) {
957 +function fep_make_read( $parent = false, $post_id = false, $user_id = false )
958 +{
959 + if( ! $post_id ) {
960 + $post_id = get_the_ID();
961 + }
962 + if( ! $user_id ) {
927 963 $user_id = get_current_user_id();
928 964 }
929 - if ( ! $mgs_id ) {
930 - $mgs_id = fep_get_the_id();
965 + if( !$post_id || !$user_id ) {
966 + return false;
931 967 }
932 - if ( ! $mgs_id || ! $user_id ) {
968 + if( $parent ) {
969 + if( 'threaded' == fep_get_message_view() ){
970 + $return = add_post_meta( fep_get_parent_id( $post_id ), '_fep_parent_read_by_'. $user_id, time(), true );
971 + } else {
972 + $return = add_post_meta( $post_id, '_fep_parent_read_by_'. $user_id, time(), true );
973 + }
974 + if( $return ) {
975 + delete_user_option( $user_id, '_fep_user_message_count' );
976 + return true;
977 + } else {
978 + return false;
979 + }
980 + }
981 + $read_by = get_post_meta( $post_id, '_fep_read_by', true );
982 +
983 + if( ! is_array( $read_by ) ) {
984 + $read_by = array();
985 + }
986 + if( in_array( $user_id, $read_by ) ) {
933 987 return false;
934 988 }
935 - $return = false;
989 + $read_by[time()] = $user_id;
936 990
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;
991 + return update_post_meta( $post_id, '_fep_read_by', $read_by );
992 +
943 993 }
944 994
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 );
995 +function fep_get_the_excerpt($count = 100, $excerpt = false ){
996 + if( false === $excerpt )
997 + $excerpt = get_the_excerpt();
998 + $excerpt = strip_shortcodes($excerpt);
999 + $excerpt = wp_strip_all_tags($excerpt);
1000 + $excerpt = substr($excerpt, 0, $count);
1001 + $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
1002 + $excerpt = $excerpt.' ...';
1003 +
1004 + return apply_filters( 'fep_get_the_excerpt', $excerpt, $count);
953 1005 }
954 1006
955 -function fep_get_current_user_max_message_number() {
1007 +function fep_get_current_user_max_message_number()
1008 +{
956 1009 $roles = wp_get_current_user()->roles;
1010 +
957 1011 $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 ) {
1012 +
1013 + if( $roles && is_array($roles) ) {
1014 + foreach( $roles as $role ) {
1015 + $count = fep_get_option("message_box_{$role}", 50);
1016 + if( ! $count ) {
962 1017 return 0;
963 1018 }
964 1019 $count_array[] = $count;
965 1020 }
966 1021 }
967 - if ( $count_array ) {
968 - return max( $count_array);
1022 + if( $count_array ) {
1023 + return max($count_array);
969 1024 } else {
970 - return 0; // FIX ME. 0 = unlimited !!!!
1025 + return 0; //FIX ME. 0 = unlimited !!!!
971 1026 }
972 1027 }
973 1028
974 -function fep_add_email_filters( $for = 'message' ) {
1029 +function fep_wp_mail_from( $from_email ) {
1030 +
1031 + $email = fep_get_option('from_email', get_bloginfo('admin_email'));
1032 +
1033 + if( is_email( $email ) ) {
1034 + return $email;
1035 + }
1036 + return $from_email;
1037 +
1038 +}
1039 +
1040 +function fep_wp_mail_from_name( $from_name ) {
1041 +
1042 + $name = stripslashes( fep_get_option('from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ) );
1043 +
1044 + if( $name ) {
1045 + return $name;
1046 + }
1047 + return $from_name;
1048 +
1049 +}
1050 +
1051 +function fep_wp_mail_content_type( $content_type ) {
1052 +
1053 + $type = fep_get_option( 'email_content_type', 'plain_text' );
1054 +
1055 + if( 'html' == $type ) {
1056 + return 'text/html';
1057 + } elseif( 'plain_text' == $type ) {
1058 + return 'text/plain';
1059 + }
1060 + return $content_type;
1061 +
1062 +}
1063 +
1064 +function fep_add_email_filters( $for = 'message' ){
1065 +
1066 + //add_filter( 'wp_mail_from', 'fep_wp_mail_from', 10 );
1067 + //add_filter( 'wp_mail_from_name', 'fep_wp_mail_from_name', 10 );
1068 + //add_filter( 'wp_mail_content_type', 'fep_wp_mail_content_type', 10 );
1069 +
975 1070 do_action( 'fep_action_after_add_email_filters', $for );
976 1071 }
977 1072
978 -function fep_remove_email_filters( $for = 'message' ) {
1073 +function fep_remove_email_filters( $for = 'message' ){
1074 +
1075 + //remove_filter( 'wp_mail_from', 'fep_wp_mail_from', 10 );
1076 + //remove_filter( 'wp_mail_from_name', 'fep_wp_mail_from_name', 10 );
1077 + //remove_filter( 'wp_mail_content_type', 'fep_wp_mail_content_type', 10 );
1078 +
979 1079 do_action( 'fep_action_after_remove_email_filters', $for );
980 1080 }
981 1081
982 -function fep_delete_message( $mgs_id, $user_id = 0 ) {
983 - if ( ! $user_id ) {
984 - $user_id = get_current_user_id();
1082 +function fep_delete_message( $message_id, $user_id = 0 ){
1083 + if( 'threaded' == fep_get_message_view() ){
1084 + $id = fep_get_parent_id( $message_id );
1085 + } else {
1086 + $id = $message_id;
985 1087 }
986 - if ( ! $mgs_id || ! $user_id ) {
987 - return false;
1088 + $return = false;
1089 +
1090 + if( $user_id ) {
1091 + $return = add_post_meta( $id, '_fep_delete_by_'. $user_id, time(), true );
1092 + } elseif( fep_current_user_can( 'delete_message', $id ) ){
1093 + $return = add_post_meta( $id, '_fep_delete_by_'. get_current_user_id(), time(), true );
988 1094 }
989 -
990 - $return = FEP_Participants::init()->mark( $mgs_id, $user_id, ['delete' => true ] );
991 -
992 1095 $should_delete_from_db = true;
993 - foreach ( FEP_Participants::init()->get( $mgs_id ) as $participant ) {
994 - if ( ! $participant->mgs_deleted ) {
1096 + foreach( fep_get_participants( $id ) as $participant ) {
1097 + if( ! get_post_meta( $id, '_fep_delete_by_'. $participant, true ) ) {
995 1098 $should_delete_from_db = false;
996 1099 break;
997 1100 }
1101 +
998 1102 }
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 - }
1103 + if( $should_delete_from_db && ! get_post_meta( $id, '_fep_group', true ) ) {
1104 + $return = wp_trash_post( $id );
1012 1105 }
1013 1106 return $return;
1014 1107 }
1015 1108
1016 -function fep_send_message( $message = null, $override = array() ) {
1017 - if ( null === $message ) {
1109 +function fep_undelete_message( $message_id, $user_id = 0 ){
1110 + if( 'threaded' == fep_get_message_view() ){
1111 + $id = fep_get_parent_id( $message_id );
1112 + } else {
1113 + $id = $message_id;
1114 + }
1115 + $return = false;
1116 +
1117 + if( $user_id ) {
1118 + $return = delete_post_meta( $id, '_fep_delete_by_'. $user_id );
1119 + } elseif( fep_current_user_can( 'delete_message', $id ) ){
1120 + $return = delete_post_meta( $id, '_fep_delete_by_'. get_current_user_id() );
1121 + }
1122 +
1123 + return $return;
1124 +}
1125 +
1126 +function fep_send_message( $message = null, $override = array() )
1127 +{
1128 + if( null === $message ) {
1018 1129 $message = $_POST;
1019 1130 }
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' ) );
1131 +
1132 + if( ! empty($message['fep_parent_id'] ) ) {
1133 + $message['post_parent'] = absint( $message['fep_parent_id'] );
1134 + $message['post_status'] = fep_get_option('reply_post_status','publish');
1135 + $message['message_title'] = __('RE:', 'front-end-pm'). ' ' . wp_slash( get_post( $message['post_parent'] )->post_title );
1136 + if( 'threaded' != fep_get_message_view() )
1137 + $message['message_to_id'] = fep_get_participants( $message['post_parent'] );
1025 1138 } else {
1026 - $message['mgs_status'] = fep_get_option( 'parent_post_status','publish' );
1027 - $message['mgs_parent'] = 0;
1139 + $message['post_status'] = fep_get_option('parent_post_status','publish');
1140 + $message['post_parent'] = 0;
1028 1141 }
1029 - $message = apply_filters( 'fep_filter_message_before_send', $message );
1030 - if ( empty( $message['message_title'] ) || empty( $message['message_content'] ) ) {
1142 +
1143 + $message = apply_filters('fep_filter_message_before_send', $message );
1144 +
1145 + if( empty($message['message_title']) || empty($message['message_content']) ) {
1031 1146 return false;
1032 1147 }
1033 1148 // Create post array
1034 1149 $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 ),
1150 + 'post_title' => $message['message_title'],
1151 + 'post_content' => $message['message_content'],
1152 + 'post_status' => $message['post_status'],
1153 + 'post_parent' => $message['post_parent'],
1154 + 'post_type' => 'fep_message'
1042 1155 );
1043 1156
1044 - if ( $override && is_array( $override ) ) {
1157 + if( $override && is_array( $override ) ) {
1045 1158 $post = wp_parse_args( $override, $post );
1046 1159 }
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 - }
1160 +
1161 + $post = apply_filters('fep_filter_message_after_override', $post, $message );
1052 1162
1053 - $post = apply_filters( 'fep_filter_message_after_override', $post, $message );
1054 -
1055 - $post = wp_unslash( $post );
1163 + // Insert the message into the database
1164 + $message_id = wp_insert_post( $post );
1056 1165
1057 - $new_message = new FEP_Message;
1058 - $message_id = $new_message->insert( $post );
1059 - // Insert the message into the database
1060 - if ( ! $message_id ) {
1166 + if( ! $message_id || is_wp_error( $message_id ) ) {
1061 1167 return false;
1062 1168 }
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 );
1169 + $inserted_message = get_post( $message_id );
1079 1170
1080 - fep_status_change( 'new', $new_message );
1171 + do_action('fep_action_message_after_send', $message_id, $message, $inserted_message );
1081 1172
1082 1173 return $message_id;
1083 1174 }
1084 1175
1085 -function fep_status_change( $old_status, $message ){
1086 - if( ! $old_status || ! is_object( $message ) ){
1087 - return false;
1176 +add_action( 'fep_action_message_after_send', 'fep_add_message_participants', 5, 3 );
1177 +
1178 +function fep_add_message_participants( $message_id, $message, $inserted_message ){
1179 +
1180 + if( $inserted_message->post_parent ) {
1181 + if( 'threaded' == fep_get_message_view() ){
1182 + if( ! in_array( $inserted_message->post_author, fep_get_participants( $inserted_message->post_parent ) )){
1183 + add_post_meta( $inserted_message->post_parent, '_fep_participants', $inserted_message->post_author );
1184 + fep_make_read( true, $message_id, $inserted_message->post_author );
1185 + }
1186 +
1187 + $participants = fep_get_participants( $inserted_message->post_parent );
1188 +
1189 + foreach( $participants as $participant )
1190 + {
1191 + if( $participant != $inserted_message->post_author ){
1192 + fep_undelete_message( $inserted_message->post_parent, $participant);
1193 + delete_post_meta( $inserted_message->post_parent, '_fep_parent_read_by_'. $participant );
1194 + }
1195 + }
1196 + }
1088 1197 }
1089 - $new_status = $message->mgs_status;
1090 -
1091 - if( $old_status == $new_status ){
1092 - return false;
1198 + if( ! $inserted_message->post_parent || ( $inserted_message->post_parent && 'threaded' != fep_get_message_view() ) ) {
1199 + if( ! empty($message['message_to_id'] ) ) { //FRONT END message_to return id of participants
1200 + if( is_array( $message['message_to_id'] ) ) {
1201 + foreach( $message['message_to_id'] as $participant ) {
1202 +
1203 + if( ! in_array( $participant, fep_get_participants( $message_id ) )){
1204 + add_post_meta( $message_id, '_fep_participants', $participant );
1205 + if( 'publish' == $inserted_message->post_status ){
1206 + delete_user_option( $participant, '_fep_user_message_count' );
1207 + delete_user_option( $participant, '_fep_notification_dismiss' );
1208 + }
1209 + }
1210 + }
1211 + } else {
1212 + if( ! in_array( $message['message_to_id'], fep_get_participants( $message_id ) )){
1213 + add_post_meta( $message_id, '_fep_participants', $message['message_to_id'] );
1214 + if( 'publish' == $inserted_message->post_status ){
1215 + delete_user_option( $message['message_to_id'], '_fep_user_message_count' );
1216 + delete_user_option( $message['message_to_id'], '_fep_notification_dismiss' );
1217 + }
1218 + }
1219 + }
1220 + }
1221 + if( ! in_array( $inserted_message->post_author, fep_get_participants( $message_id ) )){
1222 + add_post_meta( $message_id, '_fep_participants', $inserted_message->post_author );
1223 + }
1224 +
1225 + fep_make_read( true, $message_id, $inserted_message->post_author );
1093 1226 }
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 1227 }
1106 1228
1107 -function fep_delete_counts_cache( $new_status, $old_status, $message ) {
1108 - wp_cache_delete( $message->mgs_type, 'fep_counts' );
1109 -}
1229 +add_action ('transition_post_status', 'fep_send_message_transition_post_status', 10, 3);
1110 1230
1111 -function fep_send_message_transition_post_status( $new_status, $old_status, $message ) {
1112 - if ( 'message' != $message->mgs_type ) {
1113 - return;
1231 +function fep_send_message_transition_post_status( $new_status, $old_status, $post ){
1232 + if ( 'fep_message' != $post->post_type || $old_status === $new_status ) {
1233 + return;
1114 1234 }
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;
1235 +
1236 + if( 'publish' == $new_status && 'threaded' == fep_get_message_view() ){
1237 + if( $post->post_parent ) {
1238 + update_post_meta( $post->post_parent, '_fep_last_reply_by', $post->post_author );
1239 + update_post_meta( $post->post_parent, '_fep_last_reply_id', $post->ID );
1240 + update_post_meta( $post->post_parent, '_fep_last_reply_time', strtotime( $post->post_date_gmt ) );
1241 + } else {
1242 + add_post_meta( $post->ID, '_fep_last_reply_by', $post->post_author, true );
1243 + add_post_meta( $post->ID, '_fep_last_reply_id', $post->ID, true );
1244 + add_post_meta( $post->ID, '_fep_last_reply_time', strtotime( $post->post_date_gmt ), true );
1245 + }
1246 +
1247 + } elseif( 'publish' == $old_status && 'threaded' == fep_get_message_view() ){
1248 + if( $post->post_parent ) {
1249 + $child_args = array(
1250 + 'post_type' => 'fep_message',
1251 + 'post_status' => 'publish',
1252 + 'posts_per_page' => 1,
1253 + 'post_parent' => $post->post_parent
1254 + );
1255 + $child = get_posts( $child_args );
1256 +
1257 + if( $child && ! empty( $child[0] ) ){
1258 + update_post_meta( $post->post_parent, '_fep_last_reply_by', $child[0]->post_author );
1259 + update_post_meta( $post->post_parent, '_fep_last_reply_id', $child[0]->ID );
1260 + update_post_meta( $post->post_parent, '_fep_last_reply_time', strtotime( $child[0]->post_date_gmt ) );
1261 + } else {
1262 + $parent_post = get_post( $post->post_parent );
1263 +
1264 + update_post_meta( $parent_post->ID, '_fep_last_reply_by', $parent_post->post_author );
1265 + update_post_meta( $parent_post->ID, '_fep_last_reply_id', $parent_post->ID );
1266 + update_post_meta( $parent_post->ID, '_fep_last_reply_time', strtotime( $parent_post->post_date_gmt ) );
1123 1267 }
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 1268 }
1127 - FEP_Participants::init()->mark( $message->mgs_id, $message->mgs_author, [ 'parent_read' => true ] );
1128 1269 }
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' );
1270 + if( 'publish' == $new_status || 'publish' == $old_status ){
1271 +
1272 + $participants = fep_get_participants( $post->ID );
1273 +
1274 + foreach( $participants as $participant )
1275 + {
1276 + delete_user_option( $participant, '_fep_user_message_count' );
1277 + if( $participant != $post->post_author && 'publish' == $new_status ){
1278 + delete_user_option( $participant, '_fep_notification_dismiss' );
1138 1279 }
1139 1280 }
1140 1281 }
1141 1282 }
1142 1283
1143 -function fep_add_announcement( $announcement = null, $override = array() ) {
1144 - if ( null === $announcement ) {
1284 +function fep_add_announcement( $announcement = null, $override = array() )
1285 +{
1286 + if( null === $announcement ) {
1145 1287 $announcement = $_POST;
1146 1288 }
1147 - $announcement = apply_filters( 'fep_filter_announcement_before_added', $announcement );
1148 - if ( empty( $announcement['message_title'] ) || empty( $announcement['message_content'] ) ) {
1289 +
1290 + $announcement = apply_filters('fep_filter_announcement_before_added', $announcement );
1291 +
1292 + if( empty($announcement['message_title']) || empty($announcement['message_content']) ) {
1149 1293 return false;
1150 1294 }
1151 1295 // Create post array
1152 1296 $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 ),
1297 + 'post_title' => $announcement['message_title'],
1298 + 'post_content' => $announcement['message_content'],
1299 + 'post_status' => 'publish',
1300 + 'post_type' => 'fep_announcement'
1159 1301 );
1160 -
1161 - if ( $override && is_array( $override ) ) {
1302 +
1303 + if( $override && is_array( $override ) ) {
1162 1304 $post = wp_parse_args( $override, $post );
1163 1305 }
1164 - $post = apply_filters( 'fep_filter_announcement_after_override', $post, $announcement );
1165 -
1166 - $post = wp_unslash( $post );
1306 +
1307 + $post = apply_filters('fep_filter_announcement_after_override', $post, $announcement );
1167 1308
1168 - $new_message = new FEP_Message;
1169 - $announcement_id = $new_message->insert( $post );
1170 -
1171 1309 // Insert the message into the database
1172 - if ( ! $announcement_id ) {
1310 + $announcement_id = wp_insert_post( $post );
1311 +
1312 + if( ! $announcement_id || is_wp_error( $announcement_id ) ) {
1173 1313 return false;
1174 1314 }
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 );
1315 + $inserted_announcement = get_post( $announcement_id );
1316 +
1317 + if( ! empty($announcement['announcement_roles']) && is_array($announcement['announcement_roles']) ) {
1318 + foreach($announcement['announcement_roles'] as $role ) {
1319 + add_post_meta( $announcement_id, '_fep_participant_roles', $role );
1191 1320 }
1192 1321 }
1193 - if ( is_multisite() ) {
1194 - fep_add_meta( $announcement_id, '_fep_blog_id', get_current_blog_id() );
1195 - }
1322 + add_post_meta( $announcement_id, '_fep_author', $inserted_announcement->post_author, true);
1196 1323
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 );
1324 + do_action('fep_action_announcement_after_added', $announcement_id, $announcement, $inserted_announcement );
1200 1325
1201 - fep_status_change( 'new', $new_message );
1202 -
1203 1326 return $announcement_id;
1204 1327 }
1205 1328
1206 -function fep_backticker_encode( $text ) {
1329 +function fep_backticker_encode($text) {
1207 1330 $text = $text[1];
1208 - $text = str_replace( '&amp;lt;', '&lt;', $text );
1209 - $text = str_replace( '&amp;gt;', '&gt;', $text );
1210 - $text = htmlspecialchars( $text, ENT_QUOTES );
1211 - $text = preg_replace( '|\n+|', '\n', $text );
1212 - $text = nl2br( $text );
1213 - $text = str_replace( '\t', '&nbsp;&nbsp;&nbsp;&nbsp;', $text );
1214 - $text = preg_replace( '/^ /', '&nbsp;', $text );
1215 - $text = preg_replace( '/(?<=&nbsp;| |\n) /', '&nbsp;', $text );
1216 - return "<code>$text</code>";
1331 + $text = str_replace('&amp;lt;', '&lt;', $text);
1332 + $text = str_replace('&amp;gt;', '&gt;', $text);
1333 + $text = htmlspecialchars($text, ENT_QUOTES);
1334 + $text = preg_replace("|\n+|", "\n", $text);
1335 + $text = nl2br($text);
1336 + $text = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $text);
1337 + $text = preg_replace("/^ /", '&nbsp;', $text);
1338 + $text = preg_replace("/(?<=&nbsp;| |\n) /", '&nbsp;', $text);
1339 +
1340 + return "<code>$text</code>";
1217 1341 }
1218 1342
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;
1343 +function fep_backticker_display_code($text) {
1344 + //$text = preg_replace_callback("|`(.*?)`|", "fep_backticker_encode", $text);
1345 + $text = preg_replace_callback('!`(?:\r\n|\n|\r|)(.*?)(?:\r\n|\n|\r|)`!ims', "fep_backticker_encode", $text);
1346 + $text = str_replace('<code></code>', '`', $text);
1347 + return $text;
1224 1348 }
1225 1349
1226 1350 function fep_backticker_code_input_filter( $message ) {
1227 - $message['message_content'] = fep_backticker_display_code( $message['message_content'] );
1351 +
1352 + $message['message_content'] = fep_backticker_display_code($message['message_content']);
1353 +
1228 1354 return $message;
1355 + }
1356 +add_filter( 'fep_filter_message_before_send', 'fep_backticker_code_input_filter', 5);
1357 +
1358 +function fep_autosuggestion_ajax() {
1359 + _deprecated_function( __FUNCTION__, '4.4', 'Fep_Ajax class' );
1360 +
1361 + global $user_ID;
1362 +
1363 + if( !fep_get_option('show_autosuggest', 1) && !fep_is_user_admin() )
1364 + die();
1365 +
1366 + if ( check_ajax_referer( 'fep-autosuggestion', 'token', false )) {
1367 +
1368 + $searchq = $_POST['searchBy'];
1369 +
1370 +
1371 + $args = array(
1372 + 'search' => "*{$searchq}*",
1373 + 'search_columns' => array( 'display_name' ),
1374 + 'exclude' => array( $user_ID ),
1375 + 'number' => 5,
1376 + 'orderby' => 'display_name',
1377 + 'order' => 'ASC',
1378 + 'fields' => array( 'display_name', 'user_nicename' )
1379 + );
1380 +
1381 + $args = apply_filters ('fep_autosuggestion_arguments', $args );
1382 +
1383 + // The Query
1384 + $user_query = new WP_User_Query( $args );
1385 +
1386 +if(strlen($searchq)>0)
1387 +{
1388 + echo "<ul>";
1389 + if (! empty( $user_query->results ))
1390 + {
1391 + foreach($user_query->results as $user)
1392 + {
1393 +
1394 + ?>
1395 + <li><a href="#" onClick="fep_fill_autosuggestion('<?php echo $user->user_nicename; ?>','<?php echo $user->display_name; ?>');return false;"><?php echo $user->display_name; ?></a></li>
1396 + <?php
1397 +
1398 + }
1399 + }
1400 + else
1401 + echo "<li>".__("No matches found", 'front-end-pm')."</li>";
1402 + echo "</ul>";
1229 1403 }
1404 +}
1405 +die();
1406 +}
1230 1407
1231 -function fep_footer_credit() {
1408 +//add_action('wp_ajax_fep_autosuggestion_ajax','fep_autosuggestion_ajax');
1409 +
1410 +function fep_footer_credit()
1411 + {
1232 1412 $style = '';
1233 - if ( ! fep_get_option( 'show_branding', 1 ) ) {
1234 - $style = ' style="display:none;"';
1413 + if ( ! fep_get_option('show_branding', 1) ) {
1414 + $style = " style='display: none'";
1235 1415 }
1236 - echo '<div' . $style . '><a href="https://www.shamimsplugins.com/products/front-end-pm-pro/" target="_blank">Front End PM</a></div>';
1237 -}
1416 + echo "<div{$style}><a href='https://www.shamimsplugins.com/products/front-end-pm-pro/' target='_blank'>Front End PM</a></div>";
1417 + }
1238 1418
1419 +add_action('fep_footer_note', 'fep_footer_credit' );
1420 +
1421 +function fep_notification()
1422 + {
1423 + if ( ! fep_current_user_can( 'access_message' ) )
1424 + return '';
1425 + if ( ! fep_get_option('show_notification', 1) )
1426 + return '';
1427 +
1428 + $unread_count = fep_get_new_message_number();
1429 + $sm = sprintf(_n('%s message', '%s messages', $unread_count, 'front-end-pm'), number_format_i18n($unread_count) );
1430 +
1431 + $show = '';
1432 +
1433 + $unread_ann_count = fep_get_user_announcement_count( 'unread' );
1434 + $sa = sprintf(_n('%s announcement', '%s announcements', $unread_ann_count, 'front-end-pm'), number_format_i18n($unread_ann_count) );
1435 +
1436 + if ( $unread_count || $unread_ann_count ) {
1437 + $show = __("You have", 'front-end-pm');
1438 +
1439 + if ( $unread_count )
1440 + $show .= "<a href='".fep_query_url('messagebox')."'> $sm</a>";
1441 +
1442 + if ( $unread_count && $unread_ann_count )
1443 + $show .= ' ' .__('and', 'front-end-pm');
1444 +
1445 + if ( $unread_ann_count )
1446 + $show .= "<a href='".fep_query_url('announcements')."'> $sa</a>";
1447 +
1448 + $show .= ' ';
1449 + $show .= __('unread', 'front-end-pm');
1450 + }
1451 + return apply_filters('fep_header_notification', $show);
1452 + }
1453 +
1454 +
1239 1455 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 - }
1456 + if ( ! fep_current_user_can( 'access_message' ) )
1457 + return;
1458 + if ( ! fep_get_option('show_notification', 1) )
1459 + return;
1460 +
1246 1461 wp_enqueue_script( 'fep-notification-script' );
1462 +
1247 1463 $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 ) );
1464 + $sm = sprintf(_n('%s message', '%s messages', $unread_count, 'front-end-pm'), number_format_i18n($unread_count) );
1465 +
1249 1466 $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 ) );
1467 + $sa = sprintf(_n('%s announcement', '%s announcements', $unread_ann_count, 'front-end-pm'), number_format_i18n($unread_ann_count) );
1468 +
1251 1469 $class = 'fep-notification-bar';
1252 - if ( ! $unread_count && ! $unread_ann_count ) {
1470 + if( !$unread_count && !$unread_ann_count ){
1253 1471 $class .= ' fep-hide';
1254 - } elseif ( get_user_meta( get_current_user_id(), '_fep_notification_dismiss', true ) ) {
1472 + } elseif( get_user_option( '_fep_notification_dismiss' ) ){
1255 1473 $class .= ' fep-hide';
1256 1474 }
1257 - $show = '<div id="fep-notification-bar" class="' . $class . '"><p>';
1258 - $show .= __( 'You have', 'front-end-pm' );
1475 +
1476 + $show = '<div id="fep-notification-bar" class="'. $class . '"><p>';
1477 + $show .= __("You have", 'front-end-pm');
1478 +
1259 1479 $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>';
1480 + if( ! $unread_count )
1481 + $class .= ' fep-hide';
1482 +
1483 + $show .= '<span class="'.$class.'"> <a href="'.fep_query_url('messagebox').'"><span class="fep_unread_message_count_text">'. $sm . '</span></a></span>';
1484 +
1264 1485 $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>';
1486 + if( ! $unread_count || ! $unread_ann_count )
1487 + $class .= ' fep-hide';
1488 +
1489 + $show .= '<span class="'.$class.'"> ' .__('and', 'front-end-pm') . '</span>';
1490 +
1269 1491 $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>';
1492 + if( ! $unread_ann_count )
1493 + $class .= ' fep-hide';
1494 +
1495 + $show .= '<span class="'.$class.'"> <a href="'.fep_query_url('announcements').'"><span class="fep_unread_announcement_count_text">'. $sa . '</span></a></span>';
1496 +
1274 1497 $show .= ' ';
1275 - $show .= __( 'unread', 'front-end-pm' );
1498 + $show .= __('unread', 'front-end-pm');
1276 1499 $show .= '</p>';
1277 - $show .= '<button aria-label="' . esc_attr( 'Dismiss notice', 'front-end-pm' ) . '" class="fep-notice-dismiss">×</button>';
1500 + $show .= '<button aria-label="'. esc_attr( 'Dismiss notice', 'front-end-pm' ).'" class="fep-notice-dismiss">×</button>';
1278 1501 $show .= '</div>';
1279 - echo apply_filters( 'fep_header_notification', $show );
1502 +
1503 + echo apply_filters('fep_header_notification', $show);
1280 1504 }
1281 1505
1282 -function fep_auth_redirect() {
1283 - if ( ! fep_page_id() || ( ! is_page( fep_page_id() ) && ! is_single( fep_page_id() ) ) ) {
1506 +
1507 +add_action('wp_head', 'fep_notification_div', 99 );
1508 +
1509 +function fep_notification_ajax() {
1510 + _deprecated_function( __FUNCTION__, '4.4', 'Fep_Ajax class' );
1511 +
1512 + if ( check_ajax_referer( 'fep-notification', 'token', false )) {
1513 +
1514 + $notification = fep_notification();
1515 + if ( $notification )
1516 + echo $notification;
1517 + }
1518 + wp_die();
1519 + }
1520 +
1521 +//add_action('wp_ajax_fep_notification_ajax','fep_notification_ajax');
1522 +//add_action('wp_ajax_nopriv_fep_notification_ajax','fep_notification_ajax');
1523 +
1524 +function fep_auth_redirect(){
1525 + if( ! fep_page_id() || ( ! is_page( fep_page_id() ) && ! is_single( fep_page_id() ) ) ) {
1284 1526 return;
1285 1527 }
1528 +
1286 1529 do_action( 'fep_template_redirect' );
1287 - if ( apply_filters( 'fep_using_auth_redirect', false ) ) {
1530 +
1531 + if( apply_filters( 'fep_using_auth_redirect', false ) ) {
1288 1532 auth_redirect();
1289 1533 }
1290 1534 }
1535 +add_action('template_redirect','fep_auth_redirect', 99 );
1291 1536
1292 -function fep_auth_redirect_scheme( $scheme ) {
1293 - if ( ! apply_filters( 'fep_using_auth_redirect', false ) ) {
1537 +add_filter( 'auth_redirect_scheme', 'fep_auth_redirect_scheme' );
1538 +function fep_auth_redirect_scheme( $scheme ){
1539 +
1540 + if( is_admin() || ! fep_page_id() || ( ! is_page( fep_page_id() ) && ! is_single( fep_page_id() ) ) ) {
1294 1541 return $scheme;
1295 1542 }
1296 - if ( is_admin() || ! fep_page_id() || ( ! is_page( fep_page_id() ) && ! is_single( fep_page_id() ) ) ) {
1297 - return $scheme;
1543 +
1544 + return 'logged_in';
1545 +}
1546 +
1547 +add_filter( 'map_meta_cap', 'fep_map_meta_cap', 10, 4 );
1548 +
1549 +function fep_map_meta_cap( $caps, $cap, $user_id, $args ) {
1550 +
1551 + $our_caps = array( 'read_fep_message', 'edit_fep_message', 'delete_fep_message', 'read_fep_announcement', 'edit_fep_announcement', 'delete_fep_announcement' );
1552 +
1553 + /* If editing, deleting, or reading a message or announcement, get the post and post type object. */
1554 + if ( in_array( $cap, $our_caps ) ) {
1555 + $post = get_post( $args[0] );
1556 + $post_type = get_post_type_object( $post->post_type );
1557 +
1558 + /* Set an empty array for the caps. */
1559 + $caps = array();
1560 + } else {
1561 + return $caps;
1298 1562 }
1299 - return 'logged_in';
1563 +
1564 + /* If editing a message or announcement, assign the required capability. */
1565 + if ( 'edit_fep_message' == $cap || 'edit_fep_announcement' == $cap ) {
1566 + if ( $user_id == $post->post_author )
1567 + $caps[] = $post_type->cap->edit_posts;
1568 + else
1569 + $caps[] = $post_type->cap->edit_others_posts;
1570 + }
1571 +
1572 + /* If deleting a message or announcement, assign the required capability. */
1573 + elseif ( 'delete_fep_message' == $cap || 'delete_fep_announcement' == $cap ) {
1574 + if ( $user_id == $post->post_author )
1575 + $caps[] = $post_type->cap->delete_posts;
1576 + else
1577 + $caps[] = $post_type->cap->delete_others_posts;
1578 + }
1579 +
1580 + /* If reading a private message or announcement, assign the required capability. */
1581 + elseif ( 'read_fep_message' == $cap || 'read_fep_announcement' == $cap ) {
1582 +
1583 + if ( 'private' != $post->post_status )
1584 + $caps[] = 'read';
1585 + elseif ( $user_id == $post->post_author )
1586 + $caps[] = 'read';
1587 + else
1588 + $caps[] = $post_type->cap->read_private_posts;
1589 + }
1590 +
1591 + /* Return the capabilities required by the user. */
1592 + return $caps;
1300 1593 }
1301 1594
1302 -function fep_array_trim( $array ) {
1303 - if ( ! is_array( $array ) ) {
1304 - return trim( $array );
1305 - }
1306 - return array_map( 'fep_array_trim', $array );
1595 +function fep_array_trim( $array )
1596 +{
1597 +
1598 + if (!is_array( $array ))
1599 + return trim( $array );
1600 +
1601 + return array_map('fep_array_trim', $array );
1307 1602 }
1308 1603
1309 -function fep_is_pro() {
1310 - return file_exists( FEP_PLUGIN_DIR . 'pro/pro-features.php' );
1604 +function fep_is_pro(){
1605 + return file_exists( FEP_PLUGIN_DIR. 'pro/pro-features.php' );
1311 1606 }
1312 1607
1313 -function fep_errors() {
1314 - static $errors; // Will hold global variable safely
1315 - return isset( $errors ) ? $errors : ( $errors = new WP_Error() );
1608 +function fep_errors(){
1609 + static $errors; // Will hold global variable safely
1610 + return isset($errors) ? $errors : ($errors = new WP_Error());
1316 1611 }
1317 1612
1318 -function fep_success() {
1319 - static $success; // Will hold global variable safely
1320 - return isset( $success ) ? $success : ( $success = new WP_Error() );
1613 +function fep_success(){
1614 + static $success; // Will hold global variable safely
1615 + return isset($success) ? $success : ($success = new WP_Error());
1321 1616 }
1322 1617
1323 -function fep_info_output() {
1324 - do_action( 'fep_action_info_output' );
1618 +function fep_info_output(){
1619 +
1620 + /*
1621 + // If conditions are met and errors exist:
1622 + if(!fep_info()->get_error_codes()) return;
1325 1623
1624 + $success = array();
1625 + $info = array();
1626 + $errors = array();
1627 +
1628 + // Loop error codes and display errors
1629 + foreach( fep_info()->get_error_codes() as $code ){
1630 +
1631 + $data = fep_info()->get_error_data($code);
1632 + // Display stuff here
1633 + if( 'success' == $data ) {
1634 + $success[] = fep_info()->get_error_message($code);
1635 + } elseif( 'info' == $data ){
1636 + $info[] = fep_info()->get_error_message($code);
1637 + } else {
1638 + $errors[] = fep_info()->get_error_message($code);
1639 + }
1640 + }
1641 + */
1642 +
1326 1643 $html = '';
1327 - if ( fep_success()->get_error_messages() ) {
1644 +
1645 + if( fep_success()->get_error_messages() ) {
1328 1646 $html .= '<div class="fep-success">';
1329 - foreach ( fep_success()->get_error_messages() as $s ) {
1330 - $html .= esc_html( $s ). '<br />';
1647 + foreach( fep_success()->get_error_messages() as $s){
1648 + $html .= esc_html($s).'<br />';
1331 1649 }
1332 1650 $html .= '</div>';
1333 1651 }
1334 - if ( fep_errors()->get_error_messages() ) {
1652 +
1653 + if( fep_errors()->get_error_messages() ) {
1335 1654 $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 />';
1655 + foreach( fep_errors()->get_error_messages() as $e){
1656 + $html .= '<strong>' . __('Error', 'front-end-pm') . ': </strong>'.esc_html($e).'<br />';
1338 1657 }
1339 1658 $html .= '</div>';
1340 1659 }
1660 +
1341 1661 return $html;
1662 +
1342 1663 }
1343 1664
1344 1665 function fep_locate_template( $template_names, $load = false, $require_once = true ) {
1666 +
1345 1667 $locations = array();
1346 1668 $locations[10] = trailingslashit( STYLESHEETPATH ) . 'front-end-pm/';
1347 1669 $locations[20] = trailingslashit( TEMPLATEPATH ) . 'front-end-pm/';
1348 1670 $locations[30] = FEP_PLUGIN_DIR . 'pro/templates/';
1349 1671 $locations[40] = FEP_PLUGIN_DIR . 'templates/';
1672 +
1350 1673 $locations = apply_filters( 'fep_template_locations', $locations );
1351 -
1674 +
1352 1675 // sort the $locations based on priority
1353 1676 ksort( $locations, SORT_NUMERIC );
1677 +
1354 1678 $template = '';
1355 - if ( ! is_array( $template_names ) ) {
1679 +
1680 + if( ! is_array( $template_names ) )
1356 1681 $template_names = explode( ',', $template_names );
1357 - }
1358 - foreach ( $template_names as $template_name ) {
1682 +
1683 + foreach( $template_names as $template_name ){
1684 +
1359 1685 $template_name = trim( $template_name );
1360 - if ( empty( $template_name ) ) {
1686 +
1687 + if ( empty( $template_name ) )
1361 1688 continue;
1362 - }
1363 - if ( strpos( $template_name, '../' ) !== false || strpos( $template_name, '..\\' ) !== false ) {
1689 +
1690 + if( strpos( $template_name, '../') !== false || strpos( $template_name, '..\\') !== false )
1364 1691 continue;
1365 - }
1366 - foreach ( $locations as $location ) {
1367 - if ( file_exists( $location . $template_name ) ) {
1692 +
1693 + foreach( $locations as $location ){
1694 + if( file_exists( $location . $template_name ) ) {
1368 1695 $template = $location . $template_name;
1369 1696 break 2;
1370 1697 }
1371 1698 }
1699 +
1372 1700 }
1373 - if ( ( true == $load ) && ! empty( $template ) ) {
1701 +
1702 + if ( ( true == $load ) && ! empty( $template ) )
1374 1703 load_template( $template, $require_once );
1375 - }
1704 +
1376 1705 return apply_filters( 'fep_locate_template', $template, $template_names, $load, $require_once );
1377 1706 }
1378 1707
1379 -function fep_form_posted() {
1380 - $action = ! empty( $_POST['fep_action'] ) ? $_POST['fep_action'] : '';
1381 - if ( ! $action ) {
1708 +add_action('wp_loaded', 'fep_form_posted', 20 ); //After Email hook
1709 +
1710 +function fep_form_posted()
1711 +{
1712 + $action = !empty($_POST['fep_action']) ? $_POST['fep_action'] : '';
1713 +
1714 + if( ! $action )
1382 1715 return;
1383 - }
1384 - if ( ! fep_current_user_can( 'access_message' ) ) {
1716 +
1717 + if ( ! fep_current_user_can('access_message') )
1385 1718 return;
1386 - }
1719 +
1387 1720 $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' ) );
1721 +
1722 + switch( $action ) {
1723 + case has_action("fep_posted_action_{$action}"):
1724 + do_action("fep_posted_action_{$action}" );
1725 + break;
1726 + case ( 'newmessage' == $action && ! empty( $menu['newmessage'] ) ) :
1727 + case 'shortcode-newmessage' :
1728 + if ( ! fep_current_user_can( 'send_new_message') ){
1729 + fep_errors()->add( 'permission', __("You do not have permission to send new message!", 'front-end-pm') );
1396 1730 break;
1397 1731 }
1732 +
1398 1733 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' ) );
1734 + if( count( fep_errors()->get_error_messages()) == 0 ){
1735 + if( $message_id = fep_send_message() ) {
1736 + $message = get_post( $message_id );
1737 +
1738 + if( 'publish' == $message->post_status ) {
1739 + fep_success()->add( 'publish', __("Message successfully sent.", 'front-end-pm') );
1403 1740 } else {
1404 - fep_success()->add( 'pending', __( 'Message successfully sent and waiting for admin moderation.', 'front-end-pm' ) );
1741 + fep_success()->add( 'pending', __("Message successfully sent and waiting for admin moderation.", 'front-end-pm') );
1405 1742 }
1406 1743 } else {
1407 - fep_errors()->add( 'undefined', __( 'Something wrong. Please try again.', 'front-end-pm' ) );
1744 + fep_errors()->add( 'undefined', __("Something wrong. Please try again.", 'front-end-pm') );
1408 1745 }
1409 1746 }
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' ) );
1747 +
1748 + break;
1749 + case 'reply' :
1750 +
1751 + if( isset( $_GET['fep_id'] ) ){
1752 + $pID = absint( $_GET['fep_id'] );
1753 + } else {
1754 + $pID = !empty($_GET['id']) ? absint($_GET['id']) : 0;
1755 + }
1756 + $parent_id = fep_get_parent_id( $pID );
1757 +
1758 + if ( ! fep_current_user_can( 'send_reply', $parent_id ) ){
1759 + fep_errors()->add( 'permission', __("You do not have permission to send reply to this message!", 'front-end-pm') );
1415 1760 break;
1416 1761 }
1762 +
1417 1763 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' ) );
1764 + if( count( fep_errors()->get_error_messages()) == 0 ){
1765 + if( $message_id = fep_send_message() ) {
1766 + $message = get_post( $message_id );
1767 +
1768 + if( 'publish' == $message->post_status ) {
1769 + fep_success()->add( 'publish', __("Message successfully sent.", 'front-end-pm') );
1422 1770 } else {
1423 - fep_success()->add( 'pending', __( 'Message successfully sent and waiting for admin moderation.', 'front-end-pm' ) );
1771 + fep_success()->add( 'pending', __("Message successfully sent and waiting for admin moderation.", 'front-end-pm') );
1424 1772 }
1425 1773 } else {
1426 - fep_errors()->add( 'undefined', __( 'Something wrong. Please try again.', 'front-end-pm' ) );
1774 + fep_errors()->add( 'undefined', __("Something wrong. Please try again.", 'front-end-pm') );
1427 1775 }
1428 1776 }
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 ) {
1777 +
1778 + break;
1779 + case 'bulk_action' :
1780 + case 'announcement_bulk_action' :
1781 + case 'directory_bulk_action' :
1782 + $posted_bulk_action = ! empty($_POST['fep-bulk-action']) ? $_POST['fep-bulk-action'] : '';
1783 + if( ! $posted_bulk_action )
1435 1784 break;
1436 - }
1437 - $token = ! empty( $_POST['token'] ) ? $_POST['token'] : '';
1785 +
1786 + $token = ! empty($_POST['token']) ? $_POST['token'] : '';
1787 +
1438 1788 if ( ! fep_verify_nonce( $token, $action ) ) {
1439 - fep_errors()->add( 'token', __( 'Invalid Token. Please try again!', 'front-end-pm' ) );
1789 + fep_errors()->add( 'token', __("Invalid Token. Please try again!", 'front-end-pm') );
1440 1790 break;
1441 1791 }
1792 +
1442 1793 do_action( "fep_posted_bulk_{$action}", $posted_bulk_action );
1443 - break;
1794 +
1795 + break;
1796 + /*
1797 + // See Fep_User_Settings Class
1798 + case ( 'settings' == $action && ! empty( $menu['settings'] ) ) :
1799 +
1800 + add_action ('fep_action_form_validated', 'fep_user_settings_save', 10, 2);
1801 +
1802 + Fep_Form::init()->validate_form_field( 'settings' );
1803 +
1804 + if( count( fep_errors()->get_error_messages()) == 0 ){
1805 + fep_success()->add( 'saved', __("Settings successfully saved.", 'front-end-pm') );
1806 + }
1807 +
1808 + break;
1809 + */
1444 1810 default:
1445 - do_action( 'fep_posted_action' );
1446 - break;
1811 + do_action( "fep_posted_action" );
1812 + break;
1813 +
1447 1814 }
1448 - do_action( 'fep_posted_action_after', $action );
1449 1815
1450 - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
1816 + if( defined( 'DOING_AJAX' ) && DOING_AJAX ){
1451 1817 $response = array();
1452 - if ( count( fep_errors()->get_error_messages() ) > 0 ) {
1818 + if( count( fep_errors()->get_error_messages()) > 0){
1453 1819 $response['fep_return'] = 'error';
1454 - } elseif ( count( fep_success()->get_error_messages() ) > 0 ) {
1820 + } elseif( count( fep_success()->get_error_messages()) > 0 ){
1455 1821 $response['fep_return'] = 'success';
1456 1822 } else {
1457 1823 $response['fep_return'] = '';
1458 1824 }
1459 1825 $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 - }
1826 +
1463 1827 wp_send_json( $response );
1464 - } elseif ( ! empty( $_POST['fep_redirect'] ) ) {
1828 + } elseif( !empty( $_POST['fep_redirect'] ) ){
1465 1829 wp_safe_redirect( $_POST['fep_redirect'] );
1466 1830 exit;
1467 1831 }
1468 1832 }
1469 1833
1470 -function fep_get_participants( $message_id, $exclude_deleted = false ) {
1471 - if ( empty( $message_id ) || ! is_numeric( $message_id ) ) {
1472 - return array();
1834 +function fep_user_settings_save( $where, $fields )
1835 +{
1836 + if( 'settings' != $where )
1837 + return;
1838 +
1839 + _deprecated_function( __FUNCTION__, '5.3', 'Fep_User_Settings Class' );
1840 +
1841 + if( !$fields || ! is_array( $fields ) )
1842 + return;
1843 +
1844 + $settings = array();
1845 +
1846 + foreach( $fields as $field ) {
1847 + $settings[$field['name']] = $field['posted-value'];
1473 1848 }
1849 + $settings = apply_filters('fep_filter_user_settings_before_save', $settings );
1850 +
1851 + update_user_option( get_current_user_id(), 'FEP_user_options', $settings);
1852 +}
1474 1853
1475 - $participants = FEP_Participants::init()->get( $message_id, false, $exclude_deleted );
1476 - $return = [];
1854 +function fep_get_participants( $message_id ){
1855 + if( empty( $message_id ) || ! is_numeric( $message_id ) )
1856 + return array();
1477 1857
1478 - foreach( $participants as $participant ){
1479 - $return[] = $participant->mgs_participant;
1858 + if( 'threaded' == fep_get_message_view() ) {
1859 + $message_id = fep_get_parent_id( $message_id );
1480 1860 }
1481 - return $return;
1861 + $participants = get_post_meta( $message_id, '_fep_participants' );
1862 +
1863 + if( ! $participants )
1864 + $participants = get_post_meta( $message_id, '_participants' );
1865 +
1866 + return $participants;
1482 1867 }
1483 1868
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 - }
1869 +function fep_get_participant_roles( $announcement_id ){
1870 + if( empty( $announcement_id ) || ! is_numeric( $announcement_id ) )
1871 + return array();
1872 +
1873 + $roles = get_post_meta( $announcement_id, '_fep_participant_roles' );
1874 +
1875 + if( ! $roles )
1876 + $roles = get_post_meta( $announcement_id, '_participant_roles' );
1877 +
1490 1878 return $roles;
1491 1879 }
1492 1880
1493 -function fep_get_message_view() {
1494 - $message_view = fep_get_option( 'message_view', 'threaded' );
1881 +function fep_get_message_view(){
1882 + $message_view = fep_get_option('message_view','threaded');
1495 1883 $message_view = apply_filters( 'fep_get_message_view', $message_view );
1496 - if ( ! $message_view || ! in_array( $message_view, array( 'threaded', 'individual' ) ) ) {
1884 +
1885 + if( ! $message_view || ! in_array( $message_view, array( 'threaded', 'individual' ) ) )
1497 1886 $message_view = 'threaded';
1498 - }
1887 +
1499 1888 return $message_view;
1500 1889 }
1501 1890
1502 -function fep_get_blocked_users_for_user( $userid = '' ) {
1891 +function fep_get_blocked_users_for_user( $userid = '' ){
1503 1892 $return = array();
1504 - if ( $blocked_users = fep_get_user_option( 'blocked_users', '', $userid ) ) {
1893 +
1894 + if( $blocked_users = fep_get_user_option( 'blocked_users', '', $userid ) ){
1505 1895 $blocked_users = explode( ',', $blocked_users );
1506 1896 $return = array_filter( array_map( 'absint', $blocked_users ) );
1507 1897 }
1508 1898 return apply_filters( 'fep_get_blocked_users_for_user', $return, $userid );
@@ -1507,29 +1897,32 @@
1507 1897 }
1508 1898 return apply_filters( 'fep_get_blocked_users_for_user', $return, $userid );
1509 1899 }
1510 1900
1511 -function fep_is_user_blocked_for_user( $userid, $check_id = '' ) {
1901 +function fep_is_user_blocked_for_user( $userid, $check_id = '' ){
1512 1902 $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 - }
1903 +
1904 + if( ! $check_id )
1905 + $check_id = get_current_user_id();
1906 +
1907 + if( in_array( $check_id, $blocked_users ) )
1908 + return true;
1909 +
1519 1910 return false;
1520 1911 }
1521 1912
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 );
1913 +function fep_block_users_for_user( $user_ids, $userid ='' ){
1914 +
1915 + if( is_numeric( $user_ids ) )
1916 + $user_ids = array( $user_ids );
1917 +
1918 + if( ! $user_ids || ! is_array( $user_ids ) )
1919 + return 0;
1920 +
1921 + $blocked_users = fep_get_blocked_users_for_user( $userid = '' );
1530 1922 $need_block = array_diff( $user_ids, $blocked_users );
1531 - if ( $need_block ) {
1923 +
1924 + if( $need_block ){
1532 1925 $blocked_users = array_unique( array_merge( $blocked_users, $need_block ) );
1533 1926 fep_update_user_option( 'blocked_users', implode( ',', $blocked_users ) );
1534 1927 }
1535 1928 return count( $need_block );
@@ -1534,18 +1927,19 @@
1534 1927 }
1535 1928 return count( $need_block );
1536 1929 }
1537 1930
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 - }
1931 +function fep_unblock_users_for_user( $user_ids, $userid ='' ){
1932 + if( is_numeric( $user_ids ) )
1933 + $user_ids = array( $user_ids );
1934 +
1935 + if( ! $user_ids || ! is_array( $user_ids ) )
1936 + return 0;
1937 +
1545 1938 $blocked_users = fep_get_blocked_users_for_user( $userid = '' );
1546 1939 $need_unblock = array_intersect( $blocked_users, $user_ids );
1547 - if ( $need_unblock ) {
1940 +
1941 + if( $need_unblock ){
1548 1942 $blocked_users = array_unique( array_diff( $blocked_users, $need_unblock ) );
1549 1943 fep_update_user_option( 'blocked_users', implode( ',', $blocked_users ) );
1550 1944 }
1551 1945 return count( $need_unblock );
@@ -1550,26 +1944,28 @@
1550 1944 }
1551 1945 return count( $need_unblock );
1552 1946 }
1553 1947
1554 -function fep_sanitize_html_class( $class ) {
1555 - if ( $class ) {
1556 - if ( ! is_array( $class ) ) {
1557 - $class = explode( ' ', $class );
1558 - }
1948 +function fep_sanitize_html_class( $class ){
1949 + if ( $class ){
1950 + if( ! is_array( $class ) )
1951 + $class = explode( ' ', $class );
1559 1952 $class = array_map( 'sanitize_html_class', $class );
1560 - $class = implode( ' ', array_unique( array_filter( $class ) ) );
1953 + $class = implode( ' ', array_filter( $class ) );
1561 1954 }
1562 - if ( ! is_string( $class ) ) {
1563 - $class = '';
1564 - }
1565 - return apply_filters( 'fep_sanitize_html_class', $class );
1955 + if( ! is_string( $class ) )
1956 + $class = '';
1957 +
1958 + return $class;
1566 1959 }
1567 1960
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' ) ) {
1961 +add_filter( 'document_title_parts', 'fep_show_unread_count_in_title', 999 );
1962 +
1963 +function fep_show_unread_count_in_title( $title ){
1964 + if( fep_get_option( 'show_unread_count_in_title', 1 ) && fep_current_user_can( 'access_message' ) ){
1570 1965 wp_enqueue_script( 'fep-notification-script' );
1571 - if ( $count = fep_get_new_message_number() ) {
1966 +
1967 + if( $count = fep_get_new_message_number() ){
1572 1968 $count = number_format_i18n( $count );
1573 1969 $title['title'] = "($count) " . $title['title'];
1574 1970 }
1575 1971 }
@@ -1575,204 +1971,19 @@
1575 1971 }
1576 1972 return $title;
1577 1973 }
1578 1974
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' ) ) {
1975 +add_filter( 'pre_get_document_title', 'fep_pre_get_document_title', 999 );
1976 +
1977 +function fep_pre_get_document_title( $title ){
1978 +
1979 + if( ! empty( $title ) && fep_get_option( 'show_unread_count_in_title', 1 ) && fep_current_user_can( 'access_message' ) ){
1581 1980 wp_enqueue_script( 'fep-notification-script' );
1582 - if ( $count = fep_get_new_message_number() ) {
1981 +
1982 + if( $count = fep_get_new_message_number() ){
1583 1983 $count = number_format_i18n( $count );
1584 1984 $title = "($count) " . $title;
1585 1985 }
1586 1986 }
1587 1987 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 1988 }
1778 1989