PluginProbe
wpForo Forum / 1.2.0
wpForo Forum v1.2.0
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / functions-template.php

functions-template.php in wpForo Forum 1.2.0, at wpf-includes/functions-template.php

708 lines 29.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
6 register_nav_menus( array(
7 'wpforo-menu' => esc_html__( 'wpForo Menu', 'wpforo' ),
8 ) );
9
10
11 function wpforo_login_url(){
12 global $wpforo;
13 if(isset($wpforo->member_options['login_url']) && $wpforo->member_options['login_url']){
14 $wp_login_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member_options['login_url'] , '/');
15 }
16 else{
17 $wp_login_url = ((!is_wpforo_page() ? WPFORO_BASE_URL : '') . '?wpforo=signin');
18 }
19 return esc_url($wp_login_url);
20 }
21
22
23 function wpforo_register_url(){
24 global $wpforo;
25 if(isset($wpforo->member_options['register_url']) && $wpforo->member_options['register_url']){
26 $wp_register_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member_options['register_url'] , '/');
27 }
28 else{
29 $wp_register_url = WPFORO_BASE_URL . '?wpforo=signup';
30 }
31 return esc_url($wp_register_url);
32 }
33
34
35 function wpforo_lostpass_url(){
36 global $wpforo;
37 if(isset($wpforo->member_options['lost_password_url']) && $wpforo->member_options['lost_password_url']){
38 $wp_lostpass_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member_options['lost_password_url'] , '/');
39 }
40 else{
41 $wp_lostpass_url = wp_lostpassword_url( wpforo_get_request_uri() );
42 }
43 return esc_url($wp_lostpass_url);
44 }
45
46
47 function wpforo_menu_filter( $items, $menu ) {
48 global $wpforo;
49 if ( !wpforo_is_admin() ) {
50 foreach ( $items as $key => $item ) {
51 if(isset($item->url)){
52 if( strpos($item->url, '%wpforo-') !== FALSE ){
53 $shortcode = trim(str_replace(array('https://', 'http://', '/', '%'), '', $item->url));
54 if(isset($wpforo->menu) && isset($wpforo->menu[$shortcode])){
55 if(isset($wpforo->menu[$shortcode]['href'])) $item->url = $wpforo->menu[$shortcode]['href'];
56 if(isset($wpforo->menu[$shortcode]['attr']) && strpos($wpforo->menu[$shortcode]['attr'], 'wpforo-active') !== FALSE ) $item->classes[] = 'wpforo-active';
57 }
58 else{
59 unset($items[$key]);
60 }
61 }
62 }
63 }
64 }
65 return $items;
66 }
67 add_filter( 'wp_get_nav_menu_items', 'wpforo_menu_filter', 1, 2 );
68
69 function wpforo_menu_nofollow_items($item_output, $item, $depth, $args) {
70 if( isset($item->url) && strpos($item->url, '?wpforo') !== FALSE ) {
71 $item_output = str_replace('<a ', '<a rel="nofollow" ', $item_output);
72 }
73 return $item_output;
74 }
75 add_filter('walker_nav_menu_start_el', 'wpforo_menu_nofollow_items', 1, 4);
76
77 function wpforo_profile_plugin_menu( $userid = 0 ){
78
79 $menu_html = '<div class="wpf-profile-plugin-menu">';
80
81 if($url = wpforo_has_shop_plugin($userid)){
82 $menu_html .= '<div id="wpf-pp-shop-menu" class="wpf-pp-menu">
83 <a class="wpf-pp-menu-item" href="' . esc_url($url) . '">
84 <i class="fa fa-shopping-cart"></i><span>'.wpforo_phrase('Shop Account', false).'</span>
85 </a>
86 </div>';
87 }
88 if($url = wpforo_has_profile_plugin($userid)){
89 $menu_html .= '<div id="wpf-pp-site-menu" class="wpf-pp-menu">
90 <a class="wpf-pp-menu-item" href="' . esc_url($url) . '">
91 <i class="fa fa-user"></i>
92 <span>'.wpforo_phrase('Site Profile', false).'</span>
93 </a>
94 </div>';
95 }
96 $menu_html .= '<div id="wpf-pp-forum-menu" class="wpf-pp-menu">
97 <div class="wpf-pp-menu-item">
98 <i class="fa fa-comments"></i>
99 <span>'.wpforo_phrase('Forum Profile', false).'</span>
100 </div>
101 </div>';
102
103 $menu_html .= "\r\n<div class=\"wpf-clear\"></div>\r\n</div>";
104 $menu_html = apply_filters( 'wpforo_profile_plugin_menu_filter', $menu_html, $userid );
105 echo $menu_html; //This is a HTML content//
106 }
107 add_action( 'wpforo_profile_plugin_menu_action', 'wpforo_profile_plugin_menu', 1 );
108
109 class wpforo_menu_walker extends Walker_Nav_Menu {
110 public function start_lvl( &$output, $depth = 0, $args = array() ) {
111 $indent = str_repeat("\t", $depth);
112 $output .= "\n$indent<ul class=\"sub-menu\">\n";
113 }
114 public function end_lvl( &$output, $depth = 0, $args = array() ) {
115 $indent = str_repeat("\t", $depth);
116 $output .= "$indent</ul>\n";
117 }
118 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
119 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
120 $classes = empty( $item->classes ) ? array() : (array) $item->classes;
121 $classes[] = 'menu-item-' . $item->ID;
122 $args = apply_filters( 'wpforo_nav_menu_item_args', $args, $item, $depth );
123 $class_names = join( ' ', apply_filters( 'wpforo_nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
124 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
125 $id = apply_filters( 'wpforo_nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
126 $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
127 $output .= $indent . '<li' . $id . $class_names .'>';
128 $atts = array();
129 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
130 $atts['target'] = ! empty( $item->target ) ? $item->target : '';
131 $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
132 $atts['href'] = ! empty( $item->url ) ? $item->url : '';
133 $atts = apply_filters( 'wpforo_nav_menu_link_attributes', $atts, $item, $args, $depth );
134 $attributes = '';
135 foreach ( $atts as $attr => $value ) {
136 if ( ! empty( $value ) ) {
137 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
138 $attributes .= ' ' . $attr . '="' . $value . '"';
139 }
140 }
141 $title = apply_filters( 'wpforo_the_title', $item->title, $item->ID );
142 $title = apply_filters( 'wpforo_nav_menu_item_title', $title, $item, $args, $depth );
143 $item_output = $args->before;
144 $item_output .= '<a'. $attributes .'>';
145 $item_output .= $args->link_before . $title . $args->link_after;
146 $item_output .= '</a>';
147 $item_output .= $args->after;
148 $output .= apply_filters( 'wpforo_walker_nav_menu_start_el', $item_output, $item, $depth, $args );
149 }
150 public function end_el( &$output, $item, $depth = 0, $args = array() ) {
151 $output .= "</li>";
152 }
153 }
154
155 function wpforo_widgets_init() {
156 register_sidebar(array(
157 'name' => __('wpForo Sidebar', 'wpforo'),
158 'description' => __("NOTE: If you're going to add widgets in this sidebar, please use 'Full Width' template for wpForo index page to avoid sidebar duplication.", 'wpforo'),
159 'id' => 'forum-sidebar',
160 'before_widget' => '<aside id="%1$s" class="footer-widget-col %2$s clearfix">',
161 'after_widget' => '</aside>',
162 'before_title' => '<h3 class="widget-title">',
163 'after_title' => '</h3>',
164 ));
165 }
166 add_action('widgets_init', 'wpforo_widgets_init', 11);
167
168 class wpForo_Widget_search extends WP_Widget {
169 function __construct() {
170 parent::__construct(
171 'wpForo_Widget_search', // Base ID
172 'wpForo Search', // Name
173 array( 'description' => 'wpForo search form' ) // Args
174 );
175 }
176 public function widget( $args, $instance ) {
177 global $wpforo;
178 echo $args['before_widget']; //This is a HTML content//
179 echo '<div id="wpf-widget-search" class="wpforo-widget-wrap">';
180 if ( ! empty( $instance['title'] ) ) {
181 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; //This is a HTML content//
182 }
183 echo '<div class="wpforo-widget-content">';
184 ?>
185 <form action="<?php echo WPFORO_BASE_URL ?>" method="get">
186 <input type="text" placeholder="<?php wpforo_phrase('Search...') ?>" name="wpfs" class="wpfw-70" value="<?php echo isset($_GET['wpfs']) ? esc_attr(sanitize_text_field($_GET['wpfs'])) : '' ?>" ><input type="submit" class="wpfw-20" value="&raquo;">
187 </form>
188 <?php
189 echo '</div></div>';
190 echo $args['after_widget']; //This is a HTML content//
191 }
192 public function form( $instance ) {
193 $title = isset( $instance['title'] ) ? $instance['title'] : 'Forum Search';
194 ?>
195 <p>
196 <label><?php _e('Title', 'wpforo'); ?>:</label>
197 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
198 </p>
199 <?php
200 }
201 public function update( $new_instance, $old_instance ) {
202 $instance = array();
203 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
204 return $instance;
205 }
206 } // widget wpforo search
207
208 class wpForo_Widget_login_form extends WP_Widget {
209 function __construct() {
210 parent::__construct(
211 'wpForo_Widget_login_form', // Base ID
212 'wpForo Login Form', // Name
213 array( 'description' => 'wpForo login form' ) // Args
214 );
215 }
216 public function widget( $args, $instance ) {
217 global $wpforo;
218 echo $args['before_widget']; //This is a HTML content//
219 echo '<div id="wpf-widget-login" class="wpforo-widget-wrap">';
220 if ( ! empty( $instance['title'] ) ) {
221 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; //This is a HTML content//
222 }
223 echo '<div class="wpforo-widget-content">';
224 ?>
225 <?php if( is_user_logged_in() && !empty($wpforo->current_user) ) : ?>
226 <?php extract($wpforo->current_object, EXTR_OVERWRITE); extract($wpforo->current_user, EXTR_OVERWRITE); ?>
227 <div class="wpforo-profile-wrap">
228 <div class="wpforo-profile-head">
229 <div class="h-header">
230 <?php if( wpforo_feature('avatars', $wpforo) ): $rsz =''; ?>
231 <div class="h-left"><?php echo $wpforo->member->get_avatar($userid, 'alt="'.esc_attr($display_name).'"', 150); ?></div>
232 <?php else: $rsz = ' style="margin-left:10px;"'; endif; ?>
233 <div class="h-right" <?php echo $rsz; ?>>
234 <div class="h-top">
235 <div class="profile-display-name">
236 <?php $wpforo->member->show_online_indicator($userid) ?>
237 <?php echo $display_name ? esc_html($display_name) : esc_html(urldecode($user_nicename)) ?>
238 </div>
239 <div class="profile-stat-data">
240 <div class="profile-stat-data-item"><?php wpforo_phrase('Group') ?>: <?php wpforo_phrase($groupname) ?></div>
241 <div class="profile-stat-data-item"><?php wpforo_phrase('Joined') ?>: <?php esc_html(wpforo_date($user_registered, 'Y/m/d')) ?></div>
242 </div>
243 </div>
244 </div>
245 <div class="wpf-clear"></div>
246 </div>
247 <div class="h-footer wpfbg-2">
248
249 <div class="h-bottom">
250 <?php $wpforo->tpl->member_menu($userid) ?>
251 <a href="?wpforo=logout"><?php wpforo_phrase('logout') ?></a>
252 <div class="wpf-clear"></div>
253 </div>
254 </div>
255 </div>
256 </div>
257
258 <?php else : ?>
259
260 <form name="wpflogin" action="" method="POST">
261 <div class="wpforo-login-wrap">
262 <div class="wpforo-login-content">
263 <table class="wpforo-login-table wpfcl-1" width="100%" border="0" cellspacing="0" cellpadding="0">
264 <tr class="wpfbg-9">
265 <td class="wpf-login-label">
266 <p class="wpf-label wpfcl-1"><?php wpforo_phrase('Username') ?>:</p>
267 </td>
268 <td class="wpf-login-field"><input autofocus required="TRUE" type="text" name="log" class="wpf-login-text wpfw-60" /></td>
269 </tr>
270 <tr class="wpfbg-9">
271 <td class="wpf-login-label">
272 <p class="wpf-label wpfcl-1"><?php wpforo_phrase('Password') ?>:</p>
273 </td>
274 <td class="wpf-login-field"><input required="TRUE" type="password" name="pwd" class="wpf-login-text wpfw-60" /></td>
275 </tr>
276 <tr class="wpfbg-9"><td colspan="2" style="text-align: center;"><?php do_action('login_form') ?></td></tr>
277 <tr class="wpfbg-9">
278 <td class="wpf-login-label">&nbsp;</td>
279 <td class="wpf-login-field">
280 <p class="wpf-extra wpfcl-1">
281 <input type="checkbox" value="1" name="rememberme" id="wpf-login-remember">
282 <label for="wpf-login-remember"><?php wpforo_phrase('Remember Me') ?> |</label>
283 <a href="<?php echo esc_url(wp_lostpassword_url(wpforo_get_request_uri())); ?>" class="wpf-forgot-pass"><?php wpforo_phrase('Lost your password?') ?></a>
284 <a href="<?php echo esc_url(WPFORO_BASE_URL) ?>?wpforo=register"><?php wpforo_phrase('register') ?></a>
285 </p>
286 <input type="submit" name="wpforologin" value="<?php wpforo_phrase('Sign In') ?>" />
287 </td>
288 </tr>
289 </table>
290 </div>
291 </div>
292 </form>
293
294 <?php endif ?>
295 <?php
296 echo '</div></div>';
297 echo $args['after_widget'];
298 }
299 public function form( $instance ) {
300 $title = isset( $instance['title'] ) ? $instance['title'] : 'Account';
301 ?>
302 <p>
303 <label><?php _e('Title', 'wpforo'); ?>:</label>
304 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
305 </p>
306 <?php
307 }
308 public function update( $new_instance, $old_instance ) {
309 $instance = array();
310 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
311 return $instance;
312 }
313 } // widget wpforo login
314
315
316 class wpForo_Widget_online_members extends WP_Widget {
317 function __construct() {
318 parent::__construct(
319 'wpForo_Widget_online_members', // Base ID
320 'wpForo Online Members', // Name
321 array( 'description' => 'Online members.' ) // Args
322 );
323 }
324 public function widget( $args, $instance ) {
325 global $wpforo;
326 echo $args['before_widget']; //This is a HTML content//
327 echo '<div id="wpf-widget-online-users" class="wpforo-widget-wrap">';
328 if ( ! empty( $instance['title'] ) ) {
329 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
330 }
331 // widget content from front end
332 $online_members = $wpforo->member->get_online_members($instance['count']);
333 echo '<div class="wpforo-widget-content">';
334 if(!empty($online_members)){
335 echo '<ul>
336 <li>
337 <div class="wpforo-list-item">';
338 foreach( $online_members as $member ){
339 if( $instance['display_avatar'] ): ?>
340 <a href="<?php echo esc_url($wpforo->member->get_profile_url( $member['ID'] )) ?>" class="onlineavatar">
341 <?php echo $wpforo->member->get_avatar( $member['ID'], 'style="width:95%;" class="avatar" title="'.esc_attr($member['display_name']).'"'); ?>
342 </a>
343 <?php else: ?>
344 <a href="<?php echo esc_url($wpforo->member->get_profile_url( $member['ID'] )) ?>" class="onlineuser"><?php echo esc_html($member['display_name']) ?></a>
345 <?php endif; ?>
346 <?php
347 }
348 echo '<div class="wpf-clear"></div>
349 </div>
350 </li>
351 </ul>
352 </div>';
353 }
354 else{
355 echo '<p class="wpf-widget-note">&nbsp;'.wpforo_phrase('No online members at the moment', false).'</p>';
356 }
357 echo '</div>';
358 echo $args['after_widget'];//This is a HTML content//
359 }
360 public function form( $instance ) {
361 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Online Members';
362 $count = ! empty( $instance['count'] ) ? $instance['count'] : '15';
363 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
364 ?>
365 <p>
366 <label><?php _e('Title', 'wpforo'); ?>:</label>
367 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
368 </p><p>
369 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
370 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr( $count ) ; ?>">
371 </p><p>
372 <label>
373 <input<?php checked( $display_avatar ); ?> type="checkbox" value="1" name="<?php echo esc_attr( $this->get_field_name( 'display_avatar' )); ?>"/>
374 <?php _e('Display Avatars', 'wpforo'); ?>
375 </label>
376 </p>
377 <?php
378 }
379 public function update( $new_instance, $old_instance ) {
380 $instance = array();
381 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
382 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
383 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
384 return $instance;
385 }
386 } // widget online members
387
388 class wpForo_Widget_recent_topics extends WP_Widget {
389 function __construct() {
390 parent::__construct(
391 'wpForo_Widget_recent_topics', // Base ID
392 'wpForo Recent Topics', // Name
393 array( 'description' => 'Your forum\'s recent topics.' ) // Args
394 );
395 }
396 public function widget( $args, $instance ) {
397 global $wpforo;
398 echo $args['before_widget'];//This is a HTML content//
399 echo '<div id="wpf-widget-recent-replies" class="wpforo-widget-wrap">';
400 if ( ! empty( $instance['title'] ) ) {
401 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
402 }
403 // widget content from front end
404 $topic_args = array( // forumid, order, parentid
405 'orderby' => 'created',
406 'order' => 'DESC', // ASC DESC
407 'row_count' => $instance['count'] // 4 or 1 ...
408 );
409 $topics = $wpforo->topic->get_topics($topic_args);
410 echo '<div class="wpforo-widget-content"><ul>';
411 foreach( $topics as $topic ){
412 if( !$wpforo->perm->forum_can( 'vf', $topic['forumid'] ) ) continue;
413 $topic_url = $wpforo->topic->get_topic_url( $topic );
414 $member = $wpforo->member->get_member( $topic['userid'] );
415 ?>
416 <li>
417 <div class="wpforo-list-item">
418 <?php if( $instance['display_avatar'] ): ?>
419 <div class="wpforo-list-item-left">
420 <?php echo $wpforo->member->get_avatar( $topic['userid']); ?>
421 </div>
422 <?php endif; ?>
423 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
424 <p class="posttitle"><a href="<?php echo esc_url($topic_url) ?>"><?php echo esc_html($topic['title']) ?></a></p>
425 <p class="postuser"><?php wpforo_phrase('by') ?> <a href="<?php echo esc_url($wpforo->member->profile_url($member)) ?>"><?php echo esc_html($member['display_name']) ?></a>, <span style="white-space:nowrap;"><?php esc_html(wpforo_date($topic['created'])) ?></span></p>
426 </div>
427 <div class="wpf-clear"></div>
428 </div>
429 </li>
430 <?php
431 }
432 echo '</ul></div>';
433 echo '</div>';
434 echo $args['after_widget'];//This is a HTML content//
435 }
436 public function form( $instance ) {
437 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Topics';
438 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
439 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
440 ?>
441 <p>
442 <label><?php _e('Title', 'wpforo'); ?>:</label>
443 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
444 </p><p>
445 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
446 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
447 </p><p>
448 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
449 <?php _e('Display with Avatars', 'wpforo'); ?></label>
450 </p>
451 <?php
452 }
453 public function update( $new_instance, $old_instance ) {
454 $instance = array();
455 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
456 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
457 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
458 return $instance;
459 }
460 } // Recent topics
461
462
463 class wpForo_Widget_recent_replies extends WP_Widget {
464 function __construct() {
465 parent::__construct(
466 'wpForo_Widget_recent_replies', // Base ID
467 'wpForo Recent Posts', // Name
468 array( 'description' => 'Your forum\'s recent posts.' ) // Args
469 );
470 }
471
472 public function widget( $args, $instance ) {
473 global $wpforo;
474 echo $args['before_widget'];//This is a HTML content//
475 echo '<div id="wpf-widget-recent-replies" class="wpforo-widget-wrap">';
476 if ( ! empty( $instance['title'] ) ) {
477 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
478 }
479 // widget content from front end
480 $posts_args = array(
481 'orderby' => 'created',
482 'order' => 'DESC',
483 'row_count' => $instance['count'],
484 'check_private' => true
485 );
486 $recent_posts = $wpforo->post->get_posts($posts_args);
487 echo '<div class="wpforo-widget-content"><ul>';
488 foreach( $recent_posts as $post ){
489 if( !$wpforo->perm->forum_can( 'vf', $post['forumid'] ) ) continue;
490 $post_url = $wpforo->post->get_post_url( $post );
491 $member = $wpforo->member->get_member( $post['userid'] );
492 ?>
493 <li>
494 <div class="wpforo-list-item">
495 <?php if( $instance['display_avatar'] ): ?>
496 <div class="wpforo-list-item-left">
497 <?php echo $wpforo->member->get_avatar( $post['userid']); ?>
498 </div>
499 <?php endif; ?>
500 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
501 <p class="posttitle"><a href="<?php echo esc_url($post_url) ?>"><?php echo esc_html($post['title']) ?></a></p>
502 <p class="posttext"><?php echo esc_html(wpforo_text($post['body'], 55)); ?></p>
503 <p class="postuser"><?php wpforo_phrase('by') ?> <a href="<?php echo esc_url($wpforo->member->profile_url($member)) ?>"><?php echo esc_html($member['display_name']) ?></a>, <?php esc_html(wpforo_date($post['created'])) ?></p>
504 </div>
505 <div class="wpf-clear"></div>
506 </div>
507 </li>
508 <?php
509 }
510 echo '</ul></div>';
511 echo '</div>';
512 echo $args['after_widget'];//This is a HTML content//
513 }
514 public function form( $instance ) {
515 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Posts';
516 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
517 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
518 ?>
519 <p>
520 <label><?php _e('Title', 'wpforo'); ?>:</label>
521 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
522 </p><p>
523 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
524 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
525 </p><p>
526 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
527 <?php _e('Display with Avatars', 'wpforo'); ?></label>
528 </p>
529 <?php
530 }
531 public function update( $new_instance, $old_instance ) {
532 $instance = array();
533 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
534 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
535 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
536 return $instance;
537 }
538 } // Recent replies
539
540
541 class wpforo_widget_forums extends WP_Widget {
542 function __construct() {
543 parent::__construct(
544 'wpforo_widget_forums', // Base ID
545 'wpForo Forums', // Name
546 array( 'description' => 'Forum tree.' ) // Args
547 );
548 }
549 public function widget( $args, $instance ) {
550 global $wpforo;
551 echo $args['before_widget'];//This is a HTML content//
552 echo '<div id="wpf-widget-forums" class="wpforo-widget-wrap">';
553 if ( ! empty( $instance['title'] ) ) {
554 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
555 }
556 echo '<div class="wpforo-widget-content">';
557 $wpforo->forum->tree('front_list');
558 echo '</div>';
559 echo '</div>';
560 echo $args['after_widget'];//This is a HTML content//
561 }
562 public function form( $instance ) {
563 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Forums';
564 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
565 ?>
566 <p>
567 <label><?php _e('Title', 'wpforo'); ?>:</label>
568 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
569 </p>
570 <?php
571 }
572 public function update( $new_instance, $old_instance ) {
573 $instance = array();
574 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
575 return $instance;
576 }
577 } // forums tree
578
579
580 function wpforo_widget_search() {
581 register_widget( 'wpForo_Widget_search' );
582 }
583 add_action( 'widgets_init', 'wpforo_widget_search' );
584
585 function wpforo_widget_login() {
586 //Under development....
587 //register_widget( 'wpForo_Widget_login_form' );
588 }
589 add_action( 'widgets_init', 'wpforo_widget_login' );
590
591 function wpforo_widget_online_members() {
592 register_widget( 'wpForo_Widget_online_members' );
593 }
594 add_action( 'widgets_init', 'wpforo_widget_online_members' );
595
596 function wpforo_widget_recent_topics() {
597 register_widget( 'wpForo_Widget_recent_topics' );
598 }
599 add_action( 'widgets_init', 'wpforo_widget_recent_topics' );
600
601 function wpforo_widget_recent_replies() {
602 register_widget( 'wpForo_Widget_recent_replies' );
603 }
604 add_action( 'widgets_init', 'wpforo_widget_recent_replies' );
605
606 function wpforo_widget_forums() {
607 //Under Development
608 //register_widget( 'wpforo_widget_forums' );
609 }
610 add_action( 'widgets_init', 'wpforo_widget_forums' );
611
612 function wpforo_post_edited($post, $echo = true){
613 $edit_html = '';
614 if(!empty($post)){
615 $created = wpforo_date($post['created'], 'd/m/Y g:i a', false);
616 $modified = wpforo_date($post['modified'], 'd/m/Y g:i a', false);
617 if( isset($modified) && $created != $modified ){
618 $edit_html = '<div class="wpf-post-edited">' . wpforo_phrase('Edited: ', false) . wpforo_date($post['modified'], 'ago', false) . '</div>';
619 }
620 }
621 if( $echo ) {
622 echo $edit_html;
623 }
624 else{
625 return $edit_html;
626 }
627 }
628
629 function wpforo_hide_title($title, $id = 0) {
630 global $wpforo;
631 if( !wpforo_feature('page-title', $wpforo) ){
632 if( $wpforo_base_slug = basename(WPFORO_BASE_URL) ) $wpforo_page = get_page_by_path($wpforo_base_slug);
633 if(!empty($wpforo_page)){
634 if (in_the_loop() && is_page($wpforo_page->ID) && $id == get_the_ID()) {
635 $title = '';
636 }
637 }
638 }
639 return $title;
640 }
641 add_filter('the_title', 'wpforo_hide_title', 10, 2);
642
643
644 function wpforo_validate_gravatar( $email ) {
645 $hashkey = md5(strtolower(trim($email)));
646 $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
647 $data = wp_cache_get($hashkey);
648 if (false === $data) {
649 $response = wp_remote_head($uri);
650 if( is_wp_error($response) ) {
651 $data = 'not200';
652 } else {
653 $data = $response['response']['code'];
654 }
655 wp_cache_set($hashkey, $data, $group = '', $expire = 60*5);
656 }
657 if ($data == '200'){
658 return true;
659 } else {
660 return false;
661 }
662 }
663
664 function wpforo_member_title( $member = array(), $echo = true, $usergroup = true ){
665 global $wpforo;
666 if(empty($member) || !$member['groupid']) return;
667 $enabled_for_usergroup = ( isset($wpforo->member_options['rating_title_ug'][$member['groupid']]) && $wpforo->member_options['rating_title_ug'][$member['groupid']] ) ? true : false ;
668
669 if( wpforo_feature('rating_title', $wpforo) && $enabled_for_usergroup ){
670 $title = esc_html($member['stat']['title']);
671 }
672 else{
673 $title = wpforo_phrase($member['title']);
674 }
675
676 if( $echo ) {
677 echo $title;
678 }
679 else{
680 return $title;
681 }
682 }
683
684 function wpforo_member_badge( $member = array(), $sep = '', $type = 'full' ){
685 global $wpforo;
686 $enabled_for_usergroup = ( isset($wpforo->member_options['rating_badge_ug'][$member['groupid']]) && $wpforo->member_options['rating_badge_ug'][$member['groupid']] ) ? true : false ;
687 if( wpforo_feature('rating', $wpforo) && $enabled_for_usergroup ): ?>
688 <div class="author-rating-<?php echo esc_attr($type) ?>" style="color:<?php echo esc_attr($member['stat']['color']) ?>" title="<?php wpforo_phrase('Member Rating Badge') ?>">
689 <?php echo $wpforo->member->rating_badge($member['stat']['rating'], $type); ?>
690 </div><?php if($sep): ?><span class="author-rating-sep"><?php echo esc_html($sep); ?></span><?php endif; ?>
691 <?php endif;
692
693 do_action('wpforo_after_member_badge', $member);
694 }
695
696 add_filter( 'body_class', 'wpforo_page_class', 1, 10 );
697 function wpforo_page_class( $classes ) {
698 if(!empty($classes)){
699 if( function_exists('is_wpforo_page') ){
700 if ( is_wpforo_page() ) {
701 return array_merge( $classes, array( 'wpforo' ) );
702 }
703 }
704 }
705 return (array)$classes;
706 }
707
708 ?>