wp/wp-includes/rewrite.php
author ymh <ymh.work@gmail.com>
Wed, 06 Nov 2013 03:21:17 +0000
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
first import
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Rewrite API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Add a straight rewrite rule.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @see WP_Rewrite::add_rule() for long description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @param string $regex Regular Expression to match request against.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @param string $redirect Page to redirect to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * @param string $after Optional, default is 'bottom'. Where to add rule, can also be 'top'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
function add_rewrite_rule($regex, $redirect, $after = 'bottom') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	$wp_rewrite->add_rule($regex, $redirect, $after);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 * Add a new rewrite tag (like %postname%).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
 * The $query parameter is optional. If it is omitted you must ensure that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
 * you call this on, or before, the 'init' hook. This is because $query defaults
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 * to "$tag=", and for this to work a new query var has to be added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
 * @see WP_Rewrite::add_rewrite_tag()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 * @param string $tag Name of the new rewrite tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 * @param string $regex Regular expression to substitute the tag for in rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 * @param string $query String to append to the rewritten query. Must end in '='. Optional.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
function add_rewrite_tag( $tag, $regex, $query = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	// validate the tag's name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	global $wp_rewrite, $wp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	if ( empty( $query ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		$qv = trim( $tag, '%' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		$wp->add_query_var( $qv );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$query = $qv . '=';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 * Add permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 * @see WP_Rewrite::add_permastruct()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * @param string $name Name for permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 * @param string $struct Permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 * @param array $args Optional configuration for building the rules from the permalink structure,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 *     see {@link WP_Rewrite::add_permastruct()} for full details.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
function add_permastruct( $name, $struct, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	// backwards compatibility for the old parameters: $with_front and $ep_mask
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	if ( ! is_array( $args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		$args = array( 'with_front' => $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	if ( func_num_args() == 4 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		$args['ep_mask'] = func_get_arg( 3 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	return $wp_rewrite->add_permastruct( $name, $struct, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
 * Add a new feed type like /atom1/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
 * @param string $feedname
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 * @param callback $function Callback to run on feed display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
 * @return string Feed action name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
function add_feed($feedname, $function) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	if ( ! in_array($feedname, $wp_rewrite->feeds) ) //override the file if it is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		$wp_rewrite->feeds[] = $feedname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	$hook = 'do_feed_' . $feedname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	// Remove default function hook
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	remove_action($hook, $hook);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	add_action($hook, $function, 10, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	return $hook;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
 * Remove rewrite rules and then recreate rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * @see WP_Rewrite::flush_rules()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * @param bool $hard Whether to update .htaccess (hard flush) or just update
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 * 	rewrite_rules transient (soft flush). Default is true (hard).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
function flush_rewrite_rules( $hard = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	$wp_rewrite->flush_rules( $hard );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 * Endpoint Mask for default, which is nothing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
define('EP_NONE', 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 * Endpoint Mask for Permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
define('EP_PERMALINK', 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
 * Endpoint Mask for Attachment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
define('EP_ATTACHMENT', 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 * Endpoint Mask for date.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
define('EP_DATE', 4);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
 * Endpoint Mask for year
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
define('EP_YEAR', 8);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 * Endpoint Mask for month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
define('EP_MONTH', 16);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 * Endpoint Mask for day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
define('EP_DAY', 32);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 * Endpoint Mask for root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
define('EP_ROOT', 64);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 * Endpoint Mask for comments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
define('EP_COMMENTS', 128);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
 * Endpoint Mask for searches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
define('EP_SEARCH', 256);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 * Endpoint Mask for categories.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
define('EP_CATEGORIES', 512);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 * Endpoint Mask for tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
define('EP_TAGS', 1024);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
 * Endpoint Mask for authors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
define('EP_AUTHORS', 2048);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
 * Endpoint Mask for pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
define('EP_PAGES', 4096);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 * Endpoint Mask for all archive views.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
define( 'EP_ALL_ARCHIVES', EP_DATE | EP_YEAR | EP_MONTH | EP_DAY | EP_CATEGORIES | EP_TAGS | EP_AUTHORS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 * Endpoint Mask for everything.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
define( 'EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEARCH | EP_PAGES | EP_ALL_ARCHIVES );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 * Add an endpoint, like /trackback/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 * Adding an endpoint creates extra rewrite rules for each of the matching
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
 * places specified by the provided bitmask. For example:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 * <code>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 * add_rewrite_endpoint( 'json', EP_PERMALINK | EP_PAGES );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 * </code>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 * will add a new rewrite rule ending with "json(/(.*))?/?$" for every permastruct
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
 * that describes a permalink (post) or page. This is rewritten to "json=$match"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 * where $match is the part of the URL matched by the endpoint regex (e.g. "foo" in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 * "<permalink>/json/foo/").
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 * A new query var with the same name as the endpoint will also be created.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 * When specifying $places ensure that you are using the EP_* constants (or a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 * combination of them using the bitwise OR operator) as their values are not
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 * guaranteed to remain static (especially EP_ALL).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
 * Be sure to flush the rewrite rules - flush_rewrite_rules() - when your plugin gets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * activated and deactivated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
 * @see WP_Rewrite::add_endpoint()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
 * @global object $wp_rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
 * @param string $name Name of the endpoint.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 * @param int $places Endpoint mask describing the places the endpoint should be added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
function add_rewrite_endpoint( $name, $places ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	$wp_rewrite->add_endpoint( $name, $places );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 * Filter the URL base for taxonomies.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 * To remove any manually prepended /index.php/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 * @param string $base The taxonomy base that we're going to filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
function _wp_filter_taxonomy_base( $base ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	if ( !empty( $base ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		$base = preg_replace( '|^/index\.php/|', '', $base );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
		$base = trim( $base, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	return $base;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
 * Examine a url and try to determine the post ID it represents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 * Checks are supposedly from the hosted site blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 * @param string $url Permalink to check.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
 * @return int Post ID, or 0 on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
function url_to_postid($url) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	$url = apply_filters('url_to_postid', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	// First, check to see if there is a 'p=N' or 'page_id=N' to match against
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) )	{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
		$id = absint($values[2]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
		if ( $id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
			return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	// Check to see if we are using rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	$rewrite = $wp_rewrite->wp_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	if ( empty($rewrite) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
		return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	// Get rid of the #anchor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
	$url_split = explode('#', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	$url = $url_split[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	// Get rid of URL ?query=string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
	$url_split = explode('?', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
	$url = $url_split[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	// Add 'www.' if it is absent and should be there
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
	if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		$url = str_replace('://', '://www.', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	// Strip 'www.' if it is present and shouldn't be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
	if ( false === strpos(home_url(), '://www.') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		$url = str_replace('://www.', '://', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	// Strip 'index.php/' if we're not using path info permalinks
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	if ( !$wp_rewrite->using_index_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
		$url = str_replace( $wp_rewrite->index . '/', '', $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		// Chop off http://domain.com/[path]
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
		$url = str_replace(home_url(), '', $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		// Chop off /path/to/blog
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
		$home_path = parse_url( home_url( '/' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		$url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	// Trim leading and lagging slashes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	$url = trim($url, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
	$request = $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	$post_type_query_vars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	foreach ( get_post_types( array() , 'objects' ) as $post_type => $t ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
		if ( ! empty( $t->query_var ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
			$post_type_query_vars[ $t->query_var ] = $post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	// Look for matches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	$request_match = $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	foreach ( (array)$rewrite as $match => $query) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		// If the requesting file is the anchor of the match, prepend it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		// to the path info.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
			$request_match = $url . '/' . $request;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		if ( preg_match("!^$match!", $request_match, $matches) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
				// this is a verbose page match, lets check to be sure about it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
				if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
			// Got a match.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			// Trim the query of everything up to the '?'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			$query = preg_replace("!^.+\?!", '', $query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			// Substitute the substring matches into the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
			$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
			// Filter out non-public query vars
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
			global $wp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
			parse_str( $query, $query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			$query = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
			foreach ( (array) $query_vars as $key => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
				if ( in_array( $key, $wp->public_query_vars ) ){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
					$query[$key] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
					if ( isset( $post_type_query_vars[$key] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
						$query['post_type'] = $post_type_query_vars[$key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
						$query['name'] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			// Do the query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			$query = new WP_Query( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			if ( ! empty( $query->posts ) && $query->is_singular )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
				return $query->post->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
				return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 * WordPress Rewrite Component.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
 * The WordPress Rewrite class writes the rewrite module rules to the .htaccess
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 * file. It also handles parsing the request to get the correct setup for the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
 * WordPress Query class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
 * The Rewrite along with WP class function as a front controller for WordPress.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
 * You can add rules to trigger your page view and processing using this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 * component. The full functionality of a front controller does not exist,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
 * meaning you can't define how the template files load based on the rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 * rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
class WP_Rewrite {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	 * Permalink structure for posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	var $permalink_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	 * Whether to add trailing slashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	var $use_trailing_slashes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	 * Base for the author permalink structure (example.com/$author_base/authorname).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	var $author_base = 'author';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	 * Permalink structure for author archives.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	var $author_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	 * Permalink structure for date archives.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	var $date_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	 * Permalink structure for pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	var $page_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
	 * Base of the search permalink structure (example.com/$search_base/query).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	var $search_base = 'search';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	 * Permalink structure for searches.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
	var $search_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	 * Comments permalink base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
	var $comments_base = 'comments';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	 * Pagination permalink base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	var $pagination_base = 'page';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	 * Feed permalink base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	var $feed_base = 'feed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	 * Comments feed permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	var $comments_feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	 * Feed request permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	var $feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
	 * The static portion of the post permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	 * If the permalink structure is "/archive/%post_id%" then the front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	 * is "/archive/". If the permalink structure is "/%year%/%postname%/"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	 * then the front is "/".
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	 * @see WP_Rewrite::init()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	var $front;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	 * The prefix for all permalink structures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	 * If PATHINFO/index permalinks are in use then the root is the value of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	 * {@link WP_Rewrite::$index} with a trailing slash appended. Otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	 * the root will be empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	 * @see WP_Rewrite::init()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	 * @see WP_Rewrite::using_index_permalinks()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
	var $root = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
	 * The name of the index file which is the entry point to all requests.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	var $index = 'index.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	 * Variable name to use for regex matches in the rewritten query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	var $matches = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	 * Rewrite rules to match against the request to find the redirect or query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	var $rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
	 * Additional rules added external to the rewrite class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	 * Those not generated by the class, see add_rewrite_rule().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	var $extra_rules = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	 * Additional rules that belong at the beginning to match first.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	 * Those not generated by the class, see add_rewrite_rule().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
	var $extra_rules_top = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	 * Rules that don't redirect to WordPress' index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	 * These rules are written to the mod_rewrite portion of the .htaccess,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	 * and are added by {@link add_external_rule()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	var $non_wp_rules = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
	 * Extra permalink structures, e.g. categories, added by {@link add_permastruct()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	var $extra_permastructs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	 * Endpoints (like /trackback/) added by {@link add_rewrite_endpoint()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	var $endpoints;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	 * Whether to write every mod_rewrite rule for WordPress into the .htaccess file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	 * This is off by default, turning it on might print a lot of rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	 * to the .htaccess file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	 * @see WP_Rewrite::mod_rewrite_rules()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	var $use_verbose_rules = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	 * Could post permalinks be confused with those of pages?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	 * If the first rewrite tag in the post permalink structure is one that could
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
	 * also match a page name (e.g. %postname% or %author%) then this flag is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	 * set to true. Prior to WordPress 3.3 this flag indicated that every page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	 * would have a set of rules added to the top of the rewrite rules array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	 * Now it tells {@link WP::parse_request()} to check if a URL matching the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	 * page permastruct is actually a page before accepting it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	 * @link http://core.trac.wordpress.org/ticket/16687
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	 * @see WP_Rewrite::init()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
	var $use_verbose_page_rules = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
	 * Rewrite tags that can be used in permalink structures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
	 * These are translated into the regular expressions stored in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
	 * {@link WP_Rewrite::$rewritereplace} and are rewritten to the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	 * query variables listed in {@link WP_Rewrite::$queryreplace}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
	 * Additional tags can be added with {@link add_rewrite_tag()}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
	var $rewritecode = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
		'%year%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		'%monthnum%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
		'%day%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		'%hour%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		'%minute%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		'%second%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		'%postname%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
		'%post_id%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
		'%author%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
		'%pagename%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
		'%search%'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
	 * Regular expressions to be substituted into rewrite rules in place
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
	 * of rewrite tags, see {@link WP_Rewrite::$rewritecode}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	var $rewritereplace = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
		'([0-9]{4})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		'([0-9]{1,2})',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		'([^/]+)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		'([0-9]+)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		'([^/]+)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
		'([^/]+?)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		'(.+)'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	 * Query variables that rewrite tags map to, see {@link WP_Rewrite::$rewritecode}.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
	var $queryreplace = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
		'year=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
		'monthnum=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
		'day=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
		'hour=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
		'minute=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
		'second=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
		'name=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
		'p=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
		'author_name=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
		'pagename=',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
		's='
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
	 * Supported default feeds.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
	var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	 * Whether permalinks are being used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
	 * This can be either rewrite module or permalink in the HTTP query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
	 * @return bool True, if permalinks are enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
	function using_permalinks() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
		return ! empty($this->permalink_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	 * Whether permalinks are being used and rewrite module is not enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
	 * Means that permalink links are enabled and index.php is in the URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	function using_index_permalinks() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
		if ( empty($this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
		// If the index is not in the permalink, we're using mod_rewrite.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		if ( preg_match('#^/*' . $this->index . '#', $this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
	 * Whether permalinks are being used and rewrite module is enabled.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
	 * Using permalinks and index.php is not in the URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
	function using_mod_rewrite_permalinks() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
		if ( $this->using_permalinks() && ! $this->using_index_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
	 * Index for matches for usage in preg_*() functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
	 * The format of the string is, with empty matches property value, '$NUM'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
	 * The 'NUM' will be replaced with the value in the $number parameter. With
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
	 * the matches property not empty, the value of the returned string will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
	 * contain that value of the matches property. The format then will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
	 * '$MATCHES[NUM]', with MATCHES as the value in the property and NUM the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
	 * value of the $number parameter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	 * @param int $number Index number.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	function preg_index($number) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
		$match_prefix = '$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
		$match_suffix = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
		if ( ! empty($this->matches) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
			$match_prefix = '$' . $this->matches . '[';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
			$match_suffix = ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
		return "$match_prefix$number$match_suffix";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
	 * Retrieve all page and attachments for pages URIs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
	 * The attachments are for those that have pages as parents and will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
	 * retrieved.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
	 * @return array Array of page URIs as first element and attachment URIs as second element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
	function page_uri_index() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
		global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
		//get pages in order of hierarchy, i.e. children after parents
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
		$pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
		$posts = get_page_hierarchy( $pages );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
		// If we have no pages get out quick
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
		if ( !$posts )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
			return array( array(), array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
		//now reverse it, because we need parents after children for rewrite rules to work properly
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
		$posts = array_reverse($posts, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
		$page_uris = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
		$page_attachment_uris = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
		foreach ( $posts as $id => $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
			// URL => page name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
			$uri = get_page_uri($id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
			$attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
			if ( !empty($attachments) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
				foreach ( $attachments as $attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
					$attach_uri = get_page_uri($attachment->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
					$page_attachment_uris[$attach_uri] = $attachment->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
			$page_uris[$uri] = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
		return array( $page_uris, $page_attachment_uris );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
	 * Retrieve all of the rewrite rules for pages.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
	 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
	function page_rewrite_rules() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
		// the extra .? at the beginning prevents clashes with other regular expressions in the rules array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		$this->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
		return $this->generate_rewrite_rules( $this->get_page_permastruct(), EP_PAGES, true, true, false, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
	 * Retrieve date permalink structure, with year, month, and day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
	 * The permalink structure for the date, if not set already depends on the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	 * permalink structure. It can be one of three formats. The first is year,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
	 * month, day; the second is day, month, year; and the last format is month,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
	 * day, year. These are matched against the permalink structure for which
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	 * one is used. If none matches, then the default will be used, which is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	 * year, month, day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	 * Prevents post ID and date permalinks from overlapping. In the case of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	 * post_id, the date permalink will be prepended with front permalink with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
	 * 'date/' before the actual permalink to form the complete date permalink
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
	 * structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	 * @return bool|string False on no permalink structure. Date permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	function get_date_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
		if ( isset($this->date_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
			return $this->date_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
			$this->date_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
		// The date permalink must have year, month, and day separated by slashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
		$endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
		$this->date_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
		$date_endian = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
		foreach ( $endians as $endian ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
			if ( false !== strpos($this->permalink_structure, $endian) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
				$date_endian= $endian;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
		if ( empty($date_endian) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
			$date_endian = '%year%/%monthnum%/%day%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
		// Do not allow the date tags and %post_id% to overlap in the permalink
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		// structure. If they do, move the date tags to $front/date/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
		$front = $this->front;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
		preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
		$tok_index = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
		foreach ( (array) $tokens[0] as $token) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
			if ( '%post_id%' == $token && ($tok_index <= 3) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
				$front = $front . 'date/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
			$tok_index++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
		$this->date_structure = $front . $date_endian;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
		return $this->date_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
	 * Retrieve the year permalink structure without month and day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
	 * Gets the date permalink structure and strips out the month and day
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	 * permalink structures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
	 * @return bool|string False on failure. Year structure on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
	function get_year_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
		$structure = $this->get_date_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
		if ( empty($structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
		$structure = str_replace('%monthnum%', '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		$structure = str_replace('%day%', '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
		$structure = preg_replace('#/+#', '/', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
		return $structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
	 * Retrieve the month permalink structure without day and with year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
	 * Gets the date permalink structure and strips out the day permalink
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
	 * structures. Keeps the year permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
	 * @return bool|string False on failure. Year/Month structure on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
	function get_month_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
		$structure = $this->get_date_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
		if ( empty($structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		$structure = str_replace('%day%', '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
		$structure = preg_replace('#/+#', '/', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
		return $structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
	 * Retrieve the day permalink structure with month and year.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
	 * Keeps date permalink structure with all year, month, and day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
	 * @return bool|string False on failure. Year/Month/Day structure on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
	function get_day_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
		return $this->get_date_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
	 * Retrieve the permalink structure for categories.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
	 * If the category_base property has no value, then the category structure
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
	 * will have the front property value, followed by 'category', and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
	 * '%category%'. If it does, then the root property will be used, along with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
	 * the category_base property value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
	 * @return bool|string False on failure. Category permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
	function get_category_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
		return $this->get_extra_permastruct('category');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
	 * Retrieve the permalink structure for tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
	 * If the tag_base property has no value, then the tag structure will have
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
	 * the front property value, followed by 'tag', and finally '%tag%'. If it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
	 * does, then the root property will be used, along with the tag_base
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
	 * property value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
	 * @return bool|string False on failure. Tag permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
	function get_tag_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		return $this->get_extra_permastruct('post_tag');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
	 * Retrieve extra permalink structure by name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
	 * @param string $name Permalink structure name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
	function get_extra_permastruct($name) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
		if ( empty($this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
		if ( isset($this->extra_permastructs[$name]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
			return $this->extra_permastructs[$name]['struct'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
	 * Retrieve the author permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
	 * The permalink structure is front property, author base, and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
	 * '/%author%'. Will set the author_structure property and then return it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
	 * without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
	function get_author_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
		if ( isset($this->author_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
			return $this->author_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
			$this->author_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
		$this->author_structure = $this->front . $this->author_base . '/%author%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
		return $this->author_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
	 * Retrieve the search permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
	 * The permalink structure is root property, search base, and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
	 * '/%search%'. Will set the search_structure property and then return it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
	 * without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
	function get_search_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
		if ( isset($this->search_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
			return $this->search_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
			$this->search_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
		$this->search_structure = $this->root . $this->search_base . '/%search%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
		return $this->search_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
	 * Retrieve the page permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
	 * The permalink structure is root property, and '%pagename%'. Will set the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
	 * page_structure property and then return it without attempting to set the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
	 * value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
	function get_page_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
		if ( isset($this->page_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
			return $this->page_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
		if (empty($this->permalink_structure)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
			$this->page_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
		$this->page_structure = $this->root . '%pagename%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
		return $this->page_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
	 * Retrieve the feed permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
	 * The permalink structure is root property, feed base, and finally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
	 * '/%feed%'. Will set the feed_structure property and then return it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
	 * without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
	function get_feed_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
		if ( isset($this->feed_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
			return $this->feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
		if ( empty($this->permalink_structure) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
			$this->feed_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
		$this->feed_structure = $this->root . $this->feed_base . '/%feed%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
		return $this->feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
	 * Retrieve the comment feed permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
	 * The permalink structure is root property, comment base property, feed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
	 * base and finally '/%feed%'. Will set the comment_feed_structure property
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
	 * and then return it without attempting to set the value again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
	 * @return string|bool False if not found. Permalink structure string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
	function get_comment_feed_permastruct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
		if ( isset($this->comment_feed_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
			return $this->comment_feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
		if (empty($this->permalink_structure)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
			$this->comment_feed_structure = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
		$this->comment_feed_structure = $this->root . $this->comments_base . '/' . $this->feed_base . '/%feed%';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
		return $this->comment_feed_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
	 * Add or update existing rewrite tags (e.g. %postname%).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
	 * If the tag already exists, replace the existing pattern and query for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
	 * that tag, otherwise add the new tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
	 * @see WP_Rewrite::$rewritecode
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
	 * @see WP_Rewrite::$rewritereplace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	 * @see WP_Rewrite::$queryreplace
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
	 * @param string $tag Name of the rewrite tag to add or update.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
	 * @param string $regex Regular expression to substitute the tag for in rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
	 * @param string $query String to append to the rewritten query. Must end in '='.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
	function add_rewrite_tag( $tag, $regex, $query ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
		$position = array_search( $tag, $this->rewritecode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
		if ( false !== $position && null !== $position ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
			$this->rewritereplace[ $position ] = $regex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
			$this->queryreplace[ $position ] = $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
			$this->rewritecode[] = $tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
			$this->rewritereplace[] = $regex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
			$this->queryreplace[] = $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
	 * Generate rewrite rules from a permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
	 * The main WP_Rewrite function for building the rewrite rule list. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
	 * contents of the function is a mix of black magic and regular expressions,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
	 * so best just ignore the contents and move to the parameters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
	 * @param string $permalink_structure The permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
	 * @param int $ep_mask Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
	 * @param bool $paged Should archive pagination rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
	 * @param bool $feed Should feed rewrite rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
	 * @param bool $forcomments Should the feed rules be a query for a comments feed? Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
	 * @param bool $walk_dirs Should the 'directories' making up the structure be walked over and rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
	 *                        built for each in turn? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
	 * @param bool $endpoints Should endpoints be applied to the generated rewrite rules? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
	 * @return array Rewrite rule list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
	function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
		//build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
		$feedregex2 = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
		foreach ( (array) $this->feeds as $feed_name)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
			$feedregex2 .= $feed_name . '|';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
		$feedregex2 = '(' . trim($feedregex2, '|') . ')/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
		//$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
		//and <permalink>/atom are both possible
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
		$feedregex = $this->feed_base . '/' . $feedregex2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
		//build a regex to match the trackback and page/xx parts of URLs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
		$trackbackregex = 'trackback/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
		$pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
		$commentregex = 'comment-page-([0-9]{1,})/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
		//build up an array of endpoint regexes to append => queries to append
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
		if ( $endpoints ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
			$ep_query_append = array ();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
			foreach ( (array) $this->endpoints as $endpoint) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
				//match everything after the endpoint name, but allow for nothing to appear there
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
				$epmatch = $endpoint[1] . '(/(.*))?/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
				//this will be appended on to the rest of the query for each dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
				$epquery = '&' . $endpoint[1] . '=';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
				$ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
		//get everything up to the first rewrite tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
		$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
		//build an array of the tags (note that said array ends up being in $tokens[0])
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
		preg_match_all('/%.+?%/', $permalink_structure, $tokens);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
		$num_tokens = count($tokens[0]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
		$index = $this->index; //probably 'index.php'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
		$feedindex = $index;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
		$trackbackindex = $index;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
		//build a list from the rewritecode and queryreplace arrays, that will look something like
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
		//tagname=$matches[i] where i is the current $i
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
		for ( $i = 0; $i < $num_tokens; ++$i ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
			if ( 0 < $i )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
				$queries[$i] = $queries[$i - 1] . '&';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
				$queries[$i] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
			$query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
			$queries[$i] .= $query_token;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
		//get the structure, minus any cruft (stuff that isn't tags) at the front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
		$structure = $permalink_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
		if ( $front != '/' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
			$structure = str_replace($front, '', $structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
		//create a list of dirs to walk over, making rewrite rules for each level
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
		//so for example, a $structure of /%year%/%monthnum%/%postname% would create
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
		//rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname%
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
		$structure = trim($structure, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
		$dirs = $walk_dirs ? explode('/', $structure) : array( $structure );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
		$num_dirs = count($dirs);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
		//strip slashes from the front of $front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
		$front = preg_replace('|^/+|', '', $front);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
		//the main workhorse loop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
		$post_rewrite = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
		$struct = $front;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
		for ( $j = 0; $j < $num_dirs; ++$j ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
			//get the struct for this dir, and trim slashes off the front
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
			$struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
			$struct = ltrim($struct, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
			//replace tags with regexes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
			$match = str_replace($this->rewritecode, $this->rewritereplace, $struct);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
			//make a list of tags, and store how many there are in $num_toks
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
			$num_toks = preg_match_all('/%.+?%/', $struct, $toks);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
			//get the 'tagname=$matches[i]'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
			$query = ( isset($queries) && is_array($queries) && !empty($num_toks) ) ? $queries[$num_toks - 1] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
			//set up $ep_mask_specific which is used to match more specific URL types
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
			switch ( $dirs[$j] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
				case '%year%':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
					$ep_mask_specific = EP_YEAR;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
				case '%monthnum%':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
					$ep_mask_specific = EP_MONTH;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
				case '%day%':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
					$ep_mask_specific = EP_DAY;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
				default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
					$ep_mask_specific = EP_NONE;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
			//create query for /page/xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
			$pagematch = $match . $pageregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
			$pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
			//create query for /comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
			$commentmatch = $match . $commentregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
			$commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
			if ( get_option('page_on_front') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
				//create query for Root /comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
				$rootcommentmatch = $match . $commentregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
				$rootcommentquery = $index . '?' . $query . '&page_id=' . get_option('page_on_front') . '&cpage=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
			//create query for /feed/(feed|atom|rss|rss2|rdf)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
			$feedmatch = $match . $feedregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
			$feedquery = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
			//create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
			$feedmatch2 = $match . $feedregex2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
			$feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
			//if asked to, turn the feed queries into comment feed ones
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
			if ( $forcomments ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
				$feedquery .= '&withcomments=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
				$feedquery2 .= '&withcomments=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
			//start creating the array of rewrites for this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
			$rewrite = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
			if ( $feed ) //...adding on /feed/ regexes => queries
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
				$rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
			if ( $paged ) //...and /page/xx ones
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
				$rewrite = array_merge($rewrite, array($pagematch => $pagequery));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
			//only on pages with comments add ../comment-page-xx/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
			if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
				$rewrite = array_merge($rewrite, array($commentmatch => $commentquery));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
			else if ( EP_ROOT & $ep_mask && get_option('page_on_front') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
				$rewrite = array_merge($rewrite, array($rootcommentmatch => $rootcommentquery));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
			//do endpoints
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
			if ( $endpoints ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
				foreach ( (array) $ep_query_append as $regex => $ep) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
					//add the endpoints on if the mask fits
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
					if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
						$rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
			//if we've got some tags in this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
			if ( $num_toks ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
				$post = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
				$page = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
				//check to see if this dir is permalink-level: i.e. the structure specifies an
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
				//individual post. Do this by checking it contains at least one of 1) post name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
				//2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
				//minute all present). Set these flags now as we need them for the endpoints.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
				if ( strpos($struct, '%postname%') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
						|| strpos($struct, '%post_id%') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
						|| strpos($struct, '%pagename%') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
						|| (strpos($struct, '%year%') !== false && strpos($struct, '%monthnum%') !== false && strpos($struct, '%day%') !== false && strpos($struct, '%hour%') !== false && strpos($struct, '%minute%') !== false && strpos($struct, '%second%') !== false)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
						) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
					$post = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
					if ( strpos($struct, '%pagename%') !== false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
						$page = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
				if ( ! $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
					// For custom post types, we need to add on endpoints as well.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
					foreach ( get_post_types( array('_builtin' => false ) ) as $ptype ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
						if ( strpos($struct, "%$ptype%") !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
							$post = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
							$page = is_post_type_hierarchical( $ptype ); // This is for page style attachment url's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
							break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
				//if we're creating rules for a permalink, do all the endpoints like attachments etc
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
				if ( $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
					//create query and regex for trackback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
					$trackbackmatch = $match . $trackbackregex;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
					$trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
					//trim slashes from the end of the regex for this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
					$match = rtrim($match, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
					//get rid of brackets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
					$submatchbase = str_replace( array('(', ')'), '', $match);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
					//add a rule for at attachments, which take the form of <permalink>/some-text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
					$sub1 = $submatchbase . '/([^/]+)/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
					$sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
					$sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
					$sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
					$sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
					//add another rule to match attachments in the explicit form:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
					//<permalink>/attachment/some-text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
					$sub2 = $submatchbase . '/attachment/([^/]+)/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
					$sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
					$sub2feed = $sub2 . $feedregex;    //feeds, <permalink>/attachment/feed/(atom|...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
					$sub2feed2 = $sub2 . $feedregex2;  //and feeds again on to this <permalink>/attachment/(feed|atom...)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
					$sub2comment = $sub2 . $commentregex; //and <permalink>/comment-page-xx
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
					//create queries for these extra tag-ons we've just dealt with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
					$subquery = $index . '?attachment=' . $this->preg_index(1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
					$subtbquery = $subquery . '&tb=1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
					$subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
					$subcommentquery = $subquery . '&cpage=' . $this->preg_index(2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
					//do endpoints for attachments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
					if ( !empty($endpoints) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
						foreach ( (array) $ep_query_append as $regex => $ep ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
							if ( $ep[0] & EP_ATTACHMENT ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
								$rewrite[$sub1 . $regex] = $subquery . $ep[1] . $this->preg_index(3);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
								$rewrite[$sub2 . $regex] = $subquery . $ep[1] . $this->preg_index(3);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
					//now we've finished with endpoints, finish off the $sub1 and $sub2 matches
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
					//add a ? as we don't have to match that last slash, and finally a $ so we
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
					//match to the end of the URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
					$sub1 .= '?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
					$sub2 .= '?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
					//post pagination, e.g. <permalink>/2/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
					$match = $match . '(/[0-9]+)?/?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
					$query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
				} else { //not matching a permalink so this is a lot simpler
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
					//close the match and finalise the query
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
					$match .= '?$';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
					$query = $index . '?' . $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
				//create the final array for this dir by joining the $rewrite array (which currently
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
				//only contains rules/queries for trackback, pages etc) to the main regex/query for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
				//this dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
				$rewrite = array_merge($rewrite, array($match => $query));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
				//if we're matching a permalink, add those extras (attachments etc) on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
				if ( $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
					//add trackback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
					$rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
					//add regexes/queries for attachments, attachment trackbacks and so on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
					if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
						$rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery, $sub1comment => $subcommentquery));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
					$rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery), $rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
			} //if($num_toks)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
			//add the rules for this dir to the accumulating $post_rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
			$post_rewrite = array_merge($rewrite, $post_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
		} //foreach ($dir)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
		return $post_rewrite; //the finished rules. phew!
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1501
	 * Generate Rewrite rules with permalink structure and walking directory only.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
	 * Shorten version of {@link WP_Rewrite::generate_rewrite_rules()} that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
	 * allows for shorter list of parameters. See the method for longer
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
	 * description of what generating rewrite rules does.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
	 * @uses WP_Rewrite::generate_rewrite_rules() See for long description and rest of parameters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
	 * @param string $permalink_structure The permalink structure to generate rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
	 * @param bool $walk_dirs Optional, default is false. Whether to create list of directories to walk over.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
	 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
	function generate_rewrite_rule($permalink_structure, $walk_dirs = false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
		return $this->generate_rewrite_rules($permalink_structure, EP_NONE, false, false, false, $walk_dirs);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
	 * Construct rewrite matches and queries from permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
	 * Runs the action 'generate_rewrite_rules' with the parameter that is an
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
	 * reference to the current WP_Rewrite instance to further manipulate the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
	 * permalink structures and rewrite rules. Runs the 'rewrite_rules_array'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
	 * filter on the full rewrite rule array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
	 * There are two ways to manipulate the rewrite rules, one by hooking into
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	 * the 'generate_rewrite_rules' action and gaining full control of the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
	 * object or just manipulating the rewrite rule array before it is passed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
	 * from the function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
	 * @return array An associate array of matches and queries.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
	function rewrite_rules() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
		$rewrite = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
		if ( empty($this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
			return $rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
		// robots.txt -only if installed at the root
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
		$home_path = parse_url( home_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
		$robots_rewrite = ( empty( $home_path['path'] ) || '/' == $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
		// Old feed and service files
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
		$deprecated_files = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
			'.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
			'.*wp-app\.php(/.*)?$' => $this->index . '?error=403',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
		// Registration rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
		$registration_pages = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
		if ( is_multisite() && is_main_site() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
			$registration_pages['.*wp-signup.php$'] = $this->index . '?signup=true';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
			$registration_pages['.*wp-activate.php$'] = $this->index . '?activate=true';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
		$registration_pages['.*wp-register.php$'] = $this->index . '?register=true'; // Deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
		// Post
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
		$post_rewrite = $this->generate_rewrite_rules( $this->permalink_structure, EP_PERMALINK );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
		$post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
		// Date
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
		$date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
		$date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
		// Root
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
		$root_rewrite = $this->generate_rewrite_rules($this->root . '/', EP_ROOT);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
		$root_rewrite = apply_filters('root_rewrite_rules', $root_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
		// Comments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
		$comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, EP_COMMENTS, false, true, true, false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
		$comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
		// Search
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
		$search_structure = $this->get_search_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
		$search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
		$search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
		// Authors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
		$author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
		$author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
		// Pages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
		$page_rewrite = $this->page_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
		$page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
		// Extra permastructs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
		foreach ( $this->extra_permastructs as $permastructname => $struct ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
			if ( is_array( $struct ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
				if ( count( $struct ) == 2 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
					$rules = $this->generate_rewrite_rules( $struct[0], $struct[1] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
					$rules = $this->generate_rewrite_rules( $struct['struct'], $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
				$rules = $this->generate_rewrite_rules( $struct );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
			$rules = apply_filters($permastructname . '_rewrite_rules', $rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
			if ( 'post_tag' == $permastructname )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
				$rules = apply_filters('tag_rewrite_rules', $rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
			$this->extra_rules_top = array_merge($this->extra_rules_top, $rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
		// Put them together.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
		if ( $this->use_verbose_page_rules )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
			$this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
		do_action_ref_array('generate_rewrite_rules', array(&$this));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
		$this->rules = apply_filters('rewrite_rules_array', $this->rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
		return $this->rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
	 * Retrieve the rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
	 * The difference between this method and {@link
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
	 * WP_Rewrite::rewrite_rules()} is that this method stores the rewrite rules
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
	 * in the 'rewrite_rules' option and retrieves it. This prevents having to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
	 * process all of the permalinks to get the rewrite rules in the form of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
	 * caching.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
	 * @return array Rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
	function wp_rewrite_rules() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
		$this->rules = get_option('rewrite_rules');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
		if ( empty($this->rules) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
			$this->matches = 'matches';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
			$this->rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
			update_option('rewrite_rules', $this->rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
		return $this->rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
	 * Retrieve mod_rewrite formatted rewrite rules to write to .htaccess.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
	 * Does not actually write to the .htaccess file, but creates the rules for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
	 * the process that will.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
	 * Will add the non_wp_rules property rules to the .htaccess file before
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
	 * the WordPress rewrite rules one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1654
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
	function mod_rewrite_rules() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
		if ( ! $this->using_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
		$site_root = parse_url( site_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
		if ( isset( $site_root['path'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
			$site_root = trailingslashit($site_root['path']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
		$home_root = parse_url(home_url());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
		if ( isset( $home_root['path'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1669
			$home_root = trailingslashit($home_root['path']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
			$home_root = '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
		$rules = "<IfModule mod_rewrite.c>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
		$rules .= "RewriteEngine On\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
		$rules .= "RewriteBase $home_root\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
		$rules .= "RewriteRule ^index\.php$ - [L]\n"; // Prevent -f checks on index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
		//add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
		foreach ( (array) $this->non_wp_rules as $match => $query) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
			// Apache 1.3 does not support the reluctant (non-greedy) modifier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
			$match = str_replace('.+?', '.+', $match);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
			// If the match is unanchored and greedy, prepend rewrite conditions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
			// to avoid infinite redirects and eclipsing of real files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
			//if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
				//nada.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
			//}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
			$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
		if ( $this->use_verbose_rules ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
			$this->matches = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
			$rewrite = $this->rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
			$num_rules = count($rewrite);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
			$rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
				"RewriteCond %{REQUEST_FILENAME} -d\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
				"RewriteRule ^.*$ - [S=$num_rules]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
			foreach ( (array) $rewrite as $match => $query) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
				// Apache 1.3 does not support the reluctant (non-greedy) modifier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
				$match = str_replace('.+?', '.+', $match);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
				// If the match is unanchored and greedy, prepend rewrite conditions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
				// to avoid infinite redirects and eclipsing of real files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
				//if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
					//nada.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
				//}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
				if ( strpos($query, $this->index) !== false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
					$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
					$rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
			$rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
				"RewriteCond %{REQUEST_FILENAME} !-d\n" .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
				"RewriteRule . {$home_root}{$this->index} [L]\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
		$rules .= "</IfModule>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
		$rules = apply_filters('mod_rewrite_rules', $rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
		$rules = apply_filters('rewrite_rules', $rules);  // Deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1725
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
		return $rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
	 * Retrieve IIS7 URL Rewrite formatted rewrite rules to write to web.config file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
	 * Does not actually write to the web.config file, but creates the rules for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
	 * the process that will.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
	function iis7_url_rewrite_rules( $add_parent_tags = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
		if ( ! $this->using_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
		$rules = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
		if ( $add_parent_tags ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
			$rules .= '<configuration>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
	<system.webServer>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
		<rewrite>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
			<rules>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
		$rules .= '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
			<rule name="wordpress" patternSyntax="Wildcard">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
				<match url="*" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
					<conditions>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
						<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
					</conditions>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
				<action type="Rewrite" url="index.php" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
			</rule>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
		if ( $add_parent_tags ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
			$rules .= '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
			</rules>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
		</rewrite>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
	</system.webServer>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
</configuration>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
		$rules = apply_filters('iis7_url_rewrite_rules', $rules);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
		return $rules;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
	 * Add a straight rewrite rule.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
	 * Any value in the $after parameter that isn't 'bottom' will be placed at
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
	 * the top of the rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
	 * @param string $regex Regular expression to match against request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
	 * @param string $redirect URL regex redirects to when regex matches request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
	 * @param string $after Optional, default is bottom. Location to place rule.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
	function add_rule($regex, $redirect, $after = 'bottom') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
		//get everything up to the first ?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
		$index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
		$front = substr($redirect, 0, $index);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
		if ( $front != $this->index ) { //it doesn't redirect to WP's index.php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
			$this->add_external_rule($regex, $redirect);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
			if ( 'bottom' == $after)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
				$this->extra_rules = array_merge($this->extra_rules, array($regex => $redirect));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
				$this->extra_rules_top = array_merge($this->extra_rules_top, array($regex => $redirect));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
			//$this->extra_rules[$regex] = $redirect;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
	 * Add a rule that doesn't redirect to index.php.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
	 * Can redirect to any place.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
	 * @param string $regex Regular expression to match against request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
	 * @param string $redirect URL regex redirects to when regex matches request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
	function add_external_rule($regex, $redirect) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
		$this->non_wp_rules[$regex] = $redirect;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
	 * Add an endpoint, like /trackback/.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
	 * See {@link add_rewrite_endpoint()} for full documentation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
	 * @see add_rewrite_endpoint()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
	 * @uses WP::add_query_var()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
	 * @param string $name Name of the endpoint.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
	 * @param int $places Endpoint mask describing the places the endpoint should be added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
	function add_endpoint($name, $places) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
		global $wp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
		$this->endpoints[] = array ( $places, $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1834
		$wp->add_query_var($name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
	 * Add a new permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1840
	 * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules; it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
	 * is an easy way of expressing a set of regular expressions that rewrite to a set of query strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
	 * The new permastruct is added to the {@link WP_Rewrite::$extra_permastructs} array. When the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
	 * rewrite rules are built by {@link WP_Rewrite::rewrite_rules()} all of these extra permastructs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1844
	 * are passed to {@link WP_Rewrite::generate_rewrite_rules()} which transforms them into the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
	 * regular expressions that many love to hate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
	 * The $args parameter gives you control over how {@link WP_Rewrite::generate_rewrite_rules()}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
	 * works on the new permastruct.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
	 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
	 * @param string $name Name for permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
	 * @param string $struct Permalink structure (e.g. category/%category%)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
	 * @param array $args Optional configuration for building the rules from the permalink structure:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1856
	 *     - with_front (bool) - Should the structure be prepended with WP_Rewrite::$front? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
	 *     - ep_mask (int) - Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
	 *     - paged (bool) - Should archive pagination rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
	 *     - feed (bool) - Should feed rewrite rules be added for the structure? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
	 *     - forcomments (bool) - Should the feed rules be a query for a comments feed? Default is false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
	 *     - walk_dirs (bool) - Should the 'directories' making up the structure be walked over and rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
	 *                          rules built for each in turn? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
	 *     - endpoints (bool) - Should endpoints be applied to the generated rewrite rules? Default is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
	function add_permastruct( $name, $struct, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
		// backwards compatibility for the old parameters: $with_front and $ep_mask
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
		if ( ! is_array( $args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
			$args = array( 'with_front' => $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1869
		if ( func_num_args() == 4 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
			$args['ep_mask'] = func_get_arg( 3 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
		$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
			'with_front' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
			'ep_mask' => EP_NONE,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
			'paged' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
			'feed' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
			'forcomments' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
			'walk_dirs' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
			'endpoints' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
		$args = array_intersect_key( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
		$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
		if ( $args['with_front'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
			$struct = $this->front . $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
			$struct = $this->root . $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
		$args['struct'] = $struct;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
		$this->extra_permastructs[ $name ] = $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
	 * Remove rewrite rules and then recreate rewrite rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
	 * Calls {@link WP_Rewrite::wp_rewrite_rules()} after removing the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
	 * 'rewrite_rules' option. If the function named 'save_mod_rewrite_rules'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
	 * exists, it will be called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
	 * @since 2.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1902
	 * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
	function flush_rules($hard = true) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
		delete_option('rewrite_rules');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
		$this->wp_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
		 * Filter whether a "hard" rewrite rule flush should be performed when requested.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
		 * A "hard" flush updates .htaccess (Apache) or web.config (IIS).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
		 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
		 * @param bool $hard Defaults to true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
		if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
		if ( function_exists( 'save_mod_rewrite_rules' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
			save_mod_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
		if ( function_exists( 'iis7_save_url_rewrite_rules' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
			iis7_save_url_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
	 * Sets up the object's properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
	 * The 'use_verbose_page_rules' object property will be set to true if the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1927
	 * permalink structure begins with one of the following: '%postname%', '%category%',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
	 * '%tag%', or '%author%'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
	function init() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
		$this->extra_rules = $this->non_wp_rules = $this->endpoints = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
		$this->permalink_structure = get_option('permalink_structure');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
		$this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
		$this->root = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
		if ( $this->using_index_permalinks() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
			$this->root = $this->index . '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
		unset($this->author_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
		unset($this->date_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
		unset($this->page_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
		unset($this->search_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
		unset($this->feed_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
		unset($this->comment_feed_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
		$this->use_trailing_slashes = ( '/' == substr($this->permalink_structure, -1, 1) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
		// Enable generic rules for pages if permalink structure doesn't begin with a wildcard.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
		if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
			 $this->use_verbose_page_rules = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
			$this->use_verbose_page_rules = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
	 * Set the main permalink structure for the blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
	 * Will update the 'permalink_structure' option, if there is a difference
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
	 * between the current permalink structure and the parameter value. Calls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
	 * {@link WP_Rewrite::init()} after the option is updated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
	 * Fires the 'permalink_structure_changed' action once the init call has
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
	 * processed passing the old and new values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1967
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
	 * @param string $permalink_structure Permalink structure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
	function set_permalink_structure($permalink_structure) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
		if ( $permalink_structure != $this->permalink_structure ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
			$old_permalink_structure = $this->permalink_structure;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
			update_option('permalink_structure', $permalink_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
			$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
			do_action('permalink_structure_changed', $old_permalink_structure, $permalink_structure);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
	 * Set the category base for the category permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
	 * Will update the 'category_base' option, if there is a difference between
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
	 * the current category base and the parameter value. Calls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
	 * {@link WP_Rewrite::init()} after the option is updated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
	 * @param string $category_base Category permalink structure base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
	function set_category_base($category_base) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
		if ( $category_base != get_option('category_base') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
			update_option('category_base', $category_base);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
			$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
	 * Set the tag base for the tag permalink.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
	 * Will update the 'tag_base' option, if there is a difference between the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
	 * current tag base and the parameter value. Calls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2003
	 * {@link WP_Rewrite::init()} after the option is updated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
	 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
	 * @param string $tag_base Tag permalink structure base.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
	function set_tag_base( $tag_base ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
		if ( $tag_base != get_option( 'tag_base') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
			update_option( 'tag_base', $tag_base );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
			$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
	 * Constructor - Calls init(), which runs setup.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
	 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
	 * @access public
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
	 * @return WP_Rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
	function __construct() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
		$this->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
}