/** * Handle the command. * * @param TypeRepositoryInterface $types * @param PostRepositoryInterface $posts */ public function handle(TypeRepositoryInterface $types, PostRepositoryInterface $posts) { /* @var TypeInterface $type */ $type = $types->find($this->type->getId()); /* @var PostInterface $post */ foreach ($type->getPosts() as $post) { $posts->save($post->setAttribute('entry_type', $this->type->getEntryModelName())); } }
/** * Run the seeder. */ public function run() { $this->posts->truncate(); $repository = new EntryRepository(); $repository->setModel(new PostsDefaultPostsEntryModel()); $repository->truncate(); $type = $this->types->findBySlug('default'); $category = $this->categories->findBySlug('news'); $welcome = (new PostsDefaultPostsEntryModel())->create(['content' => '<p>Welcome to PyroCMS!</p>']); $this->posts->create(['en' => ['title' => 'Welcome to PyroCMS!', 'summary' => 'This is an example post to demonstrate the posts module.'], 'slug' => 'welcome-to-pyrocms', 'publish_at' => time(), 'enabled' => true, 'type' => $type, 'entry' => $welcome, 'category' => $category, 'author' => 1]); }
/** * Preview an existing post. * * @param PostRepositoryInterface $posts * @param $id * @return \Illuminate\View\View */ public function preview(PostRepositoryInterface $posts, $id) { if (!($post = $posts->findByStrId($id))) { abort(404); } $this->dispatch(new AddPostsBreadcrumb()); $this->dispatch(new MakePreviewResponse($post)); if ($category = $post->getCategory()) { $this->dispatch(new AddCategoryBreadcrumb($category)); } $this->dispatch(new AddPostBreadcrumb($post)); return $post->getResponse(); }
/** * Delete a post and go back. * * @param PostRepositoryInterface $posts * @param Authorizer $authorizer * @param $id * @return \Illuminate\Http\RedirectResponse */ public function delete(PostRepositoryInterface $posts, Authorizer $authorizer, $id) { $authorizer->authorize('anomaly.module.posts::posts.delete'); $posts->delete($posts->find($id)); return redirect()->back(); }
/** * Resolve the post. * * @return PostInterface|null */ public function resolve() { $permalink = $this->settings->value('anomaly.module.posts::permalink_structure', ['year', 'month', 'day', 'post']); return $this->posts->findBySlug($this->request->segment(array_search('post', $permalink) + 2)); }
/** * Return an RSS feed of recent posts by tag. * * @param PostRepositoryInterface $posts * @param ResponseFactory $response * @param $category * @return \Illuminate\Http\Response|ResponseFactory */ public function tag(PostRepositoryInterface $posts, ResponseFactory $response, $tag) { $response = $response->view('module::posts/rss', ['posts' => $posts->findManyByTag($tag)])->setTtl(3600); $response->headers->set('content-type', 'text/xml'); return $response; }
/** * Resolve the post. * * @return PostInterface|null */ public function resolve() { $permalink = explode('/', $this->config->get('anomaly.module.posts::paths.route')); return $this->posts->findBySlug($this->request->segment(array_search('{post}', $permalink) + 2)); }
/** * Resolve the post. * * @return PostInterface|null */ public function resolve() { $base = $this->settings->get('anomaly.module.posts::module_base', 'posts'); $structure = $base . '/' . $this->settings->get('anomaly.module.posts::permalink_structure', '{year}/{month}/{day}/{post}'); return $this->posts->findBySlug($this->request->segment(array_search('{post}', explode('/', $structure)) + 1)); }
/** * Handle the command. * * @param PostRepositoryInterface $posts */ public function handle(PostRepositoryInterface $posts) { foreach ($this->type->getPosts() as $post) { $posts->delete($post); } }
/** * Preview an existing post. * * @param PostRepositoryInterface $posts * @param $id * @return \Illuminate\View\View */ public function preview(PostRepositoryInterface $posts, $id) { if (!($post = $posts->findByStrId($id))) { abort(404); } $this->authorizer->authorize($post); $this->loader->load($post); $this->response->make($post); $this->http->cache($post); $this->dispatch(new AddPostsBreadcrumb()); if ($category = $post->getCategory()) { $this->dispatch(new AddCategoryBreadcrumb($category)); } $this->dispatch(new AddPostBreadcrumb($post)); return $post->getResponse(); }