mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-09 21:04:28 +02:00
Updated smarty_core_write_file() and smarty_modifier_date_format() to speed up Windows detection.
Emulated more parameters for Windows in smarty_modifier_date_format() and fixed some old ones. Updated the docs to tell what parameters are emulated on Windows. Updated NEWS file.
This commit is contained in:
6
NEWS
6
NEWS
@@ -3,8 +3,10 @@
|
|||||||
than $length (Sylvinus, messju)
|
than $length (Sylvinus, messju)
|
||||||
- fix handling of %I with mysql timestamps in the date_format modifier
|
- fix handling of %I with mysql timestamps in the date_format modifier
|
||||||
(danilo, boots)
|
(danilo, boots)
|
||||||
- update smarty_core_write_file() to better recognize Windows (boots)
|
- update smarty_core_write_file() and smarty_modifier_date_format() to better
|
||||||
- emulate %R in the date_format modifier on Windows (danilo, boots)
|
recognize Windows (boots, danilo)
|
||||||
|
- emulate %h, %n, %r, %R, %t in the date_format modifier on Windows
|
||||||
|
(danilo, boots)
|
||||||
|
|
||||||
Version 2.6.16 (Dec 1st, 2006)
|
Version 2.6.16 (Dec 1st, 2006)
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
@@ -79,7 +79,9 @@
|
|||||||
You may have more or less conversion specifiers available depending
|
You may have more or less conversion specifiers available depending
|
||||||
on your system's <ulink url="&url.php-manual;strftime"><varname>strftime()</varname></ulink>
|
on your system's <ulink url="&url.php-manual;strftime"><varname>strftime()</varname></ulink>
|
||||||
function where PHP was compiled. Check your
|
function where PHP was compiled. Check your
|
||||||
system's manpage for a full list of valid specifiers.
|
system's manpage for a full list of valid specifiers. However, a few of
|
||||||
|
the specifiers are emulated on Windows. These are: %D, %e, %h, %l, %n,
|
||||||
|
%r, %R, %t, %T.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
</para>
|
</para>
|
||||||
|
@@ -15,10 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
function smarty_core_write_file($params, &$smarty)
|
function smarty_core_write_file($params, &$smarty)
|
||||||
{
|
{
|
||||||
static $OS;
|
|
||||||
if (is_null($OS)) {
|
|
||||||
$OS = substr(PHP_OS,0,3);
|
|
||||||
}
|
|
||||||
$_dirname = dirname($params['filename']);
|
$_dirname = dirname($params['filename']);
|
||||||
|
|
||||||
if ($params['create_dirs']) {
|
if ($params['create_dirs']) {
|
||||||
@@ -41,7 +37,7 @@ function smarty_core_write_file($params, &$smarty)
|
|||||||
fwrite($fd, $params['contents']);
|
fwrite($fd, $params['contents']);
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
|
|
||||||
if ($OS == 'WIN' || !@rename($_tmp_file, $params['filename'])) {
|
if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
|
||||||
// On platforms and filesystems that cannot overwrite with rename()
|
// On platforms and filesystems that cannot overwrite with rename()
|
||||||
// delete the file before renaming it -- because windows always suffers
|
// delete the file before renaming it -- because windows always suffers
|
||||||
// this, it is short-circuited to avoid the initial rename() attempt
|
// this, it is short-circuited to avoid the initial rename() attempt
|
||||||
|
@@ -28,22 +28,29 @@ require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
|
|||||||
* @return string|void
|
* @return string|void
|
||||||
* @uses smarty_make_timestamp()
|
* @uses smarty_make_timestamp()
|
||||||
*/
|
*/
|
||||||
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
|
function smarty_modifier_date_format($string, $format = '%b %e, %Y', $default_date = '')
|
||||||
{
|
{
|
||||||
if (substr(PHP_OS,0,3) == 'WIN') {
|
|
||||||
$hours = strftime('%I', smarty_make_timestamp($string));
|
|
||||||
$short_hours = ( $hours < 10 ) ? substr( $hours, -1) : $hours;
|
|
||||||
$_win_from = array ('%e', '%T', '%D', '%l', '%R');
|
|
||||||
$_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y', $short_hours, '%H:%M');
|
|
||||||
$format = str_replace($_win_from, $_win_to, $format);
|
|
||||||
}
|
|
||||||
if ($string != '') {
|
if ($string != '') {
|
||||||
return strftime($format, smarty_make_timestamp($string));
|
$timestamp = smarty_make_timestamp($string);
|
||||||
} elseif (isset($default_date) && $default_date != '') {
|
} elseif ($default_date != '') {
|
||||||
return strftime($format, smarty_make_timestamp($default_date));
|
$timestamp = smarty_make_timestamp($default_date);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
Reference in New Issue
Block a user