Posted by: tommy382 - Saturday, 5 February 2011 13:48:32
As promised, this is how I implement the hidden bbcode. What this tag does is it hides the content inside from the viewer until the viewer THANK the topic starter. If the viewer is an admin or the topic starter himself, the content is not hidden.
To see a sample topic with this bbcode in action, go [url=http://forum.tkaraoke.com/tkf_postst2769_BBCode-hidden.aspx]here[/url].
Here is the code modification.
[code=csharp] public static string FormatMessage([NotNull] string message, [NotNull] MessageFlags messageFlags, bool targetBlankOverride, DateTime messageLastEdited)
{
...
// do html damage control
message = RepairHtml(message, messageFlags.IsHtml);
//Process hidden tag replacement. - //Tommy
{
bool isUserAdmin = YafContext.Current.IsAdmin;
Match hiddenTagMatch = _rgxHidden.Match(message);
if (hiddenTagMatch.Success)
{
Group hiddenContent = hiddenTagMatch.Groups["hiddencontent"];
//TODO: Get "shownContent" from configuration so an admin can change w/o recompiling.
string shownContent = "
" +
"
" +
"The content of this page is hidden. After you THANK the poster, refresh the page to see the hidden content. You only need to thank the first post (post #1).
" +
"Phần nội dung đã bị ẩn đi. Sau khi nhấn vào nút THANK để cám ơn người đăng bài này, bạn phải Refresh trang này lại để thấy nội dung. Bạn chỉ cần THANK post đầu tiên (post #1 ở trang 1)." +
"
";
if (isUserAdmin)
{
shownContent = hiddenContent.Value;
}
else if (YafContext.Current.User != null &&
YafContext.Current.User.IsApproved)
{
int userId = YafContext.Current.CurrentUserData.UserID;
int topicId = YafContext.Current.PageTopicID;
if ((GetTopicStarter(topicId) == userId) ||
(IsUserThankedTopicStarter(topicId, userId)))
{
//Show hiddent content if user is the poster or have thanked the poster.
shownContent = hiddenContent.Value;
}
}
//Update the hidden content with the updated content.
message = _rgxHidden.Replace(message, shownContent);
}
}
...[/code]
[code=csharp] public static int GetTopicStarter(int topicId) //Tommy
{
try
{
string query = "SELECT UserID FROM yaf_Topic WHERE TopicID=" + topicId;
using (var cmd = new System.Data.SqlClient.SqlCommand(query))
{
cmd.CommandType = CommandType.Text;
int userId = (int)YafDBAccess.Current.ExecuteScalar(cmd);
return userId;
}
}
catch (Exception)
{
return -1;
}
}[/code]
[code=csharp] public static bool IsUserThankedTopicStarter(int topicId, int userId) //Tommy
{
System.Text.StringBuilder querySb =
new System.Text.StringBuilder();
querySb.Append("SELECT COUNT(TH.ThanksID) ");
querySb.Append("FROM yaf_Message AS M INNER JOIN ");
querySb.Append("yaf_Topic AS T ON M.TopicID = T.TopicID INNER JOIN ");
querySb.Append("yaf_Thanks AS TH ON M.MessageID = TH.MessageID ");
querySb.Append("WHERE (T.TopicID = {0}) AND (M.Position = 0) AND (TH.ThanksFromUserID = {1})");
string query = string.Format(querySb.ToString(),
topicId, userId);
using (var cmd = new System.Data.SqlClient.SqlCommand(query))
{
cmd.CommandType = CommandType.Text;
int thankCount = (int)YafDBAccess.Current.ExecuteScalar(cmd);
return (thankCount > 0);
}
}[/code]
[code=csharp] ///
/// The regular expression to process [hidden]...[/hidden]
///
private static readonly Regex _rgxHidden =
new Regex(@"\[hidden\](?(.*?))\[/hidden\]", _options |
RegexOptions.Singleline | RegexOptions.Compiled); //Tommy[/code]
Posted by: Jaben - Tuesday, 8 February 2011 13:35:13
There is a custom BBCode module system for this type of modification. Not sure why you wanted to hard-code this code into YAF.
Posted by: tommy382 - Thursday, 10 February 2011 03:00:03
This code was added in before 1.9.5. Are you saying with 1.9.5 I can add a new bbcode like the above via the admin interface w/o adding any code? How?
Posted by: tha_watcha - Thursday, 10 February 2011 11:38:42
[quote=tommy382;46637]This code was added in before 1.9.5. Are you saying with 1.9.5 I can add a new bbcode like the above via the admin interface w/o adding any code? How?[/quote]
The BBCode Extensions are included in YAF for a very long time.
Go to Admin -> Settings -> BB Code Extensions. Take a look at the existing items how its done, in your case you need to use "Use Module:Use server-side module (class) instead of replace regex?". take a look at the SPOILER Tag, and the SpoilerBBCodeModule.cs in the Modules Folder.
Posted by: tha_watcha - Sunday, 20 March 2011 21:00:10
@tommy382
I am currently testing your mod, i converted it to a bbcode extension module. Also i made to bbcode out of it
[code=plain]
[HIDDEN]...[HIDDEN]
[/code]
and
[code=plain]
[HIDDEN=123]...[HIDDEN]
[/code]
Where you can specify the postid to directly use the current post as thank.
But i found some issues. For Example when you use the Quote on a Hidden Post, the hidden content is exposed. Also on the RSS Feed.
But i already working on it. Maybe i add it directly in yaf ?!
Posted by: tommy382 - Wednesday, 23 March 2011 02:35:14
There is another piece of code that return a constant "You can't quote a post with the hidden tag." I'll post that code when I get home. I'm not sure about RSS. Maybe RSS is also using the same "Format" method that the to-be-posted code already handled?
You can test the quote logic [url=http://forum.tkaraoke.com/tkf_postst2967_Ca-Dao-Karaoke-17---Hai-Chuyen-Tau-Dem-Iso.aspx]here[/url].
Posted by: tha_watcha - Tuesday, 29 March 2011 15:08:34
[quote=tommy382;47753]There is another piece of code that return a constant "You can't quote a post with the hidden tag." I'll post that code when I get home. I'm not sure about RSS. Maybe RSS is also using the same "Format" method that the to-be-posted code already handled?
You can test the quote logic [url=http://forum.tkaraoke.com/tkf_postst2967_Ca-Dao-Karaoke-17---Hai-Chuyen-Tau-Dem-Iso.aspx]here[/url].[/quote]
I completed my code now, its fully committed to svn. The hidden tag now uses automatically the current message id, you now can use this bbcode in any posting.
the hidden content in a reply and in the rss feed will be completly removed.
Posted by: bbobb - Tuesday, 29 March 2011 18:06:13
It would be interesting to link this to access types too. Hopefully, it works when thanks are disabled.
A useful feature in general usage.
Posted by: tha_watcha - Tuesday, 29 March 2011 18:16:12
[quote=bbobb;47939]It would be interesting to link this to access types too. Hopefully, it works when thanks are disabled.
A useful feature in general usage.[/quote]
No its currently not working when the thanks feature is disabled.
I think the only solution would be if disabled just show the hidden content.
Posted by: tommy382 - Wednesday, 30 March 2011 10:36:15
Nice work [userlink]tha_watcha[/userlink] [thumbup]. Showing the content when THANKS is disabled make sense.
By the way, did you have to put the code to remove the hidden content in RSS and REPLY or both of these call the same "format message" function so taking care of one case will automatically take care of the other? I don't use RSS ever so I have never tested my forum on RSS - if there is a backdoor to see the hidden content w/o thanking via the RSS, I want to patch up that back door.
Another backdoor: UNDO THANK
1. User X thanks Poster Y
2. User X saw the hidden content
3. User X undo thank on Poster Y
I had to manually disable undo thank in the code but would be nice to have an option to "disable undo thank" in the admin interface.
Posted by: tha_watcha - Wednesday, 30 March 2011 11:07:07
[quote]By the way, did you have to put the code to remove the hidden content in RSS and REPLY or both of these call the same "format[/quote]
Yes i do.
[code=csharp]
// Remove HIDDEN Text
message = this.Get().RemoveHiddenBBCodeContent(message);
[/code]
Another Backdoor was the printtopic page, i also use the code above there.
[quote]Another backdoor: UNDO THANK
1. User X thanks Poster Y
2. User X saw the hidden content
3. User X undo thank on Poster Y
I had to manually disable undo thank in the code but would be nice to have an option to "disable undo thank" in the admin interface.[/quote]
Not sure if this really a problem if a user removes the thank it shows the hidden image again.
Posted by: tommy382 - Wednesday, 30 March 2011 17:34:01
[quote=tha_watcha;47998]Not sure if this really a problem if a user removes the thank it shows the hidden image again.
[/quote]
Normally the poster want to know how popular a particular hidden content is. Having "undo thanks" make it possible for someone not on the "thanks list" to view the hidden content.
Posted by: juju - Monday, 6 June 2011 14:31:24
[quote=tha_watcha;47934]
I completed my code now, its fully committed to svn. The hidden tag now uses automatically the current message id, you now can use this bbcode in any posting.
the hidden content in a reply and in the rss feed will be completly removed.
[/quote]
i dowloaded the HideBBCodeModule.cs from the svn to try and implement this. I walked through this and downloaded other related modified files like the LegacyDb.cs. Unfortunately I have an error that I do not know how to fix:
'YAF.Modules.BBCode.HideBBCodeModule' does not contain a definition for 'MessageID' and no extension method 'MessageID' accepting a first argument of type 'YAF.Modules.BBCode.HideBBCodeModule' could be found (are you missing a using directive or an assembly reference?)
[code=csharp]
protected override void Render(HtmlTextWriter writer)
{
var hiddenContent = Parameters["inner"];
var messageId = this.MessageID;
if (hiddenContent.IsNotSet())
{
return;
}
[/code]
Please help
Thank you
Posted by: tha_watcha - Monday, 6 June 2011 14:39:13
You need to download all file from svn and recompile all projects, i modified multiple files when i add this bbcode.
Posted by: juju - Monday, 6 June 2011 14:51:55
Thank you for the reply, I realized it now as I step into each error. I got it up and running and about to test the hidden post feature. Nice job!
Posted by: juju - Tuesday, 7 June 2011 03:51:56
there seems to be an error in the YafNntp.cs
Error 66 'YAF.Classes.Data.LegacyDb' does not contain a definition for 'NntpForumList' F:\YafSvn\YAF.Core\Nntp\YafNntp.cs 130 44 YAF.Core
[code=csharp]
try
{
this._applicationStateBase["WorkingInYafNNTP"] = true;
// Only those not updated in the last 30 minutes
foreach (var nntpForum in LegacyDb.NntpForumList(boardID, lastUpdate, null, true))
{
[/code]
maybe somebody committed a code a forgot to create this? I looked at LegacyDb.cs and indded there isn't any property declared for it.
Posted by: Jaben - Wednesday, 8 June 2011 06:11:29
[quote=juju;50070]there seems to be an error in the YafNntp.cs
Error 66 'YAF.Classes.Data.LegacyDb' does not contain a definition for 'NntpForumList' F:\YafSvn\YAF.Core\Nntp\YafNntp.cs 130 44 YAF.Core
[code=csharp]
try
{
this._applicationStateBase["WorkingInYafNNTP"] = true;
// Only those not updated in the last 30 minutes
foreach (var nntpForum in LegacyDb.NntpForumList(boardID, lastUpdate, null, true))
{
[/code]
maybe somebody committed a code a forgot to create this? I looked at LegacyDb.cs and indded there isn't any property declared for it.[/quote]
Fixed in the latest commit.
Posted by: juju - Friday, 17 June 2011 05:03:52
[quote=tommy382;47996]
I had to manually disable undo thank in the code but would be nice to have an option to "disable undo thank" in the admin interface.[/quote]
Im trying to do the same (disable undo thank). Could you share your code revisions? Im looking at JavaScriptBlock.cs, YafAjax.cs, DisplayPost.ascx.cs and LegacyDb.cs but still feeling my way wherre to start.
Thank you
Posted by: juju - Friday, 17 June 2011 06:50:26
Got it. If anybody is interested:
Just a crude work around, I edited DisplayPost.ascx.cs line:
[code=csharp]
const string RemoveThankBoxHTML =
"'|'";
[/code]
then i created a css class with display:none
Posted by: juju - Sunday, 19 June 2011 11:41:58
Theres a small setback though, if i try to refesh the page, it will show the "remove thanks" button again. Any help would be appreciated.