Pastoid

The page you are looking at now is at this URL: http://pastoid.com/bzx

This paste was last updated on February 12, 2010 at 11:22 pm.

Pasted Coderaw

Index: system/classes/post.php
===================================================================
--- system/classes/post.php	(revision 4024)
+++ system/classes/post.php	(working copy)
@@ -777,7 +777,9 @@
 		$form->title->class[] = 'check-change';
 		$form->title->tabindex = 1;
 		$form->title->value = $this->title;
+		$form->title->add_validator( 'validate_required' );
 
+
 		// Create the silos
 		if ( count( Plugins::get_by_interface( 'MediaSilo' ) ) ) {
 			$form->append('silos', 'silos');
@@ -855,7 +857,7 @@
 		$form->post_id->value = $this->id;
 		$form->append('hidden', 'slug', 'null:null');
 		$form->slug->value = $this->slug;
-
+		$form->on_success( array( $this, 'form_publish_success' ) );
 		// Let plugins alter this form
 		Plugins::act('form_publish', $form, $this, $context);
 
@@ -863,6 +865,132 @@
 		return $form;
 	}
 
+	public function form_publish_success( FormUI $form )
+	{
+		$post_id = 0;
+		if ( isset($this->handler_vars['id']) ) {
+			$post_id = intval($this->handler_vars['id']);
+		}
+
+		// If an id has been passed in, we're updating an existing post, otherwise we're creating one
+		if ( 0 !== $post_id ) {
+			$post = Post::get( array( 'id' => $post_id, 'status' => Post::status( 'any' ) ) );
+
+			$this->theme->admin_page = sprintf(_t('Publish %s'), Plugins::filter('post_type_display', Post::type_name($post->content_type), 'singular')); 
+// 			$form = $post->get_form( 'admin' );
+
+			// Verify that the post hasn't already been updated since the form was loaded
+			if ( $post->modified != $form->modified->value ) {
+				Session::notice( _t( 'The post %1$s was updated since you made changes.  Please review those changes before overwriting them.', array( sprintf('<a href="%1$s">\'%2$s\'</a>', $post->permalink, htmlspecialchars( $post->title ) ) ) ) );
+				Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
+				exit;
+			}
+			
+			// Don't try to update form values that have been removed by plugins
+			$expected = array('title', 'tags', 'content');
+
+			foreach ( $expected as $field ) {
+				if ( isset($form->$field) ) {
+					$post->$field = $form->$field->value;
+				}
+			}
+			if ( $form->newslug->value == '' ) {
+				Session::notice( _t( 'A post slug cannot be empty. Keeping old slug.' ) );
+			}
+			elseif ( $form->newslug->value != $form->slug->value ) {
+				$post->slug = $form->newslug->value;
+			}
+
+			// sorry, we just don't allow changing posts you don't have rights to
+			if ( ! ACL::access_check( $post->get_access(), 'edit' ) ) {
+				Session::error( _t( 'You don\'t have permission to edit that post' ) );
+				$this->get_blank();
+			}
+			// sorry, we just don't allow changing content types to types you don't have rights to
+			$user = User::identify();
+			$type = 'post_' . Post::type_name( $form->content_type->value );
+			if ( $form->content_type->value != $post->content_type && ( $user->cannot( $type ) || ! $user->can_any( array( 'own_posts' => 'edit', 'post_any' => 'edit', $type => 'edit' ) ) ) ) {
+				Session::error(_t('Changing content types is not allowed'));
+				$this->get_blank();
+			}
+			$post->content_type = $form->content_type->value;
+
+			// if not previously published and the user wants to publish now, change the pubdate to the current date/time
+			// if the post pubdate is <= the current date/time.
+			if ( ( $post->status != Post::status( 'published' ) )
+				&& ( $form->status->value == Post::status( 'published' ) )
+				&& ( HabariDateTime::date_create( $form->pubdate->value )->int <= HabariDateTime::date_create()->int )
+				) {
+				$post->pubdate = HabariDateTime::date_create();
+			}
+			// else let the user change the publication date.
+			//  If previously published and the new date is in the future, the post will be unpublished and scheduled. Any other status, and the post will just get the new pubdate.
+			// This will result in the post being scheduled for future publication if the date/time is in the future and the new status is published.
+			else {
+				$post->pubdate = HabariDateTime::date_create( $form->pubdate->value );
+			}
+			$minor = $form->minor_edit->value && ($post->status != Post::status('draft'));
+			$post->status = $form->status->value;
+		}
+		else {
+			$post = new Post();
+// 			$form = $post->get_form( 'admin' );
+			// check the user can create new posts of the set type.
+			$user = User::identify();
+			$type = 'post_'  . Post::type_name($form->content_type->value);
+			if ( ACL::user_cannot( $user, $type) || ( ! ACL::user_can( $user, 'post_any', 'create' ) && ! ACL::user_can( $user, $type, 'create') ) ) {
+				Session::error(_t('Creating that post type is denied'));
+				$this->get_blank();
+			}
+
+// 			$form->set_option( 'form_action', URL::get('admin', 'page=publish' ) );
+			$form->on_success( array( $this, 'form_publish_success' ) );
+
+			if ( HabariDateTime::date_create( $form->pubdate->value )->int > $post->pubdate->int ) {
+				$post->pubdate = HabariDateTime::date_create( $form->pubdate->value );
+			}
+
+			$postdata = array(
+				'slug' => $form->newslug->value,
+				'user_id' => User::identify()->id,
+				'pubdate' => $post->pubdate,
+				'status' => $form->status->value,
+				'content_type' => $form->content_type->value,
+			);
+
+			// Don't try to add form values that have been removed by plugins
+			$expected = array('title', 'tags', 'content');
+
+			foreach ( $expected as $field ) {
+				if ( isset($form->$field) ) {
+					$postdata[$field] = $form->$field->value;
+				}
+			}
+
+			$minor = false;
+
+			$post = Post::create( $postdata );
+		}
+
+		if ( $post->pubdate->int > HabariDateTime::date_create()->int && $post->status == Post::status( 'published' ) ) {
+			$post->status = Post::status( 'scheduled' );
+		}
+
+		$post->info->comments_disabled = !$form->comments_enabled->value;
+
+		Plugins::act('publish_post', $post, $form);
+
+		$post->update( $minor );
+
+		$permalink = ( $post->status != Post::status( 'published' ) ) ? $post->permalink . '?preview=1' : $post->permalink;
+		Session::notice( sprintf( _t( 'The post %1$s has been saved as %2$s.' ), sprintf('<a href="%1$s">\'%2$s\'</a>', $permalink, htmlspecialchars( $post->title ) ), Post::status_name( $post->status ) ) );
+		if ( $post->slug != Utils::slugify( $post->title ) ) {
+			Session::notice( sprintf( _t( 'The content address is \'%1$s\'.'), $post->slug ));
+		}
+		Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
+	}
+
+
 	/**
 	 * Manage this post's comment form
 	 *
Index: system/classes/adminhandler.php
===================================================================
--- system/classes/adminhandler.php	(revision 4024)
+++ system/classes/adminhandler.php	(working copy)
@@ -467,126 +467,7 @@
 	 */
 	public function post_publish()
 	{
-		$post_id = 0;
-		if ( isset($this->handler_vars['id']) ) {
-			$post_id = intval($this->handler_vars['id']);
-		}
-
-		// If an id has been passed in, we're updating an existing post, otherwise we're creating one
-		if ( 0 !== $post_id ) {
-			$post = Post::get( array( 'id' => $post_id, 'status' => Post::status( 'any' ) ) );
-
-			$this->theme->admin_page = sprintf(_t('Publish %s'), Plugins::filter('post_type_display', Post::type_name($post->content_type), 'singular')); 
-			$form = $post->get_form( 'admin' );
-
-			// Verify that the post hasn't already been updated since the form was loaded
-			if ( $post->modified != $form->modified->value ) {
-				Session::notice( _t( 'The post %1$s was updated since you made changes.  Please review those changes before overwriting them.', array( sprintf('<a href="%1$s">\'%2$s\'</a>', $post->permalink, htmlspecialchars( $post->title ) ) ) ) );
-				Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
-				exit;
-			}
-			
-			// Don't try to update form values that have been removed by plugins
-			$expected = array('title', 'tags', 'content');
-
-			foreach ( $expected as $field ) {
-				if ( isset($form->$field) ) {
-					$post->$field = $form->$field->value;
-				}
-			}
-			if ( $form->newslug->value == '' ) {
-				Session::notice( _t( 'A post slug cannot be empty. Keeping old slug.' ) );
-			}
-			elseif ( $form->newslug->value != $form->slug->value ) {
-				$post->slug = $form->newslug->value;
-			}
-
-			// sorry, we just don't allow changing posts you don't have rights to
-			if ( ! ACL::access_check( $post->get_access(), 'edit' ) ) {
-				Session::error( _t( 'You don\'t have permission to edit that post' ) );
-				$this->get_blank();
-			}
-			// sorry, we just don't allow changing content types to types you don't have rights to
-			$user = User::identify();
-			$type = 'post_' . Post::type_name( $form->content_type->value );
-			if ( $form->content_type->value != $post->content_type && ( $user->cannot( $type ) || ! $user->can_any( array( 'own_posts' => 'edit', 'post_any' => 'edit', $type => 'edit' ) ) ) ) {
-				Session::error(_t('Changing content types is not allowed'));
-				$this->get_blank();
-			}
-			$post->content_type = $form->content_type->value;
-
-			// if not previously published and the user wants to publish now, change the pubdate to the current date/time
-			// if the post pubdate is <= the current date/time.
-			if ( ( $post->status != Post::status( 'published' ) )
-				&& ( $form->status->value == Post::status( 'published' ) )
-				&& ( HabariDateTime::date_create( $form->pubdate->value )->int <= HabariDateTime::date_create()->int )
-				) {
-				$post->pubdate = HabariDateTime::date_create();
-			}
-			// else let the user change the publication date.
-			//  If previously published and the new date is in the future, the post will be unpublished and scheduled. Any other status, and the post will just get the new pubdate.
-			// This will result in the post being scheduled for future publication if the date/time is in the future and the new status is published.
-			else {
-				$post->pubdate = HabariDateTime::date_create( $form->pubdate->value );
-			}
-			$minor = $form->minor_edit->value && ($post->status != Post::status('draft'));
-			$post->status = $form->status->value;
-		}
-		else {
-			$post = new Post();
-			$form = $post->get_form( 'admin' );
-			// check the user can create new posts of the set type.
-			$user = User::identify();
-			$type = 'post_'  . Post::type_name($form->content_type->value);
-			if ( ACL::user_cannot( $user, $type) || ( ! ACL::user_can( $user, 'post_any', 'create' ) && ! ACL::user_can( $user, $type, 'create') ) ) {
-				Session::error(_t('Creating that post type is denied'));
-				$this->get_blank();
-			}
-
-			$form->set_option( 'form_action', URL::get('admin', 'page=publish' ) );
-
-			if ( HabariDateTime::date_create( $form->pubdate->value )->int > $post->pubdate->int ) {
-				$post->pubdate = HabariDateTime::date_create( $form->pubdate->value );
-			}
-
-			$postdata = array(
-				'slug' => $form->newslug->value,
-				'user_id' => User::identify()->id,
-				'pubdate' => $post->pubdate,
-				'status' => $form->status->value,
-				'content_type' => $form->content_type->value,
-			);
-
-			// Don't try to add form values that have been removed by plugins
-			$expected = array('title', 'tags', 'content');
-
-			foreach ( $expected as $field ) {
-				if ( isset($form->$field) ) {
-					$postdata[$field] = $form->$field->value;
-				}
-			}
-
-			$minor = false;
-
-			$post = Post::create( $postdata );
-		}
-
-		if ( $post->pubdate->int > HabariDateTime::date_create()->int && $post->status == Post::status( 'published' ) ) {
-			$post->status = Post::status( 'scheduled' );
-		}
-
-		$post->info->comments_disabled = !$form->comments_enabled->value;
-
-		Plugins::act('publish_post', $post, $form);
-
-		$post->update( $minor );
-
-		$permalink = ( $post->status != Post::status( 'published' ) ) ? $post->permalink . '?preview=1' : $post->permalink;
-		Session::notice( sprintf( _t( 'The post %1$s has been saved as %2$s.' ), sprintf('<a href="%1$s">\'%2$s\'</a>', $permalink, htmlspecialchars( $post->title ) ), Post::status_name( $post->status ) ) );
-		if ( $post->slug != Utils::slugify( $post->title ) ) {
-			Session::notice( sprintf( _t( 'The content address is \'%1$s\'.'), $post->slug ));
-		}
-		Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
+		$this->get_publish();
 	}
 
 	/**
@@ -599,7 +480,9 @@
 			$$key = $value;
 		}
 
-		if ( isset( $id ) ) {
+// Utils::debug( $id );
+		// 0 is what's assigned to new posts
+ 		if ( isset( $id ) && ( $id != 0 )) {
 			$post = Post::get( array( 'id' => $id, 'status' => Post::status( 'any' ) ) );
 			if ( !$post ) {
 				Session::error(_t('Access to that post id is denied'));

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 14
drunkenmonkey.org 2
Is this paste spam?
<Hide