tommy382
  • Posts: 91
  • Joined: 11/04/2008
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 here .

Here is the code modification.
    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 = "<div class='Warning'style='width:670px;'>" +
            "<div style='float:right; padding-top:10px;'><img src='http://forum.tkaraoke.com/images/ThankYouPost.png' /></div>" +
            "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).<br /><br />" +
            "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 <span style='text-decoration:underline; font-weight:bold;'>post đầu tiên</span> (post #1 ở trang 1)." +
            "</div>";
          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);
        }
      }
...

    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;
      }
    }


    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);
      }
    }

    /// <summary>
    /// The regular expression to process [hidden]...[/hidden]
    /// </summary>
    private static readonly Regex _rgxHidden =
      new Regex(@"\[hidden\](?<hiddencontent>(.*?))\[/hidden\]", _options |
        RegexOptions.Singleline | RegexOptions.Compiled);  //Tommy
Sponsor
Jaben
  • Posts: 2544
  • Joined: 09/10/2004
There is a custom BBCode module system for this type of modification. Not sure why you wanted to hard-code this code into YAF.
tommy382
  • Posts: 91
  • Joined: 11/04/2008
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?
tha_watcha
  • Posts: 4081
  • Joined: 06/03/2010
Originally Posted by: tommy382

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?



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.

UserPostedImage
tha_watcha
  • Posts: 4081
  • Joined: 06/03/2010
@tommy382

I am currently testing your mod, i converted it to a bbcode extension module. Also i made to bbcode out of it


[HIDDEN]...[HIDDEN]


and


[HIDDEN=123]...[HIDDEN]


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 ?!
tha_watcha attached the following image(s):

UserPostedImage
tommy382
  • Posts: 91
  • Joined: 11/04/2008
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 here .
tha_watcha
  • Posts: 4081
  • Joined: 06/03/2010
Originally Posted by: tommy382

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 here .



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.


UserPostedImage
bbobb
  • Posts: 1558
  • Joined: 21/10/2008
It would be interesting to link this to access types too. Hopefully, it works when thanks are disabled.
A useful feature in general usage.
tha_watcha
  • Posts: 4081
  • Joined: 06/03/2010
Originally Posted by: bbobb

It would be interesting to link this to access types too. Hopefully, it works when thanks are disabled.
A useful feature in general usage.



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.
UserPostedImage
tommy382
  • Posts: 91
  • Joined: 11/04/2008
Nice work  tha_watcha 👍. 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.
tha_watcha
  • Posts: 4081
  • Joined: 06/03/2010
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



Yes i do.

 
// Remove HIDDEN Text
message = this.Get<IFormatMessage>().RemoveHiddenBBCodeContent(message);


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.



Not sure if this really a problem if a user removes the thank it shows the hidden image again.

UserPostedImage
tha_watcha
  • Posts: 4081
  • Joined: 06/03/2010
You need to download all file from svn and recompile all projects, i modified multiple files when i add this bbcode.
UserPostedImage
juju
  • Posts: 35
  • Joined: 05/09/2009
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!
hmmmm.... click thanks if my posts are useful
juju
  • Posts: 35
  • Joined: 05/09/2009
Originally Posted by: tommy382



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.



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
hmmmm.... click thanks if my posts are useful
juju
  • Posts: 35
  • Joined: 05/09/2009
Got it. If anybody is interested:

Just a crude work around, I edited DisplayPost.ascx.cs line:


const string RemoveThankBoxHTML =
            "'<a class=\"yaflittlebutton\" href=\...


with:

const string RemoveThankBoxHTML =
            "'<a class=\"yafhiddenbutton\">|</a>'";


then i created a css class with display:none
hmmmm.... click thanks if my posts are useful
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved