3 * Misc WordPress Administration API.
6 * @subpackage Administration
10 * {@internal Missing Short Description}}
16 function got_mod_rewrite() {
17 $got_rewrite = apache_mod_loaded('mod_rewrite', true);
18 return apply_filters('got_rewrite', $got_rewrite);
22 * {@internal Missing Short Description}}
26 * @param unknown_type $filename
27 * @param unknown_type $marker
28 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
30 function extract_from_markers( $filename, $marker ) {
33 if (!file_exists( $filename ) ) {
37 if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
40 foreach ( $markerdata as $markerline ) {
41 if (strpos($markerline, '# END ' . $marker) !== false)
44 $result[] = $markerline;
45 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
54 * {@internal Missing Short Description}}
56 * Inserts an array of strings into a file (.htaccess ), placing it between
57 * BEGIN and END markers. Replaces existing marked info. Retains surrounding
58 * data. Creates file if none exists.
62 * @param unknown_type $filename
63 * @param unknown_type $marker
64 * @param unknown_type $insertion
65 * @return bool True on write success, false on failure.
67 function insert_with_markers( $filename, $marker, $insertion ) {
68 if (!file_exists( $filename ) || is_writeable( $filename ) ) {
69 if (!file_exists( $filename ) ) {
72 $markerdata = explode( "\n", implode( '', file( $filename ) ) );
75 $f = fopen( $filename, 'w' );
79 foreach ( $markerdata as $n => $markerline ) {
80 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
83 if ( $n + 1 < count( $markerdata ) )
84 fwrite( $f, "{$markerline}\n" );
86 fwrite( $f, "{$markerline}" );
88 if (strpos($markerline, '# END ' . $marker) !== false) {
89 fwrite( $f, "# BEGIN {$marker}\n" );
90 if ( is_array( $insertion ))
91 foreach ( $insertion as $insertline )
92 fwrite( $f, "{$insertline}\n" );
93 fwrite( $f, "# END {$marker}\n" );
100 fwrite( $f, "\n# BEGIN {$marker}\n" );
101 foreach ( $insertion as $insertline )
102 fwrite( $f, "{$insertline}\n" );
103 fwrite( $f, "# END {$marker}\n" );
113 * Updates the htaccess file with the current rules if it is writable.
115 * Always writes to the file if it exists and is writable to ensure that we
116 * blank out old rules.
120 function save_mod_rewrite_rules() {
123 $home_path = get_home_path();
124 $htaccess_file = $home_path.'.htaccess';
126 // If the file doesn't already exists check for write access to the directory and whether of not we have some rules.
127 // else check for write access to the file.
128 if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
129 if ( got_mod_rewrite() ) {
130 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
131 return insert_with_markers( $htaccess_file, 'WordPress', $rules );
139 * {@internal Missing Short Description}}
143 * @param unknown_type $file
145 function update_recently_edited( $file ) {
146 $oldfiles = (array ) get_option( 'recently_edited' );
148 $oldfiles = array_reverse( $oldfiles );
150 $oldfiles = array_reverse( $oldfiles );
151 $oldfiles = array_unique( $oldfiles );
152 if ( 5 < count( $oldfiles ))
153 array_pop( $oldfiles );
157 update_option( 'recently_edited', $oldfiles );
161 * If siteurl or home changed, flush rewrite rules.
165 * @param unknown_type $old_value
166 * @param unknown_type $value
168 function update_home_siteurl( $old_value, $value ) {
171 if ( defined( "WP_INSTALLING" ) )
174 // If home changed, write rewrite rules to new location.
175 $wp_rewrite->flush_rules();
178 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
179 add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
182 * {@internal Missing Short Description}}
186 * @param unknown_type $url
189 function url_shorten( $url ) {
190 $short_url = str_replace( 'http://', '', stripslashes( $url ));
191 $short_url = str_replace( 'www.', '', $short_url );
192 if ('/' == substr( $short_url, -1 ))
193 $short_url = substr( $short_url, 0, -1 );
194 if ( strlen( $short_url ) > 35 )
195 $short_url = substr( $short_url, 0, 32 ).'...';
200 * {@internal Missing Short Description}}
204 * @param unknown_type $vars
206 function wp_reset_vars( $vars ) {
207 for ( $i=0; $i<count( $vars ); $i += 1 ) {
211 if (!isset( $$var ) ) {
212 if ( empty( $_POST["$var"] ) ) {
213 if ( empty( $_GET["$var"] ) )
216 $$var = $_GET["$var"];
218 $$var = $_POST["$var"];
225 * {@internal Missing Short Description}}
229 * @param unknown_type $message
231 function show_message($message) {
232 if( is_wp_error($message) ){
233 if( $message->get_error_data() )
234 $message = $message->get_error_message() . ': ' . $message->get_error_data();
236 $message = $message->get_error_message();
238 echo "<p>$message</p>\n";