Pastoid

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

This paste was last updated on February 14, 2010 at 6:04 pm.

Pasted Coderaw

	public function form_publish_success($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' ) ) );
 
			// we have to check again, as the earlier checks don't check for the ownership component
			// of the 'own_posts' token.
			if ( ! ACL::access_check( $post->get_access(), 'edit' ) ) {
				// die please now.
				Session::error(_t('Access to that post id is denied'));
				$this->get_blank();
			}
 
			$this->theme->admin_page = sprintf(_t('Publish %s'), ucwords(Post::type_name($post->content_type)));
			// $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( sprintf( _t( 'The post %1$s was updated since you made changes.  Please review those changes before overwriting them.' ), sprintf('<a href="%1$s">\'%2$s\'</a>', $permalink, htmlspecialchars( $post->title ) ), Post::status_name( $post->status ) ) );
				Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
				exit;
			}
 
			$post->title = $form->title->value;
			// check that we aren't going to overflow the field
			if (strlen($post->title) > self::MAX_TITLE_LENGTH)
			{
				$post->title = Utils::truncate($post->title, self::MAX_TITLE_LENGTH, FALSE);
				Session::notice( _t('A post title must be less than  ' . self::MAX_TITLE_LENGTH . '  characters long.') );
			}
 
			if ( $form->newslug->value == '' ) {
				Session::notice( _e('A post slug cannot be empty. Keeping old slug.') );
			}
			elseif ( $form->newslug->value != $form->slug->value ) {
				$post->slug = $form->newslug->value;
			}
			$post->tags = $form->tags->value;
			$post->content = $form->content->value;
 
			// sorry, we just don't allow changing content types
			if ($form->content_type->value != $post->content_type)
			{
				Session::error(_t('Changing content types is not allowed'));
				$this->get_blank();
			}
 
			// 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'));
			$minor = false;
			$post->status = $form->status->value;
		}
		else {
			$post = new Post();
			// $form = $post->get_form( 'admin' );
			// $form->set_option( 'form_action', URL::get('admin', 'page=publish' ) );
 
			// check the user can create new posts of the set type.
			if (!ACL::user_can(User::identify(), 'post_any', 'create') && !ACL::user_can(User::identify(), 'post_' . Post::type_name($form->content_type->value), 'create'))
			{
				Session::error(sprintf(_t('You do not have the privileges to create a %s.'), ucwords(Post::type_name($form->content_type->value))));
				$this->get_blank();
			}
 
			$postdata = array(
				'slug' => $form->newslug->value,
				'title' => $form->title->value,
				'tags' => $form->tags->value,
				'content' => $form->content->value,
				'user_id' => User::identify()->id,
				'pubdate' => HabariDateTime::date_create($form->pubdate->value),
				'status' => $form->status->value,
				'content_type' => $form->content_type->value,
			);
			$minor = false;
 
			// check that we aren't going to overflow the field
			if (strlen($postdata['title']) > self::MAX_TITLE_LENGTH)
			{
				$postdata['title'] = Utils::truncate($postdata['title'], self::MAX_TITLE_LENGTH, FALSE);
				Session::notice( _t('A post title must be less than ' . self::MAX_TITLE_LENGTH . ' characters long.') );
			}
 
			$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 );
 
		$linking_types = array(Post::type('project'), Post::type('video'));
		if ($post->content_type == Post::type('image')){
			Session::notice( sprintf( _t( 'The %1$s \'%2$s\' has been saved as %3$s. You can now add this image to a <a href="posts?type=6">project</a>, or add another <a href="publish?content_type=image">new image</a>.' ), 
																Post::type_name( $post->content_type ),
																htmlspecialchars( $post->title ), 
																Post::status_name( $post->status ) ) 
											);			
		}	else if ($post->content_type == Post::type('video')){
			Session::notice( sprintf( _t( 'The %1$s \'%2$s\' has been saved as %3$s. You can now add this image to a <a href="posts?type=6">project</a>, or add another <a href="publish?content_type=image">new image</a>.' ), 
																Post::type_name( $post->content_type ),
																htmlspecialchars( $post->title ), 
																Post::status_name( $post->status ) ) 
											);			
		}	else {
			Session::notice( sprintf( _t( 'The %1$s \'%2$s\' has been saved as %3$s.' ), 
																Post::type_name( $post->content_type ),
																htmlspecialchars( $post->title ), 
																Post::status_name( $post->status ) ) 
											);
		} 
		Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
	}
 

Toggle wordwrap

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