%s is not writable.', NICER_PERMALINKS_ID ),
'.htaccess'
),
'error'
);
if ( !empty( $_GET['error-htb'] ) )
bb_admin_notice(
sprintf( __( 'There is no %1$s in bbPress root folder or it is not writable.', NICER_PERMALINKS_ID ),
'htaccess.bak',
BB_PATH
),
'error'
);
if ( !empty( $_GET['unknown-error'] ) ) // Should never happen
bb_admin_notice(
__( 'An unknown processing error occurred.', NICER_PERMALINKS_ID ),
'error'
);
global $bb_admin_body_class;
$bb_admin_body_class = ' bb-admin-settings';
}
/**
* Whether or not name based permalinks are enabled
*
* @uses bb_get_option()
*
* @return boolean
*/
function name_based_permalinks_enabled() {
$mod_rewrite = (string) bb_get_option( 'mod_rewrite' );
return ( 'slugs' == $mod_rewrite );
}
/**
* Copy first file contents into second file
*
* @return int|boolean Written bytes|false (error)
*/
function copy_into( $a, $b ) {
return file_put_contents( $b, file_get_contents( $a ) );
}
/**
* Update .htaccess contents with newly generated rules
*
* @uses get_nicer_htaccess_contents()
*
* @return int|boolean Written bytes|false (error)
*/
function update_htaccess() {
// Get file contents and store them in an array for further processing
$htaccess_rules = explode( "\n", implode( '', file( BB_PATH . '.htaccess' ) ) );
// Replace existing bbPress rules with newly generated rules
$keep_rule = true;
$kept_rules = array();
foreach ( $htaccess_rules as $rule ) {
if ( false !== strpos( $rule, '# BEGIN bbPress' ) ) {
$keep_rule = false;
continue;
} elseif ( false !== strpos( $rule, '# END bbPress' ) ) {
$keep_rule = true;
continue;
}
if ( $keep_rule )
$kept_rules[] = $rule;
}
// Newly generated rules are prepended to kept rules
$nicer_contents = get_nicer_htaccess_contents() . "\n" . join( "\n", $kept_rules );
return file_put_contents( BB_PATH . '.htaccess', $nicer_contents );
}
/**
* Generate nicer .htaccess contents
*
* @uses bb_get_option()
*
* @return string Nicer .htaccess contents
*/
function get_nicer_htaccess_contents() {
$nicer_htaccess_contents = <<