· 10 years ago · Sep 16, 2016, 07:24 PM
1<?php
2/*
3Plugin Name: WordPress Chat
4Plugin URI: http://premium.wpmudev.org/project/wordpress-chat-plugin
5Description: Provides you with a fully featured chat area either in a post, page, widget or bottom corner of your site. Support BuddyPress Group chat and private chats between logged in users.
6Author: WPMU DEV
7WDP ID: 159
8Version: 2.1.3
9Author URI: http://premium.wpmudev.org
10Text Domain: wordpress_chat
11Domain Path: /languages
12Contributors: Paul Menard, Umesh Kumar
13*/
14
15// Needs to be set BEFORE loading wpmudev_chat_utilities.php!
16//define('CHAT_DEBUG_LOG', 1);
17
18include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_utilities.php' );
19include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_wpadminbar.php' );
20
21if ( ( ! defined( 'WPMUDEV_CHAT_SHORTINIT' ) ) || ( WPMUDEV_CHAT_SHORTINIT != true ) ) {
22 include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_widget.php' );
23 include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_buddypress.php' );
24}
25if ( ! class_exists( 'WPMUDEV_Chat' ) ) {
26 class WPMUDEV_Chat {
27 var $chat_current_version = '2.1.3';
28 var $translation_domain = 'wordpress-chat';
29
30 /**
31 * @var array $_chat_options Consolidated options
32 */
33 var $_chat_plugin_settings = array(); // Container for setting within the running code.
34
35 var $_chat_options = array(); // This is the local instance of the combined options from the wp_options table
36 var $_chat_options_defaults = array();
37
38 var $_admin_notice_messages = array();
39 var $_admin_notice_messages_key = ''; // Used to store local admin notices message during setting save submits
40
41 var $chat_localized = array(); // Contains localized strings passed to the JS file for display to user.
42
43 var $chat_performance = array(); // Contains information related to execution time, memory usage and other performance metrics
44
45 var $chat_sessions = array(); // Contains all active user chat_sessions known.
46 var $chat_sessions_meta = array(); // Contains all session meta information last_row, sessions_status, deleted rows, active users.
47 var $chat_user = array(); // Container for all user settings by chat_session. Things like if the chat window is minimized, sound on/off etc.
48 var $chat_auth = array(); // Container global information for how user is authenticated, avatar src, name, ID, user_hash.
49
50 var $user_meta = array(); // Contains usermeta information related to Chat functionality within wp-admin
51
52 var $using_popup_out_template = false; // Flag set when loadin the pop-out template
53
54 var $_show_own_admin = false; // Flag set in on_load_panels() and user in wp-footer and wp_enqueue_scripts to know what script/styles to load.
55
56 var $_registered_scripts = array(); // array of scripts registered or enqueued via the various startup methods. User in wp_footer via print_scripts
57 var $_registered_styles = array(); // array of styles registered or enqueued via the various startup methods. User in wp_footer via print_styles
58
59 var $site_content = ''; // Holder for site (bottom corner chats) build during many actions.
60 var $font_list; // Not used.
61
62 var $chat_log_list_table = false;
63
64 /**
65 * Initializing object
66 *
67 * Plugin register actions, filters and hooks.
68 */
69
70 function __construct() {
71
72 $this->chat_sessions = array();
73 $this->chat_sessions_meta = array();
74 $this->chat_auth = array();
75 $this->chat_user = array();
76 $this->_chat_options = array();
77
78 $this->_chat_plugin_settings['plugin_path'] = dirname( __FILE__ );
79 $this->_chat_plugin_settings['plugin_url'] = plugins_url( '', __FILE__ );
80 $this->_chat_plugin_settings['blocked_urls'] = array();
81 $this->_chat_plugin_settings['network_active'] = false;
82 $this->_chat_plugin_settings['config_file'] = dirname( __FILE__ ) . '/wpmudev-chat-config.php';
83
84 // Check our version against the options table
85 if ( is_multisite() ) {
86 $this->_chat_plugin_settings['options_version'] = get_site_option( 'wpmudev-chat-version', false );
87 } else {
88 $this->_chat_plugin_settings['options_version'] = get_option( 'wpmudev-chat-version', false );
89 }
90
91 // Short circut out. We don't need these during our SHORTINIT processing.
92 if ( ( defined( 'WPMUDEV_CHAT_SHORTINIT' ) ) && ( WPMUDEV_CHAT_SHORTINIT == true ) ) {
93 return;
94 }
95
96 // Add support for new WPMUDEV Dashboard Notices
97
98 global $wpmudev_notices;
99 $wpmudev_notices[] = array(
100 'id' => 159,
101 'name' => 'WordPress Chat',
102 'screens' => array(
103 'toplevel_page_chat_settings_panel',
104 'chat_page_chat_settings_panel_site',
105 'chat_page_chat_settings_panel_widge',
106 'chat_page_chat_settings_panel_global',
107 'chat_page_chat_session_logs'
108 )
109 );
110 include_once( dirname( __FILE__ ) . '/lib/dash-notices/wpmudev-dash-notification.php' );
111
112 // Activation deactivation hooks
113 register_activation_hook( __FILE__, array( &$this, 'install' ) );
114 register_deactivation_hook( __FILE__, array( &$this, 'uninstall' ) );
115
116 add_action( 'init', array( &$this, 'init' ) );
117 add_action( 'wp_head', array( &$this, 'wp_head' ) );
118 add_action( 'wp_enqueue_scripts', array( &$this, 'wp_enqueue_scripts' ) );
119
120 add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
122 add_action( 'admin_init', array( &$this, 'admin_init' ) );
123 add_action( 'admin_head', array( &$this, 'wp_head' ) );
124 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
125 add_action( 'admin_notices', array( &$this, 'admin_notices' ) );
126 add_action( 'network_admin_notices', array( &$this, 'admin_notices' ) );
127
128 add_action( 'wp', array( &$this, 'load_template' ), 1 );
129// add_action( 'wp_login', array( &$this, 'unset_cookies' ), 99, 2 );
130
131 add_action( 'wp_footer', array( &$this, 'wp_footer' ), 1 );
132 add_action( 'admin_footer', array( &$this, 'admin_footer' ), 1 );
133
134 // Actions for editing/saving user profile.
135 add_action( 'show_user_profile', array( &$this, 'chat_edit_user_profile' ) );
136 add_action( 'personal_options_update', array( &$this, 'chat_save_user_profile' ) );
137 add_action( 'edit_user_profile', array( &$this, 'chat_edit_user_profile' ) );
138 add_action( 'edit_user_profile_update', array( &$this, 'chat_save_user_profile' ) );
139 add_action( 'delete_user', array( &$this, 'chat_delete_user' ), 10, 2 );
140
141 add_filter( 'manage_users_columns', array( &$this, 'chat_manage_users_columns' ) );
142 add_filter( 'manage_users_custom_column', array( &$this, 'chat_manage_users_custom_column' ), 10, 3 );
143
144 add_action( 'wp_ajax_chatProcess', array( &$this, 'process_chat_actions' ) );
145 add_action( 'wp_ajax_nopriv_chatProcess', array( &$this, 'process_chat_actions' ) );
146
147 // TinyMCE options
148 add_action( 'wp_ajax_chatTinymceOptions', array( &$this, 'tinymce_options' ) );
149
150 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
151 add_action( 'network_admin_menu', array( &$this, 'network_admin_menu' ) );
152
153 // Uncomment when ready to show chat on the WP admin toolbar. Not ready 2013-01-31
154 add_action( 'wp_before_admin_bar_render', 'wpmudev_chat_wpadminbar_render' );
155
156 add_shortcode( 'chat', array( &$this, 'process_chat_shortcode' ) );
157 }
158
159 /**
160 * Get the table name with prefixes
161 *
162 * @global object $wpdb
163 *
164 * @param string $table Table name
165 *
166 * @return string Table name complete with prefixes
167 */
168 static function tablename( $table ) {
169 global $wpdb;
170
171 // We use a single table for all chats accross the network
172 return $wpdb->base_prefix . 'wpmudev_chat_' . $table;
173 }
174
175 /**
176 * Determine if we need to run the DB update options to bring the system up to date.
177 *
178 * @global none
179 *
180 * @param none
181 *
182 * @return none
183 */
184 function check_upgrade() {
185
186 if ( ( empty( $this->_chat_plugin_settings['options_version'] ) )
187 || ( version_compare( $this->chat_current_version, $this->_chat_plugin_settings['options_version'] ) > 0 )
188 ) {
189
190 // Setup the database tables
191 $this->install();
192
193 if ( version_compare( $this->_chat_plugin_settings['options_version'], '2.6' ) < 0 ) {
194 global $wpdb, $blog_id;
195
196 $sql_str = $wpdb->prepare( "UPDATE `" . WPMUDEV_Chat::tablename( 'log' ) . "` SET blog_id = %d WHERE blog_id = %d AND session_type != %s", 1, 0, 'network-site' );
197 //echo "sql_str=[". $sql_str ."]<br />";
198 $wpdb->query( $sql_str );
199
200 $sql_str = $wpdb->prepare( "UPDATE `" . WPMUDEV_Chat::tablename( 'message' ) . "` SET blog_id = %d WHERE blog_id = %d AND session_type != %s", 1, 0, 'network-site' );
201 //echo "sql_str=[". $sql_str ."]<br />";
202 $wpdb->query( $sql_str );
203
204 $sql_str = $wpdb->prepare( "UPDATE `" . WPMUDEV_Chat::tablename( 'users' ) . "` SET blog_id = %d WHERE blog_id = %d ", 1, 0 );
205 //echo "sql_str=[". $sql_str ."]<br />";
206 $wpdb->query( $sql_str );
207
208 // Need to drop the 'created column from the log table as it it not used anymore
209 //$sql_str = "ALTER TABLE `". WPMUDEV_Chat::tablename('log') ."` DROP COLUMN `created`";
210 //@$wpdb->query( $sql_str );
211
212 // Now to do some data manipulation.
213 $logs = $this->get_archives( array() );
214
215 if ( ( $logs ) && ( count( $logs ) ) ) {
216
217 foreach ( $logs as $log ) {
218
219 $chat_session_log = array();
220 $chat_session_log['blog_id'] = $log->blog_id;
221 $chat_session_log['id'] = $log->chat_id;
222 $chat_session_log['session_type'] = $log->session_type;
223
224 $chat_session_log['since'] = strtotime( $log->start );
225 $chat_session_log['end'] = strtotime( $log->end );
226 $chat_session_log['log_limit'] = 0;
227 $chat_session_log['orderby'] = 'ASC';
228 $chat_session_log['archived'] = array( 'yes' );
229 $chat_session_log['last_row_id'] = 0;
230
231 $chat_log_rows = $this->chat_session_get_messages( $chat_session_log );
232 if ( ( $chat_log_rows ) && ( count( $chat_log_rows ) ) ) {
233 $row_ids = array();
234
235 foreach ( $chat_log_rows as $row ) {
236
237 $row_ids[] = $row->id;
238 }
239
240 if ( count( $row_ids ) ) {
241
242 // Update the message rows to reference the log id
243 $sql_str = $wpdb->prepare( "UPDATE `" . WPMUDEV_Chat::tablename( 'message' ) . "` SET log_id = %d WHERE id IN (" . implode( ',', $row_ids ) . ");",
244 $log->id );
245 //echo "sql_str=[". $sql_str ."]<br />";
246 $wpdb->query( $sql_str );
247 }
248 }
249 }
250 }
251
252 // Now update the options
253 if ( is_multisite() ) {
254 update_site_option( 'wpmudev-chat-version', $this->chat_current_version );
255 } else {
256 update_option( 'wpmudev-chat-version', $this->chat_current_version );
257 }
258
259 }
260 }
261 }
262
263 /**
264 * Activation hook
265 *
266 * Create tables if they don't exist and add plugin options
267 *
268 * @see http://codex.wordpress.org/Function_Reference/register_activation_hook
269 *
270 * @global object $wpdb
271 */
272 function install() {
273 global $wpdb;
274
275 if ( ( ! empty( $this->_chat_plugin_settings['config_file'] ) ) && ( is_writable( dirname( $this->_chat_plugin_settings['config_file'] ) ) ) ) {
276 $configs_array = array();
277 $configs_array['ABSPATH'] = base64_encode( ABSPATH );
278 file_put_contents( $this->_chat_plugin_settings['config_file'], serialize( $configs_array ) );
279 }
280
281 /**
282 * WordPress database upgrade/creation functions
283 */
284 if ( ! function_exists( 'dbDelta' ) ) {
285 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
286 }
287
288 // Get the correct character collate
289 if ( ! empty( $wpdb->charset ) ) {
290 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
291 }
292 if ( ! empty( $wpdb->collate ) ) {
293 $charset_collate .= " COLLATE $wpdb->collate";
294 }
295
296 $sql_table_message_1_3_x = "CREATE TABLE " . WPMUDEV_Chat::tablename( 'message' ) . " (
297 id BIGINT NOT NULL AUTO_INCREMENT,
298 blog_id INT NOT NULL ,
299 chat_id INT NOT NULL ,
300 timestamp TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ,
301 name VARCHAR( 255 ) CHARACTER SET utf8 NOT NULL ,
302 avatar VARCHAR( 1024 ) CHARACTER SET utf8 NOT NULL ,
303 message TEXT CHARACTER SET utf8 NOT NULL ,
304 moderator ENUM( 'yes', 'no' ) NOT NULL DEFAULT 'no' ,
305 archived ENUM( 'yes', 'no', 'yes-deleted', 'no-deleted' ) DEFAULT 'no' ,
306 PRIMARY KEY (id),
307 KEY blog_id (blog_id),
308 KEY chat_id (chat_id),
309 KEY timestamp (timestamp),
310 KEY archived (archived)
311 ) {$charset_collate};";
312
313 $sql_table_log_1_3_x = "CREATE TABLE " . WPMUDEV_Chat::tablename( 'log' ) . " (
314 id BIGINT NOT NULL AUTO_INCREMENT,
315 blog_id INT NOT NULL ,
316 chat_id INT NOT NULL ,
317 start TIMESTAMP DEFAULT '0000-00-00 00:00:00' ,
318 end TIMESTAMP DEFAULT '0000-00-00 00:00:00' ,
319 created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
320 PRIMARY KEY (id),
321 KEY blog_id (blog_id),
322 KEY chat_id (chat_id)
323 ) {$charset_collate};";
324
325
326 $sql_table_message_current = "CREATE TABLE " . WPMUDEV_Chat::tablename( 'message' ) . " (
327 id bigint(20) NOT NULL AUTO_INCREMENT ,
328 blog_id bigint(20) unsigned NOT NULL ,
329 chat_id varchar(40) NOT NULL ,
330 session_type varchar(40) NOT NULL ,
331 timestamp TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ,
332 name varchar(255) NOT NULL ,
333 avatar varchar(1024) NOT NULL ,
334 auth_hash varchar(50) NOT NULL ,
335 user_type varchar(50) NOT NULL ,
336 ip_address varchar(50) NOT NULL ,
337 message text NOT NULL ,
338 moderator enum('no','yes') NOT NULL DEFAULT 'no' ,
339 deleted enum('no','yes') NOT NULL DEFAULT 'no' ,
340 archived enum('no','yes') NOT NULL DEFAULT 'no' ,
341 log_id INT(11) NOT NULL ,
342 PRIMARY KEY (id) ,
343 KEY blog_id (blog_id) ,
344 KEY chat_id (chat_id) ,
345 KEY auth_hash (auth_hash) ,
346 KEY session_type (session_type) ,
347 KEY timestamp (timestamp) ,
348 KEY archived (archived) ,
349 KEY log_id (log_id)
350 ) {$charset_collate};";
351
352 $sql_table_log_current = "CREATE TABLE " . WPMUDEV_Chat::tablename( 'log' ) . " (
353 id BIGINT NOT NULL AUTO_INCREMENT,
354 blog_id bigint(20) unsigned NOT NULL ,
355 chat_id VARCHAR( 40 ) NOT NULL ,
356 session_type VARCHAR( 40 ) NOT NULL,
357 box_title VARCHAR( 50 ) NOT NULL,
358 start TIMESTAMP DEFAULT '0000-00-00 00:00:00',
359 end TIMESTAMP DEFAULT '0000-00-00 00:00:00',
360 deleted enum('no','yes') NOT NULL DEFAULT 'no',
361 archived enum('no','yes') NOT NULL DEFAULT 'yes',
362 PRIMARY KEY (id),
363 KEY blog_id (blog_id),
364 KEY chat_id (chat_id),
365 KEY session_type (session_type),
366 KEY deleted (deleted)
367 ) {$charset_collate};";
368
369 $sql_table_users_current = "CREATE TABLE " . WPMUDEV_Chat::tablename( 'users' ) . " (
370 blog_id bigint(20) unsigned NOT NULL,
371 chat_id varchar(40) NOT NULL,
372 auth_hash varchar(50) NOT NULL,
373 name varchar(255) NOT NULL,
374 avatar varchar(255) NOT NULL,
375 moderator enum('no','yes') NOT NULL DEFAULT 'no',
376 last_polled timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
377 entered timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
378 user_type varchar(50) NOT NULL ,
379 ip_address varchar(39) NOT NULL DEFAULT '',
380 PRIMARY KEY (blog_id,chat_id,auth_hash),
381 KEY blog_id (blog_id),
382 KEY chat_id (chat_id),
383 KEY auth_hash (auth_hash),
384 KEY last_polled (last_polled)
385 ) {$charset_collate};";
386
387 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . WPMUDEV_Chat::tablename( 'message' ) . "'" ) != WPMUDEV_Chat::tablename( 'message' ) ) {
388 // First check if we have the old Chat 1.3.x table still around.
389 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->base_prefix . "chat_message'" ) == $wpdb->base_prefix . "chat_message" ) {
390
391 // Create a new table with the same structure.
392 dbDelta( $sql_table_message_1_3_x );
393
394 // Now copy the rows from the old table into the new table.
395 $sql_str = "INSERT INTO `" . WPMUDEV_Chat::tablename( 'message' ) . "` SELECT * FROM " . $wpdb->base_prefix . "chat_message;";
396 $wpdb->query( $sql_str );
397
398 // Finally we alter the table structure to work with our new plugin
399 dbDelta( $sql_table_message_current );
400
401 $wpdb->query( $sql_str );
402
403 } else {
404 dbDelta( $sql_table_message_current );
405 }
406
407 } else {
408 dbDelta( $sql_table_message_current );
409 }
410
411 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . WPMUDEV_Chat::tablename( 'log' ) . "'" ) != WPMUDEV_Chat::tablename( 'log' ) ) {
412 // First check if we have the old Chat 1.3.x table still around.
413 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $wpdb->base_prefix . "chat_log'" ) == $wpdb->base_prefix . "chat_log" ) {
414 dbDelta( $sql_table_log_1_3_x );
415
416 // Now copy the rows from the old table into the new table.
417 $sql_str = "INSERT INTO `" . WPMUDEV_Chat::tablename( 'log' ) . "` SELECT * FROM " . $wpdb->base_prefix . "chat_log;";
418 $wpdb->query( $sql_str );
419
420 // Setup the chat log table
421 dbDelta( $sql_table_log_current );
422
423 } else {
424 dbDelta( $sql_table_log_current );
425 }
426 } else {
427 dbDelta( $sql_table_log_current );
428 }
429
430 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . WPMUDEV_Chat::tablename( 'users' ) . "'" ) != WPMUDEV_Chat::tablename( 'users' ) ) {
431 dbDelta( $sql_table_users_current );
432 } else {
433 dbDelta( $sql_table_users_current );
434 }
435
436 $this->load_configs();
437
438 add_option( 'wpmudev-chat-page', $this->_chat_options['page'] );
439 add_option( 'wpmudev-chat-site', $this->_chat_options['site'] );
440 add_option( 'wpmudev-chat-widget', $this->_chat_options['widget'] );
441 add_option( 'wpmudev-chat-global', $this->_chat_options['global'] );
442 add_option( 'wpmudev-chat-banned', $this->_chat_options['banned'] );
443
444 if ( ( is_multisite() ) && ( is_network_admin() ) ) {
445 add_site_option( 'wpmudev-chat-site', $this->_chat_options['site'] );
446 add_site_option( 'wpmudev-chat-widget', $this->_chat_options['widget'] );
447 }
448 }
449
450 /**
451 * Deactivation hook
452 *
453 * @see http://codex.wordpress.org/Function_Reference/register_deactivation_hook
454 *
455 * @global object $wpdb
456 */
457 function uninstall() {
458 global $wpdb;
459 // Nothing to do
460 }
461
462 /**
463 * Loads the various config options from get_options calls. Parse the config array with the defaults in case new options were added/removed.
464 *
465 * @global none
466 *
467 * @param none
468 *
469 * @return none
470 */
471
472 function load_configs() {
473 global $blog_id;
474
475 $this->set_option_defaults();
476
477 $this->_chat_options['user-statuses'] = get_option( 'wpmudev-chat-user-statuses', array() );
478 $this->_chat_options['user-statuses'] = wp_parse_args( $this->_chat_options['user-statuses'], $this->_chat_options_defaults['user-statuses'] );
479
480 if ( isset( $_POST['wpmudev-chat-sessions'] ) ) {
481 if ( ( is_array( $_POST['wpmudev-chat-sessions'] ) ) && ( count( $_POST['wpmudev-chat-sessions'] ) ) ) {
482
483 foreach ( $_POST['wpmudev-chat-sessions'] as $chat_session ) {
484 $chat_id = $chat_session['id'];
485 $transient_key = "chat-session-" . $chat_session['id'] . '-' . $chat_session['session_type'];
486
487 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
488 $chat_session_transient = get_option( $transient_key );
489 } else {
490 $chat_session_transient = get_transient( $transient_key );
491 }
492
493 if ( ( ! empty( $chat_session_transient ) ) && ( is_array( $chat_session_transient ) ) ) {
494 $chat_session_merge = wp_parse_args( $chat_session, $chat_session_transient );
495 if ( ( ! empty( $chat_session_merge ) ) && ( is_array( $chat_session_merge ) ) ) {
496
497 $chat_session_merge = $this->chat_session_show_via_logs( $chat_session_merge );
498 }
499
500 $this->chat_sessions[ $chat_id ] = $chat_session_merge;
501 }
502
503 $this->chat_sessions_meta[ $chat_id ] = $this->chat_session_get_meta( $chat_session );
504 }
505 }
506 }
507
508 foreach ( $this->chat_sessions as $chat_id => $chat_session ) {
509 if ( ( isset( $chat_session['template'] ) ) && ( $chat_session['template'] == "wpmudev-chat-pop-out" ) ) {
510 $this->using_popup_out_template = true;
511 }
512 }
513
514 if ( ! empty( $_COOKIE['wpmudev-chat-auth'] ) ) {
515 $this->chat_auth = json_decode( stripslashes( $_COOKIE['wpmudev-chat-auth'] ), true );
516 } else {
517 $this->chat_auth = array();
518 }
519
520
521 if ( ( ! isset( $this->chat_auth['type'] ) ) || ( empty( $this->chat_auth['type'] ) ) ) {
522 if ( is_user_logged_in() ) {
523 $this->chat_auth['type'] = 'wordpress';
524 }
525 }
526
527 if ( ( isset( $this->chat_auth['type'] ) ) && ( $this->chat_auth['type'] == 'wordpress' ) ) {
528
529 if ( is_user_logged_in() ) {
530 // This is needed to update the user's activity we use to check if a user is online and available for chats
531 $current_user = wp_get_current_user();
532
533 wpmudev_chat_update_user_activity( $current_user->ID );
534
535 $this->chat_auth['type'] = 'wordpress';
536 $this->chat_auth['name'] = $current_user->display_name;
537 $this->chat_auth['email'] = $current_user->user_email;
538 $this->chat_auth['auth_hash'] = md5( $current_user->ID );
539 $this->chat_auth['profile_link'] = '';
540 $this->chat_auth['ip_address'] = ( isset( $_SERVER['HTTP_X_FORWARD_FOR'] ) ) ? $_SERVER['HTTP_X_FORWARD_FOR'] : $_SERVER['REMOTE_ADDR'];
541
542 $this->user_meta = get_user_meta( $current_user->ID, 'wpmudev-chat-user', true );
543
544 // Merge the user's meta info with the defaults.
545 $this->user_meta = wp_parse_args( $this->user_meta, $this->_chat_options_defaults['user_meta'] );
546
547 // Get the user's Chat status carried as part of the user_meta information
548 $chat_user_status = wpmudev_chat_get_user_status( $current_user->ID );
549 if ( isset( $this->_chat_options['user-statuses'][ $chat_user_status ] ) ) {
550 $this->user_meta['chat_user_status'] = $chat_user_status;
551 } else {
552 $this->user_meta['chat_user_status'] = $this->_chat_options_defaults['user_meta']['chat_user_status'];
553 }
554
555 if ( $this->user_meta['chat_name_display'] == "user_login" ) {
556 $this->chat_auth['name'] = $current_user->user_login;
557 } else {
558 $this->chat_auth['name'] = $current_user->display_name;
559 }
560
561 // We can only get the avatar when not in SHORTINIT mode since SHORTINIT removes all other plugin filters.
562 if ( ( ! defined( 'WPMUDEV_CHAT_SHORTINIT' ) ) || ( WPMUDEV_CHAT_SHORTINIT != true ) ) {
563
564 $avatar = get_avatar( $current_user->data->user_email, 96, '', $this->chat_auth['name'] );
565
566 if ( $avatar ) {
567 $avatar_parts = array();
568 if ( stristr( $avatar, ' src="' ) !== false ) {
569 preg_match( '/src="([^"]*)"/i', $avatar, $avatar_parts );
570 } else if ( stristr( $avatar, " src='" ) !== false ) {
571 preg_match( "/src='([^']*)'/i", $avatar, $avatar_parts );
572 }
573 if ( ( isset( $avatar_parts[1] ) ) && ( ! empty( $avatar_parts[1] ) ) ) {
574 $this->chat_auth['avatar'] = $avatar_parts[1];
575 }
576 }
577 }
578 $this->chat_auth['chat_status'] = $this->user_meta['chat_user_status'];
579 } else {
580 //log_chat_message(__FUNCTION__ .": is_user_logged_in: no");
581 $this->chat_auth = array();
582 //$this->chat_auth['type'] = '';
583 }
584 }
585
586 foreach ( $this->chat_sessions as $session_id => $chat_session ) {
587
588 if ( ( isset( $this->chat_auth['type'] ) ) && ( $this->chat_auth['type'] == 'wordpress' ) ) {
589 if ( wpmudev_chat_is_moderator( $chat_session ) ) {
590 $this->chat_sessions[ $session_id ]['moderator'] = "yes";
591 } else {
592 $this->chat_sessions[ $session_id ]['moderator'] = "no";
593 }
594
595 } else {
596 $this->chat_sessions[ $session_id ]['moderator'] = "no";
597 }
598 }
599
600 // Grab user chat_user cookie data. The chat_user cookie contains user settings like sounds on/off or chat box maximixed/minimized.
601 if ( ! empty( $_COOKIE['wpmudev-chat-user'] ) ) {
602 $this->chat_user = json_decode( stripslashes( $_COOKIE['wpmudev-chat-user'] ), true );
603 }
604
605 if ( ! isset( $this->chat_user['__global__'] ) ) {
606 $this->chat_user['__global__'] = array();
607 }
608
609 // The chat_user '__global__' array is the default settings used and compared to the individual settings from the chat_user cookie
610 if ( ! isset( $this->chat_user['__global__']['status_max_min'] ) ) {
611 $this->chat_user['__global__']['status_max_min'] = "max";
612 }
613
614 if ( ! isset( $this->chat_user['__global__']['sound_on_off'] ) ) {
615 $this->chat_user['__global__']['sound_on_off'] = "on";
616 }
617 //Global chat Settings
618 if ( ( is_multisite() ) && ( is_network_admin() ) ) {
619 $this->_chat_options['global'] = get_site_option( 'wpmudev-chat-global', array() );
620 } else {
621 $this->_chat_options['global'] = get_option( 'wpmudev-chat-global', array() );
622 }
623 if ( empty( $this->_chat_options['global'] ) ) { // If empty see if we have an older version
624 $_chat_options_global = get_option( 'chat_default', array() );
625 if ( ! empty( $_chat_options_global ) ) {
626 $this->_chat_options['global'] = $this->convert_config( 'global', $_chat_options_global );
627 }
628 }
629 $this->_chat_options['global'] = wp_parse_args( $this->_chat_options['global'], $this->_chat_options_defaults['global'] );
630
631 $this->_chat_options['page'] = get_option( 'wpmudev-chat-page', array() );
632
633 // Note: For tinymce options we want to allow to conditions. First if these option is NOT set
634 // then we pull the default. But we need to allow the admin to clear the selection. So if the
635 // item is found but empty we don't merge the default options.
636
637 if ( empty( $this->_chat_options['page'] ) ) { // If empty see if we have an older version
638 $_chat_options_default = get_option( 'chat_default', array() );
639 if ( ! empty( $_chat_options_default ) ) {
640 $this->_chat_options['page'] = $this->convert_config( 'page', $_chat_options_default );
641 }
642 $this->_chat_options['page']['tinymce_roles'] = array( 'administrator' );
643 $this->_chat_options['page']['tinymce_post_types'] = array( 'page' );
644 }
645 $this->_chat_options['page'] = wp_parse_args( $this->_chat_options['page'], $this->_chat_options_defaults['page'] );
646
647 $this->_chat_options['site'] = get_option( 'wpmudev-chat-site', array() );
648 if ( empty( $this->_chat_options['site'] ) ) { // If empty see if we have an older version
649 $_chat_options_site = get_option( 'chat_site', array() );
650 if ( ! empty( $_chat_options_site ) ) {
651 $this->_chat_options['site'] = $this->convert_config( 'site', $_chat_options_site );
652 }
653 }
654 $this->_chat_options['site'] = wp_parse_args( $this->_chat_options['site'], $this->_chat_options_defaults['site'] );
655
656 $this->_chat_options['widget'] = get_option( 'wpmudev-chat-widget', array() );
657 $this->_chat_options['widget'] = wp_parse_args( $this->_chat_options['widget'], $this->_chat_options_defaults['widget'] );
658
659 if ( is_network_admin() ) {
660 $this->_chat_options['dashboard'] = get_site_option( 'wpmudev-chat-dashboard', array() );
661 } else {
662 $this->_chat_options['dashboard'] = get_option( 'wpmudev-chat-dashboard', array() );
663 }
664 $this->_chat_options['dashboard'] = wp_parse_args( $this->_chat_options['dashboard'], $this->_chat_options_defaults['dashboard'] );
665
666 $this->_chat_options['bp-group'] = get_option( 'wpmudev-chat-bp-group', array() );
667
668 $this->_chat_options['bp-group'] = wp_parse_args( $this->_chat_options['bp-group'], $this->_chat_options_defaults['bp-group'] );
669 $this->_chat_options['bp-group'] = wp_parse_args( $this->_chat_options['bp-group'], $this->_chat_options['global'] );
670
671 $this->_chat_options['banned'] = get_option( 'wpmudev-chat-banned', array() );
672 $this->_chat_options['banned'] = wp_parse_args( $this->_chat_options['banned'], $this->_chat_options_defaults['banned'] );
673
674
675 $this->_chat_options_defaults['fonts_list'] = array(
676 "Arial" => "Arial, Helvetica, sans-serif",
677 "Arial Black" => "'Arial Black', Gadget, sans-serif",
678 "Bookman Old Style" => "'Bookman Old Style', serif",
679 "Comic Sans MS" => "'Comic Sans MS', cursive",
680 "Courier" => "Courier, monospace",
681 "Courier New" => "'Courier New', Courier, monospace",
682 "Garamond" => "Garamond, serif",
683 "Georgia" => "Georgia, serif",
684 "Impact" => "Impact, Charcoal, sans-serif",
685 "Lucida Console" => "'Lucida Console', Monaco, monospace",
686 "Lucida Sans Unicode" => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
687 "MS Sans Serif" => "'MS Sans Serif', Geneva, sans-serif",
688 "MS Serif" => "'MS Serif', 'New York', sans-serif",
689 "Palatino Linotype" => "'Palatino Linotype', 'Book Antiqua', Palatino, serif",
690 "Symbol" => "Symbol, sans-serif",
691 "Tahoma" => "Tahoma, Geneva, sans-serif",
692 "Times New Roman" => "'Times New Roman', Times, serif",
693 "Trebuchet MS" => "'Trebuchet MS', Helvetica, sans-serif",
694 "Verdana" => "Verdana, Geneva, sans-serif",
695 "Webdings" => "Webdings, sans-serif",
696 "Wingdings" => "Wingdings, 'Zapf Dingbats', sans-serif"
697 );
698
699 if ( ( ! defined( 'WPMUDEV_CHAT_SHORTINIT' ) ) || ( WPMUDEV_CHAT_SHORTINIT != true ) ) {
700
701 $this->_chat_plugin_settings['blocked_urls']['admin'] = wpmudev_chat_check_is_blocked_urls( $this->get_option( 'blocked_admin_urls', 'global' ),
702 $this->get_option( 'blocked_admin_urls_action', 'global' ), false );
703
704 $this->_chat_plugin_settings['blocked_urls']['site'] = wpmudev_chat_check_is_blocked_urls( $this->get_option( 'blocked_urls', 'site' ),
705 $this->get_option( 'blocked_urls_action', 'site' ), false );
706
707 $this->_chat_plugin_settings['blocked_urls']['widget'] = wpmudev_chat_check_is_blocked_urls( $this->get_option( 'blocked_urls', 'widget' ),
708 $this->get_option( 'blocked_urls_action', 'widget' ), true );
709
710 if ( $this->get_option( 'load_jscss_all', 'global' ) == "enabled" ) {
711 $this->_chat_plugin_settings['blocked_urls']['front'] = wpmudev_chat_check_is_blocked_urls( $this->get_option( 'blocked_front_urls', 'global' ),
712 $this->get_option( 'blocked_front_urls_action', 'global' ), false );
713 } else {
714 $this->_chat_plugin_settings['blocked_urls']['front'] = true;
715 }
716 }
717
718 // Related to the Network settings.
719 if ( $this->_chat_plugin_settings['network_active'] == true ) {
720 $this->_chat_options['network-site'] = get_site_option( 'wpmudev-chat-network-site', array() );
721 $this->_chat_options['network-site'] = wp_parse_args( $this->_chat_options['network-site'], $this->_chat_options_defaults['network-site'] );
722 }
723 }
724
725 /**
726 * Converts the config arrays from the old format (version 1.3.x) into the 2.x format.
727 *
728 * @global none
729 *
730 * @param none
731 *
732 * @return none
733 */
734 function convert_config( $section, $old_config ) {
735
736 $new_config = array();
737
738 $old_to_new = array(
739 'id' => 'id',
740 'sound' => 'box_sound',
741 'avatar' => 'row_name_avatar',
742 'emoticons' => 'box_emoticons',
743 'date_show' => 'row_date',
744 'time_show' => 'row_time',
745 'width' => 'box_width',
746 'height' => 'box_height',
747 'background_color' => 'box_background_color',
748 'background_row_area_color' => 'row_area_background_color',
749 'background_row_color' => 'row_background_color',
750 'row_border_color' => 'row_border_color',
751 'row_border_width' => 'row_border_width',
752 'row_spacing' => 'row_spacing',
753 'background_highlighted_color' => 'box_new_message_color',
754 'date_color' => 'row_date_color',
755 'name_color' => 'row_name_color',
756 'moderator_name_color' => 'row_moderator_name_color',
757 'special_color' => 'special_color',
758 'text_color' => 'row_text_color',
759 'code_color' => 'row_code_color',
760 'font' => 'box_font_family',
761 'font_size' => 'box_font_size',
762 'font' => 'row_font_family',
763 'font_size' => 'row_font_size',
764 'font' => 'row_message_input_font_family',
765 'font_size' => 'row_message_input_font_size',
766 'log_creation' => 'log_creation',
767 'log_display' => 'log_display',
768 'log_limit' => 'log_limit',
769 'login_options' => 'login_options',
770 'moderator_roles' => 'moderator_roles',
771 'tinymce_roles' => 'tinymce_roles',
772 'tinymce_post_types' => 'tinymce_post_types',
773 'site' => 'bottom_corner',
774 );
775
776 foreach ( $old_config as $old_config_key => $old_config_val ) {
777 // Remove emoty values to force new defaults.
778 if ( ( empty( $old_config_val ) ) && ( $old_config_key != 'id' ) ) {
779 continue;
780 }
781
782 // Partial kludge. The previous 'avatar' values were enabled/disabled. So we need to convert these to our
783 // new values of 'avatar' or 'name'. Eventually we will have 'avatar_name' to show both. Tristate
784 if ( $old_config_key == "avatar" ) {
785 if ( $old_config_val == "enabled" ) {
786 $new_config[ $old_config_key ] = "avatar";
787 } else {
788 $new_config[ $old_config_key ] = "name";
789 }
790 } else {
791 if ( isset( $old_to_new[ $old_config_key ] ) ) {
792 $new_config[ $old_to_new[ $old_config_key ] ] = $old_config_val;
793 } else {
794 $new_config[ $old_config_key ] = $old_config_val;
795 }
796 }
797 }
798
799 switch ( $section ) {
800 case 'page':
801
802 foreach ( $new_config as $_key => $_val ) {
803 if ( ! isset( $this->_chat_options_defaults['page'][ $_key ] ) ) //echo "key removed[". $_key ."]<br />";
804 {
805 unset( $new_config[ $_key ] );
806 }
807 }
808
809 break;
810
811 case 'site':
812
813 foreach ( $new_config as $_key => $_val ) {
814 if ( ! isset( $this->_chat_options_defaults['site'][ $_key ] ) ) {
815 unset( $new_config[ $_key ] );
816 }
817 }
818
819 break;
820
821 case 'global':
822 foreach ( $new_config as $_key => $_val ) {
823 if ( ! isset( $this->_chat_options_defaults['global'][ $_key ] ) ) {
824 unset( $new_config[ $_key ] );
825 }
826 }
827 break;
828
829 default:
830 break;
831 }
832
833 return $new_config;
834 }
835
836 /**
837 * Initializes our default options. All options processing is marge with the default arrays. This is how we add/remove options over time.
838 *
839 * @global none
840 *
841 * @param none
842 *
843 * @return none
844 */
845 function set_option_defaults() {
846 global $blog_id;
847 $this->_chat_options_defaults['page'] = array(
848 'id' => '',
849 'blog_id' => $blog_id,
850 'session_type' => 'page',
851 'session_status' => defined( 'WPMUDEV_CHAT_PAGE_SESSION_STATUS' ) ? WPMUDEV_CHAT_PAGE_SESSION_STATUS : '',
852 'blocked_ip_addresses_active' => defined( 'WPMUDEV_CHAT_PAGE_BLOCKED_IP_ADDRESSES_ACTIVE' ) ? WPMUDEV_CHAT_PAGE_BLOCKED_IP_ADDRESSES_ACTIVE : 'enabled',
853 'blocked_words_active' => defined( 'WPMUDEV_CHAT_PAGE_BLOCKED_WORDS_ACTIVE' ) ? WPMUDEV_CHAT_PAGE_BLOCKED_WORDS_ACTIVE : 'disabled',
854 'session_status_message' => __( 'The Moderator has closed this chat session', $this->translation_domain ),
855 'session_cleared_message' => __( 'The Moderator has cleared the chat messages', $this->translation_domain ),
856 //'session_status_auto_close' => 'yes',
857 'box_title' => '',
858 'box_width' => defined( 'WPMUDEV_CHAT_PAGE_BOX_WIDTH' ) ? WPMUDEV_CHAT_PAGE_BOX_WIDTH : '100%',
859 'box_width_mobile_adjust' => defined( 'WPMUDEV_CHAT_PAGE_BOX_WIDTH_MOBILE_ADJUST' ) ? WPMUDEV_CHAT_PAGE_BOX_WIDTH_MOBILE_ADJUST : 'window',
860 'box_height' => defined( 'WPMUDEV_CHAT_PAGE_BOX_HEIGHT' ) ? WPMUDEV_CHAT_PAGE_BOX_HEIGHT : '500px',
861 'box_height_mobile_adjust' => defined( 'WPMUDEV_CHAT_PAGE_BOX_HEIGHT_MOBILE_ADJUST' ) ? WPMUDEV_CHAT_PAGE_BOX_HEIGHT_MOBILE_ADJUST : 'full',
862 'box_class' => '',
863 'box_sound' => defined( 'WPMUDEV_CHAT_PAGE_BOX_SOUND' ) ? WPMUDEV_CHAT_PAGE_BOX_SOUND : 'enabled',
864 'box_popout' => defined( 'WPMUDEV_CHAT_PAGE_BOX_POPOUT' ) ? WPMUDEV_CHAT_PAGE_BOX_POPOUT : 'enabled',
865 'box_moderator_footer' => defined( 'WPMUDEV_CHAT_PAGE_BOX_MODERATOR_FOOTER' ) ? WPMUDEV_CHAT_PAGE_BOX_MODERATOR_FOOTER : 'enabled',
866 'box_input_position' => defined( 'WPMUDEV_CHAT_PAGE_BOX_INPUT_POSITION' ) ? WPMUDEV_CHAT_PAGE_BOX_INPUT_POSITION : 'bottom',
867 'box_send_button_enable' => defined( 'WPMUDEV_CHAT_PAGE_BOX_SEND_BUTTON_ENABLE' ) ? WPMUDEV_CHAT_PAGE_BOX_SEND_BUTTON_ENABLE : 'disabled',
868 'box_send_button_position' => defined( 'WPMUDEV_CHAT_PAGE_BOX_SEND_BUTTON_POSITION' ) ? WPMUDEV_CHAT_PAGE_BOX_SEND_BUTTON_POSITION : 'right',
869 'box_send_button_label' => defined( 'WPMUDEV_CHAT_PAGE_BOX_SEND_BUTTON_LABEL' ) ? WPMUDEV_CHAT_PAGE_BOX_SEND_BUTTON_LABEL : 'send',
870 'box_font_family' => defined( 'WPMUDEV_CHAT_PAGE_BOX_FONT_FAMILY' ) ? WPMUDEV_CHAT_PAGE_BOX_FONT_FAMILY : '',
871 'box_font_size' => defined( 'WPMUDEV_CHAT_PAGE_BOX_FONT_SIZE' ) ? WPMUDEV_CHAT_PAGE_BOX_FONT_SIZE : '',
872 'box_text_color' => defined( 'WPMUDEV_CHAT_PAGE_BOX_TEXT_COLOR' ) ? WPMUDEV_CHAT_PAGE_BOX_TEXT_COLOR : '#000000',
873 'box_background_color' => defined( 'WPMUDEV_CHAT_PAGE_BOX_BACKGROUND_COLOR' ) ? WPMUDEV_CHAT_PAGE_BOX_BACKGROUND_COLOR : '#CCCCCC',
874 'box_border_color' => defined( 'WPMUDEV_CHAT_PAGE_BOX_BORDER_COLOR' ) ? WPMUDEV_CHAT_PAGE_BOX_BORDER_COLOR : '#CCCCCC',
875 'box_border_width' => defined( 'WPMUDEV_CHAT_PAGE_BOX_BORDER_WIDTH' ) ? WPMUDEV_CHAT_PAGE_BOX_BORDER_WIDTH : '1px',
876 //'box_padding' => '3px',
877 'box_emoticons' => defined( 'WPMUDEV_CHAT_PAGE_BOX_EMOTICONS' ) ? WPMUDEV_CHAT_PAGE_BOX_EMOTICONS : 'disabled',
878 //'buttonbar' => 'disabled',
879 'row_name_avatar' => defined( 'WPMUDEV_CHAT_PAGE_ROW_NAME_AVATAR' ) ? WPMUDEV_CHAT_PAGE_ROW_NAME_AVATAR : 'avatar',
880 'row_avatar_width' => defined( 'WPMUDEV_CHAT_PAGE_ROW_AVATAR_WIDTH' ) ? WPMUDEV_CHAT_PAGE_ROW_AVATAR_WIDTH : '40px',
881 'row_date' => defined( 'WPMUDEV_CHAT_PAGE_ROW_DATE' ) ? WPMUDEV_CHAT_PAGE_ROW_DATE : 'disabled',
882 'row_date_format' => defined( 'WPMUDEV_CHAT_PAGE_ROW_DATE_FORMAT' ) ? WPMUDEV_CHAT_PAGE_ROW_DATE_FORMAT : get_option( 'date_format' ),
883 'row_time' => defined( 'WPMUDEV_CHAT_PAGE_ROW_TIME' ) ? WPMUDEV_CHAT_PAGE_ROW_TIME : 'disabled',
884 'row_time_format' => defined( 'WPMUDEV_CHAT_PAGE_ROW_TIME_FORMAT' ) ? WPMUDEV_CHAT_PAGE_ROW_TIME_FORMAT : get_option( 'time_format' ),
885 'row_area_background_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_AREA_BACKGROUND_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_AREA_BACKGROUND_COLOR : '#F9F9F9',
886 'row_background_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_BACKGROUND_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_BACKGROUND_COLOR : '#FFFFFF',
887 'row_border_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_BORDER_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_BORDER_COLOR : '#CCCCCC',
888 'row_border_width' => defined( 'WPMUDEV_CHAT_PAGE_ROW_BORDER_WIDTH' ) ? WPMUDEV_CHAT_PAGE_ROW_BORDER_WIDTH : '1px',
889 'row_spacing' => defined( 'WPMUDEV_CHAT_PAGE_ROW_SPACING' ) ? WPMUDEV_CHAT_PAGE_ROW_SPACING : '3px',
890 'row_message_input_font_size' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_FONT_SIZE' ) ? WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_FONT_SIZE : '',
891 'row_message_input_font_family' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_FONT_FAMILY' ) ? WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_FONT_FAMILY : '',
892 'row_message_input_height' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_HEIGHT' ) ? WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_HEIGHT : '45px',
893 'row_message_input_lock' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_LOCK' ) ? WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_LOCK : 'vertical',
894 'row_message_input_length' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_LENGTH' ) ? WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_LENGTH : '450',
895 'row_message_input_background_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_BACKGROUND_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_BACKGROUND_COLOR : '#FFFFFF',
896 'row_message_input_text_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_TEXT_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_MESSAGE_INPUT_TEXT_COLOR : '#000000',
897 'row_date_text_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_DATE_TEXT_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_DATE_TEXT_COLOR : '#6699CC',
898 'row_date_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_DATE_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_DATE_COLOR : '#FFFFFF',
899 'row_name_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_NAME_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_NAME_COLOR : '#666666',
900 'row_moderator_name_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_MODERATOR_NAME_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_MODERATOR_NAME_COLOR : '#6699CC',
901 'row_text_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_TEXT_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_TEXT_COLOR : '#000000',
902 'row_code_color' => defined( 'WPMUDEV_CHAT_PAGE_ROW_CODE_COLOR' ) ? WPMUDEV_CHAT_PAGE_ROW_CODE_COLOR : '#FFFFCC',
903 'row_font_family' => defined( 'WPMUDEV_CHAT_PAGE_ROW_FONT_FAMILY' ) ? WPMUDEV_CHAT_PAGE_ROW_FONT_FAMILY : '',
904 'row_font_size' => defined( 'WPMUDEV_CHAT_PAGE_ROW_FONT_SIZE' ) ? WPMUDEV_CHAT_PAGE_ROW_FONT_SIZE : '',
905 'log_creation' => defined( 'WPMUDEV_CHAT_PAGE_LOG_CREATION' ) ? WPMUDEV_CHAT_PAGE_LOG_CREATION : 'disabled',
906 'log_display' => defined( 'WPMUDEV_CHAT_PAGE_LOG_DISPLAY' ) ? WPMUDEV_CHAT_PAGE_LOG_DISPLAY : 'disabled',
907 'log_display_label' => defined( 'WPMUDEV_CHAT_PAGE_LOG_DISPLAY_LABEL' ) ? WPMUDEV_CHAT_PAGE_LOG_DISPLAY_LABEL : __( 'Chat Logs', $this->translation_domain ),
908 'log_display_limit' => defined( 'WPMUDEV_CHAT_PAGE_LOG_DISPLAY_LIMIT' ) ? WPMUDEV_CHAT_PAGE_LOG_DISPLAY_LIMIT : 10,
909 'log_display_hide_session' => defined( 'WPMUDEV_CHAT_PAGE_LOG_DISPLAY_HIDE_SESSION' ) ? WPMUDEV_CHAT_PAGE_LOG_DISPLAY_HIDE_SESSION : 'show',
910 'log_display_role_level' => defined( 'WPMUDEV_CHAT_PAGE_LOG_DISPLAY_ROLE_LEVEL' ) ? WPMUDEV_CHAT_PAGE_LOG_DISPLAY_ROLE_LEVEL : 'public',
911 'log_limit' => defined( 'WPMUDEV_CHAT_PAGE_LOG_LIMIT' ) ? WPMUDEV_CHAT_PAGE_LOG_LIMIT : '100',
912 //'log_purge' => '',
913 'login_options' => array( 'public_user' ),
914 'moderator_roles' => array(),
915 'users_list_show' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_SHOW' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_SHOW : 'avatar',
916 'users_list_position' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_POSITION' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_POSITION : 'none',
917 'users_list_style' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_STYLE' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_STYLE : 'split',
918 'users_list_width' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_WIDTH' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_WIDTH : '25%',
919 'users_list_avatar_width' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_AVATAR_WIDTH' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_AVATAR_WIDTH : '30px',
920 'users_list_moderator_avatar_border_color' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_MODERATOR_AVATAR_BORDER_COLOR' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_MODERATOR_AVATAR_BORDER_COLOR : '#FFFFFF',
921 'users_list_user_avatar_border_color' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_USER_AVATAR_BORDER_COLOR' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_USER_AVATAR_BORDER_COLOR : '#FFFFFF',
922 'users_list_avatar_border_width' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_AVATAR_BORDER_WIDTH' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_AVATAR_BORDER_WIDTH : '1px',
923 'users_list_threshold_delete' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_THRESHOLD_DELETE' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_THRESHOLD_DELETE : '20',
924 'users_list_background_color' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_BACKGROUND_COLOR' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_BACKGROUND_COLOR : '#FFFFFF',
925 'users_list_name_color' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_NAME_COLOR' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_NAME_COLOR : '#000000',
926 'users_list_moderator_color' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_MODERATOR_COLOR' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_MODERATOR_COLOR : '#000000',
927 'users_list_header' => __( 'Active Users', $this->translation_domain ),
928 'users_list_font_size' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_FONT_SIZE' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_FONT_SIZE : '',
929 'users_list_header_color' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_HEADER_COLOR' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_HEADER_COLOR : '#000000',
930 'users_list_header_font_family' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_HEADER_FONT_FAMILY' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_HEADER_FONT_FAMILY : '',
931 'users_list_header_font_size' => defined( 'WPMUDEV_CHAT_PAGE_USERS_LIST_HEADER_FONT_SIZE' ) ? WPMUDEV_CHAT_PAGE_USERS_LIST_HEADER_FONT_SIZE : '',
932 'users_enter_exit_status' => 'disabled',
933 'users_enter_exit_delay' => '2',
934 'tinymce_roles' => array(),
935 'tinymce_post_types' => array(),
936 'noauth_view' => defined( 'WPMUDEV_CHAT_PAGE_NOAUTH_VIEW' ) ? WPMUDEV_CHAT_PAGE_NOAUTH_VIEW : 'default',
937 'noauth_login_message' => __( 'To get started just enter your email address and desired username:', $this->translation_domain ),
938 'noauth_login_prompt' => __( 'You must login to participate in chat', $this->translation_domain ),
939 //'box_input_moderator_hide' => 'disabled',
940 //'box_input_moderator_hide_label' => __('Waiting for Moderator', $this->translation_domain),
941 'update_transient' => 'enabled'
942 );
943
944 $this->_chat_options_defaults['site'] = wp_parse_args( array(
945 'session_type' => 'site',
946 'bottom_corner' => defined( 'WPMUDEV_CHAT_SITE_BOTTOM_CORNER' ) ? WPMUDEV_CHAT_SITE_BOTTOM_CORNER : 'disabled',
947 'status_max_min' => defined( 'WPMUDEV_CHAT_SITE_STATUS_MAX_MIN' ) ? WPMUDEV_CHAT_SITE_STATUS_MAX_MIN : 'min',
948 'poll_max_min' => defined( 'WPMUDEV_CHAT_SITE_POLL_MAX_MIN' ) ? WPMUDEV_CHAT_SITE_POLL_MAX_MIN : 'disabled',
949 'bottom_corner_wpadmin' => defined( 'WPMUDEV_CHAT_SITE_BOTTOM_CORNER_WPADMIN' ) ? WPMUDEV_CHAT_SITE_BOTTOM_CORNER_WPADMIN : 'disabled',
950 'box_width' => defined( 'WPMUDEV_CHAT_SITE_BOX_WIDTH' ) ? WPMUDEV_CHAT_SITE_BOX_WIDTH : '200px',
951 'box_height' => defined( 'WPMUDEV_CHAT_SITE_BOX_HEIGHT' ) ? WPMUDEV_CHAT_SITE_BOX_HEIGHT : '300px',
952 'box_position_h' => defined( 'WPMUDEV_CHAT_SITE_BOX_POSITION_H' ) ? WPMUDEV_CHAT_SITE_BOX_POSITION_H : 'right',
953 'box_position_v' => defined( 'WPMUDEV_CHAT_SITE_BOX_POSITION_V' ) ? WPMUDEV_CHAT_SITE_BOX_POSITION_V : 'bottom',
954 'box_position_adjust_mobile' => defined( 'WPMUDEV_CHAT_SITE_BOX_POSITION_ADJUST_MOBILE' ) ? WPMUDEV_CHAT_SITE_BOX_POSITION_ADJUST_MOBILE : 'enabled',
955 'box_width_mobile_adjust' => defined( 'WPMUDEV_CHAT_SITE_BOX_WIDTH_MOBILE_ADJUST' ) ? WPMUDEV_CHAT_SITE_BOX_WIDTH_MOBILE_ADJUST : 'window',
956 'box_height_mobile_adjust' => defined( 'WPMUDEV_CHAT_SITE_BOX_HEIGHT_MOBILE_ADJUST' ) ? WPMUDEV_CHAT_SITE_BOX_HEIGHT_MOBILE_ADJUST : 'window',
957 'box_offset_h' => defined( 'WPMUDEV_CHAT_SITE_BOX_OFFSET_H' ) ? WPMUDEV_CHAT_SITE_BOX_OFFSET_H : '0px',
958 'box_offset_v' => defined( 'WPMUDEV_CHAT_SITE_BOX_OFFSET_V' ) ? WPMUDEV_CHAT_SITE_BOX_OFFSET_V : '0px',
959 'box_spacing_h' => defined( 'WPMUDEV_CHAT_SITE_BOX_SPACING_H' ) ? WPMUDEV_CHAT_SITE_BOX_SPACING_H : '10px',
960 'box_shadow_show' => defined( 'WPMUDEV_CHAT_SITE_BOX_SHADOW_SHOW' ) ? WPMUDEV_CHAT_SITE_BOX_SHADOW_SHOW : 'enabled',
961 'box_shadow_v' => defined( 'WPMUDEV_CHAT_SITE_BOX_SHADOW_V' ) ? WPMUDEV_CHAT_SITE_BOX_SHADOW_V : '10px',
962 'box_shadow_h' => defined( 'WPMUDEV_CHAT_SITE_BOX_SHADOW_H' ) ? WPMUDEV_CHAT_SITE_BOX_SHADOW_H : '10px',
963 'box_shadow_blur' => defined( 'WPMUDEV_CHAT_SITE_BOX_SHADOW_BLUR' ) ? WPMUDEV_CHAT_SITE_BOX_SHADOW_BLUR : '5px',
964 'box_shadow_spread' => defined( 'WPMUDEV_CHAT_SITE_BOX_SHADOW_SPREAD' ) ? WPMUDEV_CHAT_SITE_BOX_SHADOW_SPREAD : '0px',
965 'box_shadow_color' => defined( 'WPMUDEV_CHAT_SITE_BOX_SHADOW_COLOR' ) ? WPMUDEV_CHAT_SITE_BOX_SHADOW_COLOR : '#888888',
966 'box_resizable' => 'disabled',
967 'users_list_show' => defined( 'WPMUDEV_CHAT_SITE_USERS_LIST_SHOW' ) ? WPMUDEV_CHAT_SITE_USERS_LIST_SHOW : 'avatar',
968 'users_list_position' => defined( 'WPMUDEV_CHAT_SITE_USERS_LIST_POSITION' ) ? WPMUDEV_CHAT_SITE_USERS_LIST_POSITION : 'none',
969 'users_list_style' => defined( 'WPMUDEV_CHAT_SITE_USERS_LIST_STYLE' ) ? WPMUDEV_CHAT_SITE_USERS_LIST_STYLE : 'split',
970 'log_creation' => defined( 'WPMUDEV_CHAT_SITE_LOG_CREATION' ) ? WPMUDEV_CHAT_SITE_LOG_CREATION : 'disabled',
971 'log_display' => defined( 'WPMUDEV_CHAT_SITE_LOG_DISPLAY' ) ? WPMUDEV_CHAT_SITE_LOG_DISPLAY : 'disabled',
972 'invite-info' => array(),
973 'blocked_on_shortcode' => defined( 'WPMUDEV_CHAT_SITE_BLOCKED_ON_SHORTCODE' ) ? WPMUDEV_CHAT_SITE_BLOCKED_ON_SHORTCODE : 'disabled',
974 'private_reopen_after_exit' => 'enabled'
975
976 ), $this->_chat_options_defaults['page']
977 );
978
979 // Special section for Widgets. Based on the Page settings
980 $this->_chat_options_defaults['widget'] = wp_parse_args( array(
981 'session_type' => 'widget',
982 'box_width' => defined( 'WPMUDEV_CHAT_WIDGET_BOX_WIDTH' ) ? WPMUDEV_CHAT_WIDGET_BOX_WIDTH : '100%',
983 'box_height' => defined( 'WPMUDEV_CHAT_WIDGET_BOX_HEIGHT' ) ? WPMUDEV_CHAT_WIDGET_BOX_HEIGHT : '300px',
984 'box_width_mobile_adjust' => defined( 'WPMUDEV_CHAT_WIDGET_BOX_WIDTH_MOBILE_ADJUST' ) ? WPMUDEV_CHAT_WIDGET_BOX_WIDTH_MOBILE_ADJUST : 'window',
985 'box_height_mobile_adjust' => defined( 'WPMUDEV_CHAT_WIDGET_BOX_HEIGHT_MOBILE_ADJUST' ) ? WPMUDEV_CHAT_WIDGET_BOX_HEIGHT_MOBILE_ADJUST : 'window',
986 'box_new_message_color' => defined( 'WPMUDEV_CHAT_WIDGET_BOX_NEW_MESSAGE_COLOR' ) ? WPMUDEV_CHAT_WIDGET_BOX_NEW_MESSAGE_COLOR : '#ff8400',
987 'users_list_show' => defined( 'WPMUDEV_CHAT_WIDGET_USERS_LIST_SHOW' ) ? WPMUDEV_CHAT_WIDGET_USERS_LIST_SHOW : 'avatar',
988 'users_list_position' => defined( 'WPMUDEV_CHAT_WIDGET_USERS_LIST_POSITION' ) ? WPMUDEV_CHAT_WIDGET_USERS_LIST_POSITION : 'none',
989 'users_list_style' => defined( 'WPMUDEV_CHAT_WIDGET_USERS_LIST_STYLE' ) ? WPMUDEV_CHAT_WIDGET_USERS_LIST_STYLE : 'split',
990 'box_border_color' => defined( 'WPMUDEV_CHAT_WIDGET_BOX_BORDER_COLOR' ) ? WPMUDEV_CHAT_WIDGET_BOX_BORDER_COLOR : '#4b96e2',
991 //'box_padding' => '2px',
992 'box_border_width' => defined( 'WPMUDEV_CHAT_WIDGET_BOX_BORDER_WIDTH' ) ? WPMUDEV_CHAT_WIDGET_BOX_BORDER_WIDTH : '2px',
993 'row_avatar_width' => defined( 'WPMUDEV_CHAT_WIDGET_ROW_AVATAR_WIDTH' ) ? WPMUDEV_CHAT_WIDGET_ROW_AVATAR_WIDTH : '30px',
994 'row_message_input_height' => defined( 'WPMUDEV_CHAT_WIDGET_ROW_MESSAGE_INPUT_HEIGHT' ) ? WPMUDEV_CHAT_WIDGET_ROW_MESSAGE_INPUT_HEIGHT : '35px',
995 'log_creation' => defined( 'WPMUDEV_CHAT_WIDGET_LOG_CREATION' ) ? WPMUDEV_CHAT_WIDGET_LOG_CREATION : 'disabled',
996 'log_display' => defined( 'WPMUDEV_CHAT_WIDGET_LOG_DISPLAY' ) ? WPMUDEV_CHAT_WIDGET_LOG_DISPLAY : 'disabled',
997 'blocked_urls_action' => defined( 'WPMUDEV_CHAT_WIDGET_BLOCKED_URLS_ACTION' ) ? WPMUDEV_CHAT_WIDGET_BLOCKED_URLS_ACTION : 'exclude',
998 'blocked_urls' => array(),
999 'blocked_on_shortcode' => defined( 'WPMUDEV_CHAT_WIDGET_BLOCKED_ON_SHORTCODE' ) ? WPMUDEV_CHAT_WIDGET_BLOCKED_ON_SHORTCODE : 'disabled',
1000
1001 ), $this->_chat_options_defaults['page']
1002 );
1003
1004 $this->_chat_options_defaults['dashboard'] = wp_parse_args( array(
1005 'session_type' => 'dashboard',
1006 'dashboard_widget' => defined( 'WPMUDEV_CHAT_DASHBOARD_DASHBOARD_WIDGET' ) ? WPMUDEV_CHAT_DASHBOARD_DASHBOARD_WIDGET : 'disabled',
1007 'dashboard_widget_title' => __( 'Chat', $this->translation_domain ),
1008 'dashboard_widget_height' => defined( 'WPMUDEV_CHAT_DASHBOARD_DASHBOARD_WIDGET_HEIGHT' ) ? WPMUDEV_CHAT_DASHBOARD_DASHBOARD_WIDGET_HEIGHT : '200px',
1009 'dashboard_status_widget' => defined( 'WPMUDEV_CHAT_DASHBOARD_DASHBOARD_STATUS_WIDGET' ) ? WPMUDEV_CHAT_DASHBOARD_DASHBOARD_STATUS_WIDGET : 'disabled',
1010 'dashboard_status_widget_title' => __( 'Chat Status', $this->translation_domain ),
1011 'dashboard_friends_widget' => defined( 'WPMUDEV_CHAT_DASHBOARD_DASHBOARD_FRIENDS_WIDGET' ) ? WPMUDEV_CHAT_DASHBOARD_DASHBOARD_FRIENDS_WIDGET : 'disabled',
1012 'dashboard_friends_widget_height' => defined( 'WPMUDEV_CHAT_DASHBOARD_DASHBOARD_FRIENDS_WIDGET_HEIGHT' ) ? WPMUDEV_CHAT_DASHBOARD_DASHBOARD_FRIENDS_WIDGET_HEIGHT : '200px',
1013 'dashboard_friends_widget_title' => __( 'Chat Friends', $this->translation_domain ),
1014 'box_border_color' => defined( 'WPMUDEV_CHAT_DASHBOARD_BOX_BORDER_COLOR' ) ? WPMUDEV_CHAT_DASHBOARD_BOX_BORDER_COLOR : '#F1F1F1',
1015 ), $this->_chat_options_defaults['widget']
1016 );
1017
1018 $this->_chat_options_defaults['bp-group'] = wp_parse_args( array(
1019 'session_type' => 'bp-group',
1020 'box_width' => defined( 'WPMUDEV_CHAT_BP_BOX_WIDTH' ) ? WPMUDEV_CHAT_BP_BOX_WIDTH : '100%',
1021 'box_height' => defined( 'WPMUDEV_CHAT_BP_BOX_HEIGHT' ) ? WPMUDEV_CHAT_BP_BOX_HEIGHT : ' 400px',
1022 'box_popout' => defined( 'WPMUDEV_CHAT_BP_BOX_POPOUT' ) ? WPMUDEV_CHAT_BP_BOX_POPOUT : 'disabled',
1023 'bottom_corner' => defined( 'WPMUDEV_CHAT_BP_BOTTOM_CORNER' ) ? WPMUDEV_CHAT_BP_BOTTOM_CORNER : 'disabled',
1024 'users_list_show' => defined( 'WPMUDEV_CHAT_BP_USERS_LIST_SHOW' ) ? WPMUDEV_CHAT_BP_USERS_LIST_SHOW : 'avatar',
1025 'users_list_position' => defined( 'WPMUDEV_CHAT_BP_USERS_LIST_POSITION' ) ? WPMUDEV_CHAT_BP_USERS_LIST_POSITION : 'right',
1026 'users_list_style' => defined( 'WPMUDEV_CHAT_BP_USERS_LIST_STYLE' ) ? WPMUDEV_CHAT_BP_USERS_LIST_STYLE : 'split',
1027 'users_list_width' => defined( 'WPMUDEV_CHAT_BP_USERS_LIST_WIDTH' ) ? WPMUDEV_CHAT_BP_USERS_LIST_WIDTH : '30%',
1028 'users_list_avatar_width' => defined( 'WPMUDEV_CHAT_BP_USERS_LIST_AVATAR_WIDTH' ) ? WPMUDEV_CHAT_BP_USERS_LIST_AVATAR_WIDTH : '50px',
1029 'row_message_input_height' => defined( 'WPMUDEV_CHAT_BP_ROW_MESSAGE_INPUT_HEIGHT' ) ? WPMUDEV_CHAT_BP_ROW_MESSAGE_INPUT_HEIGHT : '45px',
1030 'box_border_color' => defined( 'WPMUDEV_CHAT_BP_BOX_BORDER_COLOR' ) ? WPMUDEV_CHAT_BP_BOX_BORDER_COLOR : '#4b96e2',
1031 'box_border_width' => defined( 'WPMUDEV_CHAT_BP_BOX_BORDER_WIDTH' ) ? WPMUDEV_CHAT_BP_BOX_BORDER_WIDTH : '1px',
1032 'row_avatar_width' => defined( 'WPMUDEV_CHAT_BP_ROW_AVATAR_WIDTH' ) ? WPMUDEV_CHAT_BP_ROW_AVATAR_WIDTH : '30px',
1033 'row_message_input_height' => defined( 'WPMUDEV_CHAT_BP_ROW_MESSAGE_INPUT_HEIGHT' ) ? WPMUDEV_CHAT_BP_ROW_MESSAGE_INPUT_HEIGHT : '35px',
1034 'log_creation' => defined( 'WPMUDEV_CHAT_BP_LOG_CREATION' ) ? WPMUDEV_CHAT_BP_LOG_CREATION : 'disabled',
1035 'log_display' => defined( 'WPMUDEV_CHAT_BP_LOG_DISPLAY' ) ? WPMUDEV_CHAT_BP_LOG_DISPLAY : 'disabled',
1036 'blocked_urls_action' => defined( 'WPMUDEV_CHAT_BP_BLOCKED_URLS_ACTION' ) ? WPMUDEV_CHAT_BP_BLOCKED_URLS_ACTION : 'exclude',
1037 'blocked_urls' => array(),
1038 ), $this->_chat_options_defaults['page']
1039 );
1040
1041 $this->_chat_options_defaults['user-statuses'] = array(
1042 'available' => __( 'Available', $this->translation_domain ),
1043 'unavailable' => __( 'Unavailable', $this->translation_domain ),
1044 'away' => __( 'Away', $this->translation_domain )
1045 );
1046 $this->_chat_options_defaults['user-statuses'] = apply_filters( 'wpmudev-chat-user-statuses', $this->_chat_options_defaults['user-statuses'] );
1047
1048 $this->_chat_options_defaults['global'] = array(
1049 'session_poll_interval_messages' => defined( 'WPMUDEV_CHAT_GLOBAL_SESSION_POLL_INTERVAL_MESSAGES' ) ? WPMUDEV_CHAT_GLOBAL_SESSION_POLL_INTERVAL_MESSAGES : '3',
1050 'session_poll_interval_invites' => defined( 'WPMUDEV_CHAT_GLOBAL_SESSION_POLL_INTERVAL_INVITES' ) ? WPMUDEV_CHAT_GLOBAL_SESSION_POLL_INTERVAL_INVITES : '3',
1051 'session_poll_interval_meta' => defined( 'WPMUDEV_CHAT_GLOBAL_SESSION_POLL_INTERVAL_META' ) ? WPMUDEV_CHAT_GLOBAL_SESSION_POLL_INTERVAL_META : '5',
1052 'session_poll_type' => defined( 'WPMUDEV_CHAT_GLOBAL_SESSION_POLL_TYPE' ) ? WPMUDEV_CHAT_GLOBAL_SESSION_POLL_TYPE : 'plugin',
1053 'session_performance' => 'disabled',
1054 'twitter_api_key' => '',
1055 'twitter_api_secret' => '',
1056 'google_plus_application_id' => '',
1057 'facebook_application_id' => '',
1058 'facebook_application_secret' => '',
1059 'facebook_active_in_site' => '',
1060 'blocked_ip_addresses_active' => defined( 'WPMUDEV_CHAT_GLOBAL_BLOCKED_IP_ADDRESSES_ACTIVE' ) ? WPMUDEV_CHAT_GLOBAL_BLOCKED_IP_ADDRESSES_ACTIVE : 'disabled',
1061 'blocked_ip_addresses' => array( '0.0.0.0' ),
1062 'blocked_admin_urls_action' => 'exclude',
1063 'blocked_admin_urls' => array(),
1064 'load_jscss_all' => 'enabled',
1065 'blocked_front_urls_action' => 'exclude',
1066 'blocked_front_urls' => array(),
1067 'blocked_users' => array(),
1068 'blocked_words_active' => 'disabled',
1069 'blocked_ip_message' => __( 'Your account has been banned from participating in this chat session. Please contact site administrator for more information concerning this ban.', $this->translation_domain ),
1070 'bp_menu_label' => __( 'Group Chat', $this->translation_domain ),
1071 'bp_menu_slug' => 'wpmudev-chat-bp-group',
1072 'bp_group_show_site' => defined( 'WPMUDEV_CHAT_GLOBAL_BP_GROUP_SHOW_SITE' ) ? WPMUDEV_CHAT_GLOBAL_BP_GROUP_SHOW_SITE : 'enabled',
1073 'bp_group_admin_show_site' => defined( 'WPMUDEV_CHAT_GLOBAL_BP_GROUP_ADMIN_SHOW_SITE' ) ? WPMUDEV_CHAT_GLOBAL_BP_GROUP_ADMIN_SHOW_SITE : 'enabled',
1074 'bp_group_show_widget' => defined( 'WPMUDEV_CHAT_GLOBAL_BP_GROUP_SHOW_WIDGET' ) ? WPMUDEV_CHAT_GLOBAL_BP_GROUP_SHOW_WIDGET : 'enabled',
1075 'bp_group_admin_show_widget' => defined( 'WPMUDEV_CHAT_GLOBAL_BP_GROUP_ADMIN_SHOW_WIDGET' ) ? WPMUDEV_CHAT_GLOBAL_BP_GROUP_ADMIN_SHOW_WIDGET : 'enabled',
1076 'bp_form_background_color' => defined( 'WPMUDEV_CHAT_GLOBAL_BP_FORM_BACKGROUND_COLOR' ) ? WPMUDEV_CHAT_GLOBAL_BP_FORM_BACKGROUND_COLOR : '#FDFDFD',
1077 'bp_form_label_color' => defined( 'WPMUDEV_CHAT_GLOBAL_BP_FORM_LABEL_COLOR' ) ? WPMUDEV_CHAT_GLOBAL_BP_FORM_LABEL_COLOR : '#333333',
1078 'delete_user_messages' => 'disabled'
1079
1080 );
1081
1082 $blocked_words = array();
1083 if ( is_file( dirname( __FILE__ ) . '/lib/bad_words_list.php' ) ) {
1084 $blocked_words = file( dirname( __FILE__ ) . '/lib/bad_words_list.php' );
1085 if ( ( is_array( $blocked_words ) ) && ( count( $blocked_words ) ) ) {
1086 foreach ( $blocked_words as $_idx => $_val ) {
1087 $blocked_words[ $_idx ] = trim( $_val );
1088 }
1089 }
1090 }
1091
1092 $this->_chat_options_defaults['banned']['blocked_words_active'] = 'disabled';
1093 $this->_chat_options_defaults['banned']['blocked_words'] = $blocked_words;
1094 $this->_chat_options_defaults['banned']['blocked_words_replace'] = "";
1095
1096 // User meta defaults for profile and other user specific settings. Saved to the user meta table (not wp_options)
1097 if ( is_user_logged_in() ) {
1098 $user_meta_option = get_option( 'wpmudev-chat-user-meta', array() );
1099 $this->_chat_options_defaults['user_meta'] = wp_parse_args( get_option( 'wpmudev-chat-user-meta', array() ),
1100 array(
1101 'chat_user_status' => 'available',
1102 'chat_name_display' => 'display_name',
1103 'chat_wp_admin' => 'enabled',
1104 'chat_wp_toolbar' => 'enabled',
1105 'chat_wp_toolbar_show_status' => 'enabled',
1106 'chat_wp_toolbar_show_friends' => 'enabled',
1107 'chat_users_listing' => 'disabled',
1108 'chat_dashboard_widget' => 'disabled',
1109 'chat_dashboard_widget_height' => '',
1110 'chat_dashboard_status_widget' => 'disabled',
1111 'chat_dashboard_friends_widget' => 'disabled',
1112 'chat_dashboard_friends_widget_height' => '',
1113 'chat_network_dashboard_widget' => 'disabled',
1114 'chat_network_dashboard_status_widget' => 'disabled',
1115 'chat_network_dashboard_friends_widget' => 'disabled'
1116 )
1117 );
1118 if ( has_filter( 'wpmudev-chat-options-defaults' ) ) {
1119 $this->_chat_options_defaults['user_meta'] = apply_filters( 'wpmudev-chat-options-defaults', 'user_meta', $this->_chat_options_defaults['user_meta'] );
1120 }
1121 }
1122
1123 if ( is_multisite() ) {
1124
1125 $this->_chat_options_defaults['network-site'] = wp_parse_args( $this->_chat_options_defaults['site'], array(
1126 'bottom_corner' => 'disabled'
1127 )
1128 );
1129 $this->_chat_options_defaults['network-site']['session_type'] = 'network-site';
1130 }
1131 }
1132
1133
1134 /* now that plugins are loaded we check if we are activated from the Network */
1135 function plugins_loaded() {
1136 if ( ! is_multisite() ) {
1137 return;
1138 }
1139
1140 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
1141 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
1142 }
1143 // Makes sure the plugin is defined before trying to use it
1144
1145 if ( is_plugin_active_for_network( 'wordpress-chat/wordpress-chat.php' ) ) {
1146 // Plugin is activated via Network
1147 $this->_chat_plugin_settings['network_active'] = true;
1148 }
1149 }
1150
1151 /**
1152 * Initialize the plugin
1153 *
1154 * @see http://codex.wordpress.org/Plugin_API/Action_Reference
1155 * @see http://adambrown.info/p/wp_hooks/hook/init
1156 */
1157 function init() {
1158
1159 if ( preg_match( '/mu\-plugin/', PLUGINDIR ) > 0 ) {
1160 load_muplugin_textdomain( $this->translation_domain, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
1161 } else {
1162 load_plugin_textdomain( $this->translation_domain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
1163 }
1164
1165 $this->chat_performance = wpmudev_chat_start_performance( $this->chat_performance );
1166
1167 $this->load_configs();
1168
1169 if ( ( ! defined( 'WPMUDEV_CHAT_SHORTINIT' ) ) || ( WPMUDEV_CHAT_SHORTINIT != true ) ) {
1170 $this->check_upgrade();
1171 }
1172
1173 $this->chat_localized['settings'] = array();
1174 $this->chat_localized['settings']['ajax_url'] = admin_url( 'admin-ajax.php', 'relative' );
1175 $this->chat_localized['settings']['plugin_url'] = plugins_url( "/", __FILE__ );
1176 $this->chat_localized['settings']['google_plus_text_sign_out'] = __( 'Sign out of Google+', $this->translation_domain );
1177 $this->chat_localized['settings']['facebook_text_sign_out'] = __( 'Sign out of Facebook', $this->translation_domain );
1178 $this->chat_localized['settings']['twitter_text_sign_out'] = __( 'Sign out of Twitter', $this->translation_domain );
1179
1180 $this->chat_localized['settings']['please_wait'] = __( 'Please wait...', $this->translation_domain );
1181 $this->chat_localized['settings']['row_delete_text'] = __( 'hide', $this->translation_domain );
1182 $this->chat_localized['settings']['row_undelete_text'] = __( 'unhide', $this->translation_domain );
1183
1184 $this->chat_localized['settings']['user_entered_chat'] = __( 'Entered Chat', $this->translation_domain );
1185 $this->chat_localized['settings']['user_exited_chat'] = __( 'Exited Chat', $this->translation_domain );
1186 $this->chat_localized['settings']['user_pending_chat'] = __( 'Pending', $this->translation_domain );
1187 $this->chat_localized['settings']['user_declined_chat'] = __( 'Declined', $this->translation_domain );
1188
1189 $this->chat_localized['settings']['wp_is_mobile'] = wp_is_mobile();
1190
1191
1192 $this->chat_localized['settings']["twitter_active"] = false;
1193 if ( $this->get_option( 'twitter_api_key', 'global' ) != '' ) {
1194 $this->chat_localized['settings']["twitter_active"] = true;
1195 }
1196
1197 $this->chat_localized['settings']["facebook_active"] = false;
1198 if ( $this->get_option( 'facebook_application_id', 'global' ) != '' ) {
1199 $this->chat_localized['settings']["facebook_app_id"] = $this->get_option( 'facebook_application_id', 'global' );
1200 if ( $this->get_option( 'facebook_active_in_site', 'global' ) == "yes" ) {
1201 $this->chat_localized['settings']["facebook_active"] = true;
1202 }
1203 }
1204
1205 $this->chat_localized['settings']["google_plus_active"] = false;
1206 if ( $this->get_option( 'google_plus_application_id', 'global' ) != '' ) {
1207 $this->chat_localized['settings']["google_plus_active"] = true;
1208 $this->chat_localized['settings']["google_plus_application_id"] = $this->get_option( 'google_plus_application_id', 'global' );
1209 }
1210
1211 $this->chat_localized['settings']["session_poll_interval_messages"] = $this->get_option( 'session_poll_interval_messages', 'global' );
1212 if ( $this->chat_localized['settings']["session_poll_interval_messages"] < 0 ) {
1213 $this->chat_localized['settings']["session_poll_interval_messages"] = 1;
1214 }
1215
1216 $this->chat_localized['settings']["session_poll_interval_invites"] = $this->get_option( 'session_poll_interval_invites', 'global' );
1217 if ( $this->chat_localized['settings']["session_poll_interval_invites"] < 0 ) {
1218 $this->chat_localized['settings']["session_poll_interval_invites"] = 3;
1219 }
1220
1221 $this->chat_localized['settings']["session_poll_interval_meta"] = $this->get_option( 'session_poll_interval_meta', 'global' );
1222 if ( $this->chat_localized['settings']["session_poll_interval_meta"] < 0 ) {
1223 $this->chat_localized['settings']["session_poll_interval_meta"] = 5;
1224 }
1225
1226 $this->chat_localized['settings']["session_poll_interval_users"] = 5;
1227 }
1228
1229 /**
1230 * Load things into the HTML <head></head>
1231 *
1232 * @see http://codex.wordpress.org/Plugin_API/Action_Reference
1233 * @see http://adambrown.info/p/wp_hooks/hook/wp_head
1234 * Here we are loafing both the front-end and admin header hooks. This cuts down on duplicate coding.
1235 */
1236 function wp_head() {
1237
1238 $_SHOW_SITE_CHAT = true;
1239
1240 if ( is_admin() ) {
1241 if ( $this->_chat_plugin_settings['blocked_urls']['admin'] == true ) {
1242 $_SHOW_SITE_CHAT = false;
1243 }
1244 } else {
1245 if ( $this->_chat_plugin_settings['blocked_urls']['front'] == true ) {
1246 $_SHOW_SITE_CHAT = false;
1247 }
1248 }
1249
1250 if ( ! empty( $this->_registered_styles ) ) {
1251 wp_print_styles( array_values( $this->_registered_styles ) );
1252 }
1253 if ( $_SHOW_SITE_CHAT == true ) {
1254
1255 if ( is_multisite() ) {
1256 $this->site_content .= $this->chat_network_site_box_container();
1257
1258 $site_box_height = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_height', 'network-site' ), array( 'px' ) );
1259 $site_box_position_v = $this->get_option( 'box_position_v', 'network-site' );
1260 $site_box_position_h = $this->get_option( 'box_position_h', 'network-site' );
1261 $site_box_offset_v = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_offset_v', 'network-site' ), array( 'px' ) );
1262 $site_box_offset_h = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_offset_h', 'network-site' ), array( 'px' ) );
1263 $site_box_spacing_h = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_spacing_h', 'network-site' ), array( 'px' ) );
1264
1265 $site_box_shadow = $this->get_option( 'box_shadow_show', 'network-site' );
1266 $site_box_shadow_v = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_v', 'network-site' ), array( 'px' ) );
1267 $site_box_shadow_h = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_h', 'network-site' ), array( 'px' ) );
1268 $site_box_shadow_blur = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_blur', 'network-site' ), array( 'px' ) );
1269 $site_box_shadow_spread = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_spread', 'network-site' ), array( 'px' ) );
1270 $site_box_shadow_color = $this->get_option( 'box_shadow_color', 'network-site' );
1271 }
1272
1273 if ( empty( $this->site_content ) ) {
1274 $this->site_content .= $this->chat_site_box_container();
1275
1276 $site_box_height = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_height', 'site' ), array( 'px' ) );
1277 $site_box_position_v = $this->get_option( 'box_position_v', 'site' );
1278 $site_box_position_h = $this->get_option( 'box_position_h', 'site' );
1279 $site_box_offset_v = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_offset_v', 'site' ), array( 'px' ) );
1280 $site_box_offset_h = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_offset_h', 'site' ), array( 'px' ) );
1281 $site_box_spacing_h = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_spacing_h', 'site' ), array( 'px' ) );
1282
1283 $site_box_shadow = $this->get_option( 'box_shadow_show', 'site' );
1284 $site_box_shadow_v = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_v', 'site' ), array( 'px' ) );
1285 $site_box_shadow_h = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_h', 'site' ), array( 'px' ) );
1286 $site_box_shadow_blur = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_blur', 'site' ), array( 'px' ) );
1287 $site_box_shadow_spread = wpmudev_chat_check_size_qualifier( $this->get_option( 'box_shadow_spread', 'site' ), array( 'px' ) );
1288 $site_box_shadow_color = $this->get_option( 'box_shadow_color', 'site' );
1289
1290 }
1291
1292 if ( $site_box_position_h == "left" ) {
1293 $site_box_spacing = "0 " . $site_box_spacing_h . ' 0 0';
1294 } else {
1295 $site_box_spacing = "0 0 0 " . $site_box_spacing_h . '';
1296 }
1297
1298 $site_box_float = $site_box_position_h;
1299 $site_box_position_h = $site_box_position_h . ': ' . $site_box_offset_h . ';';
1300
1301 $height_offset = 0;
1302 if ( $site_box_position_v == "bottom" ) {
1303 $border_width = intval( $this->get_option( 'box_border_width', 'site' ) );
1304 if ( $border_width > 0 ) {
1305 $height_offset = wpmudev_chat_check_size_qualifier( $border_width * 2, array( 'px' ) );
1306 }
1307 }
1308
1309 $site_box_position_v = $site_box_position_v . ': ' . $site_box_offset_v . ';';
1310
1311 echo '<style type="text/css" id="wpmudev-chat-box-site-css">';
1312 echo 'div.wpmudev-chat-box.wpmudev-chat-box-site { margin: 0; padding: 0; position: fixed; ' . $site_box_position_h . ' ' . $site_box_position_v . ' z-index: 10000; margin: ' . $site_box_spacing . '; padding: 0; ';
1313
1314 if ( $site_box_shadow == "enabled" ) {
1315 echo 'box-shadow: ' .
1316 $site_box_shadow_v . ' ' .
1317 $site_box_shadow_h . ' ' .
1318 $site_box_shadow_blur . ' ' .
1319 $site_box_shadow_spread . ' ' .
1320 $site_box_shadow_color . ' ';
1321 }
1322 echo ' } ';
1323 echo '</style>';
1324 }
1325
1326 // Are we viewing the chat logs?
1327 if ( isset( $_GET['chat-show-logs'] ) || ( isset( $_GET['chat-log-id'] ) && intval( $_GET['chat-log-id'] ) ) ) {
1328 $content_styles = $this->chat_session_box_styles( $this->_chat_options_defaults['page'], 'archive' );
1329 if ( ! empty( $content_styles ) ) {
1330 echo $content_styles;
1331 }
1332 }
1333 }
1334
1335 /**
1336 * Admin init logic. Things here will only run when viewing the admin area
1337 *
1338 * @global none
1339 *
1340 * @param none
1341 *
1342 * @return none
1343 */
1344 function admin_init() {
1345 $post_id = $post = $post_type = $post_type_object = null;
1346 $_show_tinymce_button = false;
1347
1348 $url_path = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );
1349 if ( ! $url_path ) {
1350 return $_show_tinymce_button;
1351 }
1352
1353 // If we are not on a post_type editor or add new form. Return
1354 if ( ! in_array( $url_path, array( 'post-new.php', 'post.php' ) ) ) {
1355 return $_show_tinymce_button;
1356 }
1357
1358 if ( isset( $_GET['post_type'] ) ) {
1359 $post_type = $_GET['post_type'];
1360 } else {
1361 if ( isset( $_GET['post'] ) ) {
1362 $post_id = (int) $_GET['post'];
1363 } elseif ( isset( $_POST['post_ID'] ) ) {
1364 $post_id = (int) $_POST['post_ID'];
1365 }
1366 if ( $post_id ) {
1367 $post = get_post( $post_id );
1368 if ( $post ) {
1369 $post_type = $post->post_type;
1370 }
1371 }
1372 }
1373 if ( ! $post_type ) {
1374 $post_type = "post";
1375 }
1376
1377 if ( ! get_current_user_id() ) {
1378 return $_show_tinymce_button;
1379 }
1380
1381 $current_user = wp_get_current_user();
1382
1383 $tinymce_roles = $this->get_option( 'tinymce_roles', 'page' );
1384 if ( ! $tinymce_roles ) {
1385 $tinymce_roles = array();
1386 }
1387
1388 $tinymce_post_types = $this->get_option( 'tinymce_post_types', 'page' );
1389 if ( ! $tinymce_post_types ) {
1390 $tinymce_post_types = array();
1391 }
1392
1393 // If the viewed post type is not in our allowed list return.
1394 if ( ! in_array( $post_type, $tinymce_post_types ) ) {
1395 return $_show_tinymce_button;
1396 }
1397
1398 // The user's role is in the allowed roles set for Chat > Settings Page
1399 if ( array_intersect( $current_user->roles, $tinymce_roles ) ) {
1400 $_show_tinymce_button = true;
1401 } else {
1402
1403 // If the allowed chat roles does not contain the admin then return;
1404 if ( array_search( 'administrator', $tinymce_roles ) === false ) {
1405 return;
1406 }
1407
1408 // However, if the 'administrator' role is in our allowed list and the user is super_admin then we are good.
1409 if ( is_super_admin() ) {
1410 $_show_tinymce_button = true;
1411 }
1412 }
1413
1414 if ( $_show_tinymce_button === true ) {
1415 add_filter( "mce_external_plugins", array( &$this, "tinymce_add_plugin" ) );
1416 add_filter( 'mce_buttons', array( &$this, 'tinymce_register_button' ) );
1417 //add_filter('mce_external_languages', array(&$this,'tinymce_load_langs'));
1418
1419 }
1420
1421 return $_show_tinymce_button;
1422 }
1423
1424 function admin_enqueue_scripts() {
1425
1426 global $wp_version;
1427
1428 // For some dumb reason WordPress does not include any default jQuery UI styles even for wp-admin
1429 $css_url = 'http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css';
1430 if ( is_ssl() ) {
1431 $css_url = str_replace( 'http://', 'https://', $css_url );
1432 }
1433
1434 //Register All the styles
1435 wp_register_style( 'wpmudev-chat-style', plugins_url( '/css/wpmudev-chat-style.css', __FILE__ ), array(), $this->chat_current_version );
1436 wp_register_style( 'wpmudev-chat-jquery-ui-datepicker-css', $css_url, false, '1.0.0' );
1437
1438 //Admin Styles
1439 wp_register_style( 'wpmudev-chat-wpadminbar-style', plugins_url( '/css/wpmudev-chat-wpadminbar.css', __FILE__ ), array(), $this->chat_current_version );
1440 wp_register_style( 'wpmudev-chat-admin-css', plugins_url( '/css/wpmudev-chat-admin.css', __FILE__ ), array(), $this->chat_current_version );
1441
1442 if ( ! version_compare( $wp_version, '3.7.1', '>' ) ) {
1443 wp_register_style( 'wpmudev-chat-wpadminbar-style-pre-38', plugins_url( '/css/wpmudev-chat-wpadminbar-pre-38.css', __FILE__ ), array(), $this->chat_current_version );
1444 }
1445
1446 if ( ( isset( $_GET['page'] ) ) && ( $_GET['page'] == 'chat_session_logs' ) ) {
1447 wp_enqueue_style( 'wpmudev-chat-jquery-ui-datepicker-css' );
1448 wp_enqueue_script( 'jquery-ui-datepicker' );
1449 }
1450
1451 //Register all the Scripts
1452 wp_register_script( 'wpmudev-chat-admin-js', plugins_url( '/js/wpmudev-chat-admin.js', __FILE__ ), array(
1453 'jquery',
1454 'jquery-ui-core',
1455 'jquery-ui-tabs'
1456 ), $this->chat_current_version );
1457 wp_register_script( 'jquery-cookie', plugins_url( '/js/jquery-cookie.js', __FILE__ ), array( 'jquery' ), $this->chat_current_version, true );
1458 wp_register_script( 'wpmudev-chat-admin-farbtastic-js', plugins_url( '/js/wpmudev-chat-admin-farbtastic.js', __FILE__ ), array(), $this->chat_current_version, true );
1459 wp_register_script( 'wpmudev-chat-admin-js', plugins_url( '/js/wpmudev-chat-admin.js', __FILE__ ), array(
1460 'jquery',
1461 'jquery-ui-core',
1462 'jquery-ui-tabs'
1463 ), $this->chat_current_version );
1464 wp_register_script( 'wpmudev-chat-js', plugins_url( '/js/wpmudev-chat.js', __FILE__ ), array( 'jquery' ), $this->chat_current_version, true );
1465
1466 $screen = get_current_screen();
1467
1468 //Profile Page
1469 if ( $screen->id == "profile" ) {
1470
1471 //Enqueue Chat admin js
1472 wp_enqueue_script( 'wpmudev-chat-admin-js' );
1473 $this->_registered_styles['wpmudev-chat-admin-js'] = 'wpmudev-chat-admin-js';
1474
1475 }
1476
1477 //Dashboard
1478 if ( $screen->id == "dashboard" ) {
1479
1480 $this->_registered_styles['wpmudev-chat-wpadminbar-style'] = 'wpmudev-chat-wpadminbar-style';
1481
1482 // For older versions of WP (less than 3.8) we add some supplement styles
1483 if ( ! version_compare( $wp_version, '3.7.1', '>' ) ) {
1484 $this->_registered_styles['wpmudev-chat-wpadminbar-style-pre-38'] = 'wpmudev-chat-wpadminbar-style-pre-38';
1485 }
1486 }
1487
1488 // if we are showing one of our own settings panels then we don't need to be here since the
1489 if ( $this->_show_own_admin === true ) {
1490
1491 wp_enqueue_style( 'farbtastic' );
1492 $this->_registered_styles['farbtastic'] = 'farbtastic';
1493
1494 wp_enqueue_script( 'farbtastic' );
1495 $this->_registered_scripts['farbtastic'] = 'farbtastic';
1496
1497 /* enqueue our plugin styles */
1498 $this->_registered_styles['wpmudev-chat-admin-css'] = 'wpmudev-chat-admin-css';
1499
1500 wp_enqueue_script( 'json2' );
1501 $this->_registered_scripts['json2'] = 'json2';
1502
1503 //Include Jquery Cookie
1504 wp_enqueue_script( 'jquery-cookie' );
1505 $this->_registered_scripts['jquery-cookie'] = 'jquery-cookie';
1506
1507 //Include Farbtastic Script
1508 wp_enqueue_script( 'wpmudev-chat-admin-farbtastic-js' );
1509 $this->_registered_scripts['wpmudev-chat-admin-farbtastic-js'] = 'wpmudev-chat-admin-farbtastic-js';
1510
1511 wp_enqueue_script( 'wpmudev-chat-admin-js' );
1512 $this->_registered_styles['wpmudev-chat-admin-js'] = 'wpmudev-chat-admin-js';
1513
1514 // The admin can even block chats from our own admin pages.
1515 if ( $this->_chat_plugin_settings['blocked_urls']['admin'] == false ) {
1516
1517 $this->_registered_styles['wpmudev-chat-style'] = 'wpmudev-chat-style';
1518
1519 wp_enqueue_script( 'wpmudev-chat-js' );
1520 $this->_registered_scripts['wpmudev-chat-js'] = 'wpmudev-chat-js';
1521 }
1522
1523 if ( ( isset( $this->user_meta['chat_wp_toolbar'] ) ) && ( $this->user_meta['chat_wp_toolbar'] == "enabled" ) ) {
1524
1525 $this->_registered_styles['wpmudev-chat-wpadminbar-style'] = 'wpmudev-chat-wpadminbar-style';
1526
1527 // For older versions of WP (less than 3.8) we add some supplement styles
1528 if ( ! version_compare( $wp_version, '3.7.1', '>' ) ) {
1529 $this->_registered_styles['wpmudev-chat-wpadminbar-style-pre-38'] = 'wpmudev-chat-wpadminbar-style-pre-38';
1530 }
1531 }
1532
1533 return;
1534 }
1535
1536 // Check of we are on the BuddyPress Groups admin screen within the dashboard
1537 if ( ( isset( $_GET['page'] ) ) && ( $_GET['page'] == "bp-groups" ) ) {
1538
1539 wp_enqueue_script( 'json2' );
1540 $this->_registered_scripts['json2'] = 'json2';
1541
1542 wp_enqueue_script( 'jquery-ui-core' );
1543 $this->_registered_scripts['jquery-ui-core'] = 'jquery-ui-core';
1544
1545 wp_enqueue_script( 'jquery-ui-tabs' );
1546 $this->_registered_scripts['jquery-ui-tabs'] = 'jquery-ui-tabs';
1547
1548
1549 $this->_registered_styles['wpmudev-chat-style'] = 'wpmudev-chat-style';
1550 $this->_registered_styles[] = 'wpmudev-chat-admin-css';
1551
1552 wp_enqueue_script( 'wpmudev-chat-js' );
1553 $this->_registered_scripts['wpmudev-chat-js'] = 'wpmudev-chat-js';
1554
1555 wp_enqueue_script( 'wpmudev-chat-admin-js' );
1556 $this->_registered_scripts['wpmudev-chat-admin-js'] = 'wpmudev-chat-admin-js';
1557
1558 wp_enqueue_script( 'wpmudev-chat-admin-farbtastic-js' );
1559 $this->_registered_scripts['wpmudev-chat-admin-farbtastic-js'] = 'wpmudev-chat-admin-farbtastic-js';
1560
1561 wp_enqueue_script( 'jquery-cookie' );
1562 $this->_registered_scripts['jquery-cookie'] = 'jquery-cookie';
1563 }
1564
1565 if ( $this->_chat_plugin_settings['blocked_urls']['admin'] == true ) {
1566 return;
1567 }
1568
1569 if ( ( isset( $this->user_meta['chat_wp_admin'] ) ) && ( $this->user_meta['chat_wp_admin'] != "enabled" ) ) {
1570 return;
1571 }
1572
1573 //If Admin bar chat settings are enabled
1574 if ( ( isset( $this->user_meta['chat_wp_toolbar'] ) ) && ( $this->user_meta['chat_wp_toolbar'] == "enabled" ) ) {
1575 $this->_registered_styles['wpmudev-chat-wpadminbar-style'] = 'wpmudev-chat-wpadminbar-style';
1576
1577 // For older versions of WP (less than 3.8) we add some supplement styles
1578 global $wp_version;
1579 if ( ! version_compare( $wp_version, '3.7.1', '>' ) ) {
1580 $this->_registered_styles['wpmudev-chat-wpadminbar-style-pre-38'] = 'wpmudev-chat-wpadminbar-style-pre-38';
1581 }
1582 }
1583 $this->_registered_styles['wpmudev-chat-style'] = 'wpmudev-chat-style';
1584
1585 //Commented out in 2.0.8.6, as it breaks on Gravity forms page
1586 //wp_enqueue_script( 'wpmudev-chat-js' );
1587 $this->_registered_scripts['wpmudev-chat-js'] = 'wpmudev-chat-js';
1588
1589 }
1590
1591 /**
1592 * Enqueue all the scripts and styles we need. Per proper WP methods.
1593 *
1594 * @global none
1595 *
1596 * @param none
1597 *
1598 * @return none
1599 */
1600 function wp_enqueue_scripts() {
1601 //global $bp;
1602 global $wp_version;
1603
1604 if ( is_admin() ) {
1605 return;
1606 }
1607
1608 //Register Styles And Scripts
1609 wp_register_style( 'wpmudev-chat-style', plugins_url( '/css/wpmudev-chat-style.css', __FILE__ ), array(), $this->chat_current_version );
1610 wp_register_style( 'wpmudev-chat-admin-css', plugins_url( '/css/wpmudev-chat-admin.css', __FILE__ ), array(), $this->chat_current_version );
1611 wp_register_style( 'wpmudev-chat-wpadminbar-style', plugins_url( '/css/wpmudev-chat-wpadminbar.css', __FILE__ ), array(), $this->chat_current_version );
1612
1613 if ( ! version_compare( $wp_version, '3.7.1', '>' ) ) {
1614 wp_register_style( 'wpmudev-chat-wpadminbar-style-pre-38', plugins_url( '/css/wpmudev-chat-wpadminbar-pre-38.css', __FILE__ ), array(), $this->chat_current_version );
1615 }
1616
1617 //Register scripts
1618 wp_register_script( 'wpmudev-chat-js', plugins_url( '/js/wpmudev-chat.js', __FILE__ ), array( 'jquery' ), $this->chat_current_version, true );
1619 wp_register_script( 'wpmudev-chat-admin-js', plugins_url( '/js/wpmudev-chat-admin.js', __FILE__ ), array( 'jquery' ), $this->chat_current_version, true );
1620 wp_register_script( 'wpmudev-chat-admin-farbtastic-js', plugins_url( '/js/wpmudev-chat-admin-farbtastic.js', __FILE__ ), array(), $this->chat_current_version, true );
1621
1622 //Facebook Script
1623 $locale = get_locale();
1624 $scheme = is_ssl() ? 'https://' : 'http://';
1625
1626 // We use 'facebook-all' to match our Ultimate Facebook plugin which enques the same script. Prevents enque duplication
1627 wp_register_script( 'facebook-all', $scheme . 'connect.facebook.net/' . $locale . '/all.js' );
1628
1629 //$_SCRIPTS_LOADED = false;
1630 $_BLOCK_URL = false;
1631
1632 // Why yes we are loading the scripts and styles for admin and non-admin pages. Because we are allowing chat to run under both!
1633
1634 if ( ( function_exists( 'bp_is_group_admin_screen' ) ) && ( bp_is_group_admin_screen( $this->get_option( 'bp_menu_slug', 'global' ) ) ) ) {
1635
1636 //$_SCRIPTS_LOADED = true;
1637
1638 //wp_enqueue_style( 'farbtastic' );
1639 //$this->_registered_styles['farbtastic'] = 'farbtastic';
1640
1641 wp_enqueue_script( 'jquery' );
1642 $this->_registered_scripts['jquery'] = 'jquery';
1643
1644 wp_enqueue_script( 'json2' );
1645 $this->_registered_scripts['json2'] = 'json2';
1646
1647 wp_enqueue_script( 'jquery-ui-core' );
1648 $this->_registered_scripts['jquery-ui-core'] = 'jquery-ui-core';
1649
1650 wp_enqueue_script( 'jquery-ui-tabs' );
1651 $this->_registered_scripts['jquery-ui-tabs'] = 'jquery-ui-tabs';
1652
1653 $this->_registered_styles['wpmudev-chat-style'] = 'wpmudev-chat-style';
1654 $this->_registered_styles[] = 'wpmudev-chat-admin-css';
1655
1656 wp_enqueue_script( 'wpmudev-chat-js' );
1657 $this->_registered_scripts['wpmudev-chat-js'] = 'wpmudev-chat-js';
1658
1659 wp_enqueue_script( 'wpmudev-chat-admin-js' );
1660 $this->_registered_scripts['wpmudev-chat-admin-js'] = 'wpmudev-chat-admin-js';
1661
1662 wp_enqueue_script( 'wpmudev-chat-admin-farbtastic-js' );
1663 $this->_registered_scripts['wpmudev-chat-admin-farbtastic-js'] = 'wpmudev-chat-admin-farbtastic-js';
1664
1665
1666 if ( $this->user_meta['chat_wp_toolbar'] == "enabled" ) {
1667 $this->_registered_styles['wpmudev-chat-wpadminbar-style'] = 'wpmudev-chat-wpadminbar-style';
1668
1669 // For older versions of WP (less than 3.8) we add some supplement styles
1670 if ( ! version_compare( $wp_version, '3.7.1', '>' ) ) {
1671 $this->_registered_styles['wpmudev-chat-wpadminbar-style-pre-38'] = 'wpmudev-chat-wpadminbar-style-pre-38';
1672 }
1673 }
1674
1675 } else {
1676
1677 if ( ( isset( $this->user_meta['chat_wp_toolbar'] ) ) && ( $this->user_meta['chat_wp_toolbar'] == "enabled" ) ) {
1678 $this->_registered_styles['wpmudev-chat-wpadminbar-style'] = 'wpmudev-chat-wpadminbar-style';
1679
1680 // For older versions of WP (less than 3.8) we add some supplement styles
1681 if ( ! version_compare( $wp_version, '3.7.1', '>' ) ) {
1682 $this->_registered_styles['wpmudev-chat-wpadminbar-style-pre-38'] = 'wpmudev-chat-wpadminbar-style-pre-38';
1683 }
1684 }
1685
1686 wp_enqueue_script( 'jquery' );
1687 wp_enqueue_script( 'json2' );
1688 $this->_registered_scripts['json2'] = 'json2';
1689
1690 //Facebook Scripts
1691 if ( $this->chat_localized['settings']["facebook_active"] === true ) {
1692 wp_enqueue_script( 'facebook-all' );
1693 $this->_registered_scripts['facebook-all'] = 'facebook-all';
1694 }
1695
1696 $this->_registered_styles['wpmudev-chat-style'] = 'wpmudev-chat-style';
1697 if( is_page(1635) ){
1698 wp_enqueue_script( 'wpmudev-chat-js' );
1699 $this->_registered_scripts['wpmudev-chat-js'] = 'wpmudev-chat-js';
1700 }
1701 }
1702 }
1703
1704
1705 /**
1706 * Special logic. We load two templates. One is the Twitter login popup. The second is the pop-out chat option. Both options pass query string parameters
1707 * which are checked within this function. If we find a match we load the special template and exit.
1708 *
1709 * @global none
1710 *
1711 * @param none
1712 *
1713 * @return none
1714 */
1715 function load_template() {
1716
1717 if ( ( isset( $_GET['wpmudev-chat-action'] ) ) && ( ! empty( $_GET['wpmudev-chat-action'] ) ) ) {
1718
1719 switch ( $_GET['wpmudev-chat-action'] ) {
1720 case 'pop-out':
1721
1722 if ( ( isset( $_GET['wpmudev-chat-key'] ) ) && ( ! empty( $_GET['wpmudev-chat-key'] ) ) ) {
1723
1724 $wpmudev_chat_key = base64_decode( $_GET['wpmudev-chat-key'] );
1725 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
1726 $chat_session = get_option( $wpmudev_chat_key );
1727 } else {
1728 $chat_session = get_transient( $wpmudev_chat_key );
1729 }
1730 if ( ( ! empty( $chat_session ) ) && ( is_array( $chat_session ) ) ) {
1731 $this->using_popup_out_template = true;
1732 if ( $wpmudev_chat_popup_template = locate_template( 'wpmudev-chat-pop-out-' . $chat_session['id'] . '.php' ) ) {
1733 load_template( $$wpmudev_chat_popup_template );
1734 die();
1735 } else if ( $wpmudev_chat_popup_template = locate_template( 'wpmudev-chat-pop-out.php' ) ) {
1736 load_template( $$wpmudev_chat_popup_template );
1737 die();
1738 } else {
1739 load_template( dirname( __FILE__ ) . '/templates/wpmudev-chat-pop-out.php' );
1740 die();
1741 }
1742 }
1743 }
1744 break;
1745
1746 case 'pop-twitter':
1747 load_template( dirname( __FILE__ ) . '/templates/wpmudev-chat-pop-twitter-auth.php' );
1748 die();
1749
1750 break;
1751 }
1752 }
1753 }
1754
1755 /**
1756 * Here we use a class method to get options from our internal settings array. Similar to the WP get_option call.
1757 *
1758 * @global none
1759 *
1760 * @param $key - The options key.
1761 * $session_type - This is the options group.
1762 *
1763 * @return returns found value
1764 */
1765 function get_option( $key, $session_type = 'page' ) {
1766 if ( isset( $this->_chat_options[ $session_type ][ $key ] ) ) {
1767 $val = $this->_chat_options[ $session_type ][ $key ];
1768 if ( is_string( $val ) ) {
1769 $val = stripslashes( $val );
1770 }
1771
1772 return $val;
1773 } else if ( isset( $this->_chat_options_defaults[ $session_type ][ $key ] ) ) {
1774 $val = $this->_chat_options_defaults[ $session_type ][ $key ];
1775 if ( is_string( $val ) ) {
1776 $val = stripslashes( $val );
1777 }
1778
1779 return $val;
1780 }
1781 }
1782
1783 /**
1784 * Our footer output is busy. We need to output the logic for the bottom corner chat wrapper. This is a UL element and each chat box added is an <LI>
1785 *
1786 * @global none
1787 *
1788 * @param none
1789 *
1790 * @return none
1791 */
1792 function wp_footer() {
1793
1794 // See $this->admin_footer() for admin footer logic
1795 if ( is_admin() ) {
1796 return;
1797 }
1798
1799 if ( ( $this->_chat_plugin_settings['blocked_urls']['front'] != true )
1800 || ( count( $this->chat_sessions ) > 0 )
1801 ) {
1802
1803 $this->set_chat_localized();
1804 wp_print_scripts( array_values( $this->_registered_scripts ) );
1805
1806 if ( ! empty( $this->site_content ) ) {
1807 echo $this->site_content;
1808 }
1809 } else {
1810 foreach ( $this->_registered_styles as $_handle ) {
1811 wp_dequeue_style( $_handle );
1812 }
1813 foreach ( $this->_registered_scripts as $_handle ) {
1814 wp_dequeue_script( $_handle );
1815 }
1816 }
1817 }
1818
1819 function admin_notices() {
1820
1821 if ( ( isset( $this->_admin_notice_messages_key ) ) && ( ! empty( $this->_admin_notice_messages_key ) ) ) {
1822
1823 if ( ( isset( $this->_admin_notice_messages[ $this->_admin_notice_messages_key ] ) )
1824 && ( ! empty( $this->_admin_notice_messages[ $this->_admin_notice_messages_key ] ) )
1825 ) {
1826 ?>
1827 <div id="wpmudev-chat-updated" class="updated below-h2"><p><?php
1828 echo $this->_admin_notice_messages[ $this->_admin_notice_messages_key ]; ?></p></div><?php
1829 }
1830 }
1831
1832 if ( ( is_multisite() ) && ( is_network_admin() ) ) {
1833 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
1834 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
1835 }
1836 if ( ! is_plugin_active_for_network( 'wordpress-chat/wordpress-chat.php' ) ) {
1837 return;
1838 }
1839
1840 if ( ! current_user_can( 'manage_network_options' ) ) {
1841 return;
1842 }
1843 $nag_version = get_site_option( 'wpmudev-chat-version-nag', false );
1844
1845 } else {
1846 if ( ! current_user_can( 'manage_options' ) ) {
1847 return;
1848 }
1849 $nag_version = get_option( 'wpmudev-chat-version-nag', false );
1850 }
1851
1852 if ( ( is_multisite() ) && ( is_network_admin() ) ) {
1853 $chat_url_stub = 'admin.php?page=chat_settings_panel_network_global#wpmudev_chat_interval_panel';
1854 $chat_admin_url = network_admin_url( $chat_url_stub );
1855 } else {
1856 $chat_url_stub = 'admin.php?page=chat_settings_panel_global#wpmudev_chat_interval_panel';
1857 $chat_admin_url = admin_url( $chat_url_stub );
1858 }
1859
1860 if ( ! $nag_version ) {
1861 ?>
1862 <div id="wpmudev-chat-nag-error" class="error below-h2">
1863 <p><?php echo sprintf( __( 'You have installed the WordPress Chat plugin. <strong>Please review the <a href="%s">polling interval</a> settings before using</strong>. In most cases the default options will work for your host configuration. However, in some unique cases the polling interval is too frequent and could cause your hosting to shutdown your account. Once you have reviewed and saved the chat settings this message will no longer appear.', $this->translation_domain ), esc_url( $chat_admin_url ) ) ?></p>
1864 </div><?php
1865 } else if ( version_compare( $this->_chat_plugin_settings['options_version'], $nag_version ) > 0 ) {
1866 ?>
1867 <div id="wpmudev-chat-nag-error" class="error">
1868 <p><?php echo sprintf( __( 'The WordPress Chat plugin has been upgraded on yor site. <strong>Please review the <a href="%s">polling interval</a> settings before using</strong>. In most cases the default options will work for your host configuration. However in some unique cases the polling interval is too frequent and could cause your hosting to shutdown your account. Once you have reviewed and saved the chat settings this message will no longer appear.', $this->translation_domain ), esc_url( $chat_admin_url ) ) ?></p>
1869 </div><?php
1870 }
1871 }
1872
1873 function admin_footer() {
1874
1875 if ( ( count( $this->_registered_scripts ) ) && ( isset( $this->_registered_scripts['wpmudev-chat-js'] ) ) ) {
1876
1877 if ( ( ! isset( $_GET['page'] ) ) || ( $_GET['page'] != 'chat_session_logs' ) ) {
1878 if ( ! empty( $this->site_content ) ) {
1879 echo $this->site_content;
1880 }
1881
1882 }
1883 $this->set_chat_localized();
1884
1885 // Moved to wp-head
1886 //wp_print_styles(array_values($this->_registered_styles));
1887 wp_print_scripts( array_values( $this->_registered_scripts ) );
1888
1889 } else if ( $this->_show_own_admin == true ) {
1890 wp_print_styles( array_values( $this->_registered_styles ) );
1891 wp_print_scripts( array_values( $this->_registered_scripts ) );
1892 }
1893 }
1894
1895 function set_chat_localized() {
1896 if ( $this->get_option( 'session_poll_type', 'global' ) == "plugin" ) {
1897 if ( wpmudev_chat_validate_config_file( $this->_chat_plugin_settings['config_file'], 'ABSPATH' ) === true ) {
1898 $this->chat_localized['settings']["ajax_url"] = plugins_url( '/wpmudev-chat-ajax.php', __FILE__ );
1899 } else {
1900 //$this->chat_localized['settings']["ajax_url"] = site_url()."/wp-admin/admin-ajax.php?xyz";
1901 $this->chat_localized['settings']["ajax_url"] = admin_url( 'admin-ajax.php', 'relative' );
1902 }
1903 } else {
1904 //$this->chat_localized['settings']["ajax_url"] = site_url()."/wp-admin/admin-ajax.php?123";
1905 $this->chat_localized['settings']["ajax_url"] = admin_url( 'admin-ajax.php', 'relative' );
1906
1907 }
1908
1909 $this->chat_localized['settings']['cookiepath'] = COOKIEPATH;
1910 $this->chat_localized['settings']['cookie_domain'] = COOKIE_DOMAIN;
1911 //$this->chat_localized['settings']['ABSPATH'] = base64_encode(ABSPATH);
1912 $this->chat_localized['settings']['REQUEST_URI'] = base64_encode( $_SERVER['REQUEST_URI'] );
1913 $this->chat_localized['settings']['is_admin'] = is_admin() ? true : false;
1914
1915 //$this->chat_localized['settings']['soundManager-js'] = plugins_url('/js/soundmanager2-nodebug-jsmin.js', __FILE__);
1916 $this->chat_localized['settings']['soundManager-js'] = plugins_url( '/js/buzz.min.js', __FILE__ );
1917 //$this->chat_localized['settings']['cookie-js'] = plugins_url('/js/jquery-cookie.js', __FILE__);
1918
1919 // Need to disable legacy setting.
1920 $this->chat_localized['settings']['box_resizable'] = false;
1921
1922 $this->chat_localized['sessions'] = $this->chat_sessions;
1923 $this->chat_localized['user'] = $this->chat_user;
1924 $this->chat_localized['auth'] = $this->chat_auth;
1925 $this->chat_localized['auto_scroll']['disable'] = __( 'Disable auto scroll', $this->translation_domain );
1926 $this->chat_localized['auto_scroll']['enable'] = __( 'Enable auto scroll', $this->translation_domain );
1927
1928 wp_localize_script( 'wpmudev-chat-js', 'wpmudev_chat_localized', $this->chat_localized );
1929 }
1930
1931 /**
1932 *
1933 *
1934 * @global none
1935 *
1936 * @param none
1937 *
1938 * @return none
1939 */
1940 function network_admin_menu() {
1941
1942 // Planned global settings panel the network admin can control the default settings.
1943
1944 // For example the bottom corner chat option can be set the enabled or disabled. Then all
1945 // new sites will inherit this option. Only if chat is network activated. Local activation
1946 // will not use site settings.
1947
1948 if ( ! is_multisite() ) {
1949 return;
1950 }
1951 if ( ! is_network_admin() ) {
1952 return;
1953 }
1954 if ( ! is_super_admin() ) {
1955 return;
1956 }
1957
1958 if ( $this->_chat_plugin_settings['network_active'] != true ) {
1959 return;
1960 }
1961
1962 require( dirname( __FILE__ ) . '/lib/wpmudev_chat_admin_panels.php' );
1963 $this->_admin_panels = new wpmudev_chat_admin_panels();
1964
1965 $this->_pagehooks['chat_settings_panel_network_site'] = add_menu_page( _x( "Chat", 'page label', $this->translation_domain ),
1966 _x( "Chat", 'menu label', $this->translation_domain ),
1967 'manage_network_options',
1968 'chat_settings_panel_network_site',
1969 array( $this->_admin_panels, 'chat_settings_panel_network_site' )
1970 //plugin_dir_url( __FILE__ ) .'images/icon/greyscale-16.png'
1971 );
1972
1973 $this->_pagehooks['chat_settings_panel_network_site'] = add_submenu_page( 'chat_settings_panel_network_site',
1974 _x( 'Settings Site', 'page label', $this->translation_domain ),
1975 _x( 'Settings Site', 'menu label', $this->translation_domain ),
1976 'manage_network_options',
1977 'chat_settings_panel_network_site',
1978 array( &$this->_admin_panels, 'chat_settings_panel_network_site' )
1979 );
1980 $this->_pagehooks['chat_settings_panel_network_dashboard'] = add_submenu_page( 'chat_settings_panel_network_site',
1981 _x( 'Settings Dashboard', 'page label', $this->translation_domain ),
1982 _x( 'Settings Dashboard', 'menu label', $this->translation_domain ),
1983 'manage_network_options',
1984 'chat_settings_panel_network_dashboard',
1985 array( &$this->_admin_panels, 'chat_settings_panel_dashboard' )
1986 );
1987
1988 $this->_pagehooks['chat_settings_panel_network_global'] = add_submenu_page( 'chat_settings_panel_network_site',
1989 _x( 'Settings Common', 'page label', $this->translation_domain ),
1990 _x( 'Settings Common', 'menu label', $this->translation_domain ),
1991 'manage_network_options',
1992 'chat_settings_panel_network_global',
1993 array( &$this->_admin_panels, 'chat_settings_panel_global' )
1994 );
1995
1996 $this->_pagehooks['chat_session_logs_network_site'] = add_submenu_page( 'chat_settings_panel_network_site',
1997 _x( 'Session Logs', 'page label', $this->translation_domain ),
1998 _x( 'Session Logs', 'menu label', $this->translation_domain ),
1999 'manage_network_options',
2000 'chat_session_logs',
2001 array( &$this->_admin_panels, 'chat_settings_panel_session_logs' )
2002 );
2003
2004 // Hook into the WordPress load page action for our new nav items. This is better then checking page query_str values.
2005 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_network_site'], array(
2006 &$this,
2007 'on_load_panels'
2008 ) );
2009 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_network_dashboard'], array(
2010 &$this,
2011 'on_load_panels'
2012 ) );
2013 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_network_global'], array(
2014 &$this,
2015 'on_load_panels'
2016 ) );
2017 add_action( 'load-' . $this->_pagehooks['chat_session_logs_network_site'], array(
2018 &$this,
2019 'on_load_panels'
2020 ) );
2021 }
2022
2023 /**
2024 * Standard function to create our admin menus
2025 *
2026 * @global none
2027 *
2028 * @param none
2029 *
2030 * @return none
2031 * @see http://codex.wordpress.org/Adding_Administration_Menus
2032 */
2033 function admin_menu() {
2034
2035 require( dirname( __FILE__ ) . '/lib/wpmudev_chat_admin_panels.php' );
2036 $this->_admin_panels = new wpmudev_chat_admin_panels();
2037
2038 add_menu_page( _x( "Chat", 'page label', $this->translation_domain ),
2039 _x( "Chat", 'menu label', $this->translation_domain ),
2040 'manage_options',
2041 'chat_settings_panel',
2042 array( $this->_admin_panels, 'chat_settings_panel_page' )
2043 //plugin_dir_url( __FILE__ ) .'images/icon/greyscale-16.png'
2044 );
2045
2046 $this->_pagehooks['chat_settings_panel_page'] = add_submenu_page( 'chat_settings_panel',
2047 _x( 'Settings Page', 'page label', $this->translation_domain ),
2048 _x( 'Settings Page', 'menu label', $this->translation_domain ),
2049 'manage_options',
2050 'chat_settings_panel',
2051 array( &$this->_admin_panels, 'chat_settings_panel_page' )
2052 );
2053
2054 //if ((!is_multisite()) || ($this->get_option('bottom_corner', 'network-site') == 'disabled')) {
2055
2056 $this->_pagehooks['chat_settings_panel_site'] = add_submenu_page( 'chat_settings_panel',
2057 _x( 'Settings Site', 'page label', $this->translation_domain ),
2058 _x( 'Settings Site', 'menu label', 'menu label', $this->translation_domain ),
2059 'manage_options',
2060 'chat_settings_panel_site',
2061 array( &$this->_admin_panels, 'chat_settings_panel_site' )
2062 );
2063 //}
2064
2065 $this->_pagehooks['chat_settings_panel_widget'] = add_submenu_page( 'chat_settings_panel',
2066 _x( 'Settings Widget', 'page label', $this->translation_domain ),
2067 _x( 'Settings Widget', 'menu label', 'menu label', $this->translation_domain ),
2068 'manage_options',
2069 'chat_settings_panel_widget',
2070 array( &$this->_admin_panels, 'chat_settings_panel_widget' )
2071 );
2072
2073 $this->_pagehooks['chat_settings_panel_dashboard'] = add_submenu_page( 'chat_settings_panel',
2074 _x( 'Settings Dashboard', 'page label', $this->translation_domain ),
2075 _x( 'Settings Dashboard', 'menu label', 'menu label', $this->translation_domain ),
2076 'manage_options',
2077 'chat_settings_panel_dashboard',
2078 array( &$this->_admin_panels, 'chat_settings_panel_dashboard' )
2079 );
2080
2081 $this->_pagehooks['chat_settings_panel_global'] = add_submenu_page( 'chat_settings_panel',
2082 _x( 'Settings Common', 'page label', $this->translation_domain ),
2083 _x( 'Settings Common', 'menu label', 'menu label', $this->translation_domain ),
2084 'manage_options',
2085 'chat_settings_panel_global',
2086 array( &$this->_admin_panels, 'chat_settings_panel_global' )
2087 );
2088
2089 $this->_pagehooks['chat_session_logs'] = add_submenu_page( 'chat_settings_panel',
2090 _x( 'Session Logs', 'page label', $this->translation_domain ),
2091 _x( 'Session Logs', 'menu label', $this->translation_domain ),
2092 'manage_options',
2093 'chat_session_logs',
2094 array( &$this->_admin_panels, 'chat_settings_panel_session_logs' )
2095 );
2096
2097 // Hook into the WordPress load page action for our new nav items. This is better then checking page query_str values.
2098 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_page'], array( &$this, 'on_load_panels' ) );
2099 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_site'], array( &$this, 'on_load_panels' ) );
2100 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_widget'], array( &$this, 'on_load_panels' ) );
2101 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_dashboard'], array(
2102 &$this,
2103 'on_load_panels'
2104 ) );
2105 add_action( 'load-' . $this->_pagehooks['chat_settings_panel_global'], array( &$this, 'on_load_panels' ) );
2106 add_action( 'load-' . $this->_pagehooks['chat_session_logs'], array( &$this, 'on_load_panels' ) );
2107 }
2108
2109 /**
2110 * Special function called when an of out admin pages are loaded. This way we can load any needed JS/CSS or processing logic
2111 *
2112 * @global none
2113 *
2114 * @param none
2115 *
2116 * @return none
2117 */
2118 function on_load_panels() {
2119
2120 $this->_show_own_admin = true;
2121
2122 /* These messages are displayed as part of the admin header message see 'admin_notices' WordPress action */
2123 $this->_admin_notice_messages['success-settings'] = __( "Settings have been updated.", $this->translation_domain );
2124
2125 $this->_admin_notice_messages['success-log-delete'] = __( "Chat Session Log has been deleted.", $this->translation_domain );
2126 $this->_admin_notice_messages['success-logs-delete'] = __( "Chat Session Logs have been deleted.", $this->translation_domain );
2127 $this->_admin_notice_messages['success-log-hide'] = __( "Chat Session Log has been hidden.", $this->translation_domain );
2128 $this->_admin_notice_messages['success-logs-hide'] = __( "Chat Session Logs have been hidden.", $this->translation_domain );
2129 $this->_admin_notice_messages['success-log-unhide'] = __( "Chat Session Log has been unhidden.", $this->translation_domain );
2130 $this->_admin_notice_messages['success-logs-unhide'] = __( "Chat Session Logs have been unhidden.", $this->translation_domain );
2131
2132 $this->_admin_notice_messages['success-message-delete'] = __( "Chat Session Log Message has been deleted.", $this->translation_domain );
2133 $this->_admin_notice_messages['success-messages-delete'] = __( "Chat Session Log Messages have been deleted.", $this->translation_domain );
2134 $this->_admin_notice_messages['success-message-hide'] = __( "Chat Session Log Message has been hidden.", $this->translation_domain );
2135 $this->_admin_notice_messages['success-messages-hide'] = __( "Chat Session Log Messages have been hidden.", $this->translation_domain );
2136 $this->_admin_notice_messages['success-message-unhide'] = __( "Chat Session Log Message has been unhidden.", $this->translation_domain );
2137 $this->_admin_notice_messages['success-messages-unhide'] = __( "Chat Session Log Messages have been unhidden.", $this->translation_domain );
2138
2139
2140 if ( ( isset( $_GET['page'] ) ) && ( $_GET['page'] == "chat_session_logs" ) ) {
2141
2142 if ( ( isset( $_GET['maction'] ) ) && ( isset( $_GET['_wpnonce'] ) ) && ( wp_verify_nonce( $_GET['_wpnonce'], 'chat-message-item' ) ) ) {
2143
2144 $_SERVER['REQUEST_URI'] = esc_url_raw( remove_query_arg( array(
2145 '_wp_http_referer',
2146 '_wpnonce'
2147 ), $_SERVER['REQUEST_URI'] ) );
2148
2149 $mid = '';
2150 if ( isset( $_GET['mid'] ) ) {
2151 $mid = intval( $_GET['mid'] );
2152 }
2153
2154 $maction = '';
2155 if ( isset( $_GET['maction'] ) ) {
2156 $maction = esc_attr( $_GET['maction'] );
2157 }
2158
2159 $chat_href = esc_url_raw( remove_query_arg( array( '_wpnonce', 'maction', 'mid', 'message' ) ) );
2160 if ( $maction == "delete" ) {
2161 $this->chat_session_logs_messages( 'message', 'delete', array( $mid ) );
2162 $chat_href = add_query_arg( 'message', 'success-message-delete', $chat_href );
2163 wp_redirect( $chat_href );
2164
2165 } else if ( ( $maction == "hide" ) || ( $maction == "unhide" ) ) {
2166 if ( $maction == "hide" ) {
2167 $this->chat_session_logs_messages( 'message', 'hide', array( $mid ) );
2168 $chat_href = add_query_arg( 'message', 'success-message-hide', $chat_href );
2169
2170 } else if ( $maction == "unhide" ) {
2171 $this->chat_session_logs_messages( 'message', 'unhide', array( $mid ) );
2172 $chat_href = add_query_arg( 'message', 'success-message-unhide', $chat_href );
2173 }
2174
2175 if ( isset( $_GET['lid'] ) ) {
2176 global $wpdb;
2177 $sql_str = $wpdb->prepare( "SELECT * FROM " . WPMUDEV_Chat::tablename( 'log' ) . " WHERE id=%d", intval( $_GET['lid'] ) );
2178 if ( is_multisite() ) {
2179 $sql_str .= " AND blog_id=" . $this->filters['blog_id'];
2180 }
2181 $sql_str .= " LIMIT 1";
2182
2183 $log_item = $wpdb->get_row( $sql_str );
2184 if ( ( ! empty( $log_item ) )
2185 && ( isset( $log_item->chat_id ) ) && ( ! empty( $log_item->chat_id ) )
2186 && ( isset( $log_item->session_type ) ) && ( ! empty( $log_item->session_type ) )
2187 ) {
2188 $transient_key = "chat-session-" . $log_item->chat_id . '-' . $log_item->session_type;
2189
2190 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
2191 $chat_session_transient = get_option( $transient_key );
2192 } else {
2193 $chat_session_transient = get_transient( $transient_key );
2194 }
2195 if ( ! empty( $chat_session_transient ) ) {
2196 $this->chat_session_update_message_rows_deleted( $chat_session_transient );
2197 }
2198 }
2199 }
2200 wp_redirect( $chat_href );
2201 }
2202
2203 wp_redirect( $chat_href );
2204
2205 } else if ( ( isset( $_GET['laction'] ) ) && ( isset( $_GET['_wpnonce'] ) ) && ( wp_verify_nonce( $_GET['_wpnonce'], 'chat-log-item' ) ) ) {
2206
2207 $_SERVER['REQUEST_URI'] = esc_url_raw( remove_query_arg( array(
2208 '_wp_http_referer',
2209 '_wpnonce'
2210 ), $_SERVER['REQUEST_URI'] ) );
2211
2212 $lid = '';
2213 if ( isset( $_GET['lid'] ) ) {
2214 $lid = intval( $_GET['lid'] );
2215 }
2216
2217 $laction = '';
2218 if ( isset( $_GET['laction'] ) ) {
2219 $laction = esc_attr( $_GET['laction'] );
2220 }
2221
2222 $chat_href = esc_url_raw( remove_query_arg( array(
2223 '_wpnonce',
2224 'lid',
2225 'laction',
2226 'maction',
2227 'message'
2228 ) ) );
2229 if ( $laction == "delete" ) {
2230 $this->chat_session_logs_messages( 'log', 'delete', array( $lid ) );
2231 $chat_href = add_query_arg( 'message', 'success-log-delete', $chat_href );
2232 wp_redirect( $chat_href );
2233
2234 } else if ( $laction == "hide" ) {
2235 $this->chat_session_logs_messages( 'log', 'hide', array( $lid ) );
2236 $chat_href = add_query_arg( 'message', 'success-log-hide', $chat_href );
2237 wp_redirect( $chat_href );
2238
2239 } else if ( $laction == "unhide" ) {
2240 $this->chat_session_logs_messages( 'log', 'unhide', array( $lid ) );
2241 $chat_href = add_query_arg( 'message', 'success-log-unhide', $chat_href );
2242 wp_redirect( $chat_href );
2243
2244 } else if ( $laction == "details" ) {
2245 $per_page = get_user_meta( get_current_user_id(), 'chat_page_chat_session_messages_per_page', true );
2246 if ( ! $per_page ) {
2247 $per_page = 20;
2248 }
2249
2250 if ( ( isset( $_POST['wp_screen_options']['option'] ) )
2251 && ( $_POST['wp_screen_options']['option'] == "chat_page_chat_session_logs_per_page" )
2252 ) {
2253
2254 if ( isset( $_POST['wp_screen_options']['value'] ) ) {
2255 $per_page = intval( $_POST['wp_screen_options']['value'] );
2256 if ( ( ! $per_page ) || ( $per_page < 1 ) ) {
2257 $per_page = 20;
2258 }
2259 update_user_meta( get_current_user_id(), 'chat_page_chat_session_messages_per_page', $per_page );
2260 }
2261 }
2262 add_screen_option( 'per_page', array(
2263 'label' => __( 'per Page', $this->translation_domain ),
2264 'default' => $per_page
2265 ) );
2266 }
2267 } else if ( ( isset( $_GET['chat-messages-bulk'] ) ) && ( is_array( $_GET['chat-messages-bulk'] ) ) && ( count( $_GET['chat-messages-bulk'] ) ) && ( isset( $_GET['_wpnonce'] ) ) && ( wp_verify_nonce( $_GET['_wpnonce'], 'bulk-messages' ) ) ) {
2268
2269 $bulk_action = '';
2270
2271 if ( ( isset( $_GET['action'] ) ) && ( $_GET['action'] != '-1' ) ) {
2272 $bulk_action = esc_attr( $_GET['action'] );
2273 } else if ( ( isset( $_GET['action2'] ) ) && ( $_GET['action2'] != '-1' ) ) {
2274 $bulk_action = esc_attr( $_GET['action2'] );
2275 }
2276
2277 $_SERVER['REQUEST_URI'] = esc_url_raw( remove_query_arg( array(
2278 '_wp_http_referer',
2279 '_wpnonce',
2280 'action',
2281 'action2',
2282 'mid'
2283 ), $_SERVER['REQUEST_URI'] ) );
2284
2285 if ( ( $bulk_action ) && ( ! empty( $bulk_action ) ) ) {
2286 $chat_href = esc_url_raw( remove_query_arg( array(
2287 '_wpnonce',
2288 'maction',
2289 'message'
2290 ), $_GET['_wp_http_referer'] ) );
2291 if ( $bulk_action == 'delete' ) {
2292 $this->chat_session_logs_messages( 'message', 'delete', $_GET['chat-messages-bulk'] );
2293 $chat_href = add_query_arg( 'message', 'success-messages-delete', $chat_href );
2294 wp_redirect( $chat_href );
2295
2296 } else if ( $bulk_action == "hide" ) {
2297 $this->chat_session_logs_messages( 'message', 'hide', $_GET['chat-messages-bulk'] );
2298 $chat_href = add_query_arg( 'message', 'success-messages-hide', $chat_href );
2299 wp_redirect( $chat_href );
2300 } else if ( $bulk_action == "unhide" ) {
2301 $this->chat_session_logs_messages( 'message', 'unhide', $_GET['chat-messages-bulk'] );
2302 $chat_href = add_query_arg( 'message', 'success-messages-unhide', $chat_href );
2303 wp_redirect( $chat_href );
2304 }
2305 }
2306
2307 } else if ( ( isset( $_GET['chat-logs-bulk'] ) ) && ( is_array( $_GET['chat-logs-bulk'] ) ) && ( count( $_GET['chat-logs-bulk'] ) ) && ( isset( $_GET['_wpnonce'] ) ) && ( wp_verify_nonce( $_GET['_wpnonce'], 'bulk-logs' ) ) ) {
2308
2309 $bulk_action = '';
2310
2311 if ( ( isset( $_GET['action'] ) ) && ( $_GET['action'] != '-1' ) ) {
2312 $bulk_action = esc_attr( $_GET['action'] );
2313 } else if ( ( isset( $_GET['action2'] ) ) && ( $_GET['action2'] != '-1' ) ) {
2314 $bulk_action = esc_attr( $_GET['action2'] );
2315 }
2316
2317 $_SERVER['REQUEST_URI'] = esc_url_raw( remove_query_arg( array(
2318 '_wp_http_referer',
2319 '_wpnonce',
2320 'action',
2321 'action2',
2322 'mid'
2323 ), $_SERVER['REQUEST_URI'] ) );
2324
2325 if ( ( $bulk_action ) && ( ! empty( $bulk_action ) ) ) {
2326
2327 $chat_href = esc_url_raw( remove_query_arg( array( '_wpnonce', 'maction', 'message' ) ) );
2328 if ( $bulk_action == 'delete' ) {
2329 $this->chat_session_logs_messages( 'log', 'delete', $_GET['chat-logs-bulk'] );
2330 $chat_href = add_query_arg( 'message', 'success-logs-delete', $chat_href );
2331
2332 } else if ( $bulk_action == "hide" ) {
2333 $this->chat_session_logs_messages( 'log', 'hide', $_GET['chat-logs-bulk'] );
2334 $chat_href = add_query_arg( 'message', 'success-logs-hide', $chat_href );
2335
2336 } else if ( $bulk_action == "unhide" ) {
2337 $this->chat_session_logs_messages( 'log', 'unhide', $_GET['chat-logs-bulk'] );
2338 $chat_href = add_query_arg( 'message', 'success-logs-unhide', $chat_href );
2339 }
2340 wp_redirect( $chat_href );
2341
2342 }
2343 } else {
2344 // IF we are here there are no bulk or single actions to take. So we want to make clean URLs so
2345 // remove all the cruft query string args we don't need. Then redirect to load the page.
2346
2347 $screen = get_current_screen();
2348 $screen_per_page_option = str_replace( '-', '_', $screen->id . "_per_page" );
2349 $per_page = 20;
2350
2351 if ( ( isset( $_GET['laction'] ) ) && ( $_GET['laction'] == 'details' ) ) {
2352 $per_page_option = 'chat_page_chat_session_messages_per_page';
2353 } else {
2354 $per_page_option = 'chat_page_chat_session_logs_per_page';
2355 }
2356
2357 if ( ( isset( $_POST['wp_screen_options']['option'] ) )
2358 && ( $_POST['wp_screen_options']['option'] == $screen_per_page_option )
2359 ) {
2360
2361 if ( isset( $_POST['wp_screen_options']['value'] ) ) {
2362 $per_page = intval( $_POST['wp_screen_options']['value'] );
2363 if ( ( ! $per_page ) || ( $per_page < 1 ) ) {
2364 $per_page = 20;
2365 }
2366
2367 update_user_meta( get_current_user_id(), $per_page_option, $per_page );
2368 }
2369 }
2370
2371 if ( ( isset( $_GET['_wp_http_referer'] ) ) || ( isset( $_GET['_wpnonce'] ) ) ) {
2372 $remove_args_array = array(
2373 '_wp_http_referer',
2374 '_wpnonce',
2375 'chat-filter',
2376 'action',
2377 'action2'
2378 );
2379 $args_array = array();
2380 wp_parse_str( $_SERVER['REQUEST_URI'], $args_array );
2381 foreach ( $args_array as $_key => $_val ) {
2382 if ( ( $_key == "paged" ) && ( $_val == 1 ) ) {
2383 $remove_args_array[] = $_key;
2384 }
2385
2386 if ( empty( $_val ) ) {
2387 $remove_args_array[] = $_key;
2388 }
2389 }
2390 wp_redirect( esc_url_raw( remove_query_arg( $remove_args_array, $_SERVER['REQUEST_URI'] ) ) );
2391 die();
2392 }
2393
2394 $per_page = get_user_meta( get_current_user_id(), $per_page_option, true );
2395 if ( empty( $per_page ) ) {
2396 $per_page = 20;
2397 }
2398 add_screen_option( 'per_page', array(
2399 'label' => __( 'per Page', $this->translation_domain ),
2400 'default' => $per_page
2401 ) );
2402
2403 if ( ( isset( $_GET['laction'] ) ) && ( $_GET['laction'] == 'details' ) ) {
2404 require_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_admin_session_messages.php' );
2405 $this->chat_log_list_table = new WPMUDEVChat_Session_Messages_Table();
2406
2407 } else {
2408 require_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_admin_session_logs.php' );
2409 $this->chat_log_list_table = new WPMUDEVChat_Session_Logs_Table();
2410
2411 }
2412 }
2413 }
2414
2415 $this->process_panel_actions();
2416 //$this->load_configs();
2417
2418 include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_form_sections.php' );
2419
2420 // Since we are showing one of our admin panels we init the help system.
2421 include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_admin_panels_help.php' );
2422 wpmudev_chat_panel_help();
2423
2424 // Add our tool tips.
2425 if ( ! class_exists( 'WpmuDev_HelpTooltips' ) ) {
2426 require_once( dirname( __FILE__ ) . '/lib/class_wd_help_tooltips.php' );
2427 }
2428 $this->tips = new WpmuDev_HelpTooltips();
2429 $this->tips->set_icon_url( plugins_url( '/images/information.png', __FILE__ ) );
2430 }
2431
2432 /**
2433 * Processing logic function. Called from on_load_pages above. This function handles the settings form submit filtering and storage of settings.
2434 *
2435 * @global none
2436 *
2437 * @param none
2438 *
2439 * @return none
2440 * @see http://codex.wordpress.org/Adding_Administration_Menus
2441 */
2442 function process_panel_actions() {
2443 global $wp_roles;
2444
2445 if ( isset( $_POST['chat_user_meta'] ) ) {
2446 update_option( 'wpmudev-chat-user-meta', $_POST['chat_user_meta'] );
2447 $this->_chat_options_defaults['user_meta'] = $_POST['chat_user_meta'];
2448 }
2449
2450 if ( isset( $_POST['chat'] ) ) {
2451
2452 if ( ( ! isset( $_POST['wpmudev_chat_settings_save_wpnonce'] ) )
2453 || ( ! wp_verify_nonce( $_POST['wpmudev_chat_settings_save_wpnonce'], 'wpmudev_chat_settings_save' ) )
2454 ) {
2455 return;
2456 }
2457
2458 $chat_settings = $_POST['chat'];
2459
2460 if ( isset( $chat_settings['section'] ) ) {
2461 $chat_section = $chat_settings['section'];
2462 unset( $chat_settings['section'] );
2463
2464 // Split off the Banned section since it goes into its own options key
2465 if ( $chat_section == "global" ) {
2466
2467 if ( isset( $chat_settings['banned'] ) ) {
2468 $banned_section = $chat_settings['banned'];
2469 unset( $chat_settings['banned'] );
2470
2471 // Need to convert the textarea list of words to an array for easier searching
2472 if ( isset( $banned_section['blocked_words'] ) ) {
2473 $banned_section['blocked_words'] = explode( "\n", $banned_section['blocked_words'] );
2474 foreach ( $banned_section['blocked_words'] as $_idx => $_val ) {
2475 $_word = trim( $_val );
2476 if ( ! empty( $_word ) ) {
2477 $banned_section['blocked_words'][ $_idx ] = wp_kses( $_word, '', '' );
2478 } else {
2479 unset( $banned_section['blocked_words'][ $_idx ] );
2480 }
2481 }
2482 update_option( 'wpmudev-chat-banned', $banned_section );
2483 $this->_chat_options['banned'] = $banned_section;
2484 }
2485 }
2486
2487 if ( isset( $chat_settings['blocked_ip_addresses'] ) ) {
2488 $chat_settings['blocked_ip_addresses'] = explode( "\n", $chat_settings['blocked_ip_addresses'] );
2489 foreach ( $chat_settings['blocked_ip_addresses'] as $_idx => $_val ) {
2490 $_word = trim( $_val );
2491 if ( ! empty( $_word ) ) {
2492 $chat_settings['blocked_ip_addresses'][ $_idx ] = wp_kses( $_word, '', '' );
2493 } else {
2494 unset( $chat_settings['blocked_ip_addresses'][ $_idx ] );
2495 }
2496 }
2497 }
2498
2499 if ( isset( $chat_settings['blocked_users'] ) ) {
2500 $chat_settings['blocked_users'] = explode( "\n", $chat_settings['blocked_users'] );
2501 foreach ( $chat_settings['blocked_users'] as $_idx => $_val ) {
2502 $_word = trim( $_val );
2503 if ( ! empty( $_word ) ) {
2504 $chat_settings['blocked_users'][ $_idx ] = wp_kses( $_word, '', '' );
2505 } else {
2506 unset( $chat_settings['blocked_users'][ $_idx ] );
2507 }
2508 }
2509 }
2510
2511 if ( isset( $chat_settings['blocked_admin_urls'] ) ) {
2512 $chat_settings['blocked_admin_urls'] = explode( "\n", $chat_settings['blocked_admin_urls'] );
2513 foreach ( $chat_settings['blocked_admin_urls'] as $_idx => $_val ) {
2514 $_word = trim( $_val );
2515 if ( ! empty( $_word ) ) {
2516 $chat_settings['blocked_admin_urls'][ $_idx ] = wp_kses( $_word, '', '' );
2517 } else {
2518 unset( $chat_settings['blocked_admin_urls'][ $_idx ] );
2519 }
2520 }
2521 }
2522
2523 if ( isset( $chat_settings['blocked_front_urls'] ) ) {
2524 $chat_settings['blocked_front_urls'] = explode( "\n", $chat_settings['blocked_front_urls'] );
2525 foreach ( $chat_settings['blocked_front_urls'] as $_idx => $_val ) {
2526 $_word = trim( $_val );
2527 if ( ! empty( $_word ) ) {
2528 $chat_settings['blocked_front_urls'][ $_idx ] = wp_kses( $_word, '', '' );
2529 } else {
2530 unset( $chat_settings['blocked_front_urls'][ $_idx ] );
2531 }
2532 }
2533 }
2534
2535 } else if ( ( $chat_section == "page" ) || ( $chat_section == "site" ) || ( $chat_section == "widget" ) || ( $chat_section == "dashboard" ) ) {
2536
2537 // Process the rest.
2538 if ( ! isset( $chat_settings['login_options'] ) ) {
2539 $chat_settings['login_options'] = array();
2540 }
2541
2542 if ( ! isset( $chat_settings['moderator_roles'] ) ) {
2543 $chat_settings['moderator_roles'] = array();
2544 }
2545
2546 if ( isset( $chat_settings['blocked_urls'] ) ) {
2547 $chat_settings['blocked_urls'] = explode( "\n", $chat_settings['blocked_urls'] );
2548 foreach ( $chat_settings['blocked_urls'] as $_idx => $_val ) {
2549 $_word = trim( $_val );
2550 if ( ! empty( $_word ) ) {
2551 $chat_settings['blocked_urls'][ $_idx ] = wp_kses( $_word, '', '' );
2552 } else {
2553 unset( $chat_settings['blocked_urls'][ $_idx ] );
2554 }
2555 }
2556 }
2557 }
2558 foreach ( $chat_settings as $_idx => $_val ) {
2559 if ( $_idx == "login_options" ) {
2560 $chat_settings[ $_idx ] = $_val;
2561 } else if ( $_idx == "moderator_roles" ) {
2562 $chat_settings[ $_idx ] = $_val;
2563 } else if ( is_array( $_val ) ) {
2564 $chat_settings[ $_idx ] = $_val;
2565 } else if ( ( $_idx == "noauth_login_message" ) || ( $_idx == "noauth_login_prompt" ) ) {
2566 $args = array(
2567 //formatting
2568 'br' => array(),
2569 'strong' => array(),
2570 'em' => array(),
2571 'b' => array(),
2572 'i' => array(),
2573 );
2574 $chat_settings[ $_idx ] = wp_kses( $_val, $args, '' );
2575 } else {
2576 //$chat_settings[$_idx] = $_val;
2577 $chat_settings[ $_idx ] = wp_kses( $_val, '', '' );
2578 }
2579 }
2580
2581 if ( ( is_multisite() ) && ( is_network_admin() ) ) {
2582 update_site_option( 'wpmudev-chat-' . $chat_section, $chat_settings );
2583 } else {
2584 update_option( 'wpmudev-chat-' . $chat_section, $chat_settings );
2585 }
2586
2587 // As the user is saving the settings we update the nag admin notice with the current version.
2588 if ( ( is_multisite() ) && ( is_network_admin() ) ) {
2589 update_site_option( 'wpmudev-chat-version-nag', $this->_chat_plugin_settings['options_version'] );
2590 } else {
2591 update_option( 'wpmudev-chat-version-nag', $this->_chat_plugin_settings['options_version'] );
2592 }
2593 $this->_admin_notice_messages_key = 'success-settings';
2594
2595 //if (strncasecmp($chat_section, "network-", strlen("network-")) == 0) {
2596 // update_site_option('wpmudev-chat-'. $chat_section, $chat_settings);
2597 //} else {
2598 // update_option('wpmudev-chat-'. $chat_section, $chat_settings);
2599 //}
2600 $this->_chat_options[ $chat_section ] = $chat_settings;
2601
2602 //$chat_href = remove_query_arg(array('_wpnonce', 'maction', 'message'));
2603 //$chat_href = add_query_arg('message', 'success-message-delete', $chat_href);
2604 //wp_redirect($chat_href);
2605
2606 }
2607 }
2608 }
2609
2610 /**
2611 * This function is called when we init the TinyMCE hook from out init process. This function handles the needed logic to interface
2612 * with the WP TinyMCE editor. Specifically, this function is called when the user clicks the chat button on the editor toolbar. This
2613 * functin is the gateway to showing the popup settings window.
2614 *
2615 * @global none
2616 *
2617 * @param none
2618 *
2619 * @return none
2620 */
2621 function tinymce_options() {
2622
2623 global $wp_version;
2624
2625 // Enaueue the WordPress things
2626 wp_enqueue_style( 'farbtastic' );
2627 wp_enqueue_script( 'jquery' );
2628 wp_enqueue_script( 'farbtastic' );
2629
2630 wp_enqueue_script( 'tiny_mce_popup.js', includes_url() . 'js/tinymce/tiny_mce_popup.js', array(), $wp_version );
2631 wp_enqueue_script( 'mctabs.js', includes_url() . 'js/tinymce/utils/mctabs.js', array(), $wp_version );
2632 wp_enqueue_script( 'validate.js', includes_url() . 'js/tinymce/utils/validate.js', array(), $wp_version );
2633
2634 wp_enqueue_script( 'form_utils.js', includes_url() . 'js/tinymce/utils/form_utils.js', array(), $wp_version );
2635 wp_enqueue_script( 'editable_selects.js', includes_url() . 'js/tinymce/utils/editable_selects.js', array(), $wp_version );
2636
2637
2638 // Enqueue the Chat specific things
2639 wp_register_style( 'wpmudev-chat-admin-css', plugins_url( '/css/wpmudev-chat-admin.css', __FILE__ ),
2640 array(), $this->chat_current_version );
2641 $this->_registered_styles['wpmudev-chat-admin-css'] = 'wpmudev-chat-admin-css';
2642
2643 //echo plugins_url('/js/jquery-cookie.js', dirname(__FILE__));
2644 wp_enqueue_script( 'jquery-cookie', plugins_url( '/js/jquery-cookie.js', __FILE__ ), array( 'jquery' ), $this->chat_current_version );
2645 $this->_registered_scripts['jquery-cookie'] = 'jquery-cookie';
2646
2647 wp_enqueue_script( 'wpmudev-chat-admin-js', plugins_url( '/js/wpmudev-chat-admin.js', __FILE__ ), array( 'jquery' ), $this->chat_current_version, true );
2648 $this->_registered_scripts['wpmudev-chat-admin-js'] = 'wpmudev-chat-admin-js';
2649
2650 wp_enqueue_script( 'wpmudev-chat-admin-tinymce-js', plugins_url( '/js/wpmudev-chat-admin-tinymce.js', __FILE__ ),
2651 array( 'jquery', 'jquery-ui-core', 'jquery-ui-tabs', 'farbtastic' ), $this->chat_current_version );
2652 $this->_registered_scripts['wpmudev-chat-admin-tinymce-js'] = 'wpmudev-chat-admin-tinymce-js';
2653
2654 wp_enqueue_script( 'wpmudev-chat-admin-farbtastic-js', plugins_url( '/js/wpmudev-chat-admin-farbtastic.js', __FILE__ ), array(
2655 'jquery',
2656 'farbtastic'
2657 ), $this->chat_current_version, true );
2658 $this->_registered_scripts['wpmudev-chat-admin-farbtastic-js'] = 'wpmudev-chat-admin-farbtastic-js';
2659
2660 // Add our tool tips.
2661 if ( ! class_exists( 'WpmuDev_HelpTooltips' ) ) {
2662 require_once( dirname( __FILE__ ) . '/lib/class_wd_help_tooltips.php' );
2663 }
2664 $this->tips = new WpmuDev_HelpTooltips();
2665 $this->tips->set_icon_url( plugins_url( '/images/information.png', __FILE__ ) );
2666
2667 include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_form_sections.php' );
2668 include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_admin_panels_help.php' );
2669 include_once( dirname( __FILE__ ) . '/lib/wpmudev_chat_admin_tinymce.php' );
2670 }
2671
2672
2673 /**
2674 * Called when the User profile is to be edited. This function adds some fields to the profile form specific to our chat plugin.
2675 *
2676 * @global none
2677 *
2678 * @param $user - This is the object of the user being edited.
2679 *
2680 * @return none
2681 */
2682 function chat_edit_user_profile( $user = '' ) {
2683
2684 $this->load_configs();
2685
2686 if ( ! $user ) {
2687 global $current_user;
2688 $user = $current_user;
2689 }
2690
2691 $user_meta = get_user_meta( $user->ID, 'wpmudev-chat-user', true );
2692 if ( ! $user_meta ) {
2693 $user_meta = array();
2694 }
2695 $user_meta['chat_user_status'] = wpmudev_chat_get_user_status( $user->ID );
2696 $user_meta = wp_parse_args( $user_meta, $this->_chat_options_defaults['user_meta'] );
2697
2698 ?>
2699 <h3><?php _e( 'Chat Settings', $this->translation_domain ); ?></h3>
2700
2701 <table class="form-table">
2702 <tr>
2703 <th>
2704 <label
2705 for="wpmudev_chat_status"><?php _e( 'Set Chat status', $this->translation_domain ); ?></label>
2706 </th>
2707 <td>
2708 <select name="wpmudev_chat_user_settings[chat_user_status]" id="wpmudev_chat_status">
2709 <?php
2710 foreach ( $this->_chat_options['user-statuses'] as $status_key => $status_label ) {
2711 if ( $status_key == 'away' ) {
2712 continue;
2713 }
2714
2715 if ( $status_key == $user_meta['chat_user_status'] ) {
2716 $selected = ' selected="selected" ';
2717 } else {
2718 $selected = '';
2719 }
2720
2721 ?>
2722 <option
2723 value="<?php echo $status_key; ?>" <?php echo $selected; ?>><?php echo $status_label; ?></option><?php
2724 }
2725 ?>
2726 </select>
2727 </td>
2728 </tr>
2729 <tr>
2730 <th>
2731 <label
2732 for="wpmudev_chat_name_display"><?php _e( 'In Chat Sessions show name as', $this->translation_domain ); ?></label>
2733 </th>
2734 <td>
2735 <select name="wpmudev_chat_user_settings[chat_name_display]" id="wpmudev_chat_name_display">
2736 <option
2737 value="display_name" <?php if ( $user_meta['chat_name_display'] == 'display_name' ) {
2738 echo ' selected="selected" ';
2739 } ?>><?php echo __( 'Display Name', $this->translation_domain ) . ": " . $user->display_name; ?></option>
2740 <option value="user_login" <?php if ( $user_meta['chat_name_display'] == 'user_login' ) {
2741 echo ' selected="selected" ';
2742 } ?>><?php echo __( 'User Login', $this->translation_domain ) . ": " . $user->user_login; ?></option>
2743 </select>
2744 </td>
2745 </tr>
2746 <?php
2747 if ( current_user_can( 'list_users' ) ) {
2748 ?>
2749 <tr>
2750 <th>
2751 <label
2752 for="wpmudev_chat_users_listing"><?php _e( 'Show Chat Status column on<br />Users > All Users listing?', $this->translation_domain ); ?></label>
2753 </th>
2754 <td>
2755 <select name="wpmudev_chat_user_settings[chat_users_listing]"
2756 id="wpmudev_chat_users_listing">
2757 <option value="enabled"<?php if ( $user_meta['chat_users_listing'] == 'enabled' ) {
2758 echo ' selected="selected" ';
2759 } ?>><?php
2760 _e( 'Enabled', $this->translation_domain ); ?></option>
2761 <option value="disabled"<?php if ( $user_meta['chat_users_listing'] == 'disabled' ) {
2762 echo ' selected="selected" ';
2763 } ?>><?php
2764 _e( 'Disabled', $this->translation_domain ); ?></option>
2765 </select>
2766 </td>
2767 </tr>
2768 <?php } ?>
2769
2770 <tr>
2771 <th>
2772 <label
2773 for="wpmudev_chat_wp_admin"><?php _e( 'Show Chats within WPAdmin', $this->translation_domain ); ?></label>
2774 </th>
2775 <td>
2776 <select name="wpmudev_chat_user_settings[chat_wp_admin]" id="wpmudev_chat_wp_admin">
2777 <option value="enabled"<?php if ( $user_meta['chat_wp_admin'] == 'enabled' ) {
2778 echo ' selected="selected" ';
2779 } ?>><?php
2780 _e( 'Enabled', $this->translation_domain ); ?></option>
2781 <option value="disabled"<?php if ( $user_meta['chat_wp_admin'] == 'disabled' ) {
2782 echo ' selected="selected" ';
2783 } ?>><?php
2784 _e( 'Disabled', $this->translation_domain ); ?></option>
2785 </select>
2786
2787 <p class="description"><?php _e( 'This will disable all Chat functions including WordPress toolbar menu, Dashboard Widgets, etc.', $this->translation_domain ); ?></p>
2788 </td>
2789 </tr>
2790 <tr class="wpmudev_chat_wp_admin_display" <?php if ( $user_meta['chat_wp_admin'] != 'enabled' ) {
2791 echo ' style="display:none;" ';
2792 } ?>>
2793 <th>
2794 <label
2795 for="wpmudev_chat_wp_toolbar"><?php _e( 'Show Chat WordPress toolbar menu?', $this->translation_domain ); ?></label>
2796 </th>
2797 <td>
2798 <select name="wpmudev_chat_user_settings[chat_wp_toolbar]" id="wpmudev_chat_wp_toolbar">
2799 <option value="enabled"<?php if ( $user_meta['chat_wp_toolbar'] == 'enabled' ) {
2800 echo ' selected="selected" ';
2801 } ?>><?php
2802 _e( 'Enabled', $this->translation_domain ); ?></option>
2803 <option value="disabled"<?php if ( $user_meta['chat_wp_toolbar'] == 'disabled' ) {
2804 echo ' selected="selected" ';
2805 } ?>><?php
2806 _e( 'Disabled', $this->translation_domain ); ?></option>
2807 </select>
2808
2809 <div
2810 id="wpmudev_chat_wp_toolbar_options" <?php if ( $user_meta['chat_wp_toolbar'] == 'disabled' ) {
2811 echo ' style="display:none;" ';
2812 } ?> >
2813 <p>
2814 <select name="wpmudev_chat_user_settings[chat_wp_toolbar_show_status]"
2815 id="wpmudev_chat_wp_toolbar_show_status">
2816 <option
2817 value="enabled"<?php if ( $user_meta['chat_wp_toolbar_show_status'] == 'enabled' ) {
2818 echo ' selected="selected" ';
2819 } ?>><?php _e( 'Enabled', $this->translation_domain ); ?></option>
2820 <option
2821 value="disabled"<?php if ( $user_meta['chat_wp_toolbar_show_status'] == 'disabled' ) {
2822 echo ' selected="selected" ';
2823 } ?>><?php _e( 'Disabled', $this->translation_domain ); ?></option>
2824 </select>
2825 <label
2826 for="wpmudev_chat_wp_toolbar_show_status"><?php _e( 'Show Your Chat Status on WordPress toolbar menu?', $this->translation_domain ); ?></label>
2827 </p>
2828
2829 <p>
2830 <select name="wpmudev_chat_user_settings[chat_wp_toolbar_show_friends]"
2831 id="wpmudev_chat_wp_toolbar_show_friends">
2832 <option
2833 value="enabled"<?php if ( $user_meta['chat_wp_toolbar_show_friends'] == 'enabled' ) {
2834 echo ' selected="selected" ';
2835 } ?>><?php _e( 'Enabled', $this->translation_domain ); ?></option>
2836 <option
2837 value="disabled"<?php if ( $user_meta['chat_wp_toolbar_show_friends'] == 'disabled' ) {
2838 echo ' selected="selected" ';
2839 } ?>><?php _e( 'Disabled', $this->translation_domain ); ?></option>
2840 </select>
2841 <label
2842 for="wpmudev_chat_wp_toolbar_show_friends"><?php _e( 'Show Your Chat Friends on WordPress toolbar menu?', $this->translation_domain ); ?></label>
2843 </p>
2844 </div>
2845
2846 </td>
2847 </tr>
2848
2849
2850 <?php
2851 if ( $this->_chat_options['dashboard']['dashboard_widget'] == 'enabled' ) {
2852
2853 if ( ( ( isset( $user->allcaps['level_10'] ) ) && ( $user->allcaps['level_10'] == 1 ) )
2854 || ( array_intersect( $this->_chat_options['dashboard']['login_options'], $user->roles ) )
2855 ) {
2856 ?>
2857 <tr class="wpmudev_chat_wp_admin_display" <?php if ( $user_meta['chat_wp_admin'] != 'enabled' ) {
2858 echo ' style="display:none;" ';
2859 } ?>>
2860 <th><label for="wpmudev_chat_dashboard_widget"><?php
2861 _e( 'Show Chat Widget on Dashboard', $this->translation_domain ); ?></label></th>
2862 <td>
2863 <?php
2864 if ( is_network_admin() ) {
2865 $item_key = 'chat_network_dashboard_widget';
2866 } else {
2867 $item_key = 'chat_dashboard_widget';
2868 }
2869 ?>
2870 <select name="wpmudev_chat_user_settings[<?php echo $item_key; ?>]"
2871 id="wpmudev_chat_dashboard_widget">
2872 <option value="enabled"<?php if ( $user_meta[ $item_key ] == 'enabled' ) {
2873 echo ' selected="selected" ';
2874 } ?>><?php
2875 _e( 'Enabled', $this->translation_domain ); ?></option>
2876 <option value="disabled"<?php if ( $user_meta[ $item_key ] == 'disabled' ) {
2877 echo ' selected="selected" ';
2878 } ?>><?php
2879 _e( 'Disabled', $this->translation_domain ); ?></option>
2880 </select>
2881
2882 <div
2883 id="wpmudev_chat_dashboard_widget_options" <?php if ( $user_meta[ $item_key ] == 'disabled' ) {
2884 echo ' style="display:none;" ';
2885 } ?>
2886 <?php
2887 if ( is_network_admin() ) {
2888 $item_option_key = 'chat_network_dashboard_widget_height';
2889 } else {
2890 $item_option_key = 'chat_dashboard_widget_height';
2891 }
2892 ?>
2893
2894 <p>
2895 <label
2896 for="wpmudev_chat_dashboard_widget_height"><?php _e( 'Height of Chat Widget', $this->translation_domain ); ?></label><br/><input
2897 name="wpmudev_chat_user_settings[<?php echo $item_option_key; ?>]"
2898 id="wpmudev_chat_dashboard_widget_height"
2899 value="<?php echo $user_meta[ $item_option_key ]; ?>"/> <?php _e( 'Default is', $this->translation_domain ) ?> <?php echo $this->_chat_options['dashboard']['dashboard_widget_height'] ?>
2900 </p>
2901 </div>
2902 </td>
2903 </tr>
2904 <?php
2905 }
2906 }
2907 ?>
2908
2909 <?php
2910 if ( $this->_chat_options['dashboard']['dashboard_status_widget'] == 'enabled' ) {
2911 //if (((isset($user->allcaps['level_10'])) && ($user->allcaps['level_10'] == 1))
2912 // || (array_intersect($this->_chat_options['dashboard']['login_options'], $user->roles))) {
2913
2914 ?>
2915 <tr class="wpmudev_chat_wp_admin_display" <?php if ( $user_meta['chat_wp_admin'] != 'enabled' ) {
2916 echo ' style="display:none;" ';
2917 } ?>>
2918 <th><label for="wpmudev_chat_dashboard_status_widget"><?php
2919 _e( 'Show Chat Status Widget on Dashboard', $this->translation_domain ); ?></label></th>
2920 <td>
2921 <?php
2922 if ( is_network_admin() ) {
2923 $item_key = 'chat_network_dashboard_status_widget';
2924 } else {
2925 $item_key = 'chat_dashboard_status_widget';
2926 }
2927 ?>
2928 <select name="wpmudev_chat_user_settings[<?php echo $item_key; ?>]"
2929 id="wpmudev_chat_dashboard_status_widget">
2930 <option value="enabled"<?php if ( $user_meta[ $item_key ] == 'enabled' ) {
2931 echo ' selected="selected" ';
2932 } ?>><?php
2933 _e( 'Enabled', $this->translation_domain ); ?></option>
2934 <option value="disabled"<?php if ( $user_meta[ $item_key ] == 'disabled' ) {
2935 echo ' selected="selected" ';
2936 } ?>><?php
2937 _e( 'Disabled', $this->translation_domain ); ?></option>
2938 </select>
2939 </td>
2940 </tr>
2941 <?php
2942 //}
2943 }
2944 ?>
2945
2946 <?php
2947 if ( $this->_chat_options['dashboard']['dashboard_friends_widget'] == 'enabled' ) {
2948 global $bp;
2949 if ( ( empty( $bp ) ) && ( ! is_plugin_active( 'friends/friends.php' ) )
2950 && ( ( is_multisite() ) && ( ! is_plugin_active_for_network( 'friends/friends.php' ) ) )
2951 ) {
2952
2953 } else {
2954 //if (((isset($user->allcaps['level_10'])) && ($user->allcaps['level_10'] == 1))
2955 // || (array_intersect($this->_chat_options['dashboard']['login_options'], $user->roles))) {
2956
2957 ?>
2958 <tr class="wpmudev_chat_wp_admin_display" <?php if ( $user_meta['chat_wp_admin'] != 'enabled' ) {
2959 echo ' style="display:none;" ';
2960 } ?>>
2961 <th><label for="wpmudev_chat_dashboard_friends_widget"><?php
2962 _e( 'Show Chat Friends Widget on Dashboard', $this->translation_domain ); ?></label>
2963 </th>
2964 <td>
2965 <?php
2966 if ( is_network_admin() ) {
2967 $item_key = 'chat_network_dashboard_friends_widget';
2968 } else {
2969 $item_key = 'chat_dashboard_friends_widget';
2970 }
2971 ?>
2972 <select name="wpmudev_chat_user_settings[<?php echo $item_key; ?>]"
2973 id="wpmudev_chat_dashboard_friends_widget">
2974 <option value="enabled"<?php if ( $user_meta[ $item_key ] == 'enabled' ) {
2975 echo ' selected="selected" ';
2976 } ?>><?php
2977 _e( 'Enabled', $this->translation_domain ); ?></option>
2978 <option value="disabled"<?php if ( $user_meta[ $item_key ] == 'disabled' ) {
2979 echo ' selected="selected" ';
2980 } ?>><?php
2981 _e( 'Disabled', $this->translation_domain ); ?></option>
2982 </select><br/>
2983
2984 <div
2985 id="wpmudev_chat_dashboard_friends_widget_options" <?php if ( $user_meta[ $item_key ] == 'disabled' ) {
2986 echo ' style="display:none;" ';
2987 } ?>
2988 <?php
2989 if ( is_network_admin() ) {
2990 $item_option_key = 'chat_network_dashboard_friends_widget_height';
2991 } else {
2992 $item_option_key = 'chat_dashboard_friends_widget_height';
2993 }
2994 ?>
2995
2996 <p>
2997 <label
2998 for="wpmudev_chat_dashboard_friends_widget_height"><?php _e( 'Min Height of Chat Friends Widget', $this->translation_domain ); ?></label><br/><input
2999 name="wpmudev_chat_user_settings[<?php echo $item_option_key; ?>]"
3000 id="wpmudev_chat_dashboard_friends_widget_height"
3001 value="<?php echo $user_meta[ $item_option_key ]; ?>"/> <?php _e( 'Default is', $this->translation_domain ) ?> <?php echo $this->_chat_options['dashboard']['dashboard_friends_widget_height'] ?>
3002 </p>
3003 </div>
3004 </td>
3005 </tr>
3006 <?php
3007 }
3008 }
3009 ?>
3010 </table>
3011 <?php
3012 }
3013
3014 /**
3015 * Called when the User profile is saved. This function looks for our specific form fields added in the 'chat_edit_user_profile' function and adds those
3016 * to the user's meta settings.
3017 *
3018 * @global none
3019 *
3020 * @param $user_id - This ID of the user profile we are saving.
3021 *
3022 * @return none
3023 */
3024 function chat_save_user_profile( $user_id = '' ) {
3025 if ( ! $user_id ) {
3026 return;
3027 }
3028 if ( ! isset( $_POST['wpmudev_chat_user_settings'] ) ) {
3029 return;
3030 }
3031
3032 if ( isset( $_POST['wpmudev_chat_user_settings']['chat_user_status'] ) ) {
3033 $chat_user_status = esc_attr( $_POST['wpmudev_chat_user_settings']['chat_user_status'] );
3034 if ( isset( $this->_chat_options['user-statuses'][ $chat_user_status ] ) ) {
3035 wpmudev_chat_update_user_status( $user_id, $chat_user_status );
3036 }
3037 unset( $_POST['wpmudev_chat_user_settings']['chat_user_status'] );
3038 }
3039
3040 $user_meta = get_user_meta( $user_id, 'wpmudev-chat-user', true );
3041 if ( ! $user_meta ) {
3042 $user_meta = array();
3043 }
3044
3045 $user_meta = wp_parse_args( $user_meta, $this->_chat_options_defaults['user_meta'] );
3046 $user_meta = wp_parse_args( $_POST['wpmudev_chat_user_settings'], $user_meta );
3047
3048 update_user_meta( $user_id, 'wpmudev-chat-user', $user_meta );
3049 }
3050
3051
3052 function chat_delete_user( $id, $reassign = null ) {
3053 global $wpdb;
3054
3055 // Check if we are to delete message for deleted WP users.
3056 if ( $this->get_option( 'delete_user_messages', 'global' ) != 'enabled' ) {
3057 return;
3058 }
3059
3060 $deleted_user_auth_hash = md5( $id );
3061
3062 if ( $reassign != null ) {
3063 $reassign_user_auth_hash = md5( $reassign );
3064
3065 $sql_str = $wpdb->prepare( "UPDATE `" . WPMUDEV_Chat::tablename( 'message' ) . "` SET auth_hash=%s WHERE auth_hash = %s;", $reassign_user_auth_hash, $deleted_user_auth_hash );
3066 } else {
3067
3068 $sql_str = $wpdb->prepare( "DELETE FROM `" . WPMUDEV_Chat::tablename( 'message' ) . "` WHERE auth_hash = %s;", $deleted_user_auth_hash );
3069 }
3070 //error_log(__FUNCTION__ .": sql_str: [". $sql_str ."]");
3071
3072 $sql_str = $wpdb->prepare( "DELETE FROM `" . WPMUDEV_Chat::tablename( 'users' ) . "` WHERE auth_hash = %s;", $deleted_user_auth_hash );
3073 $wpdb->query( $sql_str );
3074 }
3075
3076 /**
3077 * Used when the user (admin) wants to add the chat status to all users on the Users > All Users listing table.
3078 *
3079 * @global none
3080 *
3081 * @param $columns - An array of columns used for the table output.
3082 *
3083 * @return $columns - We add our unique columns array and return. This is a filter!
3084 */
3085 function chat_manage_users_columns( $columns ) {
3086
3087 if ( current_user_can( 'list_users' ) ) {
3088
3089 //$wpmudev_chat_user_settings = get_user_meta( get_current_user_id(), 'wpmudev-chat-user', true);
3090 if ( ( isset( $this->user_meta['chat_users_listing'] ) ) && ( $this->user_meta['chat_users_listing'] == "enabled" ) ) {
3091 if ( ! isset( $columns['wpmudev-chat-status'] ) ) {
3092 $columns['wpmudev-chat-status'] = __( 'Chat Status', $this->translation_domain );
3093 }
3094 }
3095 }
3096
3097 return $columns;
3098 }
3099
3100 /**
3101 * Used to display the custom column output for the user's row. This function works in coordination with the 'chat_manage_users_columns' function.
3102 *
3103 * @global none
3104 *
3105 * @param $output - will be blank.
3106 * $column_name - Name (key) of the column we are to output. The key is set in the 'chat_manage_users_columns' function
3107 * $friend_user_id - This is the ID of the user for the given row.
3108 *
3109 * @return $output - Will be a complete output for this cell.
3110 */
3111 function chat_manage_users_custom_column( $output, $column_name, $friend_user_id ) {
3112
3113 if ( ( current_user_can( 'list_users' ) ) && ( $column_name == 'wpmudev-chat-status' ) ) {
3114
3115 if ( $friend_user_id != get_current_user_id() ) { // Make sure we don't check ourselves
3116 $output .= wpmudev_chat_get_chat_status_label( get_current_user_id(), $friend_user_id );
3117 }
3118 }
3119
3120 return $output;
3121 }
3122
3123 /**
3124 * Process short code
3125 *
3126 * @global object $post
3127 * @global array $chat_localized Localized strings and options
3128 * @return string Content
3129 */
3130 function process_chat_shortcode( $atts ) {
3131 global $post, $current_user, $wpdb, $wp_roles;
3132
3133 if ( ( ! isset( $atts['id'] ) ) || ( $atts['id'] == '' ) ) {
3134
3135 if ( ( isset( $post->ID ) ) && ( intval( $post->ID ) )
3136 && ( isset( $post->post_type ) ) && ( ! empty( $post->post_type ) )
3137 ) {
3138 $atts['id'] = $post->post_type . '-' . $post->ID;
3139 } else {
3140 return;
3141 }
3142 }
3143
3144 // Logic stands that if the atts key is not found then we don't add it. But if the key exists but is
3145 // empty we add in out defaults BEFORE processing.
3146 $control_arrays = array( 'login_options', 'moderator_roles' );
3147 foreach ( $control_arrays as $control_item ) {
3148 if ( ( ! isset( $atts[ $control_item ] ) ) || ( empty( $atts[ $control_item ] ) ) ) {
3149 continue;
3150 } else if ( is_string( $atts[ $control_item ] ) ) {
3151 $atts[ $control_item ] = explode( ',', $atts[ $control_item ] );
3152 if ( count( $atts[ $control_item ] ) ) {
3153 foreach ( $atts[ $control_item ] as $_idx => $_val ) {
3154 $atts[ $control_item ][ $_idx ] = trim( $_val );
3155 }
3156 }
3157 }
3158 }
3159
3160 if ( ( isset( $atts['session_type'] ) ) && ( $atts['session_type'] == 'site' ) ) {
3161 $atts = $this->convert_config( 'site', $atts );
3162 $chat_session = wp_parse_args( $atts, $this->_chat_options['site'] );
3163 $chat_session['session_type'] = 'site';
3164
3165 // If the network bottom corner chat is enabled we want to disable the site bottom corner. Too many bottom corner chats.
3166 if ( $this->_chat_plugin_settings['network_active'] == true ) {
3167
3168 if ( $this->get_option( 'bottom_corner', 'network-site' ) == 'enabled' ) {
3169 $chat_session['bottom_corner'] = 'disabled';
3170 }
3171 if ( $this->get_option( 'bottom_corner_wpadmin', 'network-site' ) == 'enabled' ) {
3172 $chat_session['bottom_corner_wpadmin'] = 'disabled';
3173 }
3174 }
3175
3176 } else if ( ( isset( $atts['session_type'] ) ) && ( $atts['session_type'] == 'private' ) ) {
3177 //$atts = $this->convert_config('site', $atts);
3178 $chat_session = wp_parse_args( $atts, $this->_chat_options['site'] );
3179 $chat_session['session_type'] = 'private';
3180
3181 if ( empty( $atts['box_title'] ) ) {
3182 $chat_session['box_title'] = __( 'Private', $this->translation_domain );
3183 }
3184
3185 } else if ( ( isset( $atts['session_type'] ) ) && ( $atts['session_type'] == 'network-site' ) ) {
3186 //$atts = $this->convert_config('network-site', $atts);
3187 $chat_session = wp_parse_args( $atts, $this->_chat_options['network-site'] );
3188 $chat_session['session_type'] = 'network-site';
3189
3190 if ( empty( $atts['box_title'] ) ) {
3191 $chat_session['box_title'] = __( 'Network', $this->translation_domain );
3192 }
3193
3194 } else if ( ( isset( $atts['session_type'] ) ) && ( $atts['session_type'] == 'dashboard' ) ) {
3195 //$atts = $this->convert_config('dasahboard', $atts);
3196 $chat_session = wp_parse_args( $atts, $this->_chat_options['dashboard'] );
3197 $chat_session['session_type'] = 'dashboard';
3198
3199 //if (empty($atts['box_title']))
3200 // $chat_session['box_title'] = __('Group Chat', $this->translation_domain);
3201
3202 } else if ( ( isset( $atts['session_type'] ) ) && ( $atts['session_type'] == 'widget' ) ) {
3203 //$atts = $this->convert_config('widget', $atts);
3204 $chat_session = wp_parse_args( $atts, $this->_chat_options['widget'] );
3205 $chat_session['session_type'] = 'widget';
3206 } else if ( ( isset( $atts['session_type'] ) ) && ( $atts['session_type'] == 'bp-group' ) ) {
3207 $chat_session = wp_parse_args( $atts, $this->_chat_options['page'] );
3208 $chat_session['session_type'] = 'bp-group';
3209 } else {
3210
3211 $chat_session = wp_parse_args( $atts, $this->_chat_options['page'] );
3212 $chat_session['session_type'] = 'page';
3213 }
3214
3215 $chat_session['id'] = $atts['id'];
3216 if ( $chat_session['session_type'] == 'private' ) {
3217 $chat_session['blog_id'] = 0;
3218 } else if ( ( ( is_multisite() ) && ( $chat_session['session_type'] == 'network-site' ) ) || ( is_network_admin() ) ) {
3219 $chat_session['blog_id'] = 0;
3220 } else {
3221 global $blog_id;
3222 //$chat_session['blog_id'] = $wpdb->blogid;
3223 $chat_session['blog_id'] = $blog_id;
3224 }
3225
3226 if ( isset( $chat_session['log_display'] ) && ( $chat_session['log_display'] == "enabled-link-above" || $chat_session['log_display'] == "enabled-link-below" ) ) {
3227 $chat_session['log_display_hide_session'] = "hide";
3228 }
3229
3230 $chat_session['last_row_id'] = "__EMPTY__";
3231 $this->chat_session_update_message_rows_deleted( $chat_session );
3232
3233 // If we have the old 'current_user' array item we convert it to use the 'wp-roles' WP user roles sub-array.
3234 $current_user_idx = array_search( 'current_user', $chat_session['login_options'] );
3235 if ( $current_user_idx !== false ) {
3236 unset( $chat_session['login_options'][ $current_user_idx ] );
3237
3238 if ( count( $wp_roles ) ) {
3239 foreach ( $wp_roles->roles as $role_slug => $role ) {
3240 if ( array_search( $role_slug, $chat_session['login_options'] ) === false ) {
3241 $chat_session['login_options'][] = $role_slug;
3242 }
3243 }
3244 }
3245 }
3246
3247 // double check that we have at least one WP user roles in our login_options
3248 if ( count( $wp_roles ) ) {
3249 if ( ! array_intersect( $chat_session['login_options'], array_keys( $wp_roles->role_names ) ) ) {
3250 foreach ( $wp_roles->roles as $role_slug => $role ) {
3251 if ( isset( $role['capabilities']['level_10'] ) ) {
3252 $chat_session['login_options'][] = $role_slug;
3253 }
3254 }
3255 }
3256 }
3257
3258 if ( $chat_session['session_type'] != "private" ) {
3259 if ( ( count( $wp_roles ) ) && ( count( $chat_session['moderator_roles'] ) ) ) {
3260 foreach ( $wp_roles->roles as $role_slug => $role ) {
3261 if ( ( isset( $role['capabilities']['level_10'] ) ) && ( ! in_array( $role_slug, $chat_session['moderator_roles'] ) ) ) {
3262 $chat_settings['moderator_roles'][] = $role_slug;
3263 }
3264 }
3265 }
3266
3267 // If the chat_auth type is not yet set. check the allowed login_options. If we are not allowing non-WP
3268 // user then abort. No use showing the chat
3269 if ( ! isset( $this->chat_auth['type'] ) ) {
3270 if ( ( ! $this->use_public_auth( $chat_session ) )
3271 && ( ! $this->use_facebook_auth( $chat_session ) )
3272 && ( ! $this->use_twitter_auth( $chat_session ) )
3273 && ( ! $this->use_google_plus_auth( $chat_session ) )
3274 ) {
3275 return false;
3276 }
3277
3278 } else {
3279 //log_chat_message(__FUNCTION__ .": ". __LINE__ .": here");;
3280
3281 // Need to check the user.
3282 // Check for WordPress users
3283 if ( $this->chat_auth['type'] == "wordpress" ) {
3284
3285 // If the chat_auth[type] says 'wordpress' but the user is not actually WP authenticated...
3286 if ( ! is_user_logged_in() ) {
3287 $this->chat_auth = array();
3288 $this->chat_auth['type'] = 'invalid';
3289 } else {
3290 global $bp;
3291 // Are we viewing a BP page?
3292
3293 if ( ( isset( $bp->groups->current_group->id ) ) && ( intval( $bp->groups->current_group->id ) ) ) {
3294 if ( ( ! isset( $bp->groups->current_group->user_has_access ) ) || ( $bp->groups->current_group->user_has_access != 1 ) ) {
3295 //log_chat_message(__FUNCTION__ .": ". __LINE__ .": here");;
3296 return false;
3297 }
3298 } else {
3299 // roles not set! Should not happen. Abort. Danger. Danger
3300 if ( ! isset( $current_user->roles ) ) {
3301 return false;
3302 }
3303
3304 // For Multisite where the current user is NOT superadmin...
3305 if ( ( is_multisite() ) && ( ! is_super_admin() ) ) {
3306 global $blog_id;
3307
3308 // We chat the user's blogs to see if they have acces to the current site.
3309 $user_blogs = get_blogs_of_user( $current_user->ID );
3310
3311 // Check if the current blog_id is part of the user's visibility.
3312 if ( isset( $user_blogs[ $blog_id ] ) ) {
3313
3314 // If it is then check the user's role against allowed roles
3315 if ( ! array_intersect( $chat_session['login_options'], $current_user->roles ) ) {
3316 return false;
3317 }
3318 } else if ( in_array( 'network', $chat_session['login_options'] ) === false ) {
3319 return false;
3320 }
3321 } else {
3322 if ( ! is_super_admin() ) {
3323 // If the current user's role(s) are not found in the login_options abort.
3324 if ( ! array_intersect( $chat_session['login_options'], $current_user->roles ) ) {
3325 return false;
3326 }
3327 }
3328 }
3329 }
3330 }
3331 } else {
3332 // Check for other: Facebook, Twitter, Google+, Public
3333 if ( ! in_array( $this->chat_auth['type'], $chat_session['login_options'] ) ) {
3334 //log_chat_message(__FUNCTION__ .": ". __LINE__ .": here");;
3335 return false;
3336 }
3337 }
3338 }
3339 }
3340 //log_chat_message(__FUNCTION__ .": ". __LINE__ .": here");;
3341
3342 $box_font_style = "";
3343 if ( ! empty( $chat_session['box_font_family'] ) ) {
3344 if ( isset( $this->_chat_options_defaults['fonts_list'][ $chat_session['box_font_family'] ] ) ) {
3345 $box_font_style .= 'font-family: ' . $this->_chat_options_defaults['fonts_list'][ $chat_session['box_font_family'] ] . ';';
3346 }
3347 }
3348 if ( ! empty( $chat_session['box_font_size'] ) ) {
3349 $box_font_style .= 'font-size: ' . wpmudev_chat_check_size_qualifier( $chat_session['box_font_size'] ) . ';';
3350 }
3351 $chat_session['box_font_style'] = $box_font_style;
3352
3353 $row_font_style = "";
3354 if ( ! empty( $chat_session['row_font_family'] ) ) {
3355 if ( isset( $this->_chat_options_defaults['fonts_list'][ $chat_session['row_font_family'] ] ) ) {
3356 $row_font_style .= 'font-family: ' . $this->_chat_options_defaults['fonts_list'][ $chat_session['row_font_family'] ] . ';';
3357 }
3358 }
3359 if ( ! empty( $chat_session['row_font_size'] ) ) {
3360 $row_font_style .= 'font-size: ' . wpmudev_chat_check_size_qualifier( $chat_session['row_font_size'] ) . ';';
3361 }
3362 $chat_session['row_font_style'] = $row_font_style;
3363
3364 $row_message_input_font_style = "";
3365 if ( ! empty( $chat_session['row_message_input_font_family'] ) ) {
3366 if ( isset( $this->_chat_options_defaults['fonts_list'][ $chat_session['row_message_input_font_family'] ] ) ) {
3367 $row_message_input_font_style .= 'font-family: ' . $this->_chat_options_defaults['fonts_list'][ $chat_session['row_message_input_font_family'] ] . ';';
3368 }
3369 }
3370 if ( ! empty( $chat_session['row_message_input_font_size'] ) ) {
3371 $row_message_input_font_style .= 'font-size: ' . wpmudev_chat_check_size_qualifier( $chat_session['row_message_input_font_size'] ) . ';';
3372 }
3373 $chat_session['row_message_input_font_style'] = $row_message_input_font_style;
3374
3375 $users_list_font_style = '';
3376 if ( ! empty( $chat_session['users_list_font_family'] ) ) {
3377 if ( isset( $this->_chat_options_defaults['fonts_list'][ $chat_session['users_list_font_family'] ] ) ) {
3378 $users_list_font_style .= 'font-family: ' . $this->_chat_options_defaults['fonts_list'][ $chat_session['users_list_font_family'] ] . ';';
3379 }
3380 }
3381 if ( ! empty( $chat_session['users_list_font_size'] ) ) {
3382 $users_list_font_style .= 'font-size: ' . wpmudev_chat_check_size_qualifier( $chat_session['users_list_font_size'] ) . ';';
3383 }
3384 $chat_session['users_list_font_style'] = $users_list_font_style;
3385
3386
3387 // Need to check all the input size type fields to make sure there is proper qualifiers (px, pt, em, %)
3388
3389 $chat_session['box_width'] = wpmudev_chat_check_size_qualifier( $chat_session['box_width'] );
3390 $chat_session['box_height'] = wpmudev_chat_check_size_qualifier( $chat_session['box_height'] );
3391 $chat_session['box_border_width'] = wpmudev_chat_check_size_qualifier( $chat_session['box_border_width'] );
3392 //$chat_session['box_padding'] = wpmudev_chat_check_size_qualifier($chat_session['box_padding']);
3393 $chat_session['row_spacing'] = wpmudev_chat_check_size_qualifier( $chat_session['row_spacing'] );
3394 $chat_session['row_border_width'] = wpmudev_chat_check_size_qualifier( $chat_session['row_border_width'] );
3395 $chat_session['row_message_input_height'] = wpmudev_chat_check_size_qualifier( $chat_session['row_message_input_height'] );
3396 $chat_session['row_avatar_width'] = wpmudev_chat_check_size_qualifier( $chat_session['row_avatar_width'], array( 'px' ) );
3397
3398 $chat_session['users_list_width'] = wpmudev_chat_check_size_qualifier( $chat_session['users_list_width'], array(
3399 'px',
3400 '%'
3401 ) );
3402 $chat_session['users_list_avatar_width'] = wpmudev_chat_check_size_qualifier( $chat_session['users_list_avatar_width'], array( 'px' ) );
3403
3404 $chat_session['row_message_input_length'] = intval( $chat_session['row_message_input_length'] );
3405 $chat_session['log_limit'] = intval( $chat_session['log_limit'] );
3406
3407 if ( $chat_session['log_limit'] == 0 ) {
3408 $chat_session['log_limit'] = 100;
3409 }
3410
3411 // Enfore the user list threshold is not too low
3412 $chat_session['users_list_threshold_delete'] = intval( $chat_session['users_list_threshold_delete'] );
3413 if ( $chat_session['users_list_threshold_delete'] < 20 ) {
3414 $chat_session['users_list_threshold_delete'] = 20;
3415 }
3416
3417 if ( $chat_session['users_list_position'] != "none" ) {
3418 if ( ( $chat_session['users_list_position'] == "right" ) || ( $chat_session['users_list_position'] == "left" ) ) {
3419
3420 if ( $chat_session['users_list_position'] == "right" ) {
3421 $chat_session['show_messages_position'] = "left";
3422 } else if ( $chat_session['users_list_position'] == "left" ) {
3423 $chat_session['show_messages_position'] = "right";
3424 }
3425
3426 $user_list_width = intval( $chat_session['users_list_width'] );
3427 $chat_session['show_messages_width'] = 100 - $user_list_width . "%";
3428 $chat_session['users_list_width'] = intval( $chat_session['users_list_width'] ) . "%";
3429 } else if ( ( $chat_session['users_list_position'] == "above" ) || ( $chat_session['users_list_position'] == "below" ) ) {
3430
3431 //if ($chat_session['users_list_position'] == "above") {
3432 // $chat_session['show_messages_position'] = "right";
3433 //} else if ($chat_session['users_list_position'] == "below") {
3434 // $chat_session['show_messages_position'] = "left";
3435 //}
3436 $chat_session['show_messages_position'] = "left"; //for CSS float: positioning
3437
3438 $chat_session['users_list_height'] = $chat_session['users_list_width'];
3439 //$chat_session['users_list_width'] = "100%";
3440 $chat_session['show_messages_width'] = "100%";
3441 }
3442
3443 } else {
3444 $chat_session['users_list_width'] = "0%";
3445 $chat_session['show_messages_position'] = "left";
3446 $chat_session['show_messages_width'] = "100%";
3447 }
3448
3449 $chat_session['ip_address'] = ( isset( $_SERVER['HTTP_X_FORWARD_FOR'] ) ) ? $_SERVER['HTTP_X_FORWARD_FOR'] : $_SERVER['REMOTE_ADDR'];
3450
3451 // Setup the session in the user's meta information which will store into a cookie on JS loading.
3452 if ( ! isset( $this->chat_user[ $chat_session['id'] ] ) ) {
3453 $this->chat_user[ $chat_session['id'] ] = $this->chat_user['__global__'];
3454 if ( $chat_session['session_type'] == 'site' ) {
3455 if ( isset( $chat_session['status_max_min'] ) ) {
3456 $this->chat_user[ $chat_session['id'] ]['status_max_min'] = $chat_session['status_max_min'];
3457 }
3458 } else {
3459 $this->chat_user[ $chat_session['id'] ]['status_max_min'] = 'max';
3460 }
3461 }
3462
3463 if ( wpmudev_chat_is_moderator( $chat_session ) ) {
3464 $chat_session['moderator'] = "yes";
3465 } else {
3466 $chat_session['moderator'] = "no";
3467 }
3468
3469 $chat_session['session_status'] = $this->chat_session_get_meta( $chat_session, 'session_status' );
3470
3471 if ( ( $chat_session['session_type'] == 'page' ) || ( $chat_session['session_type'] == 'bp-group' ) ) {
3472 if ( $chat_session['session_type'] == 'page' ) {
3473 $chat_session['session_title'] = get_the_title();
3474 $chat_session['session_url'] = get_the_permalink();
3475
3476 } else if ( $chat_session['session_type'] == 'bp-group' ) {
3477 global $bp;
3478 $current_group = $bp->groups->current_group;
3479 $chat_session['session_title'] = apply_filters_ref_array( 'bp_get_group_name', array(
3480 $current_group->name,
3481 $current_group
3482 ) );
3483 $chat_session['session_url'] = bp_get_group_permalink( $current_group ) . $this->get_option( 'bp_menu_slug', 'global' );
3484 }
3485 }
3486
3487 if ( ! isset( $this->chat_sessions[ $chat_session['id'] ] ) ) {
3488 $this->chat_sessions[ $chat_session['id'] ] = array();
3489 }
3490
3491 $this->chat_sessions[ $chat_session['id'] ] = $chat_session;
3492
3493 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3494 // End of settings logic. Now to build the boxes.
3495 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3496
3497 $content = '';
3498
3499 if ( ( isset( $_GET['chat-show-logs'] ) ) || ( ( isset( $_GET['chat-log-id'] ) ) && ( intval( $_GET['chat-log-id'] ) ) ) ) {
3500
3501 if ( $chat_session['log_display_hide_session'] == "show" ) {
3502 // For most chats we simple add an empty div on page load. This empty div is populated by the 'init' AJAX call.
3503 // But for private chats we are already doing AJAX. So we build out the full chat box.
3504 if ( ( $chat_session['session_type'] == "private" ) || ( $chat_session['session_type'] == "network-site" ) ) {
3505 $content .= $this->chat_session_build_box( $chat_session );
3506 }
3507
3508 $content = $this->chat_box_container( $chat_session, $content );
3509
3510 if ( ( $chat_session['log_display'] == "enabled-list-above" ) || ( $chat_session['log_display'] == "enabled-link-above" ) ) {
3511 $content = $this->chat_logs_container( $chat_session ) . $content;
3512 }
3513
3514 if ( ( $chat_session['log_display'] == "enabled-list-below" ) || ( $chat_session['log_display'] == "enabled-link-below" ) ) {
3515 $content = $content . $this->chat_logs_container( $chat_session );
3516 }
3517
3518 } else if ( $chat_session['log_display_hide_session'] == "hide" ) {
3519 $content = $this->chat_logs_container( $chat_session );
3520 }
3521 } else {
3522 // For most chats we simple add an empty div on page load. This empty div is populated by the 'init' AJAX call.
3523 // But for private chats we are already doing AJAX. So we build out the full chat box.
3524 if ( ( $chat_session['session_type'] == "private" ) || ( $chat_session['session_type'] == "network-site" ) ) {
3525 $content = $this->chat_session_build_box( $chat_session );
3526 }
3527
3528 $content = $this->chat_box_container( $chat_session, $content );
3529
3530 //echo "chat_session log_display[". $chat_session['log_display'] ."]<br />";
3531 if ( isset( $chat_session['log_display'] ) && ( $chat_session['log_display'] == "enabled-list-above" || $chat_session['log_display'] == "enabled-link-above" ) ) {
3532 $content = $this->chat_logs_container( $chat_session ) . $content;
3533 }
3534
3535 if ( isset( $chat_session['log_display'] ) && ( $chat_session['log_display'] == "enabled-list-below" || $chat_session['log_display'] == "enabled-link-below" ) ) {
3536 $content = $content . $this->chat_logs_container( $chat_session );
3537 }
3538
3539 }
3540
3541 // In some cases when viewing the live chat in wp-admin logs we don't want to update the transient since this
3542 // may effect some settings.
3543 if ( ( ! isset( $chat_session['update_transient'] ) ) || ( $chat_session['update_transient'] == 'enabled' ) ) {
3544 $transient_key = "chat-session-" . $chat_session['id'] . '-' . $chat_session['session_type'];
3545 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
3546 update_option( $transient_key, $chat_session );
3547 } else {
3548 set_transient( $transient_key, $chat_session, 60 * 60 * 24 );
3549 }
3550 }
3551
3552 return $content;
3553 }
3554
3555 function process_chat_archive_shortcode( $atts ) {
3556 $chat_session = wp_parse_args( $atts, $this->_chat_options['page'] );
3557 $chat_session['id'] = $atts['id'];
3558 if ( ( is_multisite() ) && ( $chat_session['session_type'] == 'network-site' ) ) {
3559 $chat_session['blog_id'] = 0;
3560 } else {
3561 global $blog_id;
3562 //$chat_session['blog_id'] = $wpdb->blogid;
3563 $chat_session['blog_id'] = $blog_id;
3564 }
3565
3566 if ( isset( $_GET['set_archive_log_id'] ) ) {
3567 //echo "in set_archive_log_id<br />";
3568 global $wpdb;
3569
3570 $logs = $this->get_archives( $chat_session );
3571 }
3572 }
3573
3574 /**
3575 * Displays the chat logs archive listing below the chat box.
3576 *
3577 * @global none
3578 *
3579 * @param $chat_session - This is out master settings instance.
3580 *
3581 * @return $content - The output of the archives table. Will be echoed at some other point.
3582 */
3583 function chat_logs_container( $chat_session ) {
3584 global $bp;
3585
3586 $content = '';
3587 $return_link = '';
3588
3589 if ( ( $chat_session['session_type'] != "page" ) && ( $chat_session['session_type'] != "bp-group" ) ) {
3590 return $content;
3591 }
3592
3593 if ( $this->using_popup_out_template == true ) {
3594 return $content;
3595 }
3596
3597 if ( ! isset( $chat_session['log_display_role_level'] ) ) {
3598 $chat_session['log_display_role_level'] = "public";
3599 }
3600
3601 // if the log_display_role is NOT public then we need to check the current user' srole to see if they are allowed
3602 if ( ( $chat_session['log_display_role_level'] != 'public' ) && ( ! is_super_admin() ) ) {
3603 global $current_user;
3604
3605 if ( ( isset( $bp->groups->current_group->id ) ) && ( intval( $bp->groups->current_group->id ) ) ) {
3606 if ( $chat_session['log_display_role_level'] == 'group_admins' ) {
3607 if ( ! groups_is_user_admin( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
3608 return $content;
3609 }
3610
3611 } else if ( $chat_session['log_display_role_level'] == 'group_mods' ) {
3612 if ( ! groups_is_user_mod( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
3613 return $content;
3614 }
3615
3616 } else if ( $chat_session['log_display_role_level'] == 'group_members' ) {
3617 if ( ( ! isset( $bp->groups->current_group->user_has_access ) ) || ( $bp->groups->current_group->user_has_access != 1 ) ) {
3618 return $content;
3619 }
3620
3621 } else {
3622 return $content;
3623 }
3624
3625 } else {
3626 $current_user_role_level = wpmudev_chat_get_user_role_highest_level( $current_user->allcaps );
3627 if ( ! $current_user_role_level ) {
3628 $current_user_role_level = 0;
3629 }
3630
3631 $log_user_role_level = intval( str_replace( 'level_', '', $chat_session['log_display_role_level'] ) );
3632 if ( ! $log_user_role_level ) {
3633 $log_user_role_level = 0;
3634 }
3635
3636 // If the current user level is less than our limit return the empty content.
3637 if ( ( $log_user_role_level > $current_user_role_level ) || ( $log_user_role_level == 0 ) ) {
3638 return $content;
3639 }
3640 }
3641 }
3642
3643 $date_content = '';
3644 $chat_session_dates = $this->get_archives( $chat_session );
3645
3646 if ( ( $chat_session_dates ) && ( is_array( $chat_session_dates ) ) ) {
3647 krsort( $chat_session_dates );
3648
3649 foreach ( $chat_session_dates as $chat_session_date ) {
3650
3651 $query_args = array(
3652 'chat-log-id' => $chat_session_date->id,
3653 );
3654 $archive_href = esc_url( add_query_arg( $query_args ) );
3655
3656 $date_str = date_i18n( get_option( 'date_format' ) . ' ' .
3657 get_option( 'time_format' ), strtotime( $chat_session_date->start ) + get_option( 'gmt_offset' ) * 3600, false ) .
3658 ' - ' . date_i18n( get_option( 'date_format' ) . ' ' .
3659 get_option( 'time_format' ), strtotime( $chat_session_date->end ) + get_option( 'gmt_offset' ) * 3600, false );
3660
3661 if ( isset( $_GET['chat-log-id'] ) && $_GET['chat-log-id'] == $chat_session_date->id ) {
3662 $date_content .= '<li>' . $date_str . ' <a href="' . esc_url( remove_query_arg( 'chat-log-id' ) ) . '">' . __( 'close', $this->translation_domain ) . "</a>";
3663
3664 if ( isset( $_GET['chat-log-id'] ) && $_GET['chat-log-id'] == $chat_session_date->id ) {
3665 $chat_session_log = $chat_session;
3666 $chat_session_log['session_type'] = "log";
3667
3668 $chat_session['since'] = strtotime( $chat_session_date->start );
3669 $chat_session['end'] = strtotime( $chat_session_date->end );
3670 $chat_session['log_limit'] = 0;
3671 $chat_session['orderby'] = 'ASC';
3672 $chat_session['archived'] = array( 'yes' );
3673
3674 $chat_log_rows = $this->chat_session_get_messages( $chat_session );
3675
3676 if ( ( $chat_log_rows ) && ( is_array( $chat_log_rows ) ) && ( count( $chat_log_rows ) ) ) {
3677 $chat_rows_content = '';
3678 foreach ( $chat_log_rows as $row ) {
3679 $chat_rows_content .= $this->chat_session_build_row( $row, $chat_session_log );
3680 }
3681 if ( strlen( $chat_rows_content ) ) {
3682 $date_content .= '<div id="wpmudev-chat-box-archive" class="wpmudev-chat-box"><div class="wpmudev-chat-module-messages-list" >' . $chat_rows_content . '</div></div>';
3683 }
3684 }
3685 }
3686 } else {
3687 $date_content .= '<li><a class="chat-log-link" style="text-decoration: none;" href="' . $archive_href . '">' . $date_str . '</a>';
3688 }
3689 $date_content .= '</li>';
3690 }
3691 }
3692 if ( empty( $date_content ) ) {
3693 $date_content = "<p>" . __( 'No Chat logs found for this session', $this->translation_domain ) . '</p>';
3694 } else {
3695 $date_content = "<ul>" . $date_content . "</ul>";
3696 }
3697
3698 if ( ( $chat_session['log_display'] == "enabled-list-above" ) || ( $chat_session['log_display'] == "enabled-list-below" ) ) {
3699
3700 //if (isset($_GET['chat-log-id']))
3701 // $return_link = ' <a href="'. remove_query_arg(array('chat-log-id')) .'">'. __('Return to Chat', $this->translation_domain) .'</a>';
3702 //else
3703 // $return_link = '';
3704
3705 //$content .= '<div id="wpmudev-chat-logs-wrap-'. $chat_session['id'].'" class="wpmudev-chat-logs-wrap"><p><strong>' .
3706 // $chat_session['log_display_label'] . '</strong>'. $return_link .'</p>' . $date_content . '</div>';
3707 $content .= '<div id="wpmudev-chat-logs-wrap-' . $chat_session['id'] . '" class="wpmudev-chat-logs-wrap"><p><strong>' .
3708 $chat_session['log_display_label'] . '</strong></p>' . $date_content . '</div>';
3709
3710 //$content .= $this->chat_session_box_styles($chat_session, 'archive');
3711
3712 } else if ( ( $chat_session['log_display'] == "enabled-link-above" ) || ( $chat_session['log_display'] == "enabled-link-below" ) ) {
3713
3714 if ( isset( $_GET['chat-show-logs'] ) ) {
3715
3716 $return_link = '<a href="' . esc_url( remove_query_arg( array(
3717 'chat-log-id',
3718 'chat-show-logs'
3719 ) ) ) . '">' . __( 'Return to Chat', $this->translation_domain ) . '</a>';
3720
3721 $content .= '<div id="wpmudev-chat-logs-wrap-' . $chat_session['id'] . '" class="wpmudev-chat-logs-wrap"><p>' . $return_link . '</p>' . $date_content . '</div>';
3722 } else {
3723
3724 $chat_link = ' <a href="' . esc_url( add_query_arg( 'chat-show-logs', '' ) ) . '">' . $chat_session['log_display_label'] . '</a>';
3725
3726 $content .= '<div id="wpmudev-chat-logs-wrap-' . $chat_session['id'] . '" class="wpmudev-chat-logs-wrap"><p>' . $chat_link . '</p></div>';
3727 }
3728 }
3729
3730 return $content;
3731 }
3732
3733 /**
3734 * Adds the CSS/Style output specific to the chat_session. Each chat_session can be different. So we need to output the CSS after each chat box with all the
3735 * specifics for colors, fonts, widths, etc.
3736 *
3737 * @global none
3738 *
3739 * @param $chat_session - This is out master settings instance.
3740 *
3741 * @return $content - The output of the styles. Will be echoed at some other point.
3742 */
3743 function chat_session_box_styles( $chat_session, $id_override = '' ) {
3744 $content = '';
3745// echo $chat_session;
3746 if ( empty( $id_override ) ) {
3747 $CSS_prefix = '#wpmudev-chat-box-' . $chat_session['id'];
3748 $content .= '<style type="text/css" id="wpmudev-chat-box-' . $chat_session['id'] . '-css">';
3749
3750 } else {
3751 $CSS_prefix = '#wpmudev-chat-box-' . $id_override;
3752 $content .= '<style type="text/css" id="wpmudev-chat-box-' . $id_override . '-css">';
3753 }
3754
3755 $content .= $CSS_prefix . ' {
3756 height: ' . $chat_session['box_height'] . ';
3757 width: ' . $chat_session['box_width'] . ';
3758 color: ' . $chat_session['box_text_color'] . ';
3759 background-color: ' . $chat_session['box_background_color'] . '; ' . $chat_session['box_font_style'] . ';
3760 border: ' . $chat_session['box_border_width'] . ' solid ' . $chat_session['box_border_color'] . '; } ';
3761
3762 $content .= $CSS_prefix . ' div.wpmudev-chat-module-header {
3763 background-color: ' . $chat_session['box_border_color'] . '; } ';
3764 if ( $chat_session['users_list_position'] != "none" ) {
3765
3766 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list {
3767 background-color: ' . $chat_session['users_list_background_color'] . ';
3768 overflow-y: auto; overflow-x: hidden; } ';
3769 if ( ( $chat_session['users_list_position'] == "left" ) || ( $chat_session['users_list_position'] == "right" ) ) {
3770 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list {
3771 width: ' . $chat_session['users_list_width'] . ';
3772 float: ' . $chat_session['users_list_position'] . '; } ';
3773 } else if ( ( $chat_session['users_list_position'] == "above" ) || ( $chat_session['users_list_position'] == "below" ) ) {
3774 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list {
3775 height: ' . $chat_session['users_list_height'] . '; } ';
3776 }
3777
3778 if ( ! empty( $chat_session['users_list_header'] ) ) {
3779 $users_list_header_font_style = '';
3780 if ( ! empty( $chat_session['users_list_header_font_family'] ) ) {
3781 if ( isset( $this->_chat_options_defaults['fonts_list'][ $chat_session['users_list_header_font_family'] ] ) ) {
3782 $users_list_header_font_style .= 'font-family: ' .
3783 $this->_chat_options_defaults['fonts_list'][ $chat_session['users_list_header_font_family'] ] . ';';
3784 }
3785 }
3786 if ( ! empty( $chat_session['users_list_header_font_size'] ) ) {
3787 $users_list_header_font_style .= 'font-size: ' . wpmudev_chat_check_size_qualifier( $chat_session['users_list_header_font_size'] ) . ';';
3788 }
3789 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list .wpmudev-chat-users-list-header {
3790 color: ' . $chat_session['users_list_header_color'] . ';
3791 ' . $users_list_header_font_style . '; } ';
3792
3793 }
3794 if ( $chat_session['users_list_show'] == "avatar" ) {
3795
3796 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list ul li.wpmudev-chat-user a {
3797 width: ' . $chat_session['users_list_avatar_width'] . ';
3798 height:' . $chat_session['users_list_avatar_width'] . ';
3799 text-decoration: none;
3800 display: block; } ';
3801
3802 if ( ( isset( $chat_session['users_list_avatar_border_width'] ) ) && ( ! empty( $chat_session['users_list_avatar_border_width'] ) ) ) {
3803 $users_list_avatar_width = wpmudev_chat_check_size_qualifier( $chat_session['users_list_avatar_border_width'] );
3804 } else {
3805 $users_list_avatar_width = '0';
3806 }
3807 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list ul li.wpmudev-chat-user a img {
3808 width: ' . $chat_session['users_list_avatar_width'] . ';
3809 height:' . $chat_session['users_list_avatar_width'] . ';
3810 border-width: ' . $users_list_avatar_width . ';
3811 border-style: solid;
3812 } ';
3813
3814 if ( ( isset( $chat_session['users_list_moderator_avatar_border_color'] ) ) && ( ! empty( $chat_session['users_list_moderator_avatar_border_color'] ) ) ) {
3815 $users_list_moderator_avatar_border_color = $chat_session['users_list_moderator_avatar_border_color'];
3816
3817 } else if ( ( isset( $chat_session['users_list_background_color'] ) ) && ( ! empty( $chat_session['users_list_background_color'] ) ) ) {
3818 $users_list_moderator_avatar_border_color = $chat_session['users_list_background_color'];
3819 }
3820 if ( $users_list_moderator_avatar_border_color ) {
3821 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list ul.wpmudev-chat-moderators li.wpmudev-chat-user a img {
3822 border-color: ' . $users_list_moderator_avatar_border_color . '; }';
3823 }
3824
3825
3826 if ( ( isset( $chat_session['users_list_user_avatar_border_color'] ) ) && ( ! empty( $chat_session['users_list_user_avatar_border_color'] ) ) ) {
3827 $users_list_user_avatar_border_color = $chat_session['users_list_user_avatar_border_color'];
3828
3829 } else if ( ( isset( $chat_session['users_list_background_color'] ) ) && ( ! empty( $chat_session['users_list_background_color'] ) ) ) {
3830 $users_list_user_avatar_border_color = $chat_session['users_list_background_color'];
3831 }
3832 if ( $users_list_user_avatar_border_color ) {
3833 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list ul.wpmudev-chat-users li.wpmudev-chat-user a img {
3834 border-color: ' . $users_list_user_avatar_border_color . '; }';
3835 }
3836
3837
3838 } else if ( $chat_session['users_list_show'] == "name" ) {
3839 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list ul.wpmudev-chat-moderators li.wpmudev-chat-user a {
3840 color: ' . $chat_session['users_list_moderator_color'] . ';
3841 text-decoration: none;
3842 ' . $chat_session['users_list_font_style'] . '; } ';
3843 $content .= $CSS_prefix . ' div.wpmudev-chat-module-users-list ul.wpmudev-chat-users li.wpmudev-chat-user a {
3844 color: ' . $chat_session['users_list_name_color'] . ';
3845 text-decoration: none;
3846 ' . $chat_session['users_list_font_style'] . '; } ';
3847 }
3848 }
3849 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list {
3850 width: ' . $chat_session['show_messages_width'] . ';
3851 background-color: ' . $chat_session['row_area_background_color'] . ';
3852 float: ' . $chat_session['show_messages_position'] . '; } ';
3853
3854 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row {
3855 background-color:' . $chat_session['row_background_color'] . ';
3856 border-top:' . $chat_session['row_border_width'] . ' solid ' . $chat_session['row_border_color'] . ';
3857 border-bottom:' . $chat_session['row_border_width'] . ' solid ' . $chat_session['row_border_color'] . ';
3858 border-left: 0; border-right: 0;
3859 margin-bottom: ' . $chat_session['row_spacing'] . '; } ';
3860
3861 if ( ( isset( $this->chat_auth['auth_hash'] ) ) && ( ! empty( $this->chat_auth['auth_hash'] ) ) ) {
3862 $content .= $CSS_prefix . '.wpmudev-chat-box-moderator div.wpmudev-chat-module-messages-list div.wpmudev-chat-row-auth_hash-' . $this->chat_auth['auth_hash'] . ' ul.wpmudev-chat-row-footer li.wpmudev-chat-user-invite, #wpmudev-chat-box-' . $chat_session['id'] . '.wpmudev-chat-box-moderator div.wpmudev-chat-module-messages-list div.wpmudev-chat-row-auth_hash-' . $this->chat_auth['auth_hash'] . ' ul.wpmudev-chat-row-footer li.wpmudev-chat-admin-actions-item-block-ip { display:none; } ';
3863 }
3864
3865 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row a.wpmudev-chat-user-avatar {
3866 display: block; width: ' . $chat_session['row_avatar_width'] . '; height: ' . $chat_session['row_avatar_width'] . '; }';
3867
3868 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row a.wpmudev-chat-user-avatar img {
3869 border: 0; width: ' . $chat_session['row_avatar_width'] . '; height: ' . $chat_session['row_avatar_width'] . '; }';
3870
3871 if ( empty( $chat_session['row_date_color'] ) ) {
3872 $chat_session['row_date_color'] = $chat_session['row_background_color'];
3873 }
3874
3875 if ( $chat_session['row_date'] == "enabled" ) {
3876 if ( ! empty( $chat_session['row_date_text_color'] ) ) {
3877 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row span.date {
3878 color: ' . $chat_session['row_date_text_color'] . '; } ';
3879 }
3880 if ( ! empty( $chat_session['row_date_color'] ) ) {
3881 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row span.date {
3882 background-color:' . $chat_session['row_date_color'] . '; } ';
3883 }
3884 }
3885
3886 if ( $chat_session['row_time'] == "enabled" ) {
3887 if ( ! empty( $chat_session['row_date_text_color'] ) ) {
3888 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row span.time {
3889 color: ' . $chat_session['row_date_text_color'] . '; } ';
3890 }
3891 if ( ! empty( $chat_session['row_date_color'] ) ) {
3892 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row span.time {
3893 background-color:' . $chat_session['row_date_color'] . '; } ';
3894 }
3895 }
3896
3897 if ( ( $chat_session['row_name_avatar'] == "name" ) || ( $chat_session['row_name_avatar'] == "name-avatar" ) ) {
3898 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row a.wpmudev-chat-user-name {
3899 color: ' . $chat_session['row_name_color'] . '; } ';
3900
3901 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row-moderator a.wpmudev-chat-user-name {
3902 color: ' . $chat_session['row_moderator_name_color'] . '; } ';
3903 }
3904
3905 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row code {
3906 background-color:' . $chat_session['row_code_color'] . '; } ';
3907
3908 $content .= $CSS_prefix . ' div.wpmudev-chat-module-messages-list div.wpmudev-chat-row p.wpmudev-chat-message {
3909 color:' . $chat_session['row_text_color'] . ';
3910 ' . $chat_session['row_font_style'] . '; } ';
3911
3912 $content .= $CSS_prefix . ' ul.wpmudev-chat-actions-menu ul.wpmudev-chat-actions-settings-menu {
3913 background-color: ' . $chat_session['box_border_color'] . ';
3914 border: 0px;
3915 }';
3916
3917 if ( ! empty( $chat_session['box_border_color'] ) ) {
3918 $content .= $CSS_prefix . ' ul.wpmudev-chat-actions-menu ul.wpmudev-chat-actions-settings-menu li {
3919 background-color: ' . $chat_session['box_border_color'] . ';
3920 border-left: 1px solid ' . $chat_session['box_text_color'] . ';
3921 border-right: 1px solid ' . $chat_session['box_text_color'] . ';
3922 border-bottom: 1px solid ' . $chat_session['box_text_color'] . ';
3923 }';
3924 }
3925
3926 $content .= $CSS_prefix . ' ul.wpmudev-chat-actions-menu ul.wpmudev-chat-actions-settings-menu a {
3927 color: ' . $chat_session['box_text_color'] . ';
3928 background-color: ' . $chat_session['box_border_color'] . '
3929 }';
3930
3931 $content .= $CSS_prefix . ' ul.wpmudev-chat-actions-menu ul.wpmudev-chat-actions-settings-menu a:hover {
3932 color: ' . $chat_session['box_border_color'] . ';
3933 background-color: ' . $chat_session['box_text_color'] . '
3934 }';
3935
3936 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area textarea.wpmudev-chat-send {
3937 height: ' . $chat_session['row_message_input_height'] . ';
3938 background-color: ' . $chat_session['row_message_input_background_color'] . ';
3939 color: ' . $chat_session['row_message_input_text_color'] . '; ' . $chat_session['row_message_input_font_style'] . ';
3940 resize: ' . $chat_session['row_message_input_lock'] . ';
3941 }';
3942
3943 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area textarea.wpmudev-chat-send::-webkit-input-placeholder {
3944 color: ' . $chat_session['row_message_input_text_color'] . '; }';
3945
3946 // set the placeholder text color to match the actual color for text.
3947 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area textarea.wpmudev-chat-send::-webkit-input-placeholder {
3948 color: ' . $chat_session['row_message_input_text_color'] . '; }';
3949 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area textarea.wpmudev-chat-send:-moz-placeholder {
3950 color: ' . $chat_session['row_message_input_text_color'] . '; }';
3951 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area textarea.wpmudev-chat-send::-moz-placeholder {
3952 color: ' . $chat_session['row_message_input_text_color'] . '; }';
3953 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area textarea.wpmudev-chat-send:-ms-input-placeholder {
3954 color: ' . $chat_session['row_message_input_text_color'] . '; }';
3955
3956
3957 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area ul.wpmudev-chat-send-meta {
3958 background-color: ' . $chat_session['box_border_color'] . '; }';
3959
3960 $content .= $CSS_prefix . ' div.wpmudev-chat-module-message-area ul.wpmudev-chat-send-meta li.wpmudev-chat-send-input-emoticons ul.wpmudev-chat-emoticons-list {
3961 background-color: ' . $chat_session['box_border_color'] . '; }';
3962
3963
3964 $content .= '</style>';
3965
3966 return $content;
3967 }
3968
3969 /**
3970 * Adds the User list module to the chat box. The module is just a div container displayed within the outer chat box div
3971 *
3972 * @global none
3973 *
3974 * @param $chat_session - This is out master settings instance.
3975 *
3976 * @return $content - The output of the styles. Will be echoed at some other point.
3977 */
3978 function chat_session_users_list_module( $chat_session, $echo = false ) {
3979 $content = '';
3980
3981 $content_class = 'wpmudev-chat-module-users-list';
3982 $content_class .= ' wpmudev-chat-users-list-position-' . $chat_session['users_list_position'];
3983 $content_class .= ' wpmudev-chat-users-list-style-' . $chat_session['users_list_style'];
3984 $content_class .= ' wpmudev-chat-users-list-show-' . $chat_session['users_list_show'];
3985
3986 $session_status_style = '';
3987
3988 if ( strlen( $chat_session['users_list_header'] ) ) {
3989 $content .= '<p class="wpmudev-chat-users-list-header">' . $chat_session['users_list_header'] . '</p>';
3990 }
3991 $content = $this->chat_session_module_wrap( $chat_session, $content, $content_class, $session_status_style );
3992
3993 return $content;
3994 }
3995
3996 /**
3997 * Adds the status module to the chat box. The module is just a div container displayed within the outer chat box div
3998 *
3999 * @global none
4000 *
4001 * @param $chat_session - This is out master settings instance.
4002 *
4003 * @return $content - The output of the styles. Will be echoed at some other point.
4004 */
4005 function chat_session_status_module( $chat_session ) {
4006
4007 $content = '';
4008
4009 $content .= '<p class="chat-session-status-closed" style="text-align: center; font-weight:bold;">' . $chat_session['session_status_message'] . '</p>';
4010
4011 $session_status_style = '';
4012 $content = $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-session-status', $session_status_style );
4013
4014 return $content;
4015 }
4016
4017 /**
4018 *
4019 *
4020 * @global none
4021 *
4022 * @param none
4023 *
4024 * @return none
4025 */
4026 function chat_session_generic_message_module( $chat_session ) {
4027 $content = '';
4028
4029 $content .= '<p style="text-align: center; font-weight:bold;"></p>';
4030
4031 $session_status_style = 'display:none;';
4032 $content = $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-session-generic-message', $session_status_style );
4033
4034 return $content;
4035 }
4036
4037 /**
4038 *
4039 *
4040 * @global none
4041 *
4042 * @param none
4043 *
4044 * @return none
4045 */
4046 function chat_session_user_status_message_module( $chat_session ) {
4047 $content = '';
4048
4049 $content .= '<p style="text-align: center; font-weight:bold;"></p>';
4050
4051 $session_status_style = 'display:none;';
4052 $content = $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-session-user-status-message', $session_status_style );
4053
4054 return $content;
4055 }
4056
4057
4058 /**
4059 * Adds the bannedstatus module to the chat box. The module is just a div container displayed within the outer chat box div
4060 *
4061 * @global none
4062 *
4063 * @param $chat_session - This is out master settings instance.
4064 *
4065 * @return $content - The output of the styles. Will be echoed at some other point.
4066 */
4067 function chat_session_banned_status_module( $chat_session ) {
4068
4069 $content = '';
4070
4071 $content .= '<p class="chat-session-status-closed" style="text-align: center; font-weight:bold;">' .
4072 nl2br( $this->get_option( 'blocked_ip_message', 'global' ) ) . '</p>';
4073
4074 $session_status_style = 'display:none;';
4075
4076 $content = $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-banned-status', $session_status_style );
4077
4078 return $content;
4079 }
4080
4081 /*
4082 function chat_session_buttonbar_module($chat_session) {
4083 $content = '';
4084
4085 if ($chat_session['buttonbar'] == 'enabled') {
4086 $content .= '<script type="text/javascript">edToolbar("wpmudev-chat-send-'. $chat_session['id']. '");</script>';
4087 $content = $this->chat_session_module_wrap($chat_session, $content);
4088 }
4089 return $content;
4090 }
4091*/
4092
4093 /**
4094 * Adds the status module to the chat box. The module is just a div container displayed within the outer chat box div
4095 *
4096 * @global none
4097 *
4098 * @param $chat_session - This is out master settings instance.
4099 *
4100 * @return $content - The output of the styles. Will be echoed at some other point.
4101 */
4102 function chat_session_logout_module( $chat_session ) {
4103 $content = '';
4104
4105 $content .= '<input type="button" value="' . __( 'Logout', $this->translation_domain ) . '" name="chat-logout-submit"
4106 class="chat-logout-submit" id="chat-logout-submit-' . $chat_session['id'] . '" />';
4107
4108 $content = $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-logout', 'display:none;' );
4109
4110 return $content;
4111 }
4112
4113 /**
4114 * Adds the message area module to the chat box. The module is just a div container displayed within the outer chat box div. The
4115 * message area module contains the textarea as well as the footer buttons for emoticons, sound on/off and char count for entry limit.
4116 *
4117 * @global none
4118 *
4119 * @param $chat_session - This is out master settings instance.
4120 *
4121 * @return $content - The output of the styles. Will be echoed at some other point.
4122 */
4123 function chat_session_message_area_module( $chat_session ) {
4124 $content = '';
4125 if ( ( $chat_session['session_status'] != "open" ) && ( ! wpmudev_chat_is_moderator( $chat_session ) ) ) {
4126 $display_style = ' style="display:none;" ';
4127 } else {
4128 $display_style = ' style="display:block;" ';
4129 }
4130
4131 if ( intval( $chat_session['row_message_input_length'] ) > 0 ) {
4132 $textarea_max_length = ' maxlength="' . intval( $chat_session['row_message_input_length'] ) . '" ';
4133 } else {
4134 $textarea_max_length = '';
4135 }
4136
4137 $content .= '<textarea id="wpmudev-chat-send-' . $chat_session['id'] . '" class="wpmudev-chat-send" ' . $textarea_max_length . ' rows="5" placeholder="' . __( 'Type your message here', $this->translation_domain ) . '"></textarea>';
4138
4139
4140 if ( ( $chat_session['box_send_button_enable'] == "enabled" )
4141 || ( ( $chat_session['box_send_button_enable'] == "mobile_only" ) && ( $this->chat_localized['settings']['wp_is_mobile'] == true ) )
4142 ) {
4143 $content .= '<button id="wpmudev-chat-send-button-' . $chat_session['id'] . '" class="wpmudev-chat-send-button">' . $chat_session['box_send_button_label'] . '</button>';
4144 }
4145
4146 if ( ( $chat_session['box_emoticons'] == "enabled" ) || ( $chat_session['box_sound'] == "enabled" ) || ( intval( $chat_session['row_message_input_length'] ) > 0 ) ) {
4147
4148 $content .= '<ul class="wpmudev-chat-send-meta">';
4149
4150 if ( intval( $chat_session['row_message_input_length'] ) > 0 ) {
4151 $content .= '<li class="wpmudev-chat-send-input-length"><span class="wpmudev-chat-character-count">0</span>/' .
4152 intval( $chat_session['row_message_input_length'] ) . '</li>';
4153 }
4154
4155 if ( $chat_session['box_sound'] == "enabled" ) {
4156 $content .= '<li class="wpmudev-chat-action-menu-item-sound-on"><a href="#" class="wpmudev-chat-action-sound" title="' .
4157 __( 'Turn chat sound of', $this->translation_domain ) . '"><img height="16" width="16" src="' . plugins_url( '/images/sound-on.png', __FILE__ ) . '" alt="' . __( 'Turn chat sound off', $this->translation_domain ) . '" class="wpmudev-chat-sound-on" title="' . __( 'Turn chat sound off', $this->translation_domain ) . '" /></a></li>';
4158
4159 $content .= '<li class="wpmudev-chat-action-menu-item-sound-off"><a href="#" class="wpmudev-chat-action-sound" title="' .
4160 __( 'Turn chat sound on', $this->translation_domain ) . '"><img height="16" width="16" src="' . plugins_url( '/images/sound-off.png', __FILE__ ) . '" alt="' . __( 'Turn chat sound on', $this->translation_domain ) . '" class="wpmudev-chat-sound-off" title="' . __( 'Turn chat sound on', $this->translation_domain ) . '" /></a></li>';
4161 }
4162
4163
4164 if ( $chat_session['box_emoticons'] == "enabled" ) {
4165 $smilies_list = array(
4166 ':smile:',
4167 ':grin:',
4168 ':sad:',
4169 ':eek:',
4170 ':shock:',
4171 ':???:',
4172 ':cool:',
4173 ':mad:',
4174 ':razz:',
4175 ':neutral:',
4176 ':wink:',
4177 ':lol:',
4178 ':oops:',
4179 ':cry:',
4180 ':evil:',
4181 ':twisted:',
4182 ':roll:',
4183 ':!:',
4184 ':?:',
4185 ':idea:',
4186 ':arrow:'
4187 );
4188
4189 $content .= '<li class="wpmudev-chat-send-input-emoticons">';
4190 $content .= '<a class="wpmudev-chat-emoticons-menu" href="#">' . trim( convert_smilies( $smilies_list[0] ) ) . '</a>';
4191 $content .= '<ul class="wpmudev-chat-emoticons-list">';
4192
4193 foreach ( $smilies_list as $smilie ) {
4194 $content .= '<li>' . convert_smilies( $smilie ) . '</li>';
4195 }
4196 $content .= '</ul>';
4197 $content .= '</li>';
4198 }
4199
4200 $content .= '</ul>';
4201 }
4202
4203 $container_style = '';
4204 $content = $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-message-area', $container_style );
4205
4206 return $content;
4207 }
4208
4209 /**
4210 * Adds the login module to the chat box. The module is just a div container displayed within the outer chat box div.
4211 * The login module is a container for the public login form, as well as Facebook, Twitter and Google+ buttons
4212 *
4213 * @global none
4214 *
4215 * @param $chat_session - This is out master settings instance.
4216 *
4217 * @return $content - The output of the styles. Will be echoed at some other point.
4218 */
4219 function chat_session_login_module( $chat_session ) {
4220 $content = '';
4221
4222 if ( ( $this->use_facebook_auth( $chat_session ) ) || ( $this->use_google_plus_auth( $chat_session ) ) || ( $this->use_twitter_auth( $chat_session ) ) || ( $this->use_public_auth( $chat_session ) ) ) {
4223
4224 $content .= $this->chat_login_public( $chat_session );
4225 $content_auth = '';
4226 $twitter_login_button = $this->chat_login_twitter( $chat_session );
4227 if ( ! empty( $twitter_login_button ) ) {
4228 $content_auth .= '<span class="wpmudev-chat-login-button">' . $twitter_login_button . '</span>';
4229 }
4230 $google_login_button = $this->chat_login_google_plus( $chat_session );
4231 if ( ! empty( $google_login_button ) ) {
4232 $content_auth .= '<span class="wpmudev-chat-login-button">' . $google_login_button . '</span>';
4233 }
4234
4235 $facebook_login_button = $this->chat_login_facebook( $chat_session );
4236 if ( ! empty( $facebook_login_button ) ) {
4237 $content_auth .= '<span class="wpmudev-chat-login-button">' . $facebook_login_button . '</span>';
4238 }
4239
4240 if ( ! empty( $content_auth ) ) {
4241 $content .= '<div class="login-message">' . __( 'Log in using:', $this->translation_domain ) . '</div>';
4242 $content .= '<div class="chat-login-wrap">';
4243 $content .= $content_auth;
4244 $content .= '</div>';
4245 }
4246
4247 $container_style = 'display:none;';
4248
4249 $content = $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-login', $container_style );
4250
4251 }
4252
4253 return $content;
4254 }
4255
4256 /**
4257 * Adds the login prompt module to the chat box. The module is just a div container displayed within the outer chat box div
4258 *
4259 * @global none
4260 *
4261 * @param $chat_session - This is out master settings instance.
4262 *
4263 * @return $content - The output of the styles. Will be echoed at some other point.
4264 */
4265 function chat_session_login_prompt_module( $chat_session ) {
4266 $content = '';
4267
4268 if ( ! empty( $chat_session['noauth_login_prompt'] ) ) {
4269 $content = '<p>' . $chat_session['noauth_login_prompt'] . '</p>';
4270
4271 return $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-login-prompt' );
4272 }
4273 }
4274
4275 /**
4276 * Adds the invite prompt module to the chat box. The module is just a div container displayed within the outer chat box div.
4277 * The invite prompt module is used when one user initiates a private chat with another user. The invited user will see this
4278 * invite prompt asking if they accept the invite.
4279 *
4280 * @global none
4281 *
4282 * @param $chat_session - This is out master settings instance.
4283 *
4284 * @return $content - The output of the styles. Will be echoed at some other point.
4285 */
4286 function chat_session_invite_prompt_module( $chat_session ) {
4287 $content = '';
4288
4289 if ( ( $chat_session['session_type'] == "private" ) && ( ! wpmudev_chat_is_moderator( $chat_session ) ) ) {
4290 if ( isset( $chat_session['invite-info']['message']['host'] ) ) {
4291 if ( ( isset( $chat_session['invite-info']['message']['host']['avatar'] ) ) && ( ! empty( $chat_session['invite-info']['message']['host']['avatar'] ) ) ) {
4292 $avatar = '<img alt="' . $chat_session['invite-info']['message']['host']['name'] . '" height="' . intval( $chat_session['row_avatar_width'] ) . '" src="' . $chat_session['invite-info']['message']['host']['avatar'] . '" class="wpmudev-chat-avatar photo" />';
4293 }
4294
4295 $content .= '<p class="invite-avatar-wrapper">' . $avatar . '</p>';
4296 $content .= '<p class="wpmudev-chat-invite-buttons"><button class="wpmudev-chat-invite-accept" type="button">' . __( 'Accept', $this->translation_domain ) . '</button><button class="wpmudev-chat-invite-declined" type="button">' . __( 'Decline', $this->translation_domain ) . '</button></p>';
4297 $content .= '<p class="invite-chat-message">' . $chat_session['invite-info']['message']['host']['name'] . ' ' . __( 'has invited you to a private chat', $this->translation_domain ) . '</p>';
4298 } else {
4299 $content .= '<p>' . __( 'You have been invited to private chat', $this->translation_domain ) . '</p>';
4300 }
4301
4302 return $this->chat_session_module_wrap( $chat_session, $content, 'wpmudev-chat-module-invite-prompt' );
4303 }
4304 }
4305
4306 /**
4307 * This is the main chat box outer container. From the chat_session settings various 'class' values are determined.
4308 *
4309 * @global none
4310 *
4311 * @param $chat_session - This is out master settings instance.
4312 *
4313 * @return $content - The output of the styles. Will be echoed at some other point.
4314 */
4315 function chat_box_container( $chat_session, $content = '' ) {
4316 $chat_box_style = 'display:none;';
4317 $chat_box_class = "wpmudev-chat-box";
4318
4319 $chat_box_class .= " wpmudev-chat-box-" . $chat_session['session_type'];
4320
4321 if ( wpmudev_chat_is_moderator( $chat_session ) ) {
4322 $chat_box_class .= " wpmudev-chat-box-moderator";
4323 }
4324
4325 if ( ( isset( $chat_session['box_class'] ) ) && ( ! empty( $chat_session['box_class'] ) ) ) {
4326 $chat_box_class .= ' ' . $chat_session['box_class'];
4327 }
4328
4329 if ( $this->get_option( 'blocked_ip_addresses_active', 'global' ) == "enabled" ) {
4330 //$chat_box_class .= " wpmudev-chat-box-ip-address-". str_replace('.', '-', $chat_session['ip_address']);
4331
4332 if ( ( ! isset( $this->_chat_options['global']['blocked_ip_addresses'] ) )
4333 || ( empty( $this->_chat_options['global']['blocked_ip_addresses'] ) )
4334 ) {
4335 $this->_chat_options['global']['blocked_ip_addresses'] = array();
4336 }
4337
4338 if ( ( array_search( $chat_session['ip_address'], $this->_chat_options['global']['blocked_ip_addresses'] ) !== false )
4339 && ( ! wpmudev_chat_is_moderator( $chat_session ) ) && ( $chat_session['session_type'] != "private" )
4340 ) {
4341 $chat_box_class .= " wpmudev-chat-session-ip-blocked";
4342 }
4343 }
4344
4345 if ( ( $chat_session['session_type'] == 'private' )
4346 || ( $chat_session['session_type'] == 'site' )
4347 || ( $chat_session['session_type'] == 'network-site' )
4348 ) {
4349
4350 // For private chat box we also add the 'wpmudev-chat-box-site' for processing and CSS purpose
4351 $chat_box_class .= " wpmudev-chat-box-site wpmudev-chat-box-can-minmax";
4352
4353 if ( wpmudev_chat_is_moderator( $chat_session ) ) {
4354 $chat_box_class .= " wpmudev-chat-box-invite-accepted";
4355 } elseif ( ! empty( $chat_session['invite-info']['message'] ) ) {
4356 $chat_box_class .= " wpmudev-chat-box-invite-" . $chat_session['invite-info']['message']['invite-status'];
4357 }
4358
4359 if ( $this->chat_user[ $chat_session['id'] ]['status_max_min'] == "max" ) {
4360 $chat_box_class .= " wpmudev-chat-box-max";
4361 } else {
4362 $chat_box_class .= " wpmudev-chat-box-min";
4363 }
4364 } else {
4365 $chat_box_class .= " wpmudev-chat-box-max";
4366 }
4367
4368
4369 if ( $chat_session['box_sound'] == "enabled" ) {
4370
4371 if ( $this->chat_user[ $chat_session['id'] ]['sound_on_off'] == "on" ) {
4372 $chat_box_class .= " wpmudev-chat-box-sound-on";
4373 } else {
4374 $chat_box_class .= " wpmudev-chat-box-sound-off";
4375 }
4376 }
4377
4378 if ( $chat_session['session_status'] == "open" ) {
4379 $chat_box_class .= " wpmudev-chat-session-open";
4380 } else {
4381 $chat_box_class .= " wpmudev-chat-session-closed";
4382 }
4383
4384 if ( $chat_session['session_type'] == "log" ) {
4385 $content = '<div id="wpmudev-chat-box-' . $chat_session['id'] . '" style="' . $chat_box_style . '" class="' . $chat_box_class . '">' . $content . '</div>';
4386 } else {
4387 $content = '<div id="wpmudev-chat-box-' . $chat_session['id'] . '" style="' . $chat_box_style . '" class="' . $chat_box_class . '">' . $content . '</div>';
4388 }
4389
4390 return $content;
4391 }
4392
4393 /**
4394 *
4395 *
4396 * @global none
4397 *
4398 * @param none
4399 *
4400 * @return none
4401 */
4402 function chat_site_box_container( $content = '' ) {
4403 global $bp;
4404
4405 // We don't want to add the container on our pop-out template.
4406 if ( $this->using_popup_out_template == true ) {
4407 return;
4408 }
4409
4410 $site_chat_box = '';
4411
4412 if ( ! is_admin() ) {
4413 if ( $this->get_option( 'bottom_corner', 'site' ) == 'enabled' ) {
4414 $_SHOW_SITE_CHAT = true;
4415 } else {
4416 $_SHOW_SITE_CHAT = false;
4417 }
4418
4419 if ( $_SHOW_SITE_CHAT == true ) {
4420
4421 // Are we viewing a BuddyPress Group pages?
4422 if ( ( isset( $bp->groups->current_group->id ) ) && ( intval( $bp->groups->current_group->id ) ) ) {
4423
4424 // Are we viewing the Group Admin screen?
4425 $bp_group_admin_url_path = parse_url( bp_get_group_admin_permalink( $bp->groups->current_group ), PHP_URL_PATH );
4426 $request_url_path = parse_url( get_option( 'siteurl' ) . $_SERVER['REQUEST_URI'], PHP_URL_PATH );
4427
4428 if ( ( ! empty( $request_url_path ) ) && ( ! empty( $bp_group_admin_url_path ) )
4429 && ( substr( $request_url_path, 0, strlen( $bp_group_admin_url_path ) ) == $bp_group_admin_url_path )
4430 ) {
4431 if ( $this->get_option( 'bp_group_admin_show_site', 'global' ) != "enabled" ) {
4432 $_SHOW_SITE_CHAT = false;
4433 }
4434 } else {
4435 if ( $this->get_option( 'bp_group_show_site', 'global' ) != "enabled" ) {
4436 $_SHOW_SITE_CHAT = false;
4437 }
4438 }
4439 } else {
4440 if ( $this->_chat_plugin_settings['blocked_urls']['site'] == true ) {
4441 $_SHOW_SITE_CHAT = false;
4442 } else {
4443 if ( $this->get_option( 'blocked_on_shortcode', 'site' ) == 'enabled' ) {
4444 global $post;
4445 if ( ( ! empty( $post->post_content ) ) && ( strstr( $post->post_content, '[chat ' ) !== false ) ) {
4446 $_SHOW_SITE_CHAT = false;
4447 }
4448 }
4449 }
4450 }
4451 }
4452
4453 } else {
4454 if ( $this->get_option( 'bottom_corner_wpadmin', 'site' ) == 'enabled' ) {
4455 $_SHOW_SITE_CHAT = true;
4456 } else {
4457 $_SHOW_SITE_CHAT = false;
4458 }
4459
4460 if ( $this->_chat_plugin_settings['blocked_urls']['admin'] == true ) {
4461 $_SHOW_SITE_CHAT = false;
4462 }
4463
4464 if ( $this->_chat_plugin_settings['blocked_urls']['site'] == true ) {
4465 $_SHOW_SITE_CHAT = false;
4466 }
4467 }
4468 if ( $_SHOW_SITE_CHAT == true ) {
4469 $atts = array(
4470 'id' => 'bottom_corner',
4471 'session_type' => 'site'
4472 );
4473
4474 $atts = wp_parse_args( $atts, $this->_chat_options['site'] );
4475 $content .= $this->process_chat_shortcode( $atts );
4476 }
4477
4478 return $content;
4479 }
4480
4481 function chat_network_site_box_container( $content = '' ) {
4482 global $bp;
4483
4484 // We don't want to add the container on our pop-out template.
4485 if ( $this->using_popup_out_template == true ) {
4486 return;
4487 }
4488
4489 $site_chat_box = '';
4490
4491 if ( ! is_admin() ) {
4492 if ( $this->get_option( 'bottom_corner', 'network-site' ) == 'enabled' ) {
4493 $_SHOW_SITE_CHAT = true;
4494 } else {
4495 $_SHOW_SITE_CHAT = false;
4496 }
4497
4498 if ( $_SHOW_SITE_CHAT == true ) {
4499
4500 // Are we viewing a BuddyPress Group pages?
4501 if ( ( isset( $bp->groups->current_group->id ) ) && ( intval( $bp->groups->current_group->id ) ) ) {
4502
4503 // Are we viewing the Group Admin screen?
4504 $bp_group_admin_url_path = parse_url( bp_get_group_admin_permalink( $bp->groups->current_group ), PHP_URL_PATH );
4505 $request_url_path = parse_url( get_option( 'siteurl' ) . $_SERVER['REQUEST_URI'], PHP_URL_PATH );
4506
4507 if ( ( ! empty( $request_url_path ) ) && ( ! empty( $bp_group_admin_url_path ) )
4508 && ( substr( $request_url_path, 0, strlen( $bp_group_admin_url_path ) ) == $bp_group_admin_url_path )
4509 ) {
4510 if ( $this->get_option( 'bp_group_admin_show_site', 'global' ) != "enabled" ) {
4511 $_SHOW_SITE_CHAT = false;
4512 }
4513 } else {
4514 if ( $this->get_option( 'bp_group_show_site', 'global' ) != "enabled" ) {
4515 $_SHOW_SITE_CHAT = false;
4516 }
4517 }
4518 } else {
4519 if ( $this->_chat_plugin_settings['blocked_urls']['site'] == true ) {
4520 $_SHOW_SITE_CHAT = false;
4521 } else {
4522 if ( $this->get_option( 'blocked_on_shortcode', 'site' ) == 'enabled' ) {
4523 global $post;
4524 if ( ( ! empty( $post->post_content ) ) && ( strstr( $post->post_content, '[chat ' ) !== false ) ) {
4525 $_SHOW_SITE_CHAT = false;
4526 }
4527 }
4528 }
4529 }
4530 }
4531
4532 } else {
4533 if ( $this->get_option( 'bottom_corner_wpadmin', 'network-site' ) == 'enabled' ) {
4534 $_SHOW_SITE_CHAT = true;
4535 } else {
4536 $_SHOW_SITE_CHAT = false;
4537 }
4538
4539 if ( $this->_chat_plugin_settings['blocked_urls']['admin'] == true ) {
4540 $_SHOW_SITE_CHAT = false;
4541 }
4542
4543 if ( $this->_chat_plugin_settings['blocked_urls']['site'] == true ) {
4544 $_SHOW_SITE_CHAT = false;
4545 }
4546 }
4547
4548 if ( $_SHOW_SITE_CHAT == true ) {
4549 $atts = array(
4550 'id' => 'network-site',
4551 'session_type' => 'network-site'
4552 );
4553
4554 $atts = wp_parse_args( $atts, $this->_chat_options['network-site'] );
4555 $content .= $this->process_chat_shortcode( $atts );
4556 }
4557
4558 return $content;
4559 }
4560
4561 /**
4562 * Adds the header module to the chat box. The module is just a div container displayed within the outer chat box div.
4563 * The header module contains the top bar for the chat which include the title and gear/settings action menu.
4564 *
4565 * @global none
4566 *
4567 * @param $chat_session - This is out master settings instance.
4568 *
4569 * @return $content - The output of the styles. Will be echoed at some other point.
4570 */
4571 function chat_box_header_container( $chat_session ) {
4572 $content = '';
4573
4574 $chat_header_images = '';
4575 if ( ! isset( $this->chat_user[ $chat_session['id'] ] ) ) {
4576 return $content;
4577 }
4578
4579 if ( $this->chat_user[ $chat_session['id'] ]['status_max_min'] == "max" ) {
4580 $chat_style_min = "display:block;";
4581 $chat_style_max = "display:none;";
4582 } else {
4583 $chat_style_min = "display:none;";
4584 $chat_style_max = "display:block;";
4585 }
4586
4587 $chat_action_menu = $this->chat_session_settings_action_menu( $chat_session );
4588
4589 $chat_header_actions = '<div class="wpmudev-chat-module-header-actions"><ul class="wpmudev-chat-actions-menu">';
4590
4591 if ( $chat_session['session_type'] != "bp-group" ) {
4592 $chat_header_images .= '<img class="wpmudev-chat-min" src="' . plugins_url( '/images/16-square-blue-remove.png', __FILE__ ) . '" alt="-" width="16" height="16" style="' . $chat_style_min . '" title="' . __( 'Minimize Chat', $this->translation_domain ) . '" />';
4593 $chat_header_images .= '<img class="wpmudev-chat-max" src="' . plugins_url( '/images/16-square-green-add.png', __FILE__ ) . '" alt="+" width="16" height="16" style="' . $chat_style_max . '" title="' . __( 'Maximize Chat', $this->translation_domain ) . '" />';
4594 $chat_header_actions .= '<li class="wpmudev-chat-action-item wpmudev-chat-min-max"><a href="#">' . $chat_header_images . '</a></li>';
4595 }
4596 if ( $this->chat_user[ $chat_session['id'] ]['status_max_min'] == "max" ) {
4597 $chat_style_settings = '';
4598 } else {
4599 $chat_style_settings = "display:none;";
4600 }
4601
4602 $chat_header_actions .= '<li class="wpmudev-chat-action-item wpmudev-chat-actions-settings" style="' . $chat_style_settings . '"><a href="#" class="wpmudev-chat-actions-settings-button"><img src="' . plugins_url( '/images/gear_icon.png', __FILE__ ) . '" alt="' . __( 'Chat Settings', $this->translation_domain ) . '" width="16" height="16" title="' . __( 'Chat Settings', $this->translation_domain ) . '" /></a>' . $chat_action_menu . '</li>';
4603
4604 //$transient_key = "chat-session-". $chat_session['blog_id'] ."-". $chat_session['id'] .'-'. $chat_session['session_type'];
4605 $transient_key = "chat-session-" . $chat_session['id'] . '-' . $chat_session['session_type'];
4606
4607 if ( $chat_session['box_popout'] == "enabled" ) {
4608 $chat_header_actions .= '<li class="wpmudev-chat-action-item wpmudev-chat-actions-settings-pop-out"><a title="' . __( 'Pop out', $this->translation_domain ) . '" href="' . add_query_arg( array(
4609 'wpmudev-chat-action' => 'pop-out',
4610 'wpmudev-chat-key' => base64_encode( $transient_key )
4611 ), get_option( 'siteurl' ) ) . '" class="wpmudev-chat-action-pop-out">▲</a></li>';
4612 $chat_header_actions .= '<li class="wpmudev-chat-action-item wpmudev-chat-actions-settings-pop-in"><a title="' . __( 'Pop in', $this->translation_domain ) . '" href="' . add_query_arg( array(
4613 'wpmudev-chat-action' => 'pop-in',
4614 'wpmudev-chat-id' => base64_encode( $chat_session['id'] )
4615 ), get_option( 'siteurl' ) ) . '" class="wpmudev-chat-action-pop-out">▼</a></li>';
4616 }
4617
4618 $chat_header_actions .= '</ul></div>';
4619
4620 $chat_title = '';
4621 if ( ( strlen( $chat_session['box_title'] ) ) && ( $chat_session['session_type'] != 'widget' ) ) {
4622
4623 $chat_title = urldecode( $chat_session['box_title'] );
4624
4625 if ( $chat_session['session_type'] == "private" ) {
4626 $chat_title .= ' <span class="wpmudev-chat-private-attendees"></span>';
4627 }
4628 }
4629
4630 if ( $chat_session['session_status'] == "open" ) {
4631 $chat_title_status = __( 'open', $this->translation_domain );
4632 } else {
4633 $chat_title_status = __( 'closed', $this->translation_domain );
4634 }
4635
4636 $content .= '<div class="wpmudev-chat-module-header-title">';
4637 if ( ( $chat_session['session_type'] == 'private' ) || ( $chat_session['session_type'] == 'site' ) || ( $chat_session['session_type'] == 'network-site' ) ) {
4638 if ( $chat_session['session_type'] == 'private' ) {
4639 $content .= '<a title="' . __( 'Private chat', $this->translation_domain ) . '" href="#">';
4640 } else if ( $chat_session['session_type'] == 'site' ) {
4641 $content .= '<a title="' . __( 'Group chat', $this->translation_domain ) . '" href="#">';
4642 } else if ( $chat_session['session_type'] == 'network-site' ) {
4643 $content .= '<a title="' . __( 'Network Group chat', $this->translation_domain ) . '" href="#">';
4644 }
4645
4646 }
4647 $content .= '<span class="wpmudev-chat-title-count"></span>';
4648 $content .= '<span class="wpmudev-chat-title-text">' . $chat_title . '</span>';
4649
4650 if ( ( $chat_session['session_type'] == 'private' ) || ( $chat_session['session_type'] == 'site' ) || ( $chat_session['session_type'] == 'network-site' ) ) {
4651 $content .= '</a>';
4652 }
4653
4654 $content .= '</div>';
4655 $content .= $chat_header_actions;
4656
4657 return $content;
4658 }
4659
4660 /**
4661 * Adds the settings action menu. The module is just a div container displayed within the outer chat box div.
4662 * This function is called from the header module function and is used to build out the settings gear menu.
4663 *
4664 * @global none
4665 *
4666 * @param $chat_session - This is out master settings instance.
4667 *
4668 * @return $content - The output of the styles. Will be echoed at some other point.
4669 */
4670 function chat_session_settings_action_menu( $chat_session ) {
4671 $chat_action_menu = '<ul class="wpmudev-chat-actions-settings-menu">';
4672
4673 if ( ( isset( $this->chat_auth['type'] ) ) && ( ! empty( $this->chat_auth['type'] ) ) ) {
4674 if ( $this->chat_auth['type'] === 'wordpress' ) {
4675 $chat_style_login = "display: none;";
4676 $chat_style_logout = "display: none;";
4677 } else {
4678 $chat_style_login = "display: none;";
4679 $chat_style_logout = "display: block;";
4680 }
4681 } else {
4682 $chat_style_login = "display: block;";
4683 $chat_style_logout = "display: none;";
4684 }
4685
4686 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-login" style="' . $chat_style_login . '"><a href="#" class="wpmudev-chat-action-login">' .
4687 __( 'Login', $this->translation_domain ) . '</a></li>';
4688 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-logout" style="' . $chat_style_logout . '"><a href="#" class="wpmudev-chat-action-logout">' .
4689 __( 'Logout', $this->translation_domain ) . '</a></li>';
4690
4691 if ( $chat_session['session_type'] == "private" ) {
4692 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-exit"><a href="#" class="wpmudev-chat-action-exit">' .
4693 __( 'Leave Chat', $this->translation_domain ) . '</a></li>';
4694 }
4695
4696 if ( $chat_session['box_sound'] == "enabled" ) {
4697 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-sound-on"><a title="' . __( 'Turn chat sound off', $this->translation_domain ) . '"
4698 href="#" class="wpmudev-chat-action-sound">' . __( 'Sound Off', $this->translation_domain ) . '</a></li>';
4699 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-sound-off"><a title="' . __( 'Turn chat sound on', $this->translation_domain ) . '"
4700 href="#" class="wpmudev-chat-action-sound">' . __( 'Sound On', $this->translation_domain ) . '</a></li>';
4701 }
4702
4703 if ( wpmudev_chat_is_moderator( $chat_session ) ) {
4704
4705 $chat_style_session_status_open = '';
4706 $chat_style_session_status_closed = '';
4707
4708 if ( $chat_session['session_type'] != "private" ) {
4709
4710 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-session-status-open" style="' . $chat_style_session_status_open . '"><a href="#" class="wpmudev-chat-action-session-open">' . __( 'Open Chat', $this->translation_domain ) . '</a></li>';
4711 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-session-status-closed" style="' . $chat_style_session_status_closed . '"><a href="#" class="wpmudev-chat-action-session-closed">' . __( 'Close Chat', $this->translation_domain ) . '</a></li>';
4712 }
4713
4714 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-session-clear"><a href="#"
4715 class="wpmudev-chat-action-session-clear">' .
4716 __( 'Clear Chat', $this->translation_domain ) . '</a></li>';
4717
4718 if ( $chat_session['session_type'] != "private" ) {
4719
4720 if ( isset( $chat_session['log_creation'] ) && $chat_session['log_creation'] == 'enabled' ) {
4721 $chat_action_menu .= '<li class="wpmudev-chat-action-menu-item-session-archive"><a href="#" class="wpmudev-chat-action-session-archive">' .
4722 __( 'Archive Chat', $this->translation_domain ) . '</a></li>';
4723 }
4724 }
4725 }
4726 //Disable Auto Scroll
4727 $chat_action_menu .= '<li class="manage-auto-scroll" data-auto_scroll="on"><a href="#">' . __( 'Disable auto scroll', $this->translation_domain ) . '</a></li>';
4728 $chat_action_menu .= '</ul>';
4729
4730 return $chat_action_menu;
4731 }
4732
4733 /**
4734 * Generic utility function call from all module functions. This function builds the actual HTML output for the module.
4735 *
4736 * @global none
4737 *
4738 * @param $chat_session - This is out master settings instance.
4739 *
4740 * @return $content - The output of the styles. Will be echoed at some other point.
4741 */
4742 function chat_session_module_wrap( $chat_session, $content = '', $extra_class = '', $extra_style = '' ) {
4743
4744 $wrapper_class = "wpmudev-chat-module";
4745 if ( ! empty( $extra_class ) ) {
4746 $wrapper_class .= " " . $extra_class;
4747 }
4748 if ( ! empty( $wrapper_class ) ) {
4749 $wrapper_class = ' class="' . $wrapper_class . '"';
4750 }
4751 $wrapper_style = '';
4752 if ( ! empty( $extra_style ) ) {
4753 $wrapper_style .= " " . $extra_style;
4754 }
4755 if ( ! empty( $wrapper_style ) ) {
4756 $wrapper_style = ' style="' . $wrapper_style . '"';
4757 }
4758
4759 $content = '<div' . $wrapper_class . ' ' . $wrapper_style . '>' . $content . '</div>';
4760
4761 return $content;
4762 }
4763
4764 /**
4765 * Given a chat message from the database. This function builds the row output.
4766 *
4767 * @global none
4768 *
4769 * @param $row - The DB object containing all the message information
4770 * $chat_session - This is out master settings instance.
4771 *
4772 * @return $content - The output of the styles. Will be echoed at some other point.
4773 */
4774 function chat_session_build_row( $row, $chat_session ) {
4775
4776 $message = stripslashes( $row->message );
4777
4778 $row_class = "wpmudev-chat-row";
4779 if ( $row->moderator == 'yes' ) {
4780 $row_class .= " wpmudev-chat-row-moderator";
4781 } else {
4782 $row_class .= " wpmudev-chat-row-user";
4783
4784 if ( is_email( $row->avatar ) ) {
4785 $row_class .= " wpmudev-chat-row-user-" . str_replace( array(
4786 '@',
4787 '.'
4788 ), '-', strtolower( $row->avatar ) );
4789 }
4790 }
4791
4792 if ( ( isset( $row->auth_hash ) ) && ( ! empty( $row->auth_hash ) ) ) {
4793 $row_class .= " wpmudev-chat-row-auth_hash-" . $row->auth_hash;
4794
4795 }
4796
4797 $row_class .= " wpmudev-chat-row-ip-" . str_replace( '.', '-', $row->ip_address );
4798 //$row_class .= " wpmudev-chat-row-ip-". base64_encode($row->ip_address);
4799
4800 if ( $this->get_option( 'blocked_ip_addresses_active', 'global' ) == "enabled" ) {
4801 if ( array_search( $row->ip_address, $this->get_option( 'blocked_ip_addresses', 'global' ) ) !== false ) {
4802 $row_class .= " wpmudev-chat-row-ip-blocked";
4803 }
4804 }
4805
4806 $row_text = '';
4807 $row_text .= '<div id="wpmudev-chat-row-' . strtotime( $row->timestamp ) . '-' . $row->id . '" class="' . $row_class . '">';
4808
4809 $row_avatar_name = '';
4810 if ( empty( $row->avatar ) ) {
4811 $row->avatar = "http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96";
4812 }
4813 $row->avatar = esc_url( $row->avatar );
4814 if ( $chat_session['row_name_avatar'] == 'avatar' ) {
4815 if ( ( isset( $row->avatar ) ) && ( ! empty( $row->avatar ) ) ) {
4816 $avatar = '<img alt="' . $row->name . '" src="' . $row->avatar . '" class="wpmudev-chat-user wpmudev-chat-user-avatar" height="' .
4817 intval( $chat_session['row_avatar_width'] ) . '" />';
4818 $row_avatar_name .= '<a class="wpmudev-chat-user wpmudev-chat-user-avatar" title="@' . $row->name . '" href="#">' . $avatar . '</a>';
4819 }
4820
4821 } else if ( $chat_session['row_name_avatar'] == "name" ) {
4822
4823 $row_avatar_name .= '<a class="wpmudev-chat-user wpmudev-chat-user-name" title="@' . $row->name . '" href="#">' . $row->name . '</a>';
4824 } else if ( $chat_session['row_name_avatar'] == "name-avatar" ) {
4825 if ( ( isset( $row->avatar ) ) && ( ! empty( $row->avatar ) ) ) {
4826 $avatar = '<img alt="' . $row->name . '" src="' . $row->avatar . '" class="wpmudev-chat-user wpmudev-chat-user-avatar" height="' .
4827 intval( $chat_session['row_avatar_width'] ) . '" />';
4828 $row_avatar_name .= '<a class="wpmudev-chat-user wpmudev-chat-user-avatar" title="@' . $row->name . '" href="#">' . $avatar . '</a>';
4829 }
4830 $row_avatar_name .= '<a class="wpmudev-chat-user wpmudev-chat-user-name" title="@' . $row->name . '" href="#">' . $row->name . '</a>';
4831 }
4832
4833
4834 $row_date_time = '';
4835 if ( $chat_session['row_date'] == 'enabled' ) {
4836 if ( isset( $chat_session['row_date_format'] ) ) {
4837 $row_date_format = $chat_session['row_date_format'];
4838 } else {
4839 $row_date_format = get_option( 'date_format' );
4840 }
4841
4842 //Convert to timezone
4843 $date = get_date_from_gmt( $row->timestamp, $row_date_format );
4844
4845 //Translate
4846 $date = date_i18n( $row_date_format, strtotime( $date ) );
4847 $row_date_time .= '<span class="date new">' . $date . '</span>';
4848 }
4849
4850 if ( $chat_session['row_time'] == 'enabled' ) {
4851 if ( ! empty( $row_date_time ) ) {
4852 $row_date_time .= " ";
4853 }
4854 if ( isset( $chat_session['row_time_format'] ) ) {
4855 $row_time_format = $chat_session['row_time_format'];
4856 } else {
4857 $row_time_format = get_option( 'time_format' );
4858 }
4859
4860 $row_date_time .= '<span class="time">' . get_date_from_gmt( $row->timestamp, $row_time_format ) . '</span>';
4861 }
4862 if ( ! empty( $row_date_time ) ) {
4863 $row_date_time = "<br />" . $row_date_time;
4864 }
4865
4866 $row_text .= '<p class="wpmudev-chat-message">' . $row_avatar_name . ' ' . convert_smilies( $message ) . $row_date_time . '</p>';
4867
4868
4869// if (($chat_session['row_date'] == 'enabled')
4870// || ($chat_session['row_time'] == 'enabled')
4871// || (wpmudev_chat_is_moderator($chat_session))) {
4872
4873 if ( $chat_session['box_moderator_footer'] == "enabled" ) {
4874
4875 $row_text .= '<ul class="wpmudev-chat-row-footer">';
4876
4877 $this->chat_localized['settings']["row_delete_text"] = __( 'hide', $this->translation_domain );
4878 $this->chat_localized['settings']["row_undelete_text"] = __( 'unhide', $this->translation_domain );
4879
4880 //if (($chat_session['session_type'] != "log") && ($row->moderator != "yes")) {
4881 if ( $chat_session['session_type'] != "log" ) {
4882
4883 $row_text .= '<li class="wpmudev-chat-admin-actions-item wpmudev-chat-user-invite"><a class="wpmudev-chat-user-invite" rel="' . $row->auth_hash . '" title="' . __( 'Invite user to private chat:', $this->translation_domain ) . ' ' . $row->name . '" href="#"><span class="action"><img height="10" src="' . plugins_url( '/images/padlock-icon-th.png', __FILE__ ) . '" alt=""/></span></a></li>';
4884
4885 $row_text .= '<li class="wpmudev-chat-admin-actions-item wpmudev-chat-admin-actions-item-delete"><a class="wpmudev-chat-admin-actions-item-delete" title="' . __( 'moderate this message', $this->translation_domain ) . '" href="#"><span class="action">' . $this->chat_localized['settings']["row_delete_text"] . '</span></a></li>';
4886
4887 if ( ( $this->get_option( 'blocked_ip_addresses_active', 'global' ) == "enabled" )
4888 && ( $chat_session['blocked_ip_addresses_active'] == "enabled" )
4889 ) {
4890
4891 $row_text .= '<li class="wpmudev-chat-admin-actions-item wpmudev-chat-admin-actions-item-block-ip"><a
4892 class="wpmudev-chat-admin-actions-item-block-ip" title="' . __( 'moderate IP address:', $this->translation_domain ) .
4893 $row->ip_address . '" rel="' . $row->ip_address . '" href="#"><span class="action">' . $row->ip_address . '</span></a></li>';
4894 }
4895 /*
4896 $row_text .= '<li class="wpmudev-chat-admin-actions-item wpmudev-chat-admin-actions-item-block-user"><a
4897 class="wpmudev-chat-admin-actions-item-block-user"
4898 title="'. __('moderate user:', $this->translation_domain) . $row->name .'" rel="'. $row->auth_hash .'"
4899 href="#"><span class="action">'. $row->name .'</span></a></li>';
4900*/
4901 //$row_text .= '</ul>'; // End of ul.wpmudev-chat-admin-actions
4902 }
4903
4904 $row_text .= '</ul>'; // End of row footer span
4905 }
4906 $row_text .= '</div>'; // End of Row
4907 return $row_text;
4908 }
4909
4910 /**
4911 *
4912 *
4913 * @global none
4914 *
4915 * @param none
4916 *
4917 * @return none
4918 */
4919 function chat_session_messages_list_module( $chat_session ) {
4920 $content = '';
4921
4922 $content = '<div class="wpmudev-chat-module wpmudev-chat-module-messages-list" >' . $content . '</div>';
4923
4924 return $content;
4925 }
4926
4927 /**
4928 *
4929 *
4930 * @global none
4931 *
4932 * @param none
4933 *
4934 * @return none
4935 */
4936 function use_public_auth( $chat_session ) {
4937 return in_array( 'public_user', $chat_session['login_options'] );
4938 }
4939
4940 /**
4941 *
4942 *
4943 * @global none
4944 *
4945 * @param none
4946 *
4947 * @return none
4948 */
4949 function chat_login_public( $chat_session ) {
4950 $content = '';
4951
4952 if ( $this->use_public_auth( $chat_session ) ) {
4953
4954 $content .= '<div class="login-message">' . $this->get_option( 'noauth_login_message', $chat_session['session_type'] ) . '</div>';
4955
4956 $content .= '<div id="chat-login-wrap-' . $chat_session['id'] . '" class="chat-login-wrap">';
4957 $content .= '<p class="wpmudev-chat-login-error" style="color: #FF0000; display:none;"></p>';
4958 $content .= '<label class="wpmudev-chat-login-label" for="chat-login-name-' . $chat_session['id'] . '">' . __( 'Name', $this->translation_domain ) . '<br /></label><input id="chat-login-name-' . $chat_session['id'] . '" style="width: 90%" name="wpmudev-chat-login-name" class="wpmudev-chat-login-name" type="text" placeholder="' . __( 'Enter Name', $this->translation_domain ) . '"/><br />';
4959 $content .= '<label class="wpmudev-chat-login-label" for="chat-login-email-' . $chat_session['id'] . '">' . __( 'Email', $this->translation_domain ) . '<br /></label><input id="chat-login-email-' . $chat_session['id'] . '" style="width: 90%" name="wpmudev-chat-login-email" class="wpmudev-chat-login-email" type="text" placeholder="' . __( 'Enter Email', $this->translation_domain ) . '"/><br />';
4960
4961 $content .= '<p class="wpmudev-chat-login-buttons"><button class="wpmudev-chat-login-submit" type="button">' . __( 'Login', $this->translation_domain ) . '</button><button class="wpmudev-chat-login-cancel" type="button">' . __( 'Cancel', $this->translation_domain ) . '</button></p>';
4962
4963 $content .= '</div>';
4964 }
4965
4966 return $content;
4967 }
4968
4969 /**
4970 *
4971 *
4972 * @global none
4973 *
4974 * @param none
4975 *
4976 * @return none
4977 */
4978 function is_facebook_setup() {
4979 if ( ( $this->get_option( 'facebook_application_id', 'global' ) != '' ) && ( $this->get_option( 'facebook_application_secret', 'global' ) != '' ) ) {
4980 return true;
4981 }
4982
4983 return false;
4984 }
4985
4986 /**
4987 *
4988 *
4989 * @global none
4990 *
4991 * @param none
4992 *
4993 * @return none
4994 */
4995 function use_facebook_auth( $chat_session ) {
4996 return ( ( in_array( 'facebook', $chat_session['login_options'] ) ) && ( $this->get_option( 'facebook_application_id', 'global' ) != '' ) );
4997 }
4998
4999 /**
5000 *
5001 *
5002 * @global none
5003 *
5004 * @param none
5005 *
5006 * @return none
5007 */
5008 function chat_login_facebook( $chat_session ) {
5009 $content = '';
5010
5011 if ( $this->use_facebook_auth( $chat_session ) ) {
5012 $content .= '<span id="chat-facebook-signin-btn-' . $chat_session['id'] . '"
5013 class="chat-auth-button chat-facebook-signin-btn"><fb:login-button></fb:login-button></span>';
5014 }
5015
5016 return $content;
5017 }
5018
5019 /**
5020 *
5021 *
5022 * @global none
5023 *
5024 * @param none
5025 *
5026 * @return none
5027 */
5028 function is_google_plus_setup() {
5029 if ( $this->get_option( 'google_plus_application_id', 'global' ) != '' ) {
5030 return true;
5031 }
5032
5033 return false;
5034 }
5035
5036 /**
5037 *
5038 *
5039 * @global none
5040 *
5041 * @param none
5042 *
5043 * @return none
5044 */
5045 function use_google_plus_auth( $chat_session ) {
5046 return ( ( in_array( 'google_plus', $chat_session['login_options'] ) ) && ( $this->get_option( 'google_plus_application_id', 'global' ) != '' ) );
5047 }
5048
5049 /**
5050 *
5051 *
5052 * @global none
5053 *
5054 * @param none
5055 *
5056 * @return none
5057 */
5058 function chat_login_google_plus( $chat_session ) {
5059 $content = '';
5060
5061 if ( $this->use_google_plus_auth( $chat_session ) ) {
5062 $content .= '<span class="g-signin" data-callback="WPMUDEVChatGooglePlusSigninCallback" data-clientid="' . $this->get_option( 'google_plus_application_id', 'global' )
5063 . '" data-cookiepolicy="single_host_origin" data-requestvisibleactions="http://schemas.google.com/AddActivity" data-scope="https://www.googleapis.com/auth/plus.login"></span>';
5064 }
5065
5066 return $content;
5067 }
5068
5069
5070 /**
5071 *
5072 *
5073 * @global none
5074 *
5075 * @param none
5076 *
5077 * @return none
5078 */
5079 function is_twitter_setup() {
5080 if ( $this->get_option( 'twitter_api_key', 'global' ) != '' ) {
5081 return true;
5082 }
5083
5084 return false;
5085 }
5086
5087 /**
5088 *
5089 *
5090 * @global none
5091 *
5092 * @param none
5093 *
5094 * @return none
5095 */
5096 function use_twitter_auth( $chat_session ) {
5097 return ( ( in_array( 'twitter', $chat_session['login_options'] ) ) && ( $this->get_option( 'twitter_api_key', 'global' ) != '' ) );
5098 }
5099
5100 /**
5101 *
5102 *
5103 * @global none
5104 *
5105 * @param none
5106 *
5107 * @return none
5108 */
5109 function chat_login_twitter( $chat_session ) {
5110 $content = '';
5111
5112 if ( $this->use_twitter_auth( $chat_session ) ) {
5113 $content .= '<a href="#" id="chat-twitter-signin-btn-' . $chat_session['id'] . '" class="chat-auth-button chat-twitter-signin-btn"></a>';
5114 }
5115
5116 return $content;
5117 }
5118
5119 /**
5120 * @see http://codex.wordpress.org/TinyMCE_Custom_Buttons
5121 */
5122 function tinymce_register_button( $buttons ) {
5123 array_push( $buttons, "separator", "chat" );
5124
5125 return $buttons;
5126 }
5127
5128 /**
5129 * @see http://codex.wordpress.org/TinyMCE_Custom_Buttons
5130 */
5131 function tinymce_load_langs( $langs ) {
5132 $langs["chat"] = plugins_url( '/tinymce/langs/langs.php', __FILE__ );
5133
5134 return $langs;
5135 }
5136
5137 /**
5138 * @see http://codex.wordpress.org/TinyMCE_Custom_Buttons
5139 */
5140 function tinymce_add_plugin( $plugin_array ) {
5141 $plugin_array['chat'] = plugins_url( '/tinymce/editor_plugin.js', __FILE__ );
5142
5143 return $plugin_array;
5144 }
5145
5146 function chat_init() {
5147 $reply_data = array();
5148 $reply_data['sessions'] = array();
5149
5150 foreach ( $this->chat_sessions as $chat_id => $chat_session ) {
5151 $reply_data['sessions'][ $chat_id ] = array();
5152 $reply_data['sessions'][ $chat_id ]['html'] = $this->chat_session_build_box( $chat_session );
5153
5154 // We load the box CSS via the AJAX call. This helps when bots are hitting the page.
5155 $reply_data['sessions'][ $chat_id ]['css'] = $this->chat_session_box_styles( $chat_session );
5156 }
5157
5158 // We only show performance output to admin users.
5159 if ( ( $this->get_option( 'session_performance', 'global' ) == 'enabled' ) && ( current_user_can( 'manage_options' ) ) ) {
5160 $this->chat_performance = wpmudev_chat_end_performance( $this->chat_performance );
5161 $reply_data['performance'] = $this->chat_performance;
5162 }
5163
5164 wp_send_json( $reply_data );
5165 die();
5166 }
5167
5168 function chat_message_send() {
5169 $reply_data = array();
5170 $reply_data['errorStatus'] = false;
5171 $reply_data['errorText'] = '';
5172
5173 if ( ( ! isset( $_POST['chat_messages'] ) ) || ( ! count( $_POST['chat_messages'] ) ) ) {
5174 $reply_data['errorText'] = "chat_messages missing";
5175 $reply_data['errorStatus'] = true;
5176 wp_send_json( $reply_data );
5177 die();
5178 }
5179
5180 // Double check the user's authentication. Seems some users can login with multiple tabs. If they log out of one tab they
5181 // should not be able to post via the other tab.
5182 if ( ! isset( $this->chat_auth['type'] ) ) {
5183 $reply_data['errorText'] = "Unknown user type";
5184 $reply_data['errorStatus'] = true;
5185 wp_send_json( $reply_data );
5186 die();
5187 }
5188
5189 foreach ( $_POST['chat_messages'] as $chat_id => $chat_messages ) {
5190
5191 if ( ! isset( $this->chat_sessions[ $chat_id ] ) ) {
5192 continue;
5193 }
5194 if ( ( ! is_array( $chat_messages ) ) || ( ! count( $chat_messages ) ) ) {
5195 continue;
5196 }
5197
5198 $chat_session = $this->chat_sessions[ $chat_id ];
5199
5200 if ( ! isset( $reply_data['chat_messages'][ $chat_id ] ) ) {
5201 $reply_data['chat_messages'][ $chat_id ] = array();
5202 }
5203
5204 foreach ( $chat_messages as $chat_message_idx => $chat_message ) {
5205 $reply_data['chat_messages'][ $chat_id ][ $chat_message_idx ] = false;
5206
5207 //$chat_message = urldecode($chat_message);
5208 $chat_message = stripslashes( $chat_message );
5209
5210 // Replace the chr(10) Line feed (not the chr(13) carraige return) with a placeholder. Will be replaced with
5211 // real <br /> after filtering This is done so when we convert text within [code][/code] the <br /> are not
5212 // converted to entities. Because we want the code to be formatted
5213 $chat_message = str_replace( chr( 10 ), "[[CR]]", $chat_message );
5214
5215 // In case the user entered HTML <code></code> instead of [code][/code]
5216 $chat_message = str_replace( "<code>", "[code]", $chat_message );
5217 $chat_message = str_replace( "</code>", "[/code]", $chat_message );
5218
5219 // We also can accept backtick quoted text and convert to [code][/code]
5220 $chat_message = preg_replace( '/`(.*?)`/', '[code]$1[/code]', $chat_message );
5221
5222 // Now split out the [code][/code] sections.
5223 //preg_match_all("|\[code\](.*)\[/code\]|s", $chat_message, $code_out);
5224 preg_match_all( "~\[code\](.+?)\[/code\]~si", $chat_message, $code_out );
5225 if ( ( $code_out ) && ( is_array( $code_out ) ) && ( is_array( $code_out[0] ) ) && ( count( $code_out[0] ) ) ) {
5226 foreach ( $code_out[0] as $code_idx => $code_str_original ) {
5227 if ( ! isset( $code_out[1][ $code_idx ] ) ) {
5228 continue;
5229 }
5230
5231 // Here we replace our [code][/code] block or text in the message with placeholder [code-XXX] where XXX
5232 // is the index (0,1,2,3, etc.) Again we do this because in the next step we will strip out all HTML not
5233 // allowed. We want to protect any HTML within the code block
5234 // which will be converted to HTML entities after the filtering.
5235 $chat_message = str_replace( $code_str_original, '[code-' . $code_idx . ']', $chat_message );
5236 }
5237 }
5238
5239 // First strip all the tags!
5240 $allowed_protocols = array();
5241 $allowed_html = array();
5242 $chat_message = wp_kses( $chat_message, $allowed_html, $allowed_protocols );
5243
5244 // Not needed since we remove all HTML from the message. For now.
5245 //$chat_message = balanceTags($chat_message);
5246
5247 // If the user enters something that liiks like a link (http://, ftp://, etc) it will be made clickable
5248 // in that is will be wrapped in an anchor, etc. The the link tarket will be set so clicking it will open
5249 // in a new window
5250 $chat_message = links_add_target( make_clickable( $chat_message ) );
5251
5252 // Now that we can filtered the text outside the [code][/code] we want to convert the code section HTML to entities since it
5253 // will be viewed that way by other users.
5254 if ( ( $code_out ) && ( is_array( $code_out ) ) && ( is_array( $code_out[0] ) ) && ( count( $code_out[0] ) ) ) {
5255 foreach ( $code_out[0] as $code_idx => $code_str_original ) {
5256 if ( ! isset( $code_out[1][ $code_idx ] ) ) {
5257 continue;
5258 }
5259
5260 $code_str_replace = "<code>" . htmlentities2( $code_out[1][ $code_idx ], ENT_QUOTES | ENT_XHTML ) . "</code>";
5261 $chat_message = str_replace( '[code-' . $code_idx . ']', $code_str_replace, $chat_message );
5262 }
5263 }
5264
5265 // Finally convert any of our CR placeholders to HTML breaks.
5266 $chat_message = str_replace( "[[CR]]", '<br />', $chat_message );
5267
5268 // Just as a precaution. After processing we may end up with double breaks. So we convert to single.
5269 $chat_message = str_replace( "<br /><br />", '<br />', $chat_message );
5270
5271
5272 // End message filtering
5273
5274 if ( $chat_message == '' ) {
5275 continue;
5276 }
5277
5278 // Truncate the message IF the max length is set
5279 if ( ! wpmudev_chat_is_moderator( $chat_session ) ) {
5280 if ( ( $chat_session['row_message_input_length'] > 0 ) && ( strlen( $chat_message ) > $chat_session['row_message_input_length'] ) ) {
5281 $chat_message = substr( $chat_message, 0, $chat_session['row_message_input_length'] );
5282 }
5283 }
5284
5285 // Process bad words, if enabled
5286 if ( $chat_session['blocked_words_active'] == "enabled" ) {
5287 $chat_message = str_ireplace( $this->_chat_options['banned']['blocked_words'],
5288 $this->_chat_options['banned']['blocked_words_replace'], $chat_message );
5289 }
5290
5291 $ret = $this->chat_session_send_message( $chat_message, $chat_session );
5292 if ( ! empty( $ret ) ) {
5293 $reply_data['chat_messages'][ $chat_id ][ $chat_message_idx ] = true;
5294 }
5295
5296 if ( ( $chat_session['session_type'] == 'private' ) && ( $this->_chat_options['site']['private_reopen_after_exit'] == 'enabled' ) ) {
5297 $this->wpmudev_chat_set_private_archive_status( $chat_session );
5298 }
5299
5300 }
5301 }
5302 wp_send_json( $reply_data );
5303 die();
5304 }
5305
5306 function chat_user_login() {
5307 $reply_data = array();
5308 $reply_data['errorStatus'] = false;
5309 $reply_data['errorText'] = '';
5310
5311 if ( ! isset( $_POST['user_info'] ) ) {
5312
5313 $reply_data['errorStatus'] = true;
5314 $reply_data['errorText'] = __( 'missing POST user_info', $this->translation_domain );
5315
5316 wp_send_json( $reply_data );
5317 die();
5318 }
5319 $user_info = $_POST['user_info'];
5320
5321 switch ( $user_info['type'] ) {
5322 case 'public_user':
5323 if ( ( ! isset( $user_info['name'] ) ) || ( ! isset( $user_info['email'] ) ) ) {
5324
5325 $reply_data['errorText'] = __( 'Please provide valid Name and Email.', $this->translation_domain );
5326 $reply_data['errorStatus'] = true;
5327
5328 wp_send_json( $reply_data );
5329 die();
5330 }
5331 $user_info['name'] = esc_attr( $user_info['name'] );
5332 $user_info['email'] = esc_attr( $user_info['email'] );
5333 if ( ( empty( $user_info['name'] ) ) || ( empty( $user_info['email'] ) ) || ( ! is_email( $user_info['email'] ) ) ) {
5334
5335 $reply_data['errorText'] = __( 'Please provide valid Name and Email.', $this->translation_domain );
5336 $reply_data['errorStatus'] = true;
5337
5338 wp_send_json( $reply_data );
5339 die();
5340 }
5341
5342 $user_name_id = username_exists( $user_info['name'] );
5343 if ( $user_name_id ) {
5344
5345 $reply_data['errorText'] = __( 'Name already registered. Try something unique', $this->translation_domain );
5346 $reply_data['errorStatus'] = true;
5347
5348 wp_send_json( $reply_data );
5349 die();
5350 }
5351 $user_name_id = email_exists( $user_info['email'] );
5352 if ( $user_name_id ) {
5353
5354 $reply_data['errorText'] = __( 'Email already registered. Try something unique', $this->translation_domain );
5355 $reply_data['errorStatus'] = true;
5356
5357 wp_send_json( $reply_data );
5358 die();
5359 }
5360 $avatar = get_avatar( $user_info['email'], 96, get_option( 'avatar_default' ), $user_info['name'] );
5361 if ( $avatar ) {
5362 $avatar_parts = array();
5363 if ( stristr( $avatar, ' src="' ) !== false ) {
5364 preg_match( '/src="([^"]*)"/i', $avatar, $avatar_parts );
5365 } else if ( stristr( $avatar, " src='" ) !== false ) {
5366 preg_match( "/src='([^']*)'/i", $avatar, $avatar_parts );
5367 }
5368 if ( ( isset( $avatar_parts[1] ) ) && ( ! empty( $avatar_parts[1] ) ) ) {
5369 $user_info['avatar'] = $avatar_parts[1];
5370 }
5371 }
5372
5373 $user_info['ip_address'] = ( isset( $_SERVER['HTTP_X_FORWARD_FOR'] ) ) ? $_SERVER['HTTP_X_FORWARD_FOR'] : $_SERVER['REMOTE_ADDR'];
5374 $user_info['auth_hash'] = md5( $user_info['name'] . $user_info['email'] . $user_info['ip_address'] );
5375 $reply_data['user_info'] = $user_info;
5376 break;
5377
5378 case 'facebook':
5379 case 'google_plus':
5380 case 'twitter':
5381 $user_info['ip_address'] = ( isset( $_SERVER['HTTP_X_FORWARD_FOR'] ) ) ? $_SERVER['HTTP_X_FORWARD_FOR'] : $_SERVER['REMOTE_ADDR'];
5382 $user_info['auth_hash'] = md5( $user_info['id'] . $user_info['ip_address'] );
5383 $reply_data['user_info'] = $user_info;
5384 break;
5385
5386 default:
5387 break;
5388 }
5389 wp_send_json( $reply_data );
5390 die();
5391 }
5392
5393 /**
5394 * Check db for new messages and update all the chat sessions
5395 */
5396 function chat_message_update() {
5397 $reply_data = array();
5398
5399 $reply_data['errorStatus'] = false;
5400 $reply_data['errorText'] = '';
5401
5402 $reply_data['sessions'] = array();
5403 $reply_data['invites'] = array();
5404
5405 if ( isset( $_POST['timers'] ) ) {
5406 $timers = $_POST['timers'];
5407 } else {
5408 $timers = array();
5409 }
5410 // We first want to grab the invites for the users. This will setup the extra items in the $this->chat_sessions reference. Then later
5411 // in this section we will also add the rows and meta updates for the new invite box.
5412 if ( ( $this->using_popup_out_template == false )
5413 && ( isset( $timers['invites'] ) )
5414 && ( $timers['invites'] == 1 )
5415 /* && ($this->user_meta['chat_user_status'] == 'available') */
5416 ) {
5417
5418 $invites = $this->chat_session_get_invites_new();
5419 if ( ( is_array( $invites ) ) && ( ! empty( $invites ) ) ) {
5420 $reply_data['invites'] = $invites;
5421 }
5422 }
5423
5424 $this->chat_auth['ip_address'] = ( isset( $_SERVER['HTTP_X_FORWARD_FOR'] ) ) ? $_SERVER['HTTP_X_FORWARD_FOR'] : $_SERVER['REMOTE_ADDR'];
5425
5426 foreach ( $this->chat_sessions as $chat_id => $chat_session ) {
5427
5428 // Now process the meta information. Session Status, Deleted Row IDs and Session Users
5429 $reply_data['sessions'][ $chat_id ]['meta'] = array();
5430
5431 if ( ! isset( $this->chat_sessions_meta[ $chat_id ] ) ) {
5432 $this->chat_sessions_meta[ $chat_id ] = $this->chat_session_get_meta( $chat_session );
5433 }
5434
5435 if ( ( ( isset( $timers['messages'] ) ) && ( $timers['messages'] == 1 ) ) || ( $chat_session['session_type'] == 'private' ) ) {
5436
5437 if ( ! isset( $chat_session['last_row_id'] ) ) {
5438 $chat_session['last_row_id'] = "__EMPTY__";
5439 }
5440 $users_active = $this->chat_session_get_active_users( $chat_session );
5441
5442 $reply_data['sessions'][ $chat_id ]['rows'] = array();
5443
5444 //For private chats, check user invitation status before getting new messages
5445 if ( $chat_session['session_type'] == 'private' ) {
5446 //if not moderator, check for invite status, other wise set it as accepted
5447 if ( $chat_session['invite-info']['message']['host']['auth_hash'] !== $this->chat_auth['auth_hash'] ) {
5448 $invitation_status = $chat_session['invite-info']['message']['invite-status'];
5449 } else {
5450 //Check if other user has exited the chat
5451 if ( ! empty( $users_active['users'] ) ) {
5452
5453 foreach ( $users_active['users'] as $user ) {
5454 if ( $user['connect_status'] == 'exited' ) {
5455 $reply_data['sessions'][ $chat_id ]['errorStatus'] = true;
5456 $reply_data['sessions'][ $chat_id ]['errorText'] = __( 'User has declined the private chat invitation.', $this->translation_domain );
5457 $reply_data['sessions'][ $chat_id ]['errorText'] = apply_filters( 'wc_chat_decline_message', $reply_data['sessions'][ $chat_id ]['errorText'] );
5458 }
5459 break;
5460 }
5461 }
5462 $invitation_status = 'accepted';
5463 }
5464 //makes sure, the invitee has accepted invitation before showing it
5465 if ( $invitation_status == 'accepted' ) {
5466
5467 $new_rows = $this->chat_session_get_message_new( $chat_session );
5468 } else {
5469 $new_rows = '';
5470 }
5471 if ( $invitation_status == 'exited' ) {
5472 unset( $reply_data['sessions'][ $chat_id ] );
5473 continue;
5474 }
5475 } else {
5476 $new_rows = $this->chat_session_get_message_new( $chat_session );
5477 }
5478
5479 if ( ( $new_rows ) && ( count( $new_rows ) ) ) {
5480
5481 // Init the reply last_row_id with what was sent.
5482 $reply_data['sessions'][ $chat_id ]['last_row_id'] = $chat_session['last_row_id'];
5483
5484 $_LAST_ROW_UPDATED = false;
5485 foreach ( $new_rows as $row_idx => $row ) {
5486 if ( ( intval( $chat_session['last_row_id'] ) > 0 ) && ( $row->id == $chat_session['last_row_id'] ) ) {
5487 continue;
5488 }
5489
5490 $reply_data['sessions'][ $chat_id ]['rows'][ strtotime( $row->timestamp ) . "-" . $row->id ] =
5491 $this->chat_session_build_row( $row, $chat_session );
5492
5493 // Then update the last_row_id based on the higher row->id values returned
5494 if ( $_LAST_ROW_UPDATED == false ) {
5495 $reply_data['sessions'][ $chat_id ]['last_row_id'] = $row->id;
5496 $_LAST_ROW_UPDATED = true;
5497 }
5498 }
5499
5500 if ( count( $reply_data['sessions'][ $chat_id ]['rows'] ) ) {
5501 ksort( $reply_data['sessions'][ $chat_id ]['rows'] );
5502 }
5503
5504 } else {
5505 $reply_data['sessions'][ $chat_id ]['rows'] = "__EMPTY__";
5506 }
5507 $reply_data['sessions'][ $chat_id ]['meta'] = $this->chat_session_update_meta_log( $chat_session );
5508 }
5509
5510 if ( ( ( isset( $timers['meta'] ) ) && ( $timers['meta'] == 1 ) ) || ( $chat_session['session_type'] == 'private' ) ) {
5511
5512 $reply_data['sessions'][ $chat_id ]['global'] = $this->chat_session_update_global_log( $chat_session );
5513 $reply_data['sessions'][ $chat_id ]['meta']['users-active'] = $users_active;
5514 $this->chat_session_users_update_polltime( $chat_session );
5515 }
5516
5517 }
5518
5519 // We only show performance output to admin users.
5520 if ( ( $this->get_option( 'session_performance', 'global' ) == 'enabled' ) && ( current_user_can( 'manage_options' ) ) ) {
5521 $this->chat_performance = wpmudev_chat_end_performance( $this->chat_performance );
5522 $reply_data['performance'] = $this->chat_performance;
5523 }
5524
5525 wp_send_json( $reply_data );
5526 die();
5527 }
5528
5529 function chat_meta_leave_private_session() {
5530 $reply_data = array();
5531 $reply_data['errorStatus'] = false;
5532 $reply_data['errorText'] = '';
5533 $reply_data['sessions'] = array();
5534
5535 // Get Private chats
5536 if ( ( ! isset( $this->chat_auth['auth_hash'] ) ) || ( empty( $this->chat_auth['auth_hash'] ) ) ) {
5537 $reply_data['errorStatus'] = true;
5538 $reply_data['errorText'] = __( 'Invalid auth_hash', $this->translation_domain );
5539
5540 wp_send_json( $reply_data );
5541 die();
5542 }
5543
5544 foreach ( $this->chat_sessions as $chat_id => $chat_session ) {
5545
5546 $reply_data['sessions'][ $chat_id ] = $chat_id;
5547 $this->wpmudev_chat_update_user_invite_status( 'exited', $chat_id, $this->chat_auth['auth_hash'], 'yes' );
5548 }
5549 wp_send_json( $reply_data );
5550 die();
5551 }
5552
5553 function chat_messages_clear() {
5554 global $wpdb;
5555
5556 $reply_data = array();
5557 $reply_data['errorStatus'] = false;
5558 $reply_data['errorText'] = '';
5559
5560 // If the user doesn't have a type
5561 if ( ! isset( $this->chat_auth['type'] ) ) {
5562 $reply_data['errorStatus'] = true;
5563 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5564
5565 wp_send_json( $reply_data );
5566 die();
5567 } else if ( $this->chat_auth['type'] != "wordpress" ) {
5568 $reply_data['errorStatus'] = true;
5569 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5570
5571 wp_send_json( $reply_data );
5572 die();
5573 }
5574
5575 if ( ! is_user_logged_in() ) {
5576 $reply_data['errorStatus'] = true;
5577 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5578
5579 wp_send_json( $reply_data );
5580 die();
5581 }
5582
5583 foreach ( $this->chat_sessions as $chat_id => $chat_session ) {
5584
5585 if ( wpmudev_chat_is_moderator( $chat_session ) ) {
5586
5587 $sql_str = $wpdb->prepare( "DELETE FROM `" . WPMUDEV_Chat::tablename( 'message' ) . "` WHERE blog_id = %d AND chat_id = %s AND archived IN ('no') AND session_type = %s;", $chat_session['blog_id'], $chat_session['id'], $chat_session['session_type'] );
5588 $wpdb->query( $sql_str );
5589 //log_chat_message(__FUNCTION__ .": [". $sql_str ."]");
5590
5591 $this->chat_session_set_meta( $chat_session, 'last_row_id', '__EMPTY__' );
5592 $this->chat_session_set_meta( $chat_session, 'log_row_id', '__EMPTY__' );
5593 $this->chat_session_update_message_rows_deleted( $chat_session );
5594 } else {
5595 $reply_data['errorStatus'] = true;
5596 $reply_data['errorText'] = __( 'Not moderator', $this->translation_domain );
5597 die();
5598 }
5599 }
5600 wp_send_json( $reply_data );
5601 die();
5602 }
5603
5604 function chat_messages_archive() {
5605 $reply_data = array();
5606 $reply_data['errorStatus'] = false;
5607 $reply_data['errorText'] = '';
5608
5609 // If the user doesn't have a type
5610 if ( ! isset( $this->chat_auth['type'] ) ) {
5611 $reply_data['errorStatus'] = true;
5612 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5613
5614 wp_send_json( $reply_data );
5615 die();
5616
5617 } else if ( $this->chat_auth['type'] != "wordpress" ) {
5618 $reply_data['errorStatus'] = true;
5619 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5620
5621 wp_send_json( $reply_data );
5622 die();
5623 }
5624
5625 if ( ! is_user_logged_in() ) {
5626 $reply_data['errorStatus'] = true;
5627 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5628
5629 wp_send_json( $reply_data );
5630 die();
5631 }
5632
5633 foreach ( $this->chat_sessions as $chat_id => $chat_session ) {
5634
5635 if ( wpmudev_chat_is_moderator( $chat_session ) ) {
5636
5637 $this->chat_session_archive_messages( $chat_session );
5638 }
5639 }
5640 wp_send_json( $reply_data );
5641 die();
5642 }
5643
5644 function chat_session_moderate_status() {
5645 $reply_data = array();
5646 $reply_data['errorStatus'] = false;
5647 $reply_data['errorText'] = '';
5648
5649 $chat_id = 0;
5650
5651 if ( ! isset( $_POST['chat_session'] ) ) {
5652
5653 $reply_data['errorStatus'] = true;
5654 $reply_data['errorText'] = __( 'Invalid chat_session', $this->translation_domain );
5655
5656 wp_send_json( $reply_data );
5657 die();
5658 }
5659 $chat_session = $_POST['chat_session'];
5660 $chat_id = esc_attr( $chat_session['id'] );
5661 if ( $chat_id == '' ) {
5662 $reply_data['errorStatus'] = true;
5663 $reply_data['errorText'] = __( 'Invalid chat_id', $this->translation_domain );
5664
5665 wp_send_json( $reply_data );
5666 die();
5667 }
5668
5669 if ( ! isset( $_POST['chat_session_status'] ) ) {
5670 $reply_data['errorStatus'] = true;
5671 $reply_data['errorText'] = __( 'Invalid chat_session_status', $this->translation_domain );
5672
5673 wp_send_json( $reply_data );
5674 die();
5675 }
5676
5677 $chat_session_status = esc_attr( $_POST['chat_session_status'] );
5678 if ( ( $chat_session_status != "open" ) && ( $chat_session_status != "closed" ) ) {
5679 $reply_data['errorStatus'] = true;
5680 $reply_data['errorText'] = __( 'Invalid chat_session_status', $this->translation_domain );
5681
5682 wp_send_json( $reply_data );
5683 die();
5684 }
5685
5686 // If the user doesn't have a type
5687 if ( ! isset( $this->chat_auth['type'] ) ) {
5688 $reply_data['errorStatus'] = true;
5689 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5690
5691 wp_send_json( $reply_data );
5692 die();
5693 } else if ( $this->chat_auth['type'] != "wordpress" ) {
5694 $reply_data['errorStatus'] = true;
5695 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5696
5697 wp_send_json( $reply_data );
5698 die();
5699
5700 }
5701
5702 if ( ! is_user_logged_in() ) {
5703 $reply_data['errorStatus'] = true;
5704 $reply_data['errorText'] = __( 'Invalid chat_auth [type]', $this->translation_domain );
5705
5706 wp_send_json( $reply_data );
5707 die();
5708
5709 }
5710
5711 if ( ! wpmudev_chat_is_moderator( $chat_session ) ) {
5712 $reply_data['errorStatus'] = true;
5713 $reply_data['errorText'] = __( 'not moderator', $this->translation_domain );
5714
5715 wp_send_json( $reply_data );
5716 die();
5717 }
5718
5719 $this->chat_session_set_meta( $chat_session, 'session_status', $chat_session_status );
5720
5721 wp_send_json( $reply_data );
5722 die();
5723 }
5724
5725 function chat_session_moderate_message() {
5726 global $wpdb;
5727
5728 if ( ! isset( $_POST['chat_id'] ) ) {
5729 wp_send_json_error();
5730 die();
5731 }
5732 $chat_id = $_POST['chat_id'];
5733
5734 if ( $chat_id == '' ) {
5735 wp_send_json_error();
5736 die();
5737 }
5738
5739 if ( ! isset( $_POST['row_id'] ) ) {
5740 wp_send_json_error();
5741 die();
5742 }
5743 list( $row_time, $row_id ) = explode( '-', $_POST['row_id'] );
5744 //$row_id = intval($_POST['row_id']);
5745 if ( ( empty( $row_time ) ) || ( empty( $row_id ) ) ) {
5746 wp_send_json_error();
5747 die();
5748 }
5749
5750 //log_chat_message(__FUNCTION__ .": row_time[". $row_time ."] row_id[". $row_id ."]");
5751
5752
5753 if ( ! isset( $_POST['moderate_action'] ) ) {
5754 wp_send_json_error();
5755 die();
5756 }
5757 $moderate_action = esc_attr( $_POST['moderate_action'] );
5758 if ( empty( $moderate_action ) ) {
5759 wp_send_json_error();
5760 die();
5761 }
5762
5763 if ( ! isset( $_POST['chat_session'] ) ) {
5764 wp_send_json_error();
5765 die();
5766 }
5767 $chat_session = $_POST['chat_session'];
5768
5769 // If the user doesn't have a type
5770 if ( ! isset( $this->chat_auth['type'] ) ) {
5771 wp_send_json_error();
5772 die();
5773 } else if ( $this->chat_auth['type'] != "wordpress" ) {
5774 wp_send_json_error();
5775 die();
5776 }
5777
5778 if ( ! is_user_logged_in() ) {
5779 wp_send_json_error();
5780 die();
5781 }
5782
5783 if ( ! wpmudev_chat_is_moderator( $chat_session ) ) {
5784 wp_send_json_error();
5785 die();
5786 }
5787
5788
5789 $row_date = date( 'Y-m-d H:i:s', $row_time );
5790
5791 $sql_str = $wpdb->prepare( "SELECT id, deleted FROM `" . WPMUDEV_Chat::tablename( 'message' )
5792 . "` WHERE id = %d AND blog_id = %d AND chat_id = %s AND timestamp = %s LIMIT 1;",
5793 $row_id, $chat_session['blog_id'], $chat_id, $row_date );
5794
5795
5796 $chat_row = $wpdb->get_row( $sql_str );
5797
5798 if ( ( $chat_row ) && ( isset( $chat_row->deleted ) ) ) {
5799 $chat_row_deleted_new = '';
5800
5801 if ( $moderate_action == "delete" ) {
5802 $chat_row_deleted_new = 'yes';
5803 } else if ( $moderate_action == "undelete" ) {
5804 $chat_row_deleted_new = 'no';
5805 }
5806
5807 if ( ! empty( $chat_row_deleted_new ) ) {
5808 $sql_str = $wpdb->prepare( "UPDATE `" . WPMUDEV_Chat::tablename( 'message' )
5809 . "` SET deleted=%s WHERE id=%d AND blog_id = %d AND chat_id = %s LIMIT 1;",
5810 $chat_row_deleted_new, $chat_row->id, $chat_session['blog_id'], $chat_id );
5811
5812 $wpdb->get_results( $sql_str );
5813
5814 $this->chat_session_update_message_rows_deleted( $chat_session );
5815
5816 wp_send_json_success();
5817 die();
5818 }
5819 }
5820 }
5821
5822 function chat_session_moderate_ip_address() {
5823 global $wpdb;
5824
5825 if ( ! isset( $_POST['chat_id'] ) ) {
5826 die();
5827 }
5828 $chat_id = esc_attr( $_POST['chat_id'] );
5829 if ( $chat_id == '' ) {
5830 die();
5831 }
5832
5833 if ( ! isset( $_POST['ip_address'] ) ) {
5834 die();
5835 }
5836 $ip_address = esc_attr( $_POST['ip_address'] );
5837 if ( empty( $ip_address ) ) {
5838 die();
5839 }
5840
5841 if ( ! isset( $_POST['moderate_action'] ) ) {
5842 die();
5843 }
5844 $moderate_action = esc_attr( $_POST['moderate_action'] );
5845 if ( empty( $moderate_action ) ) {
5846 die();
5847 }
5848
5849 if ( ! isset( $_POST['chat_session'] ) ) {
5850 die();
5851 }
5852 $chat_session = $_POST['chat_session'];
5853
5854 // If the user doesn't have a type
5855 if ( ! isset( $this->chat_auth['type'] ) ) {
5856 die();
5857 } else if ( $this->chat_auth['type'] != "wordpress" ) {
5858 die();
5859 }
5860
5861 if ( ! is_user_logged_in() ) {
5862 die();
5863 }
5864
5865 if ( ! wpmudev_chat_is_moderator( $chat_session ) ) {
5866 die();
5867 }
5868
5869 if ( $this->get_option( 'blocked_ip_addresses_active', 'global' ) != "enabled" ) {
5870 die();
5871 }
5872
5873 if ( ( ! isset( $this->_chat_options['global']['blocked_ip_addresses'] ) )
5874 || ( empty( $this->_chat_options['global']['blocked_ip_addresses'] ) )
5875 ) {
5876 $this->_chat_options['global']['blocked_ip_addresses'] = array();
5877 }
5878
5879 if ( $moderate_action == "block-ip" ) {
5880
5881 $this->_chat_options['global']['blocked_ip_addresses'][] = $ip_address;
5882 $this->_chat_options['global']['blocked_ip_addresses'] = array_unique( $this->_chat_options['global']['blocked_ip_addresses'] );
5883
5884 update_option( 'wpmudev-chat-global', $this->_chat_options['global'] );
5885
5886 } else if ( $moderate_action == "unblock-ip" ) {
5887
5888 $arr_idx = array_search( $ip_address, $this->_chat_options['global']['blocked_ip_addresses'] );
5889 if ( ( $arr_idx !== false ) && ( isset( $this->_chat_options['global']['blocked_ip_addresses'][ $arr_idx ] ) ) ) {
5890 unset( $this->_chat_options['global']['blocked_ip_addresses'][ $arr_idx ] );
5891 update_option( 'wpmudev-chat-global', $this->_chat_options['global'] );
5892 }
5893 }
5894 wp_send_json_success();
5895 die();
5896 }
5897
5898 function chat_session_moderate_user() {
5899 global $wpdb;
5900
5901 if ( ! isset( $_POST['chat_id'] ) ) {
5902 die();
5903 }
5904 $chat_id = esc_attr( $_POST['chat_id'] );
5905 if ( $chat_id == '' ) {
5906 die();
5907 }
5908
5909 if ( ! isset( $_POST['moderate_item'] ) ) {
5910 die();
5911 }
5912 $moderate_item = esc_attr( $_POST['moderate_item'] );
5913 if ( empty( $moderate_item ) ) {
5914 die();
5915 }
5916
5917 if ( ! isset( $_POST['moderate_action'] ) ) {
5918 die();
5919 }
5920 $moderate_action = esc_attr( $_POST['moderate_action'] );
5921 if ( empty( $moderate_action ) ) {
5922 die();
5923 }
5924
5925 if ( ! isset( $_POST['chat_session'] ) ) {
5926 die();
5927 }
5928 $chat_session = $_POST['chat_session'];
5929
5930 // If the user doesn't have a type
5931 if ( ! isset( $this->chat_auth['type'] ) ) {
5932 die();
5933 } else if ( $this->chat_auth['type'] != "wordpress" ) {
5934 die();
5935 }
5936
5937 if ( ! is_user_logged_in() ) {
5938 die();
5939 }
5940
5941 if ( ! wpmudev_chat_is_moderator( $chat_session ) ) {
5942 die();
5943 }
5944
5945 if ( $moderate_action == "block-user" ) {
5946
5947 $this->_chat_options['global']['blocked_users'][] = $moderate_item;
5948 $this->_chat_options['global']['blocked_users'] = array_unique( $this->_chat_options['global']['blocked_users'] );
5949
5950 update_option( 'wpmudev-chat-global', $this->_chat_options['global'] );
5951
5952 } else if ( $moderate_action == "unblock-user" ) {
5953
5954 $arr_idx = array_search( $moderate_item, $this->_chat_options['global']['blocked_users'] );
5955 if ( ( $arr_idx !== false ) && ( isset( $this->_chat_options['global']['blocked_users'][ $arr_idx ] ) ) ) {
5956 unset( $this->_chat_options['global']['blocked_users'][ $arr_idx ] );
5957
5958 update_option( 'wpmudev-chat-global', $this->_chat_options['global'] );
5959 }
5960 }
5961 wp_send_json_success();
5962 die();
5963 }
5964
5965 /**
5966 * Adds the details of host and invitee for private chat to chat message table
5967 */
5968 function chat_session_invite_private() {
5969 global $wpdb, $blog_id;
5970
5971 // We ONLY allow logged in users to perform private invites
5972 if ( ! is_user_logged_in() ) {
5973 wp_send_json_error();
5974
5975 return;
5976 }
5977
5978 /** Check for Auth hash */
5979 if ( md5( get_current_user_id() ) != $this->chat_auth['auth_hash'] ) {
5980 wp_send_json_error();
5981
5982 return;
5983 }
5984 $user_from_hash = $this->chat_auth['auth_hash'];
5985
5986 if ( ( ! isset( $_REQUEST['wpmudev-chat-to-user'] ) ) || ( empty( $_REQUEST['wpmudev-chat-to-user'] ) ) ) {
5987 wp_send_json_error();
5988
5989 return;
5990 }
5991 $user_to_hash = esc_attr( $_REQUEST['wpmudev-chat-to-user'] );
5992
5993 $private_invite_nonce = time();
5994 $chat_id = "private-" . $private_invite_nonce;
5995
5996 $invitation = array();
5997 $invitation['host'] = array();
5998 $invitation['host'] = $this->chat_auth;
5999 $invitation['invite-status'] = 'accepted';
6000
6001 // IF we have a previous private chat we do a number of setup tasks
6002 $sql_str = $wpdb->prepare( "SELECT invite_from.chat_id, invite_from.id invite_from_id, invite_to.id invite_to_id FROM " . WPMUDEV_Chat::tablename( 'message' ) . " as invite_from INNER JOIN " . WPMUDEV_Chat::tablename( 'message' ) . " as invite_to ON invite_from.chat_id=invite_to.chat_id AND invite_to.auth_hash = %s WHERE invite_from.blog_id = %d AND invite_from.session_type=%s AND invite_from.auth_hash=%s ORDER BY invite_from.timestamp ASC LIMIT 1", $user_to_hash, 0, 'invite', $user_from_hash );
6003 //echo "sql_str[". $sql_str ."]<br />";
6004
6005 $invites = $wpdb->get_row( $sql_str );
6006
6007 if ( ! empty( $invites ) ) {
6008
6009 // IF we have a previous private chat we do a number of setup tasks
6010
6011 // For the user sending the invite. We update the message with the 'no' archived status and fill in the invitation.
6012 if ( isset( $invites->invite_from_id ) ) {
6013 $sql_str = $wpdb->prepare( "UPDATE " . WPMUDEV_Chat::tablename( 'message' ) . " SET archived = %s, message = %s, moderator = %s, user_type = %s WHERE id = %d AND blog_id = %d AND chat_id = %s AND auth_hash = %s LIMIT 1", 'no', serialize( $invitation ), 'yes', $this->chat_auth['type'], $invites->invite_from_id, 0, $invites->chat_id, $user_from_hash );
6014 //echo "sql_str[". $sql_str ."]<br />";
6015 $wpdb->get_results( $sql_str );
6016 }
6017
6018 // For the user receiving the invite. We update the message with the 'no' archived status and fill in the invitation. The invitation
6019 // Contains information like who did the invite.
6020 if ( isset( $invites->invite_to_id ) ) {
6021 $invitation['id'] = $invites->invite_from_id;
6022 $invitation['invite-status'] = 'pending';
6023
6024 $sql_str = $wpdb->prepare( "UPDATE " . WPMUDEV_Chat::tablename( 'message' ) . " SET archived = %s, message = %s, moderator = %s, user_type = %s WHERE id = %d AND blog_id = %d AND chat_id = %s AND auth_hash = %s LIMIT 1", 'no', serialize( $invitation ), 'no', '', $invites->invite_to_id, 0, $invites->chat_id, $user_to_hash );
6025 //echo "sql_str[". $sql_str ."]<br />";
6026 $wpdb->get_results( $sql_str );
6027 }
6028
6029 // Then we un-archive the previous messages if any
6030 $sql_str = $wpdb->prepare( "UPDATE " . WPMUDEV_Chat::tablename( 'message' ) . " SET archived = %s WHERE blog_id = %d AND chat_id = %s AND session_type = %s", 'no', 0, $invites->chat_id, 'private' );
6031 //echo "sql_str[". $sql_str ."]<br />";
6032 $wpdb->get_results( $sql_str );
6033
6034 // Lastly, we then unarchive the log reference.
6035 $sql_str = $wpdb->prepare( "UPDATE " . WPMUDEV_Chat::tablename( 'log' ) . " SET archived = %s WHERE blog_id = %d AND chat_id = %s AND session_type = %s LIMIT 1", 'no', 0, $invites->chat_id, 'private' );
6036 //echo "sql_str[". $sql_str ."]<br />";
6037 $wpdb->get_results( $sql_str );
6038
6039 } else if ( empty( $invites ) ) {
6040
6041 /**
6042 * Add details of host
6043 */
6044 /**
6045 * Invite status of host
6046 */
6047 $sql_str = $wpdb->prepare( "INSERT INTO " . WPMUDEV_Chat::tablename( 'message' ) .
6048 " (`blog_id`, `chat_id`, `session_type`, `timestamp`, `name`, `avatar`, `auth_hash`, `ip_address`, `message`, `moderator`, `deleted`, `archived`, `log_id`, `user_type`) VALUES(%d, %s, %s, NOW(), %s, %s, %s, %s, %s, %s, %s, %s, %d, %s);",
6049 0, $chat_id, 'invite', $this->chat_auth['name'], $this->chat_auth['avatar'], $user_from_hash,
6050 $this->chat_auth['ip_address'], serialize( $invitation ), 'yes', 'no', 'no', 0, $this->chat_auth['type'] );
6051
6052 $wpdb->get_results( $sql_str );
6053
6054 //If the row was inserted, insert the details of invitee
6055 if ( intval( $wpdb->insert_id ) ) {
6056
6057 $invitation['id'] = $wpdb->insert_id;
6058 /**
6059 * Invite status of invitee
6060 */
6061 $invitation['invite-status'] = 'pending';
6062
6063 /**
6064 * Add details of invitee
6065 */
6066 $user_moderator = "no";
6067
6068 //Check for existing invitation from same user
6069 $sql_str = $wpdb->prepare( "SELECT * FROM " . WPMUDEV_Chat::tablename( 'message' ) . " WHERE blog_id = %d AND chat_id=%s AND session_type=%s AND auth_hash=%s AND archived = %s ORDER BY timestamp ASC", 0, $chat_id, 'invite', $user_to_hash, 'no' );
6070
6071 $invites = $wpdb->get_results( $sql_str );
6072
6073 //there is no pending invitation, add new
6074 if ( empty( $invites ) ) {
6075
6076 $sql_str = $wpdb->prepare( "INSERT INTO " . WPMUDEV_Chat::tablename( 'message' ) .
6077 " (`blog_id`, `chat_id`, `session_type`, `timestamp`, `name`, `avatar`, `auth_hash`, `ip_address`, `message`, `moderator`, `deleted`, `archived`, `log_id`) VALUES(%d, %s, %s, NOW(), %s, %s, %s, %s, %s, %s, %s, %s, %d);",
6078 0, $chat_id, 'invite', '', '', $user_to_hash, '', serialize( $invitation ), 'no', 'no', 'no', 0 );
6079
6080 $wpdb->get_results( $sql_str );
6081 }
6082 }
6083 }
6084 wp_send_json_success();
6085 die();
6086 }
6087
6088 function chat_update_user_status() {
6089 if ( ! is_user_logged_in() ) {
6090 return;
6091 }
6092
6093 $user_id = get_current_user_id();
6094 if ( md5( $user_id ) == $this->chat_auth['auth_hash'] ) {
6095 if ( isset( $_POST['wpmudev-chat-user-status'] ) ) {
6096 $new_status = esc_attr( $_POST['wpmudev-chat-user-status'] );
6097 if ( isset( $this->_chat_options['user-statuses'][ $new_status ] ) ) {
6098 wpmudev_chat_update_user_status( $user_id, $new_status );
6099 wp_send_json_success();
6100 }
6101 }
6102 }
6103 die();
6104 }
6105
6106 function chat_invite_update_user_status() {
6107 $chat_id = esc_attr( $_POST['chat-id'] );
6108 if ( ! $chat_id ) {
6109 die();
6110 }
6111
6112 if ( ( ! isset( $this->chat_auth['auth_hash'] ) ) || ( empty( $this->chat_auth['auth_hash'] ) ) ) {
6113 die();
6114 }
6115
6116 $invite_status = esc_attr( $_POST['invite-status'] );
6117 if ( ( $invite_status != 'accepted' ) && ( ( $invite_status != 'declined' ) ) ) {
6118 $invite_status = 'declined';
6119 }
6120
6121 global $wpdb;
6122 $sql_str = $wpdb->prepare( "SELECT * FROM " . WPMUDEV_Chat::tablename( 'message' ) . " WHERE session_type=%s AND auth_hash=%s AND archived IN('no') ORDER BY timestamp ASC", 'invite', $this->chat_auth['auth_hash'] );
6123
6124 $invite_chats = $wpdb->get_results( $sql_str );
6125 if ( ! empty( $invite_chats ) ) {
6126 foreach ( $invite_chats as $invite_chat ) {
6127 if ( $invite_chat->chat_id != $chat_id ) {
6128 continue;
6129 }
6130 $invite_info = unserialize( $invite_chat->message );
6131 $invite_info['invite-status'] = $invite_status;
6132
6133 $sql_str = $wpdb->prepare( "UPDATE " . WPMUDEV_Chat::tablename( 'message' ) . " SET `message`= %s, `user_type`=%s WHERE id=%d", serialize( $invite_info ), $this->chat_auth['type'], $invite_chat->id );
6134 //log_chat_message(__FUNCTION__ .": [". $sql_str ."]");
6135
6136 $wpdb->query( $sql_str );
6137 //Update transient
6138 $transient_key = "chat-session-" . $chat_id . '-private';
6139 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
6140 $transient = get_option( $transient_key );
6141 } else {
6142 $transient = get_transient( $transient_key );
6143 }
6144
6145 if ( ! empty( $transient ) ) {
6146 //Change invite status
6147 $transient['invite-info']['message']['invite-status'] = $invite_status;
6148 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
6149 update_option( $transient_key, $transient );
6150 } else {
6151 set_transient( $transient_key, $transient, 60 * 60 * 24 );
6152 }
6153 }
6154 }
6155 }
6156 wp_send_json_success();
6157 die();
6158
6159
6160 }
6161
6162 /**
6163 * Process chat requests
6164 *
6165 * Mostly copied from process.php
6166 *
6167 * @global object $current_user
6168 *
6169 * @param string $return Return? 'yes' or 'no'
6170 *
6171 * @return string If $return is yes will return the output else echo
6172 */
6173 function process_chat_actions( $return = 'no' ) {
6174 if ( ! isset( $_POST['function'] ) ) {
6175 die();
6176 }
6177 $function = $_POST['function'];
6178
6179 switch ( $function ) {
6180
6181 case 'chat_init':
6182 $this->chat_init();
6183 break;
6184
6185 case 'chat_message_send':
6186 $this->chat_message_send();
6187 break;
6188
6189 case 'chat_user_login':
6190 $this->chat_user_login();
6191 break;
6192
6193 case 'chat_messages_update':
6194 $this->chat_message_update();
6195 break;
6196
6197 case 'chat_meta_leave_private_session':
6198 $this->chat_meta_leave_private_session();
6199
6200 break;
6201
6202 case 'chat_messages_clear':
6203 $this->chat_messages_clear();
6204
6205 break;
6206
6207 case 'chat_messages_archive':
6208 $this->chat_messages_archive();
6209 break;
6210
6211 case 'chat_session_moderate_status':
6212 $this->chat_session_moderate_status();
6213
6214 break;
6215
6216 case 'chat_session_moderate_message':
6217 $this->chat_session_moderate_message();
6218 break;
6219
6220 case 'chat_session_moderate_ipaddress':
6221 $this->chat_session_moderate_ip_address();
6222 break;
6223
6224
6225 case 'chat_session_moderate_user':
6226 $this->chat_session_moderate_user();
6227
6228 break;
6229
6230 case 'chat_session_invite_private':
6231 $this->chat_session_invite_private();
6232
6233 break;
6234
6235 case 'chat_update_user_status':
6236 $this->chat_update_user_status();
6237
6238 break;
6239 case 'chat_invite_update_user_status':
6240 $this->chat_invite_update_user_status();
6241
6242 break;
6243 }
6244 }
6245
6246 /**
6247 *
6248 *
6249 * @global none
6250 *
6251 * @param none
6252 *
6253 * @return none
6254 */
6255 function chat_session_build_box( $chat_session ) {
6256 $content = '';
6257
6258 $chat_session['session_status'] = $this->chat_session_get_meta( $chat_session, 'session_status' );
6259
6260 if ( $chat_session['session_type'] != "dashboard" ) {
6261 $content_tmp = $this->chat_box_header_container( $chat_session );
6262 $content = $this->chat_session_module_wrap( $chat_session, $content_tmp, 'wpmudev-chat-module-header' );
6263 }
6264
6265 $content .= $this->chat_session_status_module( $chat_session );
6266 $content .= $this->chat_session_generic_message_module( $chat_session );
6267 $content .= $this->chat_session_user_status_message_module( $chat_session );
6268 $content .= $this->chat_session_login_prompt_module( $chat_session );
6269 $content .= $this->chat_session_invite_prompt_module( $chat_session );
6270
6271 if ( $chat_session['box_input_position'] == "top" ) {
6272 $content .= $this->chat_session_message_area_module( $chat_session );
6273 }
6274
6275 if ( ( $chat_session['users_list_position'] == "above" ) || ( $chat_session['users_list_position'] == "left" ) ) {
6276 $content .= $this->chat_session_users_list_module( $chat_session );
6277 $content .= $this->chat_session_messages_list_module( $chat_session );
6278 } else if ( ( $chat_session['users_list_position'] == "below" ) || ( $chat_session['users_list_position'] == "right" ) ) {
6279 $content .= $this->chat_session_messages_list_module( $chat_session );
6280 $content .= $this->chat_session_users_list_module( $chat_session );
6281 } else if ( $chat_session['users_list_position'] == "none" ) {
6282 $content .= $this->chat_session_messages_list_module( $chat_session );
6283 }
6284
6285 $content .= $this->chat_session_login_module( $chat_session );
6286 $content .= $this->chat_session_banned_status_module( $chat_session );
6287
6288 if ( $chat_session['box_input_position'] == "bottom" ) {
6289 $content .= $this->chat_session_message_area_module( $chat_session );
6290 }
6291
6292 //$content .= $this->chat_session_box_styles($chat_session);
6293
6294 return $content;
6295 }
6296
6297 /**
6298 *
6299 *
6300 * @global none
6301 *
6302 * @param none
6303 *
6304 * @return none
6305 */
6306 function chat_session_get_invites_new() {
6307 global $wpdb;
6308
6309 $invite_sessions = array();
6310
6311 if ( ! isset( $this->chat_auth['auth_hash'] ) ) {
6312 return $invite_sessions;
6313 }
6314
6315 // We want to exclude existing chat_session IDs.
6316 $chat_id_str = '';
6317 foreach ( $this->chat_sessions as $chat_id => $chat_session ) {
6318 if ( strlen( $chat_id_str ) ) {
6319 $chat_id_str .= ",";
6320 }
6321 $chat_id_str .= "'" . esc_attr( $chat_id ) . "'";
6322 }
6323 if ( ! empty( $chat_id_str ) ) {
6324 $chat_id_str = " AND chat_id NOT IN (" . $chat_id_str . ") ";
6325 }
6326
6327 if ( ! empty( $this->user_meta['chat_user_status'] ) && $this->user_meta['chat_user_status'] != 'available' ) {
6328 $chat_id_str .= " AND moderator='yes' ";
6329 }
6330
6331 $sql_str = $wpdb->prepare( "SELECT * FROM " . WPMUDEV_Chat::tablename( 'message' ) . " WHERE session_type=%s AND auth_hash=%s AND archived IN('no') " . $chat_id_str . " ORDER BY timestamp ASC", 'invite', $this->chat_auth['auth_hash'] );
6332
6333 $invite_chats = $wpdb->get_results( $sql_str, ARRAY_A );
6334 if ( ! empty( $invite_chats ) ) {
6335 foreach ( $invite_chats as $invite_chat ) {
6336
6337 if ( ( empty( $invite_chat['name'] ) ) || ( empty( $invite_chat['avatar'] ) ) || ( empty( $invite_chat['ip_address'] ) ) ) {
6338
6339 $sql_str = $wpdb->prepare( "UPDATE " . WPMUDEV_Chat::tablename( 'message' ) . " SET `name` = %s, `avatar` = %s, `ip_address` = %s, `user_type` = %s WHERE `id`=%d LIMIT 1", $this->chat_auth['name'], $this->chat_auth['avatar'], $this->chat_auth['ip_address'], $this->chat_auth['type'], $invite_chat['id'] );
6340 $wpdb->query( $sql_str );
6341 //log_chat_message(__FUNCTION__ .": [". $sql_str ."]");
6342 }
6343
6344 if ( ( isset( $invite_chat['message'] ) ) && ( ! empty( $invite_chat['message'] ) ) ) {
6345 $invite_chat['message'] = maybe_unserialize( $invite_chat['message'] );
6346
6347 } else {
6348 $invite_info = array();
6349 }
6350
6351 if ( ! isset( $this->chat_sessions[ $invite_chat['chat_id'] ] ) ) {
6352
6353 $atts = array();
6354 $atts['id'] = $invite_chat['chat_id'];
6355 $atts['session_type'] = 'private';
6356 $atts['box_moderator_footer'] = 'disabled';
6357 //$atts['box_title'] = __('Private', $this->translation_domain) .'<span class="wpmudev-chat-private-attendees"></span>';
6358 $atts['box_title'] = __( '(P)', $this->translation_domain );
6359
6360 if ( ! isset( $invite_chat['message']['invite-status'] ) ) {
6361 $invite_chat['message']['invite-status'] = "pending";
6362 }
6363
6364 $atts['invite-info'] = $invite_chat;
6365
6366 $content = $this->process_chat_shortcode( $atts );
6367 //Check for content and if chat session exists and not exited
6368 if ( ( ! empty( $content ) ) && ( isset( $this->chat_sessions[ $invite_chat['chat_id'] ] ) ) && $invite_chat['message']['invite-status'] != 'exited' ) {
6369 $invite_sessions[ $invite_chat['chat_id'] ]['html'] = $content;
6370
6371 $invite_sessions[ $invite_chat['chat_id'] ]['css'] = $this->chat_session_box_styles( $this->chat_sessions[ $invite_chat['chat_id'] ] );
6372
6373 $invite_sessions[ $invite_chat['chat_id'] ]['session'] = $this->chat_sessions[ $invite_chat['chat_id'] ];
6374
6375 if ( isset( $this->chat_user[ $invite_chat['chat_id'] ] ) ) {
6376 $invite_sessions[ $invite_chat['chat_id'] ]['user'] = $this->chat_user[ $invite_chat['chat_id'] ];
6377 } else {
6378 $invite_sessions[ $invite_chat['chat_id'] ]['user'] = $this->chat_user['__global__'];
6379 }
6380
6381 $invite_sessions[ $invite_chat['chat_id'] ]['user']['invite-status'] = $invite_chat['message'];
6382 $invite_sessions[ $invite_chat['chat_id'] ]['user']['invite-moderator'] = $invite_chat['moderator'];
6383 }
6384 }
6385 }
6386 }
6387
6388 return $invite_sessions;
6389 }
6390
6391 /**
6392 * @todo: Check the functionality and add description
6393 *
6394 * @param $chat_session
6395 */
6396 function wpmudev_chat_set_private_archive_status( $chat_session ) {
6397 global $wpdb;
6398
6399 $sql_str = $wpdb->prepare( "SELECT * FROM " . WPMUDEV_Chat::tablename( 'message' ) . " WHERE chat_id=%s AND session_type=%s", $chat_session['id'], 'invite' );
6400
6401 $invite_chats = $wpdb->get_results( $sql_str );
6402 if ( ! empty( $invite_chats ) ) {
6403 foreach ( $invite_chats as $invite_chat ) {
6404 $message = maybe_unserialize( $invite_chat->message );
6405
6406 $message['invite-status'] = ! empty( $message['invite-status'] ) ? $message['invite-status'] : 'pending';
6407
6408 $sql_str = "UPDATE " . WPMUDEV_Chat::tablename( 'message' ) . " SET message= '" . maybe_serialize( $message ) . "', archived='no' WHERE id=" . $invite_chat->id;
6409 $wpdb->query( $sql_str );
6410 }
6411 }
6412 }
6413
6414 function wpmudev_chat_update_user_invite_status( $invite_status, $chat_id, $auth_hash = '', $invite_archived = '' ) {
6415 global $wpdb;
6416
6417 if ( empty( $auth_hash ) ) {
6418 if ( isset( $this->chat_auth['auth_hash'] ) ) {
6419 $auth_hash = $this->chat_auth['auth_hash'];
6420 } else {
6421 return;
6422 }
6423 }
6424
6425 $sql_str = $wpdb->prepare( "SELECT * FROM " . WPMUDEV_Chat::tablename( 'message' ) . " WHERE chat_id=%s AND session_type=%s AND auth_hash=%s LIMIT 1",
6426 $chat_id, 'invite', $auth_hash );
6427 $invite_chat = $wpdb->get_row( $sql_str );
6428 if ( ! empty( $invite_chat ) ) {
6429 if ( ( isset( $invite_chat->message ) ) && ( ! empty( $invite_chat->message ) ) ) {
6430 $invite_chat->message = maybe_unserialize( $invite_chat->message );
6431 }
6432 $invite_chat->message['invite-status'] = $invite_status;
6433
6434 if ( empty( $invite_archived ) ) {
6435 $invite_archived = $invite_chat->archived;
6436 }
6437
6438 $sql_str = "UPDATE " . WPMUDEV_Chat::tablename( 'message' ) . " SET message= '" . maybe_serialize( $invite_chat->message ) . "', archived='" . $invite_archived . "' WHERE id=" . $invite_chat->id;
6439 $wpdb->query( $sql_str );
6440 }
6441 }
6442
6443 /**
6444 *
6445 *
6446 * @global none
6447 *
6448 * @param none
6449 *
6450 * @return none
6451 */
6452 function chat_session_get_message_new( $chat_session ) {
6453
6454 if ( ( ! isset( $chat_session['last_row_id'] ) ) || ( $chat_session['last_row_id'] == "__EMPTY__" ) ) {
6455 $chat_session['last_row_id'] = 0;
6456 }
6457
6458 if ( ! isset( $chat_session['last_row_compare'] ) ) {
6459 $chat_session['last_row_compare'] = '>=';
6460 }
6461
6462 if ( $chat_session['last_row_id'] > 0 ) {
6463 $chat_session['log_limit'] = 0;
6464 }
6465
6466 if ( ! isset( $chat_session['archived'] ) ) {
6467 $chat_session['archived'] = array( 'no' );
6468 }
6469
6470 if ( ! isset( $chat_session['deleted'] ) ) {
6471 $chat_session['deleted'] = array( 'yes', 'no' );
6472 }
6473
6474 return $this->chat_session_get_messages( $chat_session, false );
6475 }
6476
6477 /**
6478 *
6479 *
6480 * @global none
6481 *
6482 * @param none
6483 *
6484 * @return none
6485 */
6486 function chat_session_update_message_rows_deleted( $chat_session ) {
6487
6488 $chat_session['last_row_id'] = 0;
6489 $chat_session['log_limit'] = 0;
6490 $chat_session['archived'] = array( 'no' );
6491 $chat_session['deleted'] = array( 'yes' );
6492
6493 $deleted_rows = array();
6494
6495 $rows_tmp = $this->chat_session_get_messages( $chat_session );
6496 if ( ( $rows_tmp ) && ( count( $rows_tmp ) ) ) {
6497
6498 foreach ( $rows_tmp as $row ) {
6499 if ( $row->deleted == "yes" ) {
6500 $deleted_rows[] = strtotime( $row->timestamp ) . "-" . $row->id;
6501 }
6502 }
6503 }
6504
6505 if ( ! count( $deleted_rows ) ) {
6506 $deleted_rows = "__EMPTY__";
6507 }
6508
6509 $this->chat_session_set_meta( $chat_session, 'deleted_rows', $deleted_rows );
6510 }
6511
6512 /**
6513 *
6514 *
6515 * @global none
6516 *
6517 * @param none
6518 *
6519 * @return none
6520 */
6521 function chat_session_update_meta_log( $chat_session, $meta_data = array() ) {
6522 global $wpdb;
6523
6524 if ( ! isset( $meta_data['deleted-rows'] ) ) {
6525 $meta_data['deleted-rows'] = $this->chat_session_get_meta( $chat_session, 'deleted_rows' );
6526 }
6527
6528 if ( ! isset( $meta_data['session-status'] ) ) {
6529
6530 if ( $chat_session['session_type'] == "private" ) {
6531 $sql_str = $wpdb->prepare( "SELECT archived FROM " . WPMUDEV_Chat::tablename( 'message' ) . " WHERE chat_id=%s AND session_type=%s AND auth_hash=%s LIMIT 1", $chat_session['id'], 'invite', $this->chat_auth['auth_hash'] );
6532 $chat_status = $wpdb->get_row( $sql_str );
6533 $meta_data['session-status'] = ! empty( $chat_status->archived ) ? $chat_status->archived : '';
6534 } else {
6535 $meta_data['session-status'] = $this->chat_session_get_meta( $chat_session, 'session_status' );
6536 }
6537 }
6538
6539 return $meta_data;
6540 }
6541
6542 /**
6543 *
6544 *
6545 * @global none
6546 *
6547 * @param none
6548 *
6549 * @return none
6550 */
6551 function chat_session_update_global_log( $chat_session, $global_data = array() ) {
6552
6553 if ( ! isset( $global_data['blocked-ip-addresses'] ) ) {
6554 $global_data['blocked-ip-addresses'] = $this->chat_session_get_blocked_ip_addresses( $chat_session );
6555 }
6556
6557 if ( ! isset( $global_data['blocked-users'] ) ) {
6558 $global_data['blocked-users'] = $this->chat_session_get_blocked_users( $chat_session );
6559 }
6560
6561 return $global_data;
6562 }
6563
6564 /**
6565 *
6566 *
6567 * @global none
6568 *
6569 * @param none
6570 *
6571 * @return none
6572 */
6573 function chat_session_users_update_polltime( $chat_session ) {
6574 global $wpdb;
6575
6576 if ( ! isset( $chat_session['id'] ) ) {
6577 return;
6578 }
6579
6580 // IF the user has not logged in yet. Ignore for now.
6581 if ( ( ! isset( $this->chat_auth['auth_hash'] ) ) || ( empty( $this->chat_auth['auth_hash'] ) ) ) {
6582 return;
6583 }
6584
6585 $blog_id = $chat_session['blog_id'];
6586 $chat_id = $chat_session['id'];
6587 $user_name = trim( $this->chat_auth['name'] );
6588 $user_avatar = ! empty( $this->chat_auth['avatar'] ) ? trim( $this->chat_auth['avatar'] ) : '';
6589 $user_hash = trim( $this->chat_auth['auth_hash'] );
6590 $user_ip_address = trim( $chat_session['ip_address'] );
6591 $user_type = trim( $this->chat_auth['type'] );
6592 $user_moderator = trim( $chat_session['moderator'] );
6593 if ( $user_moderator != "yes" ) {
6594 $user_moderator = "no";
6595 }
6596
6597 if ( ( isset( $user_name ) ) && ( strlen( $user_name ) ) ) {
6598 $sql_str = $wpdb->prepare( "INSERT INTO " . WPMUDEV_Chat::tablename( 'users' ) .
6599 " (blog_id, chat_id, auth_hash, name, avatar, moderator, last_polled, entered, ip_address, user_type)
6600 VALUES(%d, %s, %s, %s, %s, %s, NOW(), NOW(), %s, %s)
6601 ON DUPLICATE KEY UPDATE last_polled = NOW();",
6602 $blog_id, $chat_id, $user_hash, $user_name, $user_avatar, $user_moderator, $user_ip_address, $user_type );
6603 //log_chat_message(__FUNCTION__ .": [". $sql_str ."]");
6604
6605 //echo "sql_str=[". $sql_str ."]<br />";
6606
6607 $wpdb->get_results( $sql_str );
6608 }
6609
6610 return;
6611 }
6612
6613 /**
6614 *
6615 *
6616 * @global none
6617 *
6618 * @param none
6619 *
6620 * @return none
6621 */
6622 function chat_session_get_active_users( $chat_session ) {
6623 global $wpdb;
6624
6625 if ( isset( $chat_session['users_list_avatar_width'] ) ) {
6626 $avatar_size = intval( $chat_session['users_list_avatar_width'] );
6627 }
6628 if ( ( ! isset( $avatar_size ) ) || ( $avatar_size < 1 ) || ( $avatar_size > 100 ) ) {
6629 $avatar_size = 50;
6630 }
6631
6632 $users_data = array();
6633 $users_data['moderators'] = array();
6634 $users_data['users'] = array();
6635
6636 if ( $chat_session['session_type'] == 'private' ) {
6637
6638 $sql_str = $wpdb->prepare( "SELECT invites.name, invites.moderator, invites.ip_address, invites.auth_hash, invites.archived, invites.message, users.last_polled FROM " . WPMUDEV_Chat::tablename( 'message' ) . " as invites LEFT JOIN " . WPMUDEV_Chat::tablename( 'users' ) . " as users ON invites.auth_hash=users.auth_hash AND invites.blog_id=users.blog_id AND invites.chat_id=users.chat_id WHERE invites.blog_id = %d AND invites.chat_id=%s AND invites.session_type=%s", 0, $chat_session['id'], 'invite' );
6639
6640 $users = $wpdb->get_results( $sql_str );
6641 if ( ( $users ) && ( count( $users ) ) ) {
6642 foreach ( $users as $user ) {
6643
6644 $_tmp = array();
6645 //$_tmp['id'] = $user->id;
6646 $_tmp['name'] = $user->name;
6647 $_tmp['moderator'] = $user->moderator;
6648 $_tmp['ip'] = $user->ip_address;
6649 $_tmp['auth_hash'] = $user->auth_hash;
6650 $_tmp['archived'] = $user->archived;
6651
6652 if ( ! empty( $user->last_polled ) ) {
6653
6654 if ( ( isset( $user->message ) ) && ( ! empty( $user->message ) ) ) {
6655 $invitation = maybe_unserialize( $user->message );
6656 if ( ( isset( $invitation['invite-status'] ) ) && ( ! empty( $invitation['invite-status'] ) ) ) {
6657 $_tmp['connect_status'] = esc_attr( $invitation['invite-status'] );
6658 }
6659 }
6660 } else {
6661 $_tmp['connect_status'] = 'pending';
6662 }
6663
6664 if ( $user->moderator == 'yes' ) {
6665 $users_data['moderators'][ $_tmp['auth_hash'] ] = $_tmp;
6666
6667 } else if ( $user->moderator == 'no' ) {
6668 $users_data['users'][ $_tmp['auth_hash'] ] = $_tmp;
6669 }
6670 }
6671 }
6672
6673 } else {
6674
6675 $chat_delete_threshold = intval( $chat_session['users_list_threshold_delete'] );
6676 if ( ! $chat_delete_threshold ) {
6677 $chat_delete_threshold = 20;
6678 }
6679
6680 $sql_str = $wpdb->prepare( "DELETE FROM " . WPMUDEV_Chat::tablename( 'users' ) . " WHERE chat_id=%s AND
6681 last_polled < TIMESTAMPADD(SECOND, -" . $chat_delete_threshold . ", NOW());", $chat_session['id'] );
6682 //log_chat_message(__FUNCTION__ .": [". $sql_str ."]");
6683 $wpdb->query( $sql_str );
6684
6685
6686 $sql_str = $wpdb->prepare( "SELECT * FROM " . WPMUDEV_Chat::tablename( 'users' ) . " WHERE chat_id=%s AND blog_id=%d AND last_polled > TIMESTAMPADD(SECOND, -%d, NOW()) ORDER BY name ASC", $chat_session['id'], $chat_session['blog_id'], $chat_delete_threshold );
6687
6688 $users = $wpdb->get_results( $sql_str );
6689 if ( ( $users ) && ( count( $users ) ) ) {
6690
6691 foreach ( $users as $user ) {
6692 $_tmp = array();
6693 //$_tmp['id'] = $user->id;
6694 $_tmp['name'] = $user->name;
6695 $_tmp['moderator'] = $user->moderator;
6696 $_tmp['ip'] = $user->ip_address;
6697 $_tmp['auth_hash'] = $user->auth_hash;
6698 $_tmp['connect_status'] = 'accepted';
6699
6700 if ( ( isset( $user->avatar ) ) && ( strlen( $user->avatar ) ) ) {
6701 $avatar = '<img alt="' . $user->name . '" style="width: ' . $avatar_size . '; height: ' . $avatar_size . ';" width="' . $avatar_size . '" src="' . $user->avatar . '" class="avatar photo" />';
6702 $_tmp['avatar'] = $avatar;
6703 }
6704 if ( $_tmp['moderator'] == "yes" ) {
6705 $users_data['moderators'][ $_tmp['auth_hash'] ] = $_tmp;
6706 } else {
6707 $users_data['users'][ $_tmp['auth_hash'] ] = $_tmp;
6708 }
6709 }
6710 }
6711 }
6712
6713 return $users_data;
6714 }
6715
6716 /**
6717 *
6718 *
6719 * @global none
6720 *
6721 * @param none
6722 *
6723 * @return none
6724 */
6725 function chat_session_get_blocked_ip_addresses( $chat_session ) {
6726
6727 $blocked_ip_addresses = array();
6728
6729 if ( ( $this->get_option( 'blocked_ip_addresses_active', 'global' ) == "enabled" )
6730 && ( $chat_session['blocked_ip_addresses_active'] == "enabled" )
6731 ) {
6732
6733 $blocked_ip_addresses = $this->get_option( 'blocked_ip_addresses', 'global' );
6734 if ( empty( $blocked_ip_addresses ) ) {
6735 return array();
6736 } else if ( ! is_array( $blocked_ip_addresses ) ) {
6737 $blocked_ip_addresses = array( $blocked_ip_addresses );
6738 }
6739 }
6740
6741 return $blocked_ip_addresses;
6742 }
6743
6744 /**
6745 *
6746 *
6747 * @global none
6748 *
6749 * @param none
6750 *
6751 * @return none
6752 */
6753 function chat_session_get_blocked_users( $chat_session ) {
6754
6755 $blocked_users = array();
6756
6757 $blocked_users = $this->get_option( 'blocked_users', 'global' );
6758 if ( empty( $blocked_users ) ) {
6759 return array();
6760 } else if ( ! is_array( $blocked_users ) ) {
6761 return array( $blocked_users );
6762 } else {
6763 return $blocked_users;
6764 }
6765 }
6766
6767
6768 /**
6769 * Get message
6770 *
6771 * @global object $wpdb
6772 * @global int $blog_id
6773 *
6774 * @param int $chat_id Chat ID
6775 * @param int $since Start Unix timestamp
6776 * @param int $end End Unix timestamp
6777 * @param string $archived Archived? 'yes' or 'no'
6778 */
6779 function chat_session_get_messages( $chat_session ) {
6780 global $wpdb;
6781
6782 if ( ( isset( $chat_session['since'] ) ) && ( $chat_session['since'] > 0 ) ) {
6783 $since_timestamp = date( 'Y-m-d H:i:s', $chat_session['since'] );
6784 } else {
6785 $since_timestamp = 0;
6786 }
6787
6788 if ( ( isset( $chat_session['end'] ) ) && ( $chat_session['end'] > 0 ) ) {
6789 $end_timestamp = date( 'Y-m-d H:i:s', $chat_session['end'] );
6790 } else {
6791 $end_timestamp = 0;
6792 }
6793
6794 if ( isset( $chat_session['orderby'] ) ) {
6795 $orderby = $chat_session['orderby'];
6796 } else {
6797 $orderby = "DESC";
6798 }
6799
6800 if ( ! isset( $chat_session['last_row_compare'] ) ) {
6801 $chat_session['last_row_compare'] = ' > ';
6802 }
6803
6804 $archived_str = "";
6805 if ( ! isset( $chat_session['archived'] ) ) {
6806 $chat_session['archived'] = array( 'no' );
6807 }
6808
6809 if ( ( isset( $chat_session['archived'] ) ) && ( count( $chat_session['archived'] ) ) ) {
6810 foreach ( $chat_session['archived'] as $_val ) {
6811 if ( strlen( $archived_str ) ) {
6812 $archived_str .= ",";
6813 }
6814 $archived_str .= "'" . $_val . "'";
6815 }
6816 }
6817
6818 $deleted_str = "";
6819 if ( ! isset( $chat_session['deleted'] ) ) {
6820 $chat_session['deleted'] = array( 'no' );
6821 }
6822
6823 if ( ( isset( $chat_session['deleted'] ) ) && ( count( $chat_session['deleted'] ) ) ) {
6824 foreach ( $chat_session['deleted'] as $_val ) {
6825 if ( strlen( $deleted_str ) ) {
6826 $deleted_str .= ",";
6827 }
6828 $deleted_str .= "'" . $_val . "'";
6829 }
6830 }
6831
6832 if ( $end_timestamp > 0 ) {
6833 $sql_str = $wpdb->prepare( "SELECT * FROM `" . WPMUDEV_Chat::tablename( 'message' ) . "` WHERE " .
6834 " blog_id = %s " .
6835 " AND chat_id = %s " .
6836 " AND session_type=%s " .
6837 " AND archived IN ( " . $archived_str . " ) " .
6838 " AND deleted IN ( " . $deleted_str . " ) " .
6839 " AND timestamp BETWEEN '" . $since_timestamp . "' AND '" . $end_timestamp . "' " .
6840 " ORDER BY timestamp " . $orderby, $chat_session['blog_id'], $chat_session['id'], $chat_session['session_type'] );
6841 } else {
6842 $sql_str = $wpdb->prepare( "SELECT * FROM `" . WPMUDEV_Chat::tablename( 'message' ) . "` WHERE 1=1 " .
6843 " AND id " . $chat_session['last_row_compare'] . " " . $chat_session['last_row_id'] . " " .
6844 " AND blog_id = %s " .
6845 " AND chat_id = %s " .
6846 " AND session_type=%s " .
6847 " AND archived IN ( " . $archived_str . " ) " .
6848 " AND deleted IN ( " . $deleted_str . " ) " .
6849 " ORDER BY timestamp " . $orderby, $chat_session['blog_id'], $chat_session['id'], $chat_session['session_type'] );
6850 if ( intval( $chat_session['log_limit'] ) > 0 ) {
6851 $sql_str .= " LIMIT " . intval( $chat_session['log_limit'] );
6852 }
6853 }
6854
6855 return $wpdb->get_results( $sql_str );
6856 }
6857
6858 /**
6859 * Send the message
6860 *
6861 * @global object $wpdb
6862 * @global int $blog_id
6863 *
6864 * @param int $chat_id Chat ID
6865 * @param string $name Name
6866 * @param string $avatar URL or e-mail
6867 * @param string $message Payload message
6868 * @param string $moderator Moderator
6869 */
6870 function chat_session_send_message( $message, $chat_session ) {
6871 global $wpdb;
6872
6873 //$wpdb->real_escape = true;
6874
6875 //$time_stamp = date("Y-m-d H:i:s");
6876 $time_stamp_seconds = time();
6877 $time_stamp_formated = date( "Y-m-d H:i:s", $time_stamp_seconds );
6878
6879 $blog_id = $chat_session['blog_id'];
6880 $chat_id = $chat_session['id'];
6881 $session_type = trim( $chat_session['session_type'] );
6882 $name = trim( $this->chat_auth['name'] );
6883 $user_avatar = trim( $this->chat_auth['avatar'] );
6884 $auth_hash = trim( $this->chat_auth['auth_hash'] );
6885 $user_type = trim( $this->chat_auth['type'] );
6886 $ip_address = ( isset( $_SERVER['HTTP_X_FORWARD_FOR'] ) ) ? $_SERVER['HTTP_X_FORWARD_FOR'] : $_SERVER['REMOTE_ADDR'];
6887 $message = trim( $message );
6888 $moderator_str = trim( $chat_session['moderator'] );
6889
6890 if ( $message == '' ) {
6891 return false;
6892 }
6893
6894 $log_row_id = $this->chat_session_get_meta( $chat_session, 'log_row_id' );
6895 //echo "log_row_id[". $log_row_id ."]<br />";
6896 // If we don't find a record we insert a new one
6897 if ( ( empty( $log_row_id ) ) || ( $log_row_id == "__EMPTY__" ) ) {
6898 $sql_str = $wpdb->prepare( "INSERT INTO " . WPMUDEV_Chat::tablename( 'log' ) . " (`blog_id`, `chat_id`, `session_type`, `start`, `end`, `box_title`, `archived`) VALUES (%d, %s, %s, %s, %s, %s, %s);", $chat_session['blog_id'], $chat_session['id'], $chat_session['session_type'], $time_stamp_formated, '', $chat_session['box_title'], 'no' );
6899 //echo "sql_str[". $sql_str ."]<br />";
6900 //die();
6901
6902 $ret = $wpdb->query( $sql_str );
6903 if ( ( isset( $wpdb->insert_id ) ) && ( $wpdb->insert_id > 0 ) ) {
6904 $this->chat_session_set_meta( $chat_session, 'log_row_id', $wpdb->insert_id );
6905 $log_row_id = $wpdb->insert_id;
6906 }
6907 }
6908
6909 // If DB charset is not utf8mb4, emojis needs to be encoded as html entities.
6910 if ( ! strpos( $wpdb->charset, 'mb4' ) && function_exists( 'wp_encode_emoji' ) ) {
6911 $message = wp_encode_emoji( $message );
6912 }
6913
6914 $sql_str = $wpdb->prepare( "INSERT INTO " . WPMUDEV_Chat::tablename( 'message' ) . "
6915 (`blog_id`, `chat_id`, `session_type`, `timestamp`, `name`, `avatar`, `auth_hash`, `ip_address`, `message`, `moderator`, `deleted`, `archived`, `log_id`, `user_type`) VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s);", $blog_id, $chat_id, $session_type, $time_stamp_formated, $name, $user_avatar, $auth_hash, $ip_address, $message, $moderator_str, 'no', 'no', $log_row_id, $user_type );
6916
6917 $ret = $wpdb->query( $sql_str );
6918 if ( ( isset( $wpdb->insert_id ) ) && ( $wpdb->insert_id > 0 ) ) {
6919 $this->chat_session_set_meta( $chat_session, 'last_row_id', $wpdb->insert_id );
6920
6921 return $wpdb->insert_id;
6922 }
6923 }
6924
6925 function chat_session_archive_messages( $chat_session ) {
6926 global $wpdb;
6927
6928 $sql_str = $wpdb->prepare( "SELECT * FROM `" . WPMUDEV_Chat::tablename( 'message' ) . "` WHERE blog_id = %d AND chat_id = %s AND session_type = %s AND archived IN ('no') ORDER BY timestamp ASC;", $chat_session['blog_id'], $chat_session['id'], $chat_session['session_type'] );
6929
6930 $chat_messages = $wpdb->get_results( $sql_str );
6931 if ( ( $chat_messages ) && ( count( $chat_messages ) ) ) {
6932
6933 $chat_summary = array();
6934 $chat_summary['session_type'] = $chat_session['session_type'];
6935
6936 foreach ( $chat_messages as $id => $chat_message ) {
6937 $chat_summary['id'][] = $chat_message->id;
6938 if ( $id == 0 ) {
6939 $chat_summary['start'] = $chat_message->timestamp;
6940 }
6941 $chat_summary['end'] = $chat_message->timestamp;
6942 }
6943
6944 $chat_log_id = 0;
6945
6946 // Need to check the log table for an existing unarchived record record.
6947 $sql_str = $wpdb->prepare( "SELECT id FROM " . WPMUDEV_Chat::tablename( 'log' )
6948 . " WHERE blog_id = %d AND chat_id = %s AND archived = %s LIMIT 1", $chat_session['blog_id'], $chat_session['id'], 'no' );
6949 $chat_log = $wpdb->get_row( $sql_str );
6950
6951 // If we don't find a record we insert a new one
6952 if ( ( isset( $chat_log ) ) && ( isset( $chat_log->id ) ) && ( ! empty( $chat_log->id ) ) ) {
6953 $chat_log_id = $chat_log->id;
6954
6955 $sql_str = $wpdb->prepare( "UPDATE " . WPMUDEV_Chat::tablename( 'log' ) . " SET `blog_id` = %d, `chat_id`= %s, `session_type` = %s, `start` = %s, `end` = %s, `box_title` = %s, `archived` = %s WHERE id = %d LIMIT 1;",
6956 $chat_session['blog_id'],
6957 $chat_session['id'],
6958 $chat_summary['session_type'],
6959 $chat_summary['start'],
6960 $chat_summary['end'],
6961 $chat_session['box_title'],
6962 'yes',
6963 $chat_log_id
6964 );
6965 $wpdb->query( $sql_str );
6966 }
6967
6968 if ( empty( $chat_log_id ) ) {
6969 $sql_str = $wpdb->prepare( "INSERT INTO " . WPMUDEV_Chat::tablename( 'log' ) . "
6970 (`blog_id`, `chat_id`, `session_type`, `start`, `end`, `box_title`, `archived`) VALUES (%d, %s, %s, %s, %s, %s, %s);",
6971 $chat_session['blog_id'],
6972 $chat_session['id'],
6973 $chat_summary['session_type'],
6974 $chat_summary['start'],
6975 $chat_summary['end'],
6976 '',
6977 'no'
6978 );
6979 $wpdb->query( $sql_str );
6980
6981 // Then get the inserted row id
6982 if ( ( $wpdb->insert_id ) && ( ! empty( $wpdb->insert_id ) ) ) {
6983 $chat_log_id = $wpdb->insert_id;
6984 }
6985 }
6986
6987 // IF we have aquired or created a new chat_log_id we update the message rows with the log_id
6988 if ( ! empty( $chat_log_id ) ) {
6989 $sql_str = $wpdb->prepare( "UPDATE `" . WPMUDEV_Chat::tablename( 'message' ) . "` set archived = 'yes', log_id=%d WHERE blog_id = %d AND chat_id = %s AND id IN(" . join( ',', array_values( $chat_summary['id'] ) ) . ") AND archived = 'no';", $chat_log_id, $chat_session['blog_id'], $chat_session['id'], $chat_summary['start'], $chat_summary['end'] );
6990
6991 $wpdb->query( $sql_str );
6992
6993 $this->chat_session_set_meta( $chat_session, 'last_row_id', '__EMPTY__' );
6994 $this->chat_session_set_meta( $chat_session, 'log_row_id', '__EMPTY__' );
6995 $this->chat_session_update_message_rows_deleted( $chat_session );
6996 }
6997 }
6998 }
6999
7000
7001 /**
7002 * Get a list of archives for the given chat
7003 *
7004 * @global object $wpdb
7005 * @global int $blog_id
7006 *
7007 * @param int $chat_id Chat ID
7008 *
7009 * @return array List of archives
7010 */
7011 function get_archives( $chat_session ) {
7012 global $wpdb, $blog_id, $site_id;
7013
7014 if ( ! isset( $chat_session['deleted'] ) ) {
7015 $chat_session['deleted'] = 'no';
7016 }
7017 if ( ! isset( $chat_session['archived'] ) ) {
7018 $chat_session['archived'] = 'yes';
7019 }
7020
7021 $sql_where_str = "WHERE 1=1 ";
7022
7023
7024 if ( ( isset( $chat_session['blog_id'] ) ) && ( ! empty( $chat_session['blog_id'] ) ) ) {
7025 $sql_where_str .= $wpdb->prepare( " AND blog_id = %d ", $chat_session['blog_id'] );
7026 } else {
7027 $chat_session['blog_id'] = $blog_id;
7028 }
7029 if ( ( isset( $chat_session['deleted'] ) ) && ( ! empty( $chat_session['deleted'] ) ) ) {
7030 $sql_where_str .= $wpdb->prepare( " AND deleted = %s ", $chat_session['deleted'] );
7031 }
7032 if ( ( isset( $chat_session['archived'] ) ) && ( ! empty( $chat_session['archived'] ) ) ) {
7033 $sql_where_str .= $wpdb->prepare( " AND archived = %s ", $chat_session['archived'] );
7034 }
7035 if ( ( isset( $chat_session['id'] ) ) && ( ! empty( $chat_session['id'] ) ) ) {
7036 $sql_where_str .= $wpdb->prepare( " AND chat_id = %s ", $chat_session['id'] );
7037 }
7038 $sql_str = "SELECT * FROM `" . WPMUDEV_Chat::tablename( 'log' ) . "` " . $sql_where_str;
7039
7040 if ( ( isset( $chat_session['log_display_limit'] ) ) && ( ! empty( $chat_session['log_display_limit'] ) ) ) {
7041 $log_display_limit = intval( $chat_session['log_display_limit'] );
7042 if ( $log_display_limit > 0 ) {
7043 $sql_str .= " LIMIT " . $log_display_limit;
7044 }
7045 }
7046 //echo "sql_str=[". $sql_str ."]<br />";
7047 //log_chat_message(__FUNCTION__ .": [". $sql_str ."]");
7048
7049 return $wpdb->get_results( $sql_str );
7050 }
7051
7052 function chat_session_logs_messages( $table, $action, $ids = array() ) {
7053 global $wpdb;
7054
7055 $sql_str = '';
7056 switch ( $table ) {
7057 case 'log':
7058 if ( $action == 'hide' ) {
7059 $sql_str = "UPDATE `" . WPMUDEV_Chat::tablename( 'log' ) . "` SET `deleted`='yes' WHERE id IN(" . implode( ',', $ids ) . ")";
7060 $ret = $wpdb->query( $sql_str );
7061
7062 } else if ( $action == "unhide" ) {
7063 $sql_str = "UPDATE `" . WPMUDEV_Chat::tablename( 'log' ) . "` SET `deleted`='no' WHERE id IN(" . implode( ',', $ids ) . ")";
7064 $ret = $wpdb->query( $sql_str );
7065
7066 } else if ( $action == "delete" ) {
7067 $sql_str .= "DELETE FROM `" . WPMUDEV_Chat::tablename( 'log' ) . "` WHERE id IN(" . implode( ',', $ids ) . "); ";
7068 $ret = $wpdb->query( $sql_str );
7069
7070 $sql_str = "DELETE FROM `" . WPMUDEV_Chat::tablename( 'message' ) . "` WHERE log_id IN(" . implode( ',', $ids ) . "); ";
7071 $ret = $wpdb->query( $sql_str );
7072 }
7073 break;
7074
7075 case 'message':
7076 if ( $action == 'hide' ) {
7077 $sql_str = "UPDATE `" . WPMUDEV_Chat::tablename( 'message' ) . "` SET `deleted`='yes' WHERE id IN(" . implode( ',', $ids ) . ")";
7078 $ret = $wpdb->query( $sql_str );
7079
7080 } else if ( $action == "unhide" ) {
7081 $sql_str = "UPDATE `" . WPMUDEV_Chat::tablename( 'message' ) . "` SET `deleted`='no' WHERE id IN(" . implode( ',', $ids ) . ")";
7082 $ret = $wpdb->query( $sql_str );
7083
7084 } else if ( $action == "delete" ) {
7085 $sql_str = "DELETE FROM `" . WPMUDEV_Chat::tablename( 'message' ) . "` WHERE id IN(" . implode( ',', $ids ) . "); ";
7086 $ret = $wpdb->query( $sql_str );
7087 }
7088 break;
7089
7090 default:
7091 break;
7092 }
7093
7094 return true;
7095 }
7096
7097 /**
7098 * Used to prime the last_row_id meta field for the session. Either set to the highest row ID or __EMPTY__
7099 *
7100 * @global none
7101 *
7102 * @param none
7103 *
7104 * @return none
7105 */
7106 function chat_session_get_last_row_id( $chat_session ) {
7107
7108 $chat_session['last_row_id'] = 0;
7109 $chat_session['log_limit'] = 1;
7110 $chat_session['archived'] = array( 'no' );
7111 $chat_session['deleted'] = array( 'yes', 'no' );
7112 $chat_session['orderby'] = 'DESC';
7113
7114 $rows = $this->chat_session_get_messages( $chat_session, false );
7115 if ( isset( $rows[0] ) ) {
7116 $this->chat_session_set_meta( $chat_session, 'last_row_id', $rows[0]->id );
7117
7118 return $rows[0]->id;
7119 } else {
7120 $this->chat_session_set_meta( $chat_session, 'last_row_id', '__EMPTY__' );
7121
7122 return '__EMPTY__';
7123 }
7124 }
7125
7126 function chat_session_verify_meta( $chat_session, $chat_session_meta ) {
7127 global $wpdb;
7128
7129 if ( ( isset( $chat_session_meta['log_row_id'] ) ) && ( $chat_session_meta['log_row_id'] != '__EMPTY__' ) && ( $chat_session_meta['log_row_id'] != 0 ) ) {
7130 $sql_str = $wpdb->prepare( "SELECT id FROM " . WPMUDEV_Chat::tablename( 'log' ) . " WHERE id=%d AND blog_id = %d AND chat_id = %s",
7131 $chat_session_meta['log_row_id'], $chat_session['blog_id'], $chat_session['id'] );
7132 //echo "sql_str[". $sql_str ."]<br />";
7133 $chat_log = $wpdb->get_col( $sql_str );
7134
7135 if ( ( ! isset( $chat_log->id ) ) || ( empty( $chat_log->id ) ) ) {
7136 $sql_str = $wpdb->prepare( "INSERT INTO " . WPMUDEV_Chat::tablename( 'log' ) . " (`blog_id`, `chat_id`, `session_type`, `start`, `end`, `box_title`, `archived`) VALUES (%d, %s, %s, %s, %s, %s, %s);",
7137 $chat_session['blog_id'],
7138 $chat_session['id'],
7139 $chat_session['session_type'],
7140 $time_stamp_formated,
7141 '',
7142 $chat_session['box_title'],
7143 'no' );
7144 //echo "sql_str[". $sql_str ."]<br />";
7145 //die();
7146
7147 $ret = $wpdb->query( $sql_str );
7148 if ( ( isset( $wpdb->insert_id ) ) && ( $wpdb->insert_id > 0 ) ) {
7149 $this->chat_session_set_meta( $chat_session, 'log_row_id', $wpdb->insert_id );
7150 $log_row_id = $wpdb->insert_id;
7151 }
7152 }
7153 }
7154 }
7155
7156 function chat_session_get_log_row_id( $chat_session ) {
7157 global $wpdb;
7158
7159 $sql_str = $wpdb->prepare( "SELECT id FROM " . WPMUDEV_Chat::tablename( 'log' ) . " WHERE blog_id = %d AND chat_id = %s AND archived = %s", $chat_session['blog_id'], $chat_session['id'], 'no' );
7160 $chat_log = $wpdb->get_row( $sql_str );
7161
7162 if ( ( empty( $chat_log ) ) || ( ! isset( $chat_log->id ) ) ) {
7163 return '0';
7164 } else {
7165 return $chat_log->id;
7166 }
7167 }
7168
7169 /**
7170 *
7171 *
7172 * @global none
7173 *
7174 * @param none
7175 *
7176 * @return none
7177 */
7178 function chat_session_get_meta( $chat_session, $key = '' ) {
7179
7180 $transient_key = "chat-meta-" . $chat_session['id'] . '-' . $chat_session['session_type'];
7181 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
7182 $chat_meta = get_option( $transient_key );
7183 } else {
7184 $chat_meta = get_transient( $transient_key );
7185 }
7186 if ( ! $chat_meta ) {
7187 $chat_meta = array();
7188 }
7189
7190 if ( ! isset( $chat_meta['session_status'] ) ) {
7191 $chat_meta['session_status'] = "open";
7192 }
7193
7194 if ( ! isset( $chat_meta['last_row_id'] ) ) {
7195 $chat_meta['last_row_id'] = $this->chat_session_get_last_row_id( $chat_session );
7196 }
7197
7198 if ( ! isset( $chat_meta['log_row_id'] ) ) {
7199 $chat_meta['log_row_id'] = $this->chat_session_get_log_row_id( $chat_session );
7200 }
7201
7202 if ( ! isset( $chat_meta['deleted_rows'] ) ) {
7203 $chat_meta['deleted_rows'] = array();
7204 }
7205
7206 if ( empty( $key ) ) {
7207 return $chat_meta;
7208 } else if ( isset( $chat_meta[ $key ] ) ) {
7209 return $chat_meta[ $key ];
7210 } else {
7211 return array();
7212 }
7213 }
7214
7215 /**
7216 *
7217 *
7218 * @global none
7219 *
7220 * @param none
7221 *
7222 * @return none
7223 */
7224 function chat_session_set_meta( $chat_session, $key = '', $meta = '' ) {
7225
7226 $transient_key = "chat-meta-" . $chat_session['id'] . '-' . $chat_session['session_type'];
7227 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
7228 $chat_meta = get_option( $transient_key );
7229 } else {
7230 $chat_meta = get_transient( $transient_key );
7231 }
7232 //$chat_meta = get_option($transient_key);
7233 if ( ! $chat_meta ) {
7234 $chat_meta = array();
7235 }
7236
7237 if ( $key ) {
7238 //log_chat_message(__FUNCTION__ .": key[". $key ."] meta[". $meta."]");
7239
7240 $chat_meta[ $key ] = $meta;
7241 if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
7242 update_option( $transient_key, $chat_meta );
7243 } else {
7244 set_transient( $transient_key, $chat_meta, 60 * 60 * 24 );
7245 }
7246 }
7247 }
7248
7249 // Probably a better way to do this coming soon. The logic here is IF the user is viewing the chat session
7250 // from within the wp-admin session logs they can load the live open chat session. If that is happening
7251 // We want to override some of the display settings. so for example consider the actual chat session is
7252 // a widget or bottom corner chat. The widget and height would be very small. So we want to override
7253 // the widget/height for the display of the chat but but still maintain data integrity. We admin can post
7254 // to the message message which will appear within the live chat session as well as here.
7255 function chat_session_show_via_logs( $chat_session ) {
7256 $_FLAG_VIEW_ADMIN = false;
7257
7258 if ( is_admin() ) {
7259 if ( ( isset( $_GET['page'] ) ) && ( $_GET['page'] == "chat_session_logs" )
7260 && ( isset( $_GET['chat_id'] ) ) && ( $_GET['chat_id'] == $chat_session['id'] )
7261 && ( isset( $_GET['session_type'] ) ) && ( $_GET['session_type'] == $chat_session['session_type'] )
7262 ) {
7263 $_FLAG_VIEW_ADMIN = true;
7264 }
7265 } else {
7266 $REFERER_args = array();
7267 if ( isset( $_POST['wpmudev-chat-settings-request-uri'] ) ) {
7268 $request_uri = base64_decode( $_POST['wpmudev-chat-settings-request-uri'] );
7269
7270 wp_parse_str( parse_url( $request_uri, PHP_URL_QUERY ), $REFERER_args );
7271 }
7272 if ( ( isset( $REFERER_args['page'] ) ) && ( $REFERER_args['page'] == "chat_session_logs" )
7273 && ( isset( $REFERER_args['chat_id'] ) ) && ( $REFERER_args['chat_id'] == $chat_session['id'] )
7274 && ( isset( $REFERER_args['session_type'] ) ) && ( $REFERER_args['session_type'] == $chat_session['session_type'] )
7275 ) {
7276 $_FLAG_VIEW_ADMIN = true;
7277 }
7278 }
7279
7280 if ( $_FLAG_VIEW_ADMIN == false ) {
7281 return $chat_session;
7282 }
7283
7284 $chat_session['box_width'] = '100%';
7285 $chat_session['box_height'] = '500px';
7286 $chat_session['box_popout'] = 'disabled';
7287 $chat_session['box_input_position'] = 'top';
7288
7289 $chat_session['row_date'] = 'enabled';
7290 $chat_session['row_time'] = 'enabled';
7291 $chat_session['row_name_avatar'] = 'name-avatar';
7292
7293 $chat_session['login_options'] = array();
7294
7295 $chat_session['log_display'] = 'disabled';
7296 $chat_session['log_limit'] = '';
7297
7298 $chat_session['users_list_show'] = 'avatar';
7299 $chat_session['users_list_position'] = 'right';
7300 $chat_session['users_list_style'] = 'split';
7301
7302 $chat_session['users_list_width'] = '30%';
7303
7304 $chat_session['show_messages_position'] = 'left';
7305 $chat_session['show_messages_width'] = '70%';
7306
7307 $chat_session_after = apply_filters( 'chat_logs_show_session', $chat_session );
7308
7309 // Basically, don't trust users filtering out the key settings for the chat
7310 $chat_session_after['blog_id'] = $chat_session['blog_id'];
7311 $chat_session_after['id'] = $chat_session['id'];
7312 $chat_session_after['session_type'] = $chat_session['session_type'];
7313 $chat_session_after['update_transient'] = 'disabled';
7314
7315 return $chat_session_after;
7316 }
7317
7318 function unset_cookies() {
7319 if ( is_user_logged_in() ) { ?>
7320
7321 <script type="text/javascript">
7322 jQuery(document).ready(function () {
7323 var auth_name = 'wpmudev-chat-auth';
7324 var value = ' ';
7325 var expires = '; expires=Thu, 01 Jan 1970 00:00:00 GMT';
7326 var path = '; path= /';
7327 var domain = '; domain=.dilliboss.com';
7328 var secure = '; ';
7329 var name = 'wpmudev-chat-user';
7330 document.cookie = [auth_name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
7331 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
7332 });
7333 </script><?php
7334 }
7335
7336 return;
7337 }
7338 }
7339} // End of class_exists()
7340
7341// Lets get things started
7342$wpmudev_chat = new WPMUDEV_Chat();