- } //if($num_toks)
- //add the rules for this dir to the accumulating $post_rewrite
- $post_rewrite = array_merge($rewrite, $post_rewrite);
- } //foreach ($dir)
- return $post_rewrite; //the finished rules. phew!
- }
-
- function generate_rewrite_rule($permalink_structure, $walk_dirs = false) {
- return $this->generate_rewrite_rules($permalink_structure, EP_NONE, false, false, false, $walk_dirs);
- }
-
- /* rewrite_rules
- * Construct rewrite matches and queries from permalink structure.
- * Returns an associate array of matches and queries.
- */
- function rewrite_rules() {
- $rewrite = array();
-
- if (empty($this->permalink_structure)) {
- return $rewrite;
- }
-
- // robots.txt
- $robots_rewrite = array('robots.txt$' => $this->index . '?robots=1');
-
- //Default Feed rules - These are require to allow for the direct access files to work with permalink structure starting with %category%
- $default_feeds = array( '.*/wp-atom.php$' => $this->index .'?feed=atom',
- '.*/wp-rdf.php$' => $this->index .'?feed=rdf',
- '.*/wp-rss.php$' => $this->index .'?feed=rss',
- '.*/wp-rss2.php$' => $this->index .'?feed=rss2',
- '.*/wp-feed.php$' => $this->index .'?feed=feed',
- '.*/wp-commentsrss2.php$' => $this->index . '?feed=rss2&withcomments=1');
-
- // Post
- $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK);
- $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite);
-
- // Date
- $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
- $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite);
-
- // Root
- $root_rewrite = $this->generate_rewrite_rules($this->root . '/', EP_ROOT);
- $root_rewrite = apply_filters('root_rewrite_rules', $root_rewrite);
-
- // Comments
- $comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, EP_COMMENTS, true, true, true, false);
- $comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite);
-
- // Search
- $search_structure = $this->get_search_permastruct();
- $search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);
- $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
-
- // Categories
- $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);
- $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);
-
- // Tags
- $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);
- $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);
-
- // Authors
- $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
- $author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite);
-
- // Pages
- $page_rewrite = $this->page_rewrite_rules();
- $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
-
- // Extra permastructs
- foreach ( $this->extra_permastructs as $permastruct )
- $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE));
-
- // Put them together.
- if ( $this->use_verbose_page_rules )
- $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);
- else
- $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
-
- do_action_ref_array('generate_rewrite_rules', array(&$this));
- $this->rules = apply_filters('rewrite_rules_array', $this->rules);
-
- return $this->rules;
- }
-
- function wp_rewrite_rules() {
- $this->rules = get_option('rewrite_rules');
- if ( empty($this->rules) ) {
- $this->matches = 'matches';
- $this->rewrite_rules();
- update_option('rewrite_rules', $this->rules);
- }
-
- return $this->rules;
- }
-
- function mod_rewrite_rules() {
- if ( ! $this->using_permalinks()) {
- return '';
- }
-
- $site_root = parse_url(get_option('siteurl'));
- $site_root = trailingslashit($site_root['path']);
-
- $home_root = parse_url(get_option('home'));
- $home_root = trailingslashit($home_root['path']);
-
- $rules = "<IfModule mod_rewrite.c>\n";
- $rules .= "RewriteEngine On\n";
- $rules .= "RewriteBase $home_root\n";
-
- //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
- foreach ($this->non_wp_rules as $match => $query) {
- // Apache 1.3 does not support the reluctant (non-greedy) modifier.
- $match = str_replace('.+?', '.+', $match);
-
- // If the match is unanchored and greedy, prepend rewrite conditions
- // to avoid infinite redirects and eclipsing of real files.
- if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
- //nada.