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

1,197 lines 47.4 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 }else{
16 $request_uri = preg_replace( '#/?\?.*$#isu', '', wpforo_get_request_uri() );
17 $wp_login_url = (!is_wpforo_page() ? wpforo_home_url('?wpforo=signin') : wpforo_home_url( $request_uri . '?wpforo=signin' ) );
18 }
19
20 return esc_url($wp_login_url);
21 }
22
23
24 function wpforo_register_url(){
25 global $wpforo;
26 if(isset($wpforo->member->options['register_url']) && $wpforo->member->options['register_url']){
27 $wp_register_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member->options['register_url'] , '/');
28 }
29 else{
30 $wp_register_url = wpforo_home_url('?wpforo=signup');
31 }
32 return esc_url($wp_register_url);
33 }
34
35
36 function wpforo_lostpass_url(){
37 global $wpforo;
38 if(isset($wpforo->member->options['lost_password_url']) && $wpforo->member->options['lost_password_url']){
39 $wp_lostpass_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member->options['lost_password_url'] , '/');
40 }
41 else{
42 $wp_lostpass_url = wp_lostpassword_url( wpforo_get_request_uri() );
43 }
44 return esc_url($wp_lostpass_url);
45 }
46
47
48 function wpforo_menu_filter( $items, $menu ) {
49 global $wpforo;
50 if ( !wpforo_is_admin() ) {
51 foreach ( $items as $key => $item ) {
52 if(isset($item->url)){
53 if( strpos($item->url, '%wpforo-') !== FALSE ){
54 $shortcode = trim(str_replace(array('https://', 'http://', '/', '%'), '', $item->url));
55 if(isset($wpforo->menu) && isset($wpforo->menu[$shortcode])){
56 if(isset($wpforo->menu[$shortcode]['href'])) $item->url = $wpforo->menu[$shortcode]['href'];
57 if(isset($wpforo->menu[$shortcode]['attr']) && strpos($wpforo->menu[$shortcode]['attr'], 'wpforo-active') !== FALSE ) $item->classes[] = 'wpforo-active';
58 }
59 else{
60 unset($items[$key]);
61 }
62 }
63 }
64 }
65 }
66 return $items;
67 }
68 add_filter( 'wp_get_nav_menu_items', 'wpforo_menu_filter', 1, 2 );
69
70 function wpforo_menu_nofollow_items($item_output, $item, $depth, $args) {
71 if( isset($item->url) && strpos($item->url, '?wpforo') !== FALSE ) {
72 $item_output = str_replace('<a ', '<a rel="nofollow" ', $item_output);
73 }
74 return $item_output;
75 }
76 add_filter('walker_nav_menu_start_el', 'wpforo_menu_nofollow_items', 1, 4);
77
78 function wpforo_profile_plugin_menu( $userid = 0 ){
79
80 $forum_profile = false;
81 if($url = wpforo_has_shop_plugin($userid)){
82 $forum_profile = true;
83 $menu_html .= '<div id="wpf-pp-shop-menu" class="wpf-pp-menu">
84 <a class="wpf-pp-menu-item" href="' . esc_url($url) . '">
85 <i class="fa fa-shopping-cart" title="'.wpforo_phrase('Shop Account', false).'"></i>
86 </a>
87 </div>';
88 }
89 if($url = wpforo_has_profile_plugin($userid)){
90 $forum_profile = true;
91 $menu_html .= '<div id="wpf-pp-site-menu" class="wpf-pp-menu">
92 <a class="wpf-pp-menu-item" href="' . esc_url($url) . '">
93 <i class="fa fa-user" title="'.wpforo_phrase('Site Profile', false).'"></i>
94 </a>
95 </div>';
96 }
97 if( $forum_profile ) {
98 $menu_html .= '<div id="wpf-pp-forum-menu" class="wpf-pp-menu">
99 <div class="wpf-pp-menu-item">
100 <i class="fa fa-comments" title="' . wpforo_phrase('Forum Profile', false) . '"></i>
101 </div>
102 </div>';
103 $menu_html = '<div class="wpf-profile-plugin-menu">';
104 $menu_html .= "\r\n<div class=\"wpf-clear\"></div>\r\n</div>";
105 $menu_html = apply_filters( 'wpforo_profile_plugin_menu_filter', $menu_html, $userid );
106 echo $menu_html; //This is a HTML content//
107 }
108 }
109 add_action( 'wpforo_profile_plugin_menu_action', 'wpforo_profile_plugin_menu', 1 );
110
111 class wpforo_menu_walker extends Walker_Nav_Menu {
112 public function start_lvl( &$output, $depth = 0, $args = array() ) {
113 $indent = str_repeat("\t", $depth);
114 $output .= "\n$indent<ul class=\"sub-menu\">\n";
115 }
116 public function end_lvl( &$output, $depth = 0, $args = array() ) {
117 $indent = str_repeat("\t", $depth);
118 $output .= "$indent</ul>\n";
119 }
120 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
121 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
122 $classes = empty( $item->classes ) ? array() : (array) $item->classes;
123 $classes[] = 'menu-item-' . $item->ID;
124 $args = apply_filters( 'wpforo_nav_menu_item_args', $args, $item, $depth );
125 $class_names = join( ' ', apply_filters( 'wpforo_nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
126 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
127 $id = apply_filters( 'wpforo_nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
128 $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
129 $output .= $indent . '<li' . $id . $class_names .'>';
130 $atts = array();
131 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
132 $atts['target'] = ! empty( $item->target ) ? $item->target : '';
133 $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
134 $atts['href'] = ! empty( $item->url ) ? $item->url : '';
135 $atts = apply_filters( 'wpforo_nav_menu_link_attributes', $atts, $item, $args, $depth );
136 $attributes = '';
137 foreach ( $atts as $attr => $value ) {
138 if ( ! empty( $value ) ) {
139 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
140 $attributes .= ' ' . $attr . '="' . $value . '"';
141 }
142 }
143 $title = apply_filters( 'wpforo_the_title', $item->title, $item->ID );
144 $title = apply_filters( 'wpforo_nav_menu_item_title', $title, $item, $args, $depth );
145 $item_output = $args->before;
146 $item_output .= '<a'. $attributes .'>';
147 $item_output .= $args->link_before . $title . $args->link_after;
148 $item_output .= '</a>';
149 $item_output .= $args->after;
150 $output .= apply_filters( 'wpforo_walker_nav_menu_start_el', $item_output, $item, $depth, $args );
151 }
152 public function end_el( &$output, $item, $depth = 0, $args = array() ) {
153 $output .= "</li>";
154 }
155 }
156
157 function wpforo_widgets_init() {
158 register_sidebar(array(
159 'name' => __('wpForo Sidebar', 'wpforo'),
160 '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'),
161 'id' => 'forum-sidebar',
162 'before_widget' => '<aside id="%1$s" class="footer-widget-col %2$s clearfix">',
163 'after_widget' => '</aside>',
164 'before_title' => '<h3 class="widget-title">',
165 'after_title' => '</h3>',
166 ));
167 }
168 add_action('widgets_init', 'wpforo_widgets_init', 11);
169
170 class wpForo_Widget_search extends WP_Widget {
171 function __construct() {
172 parent::__construct(
173 'wpForo_Widget_search', // Base ID
174 'wpForo Search', // Name
175 array( 'description' => 'wpForo search form' ) // Args
176 );
177 }
178 public function widget( $args, $instance ) {
179 global $wpforo;
180 echo $args['before_widget']; //This is a HTML content//
181 echo '<div id="wpf-widget-search" class="wpforo-widget-wrap">';
182 if ( ! empty( $instance['title'] ) ) {
183 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; //This is a HTML content//
184 }
185 echo '<div class="wpforo-widget-content">';
186 ?>
187 <form action="<?php echo wpforo_home_url() ?>" method="get">
188 <?php wpforo_make_hidden_fields_from_url( wpforo_home_url() ) ?>
189 <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;">
190 </form>
191 <?php
192 echo '</div></div>';
193 echo $args['after_widget']; //This is a HTML content//
194 }
195 public function form( $instance ) {
196 $title = isset( $instance['title'] ) ? $instance['title'] : 'Forum Search';
197 ?>
198 <p>
199 <label><?php _e('Title', 'wpforo'); ?>:</label>
200 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
201 </p>
202 <?php
203 }
204 public function update( $new_instance, $old_instance ) {
205 $instance = array();
206 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
207 return $instance;
208 }
209 } // widget wpforo search
210
211 class wpForo_Widget_login_form extends WP_Widget {
212 function __construct() {
213 parent::__construct(
214 'wpForo_Widget_login_form', // Base ID
215 'wpForo Login Form', // Name
216 array( 'description' => 'wpForo login form' ) // Args
217 );
218 }
219 public function widget( $args, $instance ) {
220 global $wpforo;
221 echo $args['before_widget']; //This is a HTML content//
222 echo '<div id="wpf-widget-login" class="wpforo-widget-wrap">';
223 if ( ! empty( $instance['title'] ) ) {
224 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; //This is a HTML content//
225 }
226 echo '<div class="wpforo-widget-content">';
227 ?>
228 <?php if( is_user_logged_in() && !empty($wpforo->current_user) ) : ?>
229 <?php extract($wpforo->current_object, EXTR_OVERWRITE); extract($wpforo->current_user, EXTR_OVERWRITE); ?>
230 <div class="wpforo-profile-wrap">
231 <div class="wpforo-profile-head">
232 <div class="h-header">
233 <?php if( $wpforo->perm->usergroup_can('va') && wpforo_feature('avatars', $wpforo) ): $rsz =''; ?>
234 <div class="h-left"><?php echo $wpforo->member->get_avatar($userid, 'alt="'.esc_attr($display_name).'"', 150); ?></div>
235 <?php else: $rsz = ' style="margin-left:10px;"'; endif; ?>
236 <div class="h-right" <?php echo $rsz; ?>>
237 <div class="h-top">
238 <div class="profile-display-name">
239 <?php $wpforo->member->show_online_indicator($userid) ?>
240 <?php echo $display_name ? esc_html($display_name) : esc_html(urldecode($user_nicename)) ?>
241 </div>
242 <div class="profile-stat-data">
243 <div class="profile-stat-data-item"><?php wpforo_phrase('Group') ?>: <?php wpforo_phrase($groupname) ?></div>
244 <div class="profile-stat-data-item"><?php wpforo_phrase('Joined') ?>: <?php esc_html(wpforo_date($user_registered, 'Y/m/d')) ?></div>
245 </div>
246 </div>
247 </div>
248 <div class="wpf-clear"></div>
249 </div>
250 <div class="h-footer wpfbg-2">
251
252 <div class="h-bottom">
253 <?php $wpforo->tpl->member_menu($userid) ?>
254 <a href="?wpforo=logout"><?php wpforo_phrase('logout') ?></a>
255 <div class="wpf-clear"></div>
256 </div>
257 </div>
258 </div>
259 </div>
260
261 <?php else : ?>
262
263 <form name="wpflogin" action="" method="POST">
264 <div class="wpforo-login-wrap">
265 <div class="wpforo-login-content">
266 <table class="wpforo-login-table wpfcl-1" width="100%" border="0" cellspacing="0" cellpadding="0">
267 <tr class="wpfbg-9">
268 <td class="wpf-login-label">
269 <p class="wpf-label wpfcl-1"><?php wpforo_phrase('Username') ?>:</p>
270 </td>
271 <td class="wpf-login-field"><input autofocus required="TRUE" type="text" name="log" class="wpf-login-text wpfw-60" /></td>
272 </tr>
273 <tr class="wpfbg-9">
274 <td class="wpf-login-label">
275 <p class="wpf-label wpfcl-1"><?php wpforo_phrase('Password') ?>:</p>
276 </td>
277 <td class="wpf-login-field"><input required="TRUE" type="password" name="pwd" class="wpf-login-text wpfw-60" /></td>
278 </tr>
279 <tr class="wpfbg-9"><td colspan="2" style="text-align: center;"><?php do_action('login_form') ?></td></tr>
280 <tr class="wpfbg-9">
281 <td class="wpf-login-label">&nbsp;</td>
282 <td class="wpf-login-field">
283 <p class="wpf-extra wpfcl-1">
284 <input type="checkbox" value="1" name="rememberme" id="wpf-login-remember">
285 <label for="wpf-login-remember"><?php wpforo_phrase('Remember Me') ?> |</label>
286 <a href="<?php echo esc_url(wp_lostpassword_url(wpforo_get_request_uri())); ?>" class="wpf-forgot-pass"><?php wpforo_phrase('Lost your password?') ?></a>
287 <a href="<?php echo esc_url( wpforo_home_url('?wpforo=register') ) ?>"><?php wpforo_phrase('register') ?></a>
288 </p>
289 <input type="submit" name="wpforologin" value="<?php wpforo_phrase('Sign In') ?>" />
290 </td>
291 </tr>
292 </table>
293 </div>
294 </div>
295 </form>
296
297 <?php endif ?>
298 <?php
299 echo '</div></div>';
300 echo $args['after_widget'];
301 }
302 public function form( $instance ) {
303 $title = isset( $instance['title'] ) ? $instance['title'] : 'Account';
304 ?>
305 <p>
306 <label><?php _e('Title', 'wpforo'); ?>:</label>
307 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
308 </p>
309 <?php
310 }
311 public function update( $new_instance, $old_instance ) {
312 $instance = array();
313 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
314 return $instance;
315 }
316 } // widget wpforo login
317
318
319 class wpForo_Widget_online_members extends WP_Widget {
320 function __construct() {
321 parent::__construct(
322 'wpForo_Widget_online_members', // Base ID
323 'wpForo Online Members', // Name
324 array( 'description' => 'Online members.' ) // Args
325 );
326 }
327 public function widget( $args, $instance ) {
328 global $wpforo;
329 echo $args['before_widget']; //This is a HTML content//
330 echo '<div id="wpf-widget-online-users" class="wpforo-widget-wrap">';
331 if ( ! empty( $instance['title'] ) ) {
332 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
333 }
334 // widget content from front end
335 $online_members = $wpforo->member->get_online_members($instance['count']);
336 echo '<div class="wpforo-widget-content">';
337 if(!empty($online_members)){
338 echo '<ul>
339 <li>
340 <div class="wpforo-list-item">';
341 foreach( $online_members as $member ){
342 if( $instance['display_avatar'] ): ?>
343 <a href="<?php echo esc_url($wpforo->member->get_profile_url( $member['ID'] )) ?>" class="onlineavatar">
344 <?php echo $wpforo->member->get_avatar( $member['ID'], 'style="width:95%;" class="avatar" title="'.esc_attr($member['display_name']).'"'); ?>
345 </a>
346 <?php else: ?>
347 <a href="<?php echo esc_url($wpforo->member->get_profile_url( $member['ID'] )) ?>" class="onlineuser"><?php echo esc_html($member['display_name']) ?></a>
348 <?php endif; ?>
349 <?php
350 }
351 echo '<div class="wpf-clear"></div>
352 </div>
353 </li>
354 </ul>
355 </div>';
356 }
357 else{
358 echo '<p class="wpf-widget-note">&nbsp;'.wpforo_phrase('No online members at the moment', false).'</p>';
359 }
360 echo '</div>';
361 echo $args['after_widget'];//This is a HTML content//
362 }
363 public function form( $instance ) {
364 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Online Members';
365 $count = ! empty( $instance['count'] ) ? $instance['count'] : '15';
366 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
367 ?>
368 <p>
369 <label><?php _e('Title', 'wpforo'); ?>:</label>
370 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
371 </p><p>
372 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
373 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr( $count ) ; ?>">
374 </p><p>
375 <label>
376 <input<?php checked( $display_avatar ); ?> type="checkbox" value="1" name="<?php echo esc_attr( $this->get_field_name( 'display_avatar' )); ?>"/>
377 <?php _e('Display Avatars', 'wpforo'); ?>
378 </label>
379 </p>
380 <?php
381 }
382 public function update( $new_instance, $old_instance ) {
383 $instance = array();
384 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
385 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
386 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
387 return $instance;
388 }
389 } // widget online members
390
391 class wpForo_Widget_recent_topics extends WP_Widget {
392 function __construct() {
393 parent::__construct(
394 'wpForo_Widget_recent_topics', // Base ID
395 'wpForo Recent Topics', // Name
396 array( 'description' => 'Your forum\'s recent topics.' ) // Args
397 );
398 }
399 public function widget( $args, $instance ) {
400 global $wpforo;
401 echo $args['before_widget'];//This is a HTML content//
402 echo '<div id="wpf-widget-recent-replies" class="wpforo-widget-wrap">';
403 if ( ! empty( $instance['title'] ) ) {
404 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
405 }
406 // widget content from front end
407 $topic_args = array( // forumid, order, parentid
408 'orderby' => 'created',
409 'order' => 'DESC', // ASC DESC
410 'row_count' => $instance['count'] // 4 or 1 ...
411 );
412 $topics = $wpforo->topic->get_topics_filtered($topic_args);
413 $ug_can_va = $wpforo->perm->usergroup_can('va');
414 $is_avatar = wpforo_feature('avatars', $wpforo);
415 echo '<div class="wpforo-widget-content"><ul>';
416 foreach( $topics as $topic ){
417 $topic_url = wpforo_topic($topic['topicid'], 'url');
418 $member = wpforo_member($topic);
419 ?>
420 <li>
421 <div class="wpforo-list-item">
422 <?php if( $instance['display_avatar'] ): ?>
423 <?php if( $ug_can_va && $is_avatar ): ?>
424 <div class="wpforo-list-item-left">
425 <?php echo $wpforo->member->get_avatar( $topic['userid']); ?>
426 </div>
427 <?php endif; ?>
428 <?php endif; ?>
429 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
430 <p class="posttitle"><a href="<?php echo esc_url($topic_url) ?>"><?php echo esc_html($topic['title']) ?></a></p>
431 <p class="postuser"><?php wpforo_phrase('by') ?> <?php wpforo_member_link($member) ?>, <span style="white-space:nowrap;"><?php esc_html(wpforo_date($topic['created'])) ?></span></p>
432 </div>
433 <div class="wpf-clear"></div>
434 </div>
435 </li>
436 <?php
437 }
438 echo '</ul></div>';
439 echo '</div>';
440 echo $args['after_widget'];//This is a HTML content//
441 }
442 public function form( $instance ) {
443 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Topics';
444 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
445 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
446 ?>
447 <p>
448 <label><?php _e('Title', 'wpforo'); ?>:</label>
449 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
450 </p><p>
451 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
452 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
453 </p><p>
454 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
455 <?php _e('Display with Avatars', 'wpforo'); ?></label>
456 </p>
457 <?php
458 }
459 public function update( $new_instance, $old_instance ) {
460 $instance = array();
461 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
462 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
463 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
464 return $instance;
465 }
466 } // Recent topics
467
468
469 class wpForo_Widget_recent_replies extends WP_Widget {
470 function __construct() {
471 parent::__construct(
472 'wpForo_Widget_recent_replies', // Base ID
473 'wpForo Recent Posts', // Name
474 array( 'description' => 'Your forum\'s recent posts.' ) // Args
475 );
476 }
477
478 public function widget( $args, $instance ) {
479 global $wpforo;
480 echo $args['before_widget'];//This is a HTML content//
481 echo '<div id="wpf-widget-recent-replies" class="wpforo-widget-wrap">';
482 if ( ! empty( $instance['title'] ) ) {
483 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
484 }
485 // widget content from front end
486 $posts_args = array(
487 'orderby' => 'created',
488 'order' => 'DESC',
489 'row_count' => $instance['count'],
490 'check_private' => true
491 );
492 $recent_posts = $wpforo->post->get_posts_filtered($posts_args);
493 $ug_can_va = $wpforo->perm->usergroup_can('va');
494 $is_avatar = wpforo_feature('avatars', $wpforo);
495 echo '<div class="wpforo-widget-content"><ul>';
496 foreach( $recent_posts as $post ){
497 $post_url = wpforo_post( $post['postid'], 'url' );
498 $member = wpforo_member( $post );
499 ?>
500 <li>
501 <div class="wpforo-list-item">
502 <?php if( $instance['display_avatar'] ): ?>
503 <?php if( $ug_can_va && $is_avatar ): ?>
504 <div class="wpforo-list-item-left">
505 <?php echo $wpforo->member->get_avatar( $post['userid']); ?>
506 </div>
507 <?php endif; ?>
508 <?php endif; ?>
509 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
510 <p class="posttitle"><a href="<?php echo esc_url($post_url) ?>"><?php echo esc_html($post['title']) ?></a></p>
511 <p class="posttext"><?php echo esc_html(wpforo_text($post['body'], 55)); ?></p>
512 <p class="postuser"><?php wpforo_phrase('by') ?> <?php wpforo_member_link($member) ?>, <?php esc_html(wpforo_date($post['created'])) ?></p>
513 </div>
514 <div class="wpf-clear"></div>
515 </div>
516 </li>
517 <?php
518 }
519 echo '</ul></div>';
520 echo '</div>';
521 echo $args['after_widget'];//This is a HTML content//
522 }
523 public function form( $instance ) {
524 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Posts';
525 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
526 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
527 ?>
528 <p>
529 <label><?php _e('Title', 'wpforo'); ?>:</label>
530 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
531 </p><p>
532 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
533 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
534 </p><p>
535 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
536 <?php _e('Display with Avatars', 'wpforo'); ?></label>
537 </p>
538 <?php
539 }
540 public function update( $new_instance, $old_instance ) {
541 $instance = array();
542 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
543 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
544 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
545 return $instance;
546 }
547 } // Recent replies
548
549
550 class wpforo_widget_forums extends WP_Widget {
551 function __construct() {
552 parent::__construct(
553 'wpforo_widget_forums', // Base ID
554 'wpForo Forums', // Name
555 array( 'description' => 'Forum tree.' ) // Args
556 );
557 }
558 public function widget( $args, $instance ) {
559 global $wpforo;
560 echo $args['before_widget'];//This is a HTML content//
561 echo '<div id="wpf-widget-forums" class="wpforo-widget-wrap">';
562 if ( ! empty( $instance['title'] ) ) {
563 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
564 }
565 echo '<div class="wpforo-widget-content">';
566 $wpforo->forum->tree('front_list');
567 echo '</div>';
568 echo '</div>';
569 echo $args['after_widget'];//This is a HTML content//
570 }
571 public function form( $instance ) {
572 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Forums';
573 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
574 ?>
575 <p>
576 <label><?php _e('Title', 'wpforo'); ?>:</label>
577 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
578 </p>
579 <?php
580 }
581 public function update( $new_instance, $old_instance ) {
582 $instance = array();
583 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
584 return $instance;
585 }
586 } // forums tree
587
588
589 function wpforo_widget_search() {
590 register_widget( 'wpForo_Widget_search' );
591 }
592 add_action( 'widgets_init', 'wpforo_widget_search' );
593
594 function wpforo_widget_login() {
595 //Under development....
596 //register_widget( 'wpForo_Widget_login_form' );
597 }
598 add_action( 'widgets_init', 'wpforo_widget_login' );
599
600 function wpforo_widget_online_members() {
601 register_widget( 'wpForo_Widget_online_members' );
602 }
603 add_action( 'widgets_init', 'wpforo_widget_online_members' );
604
605 function wpforo_widget_recent_topics() {
606 register_widget( 'wpForo_Widget_recent_topics' );
607 }
608 add_action( 'widgets_init', 'wpforo_widget_recent_topics' );
609
610 function wpforo_widget_recent_replies() {
611 register_widget( 'wpForo_Widget_recent_replies' );
612 }
613 add_action( 'widgets_init', 'wpforo_widget_recent_replies' );
614
615 function wpforo_widget_forums() {
616 //Under Development
617 //register_widget( 'wpforo_widget_forums' );
618 }
619 add_action( 'widgets_init', 'wpforo_widget_forums' );
620
621 function wpforo_post_edited($post, $echo = true){
622 $edit_html = '';
623 if(!empty($post)){
624 $created = wpforo_date($post['created'], 'd/m/Y g:i a', false);
625 $modified = wpforo_date($post['modified'], 'd/m/Y g:i a', false);
626 if( isset($modified) && $created != $modified ){
627 $edit_html = '<div class="wpf-post-edited">' . wpforo_phrase('Edited: ', false) . wpforo_date($post['modified'], 'ago', false) . '</div>';
628 }
629 }
630 if( $echo ) {
631 echo $edit_html;
632 }
633 else{
634 return $edit_html;
635 }
636 }
637
638 function wpforo_hide_title($title, $id = 0) {
639 global $wpforo;
640 if( !wpforo_feature('page-title', $wpforo) ){
641 if( $wpforo_base_slug = basename( wpforo_home_url() ) ) $wpforo_page = get_page_by_path($wpforo_base_slug);
642 if(!empty($wpforo_page)){
643 if (in_the_loop() && is_page($wpforo_page->ID) && $id == get_the_ID()) {
644 $title = '';
645 }
646 }
647 }
648 return $title;
649 }
650 add_filter('the_title', 'wpforo_hide_title', 10, 2);
651
652
653 function wpforo_validate_gravatar( $email ) {
654 $hashkey = md5(strtolower(trim($email)));
655 $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
656 $data = wp_cache_get($hashkey);
657 if (false === $data) {
658 $response = wp_remote_head($uri);
659 if( is_wp_error($response) ) {
660 $data = 'not200';
661 } else {
662 $data = $response['response']['code'];
663 }
664 wp_cache_set($hashkey, $data, $group = '', $expire = 60*5);
665 }
666 if ($data == '200'){
667 return true;
668 } else {
669 return false;
670 }
671 }
672
673 function wpforo_member_title( $member = array(), $echo = true, $usergroup = true ){
674 global $wpforo;
675 $title = array();
676
677 if(empty($member) || !$member['groupid']) return;
678 $rating_title_ug_enabled = ( isset($wpforo->member->options['rating_title_ug'][$member['groupid']]) && $wpforo->member->options['rating_title_ug'][$member['groupid']] ) ? true : false ;
679 $usergroup_title_ug_enabled = ( isset($wpforo->member->options['title_usergroup'][$member['groupid']]) && $wpforo->member->options['title_usergroup'][$member['groupid']] ) ? true : false ;
680
681 if( wpforo_feature('rating_title', $wpforo) && $rating_title_ug_enabled && isset($member['stat']['title']) ){
682 $title[] = '<span class="wpf-member-title wpfrt" title="' . wpforo_phrase('Rating Title', false) . '">' . esc_html($member['stat']['title']) . '</span>';
683 }
684 if( empty($title) ){
685 $title[] = '<span class="wpf-member-title wpfct" title="' . wpforo_phrase('User Title', false) . '">' . wpforo_phrase($member['title'], false) . '</span>';
686 }
687 if( $usergroup_title_ug_enabled ){
688 $class = '';
689 if( $member['groupid'] == 1 ) $class = ' wpfbg-6 wpfcl-3';
690 if( $member['groupid'] == 2 ) $class = ' wpfbg-5 wpfcl-3';
691 if( $member['groupid'] == 4 ) $class = ' wpfbg-2 wpfcl-3';
692 $title[] = '<span class="wpf-member-title wpfut wpfug-' . intval($member['groupid']) . $class . '" title="' . wpforo_phrase('Usergroup', false) . '">' . esc_html($member['groupname']) . '</span>';
693 }
694 if( !empty($title) ){
695 $title_html = implode(' ', $title);
696 $title_html = apply_filters('wpforo_member_title', $title_html, $member);
697 if( $echo ) {
698 echo $title_html;
699 }
700 else{
701 return $title_html;
702 }
703 }
704 }
705
706 function wpforo_member_badge( $member = array(), $sep = '', $type = 'full' ){
707 global $wpforo;
708 $rating_badge_ug_enabled = ( isset($wpforo->member->options['rating_badge_ug'][$member['groupid']]) && $wpforo->member->options['rating_badge_ug'][$member['groupid']] ) ? true : false ;
709 if( wpforo_feature('rating', $wpforo) && $rating_badge_ug_enabled && isset($member['stat']['rating']) ): ?>
710 <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') ?>">
711 <?php echo $wpforo->member->rating_badge($member['stat']['rating'], $type); ?>
712 </div><?php if($sep): ?><span class="author-rating-sep"><?php echo esc_html($sep); ?></span><?php endif; ?>
713 <?php endif;
714
715 do_action('wpforo_after_member_badge', $member);
716 }
717
718 add_filter( 'body_class', 'wpforo_page_class', 1, 10 );
719 function wpforo_page_class( $classes ) {
720 if(!empty($classes)){
721 if( function_exists('is_wpforo_page') ){
722 if ( is_wpforo_page() ) {
723 return array_merge( $classes, array( 'wpforo' ) );
724 }
725 }
726 }
727 return (array)$classes;
728 }
729
730 ###############################################################################
731 ########################## THEME API FUNCTIONS ################################
732 ###############################################################################
733
734 function wpforo_post( $postid, $var = 'item', $echo = false ){
735
736 global $wpforo;
737 $post = ( $var == 'item' ) ? array() : '';
738 if( !$postid ) return $post;
739 $cache = $wpforo->cache->on('object_cashe');
740 if( $cache ){
741 $post = $wpforo->cache->get_item( $postid, 'post' );
742 }
743 if( empty($post) ){
744 if( !$cache && $var == 'url' ){
745 $post['url'] = $wpforo->post->get_post_url($postid);
746 }
747 elseif( !$cache && $var == 'is_answered' ){
748 $post['is_answered'] = $wpforo->post->is_answered($postid);
749 }
750 elseif( !$cache && $var == 'votes_sum' ){
751 $post['votes_sum'] = $wpforo->post->get_post_votes_sum($postid);
752 }
753 elseif( !$cache && $var == 'likes_count' ){
754 $post['likes_count'] = $wpforo->post->get_post_likes_count($postid);
755 }
756 elseif( !$cache && $var == 'likers_usernames' ){
757 $post['likers_usernames'] = $wpforo->post->get_likers_usernames($postid);
758 }
759 else{
760 $post = $wpforo->post->get_post($postid);
761 if( !empty($post) ){
762 $post['url'] = $wpforo->post->get_post_url($post);
763 if( $cache ){
764 $post['is_answered'] = $wpforo->post->is_answered($postid);
765 $post['votes_sum'] = $wpforo->post->get_post_votes_sum($postid);
766 $post['likes_count'] = $wpforo->post->get_post_likes_count($postid);
767 $post['likers_usernames'] = $wpforo->post->get_likers_usernames($postid);
768 }
769 if(!empty($post)){
770 $cache_item = array( $postid => $post );
771 $wpforo->cache->create('item', $cache_item, 'post');
772 }
773 }
774 }
775 }
776
777 if( $var != 'item' && $var ){
778 $post = ( isset($post[$var]) ) ? $post[$var] : '';
779 }
780
781 if( $echo ){
782 echo $post;
783 }
784 else{
785 return $post;
786 }
787 }
788
789 function wpforo_topic( $topicid, $var = 'item', $echo = false ){
790
791 global $wpforo;
792 $topic = ( $var == 'item' ) ? array() : '';
793 if( !$topicid ) return $topic;
794 $cache = $wpforo->cache->on('object_cashe');
795 if( $cache ) $topic = $wpforo->cache->get_item( $topicid, 'topic' );
796
797 if( empty($topic) ){
798 if( !$cache && $var == 'url' ){
799 $topic['url'] = $wpforo->topic->get_topic_url( $topicid );
800 }
801 elseif( !$cache && $var == 'is_answer' ){
802 $topic['is_answer'] = $wpforo->topic->is_solved( $topicid );
803 }
804 else{
805 $topic = $wpforo->topic->get_topic($topicid);
806 if( !empty($topic) ){
807 $topic['url'] = $wpforo->topic->get_topic_url($topic);
808 $topic['is_answer'] = $wpforo->topic->is_solved( $topic['topicid'] );
809 if(!empty($topic)){
810 $cache_item = array( $topicid => $topic );
811 $wpforo->cache->create('item', $cache_item, 'topic');
812 }
813 }
814 }
815 }
816
817 if( $var != 'item' && $var ){
818 $topic = ( isset($topic[$var]) ) ? $topic[$var] : '';
819 }
820
821 if( $echo ){
822 echo $topic;
823 }
824 else{
825 return $topic;
826 }
827 }
828
829
830 function wpforo_forum( $forumid, $var = 'item', $echo = false ){
831
832 global $wpforo;
833 $data = array();
834 $forum = ( $var == 'item' ) ? array() : '';
835 $cache = $wpforo->cache->on('object_cashe');
836 if( !$forumid ) return $forum;
837 if( $cache ) $forum = $wpforo->cache->get_item( $forumid, 'forum' );
838
839 if( empty($forum) ){
840 if( !$cache && ($var == 'childs' || $var == 'counts') ){
841 if( $var == 'childs' ) {
842 $wpforo->forum->get_childs($forumid, $data);
843 $forum['childs'] = $data;
844 }
845 else{
846 $wpforo->forum->get_childs($forumid, $data);
847 $forum['childs'] = $data;
848 $forum['counts'] = $wpforo->forum->get_counts( $data );
849 }
850 }
851 else{
852 $forum = $wpforo->forum->get_forum($forumid);
853 if( !empty($forum) ){
854 if( $cache ){
855 $wpforo->forum->get_childs($forum['forumid'], $data);
856 $forum['childs'] = $data;
857 $forum['counts'] = $wpforo->forum->get_counts( $data );
858 }
859 if(!empty($forum)){
860 $cache_item = array( $forumid => $forum );
861 $wpforo->cache->create('item', $cache_item, 'forum');
862 }
863 }
864 }
865 }
866
867 if( $var != 'item' && $var ){
868 $forum = ( isset($forum[$var]) ) ? $forum[$var] : '';
869 }
870
871 if( $echo ){
872 echo $forum;
873 }
874 else{
875 return $forum;
876 }
877 }
878
879 function wpforo_member( $object, $var = 'item', $echo = false ){
880
881 global $wpforo;
882 $member = array();
883 if( empty( $object ) ) return $member;
884
885 if( is_array( $object ) && isset($object['userid']) && $object['userid'] == 0 ){
886 $member = $wpforo->member->get_guest( $object );
887 }
888 else{
889 $userid = ( is_array( $object ) && isset($object['userid']) ) ? intval($object['userid']) : intval($object);
890 $member = $wpforo->member->get_member( $userid );
891 }
892
893 if( $var != 'item' && $var ){
894 $member = ( isset($member[$var]) ) ? $member[$var] : '';
895 }
896
897 if( $echo ){
898 echo $member;
899 }
900 else{
901 return $member;
902 }
903 }
904
905 function wpforo_member_link( $member, $prefix = '', $length = 30, $class = '', $echo = true ){
906 $display_name = ( isset($member['display_name']) && $member['display_name'] ) ? $member['display_name'] : wpforo_phrase('Anonymous', false);
907 $nofollow = ( !wpforo_feature('seo-profile')) ? ' rel="nofollow" ' : '';
908 if( isset($member['profile_url']) && $member['profile_url'] ){
909 ?><a href="<?php echo esc_url($member['profile_url']) ?>" <?php echo $nofollow ?>><?php if( strpos($prefix, '%s') !== FALSE ): ?><?php echo sprintf( wpforo_phrase($prefix, FALSE), esc_html(wpforo_text($display_name, $length, FALSE)) ); ?><?php else: ?><?php if( $prefix ){ echo wpforo_phrase( $prefix, false) . ' '; } ?><?php if( $length ){ echo esc_html(wpforo_text($display_name, $length, false)); } else { echo esc_html($display_name); } ?><?php endif; ?></a><?php
910 }
911 else{
912 ?><?php if( strpos($prefix, '%s') !== FALSE ): ?><?php echo sprintf( wpforo_phrase($prefix, FALSE), esc_html(wpforo_text($display_name, $length, FALSE)) ); ?><?php else: ?><?php if( $prefix ){ echo wpforo_phrase( $prefix, false) . ' '; } ?><?php if( $length ){ echo esc_html(wpforo_text($display_name, $length, false)); } else { echo esc_html($display_name); } ?><?php endif; ?><?php
913 }
914 }
915
916 add_shortcode('wpforo-lostpassword', 'wpforo_lostpassword');
917 function wpforo_lostpassword(){ ?>
918 <p id="wpforo-title"><?php wpforo_phrase('Reset Password') ?></p>
919
920 <form name="wpflogin" action="<?php echo wp_lostpassword_url(); ?>" method="POST">
921 <div class="wpforo-login-wrap">
922 <div class="wpforo-login-content">
923 <table class="wpforo-login-table wpfcl-1" width="100%" border="0" cellspacing="0" cellpadding="0" style="width:100%; display:table;">
924 <tbody style="width:100%;">
925 <tr class="wpfbg-9">
926 <td class="wpf-login-label">
927 <p class="wpf-label wpfcl-1">
928 <label for="userlogin"><?php wpforo_phrase('Email or Username') ?>:</label>
929 </p>
930 </td>
931 <td class="wpf-login-field">
932 <input id="userlogin" autofocus required type="text" name="user_login" class="wpf-login-text wpfw-60" />
933 <p><?php wpforo_phrase('Enter your email address and we\'ll send you a link you can use to pick a new password.') ?></p>
934 </td>
935 </tr>
936 <tr class="wpfbg-9">
937 <td class="wpf-login-label">&nbsp;</td>
938 <td class="wpf-login-field">
939 <input type="submit" name="submit" value="<?php wpforo_phrase('Reset Password') ?>" />
940 </td>
941 </tr>
942 </tbody>
943 </table>
944 </div>
945 </div>
946 </form>
947
948 <?php
949 }
950
951 add_shortcode('wpforo-resetpassword', 'wpforo_resetpassword');
952 function wpforo_resetpassword(){ ?>
953 <p id="wpforo-title"><?php wpforo_phrase('Reset Password') ?></p>
954
955 <form name="wpflogin" action="<?php echo site_url( 'wp-login.php?action=resetpass' ); ?>" method="POST" autocomplete="off">
956 <input type="hidden" name="rp_key" value="<?php echo $_REQUEST['rp_key'] ?>">
957 <input type="hidden" name="rp_login" value="<?php echo $_REQUEST['rp_login'] ?>">
958 <div class="wpforo-login-wrap">
959 <div class="wpforo-login-content">
960 <table class="wpforo-login-table wpfcl-1" width="100%" border="0" cellspacing="0" cellpadding="0" style="width:100%; display:table;">
961 <tbody style="width:100%;">
962 <tr class="wpfbg-9">
963 <td class="wpf-login-label">
964 <p class="wpf-label wpfcl-1">
965 <label for="pass1"><?php wpforo_phrase('New password') ?></label>
966 </p>
967 </td>
968 <td class="wpf-login-field">
969 <input type="password" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" required autofocus />
970 </td>
971 </tr>
972 <tr class="wpfbg-9">
973 <td class="wpf-login-label">
974 <p class="wpf-label wpfcl-1">
975 <label for="pass2"><?php wpforo_phrase('Repeat new password') ?></label>
976 </p>
977 </td>
978 <td class="wpf-login-field">
979 <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" required />
980 </td>
981 </tr>
982 <tr class="wpfbg-9">
983 <td colspan="2">
984 <p class="description" style="text-align: center;"><?php echo wp_get_password_hint(); ?></p>
985 </td>
986 </tr>
987 <tr class="wpfbg-9">
988 <td class="wpf-login-label">&nbsp;</td>
989 <td class="wpf-login-field">
990 <input type="submit" name="submit" value="<?php wpforo_phrase('Reset Password'); ?>" />
991 </td>
992 </tr>
993 </tbody>
994 </table>
995 </div>
996 </div>
997 </form>
998
999 <?php
1000 }
1001
1002 #############################################################################################
1003 /**
1004 * Generates according page form fields using tpl->form_fields() function
1005 *
1006 * @since 1.4.0
1007 *
1008 * @param array $fields arguments
1009 * @param boolean $echo
1010 *
1011 * @return string form fields HTML
1012 */
1013 function wpforo_fields( $fields, $echo = true ){
1014 if( empty($fields) ) return '';
1015 global $wpforo;
1016 $fields = apply_filters( 'wpforo_form_fields', $fields );
1017 $html = $wpforo->tpl->form_fields( $fields );
1018 if( $echo ){
1019 echo $html;
1020 }
1021 else{
1022 return $html;
1023 }
1024 }
1025
1026 ##################################################################################################
1027 /**
1028 * Collects Registration Page POST data and sends to field generator function
1029 *
1030 * @since 1.4.0
1031 *
1032 * @param array $fields arguments
1033 *
1034 * @return NULL
1035 */
1036
1037 function wpforo_register_page_field_values( $fields ){
1038 global $wpforo;
1039 $wpforo->form['value']['user_login'] = (isset($_POST['wpfreg']['user_login'])) ? sanitize_user($_POST['wpfreg']['user_login']) : '';
1040 $wpforo->form['value']['user_email'] = (isset($_POST['wpfreg']['user_email'])) ? sanitize_email($_POST['wpfreg']['user_email']) : '';
1041 $wpforo->form['varname'] = 'wpfreg';
1042 }
1043 add_action( 'wpforo_register_page_start', 'wpforo_register_page_field_values', 10, 1 );
1044
1045
1046 ##################################################################################################
1047 /**
1048 * Collects Account Page field data and sends to field generator function
1049 *
1050 * @since 1.4.0
1051 *
1052 * @param array $fields arguments
1053 *
1054 * @return NULL
1055 */
1056
1057 function wpforo_account_page_field_values( $fields ){
1058 global $wpforo;
1059
1060 if( isset($wpforo->current_object['user']) && !empty($wpforo->current_object['user']) ){
1061 $user = $wpforo->current_object['user'];
1062 $user = apply_filters('wpforo_profile_header_obj', $user);
1063 $wpforo->form['value'] = $user;
1064 $wpforo->form['varname'] = 'member';
1065 }
1066 }
1067 add_action( 'wpforo_account_page_start', 'wpforo_account_page_field_values', 10, 1 );
1068
1069
1070 ##################################################################################################
1071 /**
1072 * Collects Profile Page field data and sends to field generator function
1073 *
1074 * @since 1.4.0
1075 *
1076 * @param array $fields arguments
1077 *
1078 * @return NULL
1079 */
1080
1081 function wpforo_profile_page_field_values( $fields ){
1082 global $wpforo;
1083
1084 if( isset($wpforo->current_object['user']) && !empty($wpforo->current_object['user']) ){
1085 $user = $wpforo->current_object['user'];
1086 $wpforo->form['value'] = $user;
1087 }
1088 }
1089 add_action( 'wpforo_profile_page_start', 'wpforo_profile_page_field_values', 10, 1 );
1090
1091
1092 function wpforo_search_page_field_values( $fields ){
1093 global $wpforo;
1094 $wpforo->form['value'] = ( !empty($_GET) ? (array) $_GET : array() );
1095 $wpforo->form['varname'] = '';
1096 }
1097 add_action( 'wpforo_search_page_start', 'wpforo_search_page_field_values', 10, 1 );
1098
1099 function wpforo_user_avatar( $user, $size, $attr = '', $lastmod = false ){
1100 global $wpforo;
1101 $avatar_html = '';
1102 if( is_int($user) && $user ){
1103 $avatar_html = ($size) ? get_avatar($user, $size) : get_avatar($user);
1104 if($attr) $avatar_html = str_replace('<img', '<img ' . $attr, $avatar_html);
1105 }
1106 elseif( is_array($user) && !empty($user) ){
1107 $avatar_html = $wpforo->member->avatar($user, $attr, $size); //'alt="'.esc_html($display_name).'"'
1108 }
1109
1110 if( $lastmod ){
1111 $url = wpforo_avatar_url( $avatar_html );
1112 if($url){
1113 $avatar_html = str_replace($url, $url . '?lm=' . time(), $avatar_html);
1114 }
1115 }
1116 return $avatar_html;
1117 }
1118
1119 function wpforo_register_fields(){
1120 global $wpforo;
1121
1122 $fields = $wpforo->member->get_register_fields();
1123 do_action( 'wpforo_register_page_start', $fields );
1124
1125 return $fields;
1126 }
1127
1128 function wpforo_account_fields(){
1129 global $wpforo;
1130
1131 $fields = $wpforo->member->get_account_fields();
1132 do_action( 'wpforo_account_page_start', $fields );
1133
1134 return $fields;
1135 }
1136
1137 function wpforo_profile_fields(){
1138 global $wpforo;
1139
1140 $fields = $wpforo->member->get_profile_fields();
1141 do_action( 'wpforo_profile_page_start', $fields );
1142
1143 return $fields;
1144 }
1145
1146 function wpforo_search_fields(){
1147 global $wpforo;
1148
1149 $fields = $wpforo->member->get_search_fields();
1150 do_action( 'wpforo_search_page_start', $fields );
1151
1152 if( $wpforo->member->options['search_type'] == 'search' ){
1153 $fields = array(
1154 array(
1155 array(
1156 array(
1157 'type' => 'search',
1158 'isDefault' => 1,
1159 'isRemovable' => 0,
1160 'isRequired' => 0,
1161 'isEditable' => 1,
1162 'class' => 'wpf-member-search-field',
1163 'label' => wpforo_phrase('Find a member', false),
1164 'title' => wpforo_phrase('Find a member', false),
1165 'placeholder' => wpforo_phrase('Display Name or Nicename', false),
1166 'faIcon' => 'fa-search',
1167 'name' => 'wpfms',
1168 'canBeInactive' => 0,
1169 'can' => '',
1170 'isSearchable' => 1
1171 )
1172 )
1173 )
1174 );
1175 }
1176
1177 return $fields;
1178 }
1179
1180
1181 function wpforo_unread_forum( $logid, $return = 'class', $echo = true ){
1182 $unread = false;
1183 if(!wpforo_feature('view-logging')) return;
1184 $viwed_ids = wpforo_getcookie( 'wpf_viewed_forums', true );
1185 if( empty($viwed_ids) ) $unread = true;
1186 if( is_array($viwed_ids) && !in_array( $logid, $viwed_ids ) ) $unread = true;
1187 if( $unread ){ if( $return == 'class' ){ $log = 'wpf_forum_unread'; } else{ $log = true; } if( $echo ){ echo $log; } else { return $log; } }
1188 }
1189
1190 function wpforo_unread_topic( $logid, $return = 'class', $echo = true ){
1191 $unread = false;
1192 if(!wpforo_feature('view-logging')) return;
1193 $viwed_ids = wpforo_getcookie( 'wpf_viewed_topics', true );
1194 if( empty($viwed_ids) ) $unread = true;
1195 if( is_array($viwed_ids) && !in_array( $logid, $viwed_ids ) ) $unread = true;
1196 if( $unread ){ if( $return == 'class' ){ $log = 'wpf_topic_unread'; } else{ $log = true; } if( $echo ){ echo $log; } else { return $log; } }
1197 }