PluginProbe
wpForo Forum / 1.1.1
wpForo Forum v1.1.1
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.1.1, at wpf-includes/functions-template.php

693 lines 29.1 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', // forumid, order, parentid
482 'order' => 'DESC', // ASC DESC
483 'row_count' => $instance['count'] // 4 or 1 ...
484 );
485 $recent_posts = $wpforo->post->get_posts($posts_args);
486 echo '<div class="wpforo-widget-content"><ul>';
487 foreach( $recent_posts as $post ){
488 if( !$wpforo->perm->forum_can( 'vf', $post['forumid'] ) ) continue;
489 $post_url = $wpforo->post->get_post_url( $post );
490 $member = $wpforo->member->get_member( $post['userid'] );
491 ?>
492 <li>
493 <div class="wpforo-list-item">
494 <?php if( $instance['display_avatar'] ): ?>
495 <div class="wpforo-list-item-left">
496 <?php echo $wpforo->member->get_avatar( $post['userid']); ?>
497 </div>
498 <?php endif; ?>
499 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
500 <p class="posttitle"><a href="<?php echo esc_url($post_url) ?>"><?php echo esc_html($post['title']) ?></a></p>
501 <p class="posttext"><?php echo esc_html(wpforo_text($post['body'], 55)); ?></p>
502 <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>
503 </div>
504 <div class="wpf-clear"></div>
505 </div>
506 </li>
507 <?php
508 }
509 echo '</ul></div>';
510 echo '</div>';
511 echo $args['after_widget'];//This is a HTML content//
512 }
513 public function form( $instance ) {
514 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Posts';
515 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
516 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
517 ?>
518 <p>
519 <label><?php _e('Title', 'wpforo'); ?>:</label>
520 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
521 </p><p>
522 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
523 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
524 </p><p>
525 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
526 <?php _e('Display with Avatars', 'wpforo'); ?></label>
527 </p>
528 <?php
529 }
530 public function update( $new_instance, $old_instance ) {
531 $instance = array();
532 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
533 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
534 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
535 return $instance;
536 }
537 } // Recent replies
538
539
540 class wpforo_widget_forums extends WP_Widget {
541 function __construct() {
542 parent::__construct(
543 'wpforo_widget_forums', // Base ID
544 'wpForo Forums', // Name
545 array( 'description' => 'Forum tree.' ) // Args
546 );
547 }
548 public function widget( $args, $instance ) {
549 global $wpforo;
550 echo $args['before_widget'];//This is a HTML content//
551 echo '<div id="wpf-widget-forums" class="wpforo-widget-wrap">';
552 if ( ! empty( $instance['title'] ) ) {
553 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
554 }
555 echo '<div class="wpforo-widget-content">';
556 $wpforo->forum->tree('front_list');
557 echo '</div>';
558 echo '</div>';
559 echo $args['after_widget'];//This is a HTML content//
560 }
561 public function form( $instance ) {
562 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Forums';
563 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
564 ?>
565 <p>
566 <label><?php _e('Title', 'wpforo'); ?>:</label>
567 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
568 </p>
569 <?php
570 }
571 public function update( $new_instance, $old_instance ) {
572 $instance = array();
573 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
574 return $instance;
575 }
576 } // forums tree
577
578
579 function wpforo_widget_search() {
580 register_widget( 'wpForo_Widget_search' );
581 }
582 add_action( 'widgets_init', 'wpforo_widget_search' );
583
584 function wpforo_widget_login() {
585 //Under development....
586 //register_widget( 'wpForo_Widget_login_form' );
587 }
588 add_action( 'widgets_init', 'wpforo_widget_login' );
589
590 function wpforo_widget_online_members() {
591 register_widget( 'wpForo_Widget_online_members' );
592 }
593 add_action( 'widgets_init', 'wpforo_widget_online_members' );
594
595 function wpforo_widget_recent_topics() {
596 register_widget( 'wpForo_Widget_recent_topics' );
597 }
598 add_action( 'widgets_init', 'wpforo_widget_recent_topics' );
599
600 function wpforo_widget_recent_replies() {
601 register_widget( 'wpForo_Widget_recent_replies' );
602 }
603 add_action( 'widgets_init', 'wpforo_widget_recent_replies' );
604
605 function wpforo_widget_forums() {
606 //Under Development
607 //register_widget( 'wpforo_widget_forums' );
608 }
609 add_action( 'widgets_init', 'wpforo_widget_forums' );
610
611 function wpforo_post_edited($post, $echo = true){
612 $edit_html = '';
613 if(!empty($post)){
614 $created = wpforo_date($post['created'], 'd/m/Y g:i a', false);
615 $modified = wpforo_date($post['modified'], 'd/m/Y g:i a', false);
616 if( isset($modified) && $created != $modified ){
617 $edit_html = '<div class="wpf-post-edited">' . wpforo_phrase('Edited: ', false) . wpforo_date($post['modified'], 'ago', false) . '</div>';
618 }
619 }
620 if( $echo ) {
621 echo $edit_html;
622 }
623 else{
624 return $edit_html;
625 }
626 }
627
628 function wpforo_hide_title($title, $id = 0) {
629 global $wpforo;
630 if( !wpforo_feature('page-title', $wpforo) ){
631 if( $wpforo_base_slug = basename(WPFORO_BASE_URL) ) $wpforo_page = get_page_by_path($wpforo_base_slug);
632 if(!empty($wpforo_page)){
633 if (in_the_loop() && is_page($wpforo_page->ID) && $id == get_the_ID()) {
634 $title = '';
635 }
636 }
637 }
638 return $title;
639 }
640 add_filter('the_title', 'wpforo_hide_title', 10, 2);
641
642
643 function wpforo_validate_gravatar( $email ) {
644 $hashkey = md5(strtolower(trim($email)));
645 $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
646 $data = wp_cache_get($hashkey);
647 if (false === $data) {
648 $response = wp_remote_head($uri);
649 if( is_wp_error($response) ) {
650 $data = 'not200';
651 } else {
652 $data = $response['response']['code'];
653 }
654 wp_cache_set($hashkey, $data, $group = '', $expire = 60*5);
655 }
656 if ($data == '200'){
657 return true;
658 } else {
659 return false;
660 }
661 }
662
663 function wpforo_member_title( $member = array(), $echo = true ){
664 global $wpforo;
665 if(empty($member) || !$member['groupid']) return;
666 $enabled_for_usergroup = ( isset($wpforo->member_options['rating_title_ug'][$member['groupid']]) && $wpforo->member_options['rating_title_ug'][$member['groupid']] ) ? true : false ;
667
668 if( wpforo_feature('rating_title', $wpforo) && $enabled_for_usergroup ){
669 $title = esc_html($member['stat']['title']);
670 }
671 else{
672 $title = wpforo_phrase($member['title']);
673 }
674
675 if( $echo ) {
676 echo $title;
677 }
678 else{
679 return $title;
680 }
681 }
682
683 function wpforo_member_badge( $member = array(), $sep = '', $type = 'full' ){
684 global $wpforo;
685 $enabled_for_usergroup = ( isset($wpforo->member_options['rating_badge_ug'][$member['groupid']]) && $wpforo->member_options['rating_badge_ug'][$member['groupid']] ) ? true : false ;
686 if( wpforo_feature('rating', $wpforo) && $enabled_for_usergroup ): ?>
687 <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') ?>">
688 <?php echo $wpforo->member->rating_badge($member['stat']['rating'], $type); ?>
689 </div><?php if($sep): ?><span class="author-rating-sep"><?php echo esc_html($sep); ?></span><?php endif; ?>
690 <?php endif;
691 }
692
693 ?>