コード例 #1
0
function popular_posts_options_page()
{
    echo '<div class="wrap"><h2>';
    _e('Popular Posts ', 'popular_posts_plugin');
    echo '<a href="http://rmarsh.com/plugins/post-options/" style="font-size: 0.8em;">';
    _e('help and instructions');
    echo '</a></h2></div>';
    if (!PopularPosts::check_post_plugin_library(__('<h1>Please install the <a href="http://downloads.wordpress.org/plugin/post-plugin-library.zip">Post Plugin Library</a> plugin.</h1>'))) {
        return;
    }
    $m = new admin_subpages();
    $m->add_subpage('General', 'general', 'popular_posts_general_options_subpage');
    $m->add_subpage('Output', 'output', 'popular_posts_output_options_subpage');
    $m->add_subpage('Filter', 'filter', 'popular_posts_filter_options_subpage');
    $m->add_subpage('Placement', 'placement', 'popular_posts_placement_options_subpage');
    $m->add_subpage('Other', 'other', 'popular_posts_other_options_subpage');
    $m->add_subpage('Report a Bug', 'bug', 'popular_posts_bug_subpage');
    $m->add_subpage('Remove this Plugin', 'remove', 'popular_posts_remove_subpage');
    $m->display();
    add_action('in_admin_footer', 'popular_posts_admin_footer');
}
コード例 #2
0
 function execute($args = '', $default_output_template = '<li>{link}</li>')
 {
     if (!PopularPosts::check_post_plugin_library(__('Post-Plugin Library missing'))) {
         return;
     }
     global $wpdb, $wp_version, $popular_posts_current_ID;
     $start_time = ppl_microtime();
     if (defined('POC_CACHE_4')) {
         $cache_key = 'popular-posts' . $args;
         $result = poc_cache_fetch($cache_key);
         if ($result !== false) {
             return $result . sprintf("<!-- popular Posts took %.3f ms (cached) -->", 1000 * (ppl_microtime() - $start_time));
         }
     }
     // First we process any arguments to see if any defaults have been overridden
     $options = ppl_parse_args($args);
     // Next we retrieve the stored options and use them unless a value has been overridden via the arguments
     $options = ppl_set_options('popular-posts', $options, $default_output_template);
     if (0 < $options['limit']) {
         $match_tags = $options['match_tags'] !== 'false' && $wp_version >= 2.3;
         $exclude_cats = $options['excluded_cats'] !== '';
         $include_cats = $options['included_cats'] !== '';
         $exclude_authors = $options['excluded_authors'] !== '';
         $include_authors = $options['included_authors'] !== '';
         $exclude_posts = trim($options['excluded_posts']) !== '';
         $include_posts = trim($options['included_posts']) !== '';
         $match_category = $options['match_cat'] === 'true';
         $match_author = $options['match_author'] === 'true';
         $use_tag_str = '' != $options['tag_str'] && $wp_version >= 2.3;
         $omit_current_post = $options['omit_current_post'] !== 'false';
         $hide_pass = $options['show_private'] === 'false';
         $check_age = 'none' !== $options['age']['direction'];
         $check_custom = trim($options['custom']['key']) !== '';
         $limit = $options['skip'] . ', ' . $options['limit'];
         //the workhorse...
         $sql = "SELECT *, meta_value + 0 AS viewcount FROM {$wpdb->posts} LEFT JOIN {$wpdb->postmeta} ON post_id = ID ";
         // build the 'WHERE' clause
         $where = array();
         $where[] = "meta_key = 'pvc_views'";
         if (!function_exists('get_post_type')) {
             $where[] = where_hide_future();
         } else {
             $where[] = where_show_status($options['status'], $options['show_attachments']);
         }
         if ($match_category) {
             $where[] = where_match_category();
         }
         if ($match_tags) {
             $where[] = where_match_tags($options['match_tags']);
         }
         if ($match_author) {
             $where[] = where_match_author();
         }
         $where[] = where_show_pages($options['show_pages'], $options['show_attachments']);
         if ($include_cats) {
             $where[] = where_included_cats($options['included_cats']);
         }
         if ($exclude_cats) {
             $where[] = where_excluded_cats($options['excluded_cats']);
         }
         if ($exclude_authors) {
             $where[] = where_excluded_authors($options['excluded_authors']);
         }
         if ($include_authors) {
             $where[] = where_included_authors($options['included_authors']);
         }
         if ($exclude_posts) {
             $where[] = where_excluded_posts(trim($options['excluded_posts']));
         }
         if ($include_posts) {
             $where[] = where_included_posts(trim($options['included_posts']));
         }
         if ($use_tag_str) {
             $where[] = where_tag_str($options['tag_str']);
         }
         if ($omit_current_post) {
             $where[] = where_omit_post($popular_posts_current_ID);
         }
         if ($hide_pass) {
             $where[] = where_hide_pass();
         }
         if ($check_age) {
             $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);
         }
         if ($check_custom) {
             $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);
         }
         $sql .= "WHERE " . implode(' AND ', $where);
         if ($check_custom) {
             $sql .= " GROUP BY {$wpdb->posts}.ID";
         }
         $sql .= " ORDER BY viewcount DESC LIMIT {$limit}";
         $results = $wpdb->get_results($sql);
     } else {
         $results = false;
     }
     if ($results) {
         $translations = ppl_prepare_template($options['output_template']);
         foreach ($results as $result) {
             $items[] = ppl_expand_template($result, $options['output_template'], $translations, 'popular-posts');
         }
         if ($options['sort']['by1'] !== '') {
             $items = ppl_sort_items($options['sort'], $results, 'popular-posts', $options['group_template'], $items);
         }
         $output = implode($options['divider'] ? $options['divider'] : "\n", $items);
         $output = $options['prefix'] . $output . $options['suffix'];
     } else {
         // if we reach here our query has produced no output ... so what next?
         if ($options['no_text'] !== 'false') {
             $output = '';
             // we display nothing at all
         } else {
             // we display the blank message, with tags expanded if necessary
             $translations = ppl_prepare_template($options['none_text']);
             $output = $options['prefix'] . ppl_expand_template(array(), $options['none_text'], $translations, 'popular-posts') . $options['suffix'];
         }
     }
     if (defined('POC_CACHE_4')) {
         poc_cache_store($cache_key, $output);
     }
     return $output ? $output . sprintf("<!-- popular Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : '';
 }