/** * Generate URL by content. * * @param string $type * @param \Orchestra\Story\Model\Content|null $content * * @return string */ public function permalink($type, $content = null) { $format = $this->app['config']->get("orchestra/story::permalink.{$type}"); if (is_null($format) || !$content instanceof Content) { return handles('orchestra/story::/'); } if (is_null($published = $content->getAttribute('published_at'))) { $published = Carbon::now(); } $permalinks = ['id' => $content->getAttribute('id'), 'slug' => str_replace(['_post_/', '_page_/'], '', $content->getAttribute('slug')), 'type' => $content->getAttribute('type'), 'date' => $published->format('Y-m-d'), 'year' => $published->format('Y'), 'month' => $published->format('m'), 'day' => $published->format('d')]; foreach ($permalinks as $key => $value) { $format = str_replace('{' . $key . '}', $value, $format); } return handles("orchestra/story::{$format}"); }
/** * Manage content policy. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param \Orchestra\Story\Model\Content $content * * @return bool */ public function manage(Authenticatable $user, Content $content) { $type = $content->getAttribute('type'); return $this->can("manage {$type}"); }
/** * Determine whether published_at should be updated. * * @param \Orchestra\Story\Model\Content $content * * @return bool */ protected function updatePublishedAt(Eloquent $content) { $start = new Carbon('0000-00-00 00:00:00'); if ($content->getAttribute('status') !== Eloquent::STATUS_PUBLISH) { return false; } $published = $content->getAttribute('published_at'); switch (true) { case is_null($published): # next; # next; case $published->format('Y-m-d H:i:s') === '0000-00-00 00:00:00': # next; # next; case $published->toDateTimeString() === $start->toDateTimeString(): return true; default: return false; } }
/** * Response when content update has succeed. * * @param \Orchestra\Story\Model\Content $content * @param array $input * * @return mixed */ public function updateHasSucceed(Content $content, array $input) { messages('success', 'Post has been updated.'); return redirect(handles("orchestra::storycms/posts/{$content->getAttribute('id')}/edit")); }