Feat/code refactor (#1626)

* remove all magic methods, add type for class properties

* refactor codes

* fix all

* refactor code

* fix type

* fix all

* fix request is method

* fix all

* fix router

* fix get page
This commit is contained in:
joyqi
2023-09-24 16:21:32 +08:00
committed by GitHub
parent 9b107027ed
commit 4c8c64c79e
113 changed files with 871 additions and 860 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ if (!defined('__TYPECHO_ROOT_DIR__') && !@include_once __DIR__ . '/../config.inc
\Widget\Init::alloc();
/** 注册一个初始化插件 */
\Typecho\Plugin::factory('admin/common.php')->begin();
\Typecho\Plugin::factory('admin/common.php')->call('begin');
\Widget\Options::alloc()->to($options);
\Widget\User::alloc()->to($user);
+1 -1
View File
@@ -109,7 +109,7 @@ $(document).ready(function () {
}
});
<?php \Typecho\Plugin::factory('admin/editor-js.php')->markdownEditor($content); ?>
<?php \Typecho\Plugin::factory('admin/editor-js.php')->call('markdownEditor', $content); ?>
var th = textarea.height(), ph = preview.height(),
uploadBtn = $('<button type="button" id="btn-fullscreen-upload" class="btn btn-link">'
+2 -2
View File
@@ -1,7 +1,7 @@
<?php if(!defined('__TYPECHO_ADMIN__')) exit; ?>
<?php \Typecho\Plugin::factory('admin/footer.php')->begin(); ?>
<?php \Typecho\Plugin::factory('admin/footer.php')->call('begin'); ?>
</body>
</html>
<?php
/** 注册一个结束插件 */
\Typecho\Plugin::factory('admin/footer.php')->end();
\Typecho\Plugin::factory('admin/footer.php')->call('end');
+1 -1
View File
@@ -8,7 +8,7 @@ $header = '<link rel="stylesheet" href="' . $options->adminStaticUrl('css', 'nor
<link rel="stylesheet" href="' . $options->adminStaticUrl('css', 'style.css', true) . '">';
/** 注册一个初始化插件 */
$header = \Typecho\Plugin::factory('admin/header.php')->header($header);
$header = \Typecho\Plugin::factory('admin/header.php')->call('header', $header);
?><!DOCTYPE HTML>
<html>
+2 -2
View File
@@ -17,11 +17,11 @@ include 'header.php';
<form action="<?php $options->loginAction(); ?>" method="post" name="login" role="form">
<p>
<label for="name" class="sr-only"><?php _e('用户名'); ?></label>
<input type="text" id="name" name="name" value="<?php echo $rememberName; ?>" placeholder="<?php _e('用户名'); ?>" class="text-l w-100" autofocus />
<input type="text" id="name" name="name" value="<?php echo $rememberName; ?>" placeholder="<?php _e('用户名'); ?>" class="text-l w-100" autofocus required />
</p>
<p>
<label for="password" class="sr-only"><?php _e('密码'); ?></label>
<input type="password" id="password" name="password" class="text-l w-100" placeholder="<?php _e('密码'); ?>" />
<input type="password" id="password" name="password" class="text-l w-100" placeholder="<?php _e('密码'); ?>" required />
</p>
<p class="submit">
<button type="submit" class="btn btn-l w-100 primary"><?php _e('登录'); ?></button>
+1 -1
View File
@@ -5,7 +5,7 @@
<?php $menu->output(); ?>
</nav>
<div class="operate">
<?php \Typecho\Plugin::factory('admin/menu.php')->navBar(); ?><a title="<?php
<?php \Typecho\Plugin::factory('admin/menu.php')->call('navBar'); ?><a title="<?php
if ($user->logged > 0) {
$logged = new \Typecho\Date($user->logged);
_e('最后登录: %s', $logged->word());
+1 -1
View File
@@ -57,6 +57,6 @@ $stat = \Widget\Stat::alloc();
include 'copyright.php';
include 'common-js.php';
include 'form-js.php';
\Typecho\Plugin::factory('admin/profile.php')->bottom();
\Typecho\Plugin::factory('admin/profile.php')->call('bottom');
include 'footer.php';
?>
+1 -1
View File
@@ -60,6 +60,6 @@ include 'menu.php';
<?php
include 'copyright.php';
include 'common-js.php';
\Typecho\Plugin::factory('admin/theme-editor.php')->bottom($files);
\Typecho\Plugin::factory('admin/theme-editor.php')->call('bottom', $files);
include 'footer.php';
?>
+1 -1
View File
@@ -1,5 +1,5 @@
<?php if(!defined('__TYPECHO_ADMIN__')) exit; ?>
<?php \Typecho\Plugin::factory('admin/write-js.php')->write(); ?>
<?php \Typecho\Plugin::factory('admin/write-js.php')->call('write'); ?>
<?php \Widget\Metas\Tag\Cloud::alloc('sort=count&desc=1&limit=200')->to($tags); ?>
<script src="<?php $options->adminStaticUrl('js', 'timepicker.js'); ?>"></script>
+4 -4
View File
@@ -66,7 +66,7 @@ include 'menu.php';
</span>
</p>
<?php \Typecho\Plugin::factory('admin/write-page.php')->content($page); ?>
<?php \Typecho\Plugin::factory('admin/write-page.php')->call('content', $page); ?>
</div>
<div id="edit-secondary" class="col-mb-12 col-tb-3" role="complementary">
<ul class="typecho-option-tabs clearfix">
@@ -104,7 +104,7 @@ include 'menu.php';
<p class="description"><?php _e('如果你为此页面选择了一个自定义模板, 系统将按照你选择的模板文件展现它'); ?></p>
</section>
<?php \Typecho\Plugin::factory('admin/write-page.php')->option($page); ?>
<?php \Typecho\Plugin::factory('admin/write-page.php')->call('option', $page); ?>
<button type="button" id="advance-panel-btn" class="btn btn-xs"><?php _e('高级选项'); ?> <i
class="i-caret-down"></i></button>
@@ -136,7 +136,7 @@ include 'menu.php';
</ul>
</section>
<?php \Typecho\Plugin::factory('admin/write-page.php')->advanceOption($page); ?>
<?php \Typecho\Plugin::factory('admin/write-page.php')->call('advanceOption', $page); ?>
</div>
<?php if ($page->have()): ?>
<?php $modified = new \Typecho\Date($page->modified); ?>
@@ -167,7 +167,7 @@ include 'common-js.php';
include 'form-js.php';
include 'write-js.php';
\Typecho\Plugin::factory('admin/write-page.php')->trigger($plugged)->richEditor($page);
\Typecho\Plugin::factory('admin/write-page.php')->trigger($plugged)->call('richEditor', $page);
if (!$plugged) {
include 'editor-js.php';
}
+5 -5
View File
@@ -71,7 +71,7 @@ include 'menu.php';
</span>
</p>
<?php \Typecho\Plugin::factory('admin/write-post.php')->content($post); ?>
<?php \Typecho\Plugin::factory('admin/write-post.php')->call('content', $post); ?>
</div>
<div id="edit-secondary" class="col-mb-12 col-tb-3" role="complementary">
@@ -118,7 +118,7 @@ include 'menu.php';
class="w-100 text"/></p>
</section>
<?php \Typecho\Plugin::factory('admin/write-post.php')->option($post); ?>
<?php \Typecho\Plugin::factory('admin/write-post.php')->call('option', $post); ?>
<button type="button" id="advance-panel-btn" class="btn btn-xs"><?php _e('高级选项'); ?> <i
class="i-caret-down"></i></button>
@@ -172,7 +172,7 @@ include 'menu.php';
<p class="description"><?php _e('每一行一个引用地址, 用回车隔开'); ?></p>
</section>
<?php \Typecho\Plugin::factory('admin/write-post.php')->advanceOption($post); ?>
<?php \Typecho\Plugin::factory('admin/write-post.php')->call('advanceOption', $post); ?>
</div><!-- end #advance-panel -->
<?php if ($post->have()): ?>
@@ -204,13 +204,13 @@ include 'common-js.php';
include 'form-js.php';
include 'write-js.php';
\Typecho\Plugin::factory('admin/write-post.php')->trigger($plugged)->richEditor($post);
\Typecho\Plugin::factory('admin/write-post.php')->trigger($plugged)->call('richEditor', $post);
if (!$plugged) {
include 'editor-js.php';
}
include 'file-upload-js.php';
include 'custom-fields-js.php';
\Typecho\Plugin::factory('admin/write-post.php')->bottom($post);
\Typecho\Plugin::factory('admin/write-post.php')->call('bottom', $post);
include 'footer.php';
?>
+1 -1
View File
@@ -256,7 +256,7 @@ function install_get_default_options(): array
'frontArchive' => 0,
'commentsRequireMail' => 1,
'commentsWhitelist' => 0,
'commentsRequireURL' => 0,
'commentsRequireUrl' => 0,
'commentsRequireModeration' => 0,
'plugins' => 'a:0:{}',
'commentDateFormat' => 'F jS, Y \a\t h:i a',
+1 -1
View File
@@ -32,7 +32,7 @@
<div class="grid">
<input type="text" placeholder="<?php _e('名字'); ?>" name="author" id="author" value="<?php $this->remember('author'); ?>" required/>
<input type="email" placeholder="<?php _e('Email'); ?>" name="mail" id="mail" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?> />
<input type="url" placeholder="<?php _e('网站'); ?><?php if (!($this->options->commentsRequireURL)): ?><?php _e('(选填)'); ?><?php endif; ?>" name="url" id="url" placeholder="<?php _e('https://'); ?>" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
<input type="url" placeholder="<?php _e('网站'); ?><?php if (!($this->options->commentsRequireUrl)): ?><?php _e('(选填)'); ?><?php endif; ?>" name="url" id="url" placeholder="<?php _e('https://'); ?>" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireUrl): ?> required<?php endif; ?> />
</div>
<?php endif; ?>
<button type="submit"><?php _e('提交评论'); ?></button>
+2 -2
View File
@@ -37,9 +37,9 @@
</p>
<p>
<label
for="url"<?php if ($this->options->commentsRequireURL): ?> class="required"<?php endif; ?>><?php _e('网站'); ?></label>
for="url"<?php if ($this->options->commentsRequireUrl): ?> class="required"<?php endif; ?>><?php _e('网站'); ?></label>
<input type="url" name="url" id="url" class="text" placeholder="<?php _e('http://'); ?>"
value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireUrl): ?> required<?php endif; ?> />
</p>
<?php endif; ?>
<p>
+1 -1
View File
@@ -14,7 +14,7 @@ class Base64
*
* @var string
*/
private $data;
private string $data;
/**
* 初始化数据
+5 -5
View File
@@ -20,33 +20,33 @@ class Client
*
* @var string
*/
private $url;
private string $url;
/**
* 消息体
*
* @var Message
*/
private $message;
private Message $message;
/**
* 调试开关
*
* @var boolean
*/
private $debug = false;
private bool $debug = false;
/**
* 请求前缀
*
* @var string|null
*/
private $prefix;
private ?string $prefix;
/**
* @var Error
*/
private $error;
private Error $error;
/**
* 客户端构造函数
+12 -12
View File
@@ -9,17 +9,17 @@ namespace IXR;
*/
class Date
{
private $year;
private int $year;
private $month;
private int $month;
private $day;
private int $day;
private $hour;
private int $hour;
private $minute;
private int $minute;
private $second;
private int $second;
/**
* @param int|string $time
@@ -39,12 +39,12 @@ class Date
*/
private function parseTimestamp(int $timestamp)
{
$this->year = date('Y', $timestamp);
$this->month = date('m', $timestamp);
$this->day = date('d', $timestamp);
$this->hour = date('H', $timestamp);
$this->minute = date('i', $timestamp);
$this->second = date('s', $timestamp);
$this->year = intval(date('Y', $timestamp));
$this->month = intval(date('m', $timestamp));
$this->day = intval(date('d', $timestamp));
$this->hour = intval(date('H', $timestamp));
$this->minute = intval(date('i', $timestamp));
$this->second = intval(date('s', $timestamp));
}
/**
+2 -2
View File
@@ -15,7 +15,7 @@ class Error
* @access public
* @var integer
*/
public $code;
public int $code;
/**
* 错误消息
@@ -23,7 +23,7 @@ class Error
* @access public
* @var string|null
*/
public $message;
public ?string $message;
/**
* 构造函数
+14 -14
View File
@@ -12,35 +12,35 @@ class Message
/**
* @var string
*/
public $message;
public string $message;
/**
* @var string
*/
public $messageType; // methodCall / methodResponse / fault
public string $messageType; // methodCall / methodResponse / fault
public $faultCode;
public int $faultCode;
public $faultString;
public string $faultString;
/**
* @var string
*/
public $methodName;
public string $methodName;
/**
* @var array
*/
public $params = [];
public array $params = [];
// Current variable stacks
private $arrayStructs = []; // The stack used to keep track of the current array/struct
private array $arrayStructs = []; // The stack used to keep track of the current array/struct
private $arrayStructsTypes = []; // Stack keeping track of if things are structs or array
private array $arrayStructsTypes = []; // Stack keeping track of if things are structs or array
private $currentStructName = []; // A stack as well
private array $currentStructName = []; // A stack as well
private $currentTagContents;
private string $currentTagContents;
/**
* @param string $message
@@ -76,7 +76,7 @@ class Message
xml_parser_free($parser);
// Grab the error messages, if any
if ($this->messageType == 'fault') {
$this->faultCode = $this->params[0]['faultCode'];
$this->faultCode = intval($this->params[0]['faultCode']);
$this->faultString = $this->params[0]['faultString'];
}
return true;
@@ -84,7 +84,7 @@ class Message
/**
* @param $parser
* @param $tag
* @param string $tag
* @param $attr
*/
private function tagOpen($parser, string $tag, $attr)
@@ -133,7 +133,7 @@ class Message
$this->currentTagContents = '';
break;
case 'string':
$value = (string)trim($this->currentTagContents);
$value = trim($this->currentTagContents);
$this->currentTagContents = '';
break;
case 'dateTime.iso8601':
@@ -144,7 +144,7 @@ class Message
case 'value':
// "If no type is indicated, the type is string."
if (trim($this->currentTagContents) != '') {
$value = (string) $this->currentTagContents;
$value = $this->currentTagContents;
$this->currentTagContents = '';
}
break;
+3 -3
View File
@@ -14,12 +14,12 @@ class Pingback
/**
* @var string
*/
private $html;
private string $html;
/**
* @var string
*/
private $target;
private string $target;
/**
* @param string $url
@@ -73,7 +73,7 @@ class Pingback
*/
public function getTitle(): string
{
if (preg_match("/\<title\>([^<]*?)\<\/title\\>/is", $this->html, $matchTitle)) {
if (preg_match("/<title>([^<]*?)<\/title>/is", $this->html, $matchTitle)) {
return Common::subStr(Common::removeXSS(trim(strip_tags($matchTitle[1]))), 0, 150, '...');
}
+1 -1
View File
@@ -12,7 +12,7 @@ class Request
/**
* @var string
*/
private $xml;
private string $xml;
/**
* @param string $method
+5 -5
View File
@@ -16,19 +16,19 @@ class Server
*
* @var array
*/
private $callbacks;
private array $callbacks;
/**
* 默认参数
*
* @var array
*/
private $capabilities;
private array $capabilities;
/**
* @var Hook
*/
private $hook;
private Hook $hook;
/**
* 构造函数
@@ -248,9 +248,9 @@ class Server
*
* @access private
* @param string $method 方法名
* @return mixed
* @return bool
*/
private function hasMethod(string $method)
private function hasMethod(string $method): bool
{
return in_array($method, array_keys($this->callbacks));
}
+3 -3
View File
@@ -11,13 +11,13 @@ class Value
{
private $data;
private $type;
private ?string $type;
/**
* @param mixed $data
* @param bool|string $type
* @param string|null $type
*/
public function __construct($data, $type = false)
public function __construct($data, ?string $type)
{
$this->data = $data;
if (!$type) {
+6 -6
View File
@@ -378,8 +378,8 @@ EOF;
}
//非自闭合html标签列表
preg_match_all("/<([_0-9a-zA-Z-\:]+)\s*([^>]*)>/is", $string, $startTags);
preg_match_all("/<\/([_0-9a-zA-Z-\:]+)>/is", $string, $closeTags);
preg_match_all("/<([_0-9a-zA-Z-:]+)\s*([^>]*)>/is", $string, $startTags);
preg_match_all("/<\/([_0-9a-zA-Z-:]+)>/is", $string, $closeTags);
if (!empty($startTags[1]) && is_array($startTags[1])) {
krsort($startTags[1]);
@@ -410,7 +410,7 @@ EOF;
}
}
return preg_replace("/\<br\s*\/\>\s*\<\/p\>/is", '</p>', $string);
return preg_replace("/<br\s*\/>\s*<\/p>/is", '</p>', $string);
}
/**
@@ -432,7 +432,7 @@ EOF;
$normalizeTags = '';
$allowableAttributes = [];
if (!empty($allowableTags) && preg_match_all("/\<([_a-z0-9-]+)([^>]*)\>/is", $allowableTags, $tags)) {
if (!empty($allowableTags) && preg_match_all("/<([_a-z0-9-]+)([^>]*)>/is", $allowableTags, $tags)) {
$normalizeTags = '<' . implode('><', array_map('strtolower', $tags[1])) . '>';
$attributes = array_map('trim', $tags[2]);
foreach ($attributes as $key => $val) {
@@ -546,8 +546,8 @@ EOF;
$params = array_map(function ($string) {
$string = str_replace(['%0d', '%0a'], '', strip_tags($string));
return preg_replace([
"/\(\s*(\"|')/i", //函数开头
"/(\"|')\s*\)/i", //函数结尾
"/\(\s*([\"'])/i", //函数开头
"/([\"'])\s*\)/i", //函数结尾
], '', $string);
}, $params);
+1 -1
View File
@@ -18,7 +18,7 @@ class Config implements \Iterator, \ArrayAccess
* @access private
* @var array
*/
private $currentConfig = [];
private array $currentConfig = [];
/**
* 实例化一个当前配置
+14 -7
View File
@@ -17,7 +17,7 @@ class Cookie
* @var string
* @access private
*/
private static $prefix = '';
private static string $prefix = '';
/**
* 路径
@@ -25,25 +25,25 @@ class Cookie
* @var string
* @access private
*/
private static $path = '/';
private static string $path = '/';
/**
* @var string
* @access private
*/
private static $domain = '';
private static string $domain = '';
/**
* @var bool
* @access private
*/
private static $secure = false;
private static bool $secure = false;
/**
* @var bool
* @access private
*/
private static $httponly = false;
private static bool $httponly = false;
/**
* 获取前缀
@@ -141,7 +141,15 @@ class Cookie
{
$key = self::$prefix . $key;
$_COOKIE[$key] = $value;
Response::getInstance()->setCookie($key, $value, $expire, self::$path, self::$domain, self::$secure, self::$httponly);
Response::getInstance()->setCookie(
$key,
$value,
$expire,
self::$path,
self::$domain,
self::$secure,
self::$httponly
);
}
/**
@@ -160,4 +168,3 @@ class Cookie
unset($_COOKIE[$key]);
}
}
+7 -7
View File
@@ -17,7 +17,7 @@ class Date
* @access public
* @var integer
*/
public static $timezoneOffset = 0;
public static int $timezoneOffset = 0;
/**
* 服务器时区偏移
@@ -25,7 +25,7 @@ class Date
* @access public
* @var integer
*/
public static $serverTimezoneOffset = 0;
public static int $serverTimezoneOffset = 0;
/**
* 当前的服务器时间戳
@@ -33,7 +33,7 @@ class Date
* @access public
* @var integer
*/
public static $serverTimeStamp;
public static int $serverTimeStamp = 0;
/**
* 可以被直接转换的时间戳
@@ -41,22 +41,22 @@ class Date
* @access public
* @var integer
*/
public $timeStamp = 0;
public int $timeStamp = 0;
/**
* @var string
*/
public $year;
public string $year;
/**
* @var string
*/
public $month;
public string $month;
/**
* @var string
*/
public $day;
public string $day;
/**
* 初始化参数
+6 -6
View File
@@ -55,14 +55,14 @@ class Db
* 数据库适配器
* @var Adapter
*/
private $adapter;
private Adapter $adapter;
/**
* 默认配置
*
* @var array
*/
private $config;
private array $config;
/**
* 已经连接
@@ -70,7 +70,7 @@ class Db
* @access private
* @var array
*/
private $connectedPool;
private array $connectedPool;
/**
* 前缀
@@ -78,7 +78,7 @@ class Db
* @access private
* @var string
*/
private $prefix;
private string $prefix;
/**
* 适配器名称
@@ -86,13 +86,13 @@ class Db
* @access private
* @var string
*/
private $adapterName;
private string $adapterName;
/**
* 实例化的数据库对象
* @var Db
*/
private static $instance;
private static Db $instance;
/**
* 数据库类构造函数
+1 -1
View File
@@ -25,7 +25,7 @@ class Mysqli implements Adapter
* @access private
* @var \mysqli
*/
private $dbLink;
private \mysqli $dbLink;
/**
* 判断适配器是否可用
+2 -2
View File
@@ -23,7 +23,7 @@ abstract class Pdo implements Adapter
* @access protected
* @var \PDO
*/
protected $object;
protected \PDO $object;
/**
* 最后一次操作的数据表
@@ -31,7 +31,7 @@ abstract class Pdo implements Adapter
* @access protected
* @var string
*/
protected $lastTable;
protected string $lastTable;
/**
* 判断适配器是否可用
+3 -3
View File
@@ -11,17 +11,17 @@ trait PgsqlTrait
/**
* @var array
*/
private $pk = [];
private array $pk = [];
/**
* @var bool
*/
private $compatibleInsert = false;
private bool $compatibleInsert = false;
/**
* @var string|null
*/
private $lastInsertTable = null;
private ?string $lastInsertTable = null;
/**
* 清空数据表
+1 -1
View File
@@ -9,7 +9,7 @@ trait SQLiteTrait
{
use QueryTrait;
private $isSQLite2 = false;
private bool $isSQLite2 = false;
/**
* 清空数据表
+5 -6
View File
@@ -29,7 +29,7 @@ class Query
* @var array
* @access private
*/
private static $default = [
private static array $default = [
'action' => null,
'table' => null,
'fields' => '*',
@@ -48,14 +48,14 @@ class Query
*
* @var Adapter
*/
private $adapter;
private Adapter $adapter;
/**
* 查询语句预结构,由数组构成,方便组合为SQL查询字符串
*
* @var array
*/
private $sqlPreBuild;
private array $sqlPreBuild;
/**
* 前缀
@@ -63,12 +63,12 @@ class Query
* @access private
* @var string
*/
private $prefix;
private string $prefix;
/**
* @var array
*/
private $params = [];
private array $params = [];
/**
* 构造函数,引用数据库适配器作为内部数据
@@ -211,7 +211,6 @@ class Query
$split .= $cha;
$lastIsAlnum = false;
}
}
return $result;
+10 -10
View File
@@ -33,7 +33,7 @@ class Feed
* @access private
* @var string
*/
private $type;
private string $type;
/**
* 字符集编码
@@ -41,7 +41,7 @@ class Feed
* @access private
* @var string
*/
private $charset;
private string $charset;
/**
* 语言状态
@@ -49,7 +49,7 @@ class Feed
* @access private
* @var string
*/
private $lang;
private string $lang;
/**
* 聚合地址
@@ -57,7 +57,7 @@ class Feed
* @access private
* @var string
*/
private $feedUrl;
private string $feedUrl;
/**
* 基本地址
@@ -65,7 +65,7 @@ class Feed
* @access private
* @var string
*/
private $baseUrl;
private string $baseUrl;
/**
* 聚合标题
@@ -73,7 +73,7 @@ class Feed
* @access private
* @var string
*/
private $title;
private string $title;
/**
* 聚合副标题
@@ -81,7 +81,7 @@ class Feed
* @access private
* @var string
*/
private $subTitle;
private string $subTitle;
/**
* 版本信息
@@ -89,7 +89,7 @@ class Feed
* @access private
* @var string
*/
private $version;
private string $version;
/**
* 所有的items
@@ -97,7 +97,7 @@ class Feed
* @access private
* @var array
*/
private $items = [];
private array $items = [];
/**
* 创建Feed对象
@@ -382,7 +382,7 @@ xml:base="' . $this->baseUrl . '"
$result .= '<title type="text">' . htmlspecialchars($this->title) . '</title>
<subtitle type="text">' . htmlspecialchars($this->subTitle ?? '') . '</subtitle>
<updated>' . $this->dateFormat($lastUpdate) . '</updated>
<generator uri="http://typecho.org/" version="' . $this->version . '">Typecho</generator>
<generator uri="https://typecho.org/" version="' . $this->version . '">Typecho</generator>
<link rel="alternate" type="text/html" href="' . $this->baseUrl . '" />
<id>' . $this->feedUrl . '</id>
<link rel="self" type="application/atom+xml" href="' . $this->feedUrl . '" />
+12 -12
View File
@@ -30,33 +30,33 @@ class Client
*
* @var string
*/
private $method = self::METHOD_GET;
private string $method = self::METHOD_GET;
/**
* 传递参数
*
* @var string
*/
private $query;
private string $query;
/**
* User Agent
*
* @var string
*/
private $agent;
private string $agent;
/**
* 设置超时
*
* @var string
* @var integer
*/
private $timeout = 3;
private int $timeout = 3;
/**
* @var bool
*/
private $multipart = true;
private bool $multipart = true;
/**
* 需要在body中传递的值
@@ -71,40 +71,40 @@ class Client
* @access private
* @var array
*/
private $headers = [];
private array $headers = [];
/**
* cookies
*
* @var array
*/
private $cookies = [];
private array $cookies = [];
/**
* @var array
*/
private $options = [];
private array $options = [];
/**
* 回执头部信息
*
* @var array
*/
private $responseHeader = [];
private array $responseHeader = [];
/**
* 回执代码
*
* @var integer
*/
private $responseStatus;
private int $responseStatus;
/**
* 回执身体
*
* @var string
*/
private $responseBody;
private string $responseBody;
/**
* 设置指定的COOKIE值
+4 -4
View File
@@ -15,17 +15,17 @@ class I18n
* 是否已经载入的标志位
*
* @access private
* @var GetTextMulti
* @var GetTextMulti|null
*/
private static $loaded;
private static ?GetTextMulti $loaded = null;
/**
* 语言文件
*
* @access private
* @var string
* @var string|null
*/
private static $lang = null;
private static ?string $lang = null;
/**
* 翻译文字
+5 -5
View File
@@ -18,7 +18,7 @@ class GetTextMulti
* @access private
* @var GetText[]
*/
private $handlers = [];
private array $handlers = [];
/**
* 构造函数
@@ -48,7 +48,7 @@ class GetTextMulti
* Translates a string
*
* @access public
* @param string string to be translated
* @param string $string string to be translated
* @return string translated string (or original, if not found)
*/
public function translate(string $string): string
@@ -67,9 +67,9 @@ class GetTextMulti
* Plural version of gettext
*
* @access public
* @param string single
* @param string plural
* @param string number
* @param string $single single
* @param string $plural plural
* @param string $number number
* @return string translated plural form
*/
public function ngettext($single, $plural, $number): string
+20 -9
View File
@@ -19,28 +19,28 @@ class Plugin
*
* @var array
*/
private static $plugin = [];
private static array $plugin = [];
/**
* 实例化的插件对象
*
* @var array
*/
private static $instances;
private static array $instances;
/**
* 临时存储变量
*
* @var array
*/
private static $tmp = [];
private static array $tmp = [];
/**
* 唯一句柄
*
* @var string
*/
private $handle;
private string $handle;
/**
* 组件
@@ -54,7 +54,7 @@ class Plugin
*
* @var boolean
*/
private $signal;
private bool $signal;
/**
* 插件初始化
@@ -207,7 +207,7 @@ class Plugin
/** 分行读取 */
$described = false;
$lines = preg_split("(\r|\n)", $token[1]);
$lines = preg_split("([\r\n])", $token[1]);
foreach ($lines as $line) {
$line = trim($line);
if (!empty($line) && '*' == $line[0]) {
@@ -352,9 +352,9 @@ class Plugin
* 判断插件是否存在
*
* @param string $pluginName 插件名称
* @return mixed
* @return bool
*/
public static function exists(string $pluginName)
public static function exists(string $pluginName): bool
{
return array_key_exists($pluginName, self::$plugin['activated']);
}
@@ -433,7 +433,7 @@ class Plugin
* @param array $args 参数
* @return mixed
*/
public function __call(string $component, array $args)
public function call(string $component, ...$args)
{
$component = $this->handle . ':' . $component;
$last = count($args);
@@ -449,4 +449,15 @@ class Plugin
return $args[$last];
}
/**
* @deprecated ^1.3.0
* @param string $component
* @param array $args
* @return false|mixed|null
*/
public function __call(string $component, array $args)
{
return $this->call($component, ... $args);
}
}
+37 -27
View File
@@ -15,7 +15,7 @@ class Request
* @access private
* @var Request
*/
private static $instance;
private static Request $instance;
/**
* 沙箱参数
@@ -23,7 +23,7 @@ class Request
* @access private
* @var Config|null
*/
private $sandbox;
private ?Config $sandbox;
/**
* 用户参数
@@ -31,54 +31,54 @@ class Request
* @access private
* @var Config|null
*/
private $params;
private ?Config $params;
/**
* 路径信息
*
* @access private
* @var string
* @var string|null
*/
private $pathInfo = null;
private ?string $pathInfo = null;
/**
* requestUri
*
* @var string
* @var string|null
* @access private
*/
private $requestUri = null;
private ?string $requestUri = null;
/**
* requestRoot
*
* @var mixed
* @var string|null
* @access private
*/
private $requestRoot = null;
private ?string $requestRoot = null;
/**
* 获取baseurl
*
* @var string
* @var string|null
* @access private
*/
private $baseUrl = null;
private ?string $baseUrl = null;
/**
* 客户端ip地址
*
* @access private
* @var string
* @var string|null
*/
private $ip = null;
private ?string $ip = null;
/**
* 域名前缀
*
* @var string
* @var string|null
*/
private $urlPrefix = null;
private ?string $urlPrefix = null;
/**
* 获取单例句柄
@@ -125,6 +125,18 @@ class Request
return $this;
}
/**
* @return $this
*/
public function endProxy(): Request
{
if (isset($this->params)) {
$this->params = null;
}
return $this;
}
/**
* 获取实际传递参数
*
@@ -135,7 +147,6 @@ class Request
*/
public function get(string $key, $default = null, ?bool &$exists = true)
{
$exists = true;
$value = null;
switch (true) {
@@ -145,17 +156,13 @@ class Request
case isset($this->sandbox):
if (isset($this->sandbox[$key])) {
$value = $this->sandbox[$key];
} else {
$exists = false;
}
break;
case $key === '@json':
$exists = false;
if ($this->isJson()) {
$body = file_get_contents('php://input');
if (false !== $body) {
$exists = true;
$value = json_decode($body, true, 16);
$default = $default ?? $value;
}
@@ -168,18 +175,19 @@ class Request
$value = $_POST[$key];
break;
default:
$exists = false;
break;
}
// reset params
if (isset($this->params)) {
$this->params = null;
}
if (isset($value)) {
return is_array($default) == is_array($value) ? $value : $default;
if (is_array($default) == is_array($value)) {
$exists = is_array($value) || (is_string($value) && strlen($value) > 0);
return $value;
} else {
$exists = false;
return $default;
}
} else {
$exists = false;
return $default;
}
}
@@ -187,6 +195,7 @@ class Request
/**
* 获取实际传递参数(magic)
*
* @deprecated ^1.3.0
* @param string $key 指定参数
* @return mixed
*/
@@ -198,6 +207,7 @@ class Request
/**
* 判断参数是否存在
*
* @deprecated ^1.3.0
* @param string $key 指定参数
* @return boolean
*/
+12 -12
View File
@@ -70,49 +70,49 @@ class Response
* @access private
* @var Response
*/
private static $instance;
private static Response $instance;
/**
* 字符编码
*
* @var string
*/
private $charset = 'UTF-8';
private string $charset = 'UTF-8';
/**
* @var string
*/
private $contentType = 'text/html';
private string $contentType = 'text/html';
/**
* @var callable[]
*/
private $responders = [];
private array $responders = [];
/**
* @var array
*/
private $cookies = [];
private array $cookies = [];
/**
* @var array
*/
private $headers = [];
private array $headers = [];
/**
* @var int
*/
private $status = 200;
private int $status = 200;
/**
* @var bool
*/
private $enableAutoSendHeaders = true;
private bool $enableAutoSendHeaders = true;
/**
* @var bool
*/
private $sandbox = false;
private bool $sandbox = false;
/**
* init responder
@@ -194,7 +194,7 @@ class Response
// set header
foreach ($this->headers as $name => $value) {
if (!in_array(strtolower($name), $sentHeaders)) {
header($name . ': ' . $value, true);
header($name . ': ' . $value);
}
}
@@ -220,7 +220,7 @@ class Response
public function respond()
{
if ($this->sandbox) {
throw new Terminal();
throw new Terminal('sandbox mode');
}
if ($this->enableAutoSendHeaders) {
@@ -301,7 +301,7 @@ class Response
* @param string $contentType 文档类型
* @return $this
*/
public function setContentType(string $contentType = 'text/html'): Response
public function setContentType(string $contentType): Response
{
if (!$this->sandbox) {
$this->contentType = $contentType;
+54 -53
View File
@@ -17,32 +17,32 @@ class Router
*
* @var string
*/
public static $current;
public static string $current;
/**
* 已经解析完毕的路由表配置
*
* @var array
*/
private static $routingTable = [];
private static array $routingTable = [];
/**
* 是否已经匹配过,防止递归匹配
*
* @var bool
*/
private static $matched = false;
private static bool $matched = false;
/**
* 解析路径
*
* @param string|null $pathInfo 全路径
* @param string $pathInfo 全路径
* @param mixed $parameter 输入参数
* @param bool $once 是否只匹配一次
* @return false|Widget
* @throws \Exception
*/
public static function match(?string $pathInfo, $parameter = null, bool $once = true)
public static function match(string $pathInfo, $parameter = null, bool $once = true)
{
if ($once && self::$matched) {
throw new RouterException("Path '{$pathInfo}' not found", 404);
@@ -50,29 +50,17 @@ class Router
self::$matched = true;
foreach (self::$routingTable as $key => $route) {
if (preg_match($route['regx'], $pathInfo, $matches)) {
self::$current = $key;
try {
/** 载入参数 */
$params = null;
if (!empty($route['params'])) {
unset($matches[0]);
$params = array_combine($route['params'], $matches);
}
return Widget::widget($route['widget'], $parameter, $params);
} catch (\Exception $e) {
if (404 == $e->getCode()) {
Widget::destroy($route['widget']);
continue;
}
throw $e;
foreach (self::route($pathInfo) as $result) {
[$route, $params] = $result;
try {
return Widget::widget($route['widget'], $parameter, $params);
} catch (\Exception $e) {
if (404 == $e->getCode()) {
Widget::destroy($route['widget']);
continue;
}
throw $e;
}
}
@@ -89,35 +77,24 @@ class Router
/** 获取PATHINFO */
$pathInfo = Request::getInstance()->getPathInfo();
foreach (self::$routingTable as $key => $route) {
if (preg_match($route['regx'], $pathInfo, $matches)) {
self::$current = $key;
foreach (self::route($pathInfo) as $result) {
[$route, $params] = $result;
try {
/** 载入参数 */
$params = null;
try {
$widget = Widget::widget($route['widget'], null, $params);
if (!empty($route['params'])) {
unset($matches[0]);
$params = array_combine($route['params'], $matches);
}
$widget = Widget::widget($route['widget'], null, $params);
if (isset($route['action'])) {
$widget->{$route['action']}();
}
return;
} catch (\Exception $e) {
if (404 == $e->getCode()) {
Widget::destroy($route['widget']);
continue;
}
throw $e;
if (isset($route['action'])) {
$widget->{$route['action']}();
}
return;
} catch (\Exception $e) {
if (404 == $e->getCode()) {
Widget::destroy($route['widget']);
continue;
}
throw $e;
}
}
@@ -173,4 +150,28 @@ class Router
{
return self::$routingTable[$routeName] ?? null;
}
/**
* @param string $pathInfo
* @return \Generator
* @throws \Exception
*/
private static function route(string $pathInfo): \Generator
{
foreach (self::$routingTable as $key => $route) {
if (preg_match($route['regx'], $pathInfo, $matches)) {
self::$current = $key;
/** 载入参数 */
$params = null;
if (!empty($route['params'])) {
unset($matches[0]);
$params = array_combine($route['params'], $matches);
}
yield [$route, $params];
}
}
}
}
+3 -3
View File
@@ -18,7 +18,7 @@ class Parser
* @access private
* @var array
*/
private $defaultRegex;
private array $defaultRegex;
/**
* 路由器映射表
@@ -26,7 +26,7 @@ class Parser
* @access private
* @var array
*/
private $routingTable;
private array $routingTable;
/**
* 参数表
@@ -34,7 +34,7 @@ class Parser
* @access private
* @var array
*/
private $params;
private array $params;
/**
* 设置路由表
+5 -5
View File
@@ -15,7 +15,7 @@ class Validate
* @access private
* @var array
*/
private $data;
private array $data;
/**
* 当前验证指针
@@ -23,7 +23,7 @@ class Validate
* @access private
* @var string
*/
private $key;
private string $key;
/**
* 验证规则数组
@@ -31,7 +31,7 @@ class Validate
* @access private
* @var array
*/
private $rules = [];
private array $rules = [];
/**
* 中断模式,一旦出现验证错误即抛出而不再继续执行
@@ -39,7 +39,7 @@ class Validate
* @access private
* @var boolean
*/
private $break = false;
private bool $break = false;
/**
* 最小长度
@@ -120,7 +120,7 @@ class Validate
*
* @access public
*
* @param string
* @param string $str
*
* @return boolean
*/
+11 -11
View File
@@ -23,63 +23,63 @@ abstract class Widget
*
* @var array
*/
private static $widgetPool = [];
private static array $widgetPool = [];
/**
* widget别名
*
* @var array
*/
private static $widgetAlias = [];
private static array $widgetAlias = [];
/**
* request对象
*
* @var WidgetRequest
*/
protected $request;
protected WidgetRequest $request;
/**
* response对象
*
* @var WidgetResponse
*/
protected $response;
protected WidgetResponse $response;
/**
* 数据堆栈
*
* @var array
*/
protected $stack = [];
protected array $stack = [];
/**
* 当前队列指针顺序值,从1开始
*
* @var integer
*/
protected $sequence = 0;
protected int $sequence = 0;
/**
* 队列长度
*
* @var integer
*/
protected $length = 0;
protected int $length = 0;
/**
* config对象
*
* @var Config
*/
protected $parameter;
protected Config $parameter;
/**
* 数据堆栈每一行
*
* @var array
*/
protected $row = [];
protected array $row = [];
/**
* 构造函数,初始化组件
@@ -361,7 +361,7 @@ abstract class Widget
public function __call(string $name, array $args)
{
$method = 'call' . ucfirst($name);
self::pluginHandle()->trigger($plugged)->{$method}($this, $args);
self::pluginHandle()->trigger($plugged)->call($method, $this, $args);
if (!$plugged) {
echo $this->{$name};
@@ -394,7 +394,7 @@ abstract class Widget
if (method_exists($this, $method)) {
return $this->$method();
} else {
$return = self::pluginHandle()->trigger($plugged)->{$method}($this);
$return = self::pluginHandle()->trigger($plugged)->call($method, $this);
if ($plugged) {
return $return;
}
+1 -1
View File
@@ -18,7 +18,7 @@ class EmptyClass
* @access private
* @var EmptyClass
*/
private static $instance = null;
private static ?EmptyClass $instance = null;
/**
* 获取单例句柄
+1 -1
View File
@@ -42,7 +42,7 @@ class Form extends Layout
* @access private
* @var array
*/
private $inputs = [];
private array $inputs = [];
/**
* 构造函数,设置基本属性
+13 -13
View File
@@ -24,7 +24,7 @@ abstract class Element extends Layout
* @access protected
* @var integer
*/
protected static $uniqueId = 0;
protected static int $uniqueId = 0;
/**
* 表单元素容器
@@ -32,15 +32,15 @@ abstract class Element extends Layout
* @access public
* @var Layout
*/
public $container;
public Layout $container;
/**
* 输入栏
*
* @access public
* @var Layout
* @var Layout|null
*/
public $input;
public ?Layout $input;
/**
* inputs
@@ -48,7 +48,7 @@ abstract class Element extends Layout
* @var array
* @access public
*/
public $inputs = [];
public array $inputs = [];
/**
* 表单标题
@@ -56,7 +56,7 @@ abstract class Element extends Layout
* @access public
* @var Layout
*/
public $label;
public Layout $label;
/**
* 表单验证器
@@ -64,7 +64,7 @@ abstract class Element extends Layout
* @access public
* @var array
*/
public $rules = [];
public array $rules = [];
/**
* 表单名称
@@ -72,7 +72,7 @@ abstract class Element extends Layout
* @access public
* @var string
*/
public $name;
public ?string $name;
/**
* 表单值
@@ -86,17 +86,17 @@ abstract class Element extends Layout
* 表单描述
*
* @access private
* @var string
* @var Layout
*/
protected $description;
protected Layout $description;
/**
* 表单消息
*
* @access protected
* @var string
* @var Layout
*/
protected $message;
protected Layout $message;
/**
* 多行输入
@@ -104,7 +104,7 @@ abstract class Element extends Layout
* @access public
* @var array()
*/
protected $multiline = [];
protected array $multiline = [];
/**
* 构造函数
@@ -24,7 +24,7 @@ class Checkbox extends Element
*
* @var array
*/
private $options = [];
private array $options = [];
/**
* 初始化当前输入项
@@ -24,7 +24,7 @@ class Radio extends Element
*
* @var array
*/
private $options = [];
private array $options = [];
/**
* 初始化当前输入项
@@ -24,7 +24,7 @@ class Select extends Element
*
* @var array
*/
private $options = [];
private array $options = [];
/**
* 初始化当前输入项
+7 -7
View File
@@ -18,7 +18,7 @@ class Layout
* @access private
* @var array
*/
private $items = [];
private array $items = [];
/**
* 表单属性列表
@@ -26,7 +26,7 @@ class Layout
* @access private
* @var array
*/
private $attributes = [];
private array $attributes = [];
/**
* 标签名称
@@ -34,7 +34,7 @@ class Layout
* @access private
* @var string
*/
private $tagName = 'div';
private string $tagName = 'div';
/**
* 是否自闭合
@@ -42,15 +42,15 @@ class Layout
* @access private
* @var boolean
*/
private $close = false;
private bool $close = false;
/**
* 是否强制自闭合
*
* @access private
* @var boolean
* @var boolean|null
*/
private $forceClose = null;
private ?bool $forceClose = null;
/**
* 内部数据
@@ -58,7 +58,7 @@ class Layout
* @access private
* @var string
*/
private $html;
private string $html;
/**
* 父节点
+6 -6
View File
@@ -16,42 +16,42 @@ abstract class PageNavigator
*
* @var integer
*/
protected $total;
protected int $total;
/**
* 页面总数
*
* @var integer
*/
protected $totalPage;
protected int $totalPage;
/**
* 当前页面
*
* @var integer
*/
protected $currentPage;
protected int $currentPage;
/**
* 每页内容数
*
* @var integer
*/
protected $pageSize;
protected int $pageSize;
/**
* 页面链接模板
*
* @var string
*/
protected $pageTemplate;
protected string $pageTemplate;
/**
* 链接锚点
*
* @var string
*/
protected $anchor;
protected string $anchor = '';
/**
* 页面占位符
+19 -14
View File
@@ -33,17 +33,17 @@ class Request
* @access private
* @var array
*/
private $filter = [];
private array $filter = [];
/**
* @var HttpRequest
*/
private $request;
private HttpRequest $request;
/**
* @var Config
*/
private $params;
private Config $params;
/**
* @param HttpRequest $request
@@ -105,6 +105,7 @@ class Request
/**
* 获取实际传递参数(magic)
*
* @deprecated ^1.3.0
* @param string $key 指定参数
* @return mixed
*/
@@ -116,6 +117,7 @@ class Request
/**
* 判断参数是否存在
*
* @deprecated ^1.3.0
* @param string $key 指定参数
* @return boolean
*/
@@ -154,6 +156,19 @@ class Request
return $this->applyFilter(call_user_func_array([$this->request->proxy($this->params), 'from'], $params));
}
/**
* 判断输入是否满足要求
*
* @param mixed $query 条件
* @return boolean
*/
public function is($query): bool
{
$result = $this->request->proxy($this->params)->is($query);
$this->request->endProxy();
return $result;
}
/**
* @return string
*/
@@ -337,17 +352,6 @@ class Request
return $this->request->isJson();
}
/**
* 判断输入是否满足要求
*
* @param mixed $query 条件
* @return boolean
*/
public function is($query): bool
{
return $this->request->is($query);
}
/**
* 应用过滤器
*
@@ -366,6 +370,7 @@ class Request
$this->filter = [];
}
$this->request->endProxy();
return $value;
}
+2 -2
View File
@@ -14,12 +14,12 @@ class Response
/**
* @var HttpRequest
*/
private $request;
private HttpRequest $request;
/**
* @var HttpResponse
*/
private $response;
private HttpResponse $response;
/**
* @param HttpRequest $request
+2 -2
View File
@@ -20,7 +20,7 @@ class AutoP
* @access private
* @var integer
*/
private $uniqueId = 0;
private int $uniqueId = 0;
/**
* 存储的段落
@@ -28,7 +28,7 @@ class AutoP
* @access private
* @var array
*/
private $blocks = [];
private array $blocks = [];
/**
* 替换段落的回调函数
+2 -2
View File
@@ -75,9 +75,9 @@ class Helper
* @param $method
* @param $params
*/
public static function requestService($method, $params)
public static function requestService($method, ... $params)
{
Service::alloc()->requestService($method, $params);
Service::alloc()->requestService($method, ... $params);
}
/**
+4 -4
View File
@@ -12,13 +12,13 @@ namespace Utils;
*/
class PasswordHash
{
private $itoa64;
private string $itoa64;
private $iteration_count_log2;
private int $iteration_count_log2;
private $portable_hashes;
private bool $portable_hashes;
private $random_state;
private string $random_state;
/**
* @param int $iteration_count_log2
+2
View File
@@ -40,5 +40,7 @@ class Upgrade
$db->query($db->update('table.options')
->rows(['value' => serialize($routingTable)])
->where('name = ?', 'routingTable'));
// todo: fix options->commentsRequireURL
}
}
+2 -2
View File
@@ -21,7 +21,7 @@ class Action extends Widget
* @access private
* @var array
*/
private $map = [
private array $map = [
'ajax' => '\Widget\Ajax',
'login' => '\Widget\Login',
'logout' => '\Widget\Logout',
@@ -55,7 +55,7 @@ class Action extends Widget
public function execute()
{
/** 验证路由地址 **/
$action = $this->request->action;
$action = $this->request->get('action');
/** 判断是否为plugin */
$actionTable = array_merge($this->map, unserialize(Options::alloc()->actionTable));
+6 -4
View File
@@ -58,7 +58,7 @@ class Ajax extends BaseOptions implements ActionInterface
if (
isset($json['release'])
&& preg_match("/^[0-9\.]+$/", $json['release'])
&& preg_match("/^[0-9.]+$/", $json['release'])
&& version_compare($json['release'], $version, '>')
) {
$result = [
@@ -96,7 +96,7 @@ class Ajax extends BaseOptions implements ActionInterface
/** 匹配内容体 */
$response = $client->getResponseBody();
preg_match_all(
"/<item>\s*<title>([^>]*)<\/title>\s*<link>([^>]*)<\/link>\s*<guid>[^>]*<\/guid>\s*<pubDate>([^>]*)<\/pubDate>/is",
"/<item>\s*<title>([^>]*)<\/title>\s*<link>([^>]*)<\/link>\s*<guid>[^>]*<\/guid>\s*<pubDate>([^>]*)<\/pubDate>/i",
$response,
$matches
);
@@ -127,18 +127,20 @@ class Ajax extends BaseOptions implements ActionInterface
public function editorResize()
{
$this->user->pass('contributor');
$size = $this->request->filter('int')->get('size');
if (
$this->db->fetchObject($this->db->select(['COUNT(*)' => 'num'])
->from('table.options')->where('name = ? AND user = ?', 'editorSize', $this->user->uid))->num > 0
) {
parent::update(
['value' => $this->request->size],
['value' => $size],
$this->db->sql()->where('name = ? AND user = ?', 'editorSize', $this->user->uid)
);
} else {
parent::insert([
'name' => 'editorSize',
'value' => $this->request->size,
'value' => $size,
'user' => $this->user->uid
]);
}
+79 -94
View File
@@ -37,119 +37,119 @@ class Archive extends Contents
*
* @var string
*/
private $themeFile;
private string $themeFile;
/**
* 风格目录
*
* @var string
*/
private $themeDir;
private string $themeDir;
/**
* 分页计算对象
*
* @var Query
*/
private $countSql;
private Query $countSql;
/**
* 所有文章个数
*
* @var integer
* @var int|null
*/
private $total = false;
private ?int $total = null;
/**
* 标记是否为从外部调用
*
* @var boolean
*/
private $invokeFromOutside = false;
private bool $invokeFromOutside = false;
/**
* 是否由聚合调用
*
* @var boolean
*/
private $invokeByFeed = false;
private bool $invokeByFeed = false;
/**
* 当前页
*
* @var integer
*/
private $currentPage;
private int $currentPage;
/**
* 生成分页的内容
*
* @var array
*/
private $pageRow = [];
private array $pageRow = [];
/**
* RSS 2.0聚合地址
*
* @var string
*/
private $feedUrl;
private string $feedUrl;
/**
* RSS 1.0聚合地址
*
* @var string
*/
private $feedRssUrl;
private string $feedRssUrl;
/**
* ATOM 聚合地址
*
* @var string
*/
private $feedAtomUrl;
private string $feedAtomUrl;
/**
* 本页关键字
*
* @var string
*/
private $keywords;
private string $keywords;
/**
* 本页描述
*
* @var string
*/
private $description;
private string $description;
/**
* 归档标题
*
* @var string
* @var string|null
*/
private $archiveTitle = null;
private ?string $archiveTitle = null;
/**
* 归档地址
*
* @var string|null
*/
private $archiveUrl = null;
private ?string $archiveUrl = null;
/**
* 归档类型
*
* @var string
*/
private $archiveType = 'index';
private string $archiveType = 'index';
/**
* 是否为单一归档
*
* @var string
* @var boolean
*/
private $archiveSingle = false;
private bool $archiveSingle = false;
/**
* 是否为自定义首页, 主要为了标记自定义首页的情况
@@ -159,7 +159,7 @@ class Archive extends Contents
* @var boolean
* @access private
*/
private $makeSinglePageAsFrontPage = false;
private bool $makeSinglePageAsFrontPage = false;
/**
* 归档缩略名
@@ -167,7 +167,7 @@ class Archive extends Contents
* @access private
* @var string
*/
private $archiveSlug;
private string $archiveSlug;
/**
* 设置分页对象
@@ -175,7 +175,7 @@ class Archive extends Contents
* @access private
* @var PageNavigator
*/
private $pageNav;
private PageNavigator $pageNav;
/**
* @param Config $parameter
@@ -268,22 +268,6 @@ class Archive extends Contents
$this->archiveSlug = $archiveSlug;
}
/**
* @return string|null
*/
public function getArchiveSingle(): ?string
{
return $this->archiveSingle;
}
/**
* @param string $archiveSingle the $archiveSingle to set
*/
public function setArchiveSingle(string $archiveSingle)
{
$this->archiveSingle = $archiveSingle;
}
/**
* @return string|null
*/
@@ -469,7 +453,7 @@ class Archive extends Contents
*/
public function getTotal(): int
{
if (false === $this->total) {
if (!isset($this->total)) {
$this->total = $this->size($this->countSql);
}
@@ -553,7 +537,7 @@ class Archive extends Contents
];
/** 处理搜索结果跳转 */
if (isset($this->request->s)) {
if ($this->request->is('s')) {
$filterKeywords = $this->request->filter('search')->get('s');
/** 跳转到搜索页 */
@@ -587,11 +571,11 @@ class Archive extends Contents
}
/** 初始化分页变量 */
$this->currentPage = $this->request->filter('int')->page ?? 1;
$this->currentPage = $this->request->filter('int')->get('page', 1);
$hasPushed = false;
/** select初始化 */
$select = self::pluginHandle()->trigger($selectPlugged)->select($this);
$select = self::pluginHandle()->trigger($selectPlugged)->call('select', $this);
/** 定时发布功能 */
if (!$selectPlugged) {
@@ -632,7 +616,7 @@ class Archive extends Contents
}
/** handle初始化 */
self::pluginHandle()->handleInit($this, $select);
self::pluginHandle()->call('handleInit', $this, $select);
/** 初始化其它变量 */
$this->feedUrl = $this->options->feedUrl;
@@ -646,7 +630,7 @@ class Archive extends Contents
$handle = $handles[$this->parameter->type];
$this->{$handle}($select, $hasPushed);
} else {
$hasPushed = self::pluginHandle()->handle($this->parameter->type, $this, $select);
$hasPushed = self::pluginHandle()->call('handle', $this->parameter->type, $this, $select);
}
/** 初始化皮肤函数 */
@@ -745,7 +729,8 @@ class Archive extends Contents
$this->options->index
);
self::pluginHandle()->trigger($hasNav)->pageNav(
self::pluginHandle()->trigger($hasNav)->call(
'pageNav',
$this->currentPage,
$total,
$this->parameter->pageSize,
@@ -988,7 +973,7 @@ class Archive extends Contents
$allows = array_merge($allows, $rules);
}
$allows = self::pluginHandle()->headerOptions($allows, $this);
$allows = self::pluginHandle()->call('headerOptions', $allows, $this);
$title = (empty($this->archiveTitle) ? '' : $this->archiveTitle . ' &raquo; ') . $this->options->title;
$header = '';
@@ -1172,7 +1157,7 @@ class Archive extends Contents
echo $header;
/** 插件支持 */
self::pluginHandle()->header($header, $this);
self::pluginHandle()->call('header', $header, $this);
}
/**
@@ -1180,7 +1165,7 @@ class Archive extends Contents
*/
public function footer()
{
self::pluginHandle()->footer($this);
self::pluginHandle()->call('footer', $this);
}
/**
@@ -1321,13 +1306,13 @@ class Archive extends Contents
}
/** 挂接插件 */
self::pluginHandle()->beforeRender($this);
self::pluginHandle()->call('beforeRender', $this);
/** 输出模板 */
require_once $this->themeDir . $this->themeFile;
/** 挂接插件 */
self::pluginHandle()->afterRender($this);
self::pluginHandle()->call('afterRender', $this);
}
/**
@@ -1355,7 +1340,7 @@ class Archive extends Contents
*/
public function query($select)
{
self::pluginHandle()->trigger($queryPlugged)->query($this, $select);
self::pluginHandle()->trigger($queryPlugged)->call('query', $this, $select);
if (!$queryPlugged) {
$this->db->fetchAll($select, [$this, 'push']);
}
@@ -1373,7 +1358,7 @@ class Archive extends Contents
$commentUrl = parent::___commentUrl();
//不依赖js的父级评论
$reply = $this->request->filter('int')->replyTo;
$reply = $this->request->filter('int')->get('replyTo');
if ($reply && $this->is('single')) {
$commentUrl .= '?parent=' . $reply;
}
@@ -1432,7 +1417,7 @@ class Archive extends Contents
$select->where('table.contents.type = ?', 'post');
/** 插件接口 */
self::pluginHandle()->indexHandle($this, $select);
self::pluginHandle()->call('indexHandle', $this, $select);
}
/**
@@ -1476,7 +1461,7 @@ class Archive extends Contents
$hasPushed = true;
/** 插件接口 */
self::pluginHandle()->error404Handle($this, $select);
self::pluginHandle()->call('error404Handle', $this, $select);
}
/**
@@ -1502,18 +1487,18 @@ class Archive extends Contents
}
/** 如果是单篇文章或独立页面 */
if (isset($this->request->cid)) {
$select->where('table.contents.cid = ?', $this->request->filter('int')->cid);
if ($this->request->is('cid')) {
$select->where('table.contents.cid = ?', $this->request->filter('int')->get('cid'));
}
/** 匹配缩略名 */
if (isset($this->request->slug) && !$this->parameter->preview) {
$select->where('table.contents.slug = ?', $this->request->slug);
if ($this->request->is('slug') && !$this->parameter->preview) {
$select->where('table.contents.slug = ?', $this->request->get('slug'));
}
/** 匹配时间 */
if (isset($this->request->year) && !$this->parameter->preview) {
$year = $this->request->filter('int')->year;
if ($this->request->is('year') && !$this->parameter->preview) {
$year = $this->request->filter('int')->get('year');
$fromMonth = 1;
$toMonth = 12;
@@ -1521,15 +1506,15 @@ class Archive extends Contents
$fromDay = 1;
$toDay = 31;
if (isset($this->request->month)) {
$fromMonth = $this->request->filter('int')->month;
if ($this->request->is('month')) {
$fromMonth = $this->request->filter('int')->get('month');
$toMonth = $fromMonth;
$fromDay = 1;
$toDay = date('t', mktime(0, 0, 0, $toMonth, 1, $year));
if (isset($this->request->day)) {
$fromDay = $this->request->filter('int')->day;
if ($this->request->is('day')) {
$fromDay = $this->request->filter('int')->get('day');
$toDay = $fromDay;
}
}
@@ -1547,12 +1532,12 @@ class Archive extends Contents
if (
$this->request->isPost()
&& isset($this->request->protectPassword)
&& $this->request->is('protectPassword')
&& !$this->parameter->preview
) {
$this->security->protect();
Cookie::set(
'protectPassword_' . $this->request->filter('int')->protectCID,
'protectPassword_' . $this->request->filter('int')->get('protectCID'),
$this->request->protectPassword
);
@@ -1565,10 +1550,10 @@ class Archive extends Contents
if (
!$this->have()
|| (isset($this->request->category)
&& $this->category != $this->request->category && !$this->parameter->preview)
|| (isset($this->request->directory)
&& $this->request->directory != implode('/', $this->directory) && !$this->parameter->preview)
|| ($this->request->is('category')
&& $this->category != $this->request->get('category') && !$this->parameter->preview)
|| ($this->request->is('directory')
&& $this->request->get('directory') != implode('/', $this->directory) && !$this->parameter->preview)
) {
if (!$this->invokeFromOutside) {
/** 对没有索引情况下的判断 */
@@ -1630,7 +1615,7 @@ class Archive extends Contents
$hasPushed = true;
/** 插件接口 */
self::pluginHandle()->singleHandle($this, $select);
self::pluginHandle()->call('singleHandle', $this, $select);
}
/**
@@ -1648,16 +1633,16 @@ class Archive extends Contents
->where('type = ?', 'category')
->limit(1);
if (isset($this->request->mid)) {
$categorySelect->where('mid = ?', $this->request->filter('int')->mid);
if ($this->request->is('mid')) {
$categorySelect->where('mid = ?', $this->request->filter('int')->get('mid'));
}
if (isset($this->request->slug)) {
$categorySelect->where('slug = ?', $this->request->slug);
if ($this->request->is('slug')) {
$categorySelect->where('slug = ?', $this->request->get('slug'));
}
if (isset($this->request->directory)) {
$directory = explode('/', $this->request->directory);
if ($this->request->is('directory')) {
$directory = explode('/', $this->request->get('directory'));
$categorySelect->where('slug = ?', $directory[count($directory) - 1]);
}
@@ -1669,7 +1654,7 @@ class Archive extends Contents
$categoryListWidget = Rows::alloc('current=' . $category['mid']);
$category = $categoryListWidget->filter($category);
if (isset($directory) && ($this->request->directory != implode('/', $category['directory']))) {
if (isset($directory) && ($this->request->get('directory') != implode('/', $category['directory']))) {
throw new WidgetException(_t('父级分类不存在'), 404);
}
@@ -1717,7 +1702,7 @@ class Archive extends Contents
$this->archiveUrl = $category['permalink'];
/** 插件接口 */
self::pluginHandle()->categoryHandle($this, $select);
self::pluginHandle()->call('categoryHandle', $this, $select);
}
/**
@@ -1732,12 +1717,12 @@ class Archive extends Contents
$tagSelect = $this->db->select()->from('table.metas')
->where('type = ?', 'tag')->limit(1);
if (isset($this->request->mid)) {
$tagSelect->where('mid = ?', $this->request->filter('int')->mid);
if ($this->request->is('mid')) {
$tagSelect->where('mid = ?', $this->request->filter('int')->get('mid'));
}
if (isset($this->request->slug)) {
$tagSelect->where('slug = ?', $this->request->slug);
if ($this->request->is('slug')) {
$tagSelect->where('slug = ?', $this->request->get('slug'));
}
/** 如果是标签 */
@@ -1789,7 +1774,7 @@ class Archive extends Contents
$this->archiveUrl = $tag['permalink'];
/** 插件接口 */
self::pluginHandle()->tagHandle($this, $select);
self::pluginHandle()->call('tagHandle', $this, $select);
}
/**
@@ -1801,7 +1786,7 @@ class Archive extends Contents
*/
private function authorHandle(Query $select, bool &$hasPushed)
{
$uid = $this->request->filter('int')->uid;
$uid = $this->request->filter('int')->get('uid');
$author = $this->db->fetchRow(
$this->db->select()->from('table.users')
@@ -1848,7 +1833,7 @@ class Archive extends Contents
$this->archiveUrl = $author['permalink'];
/** 插件接口 */
self::pluginHandle()->authorHandle($this, $select);
self::pluginHandle()->call('authorHandle', $this, $select);
}
/**
@@ -1862,9 +1847,9 @@ class Archive extends Contents
private function dateHandle(Query $select, &$hasPushed)
{
/** 如果是按日期归档 */
$year = $this->request->filter('int')->year;
$month = $this->request->filter('int')->month;
$day = $this->request->filter('int')->day;
$year = $this->request->filter('int')->get('year');
$month = $this->request->filter('int')->get('month');
$day = $this->request->filter('int')->get('day');
if (!empty($year) && !empty($month) && !empty($day)) {
@@ -1934,7 +1919,7 @@ class Archive extends Contents
$this->archiveUrl = Router::url($currentRoute, $value, $this->options->index);
/** 插件接口 */
self::pluginHandle()->dateHandle($this, $select);
self::pluginHandle()->call('dateHandle', $this, $select);
}
/**
@@ -1949,8 +1934,8 @@ class Archive extends Contents
{
/** 增加自定义搜索引擎接口 */
//~ fix issue 40
$keywords = $this->request->filter('url', 'search')->keywords;
self::pluginHandle()->trigger($hasPushed)->search($keywords, $this);
$keywords = $this->request->filter('url', 'search')->get('keywords');
self::pluginHandle()->trigger($hasPushed)->call('search', $keywords, $this);
if (!$hasPushed) {
$searchQuery = '%' . str_replace(' ', '%', $keywords) . '%';
@@ -1999,6 +1984,6 @@ class Archive extends Contents
$this->archiveUrl = Router::url('search', ['keywords' => $keywords], $this->options->index);
/** 插件接口 */
self::pluginHandle()->searchHandle($this, $select);
self::pluginHandle()->call('searchHandle', $this, $select);
}
}
+6 -6
View File
@@ -25,7 +25,7 @@ class Backup extends BaseOptions implements ActionInterface
/**
* @var array
*/
private $types = [
private array $types = [
'contents' => 1,
'comments' => 2,
'metas' => 3,
@@ -37,7 +37,7 @@ class Backup extends BaseOptions implements ActionInterface
/**
* @var array
*/
private $fields = [
private array $fields = [
'contents' => [
'cid', 'title', 'slug', 'created', 'modified', 'text', 'order', 'authorId',
'template', 'type', 'status', 'password', 'commentsNum', 'allowComment', 'allowPing', 'allowFeed', 'parent'
@@ -62,17 +62,17 @@ class Backup extends BaseOptions implements ActionInterface
/**
* @var array
*/
private $lastIds = [];
private array $lastIds = [];
/**
* @var array
*/
private $cleared = [];
private array $cleared = [];
/**
* @var bool
*/
private $login = false;
private bool $login = false;
/**
* 列出已有备份文件
@@ -126,7 +126,7 @@ class Backup extends BaseOptions implements ActionInterface
} while (count($rows) == 20);
}
self::pluginHandle()->export($fp);
self::pluginHandle()->call('export', $fp);
fwrite($fp, $header);
fclose($fp);
+4 -4
View File
@@ -55,28 +55,28 @@ abstract class Base extends Widget
*
* @var Options
*/
protected $options;
protected Options $options;
/**
* 用户对象
*
* @var User
*/
protected $user;
protected User $user;
/**
* 安全模块
*
* @var Security
*/
protected $security;
protected Security $security;
/**
* 数据库对象
*
* @var Db
*/
protected $db;
protected Db $db;
/**
* init method
+7 -7
View File
@@ -243,7 +243,7 @@ class Comments extends Base implements QueryInterface
$value['text'] = $value['text'] ?? '';
$value['date'] = new Date($value['created']);
return Comments::pluginHandle()->filter($value, $this);
return Comments::pluginHandle()->call('filter', $value, $this);
}
/**
@@ -286,7 +286,7 @@ class Comments extends Base implements QueryInterface
if ($this->options->commentsAvatar && 'comment' == $this->type) {
$rating = $this->options->commentsAvatarRating;
Comments::pluginHandle()->trigger($plugged)->gravatar($size, $rating, $default, $this);
Comments::pluginHandle()->trigger($plugged)->call('gravatar', $size, $rating, $default, $this);
if (!$plugged) {
$url = Common::gravatarUrl($this->mail, $size, $rating, $default, $this->request->isSecure());
echo '<img class="avatar" loading="lazy" src="' . $url . '" alt="' .
@@ -353,7 +353,7 @@ class Comments extends Base implements QueryInterface
*/
public function markdown(?string $text): ?string
{
$html = Comments::pluginHandle()->trigger($parsed)->markdown($text);
$html = Comments::pluginHandle()->trigger($parsed)->call('markdown', $text);
if (!$parsed) {
$html = Markdown::convert($text);
@@ -370,7 +370,7 @@ class Comments extends Base implements QueryInterface
*/
public function autoP(?string $text): ?string
{
$html = Comments::pluginHandle()->trigger($parsed)->autoP($text);
$html = Comments::pluginHandle()->trigger($parsed)->call('autoP', $text);
if (!$parsed) {
static $parser;
@@ -436,7 +436,7 @@ class Comments extends Base implements QueryInterface
$select = $this->db->select('coid', 'parent')
->from('table.comments')->where('cid = ? AND status = ?', $this->parentContent['cid'], 'approved')
->where('coid ' . ('DESC' == $this->options->commentsOrder ? '>=' : '<=') . ' ?', $coid)
->order('coid', Db::SORT_ASC);
->order('coid');
if ($this->options->commentsShowCommentOnly) {
$select->where('type = ?', 'comment');
@@ -477,13 +477,13 @@ class Comments extends Base implements QueryInterface
{
$text = $this->parentContent['hidden'] ? _t('内容被隐藏') : $this->text;
$text = Comments::pluginHandle()->trigger($plugged)->content($text, $this);
$text = Comments::pluginHandle()->trigger($plugged)->call('content', $text, $this);
if (!$plugged) {
$text = $this->options->commentsMarkdown ? $this->markdown($text)
: $this->autoP($text);
}
$text = Comments::pluginHandle()->contentEx($text, $this);
$text = Comments::pluginHandle()->call('contentEx', $text, $this);
return Common::stripTags($text, '<p><br>' . $this->options->commentsHTMLTagAllowed);
}
+12 -14
View File
@@ -240,8 +240,7 @@ class Contents extends Base implements QueryInterface
/** 更新缩略名 */
if ($updateRows > 0 && isset($rows['slug'])) {
$this->applySlug(!isset($rows['slug']) || strlen($rows['slug']) === 0
? null : $rows['slug'], $updateCondition);
$this->applySlug(strlen($rows['slug']) === 0 ? null : $rows['slug'], $updateCondition);
}
return $updateRows;
@@ -312,7 +311,7 @@ class Contents extends Base implements QueryInterface
continue;
}
$isFieldReadOnly = Contents::pluginHandle()->trigger($plugged)->isFieldReadOnly($name);
$isFieldReadOnly = Contents::pluginHandle()->trigger($plugged)->call('isFieldReadOnly', $name);
if ($plugged && $isFieldReadOnly) {
continue;
}
@@ -403,7 +402,6 @@ class Contents extends Base implements QueryInterface
$exist = $this->db->fetchRow($this->db->select('type')->from('table.fields')
->where('cid = ? AND name = ?', $cid, $name));
$value = intval($value);
if (empty($exist)) {
return $this->db->query($this->db->insert('table.fields')
@@ -600,7 +598,7 @@ class Contents extends Base implements QueryInterface
$value['hidden'] = true;
}
$value = Contents::pluginHandle()->filter($value, $this);
$value = Contents::pluginHandle()->call('filter', $value, $this);
/** 如果访问权限被禁止 */
if ($value['hidden']) {
@@ -662,7 +660,7 @@ class Contents extends Base implements QueryInterface
*/
public function title(int $length = 0, string $trim = '...')
{
$title = Contents::pluginHandle()->trigger($plugged)->title($this->title, $this);
$title = Contents::pluginHandle()->trigger($plugged)->call('title', $this->title, $this);
if (!$plugged) {
echo $length > 0 ? Common::subStr($this->title, 0, $length, $trim) : $this->title;
} else {
@@ -747,7 +745,7 @@ class Contents extends Base implements QueryInterface
* @param string $split 多个分类之间分隔符
* @param boolean $link 是否输出链接
* @param string|null $default 如果没有则输出
* @throws \Typecho\Widget\Exception
* @throws Widget\Exception
*/
public function directory(string $split = '/', bool $link = true, ?string $default = null)
{
@@ -891,7 +889,7 @@ class Contents extends Base implements QueryInterface
return $this->text;
}
$content = Contents::pluginHandle()->trigger($plugged)->excerpt($this->text, $this);
$content = Contents::pluginHandle()->trigger($plugged)->call('excerpt', $this->text, $this);
if (!$plugged) {
$content = $this->isMarkdown ? $this->markdown($content)
: $this->autoP($content);
@@ -900,7 +898,7 @@ class Contents extends Base implements QueryInterface
$contents = explode('<!--more-->', $content);
[$excerpt] = $contents;
return Common::fixHtml(Contents::pluginHandle()->excerptEx($excerpt, $this));
return Common::fixHtml(Contents::pluginHandle()->call('excerptEx', $excerpt, $this));
}
/**
@@ -912,7 +910,7 @@ class Contents extends Base implements QueryInterface
{
$plainText = str_replace("\n", '', trim(strip_tags($this->excerpt)));
$plainText = $plainText ?: $this->title;
return Common::subStr($plainText, 0, 100, '...');
return Common::subStr($plainText, 0, 100);
}
/**
@@ -923,7 +921,7 @@ class Contents extends Base implements QueryInterface
*/
public function markdown(?string $text): ?string
{
$html = Contents::pluginHandle()->trigger($parsed)->markdown($text);
$html = Contents::pluginHandle()->trigger($parsed)->call('markdown', $text);
if (!$parsed) {
$html = Markdown::convert($text);
@@ -940,7 +938,7 @@ class Contents extends Base implements QueryInterface
*/
public function autoP(?string $text): ?string
{
$html = Contents::pluginHandle()->trigger($parsed)->autoP($text);
$html = Contents::pluginHandle()->trigger($parsed)->call('autoP', $text);
if (!$parsed && $text) {
static $parser;
@@ -966,14 +964,14 @@ class Contents extends Base implements QueryInterface
return $this->text;
}
$content = Contents::pluginHandle()->trigger($plugged)->content($this->text, $this);
$content = Contents::pluginHandle()->trigger($plugged)->call('content', $this->text, $this);
if (!$plugged) {
$content = $this->isMarkdown ? $this->markdown($content)
: $this->autoP($content);
}
return Contents::pluginHandle()->contentEx($content, $this);
return Contents::pluginHandle()->call('contentEx', $content, $this);
}
/**
+2 -4
View File
@@ -5,7 +5,6 @@ namespace Widget\Base;
use Typecho\Common;
use Typecho\Db\Exception;
use Typecho\Db\Query;
use Typecho\Plugin;
use Typecho\Router;
use Widget\Base;
@@ -84,8 +83,7 @@ class Metas extends Base implements QueryInterface
$value['feedAtomUrl'] = $routeExists ? Router::url($type, $value, $this->options->feedAtomUrl) : '#';
$value['slug'] = $tmpSlug;
$value = Metas::pluginHandle()->filter($value, $this);
return $value;
return Metas::pluginHandle()->call('filter', $value, $this);
}
/**
@@ -142,7 +140,7 @@ class Metas extends Base implements QueryInterface
*/
public function merge(int $mid, string $type, array $metas)
{
$contents = array_column($this->db->fetchAll($this->select('cid')
$contents = array_column($this->db->fetchAll($this->db->select('cid')
->from('table.relationships')
->where('mid = ?', $mid)), 'cid');
+7 -8
View File
@@ -50,8 +50,8 @@ class Users extends Base implements QueryInterface
->where('name = ?', $name)
->limit(1);
if ($this->request->uid) {
$select->where('uid <> ?', $this->request->uid);
if ($this->request->is('uid')) {
$select->where('uid <> ?', $this->request->get('uid'));
}
$user = $this->db->fetchRow($select);
@@ -72,8 +72,8 @@ class Users extends Base implements QueryInterface
->where('mail = ?', $mail)
->limit(1);
if ($this->request->uid) {
$select->where('uid <> ?', $this->request->uid);
if ($this->request->is('uid')) {
$select->where('uid <> ?', $this->request->get('uid'));
}
$user = $this->db->fetchRow($select);
@@ -94,8 +94,8 @@ class Users extends Base implements QueryInterface
->where('screenName = ?', $screenName)
->limit(1);
if ($this->request->uid) {
$select->where('uid <> ?', $this->request->uid);
if ($this->request->is('uid')) {
$select->where('uid <> ?', $this->request->get('uid'));
}
$user = $this->db->fetchRow($select);
@@ -137,8 +137,7 @@ class Users extends Base implements QueryInterface
/** ATOM 1.0 */
$value['feedAtomUrl'] = $routeExists ? Router::url('author', $value, $this->options->feedAtomUrl) : '#';
$value = Users::pluginHandle()->filter($value, $this);
return $value;
return Users::pluginHandle()->call('filter', $value, $this);
}
/**
+1 -1
View File
@@ -20,7 +20,7 @@ class CommentPage extends Base implements ActionInterface
{
$page = abs($this->request->filter('int')->get('commentPage'));
$archive = Router::match($this->request->permalink, [
$archive = Router::match($this->request->get('permalink'), [
'checkPermalink' => false,
'commentPage' => $page
]);
+15 -15
View File
@@ -31,7 +31,7 @@ class Admin extends Comments
* @access private
* @var Query
*/
private $countSql;
private Query $countSql;
/**
* 当前页
@@ -39,15 +39,15 @@ class Admin extends Comments
* @access private
* @var integer
*/
private $currentPage;
private int $currentPage;
/**
* 所有文章个数
*
* @access private
* @var integer
* @var integer|null
*/
private $total = false;
private ?int $total;
/**
* 获取菜单标题
@@ -78,18 +78,18 @@ class Admin extends Comments
$this->currentPage = $this->request->get('page', 1);
/** 过滤标题 */
if (null != ($keywords = $this->request->filter('search')->keywords)) {
if (null != ($keywords = $this->request->filter('search')->get('keywords'))) {
$select->where('table.comments.text LIKE ?', '%' . $keywords . '%');
}
/** 如果具有贡献者以上权限,可以查看所有评论,反之只能查看自己的评论 */
if (!$this->user->pass('editor', true)) {
$select->where('table.comments.ownerId = ?', $this->user->uid);
} elseif (!isset($this->request->cid)) {
if ('on' == $this->request->__typecho_all_comments) {
} elseif (!$this->request->is('cid')) {
if ($this->request->is('__typecho_all_comments=on')) {
Cookie::set('__typecho_all_comments', 'on');
} else {
if ('off' == $this->request->__typecho_all_comments) {
if ($this->request->is('__typecho_all_comments=off')) {
Cookie::set('__typecho_all_comments', 'off');
}
@@ -99,17 +99,17 @@ class Admin extends Comments
}
}
if (in_array($this->request->status, ['approved', 'waiting', 'spam'])) {
$select->where('table.comments.status = ?', $this->request->status);
} elseif ('hold' == $this->request->status) {
if (in_array($this->request->get('status'), ['approved', 'waiting', 'spam'])) {
$select->where('table.comments.status = ?', $this->request->get('status'));
} elseif ('hold' == $this->request->get('status')) {
$select->where('table.comments.status <> ?', 'approved');
} else {
$select->where('table.comments.status = ?', 'approved');
}
//增加按文章归档功能
if (isset($this->request->cid)) {
$select->where('table.comments.cid = ?', $this->request->filter('int')->cid);
if ($this->request->is('cid')) {
$select->where('table.comments.cid = ?', $this->request->filter('int')->get('cid'));
}
$this->countSql = clone $select;
@@ -131,7 +131,7 @@ class Admin extends Comments
/** 使用盒状分页 */
$nav = new Box(
false === $this->total ? $this->total = $this->size($this->countSql) : $this->total,
!isset($this->total) ? $this->total = $this->size($this->countSql) : $this->total,
$this->currentPage,
$this->parameter->pageSize,
$query
@@ -147,7 +147,7 @@ class Admin extends Comments
*/
protected function ___parentContent(): ?array
{
$cid = isset($this->request->cid) ? $this->request->filter('int')->cid : $this->cid;
$cid = $this->request->is('cid') ? $this->request->filter('int')->get('cid') : $this->cid;
return $this->db->fetchRow(Contents::alloc()->select()
->where('table.contents.cid = ?', $cid)
->limit(1), [Contents::alloc(), 'filter']);
+17 -15
View File
@@ -5,6 +5,7 @@ namespace Widget\Comments;
use Typecho\Config;
use Typecho\Cookie;
use Typecho\Router;
use Typecho\Widget\Exception;
use Typecho\Widget\Helper\PageNavigator\Box;
use Widget\Base\Comments;
@@ -28,7 +29,7 @@ class Archive extends Comments
* @access private
* @var integer
*/
private $currentPage;
private int $currentPage;
/**
* 所有文章个数
@@ -36,7 +37,7 @@ class Archive extends Comments
* @access private
* @var integer
*/
private $total = false;
private int $total = 0;
/**
* 子父级评论关系
@@ -44,15 +45,15 @@ class Archive extends Comments
* @access private
* @var array
*/
private $threadedComments = [];
private array $threadedComments = [];
/**
* _singleCommentOptions
*
* @var mixed
* @var Config|null
* @access private
*/
private $singleCommentOptions = null;
private ?Config $singleCommentOptions = null;
/**
* @param Config $parameter
@@ -73,7 +74,7 @@ class Archive extends Comments
$args[] = '%d';
}
$num = intval($this->total);
$num = $this->total;
echo sprintf($args[$num] ?? array_pop($args), $num);
}
@@ -101,7 +102,6 @@ class Archive extends Comments
$commentsMail,
'waiting'
);
$threadedSelect = null;
if ($this->options->commentsShowCommentOnly) {
$select->where('table.comments.type = ?', 'comment');
@@ -211,7 +211,7 @@ class Archive extends Comments
* @param string $splitWord 分割字符
* @param string|array $template 展现配置信息
* @return void
* @throws \Typecho\Widget\Exception
* @throws Exception
*/
public function pageNav(
string $prev = '&laquo;',
@@ -238,7 +238,8 @@ class Archive extends Comments
$pageRow['permalink'] = $pageRow['pathinfo'];
$query = Router::url('comment_page', $pageRow, $this->options->index);
self::pluginHandle()->trigger($hasNav)->pageNav(
self::pluginHandle()->trigger($hasNav)->call(
'pageNav',
$this->currentPage,
$this->total,
$this->options->commentsPageSize,
@@ -286,7 +287,7 @@ class Archive extends Comments
'avatarSize' => 32,
'defaultAvatar' => null
]);
self::pluginHandle()->trigger($plugged)->listComments($this->singleCommentOptions, $this);
self::pluginHandle()->trigger($plugged)->call('listComments', $this->singleCommentOptions, $this);
if (!$plugged) {
if ($this->have()) {
@@ -304,11 +305,12 @@ class Archive extends Comments
/**
* 评论回调函数
*/
private function threadedCommentsCallback()
private function threadedCommentsCallback(): void
{
$singleCommentOptions = $this->singleCommentOptions;
if (function_exists('threadedComments')) {
return threadedComments($this, $singleCommentOptions);
threadedComments($this, $singleCommentOptions);
return;
}
$commentClass = '';
@@ -403,7 +405,7 @@ class Archive extends Comments
{
if ($this->options->commentsThreaded && !$this->isTopLevel && $this->parameter->allowComment) {
$word = empty($word) ? _t('回复') : $word;
self::pluginHandle()->trigger($plugged)->reply($word, $this);
self::pluginHandle()->trigger($plugged)->call('reply', $word, $this);
if (!$plugged) {
echo '<a href="' . substr($this->permalink, 0, - strlen($this->theId) - 1) . '?replyTo=' . $this->coid .
@@ -449,10 +451,10 @@ class Archive extends Comments
{
if ($this->options->commentsThreaded) {
$word = empty($word) ? _t('取消回复') : $word;
self::pluginHandle()->trigger($plugged)->cancelReply($word, $this);
self::pluginHandle()->trigger($plugged)->call('cancelReply', $word, $this);
if (!$plugged) {
$replyId = $this->request->filter('int')->replyTo;
$replyId = $this->request->filter('int')->get('replyTo');
echo '<a id="cancel-comment-reply-link" href="' . $this->parameter->parentContent['permalink'] . '#' . $this->parameter->respondId .
'" rel="nofollow"' . ($replyId ? '' : ' style="display:none"') . ' onclick="return TypechoComment.cancelReply();">' . $word . '</a>';
}
+20 -20
View File
@@ -55,14 +55,14 @@ class Edit extends Comments implements ActionInterface
* @return boolean
* @throws Exception
*/
private function mark($coid, $status)
private function mark(int $coid, string $status): bool
{
$comment = $this->db->fetchRow($this->select()
->where('coid = ?', $coid)->limit(1), [$this, 'push']);
if ($comment && $this->commentIsWriteable()) {
/** 增加评论编辑插件接口 */
self::pluginHandle()->mark($comment, $this, $status);
self::pluginHandle()->call('mark', $comment, $this, $status);
/** 不必更新的情况 */
if ($status == $comment['status']) {
@@ -158,7 +158,7 @@ class Edit extends Comments implements ActionInterface
->where('coid = ?', $coid)->limit(1), [$this, 'push']);
if ($comment && $this->commentIsWriteable()) {
self::pluginHandle()->delete($comment, $this);
self::pluginHandle()->call('delete', $comment, $this);
/** 删除评论 */
$this->db->query($this->db->delete('table.comments')->where('coid = ?', $coid));
@@ -169,7 +169,7 @@ class Edit extends Comments implements ActionInterface
->expression('commentsNum', 'commentsNum - 1')->where('cid = ?', $comment['cid']));
}
self::pluginHandle()->finishDelete($comment, $this);
self::pluginHandle()->call('finishDelete', $comment, $this);
$deleteRows++;
}
@@ -208,12 +208,12 @@ class Edit extends Comments implements ActionInterface
public function deleteSpamComment()
{
$deleteQuery = $this->db->delete('table.comments')->where('status = ?', 'spam');
if (!$this->request->__typecho_all_comments || !$this->user->pass('editor', true)) {
if (!$this->request->is('__typecho_all_comments=on') || !$this->user->pass('editor', true)) {
$deleteQuery->where('ownerId = ?', $this->user->uid);
}
if (isset($this->request->cid)) {
$deleteQuery->where('cid = ?', $this->request->cid);
if ($this->request->is('cid')) {
$deleteQuery->where('cid = ?', $this->request->get('cid'));
}
$deleteRows = $this->db->query($deleteQuery);
@@ -235,7 +235,7 @@ class Edit extends Comments implements ActionInterface
*/
public function getComment()
{
$coid = $this->request->filter('int')->coid;
$coid = $this->request->filter('int')->get('coid');
$comment = $this->db->fetchRow($this->select()
->where('coid = ?', $coid)->limit(1), [$this, 'push']);
@@ -260,22 +260,22 @@ class Edit extends Comments implements ActionInterface
*/
public function editComment(): bool
{
$coid = $this->request->filter('int')->coid;
$coid = $this->request->filter('int')->get('coid');
$commentSelect = $this->db->fetchRow($this->select()
->where('coid = ?', $coid)->limit(1), [$this, 'push']);
if ($commentSelect && $this->commentIsWriteable()) {
$comment['text'] = $this->request->text;
$comment['author'] = $this->request->filter('strip_tags', 'trim', 'xss')->author;
$comment['mail'] = $this->request->filter('strip_tags', 'trim', 'xss')->mail;
$comment['url'] = $this->request->filter('url')->url;
$comment['text'] = $this->request->get('text');
$comment['author'] = $this->request->filter('strip_tags', 'trim', 'xss')->get('author');
$comment['mail'] = $this->request->filter('strip_tags', 'trim', 'xss')->get('mail');
$comment['url'] = $this->request->filter('url')->get('url');
if ($this->request->is('created')) {
$comment['created'] = $this->request->filter('int')->created;
$comment['created'] = $this->request->filter('int')->get('created');
}
/** 评论插件接口 */
$comment = self::pluginHandle()->edit($comment, $this);
$comment = self::pluginHandle()->call('edit', $comment, $this);
/** 更新评论 */
$this->update($comment, $this->db->sql()->where('coid = ?', $coid));
@@ -285,7 +285,7 @@ class Edit extends Comments implements ActionInterface
$updatedComment['content'] = $this->content;
/** 评论插件接口 */
self::pluginHandle()->finishEdit($this);
self::pluginHandle()->call('finishEdit', $this);
$this->response->throwJson([
'success' => 1,
@@ -306,7 +306,7 @@ class Edit extends Comments implements ActionInterface
*/
public function replyComment()
{
$coid = $this->request->filter('int')->coid;
$coid = $this->request->filter('int')->get('coid');
$commentSelect = $this->db->fetchRow($this->select()
->where('coid = ?', $coid)->limit(1), [$this, 'push']);
@@ -323,12 +323,12 @@ class Edit extends Comments implements ActionInterface
'mail' => $this->user->mail,
'url' => $this->user->url,
'parent' => $coid,
'text' => $this->request->text,
'text' => $this->request->get('text'),
'status' => 'approved'
];
/** 评论插件接口 */
self::pluginHandle()->comment($comment, $this);
self::pluginHandle()->call('comment', $comment, $this);
/** 回复评论 */
$commentId = $this->insert($comment);
@@ -338,7 +338,7 @@ class Edit extends Comments implements ActionInterface
$insertComment['content'] = $this->content;
/** 评论完成接口 */
self::pluginHandle()->finishComment($this);
self::pluginHandle()->call('finishComment', $this);
$this->response->throwJson([
'success' => 1,
+4 -3
View File
@@ -26,7 +26,7 @@ class Ping extends Comments
* @var boolean
* @access private
*/
private $customSinglePingCallback = false;
private bool $customSinglePingCallback = false;
/**
* @param Config $parameter
@@ -111,10 +111,11 @@ class Ping extends Comments
*
* @param string $singlePingOptions 单个回响自定义选项
*/
private function singlePingCallback(string $singlePingOptions)
private function singlePingCallback(string $singlePingOptions): void
{
if ($this->customSinglePingCallback) {
return singlePing($this, $singlePingOptions);
singlePing($this, $singlePingOptions);
return;
}
?>
+6 -6
View File
@@ -28,21 +28,21 @@ class Admin extends Contents
*
* @var Query
*/
private $countSql;
private Query $countSql;
/**
* 所有文章个数
*
* @var integer
* @var integer|null
*/
private $total = false;
private ?int $total;
/**
* 当前页
*
* @var integer
*/
private $currentPage;
private int $currentPage;
/**
* 执行函数
@@ -64,7 +64,7 @@ class Admin extends Contents
}
/** 过滤标题 */
if (null != ($keywords = $this->request->filter('search')->keywords)) {
if (null != ($keywords = $this->request->filter('search')->get('keywords'))) {
$args = [];
$keywordsList = explode(' ', $keywords);
$args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?'));
@@ -98,7 +98,7 @@ class Admin extends Contents
/** 使用盒状分页 */
$nav = new Box(
false === $this->total ? $this->total = $this->size($this->countSql) : $this->total,
!isset($this->total) ? $this->total = $this->size($this->countSql) : $this->total,
$this->currentPage,
$this->parameter->pageSize,
$query
+10 -12
View File
@@ -40,7 +40,7 @@ class Edit extends PostEdit implements ActionInterface
if (!empty($this->request->cid)) {
$this->db->fetchRow($this->select()
->where('table.contents.type = ?', 'attachment')
->where('table.contents.cid = ?', $this->request->filter('int')->cid)
->where('table.contents.cid = ?', $this->request->filter('int')->get('cid'))
->limit(1), [$this, 'push']);
if (!$this->have()) {
@@ -84,8 +84,8 @@ class Edit extends PostEdit implements ActionInterface
->where('slug = ?', Common::slugName($slug))
->limit(1);
if ($this->request->cid) {
$select->where('cid <> ?', $this->request->cid);
if ($this->request->is('cid')) {
$select->where('cid <> ?', $this->request->get('cid'));
}
$attachment = $this->db->fetchRow($select);
@@ -100,7 +100,7 @@ class Edit extends PostEdit implements ActionInterface
*/
public function updateAttachment()
{
if ($this->form('update')->validate()) {
if ($this->form()->validate()) {
$this->response->goBack();
}
@@ -115,7 +115,7 @@ class Edit extends PostEdit implements ActionInterface
$content['description'] = $input['description'];
$attachment['text'] = serialize($content);
$cid = $this->request->filter('int')->cid;
$cid = $this->request->filter('int')->get('cid');
/** 更新数据 */
$updateRows = $this->update($attachment, $this->db->sql()->where('cid = ?', $cid));
@@ -231,7 +231,7 @@ class Edit extends PostEdit implements ActionInterface
foreach ($posts as $post) {
// 删除插件接口
self::pluginHandle()->delete($post, $this);
self::pluginHandle()->call('delete', $post, $this);
$condition = $this->db->sql()->where('cid = ?', $post);
$row = $this->db->fetchRow($this->select()
@@ -248,7 +248,7 @@ class Edit extends PostEdit implements ActionInterface
->where('cid = ?', $post));
// 完成删除插件接口
self::pluginHandle()->finishDelete($post, $this);
self::pluginHandle()->call('finishDelete', $post, $this);
$deleteCount++;
}
@@ -285,7 +285,7 @@ class Edit extends PostEdit implements ActionInterface
$deleteCount = 0;
do {
$posts = array_column($this->db->fetchAll($this->select('cid')
$posts = array_column($this->db->fetchAll($this->db->select('cid')
->from('table.contents')
->where('type = ? AND parent = ?', 'attachment', 0)
->page($page, 100)), 'cid');
@@ -293,7 +293,7 @@ class Edit extends PostEdit implements ActionInterface
foreach ($posts as $post) {
// 删除插件接口
self::pluginHandle()->delete($post, $this);
self::pluginHandle()->call('delete', $post, $this);
$condition = $this->db->sql()->where('cid = ?', $post);
$row = $this->db->fetchRow($this->select()
@@ -309,10 +309,8 @@ class Edit extends PostEdit implements ActionInterface
$this->db->query($this->db->delete('table.comments')
->where('cid = ?', $post));
$status = $this->status;
// 完成删除插件接口
self::pluginHandle()->finishDelete($post, $this);
self::pluginHandle()->call('finishDelete', $post, $this);
$deleteCount++;
}
+1 -1
View File
@@ -42,7 +42,7 @@ class Related extends Contents
$select->where('table.contents.parent = ?', $this->parameter->parentId);
/** 提交查询 */
$select->order('table.contents.created', Db::SORT_ASC);
$select->order('table.contents.created');
if ($this->parameter->limit > 0) {
$select->limit($this->parameter->limit);
@@ -42,7 +42,7 @@ class Unattached extends Contents
(table.contents.parent = 0 OR table.contents.parent IS NULL)', 'attachment');
/** 加上对用户的判断 */
$this->where('table.contents.authorId = ?', $this->user->uid);
$select->where('table.contents.authorId = ?', $this->user->uid);
/** 提交查询 */
$select->order('table.contents.created', Db::SORT_DESC);
+2 -2
View File
@@ -38,7 +38,7 @@ class Admin extends PostAdmin
);
/** 过滤标题 */
if (null != ($keywords = $this->request->keywords)) {
if (null != ($keywords = $this->request->get('keywords'))) {
$args = [];
$keywordsList = explode(' ', $keywords);
$args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?'));
@@ -51,7 +51,7 @@ class Admin extends PostAdmin
}
/** 提交查询 */
$select->order('table.contents.order', Db::SORT_ASC);
$select->order('table.contents.order');
$this->db->fetchAll($select, [$this, 'push']);
}
+11 -11
View File
@@ -31,7 +31,7 @@ class Edit extends PostEdit implements ActionInterface
* @var string
* @access protected
*/
protected $themeCustomFieldsHook = 'themePageFields';
protected string $themeCustomFieldsHook = 'themePageFields';
/**
* 执行函数
@@ -47,10 +47,10 @@ class Edit extends PostEdit implements ActionInterface
$this->user->pass('editor');
/** 获取文章内容 */
if (!empty($this->request->cid)) {
if ($this->request->is('cid')) {
$this->db->fetchRow($this->select()
->where('table.contents.type = ? OR table.contents.type = ?', 'page', 'page_draft')
->where('table.contents.cid = ?', $this->request->filter('int')->cid)
->where('table.contents.cid = ?', $this->request->filter('int')->get('cid'))
->limit(1), [$this, 'push']);
if ('page_draft' == $this->status && $this->parent) {
@@ -85,11 +85,11 @@ class Edit extends PostEdit implements ActionInterface
$contents['created'] = $this->getCreated();
$contents['visibility'] = ('hidden' == $contents['visibility'] ? 'hidden' : 'publish');
if ($this->request->markdown && $this->options->markdown) {
if ($this->request->is('markdown=1') && $this->options->markdown) {
$contents['text'] = '<!--markdown-->' . $contents['text'];
}
$contents = self::pluginHandle()->write($contents, $this);
$contents = self::pluginHandle()->call('write', $contents, $this);
if ($this->request->is('do=publish')) {
/** 重新发布已经存在的文章 */
@@ -97,7 +97,7 @@ class Edit extends PostEdit implements ActionInterface
$this->publish($contents);
// 完成发布插件接口
self::pluginHandle()->finishPublish($contents, $this);
self::pluginHandle()->call('finishPublish', $contents, $this);
/** 发送ping */
Service::alloc()->sendPing($this);
@@ -119,7 +119,7 @@ class Edit extends PostEdit implements ActionInterface
$this->save($contents);
// 完成发布插件接口
self::pluginHandle()->finishSave($contents, $this);
self::pluginHandle()->call('finishSave', $contents, $this);
/** 设置高亮 */
Notice::alloc()->highlight($this->cid);
@@ -164,7 +164,7 @@ class Edit extends PostEdit implements ActionInterface
foreach ($pages as $page) {
// 标记插件接口
self::pluginHandle()->mark($status, $page, $this);
self::pluginHandle()->call('mark', $status, $page, $this);
$condition = $this->db->sql()->where('cid = ?', $page);
if ($this->db->query($condition->update('table.contents')->rows(['status' => $status]))) {
@@ -180,7 +180,7 @@ class Edit extends PostEdit implements ActionInterface
}
// 完成标记插件接口
self::pluginHandle()->finishMark($status, $page, $this);
self::pluginHandle()->call('finishMark', $status, $page, $this);
$markCount++;
}
@@ -211,7 +211,7 @@ class Edit extends PostEdit implements ActionInterface
foreach ($pages as $page) {
// 删除插件接口
self::pluginHandle()->delete($page, $this);
self::pluginHandle()->call('delete', $page, $this);
if ($this->delete($this->db->sql()->where('cid = ?', $page))) {
/** 删除评论 */
@@ -243,7 +243,7 @@ class Edit extends PostEdit implements ActionInterface
}
// 完成删除插件接口
self::pluginHandle()->finishDelete($page, $this);
self::pluginHandle()->call('finishDelete', $page, $this);
$deleteCount++;
}
+1 -1
View File
@@ -32,7 +32,7 @@ class Rows extends Contents
$select = $this->select()->where('table.contents.type = ?', 'page')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $this->options->time)
->order('table.contents.order', Db::SORT_ASC);
->order('table.contents.order');
//去掉自定义首页
$frontPage = explode(':', $this->options->frontPage);
+15 -15
View File
@@ -29,21 +29,21 @@ class Admin extends Contents
*
* @var Query
*/
private $countSql;
private Query $countSql;
/**
* 所有文章个数
*
* @var integer
* @var integer|null
*/
private $total = false;
private ?int $total;
/**
* 当前页
*
* @var integer
*/
private $currentPage;
private int $currentPage;
/**
* 获取菜单标题
@@ -53,9 +53,9 @@ class Admin extends Contents
*/
public function getMenuTitle(): string
{
if (isset($this->request->uid)) {
if ($this->request->is('uid')) {
return _t('%s的文章', $this->db->fetchObject($this->db->select('screenName')->from('table.users')
->where('uid = ?', $this->request->filter('int')->uid))->screenName);
->where('uid = ?', $this->request->filter('int')->get('uid')))->screenName);
}
throw new Exception(_t('用户不存在'), 404);
@@ -100,24 +100,24 @@ class Admin extends Contents
if (!$this->user->pass('editor', true)) {
$select->where('table.contents.authorId = ?', $this->user->uid);
} else {
if ('on' == $this->request->__typecho_all_posts) {
if ($this->request->is('__typecho_all_posts=on')) {
Cookie::set('__typecho_all_posts', 'on');
} else {
if ('off' == $this->request->__typecho_all_posts) {
if ($this->request->is('__typecho_all_posts=off')) {
Cookie::set('__typecho_all_posts', 'off');
}
if ('on' != Cookie::get('__typecho_all_posts')) {
$select->where('table.contents.authorId = ?', isset($this->request->uid) ?
$this->request->filter('int')->uid : $this->user->uid);
$select->where('table.contents.authorId = ?',
$this->request->filter('int')->get('uid', $this->user->uid));
}
}
}
/** 按状态查询 */
if ('draft' == $this->request->status) {
if ($this->request->is('status=draft')) {
$select->where('table.contents.type = ?', 'post_draft');
} elseif ('waiting' == $this->request->status) {
} elseif ($this->request->is('status=waiting')) {
$select->where(
'(table.contents.type = ? OR table.contents.type = ?) AND table.contents.status = ?',
'post',
@@ -134,13 +134,13 @@ class Admin extends Contents
}
/** 过滤分类 */
if (null != ($category = $this->request->category)) {
if (null != ($category = $this->request->get('category'))) {
$select->join('table.relationships', 'table.contents.cid = table.relationships.cid')
->where('table.relationships.mid = ?', $category);
}
/** 过滤标题 */
if (null != ($keywords = $this->request->filter('search')->keywords)) {
if (null != ($keywords = $this->request->filter('search')->get('keywords'))) {
$args = [];
$keywordsList = explode(' ', $keywords);
$args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?'));
@@ -174,7 +174,7 @@ class Admin extends Contents
/** 使用盒状分页 */
$nav = new Box(
false === $this->total ? $this->total = $this->size($this->countSql) : $this->total,
!isset($this->total) ? $this->total = $this->size($this->countSql) : $this->total,
$this->currentPage,
$this->parameter->pageSize,
$query
+58 -66
View File
@@ -32,7 +32,7 @@ class Edit extends Contents implements ActionInterface
*
* @var string
*/
protected $themeCustomFieldsHook = 'themePostFields';
protected string $themeCustomFieldsHook = 'themePostFields';
/**
* 执行函数
@@ -45,10 +45,10 @@ class Edit extends Contents implements ActionInterface
$this->user->pass('contributor');
/** 获取文章内容 */
if (!empty($this->request->cid)) {
if ($this->request->is('cid')) {
$this->db->fetchRow($this->select()
->where('table.contents.type = ? OR table.contents.type = ?', 'post', 'post_draft')
->where('table.contents.cid = ?', $this->request->filter('int')->cid)
->where('table.contents.cid = ?', $this->request->filter('int')->get('cid'))
->limit(1), [$this, 'push']);
if ('post_draft' == $this->type && $this->parent) {
@@ -170,7 +170,7 @@ class Edit extends Contents implements ActionInterface
foreach ($rows as $row) {
$isFieldReadOnly = Contents::pluginHandle()
->trigger($plugged)->isFieldReadOnly($row['name']);
->trigger($plugged)->call('isFieldReadOnly', $row['name']);
if ($plugged && $isFieldReadOnly) {
continue;
@@ -201,7 +201,7 @@ class Edit extends Contents implements ActionInterface
$fields = $this->fields;
}
self::pluginHandle()->getDefaultFieldItems($layout);
self::pluginHandle()->call('getDefaultFieldItems', $layout);
if (file_exists($configFile)) {
require_once $configFile;
@@ -221,7 +221,7 @@ class Edit extends Contents implements ActionInterface
$name = $item->input->getAttribute('name');
$isFieldReadOnly = Contents::pluginHandle()
->trigger($plugged)->isFieldReadOnly($name);
->trigger($plugged)->call('isFieldReadOnly', $name);
if ($plugged && $isFieldReadOnly) {
continue;
}
@@ -279,11 +279,11 @@ class Edit extends Contents implements ActionInterface
$contents['title'] = $this->request->get('title', _t('未命名文档'));
$contents['created'] = $this->getCreated();
if ($this->request->markdown && $this->options->markdown) {
if ($this->request->is('markdown=1') && $this->options->markdown) {
$contents['text'] = '<!--markdown-->' . $contents['text'];
}
$contents = self::pluginHandle()->write($contents, $this);
$contents = self::pluginHandle()->call('write', $contents, $this);
if ($this->request->is('do=publish')) {
/** 重新发布已经存在的文章 */
@@ -291,10 +291,10 @@ class Edit extends Contents implements ActionInterface
$this->publish($contents);
// 完成发布插件接口
self::pluginHandle()->finishPublish($contents, $this);
self::pluginHandle()->call('finishPublish', $contents, $this);
/** 发送ping */
$trackback = array_filter(array_unique(preg_split("/(\r|\n|\r\n)/", trim($this->request->trackback))));
$trackback = array_filter(array_unique(preg_split("/(\r|\n|\r\n)/", trim($this->request->get('trackback')))));
Service::alloc()->sendPing($this, $trackback);
/** 设置提示信息 */
@@ -316,7 +316,7 @@ class Edit extends Contents implements ActionInterface
$this->save($contents);
// 完成保存插件接口
self::pluginHandle()->finishSave($contents, $this);
self::pluginHandle()->call('finishSave', $contents, $this);
/** 设置高亮 */
Notice::alloc()->highlight($this->cid);
@@ -347,24 +347,24 @@ class Edit extends Contents implements ActionInterface
protected function getCreated(): int
{
$created = $this->options->time;
if (!empty($this->request->created)) {
$created = $this->request->created;
} elseif (!empty($this->request->date)) {
$dstOffset = !empty($this->request->dst) ? $this->request->dst : 0;
if ($this->request->is('created')) {
$created = $this->request->get('created');
} elseif ($this->request->is('date')) {
$dstOffset = $this->request->get('dst', 0);
$timezoneSymbol = $this->options->timezone >= 0 ? '+' : '-';
$timezoneOffset = abs($this->options->timezone);
$timezone = $timezoneSymbol . str_pad($timezoneOffset / 3600, 2, '0', STR_PAD_LEFT) . ':00';
[$date, $time] = explode(' ', $this->request->date);
[$date, $time] = explode(' ', $this->request->get('date'));
$created = strtotime("{$date}T{$time}{$timezone}") - $dstOffset;
} elseif (!empty($this->request->year) && !empty($this->request->month) && !empty($this->request->day)) {
$second = intval($this->request->get('sec', date('s')));
$min = intval($this->request->get('min', date('i')));
$hour = intval($this->request->get('hour', date('H')));
} elseif ($this->request->is('year&month&day')) {
$second = $this->request->filter('int')->get('sec', date('s'));
$min = $this->request->filter('int')->get('min', date('i'));
$hour = $this->request->filter('int')->get('hour', date('H'));
$year = intval($this->request->year);
$month = intval($this->request->month);
$day = intval($this->request->day);
$year = $this->request->filter('int')->get('year');
$month = $this->request->filter('int')->get('month');
$day = $this->request->filter('int')->get('day');
$created = mktime($hour, $min, $second, $month, $day, $year)
- $this->options->timezone + $this->options->serverTimezone;
@@ -388,24 +388,7 @@ class Edit extends Contents implements ActionInterface
protected function publish(array $contents)
{
/** 发布内容, 检查是否具有直接发布的权限 */
if ($this->user->pass('editor', true)) {
if (empty($contents['visibility'])) {
$contents['status'] = 'publish';
} elseif (
!in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden'])
) {
if (empty($contents['password']) || 'password' != $contents['visibility']) {
$contents['password'] = '';
}
$contents['status'] = 'publish';
} else {
$contents['status'] = $contents['visibility'];
$contents['password'] = '';
}
} else {
$contents['status'] = 'waiting';
$contents['password'] = '';
}
$this->checkStatus($contents);
/** 真实的内容id */
$realId = 0;
@@ -468,7 +451,7 @@ class Edit extends Contents implements ActionInterface
* @param integer $cid 草稿id
* @throws DbException
*/
protected function deleteDraft($cid)
protected function deleteDraft(int $cid)
{
$this->delete($this->db->sql()->where('cid = ?', $cid));
@@ -690,7 +673,7 @@ class Edit extends Contents implements ActionInterface
$cid,
'post',
$status,
'on' == $this->request->__typecho_all_posts ? 0 : $this->user->uid
$this->request->is('__typecho_all_posts=on') ? 0 : $this->user->uid
);
}
@@ -703,24 +686,7 @@ class Edit extends Contents implements ActionInterface
protected function save(array $contents)
{
/** 发布内容, 检查是否具有直接发布的权限 */
if ($this->user->pass('editor', true)) {
if (empty($contents['visibility'])) {
$contents['status'] = 'publish';
} elseif (
!in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden'])
) {
if (empty($contents['password']) || 'password' != $contents['visibility']) {
$contents['password'] = '';
}
$contents['status'] = 'publish';
} else {
$contents['status'] = $contents['visibility'];
$contents['password'] = '';
}
} else {
$contents['status'] = 'waiting';
$contents['password'] = '';
}
$this->checkStatus($contents);
/** 真实的内容id */
$realId = 0;
@@ -792,7 +758,7 @@ class Edit extends Contents implements ActionInterface
foreach ($posts as $post) {
// 标记插件接口
self::pluginHandle()->mark($status, $post, $this);
self::pluginHandle()->call('mark', $status, $post, $this);
$condition = $this->db->sql()->where('cid = ?', $post);
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
@@ -837,7 +803,7 @@ class Edit extends Contents implements ActionInterface
}
// 完成标记插件接口
self::pluginHandle()->finishMark($status, $post, $this);
self::pluginHandle()->call('finishMark', $status, $post, $this);
$markCount++;
}
@@ -868,7 +834,7 @@ class Edit extends Contents implements ActionInterface
foreach ($posts as $post) {
// 删除插件接口
self::pluginHandle()->delete($post, $this);
self::pluginHandle()->call('delete', $post, $this);
$condition = $this->db->sql()->where('cid = ?', $post);
$postObject = $this->db->fetchObject($this->db->select('status', 'type')
@@ -906,7 +872,7 @@ class Edit extends Contents implements ActionInterface
}
// 完成删除插件接口
self::pluginHandle()->finishDelete($post, $this);
self::pluginHandle()->call('finishDelete', $post, $this);
$deleteCount++;
}
@@ -935,7 +901,7 @@ class Edit extends Contents implements ActionInterface
* @param integer $cid 内容id
* @throws DbException
*/
protected function unAttach($cid)
protected function unAttach(int $cid)
{
$this->db->query($this->db->update('table.contents')->rows(['parent' => 0, 'status' => 'publish'])
->where('parent = ? AND type = ?', $cid, 'attachment'));
@@ -1044,4 +1010,30 @@ class Edit extends Contents implements ActionInterface
return null;
}
/**
* @param array $contents
* @return void
*/
private function checkStatus(array &$contents)
{
if ($this->user->pass('editor', true)) {
if (empty($contents['visibility'])) {
$contents['status'] = 'publish';
} elseif (
!in_array($contents['visibility'], ['private', 'waiting', 'publish', 'hidden'])
) {
if (empty($contents['password']) || 'password' != $contents['visibility']) {
$contents['password'] = '';
}
$contents['status'] = 'publish';
} else {
$contents['status'] = $contents['visibility'];
$contents['password'] = '';
}
} else {
$contents['status'] = 'waiting';
$contents['password'] = '';
}
}
}
+8 -4
View File
@@ -23,7 +23,7 @@ class Feed extends Contents
/**
* @var FeedGenerator
*/
private $feed;
private FeedGenerator $feed;
/**
* @param Config $parameter
@@ -41,7 +41,7 @@ class Feed extends Contents
*/
public function execute()
{
$feedPath = $this->request->feed;
$feedPath = $this->request->get('feed');
$feedType = FeedGenerator::RSS2;
$feedContentType = 'application/rss+xml';
$currentFeedUrl = $this->options->feedUrl;
@@ -136,7 +136,11 @@ class Feed extends Contents
}
while ($comments->next()) {
$suffix = self::pluginHandle()->trigger($plugged)->commentFeedItem($feed->getType(), $comments);
$suffix = self::pluginHandle()->trigger($plugged)->call(
'commentFeedItem',
$feed->getType(),
$comments
);
if (!$plugged) {
$suffix = null;
@@ -161,7 +165,7 @@ class Feed extends Contents
. ($archive->getArchiveTitle() ? ' - ' . $archive->getArchiveTitle() : ''));
while ($archive->next()) {
$suffix = self::pluginHandle()->trigger($plugged)->feedItem($feed->getType(), $archive);
$suffix = self::pluginHandle()->trigger($plugged)->call('feedItem', $feed->getType(), $archive);
if (!$plugged) {
$suffix = null;
+16 -16
View File
@@ -37,7 +37,7 @@ class Feedback extends Comments implements ActionInterface
*
* @param string $userName 用户名
* @return bool
* @throws \Typecho\Db\Exception
* @throws Db\Exception
*/
public function requireUserLogin(string $userName): bool
{
@@ -63,8 +63,8 @@ class Feedback extends Comments implements ActionInterface
public function action()
{
/** 回调方法 */
$callback = $this->request->type;
$this->content = Router::match($this->request->permalink);
$callback = $this->request->get('type');
$this->content = Router::match($this->request->get('permalink'));
/** 判断内容是否存在 */
if (
@@ -199,20 +199,20 @@ class Feedback extends Comments implements ActionInterface
$validator->addRule('text', 'required', _t('必须填写评论内容'));
$comment['text'] = $this->request->text;
$comment['text'] = $this->request->get('text');
/** 对一般匿名访问者,将用户数据保存一个月 */
if (!$this->user->hasLogin()) {
/** Anti-XSS */
$comment['author'] = $this->request->filter('trim')->author;
$comment['mail'] = $this->request->filter('trim')->mail;
$comment['url'] = $this->request->filter('trim', 'url')->url;
$comment['author'] = $this->request->filter('trim')->get('author');
$comment['mail'] = $this->request->filter('trim')->get('mail');
$comment['url'] = $this->request->filter('trim', 'url')->get('url');
/** 修正用户提交的url */
if (!empty($comment['url'])) {
$urlParams = parse_url($comment['url']);
if (!isset($urlParams['scheme'])) {
$comment['url'] = 'http://' . $comment['url'];
$comment['url'] = 'https://' . $comment['url'];
}
}
@@ -255,7 +255,7 @@ class Feedback extends Comments implements ActionInterface
/** 生成过滤器 */
try {
$comment = self::pluginHandle()->comment($comment, $this->content);
$comment = self::pluginHandle()->call('comment', $comment, $this->content);
} catch (\Typecho\Exception $e) {
Cookie::set('__typecho_remember_text', $comment['text']);
throw $e;
@@ -268,7 +268,7 @@ class Feedback extends Comments implements ActionInterface
->limit(1), [$this, 'push']);
/** 评论完成接口 */
self::pluginHandle()->finishComment($this);
self::pluginHandle()->call('finishComment', $this);
$this->response->goBack('#' . $this->theId);
}
@@ -276,7 +276,7 @@ class Feedback extends Comments implements ActionInterface
/**
* 引用处理函数
*
* @throws Exception|\Typecho\Db\Exception
* @throws Exception|Db\Exception
*/
private function trackback()
{
@@ -304,9 +304,9 @@ class Feedback extends Comments implements ActionInterface
'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved'
];
$trackback['author'] = $this->request->filter('trim')->blog_name;
$trackback['url'] = $this->request->filter('trim', 'url')->url;
$trackback['text'] = $this->request->excerpt;
$trackback['author'] = $this->request->filter('trim')->get('blog_name');
$trackback['url'] = $this->request->filter('trim', 'url')->get('url');
$trackback['text'] = $this->request->get('excerpt');
//检验格式
$validator = new Validate();
@@ -337,13 +337,13 @@ class Feedback extends Comments implements ActionInterface
}
/** 生成过滤器 */
$trackback = self::pluginHandle()->trackback($trackback, $this->content);
$trackback = self::pluginHandle()->call('trackback', $trackback, $this->content);
/** 添加引用 */
$this->insert($trackback);
/** 评论完成接口 */
self::pluginHandle()->finishTrackback($this);
self::pluginHandle()->call('finishTrackback', $this);
/** 返回正确 */
$this->response->throwXml(['success' => 0, 'message' => 'Trackback has registered.']);
+17 -15
View File
@@ -44,7 +44,7 @@ class Login extends Users implements ActionInterface
$expire = 30 * 24 * 3600;
/** 记住密码状态 */
if ($this->request->remember) {
if ($this->request->is('remember=1')) {
Cookie::set('__typecho_remember_remember', 1, $expire);
} elseif (Cookie::get('__typecho_remember_remember')) {
Cookie::delete('__typecho_remember_remember');
@@ -52,7 +52,7 @@ class Login extends Users implements ActionInterface
/** 截获验证异常 */
if ($error = $validator->run($this->request->from('name', 'password'))) {
Cookie::set('__typecho_remember_name', $this->request->name);
Cookie::set('__typecho_remember_name', $this->request->get('name'));
/** 设置提示信息 */
Notice::alloc()->set($error);
@@ -61,10 +61,10 @@ class Login extends Users implements ActionInterface
/** 开始验证用户 **/
$valid = $this->user->login(
$this->request->name,
$this->request->password,
$this->request->get('name'),
$this->request->get('password'),
false,
1 == $this->request->remember ? $expire : 0
1 == $this->request->get('name') ? $expire : 0
);
/** 比对密码 */
@@ -72,23 +72,25 @@ class Login extends Users implements ActionInterface
/** 防止穷举,休眠3秒 */
sleep(3);
self::pluginHandle()->loginFail(
self::pluginHandle()->call(
'loginFailure',
$this->user,
$this->request->name,
$this->request->password,
1 == $this->request->remember
$this->request->get('name'),
$this->request->get('password'),
$this->request->is('remember=1')
);
Cookie::set('__typecho_remember_name', $this->request->name);
Cookie::set('__typecho_remember_name', $this->request->get('name'));
Notice::alloc()->set(_t('用户名或密码无效'), 'error');
$this->response->goBack('?referer=' . urlencode($this->request->referer));
$this->response->goBack('?referer=' . urlencode($this->request->get('referer')));
}
self::pluginHandle()->loginSucceed(
self::pluginHandle()->call(
'loginSuccess',
$this->user,
$this->request->name,
$this->request->password,
1 == $this->request->remember
$this->request->get('name'),
$this->request->get('password'),
$this->request->is('remember=1')
);
/** 跳转验证后地址 */
+1 -1
View File
@@ -30,7 +30,7 @@ class Logout extends Users implements ActionInterface
$this->security->protect();
$this->user->logout();
self::pluginHandle()->logout();
self::pluginHandle()->call('logout');
@session_destroy();
$this->response->goBack(null, $this->options->index);
}
+7 -7
View File
@@ -30,41 +30,41 @@ class Menu extends Base
* 当前菜单标题
* @var string
*/
public $title;
public string $title;
/**
* 当前增加项目链接
* @var string
* @var string|null
*/
public $addLink;
public ?string $addLink;
/**
* 父菜单列表
*
* @var array
*/
private $menu = [];
private array $menu = [];
/**
* 当前父菜单
*
* @var integer
*/
private $currentParent = 1;
private int $currentParent = 1;
/**
* 当前子菜单
*
* @var integer
*/
private $currentChild = 0;
private int $currentChild = 0;
/**
* 当前页面
*
* @var string
*/
private $currentUrl;
private string $currentUrl;
/**
* 执行函数,初始化菜单
+8 -8
View File
@@ -23,10 +23,10 @@ class Admin extends Rows
public function execute()
{
$select = $this->db->select('mid')->from('table.metas')->where('type = ?', 'category');
$select->where('parent = ?', $this->request->parent ? $this->request->parent : 0);
$select->where('parent = ?', $this->request->get('parent', 0));
$this->stack = $this->getCategories(array_column(
$this->db->fetchAll($select->order('table.metas.order', Db::SORT_ASC)),
$this->db->fetchAll($select->order('table.metas.order')),
'mid'
));
}
@@ -38,9 +38,9 @@ class Admin extends Rows
*/
public function backLink()
{
if (isset($this->request->parent)) {
if ($this->request->is('parent')) {
$category = $this->db->fetchRow($this->select()
->where('type = ? AND mid = ?', 'category', $this->request->parent));
->where('type = ? AND mid = ?', 'category', $this->request->get('parent')));
if (!empty($category)) {
$parent = $this->db->fetchRow($this->select()
@@ -69,9 +69,9 @@ class Admin extends Rows
*/
public function getMenuTitle(): ?string
{
if (isset($this->request->parent)) {
if ($this->request->is('parent')) {
$category = $this->db->fetchRow($this->select()
->where('type = ? AND mid = ?', 'category', $this->request->parent));
->where('type = ? AND mid = ?', 'category', $this->request->get('parent')));
if (!empty($category)) {
return _t('管理 %s 的子分类', $category['name']);
@@ -90,8 +90,8 @@ class Admin extends Rows
*/
public function getAddLink(): string
{
if (isset($this->request->parent)) {
return 'category.php?parent=' . $this->request->filter('int')->parent;
if ($this->request->is('parent')) {
return 'category.php?parent=' . $this->request->filter('int')->get('parent');
} else {
return 'category.php';
}
+14 -14
View File
@@ -65,8 +65,8 @@ class Edit extends Metas implements ActionInterface
->where('name = ?', $name)
->limit(1);
if ($this->request->mid) {
$select->where('mid <> ?', $this->request->mid);
if ($this->request->is('mid')) {
$select->where('mid <> ?', $this->request->get('mid'));
}
$category = $this->db->fetchRow($select);
@@ -106,8 +106,8 @@ class Edit extends Metas implements ActionInterface
->where('slug = ?', Common::slugName($slug))
->limit(1);
if ($this->request->mid) {
$select->where('mid <> ?', $this->request->mid);
if ($this->request->is('mid')) {
$select->where('mid <> ?', $this->request->get('mid'));
}
$category = $this->db->fetchRow($select);
@@ -180,7 +180,7 @@ class Edit extends Metas implements ActionInterface
$options = [0 => _t('不选择')];
$parents = Rows::allocWithAlias(
'options',
(isset($this->request->mid) ? 'ignore=' . $this->request->mid : '')
($this->request->is('mid') ? 'ignore=' . $this->request->get('mid') : '')
);
while ($parents->next()) {
@@ -190,7 +190,7 @@ class Edit extends Metas implements ActionInterface
$parent = new Form\Element\Select(
'parent',
$options,
$this->request->parent,
$this->request->get('parent'),
_t('父级分类'),
_t('此分类将归档在您选择的父级分类下.')
);
@@ -278,7 +278,7 @@ class Edit extends Metas implements ActionInterface
/** 取出数据 */
$category = $this->request->from('name', 'slug', 'description', 'parent');
$category['mid'] = $this->request->mid;
$category['mid'] = $this->request->get('mid');
$category['slug'] = Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
$category['type'] = 'category';
$current = $this->db->fetchRow($this->select()->where('mid = ?', $category['mid']));
@@ -298,7 +298,7 @@ class Edit extends Metas implements ActionInterface
}
/** 更新数据 */
$this->update($category, $this->db->sql()->where('mid = ?', $this->request->filter('int')->mid));
$this->update($category, $this->db->sql()->where('mid = ?', $this->request->filter('int')->get('mid')));
$this->push($category);
/** 设置高亮 */
@@ -358,7 +358,7 @@ class Edit extends Metas implements ActionInterface
$this->response->goBack();
}
$merge = $this->request->merge;
$merge = $this->request->get('merge');
$categories = $this->request->filter('int')->getArray('mid');
if ($categories) {
@@ -367,7 +367,7 @@ class Edit extends Metas implements ActionInterface
/** 提示信息 */
Notice::alloc()->set(_t('分类已经合并'), 'success');
} else {
Notice::alloc()->set(_t('没有选择任何分类'), 'notice');
Notice::alloc()->set(_t('没有选择任何分类'));
}
/** 转向原页 */
@@ -402,12 +402,12 @@ class Edit extends Metas implements ActionInterface
$categories = $this->request->filter('int')->getArray('mid');
if ($categories) {
foreach ($categories as $category) {
$this->refreshCountByTypeAndStatus($category, 'post', 'publish');
$this->refreshCountByTypeAndStatus($category, 'post');
}
Notice::alloc()->set(_t('分类刷新已经完成'), 'success');
} else {
Notice::alloc()->set(_t('没有选择任何分类'), 'notice');
Notice::alloc()->set(_t('没有选择任何分类'));
}
/** 转向原页 */
@@ -430,10 +430,10 @@ class Edit extends Metas implements ActionInterface
Notice::alloc()->set($error, 'error');
} else {
$this->db->query($this->db->update('table.options')
->rows(['value' => $this->request->mid])
->rows(['value' => $this->request->get('mid')])
->where('name = ?', 'defaultCategory'));
$this->db->fetchRow($this->select()->where('mid = ?', $this->request->mid)
$this->db->fetchRow($this->select()->where('mid = ?', $this->request->get('mid'))
->where('type = ?', 'category')->limit(1), [$this, 'push']);
/** 设置高亮 */
+11 -9
View File
@@ -17,6 +17,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
* @package Widget
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
* @property-read int $levels
* @property-read array $children
*/
class Rows extends Metas
{
@@ -26,15 +28,15 @@ class Rows extends Metas
* @var array
* @access private
*/
private $treeViewCategories = [];
private array $treeViewCategories = [];
/**
* _categoryOptions
*
* @var mixed
* @var Config|null
* @access private
*/
private $categoryOptions = null;
private ?Config $categoryOptions = null;
/**
* 顶层分类
@@ -42,7 +44,7 @@ class Rows extends Metas
* @var array
* @access private
*/
private $top = [];
private array $top = [];
/**
* 所有分类哈希表
@@ -50,7 +52,7 @@ class Rows extends Metas
* @var array
* @access private
*/
private $map = [];
private array $map = [];
/**
* 顺序流
@@ -58,7 +60,7 @@ class Rows extends Metas
* @var array
* @access private
*/
private $orders = [];
private array $orders = [];
/**
* 所有子节点列表
@@ -66,7 +68,7 @@ class Rows extends Metas
* @var array
* @access private
*/
private $childNodes = [];
private array $childNodes = [];
/**
* 所有父节点列表
@@ -74,7 +76,7 @@ class Rows extends Metas
* @var array
* @access private
*/
private $parents = [];
private array $parents = [];
/**
* @param Config $parameter
@@ -173,7 +175,7 @@ class Rows extends Metas
]);
// 插件插件接口
self::pluginHandle()->trigger($plugged)->listCategories($this->categoryOptions, $this);
self::pluginHandle()->trigger($plugged)->call('listCategories', $this->categoryOptions, $this);
if (!$plugged) {
$this->stack = $this->getCategories($this->top);
+2 -2
View File
@@ -38,9 +38,9 @@ class Admin extends Cloud
*/
public function getMenuTitle(): ?string
{
if (isset($this->request->mid)) {
if ($this->request->is('mid')) {
$tag = $this->db->fetchRow($this->select()
->where('type = ? AND mid = ?', 'tag', $this->request->mid));
->where('type = ? AND mid = ?', 'tag', $this->request->get('mid')));
if (!empty($tag)) {
return _t('编辑标签 %s', $tag['name']);
+13 -13
View File
@@ -65,8 +65,8 @@ class Edit extends Metas implements ActionInterface
->where('name = ?', $name)
->limit(1);
if ($this->request->mid) {
$select->where('mid <> ?', $this->request->filter('int')->mid);
if ($this->request->is('mid')) {
$select->where('mid <> ?', $this->request->filter('int')->get('mid'));
}
$tag = $this->db->fetchRow($select);
@@ -106,8 +106,8 @@ class Edit extends Metas implements ActionInterface
->where('slug = ?', Common::slugName($slug))
->limit(1);
if ($this->request->mid) {
$select->where('mid <> ?', $this->request->mid);
if ($this->request->is('mid')) {
$select->where('mid <> ?', $this->request->get('mid'));
}
$tag = $this->db->fetchRow($select);
@@ -192,10 +192,10 @@ class Edit extends Metas implements ActionInterface
$submit->input->setAttribute('class', 'btn primary');
$form->addItem($submit);
if (isset($this->request->mid) && 'insert' != $action) {
if ($this->request->is('mid') && 'insert' != $action) {
/** 更新模式 */
$meta = $this->db->fetchRow($this->select()
->where('mid = ?', $this->request->mid)
->where('mid = ?', $this->request->get('mid'))
->where('type = ?', 'tag')->limit(1));
if (!$meta) {
@@ -253,7 +253,7 @@ class Edit extends Metas implements ActionInterface
$tag['slug'] = Common::slugName(empty($tag['slug']) ? $tag['name'] : $tag['slug']);
/** 更新数据 */
$this->update($tag, $this->db->sql()->where('mid = ?', $this->request->filter('int')->mid));
$this->update($tag, $this->db->sql()->where('mid = ?', $this->request->filter('int')->get('mid')));
$this->push($tag);
/** 设置高亮 */
@@ -279,7 +279,7 @@ class Edit extends Metas implements ActionInterface
$tags = $this->request->filter('int')->getArray('mid');
$deleteCount = 0;
if ($tags && is_array($tags)) {
if ($tags) {
foreach ($tags as $tag) {
if ($this->delete($this->db->sql()->where('mid = ?', $tag))) {
$this->db->query($this->db->delete('table.relationships')->where('mid = ?', $tag));
@@ -306,11 +306,11 @@ class Edit extends Metas implements ActionInterface
public function mergeTag()
{
if (empty($this->request->merge)) {
Notice::alloc()->set(_t('请填写需要合并到的标签'), 'notice');
Notice::alloc()->set(_t('请填写需要合并到的标签'));
$this->response->goBack();
}
$merge = $this->scanTags($this->request->merge);
$merge = $this->scanTags($this->request->get('merge'));
if (empty($merge)) {
Notice::alloc()->set(_t('合并到的标签名不合法'), 'error');
$this->response->goBack();
@@ -324,7 +324,7 @@ class Edit extends Metas implements ActionInterface
/** 提示信息 */
Notice::alloc()->set(_t('标签已经合并'), 'success');
} else {
Notice::alloc()->set(_t('没有选择任何标签'), 'notice');
Notice::alloc()->set(_t('没有选择任何标签'));
}
/** 转向原页 */
@@ -343,7 +343,7 @@ class Edit extends Metas implements ActionInterface
$tags = $this->request->filter('int')->getArray('mid');
if ($tags) {
foreach ($tags as $tag) {
$this->refreshCountByTypeAndStatus($tag, 'post', 'publish');
$this->refreshCountByTypeAndStatus($tag, 'post');
}
// 自动清理标签
@@ -351,7 +351,7 @@ class Edit extends Metas implements ActionInterface
Notice::alloc()->set(_t('标签刷新已经完成'), 'success');
} else {
Notice::alloc()->set(_t('没有选择任何标签'), 'notice');
Notice::alloc()->set(_t('没有选择任何标签'));
}
/** 转向原页 */
+1 -1
View File
@@ -21,7 +21,7 @@ class Notice extends Widget
*
* @var string
*/
public $highlight;
public string $highlight;
/**
* 高亮相关元素
+8 -3
View File
@@ -87,6 +87,9 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
* @property bool $commentsAntiSpam
* @property bool $commentsAutoClose
* @property bool $commentsPostIntervalEnable
* @property int $commentsMaxNestingLevels
* @property int $commentsPostTimeout
* @property int $commentsPostInterval
* @property string $commentsHTMLTagAllowed
* @property bool $allowRegister
* @property bool $allowXmlRpc
@@ -97,6 +100,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
* @property array $plugins
* @property string $secret
* @property bool $installed
* @property bool $rewrite
* @property string $postDateFormat
*/
class Options extends Base
{
@@ -106,7 +111,7 @@ class Options extends Base
* @access private
* @var array
*/
private $pluginConfig = [];
private array $pluginConfig = [];
/**
* 缓存的个人插件配置
@@ -114,7 +119,7 @@ class Options extends Base
* @access private
* @var array
*/
private $personalPluginConfig = [];
private array $personalPluginConfig = [];
/**
* @param int $components
@@ -676,7 +681,7 @@ class Options extends Base
$this->attachmentTypes
);
$attachmentTypesResult = array_unique(array_map('trim', preg_split("/(,|\.)/", $attachmentTypes)));
$attachmentTypesResult = array_unique(array_map('trim', preg_split("/([,.])/", $attachmentTypes)));
}
return $attachmentTypesResult;
+5 -5
View File
@@ -52,7 +52,7 @@ class Discussion extends Options implements ActionInterface
'commentsPostTimeout',
'commentsPostInterval',
'commentsRequireModeration',
'commentsRequireURL',
'commentsRequireUrl',
'commentsHTMLTagAllowed',
'commentsStopWords',
'commentsIpBlackList'
@@ -84,7 +84,7 @@ class Discussion extends Options implements ActionInterface
);
$settings['commentsWhitelist'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsWhitelist');
$settings['commentsRequireMail'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsRequireMail');
$settings['commentsRequireURL'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsRequireURL');
$settings['commentsRequireUrl'] = $this->isEnableByCheckbox($settings['commentsPost'], 'commentsRequireUrl');
$settings['commentsCheckReferer'] = $this->isEnableByCheckbox(
$settings['commentsPost'],
'commentsCheckReferer'
@@ -212,7 +212,7 @@ class Discussion extends Options implements ActionInterface
'commentsRequireModeration' => _t('所有评论必须经过审核'),
'commentsWhitelist' => _t('评论者之前须有评论通过了审核'),
'commentsRequireMail' => _t('必须填写邮箱'),
'commentsRequireURL' => _t('必须填写网址'),
'commentsRequireUrl' => _t('必须填写网址'),
'commentsCheckReferer' => _t('检查评论来源页 URL 是否与文章链接一致'),
'commentsAntiSpam' => _t('开启反垃圾保护'),
'commentsAutoClose' => _t('在文章发布 %s 天以后自动关闭评论',
@@ -236,8 +236,8 @@ class Discussion extends Options implements ActionInterface
$commentsPostOptionsValue[] = 'commentsRequireMail';
}
if ($this->options->commentsRequireURL) {
$commentsPostOptionsValue[] = 'commentsRequireURL';
if ($this->options->commentsRequireUrl) {
$commentsPostOptionsValue[] = 'commentsRequireUrl';
}
if ($this->options->commentsCheckReferer) {
+2 -2
View File
@@ -96,7 +96,7 @@ class General extends Options implements ActionInterface
$settings['attachmentTypes'] = $this->request->getArray('attachmentTypes');
if (!defined('__TYPECHO_SITE_URL__')) {
$settings['siteUrl'] = rtrim($this->request->siteUrl, '/');
$settings['siteUrl'] = rtrim($this->request->get('siteUrl'), '/');
}
$attachmentTypes = [];
@@ -112,7 +112,7 @@ class General extends Options implements ActionInterface
$attachmentTypes[] = '@doc@';
}
$attachmentTypesOther = $this->request->filter('trim', 'strtolower')->attachmentTypesOther;
$attachmentTypesOther = $this->request->filter('trim', 'strtolower')->get('attachmentTypesOther');
if ($this->isEnableByCheckbox($settings['attachmentTypes'], '@other@') && !empty($attachmentTypesOther)) {
$types = implode(
',',
+17 -14
View File
@@ -57,7 +57,7 @@ class Permalink extends Options implements ActionInterface
* @param string $value 是否打开rewrite
* @return bool
*/
public function checkRewrite(string $value)
public function checkRewrite(string $value): bool
{
if ($value) {
$this->user->pass('administrator');
@@ -125,7 +125,7 @@ RewriteRule . {$basePath}index.php [L]
unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess');
}
} catch (Client\Exception $e) {
if (false != $hasWrote) {
if ($hasWrote) {
@unlink(__TYPECHO_ROOT_DIR__ . '/.htaccess');
}
return false;
@@ -146,25 +146,28 @@ RewriteRule . {$basePath}index.php [L]
*/
public function updatePermalinkSettings()
{
$customPattern = $this->request->get('customPattern');
$postPattern = $this->request->get('postPattern');
/** 验证格式 */
if ($this->form()->validate()) {
Cookie::set('__typecho_form_item_postPattern', $this->request->customPattern);
Cookie::set('__typecho_form_item_postPattern', $customPattern);
$this->response->goBack();
}
$patternValid = $this->checkRule($this->request->postPattern);
$patternValid = $this->checkRule($postPattern);
/** 解析url pattern */
if ('custom' == $this->request->postPattern) {
$this->request->postPattern = '/' . ltrim($this->encodeRule($this->request->customPattern), '/');
if ('custom' == $postPattern) {
$postPattern = '/' . ltrim($this->encodeRule($customPattern), '/');
}
$settings = defined('__TYPECHO_REWRITE__') ? [] : $this->request->from('rewrite');
if (isset($this->request->postPattern) && isset($this->request->pagePattern)) {
if (isset($postPattern) && $this->request->is('pagePattern')) {
$routingTable = $this->options->routingTable;
$routingTable['post']['url'] = $this->request->postPattern;
$routingTable['page']['url'] = '/' . ltrim($this->encodeRule($this->request->pagePattern), '/');
$routingTable['category']['url'] = '/' . ltrim($this->encodeRule($this->request->categoryPattern), '/');
$routingTable['post']['url'] = $postPattern;
$routingTable['page']['url'] = '/' . ltrim($this->encodeRule($this->request->get('pagePattern')), '/');
$routingTable['category']['url'] = '/' . ltrim($this->encodeRule($this->request->get('categoryPattern')), '/');
$routingTable['category_page']['url'] = rtrim($routingTable['category']['url'], '/') . '/[page:digital]/';
if (isset($routingTable[0])) {
@@ -181,7 +184,7 @@ RewriteRule . {$basePath}index.php [L]
if ($patternValid) {
Notice::alloc()->set(_t("设置已经保存"), 'success');
} else {
Notice::alloc()->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), 'notice');
Notice::alloc()->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."));
}
$this->response->goBack();
}
@@ -246,8 +249,8 @@ RewriteRule . {$basePath}index.php [L]
/** 增加个性化路径 */
$customPatternValue = null;
if (isset($this->request->__typecho_form_item_postPattern)) {
$customPatternValue = $this->request->__typecho_form_item_postPattern;
if ($this->request->is('__typecho_form_item_postPattern')) {
$customPatternValue = $this->request->get('__typecho_form_item_postPattern');
Cookie::delete('__typecho_form_item_postPattern');
} elseif (!isset($patterns[$postPatternValue])) {
$customPatternValue = $this->decodeRule($postPatternValue);
@@ -325,7 +328,7 @@ RewriteRule . {$basePath}index.php [L]
}
$routingTable = $this->options->routingTable;
$currentTable = ['custom' => ['url' => $this->encodeRule($this->request->customPattern)]];
$currentTable = ['custom' => ['url' => $this->encodeRule($this->request->get('customPattern'))]];
$parser = new Parser($currentTable);
$currentTable = $parser->parse();
$regx = $currentTable['custom']['regx'];
+5 -5
View File
@@ -44,17 +44,17 @@ class Reading extends Permalink
);
if (
'page' == $settings['frontPage'] && isset($this->request->frontPagePage) &&
'page' == $settings['frontPage'] && $this->request->is('frontPagePage') &&
$this->db->fetchRow($this->db->select('cid')
->from('table.contents')->where('type = ?', 'page')
->where('status = ?', 'publish')->where('created < ?', $this->options->time)
->where('cid = ?', $pageId = intval($this->request->frontPagePage)))
->where('cid = ?', $pageId = intval($this->request->get('frontPagePage'))))
) {
$settings['frontPage'] = 'page:' . $pageId;
} elseif (
'file' == $settings['frontPage'] && isset($this->request->frontPageFile) &&
'file' == $settings['frontPage'] && $this->request->is('frontPageFile') &&
file_exists(__TYPECHO_ROOT_DIR__ . '/' . __TYPECHO_THEME_DIR__ . '/' . $this->options->theme . '/' .
($file = trim($this->request->frontPageFile, " ./\\")))
($file = trim($this->request->get('frontPageFile'), " ./\\")))
) {
$settings['frontPage'] = 'file:' . $file;
} else {
@@ -65,7 +65,7 @@ class Reading extends Permalink
$settings['frontArchive'] = empty($settings['frontArchive']) ? 0 : 1;
if ($settings['frontArchive']) {
$routingTable = $this->options->routingTable;
$routingTable['archive']['url'] = '/' . ltrim($this->encodeRule($this->request->archivePattern), '/');
$routingTable['archive']['url'] = '/' . ltrim($this->encodeRule($this->request->get('archivePattern')), '/');
$routingTable['archive_page']['url'] = rtrim($routingTable['archive']['url'], '/')
. '/page/[page:digital]/';
+6 -6
View File
@@ -27,21 +27,21 @@ class Config extends Options
*
* @var array
*/
public $info;
public array $info;
/**
* 插件文件路径
*
* @var string
*/
private $pluginFileName;
private string $pluginFileName;
/**
* 插件类
*
* @var string
*/
private $className;
private string $className;
/**
* 绑定动作
@@ -52,7 +52,7 @@ class Config extends Options
public function execute()
{
$this->user->pass('administrator');
$config = $this->request->filter('slug')->config;
$config = $this->request->filter('slug')->get('config');
if (empty($config)) {
throw new Exception(_t('插件不存在'), 404);
}
@@ -78,10 +78,10 @@ class Config extends Options
* @return Form
* @throws Exception|Plugin\Exception
*/
public function config()
public function config(): Form
{
/** 获取插件名称 */
$pluginName = $this->request->filter('slug')->config;
$pluginName = $this->request->filter('slug')->get('config');
/** 获取已启用插件 */
$plugins = Plugin::export();
+6 -6
View File
@@ -29,7 +29,7 @@ class Edit extends Options implements ActionInterface
/**
* @var bool
*/
private $configNoticed = false;
private bool $configNoticed = false;
/**
* 启用插件
@@ -124,7 +124,7 @@ class Edit extends Options implements ActionInterface
$result = call_user_func([$className, 'configCheck'], $settings);
if (!empty($result) && is_string($result)) {
Notice::alloc()->set($result, 'notice');
Notice::alloc()->set($result);
$this->configNoticed = true;
}
}
@@ -261,7 +261,7 @@ class Edit extends Options implements ActionInterface
$this->delete($this->db->sql()->where('name = ?', '_plugin:' . $pluginName));
if (isset($result) && is_string($result)) {
Notice::alloc()->set($result, 'notice');
Notice::alloc()->set($result);
} else {
Notice::alloc()->set(_t('插件已经被禁用'), 'success');
}
@@ -310,9 +310,9 @@ class Edit extends Options implements ActionInterface
{
$this->user->pass('administrator');
$this->security->protect();
$this->on($this->request->is('activate'))->activate($this->request->filter('slug')->activate);
$this->on($this->request->is('deactivate'))->deactivate($this->request->filter('slug')->deactivate);
$this->on($this->request->is('config'))->config($this->request->filter('slug')->config);
$this->on($this->request->is('activate'))->activate($this->request->filter('slug')->get('activate'));
$this->on($this->request->is('deactivate'))->deactivate($this->request->filter('slug')->get('deactivate'));
$this->on($this->request->is('config'))->config($this->request->filter('slug')->get('config'));
$this->response->redirect($this->options->adminUrl);
}
}
+2 -4
View File
@@ -2,7 +2,6 @@
namespace Widget\Plugins;
use Typecho\Common;
use Typecho\Plugin;
use Typecho\Widget;
@@ -27,7 +26,7 @@ class Rows extends Widget
* @access public
* @var array
*/
public $activatedPlugins = [];
public array $activatedPlugins = [];
/**
* 执行函数
@@ -89,10 +88,9 @@ class Rows extends Widget
/**
* @param string $plugin
* @param string $index
* @return array|null
*/
protected function getPlugin(string $plugin, string $index): ?array
protected function getPlugin(string $plugin): ?array
{
if (is_dir($plugin)) {
/** 获取插件名称 */

Some files were not shown because too many files have changed in this diff Show More