vars['postsTotal'] = Post::count(); $this->vars['postsPublished'] = Post::isPublished()->count(); $this->vars['postsDrafts'] = $this->vars['postsTotal'] - $this->vars['postsPublished']; $this->asExtension('ListController')->index(); } public function create() { BackendMenu::setContextSideMenu('new_post'); $this->bodyClass = 'compact-container'; $this->addCss('/plugins/rainlab/blog/assets/css/rainlab.blog-preview.css'); $this->addJs('/plugins/rainlab/blog/assets/js/post-form.js'); return $this->asExtension('FormController')->create(); } public function update($recordId = null) { $this->bodyClass = 'compact-container'; $this->addCss('/plugins/rainlab/blog/assets/css/rainlab.blog-preview.css'); $this->addJs('/plugins/rainlab/blog/assets/js/post-form.js'); return $this->asExtension('FormController')->update($recordId); } public function export() { $this->addCss('/plugins/rainlab/blog/assets/css/rainlab.blog-export.css'); return $this->asExtension('ImportExportController')->export(); } public function listExtendQuery($query) { if (!$this->user->hasAnyAccess(['rainlab.blog.access_other_posts'])) { $query->where('user_id', $this->user->id); } } public function formExtendQuery($query) { if (!$this->user->hasAnyAccess(['rainlab.blog.access_other_posts'])) { $query->where('user_id', $this->user->id); } } public function formExtendFieldsBefore($widget) { if (!$model = $widget->model) { return; } if ($model instanceof Post && $model->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel')) { $widget->secondaryTabs['fields']['content']['type'] = 'RainLab\Blog\FormWidgets\MLBlogMarkdown'; } if (BlogSettings::get('use_legacy_editor', false)) { $widget->secondaryTabs['fields']['content']['legacyMode'] = true; } } public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $postId) { if ((!$post = Post::find($postId)) || !$post->canEdit($this->user)) { continue; } $post->delete(); } Flash::success(Lang::get('rainlab.blog::lang.post.delete_success')); } return $this->listRefresh(); } /** * {@inheritDoc} */ public function listInjectRowClass($record, $definition = null) { if (!$record->published) { return 'safe disabled'; } } public function formBeforeCreate($model) { $model->user_id = $this->user->id; } public function onRefreshPreview() { $data = post('Post'); $previewHtml = Post::formatHtml($data['content'], true); return [ 'preview' => $previewHtml ]; } }