We have a taken date currently displayed:

  • hovering an image (currently 'short')
  • hovering the 'time ago' in the caption (currently 'long')
  • in the album title as being the date or interval filtered on 'taken on ..' (currently medium)
  • in the caption (currently 'time ago').

It shouldn't be too difficult to provide some settings to make this configurable with radio buttons. The date format options should be taken dynamically in case other formats have been created besides those provided by default.

Best would be to provide a field set 'Date formats'.

Comments

lolandese’s picture

Issue summary: View changes
vbouchet’s picture

Hi lolandese,

I started to work on that request. How do you think we should deal with the 'time ago' option as there is no date format for it? I planned to add a "fake" date format in the list but then if the user select something else than 'time ago' for the caption, it doesn't make sense to display a date when hovering it. Should we simply take the decision to hide the "Caption hovered" option when something else than 'time ago' is selected for the Caption option (we can use states API for that)?

  // Get list of all available date formats.
  drupal_static_reset('system_get_date_types');
  $formats = array();
  foreach (system_get_date_types() as $f => $format) {
    if (($format_string = variable_get('date_format_' . $f, FALSE)) === FALSE) {
      $format_string = key(system_get_date_formats($f));
    }

    if (!empty($format_string)) {
      $formats[$f] = $format['title'] . ' [' . format_date(REQUEST_TIME, 'custom', $format_string) . ']';
    }
  }
  $formats['interval'] = 'Time ago [' . format_interval(3600, 1) . ' ago]';
  $form['date_formats_settings']['flickr_date_format_image_title'] = array(
    '#type' => 'select',
    '#title' => t('Image title'),
    '#description' => t('Select the appropriate date format to be displayed when hovering an image.'),
    '#default_value' => variable_get('flickr_date_format_image_title', 'short'),
    '#options' => $formats,
  );

Can you also let me know how to display the date in the album title? (for now I haven't been able to have any date while displaying an album).

Let me know your opinion and I will finalize the patch for this feature.
Thanks,

lolandese’s picture

How do you think we should deal with the 'time ago' option as there is no date format for it? I planned to add a "fake" date format in the list..

Yes. Options through function system_get_date_types seems the right approach. 'Time ago' (line 619 in flickr.module) seems indeed necessary to add as 'fake' option.

..but then if the user select something else than 'time ago' for the caption, it doesn't make sense to display a date when hovering it.

Adding the option 'None' would take care of that. It might be that it is still desired to show a long date when hovering the short format in the caption. Anyway, maybe leave this up to the sitebuilder. 'Time ago' is IMHO anyway the best option for the caption to offer as being the default.

Can you also let me know how to display the date in the album title?

Enable Flickr Filter, add it to a text format and use in the node body e.g.:
[flickr-user:id=public, size=q, num=8,location=48.867556/2.364088, date=2015-01-11, filter=interesting, sort=views]
See the last album on this demo page.
Both location and date are new features only present in the dev version for now. In Flickr Blocks they can even be taken dynamically from a Location/Geofield or Date field of the node on the same page as the block. Same way it was already done for node taxonomy terms and Flickr tags.

Thanks in advance for your help.

vbouchet’s picture

Status: Active » Needs review
StatusFileSize
new7.55 KB

Hi,

Please find a patch to provide the configurable date format feature. Let me know if it's ok.

lolandese’s picture

Status: Needs review » Needs work
Issue tags: -Novice, -Config novice

Review:

  • Patch applies cleanly.
  • Tested if a custom defined date format gets added to the options. OK
  • Tested if changing several options has the desired effect. OK
  • Tested the 'None' option for the caption date hover. OK

Only the date included in the album title can lead to titles like:

Most viewed, most interesting Flickr photos near République, Paris, France taken 3 months to 3 months ago

or

Most viewed, most interesting Flickr photos near République, Paris, France taken on Sunday, 11 January, 2015 - 00:00

Cause of the first is the granularity of the 'Time ago' format. It can be resolved by removing this option for the 'Album title' or using a granularity that at least includes the day.

The second could be solved by using substr($str, 0, strrpos($str, '-').
It looks for the position the first occurunce of the dash that separates the date and time. Then it only takes the part in front of it.

In practice in the current code in flickr.inc line 744 replace

      $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . format_interval(time() - strtotime(substr($datefrom, 0, 10)), 1) . ' ' . t('ago') : ' ' . t('taken on') . ' ' . format_date(strtotime(substr($datefrom, 0, 10)), $format, '', NULL);

with

      $str = format_date(strtotime(substr($datefrom, 0, 10)), $format, '', NULL);
      $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . format_interval(time() - strtotime(substr($datefrom, 0, 10)), 1) . ' ' . t('ago') : ' ' . t('taken on') . ' ' . substr($str, 0, strrpos($str, '-'));

Similar for line 748 (multiple days).

Some other points:

Maybe put the field group 'Date formats' right under 'Global options'?

The field descriptions 'Select the appropriate date format to be displayed..' seems a bit redundant as the field group is already named 'Date formats'.
Proposed field titles and descriptions:
T: When hovering an image (mouse-over)
D: -

T: In the image caption
D: -

T: When hovering a date in the caption
D: If you don't want to display anything when hovering the date, select 'None'.

T: In the album title
D: -

Overall this is a nice addition and exactly what was intended.

Thanks.

vbouchet’s picture

Hi,
Regarding the "time ago" option for the album title, maybe we should simply check the two dates are different (after the transformation). So in that example we will have "Most viewed, most interesting Flickr photos near République, Paris, France taken 3 months ago". For another album we may have "Most viewed, most interesting Flickr photos near République, Paris, France taken 5 months to 3 months ago" which make sense from my point of view. It may be interesting to add a "hover option" to display the full date (as for the image caption).

Regarding the hour displayed, I think it's the expected behavior. If you don't want to display the hour, use a different date format which doesn't contain the hours. It makes more sense as it respects the selected format.

Let me know your opinion on these two points and I will also adapt labels and descriptions.

lolandese’s picture

Regarding the "time ago" option for the album title, maybe we should simply check the two dates are different (after the transformation).

I agree. Probably the most elegant solution.

It may be interesting to add a "hover option" to display the full date (as for the image caption).

I agree. If that can be implemented right away, nice. If it will turn in an additional feature request to take care of later, fine as well.

Regarding the hour displayed, I think it's the expected behavior.

Both the date used in Flickr Filter and Date field attached to a node (used by Flickr Block) have a granularity of 'Day'. No time is given by the user, thus expected is only a 'Day'. The time is added programmatically to have correct results returned. E.g.:
The user given date=2015-01-11 turns programmatically into two parameters for the Flickr request, min_taken_date=2015-01-11 00:00:00 and max_taken_date=2015-01-11 23:59:59. We don't want to bother the users with times to fill in.

If you don't want to display the hour, use a different date format which doesn't contain the hours. It makes more sense as it respects the selected format.

We prefer to not bother our sitebuilders to create a custom date format. Most are using the Flickr module because less 'tech savvy' or as a time saver. For both we would like to avoid more hassle. Several solutions possible:

  • Create a custom date format without time during installation of the module.
  • Use the following description on the 'album title' date format field: 'The time part is not used.'

P.S.:
The previously suggested substr method to cut off the time part of a date does only work if date and time are separated by a dash and if the date doesn't contain any dashes. So on a format like '2015-04-30 12:50' it results in an album title like:
Most viewed, most interesting Flickr photos near République, Paris, France taken on 2015-01

Instead of the dash (-) it is safer to use the colon (:) that should only be present in a time. In code that would look like:
substr($str, 0, strrpos($str, ':') - 3)
-3 to exclude also the hour part of the time. I know, it's not too elegant but it works for most cases.

We could also simply remove the last word of the string:

$lastSpacePosition = strrpos($text, ' ');
$textWithoutLastWord = substr($text, 0, $lastSpacePosition);

This should work for all the default provided date format (short, medium, long) but obviously should be skipped on 'time ago' or custom date formats that omit the space between date and time or put a space in the time (e.g. '04:12:00 pm').

Even better:
In a regular expression we could "look" for the first occurrence of a number followed by a colon and use anything that preceeds it. Something like:

      $str = format_date(strtotime(substr($datefrom, 0, 10)), $format, '', NULL);
      preg_match('/^(.*?)[-|\s].\d+:/', $str, $match);
      $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . format_interval(time() - strtotime(substr($datefrom, 0, 10)), 1) . ' ' . t('ago') : ' ' . t('taken on') . ' ' . $match[1];

See http://rubular.com/r/7IJhj19P9K.

vbouchet’s picture

StatusFileSize
new9.38 KB
new9.06 KB

Please find an updated patch and an interdiff file.

I will be off for the next two weeks so if there is any issue with the patch, feel free to jump and update it.

Please create a separate feature request for the "hover option" on the album title dates.

Thanks,

vbouchet’s picture

Status: Needs work » Needs review
lolandese’s picture

Status: Needs review » Needs work

Review:

  • Patch applies cleanly.
  • I would prefer to use the intended form attributes #empty_option https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h... and #empty_value instead of: '#options' => array('none' => '-- None --') + $formats,
  • The 'time ago' format for the image title attribute (displayed on hover) is ignored and remains a date.
  • For album titles we still have:
    Most viewed, most interesting Flickr photos near République, Paris, France taken on Sunday, 11 January, 2015 - 00:00
    if the date format contains a time. I would prefer to truncate it to a date only so we can use the core date formats without the need to create Flickr module specific ones (see also below). Also because the time will always be 00:00 as the current granularity is 'day'.
  • No cleanup of the created date format takes place on uninstall. Furthermore if the module is installed a second time and meanwhile the 'flickr_date_only' date format type had been removed it will lead to the following error:
    PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'l, d F, Y-custom' for key 'formats': INSERT INTO {date_formats} (format, type, locked) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => l, d F, Y [:db_insert_placeholder_1] => custom [:db_insert_placeholder_2] => 0 ) in drupal_write_record() (line 7207 of /home/martin/www/green/includes/common.inc).
    While it could be taken care of with more code to catch this exceptional case, I would prefer to do without custom date formats, as also indicated above. I had second thoughts about my own proposal in #7. Sorry about that.
lolandese’s picture

Status: Needs work » Needs review
StatusFileSize
new8.9 KB
new9.71 KB

.. if there is any issue with the patch, feel free to jump in and update it.

Attached patch implements all points mentioned in #10 plus it adds the - None - option to all Flickr date formats to give sitebuilders the possibility to omit the display of a date in any element (caption, image hover, caption date hover, album title).

lolandese’s picture

The regular expression /^(.*?)[-|\s].\d*:/ instead of /^(.*?)[-|\s].\d+:/ (* instead of +) matches also one digit hours (e.g. 12 June 1965 2:00:00).

lolandese’s picture

StatusFileSize
new10.8 KB
new6.54 KB
new11.69 KB

Attached patch does as above, plus:

  • Corrects the regex as described in #12.
  • Disables the caption hover option on the settings page if a date in the caption is set to 'none'.
  • Standardizes the date format, independent from the input (Flickr Filter). E.g. 11-1-2015 will be converted to 2015-01-11 00:00:00 to have a date that PHP can deal with. It might be interesting to think of another separator for two dates (now a slash '/') as this might be used also in a date format. Most obvious would be a pipe '|' (vertical bar).
  • Doesn't bother the tag mode ('all' or 'any') if we only have one tag (unrelated to this issue).
  • Corrects some indent errors and removes some unnecessary code.
  • Removes 'taken on' from the album title if the date in the album title is set to 'none'.

Tested with Flickr Filter. To test also with Flickr Block and from scratch on a clean install.

lolandese’s picture

StatusFileSize
new24.65 KB
new13.86 KB

Attached patch additionally:

  • uses a pipe instead of a slash as separator between two dates in the Flickr Filter text filter
  • detects that a date like 15/01/2015 is intended as DD/MM/YYYY but displays a warning about how some dates can be ambiguous
  • gives some text filter hint that also relative dates can be used, e.g. 'first day of last month | last day of last month' shows all 'photos of last month' dynamically (could be put in a custom block).
lolandese’s picture

Status: Needs review » Fixed
StatusFileSize
new25.72 KB
new1.35 KB

Additionally attached patch corrects an unrelated bug that was introduced in https://www.drupal.org/commitlog/commit/2102/8d757ac25a0724bcd2773be03d5....

Also Flickr Block and install/uninstall seem to work fine now with the new configurable date format feature.

Opened a child issue for #2483241: More date format options.

Thanks for your contribution.

  • lolandese committed 5eaadbd on 7.x-1.x authored by vbouchet
    Issue #2467885 by lolandese, vbouchet: Configurable date format
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.