Since I put in a feature to directly link to the forums directly from each style’s page, I’ve been finding that users assume that the forum will know which style they’re talking about. The two solutions to this are to convince the user otherwise or to make the assumption true. I’ve gone for the latter.
Now, whenever users click on the forum link on style pages and then actually create a discussion thread, the forum will store the ID of the style they came from and display it in various useful places. Here’s how I did it.
First, I created a new column in LUM_Discussions called “StyleID”. This is either 0 (meaning the discussion isn’t about a style) or the ID of an existing style. The styles table has an id field and a short_description field.
Here’s a quick overview of what the code changes do. The site includes a style parameter in the forum link. The forum takes this parameter and puts it in a hidden input field. When the user posts the new discussion, the forum reads this style ID and stores it with the other discussion data. When the forum displays that discussion, it’ll look up the style’s short description and display it along with the discussion title entered by the user.
Below are diffs with explanations as to why there was a change. A full diff is available at the bottom.
Vanilla stores all database table and column names in a configuration file. Here I added the names I used.
diff -r forum.old/appg/database.php forum/appg/database.php
150c150,157
< ?>
\ No newline at end of file
---
>
> //userstyles.org customization
> $DatabaseTables['styles'] = 'styles';
> $DatabaseColumns['Discussion']['StyleID'] = 'StyleID';
> $DatabaseColumns['styles']['id'] = 'id';
> $DatabaseColumns['styles']['short_description'] = 'short_description';
>
> ?>
Vanilla assumes that most tables start with “LUM_”. I had to tell it that my styles table didn’t have this prefix.
diff -r forum.old/library/Framework/Framework.Functions.php forum/library/Framework/Framework.Functions.php
519c519,520
< if ($Key == "User") {
---
> //userstyles.org customization
> if ($Key == "User" or $Key == "styles") {
817c818
< ?>
\ No newline at end of file
---
> ?>
I needed to tell Vanilla to pull in StyleID and StyleName (from short_description) when reading a discussion from the database.
diff -r forum.old/library/Vanilla/Vanilla.Class.DiscussionManager.php forum/library/Vanilla/Vanilla.Class.DiscussionManager.php
43c43,44
< $s->AddSelect(array('DiscussionID', 'FirstCommentID', 'AuthUserID', 'WhisperUserID', 'Active', 'Closed', 'Sticky', 'Sink', 'Name', 'DateCreated', 'LastUserID', 'DateLastActive', 'CountComments', 'CategoryID'), 't');
---
> //XXX userstyles.org customization
> $s->AddSelect(array('DiscussionID', 'FirstCommentID', 'AuthUserID', 'WhisperUserID', 'Active', 'Closed', 'Sticky', 'Sink', 'Name', 'DateCreated', 'LastUserID', 'DateLastActive', 'CountComments', 'CategoryID', 'StyleID'), 't');
51a53,56
>
> //XXX userstyles.org customization
> $s->AddJoin('styles', 'st', 'id', 't', 'StyleID', 'left join');
> $s->AddSelect('short_description', 'st', 'StyleName');
Also when reading a list of discussions.
456a462,463
> //XXX userstyles.org customization
> $s->AddFieldNameValue('StyleID', $Discussion->StyleID);
522c529
< ?>
\ No newline at end of file
---
> ?>
I had to add the ID and name to the discussion class.
diff -r forum.old/library/Vanilla/Vanilla.Class.Discussion.php forum/library/Vanilla/Vanilla.Class.Discussion.php
44a45,47
> //XXX userstyles.org customization
> var $StyleID;
> var $StyleName;
77a81,83
> //XXX userstyles.org customization
> $this->StyleID = 0;
> $this->StyleName = 0;
104a111,113
> //XXX userstyles.org customization
> $this->StyleID = @$DataSet['StyleID'];
> $this->StyleName = @$DataSet['StyleName'];
179a189,190
When saving a style, I told it to read the StyleID parameter.
> //XXX userstyles.org customization
> $this->StyleID = ForceIncomingInt('StyleID', 0);
221c232
< ?>
\ No newline at end of file
---
> ?>
I included a link back to the style on the discussion page if there was a style for this discussion.
diff -r forum.old/themes/comments.php forum/themes/comments.php
21a22,25
> //XXX userstyles.org customization
> if ($this->Discussion->StyleID > 0) {
> $CommentList .= '<a href="/styles/'.$this->Discussion->StyleID.'">'.htmlspecialchars($this->Discussion->StyleName).'</a>: ';
> }
150c154
< ?>
\ No newline at end of file
---
> ?>
I got it to take the style parameter that the site appends to the forum link and put it in a hidden field called StyleID.
diff -r forum.old/themes/discussion_form.php forum/themes/discussion_form.php
8a9
> .'<input type="hidden" name="StyleID" value="'.htmlspecialchars(array_key_exists('style', $_GET) ? $_GET['style'] : '').'"/>' //XXX userstyles.org customization
73c74
< ?>
\ No newline at end of file
---
> ?>
I included the name of the style in the discussion list, if there is one.
diff -r forum.old/themes/discussion.php forum/themes/discussion.php
9a10
> //XXX userstyles.org customization
17c18
< <span>'.$this->Context->GetDefinition('DiscussionTopic').'</span><a href="'.$UnreadUrl.'">'.$Discussion->Name.'</a>
---
> <span>'.$this->Context->GetDefinition('DiscussionTopic').'</span><a href="'.$UnreadUrl.'">'.($Discussion->StyleID == 0 ? '' : htmlspecialchars($Discussion->StyleName).': ').$Discussion->Name.'</a>
53c54
< ?>
\ No newline at end of file
---
> ?>
Full diff:
diff -r forum.old/appg/database.php forum/appg/database.php
150c150,157
< ?>
\ No newline at end of file
---
>
> //userstyles.org customization
> $DatabaseTables['styles'] = 'styles';
> $DatabaseColumns['Discussion']['StyleID'] = 'StyleID';
> $DatabaseColumns['styles']['id'] = 'id';
> $DatabaseColumns['styles']['short_description'] = 'short_description';
>
> ?>
diff -r forum.old/library/Framework/Framework.Functions.php forum/library/Framework/Framework.Functions.php
519c519,520
< if ($Key == "User") {
---
> //userstyles.org customization
> if ($Key == "User" or $Key == "styles") {
817c818
< ?>
\ No newline at end of file
---
> ?>
diff -r forum.old/library/Vanilla/Vanilla.Class.DiscussionManager.php forum/library/Vanilla/Vanilla.Class.DiscussionManager.php
43c43,44
< $s->AddSelect(array('DiscussionID', 'FirstCommentID', 'AuthUserID', 'WhisperUserID', 'Active', 'Closed', 'Sticky', 'Sink', 'Name', 'DateCreated', 'LastUserID', 'DateLastActive', 'CountComments', 'CategoryID'), 't');
---
> //XXX userstyles.org customization
> $s->AddSelect(array('DiscussionID', 'FirstCommentID', 'AuthUserID', 'WhisperUserID', 'Active', 'Closed', 'Sticky', 'Sink', 'Name', 'DateCreated', 'LastUserID', 'DateLastActive', 'CountComments', 'CategoryID', 'StyleID'), 't');
51a53,56
>
> //XXX userstyles.org customization
> $s->AddJoin('styles', 'st', 'id', 't', 'StyleID', 'left join');
> $s->AddSelect('short_description', 'st', 'StyleName');
456a462,463
> //XXX userstyles.org customization
> $s->AddFieldNameValue('StyleID', $Discussion->StyleID);
522c529
< ?>
\ No newline at end of file
---
> ?>
diff -r forum.old/library/Vanilla/Vanilla.Class.Discussion.php forum/library/Vanilla/Vanilla.Class.Discussion.php
44a45,47
> //XXX userstyles.org customization
> var $StyleID;
> var $StyleName;
77a81,83
> //XXX userstyles.org customization
> $this->StyleID = 0;
> $this->StyleName = 0;
104a111,113
> //XXX userstyles.org customization
> $this->StyleID = @$DataSet['StyleID'];
> $this->StyleName = @$DataSet['StyleName'];
179a189,190
> //XXX userstyles.org customization
> $this->StyleID = ForceIncomingInt('StyleID', 0);
221c232
< ?>
\ No newline at end of file
---
> ?>
diff -r forum.old/themes/comments.php forum/themes/comments.php
21a22,25
> //XXX userstyles.org customization
> if ($this->Discussion->StyleID > 0) {
> $CommentList .= '<a href="/styles/'.$this->Discussion->StyleID.'">'.htmlspecialchars($this->Discussion->StyleName).'</a>: ';
> }
150c154
< ?>
\ No newline at end of file
---
> ?>
diff -r forum.old/themes/discussion_form.php forum/themes/discussion_form.php
8a9
> .'<input type="hidden" name="StyleID" value="'.htmlspecialchars(array_key_exists('style', $_GET) ? $_GET['style'] : '').'"/>' //XXX userstyles.org customization
73c74
< ?>
\ No newline at end of file
---
> ?>
diff -r forum.old/themes/discussion.php forum/themes/discussion.php
9a10
> //XXX userstyles.org customization
17c18
< <span>'.$this->Context->GetDefinition('DiscussionTopic').'</span><a href="'.$UnreadUrl.'">'.$Discussion->Name.'</a>
---
> <span>'.$this->Context->GetDefinition('DiscussionTopic').'</span><a href="'.$UnreadUrl.'">'.($Discussion->StyleID == 0 ? '' : htmlspecialchars($Discussion->StyleName).': ').$Discussion->Name.'</a>
53c54
< ?>
\ No newline at end of file
---
> ?>