Index: trunk/wp-app.php
===================================================================
--- trunk/wp-app.php	(revision 12587)
+++ trunk/wp-app.php	(revision 12734)
@@ -266,5 +266,5 @@
 		global $always_authenticate;
 
-		if( !empty( $_SERVER['ORIG_PATH_INFO'] ) )
+		if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) )
 			$path = $_SERVER['ORIG_PATH_INFO'];
 		else
@@ -279,5 +279,5 @@
 
 		// exception case for HEAD (treat exactly as GET, but don't output)
-		if($method == 'HEAD') {
+		if ($method == 'HEAD') {
 			$this->do_output = false;
 			$method = 'GET';
@@ -285,32 +285,30 @@
 
 		// redirect to /service in case no path is found.
-		if(strlen($path) == 0 || $path == '/') {
+		if(strlen($path) == 0 || $path == '/')
 			$this->redirect($this->get_service_url());
-		}
 
 		// check to see if AtomPub is enabled
-		if( !get_option( 'enable_app' ) )
+		if ( !get_option( 'enable_app' ) )
 			$this->forbidden( sprintf( __( 'AtomPub services are disabled on this blog.  An admin user can enable them at %s' ), admin_url('options-writing.php') ) );
 
 		// dispatch
-		foreach($this->selectors as $regex => $funcs) {
-			if(preg_match($regex, $path, $matches)) {
-			if(isset($funcs[$method])) {
-
-				// authenticate regardless of the operation and set the current
-				// user. each handler will decide if auth is required or not.
-				if(!$this->authenticate()) {
-					if ($always_authenticate) {
-						$this->auth_required('Credentials required.');
+		foreach ( $this->selectors as $regex => $funcs ) {
+			if ( preg_match($regex, $path, $matches) ) {
+				if ( isset($funcs[$method]) ) {
+
+					// authenticate regardless of the operation and set the current
+					// user. each handler will decide if auth is required or not.
+					if ( !$this->authenticate() ) {
+						if ( $always_authenticate )
+							$this->auth_required('Credentials required.');
 					}
+
+					array_shift($matches);
+					call_user_func_array(array(&$this,$funcs[$method]), $matches);
+					exit();
+				} else {
+					// only allow what we have handlers for...
+					$this->not_allowed(array_keys($funcs));
 				}
-
-				array_shift($matches);
-				call_user_func_array(array(&$this,$funcs[$method]), $matches);
-				exit();
-			} else {
-				// only allow what we have handlers for...
-				$this->not_allowed(array_keys($funcs));
-			}
 			}
 		}
@@ -328,5 +326,5 @@
 		log_app('function','get_service()');
 
-		if( !current_user_can( 'edit_posts' ) )
+		if ( !current_user_can( 'edit_posts' ) )
 			$this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) );
 
@@ -339,5 +337,5 @@
 		}
 		$atom_prefix="atom";
-		$atom_blogname=get_bloginfo('name');
+		$atom_blogname = get_bloginfo('name');
 		$service_doc = <<<EOD
 <service xmlns="$this->ATOMPUB_NS" xmlns:$atom_prefix="$this->ATOM_NS">
@@ -369,5 +367,5 @@
 		log_app('function','get_categories_xml()');
 
-		if( !current_user_can( 'edit_posts' ) )
+		if ( !current_user_can( 'edit_posts' ) )
 			$this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) );
 
@@ -376,7 +374,7 @@
 		$categories = "";
 		$cats = get_categories(array('hierarchical' => 0, 'hide_empty' => 0));
-		foreach ((array) $cats as $cat) {
+		foreach ( (array) $cats as $cat ) {
 			$categories .= "    <category term=\"" . esc_attr($cat->name) .  "\" />\n";
-}
+		}
 		$output = <<<EOD
 <app:categories xmlns:app="$this->ATOMPUB_NS"
@@ -386,6 +384,6 @@
 </app:categories>
 EOD;
-	$this->output($output, $this->CATEGORIES_CONTENT_TYPE);
-}
+		$this->output($output, $this->CATEGORIES_CONTENT_TYPE);
+	}
 
 	/**
@@ -399,7 +397,6 @@
 
 		$parser = new AtomParser();
-		if(!$parser->parse()) {
+		if ( !$parser->parse() )
 			$this->client_error();
-		}
 
 		$entry = array_pop($parser->feed->entries);
@@ -408,6 +405,7 @@
 
 		$catnames = array();
-		foreach($entry->categories as $cat)
+		foreach ( $entry->categories as $cat ) {
 			array_push($catnames, $cat["term"]);
+		}
 
 		$wp_cats = get_categories(array('hide_empty' => false));
@@ -415,6 +413,6 @@
 		$post_category = array();
 
-		foreach($wp_cats as $cat) {
-			if(in_array($cat->name, $catnames))
+		foreach ( $wp_cats as $cat ) {
+			if ( in_array($cat->name, $catnames) )
 				array_push($post_category, $cat->term_id);
 		}
@@ -424,5 +422,5 @@
 		$cap = ($publish) ? 'publish_posts' : 'edit_posts';
 
-		if(!current_user_can($cap))
+		if ( !current_user_can($cap) )
 			$this->auth_required(__('Sorry, you do not have the right to edit/publish new posts.'));
 
@@ -449,5 +447,5 @@
 			$this->internal_error($postID->get_error_message());
 
-		if (!$postID)
+		if ( !$postID )
 			$this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.'));
 
@@ -476,5 +474,5 @@
 		global $entry;
 
-		if( !current_user_can( 'edit_post', $postID ) )
+		if ( !current_user_can( 'edit_post', $postID ) )
 			$this->auth_required( __( 'Sorry, you do not have the right to access this post.' ) );
 
@@ -499,7 +497,6 @@
 
 		$parser = new AtomParser();
-		if(!$parser->parse()) {
+		if ( !$parser->parse() )
 			$this->bad_request();
-		}
 
 		$parsed = array_pop($parser->feed->entries);
@@ -511,5 +508,5 @@
 		$this->set_current_entry($postID);
 
-		if(!current_user_can('edit_post', $entry['ID']))
+		if ( !current_user_can('edit_post', $entry['ID']) )
 			$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
 
@@ -534,7 +531,6 @@
 		$result = wp_update_post($postdata);
 
-		if (!$result) {
+		if ( !$result )
 			$this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.'));
-		}
 
 		do_action( 'atompub_put_post', $ID, $parsed );
@@ -557,14 +553,13 @@
 		$this->set_current_entry($postID);
 
-		if(!current_user_can('edit_post', $postID)) {
+		if ( !current_user_can('edit_post', $postID) )
 			$this->auth_required(__('Sorry, you do not have the right to delete this post.'));
-		}
-
-		if ($entry['post_type'] == 'attachment') {
+
+		if ( $entry['post_type'] == 'attachment' ) {
 			$this->delete_attachment($postID);
 		} else {
 			$result = wp_delete_post($postID);
 
-			if (!$result) {
+			if ( !$result ) {
 				$this->internal_error(__('For some strange yet very annoying reason, this post could not be deleted.'));
 			}
@@ -584,8 +579,8 @@
 	 */
 	function get_attachment($postID = null) {
-		if( !current_user_can( 'upload_files' ) )
+		if ( !current_user_can( 'upload_files' ) )
 			$this->auth_required( __( 'Sorry, you do not have permission to upload files.' ) );
 
-		if (!isset($postID)) {
+		if ( !isset($postID) ) {
 			$this->get_attachments();
 		} else {
@@ -606,10 +601,10 @@
 		$type = $this->get_accepted_content_type();
 
-		if(!current_user_can('upload_files'))
+		if ( !current_user_can('upload_files') )
 			$this->auth_required(__('You do not have permission to upload files.'));
 
 		$fp = fopen("php://input", "rb");
 		$bits = null;
-		while(!feof($fp)) {
+		while ( !feof($fp) ) {
 			$bits .= fread($fp, 4096);
 		}
@@ -679,5 +674,5 @@
 		$this->set_current_entry($postID);
 
-		if(!current_user_can('edit_post', $entry['ID']))
+		if ( !current_user_can('edit_post', $entry['ID']) )
 			$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
 
@@ -695,7 +690,6 @@
 		$result = wp_update_post($postdata);
 
-		if (!$result) {
+		if ( !$result )
 			$this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.'));
-		}
 
 		log_app('function',"put_attachment($postID)");
@@ -717,12 +711,11 @@
 		$this->set_current_entry($postID);
 
-		if(!current_user_can('edit_post', $postID)) {
+		if ( !current_user_can('edit_post', $postID) )
 			$this->auth_required(__('Sorry, you do not have the right to delete this post.'));
-		}
 
 		$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
 		$filetype = wp_check_filetype($location);
 
-		if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']))
+		if ( !isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']) )
 			$this->internal_error(__('Error ocurred while accessing post metadata for file location.'));
 
@@ -733,7 +726,6 @@
 		$result = wp_delete_post($postID);
 
-		if (!$result) {
+		if ( !$result )
 			$this->internal_error(__('For some strange yet very annoying reason, this post could not be deleted.'));
-		}
 
 		log_app('function',"delete_attachment($postID). File '$location' deleted.");
@@ -755,7 +747,6 @@
 
 		// then whether user can edit the specific post
-		if(!current_user_can('edit_post', $postID)) {
+		if ( !current_user_can('edit_post', $postID) )
 			$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
-		}
 
 		$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
@@ -763,5 +754,5 @@
 		$filetype = wp_check_filetype($location);
 
-		if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']))
+		if ( !isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext']) )
 			$this->internal_error(__('Error ocurred while accessing post metadata for file location.'));
 
@@ -770,10 +761,10 @@
 		header('Connection: close');
 
-		if ($fp = fopen($location, "rb")) {
+		if ( $fp = fopen($location, "rb") ) {
 			status_header('200');
 			header('Content-Type: ' . $entry['post_mime_type']);
 			header('Connection: close');
 
-			while(!feof($fp)) {
+			while ( !feof($fp) ) {
 				echo fread($fp, 4096);
 			}
@@ -798,5 +789,5 @@
 
 		// first check if user can upload
-		if(!current_user_can('upload_files'))
+		if ( !current_user_can('upload_files') )
 			$this->auth_required(__('You do not have permission to upload files.'));
 
@@ -806,7 +797,6 @@
 
 		// then whether user can edit the specific post
-		if(!current_user_can('edit_post', $postID)) {
+		if ( !current_user_can('edit_post', $postID) )
 			$this->auth_required(__('Sorry, you do not have the right to edit this post.'));
-		}
 
 		$upload_dir = wp_upload_dir( );
@@ -821,5 +811,5 @@
 		$fp = fopen("php://input", "rb");
 		$localfp = fopen($location, "w+");
-		while(!feof($fp)) {
+		while ( !feof($fp) ) {
 			fwrite($localfp,fread($fp, 4096));
 		}
@@ -838,7 +828,6 @@
 		$result = wp_update_post($post_data);
 
-		if (!$result) {
+		if ( !$result )
 			$this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.'));
-		}
 
 		wp_update_attachment_metadata( $postID, wp_generate_attachment_metadata( $postID, $location ) );
@@ -857,13 +846,11 @@
 	 */
 	function get_entries_url($page = null) {
-		if ( isset($GLOBALS['post_type']) && ( $GLOBALS['post_type'] == 'attachment' ) ) {
+		if ( isset($GLOBALS['post_type']) && ( $GLOBALS['post_type'] == 'attachment' ) )
 			$path = $this->MEDIA_PATH;
-		} else {
+		else
 			$path = $this->ENTRIES_PATH;
-		}
 		$url = $this->app_base . $path;
-		if(isset($page) && is_int($page)) {
+		if ( isset($page) && is_int($page) )
 			$url .= "/$page";
-		}
 		return $url;
 	}
