mirror of
https://github.com/typecho/typecho.git
synced 2025-01-16 20:18:19 +01:00
replace str compare (#1685)
This commit is contained in:
parent
9635a7a0ba
commit
a9fa990124
@ -677,6 +677,18 @@ EOF;
|
||||
return $length < $iLength ? ($str . $trim) : $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断两个字符串是否为空并依次返回
|
||||
*
|
||||
* @param string|null $a
|
||||
* @param string|null $b
|
||||
* @return string|null
|
||||
*/
|
||||
public static function strBy(?string $a, ?string $b = null): ?string
|
||||
{
|
||||
return isset($a) && $a !== '' ? $a : $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取宽字符串长度函数
|
||||
*
|
||||
|
@ -79,17 +79,16 @@ class Comments extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
$insertStruct = [
|
||||
'cid' => $rows['cid'],
|
||||
'created' => empty($rows['created']) ? $this->options->time : $rows['created'],
|
||||
'author' => !isset($rows['author']) || strlen($rows['author']) === 0 ? null : $rows['author'],
|
||||
'author' => Common::strBy($rows['author']),
|
||||
'authorId' => empty($rows['authorId']) ? 0 : $rows['authorId'],
|
||||
'ownerId' => empty($rows['ownerId']) ? 0 : $rows['ownerId'],
|
||||
'mail' => !isset($rows['mail']) || strlen($rows['mail']) === 0 ? null : $rows['mail'],
|
||||
'url' => !isset($rows['url']) || strlen($rows['url']) === 0 ? null : $rows['url'],
|
||||
'ip' => !isset($rows['ip']) || strlen($rows['ip']) === 0 ? $this->request->getIp() : $rows['ip'],
|
||||
'agent' => !isset($rows['agent']) || strlen($rows['agent']) === 0
|
||||
? $this->request->getAgent() : $rows['agent'],
|
||||
'text' => !isset($rows['text']) || strlen($rows['text']) === 0 ? null : $rows['text'],
|
||||
'type' => empty($rows['type']) ? 'comment' : $rows['type'],
|
||||
'status' => empty($rows['status']) ? 'approved' : $rows['status'],
|
||||
'mail' => Common::strBy($rows['mail']),
|
||||
'url' => Common::strBy($rows['url']),
|
||||
'ip' => Common::strBy($rows['ip'], $this->request->getIp()),
|
||||
'agent' => Common::strBy($rows['agent'], $this->request->getAgent()),
|
||||
'text' => Common::strBy($rows['text']),
|
||||
'type' => Common::strBy($rows['type'], 'comment'),
|
||||
'status' => Common::strBy($rows['status'], 'approved'),
|
||||
'parent' => empty($rows['parent']) ? 0 : $rows['parent'],
|
||||
];
|
||||
|
||||
@ -137,11 +136,11 @@ class Comments extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
|
||||
/** 构建插入结构 */
|
||||
$preUpdateStruct = [
|
||||
'author' => !isset($rows['author']) || strlen($rows['author']) === 0 ? null : $rows['author'],
|
||||
'mail' => !isset($rows['mail']) || strlen($rows['mail']) === 0 ? null : $rows['mail'],
|
||||
'url' => !isset($rows['url']) || strlen($rows['url']) === 0 ? null : $rows['url'],
|
||||
'text' => !isset($rows['text']) || strlen($rows['text']) === 0 ? null : $rows['text'],
|
||||
'status' => empty($rows['status']) ? 'approved' : $rows['status'],
|
||||
'author' => Common::strBy($rows['author']),
|
||||
'mail' => Common::strBy($rows['mail']),
|
||||
'url' => Common::strBy($rows['url']),
|
||||
'text' => Common::strBy($rows['text']),
|
||||
'status' => Common::strBy($rows['status'], 'approved'),
|
||||
];
|
||||
|
||||
$updateStruct = [];
|
||||
|
@ -131,15 +131,15 @@ class Contents extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
$insertStruct = [
|
||||
'title' => !isset($rows['title']) || strlen($rows['title']) === 0
|
||||
? null : htmlspecialchars($rows['title']),
|
||||
'created' => !isset($rows['created']) ? $this->options->time : $rows['created'],
|
||||
'created' => empty($rows['created']) ? $this->options->time : $rows['created'],
|
||||
'modified' => $this->options->time,
|
||||
'text' => !isset($rows['text']) || strlen($rows['text']) === 0 ? null : $rows['text'],
|
||||
'text' => Common::strBy($rows['text']),
|
||||
'order' => empty($rows['order']) ? 0 : intval($rows['order']),
|
||||
'authorId' => $rows['authorId'] ?? $this->user->uid,
|
||||
'template' => empty($rows['template']) ? null : $rows['template'],
|
||||
'type' => empty($rows['type']) ? 'post' : $rows['type'],
|
||||
'status' => empty($rows['status']) ? 'publish' : $rows['status'],
|
||||
'password' => !isset($rows['password']) || strlen($rows['password']) === 0 ? null : $rows['password'],
|
||||
'template' => Common::strBy($rows['template']),
|
||||
'type' => Common::strBy($rows['type'], 'post'),
|
||||
'status' => Common::strBy($rows['status'], 'publish'),
|
||||
'password' => Common::strBy($rows['password']),
|
||||
'commentsNum' => empty($rows['commentsNum']) ? 0 : $rows['commentsNum'],
|
||||
'allowComment' => !empty($rows['allowComment']) && 1 == $rows['allowComment'] ? 1 : 0,
|
||||
'allowPing' => !empty($rows['allowPing']) && 1 == $rows['allowPing'] ? 1 : 0,
|
||||
@ -230,11 +230,11 @@ class Contents extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
'title' => !isset($rows['title']) || strlen($rows['title']) === 0
|
||||
? null : htmlspecialchars($rows['title']),
|
||||
'order' => empty($rows['order']) ? 0 : intval($rows['order']),
|
||||
'text' => !isset($rows['text']) || strlen($rows['text']) === 0 ? null : $rows['text'],
|
||||
'template' => empty($rows['template']) ? null : $rows['template'],
|
||||
'type' => empty($rows['type']) ? 'post' : $rows['type'],
|
||||
'status' => empty($rows['status']) ? 'publish' : $rows['status'],
|
||||
'password' => empty($rows['password']) ? null : $rows['password'],
|
||||
'text' => Common::strBy($rows['text']),
|
||||
'template' => Common::strBy($rows['template']),
|
||||
'type' => Common::strBy($rows['type'], 'post'),
|
||||
'status' => Common::strBy($rows['status'], 'publish'),
|
||||
'password' => Common::strBy($rows['password']),
|
||||
'allowComment' => !empty($rows['allowComment']) && 1 == $rows['allowComment'] ? 1 : 0,
|
||||
'allowPing' => !empty($rows['allowPing']) && 1 == $rows['allowPing'] ? 1 : 0,
|
||||
'allowFeed' => !empty($rows['allowFeed']) && 1 == $rows['allowFeed'] ? 1 : 0,
|
||||
|
@ -95,7 +95,7 @@ class Edit extends Contents implements ActionInterface
|
||||
|
||||
/** 取出数据 */
|
||||
$input = $this->request->from('name', 'slug', 'description');
|
||||
$input['slug'] = Common::slugName(empty($input['slug']) ? $input['name'] : $input['slug']);
|
||||
$input['slug'] = Common::slugName(Common::strBy($input['slug'], $input['name']));
|
||||
|
||||
$attachment['title'] = $input['name'];
|
||||
$attachment['slug'] = $input['slug'];
|
||||
|
@ -133,7 +133,7 @@ class Edit extends Metas implements ActionInterface
|
||||
/** 取出数据 */
|
||||
$category = $this->request->from('name', 'slug', 'description', 'parent');
|
||||
|
||||
$category['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
|
||||
$category['slug'] = Common::slugName(Common::strBy($category['slug'], $category['name']));
|
||||
$category['type'] = 'category';
|
||||
$category['order'] = $this->getMaxOrder('category', $category['parent']) + 1;
|
||||
|
||||
@ -284,7 +284,7 @@ class Edit extends Metas implements ActionInterface
|
||||
/** 取出数据 */
|
||||
$category = $this->request->from('name', 'slug', 'description', 'parent');
|
||||
$category['mid'] = $this->request->get('mid');
|
||||
$category['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
|
||||
$category['slug'] = Common::slugName(Common::strBy($category['slug'], $category['name']));
|
||||
$category['type'] = 'category';
|
||||
$current = $this->db->fetchRow($this->select()->where('mid = ?', $category['mid']));
|
||||
|
||||
|
@ -132,7 +132,7 @@ class Edit extends Metas implements ActionInterface
|
||||
/** 取出数据 */
|
||||
$tag = $this->request->from('name', 'slug');
|
||||
$tag['type'] = 'tag';
|
||||
$tag['slug'] = Common::slugName(empty($tag['slug']) ? $tag['name'] : $tag['slug']);
|
||||
$tag['slug'] = Common::slugName(Common::strBy($tag['slug'], $tag['name']));
|
||||
|
||||
/** 插入数据 */
|
||||
$tag['mid'] = $this->insert($tag);
|
||||
@ -254,7 +254,7 @@ class Edit extends Metas implements ActionInterface
|
||||
/** 取出数据 */
|
||||
$tag = $this->request->from('name', 'slug', 'mid');
|
||||
$tag['type'] = 'tag';
|
||||
$tag['slug'] = Common::slugName(empty($tag['slug']) ? $tag['name'] : $tag['slug']);
|
||||
$tag['slug'] = Common::slugName(Common::strBy($tag['slug'], $tag['name']));
|
||||
|
||||
/** 更新数据 */
|
||||
$this->update($tag, $this->db->sql()->where('mid = ?', $this->request->filter('int')->get('mid')));
|
||||
|
@ -449,9 +449,9 @@ class XmlRpc extends Contents implements ActionInterface, Hook
|
||||
{
|
||||
/** 开始接受数据 */
|
||||
$input['name'] = $category['name'];
|
||||
$input['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
|
||||
$input['slug'] = Common::slugName(Common::strBy($category['slug'], $category['name']));
|
||||
$input['parent'] = $category['parent_id'] ?? ($category['parent'] ?? 0);
|
||||
$input['description'] = $category['description'] ?? $category['name'];
|
||||
$input['description'] = Common::strBy($category['description'], $category['name']);
|
||||
|
||||
/** 调用已有组件 */
|
||||
$categoryWidget = CategoryEdit::alloc(null, $input, function (CategoryEdit $category) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user