PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
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 beta-4, at wpf-includes/functions-template.php

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