esc_html__( 'wpForo Menu', 'wpforo' ),
) );
function wpforo_login_url(){
if(isset(WPF()->member->options['login_url']) && WPF()->member->options['login_url']){
$wp_login_url = trim(get_bloginfo('url') , '/') . '/' . ltrim(WPF()->member->options['login_url'] , '/');
}else{
$request_uri = preg_replace( '#/?\?.*$#isu', '', wpforo_get_request_uri() );
$wp_login_url = (!is_wpforo_page() ? wpforo_home_url('?wpforo=signin') : wpforo_home_url( $request_uri . '?wpforo=signin' ) );
}
return esc_url($wp_login_url);
}
function wpforo_register_url(){
if(isset(WPF()->member->options['register_url']) && WPF()->member->options['register_url']){
$wp_register_url = trim(get_bloginfo('url') , '/') . '/' . ltrim(WPF()->member->options['register_url'] , '/');
}
else{
$wp_register_url = wpforo_home_url('?wpforo=signup');
}
return esc_url($wp_register_url);
}
function wpforo_lostpass_url(){
if(isset(WPF()->member->options['lost_password_url']) && WPF()->member->options['lost_password_url']){
$wp_lostpass_url = trim(get_bloginfo('url') , '/') . '/' . ltrim(WPF()->member->options['lost_password_url'] , '/');
}
else{
$wp_lostpass_url = wp_lostpassword_url( wpforo_get_request_uri() );
}
return esc_url($wp_lostpass_url);
}
function wpforo_menu_filter( $items, $menu ) {
if ( !wpforo_is_admin() ) {
foreach ( $items as $key => $item ) {
if(isset($item->url)){
if( strpos($item->url, '%wpforo-') !== FALSE ){
$shortcode = trim(str_replace(array('https://', 'http://', '/', '%'), '', $item->url));
if(isset(WPF()->menu) && isset(WPF()->menu[$shortcode])){
if(isset(WPF()->menu[$shortcode]['href'])) $item->url = WPF()->menu[$shortcode]['href'];
if(isset(WPF()->menu[$shortcode]['attr']) && strpos(WPF()->menu[$shortcode]['attr'], 'wpforo-active') !== FALSE ) $item->classes[] = 'wpforo-active';
}
else{
unset($items[$key]);
}
}
}
}
}
return $items;
}
add_filter( 'wp_get_nav_menu_items', 'wpforo_menu_filter', 1, 2 );
function wpforo_menu_nofollow_items($item_output, $item, $depth, $args) {
//if( isset($item->url) && strpos($item->url, '?wpforo') !== FALSE ) {
//$item_output = str_replace('';
$forum_profile = false;
if($url = wpforo_has_shop_plugin($userid)){
$forum_profile = true;
$menu_html .= '';
}
if($url = wpforo_has_profile_plugin($userid)){
$forum_profile = true;
$menu_html .= '';
}
if( $forum_profile ) {
$menu_html .= '';
$menu_html .= "\r\n\r\n";
$menu_html = apply_filters( 'wpforo_profile_plugin_menu_filter', $menu_html, $userid );
echo $menu_html; //This is a HTML content//
}
}
add_action( 'wpforo_profile_plugin_menu_action', 'wpforo_profile_plugin_menu', 1 );
class wpforo_menu_walker extends Walker_Nav_Menu {
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent\n";
}
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$args = apply_filters( 'wpforo_nav_menu_item_args', $args, $item, $depth );
$class_names = join( ' ', apply_filters( 'wpforo_nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'wpforo_nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '',
'after_title' => '
',
));
}
add_action('widgets_init', 'wpforo_widgets_init', 11);
class wpForo_Widget_search extends WP_Widget {
function __construct() {
parent::__construct(
'wpForo_Widget_search', // Base ID
'wpForo Search', // Name
array( 'description' => 'wpForo search form' ) // Args
);
}
public function widget( $args, $instance ) {
echo $args['before_widget']; //This is a HTML content//
echo '';
}
}
if( $echo ) {
echo $edit_html;
}
else{
return $edit_html;
}
}
function wpforo_hide_title($title, $id = 0) {
if( !wpforo_feature('page-title') ){
if( $wpforo_base_slug = basename( wpforo_home_url() ) ) $wpforo_page = get_page_by_path($wpforo_base_slug);
if(!empty($wpforo_page)){
if (in_the_loop() && is_page($wpforo_page->ID) && $id == get_the_ID()) {
$title = '';
}
}
}
return $title;
}
add_filter('the_title', 'wpforo_hide_title', 10, 2);
function wpforo_validate_gravatar( $email ) {
$hashkey = md5(strtolower(trim($email)));
$uri = 'http://www.gravatar.com/avatar/' . $hashkey . '?d=404';
$data = wp_cache_get($hashkey);
if (false === $data) {
$response = wp_remote_head($uri);
if( is_wp_error($response) ) {
$data = 'not200';
} else {
$data = $response['response']['code'];
}
wp_cache_set($hashkey, $data, $group = '', $expire = 60*5);
}
if ($data == '200'){
return true;
} else {
return false;
}
}
function wpforo_member_title( $member = array(), $echo = true, $before = '', $after = '' ){
$title = array();
if(empty($member) || !$member['groupid']) return '';
$rating_title_ug_enabled = ( isset(WPF()->member->options['rating_title_ug'][$member['groupid']]) && WPF()->member->options['rating_title_ug'][$member['groupid']] ) ? true : false ;
$usergroup_title_ug_enabled = ( isset(WPF()->member->options['title_usergroup'][$member['groupid']]) && WPF()->member->options['title_usergroup'][$member['groupid']] ) ? true : false ;
if( wpforo_feature('rating_title') && $rating_title_ug_enabled && isset($member['stat']['title']) ){
$title[] = '' . esc_html($member['stat']['title']) . '';
}
if( empty($title) && WPF()->member->options['custom_title_is_on'] ){
$title[] = '' . wpforo_phrase($member['title'], false) . '';
}else{
$before = $after = '';
}
if( $usergroup_title_ug_enabled ){
$class = '';
if( $member['groupid'] == 1 ) $class = ' wpfbg-6 wpfcl-3';
if( $member['groupid'] == 2 ) $class = ' wpfbg-5 wpfcl-3';
if( $member['groupid'] == 4 ) $class = ' wpfbg-2 wpfcl-3';
$title[] = '' . esc_html($member['groupname']) . '';
}
if( !empty($title) ){
$title_html = $before . implode(' ', $title) . $after;
$title_html = apply_filters('wpforo_member_title', $title_html, $member);
if( $echo ) {
echo $title_html;
}
else{
return $title_html;
}
}
}
function wpforo_member_badge( $member = array(), $sep = '', $type = 'full' ){
$rating_badge_ug_enabled = ( isset(WPF()->member->options['rating_badge_ug'][$member['groupid']]) && WPF()->member->options['rating_badge_ug'][$member['groupid']] ) ? true : false ;
if( wpforo_feature('rating') && $rating_badge_ug_enabled && isset($member['stat']['rating']) ): ?>
';}
if( $bracket ) $nicename .= '(';
$nicename .= $prefix . urldecode($member['user_nicename']);
if( $bracket ) $nicename .= ')';
if( $wrap ){ $nicename .= '';}
if( $echo ){ echo $nicename; } else{ return $nicename; }
}
add_filter( 'body_class', 'wpforo_page_class', 1, 10 );
function wpforo_page_class( $classes ) {
if(!empty($classes)){
if( function_exists('is_wpforo_page') ){
if ( is_wpforo_page() ) {
return array_merge( $classes, array( 'wpforo' ) );
}
}
}
return (array)$classes;
}
###############################################################################
########################## THEME API FUNCTIONS ################################
###############################################################################
function wpforo_post( $postid, $var = 'item', $echo = false ){
$post = ( $var == 'item' ) ? array() : '';
if( !$postid ) return $post;
$cache = WPF()->cache->on('object_cashe');
if( $cache ){
$post = WPF()->cache->get_item( $postid, 'post' );
}
if( empty($post) ){
$post = array();
if( !$cache && $var == 'url' ){
$post['url'] = WPF()->post->get_post_url($postid);
}
elseif( !$cache && $var == 'is_answered' ){
$post['is_answered'] = WPF()->post->is_answered($postid);
}
elseif( !$cache && $var == 'votes_sum' ){
$post = WPF()->post->get_post($postid);
$post['votes_sum'] = $post['votes'];
}
elseif( !$cache && $var == 'likes_count' ){
$post['likes_count'] = WPF()->post->get_post_likes_count($postid);
}
elseif( !$cache && $var == 'likers_usernames' ){
$post['likers_usernames'] = WPF()->post->get_likers_usernames($postid);
}
else{
$post = WPF()->post->get_post($postid);
if( !empty($post) ){
$post['url'] = WPF()->post->get_post_url($post);
if( $cache ){
$post['is_answered'] = WPF()->post->is_answered($postid);
$post['votes_sum'] = $post['votes'];
$post['likes_count'] = WPF()->post->get_post_likes_count($postid);
$post['likers_usernames'] = WPF()->post->get_likers_usernames($postid);
}
if(!empty($post)){
$cache_item = array( $postid => $post );
WPF()->cache->create('item', $cache_item, 'post');
}
}
}
}
if( $var != 'item' && $var ){
$post = ( isset($post[$var]) ) ? $post[$var] : '';
}
if( $echo ){
echo $post;
}
else{
return $post;
}
}
function wpforo_topic( $topicid, $var = 'item', $echo = false ){
$topic = ( $var == 'item' ) ? array() : '';
if( !$topicid ) return $topic;
$cache = WPF()->cache->on('object_cashe');
if( $cache ) $topic = WPF()->cache->get_item( $topicid, 'topic' );
if( empty($topic) ){
$topic = array();
if( !$cache && $var == 'url' ){
$topic['url'] = WPF()->topic->get_topic_url( $topicid );
}
elseif( !$cache && $var == 'is_answer' ){
$topic['is_answer'] = WPF()->topic->is_solved( $topicid );
}
else{
$topic = WPF()->topic->get_topic($topicid);
if( !empty($topic) ){
$topic['url'] = WPF()->topic->get_topic_url($topic);
$topic['is_answer'] = WPF()->topic->is_solved( $topic['topicid'] );
if(!empty($topic)){
$cache_item = array( $topicid => $topic );
WPF()->cache->create('item', $cache_item, 'topic');
}
}
}
}
if( $var != 'item' && $var ){
$topic = ( isset($topic[$var]) ) ? $topic[$var] : '';
}
if( $echo ){
echo $topic;
}
else{
return $topic;
}
}
function wpforo_forum( $forumid, $var = 'item', $echo = false ){
$data = array();
$forum = ( $var == 'item' ) ? array() : '';
$cache = WPF()->cache->on('object_cashe');
if( !$forumid ) return $forum;
if( $cache ) $forum = WPF()->cache->get_item( $forumid, 'forum' );
if( empty($forum) ){
$forum = array();
if( !$cache && ($var == 'childs' || $var == 'counts') ){
if( $var == 'childs' ) {
WPF()->forum->get_childs($forumid, $data);
$forum['childs'] = $data;
}
else{
WPF()->forum->get_childs($forumid, $data);
$forum['childs'] = $data;
$forum['counts'] = WPF()->forum->get_counts( $data );
}
}
else{
$forum = WPF()->forum->get_forum($forumid);
if( !empty($forum) ){
if( $cache ){
WPF()->forum->get_childs($forum['forumid'], $data);
$forum['childs'] = $data;
$forum['counts'] = WPF()->forum->get_counts( $data );
}
if(!empty($forum)){
$cache_item = array( $forumid => $forum );
WPF()->cache->create('item', $cache_item, 'forum');
}
}
}
}
if( $var != 'item' && $var ){
$forum = ( isset($forum[$var]) ) ? $forum[$var] : '';
}
if( $echo ){
echo $forum;
}
else{
return $forum;
}
}
function wpforo_member( $object, $var = 'item', $echo = false ){
$member = array();
if( empty( $object ) ) return $member;
if( is_array( $object ) && isset($object['userid']) && !$object['userid'] ){
$member = WPF()->member->get_guest( $object );
}
else{
$userid = ( is_array( $object ) && isset($object['userid']) ) ? intval($object['userid']) : intval($object);
$member = WPF()->member->get_member( $userid );
if( isset($member['fields']) && $member['fields'] ){
$member['fields'] = json_decode($member['fields'], true);
}
}
if( $var != 'item' && $var ){
if( isset($member[$var]) ){
$member = $member[$var];
}
elseif( isset($member['fields']) && isset($member['fields'][$var]) ){
$member = $member['fields'][$var];
}
}
if( $echo ){
echo $member;
}
else{
return $member;
}
}
function wpforo_member_link( $member, $prefix = '', $length = 30, $class = '', $echo = true ){
$display_name = ( isset($member['display_name']) && $member['display_name'] ) ? $member['display_name'] : wpforo_phrase('Anonymous', false);
$color = (isset($member['color']) && $member['color'] ) ? 'style="color:' . $member['color'] . '"' : '';
$class = ($class) ? 'class="' . $class . '"' : '';
$title = ($member['display_name']) ? 'title="' . esc_attr($member['display_name']) . '"' : '';
if( wpfval($member, 'profile_url') ){
?> >