3 function got_mod_rewrite() {
4 $got_rewrite = apache_mod_loaded('mod_rewrite', true);
5 return apply_filters('got_rewrite', $got_rewrite);
8 // Returns an array of strings from a file (.htaccess ) from between BEGIN
10 function extract_from_markers( $filename, $marker ) {
13 if (!file_exists( $filename ) ) {
17 if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
20 foreach ( $markerdata as $markerline ) {
21 if (strpos($markerline, '# END ' . $marker) !== false)
24 $result[] = $markerline;
25 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
33 // Inserts an array of strings into a file (.htaccess ), placing it between
34 // BEGIN and END markers. Replaces existing marked info. Retains surrounding
35 // data. Creates file if none exists.
36 // Returns true on write success, false on failure.
37 function insert_with_markers( $filename, $marker, $insertion ) {
38 if (!file_exists( $filename ) || is_writeable( $filename ) ) {
39 if (!file_exists( $filename ) ) {
42 $markerdata = explode( "\n", implode( '', file( $filename ) ) );
45 $f = fopen( $filename, 'w' );
49 foreach ( $markerdata as $n => $markerline ) {
50 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
53 if ( $n + 1 < count( $markerdata ) )
54 fwrite( $f, "{$markerline}\n" );
56 fwrite( $f, "{$markerline}" );
58 if (strpos($markerline, '# END ' . $marker) !== false) {
59 fwrite( $f, "# BEGIN {$marker}\n" );
60 if ( is_array( $insertion ))
61 foreach ( $insertion as $insertline )
62 fwrite( $f, "{$insertline}\n" );
63 fwrite( $f, "# END {$marker}\n" );
70 fwrite( $f, "# BEGIN {$marker}\n" );
71 foreach ( $insertion as $insertline )
72 fwrite( $f, "{$insertline}\n" );
73 fwrite( $f, "# END {$marker}\n" );
83 * Updates the htaccess file with the current rules if it is writable.
85 * Always writes to the file if it exists and is writable to ensure that we blank out old rules.
88 function save_mod_rewrite_rules() {
91 $home_path = get_home_path();
92 $htaccess_file = $home_path.'.htaccess';
94 // If the file doesn't already exists check for write access to the directory and whether of not we have some rules.
95 // else check for write access to the file.
96 if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
97 if ( got_mod_rewrite() ) {
98 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
99 return insert_with_markers( $htaccess_file, 'WordPress', $rules );
106 function update_recently_edited( $file ) {
107 $oldfiles = (array ) get_option( 'recently_edited' );
109 $oldfiles = array_reverse( $oldfiles );
111 $oldfiles = array_reverse( $oldfiles );
112 $oldfiles = array_unique( $oldfiles );
113 if ( 5 < count( $oldfiles ))
114 array_pop( $oldfiles );
118 update_option( 'recently_edited', $oldfiles );
121 // If siteurl or home changed, flush rewrite rules.
122 function update_home_siteurl( $old_value, $value ) {
125 if ( defined( "WP_INSTALLING" ) )
128 // If home changed, write rewrite rules to new location.
129 $wp_rewrite->flush_rules();
132 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
133 add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
135 function url_shorten( $url ) {
136 $short_url = str_replace( 'http://', '', stripslashes( $url ));
137 $short_url = str_replace( 'www.', '', $short_url );
138 if ('/' == substr( $short_url, -1 ))
139 $short_url = substr( $short_url, 0, -1 );
140 if ( strlen( $short_url ) > 35 )
141 $short_url = substr( $short_url, 0, 32 ).'...';
145 function wp_reset_vars( $vars ) {
146 for ( $i=0; $i<count( $vars ); $i += 1 ) {
150 if (!isset( $$var ) ) {
151 if ( empty( $_POST["$var"] ) ) {
152 if ( empty( $_GET["$var"] ) )
155 $$var = $_GET["$var"];
157 $$var = $_POST["$var"];