function wppriv_fix_post_count($terms, $taxonomies, $args)
{
    global $wpdb;
    if (!in_array('category', $taxonomies) && !in_array('post_tag', $taxonomies)) {
        return $terms;
    }
    foreach ($terms as $term) {
        $term->count = $wpdb->get_var($wpdb->prepare("SELECT count(ID) FROM " . "{$wpdb->term_relationships} AS tr INNER JOIN " . "{$wpdb->posts} AS p ON (tr.object_id = p.ID) INNER JOIN " . "{$wpdb->term_taxonomy} AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) " . "WHERE tt.term_id = %s AND p.post_type = 'post' AND " . get_private_posts_cap_sql('post'), $term->term_id));
    }
    return $terms;
}
示例#2
0
function wp_list_authors_art($args = '')
{
    global $wpdb;
    $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'echo' => true, 'orderby' => 'articles', 'days' => 30, 'show' => 5);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $return = '';
    // TODO:  Move select to get_authors().
    switch ($orderby) {
        case 'views':
            $authors = $wpdb->get_results("SELECT COUNT(b.ID) AS postsperuser, a.ID AS post_id, display_name, user_nicename, b.ID AS ID, sum(m.meta_value+0) AS visitas FROM wp_posts AS a, wp_users AS b, wp_postmeta AS m WHERE a.ID = m.post_id AND meta_key='views' AND a.post_author = b.ID AND post_type = 'post' AND post_status = 'publish' AND post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY b.ID ORDER BY visitas DESC LIMIT {$show}");
            $select = (array) $wpdb->get_results("SELECT DISTINCT p.post_author, COUNT(DISTINCT p.ID) AS posts, sum(m.meta_value+0) AS count FROM wp_posts AS p, wp_postmeta AS m WHERE p.ID = m.post_id AND meta_key='views' AND p.post_type = 'post' AND p.post_status = 'publish' AND " . get_private_posts_cap_sql('post') . " AND p.post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY p.post_author ORDER BY count DESC LIMIT {$show}");
            break;
        case 'votes':
            $authors = $wpdb->get_results("SELECT COUNT(b.ID) AS postsperuser, a.ID AS post_id, display_name, user_nicename, b.ID AS ID, sum(m.meta_value+0) AS visitas FROM wp_posts AS a, wp_users AS b, wp_postmeta AS m WHERE a.ID = m.post_id AND meta_key='_liked' AND a.post_author = b.ID AND post_type = 'post' AND post_status = 'publish' AND post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY b.ID ORDER BY visitas DESC LIMIT {$show}");
            $select = (array) $wpdb->get_results("SELECT DISTINCT p.post_author, COUNT(DISTINCT p.ID) AS posts, sum(m.meta_value+0) AS count FROM wp_posts AS p, wp_postmeta AS m WHERE p.ID = m.post_id AND meta_key='_liked' AND p.post_type = 'post' AND p.post_status = 'publish' AND " . get_private_posts_cap_sql('post') . " AND p.post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY p.post_author ORDER BY count DESC LIMIT {$show}");
            break;
        case 'all':
            $authors = $wpdb->get_results("SELECT a.ID AS post_id, display_name, user_nicename, b.ID AS ID, sum(views.meta_value+0) AS viewsc, sum(votos.meta_value+0) AS votosc, COUNT(b.ID) AS postsperuser FROM wp_posts AS a, wp_users AS b, wp_postmeta AS votos, wp_postmeta AS views WHERE a.ID = votos.post_id AND a.ID = views.post_id AND votos.meta_key='_liked' AND views.meta_key='views' AND a.post_author = b.ID AND post_type = 'post' AND post_status = 'publish' AND post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY b.ID ORDER BY viewsc DESC, votosc DESC, postsperuser DESC LIMIT {$show}");
            $select = (array) $wpdb->get_results("SELECT DISTINCT p.post_author, sum(views.meta_value+0) AS viewsc, sum(votos.meta_value+0) AS votosc, COUNT(DISTINCT p.ID) AS posts, ((sum(views.meta_value+0))+(sum(votos.meta_value+0))+(COUNT(DISTINCT p.ID))) AS count FROM wp_posts AS p, wp_postmeta AS votos, wp_postmeta AS views WHERE p.ID = votos.post_id AND p.ID = views.post_id AND votos.meta_key='_liked' AND views.meta_key='views' AND p.post_type = 'post' AND p.post_status = 'publish' AND " . get_private_posts_cap_sql('post') . " AND p.post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY p.post_author ORDER BY viewsc DESC, votosc DESC, posts DESC LIMIT {$show}");
            break;
        case 'follows':
            $authors = $wpdb->get_results("SELECT COUNT(b.ID) AS postsperuser, a.ID AS post_id, display_name, user_nicename, b.ID AS ID, COUNT(DISTINCT c.item_id) AS follows FROM wp_posts AS a, wp_users AS b, wp_follows AS c WHERE a.post_author = b.ID AND c.item_id = b.ID AND c.item_id = a.post_author AND c.item_type = 'author' AND post_type = 'post' AND post_status = 'publish' AND post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY b.ID ORDER BY follows DESC LIMIT {$show}");
            $select = (array) $wpdb->get_results("SELECT DISTINCT a.post_author, COUNT(DISTINCT b.item_id) AS count FROM wp_posts AS a, wp_follows AS b WHERE a.post_type = 'post' AND a.post_status = 'publish' AND b.item_id = a.post_author AND b.item_type = 'author' AND " . get_private_posts_cap_sql('post') . " AND a.post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY a.post_author ORDER BY count DESC LIMIT {$show}");
            break;
        default:
            $authors = $wpdb->get_results("SELECT COUNT(b.ID) AS postsperuser, a.ID AS post_id, display_name, user_nicename, b.ID AS ID FROM wp_posts AS a, wp_users AS b WHERE a.post_author = b.ID AND post_type = 'post' AND post_status = 'publish' AND post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY b.ID ORDER BY postsperuser DESC LIMIT {$show}");
            $select = (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(DISTINCT ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' AND " . get_private_posts_cap_sql('post') . " AND post_date > '" . date('Y-m-d', strtotime('-' . $days . ' days')) . "' GROUP BY post_author ORDER BY count DESC LIMIT {$show}");
            break;
    }
    $author_count = array();
    foreach ($select as $row) {
        $author_count[$row->post_author] = $row->count;
    }
    foreach ((array) $authors as $author) {
        $author = get_userdata($author->ID);
        $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
        $name = $author->display_name;
        if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
            $name = "{$author->first_name} {$author->last_name}";
        }
        if (!($posts == 0 && $hide_empty)) {
            $return .= '<li>';
        }
        if ($posts == 0) {
            if (!$hide_empty) {
                $link = $name;
            }
        } else {
            $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
            if (!empty($feed_image) || !empty($feed)) {
                $link .= ' ';
                if (empty($feed_image)) {
                    $link .= '(';
                }
                $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
                if (!empty($feed)) {
                    $title = ' title="' . $feed . '"';
                    $alt = ' alt="' . $feed . '"';
                    $name = $feed;
                    $link .= $title;
                }
                $link .= '>';
                if (!empty($feed_image)) {
                    $link .= "<img src=\"{$feed_image}\" border=\"0\"{$alt}{$title}" . ' />';
                } else {
                    $link .= $name;
                }
                $link .= '</a>';
                if (empty($feed_image)) {
                    $link .= ')';
                }
            }
            if ($optioncount) {
                switch ($orderby) {
                    case 'views':
                        $link .= ' (' . $posts . ' lecturas)';
                        break;
                    case 'votes':
                        $link .= ' (' . $posts . ' votos)';
                        break;
                    case 'follows':
                        $link .= ' (' . $posts . ' seguidores)';
                        break;
                    case 'all':
                        $link .= ' (' . $posts . ' puntos)';
                        break;
                    default:
                        $link .= ' (' . $posts . ' artículos)';
                        break;
                }
            }
        }
        if (!($posts == 0 && $hide_empty)) {
            $return .= $link . '</li>';
        }
    }
    if (!$echo) {
        return $return;
    }
    echo $return;
}
示例#3
0
文件: user.php 项目: schr/wordpress
/**
 * Number of posts user has written.
 *
 * @since 0.71
 * @uses $wpdb WordPress database object for queries.
 *
 * @param int $userid User ID.
 * @return int Amount of posts user has written.
 */
function get_usernumposts($userid)
{
    global $wpdb;
    $userid = (int) $userid;
    $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_author = %d AND post_type = 'post' AND ", $userid) . get_private_posts_cap_sql('post'));
    return apply_filters('get_usernumposts', $count, $userid);
}
示例#4
0
        } else {
            echo '<a href="' . get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '" ' . $this->htmltarget('_blank', TRUE) . '>';
        }
        echo sprintf(__('%1$s on %2$s'), strip_tags($comment->comment_author), get_the_title($comment->comment_post_ID));
        echo "</a></li>\n";
    }
    if (count($comments) == $numitems && current_user_can('moderate_comments')) {
        echo '<li><a href="' . $this->admin_url . '/edit-comments.php?wphone=ajax">' . __('More &raquo;') . "</a></li>\n";
    }
    if (!$this->iscompat) {
        echo "</ul>\n</li>\n";
    }
}
# Recent posts
if (function_exists('get_private_posts_cap_sql')) {
    $recentpostssql = "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " AND post_date_gmt < '" . current_time('mysql', 1) . "' ORDER BY post_date DESC LIMIT {$numitems}";
} else {
    $recentpostssql = "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' AND post_date_gmt < '" . current_time('mysql', 1) . "' ORDER BY post_date DESC LIMIT {$numitems}";
}
if ($recentposts = $wpdb->get_results($recentpostssql)) {
    echo '<li class="group">' . __('Recent Posts', 'wphone');
    if (!$this->iscompat) {
        echo "\n<ul>\n";
    } else {
        echo "</li>\n";
    }
    $count = 0;
    foreach ($recentposts as $post) {
        $count++;
        if ($count >= $numitems) {
            break;
示例#5
0
    /**
     * Loads a list of WordPress users according to the user mapper options
     * @access private
     */
    private function load_wp_users()
    {
        global $wpdb, $phpbbForum, $db;
        $where = '';
        $mainWhere = '';
        $mainWhereAnd = '';
        $postClause = '';
        if (!empty($this->showSpecificUsers)) {
            /**
             * We don't have a need for "show specific users" yet
             */
            $mainWhere = '';
            trigger_error('UNIMPLEMENTED');
            die;
        }
        if (!empty($this->showUsersLike)) {
            // find similar users for autocomplete
            $mainWhere = $wpdb->prepare("UCASE(user_login) LIKE '%s'", '%' . strtoupper($this->showUsersLike) . '%');
            $mainWhereAnd = " AND {$mainWhere}";
            $mainWhere = " WHERE {$mainWhere}";
        }
        /** 
         * For all normal queries we need to calculate a total user count so the results can be paginated
         * @TODO: This pulls post count and/or integrated phpBB usr info. These are pulled later on again as
         * part of the user load. This is inefficient -- should consider grabbing all data here (at the expense of readability)
         */
        // if the total number of users depends on an integrated/unintegrated filter, need to start in phpBB
        if (!empty($this->showOnlyInt) || !empty($this->showOnlyUnInt)) {
            /**
             * First we pull the users to use as a filter
             * The filter could be a block or a pass filter, so we don't use LIMIT here.
             */
            $fStateChanged = $phpbbForum->foreground();
            $sql = 'SELECT user_wpuint_id 
						FROM ' . USERS_TABLE . ' 
						WHERE (user_type = ' . USER_NORMAL . ' OR user_type = ' . USER_FOUNDER . ') 
							AND user_wpuint_id > 0';
            if (!($fResults = $db->sql_query($sql))) {
                $phpbbForum->background($fStateChanged);
                return;
            }
            $usersToFetch = array();
            while ($fResult = $db->sql_fetchrow($fResults)) {
                $usersToFetch[] = $fResult['user_wpuint_id'];
            }
            $this->numUsers = sizeof($usersToFetch);
            $db->sql_freeresult();
            $phpbbForum->background($fStateChanged);
            if (!empty($this->showOnlyInt) && !sizeof($usersToFetch)) {
                return;
            }
            // Now create the filter for the WP query
            if (sizeof($usersToFetch)) {
                $set = implode(',', $usersToFetch);
                if (!empty($this->showOnlyInt)) {
                    $where = ' WHERE ID IN (' . $set . ')' . $mainWhereAnd;
                } else {
                    $where = ' WHERE ID NOT IN (' . $set . ')' . $mainWhereAnd;
                }
            }
            // If this is "show only unintegrated", we need to run a separate count query
            $this->numUsers = $wpdb->get_var('SELECT COUNT(*) AS numusers
				FROM ' . $wpdb->users . $where);
            // For other filter types (or no filter), we can just count in WordPress.
        } else {
            if ($this->showOnlyPosts) {
                $postClause = ', ' . $wpdb->posts . ' ';
                $where = ' WHERE (u.ID = post_author AND post_type = \'post\' AND ' . get_private_posts_cap_sql('post') . ')' . $mainWhereAnd;
                $this->numUsers = $wpdb->get_var('SELECT COUNT(*) AS numusers
						FROM ' . $wpdb->users . ' AS u' . $postClause . $where);
            } else {
                if ($this->showOnlyNoPosts) {
                    $postClause = ', ' . $wpdb->posts . ' ';
                    $where = ' WHERE (u.ID <> post_author AND post_type = \'post\' AND ' . get_private_posts_cap_sql('post') . ')' . $mainWhereAnd;
                    $this->numUsers = $wpdb->get_var('SELECT COUNT(*) AS numusers
						FROM ' . $wpdb->users . ' AS u' . $postClause . $where);
                } else {
                    $where = $mainWhere;
                    $this->numUsers = $wpdb->get_var('SELECT COUNT(*) AS count
						FROM ' . $wpdb->users . $where);
                }
            }
        }
        // return for all other than autocomplete if there aren't any users
        if (!$this->numUsers) {
            return;
        }
        // Now fetch the users
        $sql = "SELECT u.ID\r\n\t\t\t\tFROM {$wpdb->users} AS u {$postClause} \r\n\t\t\t\t{$where} \r\n\t\t\t\tORDER BY user_login \r\n\t\t\t\tLIMIT {$this->numStart}, {$this->numToShow}";
        $results = $wpdb->get_results($sql);
        foreach ((array) $results as $item => $result) {
            $mUser = new WPU_Mapped_WP_User($result->ID);
            $this->users[$result->ID] = $mUser;
        }
    }
function get_usernumposts($userid) {
	global $wpdb;
	$userid = (int) $userid;
	return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_type = 'post' AND " . get_private_posts_cap_sql('post'));
}
示例#7
0
    function form($instance)
    {
        $title = esc_attr($instance['title']);
        $number = absint($instance['number']);
        $posttype = $instance['posttype'];
        $sort_by = $instance['sort_by'];
        //$display = $instance['display'];
        $description = $instance['description'];
        $categories = (array) $instance['categories'];
        $tags = (array) $instance['tags'];
        $author = $instance['author'];
        $is_cats = ' style="display:none;"';
        $is_tags = ' style="display:none;"';
        $is_author = ' style="display:none;"';
        if ($posttype == "categories") {
            $is_cats = '';
        }
        if ($posttype == "tags") {
            $is_tags = '';
        }
        if ($posttype == "author") {
            $is_author = '';
        }
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
">
				Title:
			</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo $title;
        ?>
" />
        </p>

        <p>
			<label for="<?php 
        echo $this->get_field_id('description');
        ?>
">
				Description:
            </label>
			<textarea class="widefat" id="<?php 
        echo $this->get_field_id('description');
        ?>
" name="<?php 
        echo $this->get_field_name('description');
        ?>
"><?php 
        echo $description;
        ?>
</textarea>
        </p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('posttype');
        ?>
">
				Post Type:
            </label>
			<select name="<?php 
        echo $this->get_field_name('posttype');
        ?>
" id="<?php 
        echo $this->get_field_id('about_page_id');
        ?>
" class="widefat dt-get-posts">
				<option value="anywhere"<?php 
        selected($posttype, 'anywhere');
        ?>
>Any</option>
				<option value="categories"<?php 
        selected($posttype, 'categories');
        ?>
>In category...</option>
				<option value="tags"<?php 
        selected($posttype, 'tags');
        ?>
>Tagged with...</option>
				<option value="author"<?php 
        selected($posttype, 'author');
        ?>
>By author...</option>
			</select>
		</p>

		<p id="dt_cats" class="dt-hide-it"<?php 
        echo $is_cats;
        ?>
>
			<label class="head">
				Select Categories:
            </label>
			<br />
		<?php 
        $all_categories = get_categories('hide_empty=0&orderby=name');
        foreach ($all_categories as $cat) {
            $cat_id = intval($cat->cat_ID);
            $cat_name = $cat->cat_name;
            $selected = '';
            if (in_array($cat_id, $categories)) {
                $selected = ' checked="checked"';
            }
            ?>
			<input value="<?php 
            echo $cat_id;
            ?>
" class="checkbox" type="checkbox"<?php 
            echo $selected;
            ?>
 id="<?php 
            echo $this->get_field_id('categories');
            echo $cat_id;
            ?>
" name="<?php 
            echo $this->get_field_name('categories');
            ?>
[]" /> <label for="<?php 
            echo $this->get_field_id('categories');
            echo $cat_id;
            ?>
"><?php 
            echo $cat_name;
            ?>
</label> <br />
		<?php 
        }
        ?>

		</p>


		<p id="dt_tags" class="dt-hide-it"<?php 
        echo $is_tags;
        ?>
>
			<label class="head">
				Select Tags:
            </label>
			<br />
		<?php 
        $all_tags = get_tags('hide_empty=0&orderby=name');
        foreach ($all_tags as $tag) {
            $tag_id = intval($tag->term_id);
            $tag_name = $tag->name;
            $selected = '';
            if (in_array($tag_id, $tags)) {
                $selected = ' checked="checked"';
            }
            ?>
			<input value="<?php 
            echo $tag_id;
            ?>
" class="checkbox" type="checkbox"<?php 
            echo $selected;
            ?>
 id="<?php 
            echo $this->get_field_id('tags');
            echo $tag_id;
            ?>
" name="<?php 
            echo $this->get_field_name('tags');
            ?>
[]" /> <label for="<?php 
            echo $this->get_field_id('tags');
            echo $tag_id;
            ?>
"><?php 
            echo $tag_name;
            ?>
</label> <br />
		<?php 
        }
        ?>

		</p>



		<p id="dt_author" class="dt-hide-it"<?php 
        echo $is_author;
        ?>
>
			<label class="head" for="<?php 
        echo $this->get_field_id('author');
        ?>
">
				Select Author:
            </label>
			<select name="<?php 
        echo $this->get_field_name('author');
        ?>
" id="<?php 
        echo $this->get_field_id('author');
        ?>
" class="widefat">

			<?php 
        $users = get_users();
        $author_ids = array();
        foreach ((array) $users as $user) {
            $author_ids[] = $user->user_id;
        }
        global $wpdb;
        if (count($author_ids) > 0) {
            $author_ids = implode(',', $author_ids);
            $authors = $wpdb->get_results("SELECT ID, user_nicename from {$wpdb->users} WHERE ID IN({$author_ids}) ORDER BY display_name");
        } else {
            $authors = array();
        }
        $author_count = array();
        foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
            $author_count[$row->post_author] = $row->count;
        }
        foreach ((array) $authors as $author) {
            $author_id = intval($author->ID);
            $author = get_userdata($author->ID);
            $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
            if ($posts == 0) {
                continue;
            }
            $author_name = $author->display_name;
            ?>
				<option value="<?php 
            echo $author_id;
            ?>
"<?php 
            selected($instance['author'], $author_id);
            ?>
><?php 
            echo $author_name;
            ?>
 (<?php 
            echo $posts;
            ?>
 posts)</option>
<?php 
        }
        ?>
			</select>
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('sort_by');
        ?>
">
               Sort Posts by:
            </label>
			<select name="<?php 
        echo $this->get_field_name('sort_by');
        ?>
" id="<?php 
        echo $this->get_field_id('sort_by');
        ?>
" class="widefat">
				<option value="popular"<?php 
        selected($instance['sort_by'], 'popular');
        ?>
>Most popular</option>
				<option value="recent"<?php 
        selected($instance['sort_by'], 'recent');
        ?>
>Most recent</option>
				<option value="random"<?php 
        selected($instance['sort_by'], 'random');
        ?>
>Random</option>
			</select>
		</p>

		<p>
			Display Options:<br />
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['thumbnail'], true);
        ?>
 id="<?php 
        echo $this->get_field_id('thumbnail');
        ?>
" name="<?php 
        echo $this->get_field_name('thumbnail');
        ?>
" /><label for="<?php 
        echo $this->get_field_id('thumbnail');
        ?>
"> Show thumbnails</label><br />
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['posttitle'], true);
        ?>
 id="<?php 
        echo $this->get_field_id('posttitle');
        ?>
" name="<?php 
        echo $this->get_field_name('posttitle');
        ?>
" /><label for="<?php 
        echo $this->get_field_id('posttitle');
        ?>
"> Show titles</label><br />
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['byline'], true);
        ?>
 id="<?php 
        echo $this->get_field_id('byline');
        ?>
" name="<?php 
        echo $this->get_field_name('byline');
        ?>
" /><label for="<?php 
        echo $this->get_field_id('byline');
        ?>
"> Show bylines</label><br />
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['excerpt'], true);
        ?>
 id="<?php 
        echo $this->get_field_id('excerpt');
        ?>
" name="<?php 
        echo $this->get_field_name('excerpt');
        ?>
" /><label for="<?php 
        echo $this->get_field_id('excerpt');
        ?>
"> Show excerpts</label><br />
			<input class="checkbox" type="checkbox" <?php 
        checked($instance['meta'], true);
        ?>
 id="<?php 
        echo $this->get_field_id('meta');
        ?>
" name="<?php 
        echo $this->get_field_name('meta');
        ?>
" /><label for="<?php 
        echo $this->get_field_id('meta');
        ?>
"> Show meta data</label><br />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('number');
        ?>
">
               Number of Posts:
			</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('number');
        ?>
" name="<?php 
        echo $this->get_field_name('number');
        ?>
" type="text" value="<?php 
        echo $number;
        ?>
" />
        </p>

<?php 
    }
示例#8
0
/**
 * List all the authors of the blog, with several options available.
 *
 * <ul>
 * <li>optioncount (boolean) (false): Show the count in parenthesis next to the
 * author's name.</li>
 * <li>exclude_admin (boolean) (true): Exclude the 'admin' user that is
 * installed bydefault.</li>
 * <li>show_fullname (boolean) (false): Show their full names.</li>
 * <li>hide_empty (boolean) (true): Don't show authors without any posts.</li>
 * <li>feed (string) (''): If isn't empty, show links to author's feeds.</li>
 * <li>feed_image (string) (''): If isn't empty, use this image to link to
 * feeds.</li>
 * <li>echo (boolean) (true): Set to false to return the output, instead of
 * echoing.</li>
 * <li>style (string) ('list'): Whether to display list of authors in list form
 * or as a string.</li>
 * <li>html (bool) (true): Whether to list the items in html form or plaintext.
 * </li>
 * </ul>
 *
 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors
 * @since 1.2.0
 * @param array $args The argument array.
 * @return null|string The output, if echo is set to false.
 */
function wp_list_authors($args = '')
{
    global $wpdb;
    $defaults = array('orderby' => 'name', 'order' => 'ASC', 'number' => '', 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true);
    $args = wp_parse_args($args, $defaults);
    extract($args, EXTR_SKIP);
    $return = '';
    $query_args = wp_array_slice_assoc($args, array('orderby', 'order', 'number'));
    $query_args['fields'] = 'ids';
    $authors = get_users($query_args);
    $author_count = array();
    foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
        $author_count[$row->post_author] = $row->count;
    }
    foreach ($authors as $author_id) {
        $author = get_userdata($author_id);
        if ($exclude_admin && 'admin' == $author->display_name) {
            continue;
        }
        $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
        if (!$posts && $hide_empty) {
            continue;
        }
        $link = '';
        if ($show_fullname && $author->first_name && $author->last_name) {
            $name = "{$author->first_name} {$author->last_name}";
        } else {
            $name = $author->display_name;
        }
        if (!$html) {
            $return .= $name . ', ';
            continue;
            // No need to go further to process HTML.
        }
        if ('list' == $style) {
            $return .= '<li>';
        }
        $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr(sprintf(__("Posts by %s"), $author->display_name)) . '">' . $name . '</a>';
        if (!empty($feed_image) || !empty($feed)) {
            $link .= ' ';
            if (empty($feed_image)) {
                $link .= '(';
            }
            $link .= '<a href="' . get_author_feed_link($author->ID) . '"';
            $alt = $title = '';
            if (!empty($feed)) {
                $title = ' title="' . esc_attr($feed) . '"';
                $alt = ' alt="' . esc_attr($feed) . '"';
                $name = $feed;
                $link .= $title;
            }
            $link .= '>';
            if (!empty($feed_image)) {
                $link .= '<img src="' . esc_url($feed_image) . '" style="border: none;"' . $alt . $title . ' />';
            } else {
                $link .= $name;
            }
            $link .= '</a>';
            if (empty($feed_image)) {
                $link .= ')';
            }
        }
        if ($optioncount) {
            $link .= ' (' . $posts . ')';
        }
        $return .= $link;
        $return .= 'list' == $style ? '</li>' : ', ';
    }
    $return = rtrim($return, ', ');
    if (!$echo) {
        return $return;
    }
    echo $return;
}
示例#9
0
function wiziapp_get_authors($chars, $return_id = FALSE)
{
    global $wpdb;
    //    $hide_empty = TRUE;
    //    $html = FALSE;
    //
    //
    //    $defaults = array(
    //        'optioncount' => false, 'exclude_admin' => true,
    //        'show_fullname' => false, 'hide_empty' => true,
    //        'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
    //        'style' => 'list', 'html' => true
    //    );
    // @todo Refactor the authors and author_count queries to one, or replace with get_author when such a fucntion will exist
    $sql = $wpdb->prepare("SELECT ID, display_name from {$wpdb->users} WHERE display_name LIKE %s ORDER BY display_name", "%{$chars}%");
    $authors = $wpdb->get_results($sql);
    $author_count = array();
    foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
        $author_count[$row->post_author] = $row->count;
    }
    $returnAuthors = array();
    foreach ((array) $authors as $author) {
        $author = get_userdata($author->ID);
        $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
        $name = $author->display_name;
        if ($posts != 0) {
            if ($return_id) {
                $returnAuthors[$name] = $author->ID;
            } else {
                $returnAuthors[] = $name;
            }
        }
    }
    return $returnAuthors;
}
示例#10
0
/**
 * List all the *co-authors* of the blog, with several options available.
 * optioncount (boolean) (false): Show the count in parenthesis next to the author's name.
 * exclude_admin (boolean) (true): Exclude the 'admin' user that is installed by default.
 * show_fullname (boolean) (false): Show their full names.
 * hide_empty (boolean) (true): Don't show authors without any posts.
 * feed (string) (''): If isn't empty, show links to author's feeds.
 * feed_image (string) (''): If isn't empty, use this image to link to feeds.
 * echo (boolean) (true): Set to false to return the output, instead of echoing.
 * @param array $args The argument array.
 * @return null|string The output, if echo is set to false.
 */
function coauthors_wp_list_authors($args = '')
{
    global $wpdb, $coauthors_plus;
    $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $return = '';
    // @todo Move select to get_authors()
    $authors = $wpdb->get_results("SELECT ID, user_nicename from {$wpdb->users} " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
    $author_count = array();
    $query = "SELECT DISTINCT {$wpdb->users}.ID AS post_author, {$wpdb->terms}.name AS user_name, {$wpdb->term_taxonomy}.count AS count";
    $query .= " FROM {$wpdb->posts}";
    $query .= " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
    $query .= " INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id)";
    $query .= " INNER JOIN {$wpdb->terms} ON ({$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id)";
    $query .= " INNER JOIN {$wpdb->users} ON ({$wpdb->terms}.name = {$wpdb->users}.user_login)";
    $query .= " WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post');
    $query .= " AND {$wpdb->term_taxonomy}.taxonomy = '{$coauthors_plus->coauthor_taxonomy}'";
    $query .= " GROUP BY post_author";
    foreach ((array) $wpdb->get_results($query) as $row) {
        $author_count[$row->post_author] = $row->count;
    }
    foreach ((array) $authors as $author) {
        $link = '';
        $author = get_userdata($author->ID);
        $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
        $name = $author->display_name;
        if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
            $name = "{$author->first_name} {$author->last_name}";
        }
        if (!$html) {
            if ($posts == 0) {
                if (!$hide_empty) {
                    $return .= $name . ', ';
                }
            } else {
                $return .= $name . ', ';
            }
            // No need to go further to process HTML.
            continue;
        }
        if (!($posts == 0 && $hide_empty) && 'list' == $style) {
            $return .= '<li>';
        }
        if ($posts == 0) {
            if (!$hide_empty) {
                $link = $name;
            }
        } else {
            $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr(sprintf(__("Posts by %s", 'co-authors-plus'), $author->display_name)) . '">' . $name . '</a>';
            if (!empty($feed_image) || !empty($feed)) {
                $link .= ' ';
                if (empty($feed_image)) {
                    $link .= '(';
                }
                $link .= '<a href="' . get_author_feed_link($author->ID) . '"';
                if (!empty($feed)) {
                    $title = ' title="' . esc_attr($feed) . '"';
                    $alt = ' alt="' . esc_attr($feed) . '"';
                    $name = $feed;
                    $link .= $title;
                }
                $link .= '>';
                if (!empty($feed_image)) {
                    $link .= "<img src=\"" . esc_url($feed_image) . "\" style=\"border: none;\"{$alt}{$title}" . ' />';
                } else {
                    $link .= $name;
                }
                $link .= '</a>';
                if (empty($feed_image)) {
                    $link .= ')';
                }
            }
            if ($optioncount) {
                $link .= ' (' . $posts . ')';
            }
        }
        if (!($posts == 0 && $hide_empty) && 'list' == $style) {
            $return .= $link . '</li>';
        } else {
            if (!$hide_empty) {
                $return .= $link . ', ';
            }
        }
    }
    $return = trim($return, ', ');
    if (!$echo) {
        return $return;
    }
    echo $return;
}
 function wp_authors($type, $args = '')
 {
     global $wpdb;
     $this->type = $type;
     $defaults = array('orderby' => 'name', 'order' => 'ASC', 'number' => '', 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => '', 'post_types' => array('post'), 'combo_box' => '');
     $args = wp_parse_args($args, $defaults);
     extract($args, EXTR_SKIP);
     $return = '';
     $query_args = wp_array_slice_assoc($args, array('orderby', 'order', 'number', 'exclude', 'include'));
     $query_args['fields'] = 'ids';
     $authors = get_users($query_args);
     //build where conditions for post types...
     $where_conditions = array();
     $post_type_count = count($post_types);
     $where_query = '';
     if ($post_type_count > 0) {
         foreach ($post_types as $post_type) {
             if (post_type_exists($post_type)) {
                 $post_type = esc_attr($post_type);
                 $where_conditions[] = " (post_type = '{$post_type}' AND " . get_private_posts_cap_sql($post_type) . ")";
             }
         }
         $where_query = implode(" OR", $where_conditions);
     }
     $author_count = array();
     foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE{$where_query} GROUP BY post_author") as $row) {
         $author_count[$row->post_author] = $row->count;
     }
     $elem_attr = "";
     if ($this->type == "select") {
         if ($combo_box == 1) {
             $elem_attr = ' data-combobox="1"';
         }
         $return .= '<select name="' . $args['name'] . '"' . $elem_attr . '>';
         $return .= '<option class="level-0 ' . SF_ITEM_CLASS_PRE . '0" value="0">' . $args['all_items_label'] . '</option>';
     } else {
         if ($this->type == "radio") {
             $return .= '<ul>';
         } else {
             if ($this->type == "checkbox") {
                 $return .= '<ul>';
             } else {
                 if ($this->type == "multiselect") {
                     if ($combo_box == 1) {
                         $elem_attr = ' data-combobox="1"';
                     }
                     $return .= '<select multiple="multiple" name="' . $args['name'] . '[]"' . $elem_attr . '>';
                 }
             }
         }
     }
     foreach ($authors as $author_id) {
         $author = get_userdata($author_id);
         if ($exclude_admin && 'admin' == $author->display_name) {
             continue;
         }
         $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
         if (!$posts && $hide_empty) {
             continue;
         }
         $link = '';
         if ($show_fullname && $author->first_name && $author->last_name) {
             $name = "{$author->first_name} {$author->last_name}";
         } else {
             $name = $author->display_name;
         }
         if (!$html) {
             $return .= $name . ', ';
             continue;
             // No need to go further to process HTML.
         }
         /*if ( 'list' == $style ) {
         			$return .= '<li>';
         		}*/
         $selected = "";
         $checked = "";
         if (isset($args['defaults'])) {
             $noselected = count($args['defaults']);
             if ($noselected > 0 && is_array($args['defaults'])) {
                 if (in_array($author->ID, $args['defaults'])) {
                     $selected = ' selected="selected"';
                     $checked = ' checked="checked"';
                 }
             }
         }
         if ($this->type == "select" || $this->type == "multiselect") {
             $return .= '<option class="level-0 ' . SF_ITEM_CLASS_PRE . esc_attr($author->ID) . '" value="' . esc_attr($author->ID) . '"' . $selected . '>';
         } else {
             if ($this->type == "radio" || $this->type == "checkbox") {
                 $return .= '<li class="' . SF_ITEM_CLASS_PRE . esc_attr($author->ID) . '">';
             }
         }
         //$link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
         if ($this->type == "select" || $this->type == "multiselect") {
             $link = $name;
         } else {
             if ($this->type == "radio") {
                 $link = '<label><input type="radio" name="' . $args['name'] . '[]" value="' . esc_attr($author->ID) . '"' . $checked . '> ' . esc_html($name);
             } else {
                 if ($this->type == "checkbox") {
                     $link = '<label><input type="checkbox" name="' . $args['name'] . '[]" value="' . esc_attr($author->ID) . '"' . $checked . '> ' . esc_html($name);
                 }
             }
         }
         if (!empty($feed_image) || !empty($feed)) {
             $link .= ' ';
             if (empty($feed_image)) {
                 $link .= '(';
             }
             $link .= '<a href="' . get_author_feed_link($author->ID) . '"';
             $alt = $title = '';
             if (!empty($feed)) {
                 $title = ' title="' . esc_attr($feed) . '"';
                 $alt = ' alt="' . esc_attr($feed) . '"';
                 $name = $feed;
                 $link .= $title;
             }
             $link .= '>';
             if (!empty($feed_image)) {
                 $link .= '<img src="' . esc_url($feed_image) . '" style="border: none;"' . $alt . $title . ' />';
             } else {
                 $link .= $name;
             }
             $link .= '</a>';
             if (empty($feed_image)) {
                 $link .= ')';
             }
         }
         if ($optioncount) {
             if ($this->type == "checkbox" || $this->type == "radio") {
                 $link .= ' <span class="' . SF_CLASS_PRE . 'count">(' . $posts . ')</span>';
             } else {
                 $link .= ' (' . $posts . ')';
             }
         }
         $return .= $link;
         //$return .= ( 'list' == $style ) ? '</li>' : ', ';
         if ($this->type == "select" || $this->type == "multiselect") {
             $return .= '</option>';
         } else {
             if ($this->type == "radio" || $this->type == "checkbox") {
                 $return .= '</label></li>';
             }
         }
     }
     if ($this->type == "select") {
         $return .= '</select>';
     } else {
         if ($this->type == "radio") {
             $return .= '</ul>';
         } else {
             if ($this->type == "checkbox") {
                 $return .= '</ul>';
             } else {
                 if ($this->type == "multiselect") {
                     $return .= '</select>';
                 }
             }
         }
     }
     $return = rtrim($return, ', ');
     if (!$echo) {
         return $return;
     }
     echo $return;
 }
 public function writeMetaAuthors()
 {
     // authors
     global $wpdb;
     $plugin_dir = plugin_dir_path(__FILE__);
     $dir = $this->destination . '/authors/';
     $defaults = array('orderby' => 'name', 'order' => 'ASC', 'number' => '', 'optioncount' => false, 'exclude_admin' => false, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => false, 'exclude' => '', 'include' => '');
     $authors = get_users($defaults);
     foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
         $author_count[$row->post_author] = $row->count;
     }
     foreach ($author_count as $author_id => $cnt) {
         $author = get_userdata($author_id);
         $authorDir = $dir . $author->user_nicename;
         $authorFile = $authorDir . '/author.md';
         if (!is_dir($authorDir)) {
             wp_mkdir_p($authorDir);
         }
         // include export template by type
         ob_start();
         include $plugin_dir . '../templates/export/author.md';
         $content = ob_get_contents();
         ob_end_clean();
         //        $data = file_get_contents($permalink);
         file_put_contents($authorFile, $content);
     }
     // category, tags
 }
 function wp_authors($args = '')
 {
     global $wpdb;
     $defaults = array('orderby' => 'name', 'order' => 'ASC', 'number' => '', 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => '', 'post_types' => array('post'), 'combo_box' => '');
     $args = wp_parse_args($args, $defaults);
     extract($args, EXTR_SKIP);
     $return = '';
     $query_args = wp_array_slice_assoc($args, array('orderby', 'order', 'number', 'exclude', 'include'));
     $query_args['fields'] = 'ids';
     $authors = get_users($query_args);
     //build where conditions for post types...
     $where_conditions = array();
     $post_type_count = count($post_types);
     $where_query = '';
     if ($post_type_count > 0) {
         foreach ($post_types as $post_type) {
             if (post_type_exists($post_type)) {
                 $post_type = esc_attr($post_type);
                 $where_conditions[] = " (post_type = '{$post_type}' AND " . get_private_posts_cap_sql($post_type) . ")";
             }
         }
         $where_query = implode(" OR", $where_conditions);
     }
     $author_count = array();
     foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE{$where_query} GROUP BY post_author") as $row) {
         $author_count[$row->post_author] = $row->count;
     }
     $show_option_all_sf = $args['show_option_all_sf'];
     $show_default_option_sf = $args['show_default_option_sf'];
     if (isset($show_option_all_sf) && $show_default_option_sf == true) {
         $default_option = new stdClass();
         $default_option->label = $show_option_all_sf;
         $default_option->attributes = array('class' => SF_CLASS_PRE . 'level-0 ' . SF_ITEM_CLASS_PRE . '0');
         $default_option->value = "";
         $default_option->count = 0;
         array_push($this->options, $default_option);
     }
     foreach ($authors as $author_id) {
         $author = get_userdata($author_id);
         //var_dump($author);
         if ($exclude_admin && 'admin' == $author->display_name) {
             continue;
         }
         $option_count = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
         if (!$option_count && $hide_empty) {
             continue;
         }
         $link = '';
         if ($show_fullname && $author->first_name && $author->last_name) {
             $name = "{$author->first_name} {$author->last_name}";
         } else {
             $name = $author->display_name;
         }
         /*if ( !$html ) {
         				$return .= $name . ', ';
         
         				continue; // No need to go further to process HTML.
         			}*/
         if ($optioncount) {
             if ($show_count_format_sf == "inline") {
                 $name .= ' (' . number_format_i18n($option_count) . ')';
             } else {
                 if ($show_count_format_sf == "html") {
                     $name .= '<span class="' . SF_CLASS_PRE . 'count">(' . number_format_i18n($option_count) . ')</span>';
                 }
             }
         }
         $option = new stdClass();
         $option->attributes = array('class' => SF_CLASS_PRE . 'level-0');
         $option->value = $author->user_nicename;
         //$option->selected_value = $author->ID; //we want to match defaults based on ID
         $option->label = $name;
         $option->count = $option_count;
         array_push($this->options, $option);
     }
     $this->options_obj->set($this->options);
 }
示例#14
0
    if ($comments) {
        foreach ($comments as $comment) {
            echo '<li>' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="' . get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . apply_filters('the_title', get_the_title($comment->comment_post_ID)) . '</a>');
            edit_comment_link(__("Edit"), ' <small>(', ')</small>');
            echo '</li>';
        }
    }
    ?>
</ul>
</div>
<?php 
}
?>

<?php 
if ($recentposts = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " AND post_date_gmt < '{$today}' ORDER BY post_date DESC LIMIT 5")) {
    ?>
<div>
<h3><?php 
    _e('Posts');
    ?>
 <a href="edit.php" title="<?php 
    _e('More posts...');
    ?>
">&raquo;</a></h3>
<ul>
<?php 
    foreach ($recentposts as $post) {
        if ($post->post_title == '') {
            $post->post_title = sprintf(__('Post #%s'), $post->ID);
        }
/**
 * List all the authors of the blog, with several options available.
 *
 * <ul>
 * <li>optioncount (boolean) (false): Show the count in parenthesis next to the
 * author's name.</li>
 * <li>exclude_admin (boolean) (true): Exclude the 'admin' user that is
 * installed bydefault.</li>
 * <li>show_fullname (boolean) (false): Show their full names.</li>
 * <li>hide_empty (boolean) (true): Don't show authors without any posts.</li>
 * <li>feed (string) (''): If isn't empty, show links to author's feeds.</li>
 * <li>feed_image (string) (''): If isn't empty, use this image to link to
 * feeds.</li>
 * <li>echo (boolean) (true): Set to false to return the output, instead of
 * echoing.</li>
 * <li>style (string) ('list'): Whether to display list of authors in list form
 * or as a string.</li>
 * <li>html (bool) (true): Whether to list the items in html for or plaintext.
 * </li>
 * </ul>
 *
 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors
 * @since 1.2.0
 * @param array $args The argument array.
 * @return null|string The output, if echo is set to false.
 */
function wp_list_authors($args = '')
{
    global $wpdb;
    $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $return = '';
    /** @todo Move select to get_authors(). */
    $users = get_users_of_blog();
    $author_ids = array();
    foreach ((array) $users as $user) {
        $author_ids[] = $user->user_id;
    }
    if (count($author_ids) > 0) {
        $author_ids = implode(',', $author_ids);
        $authors = $wpdb->get_results("SELECT ID, user_nicename from {$wpdb->users} WHERE ID IN({$author_ids}) " . ($exclude_admin ? "AND user_login <> 'admin' " : '') . "ORDER BY display_name");
    } else {
        $authors = array();
    }
    $author_count = array();
    foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
        $author_count[$row->post_author] = $row->count;
    }
    foreach ((array) $authors as $author) {
        $link = '';
        $author = get_userdata($author->ID);
        $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
        $name = $author->display_name;
        if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
            $name = "{$author->first_name} {$author->last_name}";
        }
        if (!$html) {
            if ($posts == 0) {
                if (!$hide_empty) {
                    $return .= $name . ', ';
                }
            } else {
                $return .= $name . ', ';
            }
            // No need to go further to process HTML.
            continue;
        }
        if (!($posts == 0 && $hide_empty) && 'list' == $style) {
            $return .= '<li>';
        }
        if ($posts == 0) {
            if (!$hide_empty) {
                $link = $name;
            }
        } else {
            $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr(sprintf(__("Posts by %s"), $author->display_name)) . '">' . $name . '</a>';
            if (!empty($feed_image) || !empty($feed)) {
                $link .= ' ';
                if (empty($feed_image)) {
                    $link .= '(';
                }
                $link .= '<a href="' . get_author_feed_link($author->ID) . '"';
                if (!empty($feed)) {
                    $title = ' title="' . esc_attr($feed) . '"';
                    $alt = ' alt="' . esc_attr($feed) . '"';
                    $name = $feed;
                    $link .= $title;
                }
                $link .= '>';
                if (!empty($feed_image)) {
                    $link .= "<img src=\"" . esc_url($feed_image) . "\" style=\"border: none;\"{$alt}{$title}" . ' />';
                } else {
                    $link .= $name;
                }
                $link .= '</a>';
                if (empty($feed_image)) {
                    $link .= ')';
                }
            }
            if ($optioncount) {
                $link .= ' (' . $posts . ')';
            }
        }
        if (!($posts == 0 && $hide_empty) && 'list' == $style) {
            $return .= $link . '</li>';
        } else {
            if (!$hide_empty) {
                $return .= $link . ', ';
            }
        }
    }
    $return = trim($return, ', ');
    if (!$echo) {
        return $return;
    }
    echo $return;
}
示例#16
0
function dt_make_option_list($args)
{
    extract($args);
    $return = array('options' => array(), 'values' => array(), 'default' => array());
    switch ($type) {
        case 'categories':
            $all_cats = get_categories('hide_empty=0&orderby=name');
            foreach ($all_cats as $cat) {
                $return['options'][] = (string) $cat->cat_name;
                $return['values'][] = (string) $cat->cat_ID;
                $return['default'][] = "not";
            }
            break;
        case 'tags':
            $all_tags = get_tags('hide_empty=0&orderby=name');
            foreach ($all_tags as $tag) {
                $return['options'][] = (string) $tag->name;
                $return['values'][] = (string) $tag->term_id;
                $return['default'][] = "not";
            }
            break;
        case 'authors':
            $users = get_users();
            $author_ids = array();
            foreach ((array) $users as $user) {
                $author_ids[] = $user->user_id;
            }
            global $wpdb;
            if (count($author_ids) > 0) {
                $author_ids = implode(',', $author_ids);
                $authors = $wpdb->get_results("SELECT ID, user_nicename from {$wpdb->users} WHERE ID IN({$author_ids}) ORDER BY display_name");
            } else {
                $authors = array();
            }
            $author_count = array();
            foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
                $author_count[$row->post_author] = $row->count;
            }
            foreach ((array) $authors as $author) {
                $author = get_userdata($author->ID);
                $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
                $author_name = $author->display_name;
                $return['options'][] = (string) $author_name . " (" . $posts . " posts)";
                $return['values'][] = (string) $author->ID;
                $return['default'][] = "not";
            }
            break;
        case 'pages':
            $all_pages = get_pages();
            foreach ($all_pages as $this_page) {
                $return['options'][] = (string) $this_page->post_title;
                $return['values'][] = (string) $this_page->ID;
                $return['default'][] = "not";
            }
            break;
    }
    return $return;
}
示例#17
0
/**
 * List all the authors of the blog, with several options available.
 * optioncount (boolean) (false): Show the count in parenthesis next to the author's name.
 * exclude_admin (boolean) (true): Exclude the 'admin' user that is installed by default.
 * show_fullname (boolean) (false): Show their full names.
 * hide_empty (boolean) (true): Don't show authors without any posts.
 * feed (string) (''): If isn't empty, show links to author's feeds.
 * feed_image (string) (''): If isn't empty, use this image to link to feeds.
 * echo (boolean) (true): Set to false to return the output, instead of echoing.
 * @param array $args The argument array.
 * @return null|string The output, if echo is set to false.
 */
function wp_list_authors($args = '')
{
    global $wpdb;
    $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    $return = '';
    // TODO:  Move select to get_authors().
    $authors = $wpdb->get_results("SELECT ID, user_nicename from {$wpdb->users} " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
    $author_count = array();
    foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
        $author_count[$row->post_author] = $row->count;
    }
    foreach ((array) $authors as $author) {
        $author = get_userdata($author->ID);
        $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
        $name = $author->display_name;
        if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
            $name = "{$author->first_name} {$author->last_name}";
        }
        if (!($posts == 0 && $hide_empty)) {
            $return .= '<li>';
        }
        if ($posts == 0) {
            if (!$hide_empty) {
                $link = $name;
            }
        } else {
            $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
            if (!empty($feed_image) || !empty($feed)) {
                $link .= ' ';
                if (empty($feed_image)) {
                    $link .= '(';
                }
                $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"';
                if (!empty($feed)) {
                    $title = ' title="' . $feed . '"';
                    $alt = ' alt="' . $feed . '"';
                    $name = $feed;
                    $link .= $title;
                }
                $link .= '>';
                if (!empty($feed_image)) {
                    $link .= "<img src=\"{$feed_image}\" border=\"0\"{$alt}{$title}" . ' />';
                } else {
                    $link .= $name;
                }
                $link .= '</a>';
                if (empty($feed_image)) {
                    $link .= ')';
                }
            }
            if ($optioncount) {
                $link .= ' (' . $posts . ')';
            }
        }
        if (!($posts == 0 && $hide_empty)) {
            $return .= $link . '</li>';
        }
    }
    if (!$echo) {
        return $return;
    }
    echo $return;
}
示例#18
0
function user_cloud()
{
    global $wpdb;
    $authors = $wpdb->get_results("SELECT ID, user_nicename from {$wpdb->users} ORDER BY display_name");
    $author_count = array();
    foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
        $author_count[$row->post_author] = $row->count;
    }
    foreach ((array) $authors as $author) {
        $author = get_userdata($author->ID);
        echo '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">';
        echo get_avatar($author->ID, 48) . "</a>";
    }
}
示例#19
0
 function widget_authors_list_authors($args = '')
 {
     global $wpdb;
     $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true, 'show_avatar' => false, 'avatar_size' => 32);
     $r = wp_parse_args($args, $defaults);
     extract($r, EXTR_SKIP);
     $return = '';
     /** @todo Move select to get_authors(). */
     $authors = $wpdb->get_results("SELECT ID, user_nicename FROM {$wpdb->users} WHERE ID = 3 OR ID = 7 OR ID = 2 OR ID = 5 ORDER BY display_name");
     $author_count = array();
     foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " GROUP BY post_author") as $row) {
         $author_count[$row->post_author] = $row->count;
     }
     foreach ((array) $authors as $author) {
         $link = '';
         $author = get_userdata($author->ID);
         if ($exclude_admin && 10 == $author->user_level) {
             continue;
         }
         $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
         $name = $author->display_name;
         $email = $author->user_email;
         $avatar = get_avatar($email, $avatar_size);
         if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
             $name = "{$author->first_name} {$author->last_name}";
         }
         if (!$html) {
             if ($posts == 0) {
                 if (!$hide_empty) {
                     $return .= $name . ', ';
                 }
             } else {
                 $return .= $name . ', ';
             }
             // No need to go further to process HTML.
             continue;
         }
         if (!($posts == 0 && $hide_empty) && 'list' == $style) {
             $return .= '<li><div class="maw-author-head">';
         }
         if ($posts == 0) {
             if (!$hide_empty) {
                 $link = $name;
             }
         } else {
             $link = '';
             if ($show_avatar && !empty($avatar)) {
                 $return .= "<div class='maw-author-img'>" . $avatar . '</div>';
             }
             $return .= '<div class="maw-author-name"><a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr(sprintf(__("Posts by %s"), $author->display_name)) . '">' . $name . '</a></div>';
             if ($optioncount) {
                 $link .= ' (' . $posts . ')';
             }
             $return .= "</div><ul>";
             $author_posts = $wpdb->get_results("SELECT id, post_title, guid FROM {$wpdb->posts} WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " AND post_author = " . $author->ID . " ORDER BY ID desc LIMIT " . $posts_limit);
             $post_links = "";
             foreach ($author_posts as $author_post) {
                 $post_links .= "<li><a href = " . get_permalink($author_post->id) . " > " . $author_post->post_title . "</a></li>";
             }
             $post_links .= "</ul>";
         }
         if (!($posts == 0 && $hide_empty) && 'list' == $style) {
             $return .= $link . $post_links . '</li>' . "\n";
         } else {
             if (!$hide_empty) {
                 $return .= $link . ', ';
             }
         }
     }
     $return = trim($return, ', ');
     if (!$echo) {
         return $return;
     }
     echo $return;
 }