PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.3.3
Forumax – AI Powered Advanced Community Forum Plugin v1.3.3
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / widgets / forum-info / Forum_Information.php

Forum_Information.php in Forumax – AI Powered Advanced Community Forum Plugin 1.3.3, at widgets/forum-info/Forum_Information.php

193 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BBPCore\WpWidgets;
3
4 use WP_Widget;
5
6 // Newsletter
7 class Forum_Information extends WP_Widget {
8 public function __construct() {
9 parent::__construct( 'bbpc_forum_info', esc_html__( '(BBPC) Current Forum Info', 'bbp-core' ), array(
10 'description' => esc_html__( "Displays the current forum's information, including the number of topics, replies, Last post by, and Last activity, as well as the Subscribe button", 'bbp-core' ),
11 'classname' => 'bbpc_forum_information'
12 ) );
13 }
14
15 // Front End
16 public function widget( $args, $instance ) {
17 // if single forum page
18 if ( ! isset( $args['widget_id'] ) ) {
19 $args['widget_id'] = $this->id;
20 }
21
22 $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : esc_html__( 'Forum Informations', 'bbp-core' );
23 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
24 $show_icons = $instance['show_icons'] ?? false;
25 $show_topics_count = $instance['show_topics_count'] ?? false;
26 $show_replies_count = $instance['show_replies_count'] ?? false;
27 $show_last_post_user = $instance['show_last_post_user'] ?? false;
28 $show_last_activity = $instance['show_last_activity'] ?? false;
29 $show_subscribe = $instance['show_subscribe'] ?? false;
30
31 echo $args['before_widget'];
32
33 if( is_bbpress() && is_singular( 'forum' ) ) :
34 $forum_id = bbp_get_forum_id();
35 $topic_count = bbp_get_forum_topic_count( $forum_id );
36 $reply_count = bbp_get_forum_reply_count( $forum_id );
37 $last_active = bbp_get_forum_last_active_time( $forum_id );
38 $last_active_user_id = bbp_get_forum_last_active_id( $forum_id );
39 $last_active_user = get_post_field( 'post_author', $last_active_user_id );
40
41 if ( $title ) {
42 echo $args['before_title'] . $title . $args['after_title'];
43 }
44
45 $subscribe_link = '';
46 if ( is_user_logged_in() ) {
47 $subscribe_link = bbp_get_forum_subscription_link();
48 }
49
50 if ( $show_topics_count == 'on' || $show_replies_count == 'on' || $show_last_post_user == 'on' || $show_last_activity == 'on' || $show_subscribe == 'on') :
51 ?>
52 <div class="bbpc-widget-forum-info">
53 <table>
54 <tbody>
55 <?php
56 if ( $show_topics_count == 'on' ) :
57 ?>
58 <tr class="show_count_topics">
59 <th>
60 <?php
61 if( $show_icons == 'on' ) :
62 ?>
63 <i class="icon_documents"></i>
64 <?php
65 endif;
66 esc_html_e( 'Topics', 'bbp-core' );
67 ?>
68 </th>
69 <td><?php echo esc_html($topic_count); ?></td>
70 </tr>
71 <?php
72 endif;
73
74 if ( $show_replies_count == 'on' ) :
75 ?>
76 <tr class="show_count_replies">
77 <th>
78 <?php
79 if( $show_icons == 'on' ) :
80 ?>
81 <i class="icon_chat_alt"></i>
82 <?php
83 endif;
84 esc_html_e( 'Replies', 'bbp-core' );
85 ?>
86 </th>
87 <td><?php echo esc_html($reply_count); ?></td>
88 </tr>
89 <?php
90 endif;
91
92 if ( $show_last_post_user == 'on' ) :
93 ?>
94 <tr class="show_last_post_user">
95 <th>
96 <?php
97 if ( $show_icons == 'on' ) :
98 ?>
99 <img src="<?php echo BBPC_IMG ?>/avatar.svg" alt="<?php esc_attr_e( 'BBP Core Pro avatar icon', 'bbp-core' ); ?>">
100 <?php
101 endif;
102 esc_html_e( 'Last post by', 'bbp-core' );
103 ?>
104 </th>
105 <td>
106 <a href="<?php echo get_author_posts_url( $last_active_user ); ?>">
107 <?php echo esc_html($last_active_user = get_the_author_meta( 'user_nicename', $last_active_user )); ?>
108 </a>
109 </td>
110 </tr>
111 <?php
112 endif;
113
114 if ( $show_last_activity == 'on' ) :
115 ?>
116 <tr class="show_last_activity">
117 <th>
118 <?php
119 if( $show_icons == 'on' ) :
120 ?>
121 <i class="icon_clock_alt"></i>
122 <?php
123 endif;
124 esc_html_e( 'Last activity', 'bbp-core' );
125 ?>
126 </th>
127 <td> <?php echo esc_html($last_active); ?> </td>
128 </tr>
129 <?php
130 endif;
131
132 if ( $show_subscribe == 'on' ) :
133 wp_enqueue_script( 'bbpc-wp-widget' );
134 ?>
135 <tr class="show_subscribe">
136 <th>
137 <?php
138 if( $show_icons == 'on' ) :
139 ?>
140 <i class="icon_action"></i>
141 <?php
142 endif;
143 esc_html_e( 'Actions', 'bbp-core' );
144 ?>
145 </th>
146 <td>
147 <?php
148 if( is_user_logged_in() ){
149 echo bbp_get_forum_subscription_link();
150 } else {
151 echo $subscribe_link = '<a href="'. wp_login_url(get_permalink()) .'">'. esc_html__('Login to subscribe', 'bbp-core') .'</a>';
152 }
153 ?>
154 </td>
155 </tr>
156 <?php
157 endif;
158 ?>
159 </tbody>
160 </table>
161 </div>
162 <?php
163 endif;
164 endif;
165
166 echo $args['after_widget'];
167 }
168
169 public function form( $instance ) {
170 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
171 $show_icons = isset( $instance['show_icons'] ) ? esc_attr( $instance['show_icons'] ) : '';
172 $show_topics_count = isset( $instance['show_topics_count'] ) ? esc_attr( $instance['show_topics_count'] ) : '';
173 $show_replies_count = isset( $instance['show_replies_count'] ) ? esc_attr( $instance['show_replies_count'] ) : '';
174 $show_last_post_user = isset( $instance['show_last_post_user'] ) ? esc_attr( $instance['show_last_post_user'] ) : '';
175 $show_last_activity = isset( $instance['show_last_activity'] ) ? esc_attr( $instance['show_last_activity'] ) : '';
176 $show_subscribe = isset( $instance['show_subscribe'] ) ? esc_attr( $instance['show_subscribe'] ) : '';
177 require plugin_dir_path(__FILE__) . 'admin-options.php';
178 }
179
180 public function update($new_instance, $old_instance){
181 $instance = array();
182 $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
183 $instance['show_icons'] = (!empty($new_instance['show_icons'])) ? strip_tags($new_instance['show_icons']) : '';
184 $instance['show_topics_count'] = (!empty($new_instance['show_topics_count'])) ? strip_tags($new_instance['show_topics_count']) : '';
185 $instance['show_replies_count'] = (!empty($new_instance['show_replies_count'])) ? strip_tags($new_instance['show_replies_count']) : '';
186 $instance['show_last_post_user'] = (!empty($new_instance['show_last_post_user'])) ? strip_tags($new_instance['show_last_post_user']) : '';
187 $instance['show_last_activity'] = (!empty($new_instance['show_last_activity'])) ? strip_tags($new_instance['show_last_activity']) : '';
188 $instance['show_subscribe'] = (!empty($new_instance['show_subscribe'])) ? strip_tags($new_instance['show_subscribe']) : '';
189
190 return $instance;
191 }
192 }
193