formatted rewrite rules to write to web.config file. * * Does not actually write to the web.config file, but creates the rules for * the process that will. * * @since 2.8.0 * @access public * * @return string */ function iis7_url_rewrite_rules( $add_parent_tags = false ) { if ( ! $this->using_permalinks() ) return ''; $rules = ''; if ( $add_parent_tags ) { $rules .= ' '; } if ( !is_multisite() ) { $rules .= ' '; } else { if (is_subdomain_install()) { $rules .= ' '; } else { $rules .= ' '; } } if ( $add_parent_tags ) { $rules .= ' '; } $rules = apply_filters('iis7_url_rewrite_rules', $rules); return $rules; } /** * Add a straight rewrite rule. * * Any value in the $after parameter that isn't 'bottom' will be placed at * the top of the rules. * * @since 2.1.0 * @access public * * @param string $regex Regular expression to match against request. * @param string $redirect URL regex redirects to when regex matches request. * @param string $after Optional, default is bottom. Location to place rule. */ function add_rule($regex, $redirect, $after = 'bottom') { //get everything up to the first ? $index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?')); $front = substr($redirect, 0, $index); if ( $front != $this->index ) { //it doesn't redirect to WP's index.php $this->add_external_rule($regex, $redirect); } else { if ( 'bottom' == $after) $this->extra_rules = array_merge($this->extra_rules, array($regex => $redirect)); else $this->extra_rules_top = array_merge($this->extra_rules_top, array($regex => $redirect)); //$this->extra_rules[$regex] = $redirect; } } /** * Add a rule that doesn't redirect to index.php. * * Can redirect to any place. * * @since 2.1.0 * @access public * * @param string $regex Regular expression to match against request. * @param string $redirect URL regex redirects to when regex matches request. */ function add_external_rule($regex, $redirect) { $this->non_wp_rules[$regex] = $redirect; } /** * Add an endpoint, like /trackback/. * * See {@link add_rewrite_endpoint()} for full documentation. * * @see add_rewrite_endpoint() * @since 2.1.0 * @access public * @uses WP::add_query_var() * * @param string $name Name of the endpoint. * @param int $places Endpoint mask describing the places the endpoint should be added. */ function add_endpoint($name, $places) { global $wp; $this->endpoints[] = array ( $places, $name ); $wp->add_query_var($name); } /** * Add a new permalink structure. * * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules; it * is an easy way of expressing a set of regular expressions that rewrite to a set of query strings. * The new permastruct is added to the {@link WP_Rewrite::$extra_permastructs} array. When the * rewrite rules are built by {@link WP_Rewrite::rewrite_rules()} all of these extra permastructs * are passed to {@link WP_Rewrite::generate_rewrite_rules()} which transforms them into the * regular expressions that many love to hate. * * The $args parameter gives you control over how {@link WP_Rewrite::generate_rewrite_rules()} * works on the new permastruct. * * @since 2.5.0 * @access public * * @param string $name Name for permalink structure. * @param string $struct Permalink structure (e.g. category/%category%) * @param array $args Optional configuration for building the rules from the permalink structure: * - with_front (bool) - Should the structure be prepended with WP_Rewrite::$front? Default is true. * - ep_mask (int) - Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE. * - paged (bool) - Should archive pagination rules be added for the structure? Default is true. * - feed (bool) - Should feed rewrite rules be added for the structure? Default is true. * - forcomments (bool) - Should the feed rules be a query for a comments feed? Default is false. * - walk_dirs (bool) - Should the 'directories' making up the structure be walked over and rewrite * rules built for each in turn? Default is true. * - endpoints (bool) - Should endpoints be applied to the generated rewrite rules? Default is true. */ function add_permastruct( $name, $struct, $args = array() ) { // backwards compatibility for the old parameters: $with_front and $ep_mask if ( ! is_array( $args ) ) $args = array( 'with_front' => $args ); if ( func_num_args() == 4 ) $args['ep_mask'] = func_get_arg( 3 ); $defaults = array( 'with_front' => true, 'ep_mask' => EP_NONE, 'paged' => true, 'feed' => true, 'forcomments' => false, 'walk_dirs' => true, 'endpoints' => true, ); $args = array_intersect_key( $args, $defaults ); $args = wp_parse_args( $args, $defaults ); if ( $args['with_front'] ) $struct = $this->front . $struct; else $struct = $this->root . $struct; $args['struct'] = $struct; $this->extra_permastructs[ $name ] = $args; } /** * Remove rewrite rules and then recreate rewrite rules. * * Calls {@link WP_Rewrite::wp_rewrite_rules()} after removing the * 'rewrite_rules' option. If the function named 'save_mod_rewrite_rules' * exists, it will be called. * * @since 2.0.1 * @access public * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard). */ function flush_rules($hard = true) { delete_option('rewrite_rules'); $this->wp_rewrite_rules(); if ( $hard && function_exists('save_mod_rewrite_rules') ) save_mod_rewrite_rules(); if ( $hard && function_exists('iis7_save_url_rewrite_rules') ) iis7_save_url_rewrite_rules(); } /** * Sets up the object's properties. * * The 'use_verbose_page_rules' object property will be set to true if the * permalink structure begins with one of the following: '%postname%', '%category%', * '%tag%', or '%author%'. * * @since 1.5.0 * @access public */ function init() { $this->extra_rules = $this->non_wp_rules = $this->endpoints = array(); $this->permalink_structure = get_option('permalink_structure'); $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%')); $this->root = ''; if ( $this->using_index_permalinks() ) $this->root = $this->index . '/'; unset($this->author_structure); unset($this->date_structure); unset($this->page_structure); unset($this->search_structure); unset($this->feed_structure); unset($this->comment_feed_structure); $this->use_trailing_slashes = ( '/' == substr($this->permalink_structure, -1, 1) ); // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) ) $this->use_verbose_page_rules = true; else $this->use_verbose_page_rules = false; } /** * Set the main permalink structure for the blog. * * Will update the 'permalink_structure' option, if there is a difference * between the current permalink structure and the parameter value. Calls * {@link WP_Rewrite::init()} after the option is updated. * * Fires the 'permalink_structure_changed' action once the init call has * processed passing the old and new values * * @since 1.5.0 * @access public * * @param string $permalink_structure Permalink structure. */ function set_permalink_structure($permalink_structure) { if ( $permalink_structure != $this->permalink_structure ) { update_option('permalink_structure', $permalink_structure); $this->init(); do_action('permalink_structure_changed', $this->permalink_structure, $permalink_structure); } } /** * Set the category base for the category permalink. * * Will update the 'category_base' option, if there is a difference between * the current category base and the parameter value. Calls * {@link WP_Rewrite::init()} after the option is updated. * * @since 1.5.0 * @access public * * @param string $category_base Category permalink structure base. */ function set_category_base($category_base) { if ( $category_base != get_option('category_base') ) { update_option('category_base', $category_base); $this->init(); } } /** * Set the tag base for the tag permalink. * * Will update the 'tag_base' option, if there is a difference between the * current tag base and the parameter value. Calls * {@link WP_Rewrite::init()} after the option is updated. * * @since 2.3.0 * @access public * * @param string $tag_base Tag permalink structure base. */ function set_tag_base( $tag_base ) { if ( $tag_base != get_option( 'tag_base') ) { update_option( 'tag_base', $tag_base ); $this->init(); } } /** * Constructor - Calls init(), which runs setup. * * @since 1.5.0 * @access public * * @return WP_Rewrite */ function __construct() { $this->init(); } }