intval(get_option('posts_per_rss')), //post limit in category feed 'comments_per_rss' => intval(get_option('posts_per_rss')), //comment limit in comment feed 'posts_per_rss' => 10, //post limit in main feed 'what_to_show' => 'posts', //posts or days 'postsort' => 0, //post sort, 0=>publish date, 1=>modified date, 2=>post ID 'page' => false, //Include page 'pages_per_rss' => 3, //page limit in main feed 'pagesort' => 1, //page sort, 0=>publish date, 1=>modified date, 2=>post ID 'exclude' => '', //exclude ID 'include' => '' //include ID ); update_option("feedcontrolplus", $options); } } function fcp_deactivate() { //delete_option("feedcontrolplus"); } load_plugin_textdomain('fcp'); add_filter('option_posts_per_rss', 'fcp_post_per_rss' ); function fcp_post_per_rss($value) { global $withcomments; if ( !is_feed() ) return $value; //admin page $fc = get_option('feedcontrolplus'); if ( $withcomments == 1 ) return $fc['comments_per_rss']; //main comment feed and post comment feed if ( is_archive() ) return $fc['cat_feed_posts']; //categories feed return 999; //for if ($items_count == get_settings('posts_per_rss')) at the end of wp-rss2.php } add_filter('posts_request', 'fcp_posts_request'); function fcp_posts_request($request) { global $withcomments; if ( !is_feed() || ($withcomments==1) || is_attachment() || is_archive() || is_single() || is_page() || is_search() || is_home() || is_trackback() || is_404() || is_admin() || is_comments_popup() ) { return $request; } else { $fcp_pr = new Fcp_pr(); return $fcp_pr->get_request($request); } } class Fcp_pr { var $fc; var $now; var $sort = array( 0 => 'post_date_gmt', 1 => 'post_modified_gmt', 2 => 'ID' ); var $where_exclude; function Fcp_pr() { global $wpdb; $this->fc = get_option('feedcontrolplus'); $this->now = current_time('mysql', 1); //set where_exclude $where_exclude = ''; if ( !empty($this->fc['exclude']) ) { $excludes = explode(',', $this->fc['exclude']); if ( count($excludes) ) { foreach ( $excludes as $exclude ) { if (strpos($exclude, '-')==false) { $where_exclude .= " AND $wpdb->posts.ID <> " . intval($exclude); } else { $pos = strpos($exclude, '-'); $first = intval( substr($exclude, 0, $pos) ); $last = intval( substr($exclude, $pos+1) ); $where_exclude .= " AND ($wpdb->posts.ID < $first OR $wpdb->posts.ID > $last)"; } } } } $this->where_exclude = $where_exclude; } function get_request($request) { $requests = array(); $requests[] = $this->get_post(); if ( $this->fc['page'] ) $requests[] = $this->get_page(); if ( !empty($this->fc['include']) ) $requests[] = $this->get_include(); $request = '(' . implode(') UNION (', $requests) . ')'; return $request; } function get_post() { global $wpdb; $where = " AND post_date_gmt <= '{$this->now}'"; $where .= " AND post_status = 'publish'"; $where .= $this->where_exclude; $orderby = $this->sort[$this->fc['postsort']]; if ( $this->fc['what_to_show'] == 'posts' ) { $limit = ' LIMIT 0, ' . $this->fc['posts_per_rss']; } else { $endrow = $this->fc['posts_per_rss'] - 1; $post_date = ($this->fc['postsort']==1) ? 'post_modified' : 'post_date'; $end_date = $wpdb->get_var("SELECT min($post_date) FROM $wpdb->posts WHERE post_date_gmt <= '{$this->now}' AND post_status = 'publish'{$this->where_exclude} GROUP BY year($post_date), month($post_date), dayofmonth($post_date) ORDER BY $post_date DESC LIMIT $endrow,1"); $where .= " AND $post_date >= '$end_date'"; $limit = ' LIMIT 999'; //If don't add this, the SQL result order will be error. Fix MySQL UNION order error } return "SELECT DISTINCT * FROM $wpdb->posts WHERE 1=1$where GROUP BY ID ORDER BY $orderby DESC$limit"; //SELECT DISTINCT * FROM wp_posts WHERE 1=1 AND post_date_gmt <= '2006-11-18 12:03:59' AND (post_status = "publish" OR post_author = 1 AND post_status != 'draft' AND post_status != 'static') AND post_status != "attachment" GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 10 //$request = " SELECT * FROM $wpdb->posts WHERE 1=1" . $where . " ORDER BY " . $orderby . " DESC LIMIT 0, " . $limit; } function get_page() { global $wpdb; $where = " AND post_date_gmt <= '{$this->now}'"; $where .= " AND post_status = 'static'"; $where .= $this->where_exclude; $orderby = $this->sort[$this->fc['pagesort']]; return "SELECT DISTINCT * FROM $wpdb->posts WHERE 1=1$where GROUP BY ID ORDER BY $orderby DESC LIMIT 0, " . $this->fc['pages_per_rss']; } function get_include() { global $wpdb; $where = ''; $includes = explode(',', $this->fc['include']); if ( count($includes) ) { foreach ( $includes as $include ) { if (strpos($include, '-')==false) { $where .= " OR $wpdb->posts.ID = " . intval($include); } else { $pos = strpos($include, '-'); $first = intval( substr($include, 0, $pos) ); $last = intval( substr($include, $pos+1) ); $where .= " OR ($wpdb->posts.ID >= $first AND $wpdb->posts.ID <= $last)"; } } } return "SELECT DISTINCT * FROM $wpdb->posts WHERE 1=0$where GROUP BY ID"; } } //end of class Fcp_pr add_action('admin_menu', 'fcp_add_option_page'); function fcp_add_option_page() { if ( function_exists('add_options_page') ) { add_options_page('Feed Control Plus Settings', 'Feed Control+', 8, __FILE__, 'fcp_option_page'); } } function fcp_option_page() { global $wpdb; if ( isset($_POST['Submit']) ) { $options = array(); $options['cat_feed_posts'] = (int) $_POST['cat_feed_posts']; $options['comments_per_rss'] = (int) $_POST['comments_per_rss']; $options['posts_per_rss'] = (int) $_POST['posts_per_rss']; $options['what_to_show'] = (string) $_POST['what_to_show']; $options['postsort'] = (int) $_POST['postsort']; $options['page'] = (bool) $_POST['page']; $options['pages_per_rss'] = (int) $_POST['pages_per_rss']; $options['pagesort'] = (int) $_POST['pagesort']; $options['exclude'] = fcp_option_optimize( (string) $_POST['exclude'] ); $options['include'] = fcp_option_optimize( (string) $_POST['include'] ); update_option('feedcontrolplus', $options); ?>

this plugin\'s page.', 'fcp') ?>
">



'; } ?>
' . __('Posts in feed:', 'fcp') . ''; $fcp_post_request = $fcp_pr->get_post(); $result = $wpdb->get_results($fcp_post_request); $posts = fcp_get_id($result); foreach ( $posts as $id ) { $post = get_post($id); echo $id . '. ' . $post->post_title . ' (' . ( ($fc['postsort']==1) ? (__('Modified at ', 'fcp') . mysql2date('Y-m-d G:i', $post->post_modified)) : (__('Publish at ', 'fcp') . mysql2date('Y-m-d G:i', $post->post_date)) ) . ')
'; } echo '

'; } ?>
/>
' . __('Pages in feed:', 'fcp') . ''; $fcp_page_request = $fcp_pr->get_page(); $result = $wpdb->get_results($fcp_page_request); $pages = fcp_get_id($result); foreach ( $pages as $id ) { $post = get_post($id); echo $id . '. ' . $post->post_title . ' (' . ( ($fc['postsort']!=1) ? (__('Publish at ', 'fcp') . mysql2date('Y-m-d G:i', $post->post_date)) : (__('Modified at ', 'fcp') . mysql2date('Y-m-d G:i', $post->post_modified)) ) . ')
'; } echo '

where_exclude = ''; //clear exclude, and than get IDs. $fcp_post_request = $fcp_pr->get_post(); $result = $wpdb->get_results($fcp_post_request); $posts = fcp_get_id($result); if ($fc['page']) { $fcp_page_request = $fcp_pr->get_page(); $result = $wpdb->get_results($fcp_page_request); $pages = fcp_get_id($result); } $post_page = array_merge($posts, $pages); if ( !empty($fc['exclude']) ) { echo ''; } ?>


' . __('Excluded posts/pages:', 'fcp') . ''; $excludes = explode(',', $fc['exclude']); $excludes = fcp_spread($excludes); $exclude_tip = false; foreach ( $excludes as $id ) { $post = get_post($id); $id_style = ''; if ( !in_array($id, $post_page) or (!$fc['page'] && ($post->post_status == 'static')) ) { $id_style = ' style="color:#A0A0A0"'; $exclude_tip = true; } echo "" . $id . '. ' . $post->post_title . ' (' . fcp_posttype($post->post_status) . ')
'; } echo '
'; if ($exclude_tip) printf(__("The grey IDs are not in the newest %1\$s posts", 'fcp') . ( $fc['page'] ? (__(" and %2\$s pages", 'fcp')) : '' ) . __('.', 'fcp'), $fc['posts_per_rss'], $fc['pages_per_rss']); echo '

'; } ?>

' . __('Included posts/pages:', 'fcp') . ''; $includes = explode(',', $fc['include']); $includes = fcp_spread($includes); $include_tip = false; foreach ( $includes as $id ) { $post = get_post($id); $id_style = ''; if ( in_array($id, $post_page) ) { $id_style = ' style="color:#A0A0A0"'; $include_tip = true; } echo "" . $id . '. ' . $post->post_title . ' (' . fcp_posttype($post->post_status) . ')' . ( (isset($excludes) && in_array($id, $excludes)) ? '
' . __('Warning: ID ', 'fcp') . $id . __(' is also excluded!', 'fcp') . '' : '' ) . '
'; } echo '
'; if ($include_tip) printf(__("The grey IDs are now already in the newest %1\$s posts", 'fcp') . ( $fc['page'] ? (__(" and %2\$s pages", 'fcp')) : '' ) . __('.', 'fcp'), $fc['posts_per_rss'], $fc['pages_per_rss']); echo '
get_request(''); //debug ?>

__('post', 'fcp'), 'static' => __('page', 'fcp'), 'draft' => __('draft', 'fcp'), 'private' => __('private', 'fcp'), 'object' => __('object', 'fcp'), 'attachment' => __('attachment', 'fcp') ); return isset($type[$post_status]) ? $type[$post_status] : $post_status; } //Optimize exclude string and include string. function fcp_option_optimize($exclude) { $excludes = preg_split( '/[\s,]+/',preg_replace("/[^\s\d,-]/", '', $exclude) ); $excludes = array_unique($excludes); sort($excludes); if ($excludes[0]=='') unset($excludes[0]); return implode($excludes, ','); } //Spread string into IDs. function fcp_spread($ids) { $result = array(); foreach ($ids as $id) { if ( strpos($id, '-')==false ) { $result[] = intval($id); } else { $pos = strpos($id, '-'); $first = intval( substr($id, 0, $pos) ); $last = intval( substr($id, $pos+1) ); $result = array_merge( $result, range($first, $last) ); } } return array_unique($result); } function fcp_get_id($result) { $ids = array(); foreach ($result as $i => $id) $ids[$i] = $result[$i]->ID; return $ids; } ?>