Skip to content

Commit cac61de

Browse files
committed
优化日期显示
加强表单元素生成转义
1 parent 24be463 commit cac61de

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

extend/fast/Date.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static function span($remote, $local = null, $output = 'years,months,week
124124
*/
125125
public static function human($remote, $local = null)
126126
{
127-
$time_diff = (is_null($local) ? time() : $local) - $remote;
127+
$time_diff = (is_null($local) ? time() : $local) - (int)$remote;
128128
$tense = $time_diff < 0 ? 'after' : 'ago';
129129
$time_diff = abs($time_diff);
130130
$chunks = [
@@ -196,11 +196,11 @@ public static function unixtime($type = 'day', $offset = 0, $position = 'begin',
196196
case 'quarter':
197197
$quarter = ceil(date('n', $baseTime) / 3) + $offset;
198198
$month = $quarter * 3;
199-
$offset_year = ceil($month/12) - 1;
199+
$offset_year = ceil($month / 12) - 1;
200200
$year = $year + $offset_year;
201201
$month = $month - ($offset_year * 12);
202202
$time = $position ?
203-
mktime(0, 0, 0, $month-2, 1, $year) :
203+
mktime(0, 0, 0, $month - 2, 1, $year) :
204204
mktime(23, 59, 59, $month, self::days_in_month($month, $year), $year);
205205
break;
206206
case 'year':

extend/fast/Form.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public function input($type, $name, $value = null, $options = [])
205205
$value = $this->getValueAttribute($name, $value);
206206
$options['class'] = isset($options['class']) ? $options['class'] . (stripos($options['class'], 'form-control') !== false ? '' : ' form-control') : 'form-control';
207207
}
208+
$value = $this->escape($value);
208209

209210
$merge = compact('type', 'value', 'id');
210211
$options = array_merge($options, $merge);
@@ -586,9 +587,9 @@ public function timepicker($name, $value, $options = [])
586587
public function datetimepicker($name, $value, $options = [])
587588
{
588589
$defaults = [
589-
'data-date-format' => "YYYY-MM-DD HH:mm:ss",
590+
'data-date-format' => "YYYY-MM-DD HH:mm:ss",
590591
// 兼容旧的用法
591-
'data-use-current' => "true",
592+
'data-use-current' => "true",
592593
'data-date-use-current' => "true",
593594
];
594595
$value = is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
@@ -680,6 +681,7 @@ public function fieldlist($name, $value, $title = null, $template = null, $optio
680681
return "<ins>{$value}</ins>";
681682
}, $title));
682683
$value = is_array($value) ? json_encode($value) : $value;
684+
$value = $this->escape($value);
683685
$html = <<<EOD
684686
<dl class="fieldlist" data-name="{$name}" {$template} {$attributes}>
685687
<dd>
@@ -710,7 +712,8 @@ public function cxselect($url, $names = [], $values = [], $options = [])
710712
$level = $index + 1;
711713
$class = "cxselect-{$level}";
712714
$classes[] = $class;
713-
$selectValue = isset($values[$value]) ? $values[$value] : (isset($values[$index]) ? $values[$index] : '');
715+
$selectValue = $values[$value] ?? ($values[$index] ?? '');
716+
$selectValue = $this->escape($selectValue);
714717

715718
$cxselect[] = <<<EOD
716719
<select class="{$class} form-control" name="{$value}" data-value="{$selectValue}" data-url="{$url}?level={$level}&name={$value}" {$attributes}></select>

0 commit comments

Comments
 (0)