mirror of
https://github.com/typecho/typecho.git
synced 2025-04-04 18:22:23 +02:00
fix #1632
This commit is contained in:
parent
b00a0ae06f
commit
b28d5b7bab
@ -178,12 +178,11 @@ class Request
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($value)) {
|
||||
if (isset($value) && $value !== '') {
|
||||
$exists = true;
|
||||
if (is_array($default) == is_array($value)) {
|
||||
$exists = is_array($value) || (is_string($value) && strlen($value) > 0);
|
||||
return $value;
|
||||
} else {
|
||||
$exists = true;
|
||||
return $default;
|
||||
}
|
||||
} else {
|
||||
|
@ -80,16 +80,4 @@ class Options extends Base implements QueryInterface
|
||||
{
|
||||
return $this->db->fetchObject($condition->select(['COUNT(name)' => 'num'])->from('table.options'))->num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以checkbox选项判断是否某个值被启用
|
||||
*
|
||||
* @param mixed $settings 选项集合
|
||||
* @param string $name 选项名称
|
||||
* @return integer
|
||||
*/
|
||||
protected function isEnableByCheckbox($settings, string $name): int
|
||||
{
|
||||
return is_array($settings) && in_array($name, $settings) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
@ -36,72 +36,6 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
*/
|
||||
class Users extends Base implements QueryInterface
|
||||
{
|
||||
/**
|
||||
* 判断用户名称是否存在
|
||||
*
|
||||
* @param string $name 用户名称
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function nameExists(string $name): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.users')
|
||||
->where('name = ?', $name)
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->is('uid')) {
|
||||
$select->where('uid <> ?', $this->request->get('uid'));
|
||||
}
|
||||
|
||||
$user = $this->db->fetchRow($select);
|
||||
return !$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断电子邮件是否存在
|
||||
*
|
||||
* @param string $mail 电子邮件
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mailExists(string $mail): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.users')
|
||||
->where('mail = ?', $mail)
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->is('uid')) {
|
||||
$select->where('uid <> ?', $this->request->get('uid'));
|
||||
}
|
||||
|
||||
$user = $this->db->fetchRow($select);
|
||||
return !$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户昵称是否存在
|
||||
*
|
||||
* @param string $screenName 昵称
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function screenNameExists(string $screenName): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.users')
|
||||
->where('screenName = ?', $screenName)
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->is('uid')) {
|
||||
$select->where('uid <> ?', $this->request->get('uid'));
|
||||
}
|
||||
|
||||
$user = $this->db->fetchRow($select);
|
||||
return !$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将每行的值压入堆栈
|
||||
*
|
||||
@ -232,27 +166,4 @@ class Users extends Base implements QueryInterface
|
||||
|
||||
return new Config($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取页面偏移
|
||||
*
|
||||
* @param string $column 字段名
|
||||
* @param integer $offset 偏移值
|
||||
* @param string|null $group 用户组
|
||||
* @param integer $pageSize 分页值
|
||||
* @return integer
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getPageOffset(string $column, int $offset, ?string $group = null, int $pageSize = 20): int
|
||||
{
|
||||
$select = $this->db->select(['COUNT(uid)' => 'num'])->from('table.users')
|
||||
->where("table.users.{$column} > {$offset}");
|
||||
|
||||
if (!empty($group)) {
|
||||
$select->where('table.users.group = ?', $group);
|
||||
}
|
||||
|
||||
$count = $this->db->fetchObject($select)->num + 1;
|
||||
return ceil($count / $pageSize);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
*/
|
||||
class Discussion extends Options implements ActionInterface
|
||||
{
|
||||
use EditTrait;
|
||||
|
||||
/**
|
||||
* 执行更新动作
|
||||
*
|
||||
|
21
var/Widget/Options/EditTrait.php
Normal file
21
var/Widget/Options/EditTrait.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Widget\Options;
|
||||
|
||||
/**
|
||||
* 编辑选项组件
|
||||
*/
|
||||
trait EditTrait
|
||||
{
|
||||
/**
|
||||
* 以checkbox选项判断是否某个值被启用
|
||||
*
|
||||
* @param mixed $settings 选项集合
|
||||
* @param string $name 选项名称
|
||||
* @return integer
|
||||
*/
|
||||
protected function isEnableByCheckbox($settings, string $name): int
|
||||
{
|
||||
return is_array($settings) && in_array($name, $settings) ? 1 : 0;
|
||||
}
|
||||
}
|
@ -24,6 +24,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
*/
|
||||
class General extends Options implements ActionInterface
|
||||
{
|
||||
use EditTrait;
|
||||
|
||||
/**
|
||||
* 检查是否在语言列表中
|
||||
*
|
||||
|
@ -24,6 +24,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
*/
|
||||
class Edit extends Users implements ActionInterface
|
||||
{
|
||||
use EditTrait;
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
|
100
var/Widget/Users/EditTrait.php
Normal file
100
var/Widget/Users/EditTrait.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Widget\Users;
|
||||
|
||||
use Typecho\Db\Exception;
|
||||
|
||||
/**
|
||||
* 编辑用户组件
|
||||
*/
|
||||
trait EditTrait
|
||||
{
|
||||
/**
|
||||
* 判断用户名称是否存在
|
||||
*
|
||||
* @param string $name 用户名称
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function nameExists(string $name): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.users')
|
||||
->where('name = ?', $name)
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->is('uid')) {
|
||||
$select->where('uid <> ?', $this->request->get('uid'));
|
||||
}
|
||||
|
||||
$user = $this->db->fetchRow($select);
|
||||
return !$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断电子邮件是否存在
|
||||
*
|
||||
* @param string $mail 电子邮件
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mailExists(string $mail): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.users')
|
||||
->where('mail = ?', $mail)
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->is('uid')) {
|
||||
$select->where('uid <> ?', $this->request->get('uid'));
|
||||
}
|
||||
|
||||
$user = $this->db->fetchRow($select);
|
||||
return !$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户昵称是否存在
|
||||
*
|
||||
* @param string $screenName 昵称
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public function screenNameExists(string $screenName): bool
|
||||
{
|
||||
$select = $this->db->select()
|
||||
->from('table.users')
|
||||
->where('screenName = ?', $screenName)
|
||||
->limit(1);
|
||||
|
||||
if ($this->request->is('uid')) {
|
||||
$select->where('uid <> ?', $this->request->get('uid'));
|
||||
}
|
||||
|
||||
$user = $this->db->fetchRow($select);
|
||||
return !$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取页面偏移
|
||||
*
|
||||
* @param string $column 字段名
|
||||
* @param integer $offset 偏移值
|
||||
* @param string|null $group 用户组
|
||||
* @param integer $pageSize 分页值
|
||||
* @return integer
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getPageOffset(string $column, int $offset, ?string $group = null, int $pageSize = 20): int
|
||||
{
|
||||
$select = $this->db->select(['COUNT(uid)' => 'num'])->from('table.users')
|
||||
->where("table.users.{$column} > {$offset}");
|
||||
|
||||
if (!empty($group)) {
|
||||
$select->where('table.users.group = ?', $group);
|
||||
}
|
||||
|
||||
$count = $this->db->fetchObject($select)->num + 1;
|
||||
return ceil($count / $pageSize);
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ use Typecho\Widget\Helper\Form;
|
||||
use Utils\PasswordHash;
|
||||
use Widget\ActionInterface;
|
||||
use Widget\Base\Options;
|
||||
use Widget\Base\Users;
|
||||
use Widget\Notice;
|
||||
use Widget\Plugins\Rows;
|
||||
|
||||
@ -24,8 +25,10 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Profile extends Edit implements ActionInterface
|
||||
class Profile extends Users implements ActionInterface
|
||||
{
|
||||
use EditTrait;
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user