Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Adding time stamps to quotes

I've been trying to add a timestamp to quotes, but I'm not sure how to add the timestamp in a way that will be correct across time zones. Right now it gets the timezone of the comment relative to the person who is clicking on the quote button, then that becomes hard coded along with the rest of the comment in the DB.

This is in plugins\Quotes\class.quotes.plugin.php, line 474:

$DateInserted = strtotime($Data->DateInserted); //Get the date the post was created $QuoteBody = $Data->Body; $Quote = '> Posted by '.sprintf(t('%s '), '@'.$Data->InsertName)." (".date("M d, Y", $DateInserted).' at '.date("g:i A", $DateInserted + 7200).") > \n". //Add timestamp and name of author '> '.str_replace("\n", "\n> ", $QuoteBody)."\n";

I suppose I need to add the date in as a tag or some sorts that gets rendered later?
Any advice from master Vanilla Jedi would be most appreciated.

Comments

  • R_JR_J Admin

    Sounds like a nice idea and like a very complex idea...

    I would say it is only possible when there is a direct reference to to quoted posing made in the moment when I click the quote button. By now a quote looks like that:


    The JavaScript that does this has to be extended so that it inserts some extra information


    In principal it could be shortened to


    While this will look all right after it has been posted, it looks ugly to the user who does the quoting.

    If you are okay with the solution above, you could either parse postings before they are rendered for time tags and use Gdn_Format::date() in order to render the time based on the users local settings or you could use a JavaScript like timeago. That does even exist as a Vanilla plugin so you might not even need to do anything more after you have made the quote button to include the time.

    If you are using BBCode you could try to use a custom BBCode like [quote="user" discussion="123"] or [quote="user" comment="321"]. Whenever that is parsed you could grab the date of the quoted posting.

    And for markdown you could build a link to that quoted posting, but that would look quite ugly.

    You could also try to add the post with a custom "html" tag <span data-type"d" data-id="123" /> or <span data-reference="c321">

    But I would prefer the html time tag since that is at least a little bit of a standard


    But all of that would result in something which looks quite ugly to the quoting user and would need changes made to the quote plugins js file.

    Vanillas easy way to display a localized time is Gdn_Format::date() method.

  • Thank you very much @R_J

    I found the timeago plugin here. I don't think I'll use it now, but timeago.js is very nice and the html time tag is a great idea. I'm using markup though, so I'll have to dig deeper to figure that out too.

    Where is the best place to use Gdn_Format::date()? I suppose I could use it in my theme hooks file, but it's not really a theme thing.

  • @RodSloan said:
    Where is the best place to use Gdn_Format::date()? ...

    Maybe in theme/views//discussion.php is better. I'll try it out anyway.

  • R_JR_J Admin

    No, don't do it in a view. If you want this to happen as part of a custom theme, you would have to use a themehooks file.

    But I think that idea is so nice, that you should make it a plugin which can be used by anybody.

    How much support do you want?

    I'd be happy to provide you with a solution for the PHP part and might give hints to the JS part as well. In order not to reveal too much, I just start with a ominous hint: find out more about the AfterCommentFormat event. It is the answer to your question ;)

    Just drop a note if you need more support.

  • I'd love to make it a plugin! I've got a lot to learn though, so I'd be very happy for your help.

    I found this discussion that mentions using AfterCommentFormat. I'll play around with it and see what I come up with.

  • So at the moment I'm trying to figure out how to stop my <time> tags from being stripped out in Markdown.

  • R_JR_J Admin

    I have no time to investigate further on that, but I would assume that it is HtmLawed which is stripping the time tags.

    As far as I understand Markup, it shouldn't change any HTML at all.

    And in Vanilla HtmLawed is used for sanitizing HTML output. I would search for a white list for tags which might be set for HtmLawed

Sign In or Register to comment.