2015-02-01 01:30:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class UM_User_posts {
|
|
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
|
|
|
|
|
|
add_filter('um_profile_tabs', array(&$this, 'add_tab'), 100);
|
|
|
|
|
|
|
|
|
|
add_action('um_profile_content_posts', array(&$this, 'add_posts') );
|
|
|
|
|
add_action('um_profile_content_comments', array(&$this, 'add_comments') );
|
|
|
|
|
|
|
|
|
|
add_action('um_ajax_load_posts__um_load_posts', array(&$this, 'load_posts') );
|
|
|
|
|
add_action('um_ajax_load_posts__um_load_comments', array(&$this, 'load_comments') );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @dynamic load of posts
|
|
|
|
|
***/
|
|
|
|
|
function load_posts( $args ) {
|
|
|
|
|
global $ultimatemember;
|
|
|
|
|
|
|
|
|
|
$array = explode(',', $args );
|
|
|
|
|
$post_type = $array[0];
|
|
|
|
|
$posts_per_page = $array[1];
|
|
|
|
|
$offset = $array[2];
|
|
|
|
|
$author = $array[3];
|
|
|
|
|
|
|
|
|
|
$offset_n = $posts_per_page + $offset;
|
|
|
|
|
|
2015-02-04 20:31:39 +02:00
|
|
|
$ultimatemember->shortcodes->modified_args = "$post_type,$posts_per_page,$offset_n,$author";
|
|
|
|
|
|
|
|
|
|
$ultimatemember->shortcodes->loop = $ultimatemember->query->make("post_type=$post_type&posts_per_page=$posts_per_page&offset=$offset&author=$author");
|
|
|
|
|
|
|
|
|
|
$ultimatemember->shortcodes->load_template('profile/posts-single');
|
2015-02-01 01:30:04 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @dynamic load of comments
|
|
|
|
|
***/
|
|
|
|
|
function load_comments( $args ) {
|
|
|
|
|
global $ultimatemember;
|
|
|
|
|
|
|
|
|
|
$array = explode(',', $args );
|
|
|
|
|
$post_type = $array[0];
|
|
|
|
|
$posts_per_page = $array[1];
|
|
|
|
|
$offset = $array[2];
|
|
|
|
|
$author = $array[3];
|
|
|
|
|
|
|
|
|
|
$offset_n = $posts_per_page + $offset;
|
|
|
|
|
|
2015-02-04 20:31:39 +02:00
|
|
|
$ultimatemember->shortcodes->modified_args = "$post_type,$posts_per_page,$offset_n,$author";
|
|
|
|
|
|
2015-03-14 23:39:33 +02:00
|
|
|
$ultimatemember->shortcodes->loop = $ultimatemember->query->make("post_type=$post_type&number=$posts_per_page&offset=$offset&user_id=$author");
|
2015-02-01 01:30:04 +02:00
|
|
|
|
2015-02-04 20:31:39 +02:00
|
|
|
$ultimatemember->shortcodes->load_template('profile/comments-single');
|
2015-02-01 01:30:04 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @adds a tab
|
|
|
|
|
***/
|
|
|
|
|
function add_tab( $tabs ){
|
|
|
|
|
|
|
|
|
|
$tabs['posts'] = array(
|
|
|
|
|
'name' => __('Posts','ultimatemember'),
|
|
|
|
|
'icon' => 'um-faicon-pencil',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$tabs['comments'] = array(
|
|
|
|
|
'name' => __('Comments','ultimatemember'),
|
|
|
|
|
'icon' => 'um-faicon-comment',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $tabs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @add posts
|
|
|
|
|
***/
|
|
|
|
|
function add_posts() {
|
|
|
|
|
global $ultimatemember;
|
2015-02-04 20:31:39 +02:00
|
|
|
$ultimatemember->shortcodes->load_template('profile/posts');
|
|
|
|
|
|
2015-02-01 01:30:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @add comments
|
|
|
|
|
***/
|
|
|
|
|
function add_comments() {
|
|
|
|
|
global $ultimatemember;
|
2015-02-04 20:31:39 +02:00
|
|
|
$ultimatemember->shortcodes->load_template('profile/comments');
|
2015-02-01 01:30:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @count posts
|
|
|
|
|
***/
|
|
|
|
|
function count_user_posts_by_type( $user_id= '', $post_type = 'post' ) {
|
|
|
|
|
global $wpdb;
|
|
|
|
|
if ( !$user_id )
|
|
|
|
|
$user_id = um_user('ID');
|
2015-02-02 02:10:06 +02:00
|
|
|
|
2015-02-04 20:31:39 +02:00
|
|
|
if ( !$user_id ) return 0;
|
|
|
|
|
|
2015-02-01 01:30:04 +02:00
|
|
|
$where = get_posts_by_author_sql( $post_type, true, $user_id );
|
|
|
|
|
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
|
2015-02-02 02:10:06 +02:00
|
|
|
|
2015-02-01 01:30:04 +02:00
|
|
|
return apply_filters('um_pretty_number_formatting', $count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @count comments
|
|
|
|
|
***/
|
|
|
|
|
function count_user_comments( $user_id = null ) {
|
|
|
|
|
global $wpdb;
|
|
|
|
|
if ( !$user_id )
|
|
|
|
|
$user_id = um_user('ID');
|
2015-02-04 20:31:39 +02:00
|
|
|
|
|
|
|
|
if ( !$user_id ) return 0;
|
2015-02-02 02:10:06 +02:00
|
|
|
|
2015-02-04 20:31:39 +02:00
|
|
|
$count = $wpdb->get_var("SELECT COUNT(comment_ID) FROM " . $wpdb->comments. " WHERE user_id = " . $user_id . " AND comment_approved = '1'");
|
2015-02-02 02:10:06 +02:00
|
|
|
|
2015-02-01 01:30:04 +02:00
|
|
|
return apply_filters('um_pretty_number_formatting', $count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|