function execute($args = '', $default_output_template = '<li>{commentlink}</li>') { if (!RecentComments::check_post_plugin_library(__('Post-Plugin Library missing', 'recent_comments_plugin'))) { return; } global $wpdb, $wp_version, $recent_comments_current_ID; $start_time = ppl_microtime(); if (defined('POC_CACHE_4')) { $cache_key = 'recent-comments' . $args; $result = poc_cache_fetch($cache_key); if ($result !== false) { return $result . sprintf("<!-- Recent Comments 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('recent-comments', $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'; $just_current_post = $options['just_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']; $unique = $options['unique'] === 'true'; $filter_comments = ($options['show_type'] === 'comments' or $options['show_type'] === 'trackbacks'); $no_author_comments = $options['no_author_comments'] === 'true'; $no_user_comments = $options['no_user_comments'] !== 'false'; //the workhorse... $where = $groupby = array(); if (!$unique) { $sql = "SELECT * FROM {$wpdb->comments} LEFT JOIN `{$wpdb->posts}` ON `comment_post_ID` = `ID` "; } else { $sql = "SELECT *, MAX(comment_date) AS comment_date FROM {$wpdb->comments} LEFT JOIN `{$wpdb->posts}` ON `comment_post_ID` = `ID` "; $groupby[] = "comment_post_ID"; } if ($check_custom) { $sql .= "LEFT JOIN {$wpdb->postmeta} ON post_id = ID "; $groupby[] = "ID"; } // build the 'WHERE' clause 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($recent_comments_current_ID); } if ($just_current_post) { $where[] = where_just_post(); } if ($hide_pass) { $where[] = where_hide_pass(); } if ($check_age) { $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']); } if ($no_author_comments) { $where[] = where_author_comments(); } if ($no_user_comments) { $where[] = where_user_comments(); } if ($filter_comments) { $where[] = where_comment_type($options['show_type']); } if ($check_custom) { $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']); } $where[] = "comment_approved = '1'"; $sql .= "WHERE " . implode(' AND ', $where); if (count($groupby) > 0) { $sql .= " GROUP BY " . implode(', ', $groupby); } $sql .= " ORDER BY comment_date DESC LIMIT {$limit}"; //echo $sql; $results = $wpdb->get_results($sql); } else { $results = false; } if ($results) { $translations = ppl_prepare_template($options['output_template']); if ($options['group_by'] === 'post') { $options['sort']['by1'] = '{date:raw}'; $options['sort']['order1'] = SORT_DESC; $options['sort']['case1'] = 'false'; $options['sort']['by2'] = '{commentdate:raw}'; $options['sort']['order2'] = SORT_DESC; $options['sort']['case2'] = 'false'; } elseif ($options['group_by'] === 'author') { $options['sort']['by1'] = '{commenter}'; $options['sort']['order1'] = SORT_ASC; $options['sort']['case1'] = 'true'; $options['sort']['by2'] = '{commentdate:raw}'; $options['sort']['order2'] = SORT_DESC; $options['sort']['case2'] = 'false'; } foreach ($results as $result) { $items[] = ppl_expand_template($result, $options['output_template'], $translations, 'recent-comments'); } if ($options['sort']['by1'] !== '') { $items = ppl_sort_items($options['sort'], $results, 'recent-comments', $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, 'recent_comments') . $options['suffix']; } } if (defined('POC_CACHE_4')) { poc_cache_store($cache_key, $output); } return $output ? $output . sprintf("<!-- Recent Comments took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : ''; }
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)) : ''; }