Example #1
0
	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' ) ) );

			// 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, Utils::htmlspecialchars( $post->title ) ) ) ) );
				Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
				exit;
			}

			// REFACTOR: this is duplicated in the insert code below, move it outside of the conditions
			// 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 == '' && $post->status == Post::status( 'published' ) ) {
				Session::notice( _t( 'A post slug cannot be empty. Keeping old slug.' ) );
			}
			elseif ( $form->newslug->value != $form->slug->value ) {
				$post->slug = $form->newslug->value;
			}

			// REFACTOR: the permissions checks should go before any of this other logic

			// 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 unless a date has been explicitly set
			if ( ( $post->status != Post::status( 'published' ) )
				&& ( $form->status->value == Post::status( 'published' ) )
				&& ( HabariDateTime::date_create( $form->pubdate->value )->int == $form->updated->value )
				) {
				$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 {
			// REFACTOR: don't do this here, it's duplicated in Post::create()
			$post = new Post();

			// 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();
			}

			// REFACTOR: why is this on_success here? We don't even display a form
			$form->on_success( array( $this, 'form_publish_success' ) );
			if ( HabariDateTime::date_create( $form->pubdate->value )->int != $form->updated->value ) {
				$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;

			// REFACTOR: consider using new Post( $postdata ) instead and call ->insert() manually
			$post = Post::create( $postdata );
		}

		$post->info->comments_disabled = !$form->comments_enabled->value;

		// REFACTOR: admin should absolutely not have a hook for this here
		Plugins::act( 'publish_post', $post, $form );

		// REFACTOR: we should not have to update a post we just created, this should be moved to the post-update functionality above and only called if changes have been made
		// alternately, perhaps call ->update() or ->insert() as appropriate here, so things that apply to each operation (like comments_disabled) can still be included once outside the conditions above
		$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, Utils::htmlspecialchars( $post->title ) ), Post::status_name( $post->status ) ) );
		Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) );
	}
 public function action_post_delete_after($post)
 {
     if (Post::status_name($post->status) == 'published') {
         Cache::expire($this->cache_name);
     }
 }
Example #3
0
 public function action_post_delete_after($post)
 {
     if (Post::status_name($post->status) == 'published') {
         $this->expire_cache();
     }
 }
Example #4
0
 /**
  * Assign values needed to display the entries page to the theme based on handlervars and parameters
  *
  */
 private function fetch_posts($params = array())
 {
     // Make certain handler_vars local with defaults, and add them to the theme output
     $locals = array('do_update' => false, 'post_ids' => null, 'nonce' => '', 'timestamp' => '', 'PasswordDigest' => '', 'change' => '', 'user_id' => 0, 'type' => Post::type('any'), 'status' => Post::status('any'), 'limit' => 20, 'offset' => 0, 'search' => '');
     foreach ($locals as $varname => $default) {
         ${$varname} = isset($this->handler_vars[$varname]) ? $this->handler_vars[$varname] : (isset($params[$varname]) ? $params[$varname] : $default);
         $this->theme->{$varname} = ${$varname};
     }
     // numbers submitted by HTTP forms are seen as strings
     // but we want the integer value for use in Posts::get,
     // so cast these two values to (int)
     if (isset($this->handler_vars['type'])) {
         $type = (int) $this->handler_vars['type'];
     }
     if (isset($this->handler_vars['status'])) {
         $status = (int) $this->handler_vars['status'];
     }
     // if we're updating posts, let's do so:
     if ($do_update && isset($post_ids)) {
         $okay = true;
         if (empty($nonce) || empty($timestamp) || empty($PasswordDigest)) {
             $okay = false;
         }
         $wsse = Utils::WSSE($nonce, $timestamp);
         if ($PasswordDigest != $wsse['digest']) {
             $okay = false;
         }
         if ($okay) {
             foreach ($post_ids as $id) {
                 $ids[] = array('id' => $id);
             }
             $to_update = Posts::get(array('where' => $ids, 'nolimit' => 1));
             foreach ($to_update as $post) {
                 switch ($change) {
                     case 'delete':
                         if (ACL::access_check($post->get_access(), 'delete')) {
                             $post->delete();
                         }
                         break;
                     case 'publish':
                         if (ACL::access_check($post->get_access(), 'edit')) {
                             $post->publish();
                         }
                         break;
                     case 'unpublish':
                         if (ACL::access_check($post->get_access(), 'edit')) {
                             $post->status = Post::status('draft');
                             $post->update();
                         }
                         break;
                 }
             }
             unset($this->handler_vars['change']);
         }
     }
     // we load the WSSE tokens
     // for use in the delete button
     $this->theme->wsse = Utils::WSSE();
     $arguments = array('content_type' => $type, 'status' => $status, 'limit' => $limit, 'offset' => $offset, 'user_id' => $user_id);
     if ('' != $search) {
         $arguments = array_merge($arguments, Posts::search_to_get($search));
     }
     $this->theme->posts = Posts::get($arguments);
     // setup keyword in search field if a status or type was passed in POST
     $this->theme->search_args = '';
     if ($status != Post::status('any')) {
         $this->theme->search_args = 'status:' . Post::status_name($status) . ' ';
     }
     if ($type != Post::type('any')) {
         $this->theme->search_args .= 'type:' . Post::type_name($type) . ' ';
     }
     if ($user_id != 0) {
         $this->theme->search_args .= 'author:' . User::get_by_id($user_id)->username . ' ';
     }
     if ($search != '') {
         $this->theme->search_args .= $search;
     }
     $monthcts = Posts::get(array_merge($arguments, array('month_cts' => 1)));
     $years = array();
     foreach ($monthcts as $month) {
         if (isset($years[$month->year])) {
             $years[$month->year][] = $month;
         } else {
             $years[$month->year] = array($month);
         }
     }
     if (isset($years)) {
         $this->theme->years = $years;
     }
 }
Example #5
0
 public function form_publish_success(FormUI $form)
 {
     // var_dump( $form->post->storage);
     $user = User::identify();
     // Get the Post object from the hidden 'post' control on the form
     /** @var Post $post */
     $post = $form->post->storage;
     // Do some permission checks
     // @todo REFACTOR: These probably don't work and should be refactored to use validators on the form fields instead
     // sorry, we just don't allow changing posts you don't have rights to
     if ($post->id != 0 && !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
     $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'));
         // @todo This isn't ideal at all, since it loses all of the changes...
         Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id));
         exit;
     }
     // If we're creating a new post...
     if ($post->id == 0) {
         // check the user can create new posts of the set type.
         $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'));
             Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id));
             exit;
         }
         // Only the original author is associated with a new post
         $post->user_id = $user->id;
     } else {
         // check the user can create new posts of the set type.
         $type = 'post_' . Post::type_name($form->content_type->value);
         if (!ACL::access_check($post->get_access(), 'edit')) {
             Session::error(_t('Editing that post type is denied'));
             Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id));
             exit;
         }
         // 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, Utils::htmlspecialchars($post->title)))));
             Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id));
             exit;
         }
         // Prevent a published post from having its slug zeroed
         if ($form->newslug->value == '' && $post->status == Post::status('published')) {
             Session::notice(_t('A post slug cannot be empty. Keeping old slug.'));
             $form->newslug->value = $form->slug->value;
         }
     }
     // if not previously published and the user wants to publish now, change the pubdate to the current date/time unless a date has been explicitly set
     if ($post->status != Post::status('published') && $form->status->value == Post::status('published') && HabariDateTime::date_create($form->pubdate->value)->int == $form->updated->value) {
         $post->pubdate = HabariDateTime::date_create();
     } else {
         $post->pubdate = HabariDateTime::date_create($form->pubdate->value);
     }
     // Minor updates are when the user has checked the minor update box and the post isn't in draft or new
     $minor = $form->minor_edit->value && $post->status != Post::status('draft') && $post->id != 0;
     // Don't try to update form values that have been removed by plugins,
     // look for these fields before committing their values to the post
     $expected = array('title' => 'title', 'tags' => 'tags', 'content' => 'content', 'slug' => 'newslug', 'content_type' => 'content_type', 'status' => 'status');
     // var_dump($form->$field);
     // exit;
     foreach ($expected as $field => $control) {
         if (isset($form->{$field})) {
             //var_dump( $form->$control->value);
             // exit;
             //echo $field."----------".$control;
             $post->{$field} = $form->{$control}->value;
             // $post->title = '新的的標題1111';
             // $post->tags = '標籤1111';
             // $post->content = '我的文章內容測試';
             // $post->slug = '我的文章內容測試-1';
             // // $post->content_type = 'kkk-2';
             // $post->status = 2;
             // print_r($post);
             // echo  "<br/>";
             // print_r($post->$field);
             // echo  "<br/>";
             // exit;
         }
     }
     // $post->insert();
     // exit;
     // This seems cheesy
     $post->info->comments_disabled = !$form->comments_enabled->value;
     // var_dump($post->info->comments_disabled);
     // var_dump($form->comments_enabled->value);
     // exit;
     // This plugin hook allows changes to be made to the post object prior to its save to the database
     Plugins::act('publish_post', $post, $form);
     // Insert or Update
     if ($post->id == 0) {
         $post->insert();
     } else {
         $post->update($minor);
     }
     // Calling $form->save() calls ->save() on any controls that might have been added to the form by plugins
     $form->save();
     $permalink = $post->status != Post::status('published') ? $post->permalink . '?preview=1' : $post->permalink;
     Session::notice(_t('The post %1$s has been saved as %2$s.', array(sprintf('<a href="%1$s">\'%2$s\'</a>', $permalink, Utils::htmlspecialchars($post->title)), Post::status_name($post->status))));
     Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id));
 }
 public function action_publish_post($post)
 {
     if (Post::status_name($post->status) == 'scheduled') {
         $post->status = Post::status('published');
     }
 }
 /**
  * Altered copy of AdminHandler::post_publish():
  * - Throws exceptions rather than Session notices so we can return errors to AJAX calls;
  * - Does not redirect but echo a JSON object with the post's ID and slug
  *
  * @see AdminHandler::post_publish()
  *
  * @param AjaxHandler $that The AjaxHandler instance
  */
 public function action_auth_ajax_autosave($handler)
 {
     // @todo until ACL checks forr this are added, make inoperable
     return null;
     $response = array();
     try {
         $post_id = 0;
         if (isset($handler->handler_vars['id'])) {
             $post_id = intval($handler->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('ajax');
             $post->title = $form->title->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;
             }
             $post->tags = $form->tags->value;
             $post->content = $form->content->value;
             $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 {
                 $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('ajax');
             $form->set_option('form_action', URL::get('admin', 'page=publish'));
             $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;
             $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));
         }
         $response['post_id'] = $post->id;
         $response['post_slug'] = $post->slug;
         $response['messages'] = Session::messages_get(true, 'array');
         ob_end_clean();
         echo json_encode($response);
         // Prevent rest of adminhandler to run, we only wanted to save!
         exit;
     } catch (Exception $e) {
         $response['error'] = $e->getMessage();
         ob_end_clean();
         echo json_encode($response);
         // Prevent rest of adminhandler to run, we only wanted to save!
         exit;
     }
 }
	/**
	 * filter_dash_module_post_types
	 * Function used to set theme variables to the post types dashboard widget
	 * @param string $module_id
	 * @return string The contents of the module
	 */
	public function filter_dash_module_post_types_and_statuses( $module, $module_id, $theme )
	{
		$messages = array();
		$user = User::identify();

		$post_types = Post::list_active_post_types();
		array_shift( $post_types );
		$post_statuses = array_values( Post::list_post_statuses() );
		array_shift( $post_statuses );

		foreach( $post_types as $type => $type_id ) {
			$plural = Plugins::filter( 'post_type_display', $type, 'plural' );
			foreach( $post_statuses as $status => $status_id ) {
				$status_display = MultiByte::ucfirst( Plugins::filter( 'post_status_display', Post::status_name( $status_id ) ) );
				$site_count = Posts::get( array( 'content_type' => $type_id, 'count' => true, 'status' => $status_id ) );
				$user_count = Posts::get( array( 'content_type' => $type_id, 'count' => true, 'status' => $status_id, 'user_id' => $user->id ) );

				// @locale First variable is the post status, second is the post type
				$message['label'] = _t( '%1$s %2$s', array( $status_display, $plural ) );

				if( ! $site_count ) {
					$message['site_count'] = '';
				}
				else if( $user->cannot( 'post_unpublished' ) && Post::status_name( $status_id ) != 'published' ) {
					$message['site_count'] = '';
				}
				else {
					$message['site_count'] = $site_count;
				}
				$perms = array(
					'post_any' => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ),
					'own_posts' => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ),
					'post_' . $type => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ),
				);
				if ( $user->can_any( $perms ) && $message['site_count'] ) {
					$message['site_count'] = '<a href="' . Utils::htmlspecialchars( URL::get( 'admin', array( 'page' => 'posts', 'type' => Post::type( $type ), 'status' => $status_id ) ) ) . '">' . Utils::htmlspecialchars( $message['site_count'] ) . '</a>';
				}

				if( ! $user_count ) {
					$message['user_count'] = '';
				}
				else {
					$message['user_count'] = $user_count;
				}
				// @locale First variable is the post status, second is the post type
				$perms = array(
					'own_posts' => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ),
					'post_' . $type => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ),
				);
				if ( $user->can_any( $perms )  && $message['user_count'] ) {
					$message['user_count'] = '<a href="' . Utils::htmlspecialchars( URL::get( 'admin', array( 'page' => 'posts', 'type' => Post::type( $type ), 'status' => $status_id, 'user_id' => $user->id ) ) ) . '">' . Utils::htmlspecialchars( $message['user_count'] ) . '</a>';
				}

				if( $message['site_count'] || $message['user_count'] ) {
					$messages[] = $message;
				}
			}
		}

		$theme->type_messages = $messages;

		$module['title'] = _t( 'Post Types and Statuses' );
		$module['content'] = $theme->fetch( 'dash_posttypes' );
		return $module;
	}
Example #9
0
 /**
  * Called when the publish form is successfully submitted
  * @param FormUI $form
  */
 public function form_publish_success(FormUI $form)
 {
     $user = User::identify();
     // Get the Post object from the hidden 'post' control on the form
     /** @var Post $post */
     $post = $form->post->value;
     // Do some permission checks
     // @todo REFACTOR: These probably don't work and should be refactored to use validators on the form fields instead
     // sorry, we just don't allow changing posts you don't have rights to
     if ($post->id != 0 && !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
     $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('You don\'t have permission to change to that content type'));
         // @todo This isn't ideal at all, since it loses all of the changes...
         Utils::redirect(URL::get('display_publish', $post, false));
         exit;
     }
     // If we're creating a new post...
     if ($post->id == 0) {
         // check the user can create new posts of the set type.
         $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('You don\'t have permission to create posts of that type'));
             Utils::redirect(URL::get('display_publish', $post, false));
             exit;
         }
         // Only the original author is associated with a new post
         $post->user_id = $user->id;
     } else {
         // check the user can create new posts of the set type.
         $type = 'post_' . Post::type_name($form->content_type->value);
         if (!ACL::access_check($post->get_access(), 'edit')) {
             Session::error(_t('You don\'t have permission to edit posts of that type'));
             Utils::redirect(URL::get('display_publish', $post, false));
             exit;
         }
         // 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, Utils::htmlspecialchars($post->title)))));
             Utils::redirect(URL::get('display_publish', $post, false));
             exit;
         }
         // Prevent a published post from having its slug zeroed
         if ($form->newslug->value == '' && $post->status == Post::status('published')) {
             Session::notice(_t('A post slug cannot be empty. Keeping old slug.'));
             $form->newslug->value = $form->slug->value;
         }
     }
     // sometimes we want to overwrite the published date with the current date, if:
     //		1) the post was not previously published
     //		2) the post is now supposed to be published
     //		3) the user has not entered a specific publish date already -- that is, the one on the form that was submitted is the same as the currently saved one
     //		AND
     //		4) the published date is NOT in the future -- if it were, we would reset the date on scheduled posts if we edit them again before they are published
     if ($post->status != Post::status('published') && $form->status->value == Post::status('published') && ($post->pubdate == DateTime::create($form->pubdate->value) && $post->pubdate <= DateTime::create())) {
         $post->pubdate = DateTime::create();
     } else {
         $post->pubdate = DateTime::create($form->pubdate->value);
     }
     // Minor updates are when the user has checked the minor update box and the post isn't in draft or new
     $minor = $form->minor_edit->value && $post->status != Post::status('draft') && $post->id != 0;
     // Don't try to update form values that have been removed by plugins,
     // look for these fields before committing their values to the post
     $expected = array('title' => 'title', 'tags' => 'tags', 'content' => 'content', 'slug' => 'newslug', 'content_type' => 'content_type', 'status' => 'status');
     foreach ($expected as $field => $control) {
         if (isset($form->{$field})) {
             $post->{$field} = $form->{$control}->value;
         }
     }
     // This seems cheesy
     $post->info->comments_disabled = !$form->comments_enabled->value;
     // This plugin hook allows changes to be made to the post object prior to its save to the database
     Plugins::act('publish_post', $post, $form);
     // Insert or Update
     if ($post->id == 0) {
         $post->insert();
     } else {
         $post->update($minor);
     }
     // Calling $form->save() calls ->save() on any controls that might have been added to the form by plugins
     $form->save();
     $permalink = $post->status != Post::status('published') ? $post->permalink . '?preview=1' : $post->permalink;
     $postname = sprintf('<a href="%1$s">\'%2$s\'</a>', $permalink, Utils::htmlspecialchars($post->title));
     $status = Post::status_name($post->status);
     Session::notice(_t('The post !postname has been saved as !status.', array('!postname' => $postname, '!status' => $status)));
     Utils::redirect(URL::get('display_publish', $post, false));
 }
Example #10
0
 /**
  * Handles POST values from /manage/posts.
  * Used to control what content to show / manage.
  */
 public function post_posts()
 {
     // Simply pass $_GET to the function, it's save as only values we understand will be read
     $this->fetch_posts($_GET);
     // Check which values have been passed and translate them for the faceted seach
     $search_values = array();
     foreach ($this->locals as $varname => $default) {
         if (isset($_GET[$varname])) {
             switch ($varname) {
                 case 'type':
                     $search_values[] = 'type: ' . Post::type_name($_GET['type']);
                     break;
                 case 'status':
                     $search_values[] = 'status: ' . Post::status_name($_GET['status']);
                     break;
                 case 'tag':
                     $tags = explode(',', $_GET['tag']);
                     foreach ($tags as $tag) {
                         $search_values[] = 'tag: ' . $tag;
                     }
                     break;
                 case 'author':
                     $search_values[] = 'author: ' . User::get($_GET['author'])->username;
                     break;
                 default:
                     $search_values[] = $varname . ': ' . $_GET[$varname];
             }
         }
     }
     if (count($search_values) > 0) {
         $search_value = implode(' ', $search_values);
     } else {
         $search_value = '';
     }
     // Create search controls and global buttons for the manage page
     $search = FormControlFacet::create('search');
     $search->set_value($search_value)->set_property('data-facet-config', array('onsearch' => '$(".posts").manager("update", self.data("visualsearch").searchQuery.facets());', 'facetsURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'manage', 'component' => 'facets')), 'valuesURL' => URL::get('admin_ajax_facets', array('context' => 'facets', 'page' => 'manage', 'component' => 'values'))));
     $navigation = FormControlStatic::create('navigation')->set_static('<a href="" id="nav_prev" class="navigation">' . _t('Previous page') . '</a>' . '<a href="" id="nav_next" class="navigation">' . _t('Next page') . '</a>');
     $aggregate = FormControlAggregate::create('selected_items')->set_selector('.post_item')->label('None Selected');
     $page_actions = FormControlDropbutton::create('page_actions');
     $page_actions->append(FormControlSubmit::create('delete')->set_caption(_t('Delete Selected'))->set_properties(array('onclick' => 'itemManage.update(\'delete\');return false;', 'title' => _t('Delete Selected'))));
     Plugins::act('posts_manage_actions', $page_actions);
     $form = new FormUI('manage');
     $form->append($search);
     $form->append($navigation);
     $form->append($aggregate);
     $form->append($page_actions);
     $this->theme->form = $form;
     $this->theme->admin_page = _t('Manage Posts');
     $this->theme->admin_title = _t('Manage Posts');
     Stack::add('admin_header_javascript', 'visualsearch');
     Stack::add('admin_header_javascript', 'manage-js');
     Stack::add('admin_stylesheet', 'visualsearch-css');
     Stack::add('admin_stylesheet', 'visualsearch-datauri-css');
     $this->display('posts');
 }