sprintf( __( '%s status', NICER_PERMALINKS_ID ), NICER_PERMALINKS_NAME ), 'type' => 'radio', 'options' => array( 0 => __( 'Disabled', NICER_PERMALINKS_ID ), 1 => __( 'Enabled', NICER_PERMALINKS_ID ) ) ) ); ?>
  • %s.', NICER_PERMALINKS_ID ), PHP_VERSION ); ?>

  • Name based permalinks enabled', NICER_PERMALINKS_ID ), bb_get_uri( 'bb-admin/options-permalinks.php' ) ); ?>

    %2$s.', NICER_PERMALINKS_ID ), NICER_PERMALINKS_NAME, '.htaccess' ); ?>

  • %s', NICER_PERMALINKS_ID ), '.htaccess' ); ?>

  • %1$s in bbPress root folder, to store %3$s backup', NICER_PERMALINKS_ID ), 'htaccess.bak', BB_PATH, '.htaccess' ); ?>
Settings saved.', NICER_PERMALINKS_ID ) ); if ( !empty( $_GET['error-php'] ) ) bb_admin_notice( sprintf( __( 'Your Webserver is running PHP version %1$s, which is no longer receiving security updates. Please contact your host and have them upgrade PHP to its latest stable branch as soon as possible.', NICER_PERMALINKS_ID ), PHP_VERSION, 'http://www.php.net/archive/2007.php#2007-07-13-1' ), 'error' ); if ( !empty( $_GET['error-nbp'] ) ) bb_admin_notice( sprintf( __( 'Name based permalinks are not enabled.', NICER_PERMALINKS_ID ), bb_get_uri( 'bb-admin/options-permalinks.php' ) ), 'error' ); if ( !empty( $_GET['error-htw'] ) ) bb_admin_notice( sprintf( __( '%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 = << RewriteEngine On # %PATH% and bb_get_option( 'path' ) must match RewriteBase %PATH% Options +FollowSymlinks # admin stuff, not processed RewriteRule ^bb-admin/.*$ - [L,QSA] RewriteRule ^page/([0-9]+)/?$ ?page=$1 [L,QSA] RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ profile.php?id=$1&tab=$2&page=$3 [L,QSA] RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ profile.php?id=$1&page=$2 [L,QSA] RewriteRule ^profile/([^/]+)/([^/]+)$ profile.php?id=$1&tab=$2 [L,QSA] RewriteRule ^profile/([^/]+)$ profile.php?id=$1 [L,QSA] RewriteRule ^profile/$ profile.php [L,QSA] RewriteRule ^rss/forum/([^/]+)/topics/?$ rss.php?forum=$1&topics=1 [L,QSA] RewriteRule ^rss/forum/([^/]+)/?$ rss.php?forum=$1 [L,QSA] RewriteRule ^rss/profile/([^/]+)$ rss.php?profile=$1 [L,QSA] RewriteRule ^rss/tags/([^/]+)/topics/?$ rss.php?tag=$1&topics=1 [L,QSA] RewriteRule ^rss/tags/([^/]+)$ rss.php?tag=$1 [L,QSA] RewriteRule ^rss/topic/([^/]+)$ rss.php?topic=$1 [L,QSA] RewriteRule ^rss/view/([^/]+)$ rss.php?view=$1 [L,QSA] RewriteRule ^rss/topics/?$ rss.php?topics=1 [L,QSA] RewriteRule ^rss/?$ rss.php [L,QSA] RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ tags.php?tag=$1&page=$2 [L,QSA] RewriteRule ^tags/([^/]+)$ tags.php?tag=$1 [L,QSA] RewriteRule ^tags/?$ tags.php [L,QSA] RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ view.php?view=$1&page=$2 [L,QSA] RewriteRule ^view/([^/]+)$ view.php?view=$1 [L,QSA] # forums RewriteRule ^([^/]+)/page/([0-9]+)/?$ forum.php?id=$1&page=$2 [L,QSA] RewriteRule ^([^/]+)/$ forum.php?id=$1 [L,QSA] # tailed '/' is mandatory for forum URIs! Props: Mohta # topics RewriteRule ^([^/]+)/([^/]+)/page/([0-9]+)/?$ topic.php?id=$2&page=$3 [L,QSA] RewriteRule ^([^/]+)/([^/]+)$ topic.php?id=$2 [L,QSA] # other pages RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php [L] # END bbPress EOF; // Process percent-substitution tag and return nicer .htaccess contents return str_replace( '%PATH%', bb_get_option( 'path' ), $nicer_htaccess_contents ); } /** * Restore .htaccess contents from its backup at htaccess.bak and remove plugin data from database * * Note: this function is automatically skipped if plugin is already disabled. * * @uses nicer_permalinks_enabled() * @uses bb_get_uri() * @uses bb_die() * @uses copy_into() * @uses bb_delete_option() * * @return void */ function nicer_permalinks_uninstall() { if ( false === (bool) nicer_permalinks_enabled() ) // Plugin is already disabled return; // Check plugin configuration if ( !is_writable( BB_PATH . '.htaccess' ) || !file_exists( BB_PATH . 'htaccess.bak' ) ) { // Die if .htaccess is not writable or there is no htaccess.bak in bbPress root folder bb_die( sprintf( __( 'Cannot deactivate "%1$s". See "%1$s" configuration page for information on how to proceed.', NICER_PERMALINKS_ID ), NICER_PERMALINKS_NAME, bb_get_uri( 'bb-admin/admin-base.php', array( 'plugin' => 'nicer_permalinks_configuration_page' ), BB_URI_CONTEXT_BB_ADMIN ) ) ); exit; } // Try to restore .htaccess if ( false === (bool) copy_into( BB_PATH . 'htaccess.bak', BB_PATH . '.htaccess' ) ) { // Die if .htaccess is not writable or there is no htaccess.bak in bbPress root folder bb_die( sprintf( __( 'Could not deactivate "%1$s". See "%1$s" configuration page for error details.', NICER_PERMALINKS_ID ), NICER_PERMALINKS_NAME, bb_get_uri( 'bb-admin/admin-base.php', array( 'plugin' => 'nicer_permalinks_configuration_page' ), BB_URI_CONTEXT_BB_ADMIN ) ) ); exit; } // Remove plugin data from database bb_delete_option( 'nicer_permalinks_enabled' ); } ?>