reformat code

This commit is contained in:
joyqi 2021-08-18 18:41:39 +08:00
parent 467471c9c3
commit 44aef6c707
25 changed files with 1216 additions and 1032 deletions

View File

@ -1,7 +1,7 @@
<?php if(!defined('__TYPECHO_ADMIN__')) exit; ?>
<script src="<?php $options->adminStaticUrl('js', 'jquery.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'jquery-ui.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'typecho.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'jquery.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'jquery-ui.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'typecho.js'); ?>"></script>
<script>
(function () {
$(document).ready(function() {

View File

@ -23,12 +23,11 @@ Typecho_Widget::widget('Widget_Security')->to($security);
Typecho_Widget::widget('Widget_Menu')->to($menu);
/** 初始化上下文 */
$request = $options->request;
$response = $options->response;
$request = Typecho_Request::getInstance();
$response = Typecho_Response::getInstance();
/** 检测是否是第一次登录 */
$currentMenu = $menu->getCurrentMenu();
list($prefixVersion, $suffixVersion) = explode('/', $options->version);
if (!empty($currentMenu)) {
$params = parse_url($currentMenu[2]);
@ -43,8 +42,7 @@ if (!empty($currentMenu)) {
}
} elseif ($user->pass('administrator', true)) {
/** 检测版本是否升级 */
$mustUpgrade = (!defined('Typecho_Common::VERSION') || version_compare(str_replace('/', '.', Typecho_Common::VERSION),
str_replace('/', '.', $options->version), '>'));
$mustUpgrade = version_compare(Typecho_Common::VERSION, $options->version, '>');
if ($mustUpgrade && 'upgrade.php' != $adminFile && 'backup.php' != $adminFile) {
$response->redirect(Typecho_Common::url('upgrade.php', $options->adminUrl));

View File

@ -2,7 +2,7 @@
<div class="typecho-foot" role="contentinfo">
<div class="copyright">
<a href="http://typecho.org" class="i-logo-s">Typecho</a>
<p><?php _e('由 <a href="http://typecho.org">%s</a> 强力驱动, 版本 %s (%s)', $options->software, $prefixVersion, $suffixVersion); ?></p>
<p><?php _e('由 <a href="http://typecho.org">%s</a> 强力驱动, 版本 %s', $options->software, $options->version); ?></p>
</div>
<nav class="resource">
<a href="http://docs.typecho.org"><?php _e('帮助文档'); ?></a> &bull;

View File

@ -1,9 +1,9 @@
<?php if(!defined('__TYPECHO_ADMIN__')) exit; ?>
<?php $content = !empty($post) ? $post : $page; if ($options->markdown): ?>
<script src="<?php $options->adminStaticUrl('js', 'hyperdown.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'pagedown.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'paste.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'purify.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'hyperdown.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'pagedown.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'paste.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'purify.js'); ?>"></script>
<script>
$(document).ready(function () {
var textarea = $('#text'),

View File

@ -13,8 +13,8 @@ if (preg_match("/^([0-9]+)([a-z]{1,2})$/i", $phpMaxFilesize, $matches)) {
}
?>
<script src="<?php $options->adminStaticUrl('js', 'moxie.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'plupload.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'moxie.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'plupload.js'); ?>"></script>
<script>
$(document).ready(function() {
function updateAttacmentNumber () {

View File

@ -3,9 +3,9 @@ if (!defined('__TYPECHO_ADMIN__')) {
exit;
}
$header = '<link rel="stylesheet" href="' . Typecho_Common::url('normalize.css?v=' . $suffixVersion, $options->adminStaticUrl('css')) . '">
<link rel="stylesheet" href="' . Typecho_Common::url('grid.css?v=' . $suffixVersion, $options->adminStaticUrl('css')) . '">
<link rel="stylesheet" href="' . Typecho_Common::url('style.css?v=' . $suffixVersion, $options->adminStaticUrl('css')) . '">';
$header = '<link rel="stylesheet" href="' . $options->adminStaticUrl('css', 'normalize.css', true) . '">
<link rel="stylesheet" href="' . $options->adminStaticUrl('css', 'grid.css', true) . '">
<link rel="stylesheet" href="' . $options->adminStaticUrl('css', 'style.css', true) . '">';
/** 注册一个初始化插件 */
$header = Typecho_Plugin::factory('admin/header.php')->header($header);

View File

@ -48,8 +48,8 @@ Typecho_Widget::widget('Widget_Contents_Attachment_Edit')->to($attachment);
include 'copyright.php';
include 'common-js.php';
?>
<script src="<?php $options->adminStaticUrl('js', 'moxie.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'plupload.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'moxie.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'plupload.js'); ?>"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#attachment-url').click(function () {

View File

@ -2,8 +2,8 @@
<?php Typecho_Plugin::factory('admin/write-js.php')->write(); ?>
<?php Typecho_Widget::widget('Widget_Metas_Tag_Cloud', 'sort=count&desc=1&limit=200')->to($tags); ?>
<script src="<?php $options->adminStaticUrl('js', 'timepicker.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'tokeninput.js?v=' . $suffixVersion); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'timepicker.js'); ?>"></script>
<script src="<?php $options->adminStaticUrl('js', 'tokeninput.js'); ?>"></script>
<script>
$(document).ready(function() {
// 日期时间控件

View File

@ -111,21 +111,15 @@ function get_pot($file) {
require_once __DIR__ . '/../var/Typecho/Common.php';
$version = Typecho_Common::VERSION;
$date = date('Y-m-d H:iO');
$year = date('Y');
echo <<<EOF
# Copyright (C) {$year} Typecho
# Copyright (C) Typecho
# This file is distributed under the same license as the Typecho Project.
# FIRST AUTHOR <joyqi@typecho.org>, {$year}.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: {$version}\\n"
"Report-Msgid-Bugs-To: \\n"
"POT-Creation-Date: {$date}\\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: Typecho Dev <team@typecho.org>\\n"

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ class Typecho_Cookie
{
/**
* 前缀
*
*
* @var string
* @access private
*/
@ -28,46 +28,47 @@ class Typecho_Cookie
/**
* 路径
*
*
* @var string
* @access private
*/
private static $_path = '/';
/**
* 设置前缀
*
* @param string $url
* @access public
* @return void
*/
public static function setPrefix($url)
{
self::$_prefix = md5($url);
$parsed = parse_url($url);
/** 在路径后面强制加上斜杠 */
self::$_path = empty($parsed['path']) ? '/' : Typecho_Common::url(NULL, $parsed['path']);
}
/**
* 获取前缀
*
* 获取前缀
*
* @access public
* @return string
*/
public static function getPrefix()
public static function getPrefix(): string
{
return self::$_prefix;
}
/**
* 获取目录
*
* 设置前缀
*
* @param string $url
*
* @access public
* @return void
*/
public static function setPrefix(string $url)
{
self::$_prefix = md5($url);
$parsed = parse_url($url);
/** 在路径后面强制加上斜杠 */
self::$_path = empty($parsed['path']) ? '/' : Typecho_Common::url(null, $parsed['path']);
}
/**
* 获取目录
*
* @access public
* @return string
*/
public static function getPath()
public static function getPath(): string
{
return self::$_path;
}
@ -76,14 +77,16 @@ class Typecho_Cookie
* 获取指定的COOKIE值
*
* @access public
*
* @param string $key 指定的参数
* @param string $default 默认的参数
* @param string|null $default 默认的参数
*
* @return mixed
*/
public static function get($key, $default = NULL)
public static function get(string $key, ?string $default = null)
{
$key = self::$_prefix . $key;
$value = isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
$value = $_COOKIE[$key] ?? $default;
return is_array($value) ? $default : $value;
}
@ -91,12 +94,14 @@ class Typecho_Cookie
* 设置指定的COOKIE值
*
* @access public
*
* @param string $key 指定的参数
* @param mixed $value 设置的值
* @param integer $expire 过期时间,默认为0,表示随会话时间结束
*
* @return void
*/
public static function set($key, $value, $expire = 0)
public static function set(string $key, $value, int $expire = 0)
{
$key = self::$_prefix . $key;
setrawcookie($key, rawurlencode($value), $expire, self::$_path);
@ -107,10 +112,12 @@ class Typecho_Cookie
* 删除指定的COOKIE值
*
* @access public
*
* @param string $key 指定的参数
*
* @return void
*/
public static function delete($key)
public static function delete(string $key)
{
$key = self::$_prefix . $key;
if (!isset($_COOKIE[$key])) {

View File

@ -45,9 +45,10 @@ class Typecho_Date
* 初始化参数
*
* @access public
* @param integer $time 时间戳
*
* @param integer|null $time 时间戳
*/
public function __construct($time = NULL)
public function __construct(?int $time = NULL)
{
$this->timeStamp = (NULL === $time ? self::time() : $time) + (self::$timezoneOffset - self::$serverTimezoneOffset);
}
@ -56,10 +57,12 @@ class Typecho_Date
* 设置当前期望的时区偏移
*
* @access public
*
* @param integer $offset
*
* @return void
*/
public static function setTimezoneOffset($offset)
public static function setTimezoneOffset(int $offset)
{
self::$timezoneOffset = $offset;
self::$serverTimezoneOffset = idate('Z');
@ -69,10 +72,12 @@ class Typecho_Date
* 获取格式化时间
*
* @access public
*
* @param string $format 时间格式
*
* @return string
*/
public function format($format)
public function format(string $format): string
{
return date($format, $this->timeStamp);
}
@ -83,7 +88,7 @@ class Typecho_Date
* @access public
* @return string
*/
public function word()
public function word(): string
{
return Typecho_I18n::dateWord($this->timeStamp, self::time() + (self::$timezoneOffset - self::$serverTimezoneOffset));
}
@ -92,10 +97,12 @@ class Typecho_Date
* 获取单项数据
*
* @access public
*
* @param string $name 名称
*
* @return integer
*/
public function __get($name)
public function __get(string $name)
{
switch ($name) {
case 'year':
@ -105,7 +112,7 @@ class Typecho_Date
case 'day':
return date('d', $this->timeStamp);
default:
return;
return 0;
}
}
@ -115,7 +122,7 @@ class Typecho_Date
* @deprecated
* @return int
*/
public static function gmtTime()
public static function gmtTime(): int
{
return self::time();
}
@ -125,8 +132,8 @@ class Typecho_Date
*
* @return int
*/
public static function time()
public static function time(): int
{
return self::$serverTimeStamp ? self::$serverTimeStamp : (self::$serverTimeStamp = time());
return self::$serverTimeStamp ?: (self::$serverTimeStamp = time());
}
}

View File

@ -65,14 +65,6 @@ class Typecho_Db
*/
private $_config;
/**
* 连接池
*
* @access private
* @var array
*/
private $_pool;
/**
* 已经连接
*
@ -126,7 +118,6 @@ class Typecho_Db
$this->_prefix = $prefix;
/** 初始化内部变量 */
$this->_pool = [];
$this->_connectedPool = [];
$this->_config = [

View File

@ -75,7 +75,7 @@ class Typecho_Feed
* 基本地址
*
* @access private
* @var unknown
* @var string
*/
private $_baseUrl;
@ -109,7 +109,7 @@ class Typecho_Feed
* @access private
* @var array
*/
private $_items = array();
private $_items = [];
/**
* 创建Feed对象
@ -129,10 +129,12 @@ class Typecho_Feed
* 设置标题
*
* @access public
*
* @param string $title 标题
*
* @return void
*/
public function setTitle($title)
public function setTitle(string $title)
{
$this->_title = $title;
}
@ -141,10 +143,12 @@ class Typecho_Feed
* 设置副标题
*
* @access public
*
* @param string $subTitle 副标题
*
* @return void
*/
public function setSubTitle($subTitle)
public function setSubTitle(string $subTitle)
{
$this->_subTitle = $subTitle;
}
@ -153,10 +157,12 @@ class Typecho_Feed
* 设置聚合地址
*
* @access public
*
* @param string $feedUrl 聚合地址
*
* @return void
*/
public function setFeedUrl($feedUrl)
public function setFeedUrl(string $feedUrl)
{
$this->_feedUrl = $feedUrl;
}
@ -165,30 +171,16 @@ class Typecho_Feed
* 设置主页
*
* @access public
*
* @param string $baseUrl 主页地址
*
* @return void
*/
public function setBaseUrl($baseUrl)
public function setBaseUrl(string $baseUrl)
{
$this->_baseUrl = $baseUrl;
}
/**
* 获取Feed时间格式
*
* @access public
* @param integer $stamp 时间戳
* @return string
*/
public function dateFormat($stamp)
{
if (self::RSS2 == $this->_type) {
return date(self::DATE_RFC822, $stamp);
} else if (self::RSS1 == $this->_type || self::ATOM1 == $this->_type) {
return date(self::DATE_W3CDTF, $stamp);
}
}
/**
* $item的格式为
* <code>
@ -206,8 +198,8 @@ class Typecho_Feed
* </code>
*
* @access public
*
* @param array $item
* @return unknown
*/
public function addItem(array $item)
{
@ -231,7 +223,7 @@ xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">' . self::EOL;
$content = '';
$links = array();
$links = [];
$lastUpdate = 0;
foreach ($this->_items as $item) {
@ -301,9 +293,9 @@ xmlns:wfw="http://wellformedweb.org/CommentAPI/">
if (!empty($item['content'])) {
$content .= '<content:encoded xml:lang="' . $this->_lang . '"><![CDATA['
. self::EOL .
$item['content'] . self::EOL .
']]></content:encoded>' . self::EOL;
. self::EOL .
$item['content'] . self::EOL .
']]></content:encoded>' . self::EOL;
}
if (isset($item['comments']) && strlen($item['comments']) > 0) {
@ -371,9 +363,9 @@ xml:base="' . $this->_baseUrl . '"
if (!empty($item['content'])) {
$content .= '<content type="html" xml:base="' . $item['link'] . '" xml:lang="' . $this->_lang . '"><![CDATA['
. self::EOL .
$item['content'] . self::EOL .
']]></content>' . self::EOL;
. self::EOL .
$item['content'] . self::EOL .
']]></content>' . self::EOL;
}
if (isset($item['comments']) && strlen($item['comments']) > 0) {
@ -408,4 +400,22 @@ xml:base="' . $this->_baseUrl . '"
return $result;
}
/**
* 获取Feed时间格式
*
* @access public
*
* @param integer $stamp 时间戳
*
* @return string
*/
public function dateFormat(int $stamp): string
{
if (self::RSS2 == $this->_type) {
return date(self::DATE_RFC822, $stamp);
} else if (self::RSS1 == $this->_type || self::ATOM1 == $this->_type) {
return date(self::DATE_W3CDTF, $stamp);
}
}
}

View File

@ -28,7 +28,22 @@ class Typecho_I18n
* @access private
* @var string
*/
private static $_lang = NULL;
private static $_lang = null;
/**
* 翻译文字
*
* @access public
*
* @param string $string 待翻译的文字
*
* @return string
*/
public static function translate(string $string): string
{
self::init();
return self::$_loaded ? self::$_loaded->translate($string) : $string;
}
/**
* 初始化语言文件
@ -43,28 +58,16 @@ class Typecho_I18n
}
}
/**
* 翻译文字
*
* @access public
* @param string $string 待翻译的文字
* @return string
*/
public static function translate($string)
{
self::init();
return self::$_loaded ? self::$_loaded->translate($string) : $string;
}
/**
* 针对复数形式的翻译函数
*
* @param string $single 单数形式的翻译
* @param string $plural 复数形式的翻译
* @param integer $number 数字
*
* @return string
*/
public static function ngettext($single, $plural, $number)
public static function ngettext(string $single, string $plural, int $number): string
{
self::init();
return self::$_loaded ? self::$_loaded->ngettext($single, $plural, $number) : ($number > 1 ? $plural : $single);
@ -74,11 +77,13 @@ class Typecho_I18n
* 词义化时间
*
* @access public
*
* @param string $from 起始时间
* @param string $now 终止时间
*
* @return string
*/
public static function dateWord($from, $now)
public static function dateWord(int $from, int $now): string
{
$between = $now - $from;
@ -104,9 +109,9 @@ class Typecho_I18n
}
/** 如果是昨天 */
if ($between > 0 && $between < 172800
&& (date('z', $from) + 1 == date('z', $now) // 在同一年的情况
|| date('z', $from) + 1 == date('L') + 365 + date('z', $now))) { // 跨年的情况
if ($between > 0 && $between < 172800
&& (date('z', $from) + 1 == date('z', $now) // 在同一年的情况
|| date('z', $from) + 1 == date('L') + 365 + date('z', $now))) { // 跨年的情况
return _t('昨天 %s', date('H:i', $from));
}
@ -124,26 +129,16 @@ class Typecho_I18n
return date(_t('Y年m月d日'), $from);
}
/**
* 设置语言项
*
* @access public
* @param string $lang 配置信息
* @return void
*/
public static function setLang($lang)
{
self::$_lang = $lang;
}
/**
* 增加语言项
*
* @access public
*
* @param string $lang 语言名称
*
* @return void
*/
public static function addLang($lang)
public static function addLang(string $lang)
{
self::$_loaded->addFile($lang);
}
@ -152,10 +147,24 @@ class Typecho_I18n
* 获取语言项
*
* @access public
* @return void
* @return string
*/
public static function getLang()
public static function getLang(): ?string
{
return self::$_lang;
}
/**
* 设置语言项
*
* @access public
*
* @param string $lang 配置信息
*
* @return void
*/
public static function setLang(string $lang)
{
self::$_lang = $lang;
}
}

View File

@ -23,7 +23,7 @@ class Typecho_Plugin
* @access private
* @var array
*/
private static $_plugins = array();
private static $_plugins = [];
/**
* 已经加载的文件
@ -31,7 +31,7 @@ class Typecho_Plugin
* @access private
* @var array
*/
private static $_required = array();
private static $_required = [];
/**
* 实例化的插件对象
@ -47,7 +47,7 @@ class Typecho_Plugin
* @access private
* @var array
*/
private static $_tmp = array();
private static $_tmp = [];
/**
* 唯一句柄
@ -77,44 +77,28 @@ class Typecho_Plugin
* 插件初始化
*
* @access public
*
* @param string $handle 插件
*/
public function __construct($handle)
public function __construct(string $handle)
{
/** 初始化变量 */
$this->_handle = $handle;
}
/**
* 插件handle比对
*
* @access private
* @param array $pluginHandles
* @param array $otherPluginHandles
* @return array
*/
private static function pluginHandlesDiff(array $pluginHandles, array $otherPluginHandles)
{
foreach ($otherPluginHandles as $handle) {
while (false !== ($index = array_search($handle, $pluginHandles))) {
unset($pluginHandles[$index]);
}
}
return $pluginHandles;
}
/**
* 插件初始化
*
* @access public
*
* @param array $plugins 插件列表
*
* @return void
*/
public static function init(array $plugins)
{
$plugins['activated'] = array_key_exists('activated', $plugins) ? $plugins['activated'] : array();
$plugins['handles'] = array_key_exists('handles', $plugins) ? $plugins['handles'] : array();
$plugins['activated'] = array_key_exists('activated', $plugins) ? $plugins['activated'] : [];
$plugins['handles'] = array_key_exists('handles', $plugins) ? $plugins['handles'] : [];
/** 初始化变量 */
self::$_plugins = $plugins;
@ -124,43 +108,48 @@ class Typecho_Plugin
* 获取实例化插件对象
*
* @access public
*
* @param string $handle 插件
*
* @return Typecho_Plugin
*/
public static function factory($handle)
public static function factory(string $handle): Typecho_Plugin
{
return isset(self::$_instances[$handle]) ? self::$_instances[$handle] :
(self::$_instances[$handle] = new Typecho_Plugin($handle));
return self::$_instances[$handle] ?? (self::$_instances[$handle] = new Typecho_Plugin($handle));
}
/**
* 启用插件
*
* @access public
*
* @param string $pluginName 插件名称
*
* @return void
*/
public static function activate($pluginName)
public static function activate(string $pluginName)
{
self::$_plugins['activated'][$pluginName] = self::$_tmp;
self::$_tmp = array();
self::$_tmp = [];
}
/**
* 禁用插件
*
* @access public
*
* @param string $pluginName 插件名称
*
* @return void
*/
public static function deactivate($pluginName)
public static function deactivate(string $pluginName)
{
/** 去掉所有相关回调函数 */
if (isset(self::$_plugins['activated'][$pluginName]['handles']) && is_array(self::$_plugins['activated'][$pluginName]['handles'])) {
foreach (self::$_plugins['activated'][$pluginName]['handles'] as $handle => $handles) {
self::$_plugins['handles'][$handle] = self::pluginHandlesDiff(
empty(self::$_plugins['handles'][$handle]) ? array() : self::$_plugins['handles'][$handle],
empty($handles) ? array() : $handles);
empty(self::$_plugins['handles'][$handle]) ? [] : self::$_plugins['handles'][$handle],
empty($handles) ? [] : $handles);
if (empty(self::$_plugins['handles'][$handle])) {
unset(self::$_plugins['handles'][$handle]);
}
@ -171,13 +160,34 @@ class Typecho_Plugin
unset(self::$_plugins['activated'][$pluginName]);
}
/**
* 插件handle比对
*
* @access private
*
* @param array $pluginHandles
* @param array $otherPluginHandles
*
* @return array
*/
private static function pluginHandlesDiff(array $pluginHandles, array $otherPluginHandles): array
{
foreach ($otherPluginHandles as $handle) {
while (false !== ($index = array_search($handle, $pluginHandles))) {
unset($pluginHandles[$index]);
}
}
return $pluginHandles;
}
/**
* 导出当前插件设置
*
* @access public
* @return array
*/
public static function export()
public static function export(): array
{
return self::$_plugins;
}
@ -186,10 +196,12 @@ class Typecho_Plugin
* 获取插件文件的头信息
*
* @access public
*
* @param string $pluginFile 插件文件路径
*
* @return array
*/
public static function parseInfo($pluginFile)
public static function parseInfo(string $pluginFile): array
{
$tokens = token_get_all(file_get_contents($pluginFile));
$isDoc = false;
@ -198,29 +210,29 @@ class Typecho_Plugin
$isInClass = false;
$isInFunction = false;
$isDefined = false;
$current = NULL;
$current = null;
/** 初始信息 */
$info = array(
'description' => '',
'title' => '',
'author' => '',
'homepage' => '',
'version' => '',
'dependence' => '',
'activate' => false,
'deactivate' => false,
'config' => false,
'personalConfig' => false
);
$info = [
'description' => '',
'title' => '',
'author' => '',
'homepage' => '',
'version' => '',
'dependence' => '',
'activate' => false,
'deactivate' => false,
'config' => false,
'personalConfig' => false
];
$map = array(
'package' => 'title',
'author' => 'author',
'link' => 'homepage',
'dependence'=> 'dependence',
'version' => 'version'
);
$map = [
'package' => 'title',
'author' => 'author',
'link' => 'homepage',
'dependence' => 'dependence',
'version' => 'version'
];
foreach ($tokens as $token) {
/** 获取doc comment */
@ -312,7 +324,7 @@ class Typecho_Plugin
$isDefined = false;
$isFunction = false;
$isInFunction = false;
$current = NULL;
$current = null;
break;
default:
if (!empty($current) && $isInFunction && $isInClass) {
@ -332,12 +344,14 @@ class Typecho_Plugin
* 第一项为插件路径,第二项为类名
*
* @access public
*
* @param string $pluginName 插件名
* @param string $path 插件目录
*
* @return array
* @throws Typecho_Plugin_Exception
*/
public static function portal($pluginName, $path)
public static function portal(string $pluginName, string $path): array
{
switch (true) {
case file_exists($pluginFileName = $path . '/' . $pluginName . '/Plugin.php'):
@ -350,18 +364,20 @@ class Typecho_Plugin
throw new Typecho_Plugin_Exception('Missing Plugin ' . $pluginName, 404);
}
return array($pluginFileName, $className);
return [$pluginFileName, $className];
}
/**
* 版本依赖性检测
*
* @access public
*
* @param string $version 程序版本
* @param string $versionRange 依赖的版本规则
*
* @return boolean
*/
public static function checkDependence($version, $versionRange)
public static function checkDependence(string $version, string $versionRange): bool
{
//如果没有检测规则,直接掠过
if (empty($versionRange)) {
@ -373,11 +389,11 @@ class Typecho_Plugin
$items[1] = '9999.9999.9999';
}
list ($minVersion, $maxVersion) = $items;
[$minVersion, $maxVersion] = $items;
//对*和?的支持,4个9是最大版本
$minVersion = str_replace(array('*', '?'), array('9999', '9'), $minVersion);
$maxVersion = str_replace(array('*', '?'), array('9999', '9'), $maxVersion);
$minVersion = str_replace(['*', '?'], ['9999', '9'], $minVersion);
$maxVersion = str_replace(['*', '?'], ['9999', '9'], $maxVersion);
if (version_compare($version, $minVersion, '>=') && version_compare($version, $maxVersion, '<=')) {
return true;
@ -386,14 +402,30 @@ class Typecho_Plugin
return false;
}
/**
* 判断插件是否存在
*
* @access public
*
* @param string $pluginName 插件名称
*
* @return mixed
*/
public static function exists(string $pluginName)
{
return array_key_exists($pluginName, self::$_plugins['activated']);
}
/**
* 插件调用后的触发器
*
* @access public
* @param boolean $signal 触发器
*
* @param boolean|null $signal 触发器
*
* @return Typecho_Plugin
*/
public function trigger(&$signal)
public function trigger(?bool &$signal): Typecho_Plugin
{
$signal = false;
$this->_signal = &$signal;
@ -401,42 +433,48 @@ class Typecho_Plugin
}
/**
* 判断插件是否存在
* 通过魔术函数设置当前组件位置
*
* @access public
* @param string $pluginName 插件名称
* @return mixed
*
* @param string $component 当前组件
*
* @return Typecho_Plugin
*/
public static function exists($pluginName) {
return array_key_exists($pluginName, self::$_plugins['activated']);
public function __get(string $component)
{
$this->_component = $component;
return $this;
}
/**
* 设置回调函数
*
* @access public
*
* @param string $component 当前组件
* @param mixed $value 回调函数
*
* @return void
*/
public function __set($component, $value)
public function __set(string $component, $value)
{
$weight = 0;
if (strpos($component, '_') > 0) {
$parts = explode('_', $component, 2);
list($component, $weight) = $parts;
[$component, $weight] = $parts;
$weight = intval($weight) - 10;
}
$component = $this->_handle . ':' . $component;
if (!isset(self::$_plugins['handles'][$component])) {
self::$_plugins['handles'][$component] = array();
self::$_plugins['handles'][$component] = [];
}
if (!isset(self::$_tmp['handles'][$component])) {
self::$_tmp['handles'][$component] = array();
self::$_tmp['handles'][$component] = [];
}
foreach (self::$_plugins['handles'][$component] as $key => $val) {
@ -455,35 +493,24 @@ class Typecho_Plugin
ksort(self::$_plugins['handles'][$component], SORT_NUMERIC);
}
/**
* 通过魔术函数设置当前组件位置
*
* @access public
* @param string $component 当前组件
* @return Typecho_Plugin
*/
public function __get($component)
{
$this->_component = $component;
return $this;
}
/**
* 回调处理函数
*
* @access public
*
* @param string $component 当前组件
* @param string $args 参数
* @param array $args 参数
*
* @return mixed
*/
public function __call($component, $args)
public function __call(string $component, array $args)
{
$component = $this->_handle . ':' . $component;
$last = count($args);
$args[$last] = $last > 0 ? $args[0] : false;
if (isset(self::$_plugins['handles'][$component])) {
$args[$last] = NULL;
$args[$last] = null;
$this->_signal = true;
foreach (self::$_plugins['handles'][$component] as $callback) {
$args[$last] = call_user_func_array($callback, $args);

View File

@ -29,7 +29,7 @@ class Typecho_Router
* @access private
* @var mixed
*/
private static $_routingTable = array();
private static $_routingTable = [];
/**
* 全路径
@ -37,18 +37,20 @@ class Typecho_Router
* @access private
* @var string
*/
private static $_pathInfo = NULL;
private static $_pathInfo = null;
/**
* 解析路径
*
* @access public
*
* @param string $pathInfo 全路径
* @param mixed $parameter 输入参数
*
* @return mixed
* @throws Exception
*/
public static function match($pathInfo, $parameter = NULL)
public static function match(string $pathInfo, $parameter = null)
{
foreach (self::$_routingTable as $key => $route) {
if (preg_match($route['regx'], $pathInfo, $matches)) {
@ -56,7 +58,7 @@ class Typecho_Router
try {
/** 载入参数 */
$params = NULL;
$params = null;
if (!empty($route['params'])) {
unset($matches[0]);
@ -69,7 +71,7 @@ class Typecho_Router
} catch (Exception $e) {
if (404 == $e->getCode()) {
Typecho_Widget::destory($route['widget']);
Typecho_Widget::destroy($route['widget']);
continue;
}
@ -81,33 +83,6 @@ class Typecho_Router
return false;
}
/**
* 设置全路径
*
* @access public
* @param string $pathInfo
* @return void
*/
public static function setPathInfo($pathInfo = '/')
{
self::$_pathInfo = $pathInfo;
}
/**
* 获取全路径
*
* @access public
* @return string
*/
public static function getPathInfo()
{
if (NULL === self::$_pathInfo) {
self::setPathInfo();
}
return self::$_pathInfo;
}
/**
* 路由分发函数
*
@ -125,14 +100,14 @@ class Typecho_Router
try {
/** 载入参数 */
$params = NULL;
$params = null;
if (!empty($route['params'])) {
unset($matches[0]);
$params = array_combine($route['params'], $matches);
}
$widget = Typecho_Widget::widget($route['widget'], NULL, $params);
$widget = Typecho_Widget::widget($route['widget'], null, $params);
if (isset($route['action'])) {
$widget->{$route['action']}();
@ -143,7 +118,7 @@ class Typecho_Router
} catch (Exception $e) {
if (404 == $e->getCode()) {
Typecho_Widget::destory($route['widget']);
Typecho_Widget::destroy($route['widget']);
continue;
}
@ -156,22 +131,52 @@ class Typecho_Router
throw new Typecho_Router_Exception("Path '{$pathInfo}' not found", 404);
}
/**
* 获取全路径
*
* @access public
* @return string
*/
public static function getPathInfo(): ?string
{
if (null === self::$_pathInfo) {
self::setPathInfo();
}
return self::$_pathInfo;
}
/**
* 设置全路径
*
* @access public
*
* @param string $pathInfo
*
* @return void
*/
public static function setPathInfo(string $pathInfo = '/')
{
self::$_pathInfo = $pathInfo;
}
/**
* 路由反解析函数
*
* @param string $name 路由配置表名称
* @param array $value 路由填充值
* @param string $prefix 最终合成路径的前缀
* @param array|null $value 路由填充值
* @param string|null $prefix 最终合成路径的前缀
*
* @return string
*/
public static function url($name, array $value = NULL, $prefix = NULL)
public static function url(string $name, ?array $value = null, ?string $prefix = null): string
{
$route = self::$_routingTable[$name];
//交换数组键值
$pattern = array();
$pattern = [];
foreach ($route['params'] as $row) {
$pattern[$row] = isset($value[$row]) ? $value[$row] : '{' . $row . '}';
$pattern[$row] = $value[$row] ?? '{' . $row . '}';
}
return Typecho_Common::url(vsprintf($route['format'], $pattern), $prefix);
@ -181,7 +186,9 @@ class Typecho_Router
* 设置路由器默认配置
*
* @access public
*
* @param mixed $routes 配置信息
*
* @return void
*/
public static function setRoutes($routes)
@ -199,12 +206,13 @@ class Typecho_Router
* 获取路由信息
*
* @param string $routeName 路由名称
*
* @static
* @access public
* @return mixed
*/
public static function get($routeName)
public static function get(string $routeName)
{
return isset(self::$_routingTable[$routeName]) ? self::$_routingTable[$routeName] : NULL;
return self::$_routingTable[$routeName] ?? null;
}
}

View File

@ -45,7 +45,7 @@ class Typecho_Validate
* @access private
* @var array
*/
private $_rules = array();
private $_rules = [];
/**
* 中断模式,一旦出现验证错误即抛出而不再继续执行
@ -55,13 +55,193 @@ class Typecho_Validate
*/
private $_break = false;
/**
* 最小长度
*
* @access public
*
* @param string $str 待处理的字符串
* @param integer $length 最小长度
*
* @return boolean
*/
public static function minLength(string $str, int $length): bool
{
return (Typecho_Common::strLen($str) >= $length);
}
/**
* 枚举类型判断
*
* @access public
*
* @param string $str 待处理的字符串
* @param array $params 枚举值
*
* @return bool
*/
public static function enum(string $str, array $params): bool
{
$keys = array_flip($params);
return isset($keys[$str]);
}
/**
* Max Length
*
* @param string $str
* @param int $length
*
* @return bool
*/
public static function maxLength(string $str, int $length): bool
{
return (Typecho_Common::strLen($str) < $length);
}
/**
* Valid Email
*
* @access public
*
* @param string $str
*
* @return boolean
*/
public static function email(string $str): bool
{
return preg_match("/^[_a-z0-9-\.+]+@([-a-z0-9]+\.)+[a-z]{2,}$/i", $str);
}
/**
* 验证是否为网址
*
* @access public
*
* @param string $str
*
* @return boolean
*/
public static function url(string $str): bool
{
$parts = @parse_url($str);
if (!$parts) {
return false;
}
return isset($parts['scheme']) &&
in_array($parts['scheme'], ['http', 'https', 'ftp']) &&
!preg_match('/(\(|\)|\\\|"|<|>|[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19])/', $str);
}
/**
* Alpha
*
* @access public
*
* @param string
*
* @return boolean
*/
public static function alpha(string $str): bool
{
return preg_match("/^([a-z])+$/i", $str) ? true : false;
}
/**
* Alpha-numeric
*
* @access public
*
* @param string
*
* @return boolean
*/
public static function alphaNumeric(string $str): bool
{
return preg_match("/^([a-z0-9])+$/i", $str);
}
/**
* Alpha-numeric with underscores and dashes
*
* @access public
*
* @param string
*
* @return boolean
*/
public static function alphaDash(string $str): bool
{
return preg_match("/^([_a-z0-9-])+$/i", $str) ? true : false;
}
/**
* 对xss字符串的检测
*
* @access public
*
* @param string $str
*
* @return boolean
*/
public static function xssCheck(string $str): bool
{
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < strlen($search); $i++) {
// ;? matches the ;, which is optional
// 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
// &#x0040 @ search for the hex values
$str = preg_replace('/(&#[xX]0{0,8}' . dechex(ord($search[$i])) . ';?)/i', $search[$i], $str); // with a ;
// &#00064 @ 0{0,7} matches '0' zero to seven times
$str = preg_replace('/(&#0{0,8}' . ord($search[$i]) . ';?)/', $search[$i], $str); // with a ;
}
return !preg_match('/(\(|\)|\\\|"|<|>|[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19]|' . "\r|\n|\t" . ')/', $str);
}
/**
* Numeric
*
* @access public
*
* @param mixed $str
*
* @return boolean
*/
public static function isFloat($str): bool
{
return preg_match("/^[0-9\.]+$/", $str);
}
/**
* Is Numeric
*
* @access public
*
* @param mixed $str
*
* @return boolean
*/
public static function isInteger($str): bool
{
return is_numeric($str);
}
/**
* 增加验证规则
*
* @access public
*
* @param string $key 数值键值
* @param string $rule 规则名称
* @param string $message 错误字符串
*
* @return $this
*/
public function addRule(string $key, string $rule, string $message): Typecho_Validate
@ -92,10 +272,12 @@ class Typecho_Validate
* Run the Validator
* This function does all the work.
*
* @access public
* @param array $data 需要验证的数据
* @access public
*
* @param array $data 需要验证的数据
* @param array|null $rules 验证数据遵循的规则
* @return array
*
* @return array
*/
public function run(array $data, array $rules = null): array
{
@ -135,25 +317,14 @@ class Typecho_Validate
return $result;
}
/**
* 最小长度
*
* @access public
* @param string $str 待处理的字符串
* @param integer $length 最小长度
* @return boolean
*/
public static function minLength(string $str, int $length): bool
{
return (Typecho_Common::strLen($str) >= $length);
}
/**
* 验证输入是否一致
*
* @access public
*
* @param string|null $str 待处理的字符串
* @param string $key 需要一致性检查的键值
*
* @return boolean
*/
public function confirm(?string $str, string $key): bool
@ -165,155 +336,13 @@ class Typecho_Validate
* 是否为空
*
* @access public
*
* @param string|null $str 待处理的字符串
*
* @return boolean
*/
public function required(?string $str): bool
{
return !empty($this->_data[$this->_key]);
}
/**
* 枚举类型判断
*
* @access public
* @param string $str 待处理的字符串
* @param array $params 枚举值
* @return bool
*/
public static function enum(string $str, array $params): bool
{
$keys = array_flip($params);
return isset($keys[$str]);
}
/**
* Max Length
*
* @param string $str
* @param int $length
* @return bool
*/
public static function maxLength(string $str, int $length): bool
{
return (Typecho_Common::strLen($str) < $length);
}
/**
* Valid Email
*
* @access public
* @param string $str
* @return boolean
*/
public static function email(string $str): bool
{
return preg_match("/^[_a-z0-9-\.+]+@([-a-z0-9]+\.)+[a-z]{2,}$/i", $str);
}
/**
* 验证是否为网址
*
* @access public
* @param string $str
* @return boolean
*/
public static function url(string $str): bool
{
$parts = @parse_url($str);
if (!$parts) {
return false;
}
return isset($parts['scheme']) &&
in_array($parts['scheme'], ['http', 'https', 'ftp']) &&
!preg_match('/(\(|\)|\\\|"|<|>|[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19])/', $str);
}
/**
* Alpha
*
* @access public
* @param string
* @return boolean
*/
public static function alpha(string $str): bool
{
return preg_match("/^([a-z])+$/i", $str) ? true : false;
}
/**
* Alpha-numeric
*
* @access public
* @param string
* @return boolean
*/
public static function alphaNumeric(string $str): bool
{
return preg_match("/^([a-z0-9])+$/i", $str);
}
/**
* Alpha-numeric with underscores and dashes
*
* @access public
* @param string
* @return boolean
*/
public static function alphaDash(string $str): bool
{
return preg_match("/^([_a-z0-9-])+$/i", $str) ? true : false;
}
/**
* 对xss字符串的检测
*
* @access public
* @param string $str
* @return boolean
*/
public static function xssCheck(string $str): bool
{
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < strlen($search); $i++) {
// ;? matches the ;, which is optional
// 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
// &#x0040 @ search for the hex values
$str = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $str); // with a ;
// &#00064 @ 0{0,7} matches '0' zero to seven times
$str = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $str); // with a ;
}
return !preg_match('/(\(|\)|\\\|"|<|>|[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19]|' . "\r|\n|\t" . ')/', $str);
}
/**
* Numeric
*
* @access public
* @param mixed $str
* @return boolean
*/
public static function isFloat($str): bool
{
return preg_match("/^[0-9\.]+$/", $str);
}
/**
* Is Numeric
*
* @access public
* @param mixed $str
* @return boolean
*/
public static function isInteger($str): bool
{
return is_numeric($str);
}
}

View File

@ -20,8 +20,7 @@ abstract class Typecho_Widget
* @access private
* @var array
*/
private static $_widgetPool = array();
private static $_widgetPool = [];
/**
* widget别名
@ -29,23 +28,7 @@ abstract class Typecho_Widget
* @access private
* @var array
*/
private static $_widgetAlias = array();
/**
* 帮手列表
*
* @access private
* @var array
*/
private $_helpers = array();
/**
* 数据堆栈每一行
*
* @access protected
* @var array
*/
protected $row = array();
private static $_widgetAlias = [];
/**
* 数据堆栈
@ -53,15 +36,14 @@ abstract class Typecho_Widget
* @access public
* @var array
*/
public $stack = array();
protected $stack = [];
/**
* 当前队列指针顺序值,从1开始
*
* @access public
* @var integer
*/
public $sequence = 0;
protected $sequence = 0;
/**
* 队列长度
@ -69,7 +51,7 @@ abstract class Typecho_Widget
* @access public
* @var integer
*/
public $length = 0;
protected $length = 0;
/**
* request对象
@ -77,7 +59,7 @@ abstract class Typecho_Widget
* @var Typecho_Request
* @access public
*/
public $request;
protected $request;
/**
* response对象
@ -85,7 +67,7 @@ abstract class Typecho_Widget
* @var Typecho_Response
* @access public
*/
public $response;
protected $response;
/**
* config对象
@ -93,17 +75,26 @@ abstract class Typecho_Widget
* @access public
* @var Typecho_Config
*/
public $parameter;
protected $parameter;
/**
* 数据堆栈每一行
*
* @access protected
* @var array
*/
protected $row = [];
/**
* 构造函数,初始化组件
*
* @access public
*
* @param mixed $request request对象
* @param mixed $response response对象
* @param mixed $params 参数列表
*/
public function __construct($request, $response, $params = NULL)
public function __construct($request, $response, $params = null)
{
//设置函数内部对象
$this->request = $request;
@ -116,62 +107,16 @@ abstract class Typecho_Widget
}
/**
* 解析回调
*
* @param array $matches
* @access protected
* @return string
*/
protected function __parseCallback($matches)
{
return $this->{$matches[1]};
}
/**
* execute function.
* widget别名
*
* @access public
* @return void
*/
public function execute(){}
/**
* post事件触发
* @param string $widgetClass
* @param string $aliasClass
*
* @param boolean $condition 触发条件
* @return mixed
*/
public function on($condition)
{
if ($condition) {
return $this;
} else {
return new Typecho_Widget_Helper_Empty();
}
}
/**
* 获取对象插件句柄
*
* @access public
* @param string $handle 句柄
* @return Typecho_Plugin
*/
public function pluginHandle($handle = NULL)
{
return Typecho_Plugin::factory(empty($handle) ? get_class($this) : $handle);
}
/**
* widget别名
*
* @param string $widgetClass
* @param string $aliasClass
* @static
* @access public
* @return void
*/
public static function alias($widgetClass, $aliasClass)
public static function alias(string $widgetClass, string $aliasClass)
{
self::$_widgetAlias[$widgetClass] = $aliasClass;
}
@ -180,14 +125,16 @@ abstract class Typecho_Widget
* 工厂方法,将类静态化放置到列表中
*
* @access public
*
* @param string $alias 组件别名
* @param mixed $params 传递的参数
* @param mixed $request 前端参数
* @param boolean $enableResponse 是否允许http回执
*
* @return Typecho_Widget
* @throws Typecho_Exception
*/
public static function widget($alias, $params = NULL, $request = NULL, $enableResponse = true)
public static function widget(string $alias, $params = null, $request = null, bool $enableResponse = true): Typecho_Widget
{
$parts = explode('@', $alias);
$className = $parts[0];
@ -213,7 +160,7 @@ abstract class Typecho_Widget
/** 初始化response */
$responseObject = $enableResponse ? Typecho_Response::getInstance()
: Typecho_Widget_Helper_Empty::getInstance();
: Typecho_Widget_Helper_Empty::getInstance();
/** 初始化组件 */
$widget = new $className($requestObject, $responseObject, $params);
@ -228,24 +175,60 @@ abstract class Typecho_Widget
/**
* 释放组件
*
* @access public
* @deprecated alias for destroy
* @param string $alias 组件名称
* @return void
*/
public static function destory($alias)
public static function destory(string $alias)
{
self::destroy($alias);
}
/**
* 释放组件
*
* @param string $alias 组件名称
*/
public static function destroy(string $alias)
{
if (isset(self::$_widgetPool[$alias])) {
unset(self::$_widgetPool[$alias]);
}
}
/**
* execute function.
*
* @access public
* @return void
*/
public function execute()
{
}
/**
* post事件触发
*
* @param boolean $condition 触发条件
*
* @return mixed
*/
public function on(bool $condition)
{
if ($condition) {
return $this;
} else {
return new Typecho_Widget_Helper_Empty();
}
}
/**
* 将类本身赋值
*
* @param string $variable 变量名
* @param mixed $variable 变量名
*
* @return self
*/
public function to(&$variable)
public function to(&$variable): Typecho_Widget
{
return $variable = $this;
}
@ -254,27 +237,47 @@ abstract class Typecho_Widget
* 格式化解析堆栈内的所有数据
*
* @param string $format 数据格式
*
* @return void
*/
public function parse($format)
public function parse(string $format)
{
while ($this->next()) {
echo preg_replace_callback("/\{([_a-z0-9]+)\}/i",
array($this, '__parseCallback'), $format);
echo preg_replace_callback("/\{([_a-z0-9]+)\}/i",
[$this, '__parseCallback'], $format);
}
}
/**
* 返回堆栈每一行的值
*
* @return mixed
*/
public function next()
{
if ($this->sequence < count($this->stack)) {
$this->row = $this->stack[$this->sequence];
$this->sequence++;
} else {
$this->sequence = 0;
return false;
}
return $this->row;
}
/**
* 将每一行的值压入堆栈
*
* @param array $value 每一行的值
* @return array
*
* @return mixed
*/
public function push(array $value)
{
//将行数据按顺序置位
$this->row = $value;
$this->length ++;
$this->length++;
$this->stack[] = $value;
return $value;
@ -291,7 +294,7 @@ abstract class Typecho_Widget
$args = func_get_args();
$num = func_num_args();
$split = $this->sequence % $num;
echo $args[(0 == $split ? $num : $split) -1];
echo $args[(0 == $split ? $num : $split) - 1];
}
/**
@ -321,46 +324,22 @@ abstract class Typecho_Widget
*
* @return boolean
*/
public function have()
public function have(): bool
{
return !empty($this->stack);
}
/**
* 返回堆栈每一行的值
*
* @return array
*/
public function next()
{
if ($this->stack) {
$this->row = @$this->stack[key($this->stack)];
next($this->stack);
$this->sequence ++;
}
if (!$this->row) {
reset($this->stack);
if ($this->stack) {
$this->row = $this->stack[key($this->stack)];
}
$this->sequence = 0;
return false;
}
return $this->row;
}
/**
* 魔术函数,用于挂接其它函数
*
* @access public
*
* @param string $name 函数名
* @param array $args 函数参数
*
* @return void
*/
public function __call($name, $args)
public function __call(string $name, array $args)
{
$method = 'call' . ucfirst($name);
$this->pluginHandle()->trigger($plugged)->{$method}($this, $args);
@ -370,14 +349,30 @@ abstract class Typecho_Widget
}
}
/**
* 获取对象插件句柄
*
* @access public
*
* @param string|null $handle 句柄
*
* @return Typecho_Plugin
*/
public function pluginHandle(?string $handle = null): Typecho_Plugin
{
return Typecho_Plugin::factory(empty($handle) ? get_class($this) : $handle);
}
/**
* 魔术函数,用于获取内部变量
*
* @access public
*
* @param string $name 变量名
*
* @return mixed
*/
public function __get($name)
public function __get(string $name)
{
if (array_key_exists($name, $this->row)) {
return $this->row[$name];
@ -394,7 +389,7 @@ abstract class Typecho_Widget
}
}
return NULL;
return null;
}
/**
@ -402,9 +397,10 @@ abstract class Typecho_Widget
*
* @param string $name 值对应的键值
* @param mixed $value 相应的值
*
* @return void
*/
public function __set($name, $value)
public function __set(string $name, $value)
{
$this->row[$name] = $value;
}
@ -413,11 +409,26 @@ abstract class Typecho_Widget
* 验证堆栈值是否存在
*
* @access public
*
* @param string $name
*
* @return boolean
*/
public function __isSet($name)
public function __isSet(string $name)
{
return isset($this->row[$name]);
}
/**
* 解析回调
*
* @param array $matches
*
* @access protected
* @return string
*/
protected function __parseCallback(array $matches): string
{
return $this->{$matches[1]};
}
}

View File

@ -105,7 +105,7 @@ class Widget_Comments_Ping extends Widget_Abstract_Comments
$args[] = '%d';
}
echo sprintf(isset($args[$this->length]) ? $args[$this->length] : array_pop($this->length), $this->length);
echo sprintf($args[$this->length] ?? array_pop($this->length), $this->length);
}
/**

View File

@ -314,7 +314,7 @@ class Widget_Options extends Typecho_Widget
*/
protected function ___software()
{
list($software, $version) = explode(' ', $this->generator);
[$software, $version] = explode(' ', $this->generator);
return $software;
}
@ -326,7 +326,14 @@ class Widget_Options extends Typecho_Widget
*/
protected function ___version()
{
list($software, $version) = explode(' ', $this->generator);
[$software, $version] = explode(' ', $this->generator);
$pos = strpos($version, '/');
// fix for old version
if ($pos !== false) {
$version = substr($version, 0, $pos);
}
return $version;
}
@ -520,22 +527,33 @@ class Widget_Options extends Typecho_Widget
* 输出后台路径
*
* @access public
* @param string $path 子路径
* @return void
*
* @param string|null $path 子路径
* @param bool $return
*
* @return void|string
*/
public function adminUrl($path = null)
public function adminUrl(?string $path = null, bool $return = false)
{
echo Typecho_Common::url($path, $this->adminUrl);
$url = Typecho_Common::url($path, $this->adminUrl);
if ($return) {
return $url;
}
echo $url;
}
/**
* 获取或输出后台静态文件路径
*
* @param string $type
* @param string $file
* @param string|null $file
* @param bool $return
*
* @return void|string
*/
public function adminStaticUrl($type, $file = null)
public function adminStaticUrl(string $type, ?string $file = null, bool $return = false)
{
$url = Typecho_Common::url($type, $this->adminUrl);
@ -543,7 +561,13 @@ class Widget_Options extends Typecho_Widget
return $url;
}
echo Typecho_Common::url($file, $url);
$url = Typecho_Common::url($file, $url) . '?v=' . $this->version;
if ($return) {
return $url;
}
echo $url;
}
/**

View File

@ -82,8 +82,7 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
$info = Typecho_Plugin::parseInfo($pluginFileName);
/** 检测依赖信息 */
list ($version, $build) = explode('/', Typecho_Common::VERSION);
if (Typecho_Plugin::checkDependence($build, $info['dependence'])) {
if (Typecho_Plugin::checkDependence(Typecho_Common::VERSION, $info['dependence'])) {
/** 获取已启用插件 */
$plugins = Typecho_Plugin::export();

View File

@ -92,8 +92,10 @@ class Widget_Plugins_List extends Typecho_Widget
$info = Typecho_Plugin::parseInfo($pluginFileName);
$info['name'] = $pluginName;
list ($version, $build) = explode('/', Typecho_Common::VERSION);
$info['dependence'] = Typecho_Plugin::checkDependence($build, $info['dependence']);
$info['dependence'] = Typecho_Plugin::checkDependence(
Typecho_Common::VERSION,
$info['dependence']
);
/** 默认即插即用 */
$info['activated'] = true;

View File

@ -31,16 +31,18 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
* 对升级包按版本进行排序
*
* @access public
*
* @param string $a a版本
* @param string $b b版本
*
* @return integer
*/
public function sortPackage($a, $b)
{
list ($ver, $rev) = explode('r', $a);
[$ver, $rev] = explode('r', $a);
$a = str_replace('_', '.', $rev);
list ($ver, $rev) = explode('r', $b);
[$ver, $rev] = explode('r', $b);
$b = str_replace('_', '.', $rev);
return version_compare($a, $b, '>') ? 1 : -1;
@ -50,12 +52,14 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
* 过滤低版本的升级包
*
* @access public
*
* @param string $version 版本号
*
* @return boolean
*/
public function filterPackage($version)
{
list ($ver, $rev) = explode('r', $version);
[$ver, $rev] = explode('r', $version);
$rev = str_replace('_', '.', $rev);
return version_compare($rev, $this->_currentVersion, '>');
}
@ -68,19 +72,19 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
*/
public function upgrade()
{
list($prefix, $this->_currentVersion) = explode('/', $this->options->generator);
[$prefix, $this->_currentVersion] = explode('/', $this->options->generator);
$packages = get_class_methods('Upgrade');
$packages = array_filter($packages, array($this, 'filterPackage'));
usort($packages, array($this, 'sortPackage'));
$packages = array_filter($packages, [$this, 'filterPackage']);
usort($packages, [$this, 'sortPackage']);
$message = array();
$message = [];
foreach ($packages as $package) {
$options = $this->widget('Widget_Options@' . $package);
/** 执行升级脚本 */
try {
$result = call_user_func(array('Upgrade', $package), $this->db, $options);
$result = call_user_func(['Upgrade', $package], $this->db, $options);
if (!empty($result)) {
$message[] = $result;
}
@ -90,23 +94,23 @@ class Widget_Upgrade extends Widget_Abstract_Options implements Widget_Interface
return;
}
list ($ver, $rev) = explode('r', $package);
[$ver, $rev] = explode('r', $package);
$ver = substr(str_replace('_', '.', $ver), 1);
$rev = str_replace('_', '.', $rev);
/** 更新版本号 */
$this->update(array('value' => 'Typecho ' . $ver . '/' . $rev),
$this->db->sql()->where('name = ?', 'generator'));
$this->update(['value' => 'Typecho ' . $ver . '/' . $rev],
$this->db->sql()->where('name = ?', 'generator'));
$this->destory('Widget_Options@' . $package);
$this->destroy('Widget_Options@' . $package);
}
/** 更新版本号 */
$this->update(array('value' => 'Typecho ' . Typecho_Common::VERSION),
$this->db->sql()->where('name = ?', 'generator'));
$this->update(['value' => 'Typecho ' . Typecho_Common::VERSION],
$this->db->sql()->where('name = ?', 'generator'));
$this->widget('Widget_Notice')->set(empty($message) ? _t("升级已经完成") : $message,
empty($message) ? 'success' : 'notice');
empty($message) ? 'success' : 'notice');
}
/**

View File

@ -2186,7 +2186,7 @@ class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface
{
if (!empty($this->_usedWidgetNameList)) {
foreach ($this->_usedWidgetNameList as $key => $widgetName) {
$this->destory($widgetName);
$this->destroy($widgetName);
unset($this->_usedWidgetNameList[$key]);
}
}