Beispiel #1
0
 /**
  * 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}");
 }
Beispiel #2
0
 /**
  * Handle pane for dashboard page.
  *
  * @return void
  */
 public function compose()
 {
     $pane = $this->widget->make('pane.orchestra');
     $posts = Content::post()->publish()->latest(10)->get();
     if ($posts->isEmpty()) {
         return;
     }
     $pane->add('story-latest-posts')->attributes(['class' => 'six columns widget'])->title('Latest Post')->content(view('orchestra/story::widgets.latest-posts')->with('posts', $posts));
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 protected function getRequestedContent($id, $slug)
 {
     if (isset($id) and !is_null($id)) {
         return Content::post()->publish()->where('id', $id)->firstOrFail();
     } elseif (isset($slug) and !is_null($slug)) {
         return Content::post()->publish()->where('slug', "_post_/{$slug}")->firstOrFail();
     }
     throw new NotFoundHttpException();
 }
Beispiel #4
0
 /**
  * Show default page.
  *
  * @param  string  $slug
  *
  * @return mixed
  */
 protected function page($slug)
 {
     $page = Content::page()->publish()->where('slug', '=', $slug)->firstOrFail();
     $slug = preg_replace('/^_page_\\//', '', $slug);
     if (!View::exists($view = "orchestra/story::pages.{$slug}")) {
         $view = 'orchestra/story::page';
     }
     return Facile::view($view)->with(['page' => $page])->render();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $posts = ['2013-05-10-hello-world', '2013-05-31-why-orchestra-asset', '2013-06-01-simple-website-1', '2013-06-01-simple-website-2', '2013-06-01-simple-website-3', '2013-06-02-simple-website-4', '2013-06-11-quick-update-1', '2013-06-12-simple-website-5', '2013-06-13-simple-website-6', '2013-06-20-release-2.0.0', '2013-07-09-installation-preview', '2013-07-09-storycms-preview', '2013-07-10-ftp-publishing-preview', '2013-07-28-quick-update-2', '2013-07-28-simple-website-7', '2013-09-10-simple-website-8'];
     $parser = app(DocumentParser::class);
     foreach ($posts as $post) {
         $source = file_get_contents(__DIR__ . "/posts/{$post}.md");
         $document = $parser->parse($source);
         $metadata = $document->get();
         preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})-(.*)$/', $post, $matches);
         list(, $year, $month, $day, $slug) = $matches;
         $content = new Content();
         $content->type = Content::POST;
         $content->format = 'markdown';
         $content->title = $metadata['title'];
         $content->content = $document->getContent();
         $content->slug = "_post_/{$slug}";
         $content->status = 'publish';
         $content->published_at = Carbon::createFromDate($year, $month, $day);
         $content->user_id = 1;
         $content->save();
         $this->command->info("Seed: [{$post}]");
         sleep(10);
     }
 }
Beispiel #6
0
 /**
  * Setup the form.
  *
  * @param  \Illuminate\Support\Fluent  $model
  * @param  \Orchestra\Contracts\Html\Form\Builder  $form
  *
  * @return void
  */
 protected function form(Fluent $model, FormBuilder $form)
 {
     $form->extend(function ($form) use($model) {
         $form->fieldset('Page Management', function ($fieldset) {
             $pages = Content::page()->publish()->lists('title', 'slug');
             if ($pages instanceof Arrayable) {
                 $pages = $pages->toArray();
             }
             $pages = array_merge(['_posts_' => 'Display Posts'], $pages);
             $fieldset->control('select', 'default_format')->label('Default Format')->options(StoryFormat::getParsers());
             $fieldset->control('select', 'default_page')->label('Default Page')->options($pages);
             $fieldset->control('text', 'Page Permalink', 'page_permalink');
             $fieldset->control('text', 'Post Permalink', 'post_permalink');
         });
     });
 }
Beispiel #7
0
 /**
  * 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}");
 }
Beispiel #8
0
 /**
  * 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;
     }
 }
Beispiel #9
0
 /**
  * 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"));
 }
Beispiel #10
0
 /**
  * Write a post.
  *
  * @param  \Orchestra\Story\Model\Content  $content
  *
  * @return mixed
  */
 protected function writePost(Content $content)
 {
     set_meta('title', 'Write a Post');
     $content->setAttribute('format', $this->editorFormat);
     return view('orchestra/story::admin.editor', ['content' => $content, 'url' => handles('orchestra::storycms/posts'), 'method' => 'POST']);
 }