| 1 |
<?php |
| 2 |
if( ! defined( 'ABSPATH' ) ) exit; |
| 3 |
|
| 4 |
/** |
| 5 |
* @var array $attributes The block attributes. |
| 6 |
* @var string $content The block default content. |
| 7 |
* @var WP_Block $block The block instance. |
| 8 |
*/ |
| 9 |
|
| 10 |
$instance = wp_parse_args( $attributes, [ |
| 11 |
'title' => __( 'Online Members', 'wpforo' ), |
| 12 |
'count' => 15, |
| 13 |
'display_avatar' => true, |
| 14 |
'groupids' => WPF()->usergroup->get_visible_usergroup_ids(), |
| 15 |
'refresh_interval' => 0, |
| 16 |
] ); |
| 17 |
|
| 18 |
if( is_string( $instance['groupids'] ) && wpforo_is_json( $instance['groupids'] ) ) { |
| 19 |
$instance['groupids'] = json_decode( $instance['groupids'], true ); |
| 20 |
} |
| 21 |
|
| 22 |
if( is_array( $instance['groupids'] ) ) { |
| 23 |
$instance['groupids'] = array_filter( array_map( 'intval', $instance['groupids'] ) ); |
| 24 |
} |
| 25 |
|
| 26 |
// wpForo OnlineMembers widget logic |
| 27 |
$data = [ |
| 28 |
'boardid' => 0, |
| 29 |
'action' => 'wpforo_load_ajax_widget_OnlineMembers', |
| 30 |
'instance' => $instance, |
| 31 |
]; |
| 32 |
|
| 33 |
if( WPF()->board->get_current( 'boardid' ) !== 0 ) $data['referer'] = home_url(); |
| 34 |
|
| 35 |
// We need to use the OnlineMembers widget class to get the HTML |
| 36 |
// To avoid duplicating logic, we can try to instantiate it or use its methods if possible. |
| 37 |
// However, the widget class is designed to be used as a WP_Widget. |
| 38 |
// Let's manually implement the HTML generation logic here, similar to get_widget() in OnlineMembers.php |
| 39 |
|
| 40 |
$online_members = WPF()->member->get_online_members( $instance['count'], $instance['groupids'] ); |
| 41 |
$html = ''; |
| 42 |
|
| 43 |
if( ! empty( $online_members ) ) { |
| 44 |
$html .= '<ul> |
| 45 |
<li> |
| 46 |
<div class="wpforo-list-item">'; |
| 47 |
foreach( $online_members as $member ) { |
| 48 |
if( $instance['display_avatar'] ) { |
| 49 |
$html .= wpforo_member_link( $member, '', 96, 'onlineavatar', false, 'avatar', 'style="width:95%;" class="avatar"' ); |
| 50 |
} else { |
| 51 |
$html .= wpforo_member_link( $member, '', 30, 'onlineuser', false ); |
| 52 |
} |
| 53 |
} |
| 54 |
$html .= '<div class="wpf-clear"></div> |
| 55 |
</div> |
| 56 |
</li> |
| 57 |
</ul>'; |
| 58 |
} else { |
| 59 |
$html .= '<p class="wpf-widget-note"> ' . wpforo_phrase( 'No online members at the moment', false ) . '</p>'; |
| 60 |
} |
| 61 |
|
| 62 |
$json = json_encode( $data ); |
| 63 |
wp_enqueue_script( 'wpforo-widgets-js' ); |
| 64 |
?> |
| 65 |
<div id="wpf-widget-online-users" class="wpforo-block-online-members wpforo-widget-wrap"> |
| 66 |
<?php if( $instance['title'] ) : ?> |
| 67 |
<h3 class="widget-title"><?php echo apply_filters( 'widget_title', $instance['title'] ); ?></h3> |
| 68 |
<?php endif; ?> |
| 69 |
<div class="wpforo-widget-content wpforo-ajax-widget wpforo-ajax-widget-onload-false" data-json="<?php echo esc_attr( $json ); ?>"> |
| 70 |
<?php echo $html; ?> |
| 71 |
</div> |
| 72 |
</div> |
| 73 |
|