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