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

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