function random_posts_options_page() { echo '<div class="wrap"><h2>'; _e('Random Posts ', 'random_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 (!RandomPosts::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', 'random_posts_general_options_subpage'); $m->add_subpage('Output', 'output', 'random_posts_output_options_subpage'); $m->add_subpage('Filter', 'filter', 'random_posts_filter_options_subpage'); $m->add_subpage('Placement', 'placement', 'random_posts_placement_options_subpage'); $m->add_subpage('Other', 'other', 'random_posts_other_options_subpage'); $m->add_subpage('Report a Bug', 'bug', 'random_posts_bug_subpage'); $m->add_subpage('Remove this Plugin', 'remove', 'random_posts_remove_subpage'); $m->display(); add_action('in_admin_footer', 'random_posts_admin_footer'); }
function execute($args = '', $default_output_template = '<li>{link}</li>') { if (!RandomPosts::check_post_plugin_library(__('Post-Plugin Library missing'))) { return; } global $wpdb, $wp_version, $random_posts_current_ID; $start_time = ppl_microtime(); // 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('random-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 * FROM {$wpdb->posts} "; if ($check_custom) { $sql .= "LEFT JOIN {$wpdb->postmeta} ON post_id = ID "; } // build the 'WHERE' clause $where = array(); 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($random_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 RAND() 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, 'random-posts'); } if ($options['sort']['by1'] !== '') { $items = ppl_sort_items($options['sort'], $results, 'random-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, 'random-posts') . $options['suffix']; } } return $output ? $output . sprintf("<!-- Random Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : ''; }