Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangpeng96 committed Feb 1, 2022
2 parents 01a8d58 + 00c75d2 commit 34a64d0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
6 changes: 3 additions & 3 deletions admin/manage-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<ul class="typecho-option-tabs right">
<?php if ($user->pass('editor', true) && !isset($request->uid)): ?>
<li class="<?php if ($isAllPosts): ?> current<?php endif; ?>"><a
href="<?php echo $request->makeUriByRequest('__typecho_all_posts=on'); ?>"><?php _e('所有'); ?></a>
href="<?php echo $request->makeUriByRequest('__typecho_all_posts=on&page=1'); ?>"><?php _e('所有'); ?></a>
</li>
<li class="<?php if (!$isAllPosts): ?> current<?php endif; ?>"><a
href="<?php echo $request->makeUriByRequest('__typecho_all_posts=off'); ?>"><?php _e('我的'); ?></a>
href="<?php echo $request->makeUriByRequest('__typecho_all_posts=off&page=1'); ?>"><?php _e('我的'); ?></a>
</li>
<?php endif; ?>
</ul>
Expand Down Expand Up @@ -91,7 +91,7 @@ class="i-caret-down"></i></button>
(isset($request->uid) ? '?uid=' . htmlspecialchars($request->get('uid')) : '') : '')); ?>"><?php _e('&laquo; 取消筛选'); ?></a>
<?php endif; ?>
<input type="text" class="text-s" placeholder="<?php _e('请输入关键字'); ?>"
value="<?php echo htmlspecialchars($request->keywords); ?>" name="keywords"/>
value="<?php echo htmlspecialchars($request->keywords ?? ''); ?>" name="keywords"/>
<select name="category">
<option value=""><?php _e('所有分类'); ?></option>
<?php \Widget\Metas\Category\Rows::alloc()->to($category); ?>
Expand Down
4 changes: 2 additions & 2 deletions var/Typecho/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ function ($matches) use ($allowableAttributes) {
*/
public static function filterSearchQuery(?string $query): string
{
return str_replace('-', ' ', self::slugName($query));
return isset($query) ? str_replace('-', ' ', self::slugName($query)) : '';
}

/**
Expand All @@ -498,7 +498,7 @@ public static function filterSearchQuery(?string $query): string
*/
public static function slugName(?string $str, ?string $default = null, int $maxLength = 128): ?string
{
$str = trim($str);
$str = trim($str ?? '');

if (!strlen($str)) {
return $default;
Expand Down
8 changes: 4 additions & 4 deletions var/Typecho/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function isEmpty(): bool
* @access public
* @return void
*/
public function rewind()
public function rewind(): void
{
reset($this->currentConfig);
}
Expand All @@ -113,7 +113,7 @@ public function current()
* @access public
* @return void
*/
public function next()
public function next(): void
{
next($this->currentConfig);
}
Expand Down Expand Up @@ -231,15 +231,15 @@ public function offsetGet($offset)
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
$this->currentConfig[$offset] = $value;
}

/**
* @param mixed $offset
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->currentConfig[$offset]);
}
Expand Down
2 changes: 1 addition & 1 deletion var/Typecho/Db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public function prepare(string $query): string

return preg_replace_callback("/#param:([0-9]+)#/", function ($matches) use ($params, $adapter) {
if (array_key_exists($matches[1], $params)) {
return $adapter->quoteValue($params[$matches[1]]);
return is_null($params[$matches[1]]) ? 'NULL' : $adapter->quoteValue($params[$matches[1]]);
} else {
return $matches[0];
}
Expand Down
6 changes: 5 additions & 1 deletion var/Typecho/Widget/Helper/Form/Element/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function input(?string $name = null, ?array $options = null): ?Layout
*/
protected function inputValue($value)
{
$this->input->setAttribute('value', htmlspecialchars($value));
if (isset($value)) {
$this->input->setAttribute('value', htmlspecialchars($value));
} else {
$this->input->removeAttribute('value');
}
}
}
13 changes: 5 additions & 8 deletions var/Widget/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,17 @@ public function checkVersion()
$json = json_decode($response, true);

if (!empty($json)) {
[$soft, $version] = explode(' ', $this->options->generator);
$current = explode('/', $version);
$version = $this->options->version;

if (
isset($json['release']) && isset($json['version'])
isset($json['release'])
&& preg_match("/^[0-9\.]+$/", $json['release'])
&& preg_match("/^[0-9\.]+$/", $json['version'])
&& version_compare($json['release'], $current[0], '>=')
&& version_compare($json['version'], $current[1], '>')
&& version_compare($json['release'], $version, '>=')
) {
$result = [
'available' => 1,
'latest' => $json['release'] . '-' . $json['version'],
'current' => $current[0] . '-' . $current[1],
'latest' => $json['release'],
'current' => $version,
'link' => 'http://typecho.org/download'
];
}
Expand Down
8 changes: 8 additions & 0 deletions var/Widget/Base/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ public function push(array $value): array
*/
public function filter(array $value): array
{
/** 处理默认空值 */
$value['author'] = $value['author'] ?? '';
$value['mail'] = $value['mail'] ?? '';
$value['url'] = $value['url'] ?? '';
$value['ip'] = $value['ip'] ?? '';
$value['agent'] = $value['agent'] ?? '';
$value['text'] = $value['text'] ?? '';

$value['date'] = new Date($value['created']);
return Comments::pluginHandle()->filter($value, $this);
}
Expand Down
7 changes: 6 additions & 1 deletion var/Widget/Base/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,19 @@ public function push(array $value): array
*/
public function filter(array $value): array
{
/** 处理默认空值 */
$value['title'] = $value['title'] ?? '';
$value['text'] = $value['text'] ?? '';
$value['slug'] = $value['slug'] ?? '';

/** 取出所有分类 */
$value['categories'] = $this->db->fetchAll($this->db
->select()->from('table.metas')
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
->where('table.relationships.cid = ?', $value['cid'])
->where('table.metas.type = ?', 'category'), [Rows::alloc(), 'filter']);

$value['category'] = null;
$value['category'] = '';
$value['directory'] = [];

/** 取出第一个分类作为slug条件 */
Expand Down

0 comments on commit 34a64d0

Please sign in to comment.