Skip to content

Commit ddf794e

Browse files
committed
fix: cleanup
1 parent c237bfd commit ddf794e

File tree

15 files changed

+545
-518
lines changed

15 files changed

+545
-518
lines changed

_config/legacy.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
SilverStripe\ORM\DatabaseAdmin:
22
classname_value_remapping:
3-
ForumThread_Subscription: SilverStripe\Forum\Model\ForumThreadSubscription
4-
ForumThread: SilverStripe\Forum\Model\ForumThread
5-
Forum: SilverStripe\Forum\Model\Forum
6-
ForumCategory: SilverStripe\Forum\Model\ForumCategory
7-
ForumHolder: SilverStripe\Forum\Model\ForumHolder
8-
ForumMemberProfile: SilverStripe\Forum\Model\ForumMemberProfile
3+
Post: FullscreenInteractive\SilverStripe\Forum\Model\Post
4+
ForumThread_Subscription: FullscreenInteractive\SilverStripe\Forum\Model\ForumThreadSubscription
5+
ForumThread: FullscreenInteractive\SilverStripe\Forum\Model\ForumThread
6+
Forum: FullscreenInteractive\SilverStripe\Forum\Model\Forum
7+
ForumCategory: FullscreenInteractive\SilverStripe\Forum\Model\ForumCategory
8+
ForumHolder: FullscreenInteractive\SilverStripe\Forum\Model\ForumHolder
9+
ForumMemberProfile: FullscreenInteractive\SilverStripe\Forum\Model\ForumMemberProfile
10+
SilverStripe\Forum\Model\Post: FullscreenInteractive\SilverStripe\Forum\Model\Post
11+
SilverStripe\Forum\Model\ForumThreadSubscription: FullscreenInteractive\SilverStripe\Forum\Model\ForumThreadSubscription
12+
SilverStripe\Forum\Model\ForumThread: FullscreenInteractive\SilverStripe\Forum\Model\ForumThread
13+
SilverStripe\Forum\Model\Forum: FullscreenInteractive\SilverStripe\Forum\Model\Forum
14+
SilverStripe\Forum\Model\ForumCategory: FullscreenInteractive\SilverStripe\Forum\Model\ForumCategory
15+
SilverStripe\Forum\Model\ForumHolder: FullscreenInteractive\SilverStripe\Forum\Model\ForumHolder
16+
SilverStripe\Forum\Model\ForumMemberProfile: FullscreenInteractive\SilverStripe\Forum\Model\ForumMemberProfile

client/css/Forum_CMS.css

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/* Styling for forum CMS fields */
22

3-
43
#ForumRefreshTime label.left {
5-
display: inline;
6-
float: none;
4+
display: inline;
5+
float: none;
76
}
87
#ForumRefreshTime input {
9-
width: 20px;
10-
padding: 0px;
11-
vertical-align: center;
8+
width: 20px;
9+
padding: 0px;
10+
vertical-align: center;
1211
}

docs/en/userguide/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ summary: Setting up and running forums on your website.
1313
* Learn how to administrate forum users.
1414

1515
## Before we begin
16-
Make sure that your SilverStripe installation has the [Forum](http://addons.silverstripe.org/add-ons/silverstripe/forum) module installed.
1716

1817
Make sure you are in the "Pages" section on the navigation tabs in the Content Management System backend (CMS) and you are on your "Forums" Forum Holder page. If you do not have a forum holder page, you can create one by clicking on the top level of your website in the CMS, or the page you would like the forum to be a subpage of, hitting the "Add New" button on the top of the pane. Choose "Forum Holder" from the list, and then press the "Create" button.
1918

2019
## Forum features
2120

2221
* [Set up a forum](set_up)
2322
* [Using the forum](using_forum)
24-
* [Forum administration](administration)
23+
* [Forum administration](administration)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace FullscreenInteractive\SilverStripe\Forum\Email;
4+
5+
use FullscreenInteractive\SilverStripe\Forum\Model\ForumThread;
6+
use FullscreenInteractive\SilverStripe\Forum\Model\Post;
7+
use SilverStripe\Control\Email\Email;
8+
use SilverStripe\Security\Member;
9+
10+
class ForumNotifyModeratorEmail extends Email
11+
{
12+
protected ?Post $post = null;
13+
14+
protected ?ForumThread $thread = null;
15+
16+
protected ?Member $moderator = null;
17+
18+
protected bool $startingThread = false;
19+
20+
public function setPost(Post $post): self
21+
{
22+
$this->post = $post;
23+
return $this;
24+
}
25+
26+
public function setThread(ForumThread $thread): self
27+
{
28+
$this->thread = $thread;
29+
return $this;
30+
}
31+
32+
public function setStartingThread(bool $startingThread): self
33+
{
34+
$this->startingThread = $startingThread;
35+
return $this;
36+
}
37+
38+
39+
public function setModerator(Member $moderator): self
40+
{
41+
$this->moderator = $moderator;
42+
return $this;
43+
}
44+
45+
46+
public function send(): void
47+
{
48+
if ($this->startingThread) {
49+
$this->setSubject('New thread "' . $this->thread->Title . '" in forum [' . $this->thread->Forum->Title . ']');
50+
} else {
51+
$this->setSubject('New post "' . $this->post->Title . '" in forum [' . $this->thread->Forum->Title . ']');
52+
}
53+
$this->setTemplate('ForumMember_NotifyModerator');
54+
$this->addData([
55+
'NewThread' => $this->startingThread,
56+
'Moderator' => $this->moderator,
57+
'Author' => $this->post->Author(),
58+
'Forum' => $this,
59+
'Post' => $this->post
60+
]);
61+
62+
parent::send();
63+
}
64+
}

src/Form/AdminActionsForm.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace FullscreenInteractive\SilverStripe\Forum\Form;
4+
5+
use FullscreenInteractive\SilverStripe\Forum\Model\ForumThread;
6+
use FullscreenInteractive\SilverStripe\Forum\PageTypes\Forum;
7+
use SilverStripe\Forms\Form;
8+
use SilverStripe\Forms\FieldList;
9+
use SilverStripe\Forms\CheckboxField;
10+
use SilverStripe\Forms\HiddenField;
11+
use SilverStripe\Forms\DropdownField;
12+
use SilverStripe\Forms\FormAction;
13+
use SilverStripe\Security\Security;
14+
15+
class AdminActionsForm extends Form
16+
{
17+
public function __construct($controller, $name)
18+
{
19+
20+
$fields = FieldList::create([
21+
CheckboxField::create('IsSticky', _t('Forum.ISSTICKYTHREAD', 'Is this a Sticky Thread?')),
22+
CheckboxField::create('IsGlobalSticky', _t('Forum.ISGLOBALSTICKY', 'Is this a Global Sticky (shown on all forums)')),
23+
CheckboxField::create('IsReadOnly', _t('Forum.ISREADONLYTHREAD', 'Is this a Read only Thread?')),
24+
HiddenField::create('ID', 'Thread')
25+
]);
26+
27+
if (($forums = Forum::get()) && $forums->exists()) {
28+
$fields->push(DropdownField::create(
29+
'ForumID',
30+
_t('Forum.CHANGETHREADFORUM', "Change Thread Forum"),
31+
$forums->map('ID', 'Title', 'Select New Category:'),
32+
'',
33+
null,
34+
'Select New Location:'
35+
));
36+
}
37+
38+
$actions = FieldList::create([
39+
FormAction::create('doAdminFormFeatures', _t('Forum.SAVE', 'Save'))
40+
]);
41+
42+
parent::__construct($controller, $name, $fields, $actions);
43+
}
44+
45+
46+
/**
47+
* Process's the moving of a given topic. Has to check for admin privileges,
48+
* passed an old topic id (post id in URL) and a new topic id
49+
*/
50+
public function doAdminFormFeatures($data, $form)
51+
{
52+
if (isset($data['ID'])) {
53+
$thread = ForumThread::get()->byID($data['ID']);
54+
55+
if ($thread) {
56+
if (!$thread->canModerate()) {
57+
return Security::permissionFailure($this);
58+
}
59+
60+
$form->saveInto($thread);
61+
$thread->write();
62+
}
63+
}
64+
65+
return $this->redirect($this->Link());
66+
}
67+
}

src/Form/PostMessageForm.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace FullscreenInteractive\SilverStripe\Forum\Form;
4+
5+
use SilverStripe\Forms\CheckboxField;
6+
use SilverStripe\Forms\FieldList;
7+
use SilverStripe\Forms\Form;
8+
use SilverStripe\Forms\HiddenField;
9+
use SilverStripe\Forms\TextareaField;
10+
use SilverStripe\Forms\TextField;
11+
use SilverStripe\Forms\FileField;
12+
use SilverStripe\Forms\FormAction;
13+
use SilverStripe\Forms\LiteralField;
14+
use FullscreenInteractive\SilverStripe\Forum\Model\Post;
15+
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
16+
use SilverStripe\Security\SecurityToken;
17+
18+
class PostMessageForm extends Form
19+
{
20+
protected ?Post $post = null;
21+
22+
public function __construct($controller, $name)
23+
{
24+
$fields = FieldList::create([
25+
TextField::create("Title", _t('Forum.FORUMTHREADTITLE', 'Title')),
26+
TextareaField::create("Content", _t('Forum.FORUMREPLYCONTENT', 'Content')),
27+
HiddenField::create('ThreadID', 'ThreadID'),
28+
HiddenField::create('ID', 'ID'),
29+
CheckboxField::create(
30+
"TopicSubscription",
31+
_t('Forum.SUBSCRIBETOPIC', 'Subscribe to this topic (Receive email notifications when a new reply is added)')
32+
)
33+
]);
34+
35+
if ($controller->data()->canAttach()) {
36+
$fields->insertAfter("Content", FileField::create("Attachment", _t('Forum.ATTACH', 'Attach file')));
37+
}
38+
39+
$actions = FieldList::create([
40+
FormAction::create("doPostMessageForm", _t('Forum.REPLYFORMPOST', 'Post'))
41+
]);
42+
43+
$required = RequiredFieldsValidator::create(["Title", "Content"]);
44+
45+
parent::__construct($controller, $name, $fields, $actions, $required);
46+
}
47+
48+
49+
public function setPost(Post $post)
50+
{
51+
$this->loadDataFrom($post);
52+
53+
$this->post = $post;
54+
55+
if (!$post->isFirstPost() || $post->ThreadID) {
56+
$this->fields->makeFieldReadonly('Title');
57+
}
58+
59+
if ($post->Attachments()->exists()) {
60+
$attachments = sprintf(
61+
"<div id=\"CurrentAttachments\"><h4>%s</h4><ul>",
62+
_t('Forum.CURRENTATTACHMENTS', 'Current Attachments')
63+
);
64+
65+
// An instance of the security token
66+
$token = SecurityToken::inst();
67+
68+
foreach ($post->Attachments() as $attachment) {
69+
// Generate a link properly, since it requires a security token
70+
$attachmentLink = $this->controller->Link('deleteattachment', $attachment->ID);
71+
$attachmentLink = $token->addToUrl($attachmentLink);
72+
73+
$attachments .= sprintf(
74+
"<li class='attachment-%d'>%s [<a href='%s' rel='%d' class='deleteAttachment'>%s</a>]</li>",
75+
$attachment->ID,
76+
$attachment->Name,
77+
$attachmentLink,
78+
$attachment->ID,
79+
_t('Forum.REMOVE', 'remove')
80+
);
81+
}
82+
83+
$attachments .= "</ul></div>";
84+
85+
$this->fields->push(LiteralField::create('CurrentAttachments', $attachments));
86+
}
87+
88+
return $this;
89+
}
90+
}

src/Model/ForumCategory.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
namespace FullscreenInteractive\SilverStripe\Forum\Model;
44

55
use SilverStripe\ORM\DataObject;
6-
use SilverStripe\Forms\FieldList;
7-
use SilverStripe\Forms\TextField;
8-
use SilverStripe\Forms\DropdownField;
96
use FullscreenInteractive\SilverStripe\Forum\PageTypes\Forum;
107
use FullscreenInteractive\SilverStripe\Forum\PageTypes\ForumHolder;
118

129
class ForumCategory extends DataObject
1310
{
1411
private static $table_name = 'ForumCategory';
1512

13+
private static string $singular_name = 'Forum Category';
14+
15+
private static string $plural_name = 'Forum Categories';
16+
17+
private static string $description = 'A category for forums';
18+
1619
private static $db = [
1720
'Title' => 'Varchar(100)',
18-
'StackableOrder' => 'Varchar(2)'
21+
'SortOrder' => 'Int'
1922
];
2023

2124
private static $has_one = [
@@ -26,27 +29,7 @@ class ForumCategory extends DataObject
2629
'Forums' => Forum::class
2730
];
2831

29-
30-
private static $default_sort = "\"StackableOrder\" DESC";
31-
32-
/**
33-
* Get the fields for the category edit/ add
34-
* in the complex table field popup window.
35-
*
36-
* @return FieldList
37-
*/
38-
public function getCMSFields_forPopup()
39-
{
40-
41-
// stackable order is a bit of a workaround for sorting in complex table
42-
$values = array();
43-
for ($i = 1; $i < 100; $i++) {
44-
$values[$i] = $i;
45-
}
46-
47-
return new FieldList(
48-
new TextField('Title'),
49-
new DropdownField('StackableOrder', 'Select the Ordering (99 top of the page, 1 bottom)', $values)
50-
);
51-
}
32+
private static $default_sort = [
33+
'SortOrder' => 'DESC'
34+
];
5235
}

src/Model/ForumThreadSubscription.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Psr\Log\LoggerInterface;
77
use SilverStripe\ORM\DataObject;
88
use SilverStripe\Security\Member;
9-
use SilverStripe\Security\Security;
109
use SilverStripe\Core\Injector\Injector;
1110
use FullscreenInteractive\SilverStripe\Forum\Model\Post;
1211
use FullscreenInteractive\SilverStripe\Forum\Email\ForumSubscriptionEmail;

0 commit comments

Comments
 (0)