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

904 lines 36.3 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 return esc_url($wp_login_url);
20 }
21
22
23 function wpforo_register_url(){
24 global $wpforo;
25 if(isset($wpforo->member_options['register_url']) && $wpforo->member_options['register_url']){
26 $wp_register_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member_options['register_url'] , '/');
27 }
28 else{
29 $wp_register_url = wpforo_home_url('?wpforo=signup');
30 }
31 return esc_url($wp_register_url);
32 }
33
34
35 function wpforo_lostpass_url(){
36 global $wpforo;
37 if(isset($wpforo->member_options['lost_password_url']) && $wpforo->member_options['lost_password_url']){
38 $wp_lostpass_url = trim(get_bloginfo('url') , '/') . '/' . ltrim($wpforo->member_options['lost_password_url'] , '/');
39 }
40 else{
41 $wp_lostpass_url = wp_lostpassword_url( wpforo_get_request_uri() );
42 }
43 return esc_url($wp_lostpass_url);
44 }
45
46
47 function wpforo_menu_filter( $items, $menu ) {
48 global $wpforo;
49 if ( !wpforo_is_admin() ) {
50 foreach ( $items as $key => $item ) {
51 if(isset($item->url)){
52 if( strpos($item->url, '%wpforo-') !== FALSE ){
53 $shortcode = trim(str_replace(array('https://', 'http://', '/', '%'), '', $item->url));
54 if(isset($wpforo->menu) && isset($wpforo->menu[$shortcode])){
55 if(isset($wpforo->menu[$shortcode]['href'])) $item->url = $wpforo->menu[$shortcode]['href'];
56 if(isset($wpforo->menu[$shortcode]['attr']) && strpos($wpforo->menu[$shortcode]['attr'], 'wpforo-active') !== FALSE ) $item->classes[] = 'wpforo-active';
57 }
58 else{
59 unset($items[$key]);
60 }
61 }
62 }
63 }
64 }
65 return $items;
66 }
67 add_filter( 'wp_get_nav_menu_items', 'wpforo_menu_filter', 1, 2 );
68
69 function wpforo_menu_nofollow_items($item_output, $item, $depth, $args) {
70 if( isset($item->url) && strpos($item->url, '?wpforo') !== FALSE ) {
71 $item_output = str_replace('<a ', '<a rel="nofollow" ', $item_output);
72 }
73 return $item_output;
74 }
75 add_filter('walker_nav_menu_start_el', 'wpforo_menu_nofollow_items', 1, 4);
76
77 function wpforo_profile_plugin_menu( $userid = 0 ){
78
79 $menu_html = '<div class="wpf-profile-plugin-menu">';
80
81 if($url = wpforo_has_shop_plugin($userid)){
82 $menu_html .= '<div id="wpf-pp-shop-menu" class="wpf-pp-menu">
83 <a class="wpf-pp-menu-item" href="' . esc_url($url) . '">
84 <i class="fa fa-shopping-cart"></i><span>'.wpforo_phrase('Shop Account', false).'</span>
85 </a>
86 </div>';
87 }
88 if($url = wpforo_has_profile_plugin($userid)){
89 $menu_html .= '<div id="wpf-pp-site-menu" class="wpf-pp-menu">
90 <a class="wpf-pp-menu-item" href="' . esc_url($url) . '">
91 <i class="fa fa-user"></i>
92 <span>'.wpforo_phrase('Site Profile', false).'</span>
93 </a>
94 </div>';
95 }
96 $menu_html .= '<div id="wpf-pp-forum-menu" class="wpf-pp-menu">
97 <div class="wpf-pp-menu-item">
98 <i class="fa fa-comments"></i>
99 <span>'.wpforo_phrase('Forum Profile', false).'</span>
100 </div>
101 </div>';
102
103 $menu_html .= "\r\n<div class=\"wpf-clear\"></div>\r\n</div>";
104 $menu_html = apply_filters( 'wpforo_profile_plugin_menu_filter', $menu_html, $userid );
105 echo $menu_html; //This is a HTML content//
106 }
107 add_action( 'wpforo_profile_plugin_menu_action', 'wpforo_profile_plugin_menu', 1 );
108
109 class wpforo_menu_walker extends Walker_Nav_Menu {
110 public function start_lvl( &$output, $depth = 0, $args = array() ) {
111 $indent = str_repeat("\t", $depth);
112 $output .= "\n$indent<ul class=\"sub-menu\">\n";
113 }
114 public function end_lvl( &$output, $depth = 0, $args = array() ) {
115 $indent = str_repeat("\t", $depth);
116 $output .= "$indent</ul>\n";
117 }
118 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
119 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
120 $classes = empty( $item->classes ) ? array() : (array) $item->classes;
121 $classes[] = 'menu-item-' . $item->ID;
122 $args = apply_filters( 'wpforo_nav_menu_item_args', $args, $item, $depth );
123 $class_names = join( ' ', apply_filters( 'wpforo_nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
124 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
125 $id = apply_filters( 'wpforo_nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
126 $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
127 $output .= $indent . '<li' . $id . $class_names .'>';
128 $atts = array();
129 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
130 $atts['target'] = ! empty( $item->target ) ? $item->target : '';
131 $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
132 $atts['href'] = ! empty( $item->url ) ? $item->url : '';
133 $atts = apply_filters( 'wpforo_nav_menu_link_attributes', $atts, $item, $args, $depth );
134 $attributes = '';
135 foreach ( $atts as $attr => $value ) {
136 if ( ! empty( $value ) ) {
137 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
138 $attributes .= ' ' . $attr . '="' . $value . '"';
139 }
140 }
141 $title = apply_filters( 'wpforo_the_title', $item->title, $item->ID );
142 $title = apply_filters( 'wpforo_nav_menu_item_title', $title, $item, $args, $depth );
143 $item_output = $args->before;
144 $item_output .= '<a'. $attributes .'>';
145 $item_output .= $args->link_before . $title . $args->link_after;
146 $item_output .= '</a>';
147 $item_output .= $args->after;
148 $output .= apply_filters( 'wpforo_walker_nav_menu_start_el', $item_output, $item, $depth, $args );
149 }
150 public function end_el( &$output, $item, $depth = 0, $args = array() ) {
151 $output .= "</li>";
152 }
153 }
154
155 function wpforo_widgets_init() {
156 register_sidebar(array(
157 'name' => __('wpForo Sidebar', 'wpforo'),
158 'description' => __("NOTE: If you're going to add widgets in this sidebar, please use 'Full Width' template for wpForo index page to avoid sidebar duplication.", 'wpforo'),
159 'id' => 'forum-sidebar',
160 'before_widget' => '<aside id="%1$s" class="footer-widget-col %2$s clearfix">',
161 'after_widget' => '</aside>',
162 'before_title' => '<h3 class="widget-title">',
163 'after_title' => '</h3>',
164 ));
165 }
166 add_action('widgets_init', 'wpforo_widgets_init', 11);
167
168 class wpForo_Widget_search extends WP_Widget {
169 function __construct() {
170 parent::__construct(
171 'wpForo_Widget_search', // Base ID
172 'wpForo Search', // Name
173 array( 'description' => 'wpForo search form' ) // Args
174 );
175 }
176 public function widget( $args, $instance ) {
177 global $wpforo;
178 echo $args['before_widget']; //This is a HTML content//
179 echo '<div id="wpf-widget-search" class="wpforo-widget-wrap">';
180 if ( ! empty( $instance['title'] ) ) {
181 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; //This is a HTML content//
182 }
183 echo '<div class="wpforo-widget-content">';
184 ?>
185 <form action="<?php echo wpforo_home_url() ?>" method="get">
186 <?php wpforo_make_hidden_fields_from_url( wpforo_home_url() ) ?>
187 <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;">
188 </form>
189 <?php
190 echo '</div></div>';
191 echo $args['after_widget']; //This is a HTML content//
192 }
193 public function form( $instance ) {
194 $title = isset( $instance['title'] ) ? $instance['title'] : 'Forum Search';
195 ?>
196 <p>
197 <label><?php _e('Title', 'wpforo'); ?>:</label>
198 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
199 </p>
200 <?php
201 }
202 public function update( $new_instance, $old_instance ) {
203 $instance = array();
204 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
205 return $instance;
206 }
207 } // widget wpforo search
208
209 class wpForo_Widget_login_form extends WP_Widget {
210 function __construct() {
211 parent::__construct(
212 'wpForo_Widget_login_form', // Base ID
213 'wpForo Login Form', // Name
214 array( 'description' => 'wpForo login form' ) // Args
215 );
216 }
217 public function widget( $args, $instance ) {
218 global $wpforo;
219 echo $args['before_widget']; //This is a HTML content//
220 echo '<div id="wpf-widget-login" class="wpforo-widget-wrap">';
221 if ( ! empty( $instance['title'] ) ) {
222 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; //This is a HTML content//
223 }
224 echo '<div class="wpforo-widget-content">';
225 ?>
226 <?php if( is_user_logged_in() && !empty($wpforo->current_user) ) : ?>
227 <?php extract($wpforo->current_object, EXTR_OVERWRITE); extract($wpforo->current_user, EXTR_OVERWRITE); ?>
228 <div class="wpforo-profile-wrap">
229 <div class="wpforo-profile-head">
230 <div class="h-header">
231 <?php if( wpforo_feature('avatars', $wpforo) ): $rsz =''; ?>
232 <div class="h-left"><?php echo $wpforo->member->get_avatar($userid, 'alt="'.esc_attr($display_name).'"', 150); ?></div>
233 <?php else: $rsz = ' style="margin-left:10px;"'; endif; ?>
234 <div class="h-right" <?php echo $rsz; ?>>
235 <div class="h-top">
236 <div class="profile-display-name">
237 <?php $wpforo->member->show_online_indicator($userid) ?>
238 <?php echo $display_name ? esc_html($display_name) : esc_html(urldecode($user_nicename)) ?>
239 </div>
240 <div class="profile-stat-data">
241 <div class="profile-stat-data-item"><?php wpforo_phrase('Group') ?>: <?php wpforo_phrase($groupname) ?></div>
242 <div class="profile-stat-data-item"><?php wpforo_phrase('Joined') ?>: <?php esc_html(wpforo_date($user_registered, 'Y/m/d')) ?></div>
243 </div>
244 </div>
245 </div>
246 <div class="wpf-clear"></div>
247 </div>
248 <div class="h-footer wpfbg-2">
249
250 <div class="h-bottom">
251 <?php $wpforo->tpl->member_menu($userid) ?>
252 <a href="?wpforo=logout"><?php wpforo_phrase('logout') ?></a>
253 <div class="wpf-clear"></div>
254 </div>
255 </div>
256 </div>
257 </div>
258
259 <?php else : ?>
260
261 <form name="wpflogin" action="" method="POST">
262 <div class="wpforo-login-wrap">
263 <div class="wpforo-login-content">
264 <table class="wpforo-login-table wpfcl-1" width="100%" border="0" cellspacing="0" cellpadding="0">
265 <tr class="wpfbg-9">
266 <td class="wpf-login-label">
267 <p class="wpf-label wpfcl-1"><?php wpforo_phrase('Username') ?>:</p>
268 </td>
269 <td class="wpf-login-field"><input autofocus required="TRUE" type="text" name="log" class="wpf-login-text wpfw-60" /></td>
270 </tr>
271 <tr class="wpfbg-9">
272 <td class="wpf-login-label">
273 <p class="wpf-label wpfcl-1"><?php wpforo_phrase('Password') ?>:</p>
274 </td>
275 <td class="wpf-login-field"><input required="TRUE" type="password" name="pwd" class="wpf-login-text wpfw-60" /></td>
276 </tr>
277 <tr class="wpfbg-9"><td colspan="2" style="text-align: center;"><?php do_action('login_form') ?></td></tr>
278 <tr class="wpfbg-9">
279 <td class="wpf-login-label">&nbsp;</td>
280 <td class="wpf-login-field">
281 <p class="wpf-extra wpfcl-1">
282 <input type="checkbox" value="1" name="rememberme" id="wpf-login-remember">
283 <label for="wpf-login-remember"><?php wpforo_phrase('Remember Me') ?> |</label>
284 <a href="<?php echo esc_url(wp_lostpassword_url(wpforo_get_request_uri())); ?>" class="wpf-forgot-pass"><?php wpforo_phrase('Lost your password?') ?></a>
285 <a href="<?php echo esc_url( wpforo_home_url('?wpforo=register') ) ?>"><?php wpforo_phrase('register') ?></a>
286 </p>
287 <input type="submit" name="wpforologin" value="<?php wpforo_phrase('Sign In') ?>" />
288 </td>
289 </tr>
290 </table>
291 </div>
292 </div>
293 </form>
294
295 <?php endif ?>
296 <?php
297 echo '</div></div>';
298 echo $args['after_widget'];
299 }
300 public function form( $instance ) {
301 $title = isset( $instance['title'] ) ? $instance['title'] : 'Account';
302 ?>
303 <p>
304 <label><?php _e('Title', 'wpforo'); ?>:</label>
305 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
306 </p>
307 <?php
308 }
309 public function update( $new_instance, $old_instance ) {
310 $instance = array();
311 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
312 return $instance;
313 }
314 } // widget wpforo login
315
316
317 class wpForo_Widget_online_members extends WP_Widget {
318 function __construct() {
319 parent::__construct(
320 'wpForo_Widget_online_members', // Base ID
321 'wpForo Online Members', // Name
322 array( 'description' => 'Online members.' ) // Args
323 );
324 }
325 public function widget( $args, $instance ) {
326 global $wpforo;
327 echo $args['before_widget']; //This is a HTML content//
328 echo '<div id="wpf-widget-online-users" class="wpforo-widget-wrap">';
329 if ( ! empty( $instance['title'] ) ) {
330 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
331 }
332 // widget content from front end
333 $online_members = $wpforo->member->get_online_members($instance['count']);
334 echo '<div class="wpforo-widget-content">';
335 if(!empty($online_members)){
336 echo '<ul>
337 <li>
338 <div class="wpforo-list-item">';
339 foreach( $online_members as $member ){
340 if( $instance['display_avatar'] ): ?>
341 <a href="<?php echo esc_url($wpforo->member->get_profile_url( $member['ID'] )) ?>" class="onlineavatar">
342 <?php echo $wpforo->member->get_avatar( $member['ID'], 'style="width:95%;" class="avatar" title="'.esc_attr($member['display_name']).'"'); ?>
343 </a>
344 <?php else: ?>
345 <a href="<?php echo esc_url($wpforo->member->get_profile_url( $member['ID'] )) ?>" class="onlineuser"><?php echo esc_html($member['display_name']) ?></a>
346 <?php endif; ?>
347 <?php
348 }
349 echo '<div class="wpf-clear"></div>
350 </div>
351 </li>
352 </ul>
353 </div>';
354 }
355 else{
356 echo '<p class="wpf-widget-note">&nbsp;'.wpforo_phrase('No online members at the moment', false).'</p>';
357 }
358 echo '</div>';
359 echo $args['after_widget'];//This is a HTML content//
360 }
361 public function form( $instance ) {
362 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Online Members';
363 $count = ! empty( $instance['count'] ) ? $instance['count'] : '15';
364 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
365 ?>
366 <p>
367 <label><?php _e('Title', 'wpforo'); ?>:</label>
368 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
369 </p><p>
370 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
371 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr( $count ) ; ?>">
372 </p><p>
373 <label>
374 <input<?php checked( $display_avatar ); ?> type="checkbox" value="1" name="<?php echo esc_attr( $this->get_field_name( 'display_avatar' )); ?>"/>
375 <?php _e('Display Avatars', 'wpforo'); ?>
376 </label>
377 </p>
378 <?php
379 }
380 public function update( $new_instance, $old_instance ) {
381 $instance = array();
382 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
383 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
384 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
385 return $instance;
386 }
387 } // widget online members
388
389 class wpForo_Widget_recent_topics extends WP_Widget {
390 function __construct() {
391 parent::__construct(
392 'wpForo_Widget_recent_topics', // Base ID
393 'wpForo Recent Topics', // Name
394 array( 'description' => 'Your forum\'s recent topics.' ) // Args
395 );
396 }
397 public function widget( $args, $instance ) {
398 global $wpforo;
399 echo $args['before_widget'];//This is a HTML content//
400 echo '<div id="wpf-widget-recent-replies" class="wpforo-widget-wrap">';
401 if ( ! empty( $instance['title'] ) ) {
402 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
403 }
404 // widget content from front end
405 $topic_args = array( // forumid, order, parentid
406 'orderby' => 'created',
407 'order' => 'DESC', // ASC DESC
408 'row_count' => $instance['count'] // 4 or 1 ...
409 );
410 $topics = $wpforo->topic->get_topics_filtered($topic_args);
411 echo '<div class="wpforo-widget-content"><ul>';
412 foreach( $topics as $topic ){
413 $topic_url = wpforo_topic($topic['topicid'], 'url');
414 $member = wpforo_member($topic);
415 ?>
416 <li>
417 <div class="wpforo-list-item">
418 <?php if( $instance['display_avatar'] ): ?>
419 <div class="wpforo-list-item-left">
420 <?php echo $wpforo->member->get_avatar( $topic['userid']); ?>
421 </div>
422 <?php endif; ?>
423 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
424 <p class="posttitle"><a href="<?php echo esc_url($topic_url) ?>"><?php echo esc_html($topic['title']) ?></a></p>
425 <p class="postuser"><?php wpforo_phrase('by') ?> <?php wpforo_member_link($member) ?>, <span style="white-space:nowrap;"><?php esc_html(wpforo_date($topic['created'])) ?></span></p>
426 </div>
427 <div class="wpf-clear"></div>
428 </div>
429 </li>
430 <?php
431 }
432 echo '</ul></div>';
433 echo '</div>';
434 echo $args['after_widget'];//This is a HTML content//
435 }
436 public function form( $instance ) {
437 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Topics';
438 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
439 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
440 ?>
441 <p>
442 <label><?php _e('Title', 'wpforo'); ?>:</label>
443 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
444 </p><p>
445 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
446 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
447 </p><p>
448 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
449 <?php _e('Display with Avatars', 'wpforo'); ?></label>
450 </p>
451 <?php
452 }
453 public function update( $new_instance, $old_instance ) {
454 $instance = array();
455 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
456 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
457 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
458 return $instance;
459 }
460 } // Recent topics
461
462
463 class wpForo_Widget_recent_replies extends WP_Widget {
464 function __construct() {
465 parent::__construct(
466 'wpForo_Widget_recent_replies', // Base ID
467 'wpForo Recent Posts', // Name
468 array( 'description' => 'Your forum\'s recent posts.' ) // Args
469 );
470 }
471
472 public function widget( $args, $instance ) {
473 global $wpforo;
474 echo $args['before_widget'];//This is a HTML content//
475 echo '<div id="wpf-widget-recent-replies" class="wpforo-widget-wrap">';
476 if ( ! empty( $instance['title'] ) ) {
477 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
478 }
479 // widget content from front end
480 $posts_args = array(
481 'orderby' => 'created',
482 'order' => 'DESC',
483 'row_count' => $instance['count'],
484 'check_private' => true
485 );
486 $recent_posts = $wpforo->post->get_posts_filtered($posts_args);
487 echo '<div class="wpforo-widget-content"><ul>';
488 foreach( $recent_posts as $post ){
489 $post_url = wpforo_post( $post['postid'], 'url' );
490 $member = wpforo_member( $post );
491 ?>
492 <li>
493 <div class="wpforo-list-item">
494 <?php if( $instance['display_avatar'] ): ?>
495 <div class="wpforo-list-item-left">
496 <?php echo $wpforo->member->get_avatar( $post['userid']); ?>
497 </div>
498 <?php endif; ?>
499 <div class="wpforo-list-item-right" <?php if( !$instance['display_avatar'] ): ?> style="width:100%"<?php endif; ?>>
500 <p class="posttitle"><a href="<?php echo esc_url($post_url) ?>"><?php echo esc_html($post['title']) ?></a></p>
501 <p class="posttext"><?php echo esc_html(wpforo_text($post['body'], 55)); ?></p>
502 <p class="postuser"><?php wpforo_phrase('by') ?> <?php wpforo_member_link($member) ?>, <?php esc_html(wpforo_date($post['created'])) ?></p>
503 </div>
504 <div class="wpf-clear"></div>
505 </div>
506 </li>
507 <?php
508 }
509 echo '</ul></div>';
510 echo '</div>';
511 echo $args['after_widget'];//This is a HTML content//
512 }
513 public function form( $instance ) {
514 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Recent Posts';
515 $count = ! empty( $instance['count'] ) ? $instance['count'] : '9';
516 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
517 ?>
518 <p>
519 <label><?php _e('Title', 'wpforo'); ?>:</label>
520 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
521 </p><p>
522 <label><?php _e('Number of Items', 'wpforo'); ?></label>&nbsp;
523 <input type="number" min="1" style="width: 53px;" name="<?php echo esc_attr($this->get_field_name( 'count' )); ?>" value="<?php echo esc_attr($count) ; ?>">
524 </p><p>
525 <label><input <?php checked( $display_avatar ); ?> type="checkbox" name="<?php echo esc_attr($this->get_field_name( 'display_avatar' )); ?>" >
526 <?php _e('Display with Avatars', 'wpforo'); ?></label>
527 </p>
528 <?php
529 }
530 public function update( $new_instance, $old_instance ) {
531 $instance = array();
532 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
533 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? intval( $new_instance['count'] ) : '';
534 $instance['display_avatar'] = isset( $new_instance['display_avatar'] ) ? (bool) $new_instance['display_avatar'] : false;
535 return $instance;
536 }
537 } // Recent replies
538
539
540 class wpforo_widget_forums extends WP_Widget {
541 function __construct() {
542 parent::__construct(
543 'wpforo_widget_forums', // Base ID
544 'wpForo Forums', // Name
545 array( 'description' => 'Forum tree.' ) // Args
546 );
547 }
548 public function widget( $args, $instance ) {
549 global $wpforo;
550 echo $args['before_widget'];//This is a HTML content//
551 echo '<div id="wpf-widget-forums" class="wpforo-widget-wrap">';
552 if ( ! empty( $instance['title'] ) ) {
553 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];//This is a HTML content//
554 }
555 echo '<div class="wpforo-widget-content">';
556 $wpforo->forum->tree('front_list');
557 echo '</div>';
558 echo '</div>';
559 echo $args['after_widget'];//This is a HTML content//
560 }
561 public function form( $instance ) {
562 $title = ! empty( $instance['title'] ) ? $instance['title'] : 'Forums';
563 $display_avatar = isset( $instance['display_avatar'] ) ? (bool) $instance['display_avatar'] : false;
564 ?>
565 <p>
566 <label><?php _e('Title', 'wpforo'); ?>:</label>
567 <input class="widefat" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
568 </p>
569 <?php
570 }
571 public function update( $new_instance, $old_instance ) {
572 $instance = array();
573 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
574 return $instance;
575 }
576 } // forums tree
577
578
579 function wpforo_widget_search() {
580 register_widget( 'wpForo_Widget_search' );
581 }
582 add_action( 'widgets_init', 'wpforo_widget_search' );
583
584 function wpforo_widget_login() {
585 //Under development....
586 //register_widget( 'wpForo_Widget_login_form' );
587 }
588 add_action( 'widgets_init', 'wpforo_widget_login' );
589
590 function wpforo_widget_online_members() {
591 register_widget( 'wpForo_Widget_online_members' );
592 }
593 add_action( 'widgets_init', 'wpforo_widget_online_members' );
594
595 function wpforo_widget_recent_topics() {
596 register_widget( 'wpForo_Widget_recent_topics' );
597 }
598 add_action( 'widgets_init', 'wpforo_widget_recent_topics' );
599
600 function wpforo_widget_recent_replies() {
601 register_widget( 'wpForo_Widget_recent_replies' );
602 }
603 add_action( 'widgets_init', 'wpforo_widget_recent_replies' );
604
605 function wpforo_widget_forums() {
606 //Under Development
607 //register_widget( 'wpforo_widget_forums' );
608 }
609 add_action( 'widgets_init', 'wpforo_widget_forums' );
610
611 function wpforo_post_edited($post, $echo = true){
612 $edit_html = '';
613 if(!empty($post)){
614 $created = wpforo_date($post['created'], 'd/m/Y g:i a', false);
615 $modified = wpforo_date($post['modified'], 'd/m/Y g:i a', false);
616 if( isset($modified) && $created != $modified ){
617 $edit_html = '<div class="wpf-post-edited">' . wpforo_phrase('Edited: ', false) . wpforo_date($post['modified'], 'ago', false) . '</div>';
618 }
619 }
620 if( $echo ) {
621 echo $edit_html;
622 }
623 else{
624 return $edit_html;
625 }
626 }
627
628 function wpforo_hide_title($title, $id = 0) {
629 global $wpforo;
630 if( !wpforo_feature('page-title', $wpforo) ){
631 if( $wpforo_base_slug = basename( wpforo_home_url() ) ) $wpforo_page = get_page_by_path($wpforo_base_slug);
632 if(!empty($wpforo_page)){
633 if (in_the_loop() && is_page($wpforo_page->ID) && $id == get_the_ID()) {
634 $title = '';
635 }
636 }
637 }
638 return $title;
639 }
640 add_filter('the_title', 'wpforo_hide_title', 10, 2);
641
642
643 function wpforo_validate_gravatar( $email ) {
644 $hashkey = md5(strtolower(trim($email)));
645 $uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
646 $data = wp_cache_get($hashkey);
647 if (false === $data) {
648 $response = wp_remote_head($uri);
649 if( is_wp_error($response) ) {
650 $data = 'not200';
651 } else {
652 $data = $response['response']['code'];
653 }
654 wp_cache_set($hashkey, $data, $group = '', $expire = 60*5);
655 }
656 if ($data == '200'){
657 return true;
658 } else {
659 return false;
660 }
661 }
662
663 function wpforo_member_title( $member = array(), $echo = true, $usergroup = true ){
664 global $wpforo;
665 $title = array();
666
667 if(empty($member) || !$member['groupid']) return;
668 $rating_title_ug_enabled = ( isset($wpforo->member_options['rating_title_ug'][$member['groupid']]) && $wpforo->member_options['rating_title_ug'][$member['groupid']] ) ? true : false ;
669 $usergroup_title_ug_enabled = ( isset($wpforo->member_options['title_usergroup'][$member['groupid']]) && $wpforo->member_options['title_usergroup'][$member['groupid']] ) ? true : false ;
670
671 if( wpforo_feature('rating_title', $wpforo) && $rating_title_ug_enabled && isset($member['stat']['title']) ){
672 $title[] = '<span class="wpf-member-title wpfrt" title="' . wpforo_phrase('Rating Title', false) . '">' . esc_html($member['stat']['title']) . '</span>';
673 }
674 if( empty($title) ){
675 $title[] = '<span class="wpf-member-title wpfct" title="' . wpforo_phrase('User Title', false) . '">' . wpforo_phrase($member['title'], false) . '</span>';
676 }
677 if( $usergroup_title_ug_enabled ){
678 $class = '';
679 if( $member['groupid'] == 1 ) $class = ' wpfbg-6 wpfcl-3';
680 if( $member['groupid'] == 2 ) $class = ' wpfbg-5 wpfcl-3';
681 if( $member['groupid'] == 4 ) $class = ' wpfbg-2 wpfcl-3';
682 $title[] = '<span class="wpf-member-title wpfut wpfug-' . intval($member['groupid']) . $class . '" title="' . wpforo_phrase('Usergroup', false) . '">' . esc_html($member['groupname']) . '</span>';
683 }
684 if( !empty($title) ){
685 $title_html = implode(' ', $title);
686 $title_html = apply_filters('wpforo_member_title', $title_html, $member);
687 if( $echo ) {
688 echo $title_html;
689 }
690 else{
691 return $title_html;
692 }
693 }
694 }
695
696 function wpforo_member_badge( $member = array(), $sep = '', $type = 'full' ){
697 global $wpforo;
698 $rating_badge_ug_enabled = ( isset($wpforo->member_options['rating_badge_ug'][$member['groupid']]) && $wpforo->member_options['rating_badge_ug'][$member['groupid']] ) ? true : false ;
699 if( wpforo_feature('rating', $wpforo) && $rating_badge_ug_enabled && isset($member['stat']['rating']) ): ?>
700 <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') ?>">
701 <?php echo $wpforo->member->rating_badge($member['stat']['rating'], $type); ?>
702 </div><?php if($sep): ?><span class="author-rating-sep"><?php echo esc_html($sep); ?></span><?php endif; ?>
703 <?php endif;
704
705 do_action('wpforo_after_member_badge', $member);
706 }
707
708 add_filter( 'body_class', 'wpforo_page_class', 1, 10 );
709 function wpforo_page_class( $classes ) {
710 if(!empty($classes)){
711 if( function_exists('is_wpforo_page') ){
712 if ( is_wpforo_page() ) {
713 return array_merge( $classes, array( 'wpforo' ) );
714 }
715 }
716 }
717 return (array)$classes;
718 }
719
720 ###############################################################################
721 ########################## THEME API FUNCTIONS ################################
722 ###############################################################################
723
724 function wpforo_post( $postid, $var = 'item', $echo = false ){
725
726 global $wpforo;
727 $post = ( $var == 'item' ) ? array() : '';
728 if( !$postid ) return $post;
729 $cache = $wpforo->cache->on('object_cashe');
730 if( $cache ){
731 $post = $wpforo->cache->get_item( $postid, 'post' );
732 }
733 if( empty($post) ){
734 if( !$cache && $var == 'url' ){
735 $post['url'] = $wpforo->post->get_post_url($postid);
736 }
737 elseif( !$cache && $var == 'is_answered' ){
738 $post['is_answered'] = $wpforo->post->is_answered($postid);
739 }
740 elseif( !$cache && $var == 'votes_sum' ){
741 $post['votes_sum'] = $wpforo->post->get_post_votes_sum($postid);
742 }
743 elseif( !$cache && $var == 'likes_count' ){
744 $post['likes_count'] = $wpforo->post->get_post_likes_count($postid);
745 }
746 elseif( !$cache && $var == 'likers_usernames' ){
747 $post['likers_usernames'] = $wpforo->post->get_likers_usernames($postid);
748 }
749 else{
750 $post = $wpforo->post->get_post($postid);
751 if( !empty($post) ){
752 $post['url'] = $wpforo->post->get_post_url($post);
753 if( $cache ){
754 $post['is_answered'] = $wpforo->post->is_answered($postid);
755 $post['votes_sum'] = $wpforo->post->get_post_votes_sum($postid);
756 $post['likes_count'] = $wpforo->post->get_post_likes_count($postid);
757 $post['likers_usernames'] = $wpforo->post->get_likers_usernames($postid);
758 }
759 if(!empty($post)){
760 $cache_item = array( $postid => $post );
761 $wpforo->cache->create('item', $cache_item, 'post');
762 }
763 }
764 }
765 }
766
767 if( $var != 'item' && $var ){
768 $post = ( isset($post[$var]) ) ? $post[$var] : '';
769 }
770
771 if( $echo ){
772 echo $post;
773 }
774 else{
775 return $post;
776 }
777 }
778
779 function wpforo_topic( $topicid, $var = 'item', $echo = false ){
780
781 global $wpforo;
782 $topic = ( $var == 'item' ) ? array() : '';
783 if( !$topicid ) return $topic;
784 $cache = $wpforo->cache->on('object_cashe');
785 if( $cache ) $topic = $wpforo->cache->get_item( $topicid, 'topic' );
786
787 if( empty($topic) ){
788 if( !$cache && $var == 'url' ){
789 $topic['url'] = $wpforo->topic->get_topic_url( $topicid );
790 }
791 elseif( !$cache && $var == 'is_answer' ){
792 $topic['is_answer'] = $wpforo->topic->is_solved( $topicid );
793 }
794 else{
795 $topic = $wpforo->topic->get_topic($topicid);
796 if( !empty($topic) ){
797 $topic['url'] = $wpforo->topic->get_topic_url($topic);
798 $topic['is_answer'] = $wpforo->topic->is_solved( $topic['topicid'] );
799 if(!empty($topic)){
800 $cache_item = array( $topicid => $topic );
801 $wpforo->cache->create('item', $cache_item, 'topic');
802 }
803 }
804 }
805 }
806
807 if( $var != 'item' && $var ){
808 $topic = ( isset($topic[$var]) ) ? $topic[$var] : '';
809 }
810
811 if( $echo ){
812 echo $topic;
813 }
814 else{
815 return $topic;
816 }
817 }
818
819
820 function wpforo_forum( $forumid, $var = 'item', $echo = false ){
821
822 global $wpforo;
823 $data = array();
824 $forum = ( $var == 'item' ) ? array() : '';
825 $cache = $wpforo->cache->on('object_cashe');
826 if( !$forumid ) return $forum;
827 if( $cache ) $forum = $wpforo->cache->get_item( $forumid, 'forum' );
828
829 if( empty($forum) ){
830 if( !$cache && ($var == 'childs' || $var == 'counts') ){
831 if( $var == 'childs' ) {
832 $wpforo->forum->get_childs($forumid, $data);
833 $forum['childs'] = $data;
834 }
835 else{
836 $wpforo->forum->get_childs($forumid, $data);
837 $forum['childs'] = $data;
838 $forum['counts'] = $wpforo->forum->get_counts( $data );
839 }
840 }
841 else{
842 $forum = $wpforo->forum->get_forum($forumid);
843 if( !empty($forum) ){
844 if( $cache ){
845 $wpforo->forum->get_childs($forum['forumid'], $data);
846 $forum['childs'] = $data;
847 $forum['counts'] = $wpforo->forum->get_counts( $data );
848 }
849 if(!empty($forum)){
850 $cache_item = array( $forumid => $forum );
851 $wpforo->cache->create('item', $cache_item, 'forum');
852 }
853 }
854 }
855 }
856
857 if( $var != 'item' && $var ){
858 $forum = ( isset($forum[$var]) ) ? $forum[$var] : '';
859 }
860
861 if( $echo ){
862 echo $forum;
863 }
864 else{
865 return $forum;
866 }
867 }
868
869 function wpforo_member( $object, $var = 'item', $echo = false ){
870
871 global $wpforo;
872 $member = array();
873 if( empty( $object ) ) return $member;
874
875 if( is_array( $object ) && isset($object['userid']) && $object['userid'] == 0 ){
876 $member = $wpforo->member->get_guest( $object );
877 }
878 else{
879 $userid = ( is_array( $object ) && isset($object['userid']) ) ? intval($object['userid']) : intval($object);
880 $member = $wpforo->member->get_member( $userid );
881 }
882
883 if( $var != 'item' && $var ){
884 $member = ( isset($member[$var]) ) ? $member[$var] : '';
885 }
886
887 if( $echo ){
888 echo $member;
889 }
890 else{
891 return $member;
892 }
893 }
894
895 function wpforo_member_link( $member, $prefix = '', $length = 30, $class = '', $echo = true ){
896 $display_name = ( isset($member['display_name']) && $member['display_name'] ) ? $member['display_name'] : wpforo_phrase('Anonymous', false);
897 if( isset($member['profile_url']) && $member['profile_url'] ){
898 ?><a href="<?php echo esc_url($member['profile_url']) ?>"><?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
899 }
900 else{
901 ?><?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
902 }
903 }
904 ?>