예제 #1
0
 public function getFeaturedBlogPost()
 {
     $category = $this->getCategory();
     $tag = $this->getTag();
     $archive = $this->getArchive();
     if ($category) {
         $category = BlogCategory::get()->filter("URLSegment", $category)->first();
         return $category->BlogPosts()->filter("FeaturedPost", true)->first();
     }
     if ($tag) {
         $tag = BlogTag::get()->filter("URLSegment", $tag)->first();
         return $tag->BlogPosts()->filter("FeaturedPost", true)->first();
     }
     if ($archive) {
         return $this->owner->getArchivedBlogPosts($archive["Year"], $archive["Month"], $archive["Day"])->filter("FeaturedPost", true)->first();
     }
     return BlogPost::get()->filter("FeaturedPost", true)->first();
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function up()
 {
     //Migrate comma separated tags into BlogTag objects.
     foreach ($this->TagNames() as $tag) {
         $existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID));
         if ($existingTag->count()) {
             //if tag already exists we will simply add it to this post.
             $tagObject = $existingTag->First();
         } else {
             //if the tag is now we create it and add it to this post.
             $tagObject = new BlogTag();
             $tagObject->Title = $tag;
             $tagObject->BlogID = $this->ParentID;
             $tagObject->write();
         }
         if ($tagObject) {
             $this->Tags()->add($tagObject);
         }
     }
     //Store if the original entity was published or not (draft)
     $published = $this->IsPublished();
     // If a user has subclassed BlogEntry, it should not be turned into a BlogPost.
     if ($this->ClassName === 'BlogEntry') {
         $this->ClassName = 'BlogPost';
         $this->RecordClassName = 'BlogPost';
     }
     //Migrate these key data attributes
     $this->PublishDate = $this->Date;
     $this->AuthorNames = $this->Author;
     $this->InheritSideBar = true;
     //Write and additionally publish the item if it was published before.
     $this->write();
     if ($published) {
         $this->publish('Stage', 'Live');
         $message = "PUBLISHED: ";
     } else {
         $message = "DRAFT: ";
     }
     return $message . $this->Title;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function getCMSFields()
 {
     Requirements::css(BLOGGER_DIR . '/css/cms.css');
     Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
     $self =& $this;
     $this->beforeUpdateCMSFields(function ($fields) use($self) {
         $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image'));
         $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
         /**
          * @var FieldList $fields
          */
         $fields->insertAfter($uploadField, 'Content');
         $summary = HtmlEditorField::create('Summary', false);
         $summary->setRows(5);
         $summary->setDescription(_t('BlogPost.SUMMARY_DESCRIPTION', 'If no summary is specified the first 30 words will be used.'));
         $summaryHolder = ToggleCompositeField::create('CustomSummary', _t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'), array($summary));
         $summaryHolder->setHeadingLevel(4);
         $summaryHolder->addExtraClass('custom-summary');
         $fields->insertAfter($summaryHolder, 'FeaturedImage');
         $fields->push(HiddenField::create('MenuTitle'));
         $urlSegment = $fields->dataFieldByName('URLSegment');
         $urlSegment->setURLPrefix($self->Parent()->RelativeLink());
         $fields->removeFieldsFromTab('Root.Main', array('MenuTitle', 'URLSegment'));
         $authorField = ListboxField::create('Authors', _t('BlogPost.Authors', 'Authors'), $self->getCandidateAuthors()->map()->toArray())->setMultiple(true);
         $authorNames = TextField::create('AuthorNames', _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024)->setDescription(_t('BlogPost.AdditionalCredits_Description', 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.'));
         if (!$self->canEditAuthors()) {
             $authorField = $authorField->performDisabledTransformation();
             $authorNames = $authorNames->performDisabledTransformation();
         }
         $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
         $publishDate->getDateField()->setConfig('showcalendar', true);
         if (!$self->PublishDate) {
             $publishDate->setDescription(_t('BlogPost.PublishDate_Description', 'Will be set to "now" if published without a value.'));
         }
         // Get categories and tags
         $parent = $self->Parent();
         $categories = $parent instanceof Blog ? $parent->Categories() : BlogCategory::get();
         $tags = $parent instanceof Blog ? $parent->Tags() : BlogTag::get();
         $options = BlogAdminSidebar::create($publishDate, $urlSegment, TagField::create('Categories', _t('BlogPost.Categories', 'Categories'), $categories, $self->Categories())->setCanCreate($self->canCreateCategories())->setShouldLazyLoad(true), TagField::create('Tags', _t('BlogPost.Tags', 'Tags'), $tags, $self->Tags())->setCanCreate($self->canCreateTags())->setShouldLazyLoad(true), $authorField, $authorNames)->setTitle('Post Options');
         $options->setName('blog-admin-sidebar');
         $fields->insertBefore($options, 'Root');
     });
     $fields = parent::getCMSFields();
     $fields->fieldByName('Root')->setTemplate('TabSet_holder');
     return $fields;
 }