Jump to content


Photo
- - - - -

Change the way date is displayed in API?


  • Please log in to reply
3 replies to this topic

#1 stormrider

stormrider

    Senior Member

  • Customers
  • 245 posts

Posted 25 September 2009 - 12:11 AM

in the getHTMLReview function of censuraAPI.php it uses .$review['date'] to add the date to the template.

This code shows long-form date (eg: September 24, 2009). This makes it hard to theme, as "May 1, 2009" is almost half the characters.

Does this use a standard smarty date function somewhere, so I could make it %b for the abbreviated month name?

#2 Gavin

Gavin

    Censura Team

  • Administrators
  • 418 posts

Posted 30 September 2009 - 09:05 AM

Hmm you're right it should also pass the timestamp so you can format it yourself, which I will add in future, also pending the changes to allow your own API templates this should become much eaiser then.
If you want to do it now by changing the API output itself you can, it doesn't use smarty for performance reasons, so there's no neat smarty function to format the date in this case, so you'll have to do it using plain old PHP.
Replace:
$review['date']
with
date("format", $review->get('date'))
Where you replace "format" with a valid format string as decribed here: http://www.php.net/date

Gavin Vincent, Censura Lead Developer
www.gavinvincent.co.uk


#3 stormrider

stormrider

    Senior Member

  • Customers
  • 245 posts

Posted 05 October 2009 - 11:57 PM

Getting this error when I swap that out in censuraAPI.php.

Fatal error: Call to a member function get() on a non-object in /path/reviews/api/censuraAPI.php on line 587

Line 587 is where I'm replacing
$output .= "<div class=\"item_date\">" . $review['date'] . "</div>";
with
$output .= "<div class=\"item_date\">" . date("M js, Y", $review->get('date')) . "</div>";


#4 Gavin

Gavin

    Censura Team

  • Administrators
  • 418 posts

Posted 07 October 2009 - 08:37 AM

Hi Stormrider,

Actually I meant to change /themes/api/includes/review.tpl, and it should have been replace...
$review->date
...with...
date("format", $review->get('date'))

But wait...
Now that 2.2.1 is out, it contains a better way of doing it without having to "hack" the /themes/api folder, so if you install 2.2.1 forget everything I just said and do more or less the way you did it instead, except ever so slightly different. On that same line (now line 593) of CensuraAPI.php, replace...
$review['date']
...with...
date("M js, Y", $review['dateTimestamp']);

Best Regards
Gavin

Edited by Gavin, 07 October 2009 - 09:03 AM.

Gavin Vincent, Censura Lead Developer
www.gavinvincent.co.uk





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users