diff -u b/flickr.admin.inc b/flickr.admin.inc --- b/flickr.admin.inc +++ b/flickr.admin.inc @@ -220,31 +220,46 @@ $formats[$f] = $format['title'] . ' [' . format_date(REQUEST_TIME, 'custom', $format_string) . ']'; } } - $formats['interval'] = 'Time ago [' . format_interval(3600, 1) . ' ago]'; + $formats['interval'] = 'Time ago [' . format_interval(3600 * 24 * 90, 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'), + '#default_value' => variable_get('flickr_date_format_image_title', 'medium'), '#options' => $formats, + '#empty_option' => t('- None -'), + '#empty_value' => 'none', ); $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, + '#empty_option' => t('- None -'), + '#empty_value' => 'none', ); $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, + '#options' => $formats, + '#empty_option' => t('- None -'), + '#empty_value' => 'none', ); + // Disable the caption hover option if a date in the caption is set to 'none'. + if (variable_get('flickr_date_format_image_caption', 'interval') == 'none') { + $form['date_formats_settings']['flickr_date_format_image_caption_hover']['#disabled'] = TRUE; + $form['date_formats_settings']['flickr_date_format_image_caption_hover']['#title'] = '' . t('When hovering a date in the caption') . ''; + $form['date_formats_settings']['flickr_date_format_image_caption_hover']['#description'] = t('Disabled until a date format for the image caption is selected.'); + } $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'), + '#description' => t("If the selected date format contains a time, only the date part of it will be used in the album title."), + '#default_value' => variable_get('flickr_date_format_album_title', 'short'), '#options' => $formats, + '#empty_option' => t('- None -'), + '#empty_value' => 'none', ); $colorbox_module = l(t('Colorbox module'), 'https://drupal.org/project/colorbox', array( 'attributes' => array( diff -u b/flickr.inc b/flickr.inc --- b/flickr.inc +++ b/flickr.inc @@ -311,7 +311,17 @@ $info = !is_array($photo['title']) ? flickr_photos_getinfo($photo['id']) : ''; if (isset($info['dates']) || isset($photo['dates'])) { $date_taken = isset($info['dates']['taken']) ? $info['dates']['taken'] : $photo['dates']['taken']; - $taken_short = format_date(strtotime($date_taken), variable_get('flickr_date_format_image_title', 'short'), '', NULL); + $format_title = variable_get('flickr_date_format_image_title', 'medium'); + switch ($format_title) { + case 'interval': + $taken_short = format_interval(time() - strtotime($date_taken), 1) . ' ' . t('ago'); + break; + case 'none': + $taken_short = ''; + break; + default: + $taken_short = format_date(strtotime($date_taken), $format_title, '', NULL); + } } $taken_short = empty($taken_short) ? '' : $taken_short . ' - '; $title = is_array($photo['title']) ? str_replace('"', "'", htmlspecialchars_decode(strip_tags($photo['description']['_content']))) : str_replace('"', "'", htmlspecialchars_decode(strip_tags($info['description']['_content']))); @@ -569,11 +579,14 @@ // As variables might change during processing, we set a fixed version of it // to use for the key to set the block cache after processing at the end. $idfix = $id; + // Standarize the date format, independent from the input. $datefromfix = $datefrom; $datetofix = $dateto; if (!isset($dateto)) { $dateto = $datefrom; } + $datefrom = empty($datefrom) ? '' : date("Y-m-d", strtotime($datefrom)); + $dateto = empty($dateto) ? '' : date("Y-m-d", strtotime($dateto)); $datefrom = isset($datefrom) ? $datefrom . ' 00:00:00' : ''; $dateto = isset($dateto) ? $dateto . ' 23:59:59' : ''; // Remove spaces from tags but save the original for matches in text instead @@ -588,7 +601,7 @@ if ($tag_mode == 'context') { $tag_mode = empty($id) || $id == 'public' || $id == '39873962@N08' ? 'all' : 'any'; } - if ($extend && $tag_mode == 'all') { + if ($extend && $tag_mode == 'all' && strpos($tags, ',') !== FALSE) { $tag_mode = 'any'; drupal_set_message(t("The tag mode has been forced to 'any' (OR) for extended text matching (tags, titles and description). To use 'all' (AND) put 'extend=false' in Flickr's text filter code."), 'warning', FALSE); } @@ -739,22 +752,51 @@ $tagged = (empty($tags) || $size == 'x' || $size == 'y') ? '' : '' . $flickr; // A single date. - $format = variable_get('flickr_date_format_album_title', 'short'); - $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); - + $format = empty($datefrom) ? 'none' : variable_get('flickr_date_format_album_title', 'short'); + switch ($format) { + case 'interval': + $formated_datefrom = format_interval(time() - strtotime(substr($datefrom, 0, 10)), 1); + $formated_dateto = format_interval(time() - strtotime(substr($dateto, 0, 10)), 1); + break; + default: + $formated_datefrom = format_date(strtotime(substr($datefrom, 0, 10)), $format, '', NULL); + $formated_dateto = 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; + // Remove the time by capturing anything preceding one or more digits + // followed by a colon. See http://rubular.com/r/7IJhj19P9K + $match1 = preg_match('/^(.*?)[-|\s].\d*:/', $formated_datefrom, $match); + // Only use the match if there is one (date with time). + $date1 = isset($match[1]) ? $match[1] : $formated_datefrom; + $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . $formated_datefrom . ' ' . t('ago') : ' ' . t('taken on') . ' ' . $date1; } // Multiple days. elseif (!empty($datefromfix)) { - $taken = ($format == 'interval') ? ' ' . t('taken') . ' ' . $formated_datefrom . ' ' . t('to') . ' ' . $formated_dateto . ' ' . t('ago') : ' ' . t('taken from') . ' ' . $formated_datefrom . ' ' . t('to') . ' ' . $formated_dateto; + // Remove the times. + $match1 = preg_match('/^(.*?)[-|\s].\d*:/', $formated_datefrom, $matchfrom); + if (isset($matchfrom[1])) { + preg_match('/^(.*?)[-|\s].\d*:/', $formated_dateto, $matchto); + $date1 = $matchfrom[1]; + $date2 = $matchto[1]; + } + else { + $date1 = $formated_datefrom; + $date2 = $formated_dateto; + } + switch ($format) { + case 'interval': + $taken = ' ' . t('taken') . ' ' . $formated_datefrom . ' ' . t('to') . ' ' . $formated_dateto . ' ' . t('ago'); + break; + default: + $taken = ' ' . t('taken from') . ' ' . $date1 . ' ' . t('to') . ' ' . $date2; + } } else { $taken = ''; $datefrom = ''; $dateto = ''; } + $taken = $format == 'none' ? '' : $taken; // Generate an album heading depending on type. switch ($type) { diff -u b/flickr.install b/flickr.install --- b/flickr.install +++ b/flickr.install @@ -16,9 +16,6 @@ elseif (module_exists('lightbox2')) { variable_set('flickr_rel', 'lightbox[gallery]'); } - - // Install appropriate date format for album title. - flickr_update_7104(); } /** @@ -136,36 +132,0 @@ - -/** - * 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'); - } -} diff -u b/flickr.module b/flickr.module --- b/flickr.module +++ b/flickr.module @@ -620,7 +620,16 @@ if (isset($info['dates']['taken'])) { // Format the date displayed on image caption. $format_taken = variable_get('flickr_date_format_image_caption', 'interval'); - $taken = ($format_taken == 'interval') ? format_interval(time() - strtotime($info['dates']['taken']), 1) : format_date(strtotime($info['dates']['taken']), $format_taken, '', NULL); + switch ($format_taken) { + case 'interval': + $taken = format_interval(time() - strtotime($info['dates']['taken']), 1) . ' ' . t('ago'); + break; + case 'none': + $taken = ''; + break; + default: + $taken = format_date(strtotime($info['dates']['taken']), $format_taken, '', NULL); + } // Format the date displayed when hovering the date on image caption. $format_hover = variable_get('flickr_date_format_image_caption_hover', 'long'); switch ($format_hover) {