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.
How to always show full date of posting (publishing date as required by Google's Data Highlighter)?
MasterOne
✭✭
I've been playing around with the Data Highlighter function in Google's Webmaster Center, and found out that that auto-tagging of forum discussions as Articles fails because it can not identify the publishing date, which looks like this:
Is there an easy way to always show the full date of posting (like "31 July 2014") at least in the initial posting of a discussion?
I'm on Vanilla 2.1 using a modified default template.
0
Comments
Don't know if there is a more easy way, but you can add a custom function to your /bootstrap.php:
@R_J, can you please explain that in more details?
I've taken a look, the function
FormatDateCustom
doesn't exist, but is checked on inlibrary/core/class.format.php
. I don't really know what to return with aFormatDateCustom
function added tobootstrap.php
, but it seems the formating magic takes place inlibrary/core/class.format.php
inpublic static function Date($Timestamp = '', $Format = '')
The part applying the different formating checks if
$Format
is set, so I think it's not set when called, because it then formats the date differently based on how long ago it's been posted in that function if$Format
is empty.Where could the application's default format be set, so that it's used by that function?
@manisso, no idea what your comment means.
Weil's schnell gehen muss kurz auf Deutsch:
Die bootstrap wird vor allem anderen ausgeführt. Wenn du dort eine Funktion anlegst, ist sie für das gesamte Framework verfügbar.
Die Stelle die du gefunden hast, an der diese Funktion abgefragt wird, überprüft, ob es diese Funktion gibt. Wenn ja, wird sie aufgerufen, damit sie die Ausgabensteuerung übernimmt. Wenn nein, macht die Standard Funktion weiter.
Du musst also eine Funktion schreiben, die das Datum so ausgibt, wie du es brauchst. Es wird ein Timstamp übergeben. Ich glaube, mit der php Funktion date() kannst du ein Format ausgeben. Statt "Whatever..." muss also so was wie return(date($Timestamp, 'd.m.Y' )); dort stehen, aber da musst du leider selber weiter nachgoogeln (Ich kann immer gerade genug PHP um mich von einem zum nächsten Schritt zu hangeln )
Der Befehlt strftime ist auch ein spannender Ansatz, denke ich. Der soll Zeiten in lokalem Format ausgeben. Das lokale Format sollte übrigens auch in der Übersetzungsdatei stehen. Vielleicht nimmst du also statt 'd.m.y' den config Wert Gdn::Config('Garden.WieAuchImmerDasLokaleZeitFormatHeißt')
Du musst ggf. auch noch eine Fehlerprüfung implementieren.
Leider bin ich jetzt erst mal eine Weile vom Rechner, aber da findet sich bestimmt jemand, der dir weiterhilft - viel Glück!
data format are set in locale no need for custom functions.
grep is your friend.
Still, something is missing here, because
$Format
seems to be empty whenpublic static function Date($Timestamp = '', $Format = '')
is called inlibrary/core/class.format.php
, otherwise that code-block formating the posting date depending on the time that has passed since posting would not come into action.I'm sure @R_J's approach would work, but there should be an easier solution already in place, hence the check if
$Format
is empty or not and the hint that it defaults to the application's default format (although it seems to be empty anyway).Is this something that should be configuarable in
config.php
?it is not set in config.php is is set in locale
you can put this in conf/locale.php
and format based on this
http://php.net/manual/en/function.strftime.php
grep is your friend.
what x00 said is the way to do it.
if you want the time to show on a post for the day as well as dd-mm-yyyy
9:38AM 31-07-2014
and dd-mm-yyyy for posts that are not current day.
31-07-2014
or
if you want the time to show on a post for the current day as well as dd-mm-yyyy
31-Jul-2014 (9:38AM)
and dd-mm-yyyy for posts that are not current day.
31-Jul-2014
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Off-Topic
Does this mean "no longer searching"? I have only basic German understanding, but I love this word, whatever it means.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
It is from "etwas nachgucken" which means "to look something up". You certainly know "to google for something" as a synonym for look something up on the net and that is nachgoogeln
It is from "etwas nachgucken" which means "to look something up". You certainly know "to google for something" as a synonym for look something up on the net and that is nachgoogeln
What I love in the German language is the freedom you have when creating words. It's absolutely okay to combine nearly arbitrary words - although it's not always good style. One "famous" example that nearly every German knows is "Donaudampfschifffahrtskapitän" and what you can make of it. Rough translation would be Danube-steamboat-shipping-captain. I've even found an Englisch Wikipedia entry based on that.
As I said before, that often is simply lazy and bad style bad it makes it quite easy to talk in expressive pictures.
Nevertheless I really love the sound of British English. I've seen Macbeth at least 4 times in original language and I would visit that play at the next chance again without hesitation. Just the sound of that line alone... "Fair is foul, and foul is fair, hover through the fog and filthy air"
Well, those definitions in
conf/locale.php
do exactly what they are supposed to, but that solution has a negative side effect, it influences the whole system, even the display in the "In this Discussion" and "Who's Online" side-column boxes.The desired setting to work with Google's Data Highlighter would be something like this:
but that messes up the display in the "In this Discussion" and "Who's Online" side-column boxes, with entries getting wrapped into two lines depending on length of member name.
For the Google Data Highlighter to work it would be enough if only the publishing date in the initial posting of a discussion would be shown in the desired format (%e %B %Y).
No idea how this could be solved. Any more ideas?
That is the line in the code where the output of the discussions date is made: https://github.com/vanilla/vanilla/blob/2.1/applications/vanilla/views/discussion/discussion.php#L47
(DO NOT CHANGE THAT LINE!)
What you can do is to create a custom theme with following file:
/themes/yourtheme/views/vanilla/discussion.php
Copy the contents of the original view to that file and change the file of your new theme the way you like.
@R_J, would look like a plan, but with
Gdn_Format::Date($Discussion->DateInserted
the data only gets inserted and formated elsewhere. No clue on how to change the displayed format in that place.Such a little change (with the goal of having the publishing date properly formated in the initial posting of a discussion) seem to be way more complicated than anticipated.
You want to change the look/functionality of your board on one single place for one single purpose. Whenever you have the need to do something like that, you could expect that you have to dig some deeper into the code than just simply add one line of CSS somewhere.
But all in all what you have to do is not very hard to achieve. You simply shouldn't change core files and so you have to override a view which means creating your own theme.
By the way: if the google data highlighter works with html5 time tag, I would prefer doing something like that:
That would enclose the normal link with a
<time datetime="Y-m-d H:i:s">
tag and hopefully Google could use that information.For certain you can try it out first by simply modifying the original view, but you should end up with a custom theme and a reconstruction of the original view.
But I haven't answered your question...
Yes, it is formatted elsewhere but if you are overriding the view, you can simply drop that function call and replace it with a
date("Y-m-d H:i:s", $Discussion->DateInserted)
I'm surprised that Data Highlighter doesn't work with the html5
<time>
element in some of the 2.1 themes there is e.g.<time datetime="2014-08-01T09:30:22+00:00" title="August 1, 2014 10:30AM">10:30AM</time>
See the datetime attribute, I don't really know enough about the highlighter TBH
grep is your friend.
Since my theme is based on the default one it already has that HTML5
<time>
line as shown by you, @x00, but it indeed does not work for the Google Data Highlighter as shown in the screenshot of my initial posting.I wonder if it is actaully working as expected.
See
https://support.google.com/webmasters/answer/176035?hl=en
the only thing missing is the
itemprop
In other words the display date, is different from he the date time. I would ask on one of the mailing lists.
grep is your friend.
Just checked again with the Google Data Highlighter by marking the shown date (in the visual form of "July 31") and choosing "Automatic Date/Time Detection" but it just does not work. It seems it only uses visual elements.