/** * Hide or show post * * @param type $post_id */ public function hide_action($post_id) { $post = new Post(); $post->id = $post_id; if ($post->find() && (access('Post.hide.all') or $post->aid == $this->user->id)) { $data = array(); if ($post->published) { $post->published = 0; $data['action'] = 'hide'; } else { $post->published = 1; $data['action'] = 'show'; } if ($post->save()) { $data['success'] = TRUE; } if (Ajax::is()) { $ajax = new Ajax(); $ajax->json($data); } else { redirect($post->getLink()); } } }