2003-10-26 06:25:26 +01:00
< ? php
$title = 'Permalink Options' ;
2003-12-11 01:22:36 +01:00
$this_file = 'options.php' ;
2003-10-26 06:25:26 +01:00
function add_magic_quotes ( $array ) {
foreach ( $array as $k => $v ) {
if ( is_array ( $v )) {
$array [ $k ] = add_magic_quotes ( $v );
} else {
$array [ $k ] = addslashes ( $v );
}
}
return $array ;
}
if ( ! get_magic_quotes_gpc ()) {
$HTTP_GET_VARS = add_magic_quotes ( $HTTP_GET_VARS );
$HTTP_POST_VARS = add_magic_quotes ( $HTTP_POST_VARS );
$HTTP_COOKIE_VARS = add_magic_quotes ( $HTTP_COOKIE_VARS );
}
2003-12-18 10:36:13 +01:00
$wpvarstoreset = array ( 'action' , 'standalone' , 'option_group_id' );
for ( $i = 0 ; $i < count ( $wpvarstoreset ); $i += 1 ) {
$wpvar = $wpvarstoreset [ $i ];
if ( ! isset ( $$wpvar )) {
if ( empty ( $HTTP_POST_VARS [ " $wpvar " ])) {
if ( empty ( $HTTP_GET_VARS [ " $wpvar " ])) {
$$wpvar = '' ;
2003-10-26 06:25:26 +01:00
} else {
2003-12-18 10:36:13 +01:00
$$wpvar = $HTTP_GET_VARS [ " $wpvar " ];
2003-10-26 06:25:26 +01:00
}
} else {
2003-12-18 10:36:13 +01:00
$$wpvar = $HTTP_POST_VARS [ " $wpvar " ];
2003-10-26 06:25:26 +01:00
}
}
}
require_once ( 'optionhandler.php' );
2003-10-30 15:56:29 +01:00
if ( $HTTP_POST_VARS [ 'Submit' ] == 'Update' ) {
2003-10-26 06:25:26 +01:00
update_option ( 'permalink_structure' , $HTTP_POST_VARS [ 'permalink_structure' ]);
$permalink_structure = $HTTP_POST_VARS [ 'permalink_structure' ];
} else {
$permalink_structure = get_settings ( 'permalink_structure' );
}
switch ( $action ) {
default :
$standalone = 0 ;
2003-12-11 01:22:36 +01:00
include_once ( 'admin-header.php' );
2003-10-26 06:25:26 +01:00
if ( $user_level <= 3 ) {
2004-03-01 20:55:45 +01:00
die ( " You have do not have sufficient permissions to edit the options for this blog. " );
2003-10-26 06:25:26 +01:00
}
?>
< ul id = " adminmenu2 " >
< ? php
//we need to iterate through the available option groups.
$option_groups = $wpdb -> get_results ( " SELECT group_id, group_name, group_desc, group_longdesc FROM $tableoptiongroups ORDER BY group_id " );
foreach ( $option_groups as $option_group ) {
if ( $option_group -> group_id == $option_group_id ) {
$current_desc = $option_group -> group_desc ;
$current_long_desc = $option_group -> group_longdesc ;
echo ( " <li><a id= \" current2 \" href= \" $this_file ?option_group_id= { $option_group -> group_id } \" title= \" { $option_group -> group_desc } \" > { $option_group -> group_name } </a></li> \n " );
} else {
echo ( " <li><a href= \" $this_file ?option_group_id= { $option_group -> group_id } \" title= \" { $option_group -> group_desc } \" > { $option_group -> group_name } </a></li> \n " );
}
} // end for each group
?>
2003-12-11 01:22:36 +01:00
< li class = " last " >< a href = " options-permalink.php " > Permalinks </ a ></ li >
2003-10-26 06:25:26 +01:00
</ ul >
< br clear = " all " />
< div class = " wrap " >
< h2 > Edit Permalink Structure </ h2 >
< p > WordPress offers you the ability to create a custom URI structure for your permalinks and archives . The following & #8220;tags” are available:</p>
< ul >
2004-01-12 01:55:14 +01:00
< li >< code >% year %</ code > --- The year of the post , 4 digits , for example < code > 2004 </ code > </ li >
2004-01-14 07:47:52 +01:00
< li >< code >% monthnum %</ code > --- Month of the year , for example < code > 05 </ code ></ li >
2004-01-12 01:55:14 +01:00
< li >< code >% day % </ code >--- Day of the month , for example < code > 28 </ code ></ li >
< li >< code >% postname %</ code > --- A sanitized version of the title of the post . So & quot ; This Is A Great Post !& quot ; becomes & quot ; < code > this - is - a - great - post </ code >& quot ; in the URI </ li >
< li >< code >% post_id %</ code > --- The unique ID # of the post, for example <code>423</code> <strong></strong></li>
2003-10-26 06:25:26 +01:00
</ ul >
2003-12-04 23:53:15 +01:00
< p > So for example a value like < code >/ archives /% year %/% monthnum %/% day %/% postname %/</ code > could give you a permalink like < code >/ archives / 2003 / 05 / 23 / my - cheese - sandwich /</ code > . For this to work you ' ll need mod_rewrite installed on your server for the rule generation rule to work below . In the future there may be other options . </ p >
2003-12-11 01:22:36 +01:00
< form name = " form " action = " options-permalink.php " method = " post " >
2003-10-26 06:25:26 +01:00
< p > Use the template tags above to create a virtual site structure :</ p >
< p >
< input name = " permalink_structure " type = " text " style = " width: 100%; " value = " <?php echo $permalink_structure ; ?> " />
</ p >
< p >
< input type = " submit " name = " Submit " value = " Update " >
</ p >
</ form >
2003-10-30 16:03:30 +01:00
< ? php
if ( $permalink_structure ) {
?>
2003-10-26 06:25:26 +01:00
< p > Using the permalink structure value you currently have , < code >< ? php echo $permalink_structure ; ?> </code>, these are the mod_rewrite rules you should have in your <code>.htaccess</code> file.</p>
< ? php
2004-02-26 17:15:48 +01:00
$site_root = str_replace ( 'http://' , '' , trim ( get_settings ( 'siteurl' )));
2003-10-26 06:25:26 +01:00
$site_root = preg_replace ( '|([^/]*)(.*)|i' , '$2' , $site_root );
if ( '/' != substr ( $site_root , - 1 )) $site_root = $site_root . '/' ;
$rewritecode = array (
'%year%' ,
'%monthnum%' ,
'%day%' ,
2003-12-23 00:00:45 +01:00
'%postname%' ,
'%post_id%'
2003-10-26 06:25:26 +01:00
);
$rewritereplace = array (
'([0-9]{4})?' ,
'([0-9]{1,2})?' ,
2003-10-27 01:42:16 +01:00
'([0-9]{1,2})?' ,
2003-12-23 00:00:45 +01:00
'([0-9a-z-]+)?' ,
'([0-9]+)?'
2003-10-26 06:25:26 +01:00
);
$queryreplace = array (
'year=' ,
'monthnum=' ,
'day=' ,
2003-12-23 00:00:45 +01:00
'name=' ,
'p='
2003-10-26 06:25:26 +01:00
);
$match = str_replace ( '/' , '/?' , $permalink_structure );
2003-12-05 21:14:07 +01:00
$match = preg_replace ( '|/[?]|' , '' , $match , 1 );
2003-10-26 06:25:26 +01:00
2003-12-05 21:14:07 +01:00
$match = str_replace ( $rewritecode , $rewritereplace , $match );
$match = preg_replace ( '|[?]|' , '' , $match , 1 );
2004-02-05 21:55:50 +01:00
$feedmatch = str_replace ( '?/?' , '/' , $match );
$trackbackmatch = $feedmatch ;
2003-10-26 06:25:26 +01:00
preg_match_all ( '/%.+?%/' , $permalink_structure , $tokens );
2003-11-11 23:15:16 +01:00
$query = 'index.php?' ;
2004-02-05 21:55:50 +01:00
$feedquery = 'wp-feed.php?' ;
$trackbackquery = 'wp-trackback.php?' ;
2003-10-26 06:25:26 +01:00
for ( $i = 0 ; $i < count ( $tokens [ 0 ]); ++ $i ) {
2004-02-05 21:55:50 +01:00
if ( 0 < $i ) {
$query .= '&' ;
$feedquery .= '&' ;
$trackbackquery .= '&' ;
}
$query_token = str_replace ( $rewritecode , $queryreplace , $tokens [ 0 ][ $i ]) . '$' . ( $i + 1 );
$query .= $query_token ;
$feedquery .= $query_token ;
$trackbackquery .= $query_token ;
2003-10-26 06:25:26 +01:00
}
2003-12-10 20:06:28 +01:00
++ $i ;
2004-02-05 21:55:50 +01:00
2003-12-10 20:06:28 +01:00
// Add post paged stuff
$match .= '([0-9]+)?/?' ;
$query .= " &page= $ $i " ;
2003-10-26 06:25:26 +01:00
2004-02-05 21:55:50 +01:00
// Add post feed stuff
$feedregex = '(feed|rdf|rss|rss2|atom)/?' ;
$feedmatch .= $feedregex ;
$feedquery .= " &feed= $ $i " ;
// Add post trackback stuff
$trackbackregex = 'trackback/?' ;
$trackbackmatch .= $trackbackregex ;
// Site feed
$sitefeedmatch = 'feed/?([0-9a-z-]+)?/?$' ;
$sitefeedquery = $site_root . 'wp-feed.php?feed=$1' ;
// Site comment feed
$sitecommentfeedmatch = 'comments/feed/?([0-9a-z-]+)?/?$' ;
$sitecommentfeedquery = $site_root . 'wp-feed.php?feed=$1&withcomments=1' ;
2003-12-08 10:29:47 +01:00
// Code for nice categories, currently not very flexible
$front = substr ( $permalink_structure , 0 , strpos ( $permalink_structure , '%' ));
$catmatch = $front . 'category/' ;
$catmatch = preg_replace ( '|^/+|' , '' , $catmatch );
2004-02-11 05:51:19 +01:00
$authormatch = $front . 'author/' ;
$authormatch = preg_replace ( '|^/+|' , '' , $authormatch );
2003-12-08 10:29:47 +01:00
2003-10-26 06:25:26 +01:00
?>
2003-12-10 20:06:28 +01:00
< form action " " >
< textarea rows = " 5 " style = " width: 100%; " > RewriteEngine On
RewriteBase < ? php echo $site_root ; ?>
RewriteRule ^< ? php echo $match ; echo '$ ' . $site_root . $query ?> [QSA]
2004-02-05 21:55:50 +01:00
RewriteRule ^< ? php echo $feedmatch ; echo '$ ' . $site_root . $feedquery ?> [QSA]
RewriteRule ^< ? php echo $trackbackmatch ; echo '$ ' . $site_root . $trackbackquery ?> [QSA]
RewriteRule ^< ? php echo $catmatch ; ?> (.*)/<?php echo $feedregex ?>$ <?php echo $site_root; ?>wp-feed.php?category_name=$1&feed=$2 [QSA]
RewriteRule ^< ? php echo $catmatch ; ?> ?(.*) <?php echo $site_root; ?>index.php?category_name=$1 [QSA]
2004-02-11 05:51:19 +01:00
RewriteRule ^< ? php echo $authormatch ; ?> (.*)/<?php echo $feedregex ?>$ <?php echo $site_root; ?>wp-feed.php?author_name=$1&feed=$2 [QSA]
RewriteRule ^< ? php echo $authormatch ; ?> ?(.*) <?php echo $site_root; ?>index.php?author_name=$1 [QSA]
2004-02-05 21:55:50 +01:00
RewriteRule ^< ? php echo $sitefeedmatch ; ?> <?php echo $sitefeedquery ?> [QSA]
RewriteRule ^< ? php echo $sitecommentfeedmatch ; ?> <?php echo $sitecommentfeedquery ?> [QSA]</textarea>
2003-12-10 20:06:28 +01:00
</ form >
2003-10-26 06:25:26 +01:00
</ div >
< ? php
2003-10-30 16:03:30 +01:00
} else {
?>
< p >
You are not currently using customized permalinks . No special mod_rewrite
rules are needed .
</ p >
< ? php
}
echo " </div> \n " ;
2003-10-26 06:25:26 +01:00
break ;
}
2003-12-11 01:22:36 +01:00
include ( " admin-footer.php " ) ?>