this commit addresses some locale issues (date combobox in search template) and refactors a bit the date_formatting code; date_strformat was not used, so it's been modified to work as it should by moving around things a bit, and making it compatible - for what concerns the prototype of the function - to strftime
This commit is contained in:
		
							parent
							
								
									5c096dcd37
								
							
						
					
					
						commit
						7fc51f79d1
					
				@ -1,21 +1,49 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
	function date_strformat($timestamp=null, $offset=0, $format='l dS F Y h:i:s A') {
 | 
			
		||||
		if ( strpos( $timestamp, ',' ) !== false ) {
 | 
			
		||||
			// This is an hack for compatibility with the time
 | 
			
		||||
			// format from versions < 0.3.3. In 0.3.3 spb switched
 | 
			
		||||
			// to the unix timestamp for storing times.
 | 
			
		||||
			//
 | 
			
		||||
			// Before that it was in this format:
 | 
			
		||||
			//   date( 'F j, Y, g:i a', $time_stamp );
 | 
			
		||||
			//   'May 10, 2004, 3:57 pm'
 | 
			
		||||
			$time_stamp = str_replace( ',', '', $time_stamp );
 | 
			
		||||
			$time_stamp = strtotime( $time_stamp );
 | 
			
		||||
	function date_strformat($format, $timestamp=0) {
 | 
			
		||||
		global $lang;
 | 
			
		||||
 | 
			
		||||
		// D l day
 | 
			
		||||
		
 | 
			
		||||
		if ( strpos($format, '%a') !== false ) {
 | 
			
		||||
			$i = strftime('%w', $timestamp);
 | 
			
		||||
			$format = str_replace('%a', $lang['date']['weekday_abbr'][$i], $format);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		$timestamp = ($timestamp != null) ? $timestamp : time();
 | 
			
		||||
		$time_stamp = intval($timestamp) + intval($offset) * 60 * 60;
 | 
			
		||||
		return date($format, $time_stamp);
 | 
			
		||||
		if ( strpos($format, '%A') !== false  ) {
 | 
			
		||||
			$i = strftime('%w', $timestamp);
 | 
			
		||||
			$format = str_replace('%A', $lang['date']['weekday'][$i], $format);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		// F M month
 | 
			
		||||
		
 | 
			
		||||
		if ( strpos($format, '%b') !== false  ) {
 | 
			
		||||
			$i = intval(strftime('%m', $timestamp))-1;
 | 
			
		||||
			$format = str_replace('%b', $lang['date']['month_abbr'][$i], $format);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		if ( strpos($format, '%B') !== false  ) {
 | 
			
		||||
			$i = intval(strftime('%m', $timestamp))-1;
 | 
			
		||||
			$format = str_replace('%B', $lang['date']['month'][$i], $format);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
			if (DIRECTORY_SEPARATOR == '\\') {
 | 
			
		||||
			$_win_from = array('%D',       '%h', '%n', '%r',          '%R',    '%t', '%T');
 | 
			
		||||
			$_win_to   = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
 | 
			
		||||
				if (strpos($format, '%e') !== false) {
 | 
			
		||||
					$_win_from[] = '%e';
 | 
			
		||||
					$_win_to[]   = sprintf('%\' 2d', date('j', $timestamp));
 | 
			
		||||
				}
 | 
			
		||||
				if (strpos($format, '%l') !== false) {
 | 
			
		||||
					$_win_from[] = '%l';
 | 
			
		||||
					$_win_to[]   = sprintf('%\' 2d', date('h', $timestamp));
 | 
			
		||||
				}
 | 
			
		||||
				$format = str_replace($_win_from, $_win_to, $format);
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
		return strftime($format, $timestamp);
 | 
			
		||||
	
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -327,13 +327,11 @@
 | 
			
		||||
			
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	function theme_date_format(	$string,
 | 
			
		||||
											$format = null,
 | 
			
		||||
											$default_date = ''
 | 
			
		||||
											) {										
 | 
			
		||||
		global $lang;
 | 
			
		||||
	function theme_date_format($string, $format = null, $default_date = '') {
 | 
			
		||||
 | 
			
		||||
		if ($string != '') {
 | 
			
		||||
		$timestamp = 0;
 | 
			
		||||
 | 
			
		||||
		if ($string) {
 | 
			
		||||
			$timestamp = $string; // smarty_make_timestamp($string);
 | 
			
		||||
		} elseif ($default_date != '') {
 | 
			
		||||
			$timestamp = $default_date; // smarty_make_timestamp($default_date);
 | 
			
		||||
@ -347,66 +345,23 @@
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
	
 | 
			
		||||
			// D l day
 | 
			
		||||
 | 
			
		||||
			if ( strpos($format, '%a') !== false ) {
 | 
			
		||||
				$i = strftime('%w', $timestamp);
 | 
			
		||||
				$format = str_replace('%a', $lang['date']['weekday_abbr'][$i], $format);
 | 
			
		||||
			}
 | 
			
		||||
		return date_strformat($format, $timestamp);
 | 
			
		||||
		
 | 
			
		||||
			if ( strpos($format, '%A') !== false  ) {
 | 
			
		||||
				$i = strftime('%w', $timestamp);
 | 
			
		||||
				$format = str_replace('%A', $lang['date']['weekday'][$i], $format);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			// F M month
 | 
			
		||||
			
 | 
			
		||||
			if ( strpos($format, '%b') !== false  ) {
 | 
			
		||||
				$i = intval(strftime('%m', $timestamp))-1;
 | 
			
		||||
				$format = str_replace('%b', $lang['date']['month_abbr'][$i], $format);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			if ( strpos($format, '%B') !== false  ) {
 | 
			
		||||
				$i = intval(strftime('%m', $timestamp))-1;
 | 
			
		||||
				$format = str_replace('%B', $lang['date']['month'][$i], $format);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
				if (DIRECTORY_SEPARATOR == '\\') {
 | 
			
		||||
				$_win_from = array('%D',       '%h', '%n', '%r',          '%R',    '%t', '%T');
 | 
			
		||||
				$_win_to   = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
 | 
			
		||||
					if (strpos($format, '%e') !== false) {
 | 
			
		||||
						$_win_from[] = '%e';
 | 
			
		||||
						$_win_to[]   = sprintf('%\' 2d', date('j', $timestamp));
 | 
			
		||||
					}
 | 
			
		||||
					if (strpos($format, '%l') !== false) {
 | 
			
		||||
						$_win_from[] = '%l';
 | 
			
		||||
						$_win_to[]   = sprintf('%\' 2d', date('h', $timestamp));
 | 
			
		||||
					}
 | 
			
		||||
					$format = str_replace($_win_from, $_win_to, $format);
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
			return strftime($format, $timestamp);
 | 
			
		||||
			
 | 
			
		||||
		
 | 
			
		||||
    } 
 | 
			
		||||
	} 
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	function theme_smarty_modifier_date_format_daily(
 | 
			
		||||
												$string,
 | 
			
		||||
												$format = null,
 | 
			
		||||
												$default_date = ''
 | 
			
		||||
												) {
 | 
			
		||||
			$string, $format = null, $default_date = '' ) {
 | 
			
		||||
	
 | 
			
		||||
	global $THEME_CURRENT_DAY, $lang, $fp_config;
 | 
			
		||||
		global $THEME_CURRENT_DAY, $lang, $fp_config;
 | 
			
		||||
	
 | 
			
		||||
	if (is_null($format))
 | 
			
		||||
		$format = $fp_config['locale']['dateformat'];
 | 
			
		||||
		if (is_null($format))
 | 
			
		||||
			$format = $fp_config['locale']['dateformat'];
 | 
			
		||||
 | 
			
		||||
	$current_day = theme_date_format($string, $format, $default_date);
 | 
			
		||||
		$current_day = theme_date_format($string, $format, $default_date);
 | 
			
		||||
    
 | 
			
		||||
    if (!isset($THEME_CURRENT_DAY) || $THEME_CURRENT_DAY != $current_day) {
 | 
			
		||||
	if (!isset($THEME_CURRENT_DAY) || $THEME_CURRENT_DAY != $current_day) {
 | 
			
		||||
		$THEME_CURRENT_DAY = $current_day;
 | 
			
		||||
		
 | 
			
		||||
		return $current_day;
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@ function smarty_function_html_select_date($params, &$smarty)
 | 
			
		||||
    require_once $smarty->_get_plugin_filepath('function','html_options');
 | 
			
		||||
    /* Default values. */
 | 
			
		||||
    $prefix          = "Date_";
 | 
			
		||||
    $start_year      = strftime("%Y");
 | 
			
		||||
    $start_year      = date_strformat("%Y");
 | 
			
		||||
    $end_year        = $start_year;
 | 
			
		||||
    $display_days    = true;
 | 
			
		||||
    $display_months  = true;
 | 
			
		||||
@ -142,8 +142,8 @@ function smarty_function_html_select_date($params, &$smarty)
 | 
			
		||||
        $time = $found[1];
 | 
			
		||||
    } else {
 | 
			
		||||
        // use smarty_make_timestamp to get an unix timestamp and
 | 
			
		||||
        // strftime to make yyyy-mm-dd
 | 
			
		||||
        $time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
 | 
			
		||||
        // date_strformat to make yyyy-mm-dd
 | 
			
		||||
        $time = date_strformat('%Y-%m-%d', smarty_make_timestamp($time));
 | 
			
		||||
    }
 | 
			
		||||
    // Now split this in pieces, which later can be used to set the select
 | 
			
		||||
    $time = explode("-", $time);
 | 
			
		||||
@ -151,16 +151,16 @@ function smarty_function_html_select_date($params, &$smarty)
 | 
			
		||||
    // make syntax "+N" or "-N" work with start_year and end_year
 | 
			
		||||
    if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
 | 
			
		||||
        if ($match[1] == '+') {
 | 
			
		||||
            $end_year = strftime('%Y') + $match[2];
 | 
			
		||||
            $end_year = date_strformat('%Y') + $match[2];
 | 
			
		||||
        } else {
 | 
			
		||||
            $end_year = strftime('%Y') - $match[2];
 | 
			
		||||
            $end_year = date_strformat('%Y') - $match[2];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) {
 | 
			
		||||
        if ($match[1] == '+') {
 | 
			
		||||
            $start_year = strftime('%Y') + $match[2];
 | 
			
		||||
            $start_year = date_strformat('%Y') + $match[2];
 | 
			
		||||
        } else {
 | 
			
		||||
            $start_year = strftime('%Y') - $match[2];
 | 
			
		||||
            $start_year = date_strformat('%Y') - $match[2];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (strlen($time[0]) > 0) {
 | 
			
		||||
@ -188,8 +188,8 @@ function smarty_function_html_select_date($params, &$smarty)
 | 
			
		||||
            $month_values[''] = '';
 | 
			
		||||
        }
 | 
			
		||||
        for ($i = 1; $i <= 12; $i++) {
 | 
			
		||||
            $month_names[$i] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
 | 
			
		||||
            $month_values[$i] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
 | 
			
		||||
            $month_names[$i] = date_strformat($month_format, mktime(0, 0, 0, $i, 1, 2000));
 | 
			
		||||
            $month_values[$i] = date_strformat($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $month_result .= '<select name=';
 | 
			
		||||
@ -211,7 +211,7 @@ function smarty_function_html_select_date($params, &$smarty)
 | 
			
		||||
 | 
			
		||||
        $month_result .= smarty_function_html_options(array('output'     => $month_names,
 | 
			
		||||
                                                            'values'     => $month_values,
 | 
			
		||||
                                                            'selected'   => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
 | 
			
		||||
                                                            'selected'   => (int)$time[1] ? date_strformat($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
 | 
			
		||||
                                                            'print_result' => false),
 | 
			
		||||
                                                      $smarty);
 | 
			
		||||
        $month_result .= '</select>';
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user