PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.4.1
Forumax – AI Powered Advanced Community Forum Plugin v1.4.1
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.4.1, at widgets/forum-info/Forum_Information.php

187 lines 10.0 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 wp_kses_post( $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 wp_kses_post( $args['before_title'] . $title . $args['after_title'] );
43 }
44
45 if ( $show_topics_count == 'on' || $show_replies_count == 'on' || $show_last_post_user == 'on' || $show_last_activity == 'on' || $show_subscribe == 'on') :
46 ?>
47 <div class="bbpc-widget-forum-info bs-sm">
48 <table>
49 <tbody>
50 <?php
51 if ( $show_topics_count == 'on' ) :
52 ?>
53 <tr class="show_count_topics">
54 <th>
55 <?php
56 if( $show_icons == 'on' ) :
57 ?>
58 <i class="icon_documents"></i>
59 <?php
60 endif;
61 esc_html_e( 'Topics', 'bbp-core' );
62 ?>
63 </th>
64 <td><?php echo esc_html($topic_count); ?></td>
65 </tr>
66 <?php
67 endif;
68
69 if ( $show_replies_count == 'on' ) :
70 ?>
71 <tr class="show_count_replies">
72 <th>
73 <?php
74 if( $show_icons == 'on' ) :
75 ?>
76 <i class="icon_chat_alt"></i>
77 <?php
78 endif;
79 esc_html_e( 'Replies', 'bbp-core' );
80 ?>
81 </th>
82 <td><?php echo esc_html($reply_count); ?></td>
83 </tr>
84 <?php
85 endif;
86
87 if ( $show_last_post_user == 'on' ) :
88 ?>
89 <tr class="show_last_post_user">
90 <th>
91 <?php
92 if ( $show_icons == 'on' ) :
93 ?>
94 <img src="<?php echo esc_url( BBPC_IMG . 'avatar.svg' ) ?>" alt="<?php esc_attr_e( 'BBP Core Pro avatar icon', 'bbp-core' ); ?>">
95 <?php
96 endif;
97 esc_html_e( 'Last post by', 'bbp-core' );
98 ?>
99 </th>
100 <td>
101 <a href="<?php echo esc_url( get_author_posts_url( $last_active_user ) ); ?>">
102 <?php echo esc_html( get_the_author_meta( 'user_nicename', $last_active_user ) ); ?>
103 </a>
104 </td>
105 </tr>
106 <?php
107 endif;
108
109 if ( $show_last_activity == 'on' ) :
110 ?>
111 <tr class="show_last_activity">
112 <th>
113 <?php
114 if( $show_icons == 'on' ) :
115 ?>
116 <i class="icon_clock_alt"></i>
117 <?php
118 endif;
119 esc_html_e( 'Last activity', 'bbp-core' );
120 ?>
121 </th>
122 <td> <?php echo esc_html( $last_active ); ?> </td>
123 </tr>
124 <?php
125 endif;
126
127 if ( $show_subscribe == 'on' ) :
128 wp_enqueue_script( 'bbpc-wp-widget' );
129 ?>
130 <tr class="show_subscribe">
131 <th>
132 <?php
133 if( $show_icons == 'on' ) :
134 ?>
135 <i class="icon_action"></i>
136 <?php
137 endif;
138 esc_html_e( 'Actions', 'bbp-core' );
139 ?>
140 </th>
141 <td>
142 <?php
143 if( is_user_logged_in() ){
144 echo wp_kses_post( bbp_get_forum_subscription_link() );
145 } else {
146 echo wp_kses_post( '<a href="'. wp_login_url(get_permalink()) .'">'. esc_html__('Login to subscribe', 'bbp-core') .'</a>' );
147 }
148 ?>
149 </td>
150 </tr>
151 <?php
152 endif;
153 ?>
154 </tbody>
155 </table>
156 </div>
157 <?php
158 endif;
159 endif;
160
161 echo wp_kses_post( $args['after_widget'] );
162 }
163
164 public function form( $instance ) {
165 $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
166 $show_icons = isset( $instance['show_icons'] ) ? esc_attr( $instance['show_icons'] ) : '';
167 $show_topics_count = isset( $instance['show_topics_count'] ) ? esc_attr( $instance['show_topics_count'] ) : '';
168 $show_replies_count = isset( $instance['show_replies_count'] ) ? esc_attr( $instance['show_replies_count'] ) : '';
169 $show_last_post_user = isset( $instance['show_last_post_user'] ) ? esc_attr( $instance['show_last_post_user'] ) : '';
170 $show_last_activity = isset( $instance['show_last_activity'] ) ? esc_attr( $instance['show_last_activity'] ) : '';
171 $show_subscribe = isset( $instance['show_subscribe'] ) ? esc_attr( $instance['show_subscribe'] ) : '';
172 require plugin_dir_path(__FILE__) . 'admin-options.php';
173 }
174
175 public function update($new_instance, $old_instance){
176 $instance = array();
177 $instance['title'] = (!empty($new_instance['title'])) ? wp_strip_all_tags($new_instance['title']) : '';
178 $instance['show_icons'] = (!empty($new_instance['show_icons'])) ? wp_strip_all_tags($new_instance['show_icons']) : '';
179 $instance['show_topics_count'] = (!empty($new_instance['show_topics_count'])) ? wp_strip_all_tags($new_instance['show_topics_count']) : '';
180 $instance['show_replies_count'] = (!empty($new_instance['show_replies_count'])) ? wp_strip_all_tags($new_instance['show_replies_count']) : '';
181 $instance['show_last_post_user'] = (!empty($new_instance['show_last_post_user'])) ? wp_strip_all_tags($new_instance['show_last_post_user']) : '';
182 $instance['show_last_activity'] = (!empty($new_instance['show_last_activity'])) ? wp_strip_all_tags($new_instance['show_last_activity']) : '';
183 $instance['show_subscribe'] = (!empty($new_instance['show_subscribe'])) ? wp_strip_all_tags($new_instance['show_subscribe']) : '';
184
185 return $instance;
186 }
187 }