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

1,227 lines 48.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
6 register_nav_menus( array(
7 'wpforo-menu' => esc_html__( 'wpForo Menu', 'wpforo' ),
8 ) );
9
10
11 function wpforo_login_url(){
12 global $wpforo;
13 if(isset($wpforo->member->options['login_url']) && $wpforo->member->options['login_url']){
14 $wp_login_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member->options['login_url'] , '/');
15 }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 $private = (!is_user_logged_in() || !$wpforo->perm->usergroup_can('em')) ? 0 : NULL;
408 $status = (!is_user_logged_in() || !$wpforo->perm->usergroup_can('em')) ? 0 : NULL;
409 $topic_args = array( // forumid, order, parentid
410 'orderby' => 'created',
411 'order' => 'DESC', // ASC DESC
412 'row_count' => $instance['count'], // 4 or 1 ...
413 'private' => $private,
414 'status' => $status
415 );
416 $topics = $wpforo->topic->get_topics_filtered($topic_args);
417 $ug_can_va = $wpforo->perm->usergroup_can('va');
418 $is_avatar = wpforo_feature('avatars', $wpforo);
419 echo '<div class="wpforo-widget-content"><ul>';
420 foreach( $topics as $topic ){
421 $topic_url = wpforo_topic($topic['topicid'], 'url');
422 $member = wpforo_member($topic);
423 ?>
424 <li>
425 <div class="wpforo-list-item">
426 <?php if( $instance['display_avatar'] ): ?>
427 <?php if( $ug_can_va && $is_avatar ): ?>
428 <div class="wpforo-list-item-left">
429 <?php echo $wpforo->member->get_avatar( $topic['userid']); ?>
430 </div>
431 <?php endif; ?>
432 <?php endif; ?>
433 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
434 <p class="posttitle"><a href="<?php echo esc_url($topic_url) ?>"><?php echo esc_html($topic['title']) ?></a></p>
435 <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>
436 </div>
437 <div class="wpf-clear"></div>
438 </div>
439 </li>
440 <?php
441 }
442 echo '</ul></div>';
443 echo '</div>';
444 echo $args['after_widget'];//This is a HTML content//
445 }
446 public function form( $instance ) {
447 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Topics';
448 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
449 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
450 ?>
451 <p>
452 <label><?php _e('Title', 'wpforo'); ?>:</label>
453 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
454 </p><p>
455 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
456 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
457 </p><p>
458 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
459 <?php _e('Display with Avatars', 'wpforo'); ?></label>
460 </p>
461 <?php
462 }
463 public function update( $new_instance, $old_instance ) {
464 $instance = array();
465 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
466 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
467 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
468 return $instance;
469 }
470 } // Recent topics
471
472
473 class wpForo_Widget_recent_replies extends WP_Widget {
474 function __construct() {
475 parent::__construct(
476 'wpForo_Widget_recent_replies', // Base ID
477 'wpForo Recent Posts', // Name
478 array( 'description' => 'Your forum\'s recent posts.' ) // Args
479 );
480 }
481
482 public function widget( $args, $instance ) {
483 global $wpforo;
484 echo $args['before_widget'];//This is a HTML content//
485 echo '<div id="wpf-widget-recent-replies" class="wpforo-widget-wrap">';
486 if ( ! empty( $instance['title'] ) ) {
487 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
488 }
489 $private = (!is_user_logged_in() || !$wpforo->perm->usergroup_can('em')) ? 0 : NULL;
490 $status = (!is_user_logged_in() || !$wpforo->perm->usergroup_can('em')) ? 0 : NULL;
491 // widget content from front end
492 $posts_args = array(
493 'orderby' => 'created',
494 'order' => 'DESC',
495 'row_count' => $instance['count'],
496 'private' => $private,
497 'status' => $status
498 );
499 $recent_posts = $wpforo->post->get_posts_filtered($posts_args);
500 $ug_can_va = $wpforo->perm->usergroup_can('va');
501 $is_avatar = wpforo_feature('avatars', $wpforo);
502 echo '<div class="wpforo-widget-content"><ul>';
503 foreach( $recent_posts as $post ){
504 $post_url = wpforo_post( $post['postid'], 'url' );
505 $member = wpforo_member( $post );
506 ?>
507 <li>
508 <div class="wpforo-list-item">
509 <?php if( $instance['display_avatar'] ): ?>
510 <?php if( $ug_can_va && $is_avatar ): ?>
511 <div class="wpforo-list-item-left">
512 <?php echo $wpforo->member->get_avatar( $post['userid']); ?>
513 </div>
514 <?php endif; ?>
515 <?php endif; ?>
516 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
517 <p class="posttitle"><a href="<?php echo esc_url($post_url) ?>"><?php echo esc_html($post['title']) ?></a></p>
518 <p class="posttext"><?php echo esc_html(wpforo_text($post['body'], 55)); ?></p>
519 <p class="postuser"><?php wpforo_phrase('by') ?> <?php wpforo_member_link($member) ?>, <?php esc_html(wpforo_date($post['created'])) ?></p>
520 </div>
521 <div class="wpf-clear"></div>
522 </div>
523 </li>
524 <?php
525 }
526 echo '</ul></div>';
527 echo '</div>';
528 echo $args['after_widget'];//This is a HTML content//
529 }
530 public function form( $instance ) {
531 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Posts';
532 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
533 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
534 ?>
535 <p>
536 <label><?php _e('Title', 'wpforo'); ?>:</label>
537 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
538 </p><p>
539 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
540 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
541 </p><p>
542 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
543 <?php _e('Display with Avatars', 'wpforo'); ?></label>
544 </p>
545 <?php
546 }
547 public function update( $new_instance, $old_instance ) {
548 $instance = array();
549 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
550 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
551 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
552 return $instance;
553 }
554 } // Recent replies
555
556
557 class wpforo_widget_forums extends WP_Widget {
558 function __construct() {
559 parent::__construct(
560 'wpforo_widget_forums', // Base ID
561 'wpForo Forums', // Name
562 array( 'description' => 'Forum tree.' ) // Args
563 );
564 }
565 public function widget( $args, $instance ) {
566 global $wpforo;
567 echo $args['before_widget'];//This is a HTML content//
568 echo '<div id="wpf-widget-forums" class="wpforo-widget-wrap">';
569 if ( ! empty( $instance['title'] ) ) {
570 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
571 }
572 echo '<div class="wpforo-widget-content">';
573 $wpforo->forum->tree('front_list');
574 echo '</div>';
575 echo '</div>';
576 echo $args['after_widget'];//This is a HTML content//
577 }
578 public function form( $instance ) {
579 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Forums';
580 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
581 ?>
582 <p>
583 <label><?php _e('Title', 'wpforo'); ?>:</label>
584 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
585 </p>
586 <?php
587 }
588 public function update( $new_instance, $old_instance ) {
589 $instance = array();
590 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
591 return $instance;
592 }
593 } // forums tree
594
595
596 function wpforo_widget_search() {
597 register_widget( 'wpForo_Widget_search' );
598 }
599 add_action( 'widgets_init', 'wpforo_widget_search' );
600
601 function wpforo_widget_login() {
602 //Under development....
603 //register_widget( 'wpForo_Widget_login_form' );
604 }
605 add_action( 'widgets_init', 'wpforo_widget_login' );
606
607 function wpforo_widget_online_members() {
608 register_widget( 'wpForo_Widget_online_members' );
609 }
610 add_action( 'widgets_init', 'wpforo_widget_online_members' );
611
612 function wpforo_widget_recent_topics() {
613 register_widget( 'wpForo_Widget_recent_topics' );
614 }
615 add_action( 'widgets_init', 'wpforo_widget_recent_topics' );
616
617 function wpforo_widget_recent_replies() {
618 register_widget( 'wpForo_Widget_recent_replies' );
619 }
620 add_action( 'widgets_init', 'wpforo_widget_recent_replies' );
621
622 function wpforo_widget_forums() {
623 //Under Development
624 //register_widget( 'wpforo_widget_forums' );
625 }
626 add_action( 'widgets_init', 'wpforo_widget_forums' );
627
628 function wpforo_post_edited($post, $echo = true){
629 $edit_html = '';
630 if(!empty($post)){
631 $created = wpforo_date($post['created'], 'd/m/Y g:i a', false);
632 $modified = wpforo_date($post['modified'], 'd/m/Y g:i a', false);
633 if( isset($modified) && $created != $modified ){
634 $edit_html = '<div class="wpf-post-edited">' . wpforo_phrase('Edited: ', false) . wpforo_date($post['modified'], 'ago', false) . '</div>';
635 }
636 }
637 if( $echo ) {
638 echo $edit_html;
639 }
640 else{
641 return $edit_html;
642 }
643 }
644
645 function wpforo_hide_title($title, $id = 0) {
646 global $wpforo;
647 if( !wpforo_feature('page-title', $wpforo) ){
648 if( $wpforo_base_slug = basename( wpforo_home_url() ) ) $wpforo_page = get_page_by_path($wpforo_base_slug);
649 if(!empty($wpforo_page)){
650 if (in_the_loop() && is_page($wpforo_page->ID) && $id == get_the_ID()) {
651 $title = '';
652 }
653 }
654 }
655 return $title;
656 }
657 add_filter('the_title', 'wpforo_hide_title', 10, 2);
658
659
660 function wpforo_validate_gravatar( $email ) {
661 $hashkey = md5(strtolower(trim($email)));
662 $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
663 $data = wp_cache_get($hashkey);
664 if (false === $data) {
665 $response = wp_remote_head($uri);
666 if( is_wp_error($response) ) {
667 $data = 'not200';
668 } else {
669 $data = $response['response']['code'];
670 }
671 wp_cache_set($hashkey, $data, $group = '', $expire = 60*5);
672 }
673 if ($data == '200'){
674 return true;
675 } else {
676 return false;
677 }
678 }
679
680 function wpforo_member_title( $member = array(), $echo = true, $usergroup = true ){
681 global $wpforo;
682 $title = array();
683
684 if(empty($member) || !$member['groupid']) return;
685 $rating_title_ug_enabled = ( isset($wpforo->member->options['rating_title_ug'][$member['groupid']]) && $wpforo->member->options['rating_title_ug'][$member['groupid']] ) ? true : false ;
686 $usergroup_title_ug_enabled = ( isset($wpforo->member->options['title_usergroup'][$member['groupid']]) && $wpforo->member->options['title_usergroup'][$member['groupid']] ) ? true : false ;
687
688 if( wpforo_feature('rating_title', $wpforo) && $rating_title_ug_enabled && isset($member['stat']['title']) ){
689 $title[] = '<span class="wpf-member-title wpfrt" title="' . wpforo_phrase('Rating Title', false) . '">' . esc_html($member['stat']['title']) . '</span>';
690 }
691 if( empty($title) ){
692 $title[] = '<span class="wpf-member-title wpfct" title="' . wpforo_phrase('User Title', false) . '">' . wpforo_phrase($member['title'], false) . '</span>';
693 }
694 if( $usergroup_title_ug_enabled ){
695 $class = '';
696 if( $member['groupid'] == 1 ) $class = ' wpfbg-6 wpfcl-3';
697 if( $member['groupid'] == 2 ) $class = ' wpfbg-5 wpfcl-3';
698 if( $member['groupid'] == 4 ) $class = ' wpfbg-2 wpfcl-3';
699 $title[] = '<span class="wpf-member-title wpfut wpfug-' . intval($member['groupid']) . $class . '" title="' . wpforo_phrase('Usergroup', false) . '">' . esc_html($member['groupname']) . '</span>';
700 }
701 if( !empty($title) ){
702 $title_html = implode(' ', $title);
703 $title_html = apply_filters('wpforo_member_title', $title_html, $member);
704 if( $echo ) {
705 echo $title_html;
706 }
707 else{
708 return $title_html;
709 }
710 }
711 }
712
713 function wpforo_member_badge( $member = array(), $sep = '', $type = 'full' ){
714 global $wpforo;
715 $rating_badge_ug_enabled = ( isset($wpforo->member->options['rating_badge_ug'][$member['groupid']]) && $wpforo->member->options['rating_badge_ug'][$member['groupid']] ) ? true : false ;
716 if( wpforo_feature('rating', $wpforo) && $rating_badge_ug_enabled && isset($member['stat']['rating']) ): ?>
717 <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') ?>">
718 <?php echo $wpforo->member->rating_badge($member['stat']['rating'], $type); ?>
719 </div><?php if($sep): ?><span class="author-rating-sep"><?php echo esc_html($sep); ?></span><?php endif; ?>
720 <?php endif;
721
722 do_action('wpforo_after_member_badge', $member);
723 }
724
725 add_filter( 'body_class', 'wpforo_page_class', 1, 10 );
726 function wpforo_page_class( $classes ) {
727 if(!empty($classes)){
728 if( function_exists('is_wpforo_page') ){
729 if ( is_wpforo_page() ) {
730 return array_merge( $classes, array( 'wpforo' ) );
731 }
732 }
733 }
734 return (array)$classes;
735 }
736
737 ###############################################################################
738 ########################## THEME API FUNCTIONS ################################
739 ###############################################################################
740
741 function wpforo_post( $postid, $var = 'item', $echo = false ){
742
743 global $wpforo;
744 $post = ( $var == 'item' ) ? array() : '';
745 if( !$postid ) return $post;
746 $cache = $wpforo->cache->on('object_cashe');
747 if( $cache ){
748 $post = $wpforo->cache->get_item( $postid, 'post' );
749 }
750 if( empty($post) ){
751 if( !$cache && $var == 'url' ){
752 $post['url'] = $wpforo->post->get_post_url($postid);
753 }
754 elseif( !$cache && $var == 'is_answered' ){
755 $post['is_answered'] = $wpforo->post->is_answered($postid);
756 }
757 elseif( !$cache && $var == 'votes_sum' ){
758 $post['votes_sum'] = $wpforo->post->get_post_votes_sum($postid);
759 }
760 elseif( !$cache && $var == 'likes_count' ){
761 $post['likes_count'] = $wpforo->post->get_post_likes_count($postid);
762 }
763 elseif( !$cache && $var == 'likers_usernames' ){
764 $post['likers_usernames'] = $wpforo->post->get_likers_usernames($postid);
765 }
766 else{
767 $post = $wpforo->post->get_post($postid);
768 if( !empty($post) ){
769 $post['url'] = $wpforo->post->get_post_url($post);
770 if( $cache ){
771 $post['is_answered'] = $wpforo->post->is_answered($postid);
772 $post['votes_sum'] = $wpforo->post->get_post_votes_sum($postid);
773 $post['likes_count'] = $wpforo->post->get_post_likes_count($postid);
774 $post['likers_usernames'] = $wpforo->post->get_likers_usernames($postid);
775 }
776 if(!empty($post)){
777 $cache_item = array( $postid => $post );
778 $wpforo->cache->create('item', $cache_item, 'post');
779 }
780 }
781 }
782 }
783
784 if( $var != 'item' && $var ){
785 $post = ( isset($post[$var]) ) ? $post[$var] : '';
786 }
787
788 if( $echo ){
789 echo $post;
790 }
791 else{
792 return $post;
793 }
794 }
795
796 function wpforo_topic( $topicid, $var = 'item', $echo = false ){
797
798 global $wpforo;
799 $topic = ( $var == 'item' ) ? array() : '';
800 if( !$topicid ) return $topic;
801 $cache = $wpforo->cache->on('object_cashe');
802 if( $cache ) $topic = $wpforo->cache->get_item( $topicid, 'topic' );
803
804 if( empty($topic) ){
805 if( !$cache && $var == 'url' ){
806 $topic['url'] = $wpforo->topic->get_topic_url( $topicid );
807 }
808 elseif( !$cache && $var == 'is_answer' ){
809 $topic['is_answer'] = $wpforo->topic->is_solved( $topicid );
810 }
811 else{
812 $topic = $wpforo->topic->get_topic($topicid);
813 if( !empty($topic) ){
814 $topic['url'] = $wpforo->topic->get_topic_url($topic);
815 $topic['is_answer'] = $wpforo->topic->is_solved( $topic['topicid'] );
816 if(!empty($topic)){
817 $cache_item = array( $topicid => $topic );
818 $wpforo->cache->create('item', $cache_item, 'topic');
819 }
820 }
821 }
822 }
823
824 if( $var != 'item' && $var ){
825 $topic = ( isset($topic[$var]) ) ? $topic[$var] : '';
826 }
827
828 if( $echo ){
829 echo $topic;
830 }
831 else{
832 return $topic;
833 }
834 }
835
836
837 function wpforo_forum( $forumid, $var = 'item', $echo = false ){
838
839 global $wpforo;
840 $data = array();
841 $forum = ( $var == 'item' ) ? array() : '';
842 $cache = $wpforo->cache->on('object_cashe');
843 if( !$forumid ) return $forum;
844 if( $cache ) $forum = $wpforo->cache->get_item( $forumid, 'forum' );
845
846 if( empty($forum) ){
847 if( !$cache && ($var == 'childs' || $var == 'counts') ){
848 if( $var == 'childs' ) {
849 $wpforo->forum->get_childs($forumid, $data);
850 $forum['childs'] = $data;
851 }
852 else{
853 $wpforo->forum->get_childs($forumid, $data);
854 $forum['childs'] = $data;
855 $forum['counts'] = $wpforo->forum->get_counts( $data );
856 }
857 }
858 else{
859 $forum = $wpforo->forum->get_forum($forumid);
860 if( !empty($forum) ){
861 if( $cache ){
862 $wpforo->forum->get_childs($forum['forumid'], $data);
863 $forum['childs'] = $data;
864 $forum['counts'] = $wpforo->forum->get_counts( $data );
865 }
866 if(!empty($forum)){
867 $cache_item = array( $forumid => $forum );
868 $wpforo->cache->create('item', $cache_item, 'forum');
869 }
870 }
871 }
872 }
873
874 if( $var != 'item' && $var ){
875 $forum = ( isset($forum[$var]) ) ? $forum[$var] : '';
876 }
877
878 if( $echo ){
879 echo $forum;
880 }
881 else{
882 return $forum;
883 }
884 }
885
886 function wpforo_member( $object, $var = 'item', $echo = false ){
887
888 global $wpforo;
889 $member = array();
890 if( empty( $object ) ) return $member;
891
892 if( is_array( $object ) && isset($object['userid']) && $object['userid'] == 0 ){
893 $member = $wpforo->member->get_guest( $object );
894 }
895 else{
896 $userid = ( is_array( $object ) && isset($object['userid']) ) ? intval($object['userid']) : intval($object);
897 $member = $wpforo->member->get_member( $userid );
898 }
899
900 if( $var != 'item' && $var ){
901 $member = ( isset($member[$var]) ) ? $member[$var] : '';
902 }
903
904 if( $echo ){
905 echo $member;
906 }
907 else{
908 return $member;
909 }
910 }
911
912 function wpforo_member_link( $member, $prefix = '', $length = 30, $class = '', $echo = true ){
913 $display_name = ( isset($member['display_name']) && $member['display_name'] ) ? $member['display_name'] : wpforo_phrase('Anonymous', false);
914 $nofollow = ( !wpforo_feature('seo-profile')) ? ' rel="nofollow" ' : '';
915 if( isset($member['profile_url']) && $member['profile_url'] ){
916 ?><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
917 }
918 else{
919 ?><?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
920 }
921 }
922
923 add_shortcode('wpforo-lostpassword', 'wpforo_lostpassword');
924 function wpforo_lostpassword(){ ?>
925 <p id="wpforo-title"><?php wpforo_phrase('Reset Password') ?></p>
926
927 <form name="wpflogin" action="<?php echo wp_lostpassword_url(); ?>" method="POST">
928 <div class="wpforo-login-wrap">
929 <div class="wpforo-login-content">
930 <table class="wpforo-login-table wpfcl-1" width="100%" border="0" cellspacing="0" cellpadding="0" style="width:100%; display:table;">
931 <tbody style="width:100%;">
932 <tr class="wpfbg-9">
933 <td class="wpf-login-label">
934 <p class="wpf-label wpfcl-1">
935 <label for="userlogin"><?php wpforo_phrase('Email or Username') ?>:</label>
936 </p>
937 </td>
938 <td class="wpf-login-field">
939 <input id="userlogin" autofocus required type="text" name="user_login" class="wpf-login-text wpfw-60" />
940 <p><?php wpforo_phrase('Enter your email address and we\'ll send you a link you can use to pick a new password.') ?></p>
941 </td>
942 </tr>
943 <tr class="wpfbg-9">
944 <td class="wpf-login-label">&nbsp;</td>
945 <td class="wpf-login-field">
946 <input type="submit" name="submit" value="<?php wpforo_phrase('Reset Password') ?>" />
947 </td>
948 </tr>
949 </tbody>
950 </table>
951 </div>
952 </div>
953 </form>
954
955 <?php
956 }
957
958 add_shortcode('wpforo-resetpassword', 'wpforo_resetpassword');
959 function wpforo_resetpassword(){ ?>
960 <p id="wpforo-title"><?php wpforo_phrase('Reset Password') ?></p>
961
962 <form name="wpflogin" action="<?php echo site_url( 'wp-login.php?action=resetpass' ); ?>" method="POST" autocomplete="off">
963 <input type="hidden" name="rp_key" value="<?php echo $_REQUEST['rp_key'] ?>">
964 <input type="hidden" name="rp_login" value="<?php echo $_REQUEST['rp_login'] ?>">
965 <div class="wpforo-login-wrap">
966 <div class="wpforo-login-content">
967 <table class="wpforo-login-table wpfcl-1" width="100%" border="0" cellspacing="0" cellpadding="0" style="width:100%; display:table;">
968 <tbody style="width:100%;">
969 <tr class="wpfbg-9">
970 <td class="wpf-login-label">
971 <p class="wpf-label wpfcl-1">
972 <label for="pass1"><?php wpforo_phrase('New password') ?></label>
973 </p>
974 </td>
975 <td class="wpf-login-field">
976 <input type="password" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" required autofocus />
977 </td>
978 </tr>
979 <tr class="wpfbg-9">
980 <td class="wpf-login-label">
981 <p class="wpf-label wpfcl-1">
982 <label for="pass2"><?php wpforo_phrase('Repeat new password') ?></label>
983 </p>
984 </td>
985 <td class="wpf-login-field">
986 <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" required />
987 </td>
988 </tr>
989 <tr class="wpfbg-9">
990 <td colspan="2">
991 <p class="description" style="text-align: center;"><?php echo wp_get_password_hint(); ?></p>
992 </td>
993 </tr>
994 <tr class="wpfbg-9">
995 <td class="wpf-login-label">&nbsp;</td>
996 <td class="wpf-login-field">
997 <input type="submit" name="submit" value="<?php wpforo_phrase('Reset Password'); ?>" />
998 </td>
999 </tr>
1000 </tbody>
1001 </table>
1002 </div>
1003 </div>
1004 </form>
1005
1006 <?php
1007 }
1008
1009 #############################################################################################
1010 /**
1011 * Generates according page form fields using tpl->form_fields() function
1012 *
1013 * @since 1.4.0
1014 *
1015 * @param array $fields arguments
1016 * @param boolean $echo
1017 *
1018 * @return string form fields HTML
1019 */
1020 function wpforo_fields( $fields, $echo = true ){
1021 if( empty($fields) ) return '';
1022 global $wpforo;
1023 $fields = apply_filters( 'wpforo_form_fields', $fields );
1024 $html = $wpforo->tpl->form_fields( $fields );
1025 if( $echo ){
1026 echo $html;
1027 }
1028 else{
1029 return $html;
1030 }
1031 }
1032
1033 ##################################################################################################
1034 /**
1035 * Collects Registration Page POST data and sends to field generator function
1036 *
1037 * @since 1.4.0
1038 *
1039 * @param array $fields arguments
1040 *
1041 * @return NULL
1042 */
1043
1044 function wpforo_register_page_field_values( $fields ){
1045 global $wpforo;
1046 $wpforo->form['value']['user_login'] = (isset($_POST['wpfreg']['user_login'])) ? sanitize_user($_POST['wpfreg']['user_login']) : '';
1047 $wpforo->form['value']['user_email'] = (isset($_POST['wpfreg']['user_email'])) ? sanitize_email($_POST['wpfreg']['user_email']) : '';
1048 $wpforo->form['varname'] = 'wpfreg';
1049 }
1050 add_action( 'wpforo_register_page_start', 'wpforo_register_page_field_values', 10, 1 );
1051
1052
1053 ##################################################################################################
1054 /**
1055 * Collects Account Page field data and sends to field generator function
1056 *
1057 * @since 1.4.0
1058 *
1059 * @param array $fields arguments
1060 *
1061 * @return NULL
1062 */
1063
1064 function wpforo_account_page_field_values( $fields ){
1065 global $wpforo;
1066
1067 if( isset($wpforo->current_object['user']) && !empty($wpforo->current_object['user']) ){
1068 $user = $wpforo->current_object['user'];
1069 $user = apply_filters('wpforo_profile_header_obj', $user);
1070 $wpforo->form['value'] = $user;
1071 $wpforo->form['varname'] = 'member';
1072 }
1073 }
1074 add_action( 'wpforo_account_page_start', 'wpforo_account_page_field_values', 10, 1 );
1075
1076
1077 ##################################################################################################
1078 /**
1079 * Collects Profile Page field data and sends to field generator function
1080 *
1081 * @since 1.4.0
1082 *
1083 * @param array $fields arguments
1084 *
1085 * @return NULL
1086 */
1087
1088 function wpforo_profile_page_field_values( $fields ){
1089 global $wpforo;
1090
1091 if( isset($wpforo->current_object['user']) && !empty($wpforo->current_object['user']) ){
1092 $user = $wpforo->current_object['user'];
1093 $wpforo->form['value'] = $user;
1094 }
1095 }
1096 add_action( 'wpforo_profile_page_start', 'wpforo_profile_page_field_values', 10, 1 );
1097
1098
1099 function wpforo_search_page_field_values( $fields ){
1100 global $wpforo;
1101 $wpforo->form['value'] = ( !empty($_GET) ? (array) $_GET : array() );
1102 $wpforo->form['varname'] = '';
1103 }
1104 add_action( 'wpforo_search_page_start', 'wpforo_search_page_field_values', 10, 1 );
1105
1106 function wpforo_user_avatar( $user, $size, $attr = '', $lastmod = false ){
1107 global $wpforo;
1108 $avatar_html = '';
1109 if( is_int($user) && $user ){
1110 $avatar_html = ($size) ? get_avatar($user, $size) : get_avatar($user);
1111 if($attr) $avatar_html = str_replace('<img', '<img ' . $attr, $avatar_html);
1112 }
1113 elseif( is_array($user) && !empty($user) ){
1114 $avatar_html = $wpforo->member->avatar($user, $attr, $size); //'alt="'.esc_html($display_name).'"'
1115 }
1116
1117 if( $lastmod ){
1118 $url = wpforo_avatar_url( $avatar_html );
1119 if($url){
1120 $avatar_html = str_replace($url, $url . '?lm=' . time(), $avatar_html);
1121 }
1122 }
1123 return $avatar_html;
1124 }
1125
1126 function wpforo_register_fields(){
1127 global $wpforo;
1128
1129 $fields = $wpforo->member->get_register_fields();
1130 do_action( 'wpforo_register_page_start', $fields );
1131
1132 return $fields;
1133 }
1134
1135 function wpforo_account_fields(){
1136 global $wpforo;
1137
1138 $fields = $wpforo->member->get_account_fields();
1139 do_action( 'wpforo_account_page_start', $fields );
1140
1141 return $fields;
1142 }
1143
1144 function wpforo_profile_fields(){
1145 global $wpforo;
1146
1147 $fields = $wpforo->member->get_profile_fields();
1148 do_action( 'wpforo_profile_page_start', $fields );
1149
1150 return $fields;
1151 }
1152
1153 function wpforo_search_fields(){
1154 global $wpforo;
1155
1156 $fields = $wpforo->member->get_search_fields();
1157 do_action( 'wpforo_search_page_start', $fields );
1158
1159 if( $wpforo->member->options['search_type'] == 'search' ){
1160 $fields = array(
1161 array(
1162 array(
1163 array(
1164 'type' => 'search',
1165 'isDefault' => 1,
1166 'isRemovable' => 0,
1167 'isRequired' => 0,
1168 'isEditable' => 1,
1169 'class' => 'wpf-member-search-field',
1170 'label' => wpforo_phrase('Find a member', false),
1171 'title' => wpforo_phrase('Find a member', false),
1172 'placeholder' => wpforo_phrase('Display Name or Nicename', false),
1173 'faIcon' => 'fa-search',
1174 'name' => 'wpfms',
1175 'canBeInactive' => 0,
1176 'can' => '',
1177 'isSearchable' => 1
1178 )
1179 )
1180 )
1181 );
1182 }
1183
1184 return $fields;
1185 }
1186
1187
1188 function wpforo_unread_forum( $logid, $return = 'class', $echo = true ){
1189 $unread = false;
1190 if(!wpforo_feature('view-logging')) return;
1191 $viwed_ids = wpforo_getcookie( 'wpf_viewed_forums', true );
1192 if( empty($viwed_ids) ) $unread = true;
1193 if( is_array($viwed_ids) && !in_array( $logid, $viwed_ids ) ) $unread = true;
1194 if( $unread ){ if( $return == 'class' ){ $log = 'wpf_forum_unread'; } else{ $log = true; } if( $echo ){ echo $log; } else { return $log; } }
1195 }
1196
1197 function wpforo_unread_topic( $logid, $return = 'class', $echo = true ){
1198 $unread = false;
1199 if(!wpforo_feature('view-logging')) return;
1200 $viwed_ids = wpforo_getcookie( 'wpf_viewed_topics', true );
1201 if( empty($viwed_ids) ) $unread = true;
1202 if( is_array($viwed_ids) && !in_array( $logid, $viwed_ids ) ) $unread = true;
1203 if( $unread ){ if( $return == 'class' ){ $log = 'wpf_topic_unread'; } else{ $log = true; } if( $echo ){ echo $log; } else { return $log; } }
1204 }
1205
1206 if( !function_exists('custom_wpforo_get_account_fields') ){
1207 function custom_wpforo_get_account_fields($fields){
1208 $hide = array(
1209 'user_email',
1210 'user_nicename'
1211 );
1212
1213 foreach ( $fields as $row_key => $row ){
1214 foreach ( $row as $col_key => $col ){
1215 foreach ( $col as $key => $field ){
1216 if( in_array($field['fieldKey'], $hide) ){
1217 unset($fields[$row_key][$col_key][$key]);
1218 }
1219 }
1220 }
1221 }
1222
1223 return $fields;
1224 }
1225 // add_filter('wpforo_get_account_fields', 'custom_wpforo_get_account_fields', 20);
1226 }
1227