diff --git a/flickr.admin.inc b/flickr.admin.inc index c55df91..9b8be3b 100644 --- a/flickr.admin.inc +++ b/flickr.admin.inc @@ -202,6 +202,50 @@ function flickr_admin_settings() { 'caption' => t('In the photo caption'), ), ); + $form['date_formats_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Date formats'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + // 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('When hovering an image (mouse-over)'), + '#default_value' => variable_get('flickr_date_format_image_title', 'short'), + '#options' => $formats, + ); + $form['date_formats_settings']['flickr_date_format_image_caption'] = array( + '#type' => 'select', + '#title' => t('In the image caption'), + '#default_value' => variable_get('flickr_date_format_image_caption', 'interval'), + '#options' => $formats, + ); + $form['date_formats_settings']['flickr_date_format_image_caption_hover'] = array( + '#type' => 'select', + '#title' => t('When hovering a date in the caption'), + '#description' => t("If you don't want to display anything when hovering the date, select 'None'."), + '#default_value' => variable_get('flickr_date_format_image_caption_hover', 'long'), + '#options' => array('none' => '-- None --') + $formats, + ); + $form['date_formats_settings']['flickr_date_format_album_title'] = array( + '#type' => 'select', + '#title' => t('In the album title'), + '#default_value' => variable_get('flickr_date_format_album_title', 'flickr_date_only'), + '#options' => $formats, + ); $colorbox_module = l(t('Colorbox module'), 'https://drupal.org/project/colorbox', array( 'attributes' => array( 'title' => t('Colorbox| Drupal.org'), @@ -400,53 +444,6 @@ function flickr_admin_settings() { $form['advanced_settings']['flickr_debug'][2]['#disabled'] = TRUE; $form['advanced_settings']['flickr_debug']['#description'] = t('Display the Flickr XML response.'); } - $form['date_formats_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Date formats'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - // 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, - ); - $form['date_formats_settings']['flickr_date_format_image_caption'] = array( - '#type' => 'select', - '#title' => t('Image caption'), - '#description' => t('Select the appropriate date format to be displayed in the image caption.'), - '#default_value' => variable_get('flickr_date_format_image_caption', 'interval'), - '#options' => $formats, - ); - $form['date_formats_settings']['flickr_date_format_image_caption_hover'] = array( - '#type' => 'select', - '#title' => t('Image caption hover'), - '#description' => t("Select the appropriate date format to be displayed when hovering the date display in the image caption. If you don't want to display anything when hovering the date, select 'None'."), - '#default_value' => variable_get('flickr_date_format_image_caption_hover', 'long'), - '#options' => array('none' => '-- None --') + $formats, - ); - $form['date_formats_settings']['flickr_date_format_album_title'] = array( - '#type' => 'select', - '#title' => t('Album title'), - '#description' => t('Select the appropriate date format to be displayed in the album title.'), - '#default_value' => variable_get('flickr_date_format_album_title', 'short'), - '#options' => $formats, - ); $form['block_settings'] = array( '#type' => 'fieldset', '#title' => t('Block options'), diff --git a/flickr.inc b/flickr.inc index ba86b1d..d0bfaf8 100644 --- a/flickr.inc +++ b/flickr.inc @@ -740,12 +740,15 @@ function flickr_album($type = 'user', $id = '39873962@N08', $show_n = NULL, $siz $tagged = (empty($tags) || $size == 'x' || $size == 'y') ? '' : '' . $flickr; // A single date. $format = variable_get('flickr_date_format_album_title', 'short'); - if ((empty($datetofix) || $datetofix == $datefromfix) && !empty($datefromfix)) { - $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); + $formated_datefrom = ($format == 'interval') ? format_interval(time() - strtotime(substr($datefrom, 0, 10)), 1) : format_date(strtotime(substr($datefrom, 0, 10)), $format, '', NULL); + $formated_dateto = ($format == 'interval') ? format_interval(time() - strtotime(substr($dateto, 0, 10)), 1) : format_date(strtotime(substr($dateto, 0, 10)), $format, '', NULL); + + if ((empty($datetofix) || $datetofix == $datefromfix || $formated_datefrom == $formated_dateto) && !empty($datefromfix)) { + $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . $formated_datefrom . ' ' . t('ago') : ' ' . t('taken on') . ' ' . $formated_datefrom; } // Multiple days. elseif (!empty($datefromfix)) { - $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . format_interval(time() - strtotime(substr($datefrom, 0, 10)), 1) . ' ' . t('to') . ' ' . format_interval(time() - strtotime(substr($dateto, 0, 10)), 1) . ' ' . t('ago') : ' ' . t('taken from') . ' ' . format_date(strtotime(substr($datefrom, 0, 10)), $format, '', NULL) . ' ' . t('to') . ' ' . format_date(strtotime(substr($dateto, 0, 10)), $format, '', NULL); + $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . $formated_datefrom . ' ' . t('to') . ' ' . $formated_dateto . ' ' . t('ago') : ' ' . t('taken from') . ' ' . $formated_datefrom . ' ' . t('to') . ' ' . $formated_dateto; } else { $taken = ''; diff --git a/flickr.install b/flickr.install index e195ccf..284c1d4 100644 --- a/flickr.install +++ b/flickr.install @@ -16,6 +16,9 @@ function flickr_install() { elseif (module_exists('lightbox2')) { variable_set('flickr_rel', 'lightbox[gallery]'); } + + // Install appropriate date format for album title. + flickr_update_7104(); } /** @@ -47,6 +50,10 @@ function flickr_uninstall() { variable_del('flickr_maps'); variable_del('flickr_geophp'); variable_del('flickr_smart'); + variable_del('flickr_date_format_image_title'); + variable_del('flickr_date_format_image_caption'); + variable_del('flickr_date_format_image_caption_hover'); + variable_del('flickr_date_format_album_title'); } /** @@ -126,3 +133,39 @@ function flickr_update_7102() { function flickr_update_7103() { variable_del('flickr_caption_padding'); } + +/** + * Create a new date format for album title. + */ +function flickr_update_7104() { + drupal_static_reset('system_get_date_types'); + 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)); + } + + // There is already a date format without hours. + if (strpos(strtolower($format_string), 'h') === FALSE && strpos(strtolower($format_string), 'g') === FALSE) { + variable_set('flickr_date_format_album_title', $f); + } + } + + // There is no date format defined using the expected format. Create it. + if (variable_get('flickr_date_format_album_title', FALSE) === FALSE) { + system_date_format_save(array( + 'type' => 'custom', + 'format' => 'l, d F, Y', + 'locked' => 0, + 'is_new' => 1, + )); + system_date_format_type_save(array( + 'type' => 'flickr_date_only', + 'title' => 'Date only', + 'locked' => 0, + 'is_new' => 1 + )); + variable_set('date_format_flickr_date_only', 'l, d F, Y'); + + variable_set('flickr_date_format_album_title', 'flickr_date_only'); + } +}